Skip to content

Commit 3dc524b

Browse files
author
Jeff Brown
committed
Use new API to override user activity timeout from keyguard.
This now replaces the internal user activity timer that keyguard maintained. We can probably simplify things a great deal further now. Bug: 7165399 Change-Id: Ia0d5a156a4ff0c339bbd094380b9f7ab3cec5d9b
1 parent 1e3b98d commit 3dc524b

File tree

5 files changed

+29
-74
lines changed

5 files changed

+29
-74
lines changed

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ void showGlobalActionsDialog() {
775775
if (keyguardShowing) {
776776
// since it took two seconds of long press to bring this up,
777777
// poke the wake lock so they have some time to see the dialog.
778-
mKeyguardMediator.pokeWakelock();
778+
mKeyguardMediator.userActivity();
779779
}
780780
}
781781

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void addWidget(AppWidgetHostView view) {
234234

235235
public void userActivity(long timeout) {
236236
if (mViewMediatorCallback != null) {
237-
mViewMediatorCallback.pokeWakelock(timeout);
237+
mViewMediatorCallback.userActivity(timeout);
238238
}
239239
}
240240

@@ -638,7 +638,7 @@ public void wakeWhenReadyTq(int keyCode) {
638638
if (DEBUG) Log.d(TAG, "poking wake lock immediately");
639639
}
640640
if (mViewMediatorCallback != null) {
641-
mViewMediatorCallback.pokeWakelock();
641+
mViewMediatorCallback.wakeUp();
642642
}
643643
}
644644

policy/src/com/android/internal/policy/impl/keyguard/KeyguardSelectorView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void onTrigger(View v, int target) {
7676

7777
case com.android.internal.R.drawable.ic_lockscreen_unlock_phantom:
7878
case com.android.internal.R.drawable.ic_lockscreen_unlock:
79+
mCallback.userActivity(0);
7980
mCallback.dismiss(false);
8081
break;
8182
}
@@ -86,6 +87,7 @@ public void onReleased(View v, int handle) {
8687
}
8788

8889
public void onGrabbed(View v, int handle) {
90+
mCallback.userActivity(0);
8991
doTransition(mFadeView, 0.0f);
9092
}
9193

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ private void maybeCreateKeyguardLocked(boolean enableScreenRotation) {
155155
WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
156156
}
157157
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
158+
lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
159+
lp.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
158160
lp.setTitle(isActivity ? "KeyguardMock" : "Keyguard");
159161
mWindowLayoutParams = lp;
160162
mViewManager.addView(mKeyguardHost, lp);

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java

Lines changed: 22 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public class KeyguardViewMediator {
104104
"com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
105105

106106
// used for handler messages
107-
private static final int TIMEOUT = 1;
108107
private static final int SHOW = 2;
109108
private static final int HIDE = 3;
110109
private static final int RESET = 4;
@@ -166,12 +165,6 @@ public class KeyguardViewMediator {
166165
/** UserManager for querying number of users */
167166
private UserManager mUserManager;
168167

169-
/**
170-
* Used to keep the device awake while the keyguard is showing, i.e for
171-
* calls to {@link #pokeWakelock()}
172-
*/
173-
private PowerManager.WakeLock mWakeLock;
174-
175168
/**
176169
* Used to keep the device awake while to ensure the keyguard finishes opening before
177170
* we sleep.
@@ -215,8 +208,6 @@ public class KeyguardViewMediator {
215208
*/
216209
private int mDelayedShowingSequence;
217210

218-
private int mWakelockSequence;
219-
220211
/**
221212
* If the user has disabled the keyguard, then requests to exit, this is
222213
* how we'll ultimately let them know whether it was successful. We use this
@@ -262,15 +253,16 @@ public class KeyguardViewMediator {
262253
public interface ViewMediatorCallback {
263254

264255
/**
265-
* Request the wakelock to be poked for the default amount of time.
256+
* Wake the device immediately.
266257
*/
267-
void pokeWakelock();
258+
void wakeUp();
268259

269260
/**
270-
* Request the wakelock to be poked for a specific amount of time.
261+
* Reports user activity and requests that the screen stay on for the specified
262+
* amount of time.
271263
* @param millis The amount of time in millis.
272264
*/
273-
void pokeWakelock(long millis);
265+
void userActivity(long millis);
274266

275267
/**
276268
* Report that the keyguard is done.
@@ -402,12 +394,12 @@ public void onSimStateChanged(IccCardConstants.State simState) {
402394
};
403395

404396
ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
405-
public void pokeWakelock() {
406-
KeyguardViewMediator.this.pokeWakelock();
397+
public void wakeUp() {
398+
KeyguardViewMediator.this.wakeUp();
407399
}
408400

409-
public void pokeWakelock(long holdMs) {
410-
KeyguardViewMediator.this.pokeWakelock(holdMs);
401+
public void userActivity(long holdMs) {
402+
KeyguardViewMediator.this.userActivity(holdMs);
411403
}
412404

413405
public void keyguardDone(boolean authenticated) {
@@ -424,19 +416,18 @@ public void setNeedsInput(boolean needsInput) {
424416
}
425417
};
426418

427-
public void pokeWakelock() {
428-
pokeWakelock(AWAKE_INTERVAL_DEFAULT_MS);
419+
public void wakeUp() {
420+
mPM.wakeUp(SystemClock.uptimeMillis());
429421
}
430422

431-
public void pokeWakelock(long holdMs) {
432-
synchronized (this) {
433-
if (DBG_WAKE) Log.d(TAG, "pokeWakelock(" + holdMs + ")");
434-
mWakeLock.acquire();
435-
mHandler.removeMessages(TIMEOUT);
436-
mWakelockSequence++;
437-
Message msg = mHandler.obtainMessage(TIMEOUT, mWakelockSequence, 0);
438-
mHandler.sendMessageDelayed(msg, holdMs);
439-
}
423+
public void userActivity() {
424+
userActivity(AWAKE_INTERVAL_DEFAULT_MS);
425+
}
426+
427+
public void userActivity(long holdMs) {
428+
// We ignore the hold time. Eventually we should remove it.
429+
// Instead, the keyguard window has an explicit user activity timeout set on it.
430+
mPM.userActivity(SystemClock.uptimeMillis(), false);
440431
}
441432

442433
/**
@@ -448,9 +439,6 @@ public KeyguardViewMediator(Context context, LockPatternUtils lockPatternUtils)
448439
mContext = context;
449440
mPM = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
450441
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
451-
mWakeLock = mPM.newWakeLock(
452-
PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "keyguard");
453-
mWakeLock.setReferenceCounted(false);
454442
mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
455443
mShowKeyguardWakeLock.setReferenceCounted(false);
456444

@@ -737,7 +725,6 @@ private void handleSetHidden(boolean isHidden) {
737725
if (mHidden != isHidden) {
738726
mHidden = isHidden;
739727
updateActivityLockScreenState();
740-
adjustUserActivityLocked();
741728
adjustStatusBarLocked();
742729
}
743730
}
@@ -1050,9 +1037,6 @@ public void keyguardDone(boolean authenticated, boolean wakeup) {
10501037
@Override
10511038
public void handleMessage(Message msg) {
10521039
switch (msg.what) {
1053-
case TIMEOUT:
1054-
handleTimeout(msg.arg1);
1055-
return ;
10561040
case SHOW:
10571041
handleShow();
10581042
return ;
@@ -1103,9 +1087,8 @@ private void handleKeyguardDone(boolean wakeup) {
11031087
if (DEBUG) Log.d(TAG, "handleKeyguardDone");
11041088
handleHide();
11051089
if (wakeup) {
1106-
mPM.wakeUp(SystemClock.uptimeMillis());
1090+
wakeUp();
11071091
}
1108-
mWakeLock.release();
11091092

11101093
sendUserPresentBroadcast();
11111094
}
@@ -1137,21 +1120,6 @@ private void handleKeyguardDoneDrawing() {
11371120
}
11381121
}
11391122

1140-
/**
1141-
* Handles the message sent by {@link #pokeWakelock}
1142-
* @param seq used to determine if anything has changed since the message
1143-
* was sent.
1144-
* @see #TIMEOUT
1145-
*/
1146-
private void handleTimeout(int seq) {
1147-
synchronized (KeyguardViewMediator.this) {
1148-
if (DEBUG) Log.d(TAG, "handleTimeout");
1149-
if (seq == mWakelockSequence) {
1150-
mWakeLock.release();
1151-
}
1152-
}
1153-
}
1154-
11551123
private void playSounds(boolean locked) {
11561124
// User feedback for keyguard.
11571125

@@ -1200,8 +1168,8 @@ private void handleShow() {
12001168
mKeyguardViewManager.show();
12011169
mShowing = true;
12021170
updateActivityLockScreenState();
1203-
adjustUserActivityLocked();
12041171
adjustStatusBarLocked();
1172+
userActivity();
12051173
try {
12061174
ActivityManagerNative.getDefault().closeSystemDialogs("lock");
12071175
} catch (RemoteException e) {
@@ -1235,23 +1203,10 @@ private void handleHide() {
12351203
mKeyguardViewManager.hide();
12361204
mShowing = false;
12371205
updateActivityLockScreenState();
1238-
adjustUserActivityLocked();
12391206
adjustStatusBarLocked();
12401207
}
12411208
}
12421209

1243-
private void adjustUserActivityLocked() {
1244-
// disable user activity if we are shown and not hidden
1245-
if (DEBUG) Log.d(TAG, "adjustUserActivityLocked mShowing: " + mShowing + " mHidden: " + mHidden);
1246-
boolean enabled = !mShowing || mHidden;
1247-
// FIXME: Replace this with a new timeout control mechanism.
1248-
//mRealPowerManager.enableUserActivity(enabled);
1249-
if (!enabled && mScreenOn) {
1250-
// reinstate our short screen timeout policy
1251-
pokeWakelock();
1252-
}
1253-
}
1254-
12551210
private void adjustStatusBarLocked() {
12561211
if (mStatusBarManager == null) {
12571212
mStatusBarManager = (StatusBarManager)
@@ -1320,18 +1275,14 @@ private void handleWakeWhenReady(int keyCode) {
13201275
if (!mKeyguardViewManager.wakeWhenReadyTq(keyCode)) {
13211276
// poke wakelock ourselves if keyguard is no longer active
13221277
Log.w(TAG, "mKeyguardViewManager.wakeWhenReadyTq did not poke wake lock, so poke it ourselves");
1323-
pokeWakelock();
1278+
userActivity();
13241279
}
13251280

13261281
/**
13271282
* Now that the keyguard is ready and has poked the wake lock, we can
13281283
* release the handoff wakelock
13291284
*/
13301285
mWakeAndHandOff.release();
1331-
1332-
if (!mWakeLock.isHeld()) {
1333-
Log.w(TAG, "mWakeLock not held in mKeyguardViewManager.wakeWhenReadyTq");
1334-
}
13351286
}
13361287
}
13371288

0 commit comments

Comments
 (0)