Merge "Use new powerHintAsync when available" into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f54dbc5253
@@ -59,7 +59,7 @@ namespace android
|
||||
|
||||
static bool wakeup_init = false;
|
||||
static sem_t wakeup_sem;
|
||||
extern sp<IPower> gPowerHal;
|
||||
extern sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0;
|
||||
extern std::mutex gPowerHalMutex;
|
||||
extern bool getPowerHal();
|
||||
|
||||
@@ -203,7 +203,7 @@ static jint getPlatformLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject o
|
||||
return -1;
|
||||
}
|
||||
|
||||
Return<void> ret = gPowerHal->getPlatformLowPowerStats(
|
||||
Return<void> ret = gPowerHalV1_0->getPlatformLowPowerStats(
|
||||
[&offset, &remaining, &total_added](hidl_vec<PowerStatePlatformSleepState> states,
|
||||
Status status) {
|
||||
if (status != Status::SUCCESS)
|
||||
@@ -257,7 +257,7 @@ static jint getPlatformLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject o
|
||||
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("getPlatformLowPowerStats() failed: power HAL service not available");
|
||||
gPowerHal = nullptr;
|
||||
gPowerHalV1_0 = nullptr;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,7 @@ static jint getSubsystemLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject
|
||||
}
|
||||
|
||||
//Trying to cast to 1.1, this will succeed only for devices supporting 1.1
|
||||
gPowerHal_1_1 = android::hardware::power::V1_1::IPower::castFrom(gPowerHal);
|
||||
gPowerHal_1_1 = android::hardware::power::V1_1::IPower::castFrom(gPowerHalV1_0);
|
||||
if (gPowerHal_1_1 == nullptr) {
|
||||
//This device does not support IPower@1.1, exiting gracefully
|
||||
return 0;
|
||||
@@ -351,7 +351,7 @@ static jint getSubsystemLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject
|
||||
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("getSubsystemLowPowerStats() failed: power HAL service not available");
|
||||
gPowerHal = nullptr;
|
||||
gPowerHalV1_0 = nullptr;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include <android/hardware/power/1.0/IPower.h>
|
||||
#include <android/hardware/power/1.1/IPower.h>
|
||||
#include "JNIHelp.h"
|
||||
#include "jni.h"
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
using android::hardware::Return;
|
||||
using android::hardware::Void;
|
||||
using android::hardware::power::V1_0::IPower;
|
||||
using android::hardware::power::V1_1::IPower;
|
||||
using android::hardware::power::V1_0::PowerHint;
|
||||
using android::hardware::power::V1_0::Feature;
|
||||
using android::String8;
|
||||
@@ -56,7 +56,8 @@ static struct {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static jobject gPowerManagerServiceObj;
|
||||
sp<IPower> gPowerHal = nullptr;
|
||||
sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr;
|
||||
sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr;
|
||||
bool gPowerHalExists = true;
|
||||
std::mutex gPowerHalMutex;
|
||||
static nsecs_t gLastEventTime[USER_ACTIVITY_EVENT_LAST + 1];
|
||||
@@ -79,16 +80,17 @@ static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodNa
|
||||
// Check validity of current handle to the power HAL service, and call getService() if necessary.
|
||||
// The caller must be holding gPowerHalMutex.
|
||||
bool getPowerHal() {
|
||||
if (gPowerHalExists && gPowerHal == nullptr) {
|
||||
gPowerHal = IPower::getService();
|
||||
if (gPowerHal != nullptr) {
|
||||
if (gPowerHalExists && gPowerHalV1_0 == nullptr) {
|
||||
gPowerHalV1_0 = android::hardware::power::V1_0::IPower::getService();
|
||||
if (gPowerHalV1_0 != nullptr) {
|
||||
gPowerHalV1_1 = android::hardware::power::V1_1::IPower::castFrom(gPowerHalV1_0);
|
||||
ALOGI("Loaded power HAL service");
|
||||
} else {
|
||||
ALOGI("Couldn't load power HAL service");
|
||||
gPowerHalExists = false;
|
||||
}
|
||||
}
|
||||
return gPowerHal != nullptr;
|
||||
return gPowerHalV1_0 != nullptr;
|
||||
}
|
||||
|
||||
// Check if a call to a power HAL function failed; if so, log the failure and invalidate the
|
||||
@@ -96,7 +98,7 @@ bool getPowerHal() {
|
||||
static void processReturn(const Return<void> &ret, const char* functionName) {
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("%s() failed: power HAL service not available.", functionName);
|
||||
gPowerHal = nullptr;
|
||||
gPowerHalV1_0 = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +106,12 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t
|
||||
// Tell the power HAL when user activity occurs.
|
||||
gPowerHalMutex.lock();
|
||||
if (getPowerHal()) {
|
||||
Return<void> ret = gPowerHal->powerHint(PowerHint::INTERACTION, 0);
|
||||
Return<void> ret;
|
||||
if (gPowerHalV1_1 != nullptr) {
|
||||
ret = gPowerHalV1_1->powerHintAsync(PowerHint::INTERACTION, 0);
|
||||
} else {
|
||||
ret = gPowerHalV1_0->powerHint(PowerHint::INTERACTION, 0);
|
||||
}
|
||||
processReturn(ret, "powerHint");
|
||||
}
|
||||
gPowerHalMutex.unlock();
|
||||
@@ -161,7 +168,7 @@ static void nativeSetInteractive(JNIEnv* /* env */, jclass /* clazz */, jboolean
|
||||
"Excessive delay in setInteractive(%s) while turning screen %s",
|
||||
enable ? "true" : "false", enable ? "on" : "off");
|
||||
ALOGD_IF_SLOW(20, err);
|
||||
Return<void> ret = gPowerHal->setInteractive(enable);
|
||||
Return<void> ret = gPowerHalV1_0->setInteractive(enable);
|
||||
processReturn(ret, "setInteractive");
|
||||
}
|
||||
}
|
||||
@@ -179,7 +186,12 @@ static void nativeSetAutoSuspend(JNIEnv* /* env */, jclass /* clazz */, jboolean
|
||||
static void nativeSendPowerHint(JNIEnv *env, jclass clazz, jint hintId, jint data) {
|
||||
std::lock_guard<std::mutex> lock(gPowerHalMutex);
|
||||
if (getPowerHal()) {
|
||||
Return<void> ret = gPowerHal->powerHint((PowerHint)hintId, data);
|
||||
Return<void> ret;
|
||||
if (gPowerHalV1_1 != nullptr) {
|
||||
ret = gPowerHalV1_1->powerHintAsync((PowerHint)hintId, data);
|
||||
} else {
|
||||
ret = gPowerHalV1_0->powerHint((PowerHint)hintId, data);
|
||||
}
|
||||
processReturn(ret, "powerHint");
|
||||
}
|
||||
}
|
||||
@@ -187,7 +199,7 @@ static void nativeSendPowerHint(JNIEnv *env, jclass clazz, jint hintId, jint dat
|
||||
static void nativeSetFeature(JNIEnv *env, jclass clazz, jint featureId, jint data) {
|
||||
std::lock_guard<std::mutex> lock(gPowerHalMutex);
|
||||
if (getPowerHal()) {
|
||||
Return<void> ret = gPowerHal->setFeature((Feature)featureId, static_cast<bool>(data));
|
||||
Return<void> ret = gPowerHalV1_0->setFeature((Feature)featureId, static_cast<bool>(data));
|
||||
processReturn(ret, "setFeature");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user