From 03d83df18afecdce63d39462c1cc90bb2db735b5 Mon Sep 17 00:00:00 2001 From: wesj Date: Mon, 29 Sep 2014 13:14:39 -0700 Subject: [PATCH] Bug 1072376 - Only set lock screen flags if we're showing on the lockscreen. r=lucasr --- mobile/android/base/BrowserApp.java | 22 +++++++++++++++------- mobile/android/base/GuestSession.java | 9 +++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 287a4481284..b16cc305caf 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -78,8 +78,8 @@ import org.mozilla.gecko.widget.GeckoActionProvider; import android.app.Activity; import android.app.AlertDialog; -import android.content.BroadcastReceiver; import android.app.KeyguardManager; +import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; @@ -521,14 +521,8 @@ public class BrowserApp extends GeckoApp final String args = intent.getStringExtra("args"); if (GuestSession.shouldUse(this, args)) { - GuestSession.configureWindow(getWindow()); mProfile = GeckoProfile.createGuestProfile(this); } else { - // We also allow non-guest sessions if the keyguard isn't a secure one. - final KeyguardManager manager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); - if (Versions.feature16Plus && !manager.isKeyguardSecure()) { - GuestSession.configureWindow(getWindow()); - } GeckoProfile.maybeCleanupGuestProfile(this); } @@ -757,6 +751,7 @@ public class BrowserApp extends GeckoApp final String args = getIntent().getStringExtra("args"); // If an external intent tries to start Fennec in guest mode, and it's not already // in guest mode, this will change modes before opening the url. + // NOTE: OnResume is called twice sometimes when showing on the lock screen. final boolean enableGuestSession = GuestSession.shouldUse(this, args); final boolean inGuestSession = GeckoProfile.get(this).inGuestMode(); if (enableGuestSession != inGuestSession) { @@ -765,6 +760,19 @@ public class BrowserApp extends GeckoApp return; } + final KeyguardManager manager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); + // The test machines return null for the KeyguardService, despite running Android 4.2. + if (Versions.feature11Plus && manager != null) { + // If the keyguard is showing AND we're either in guest mode or the keyguard is insecure, + // allow showing this window. We do this in onResume so that we can avoid setting these flags if the keyguard + // is not showing since it affects Android's layout of the window. + if (manager.isKeyguardLocked() && (GeckoProfile.get(this).inGuestMode() || !manager.isKeyguardSecure())) { + GuestSession.configureWindow(getWindow()); + } else { + GuestSession.unconfigureWindow(getWindow()); + } + } + EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener)this, "Prompt:ShowTop"); } diff --git a/mobile/android/base/GuestSession.java b/mobile/android/base/GuestSession.java index 538346fcdaa..ab952e11539 100644 --- a/mobile/android/base/GuestSession.java +++ b/mobile/android/base/GuestSession.java @@ -73,9 +73,14 @@ public class GuestSession { public static void configureWindow(Window window) { // In guest sessions we allow showing over the keyguard. - window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); - window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); } + + public static void unconfigureWindow(Window window) { + // In guest sessions we allow showing over the keyguard. + window.clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + } + private static PendingIntent getNotificationIntent(Context context) { Intent intent = new Intent(NOTIFICATION_INTENT); intent.setClass(context, BrowserApp.class);