Merge "powerstats: Add NFC, PCIE, WIFI stats" into sc-dev
diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp
index b754404..8a24334 100644
--- a/interfaces/boot/1.2/BootControl.cpp
+++ b/interfaces/boot/1.2/BootControl.cpp
@@ -17,16 +17,15 @@
 #define LOG_TAG "bootcontrolhal"
 
 #include "BootControl.h"
-#include "GptUtils.h"
 
 #include <android-base/file.h>
 #include <android-base/unique_fd.h>
 #include <bootloader_message/bootloader_message.h>
 #include <cutils/properties.h>
-//#include <hardware/boot_control.h>
 #include <libboot_control/libboot_control.h>
 #include <log/log.h>
 
+#include "GptUtils.h"
 
 namespace android {
 namespace hardware {
@@ -37,12 +36,14 @@
 using android::bootable::GetMiscVirtualAbMergeStatus;
 using android::bootable::InitMiscVirtualAbMessageIfNeeded;
 using android::bootable::SetMiscVirtualAbMergeStatus;
-using android::hardware::boot::V1_1::MergeStatus;
-using android::hardware::boot::V1_0::CommandResult;
 using android::hardware::boot::V1_0::BoolResult;
+using android::hardware::boot::V1_0::CommandResult;
+using android::hardware::boot::V1_1::MergeStatus;
 
 namespace {
 
+// clang-format off
+
 #define BOOT_A_PATH     "/dev/block/by-name/boot_a"
 #define BOOT_B_PATH     "/dev/block/by-name/boot_b"
 
@@ -59,6 +60,8 @@
 #define AB_ATTR_MAX_PRIORITY        3UL
 #define AB_ATTR_MAX_RETRY_COUNT     3UL
 
+// clang-format on
+
 static std::string getDevPath(uint32_t slot) {
     char real_path[PATH_MAX];
 
@@ -122,17 +125,17 @@
     return 0;
 }
 
-}
+}  // namespace
 
 // Methods from ::android::hardware::boot::V1_0::IBootControl follow.
 Return<uint32_t> BootControl::getNumberSlots() {
     uint32_t slots = 0;
 
     if (access(BOOT_A_PATH, F_OK) == 0)
-      slots++;
+        slots++;
 
     if (access(BOOT_B_PATH, F_OK) == 0)
-      slots++;
+        slots++;
 
     return slots;
 }
@@ -189,14 +192,14 @@
         return Void();
     }
 
-    std::string boot_lun_path = std::string("/sys/devices/platform/") +
-                                boot_dev + "/pixel/boot_lun_enabled";
+    std::string boot_lun_path =
+            std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled";
     int fd = open(boot_lun_path.c_str(), O_RDWR);
     if (fd < 0) {
         // Try old path for kernels < 5.4
         // TODO: remove once kernel 4.19 support is deprecated
-        std::string boot_lun_path = std::string("/sys/devices/platform/") +
-                                    boot_dev + "/attributes/boot_lun_enabled";
+        std::string boot_lun_path =
+                std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled";
         fd = open(boot_lun_path.c_str(), O_RDWR);
         if (fd < 0) {
             _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"});
@@ -257,7 +260,8 @@
     return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE;
 }
 
-Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) {
+Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(
+        uint32_t slot) {
     if (getNumberSlots() == 0) {
         // just return true so that we don't we another call trying to mark it as successful
         // when there is no slots
@@ -278,7 +282,8 @@
     return InitMiscVirtualAbMessageIfNeeded();
 }
 
-Return<bool> BootControl::setSnapshotMergeStatus(::android::hardware::boot::V1_1::MergeStatus status) {
+Return<bool> BootControl::setSnapshotMergeStatus(
+        ::android::hardware::boot::V1_1::MergeStatus status) {
     return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status);
 }
 
@@ -300,8 +305,7 @@
 
 // Methods from ::android::hidl::base::V1_0::IBase follow.
 
-
-IBootControl* HIDL_FETCH_IBootControl(const char* /* name */) {
+IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) {
     auto module = new BootControl();
 
     module->Init();
diff --git a/interfaces/boot/1.2/BootControl.h b/interfaces/boot/1.2/BootControl.h
index b601779..17b5f0f 100644
--- a/interfaces/boot/1.2/BootControl.h
+++ b/interfaces/boot/1.2/BootControl.h
@@ -26,16 +26,15 @@
 namespace V1_2 {
 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;
-using ::android::sp;
 
 struct BootControl : public IBootControl {
-
     bool Init();
 
     // Methods from ::android::hardware::boot::V1_0::IBootControl follow.
@@ -45,22 +44,23 @@
     Return<void> setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override;
     Return<void> setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override;
     Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override;
-    Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override;
+    Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(
+            uint32_t slot) override;
     Return<void> getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override;
 
     // Methods from ::android::hardware::boot::V1_1::IBootControl follow.
-    Return<bool> setSnapshotMergeStatus(::android::hardware::boot::V1_1::MergeStatus status) override;
+    Return<bool> setSnapshotMergeStatus(
+            ::android::hardware::boot::V1_1::MergeStatus status) override;
     Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override;
 
     // Methods from ::android::hardware::boot::V1_2::IBootControl follow.
     Return<uint32_t> getActiveBootSlot() override;
 
     // Methods from ::android::hidl::base::V1_0::IBase follow.
-
 };
 
 // FIXME: most likely delete, this is only for passthrough implementations
-extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name);
+extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name);
 
 }  // namespace implementation
 }  // namespace V1_2
diff --git a/interfaces/boot/1.2/GptUtils.cpp b/interfaces/boot/1.2/GptUtils.cpp
index 514aa89..25088e7 100644
--- a/interfaces/boot/1.2/GptUtils.cpp
+++ b/interfaces/boot/1.2/GptUtils.cpp
@@ -18,10 +18,10 @@
 
 #include "GptUtils.h"
 
-#include <errno.h>
-#include <log/log.h>
 #include <android-base/file.h>
+#include <errno.h>
 #include <linux/fs.h>
+#include <log/log.h>
 #include <zlib.h>
 
 namespace android {
@@ -32,8 +32,7 @@
 
 namespace {
 
-static int ValidateGptHeader(gpt_header *gpt)
-{
+static int ValidateGptHeader(gpt_header *gpt) {
     if (gpt->signature != GPT_SIGNATURE) {
         ALOGE("invalid gpt signature 0x%lx\n", gpt->signature);
         return -1;
@@ -52,12 +51,11 @@
     return 0;
 }
 
-}
+}  // namespace
 
 GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {}
 
-int GptUtils::Load(void)
-{
+int GptUtils::Load(void) {
     fd = open(dev_path.c_str(), O_RDWR);
     if (fd < 0) {
         ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno);
@@ -102,20 +100,19 @@
     }
 
     if (ValidateGptHeader(&gpt_backup)) {
-        ALOGW("error validating gpt backup\n"); // just warn about it, not fail
+        ALOGW("error validating gpt backup\n");  // just warn about it, not fail
     }
 
     // Create map <partition name, gpt_entry pointer>
     auto get_name = [](const uint16_t *efi_name) {
         char name[37] = {};
-        for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i)
-            name[i] = efi_name[i];
+        for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i];
         return std::string(name);
     };
 
-    for (auto const &e: entry_array) {
+    for (auto const &e : entry_array) {
         if (e.name[0] == 0)
-            break;   // stop at the first partition with no name
+            break;  // stop at the first partition with no name
         std::string s = get_name(e.name);
         entries[s] = const_cast<gpt_entry *>(&e);
     }
@@ -123,19 +120,17 @@
     return 0;
 }
 
-gpt_entry *GptUtils::GetPartitionEntry(std::string name)
-{
-    return entries.find(name) != entries.end() ?  entries[name] : nullptr;
+gpt_entry *GptUtils::GetPartitionEntry(std::string name) {
+    return entries.find(name) != entries.end() ? entries[name] : nullptr;
 }
 
-int GptUtils::Sync(void)
-{
+int GptUtils::Sync(void) {
     if (!fd)
         return -1;
 
     // calculate crc and check if we need to update gpt
     gpt_primary.entries_crc32 = crc32(0, reinterpret_cast<uint8_t *>(entry_array.data()),
-                                entry_array.size() * sizeof(gpt_entry));
+                                      entry_array.size() * sizeof(gpt_entry));
 
     // save old crc
     uint32_t crc = gpt_primary.crc32;
@@ -143,7 +138,7 @@
 
     gpt_primary.crc32 = crc32(0, reinterpret_cast<uint8_t *>(&gpt_primary), sizeof gpt_primary);
     if (crc == gpt_primary.crc32)
-        return 0; // nothing to do (no changes)
+        return 0;  // nothing to do (no changes)
 
     ALOGI("updating GPT\n");
 
@@ -161,7 +156,7 @@
         return -1;
     }
 
-    //update GPT backup entries and backup
+    // update GPT backup entries and backup
     lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET);
     ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
     if (ret < 0) {
@@ -184,8 +179,7 @@
     return 0;
 }
 
-GptUtils::~GptUtils()
-{
+GptUtils::~GptUtils() {
     if (fd) {
         Sync();
         close(fd);
diff --git a/interfaces/boot/1.2/GptUtils.h b/interfaces/boot/1.2/GptUtils.h
index 8965118..a2bed33 100644
--- a/interfaces/boot/1.2/GptUtils.h
+++ b/interfaces/boot/1.2/GptUtils.h
@@ -16,9 +16,9 @@
 
 #pragma once
 
+#include <map>
 #include <string>
 #include <vector>
-#include <map>
 
 namespace android {
 namespace hardware {
@@ -26,7 +26,7 @@
 namespace V1_2 {
 namespace implementation {
 
-#define GPT_SIGNATURE       0x5452415020494645UL
+#define GPT_SIGNATURE 0x5452415020494645UL
 
 typedef struct {
     uint8_t type_guid[16];
@@ -55,21 +55,21 @@
 } __attribute__((packed)) gpt_header;
 
 class GptUtils {
-   public:
+  public:
     GptUtils(const std::string dev_path);
     int Load(void);
     gpt_entry *GetPartitionEntry(std::string name);
     int Sync(void);
     ~GptUtils();
 
-   private:
+  private:
     std::string dev_path;
     int fd;
     uint32_t block_size;
     gpt_header gpt_primary;
     gpt_header gpt_backup;
     std::vector<gpt_entry> entry_array;
-    std::map<std::string, gpt_entry *>entries;
+    std::map<std::string, gpt_entry *> entries;
 };
 
 }  // namespace implementation
diff --git a/interfaces/boot/1.2/service.cpp b/interfaces/boot/1.2/service.cpp
index 158c456..f07682e 100644
--- a/interfaces/boot/1.2/service.cpp
+++ b/interfaces/boot/1.2/service.cpp
@@ -16,10 +16,11 @@
 
 #define LOG_TAG "android.hardware.boot@1.2-service"
 
-#include <log/log.h>
+#include <android/hardware/boot/1.2/IBootControl.h>
 #include <hidl/HidlTransportSupport.h>
 #include <hidl/Status.h>
-#include <android/hardware/boot/1.2/IBootControl.h>
+#include <log/log.h>
+
 #include "BootControl.h"
 
 using ::android::status_t;
@@ -27,9 +28,9 @@
 using ::android::hardware::boot::V1_2::IBootControl;
 
 using ::android::hardware::boot::V1_2::implementation::BootControl;
-//using ::android::hardware::boot::implementation::BootControl;
+// using ::android::hardware::boot::implementation::BootControl;
 
-int main (int /* argc */, char * /* argv */ []) {
+int main(int /* argc */, char * /* argv */[]) {
     // This function must be called before you join to ensure the proper
     // number of threads are created. The threadpool will never exceed
     // size one because of this call.
@@ -38,12 +39,12 @@
     ::android::sp bootctrl = new BootControl();
     const status_t status = bootctrl->registerAsService();
     if (status != ::android::OK) {
-        return 1; // or handle error
+        return 1;  // or handle error
     }
 
     // Adds this thread to the threadpool, resulting in one total
     // thread in the threadpool. We could also do other things, but
     // would have to specify 'false' to willJoin in configureRpcThreadpool.
     ::android::hardware::joinRpcThreadpool();
-    return 1; // joinRpcThreadpool should never return
+    return 1;  // joinRpcThreadpool should never return
 }