Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d329f637 authored by dianlujitao's avatar dianlujitao Committed by Michael Bestas
Browse files

perf: Adapt for HIDL Lineage power hal

Change-Id: I90fd1438cc85d26777cf37d18c14e91dc38ea48f
parent 80ec485d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@ LOCAL_SHARED_LIBRARIES += \
    android.frameworks.schedulerservice@1.0 \
    android.frameworks.sensorservice@1.0 \

LOCAL_SHARED_LIBRARIES += \
    vendor.lineage.power@1.0

LOCAL_STATIC_LIBRARIES += \
    android.hardware.broadcastradio@1.1-utils-lib \
    libscrypt_static \
+22 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
//#define LOG_NDEBUG 0

#include <android/hardware/power/1.1/IPower.h>
#include <vendor/lineage/power/1.0/ILineagePower.h>
#include "JNIHelp.h"
#include "jni.h"

@@ -45,6 +46,7 @@ using android::hardware::power::V1_1::IPower;
using android::hardware::power::V1_0::PowerHint;
using android::hardware::power::V1_0::Feature;
using android::String8;
using vendor::lineage::power::V1_0::LineageFeature;

namespace android {

@@ -59,7 +61,9 @@ static struct {
static jobject gPowerManagerServiceObj;
sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr;
sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr;
sp<vendor::lineage::power::V1_0::ILineagePower> gLineagePowerHalV1_0 = nullptr;
bool gPowerHalExists = true;
bool gLineagePowerHalExists = true;
std::mutex gPowerHalMutex;
static nsecs_t gLastEventTime[USER_ACTIVITY_EVENT_LAST + 1];

@@ -94,6 +98,21 @@ bool getPowerHal() {
    return gPowerHalV1_0 != nullptr;
}

// Check validity of current handle to the Lineage power HAL service, and call getService() if necessary.
// The caller must be holding gPowerHalMutex.
bool getLineagePowerHal() {
    if (gLineagePowerHalExists && gLineagePowerHalV1_0 == nullptr) {
        gLineagePowerHalV1_0 = vendor::lineage::power::V1_0::ILineagePower::getService();
        if (gLineagePowerHalV1_0 != nullptr) {
            ALOGI("Loaded power HAL service");
        } else {
            ALOGI("Couldn't load power HAL service");
            gLineagePowerHalExists = false;
        }
    }
    return gLineagePowerHalV1_0 != nullptr;
}

// Check if a call to a power HAL function failed; if so, log the failure and invalidate the
// current handle to the power HAL service. The caller must be holding gPowerHalMutex.
static void processReturn(const Return<void> &ret, const char* functionName) {
@@ -217,8 +236,9 @@ static void nativeSetFeature(JNIEnv *env, jclass clazz, jint featureId, jint dat
static jint nativeGetFeature(JNIEnv *env, jclass clazz, jint featureId) {
    int value = -1;

    if (gPowerModule && gPowerModule->getFeature) {
        value = gPowerModule->getFeature(gPowerModule, (feature_t)featureId);
    std::lock_guard<std::mutex> lock(gPowerHalMutex);
    if (getLineagePowerHal()) {
        value = gLineagePowerHalV1_0->getFeature((LineageFeature)featureId);
    }

    return (jint)value;