From 30666f39132a30539d9d3430a19f98d1a47b01c8 Mon Sep 17 00:00:00 2001 From: SamarV-121 Date: Fri, 1 Jan 2021 15:37:27 +0100 Subject: [PATCH] kunlun2: Import Pixel power AIDL HAL Nuke Powerstats --- Android.bp | 1 + configs/powerhint.json | 114 ++---- device.mk | 4 +- framework_manifest.xml | 13 +- power-libperfmgr/Android.bp | 63 ++-- power-libperfmgr/Power.cpp | 339 ------------------ power-libperfmgr/Power.h | 87 ----- power-libperfmgr/aidl/Power.cpp | 256 +++++++++++++ power-libperfmgr/aidl/Power.h | 63 ++++ power-libperfmgr/aidl/PowerExt.cpp | 87 +++++ power-libperfmgr/aidl/PowerExt.h | 56 +++ .../android.hardware.power-service.lenovo.rc | 17 + .../android.hardware.power-service.lenovo.xml | 6 + power-libperfmgr/aidl/service.cpp | 78 ++++ ...are.power@1.3-service.lenovo-libperfmgr.rc | 16 - ...roid.hardware.power@1.3-service.lenovo.xml | 11 - .../disp-power/DisplayLowPower.cpp | 73 ++++ power-libperfmgr/disp-power/DisplayLowPower.h | 37 ++ .../{ => disp-power}/InteractionHandler.cpp | 2 +- .../{ => disp-power}/InteractionHandler.h | 0 power-libperfmgr/service.cpp | 59 --- powerstats/Android.bp | 38 -- ...hardware.power.stats@1.0-service.lenovo.rc | 4 - powerstats/service.cpp | 141 -------- sepolicy/private/file.te | 1 - sepolicy/private/file_contexts | 3 +- sepolicy/private/genfs_contexts | 1 - sepolicy/private/hal_power_pixel.te | 1 - sepolicy/private/hal_powerstats.te | 19 - sepolicy/private/system_server.te | 1 - 30 files changed, 751 insertions(+), 840 deletions(-) delete mode 100644 power-libperfmgr/Power.cpp delete mode 100644 power-libperfmgr/Power.h create mode 100644 power-libperfmgr/aidl/Power.cpp create mode 100644 power-libperfmgr/aidl/Power.h create mode 100644 power-libperfmgr/aidl/PowerExt.cpp create mode 100644 power-libperfmgr/aidl/PowerExt.h create mode 100644 power-libperfmgr/aidl/android.hardware.power-service.lenovo.rc create mode 100644 power-libperfmgr/aidl/android.hardware.power-service.lenovo.xml create mode 100644 power-libperfmgr/aidl/service.cpp delete mode 100644 power-libperfmgr/android.hardware.power@1.3-service.lenovo-libperfmgr.rc delete mode 100644 power-libperfmgr/android.hardware.power@1.3-service.lenovo.xml create mode 100644 power-libperfmgr/disp-power/DisplayLowPower.cpp create mode 100644 power-libperfmgr/disp-power/DisplayLowPower.h rename power-libperfmgr/{ => disp-power}/InteractionHandler.cpp (99%) rename power-libperfmgr/{ => disp-power}/InteractionHandler.h (100%) delete mode 100644 power-libperfmgr/service.cpp delete mode 100644 powerstats/Android.bp delete mode 100644 powerstats/android.hardware.power.stats@1.0-service.lenovo.rc delete mode 100644 powerstats/service.cpp delete mode 100644 sepolicy/private/hal_powerstats.te diff --git a/Android.bp b/Android.bp index c028497..e69df8d 100644 --- a/Android.bp +++ b/Android.bp @@ -1,5 +1,6 @@ soong_namespace { imports: [ + "hardware/google/interfaces", "hardware/google/pixel", ], } diff --git a/configs/powerhint.json b/configs/powerhint.json index 6b70640..2a8d345 100644 --- a/configs/powerhint.json +++ b/configs/powerhint.json @@ -115,8 +115,8 @@ "Name": "TASchedtuneBoost", "Path": "/dev/stune/top-app/schedtune.boost", "Values": [ - "10", - "5" + "50", + "10" ], "ResetOnInit": true }, @@ -206,9 +206,6 @@ "Name": "PowerHALMainState", "Path": "vendor.powerhal.state", "Values": [ - "CAMERA_STREAMING", - "CAMERA_STREAMING_1080P", - "CAMERA_STREAMING_4K", "SUSTAINED_PERFORMANCE", "" ], @@ -218,16 +215,7 @@ "Name": "PowerHALAudioState", "Path": "vendor.powerhal.audio", "Values": [ - "AUDIO_LOW_LATENCY", - "" - ], - "Type": "Property" - }, - { - "Name": "PowerHALRenderingState", - "Path": "vendor.powerhal.rendering", - "Values": [ - "EXPENSIVE_RENDERING", + "AUDIO_STREAMING_LOW_LATENCY", "" ], "Type": "Property" @@ -262,19 +250,19 @@ "PowerHint": "INTERACTION", "Node": "CPUBigClusterMinFreq", "Duration": 0, - "Value": "825600" + "Value": "1132800" }, { "PowerHint": "INTERACTION", "Node": "CPULittleClusterMinFreq", "Duration": 0, - "Value": "576000" + "Value": "1209600" }, { "PowerHint": "INTERACTION", "Node": "TASchedtuneBoost", "Duration": 0, - "Value": "10" + "Value": "50" }, { "PowerHint": "INTERACTION", @@ -309,87 +297,93 @@ { "PowerHint": "LAUNCH", "Node": "SchedBoost", - "Duration": 3000, + "Duration": 5000, "Value": "1" }, { "PowerHint": "LAUNCH", "Node": "CPUBigClusterMaxFreq", - "Duration": 3000, + "Duration": 5000, "Value": "9999999" }, { "PowerHint": "LAUNCH", "Node": "CPUBigClusterMinFreq", - "Duration": 3000, + "Duration": 5000, "Value": "9999999" }, { "PowerHint": "LAUNCH", "Node": "CPULittleClusterMinFreq", - "Duration": 3000, + "Duration": 5000, "Value": "9999999" }, { "PowerHint": "LAUNCH", "Node": "PMQoSCpuDmaLatency", - "Duration": 3000, + "Duration": 5000, "Value": "67" }, { "PowerHint": "LAUNCH", "Node": "CPUBWHystTriggerCount", - "Duration": 3000, + "Duration": 5000, "Value": "0" }, { "PowerHint": "LAUNCH", "Node": "CPUBWHystLength", - "Duration": 3000, + "Duration": 5000, "Value": "0" }, { "PowerHint": "LAUNCH", "Node": "CPUBWHistMemory", - "Duration": 3000, + "Duration": 5000, "Value": "0" }, { "PowerHint": "LAUNCH", "Node": "CPUBWMinFreq", - "Duration": 3000, + "Duration": 5000, "Value": "6881" }, { "PowerHint": "LAUNCH", "Node": "GPUForceClkOn", - "Duration": 3000, + "Duration": 5000, "Value": "1" }, { "PowerHint": "LAUNCH", "Node": "GPUForceRailOn", - "Duration": 3000, + "Duration": 5000, "Value": "1" }, { "PowerHint": "LAUNCH", "Node": "GPUIdleTimer", - "Duration": 3000, + "Duration": 5000, "Value": "10000" }, { "PowerHint": "LAUNCH", "Node": "L3LittleClusterMinFreq", - "Duration": 3000, + "Duration": 5000, "Value": "1440000000" }, { "PowerHint": "LAUNCH", "Node": "L3BigClusterMinFreq", - "Duration": 3000, + "Duration": 5000, "Value": "1440000000" }, + { + "PowerHint": "CAMERA_LAUNCH", + "Node": "SchedBoost", + "Duration": 1000, + "Value": "1" + }, { "PowerHint": "CAMERA_LAUNCH", "Node": "CPUBigClusterMaxFreq", @@ -421,49 +415,31 @@ "Value": "67" }, { - "PowerHint": "CAMERA_STREAMING", - "Node": "PowerHALMainState", - "Duration": 0, - "Value": "CAMERA_STREAMING" - }, - { - "PowerHint": "CAMERA_STREAMING", + "PowerHint": "CAMERA_STREAMING_MID", "Node": "CPUBigClusterMaxFreq", "Duration": 0, "Value": "1996800" }, { - "PowerHint": "CAMERA_STREAMING_1080P", - "Node": "PowerHALMainState", - "Duration": 0, - "Value": "CAMERA_STREAMING_1080P" - }, - { - "PowerHint": "CAMERA_STREAMING_1080P", + "PowerHint": "CAMERA_STREAMING_HIGH", "Node": "CPUBigClusterMaxFreq", "Duration": 0, "Value": "1996800" }, { - "PowerHint": "CAMERA_STREAMING_1080P", + "PowerHint": "CAMERA_STREAMING_HIGH", "Node": "GPUMinFreq", "Duration": 0, "Value": "430000000" }, { - "PowerHint": "CAMERA_STREAMING_1080P", + "PowerHint": "CAMERA_STREAMING_HIGH", "Node": "GPUMaxFreq", "Duration": 0, "Value": "430000000" }, { - "PowerHint": "CAMERA_STREAMING_4K", - "Node": "PowerHALMainState", - "Duration": 0, - "Value": "CAMERA_STREAMING_4K" - }, - { - "PowerHint": "CAMERA_STREAMING_4K", + "PowerHint": "CAMERA_STREAMING_LOW", "Node": "CPUBigClusterMaxFreq", "Duration": 0, "Value": "1996800" @@ -499,46 +475,28 @@ "Value": "67" }, { - "PowerHint": "AUDIO_STREAMING", + "PowerHint": "AUDIO_LAUNCH", "Node": "CPUBigClusterMinFreq", "Duration": 2000, "Value": "1363200" }, { - "PowerHint": "AUDIO_STREAMING", + "PowerHint": "AUDIO_LAUNCH", "Node": "PMQoSCpuDmaLatency", "Duration": 2000, "Value": "67" }, { - "PowerHint": "AUDIO_LOW_LATENCY", + "PowerHint": "AUDIO_STREAMING_LOW_LATENCY", "Node": "PowerHALAudioState", "Duration": 0, - "Value": "AUDIO_LOW_LATENCY" + "Value": "AUDIO_STREAMING_LOW_LATENCY" }, { - "PowerHint": "AUDIO_LOW_LATENCY", + "PowerHint": "AUDIO_STREAMING_LOW_LATENCY", "Node": "PMQoSCpuDmaLatency", "Duration": 0, "Value": "67" - }, - { - "PowerHint": "EXPENSIVE_RENDERING", - "Node": "PowerHALRenderingState", - "Duration": 0, - "Value": "EXPENSIVE_RENDERING" - }, - { - "PowerHint": "EXPENSIVE_RENDERING", - "Node": "GPUMinFreq", - "Duration": 0, - "Value": "355000000" - }, - { - "PowerHint": "EXPENSIVE_RENDERING", - "Node": "GPUMaxFreq", - "Duration": 0, - "Value": "430000000" } ] } diff --git a/device.mk b/device.mk index 6d9ede6..3d4e702 100644 --- a/device.mk +++ b/device.mk @@ -108,8 +108,7 @@ PRODUCT_PACKAGES += \ # Power PRODUCT_PACKAGES += \ - android.hardware.power@1.3-service.lenovo-libperfmgr \ - android.hardware.power.stats@1.0-service.lenovo + android.hardware.power-service.lenovo PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/powerhint.json:$(TARGET_COPY_OUT_SYSTEM)/etc/powerhint.json @@ -123,6 +122,7 @@ PRODUCT_PACKAGES += \ # Soong namespaces PRODUCT_SOONG_NAMESPACES += \ $(LOCAL_PATH) \ + hardware/google/interfaces \ hardware/google/pixel # System properties diff --git a/framework_manifest.xml b/framework_manifest.xml index 1c213fd..4abca30 100644 --- a/framework_manifest.xml +++ b/framework_manifest.xml @@ -1,12 +1,11 @@ - - android.hardware.power.stats + + android.hardware.power + hwbinder + + + vendor.qti.hardware.perf hwbinder - 1.0 - - IPowerStats - default - vendor.lineage.livedisplay diff --git a/power-libperfmgr/Android.bp b/power-libperfmgr/Android.bp index ac2c9e7..6d750c6 100644 --- a/power-libperfmgr/Android.bp +++ b/power-libperfmgr/Android.bp @@ -1,44 +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. - cc_library_headers { name: "lenovo_power_headers", vendor_available: true, export_include_dirs: ["."], } -cc_binary { - name: "android.hardware.power@1.3-service.lenovo-libperfmgr", - relative_install_path: "hw", - vintf_fragments: ["android.hardware.power@1.3-service.lenovo.xml"], - init_rc: ["android.hardware.power@1.3-service.lenovo-libperfmgr.rc"], - srcs: ["service.cpp", "Power.cpp", "InteractionHandler.cpp"], - cflags: [ - "-Wall", - "-Werror", +cc_library { + name: "libdisppower-lenovo", + srcs: [ + "disp-power/DisplayLowPower.cpp", + "disp-power/InteractionHandler.cpp", ], - shared_libs: [ + shared_libs: [ "libbase", - "libhidlbase", - "liblog", - "libutils", "libcutils", - "android.hardware.power@1.0", - "android.hardware.power@1.1", - "android.hardware.power@1.2", - "android.hardware.power@1.3", + "liblog", "libperfmgr", + "libutils", + ], +} + +cc_binary { + name: "android.hardware.power-service.lenovo", + relative_install_path: "hw", + init_rc: ["aidl/android.hardware.power-service.lenovo.rc"], + vintf_fragments: ["aidl/android.hardware.power-service.lenovo.xml"], + shared_libs: [ + "android.hardware.power-ndk_platform", + "libbase", + "libcutils", + "liblog", + "libutils", + "libbinder_ndk", + "libdisppower-lenovo", + "libperfmgr", + "pixel-power-ext-ndk_platform", + ], + srcs: [ + "aidl/service.cpp", + "aidl/Power.cpp", + "aidl/PowerExt.cpp", ], } diff --git a/power-libperfmgr/Power.cpp b/power-libperfmgr/Power.cpp deleted file mode 100644 index a101231..0000000 --- a/power-libperfmgr/Power.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* - * 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 ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) -#define LOG_TAG "android.hardware.power@1.3-service.pixel-libperfmgr" - -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "Power.h" - -#ifndef TAP_TO_WAKE_NODE -#define TAP_TO_WAKE_NODE "/sys/class/touch/tp_dev/gesture_on" -#endif - -namespace android { -namespace hardware { -namespace power { -namespace V1_3 { -namespace implementation { - -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::power::V1_0::Feature; -using ::android::hardware::power::V1_0::Status; - -constexpr char kPowerHalStateProp[] = "vendor.powerhal.state"; -constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio"; -constexpr char kPowerHalInitProp[] = "vendor.powerhal.init"; -constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering"; -constexpr char kPowerHalConfigPath[] = "/system/etc/powerhint.json"; - -Power::Power() - : mHintManager(nullptr), - mInteractionHandler(nullptr), - mVRModeOn(false), - mSustainedPerfModeOn(false), - mCameraStreamingMode(false), - mReady(false) { - mInitThread = std::thread([this]() { - android::base::WaitForProperty(kPowerHalInitProp, "1"); - mHintManager = HintManager::GetFromJSON(kPowerHalConfigPath); - if (!mHintManager) { - LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath; - } - mInteractionHandler = std::make_unique(mHintManager); - mInteractionHandler->Init(); - std::string state = android::base::GetProperty(kPowerHalStateProp, ""); - if (state == "CAMERA_STREAMING") { - ALOGI("Initialize with CAMERA_STREAMING on"); - mHintManager->DoHint("CAMERA_STREAMING"); - mCameraStreamingMode = true; - } else if (state == "SUSTAINED_PERFORMANCE") { - ALOGI("Initialize with SUSTAINED_PERFORMANCE on"); - mHintManager->DoHint("SUSTAINED_PERFORMANCE"); - mSustainedPerfModeOn = true; - } else if (state == "VR_MODE") { - ALOGI("Initialize with VR_MODE on"); - mHintManager->DoHint("VR_MODE"); - mVRModeOn = true; - } else if (state == "VR_SUSTAINED_PERFORMANCE") { - ALOGI("Initialize with SUSTAINED_PERFORMANCE and VR_MODE on"); - mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); - mSustainedPerfModeOn = true; - mVRModeOn = true; - } else { - ALOGI("Initialize PowerHAL"); - } - - state = android::base::GetProperty(kPowerHalAudioProp, ""); - if (state == "AUDIO_LOW_LATENCY") { - ALOGI("Initialize with AUDIO_LOW_LATENCY on"); - mHintManager->DoHint("AUDIO_LOW_LATENCY"); - } - - state = android::base::GetProperty(kPowerHalRenderingProp, ""); - if (state == "EXPENSIVE_RENDERING") { - ALOGI("Initialize with EXPENSIVE_RENDERING on"); - mHintManager->DoHint("EXPENSIVE_RENDERING"); - } - // Now start to take powerhint - mReady.store(true); - ALOGI("PowerHAL ready to process hints"); - }); - mInitThread.detach(); -} - -// Methods from ::android::hardware::power::V1_0::IPower follow. -Return Power::setInteractive(bool /* interactive */) { - return Void(); -} - -Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { - if (!mReady) { - return Void(); - } - ATRACE_INT(android::hardware::power::V1_0::toString(hint).c_str(), data); - ALOGD_IF(hint != PowerHint_1_0::INTERACTION, "%s: %d", - android::hardware::power::V1_0::toString(hint).c_str(), static_cast(data)); - switch (hint) { - case PowerHint_1_0::INTERACTION: - if (mVRModeOn || mSustainedPerfModeOn) { - ALOGV("%s: ignoring due to other active perf hints", __func__); - } else { - mInteractionHandler->Acquire(data); - } - break; - case PowerHint_1_0::SUSTAINED_PERFORMANCE: - if (data && !mSustainedPerfModeOn) { - if (!mVRModeOn) { // Sustained mode only. - mHintManager->DoHint("SUSTAINED_PERFORMANCE"); - } else { // Sustained + VR mode. - mHintManager->EndHint("VR_MODE"); - mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); - } - mSustainedPerfModeOn = true; - } else if (!data && mSustainedPerfModeOn) { - mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE"); - mHintManager->EndHint("SUSTAINED_PERFORMANCE"); - if (mVRModeOn) { // Switch back to VR Mode. - mHintManager->DoHint("VR_MODE"); - } - mSustainedPerfModeOn = false; - } - break; - case PowerHint_1_0::VR_MODE: - if (data && !mVRModeOn) { - if (!mSustainedPerfModeOn) { // VR mode only. - mHintManager->DoHint("VR_MODE"); - } else { // Sustained + VR mode. - mHintManager->EndHint("SUSTAINED_PERFORMANCE"); - mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); - } - mVRModeOn = true; - } else if (!data && mVRModeOn) { - mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE"); - mHintManager->EndHint("VR_MODE"); - if (mSustainedPerfModeOn) { // Switch back to sustained Mode. - mHintManager->DoHint("SUSTAINED_PERFORMANCE"); - } - mVRModeOn = false; - } - break; - case PowerHint_1_0::LAUNCH: - if (mVRModeOn || mSustainedPerfModeOn) { - ALOGV("%s: ignoring due to other active perf hints", __func__); - } else { - if (data) { - // Hint until canceled - mHintManager->DoHint("LAUNCH"); - } else { - mHintManager->EndHint("LAUNCH"); - } - } - break; - default: - break; - } - return Void(); -} - -Return Power::setFeature(Feature feature, bool activate) { - switch (feature) { -#ifdef TAP_TO_WAKE_NODE - case Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE: - ::android::base::WriteStringToFile(activate ? "1" : "0", TAP_TO_WAKE_NODE); - break; -#endif - default: - break; - } - return Void(); -} - -Return Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) { - LOG(ERROR) << "getPlatformLowPowerStats not supported. Use IPowerStats HAL."; - _hidl_cb({}, Status::SUCCESS); - return Void(); -} - -// Methods from ::android::hardware::power::V1_1::IPower follow. -Return Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) { - LOG(ERROR) << "getSubsystemLowPowerStats not supported. Use IPowerStats HAL."; - _hidl_cb({}, Status::SUCCESS); - return Void(); -} - -Return Power::powerHintAsync(PowerHint_1_0 hint, int32_t data) { - // just call the normal power hint in this oneway function - return powerHint(hint, data); -} - -// Methods from ::android::hardware::power::V1_2::IPower follow. -Return Power::powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) { - if (!mReady) { - return Void(); - } - - ATRACE_INT(android::hardware::power::V1_2::toString(hint).c_str(), data); - ALOGD_IF(hint >= PowerHint_1_2::AUDIO_STREAMING, "%s: %d", - android::hardware::power::V1_2::toString(hint).c_str(), static_cast(data)); - - switch (hint) { - case PowerHint_1_2::AUDIO_LOW_LATENCY: - if (data) { - // Hint until canceled - mHintManager->DoHint("AUDIO_LOW_LATENCY"); - } else { - mHintManager->EndHint("AUDIO_LOW_LATENCY"); - } - break; - case PowerHint_1_2::AUDIO_STREAMING: - if (mVRModeOn || mSustainedPerfModeOn) { - ALOGV("%s: ignoring due to other active perf hints", __func__); - } else { - if (data) { - mHintManager->DoHint("AUDIO_STREAMING"); - } else { - mHintManager->EndHint("AUDIO_STREAMING"); - } - } - break; - case PowerHint_1_2::CAMERA_LAUNCH: - if (data > 0) { - mHintManager->DoHint("CAMERA_LAUNCH"); - } else if (data == 0) { - mHintManager->EndHint("CAMERA_LAUNCH"); - } else { - ALOGE("CAMERA LAUNCH INVALID DATA: %d", data); - } - break; - case PowerHint_1_2::CAMERA_STREAMING: { - if (data > 0) { - mHintManager->DoHint("CAMERA_STREAMING"); - mCameraStreamingMode = true; - } else { - mHintManager->EndHint("CAMERA_STREAMING"); - mCameraStreamingMode = false; - } - - const auto prop = mCameraStreamingMode - ? "CAMERA_STREAMING" - : ""; - if (!android::base::SetProperty(kPowerHalStateProp, prop)) { - ALOGE("%s: could set powerHAL state %s property", __func__, prop); - } - break; - } - case PowerHint_1_2::CAMERA_SHOT: - if (data > 0) { - mHintManager->DoHint("CAMERA_SHOT", std::chrono::milliseconds(data)); - } else if (data == 0) { - mHintManager->EndHint("CAMERA_SHOT"); - } else { - ALOGE("CAMERA SHOT INVALID DATA: %d", data); - } - break; - default: - return powerHint(static_cast(hint), data); - } - return Void(); -} - -// Methods from ::android::hardware::power::V1_3::IPower follow. -Return Power::powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) { - if (!mReady) { - return Void(); - } - - if (hint == PowerHint_1_3::EXPENSIVE_RENDERING) { - ATRACE_INT(android::hardware::power::V1_3::toString(hint).c_str(), data); - if (mVRModeOn || mSustainedPerfModeOn) { - ALOGV("%s: ignoring due to other active perf hints", __func__); - } else { - if (data > 0) { - mHintManager->DoHint("EXPENSIVE_RENDERING"); - } else { - mHintManager->EndHint("EXPENSIVE_RENDERING"); - } - } - } else { - return powerHintAsync_1_2(static_cast(hint), data); - } - return Void(); -} - -constexpr const char *boolToString(bool b) { - return b ? "true" : "false"; -} - -Return Power::debug(const hidl_handle &handle, const hidl_vec &) { - if (handle != nullptr && handle->numFds >= 1 && mReady) { - int fd = handle->data[0]; - - std::string buf(android::base::StringPrintf( - "HintManager Running: %s\n" - "VRMode: %s\n" - "CameraStreamingMode: %s\n" - "SustainedPerformanceMode: %s\n", - boolToString(mHintManager->IsRunning()), boolToString(mVRModeOn), - boolToString(mCameraStreamingMode), - boolToString(mSustainedPerfModeOn))); - // Dump nodes through libperfmgr - mHintManager->DumpToFd(fd); - if (!android::base::WriteStringToFd(buf, fd)) { - PLOG(ERROR) << "Failed to dump state to fd"; - } - fsync(fd); - } - return Void(); -} - -} // namespace implementation -} // namespace V1_3 -} // namespace power -} // namespace hardware -} // namespace android diff --git a/power-libperfmgr/Power.h b/power-libperfmgr/Power.h deleted file mode 100644 index 1acabdb..0000000 --- a/power-libperfmgr/Power.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 POWER_LIBPERFMGR_POWER_H_ -#define POWER_LIBPERFMGR_POWER_H_ - -#include -#include -#include - -#include -#include -#include -#include - -#include "InteractionHandler.h" - -namespace android { -namespace hardware { -namespace power { -namespace V1_3 { -namespace implementation { - -using ::InteractionHandler; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::power::V1_0::Feature; -using ::android::hardware::power::V1_3::IPower; -using PowerHint_1_0 = ::android::hardware::power::V1_0::PowerHint; -using PowerHint_1_2 = ::android::hardware::power::V1_2::PowerHint; -using PowerHint_1_3 = ::android::hardware::power::V1_3::PowerHint; -using ::android::perfmgr::HintManager; - -class Power : public IPower { - public: - // Methods from ::android::hardware::power::V1_0::IPower follow. - - Power(); - - Return setInteractive(bool /* interactive */) override; - Return powerHint(PowerHint_1_0 hint, int32_t data) override; - Return setFeature(Feature feature, bool activate) override; - Return getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) override; - - // Methods from ::android::hardware::power::V1_1::IPower follow. - Return getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) override; - Return powerHintAsync(PowerHint_1_0 hint, int32_t data) override; - - // Methods from ::android::hardware::power::V1_2::IPower follow. - Return powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) override; - - // Methods from ::android::hardware::power::V1_3::IPower follow. - Return powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. - Return debug(const hidl_handle &fd, const hidl_vec &args) override; - - private: - std::shared_ptr mHintManager; - std::unique_ptr mInteractionHandler; - std::atomic mVRModeOn; - std::atomic mSustainedPerfModeOn; - std::atomic mCameraStreamingMode; - std::atomic mReady; - std::thread mInitThread; -}; - -} // namespace implementation -} // namespace V1_3 -} // namespace power -} // namespace hardware -} // namespace android - -#endif // POWER_LIBPERFMGR_POWER_H_ diff --git a/power-libperfmgr/aidl/Power.cpp b/power-libperfmgr/aidl/Power.cpp new file mode 100644 index 0000000..d944cf4 --- /dev/null +++ b/power-libperfmgr/aidl/Power.cpp @@ -0,0 +1,256 @@ +/* + * 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. + */ + +#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) +#define LOG_TAG "android.hardware.power-service.pixel-libperfmgr" + +#include "Power.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "disp-power/DisplayLowPower.h" + +namespace aidl { +namespace google { +namespace hardware { +namespace power { +namespace impl { +namespace pixel { + +constexpr char kPowerHalStateProp[] = "vendor.powerhal.state"; +constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio"; +constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering"; + +Power::Power(std::shared_ptr hm, std::shared_ptr dlpw) + : mHintManager(hm), + mDisplayLowPower(dlpw), + mInteractionHandler(nullptr), + mVRModeOn(false), + mSustainedPerfModeOn(false) { + mInteractionHandler = std::make_unique(mHintManager); + mInteractionHandler->Init(); + + std::string state = ::android::base::GetProperty(kPowerHalStateProp, ""); + if (state == "SUSTAINED_PERFORMANCE") { + ALOGI("Initialize with SUSTAINED_PERFORMANCE on"); + mHintManager->DoHint("SUSTAINED_PERFORMANCE"); + mSustainedPerfModeOn = true; + } else if (state == "VR") { + ALOGI("Initialize with VR on"); + mHintManager->DoHint(state); + mVRModeOn = true; + } else if (state == "VR_SUSTAINED_PERFORMANCE") { + ALOGI("Initialize with SUSTAINED_PERFORMANCE and VR on"); + mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); + mSustainedPerfModeOn = true; + mVRModeOn = true; + } else { + ALOGI("Initialize PowerHAL"); + } + + state = ::android::base::GetProperty(kPowerHalAudioProp, ""); + if (state == "AUDIO_STREAMING_LOW_LATENCY") { + ALOGI("Initialize with AUDIO_LOW_LATENCY on"); + mHintManager->DoHint(state); + } + + state = ::android::base::GetProperty(kPowerHalRenderingProp, ""); + if (state == "EXPENSIVE_RENDERING") { + ALOGI("Initialize with EXPENSIVE_RENDERING on"); + mHintManager->DoHint("EXPENSIVE_RENDERING"); + } + + // Now start to take powerhint + ALOGI("PowerHAL ready to process hints"); +} + +ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) { + LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled; + ATRACE_INT(toString(type).c_str(), enabled); + switch (type) { + case Mode::LOW_POWER: + mDisplayLowPower->SetDisplayLowPower(enabled); + if (enabled) { + mHintManager->DoHint(toString(type)); + } else { + mHintManager->EndHint(toString(type)); + } + break; + case Mode::SUSTAINED_PERFORMANCE: + if (enabled && !mSustainedPerfModeOn) { + if (!mVRModeOn) { // Sustained mode only. + mHintManager->DoHint("SUSTAINED_PERFORMANCE"); + } else { // Sustained + VR mode. + mHintManager->EndHint("VR"); + mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); + } + mSustainedPerfModeOn = true; + } else if (!enabled && mSustainedPerfModeOn) { + mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE"); + mHintManager->EndHint("SUSTAINED_PERFORMANCE"); + if (mVRModeOn) { // Switch back to VR Mode. + mHintManager->DoHint("VR"); + } + mSustainedPerfModeOn = false; + } + break; + case Mode::VR: + if (enabled && !mVRModeOn) { + if (!mSustainedPerfModeOn) { // VR mode only. + mHintManager->DoHint("VR"); + } else { // Sustained + VR mode. + mHintManager->EndHint("SUSTAINED_PERFORMANCE"); + mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); + } + mVRModeOn = true; + } else if (!enabled && mVRModeOn) { + mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE"); + mHintManager->EndHint("VR"); + if (mSustainedPerfModeOn) { // Switch back to sustained Mode. + mHintManager->DoHint("SUSTAINED_PERFORMANCE"); + } + mVRModeOn = false; + } + break; + case Mode::LAUNCH: + if (mVRModeOn || mSustainedPerfModeOn) { + break; + } + [[fallthrough]]; + case Mode::DOUBLE_TAP_TO_WAKE: + [[fallthrough]]; + case Mode::FIXED_PERFORMANCE: + [[fallthrough]]; + case Mode::EXPENSIVE_RENDERING: + [[fallthrough]]; + case Mode::INTERACTIVE: + [[fallthrough]]; + case Mode::DEVICE_IDLE: + [[fallthrough]]; + case Mode::DISPLAY_INACTIVE: + [[fallthrough]]; + case Mode::AUDIO_STREAMING_LOW_LATENCY: + [[fallthrough]]; + case Mode::CAMERA_STREAMING_SECURE: + [[fallthrough]]; + case Mode::CAMERA_STREAMING_LOW: + [[fallthrough]]; + case Mode::CAMERA_STREAMING_MID: + [[fallthrough]]; + case Mode::CAMERA_STREAMING_HIGH: + [[fallthrough]]; + default: + if (enabled) { + mHintManager->DoHint(toString(type)); + } else { + mHintManager->EndHint(toString(type)); + } + break; + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) { + bool supported = mHintManager->IsHintSupported(toString(type)); + // LOW_POWER handled insides PowerHAL specifically + if (type == Mode::LOW_POWER) { + supported = true; + } + LOG(INFO) << "Power mode " << toString(type) << " isModeSupported: " << supported; + *_aidl_return = supported; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { + LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs; + ATRACE_INT(toString(type).c_str(), durationMs); + switch (type) { + case Boost::INTERACTION: + if (mVRModeOn || mSustainedPerfModeOn) { + break; + } + mInteractionHandler->Acquire(durationMs); + break; + case Boost::DISPLAY_UPDATE_IMMINENT: + [[fallthrough]]; + case Boost::ML_ACC: + [[fallthrough]]; + case Boost::AUDIO_LAUNCH: + [[fallthrough]]; + case Boost::CAMERA_LAUNCH: + [[fallthrough]]; + case Boost::CAMERA_SHOT: + [[fallthrough]]; + default: + if (mVRModeOn || mSustainedPerfModeOn) { + break; + } + if (durationMs > 0) { + mHintManager->DoHint(toString(type), std::chrono::milliseconds(durationMs)); + } else if (durationMs == 0) { + mHintManager->DoHint(toString(type)); + } else { + mHintManager->EndHint(toString(type)); + } + break; + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) { + bool supported = mHintManager->IsHintSupported(toString(type)); + LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported; + *_aidl_return = supported; + return ndk::ScopedAStatus::ok(); +} + +constexpr const char *boolToString(bool b) { + return b ? "true" : "false"; +} + +binder_status_t Power::dump(int fd, const char **, uint32_t) { + std::string buf(::android::base::StringPrintf( + "HintManager Running: %s\n" + "VRMode: %s\n" + "SustainedPerformanceMode: %s\n", + boolToString(mHintManager->IsRunning()), boolToString(mVRModeOn), + boolToString(mSustainedPerfModeOn))); + // Dump nodes through libperfmgr + mHintManager->DumpToFd(fd); + if (!::android::base::WriteStringToFd(buf, fd)) { + PLOG(ERROR) << "Failed to dump state to fd"; + } + fsync(fd); + return STATUS_OK; +} + +} // namespace pixel +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace google +} // namespace aidl diff --git a/power-libperfmgr/aidl/Power.h b/power-libperfmgr/aidl/Power.h new file mode 100644 index 0000000..8b90cb4 --- /dev/null +++ b/power-libperfmgr/aidl/Power.h @@ -0,0 +1,63 @@ +/* + * 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 +#include +#include + +#include +#include + +#include "disp-power/DisplayLowPower.h" +#include "disp-power/InteractionHandler.h" + +namespace aidl { +namespace google { +namespace hardware { +namespace power { +namespace impl { +namespace pixel { + +using ::InteractionHandler; +using ::aidl::android::hardware::power::Boost; +using ::aidl::android::hardware::power::Mode; +using ::android::perfmgr::HintManager; + +class Power : public ::aidl::android::hardware::power::BnPower { + public: + Power(std::shared_ptr hm, std::shared_ptr dlpw); + ndk::ScopedAStatus setMode(Mode type, bool enabled) override; + ndk::ScopedAStatus isModeSupported(Mode type, bool *_aidl_return) override; + ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override; + ndk::ScopedAStatus isBoostSupported(Boost type, bool *_aidl_return) override; + binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; + + private: + std::shared_ptr mHintManager; + std::shared_ptr mDisplayLowPower; + std::unique_ptr mInteractionHandler; + std::atomic mVRModeOn; + std::atomic mSustainedPerfModeOn; +}; + +} // namespace pixel +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace google +} // namespace aidl diff --git a/power-libperfmgr/aidl/PowerExt.cpp b/power-libperfmgr/aidl/PowerExt.cpp new file mode 100644 index 0000000..24e855d --- /dev/null +++ b/power-libperfmgr/aidl/PowerExt.cpp @@ -0,0 +1,87 @@ +/* + * 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. + */ + +#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) +#define LOG_TAG "android.hardware.power-service.pixel.ext-libperfmgr" + +#include "PowerExt.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace aidl { +namespace google { +namespace hardware { +namespace power { +namespace impl { +namespace pixel { + +ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) { + LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled; + ATRACE_INT(mode.c_str(), enabled); + + if (enabled) { + mHintManager->DoHint(mode); + } else { + mHintManager->EndHint(mode); + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) { + bool supported = mHintManager->IsHintSupported(mode); + LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported; + *_aidl_return = supported; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) { + LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs; + ATRACE_INT(boost.c_str(), durationMs); + + if (durationMs > 0) { + mHintManager->DoHint(boost, std::chrono::milliseconds(durationMs)); + } else if (durationMs == 0) { + mHintManager->DoHint(boost); + } else { + mHintManager->EndHint(boost); + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) { + bool supported = mHintManager->IsHintSupported(boost); + LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported; + *_aidl_return = supported; + return ndk::ScopedAStatus::ok(); +} + +} // namespace pixel +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace google +} // namespace aidl diff --git a/power-libperfmgr/aidl/PowerExt.h b/power-libperfmgr/aidl/PowerExt.h new file mode 100644 index 0000000..65cec2c --- /dev/null +++ b/power-libperfmgr/aidl/PowerExt.h @@ -0,0 +1,56 @@ +/* + * 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 +#include +#include + +#include +#include + +#include "disp-power/DisplayLowPower.h" + +namespace aidl { +namespace google { +namespace hardware { +namespace power { +namespace impl { +namespace pixel { + +using ::android::perfmgr::HintManager; + +class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt { + public: + PowerExt(std::shared_ptr hm, std::shared_ptr dlpw) + : mHintManager(hm), mDisplayLowPower(dlpw) {} + ndk::ScopedAStatus setMode(const std::string &mode, bool enabled) override; + ndk::ScopedAStatus isModeSupported(const std::string &mode, bool *_aidl_return) override; + ndk::ScopedAStatus setBoost(const std::string &boost, int32_t durationMs) override; + ndk::ScopedAStatus isBoostSupported(const std::string &boost, bool *_aidl_return) override; + + private: + std::shared_ptr mHintManager; + std::shared_ptr mDisplayLowPower; +}; + +} // namespace pixel +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace google +} // namespace aidl diff --git a/power-libperfmgr/aidl/android.hardware.power-service.lenovo.rc b/power-libperfmgr/aidl/android.hardware.power-service.lenovo.rc new file mode 100644 index 0000000..480a07c --- /dev/null +++ b/power-libperfmgr/aidl/android.hardware.power-service.lenovo.rc @@ -0,0 +1,17 @@ +service vendor.power-hal-aidl /system/bin/hw/android.hardware.power-service.lenovo + class hal + user root + group system + priority -20 + +# restart powerHAL when framework died +on property:init.svc.zygote=restarting && property:vendor.powerhal.state=* + setprop vendor.powerhal.state "" + setprop vendor.powerhal.audio "" + setprop vendor.powerhal.rendering "" + restart vendor.power-hal-aidl + +# restart powerHAL when audioHAL died +on property:init.svc.vendor.audio-hal-2-0=restarting && property:vendor.powerhal.audio=AUDIO_STREAMING_LOW_LATENCY + setprop vendor.powerhal.audio "" + restart vendor.power-hal-aidl diff --git a/power-libperfmgr/aidl/android.hardware.power-service.lenovo.xml b/power-libperfmgr/aidl/android.hardware.power-service.lenovo.xml new file mode 100644 index 0000000..4c75d15 --- /dev/null +++ b/power-libperfmgr/aidl/android.hardware.power-service.lenovo.xml @@ -0,0 +1,6 @@ + + + android.hardware.power + IPower/default + + diff --git a/power-libperfmgr/aidl/service.cpp b/power-libperfmgr/aidl/service.cpp new file mode 100644 index 0000000..9d12339 --- /dev/null +++ b/power-libperfmgr/aidl/service.cpp @@ -0,0 +1,78 @@ +/* + * 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. + */ + +#define LOG_TAG "android.hardware.power-service.pixel-libperfmgr" + +#include + +#include +#include +#include +#include + +#include "Power.h" +#include "PowerExt.h" +#include "disp-power/DisplayLowPower.h" + +using aidl::google::hardware::power::impl::pixel::Power; +using aidl::google::hardware::power::impl::pixel::PowerExt; +using ::android::perfmgr::HintManager; + +constexpr char kPowerHalConfigPath[] = "/system/etc/powerhint.json"; +constexpr char kPowerHalInitProp[] = "vendor.powerhal.init"; + +int main() { + LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is starting."; + + // Parse config but do not start the looper + std::shared_ptr hm = HintManager::GetFromJSON(kPowerHalConfigPath, false); + if (!hm) { + LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath; + } + + std::shared_ptr dlpw = std::make_shared(); + + // single thread + ABinderProcess_setThreadPoolMaxThreadCount(0); + + // core service + std::shared_ptr pw = ndk::SharedRefBase::make(hm, dlpw); + ndk::SpAIBinder pwBinder = pw->asBinder(); + + // extension service + std::shared_ptr pwExt = ndk::SharedRefBase::make(hm, dlpw); + + // attach the extension to the same binder we will be registering + CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get())); + + const std::string instance = std::string() + Power::descriptor + "/default"; + binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str()); + CHECK(status == STATUS_OK); + LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is started."; + + std::thread initThread([&]() { + ::android::base::WaitForProperty(kPowerHalInitProp, "1"); + hm->Start(); + dlpw->Init(); + }); + initThread.detach(); + + ABinderProcess_joinThreadPool(); + + // should not reach + LOG(ERROR) << "Pixel Power HAL AIDL Service with Extension just died."; + return EXIT_FAILURE; +} diff --git a/power-libperfmgr/android.hardware.power@1.3-service.lenovo-libperfmgr.rc b/power-libperfmgr/android.hardware.power@1.3-service.lenovo-libperfmgr.rc deleted file mode 100644 index 3a13b25..0000000 --- a/power-libperfmgr/android.hardware.power@1.3-service.lenovo-libperfmgr.rc +++ /dev/null @@ -1,16 +0,0 @@ -service vendor.power-hal-1-3 /system/bin/hw/android.hardware.power@1.3-service.lenovo-libperfmgr - class hal - user root - group system - priority -20 - interface android.hardware.power@1.0::IPower default - interface android.hardware.power@1.1::IPower default - interface android.hardware.power@1.2::IPower default - interface android.hardware.power@1.3::IPower default - -# restart powerHAL when framework died -on property:init.svc.zygote=restarting && property:vendor.powerhal.state=* - setprop vendor.powerhal.state "" - setprop vendor.powerhal.audio "" - setprop vendor.powerhal.rendering "" - restart vendor.power-hal-1-3 diff --git a/power-libperfmgr/android.hardware.power@1.3-service.lenovo.xml b/power-libperfmgr/android.hardware.power@1.3-service.lenovo.xml deleted file mode 100644 index 1dafea0..0000000 --- a/power-libperfmgr/android.hardware.power@1.3-service.lenovo.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - android.hardware.power - hwbinder - 1.3 - - IPower - default - - - diff --git a/power-libperfmgr/disp-power/DisplayLowPower.cpp b/power-libperfmgr/disp-power/DisplayLowPower.cpp new file mode 100644 index 0000000..d38972a --- /dev/null +++ b/power-libperfmgr/disp-power/DisplayLowPower.cpp @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#define LOG_TAG "android.hardware.power@-service.pixel-libperfmgr" + +#include +#include + +#include +#include + +#include "DisplayLowPower.h" + +DisplayLowPower::DisplayLowPower() : mFossStatus(false) {} + +void DisplayLowPower::Init() { + ConnectPpsDaemon(); +} + +void DisplayLowPower::SetDisplayLowPower(bool enable) { + SetFoss(enable); +} + +void DisplayLowPower::ConnectPpsDaemon() { + constexpr const char kPpsDaemon[] = "pps"; + + mPpsSocket.reset( + socket_local_client(kPpsDaemon, ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM)); + if (mPpsSocket.get() < 0) { + ALOGW("Connecting to PPS daemon failed (%s)", strerror(errno)); + } +} + +int DisplayLowPower::SendPpsCommand(const std::string_view cmd) { + if (TEMP_FAILURE_RETRY(write(mPpsSocket.get(), cmd.data(), cmd.size())) < 0) { + ALOGE("Failed to send pps command '%s' over socket (%s)", cmd.data(), strerror(errno)); + return -1; + } + + return 0; +} + +void DisplayLowPower::SetFoss(bool enable) { + if (mPpsSocket.get() < 0 || mFossStatus == enable) { + return; + } + + ALOGI("%s foss", (enable) ? "Enable" : "Disable"); + + std::string_view foss_cmd; + if (enable) { + foss_cmd = "foss:on"; + } else { + foss_cmd = "foss:off"; + } + + if (!SendPpsCommand(foss_cmd)) { + mFossStatus = enable; + } +} diff --git a/power-libperfmgr/disp-power/DisplayLowPower.h b/power-libperfmgr/disp-power/DisplayLowPower.h new file mode 100644 index 0000000..c0d6c33 --- /dev/null +++ b/power-libperfmgr/disp-power/DisplayLowPower.h @@ -0,0 +1,37 @@ +/* + * 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 + +#include + +class DisplayLowPower { + public: + DisplayLowPower(); + ~DisplayLowPower() {} + void Init(); + void SetDisplayLowPower(bool enable); + + private: + void ConnectPpsDaemon(); + int SendPpsCommand(const std::string_view cmd); + void SetFoss(bool enable); + + android::base::unique_fd mPpsSocket; + bool mFossStatus; +}; diff --git a/power-libperfmgr/InteractionHandler.cpp b/power-libperfmgr/disp-power/InteractionHandler.cpp similarity index 99% rename from power-libperfmgr/InteractionHandler.cpp rename to power-libperfmgr/disp-power/InteractionHandler.cpp index da6a917..1826958 100644 --- a/power-libperfmgr/InteractionHandler.cpp +++ b/power-libperfmgr/disp-power/InteractionHandler.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "android.hardware.power@1.3-service.pixel-libperfmgr" +#define LOG_TAG "android.hardware.power@-service.pixel-libperfmgr" #define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) #include diff --git a/power-libperfmgr/InteractionHandler.h b/power-libperfmgr/disp-power/InteractionHandler.h similarity index 100% rename from power-libperfmgr/InteractionHandler.h rename to power-libperfmgr/disp-power/InteractionHandler.h diff --git a/power-libperfmgr/service.cpp b/power-libperfmgr/service.cpp deleted file mode 100644 index 7bcc907..0000000 --- a/power-libperfmgr/service.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.power@1.3-service.pixel-libperfmgr" - -#include -#include - -#include "Power.h" - -using android::OK; -using android::sp; -using android::status_t; - -// libhwbinder: -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; - -// Generated HIDL files -using android::hardware::power::V1_3::IPower; -using android::hardware::power::V1_3::implementation::Power; - -int main(int /* argc */, char ** /* argv */) { - ALOGI("Power HAL Service 1.3 for Pixel is starting."); - - android::sp service = new Power(); - if (service == nullptr) { - ALOGE("Can not create an instance of Power HAL Iface, exiting."); - return 1; - } - android::hardware::setMinSchedulerPolicy(service, SCHED_NORMAL, -20); - configureRpcThreadpool(1, true /*callerWillJoin*/); - - status_t status = service->registerAsService(); - if (status != OK) { - ALOGE("Could not register service for Power HAL Iface (%d), exiting.", status); - return 1; - } - - ALOGI("Power Service is ready"); - joinRpcThreadpool(); - - // In normal operation, we don't expect the thread pool to exit - ALOGE("Power Service is shutting down"); - return 1; -} diff --git a/powerstats/Android.bp b/powerstats/Android.bp deleted file mode 100644 index a87b263..0000000 --- a/powerstats/Android.bp +++ /dev/null @@ -1,38 +0,0 @@ -// -// 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. -cc_binary { - name: "android.hardware.power.stats@1.0-service.lenovo", - relative_install_path: "hw", - init_rc: ["android.hardware.power.stats@1.0-service.lenovo.rc"], - srcs: ["service.cpp"], - cflags: [ - "-Wall", - "-Werror", - ], - static_libs: [ - "libpixelpowerstats", - ], - shared_libs: [ - "libbase", - "libcutils", - "libhidlbase", - "libfmq", - "liblog", - "libutils", - "android.hardware.power.stats@1.0", - "pixelpowerstats_provider_aidl_interface-cpp", - "libbinder", - ], -} diff --git a/powerstats/android.hardware.power.stats@1.0-service.lenovo.rc b/powerstats/android.hardware.power.stats@1.0-service.lenovo.rc deleted file mode 100644 index be081b0..0000000 --- a/powerstats/android.hardware.power.stats@1.0-service.lenovo.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.power.stats-hal-1-0 /system/bin/hw/android.hardware.power.stats@1.0-service.lenovo - class hal - user system - group system diff --git a/powerstats/service.cpp b/powerstats/service.cpp deleted file mode 100644 index 2e43607..0000000 --- a/powerstats/service.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.power.stats@1.0-service.pixel" - -#include -#include -#include -#include - -#include -#include -#include - -using android::OK; -using android::sp; -using android::status_t; - -// libhwbinder: -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; - -// Generated HIDL files -using android::hardware::power::stats::V1_0::IPowerStats; -using android::hardware::power::stats::V1_0::PowerEntityInfo; -using android::hardware::power::stats::V1_0::PowerEntityStateSpace; -using android::hardware::power::stats::V1_0::PowerEntityType; -using android::hardware::power::stats::V1_0::implementation::PowerStats; - -// Pixel specific -using android::hardware::google::pixel::powerstats::AidlStateResidencyDataProvider; -using android::hardware::google::pixel::powerstats::GenericStateResidencyDataProvider; -using android::hardware::google::pixel::powerstats::PowerEntityConfig; -using android::hardware::google::pixel::powerstats::StateResidencyConfig; - -int main(int /* argc */, char ** /* argv */) { - ALOGE("power.stats service 1.0 is starting."); - - PowerStats *service = new PowerStats(); - - // Add power entities related to rpmh - const uint64_t RPM_CLK = 19200; // RPM runs at 19.2Mhz. Divide by 19200 for msec - std::function rpmConvertToMs = [](uint64_t a) { return a / RPM_CLK; }; - std::vector rpmStateResidencyConfigs = { - {.name = "Sleep", - .entryCountSupported = true, - .entryCountPrefix = "Sleep Count:", - .totalTimeSupported = true, - .totalTimePrefix = "Sleep Accumulated Duration:", - .totalTimeTransform = rpmConvertToMs, - .lastEntrySupported = true, - .lastEntryPrefix = "Sleep Last Entered At:", - .lastEntryTransform = rpmConvertToMs}}; - - sp rpmSdp = - new GenericStateResidencyDataProvider("/sys/power/rpmh_stats/master_stats"); - - uint32_t apssId = service->addPowerEntity("APSS", PowerEntityType::SUBSYSTEM); - rpmSdp->addEntity(apssId, PowerEntityConfig("APSS", rpmStateResidencyConfigs)); - - uint32_t mpssId = service->addPowerEntity("MPSS", PowerEntityType::SUBSYSTEM); - rpmSdp->addEntity(mpssId, PowerEntityConfig("MPSS", rpmStateResidencyConfigs)); - - uint32_t adspId = service->addPowerEntity("ADSP", PowerEntityType::SUBSYSTEM); - rpmSdp->addEntity(adspId, PowerEntityConfig("ADSP", rpmStateResidencyConfigs)); - - uint32_t cdspId = service->addPowerEntity("CDSP", PowerEntityType::SUBSYSTEM); - rpmSdp->addEntity(cdspId, PowerEntityConfig("CDSP", rpmStateResidencyConfigs)); - - service->addStateResidencyDataProvider(rpmSdp); - - // Add SoC power entity - std::vector socStateResidencyConfigs = { - {.name = "AOSD", - .header = "RPM Mode:aosd", - .entryCountSupported = true, - .entryCountPrefix = "count:", - .totalTimeSupported = true, - .totalTimePrefix = "actual last sleep(msec):", - .lastEntrySupported = false}, - {.name = "CXSD", - .header = "RPM Mode:cxsd", - .entryCountSupported = true, - .entryCountPrefix = "count:", - .totalTimeSupported = true, - .totalTimePrefix = "actual last sleep(msec):", - .lastEntrySupported = false}}; - - sp socSdp = - new GenericStateResidencyDataProvider("/sys/power/system_sleep/stats"); - - uint32_t socId = service->addPowerEntity("SoC", PowerEntityType::POWER_DOMAIN); - socSdp->addEntity(socId, PowerEntityConfig(socStateResidencyConfigs)); - - service->addStateResidencyDataProvider(socSdp); - - // Add Power Entities that require the Aidl data provider - sp aidlSdp = new AidlStateResidencyDataProvider(); - uint32_t citadelId = service->addPowerEntity("Citadel", PowerEntityType::SUBSYSTEM); - aidlSdp->addEntity(citadelId, "Citadel", {"Last-Reset", "Active", "Deep-Sleep"}); - - auto serviceStatus = android::defaultServiceManager()->addService( - android::String16("power.stats-vendor"), aidlSdp); - if (serviceStatus != android::OK) { - ALOGE("Unable to register power.stats-vendor service %d", serviceStatus); - return 1; - } - sp ps{android::ProcessState::self()}; // Create non-HW binder threadpool - ps->startThreadPool(); - - service->addStateResidencyDataProvider(aidlSdp); - - // Configure the threadpool - configureRpcThreadpool(1, true /*callerWillJoin*/); - - status_t status = service->registerAsService(); - if (status != OK) { - ALOGE("Could not register service for power.stats HAL Iface (%d), exiting.", status); - return 1; - } - - ALOGI("power.stats service is ready"); - joinRpcThreadpool(); - - // In normal operation, we don't expect the thread pool to exit - ALOGE("power.stats service is shutting down"); - return 1; -} diff --git a/sepolicy/private/file.te b/sepolicy/private/file.te index fe38e7e..ffab6d3 100644 --- a/sepolicy/private/file.te +++ b/sepolicy/private/file.te @@ -10,7 +10,6 @@ type sysfs_graphics, sysfs_type, fs_type; type sysfs_devfreq, sysfs_type, fs_type; type sysfs_kgsl, sysfs_type, fs_type; type sysfs_scsi_devices, sysfs_type, fs_type; -type sysfs_power_stats, sysfs_type, fs_type; type debugfs_wlan, debugfs_type, fs_type; type debugfs_sched_features, debugfs_type, fs_type; type proc_sysctl_schedboost, proc_type, fs_type; diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts index 91dcd7a..764750a 100644 --- a/sepolicy/private/file_contexts +++ b/sepolicy/private/file_contexts @@ -8,8 +8,7 @@ /persist(/.*)? u:object_r:persist_file:s0 # HALs -/system/bin/hw/android\.hardware\.power@1\.3-service\.lenovo-libperfmgr u:object_r:hal_power_pixel_exec:s0 -/system/bin/hw/android\.hardware\.power\.stats@1\.0-service\.lenovo u:object_r:hal_powerstats_exec:s0 +/system/bin/hw/android\.hardware\.power-service\.lenovo u:object_r:hal_power_pixel_exec:s0 /system/bin/hw/lineage\.livedisplay@2\.0-service-sdm u:object_r:shal_livedisplay_default_exec:s0 /(product|system/product)/vendor_overlay/[0-9]+/bin/hw/android\.hardware\.light@2\.0-service u:object_r:hal_light_default_exec:s0 diff --git a/sepolicy/private/genfs_contexts b/sepolicy/private/genfs_contexts index 95f4fba..0e64cd6 100644 --- a/sepolicy/private/genfs_contexts +++ b/sepolicy/private/genfs_contexts @@ -9,7 +9,6 @@ genfscon sysfs /devices/platform/soc/1d84000.ufshc/clkgate_enable genfscon sysfs /devices/platform/soc/1d84000.ufshc/hibern8_on_idle_enable u:object_r:sysfs_scsi_devices:s0 genfscon sysfs /power/rpmh_stats/master_stats u:object_r:sysfs_rpm:s0 -genfscon sysfs /kernel/wlan/power_stats u:object_r:sysfs_power_stats:s0 genfscon sysfs /power/system_sleep/stats u:object_r:sysfs_system_sleep_stats:s0 genfscon proc /sys/kernel/sched_boost u:object_r:proc_sysctl_schedboost:s0 diff --git a/sepolicy/private/hal_power_pixel.te b/sepolicy/private/hal_power_pixel.te index 7ea2b06..4ea3867 100644 --- a/sepolicy/private/hal_power_pixel.te +++ b/sepolicy/private/hal_power_pixel.te @@ -20,7 +20,6 @@ allow hal_power_pixel sysfs_graphics:file r_file_perms; allow hal_power_pixel sysfs_rpm:file r_file_perms; allow hal_power_pixel sysfs_system_sleep_stats:file r_file_perms; -allow hal_power_pixel sysfs_power_stats:file r_file_perms; r_dir_file(hal_power, sysfs_tp) allow hal_power_pixel sysfs_tp:file write; diff --git a/sepolicy/private/hal_powerstats.te b/sepolicy/private/hal_powerstats.te deleted file mode 100644 index dfb1db0..0000000 --- a/sepolicy/private/hal_powerstats.te +++ /dev/null @@ -1,19 +0,0 @@ -type hal_powerstats, domain; -type hal_powerstats_exec, system_file_type, exec_type, file_type; -init_daemon_domain(hal_powerstats) - -allow hal_powerstats sysfs_rpm:file r_file_perms; -allow hal_powerstats sysfs_system_sleep_stats:file r_file_perms; -allow hal_powerstats sysfs_power_stats:file r_file_perms; - -allow hal_powerstats default_android_service:service_manager add; -allow hal_powerstats hal_power_stats_hwservice:hwservice_manager { add find }; -allow hal_powerstats hidl_base_hwservice:hwservice_manager add; -get_prop(hal_powerstats, hwservicemanager_prop) - -binder_call(hal_powerstats, servicemanager) -binder_call(hal_powerstats, hwservicemanager) -binder_call(hal_powerstats, system_server) -allow hal_powerstats binder_device:chr_file rw_file_perms; - -allow servicemanager hal_powerstats:binder call; diff --git a/sepolicy/private/system_server.te b/sepolicy/private/system_server.te index 4758f6c..ab50373 100644 --- a/sepolicy/private/system_server.te +++ b/sepolicy/private/system_server.te @@ -1,3 +1,2 @@ get_prop(system_server, vendor_camera_prop) allow system_server hal_power_pixel:binder call; -allow system_server hal_powerstats:binder call;