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

Commit 14aadb0c 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 a17c796c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -51,4 +51,6 @@ interface IPowerManager

    // sets the attention light (used by phone app only)
    void setAttentionLight(boolean on, int color);

    void cpuBoost(int duration);
}
+18 −0
Original line number Diff line number Diff line
@@ -603,6 +603,24 @@ public final 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) {
        }
    }

    /**
     * A wake lock is a mechanism to indicate that your application needs
     * to have the device stay on.
+18 −0
Original line number Diff line number Diff line
@@ -170,6 +170,9 @@ public final class PowerManagerService extends IPowerManager.Stub
    // effectively and terminate the dream.
    private static final int DREAM_BATTERY_LEVEL_DRAIN_CUTOFF = 5;

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

    private Context mContext;
    private LightsService mLightsService;
    private BatteryService mBatteryService;
@@ -367,6 +370,7 @@ public final class PowerManagerService extends IPowerManager.Stub
    private static native void nativeReleaseSuspendBlocker(String name);
    private static native void nativeSetInteractive(boolean enable);
    private static native void nativeSetAutoSuspend(boolean enable);
    private static native void nativeCpuBoost(int duration);

    public PowerManagerService() {
        synchronized (mLock) {
@@ -1823,6 +1827,20 @@ public final class PowerManagerService extends IPowerManager.Stub
        }
    }

    /**
     * Boost the CPU
     * @param duration Duration to boost the CPU for, in milliseconds.
     * @hide
     */
    @Override // Binder call
    public void cpuBoost(int duration) {
        if (duration > 0 && duration <= MAX_CPU_BOOST_TIME) {
            nativeCpuBoost(duration);
        } else {
            Log.e(TAG, "Invalid boost duration: " + duration);
        }
    }

    private void shutdownOrRebootInternal(final boolean shutdown, final boolean confirm,
            final String reason, boolean wait) {
        if (mHandler == null || !mSystemReady) {
+8 −0
Original line number Diff line number Diff line
@@ -204,6 +204,12 @@ static void nativeReboot(JNIEnv *env, jclass clazz, jstring reason) {
    jniThrowIOException(env, errno);
}

static 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);
    }
}

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

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

#define FIND_CLASS(var, className) \
+5 −0
Original line number Diff line number Diff line
@@ -119,4 +119,9 @@ public class BridgePowerManager implements IPowerManager {
    public void wakeUp(long time) throws RemoteException {
        // pass for now.
    }

    @Override
    public void cpuBoost(int duration) throws RemoteException {
        // pass for now
    }
}