@@ -266,6 +266,11 @@ public final class PowerManagerService extends IPowerManager.Stub
266266 // Use -1 to disable.
267267 private int mScreenBrightnessOverrideFromWindowManager = -1 ;
268268
269+ // The user activity timeout override from the window manager
270+ // to allow the current foreground activity to override the user activity timeout.
271+ // Use -1 to disable.
272+ private long mUserActivityTimeoutOverrideFromWindowManager = -1 ;
273+
269274 // The screen brightness setting override from the settings application
270275 // to temporarily adjust the brightness until next updated,
271276 // Use -1 to disable.
@@ -1156,6 +1161,9 @@ private int getScreenOffTimeoutLocked() {
11561161 if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked ()) {
11571162 timeout = Math .min (timeout , mMaximumScreenOffTimeoutFromDeviceAdmin );
11581163 }
1164+ if (mUserActivityTimeoutOverrideFromWindowManager >= 0 ) {
1165+ timeout = (int )Math .min (timeout , mUserActivityTimeoutOverrideFromWindowManager );
1166+ }
11591167 return Math .max (timeout , MINIMUM_SCREEN_OFF_TIMEOUT );
11601168 }
11611169
@@ -1573,12 +1581,6 @@ public void run() {
15731581 }
15741582 }
15751583
1576- @ Override // Binder call
1577- public void setPokeLock (int pokey , IBinder lock , String tag ) {
1578- // TODO Auto-generated method stub
1579- // Only used by phone app, delete this
1580- }
1581-
15821584 /**
15831585 * Set the setting that determines whether the device stays on when plugged in.
15841586 * The argument is a bit string, with each bit specifying a power source that,
@@ -1720,6 +1722,36 @@ public void setButtonBrightnessOverrideFromWindowManager(int brightness) {
17201722 mContext .enforceCallingOrSelfPermission (android .Manifest .permission .DEVICE_POWER , null );
17211723 }
17221724
1725+ /**
1726+ * Used by the window manager to override the user activity timeout based on the
1727+ * current foreground activity. It can only be used to make the timeout shorter
1728+ * than usual, not longer.
1729+ *
1730+ * This method must only be called by the window manager.
1731+ *
1732+ * @param timeoutMillis The overridden timeout, or -1 to disable the override.
1733+ */
1734+ public void setUserActivityTimeoutOverrideFromWindowManager (long timeoutMillis ) {
1735+ mContext .enforceCallingOrSelfPermission (android .Manifest .permission .DEVICE_POWER , null );
1736+
1737+ final long ident = Binder .clearCallingIdentity ();
1738+ try {
1739+ setUserActivityTimeoutOverrideFromWindowManagerInternal (timeoutMillis );
1740+ } finally {
1741+ Binder .restoreCallingIdentity (ident );
1742+ }
1743+ }
1744+
1745+ private void setUserActivityTimeoutOverrideFromWindowManagerInternal (long timeoutMillis ) {
1746+ synchronized (mLock ) {
1747+ if (mUserActivityTimeoutOverrideFromWindowManager != timeoutMillis ) {
1748+ mUserActivityTimeoutOverrideFromWindowManager = timeoutMillis ;
1749+ mDirty |= DIRTY_SETTINGS ;
1750+ updatePowerStateLocked ();
1751+ }
1752+ }
1753+ }
1754+
17231755 /**
17241756 * Used by the settings application and brightness control widgets to
17251757 * temporarily override the current screen brightness setting so that the
@@ -1869,6 +1901,8 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
18691901 pw .println (" mScreenBrightnessModeSetting=" + mScreenBrightnessModeSetting );
18701902 pw .println (" mScreenBrightnessOverrideFromWindowManager="
18711903 + mScreenBrightnessOverrideFromWindowManager );
1904+ pw .println (" mUserActivityTimeoutOverrideFromWindowManager="
1905+ + mUserActivityTimeoutOverrideFromWindowManager );
18721906 pw .println (" mTemporaryScreenBrightnessSettingOverride="
18731907 + mTemporaryScreenBrightnessSettingOverride );
18741908 pw .println (" mTemporaryScreenAutoBrightnessAdjustmentSettingOverride="
0 commit comments