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

Commit 1d96fbc4 authored by Steve Kondik's avatar Steve Kondik
Browse files

power: Add CPU boosting interface

 * Boosts CPU using Power HAL for the given duration.
 * Duration is given in microseconds.
 * Power HAL must implement POWER_HINT_CPU_BOOST.

Change-Id: Ic79baf7e3d0f75483c2fe8a242b4c3d93368b68b
parent 4aad10d2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -53,4 +53,6 @@ interface IPowerManager
    int getLightSensorScreenBrightness();
    int getLightSensorButtonBrightness();
    int getLightSensorKeyboardBrightness();

    void cpuBoost(int duration);
}
+2 −0
Original line number Diff line number Diff line
@@ -45,4 +45,6 @@ public interface LocalPowerManager {

    void setScreenBrightnessOverride(int brightness);
    void setButtonBrightnessOverride(int brightness);

    void cpuBoost(int duration);
}
+18 −0
Original line number Diff line number Diff line
@@ -559,6 +559,24 @@ public class PowerManager
        }
    }

    /**
     * Boost the CPU. Boosts the cpu for the given duration in microseconds.
     * Requires the {@link android.Manifest.permission#CPU_BOOST} permission.
     *
     * @param duration in microseconds to boost the CPU
     *
     * @hide
     */
    public void cpuBoost(int duration)
    {
        try {
            if (mService != null) {
                mService.cpuBoost(duration);
            }
        } catch (RemoteException e) {
        }
    }

    private PowerManager()
    {
    }
+13 −0
Original line number Diff line number Diff line
@@ -196,6 +196,9 @@ public class PowerManagerService extends IPowerManager.Stub
    static final int INITIAL_BUTTON_BRIGHTNESS = PowerManager.BRIGHTNESS_OFF;
    static final int INITIAL_KEYBOARD_BRIGHTNESS = PowerManager.BRIGHTNESS_OFF;

    // Max time (microseconds) to allow a CPU boost for
    static final int MAX_CPU_BOOST_TIME = 5000000;

    private final int MY_UID;
    private final int MY_PID;

@@ -358,6 +361,7 @@ public class PowerManagerService extends IPowerManager.Stub
    private static native int nativeSetScreenState(boolean on);
    private static native void nativeShutdown();
    private static native void nativeReboot(String reason) throws IOException;
    private static native void nativeCpuBoost(int duration);

    /*
    static PrintStream mLog;
@@ -1185,6 +1189,15 @@ public class PowerManagerService extends IPowerManager.Stub
        }
    }

    public void cpuBoost(int duration)
    {
        if (duration > 0 && duration <= MAX_CPU_BOOST_TIME) {
            nativeCpuBoost(duration);
        } else {
            Log.e(TAG, "Invalid boost duration: " + duration);
        }
    }

    private static String lockType(int type)
    {
        switch (type)
+9 −0
Original line number Diff line number Diff line
@@ -207,6 +207,13 @@ static void nativeReboot(JNIEnv *env, jobject clazz, jstring reason) {
    jniThrowIOException(env, errno);
}

void nativeCpuBoost(JNIEnv *env, jobject clazz, jint duration) {
    // Tell the Power HAL to boost the CPU
    if (gPowerModule && gPowerModule->powerHint) {
        gPowerModule->powerHint(gPowerModule, POWER_HINT_CPU_BOOST, (void *) duration);
    }
}


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

@@ -228,6 +235,8 @@ static JNINativeMethod gPowerManagerServiceMethods[] = {
            (void*) nativeShutdown },
    { "nativeReboot", "(Ljava/lang/String;)V",
            (void*) nativeReboot },
    { "nativeCpuBoost", "(I)V",
            (void*) nativeCpuBoost },
};

#define FIND_CLASS(var, className) \
Loading