Skip to content

Commit 1e3b98d

Browse files
author
Jeff Brown
committed
New internal API to eliminate poke locks.
Added a new WindowManager.LayoutParams inputFeatures flag to disable automatic user activity behavior when an input event is sent to a window. Added a new WindowManager.LayoutParams field userActivityTimeout. Bug: 7165399 Change-Id: I204eafa37ef26aacc2c52a1ba1ecce1eebb0e0d9
1 parent 1f7a09b commit 1e3b98d

File tree

9 files changed

+102
-106
lines changed

9 files changed

+102
-106
lines changed

core/java/android/os/IPowerManager.aidl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ interface IPowerManager
4040
void reboot(String reason);
4141
void crash(String message);
4242

43-
void setPokeLock(int pokey, IBinder lock, String tag);
4443
void setStayOnSetting(int val);
4544
void setMaximumScreenOffTimeoutFromDeviceAdmin(int timeMs);
4645

core/java/android/os/LocalPowerManager.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

core/java/android/view/WindowManager.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,43 @@ public static boolean mayUseInputMethod(int flags) {
11751175
*/
11761176
public static final int INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002;
11771177

1178+
/**
1179+
* When this window has focus, does not call user activity for all input events so
1180+
* the application will have to do it itself. Should only be used by
1181+
* the keyguard and phone app.
1182+
* <p>
1183+
* Should only be used by the keyguard and phone app.
1184+
* </p>
1185+
*
1186+
* @hide
1187+
*/
1188+
public static final int INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004;
1189+
11781190
/**
11791191
* Control special features of the input subsystem.
11801192
*
11811193
* @see #INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES
11821194
* @see #INPUT_FEATURE_NO_INPUT_CHANNEL
1195+
* @see #INPUT_FEATURE_DISABLE_USER_ACTIVITY
11831196
* @hide
11841197
*/
11851198
public int inputFeatures;
11861199

1200+
/**
1201+
* Sets the number of milliseconds before the user activity timeout occurs
1202+
* when this window has focus. A value of -1 uses the standard timeout.
1203+
* A value of 0 uses the minimum support display timeout.
1204+
* <p>
1205+
* This property can only be used to reduce the user specified display timeout;
1206+
* it can never make the timeout longer than it normally would be.
1207+
* </p><p>
1208+
* Should only be used by the keyguard and phone app.
1209+
* </p>
1210+
*
1211+
* @hide
1212+
*/
1213+
public long userActivityTimeout = -1;
1214+
11871215
public LayoutParams() {
11881216
super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
11891217
type = TYPE_APPLICATION;
@@ -1268,6 +1296,7 @@ public void writeToParcel(Parcel out, int parcelableFlags) {
12681296
out.writeInt(subtreeSystemUiVisibility);
12691297
out.writeInt(hasSystemUiListeners ? 1 : 0);
12701298
out.writeInt(inputFeatures);
1299+
out.writeLong(userActivityTimeout);
12711300
}
12721301

12731302
public static final Parcelable.Creator<LayoutParams> CREATOR
@@ -1308,6 +1337,7 @@ public LayoutParams(Parcel in) {
13081337
subtreeSystemUiVisibility = in.readInt();
13091338
hasSystemUiListeners = in.readInt() != 0;
13101339
inputFeatures = in.readInt();
1340+
userActivityTimeout = in.readLong();
13111341
}
13121342

13131343
@SuppressWarnings({"PointlessBitwiseExpression"})
@@ -1334,6 +1364,8 @@ public LayoutParams(Parcel in) {
13341364
/** {@hide} */
13351365
public static final int PRIVATE_FLAGS_CHANGED = 1<<16;
13361366
/** {@hide} */
1367+
public static final int USER_ACTIVITY_TIMEOUT_CHANGED = 1<<17;
1368+
/** {@hide} */
13371369
public static final int EVERYTHING_CHANGED = 0xffffffff;
13381370

13391371
// internal buffer to backup/restore parameters under compatibility mode.
@@ -1455,6 +1487,11 @@ public final int copyFrom(LayoutParams o) {
14551487
changes |= INPUT_FEATURES_CHANGED;
14561488
}
14571489

1490+
if (userActivityTimeout != o.userActivityTimeout) {
1491+
userActivityTimeout = o.userActivityTimeout;
1492+
changes |= USER_ACTIVITY_TIMEOUT_CHANGED;
1493+
}
1494+
14581495
return changes;
14591496
}
14601497

@@ -1547,6 +1584,9 @@ public String toString() {
15471584
if (inputFeatures != 0) {
15481585
sb.append(" if=0x").append(Integer.toHexString(inputFeatures));
15491586
}
1587+
if (userActivityTimeout >= 0) {
1588+
sb.append(" userActivityTimeout=").append(userActivityTimeout);
1589+
}
15501590
sb.append('}');
15511591
return sb.toString();
15521592
}

services/input/InputDispatcher.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,16 @@ String8 InputDispatcher::getApplicationWindowLabelLocked(
17161716
}
17171717

17181718
void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
1719+
if (mFocusedWindowHandle != NULL) {
1720+
const InputWindowInfo* info = mFocusedWindowHandle->getInfo();
1721+
if (info->inputFeatures & InputWindowInfo::INPUT_FEATURE_DISABLE_USER_ACTIVITY) {
1722+
#if DEBUG_DISPATCH_CYCLE
1723+
ALOGD("Not poking user activity: disabled by window '%s'.", info->name.string());
1724+
#endif
1725+
return;
1726+
}
1727+
}
1728+
17191729
int32_t eventType = USER_ACTIVITY_EVENT_OTHER;
17201730
switch (eventEntry->type) {
17211731
case EventEntry::TYPE_MOTION: {

services/input/InputWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ struct InputWindowInfo {
110110

111111
enum {
112112
INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
113+
INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002,
114+
INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004,
113115
};
114116

115117
sp<InputChannel> inputChannel;

services/java/com/android/server/power/PowerManagerService.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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="

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ class LayoutFields {
598598
private boolean mSyswin = false;
599599
private float mScreenBrightness = -1;
600600
private float mButtonBrightness = -1;
601+
private long mUserActivityTimeout = -1;
601602
private boolean mUpdateRotation = false;
602603

603604
private static final int DISPLAY_CONTENT_UNKNOWN = 0;
@@ -8775,6 +8776,11 @@ private void handleNotObscuredLocked(final WindowState w, final long currentTime
87758776
&& mInnerFields.mButtonBrightness < 0) {
87768777
mInnerFields.mButtonBrightness = w.mAttrs.buttonBrightness;
87778778
}
8779+
if (!mInnerFields.mSyswin && w.mAttrs.userActivityTimeout >= 0
8780+
&& mInnerFields.mUserActivityTimeout < 0) {
8781+
mInnerFields.mUserActivityTimeout = w.mAttrs.userActivityTimeout;
8782+
}
8783+
87788784
final int type = attrs.type;
87798785
if (canBeSeen
87808786
&& (type == TYPE_SYSTEM_DIALOG
@@ -8874,7 +8880,9 @@ private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMe
88748880
mInnerFields.mHoldScreen = null;
88758881
mInnerFields.mScreenBrightness = -1;
88768882
mInnerFields.mButtonBrightness = -1;
8883+
mInnerFields.mUserActivityTimeout = -1;
88778884
mInnerFields.mDisplayHasContent = LayoutFields.DISPLAY_CONTENT_UNKNOWN;
8885+
88788886
mTransactionSequence++;
88798887

88808888
final DisplayContent defaultDisplay = getDefaultDisplayContentLocked();
@@ -9349,6 +9357,8 @@ private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMe
93499357
mPowerManager.setButtonBrightnessOverrideFromWindowManager(
93509358
toBrightnessOverride(mInnerFields.mButtonBrightness));
93519359
}
9360+
mPowerManager.setUserActivityTimeoutOverrideFromWindowManager(
9361+
mInnerFields.mUserActivityTimeout);
93529362
}
93539363

93549364
if (mTurnOnScreen) {

tests/StatusBar/src/com/android/statusbartest/PowerTest.java

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import android.os.IPowerManager;
2222
import android.content.ComponentName;
2323
import android.content.pm.PackageManager;
24-
import android.os.RemoteException;
2524
import android.os.Handler;
26-
import android.os.LocalPowerManager;
2725
import android.os.ServiceManager;
2826
import android.os.PowerManager;
2927

@@ -106,69 +104,5 @@ public void run() {
106104
}, 5000);
107105
}
108106
},
109-
new Test("Touch events don't poke") {
110-
public void run() {
111-
mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS;
112-
try {
113-
mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
114-
} catch (RemoteException e) {
115-
throw new RuntimeException(e);
116-
}
117-
}
118-
},
119-
120-
new Test("Touch events poke") {
121-
public void run() {
122-
mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS;
123-
try {
124-
mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
125-
} catch (RemoteException e) {
126-
throw new RuntimeException(e);
127-
}
128-
}
129-
},
130-
new Test("Short timeout") {
131-
public void run() {
132-
mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK;
133-
mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT;
134-
try {
135-
mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
136-
} catch (RemoteException e) {
137-
throw new RuntimeException(e);
138-
}
139-
}
140-
},
141-
new Test("Medium timeout") {
142-
public void run() {
143-
mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK;
144-
mPokeState |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT;
145-
try {
146-
mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
147-
} catch (RemoteException e) {
148-
throw new RuntimeException(e);
149-
}
150-
}
151-
},
152-
new Test("Normal timeout") {
153-
public void run() {
154-
mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK;
155-
try {
156-
mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
157-
} catch (RemoteException e) {
158-
throw new RuntimeException(e);
159-
}
160-
}
161-
},
162-
new Test("Illegal timeout") {
163-
public void run() {
164-
mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT
165-
| LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT;
166-
try {
167-
mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
168-
} catch (RemoteException e) {
169-
throw new RuntimeException(e);
170-
}
171-
}
172-
},
173107
};
174108
}

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePowerManager.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ public void setMaximumScreenOffTimeoutFromDeviceAdmin(int arg0) throws RemoteExc
8989
// pass for now.
9090
}
9191

92-
@Override
93-
public void setPokeLock(int arg0, IBinder arg1, String arg2) throws RemoteException {
94-
// pass for now.
95-
}
96-
9792
@Override
9893
public void setStayOnSetting(int arg0) throws RemoteException {
9994
// pass for now.

0 commit comments

Comments
 (0)