@@ -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