wahoo: power: Add hint state into PowerHAL in case of restart

PowerHAL should remember the long-lasting hint when it (re)starts,
in case it crashed/killed. Also when clint crashed, the long-lasting
hint should be cancelled.

This CL adds a property for PowerHAL to store its long-lasting hint,
and uses init to clear the property and restart PowerHAL when client
died.


Bug: 67648152
Test: kill cameraHAL, powerHAL, system-server
Change-Id: I6b2cae3c2228da00bcb97a3befacf9ab045eeba8
This commit is contained in:
Wei Wang
2018-01-08 23:25:05 -08:00
parent 4c69ba7dda
commit 1c36565762
7 changed files with 79 additions and 15 deletions

View File

@@ -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<void> 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<void> 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<void> 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<void> 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<void> 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;
}

View File

@@ -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.

View File

@@ -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

View File

@@ -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<IPower> service = nullptr;
ALOGI("Power HAL Service 1.2 for Wahoo is starting.");
service = new Power();
android::sp<IPower> 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;
}

View File

@@ -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)

View File

@@ -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;

View File

@@ -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