diff --git a/power-libperfmgr/Power.cpp b/power-libperfmgr/Power.cpp index 0b05518f..6d4e374d 100644 --- a/power-libperfmgr/Power.cpp +++ b/power-libperfmgr/Power.cpp @@ -54,6 +54,29 @@ Power::Power() : mSustainedPerfModeOn(false), mEncoderModeOn(false) { mInteractionHandler.Init(); + + std::string state = android::base::GetProperty(kPowerHalStateProp, ""); + if (state == "VIDEO_ENCODE") { + ALOGI("Initialize with VIDEO_ENCODE on"); + mHintManager->DoHint("VIDEO_ENCODE"); + mEncoderModeOn = 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 with default setting"); + } + } // Methods from ::android::hardware::power::V1_0::IPower follow. @@ -84,11 +107,17 @@ Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { ATRACE_INT("video_encode_lock", 1); mHintManager->DoHint("VIDEO_ENCODE"); ALOGD("VIDEO_ENCODE ON"); + if (!android::base::SetProperty(kPowerHalStateProp, "VIDEO_ENCODE")) { + ALOGE("%s: could not set powerHAL state property to VIDEO_ENCODE", __func__); + } mEncoderModeOn = true; } else { ATRACE_INT("video_encode_lock", 0); mHintManager->EndHint("VIDEO_ENCODE"); ALOGD("VIDEO_ENCODE OFF"); + if (!android::base::SetProperty(kPowerHalStateProp, "")) { + ALOGE("%s: could not clear powerHAL state property", __func__); + } mEncoderModeOn = false; } } @@ -99,9 +128,15 @@ Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { ALOGD("SUSTAINED_PERFORMANCE ON"); if (!mVRModeOn) { // Sustained mode only. mHintManager->DoHint("SUSTAINED_PERFORMANCE"); + if (!android::base::SetProperty(kPowerHalStateProp, "SUSTAINED_PERFORMANCE")) { + ALOGE("%s: could not set powerHAL state property to SUSTAINED_PERFORMANCE", __func__); + } } else { // Sustained + VR mode. mHintManager->EndHint("VR_MODE"); mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); + if (!android::base::SetProperty(kPowerHalStateProp, "VR_SUSTAINED_PERFORMANCE")) { + ALOGE("%s: could not set powerHAL state property to VR_SUSTAINED_PERFORMANCE", __func__); + } } mSustainedPerfModeOn = true; } else if (!data && mSustainedPerfModeOn) { @@ -110,6 +145,13 @@ Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { mHintManager->EndHint("SUSTAINED_PERFORMANCE"); if (mVRModeOn) { // Switch back to VR Mode. mHintManager->DoHint("VR_MODE"); + if (!android::base::SetProperty(kPowerHalStateProp, "VR_MODE")) { + ALOGE("%s: could not set powerHAL state property to VR_MODE", __func__); + } + } else { + if (!android::base::SetProperty(kPowerHalStateProp, "")) { + ALOGE("%s: could not clear powerHAL state property", __func__); + } } mSustainedPerfModeOn = false; } @@ -119,9 +161,15 @@ Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { ALOGD("VR_MODE ON"); if (!mSustainedPerfModeOn) { // VR mode only. mHintManager->DoHint("VR_MODE"); + if (!android::base::SetProperty(kPowerHalStateProp, "VR_MODE")) { + ALOGE("%s: could not set powerHAL state property to VR_MODE", __func__); + } } else { // Sustained + VR mode. mHintManager->EndHint("SUSTAINED_PERFORMANCE"); mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); + if (!android::base::SetProperty(kPowerHalStateProp, "VR_SUSTAINED_PERFORMANCE")) { + ALOGE("%s: could not set powerHAL state property to VR_SUSTAINED_PERFORMANCE", __func__); + } } mVRModeOn = true; } else if (!data && mVRModeOn) { @@ -130,6 +178,13 @@ Return Power::powerHint(PowerHint_1_0 hint, int32_t data) { mHintManager->EndHint("VR_MODE"); if (mSustainedPerfModeOn) { // Switch back to sustained Mode. mHintManager->DoHint("SUSTAINED_PERFORMANCE"); + if (!android::base::SetProperty(kPowerHalStateProp, "SUSTAINED_PERFORMANCE")) { + ALOGE("%s: could not set powerHAL state property to SUSTAINED_PERFORMANCE", __func__); + } + } else { + if (!android::base::SetProperty(kPowerHalStateProp, "")) { + ALOGE("%s: could not clear powerHAL state property", __func__); + } } mVRModeOn = false; } diff --git a/power-libperfmgr/Power.h b/power-libperfmgr/Power.h index 30409708..1b301c8c 100644 --- a/power-libperfmgr/Power.h +++ b/power-libperfmgr/Power.h @@ -41,6 +41,8 @@ using PowerHint_1_0 = ::android::hardware::power::V1_0::PowerHint; using PowerHint_1_2 = ::android::hardware::power::V1_2::PowerHint; using ::android::perfmgr::HintManager; +constexpr char kPowerHalStateProp[] = "vendor.powerhal.state"; + struct Power : public IPower { // Methods from ::android::hardware::power::V1_0::IPower follow. diff --git a/power-libperfmgr/android.hardware.power@1.2-service.wahoo-libperfmgr.rc b/power-libperfmgr/android.hardware.power@1.2-service.wahoo-libperfmgr.rc index 65c43b67..06df36ab 100644 --- a/power-libperfmgr/android.hardware.power@1.2-service.wahoo-libperfmgr.rc +++ b/power-libperfmgr/android.hardware.power@1.2-service.wahoo-libperfmgr.rc @@ -2,3 +2,13 @@ service vendor.power-hal-1-2 /vendor/bin/hw/android.hardware.power@1.2-service.w class hal user system group system + +# restart powerHAL when framework died +on property:init.svc.zygote=restarting + setprop vendor.powerhal.state 0 + restart vendor.power-hal-1-2 + +# restart powerHAL when cameraHAL died +on property:init.svc.vendor.camera-provider-2-4=restarting && property:vendor.powerhal.state=VIDEO_ENCODE + setprop vendor.powerhal.state 0 + restart vendor.power-hal-1-2 diff --git a/power-libperfmgr/service.cpp b/power-libperfmgr/service.cpp index 77fb1390..c128f95d 100644 --- a/power-libperfmgr/service.cpp +++ b/power-libperfmgr/service.cpp @@ -33,35 +33,27 @@ using android::hardware::joinRpcThreadpool; using android::hardware::power::V1_2::IPower; using android::hardware::power::V1_2::implementation::Power; -int main() { +int main(int /* argc */, char** /* argv */) { + ALOGI("Power HAL Service 1.2 for Wahoo is starting"); - status_t status; - android::sp service = nullptr; - - ALOGI("Power HAL Service 1.2 for Wahoo is starting."); - - service = new Power(); + android::sp service = new Power(); if (service == nullptr) { ALOGE("Can not create an instance of Power HAL Iface, exiting."); - - goto shutdown; + return 1; } configureRpcThreadpool(1, true /*callerWillJoin*/); - status = service->registerAsService(); + status_t status = service->registerAsService(); if (status != OK) { - ALOGE("Could not register service for Power HAL Iface (%d).", status); - goto shutdown; + ALOGE("Could not register service for Power HAL Iface (%d), exiting.", status); + return 1; } ALOGI("Power Service is ready"); joinRpcThreadpool(); - //Should not pass this line -shutdown: // In normal operation, we don't expect the thread pool to exit - ALOGE("Power Service is shutting down"); return 1; } diff --git a/sepolicy/vendor/hal_power_default.te b/sepolicy/vendor/hal_power_default.te index 3794e32b..48009432 100644 --- a/sepolicy/vendor/hal_power_default.te +++ b/sepolicy/vendor/hal_power_default.te @@ -11,3 +11,6 @@ allow hal_power_default sysfs_msm_subsys:dir search; allow hal_power_default sysfs_msm_subsys:file w_file_perms; allow hal_power_default sysfs_devices_system_cpu:file w_file_perms; allow hal_power_default latency_device:chr_file w_file_perms; + +# To get/set powerhal state property +set_prop(hal_power_default, power_prop) diff --git a/sepolicy/vendor/property.te b/sepolicy/vendor/property.te index 9f38fab0..30822410 100644 --- a/sepolicy/vendor/property.te +++ b/sepolicy/vendor/property.te @@ -15,3 +15,4 @@ type tel_mon_prop, property_type; type sys_time_prop, property_type; type atfwd_start_prop, property_type; type bluetooth_log_prop, property_type; +type power_prop, property_type; diff --git a/sepolicy/vendor/property_contexts b/sepolicy/vendor/property_contexts index d698bf31..bce1fda4 100644 --- a/sepolicy/vendor/property_contexts +++ b/sepolicy/vendor/property_contexts @@ -24,3 +24,4 @@ persist.radio.enable_tel_mon u:object_r:tel_mon_prop:s0 sys.time.set u:object_r:sys_time_prop:s0 persist.radio.atfwd.start u:object_r:atfwd_start_prop:s0 sys.logger.bluetooth u:object_r:bluetooth_log_prop:s0 +vendor.powerhal.state u:object_r:power_prop:s0