Loading services/core/jni/com_android_server_power_PowerManagerService.cpp +90 −71 Original line number Diff line number Diff line Loading @@ -178,58 +178,13 @@ bool processPowerHalReturn(bool isOk, const char* functionName) { return isOk; } static void sendPowerHint(PowerHint hintId, uint32_t data) { std::unique_lock<std::mutex> lock(gPowerHalMutex); switch (connectPowerHalLocked()) { case HalVersion::NONE: return; case HalVersion::HIDL_1_0: { sp<IPowerV1_0> handle = gPowerHalHidlV1_0_; lock.unlock(); auto ret = handle->powerHint(hintId, data); processPowerHalReturn(ret.isOk(), "powerHint"); break; } case HalVersion::HIDL_1_1: { sp<IPowerV1_1> handle = gPowerHalHidlV1_1_; lock.unlock(); auto ret = handle->powerHintAsync(hintId, data); processPowerHalReturn(ret.isOk(), "powerHintAsync"); break; } case HalVersion::AIDL: { if (hintId == PowerHint::INTERACTION) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); auto ret = handle->setBoost(Boost::INTERACTION, data); processPowerHalReturn(ret.isOk(), "setBoost"); break; } else if (hintId == PowerHint::LAUNCH) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); auto ret = handle->setMode(Mode::LAUNCH, static_cast<bool>(data)); processPowerHalReturn(ret.isOk(), "setMode"); break; } else { ALOGE("Unsupported power hint: %s.", toString(hintId).c_str()); return; } } default: { ALOGE("Unknown power HAL state"); return; } } SurfaceComposerClient::notifyPowerHint(static_cast<int32_t>(hintId)); } enum class HalSupport { UNKNOWN = 0, ON, OFF, }; static void setPowerBoost(Boost boost, int32_t durationMs) { static void setPowerBoostWithHandle(sp<IPowerAidl> handle, Boost boost, int32_t durationMs) { // Android framework only sends boost upto DISPLAY_UPDATE_IMMINENT. // Need to increase the array size if more boost supported. static std::array<std::atomic<HalSupport>, Loading @@ -243,14 +198,6 @@ static void setPowerBoost(Boost boost, int32_t durationMs) { return; } std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); if (boostSupportedArray[static_cast<int32_t>(boost)] == HalSupport::UNKNOWN) { bool isSupported = false; handle->isBoostSupported(boost, &isSupported); Loading @@ -267,11 +214,21 @@ static void setPowerBoost(Boost boost, int32_t durationMs) { processPowerHalReturn(ret.isOk(), "setPowerBoost"); } static void setPowerMode(Mode mode, bool enabled) { static void setPowerBoost(Boost boost, int32_t durationMs) { std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerBoostWithHandle(handle, boost, durationMs); } static void setPowerModeWithHandle(sp<IPowerAidl> handle, Mode mode, bool enabled) { // Android framework only sends mode upto DISPLAY_INACTIVE. // Need to increase the array if more mode supported. static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1> static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1> modeSupportedArray = {HalSupport::UNKNOWN}; // Quick return if mode is not supported by HAL Loading @@ -281,14 +238,6 @@ static void setPowerMode(Mode mode, bool enabled) { return; } std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); if (modeSupportedArray[static_cast<int32_t>(mode)] == HalSupport::UNKNOWN) { bool isSupported = false; handle->isModeSupported(mode, &isSupported); Loading @@ -304,6 +253,76 @@ static void setPowerMode(Mode mode, bool enabled) { processPowerHalReturn(ret.isOk(), "setPowerMode"); } static void setPowerMode(Mode mode, bool enabled) { std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, mode, enabled); } static void sendPowerHint(PowerHint hintId, uint32_t data) { std::unique_lock<std::mutex> lock(gPowerHalMutex); switch (connectPowerHalLocked()) { case HalVersion::NONE: return; case HalVersion::HIDL_1_0: { sp<IPowerV1_0> handle = gPowerHalHidlV1_0_; lock.unlock(); auto ret = handle->powerHint(hintId, data); processPowerHalReturn(ret.isOk(), "powerHint"); break; } case HalVersion::HIDL_1_1: { sp<IPowerV1_1> handle = gPowerHalHidlV1_1_; lock.unlock(); auto ret = handle->powerHintAsync(hintId, data); processPowerHalReturn(ret.isOk(), "powerHintAsync"); break; } case HalVersion::AIDL: { if (hintId == PowerHint::INTERACTION) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerBoostWithHandle(handle, Boost::INTERACTION, data); break; } else if (hintId == PowerHint::LAUNCH) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::LAUNCH, static_cast<bool>(data)); break; } else if (hintId == PowerHint::LOW_POWER) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::LOW_POWER, static_cast<bool>(data)); break; } else if (hintId == PowerHint::SUSTAINED_PERFORMANCE) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::SUSTAINED_PERFORMANCE, static_cast<bool>(data)); break; } else if (hintId == PowerHint::VR_MODE) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::VR, static_cast<bool>(data)); break; } else { ALOGE("Unsupported power hint: %s.", toString(hintId).c_str()); return; } } default: { ALOGE("Unknown power HAL state"); return; } } SurfaceComposerClient::notifyPowerHint(static_cast<int32_t>(hintId)); } void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType) { if (gPowerManagerServiceObj) { // Throttle calls into user activity by event type. Loading Loading @@ -426,8 +445,7 @@ static void nativeSetInteractive(JNIEnv* /* env */, jclass /* clazz */, jboolean case HalVersion::AIDL: { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); auto ret = handle->setMode(Mode::INTERACTIVE, enable); processPowerHalReturn(ret.isOk(), "setMode"); setPowerModeWithHandle(handle, Mode::INTERACTIVE, enable); return; } default: { Loading Loading @@ -481,8 +499,9 @@ static void nativeSetFeature(JNIEnv* /* env */, jclass /* clazz */, jint feature return; } case HalVersion::AIDL: { auto ret = gPowerHalAidl_->setMode(Mode::DOUBLE_TAP_TO_WAKE, static_cast<bool>(data)); processPowerHalReturn(ret.isOk(), "setMode"); sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::DOUBLE_TAP_TO_WAKE, static_cast<bool>(data)); return; } default: { Loading Loading
services/core/jni/com_android_server_power_PowerManagerService.cpp +90 −71 Original line number Diff line number Diff line Loading @@ -178,58 +178,13 @@ bool processPowerHalReturn(bool isOk, const char* functionName) { return isOk; } static void sendPowerHint(PowerHint hintId, uint32_t data) { std::unique_lock<std::mutex> lock(gPowerHalMutex); switch (connectPowerHalLocked()) { case HalVersion::NONE: return; case HalVersion::HIDL_1_0: { sp<IPowerV1_0> handle = gPowerHalHidlV1_0_; lock.unlock(); auto ret = handle->powerHint(hintId, data); processPowerHalReturn(ret.isOk(), "powerHint"); break; } case HalVersion::HIDL_1_1: { sp<IPowerV1_1> handle = gPowerHalHidlV1_1_; lock.unlock(); auto ret = handle->powerHintAsync(hintId, data); processPowerHalReturn(ret.isOk(), "powerHintAsync"); break; } case HalVersion::AIDL: { if (hintId == PowerHint::INTERACTION) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); auto ret = handle->setBoost(Boost::INTERACTION, data); processPowerHalReturn(ret.isOk(), "setBoost"); break; } else if (hintId == PowerHint::LAUNCH) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); auto ret = handle->setMode(Mode::LAUNCH, static_cast<bool>(data)); processPowerHalReturn(ret.isOk(), "setMode"); break; } else { ALOGE("Unsupported power hint: %s.", toString(hintId).c_str()); return; } } default: { ALOGE("Unknown power HAL state"); return; } } SurfaceComposerClient::notifyPowerHint(static_cast<int32_t>(hintId)); } enum class HalSupport { UNKNOWN = 0, ON, OFF, }; static void setPowerBoost(Boost boost, int32_t durationMs) { static void setPowerBoostWithHandle(sp<IPowerAidl> handle, Boost boost, int32_t durationMs) { // Android framework only sends boost upto DISPLAY_UPDATE_IMMINENT. // Need to increase the array size if more boost supported. static std::array<std::atomic<HalSupport>, Loading @@ -243,14 +198,6 @@ static void setPowerBoost(Boost boost, int32_t durationMs) { return; } std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); if (boostSupportedArray[static_cast<int32_t>(boost)] == HalSupport::UNKNOWN) { bool isSupported = false; handle->isBoostSupported(boost, &isSupported); Loading @@ -267,11 +214,21 @@ static void setPowerBoost(Boost boost, int32_t durationMs) { processPowerHalReturn(ret.isOk(), "setPowerBoost"); } static void setPowerMode(Mode mode, bool enabled) { static void setPowerBoost(Boost boost, int32_t durationMs) { std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerBoostWithHandle(handle, boost, durationMs); } static void setPowerModeWithHandle(sp<IPowerAidl> handle, Mode mode, bool enabled) { // Android framework only sends mode upto DISPLAY_INACTIVE. // Need to increase the array if more mode supported. static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1> static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1> modeSupportedArray = {HalSupport::UNKNOWN}; // Quick return if mode is not supported by HAL Loading @@ -281,14 +238,6 @@ static void setPowerMode(Mode mode, bool enabled) { return; } std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); if (modeSupportedArray[static_cast<int32_t>(mode)] == HalSupport::UNKNOWN) { bool isSupported = false; handle->isModeSupported(mode, &isSupported); Loading @@ -304,6 +253,76 @@ static void setPowerMode(Mode mode, bool enabled) { processPowerHalReturn(ret.isOk(), "setPowerMode"); } static void setPowerMode(Mode mode, bool enabled) { std::unique_lock<std::mutex> lock(gPowerHalMutex); if (connectPowerHalLocked() != HalVersion::AIDL) { ALOGV("Power HAL AIDL not available"); return; } sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, mode, enabled); } static void sendPowerHint(PowerHint hintId, uint32_t data) { std::unique_lock<std::mutex> lock(gPowerHalMutex); switch (connectPowerHalLocked()) { case HalVersion::NONE: return; case HalVersion::HIDL_1_0: { sp<IPowerV1_0> handle = gPowerHalHidlV1_0_; lock.unlock(); auto ret = handle->powerHint(hintId, data); processPowerHalReturn(ret.isOk(), "powerHint"); break; } case HalVersion::HIDL_1_1: { sp<IPowerV1_1> handle = gPowerHalHidlV1_1_; lock.unlock(); auto ret = handle->powerHintAsync(hintId, data); processPowerHalReturn(ret.isOk(), "powerHintAsync"); break; } case HalVersion::AIDL: { if (hintId == PowerHint::INTERACTION) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerBoostWithHandle(handle, Boost::INTERACTION, data); break; } else if (hintId == PowerHint::LAUNCH) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::LAUNCH, static_cast<bool>(data)); break; } else if (hintId == PowerHint::LOW_POWER) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::LOW_POWER, static_cast<bool>(data)); break; } else if (hintId == PowerHint::SUSTAINED_PERFORMANCE) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::SUSTAINED_PERFORMANCE, static_cast<bool>(data)); break; } else if (hintId == PowerHint::VR_MODE) { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::VR, static_cast<bool>(data)); break; } else { ALOGE("Unsupported power hint: %s.", toString(hintId).c_str()); return; } } default: { ALOGE("Unknown power HAL state"); return; } } SurfaceComposerClient::notifyPowerHint(static_cast<int32_t>(hintId)); } void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType) { if (gPowerManagerServiceObj) { // Throttle calls into user activity by event type. Loading Loading @@ -426,8 +445,7 @@ static void nativeSetInteractive(JNIEnv* /* env */, jclass /* clazz */, jboolean case HalVersion::AIDL: { sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); auto ret = handle->setMode(Mode::INTERACTIVE, enable); processPowerHalReturn(ret.isOk(), "setMode"); setPowerModeWithHandle(handle, Mode::INTERACTIVE, enable); return; } default: { Loading Loading @@ -481,8 +499,9 @@ static void nativeSetFeature(JNIEnv* /* env */, jclass /* clazz */, jint feature return; } case HalVersion::AIDL: { auto ret = gPowerHalAidl_->setMode(Mode::DOUBLE_TAP_TO_WAKE, static_cast<bool>(data)); processPowerHalReturn(ret.isOk(), "setMode"); sp<IPowerAidl> handle = gPowerHalAidl_; lock.unlock(); setPowerModeWithHandle(handle, Mode::DOUBLE_TAP_TO_WAKE, static_cast<bool>(data)); return; } default: { Loading