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

Commit fcd1c336 authored by dianlujitao's avatar dianlujitao Committed by Michael Bestas
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 3874e9c8
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -323,4 +323,10 @@ public abstract class PowerManagerInternal {


    /** Allows power button to intercept a power key button press. */
    /** Allows power button to intercept a power key button press. */
    public abstract boolean interceptPowerKeyDown(KeyEvent event);
    public abstract boolean interceptPowerKeyDown(KeyEvent event);

    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 Original line Diff line number Diff line
@@ -857,6 +857,7 @@ public final class PowerManagerService extends SystemService
    private static native void nativeSetPowerBoost(int boost, int durationMs);
    private static native void nativeSetPowerBoost(int boost, int durationMs);
    private static native boolean nativeSetPowerMode(int mode, boolean enabled);
    private static native boolean nativeSetPowerMode(int mode, boolean enabled);
    private static native void nativeSetFeature(int featureId, int data);
    private static native void nativeSetFeature(int featureId, int data);
    private static native int nativeGetFeature(int featureId);
    private static native boolean nativeForceSuspend();
    private static native boolean nativeForceSuspend();


    public PowerManagerService(Context context) {
    public PowerManagerService(Context context) {
@@ -5590,5 +5591,20 @@ public final class PowerManagerService extends SystemService
        public boolean interceptPowerKeyDown(KeyEvent event) {
        public boolean interceptPowerKeyDown(KeyEvent event) {
            return interceptPowerKeyDownInternal(event);
            return interceptPowerKeyDownInternal(event);
        }
        }

        @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 Original line Diff line number Diff line
@@ -167,6 +167,7 @@ cc_defaults {
        "android.system.suspend@1.0",
        "android.system.suspend@1.0",
        "service.incremental",
        "service.incremental",
        "suspend_control_aidl_interface-cpp",
        "suspend_control_aidl_interface-cpp",
        "vendor.lineage.power@1.0",
    ],
    ],


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


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


namespace android {
namespace android {


@@ -75,6 +78,7 @@ static jobject gPowerManagerServiceObj;
static sp<IPowerV1_0> gPowerHalHidlV1_0_ = nullptr;
static sp<IPowerV1_0> gPowerHalHidlV1_0_ = nullptr;
static sp<IPowerV1_1> gPowerHalHidlV1_1_ = nullptr;
static sp<IPowerV1_1> gPowerHalHidlV1_1_ = nullptr;
static sp<IPowerAidl> gPowerHalAidl_ = nullptr;
static sp<IPowerAidl> gPowerHalAidl_ = nullptr;
static sp<ILineagePowerV1_0> gLineagePowerHalV1_0_ = nullptr;
static std::mutex gPowerHalMutex;
static std::mutex gPowerHalMutex;


enum class HalVersion {
enum class HalVersion {
@@ -143,6 +147,21 @@ static HalVersion connectPowerHalLocked() {
    return HalVersion::NONE;
    return HalVersion::NONE;
}
}


// Check validity of current handle to the Lineage power HAL service, and call getService() if necessary.
// The caller must be holding gPowerHalMutex.
void connectLineagePowerHalLocked() {
    static bool gLineagePowerHalExists = true;
    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 HIDL V1_0
// Retrieve a copy of PowerHAL HIDL V1_0
sp<IPowerV1_0> getPowerHalHidlV1_0() {
sp<IPowerV1_0> getPowerHalHidlV1_0() {
    std::lock_guard<std::mutex> lock(gPowerHalMutex);
    std::lock_guard<std::mutex> lock(gPowerHalMutex);
@@ -164,6 +183,13 @@ sp<IPowerV1_1> getPowerHalHidlV1_1() {
    return nullptr;
    return nullptr;
}
}


// 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
// 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.
// current handle to the power HAL service.
bool processPowerHalReturn(bool isOk, const char* functionName) {
bool processPowerHalReturn(bool isOk, const char* functionName) {
@@ -404,6 +430,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) {
static void nativeInit(JNIEnv* env, jobject obj) {
@@ -535,6 +572,7 @@ static const JNINativeMethod gPowerManagerServiceMethods[] = {
        {"nativeSetPowerBoost", "(II)V", (void*)nativeSetPowerBoost},
        {"nativeSetPowerBoost", "(II)V", (void*)nativeSetPowerBoost},
        {"nativeSetPowerMode", "(IZ)Z", (void*)nativeSetPowerMode},
        {"nativeSetPowerMode", "(IZ)Z", (void*)nativeSetPowerMode},
        {"nativeSetFeature", "(II)V", (void*)nativeSetFeature},
        {"nativeSetFeature", "(II)V", (void*)nativeSetFeature},
        {"nativeGetFeature", "(I)I", (void*)nativeGetFeature},
};
};


#define FIND_CLASS(var, className) \
#define FIND_CLASS(var, className) \