diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 5501f2efdb1..2667dc0991a 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -191,7 +191,7 @@ public class BrowserApp extends GeckoApp public boolean added; // So we can re-add after a locale change. } - // The types of guest mdoe dialogs we show + // The types of guest mode dialogs we show. public static enum GuestModeDialog { ENTERING, LEAVING @@ -673,13 +673,6 @@ public class BrowserApp extends GeckoApp Log.e(LOGTAG, "Error initializing media manager", ex); } } - - if (getProfile().inGuestMode()) { - GuestSession.showNotification(this); - } else { - // If we're restarting, we won't destroy the activity. Make sure we remove any guest notifications that might have been shown. - GuestSession.hideNotification(this); - } } private void setupSystemUITinting() { @@ -790,6 +783,35 @@ public class BrowserApp extends GeckoApp lbm.unregisterReceiver(mOnboardingReceiver); } + @Override + public void onStart() { + super.onStart(); + + // Queue this work so that the first launch of the activity doesn't + // trigger profile init too early. + ThreadUtils.postToBackgroundThread(new Runnable() { + @Override + public void run() { + if (getProfile().inGuestMode()) { + GuestSession.showNotification(BrowserApp.this); + } else { + // If we're restarting, we won't destroy the activity. + // Make sure we remove any guest notifications that might + // have been shown. + GuestSession.hideNotification(BrowserApp.this); + } + } + }); + } + + @Override + public void onStop() { + super.onStop(); + + // We only show the guest mode notification when our activity is in the foreground. + GuestSession.hideNotification(this); + } + @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); @@ -1087,8 +1109,6 @@ public class BrowserApp extends GeckoApp mBrowserHealthReporter = null; } - GuestSession.onDestroy(this); - EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener)this, "Menu:Update", "Reader:Added", @@ -2939,6 +2959,9 @@ public class BrowserApp extends GeckoApp args = GUEST_BROWSING_ARG; } else { GeckoProfile.leaveGuestSession(BrowserApp.this); + + // Now's a good time to make sure we're not displaying the Guest Browsing notification. + GuestSession.hideNotification(BrowserApp.this); } if (!GuestSession.isSecureKeyguardLocked(BrowserApp.this)) { diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index d5277486de4..d0bd802c91d 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -9,7 +9,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -45,7 +44,6 @@ import org.mozilla.gecko.mozglue.GeckoLoader; import org.mozilla.gecko.preferences.ClearOnShutdownPref; import org.mozilla.gecko.preferences.GeckoPreferences; import org.mozilla.gecko.prompts.PromptService; -import org.mozilla.gecko.SmsManager; import org.mozilla.gecko.updater.UpdateService; import org.mozilla.gecko.updater.UpdateServiceHelper; import org.mozilla.gecko.util.ActivityResultHandler; @@ -443,6 +441,9 @@ public abstract class GeckoApp @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.quit) { + // Make sure the Guest Browsing notification goes away when we quit. + GuestSession.hideNotification(this); + if (GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.GeckoRunning, GeckoThread.LaunchState.GeckoExiting)) { final SharedPreferences prefs = GeckoSharedPrefs.forProfile(this); final Set clearSet = PrefUtils.getStringSet(prefs, ClearOnShutdownPref.PREF, new HashSet()); diff --git a/mobile/android/base/GuestSession.java b/mobile/android/base/GuestSession.java index ab952e11539..8b2cf832b4d 100644 --- a/mobile/android/base/GuestSession.java +++ b/mobile/android/base/GuestSession.java @@ -4,29 +4,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.gecko; -import android.app.NotificationManager; import android.app.KeyguardManager; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.res.Resources; -import android.net.Uri; -import android.util.Log; +import android.support.v4.app.NotificationCompat; import android.view.Window; import android.view.WindowManager; -import android.widget.ListView; -import android.support.v4.app.NotificationCompat; - -import org.mozilla.gecko.prompts.Prompt; -import org.mozilla.gecko.util.EventCallback; -import org.mozilla.gecko.util.NativeEventListener; -import org.mozilla.gecko.util.NativeJSObject; -import org.mozilla.gecko.util.ThreadUtils; - -import java.io.File; - -import org.json.JSONException; -import org.json.JSONObject; // Utility methods for entering/exiting guest mode. public class GuestSession { @@ -105,12 +91,6 @@ public class GuestSession { manager.cancel(R.id.guestNotification); } - public static void onDestroy(Context context) { - if (GeckoProfile.get(context).inGuestMode()) { - hideNotification(context); - } - } - public static void handleIntent(BrowserApp context, Intent intent) { context.showGuestModeDialog(BrowserApp.GuestModeDialog.LEAVING); }