diff options
author | Jeff Brown <jeffbrown@google.com> | 2014-08-21 21:50:43 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2014-08-21 22:36:45 -0700 |
commit | 0a571123544058578b4ef1558c276a4050519652 (patch) | |
tree | 40e9fa1d715dbe02c53d7faada2a7909939e1d88 /services/core/java/com/android/server/power | |
parent | 72671fbb2036e13fccb0b8eeb98be606de1819dd (diff) | |
download | frameworks_base-0a571123544058578b4ef1558c276a4050519652.zip frameworks_base-0a571123544058578b4ef1558c276a4050519652.tar.gz frameworks_base-0a571123544058578b4ef1558c276a4050519652.tar.bz2 |
Poke interactive hint from userActivity and add @SystemApi.
Previously we only poked the interactive hint for input events that
were dispatched through the regular input system. However, when
using a car dock in projection mode input events are directly
delivered to apps by other system components, bypassing user activity.
So now we poke the interactive hint on all user activity.
Added an @SystemApi version of userActivity.
Added a new signature|system permission called USER_ACTIVITY
to allow system apps to poke userActivity. For now it seems
prudent to keep DEVICE_POWER signature only.
Bug: 17043684
Change-Id: Ia84bd03083065b8938a9853c08901fbf71b2e56b
Diffstat (limited to 'services/core/java/com/android/server/power')
-rw-r--r-- | services/core/java/com/android/server/power/PowerManagerService.java | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index a10136b..f47a07c 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -160,9 +160,9 @@ public final class PowerManagerService extends com.android.server.SystemService // Poll interval in milliseconds for watching boot animation finished. private static final int BOOT_ANIMATION_POLL_INTERVAL = 200; - // Used to send the hint to the PowerHAL indicating transitions - // from and to the low power mode. - private static final int POWER_HINT_LOW_POWER_MODE = 5; + // Power hints defined in hardware/libhardware/include/hardware/power.h. + private static final int POWER_HINT_INTERACTION = 2; + private static final int POWER_HINT_LOW_POWER = 5; private final Context mContext; private final ServiceThread mHandlerThread; @@ -223,6 +223,9 @@ public final class PowerManagerService extends com.android.server.SystemService private long mLastUserActivityTime; private long mLastUserActivityTimeNoChangeLights; + // Timestamp of last interactive power hint. + private long mLastInteractivePowerHintTime; + // A bitfield that summarizes the effect of the user activity timer. // A zero value indicates that the user activity timer has expired. private int mUserActivitySummary; @@ -707,7 +710,7 @@ public final class PowerManagerService extends com.android.server.SystemService final boolean lowPowerModeEnabled = mLowPowerModeSetting; if (mLowPowerModeEnabled != lowPowerModeEnabled) { mLowPowerModeEnabled = lowPowerModeEnabled; - powerHintInternal(POWER_HINT_LOW_POWER_MODE, lowPowerModeEnabled ? 1 : 0); + powerHintInternal(POWER_HINT_LOW_POWER, lowPowerModeEnabled ? 1 : 0); mLowPowerModeEnabled = lowPowerModeEnabled; BackgroundThread.getHandler().post(new Runnable() { @Override @@ -969,15 +972,25 @@ public final class PowerManagerService extends com.android.server.SystemService } if (eventTime < mLastSleepTime || eventTime < mLastWakeTime - || mWakefulness == WAKEFULNESS_ASLEEP || mWakefulness == WAKEFULNESS_DOZING || !mBootCompleted || !mSystemReady) { return false; } Trace.traceBegin(Trace.TRACE_TAG_POWER, "userActivity"); try { + if (eventTime > mLastInteractivePowerHintTime) { + powerHintInternal(POWER_HINT_INTERACTION, 0); + mLastInteractivePowerHintTime = eventTime; + } + mNotifier.onUserActivity(event, uid); + if (mWakefulness == WAKEFULNESS_ASLEEP + || mWakefulness == WAKEFULNESS_DOZING + || (flags & PowerManager.USER_ACTIVITY_FLAG_INDIRECT) != 0) { + return false; + } + if ((flags & PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS) != 0) { if (eventTime > mLastUserActivityTimeNoChangeLights && eventTime > mLastUserActivityTime) { @@ -2319,6 +2332,8 @@ public final class PowerManagerService extends com.android.server.SystemService pw.println(" mLastUserActivityTime=" + TimeUtils.formatUptime(mLastUserActivityTime)); pw.println(" mLastUserActivityTimeNoChangeLights=" + TimeUtils.formatUptime(mLastUserActivityTimeNoChangeLights)); + pw.println(" mLastInteractivePowerHintTime=" + + TimeUtils.formatUptime(mLastInteractivePowerHintTime)); pw.println(" mDisplayReady=" + mDisplayReady); pw.println(" mHoldingWakeLockSuspendBlocker=" + mHoldingWakeLockSuspendBlocker); pw.println(" mHoldingDisplaySuspendBlocker=" + mHoldingDisplaySuspendBlocker); @@ -2863,7 +2878,10 @@ public final class PowerManagerService extends com.android.server.SystemService public void userActivity(long eventTime, int event, int flags) { final long now = SystemClock.uptimeMillis(); if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER) - != PackageManager.PERMISSION_GRANTED) { + != PackageManager.PERMISSION_GRANTED + && mContext.checkCallingOrSelfPermission( + android.Manifest.permission.USER_ACTIVITY) + != PackageManager.PERMISSION_GRANTED) { // Once upon a time applications could call userActivity(). // Now we require the DEVICE_POWER permission. Log a warning and ignore the // request instead of throwing a SecurityException so we don't break old apps. @@ -2871,8 +2889,8 @@ public final class PowerManagerService extends com.android.server.SystemService if (now >= mLastWarningAboutUserActivityPermission + (5 * 60 * 1000)) { mLastWarningAboutUserActivityPermission = now; Slog.w(TAG, "Ignoring call to PowerManager.userActivity() because the " - + "caller does not have DEVICE_POWER permission. " - + "Please fix your app! " + + "caller does not have DEVICE_POWER or USER_ACTIVITY " + + "permission. Please fix your app! " + " pid=" + Binder.getCallingPid() + " uid=" + Binder.getCallingUid()); } |