diff options
author | Steve Kondik <steve@cyngn.com> | 2013-11-04 02:59:16 +0000 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2014-11-08 15:14:54 -0800 |
commit | 4ba189ba45605105a91230888078828f861e1ac8 (patch) | |
tree | c3489c58530810c3054bef0934de37aaf477f7ea | |
parent | 2437f21f778920d9de3d0499aeeda97a370417b1 (diff) | |
download | android_frameworks_base-staging/cm-12.0-caf.tar.gz android_frameworks_base-staging/cm-12.0-caf.tar.bz2 android_frameworks_base-staging/cm-12.0-caf.zip |
power: Add CPU boosting interfacestaging/cm-12.0-caf
* 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
Add CPU boosting hooks
* Send boost hint during scrolling
* Still relevant on even high-end hardware
Change-Id: I72f2c2851b01fbceabddead03a4c3a7a0526ca61
perf: Send a boost hint when a key on the navbar is pressed
* A lot of stuff happens, especially when invoking recents.
* Get ahead of the storm by sending a boost hint before
kicking off the animations.
Change-Id: I0cecd0c58f8bc8479ea44f63af796500d7b9d7d2
perf: Send boost hint during initial launch
Change-Id: I26afc909c35e514958894b0a07a650a20ce6e537
9 files changed, 78 insertions, 3 deletions
diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 87b0820916c..9e95b586fe8 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -60,4 +60,6 @@ interface IPowerManager void setAttentionLight(boolean on, int color); // update the uids being synchronized by network socket request manager void updateBlockedUids(int uid, boolean isBlocked); + + void cpuBoost(int duration); } diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 3b6ce53fd62..325e3846a4a 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -813,6 +813,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) { + } + } + + /** * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. * This broadcast is only sent to registered receivers. */ diff --git a/core/java/android/widget/OverScroller.java b/core/java/android/widget/OverScroller.java index 7b3dd31fd15..9818bb5cb4b 100644 --- a/core/java/android/widget/OverScroller.java +++ b/core/java/android/widget/OverScroller.java @@ -18,6 +18,7 @@ package android.widget; import android.content.Context; import android.hardware.SensorManager; +import android.os.PowerManager; import android.util.FloatMath; import android.util.Log; import android.view.ViewConfiguration; @@ -602,6 +603,8 @@ public class OverScroller { private static final int CUBIC = 1; private static final int BALLISTIC = 2; + private final PowerManager mPm; + static { float x_min = 0.0f; float y_min = 0.0f; @@ -646,6 +649,7 @@ public class OverScroller { * 39.37f // inch/meter * ppi * 0.84f; // look and feel tuning + mPm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); } void updateScroll(float q) { @@ -763,6 +767,7 @@ public class OverScroller { if (velocity != 0) { mDuration = mSplineDuration = getSplineFlingDuration(velocity); totalDistance = getSplineFlingDistance(velocity); + mPm.cpuBoost(mDuration * 1000); } mSplineDistance = (int) (totalDistance * Math.signum(velocity)); diff --git a/core/java/android/widget/Scroller.java b/core/java/android/widget/Scroller.java index 5e88a968271..f245b79273a 100644 --- a/core/java/android/widget/Scroller.java +++ b/core/java/android/widget/Scroller.java @@ -19,6 +19,7 @@ package android.widget; import android.content.Context; import android.hardware.SensorManager; import android.os.Build; +import android.os.PowerManager; import android.util.FloatMath; import android.view.ViewConfiguration; import android.view.animation.AnimationUtils; @@ -109,6 +110,8 @@ public class Scroller { private float mDeceleration; private final float mPpi; + private final PowerManager mPm; + // A context-specific coefficient adjusted to physical values. private float mPhysicalCoeff; @@ -179,6 +182,8 @@ public class Scroller { mFlywheel = flywheel; mPhysicalCoeff = computeDeceleration(0.84f); // look and feel tuning + + mPm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); } /** @@ -396,6 +401,8 @@ public class Scroller { mDeltaX = dx; mDeltaY = dy; mDurationReciprocal = 1.0f / (float) mDuration; + + mPm.cpuBoost(duration * 1000); } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java index 7cc75da1db5..24ebfe07ce2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java @@ -30,6 +30,7 @@ import android.graphics.RectF; import android.hardware.input.InputManager; import android.media.AudioManager; import android.os.Bundle; +import android.os.PowerManager; import android.os.SystemClock; import android.util.AttributeSet; import android.util.Log; @@ -71,6 +72,8 @@ public class KeyButtonView extends ImageView { private AudioManager mAudioManager; private Animator mAnimateToQuiescent = new ObjectAnimator(); + private PowerManager mPm; + private final Runnable mCheckLongPress = new Runnable() { public void run() { if (isPressed()) { @@ -109,6 +112,7 @@ public class KeyButtonView extends ImageView { mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); setBackground(new KeyButtonRipple(context, this)); + mPm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); } @Override @@ -175,6 +179,9 @@ public class KeyButtonView extends ImageView { final int action = ev.getAction(); int x, y; + // A lot of stuff is about to happen. Lets get ready. + mPm.cpuBoost(750000); + switch (action) { case MotionEvent.ACTION_DOWN: //Log.d("KeyButtonView", "press"); diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 03dd3c0c7e4..e0db3346833 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -232,6 +232,8 @@ public final class ActivityStackSupervisor implements DisplayListener { * setWindowManager is called. **/ private boolean mLeanbackOnlyDevice; + private PowerManager mPm; + /** * We don't want to allow the device to go to sleep while in the process * of launching an activity. This is primarily to allow alarm intent @@ -303,10 +305,10 @@ public final class ActivityStackSupervisor implements DisplayListener { * initialized. So we initialize our wakelocks afterwards. */ void initPowerManagement() { - PowerManager pm = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); - mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); + mPm = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); + mGoingToSleep = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); mLaunchingActivity = - pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch"); + mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch"); mLaunchingActivity.setReferenceCounted(false); } @@ -2632,6 +2634,7 @@ public final class ActivityStackSupervisor implements DisplayListener { } } } + mPm.cpuBoost(2000 * 1000); if (DEBUG_TASKS) Slog.d(TAG, "No task found"); return null; } diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 87346610706..36e503bd647 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -159,6 +159,9 @@ public final class PowerManagerService extends SystemService // Config value for NSRM private static final int DPM_CONFIG_FEATURE_MASK_NSRM = 0x00000004; + // Max time (microseconds) to allow a CPU boost for + private static final int MAX_CPU_BOOST_TIME = 5000000; + private final Context mContext; private final ServiceThread mHandlerThread; private final PowerManagerHandler mHandler; @@ -439,6 +442,7 @@ public final class PowerManagerService extends SystemService private static native void nativeSetInteractive(boolean enable); private static native void nativeSetAutoSuspend(boolean enable); private static native void nativeSendPowerHint(int hintId, int data); + private static native void nativeCpuBoost(int duration); public PowerManagerService(Context context) { super(context); @@ -3030,6 +3034,21 @@ public final class PowerManagerService extends SystemService } /** + * Boost the CPU + * @param duration Duration to boost the CPU for, in milliseconds. + * @hide + */ + @Override + public void cpuBoost(int duration) { + if (duration > 0 && duration <= MAX_CPU_BOOST_TIME) { + nativeCpuBoost(duration); + } else { + Log.e(TAG, "Invalid boost duration: " + duration); + } + } + + + /** * Reboots the device. * * @param confirm If true, shows a reboot confirmation dialog. diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp index 33e0bd7f371..6e42acc44b9 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp @@ -156,6 +156,13 @@ static void nativeSendPowerHint(JNIEnv *env, jclass clazz, jint hintId, jint dat } } +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); + } +} + // ---------------------------------------------------------------------------- static JNINativeMethod gPowerManagerServiceMethods[] = { @@ -172,6 +179,8 @@ static JNINativeMethod gPowerManagerServiceMethods[] = { (void*) nativeSetAutoSuspend }, { "nativeSendPowerHint", "(II)V", (void*) nativeSendPowerHint }, + { "nativeCpuBoost", "(I)V", + (void*) nativeCpuBoost }, }; #define FIND_CLASS(var, className) \ diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePowerManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePowerManager.java index 22265a30e9a..ebdb3ece573 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePowerManager.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePowerManager.java @@ -145,4 +145,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 + } } |