Explorar el Código

Move to new git repo

Change-Id: Ifffe8aa3465b8c2c87716f78d0b712cf4fe7fe0f
Mao Han hace 1 año
padre
commit
32c175cfd8

+ 38 - 0
atrace/Android.bp

@@ -0,0 +1,38 @@
+//
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_binary {
+    name: "android.hardware.atrace@1.0-service.th1520",
+    defaults: ["hidl_defaults"],
+    relative_install_path: "hw",
+    vendor: true,
+    init_rc: ["android.hardware.atrace@1.0-service.th1520.rc"],
+    vintf_fragments: ["android.hardware.atrace@1.0-service.th1520.xml"],
+    srcs: [
+        "AtraceDevice.cpp",
+        "service.cpp",
+    ],
+    shared_libs: [
+        "liblog",
+        "libbase",
+        "libutils",
+        "libhidlbase",
+        "android.hardware.atrace@1.0",
+    ],
+}

+ 138 - 0
atrace/AtraceDevice.cpp

@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android-base/file.h>
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+
+#include "AtraceDevice.h"
+
+namespace android {
+namespace hardware {
+namespace atrace {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::atrace::V1_0::Status;
+using ::android::hardware::atrace::V1_0::TracingCategory;
+
+struct TracingConfig {
+    std::string description;
+    // path and if error on failure
+    std::vector<std::pair<std::string, bool>> paths;
+};
+
+// This is a map stores categories and their tracefs event name with required flags
+const std::map<std::string, TracingConfig> kTracingMap = {
+        {
+                "gfx",
+                {"Graphics",
+                 {{"mdss", false},
+                  {"sde", false},
+                  {"dpu", false},
+                  {"g2d", false},
+                  {"mali", false}}},
+        },
+        {
+                "memory",
+                {"Memory", {{"fastrpc/fastrpc_dma_stat", false}, {"dmabuf_heap", false}}},
+        },
+        {
+                "ion",
+                {"ION Allocation", {{"kmem/ion_alloc_buffer_start", false}}},
+        },
+        {
+                "sched",
+                {"CPU Scheduling and Trustzone", {{"scm", false}, {"systrace", false}}},
+        },
+};
+
+// Methods from ::android::hardware::atrace::V1_0::IAtraceDevice follow.
+Return<void> AtraceDevice::listCategories(listCategories_cb _hidl_cb) {
+    hidl_vec<TracingCategory> categories;
+    categories.resize(kTracingMap.size());
+    std::size_t i = 0;
+    for (auto &c : kTracingMap) {
+        categories[i].name = c.first;
+        categories[i].description = c.second.description;
+        i++;
+    }
+    _hidl_cb(categories);
+    return Void();
+}
+
+AtraceDevice::AtraceDevice() {
+    struct stat st;
+
+    mTracefsEventRoot = "/sys/kernel/tracing/events/";
+    if (stat(mTracefsEventRoot.c_str(), &st) != 0) {
+        mTracefsEventRoot = "/sys/kernel/debug/tracing/events/";
+        CHECK(stat(mTracefsEventRoot.c_str(), &st) == 0) << "tracefs must be mounted at either"
+                                                            "/sys/kernel/tracing or "
+                                                            "/sys/kernel/debug/tracing";
+    }
+}
+
+Return<::android::hardware::atrace::V1_0::Status> AtraceDevice::enableCategories(
+        const hidl_vec<hidl_string> &categories) {
+    if (!categories.size()) {
+        return Status::ERROR_INVALID_ARGUMENT;
+    }
+
+    for (auto &c : categories) {
+        if (kTracingMap.count(c)) {
+            for (auto &p : kTracingMap.at(c).paths) {
+                std::string tracefs_event_enable_path = android::base::StringPrintf(
+                        "%s%s/enable", mTracefsEventRoot.c_str(), p.first.c_str());
+                if (!android::base::WriteStringToFile("1", tracefs_event_enable_path)) {
+                    LOG(ERROR) << "Failed to enable tracing on: " << tracefs_event_enable_path;
+                    if (p.second) {
+                        // disable before return
+                        disableAllCategories();
+                        return Status::ERROR_TRACING_POINT;
+                    }
+                }
+            }
+        } else {
+            return Status::ERROR_INVALID_ARGUMENT;
+        }
+    }
+    return Status::SUCCESS;
+}
+
+Return<::android::hardware::atrace::V1_0::Status> AtraceDevice::disableAllCategories() {
+    auto ret = Status::SUCCESS;
+
+    for (auto &c : kTracingMap) {
+        for (auto &p : c.second.paths) {
+            std::string tracefs_event_enable_path = android::base::StringPrintf(
+                    "%s%s/enable", mTracefsEventRoot.c_str(), p.first.c_str());
+            if (!android::base::WriteStringToFile("0", tracefs_event_enable_path)) {
+                LOG(ERROR) << "Failed to disable tracing on: " << tracefs_event_enable_path;
+                if (p.second) {
+                    ret = Status::ERROR_TRACING_POINT;
+                }
+            }
+        }
+    }
+    return ret;
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace atrace
+}  // namespace hardware
+}  // namespace android

+ 53 - 0
atrace/AtraceDevice.h

@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <android/hardware/atrace/1.0/IAtraceDevice.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace atrace {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::sp;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+
+struct AtraceDevice : public IAtraceDevice {
+    AtraceDevice();
+    // Methods from ::android::hardware::atrace::V1_0::IAtraceDevice follow.
+    Return<void> listCategories(listCategories_cb _hidl_cb) override;
+    Return<::android::hardware::atrace::V1_0::Status> enableCategories(
+            const hidl_vec<hidl_string> &categories) override;
+    Return<::android::hardware::atrace::V1_0::Status> disableAllCategories() override;
+
+  private:
+    std::string mTracefsEventRoot;
+    // Methods from ::android::hidl::base::V1_0::IBase follow.
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace atrace
+}  // namespace hardware
+}  // namespace android

+ 2 - 0
atrace/OWNERS

@@ -0,0 +1,2 @@
+wvw@google.com
+namhyung@google.com

+ 43 - 0
atrace/android.hardware.atrace@1.0-service.th1520.rc

@@ -0,0 +1,43 @@
+on late-init
+    # vendor graphics trace points
+    chmod 0666 /sys/kernel/debug/tracing/events/sde/enable
+    chmod 0666 /sys/kernel/tracing/events/sde/enable
+    chmod 0666 /sys/kernel/debug/tracing/events/mdss/enable
+    chmod 0666 /sys/kernel/tracing/events/mdss/enable
+    chmod 0666 /sys/kernel/debug/tracing/events/dpu/enable
+    chmod 0666 /sys/kernel/tracing/events/dpu/enable
+    chmod 0666 /sys/kernel/debug/tracing/events/g2d/enable
+    chmod 0666 /sys/kernel/tracing/events/g2d/enable
+    chmod 0666 /sys/kernel/debug/tracing/events/mali/enable
+    chmod 0666 /sys/kernel/tracing/events/mali/enable
+
+    # ion allocation trace point
+    chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_alloc_buffer_start/enable
+    chmod 0666 /sys/kernel/tracing/events/kmem/ion_alloc_buffer_start/enable
+    # scm trace point
+    chmod 0666 /sys/kernel/debug/tracing/events/scm/enable
+    chmod 0666 /sys/kernel/tracing/events/scm/enable
+    # legacy systrace point
+    chmod 0666 /sys/kernel/debug/tracing/events/systrace/enable
+    chmod 0666 /sys/kernel/tracing/events/systrace/enable
+    # qct hw lmh-dcvs
+    chmod 0666 /sys/kernel/debug/tracing/events/lmh/lmh_dcvs_freq/enable
+    chmod 0666 /sys/kernel/tracing/events/lmh/lmh_dcvs_freq/enable
+    # qct fastrpc dma buffers
+    chmod 0666 /sys/kernel/debug/tracing/events/fastrpc/fastrpc_dma_stat/enable
+    chmod 0666 /sys/kernel/tracing/events/fastrpc/fastrpc_dma_stat/enable
+    # dmabuf heap stats
+    chmod 0666 /sys/kernel/tracing/events/dmabuf_heap/enable
+    # Tj pid control loop trace points
+    chmod 0666 /sys/kernel/debug/tracing/events/thermal_exynos/enable
+    chmod 0666 /sys/kernel/tracing/events/thermal_exynos/enable
+    chmod 0666 /sys/kernel/debug/tracing/events/thermal_exynos_gpu/enable
+    chmod 0666 /sys/kernel/tracing/events/thermal_exynos_gpu/enable
+
+service vendor.atrace-hal-1-0 /vendor/bin/hw/android.hardware.atrace@1.0-service.th1520
+    interface android.hardware.atrace@1.0::IAtraceDevice default
+    class early_hal
+    user system
+    group system
+    oneshot
+    disabled

+ 11 - 0
atrace/android.hardware.atrace@1.0-service.th1520.xml

@@ -0,0 +1,11 @@
+<manifest version="1.0" type="device">
+    <hal format="hidl">
+        <name>android.hardware.atrace</name>
+        <transport>hwbinder</transport>
+        <version>1.0</version>
+        <interface>
+            <name>IAtraceDevice</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+</manifest>

+ 45 - 0
atrace/service.cpp

@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "android.hardware.atrace@1.0-service.th1520"
+
+#include <hidl/HidlLazyUtils.h>
+#include <hidl/HidlSupport.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include "AtraceDevice.h"
+
+using ::android::OK;
+using ::android::sp;
+using ::android::hardware::configureRpcThreadpool;
+using ::android::hardware::joinRpcThreadpool;
+using ::android::hardware::LazyServiceRegistrar;
+using ::android::hardware::atrace::V1_0::IAtraceDevice;
+using ::android::hardware::atrace::V1_0::implementation::AtraceDevice;
+
+int main(int /* argc */, char * /* argv */ []) {
+    sp<IAtraceDevice> atrace = new AtraceDevice;
+    configureRpcThreadpool(1, true /* will join */);
+    auto serviceRegistrar = LazyServiceRegistrar::getInstance();
+    if (serviceRegistrar.registerService(atrace) != OK) {
+        ALOGE("Could not register service.");
+        return 1;
+    }
+    joinRpcThreadpool();
+
+    ALOGE("Service exited!");
+    return 1;
+}

+ 48 - 0
dumpstate/Android.bp

@@ -0,0 +1,48 @@
+//
+// Copyright 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_binary {
+    name: "android.hardware.dumpstate@1.1-service.th1520",
+    init_rc: ["android.hardware.dumpstate@1.1-service.th1520.rc"],
+    vintf_fragments: [
+        "android.hardware.dumpstate@1.1-service.th1520.xml",
+    ],
+    relative_install_path: "hw",
+    srcs: [
+        "DumpstateDevice.cpp",
+        "service.cpp",
+    ],
+    shared_libs: [
+        "android.hardware.dumpstate@1.0",
+        "android.hardware.dumpstate@1.1",
+        "libbase",
+        "libcutils",
+        "libdumpstateutil",
+        "libhidlbase",
+        "liblog",
+        "libutils",
+    ],
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+    proprietary: true,
+}

+ 319 - 0
dumpstate/DumpstateDevice.cpp

@@ -0,0 +1,319 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "dumpstate"
+
+#include "DumpstateDevice.h"
+
+#include <android-base/file.h>
+#include <android-base/properties.h>
+#include <android-base/unique_fd.h>
+#include <cutils/properties.h>
+#include <hidl/HidlBinderSupport.h>
+#include <hidl/HidlSupport.h>
+
+#include <log/log.h>
+#include <pthread.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#define _SVID_SOURCE
+#include <dirent.h>
+
+#include "DumpstateUtil.h"
+
+#define TCPDUMP_NUMBER_BUGREPORT "persist.vendor.tcpdump.log.br_num"
+#define TCPDUMP_PERSIST_PROPERTY "persist.vendor.tcpdump.log.alwayson"
+
+#define HW_VERSION_PROPERTY "ro.boot.hardware.revision"
+
+#define VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY "persist.vendor.verbose_logging_enabled"
+
+using android::os::dumpstate::CommandOptions;
+using android::os::dumpstate::DumpFileToFd;
+using android::os::dumpstate::PropertiesHelper;
+using android::os::dumpstate::RunCommandToFd;
+
+namespace android {
+namespace hardware {
+namespace dumpstate {
+namespace V1_1 {
+namespace implementation {
+
+#define DIAG_LOG_PREFIX "diag_log_"
+#define TCPDUMP_LOG_PREFIX "tcpdump"
+#define EXTENDED_LOG_PREFIX "extended_log_"
+
+#define BUFSIZE 65536
+
+static void DumpTouch(int fd) {
+    const char touch_spi_path[] = "/sys/class/spi_master/spi1/spi1.0";
+    char cmd[256];
+
+    snprintf(cmd, sizeof(cmd), "%s/appid", touch_spi_path);
+    if (!access(cmd, R_OK)) {
+        // Touch firmware version
+        DumpFileToFd(fd, "STM touch firmware version", cmd);
+
+        // Touch controller status
+        snprintf(cmd, sizeof(cmd), "%s/status", touch_spi_path);
+        DumpFileToFd(fd, "STM touch status", cmd);
+
+        // Mutual raw data
+        snprintf(cmd, sizeof(cmd),
+                 "echo 13 00 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
+                 touch_spi_path, touch_spi_path);
+        RunCommandToFd(fd, "Mutual Raw", {"/vendor/bin/sh", "-c", cmd});
+
+        // Mutual strength data
+        snprintf(cmd, sizeof(cmd),
+                 "echo 17 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
+                 touch_spi_path, touch_spi_path);
+        RunCommandToFd(fd, "Mutual Strength", {"/vendor/bin/sh", "-c", cmd});
+
+        // Self raw data
+        snprintf(cmd, sizeof(cmd),
+                 "echo 15 00 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
+                 touch_spi_path, touch_spi_path);
+        RunCommandToFd(fd, "Self Raw", {"/vendor/bin/sh", "-c", cmd});
+    }
+
+    if (!access("/proc/fts/driver_test", R_OK)) {
+        RunCommandToFd(fd, "Mutual Raw Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 23 00 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Mutual Baseline Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 23 03 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Mutual Strength Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 23 02 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Self Raw Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 24 00 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Self Baseline Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 24 03 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Self Strength Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 24 02 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Mutual Compensation",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 32 10 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Self Compensation",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 33 12 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+        RunCommandToFd(fd, "Golden Mutual Raw Data",
+                       {"/vendor/bin/sh", "-c",
+                        "echo 34 > /proc/fts/driver_test && "
+                        "cat /proc/fts/driver_test"});
+    }
+}
+
+static void DumpDisplay(int fd) {
+    DumpFileToFd(fd, "PANEL VENDOR NAME", "/sys/class/panel_info/panel0/panel_vendor_name");
+    DumpFileToFd(fd, "PANEL SN", "/sys/class/panel_info/panel0/serial_number");
+    DumpFileToFd(fd, "PANEL EXTRA INFO", "/sys/class/panel_info/panel0/panel_extinfo");
+
+    const std::string pmic_regmap_path = "/sys/kernel/debug/regmap/spmi0-05";
+    using android::base::WriteStringToFile;
+
+    if (WriteStringToFile("0x80", pmic_regmap_path + "/count", true) &&
+            WriteStringToFile("0xE000", pmic_regmap_path + "/address", true)) {
+        DumpFileToFd(fd, "OLEDB Register Dump", pmic_regmap_path + "/data");
+    } else {
+	dprintf(fd, "Unable to print OLEDB Register Dump\n");
+    }
+
+    if (WriteStringToFile("0x80", pmic_regmap_path + "/count", true) &&
+            WriteStringToFile("0xDE00", pmic_regmap_path + "/address", true)) {
+        DumpFileToFd(fd, "ELVDD Register Dump", pmic_regmap_path + "/data");
+    } else {
+	dprintf(fd, "Unable to print ELVDD Register Dump\n");
+    }
+
+    if (WriteStringToFile("0x60", pmic_regmap_path + "/count", true) &&
+            WriteStringToFile("0xDC00", pmic_regmap_path + "/address", true)) {
+        DumpFileToFd(fd, "ELVSS Register Dump", pmic_regmap_path + "/data");
+    } else {
+	dprintf(fd, "Unable to print ELVSS Register Dump\n");
+    }
+}
+
+static void DumpF2FS(int fd) {
+    DumpFileToFd(fd, "F2FS", "/sys/kernel/debug/f2fs/status");
+    RunCommandToFd(fd, "F2FS - fsck time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.fsck.data"});
+    RunCommandToFd(fd, "F2FS - checkpoint=disable time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.mount.data"});
+}
+
+static void DumpUFS(int fd) {
+    DumpFileToFd(fd, "UFS model", "/sys/block/sda/device/model");
+    DumpFileToFd(fd, "UFS rev", "/sys/block/sda/device/rev");
+    DumpFileToFd(fd, "UFS size", "/sys/block/sda/size");
+    DumpFileToFd(fd, "UFS show_hba", "/sys/kernel/debug/ufshcd0/show_hba");
+
+    DumpFileToFd(fd, "UFS Slow IO Read", "/dev/sys/block/bootdevice/slowio_read_cnt");
+    DumpFileToFd(fd, "UFS Slow IO Write", "/dev/sys/block/bootdevice/slowio_write_cnt");
+    DumpFileToFd(fd, "UFS Slow IO Unmap", "/dev/sys/block/bootdevice/slowio_unmap_cnt");
+    DumpFileToFd(fd, "UFS Slow IO Sync", "/dev/sys/block/bootdevice/slowio_sync_cnt");
+
+    RunCommandToFd(fd, "UFS err_stats", {"/vendor/bin/sh", "-c",
+                       "path=\"/dev/sys/block/bootdevice/err_stats\"; "
+                       "for node in `ls $path/err_*`; do "
+                       "printf \"%s:%d\\n\" $(basename $node) $(cat $node); done;"});
+
+    RunCommandToFd(fd, "UFS io_stats", {"/vendor/bin/sh", "-c",
+                       "path=\"/dev/sys/block/bootdevice/io_stats\"; "
+                       "printf \"\\t\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "ReadCnt ReadBytes WriteCnt WriteBytes RWCnt RWBytes; "
+                       "str=$(cat $path/*_start); arr=($str); "
+                       "printf \"Started: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
+                       "str=$(cat $path/*_complete); arr=($str); "
+                       "printf \"Completed: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
+                       "str=$(cat $path/*_maxdiff); arr=($str); "
+                       "printf \"MaxDiff: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
+                       "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "});
+
+    RunCommandToFd(fd, "UFS req_stats", {"/vendor/bin/sh", "-c",
+                       "path=\"/dev/sys/block/bootdevice/req_stats\"; "
+                       "printf \"\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "All Write Read Read\\(urg\\) Write\\(urg\\) Flush Discard; "
+                       "str=$(cat $path/*_min); arr=($str); "
+                       "printf \"Min:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
+                       "str=$(cat $path/*_max); arr=($str); "
+                       "printf \"Max:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
+                       "str=$(cat $path/*_avg); arr=($str); "
+                       "printf \"Avg.:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
+                       "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
+                       "str=$(cat $path/*_sum); arr=($str); "
+                       "printf \"Count:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
+                       "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]};"});
+
+    std::string ufs_health = "for f in $(find /dev/sys/block/bootdevice/health -type f); do if [[ -r $f && -f $f ]]; then echo --- $f; cat $f; echo ''; fi; done";
+    RunCommandToFd(fd, "UFS health", {"/vendor/bin/sh", "-c", ufs_health.c_str()});
+}
+
+static void DumpPower(int fd) {
+    RunCommandToFd(fd, "Power Stats Times", {"/vendor/bin/sh", "-c",
+                   "echo -n \"Boot: \" && /vendor/bin/uptime -s &&"
+                   "echo -n \"Now: \" && date"});
+    DumpFileToFd(fd, "Sleep Stats", "/sys/power/system_sleep/stats");
+    DumpFileToFd(fd, "Power Management Stats", "/sys/power/rpmh_stats/master_stats");
+    DumpFileToFd(fd, "WLAN Power Stats", "/sys/kernel/wlan/power_stats");
+}
+
+// Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
+Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
+    // Ignore return value, just return an empty status.
+    dumpstateBoard_1_1(handle, DumpstateMode::DEFAULT, 30 * 1000 /* timeoutMillis */);
+    return Void();
+}
+
+// Methods from ::android::hardware::dumpstate::V1_1::IDumpstateDevice follow.
+Return<DumpstateStatus> DumpstateDevice::dumpstateBoard_1_1(const hidl_handle& handle,
+                                                            const DumpstateMode mode,
+                                                            const uint64_t timeoutMillis) {
+    // Unused arguments.
+    (void) timeoutMillis;
+
+    // Exit when dump is completed since this is a lazy HAL.
+    addPostCommandTask([]() {
+        exit(0);
+    });
+
+    if (handle == nullptr || handle->numFds < 1) {
+        ALOGE("no FDs\n");
+        return DumpstateStatus::ILLEGAL_ARGUMENT;
+    }
+
+    int fd = handle->data[0];
+    if (fd < 0) {
+        ALOGE("invalid FD: %d\n", handle->data[0]);
+        return DumpstateStatus::ILLEGAL_ARGUMENT;
+    }
+
+    bool isModeValid = false;
+    for (const auto dumpstateMode : hidl_enum_range<DumpstateMode>()) {
+        if (mode == dumpstateMode) {
+            isModeValid = true;
+            break;
+        }
+    }
+    if (!isModeValid) {
+        ALOGE("Invalid mode: %d\n", mode);
+        return DumpstateStatus::ILLEGAL_ARGUMENT;
+    } else if (mode == DumpstateMode::WEAR) {
+        // We aren't a Wear device.
+        ALOGE("Unsupported mode: %d\n", mode);
+        return DumpstateStatus::UNSUPPORTED_MODE;
+    }
+
+    RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"});
+    DumpFileToFd(fd, "SoC serial number", "/sys/devices/soc0/serial_number");
+    DumpFileToFd(fd, "CPU present", "/sys/devices/system/cpu/present");
+    DumpFileToFd(fd, "CPU online", "/sys/devices/system/cpu/online");
+    DumpTouch(fd);
+    DumpDisplay(fd);
+
+    DumpF2FS(fd);
+    DumpUFS(fd);
+
+    DumpFileToFd(fd, "INTERRUPTS", "/proc/interrupts");
+
+    DumpPower(fd);
+
+    DumpFileToFd(fd, "LL-Stats", "/d/wlan0/ll_stats");
+    DumpFileToFd(fd, "WLAN Connect Info", "/d/wlan0/connect_info");
+    DumpFileToFd(fd, "WLAN Offload Info", "/d/wlan0/offload_info");
+    DumpFileToFd(fd, "WLAN Roaming Stats", "/d/wlan0/roam_stats");
+    DumpFileToFd(fd, "ICNSS Stats", "/d/icnss/stats");
+    DumpFileToFd(fd, "SMD Log", "/d/ipc_logging/smd/log");
+    RunCommandToFd(fd, "ION HEAPS", {"/vendor/bin/sh", "-c", "for d in $(ls -d /d/ion/*); do for f in $(ls $d); do echo --- $d/$f; cat $d/$f; done; done"});
+    DumpFileToFd(fd, "dmabuf info", "/d/dma_buf/bufinfo");
+    RunCommandToFd(fd, "Temperatures", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/thermal* ; do type=`cat $f/type` ; temp=`cat $f/temp` ; echo \"$type: $temp\" ; done"});
+    RunCommandToFd(fd, "Cooling Device Current State", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/cooling* ; do type=`cat $f/type` ; temp=`cat $f/cur_state` ; echo \"$type: $temp\" ; done"});
+    RunCommandToFd(fd, "CPU time-in-state", {"/vendor/bin/sh", "-c", "for cpu in /sys/devices/system/cpu/cpu*; do f=$cpu/cpufreq/stats/time_in_state; if [ ! -f $f ]; then continue; fi; echo $f:; cat $f; done"});
+    RunCommandToFd(fd, "CPU cpuidle", {"/vendor/bin/sh", "-c", "for cpu in /sys/devices/system/cpu/cpu*; do for d in $cpu/cpuidle/state*; do if [ ! -d $d ]; then continue; fi; echo \"$d: `cat $d/name` `cat $d/desc` `cat $d/time` `cat $d/usage`\"; done; done"});
+
+    return DumpstateStatus::OK;
+}
+
+Return<void> DumpstateDevice::setVerboseLoggingEnabled(const bool enable) {
+    android::base::SetProperty(VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY, enable ? "true" : "false");
+    return Void();
+}
+
+Return<bool> DumpstateDevice::getVerboseLoggingEnabled() {
+    return android::base::GetBoolProperty(VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY, false);
+}
+
+}  // namespace implementation
+}  // namespace V1_1
+}  // namespace dumpstate
+}  // namespace hardware
+}  // namespace android

+ 59 - 0
dumpstate/DumpstateDevice.h

@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ANDROID_HARDWARE_DUMPSTATE_V1_1_DUMPSTATEDEVICE_H
+#define ANDROID_HARDWARE_DUMPSTATE_V1_1_DUMPSTATEDEVICE_H
+
+#include <android/hardware/dumpstate/1.1/IDumpstateDevice.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <string>
+
+namespace android {
+namespace hardware {
+namespace dumpstate {
+namespace V1_1 {
+namespace implementation {
+
+using ::android::hardware::dumpstate::V1_1::DumpstateMode;
+using ::android::hardware::dumpstate::V1_1::DumpstateStatus;
+using ::android::hardware::dumpstate::V1_1::IDumpstateDevice;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_handle;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct DumpstateDevice : public IDumpstateDevice {
+  // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
+  Return<void> dumpstateBoard(const hidl_handle& h) override;
+
+  // Methods from ::android::hardware::dumpstate::V1_1::IDumpstateDevice follow.
+  Return<DumpstateStatus> dumpstateBoard_1_1(const hidl_handle& h,
+                                             const DumpstateMode mode,
+                                             const uint64_t timeoutMillis) override;
+  Return<void> setVerboseLoggingEnabled(const bool enable) override;
+  Return<bool> getVerboseLoggingEnabled() override;
+};
+
+}  // namespace implementation
+}  // namespace V1_1
+}  // namespace dumpstate
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_DUMPSTATE_V1_1_DUMPSTATEDEVICE_H

+ 7 - 0
dumpstate/android.hardware.dumpstate@1.1-service.th1520.rc

@@ -0,0 +1,7 @@
+service vendor.dumpstate-1-1 /vendor/bin/hw/android.hardware.dumpstate@1.1-service.th1520
+    class hal
+    user system
+    interface android.hardware.dumpstate@1.0::IDumpstateDevice default
+    interface android.hardware.dumpstate@1.1::IDumpstateDevice default
+    oneshot
+    disabled

+ 11 - 0
dumpstate/android.hardware.dumpstate@1.1-service.th1520.xml

@@ -0,0 +1,11 @@
+<manifest version="1.0" type="device">
+    <hal format="hidl">
+        <name>android.hardware.dumpstate</name>
+        <transport>hwbinder</transport>
+        <version>1.1</version>
+        <interface>
+            <name>IDumpstateDevice</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+</manifest>

+ 43 - 0
dumpstate/service.cpp

@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "android.hardware.dumpstate@1.1-service.th1520"
+
+#include <hidl/HidlSupport.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include "DumpstateDevice.h"
+
+using ::android::hardware::configureRpcThreadpool;
+using ::android::hardware::dumpstate::V1_1::IDumpstateDevice;
+using ::android::hardware::dumpstate::V1_1::implementation::DumpstateDevice;
+using ::android::hardware::joinRpcThreadpool;
+using ::android::sp;
+
+
+int main(int /* argc */, char* /* argv */ []) {
+  sp<IDumpstateDevice> dumpstate = new DumpstateDevice;
+  configureRpcThreadpool(1, true);
+
+  android::status_t status = dumpstate->registerAsService();
+
+  if (status != android::OK)
+  {
+    ALOGE("Could not register DumpstateDevice service (%d).", status);
+    return -1;
+  }
+
+  joinRpcThreadpool();
+}

+ 51 - 0
health/Android.bp

@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_library_shared {
+    name: "android.hardware.health@2.1-impl-thead",
+    stem: "android.hardware.health@2.0-impl-2.1-thead",
+
+    proprietary: true,
+    relative_install_path: "hw",
+    srcs: [
+        "Health.cpp",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+
+    static_libs: [
+        "android.hardware.health@1.0-convert",
+        "libbatterymonitor",
+        "libhealth2impl",
+        "libhealthloop",
+    ],
+
+    shared_libs: [
+        "libbase",
+        "libcutils",
+        "libhidlbase",
+        "libutils",
+        "android.hardware.health@2.0",
+        "android.hardware.health@2.1",
+    ],
+}

+ 192 - 0
health/Health.cpp

@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "android.hardware.health@2.1-impl-thead"
+#include <android-base/logging.h>
+
+#include <android-base/file.h>
+#include <android-base/parseint.h>
+#include <android-base/strings.h>
+#include <android/hardware/health/2.0/types.h>
+#include <health2impl/Health.h>
+#include <health/utils.h>
+#include <hal_conversion.h>
+
+#include <fstream>
+#include <iomanip>
+#include <string>
+#include <vector>
+
+namespace {
+
+using namespace std::literals;
+
+using android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo;
+using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;
+using android::hardware::health::V2_0::DiskStats;
+using android::hardware::health::V2_0::StorageAttribute;
+using android::hardware::health::V2_0::StorageInfo;
+using android::hardware::health::V2_0::Result;
+using ::android::hardware::health::V2_1::IHealth;
+using android::hardware::health::InitHealthdConfig;
+
+#define FG_DIR "/sys/class/power_supply"
+//constexpr char kBatteryResistance[] {FG_DIR "/bms/resistance"};
+//constexpr char kBatteryOCV[] {FG_DIR "/bms/voltage_ocv"};
+//constexpr char kVoltageAvg[] {FG_DIR "/battery/voltage_now"};
+
+#define UFS_DIR "/sys/devices/platform/soc/1d84000.ufshc"
+constexpr char kUfsHealthEol[]{UFS_DIR "/health/eol"};
+constexpr char kUfsHealthLifetimeA[]{UFS_DIR "/health/lifetimeA"};
+constexpr char kUfsHealthLifetimeB[]{UFS_DIR "/health/lifetimeB"};
+constexpr char kUfsVersion[]{UFS_DIR "/version"};
+constexpr char kDiskStatsFile[]{"/sys/block/sda/stat"};
+constexpr char kUFSName[]{"UFS0"};
+
+constexpr char kTCPMPSYName[]{"tcpm-source-psy-usbpd0"};
+
+std::ifstream assert_open(const std::string &path) {
+  std::ifstream stream(path);
+  if (!stream.is_open()) {
+    LOG(WARNING) << "Cannot read " << path;
+  }
+  return stream;
+}
+
+template <typename T>
+void read_value_from_file(const std::string &path, T *field) {
+  auto stream = assert_open(path);
+  stream.unsetf(std::ios_base::basefield);
+  stream >> *field;
+}
+
+void read_ufs_version(StorageInfo *info) {
+  uint64_t value;
+  read_value_from_file(kUfsVersion, &value);
+  std::stringstream ss;
+  ss << "ufs " << std::hex << value;
+  info->version = ss.str();
+}
+
+void fill_ufs_storage_attribute(StorageAttribute *attr) {
+  attr->isInternal = true;
+  attr->isBootDevice = true;
+  attr->name = kUFSName;
+}
+
+void private_healthd_board_init(struct healthd_config *hc) {
+  hc->ignorePowerSupplyNames.push_back(android::String8(kTCPMPSYName));
+}
+
+int private_healthd_board_battery_update(struct android::BatteryProperties *props) {
+  return 0;
+}
+
+void private_get_storage_info(std::vector<StorageInfo> &vec_storage_info) {
+  vec_storage_info.resize(1);
+  StorageInfo *storage_info = &vec_storage_info[0];
+  fill_ufs_storage_attribute(&storage_info->attr);
+
+  read_ufs_version(storage_info);
+  read_value_from_file(kUfsHealthEol, &storage_info->eol);
+  read_value_from_file(kUfsHealthLifetimeA, &storage_info->lifetimeA);
+  read_value_from_file(kUfsHealthLifetimeB, &storage_info->lifetimeB);
+  return;
+}
+
+void private_get_disk_stats(std::vector<DiskStats> &vec_stats) {
+  vec_stats.resize(1);
+  DiskStats *stats = &vec_stats[0];
+  fill_ufs_storage_attribute(&stats->attr);
+
+  auto stream = assert_open(kDiskStatsFile);
+  // Regular diskstats entries
+  stream >> stats->reads >> stats->readMerges >> stats->readSectors >>
+      stats->readTicks >> stats->writes >> stats->writeMerges >>
+      stats->writeSectors >> stats->writeTicks >> stats->ioInFlight >>
+      stats->ioTicks >> stats->ioInQueue;
+  return;
+}
+}  // anonymous namespace
+
+namespace android {
+namespace hardware {
+namespace health {
+namespace V2_1 {
+namespace implementation {
+class HealthImpl : public Health {
+ public:
+  HealthImpl(std::unique_ptr<healthd_config>&& config)
+    : Health(std::move(config)) {}
+
+  Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
+  Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
+
+ protected:
+  void UpdateHealthInfo(HealthInfo* health_info) override;
+
+};
+
+void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) {
+  struct BatteryProperties props;
+  convertFromHealthInfo(health_info->legacy.legacy, &props);
+  private_healthd_board_battery_update(&props);
+  convertToHealthInfo(&props, health_info->legacy.legacy);
+}
+
+Return<void> HealthImpl::getStorageInfo(getStorageInfo_cb _hidl_cb)
+{
+  std::vector<struct StorageInfo> info;
+  private_get_storage_info(info);
+  hidl_vec<struct StorageInfo> info_vec(info);
+  if (!info.size()) {
+      _hidl_cb(Result::NOT_SUPPORTED, info_vec);
+  } else {
+      _hidl_cb(Result::SUCCESS, info_vec);
+  }
+  return Void();
+}
+
+Return<void> HealthImpl::getDiskStats(getDiskStats_cb _hidl_cb)
+{
+  std::vector<struct DiskStats> stats;
+  private_get_disk_stats(stats);
+  hidl_vec<struct DiskStats> stats_vec(stats);
+  if (!stats.size()) {
+      _hidl_cb(Result::NOT_SUPPORTED, stats_vec);
+  } else {
+      _hidl_cb(Result::SUCCESS, stats_vec);
+  }
+  return Void();
+}
+
+}  // namespace implementation
+}  // namespace V2_1
+}  // namespace health
+}  // namespace hardware
+}  // namespace android
+
+extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
+  using ::android::hardware::health::V2_1::implementation::HealthImpl;
+  if (instance != "default"sv) {
+      return nullptr;
+  }
+  auto config = std::make_unique<healthd_config>();
+  InitHealthdConfig(config.get());
+
+  private_healthd_board_init(config.get());
+
+  return new HealthImpl(std::move(config));
+}

+ 29 - 0
libmemtrack/Android.mk

@@ -0,0 +1,29 @@
+# Copyright (C) 2021 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+# HAL module implemenation stored in
+# hw/<POWERS_HARDWARE_MODULE_ID>.<ro.hardware>.so
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_C_INCLUDES += hardware/libhardware/include
+LOCAL_CFLAGS := -Wconversion -Wall -Werror -Wno-sign-conversion
+LOCAL_CLANG  := true
+LOCAL_SHARED_LIBRARIES := liblog libhardware
+LOCAL_SRC_FILES := memtrack_dummy.c
+LOCAL_MODULE := memtrack.$(TARGET_BOARD_PLATFORM)
+include $(BUILD_SHARED_LIBRARY)

+ 45 - 0
libmemtrack/memtrack_dummy.c

@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+
+#include <hardware/memtrack.h>
+
+int dummy_memtrack_init(const struct memtrack_module *module)
+{
+    if (!module)
+        return -1;
+
+    return 0;
+}
+
+static struct hw_module_methods_t memtrack_module_methods = {
+    .open = NULL,
+};
+
+struct memtrack_module HAL_MODULE_INFO_SYM = {
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .module_api_version = MEMTRACK_MODULE_API_VERSION_0_1,
+        .hal_api_version = HARDWARE_HAL_API_VERSION,
+        .id = MEMTRACK_HARDWARE_MODULE_ID,
+        .name = "DUMMY Memory Tracker HAL",
+        .author = "The Android Open Source Project",
+        .methods = &memtrack_module_methods,
+    },
+
+    .init = dummy_memtrack_init,
+};

+ 33 - 0
oemlock/Android.bp

@@ -0,0 +1,33 @@
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_binary {
+    name: "android.hardware.oemlock-service.th1520",
+    relative_install_path: "hw",
+    init_rc: ["android.hardware.oemlock-service.th1520.rc"],
+    vintf_fragments: ["android.hardware.oemlock-service.th1520.xml"],
+    vendor: true,
+    srcs: [
+        "service.cpp",
+        "OemLock.cpp",
+    ],
+    shared_libs: [
+        "android.hardware.oemlock-V1-ndk_platform",
+        "libbase",
+        "libbinder_ndk",
+    ],
+}

+ 58 - 0
oemlock/OemLock.cpp

@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "OemLock.h"
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace oemlock {
+
+// Methods from ::android::hardware::oemlock::IOemLock follow.
+
+::ndk::ScopedAStatus OemLock::getName(std::string *out_name) {
+    *out_name = "OemLock";
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus OemLock::setOemUnlockAllowedByCarrier(bool in_allowed, const std::vector<uint8_t> &in_signature, OemLockSecureStatus *_aidl_return) {
+    // Default impl doesn't care about a valid vendor signature
+    (void)in_signature;
+
+    mAllowedByCarrier = in_allowed;
+    *_aidl_return = OemLockSecureStatus::OK;
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus OemLock::isOemUnlockAllowedByCarrier(bool *out_allowed) {
+    *out_allowed = mAllowedByCarrier;
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus OemLock::setOemUnlockAllowedByDevice(bool in_allowed) {
+    mAllowedByDevice = in_allowed;
+    return ::ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus OemLock::isOemUnlockAllowedByDevice(bool *out_allowed) {
+    *out_allowed = mAllowedByDevice;
+    return ::ndk::ScopedAStatus::ok();
+}
+
+} // namespace oemlock
+} // namespace hardware
+} // namespace android
+} // aidl

+ 48 - 0
oemlock/OemLock.h

@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <aidl/android/hardware/oemlock/BnOemLock.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace oemlock {
+
+using ::aidl::android::hardware::oemlock::IOemLock;
+using ::aidl::android::hardware::oemlock::OemLockSecureStatus;
+
+struct OemLock : public BnOemLock {
+public:
+    OemLock() = default;
+
+    // Methods from ::android::hardware::oemlock::IOemLock follow.
+    ::ndk::ScopedAStatus getName(std::string* out_name) override;
+    ::ndk::ScopedAStatus isOemUnlockAllowedByCarrier(bool* out_allowed) override;
+    ::ndk::ScopedAStatus isOemUnlockAllowedByDevice(bool* out_allowed) override;
+    ::ndk::ScopedAStatus setOemUnlockAllowedByCarrier(bool in_allowed, const std::vector<uint8_t>& in_signature, OemLockSecureStatus* _aidl_return) override;
+    ::ndk::ScopedAStatus setOemUnlockAllowedByDevice(bool in_allowed) override;
+
+    private:
+    bool mAllowedByCarrier = false;
+    bool mAllowedByDevice = false;
+};
+
+} // namespace oemlock
+} // namespace hardware
+} // namespace android
+} // aidl

+ 4 - 0
oemlock/android.hardware.oemlock-service.th1520.rc

@@ -0,0 +1,4 @@
+service vendor.oemlock_default /vendor/bin/hw/android.hardware.oemlock-service.th1520
+    class hal
+    user hsm
+    group hsm

+ 9 - 0
oemlock/android.hardware.oemlock-service.th1520.xml

@@ -0,0 +1,9 @@
+<manifest version="1.0" type="device">
+    <hal format="aidl">
+        <name>android.hardware.oemlock</name>
+        <interface>
+            <name>IOemLock</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+</manifest>

+ 35 - 0
oemlock/service.cpp

@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+#include "OemLock.h"
+
+using ::aidl::android::hardware::oemlock::OemLock;
+
+int main() {
+    ABinderProcess_setThreadPoolMaxThreadCount(0);
+    std::shared_ptr<OemLock> oemlock = ndk::SharedRefBase::make<OemLock>();
+
+    const std::string instance = std::string() + OemLock::descriptor + "/default";
+    binder_status_t status = AServiceManager_addService(oemlock->asBinder().get(), instance.c_str());
+    CHECK(status == STATUS_OK);
+
+    ABinderProcess_joinThreadPool();
+    return -1; // Should never be reached
+}