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

Commit 5dc32667 authored by dianlujitao's avatar dianlujitao Committed by Sam Mortimer
Browse files

perf: Add support for HIDL Lineage power HAL

Author: Steve Kondik <steve@cyngn.com>
Date:   Mon Nov 2 17:38:41 2015 -0800

    perf: Add plumbing for PerformanceManager

    * Expose a couple of helpers on PowerManagerInternal to handle
      features.

    Change-Id: Ic8df7d891dece4e678711a2a5ad1434b4971663a

Author: dianlujitao <dianlujitao@lineageos.org>
Date:   Thu Jan 18 17:09:33 2018 +0800

    perf: Adapt for HIDL Lineage power hal

    Change-Id: I90fd1438cc85d26777cf37d18c14e91dc38ea48f

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Wed, 29 Aug 2018 11:50:09 +0200

    perf: Update Lineage HAL impl to match AOSP

    Change-Id: I176e5687378cb14b4e2a9f41a9da81e735688a71

Change-Id: I2d170d86b6c90f4ef8145298bc142c1977db6037
parent 3d04dbd3
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -206,4 +206,10 @@ public abstract class PowerManagerInternal {

    /** Returns information about the last wakeup event. */
    public abstract PowerManager.WakeData getLastWakeup();

    public abstract boolean setPowerSaveMode(boolean mode);

    public abstract void setFeature(int featureId, int data);

    public abstract int getFeature(int featureId);
}
+16 −0
Original line number Diff line number Diff line
@@ -736,6 +736,7 @@ public final class PowerManagerService extends SystemService
    private static native void nativeSetAutoSuspend(boolean enable);
    private static native void nativeSendPowerHint(int hintId, int data);
    private static native void nativeSetFeature(int featureId, int data);
    private static native int nativeGetFeature(int featureId);
    private static native boolean nativeForceSuspend();

    public PowerManagerService(Context context) {
@@ -4984,5 +4985,20 @@ public final class PowerManagerService extends SystemService
        public WakeData getLastWakeup() {
            return getLastWakeupInternal();
        }

        @Override
        public boolean setPowerSaveMode(boolean mode) {
            return setLowPowerModeInternal(mode);
        }

        @Override
        public int getFeature(int featureId) {
            return nativeGetFeature(featureId);
        }

        @Override
        public void setFeature(int featureId, int data) {
            nativeSetFeature(featureId, data);
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ cc_defaults {
        "android.frameworks.sensorservice@1.0",
        "android.system.suspend@1.0",
        "suspend_control_aidl_interface-cpp",
        "vendor.lineage.power@1.0",
    ],

    static_libs: [
+39 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <android/system/suspend/1.0/ISystemSuspend.h>
#include <android/system/suspend/ISuspendControlService.h>
#include <nativehelper/JNIHelp.h>
#include <vendor/lineage/power/1.0/ILineagePower.h>
#include "jni.h"

#include <nativehelper/ScopedUtfChars.h>
@@ -54,6 +55,8 @@ using android::system::suspend::V1_0::WakeLockType;
using android::system::suspend::ISuspendControlService;
using IPowerV1_1 = android::hardware::power::V1_1::IPower;
using IPowerV1_0 = android::hardware::power::V1_0::IPower;
using ILineagePowerV1_0 = vendor::lineage::power::V1_0::ILineagePower;
using vendor::lineage::power::V1_0::LineageFeature;

namespace android {

@@ -69,7 +72,9 @@ static jobject gPowerManagerServiceObj;
// Use getPowerHal* to retrieve a copy
static sp<IPowerV1_0> gPowerHalV1_0_ = nullptr;
static sp<IPowerV1_1> gPowerHalV1_1_ = nullptr;
static sp<ILineagePowerV1_0> gLineagePowerHalV1_0_ = nullptr;
static bool gPowerHalExists = true;
static bool gLineagePowerHalExists = true;
static std::mutex gPowerHalMutex;
static nsecs_t gLastEventTime[USER_ACTIVITY_EVENT_LAST + 1];

@@ -108,6 +113,20 @@ static void connectPowerHalLocked() {
    }
}

// Check validity of current handle to the Lineage power HAL service, and call getService() if necessary.
// The caller must be holding gPowerHalMutex.
void connectLineagePowerHalLocked() {
    if (gLineagePowerHalExists && gLineagePowerHalV1_0_ == nullptr) {
        gLineagePowerHalV1_0_ = ILineagePowerV1_0::getService();
        if (gLineagePowerHalV1_0_ != nullptr) {
            ALOGI("Loaded power HAL service");
        } else {
            ALOGI("Couldn't load power HAL service");
            gLineagePowerHalExists = false;
        }
    }
}

// Retrieve a copy of PowerHAL V1_0
sp<IPowerV1_0> getPowerHalV1_0() {
    std::lock_guard<std::mutex> lock(gPowerHalMutex);
@@ -122,6 +141,13 @@ sp<IPowerV1_1> getPowerHalV1_1() {
    return gPowerHalV1_1_;
}

// Retrieve a copy of LineagePowerHAL V1_0
sp<ILineagePowerV1_0> getLineagePowerHalV1_0() {
    std::lock_guard<std::mutex> lock(gPowerHalMutex);
    connectLineagePowerHalLocked();
    return gLineagePowerHalV1_0_;
}

// 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.
bool processPowerHalReturn(const Return<void> &ret, const char* functionName) {
@@ -237,6 +263,17 @@ void disableAutoSuspend() {
    }
}

static jint nativeGetFeature(JNIEnv* /* env */, jclass /* clazz */, jint featureId) {
    int value = -1;

    sp<ILineagePowerV1_0> lineagePowerHalV1_0 = getLineagePowerHalV1_0();
    if (lineagePowerHalV1_0 != nullptr) {
        value = lineagePowerHalV1_0->getFeature(static_cast<LineageFeature>(featureId));
    }

    return static_cast<jint>(value);
}

// ----------------------------------------------------------------------------

static void nativeInit(JNIEnv* env, jobject obj) {
@@ -324,6 +361,8 @@ static const JNINativeMethod gPowerManagerServiceMethods[] = {
            (void*) nativeSendPowerHint },
    { "nativeSetFeature", "(II)V",
            (void*) nativeSetFeature },
    { "nativeGetFeature", "(I)I",
            (void*) nativeGetFeature },
};

#define FIND_CLASS(var, className) \