summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/keyguard
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2015-05-27 15:39:09 -0700
committerJorim Jaggi <jjaggi@google.com>2015-05-30 00:41:07 +0000
commitd175b6cfe0b35dfe251cc9315aacb048bf6e54c5 (patch)
tree171a563eb7be27948dcd330037ef9e5cd6a0393a /packages/SystemUI/src/com/android/systemui/keyguard
parentcb81d183672a3d9858ade10a997990c5d66a1be3 (diff)
downloadframeworks_base-d175b6cfe0b35dfe251cc9315aacb048bf6e54c5.zip
frameworks_base-d175b6cfe0b35dfe251cc9315aacb048bf6e54c5.tar.gz
frameworks_base-d175b6cfe0b35dfe251cc9315aacb048bf6e54c5.tar.bz2
Cleanup Keyguard handling when turning off screen
Before, Keyguard was shown whenever PhoneWindowManager went to sleep. However, this was too early on some devices, and too late on others. Now, the callbacks are split up into two phases: startedGoingToSleep and finishedGoingToSleep. In the first callback, we decide what to do and play the lock sound if necessary. In the second callback, we actually show the Keyguard, or reset its state necessary, so it doesn't interfere with the screen off animation. Bug: 17929748 Bug: 20782303 Change-Id: I4c4406595b07b7589d64f380cd3fa96bed3d20ee
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/keyguard')
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java14
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java102
2 files changed, 68 insertions, 48 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
index 73fa2ed..98558b4 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
@@ -108,15 +108,21 @@ public class KeyguardService extends Service {
}
@Override // Binder interface
- public void onScreenTurnedOff(int reason) {
+ public void onStartedGoingToSleep(int reason) {
checkPermission();
- mKeyguardViewMediator.onScreenTurnedOff(reason);
+ mKeyguardViewMediator.onStartedGoingToSleep(reason);
}
@Override // Binder interface
- public void onScreenTurnedOn(IKeyguardShowCallback callback) {
+ public void onFinishedGoingToSleep(int reason) {
checkPermission();
- mKeyguardViewMediator.onScreenTurnedOn(callback);
+ mKeyguardViewMediator.onFinishedGoingToSleep(reason);
+ }
+
+ @Override // Binder interface
+ public void onStartedWakingUp(IKeyguardShowCallback callback) {
+ checkPermission();
+ mKeyguardViewMediator.onStartedWakingUp(callback);
}
@Override // Binder interface
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 74962ec..bc42105 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -188,11 +188,6 @@ public class KeyguardViewMediator extends SystemUI {
private boolean mBootCompleted;
private boolean mBootSendUserPresent;
- // Whether the next call to playSounds() should be skipped. Defaults to
- // true because the first lock (on boot) should be silent.
- private boolean mSuppressNextLockSound = true;
-
-
/** High level access to the power manager for WakeLocks */
private PowerManager mPM;
@@ -255,7 +250,7 @@ public class KeyguardViewMediator extends SystemUI {
private KeyguardUpdateMonitor mUpdateMonitor;
- private boolean mScreenOn;
+ private boolean mDeviceInteractive;
// last known state of the cellular connection
private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
@@ -306,6 +301,18 @@ public class KeyguardViewMediator extends SystemUI {
private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
+ /**
+ * When starting going to sleep, we figured out that we need to reset Keyguard state and this
+ * should be committed when finished going to sleep.
+ */
+ private boolean mPendingReset;
+
+ /**
+ * When starting goign to sleep, we figured out that we need to lock Keyguard and this should be
+ * committed when finished going to sleep.
+ */
+ private boolean mPendingLock;
+
KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
@Override
@@ -341,7 +348,7 @@ public class KeyguardViewMediator extends SystemUI {
public void onPhoneStateChanged(int phoneState) {
synchronized (KeyguardViewMediator.this) {
if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
- && !mScreenOn // screen off
+ && !mDeviceInteractive // screen off
&& mExternallyEnabled) { // not disabled by any app
// note: this is a way to gracefully reenable the keyguard when the call
@@ -514,7 +521,7 @@ public class KeyguardViewMediator extends SystemUI {
@Override
public boolean isScreenOn() {
- return mScreenOn;
+ return mDeviceInteractive;
}
};
@@ -550,7 +557,7 @@ public class KeyguardViewMediator extends SystemUI {
mViewMediatorCallback, mLockPatternUtils);
final ContentResolver cr = mContext.getContentResolver();
- mScreenOn = mPM.isScreenOn();
+ mDeviceInteractive = mPM.isInteractive();
mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
@@ -613,23 +620,18 @@ public class KeyguardViewMediator extends SystemUI {
* @param why either {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_USER} or
* {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT}.
*/
- public void onScreenTurnedOff(int why) {
+ public void onStartedGoingToSleep(int why) {
+ if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
synchronized (this) {
- mScreenOn = false;
- if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")");
-
- resetKeyguardDonePendingLocked();
- mHideAnimationRun = false;
+ mDeviceInteractive = false;
// Lock immediately based on setting if secure (user has a pin/pattern/password).
// This also "locks" the device when not secure to provide easy access to the
// camera while preventing unwanted input.
int currentUser = KeyguardUpdateMonitor.getCurrentUser();
final boolean lockImmediately =
- mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
- || !mLockPatternUtils.isSecure(currentUser);
-
- notifyScreenOffLocked();
+ mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
+ || !mLockPatternUtils.isSecure(currentUser);
if (mExitSecureCallback != null) {
if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
@@ -643,12 +645,37 @@ public class KeyguardViewMediator extends SystemUI {
hideLocked();
}
} else if (mShowing) {
- resetStateLocked();
+ mPendingReset = true;
} else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
- || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
+ || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
doKeyguardLaterLocked();
- } else {
+ } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
+ mPendingLock = true;
+ }
+
+ if (mPendingLock || mPendingReset) {
+ playSounds(true);
+ }
+ }
+ }
+
+ public void onFinishedGoingToSleep(int why) {
+ if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
+ synchronized (this) {
+ mDeviceInteractive = false;
+
+ resetKeyguardDonePendingLocked();
+ mHideAnimationRun = false;
+
+ notifyScreenOffLocked();
+
+ if (mPendingReset) {
+ resetStateLocked();
+ mPendingReset = false;
+ }
+ if (mPendingLock) {
doKeyguardLocked(null);
+ mPendingLock = false;
}
}
KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOff(why);
@@ -686,7 +713,6 @@ public class KeyguardViewMediator extends SystemUI {
if (timeout <= 0) {
// Lock now
- mSuppressNextLockSound = true;
doKeyguardLocked(null);
} else {
// Lock in the future
@@ -706,13 +732,15 @@ public class KeyguardViewMediator extends SystemUI {
}
/**
- * Let's us know the screen was turned on.
+ * Let's us know when the device is waking up.
*/
- public void onScreenTurnedOn(IKeyguardShowCallback callback) {
+ public void onStartedWakingUp(IKeyguardShowCallback callback) {
+
+ // TODO: Rename all screen off/on references to interactive/sleeping
synchronized (this) {
- mScreenOn = true;
+ mDeviceInteractive = true;
cancelDoKeyguardLaterLocked();
- if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence);
+ if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
if (callback != null) {
notifyScreenOnLocked(callback);
}
@@ -737,7 +765,8 @@ public class KeyguardViewMediator extends SystemUI {
*/
public void onDreamingStarted() {
synchronized (this) {
- if (mScreenOn && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
+ if (mDeviceInteractive
+ && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
doKeyguardLaterLocked();
}
}
@@ -748,7 +777,7 @@ public class KeyguardViewMediator extends SystemUI {
*/
public void onDreamingStopped() {
synchronized (this) {
- if (mScreenOn) {
+ if (mDeviceInteractive) {
cancelDoKeyguardLaterLocked();
}
}
@@ -1100,8 +1129,6 @@ public class KeyguardViewMediator extends SystemUI {
+ sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
synchronized (KeyguardViewMediator.this) {
if (mDelayedShowingSequence == sequence) {
- // Don't play lockscreen SFX if the screen went off due to timeout.
- mSuppressNextLockSound = true;
doKeyguardLocked(null);
}
}
@@ -1252,13 +1279,6 @@ public class KeyguardViewMediator extends SystemUI {
}
private void playSounds(boolean locked) {
- // User feedback for keyguard.
-
- if (mSuppressNextLockSound) {
- mSuppressNextLockSound = false;
- return;
- }
-
playSound(locked ? mLockSoundId : mUnlockSoundId);
}
@@ -1283,9 +1303,6 @@ public class KeyguardViewMediator extends SystemUI {
}
private void playTrustedSound() {
- if (mSuppressNextLockSound) {
- return;
- }
playSound(mTrustedSoundId);
}
@@ -1318,9 +1335,6 @@ public class KeyguardViewMediator extends SystemUI {
adjustStatusBarLocked();
userActivity();
- // Do this at the end to not slow down display of the keyguard.
- playSounds(true);
-
mShowKeyguardWakeLock.release();
}
mKeyguardDisplayManager.show();