Move power stats service to device specific folders

Bug: 183052760
Test: dumpsys android.hardware.power.stats.IPowerStats/default
Change-Id: I4d4881e227982aa17b88af8844c82dc448ef5b6f
Merged-In: I4d4881e227982aa17b88af8844c82dc448ef5b6f
diff --git a/powerstats/Android.bp b/powerstats/Android.bp
index 7c7066c..10ecbed 100644
--- a/powerstats/Android.bp
+++ b/powerstats/Android.bp
@@ -22,30 +22,17 @@
     ],
 }
 
-cc_binary {
-    name: "android.hardware.power.stats-service.pixel",
-    init_rc: ["android.hardware.power.stats-service.pixel.rc"],
-    vintf_fragments: ["android.hardware.power.stats-service.pixel.xml"],
+cc_library {
+    name: "android.hardware.power.stats-impl.gs101",
+    vendor_available: true,
+    export_include_dirs: ["include"],
+    defaults: ["powerstats_pixel_defaults"],
+
     srcs: [
         "*.cpp",
     ],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-    static_libs: [
+
+    shared_libs: [
         "android.hardware.power.stats-impl.pixel",
     ],
-    shared_libs: [
-        "libbase",
-        "libcutils",
-        "liblog",
-        "libutils",
-        "libbinder_ndk",
-        "pixel_stateresidency_provider_aidl_interface-ndk_platform",
-        "android.hardware.power.stats-V1-ndk_platform",
-    ],
-    relative_install_path: "hw",
-    vendor: true,
-    proprietary: true,
 }
diff --git a/powerstats/service.cpp b/powerstats/Gs101CommonDataProviders.cpp
similarity index 96%
rename from powerstats/service.cpp
rename to powerstats/Gs101CommonDataProviders.cpp
index 16953ee..a47f93a 100644
--- a/powerstats/service.cpp
+++ b/powerstats/Gs101CommonDataProviders.cpp
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "android.hardware.power.stats-service.pixel"
-
 #include <PowerStatsAidl.h>
+#include <Gs101CommonDataProviders.h>
 #include "AocStateResidencyDataProvider.h"
 #include "DvfsStateResidencyDataProvider.h"
 #include "UfsStateResidencyDataProvider.h"
@@ -41,7 +40,6 @@
 using aidl::android::hardware::power::stats::GenericStateResidencyDataProvider;
 using aidl::android::hardware::power::stats::IioEnergyMeterDataProvider;
 using aidl::android::hardware::power::stats::PixelStateResidencyDataProvider;
-using aidl::android::hardware::power::stats::PowerStats;
 using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
 
 constexpr char kBootHwSoCRev[] = "ro.boot.hw.soc.rev";
@@ -575,14 +573,7 @@
     p->addStateResidencyDataProvider(std::move(pixelSdp));
 }
 
-int main() {
-    LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
-
-    // single thread
-    ABinderProcess_setThreadPoolMaxThreadCount(0);
-
-    std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
-
+void addGs101CommonDataProviders(std::shared_ptr<PowerStats> p) {
     setEnergyMeter(p);
 
     addPixelStateResidencyDataProvider(p);
@@ -602,11 +593,4 @@
     // TODO (b/181070764) (b/182941084):
     // Remove this when Wifi/BT energy consumption models are available or revert before ship
     addPlaceholderEnergyConsumers(p);
-
-    const std::string instance = std::string() + PowerStats::descriptor + "/default";
-    binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
-    LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
-
-    ABinderProcess_joinThreadPool();
-    return EXIT_FAILURE;  // should not reach
 }
diff --git a/powerstats/android.hardware.power.stats-service.pixel.rc b/powerstats/android.hardware.power.stats-service.pixel.rc
deleted file mode 100644
index f044b05..0000000
--- a/powerstats/android.hardware.power.stats-service.pixel.rc
+++ /dev/null
@@ -1,4 +0,0 @@
-service vendor.power.stats.pixel /vendor/bin/hw/android.hardware.power.stats-service.pixel
-    class hal
-    user system
-    group system
diff --git a/powerstats/android.hardware.power.stats-service.pixel.xml b/powerstats/android.hardware.power.stats-service.pixel.xml
deleted file mode 100644
index 3fade2a..0000000
--- a/powerstats/android.hardware.power.stats-service.pixel.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<manifest version="1.0" type="device">
-    <hal format="aidl">
-        <name>android.hardware.power.stats</name>
-        <fqname>IPowerStats/default</fqname>
-    </hal>
-</manifest>
\ No newline at end of file
diff --git a/powerstats/include/Gs101CommonDataProviders.h b/powerstats/include/Gs101CommonDataProviders.h
new file mode 100644
index 0000000..983650c
--- /dev/null
+++ b/powerstats/include/Gs101CommonDataProviders.h
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <PowerStatsAidl.h>
+
+using aidl::android::hardware::power::stats::PowerStats;
+
+void addGs101CommonDataProviders(std::shared_ptr<PowerStats> p);