Fix camera app still opens the camera in lock screen sometimes.
Suppose camera app is in the foreground. If users turn off and turn
on the screen very fast, camera app can still have the focus when the
lock screen shows up. Now the camera app will not open the camera as
long as screen is locked.
bug:5491362
Change-Id: Idf2a1b160c94abb889729e0525c9903b62f12dd0
diff --git a/src/com/android/camera/ActivityBase.java b/src/com/android/camera/ActivityBase.java
index b2ef481..439f830 100644
--- a/src/com/android/camera/ActivityBase.java
+++ b/src/com/android/camera/ActivityBase.java
@@ -61,11 +61,16 @@
// Don't grab the camera if in use by lockscreen. For example, face
// unlock may be using the camera. Camera may be already opened in
// onCreate. doOnResume should continue if mCameraDevice != null.
- if (mCameraDevice == null && !hasWindowFocus() && isKeyguardLocked()) {
- if (LOGV) Log.v(TAG, "onRsume. mOnResumePending=true");
+ // Suppose camera app is in the foreground. If users turn off and turn
+ // on the screen very fast, camera app can still have the focus when the
+ // lock screen shows up. The keyguard takes input focus, so the caemra
+ // app will lose focus when it is displayed.
+ if (LOGV) Log.v(TAG, "onResume. hasWindowFocus()=" + hasWindowFocus());
+ if (mCameraDevice == null && isKeyguardLocked()) {
+ if (LOGV) Log.v(TAG, "onResume. mOnResumePending=true");
mOnResumePending = true;
} else {
- if (LOGV) Log.v(TAG, "onRsume. mOnResumePending=false");
+ if (LOGV) Log.v(TAG, "onResume. mOnResumePending=false");
doOnResume();
mOnResumePending = false;
}
@@ -124,6 +129,12 @@
private boolean isKeyguardLocked() {
KeyguardManager kgm = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
+ if (LOGV) {
+ if (kgm != null) {
+ Log.v(TAG, "kgm.isKeyguardLocked()="+kgm.isKeyguardLocked()
+ + ". kgm.isKeyguardSecure()="+kgm.isKeyguardSecure());
+ }
+ }
// isKeyguardSecure excludes the slide lock case.
return (kgm != null) && kgm.isKeyguardLocked() && kgm.isKeyguardSecure();
}