Bug 886123 - Handle locale changes with BroadcastReceiver instead of getLastCustomNonConfigurationInstance(). r=sriram
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 02 Jul 2013 11:36:33 -0700
changeset 137242 c9cc5fb69f073a51eb6776ebb6ad45c69e32c3b9
parent 137241 a081df164311c36876d6d4ccb384eabd79a3b021
child 137243 7099355d3666a3143de09659449b31f49924e81a
push id1824
push userryanvm@gmail.com
push dateWed, 03 Jul 2013 18:16:56 +0000
treeherderfx-team@dcbbfcdf7bb4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs886123
milestone25.0a1
Bug 886123 - Handle locale changes with BroadcastReceiver instead of getLastCustomNonConfigurationInstance(). r=sriram
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoApplication.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1198,19 +1198,22 @@ abstract public class GeckoApp
         sAppContext = this;
         GeckoAppShell.setContextGetter(this);
         GeckoAppShell.setGeckoInterface(this);
         ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
 
         Tabs.getInstance().attachToActivity(this);
         Favicons.getInstance().attachToContext(this);
 
-        // Check to see if the activity is restarted after configuration change.
-        if (getLastCustomNonConfigurationInstance() != null) {
-            // Restart the application as a safe way to handle the configuration change.
+        // When we detect a locale change, we need to restart Gecko, which
+        // actually means restarting the entire application. This logic should
+        // actually be handled elsewhere since GeckoApp may not be alive to
+        // handle this event if "Don't keep activities" is enabled (filed as
+        // bug 889082).
+        if (((GeckoApplication)getApplication()).needsRestart()) {
             doRestart();
             System.exit(0);
             return;
         }
 
         if (sGeckoThread != null) {
             // This happens when the GeckoApp activity is destroyed by Android
             // without killing the entire application (see Bug 769269).
@@ -2079,23 +2082,16 @@ abstract public class GeckoApp
 
         if (mAppStateListeners != null) {
             for (GeckoAppShell.AppStateListener listener: mAppStateListeners) {
                 listener.onConfigurationChanged();
             }
         }
     }
 
-    @Override
-    public Object onRetainCustomNonConfigurationInstance() {
-        // Send a non-null value so that we can restart the application, 
-        // when activity restarts due to configuration change.
-        return Boolean.TRUE;
-    } 
-
     public String getContentProcessName() {
         return AppConstants.MOZ_CHILD_PROCESS_NAME;
     }
 
     public void addEnvToIntent(Intent intent) {
         Map<String,String> envMap = System.getenv();
         Set<Map.Entry<String,String>> envSet = envMap.entrySet();
         Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
--- a/mobile/android/base/GeckoApplication.java
+++ b/mobile/android/base/GeckoApplication.java
@@ -7,22 +7,27 @@ package org.mozilla.gecko;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Application;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 
 public class GeckoApplication extends Application {
 
     private boolean mInited;
     private boolean mInBackground;
     private boolean mPausedGecko;
+    private boolean mNeedsRestart;
 
     private LightweightTheme mLightweightTheme;
 
     protected void initialize() {
         if (mInited)
             return;
 
         // workaround for http://code.google.com/p/android/issues/detail?id=20915
@@ -33,16 +38,24 @@ public class GeckoApplication extends Ap
         mLightweightTheme = new LightweightTheme(this);
 
         GeckoConnectivityReceiver.getInstance().init(getApplicationContext());
         GeckoBatteryManager.getInstance().init(getApplicationContext());
         GeckoBatteryManager.getInstance().start();
         GeckoNetworkManager.getInstance().init(getApplicationContext());
         MemoryMonitor.getInstance().init(getApplicationContext());
 
+        BroadcastReceiver receiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                mNeedsRestart = true;
+            }
+        };
+        registerReceiver(receiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
+
         mInited = true;
     }
 
     protected void onActivityPause(GeckoActivityStatus activity) {
         mInBackground = true;
 
         if ((activity.isFinishing() == false) &&
             (activity.isGeckoActivityOpened() == false)) {
@@ -72,16 +85,20 @@ public class GeckoApplication extends Ap
             mPausedGecko = false;
         }
         GeckoConnectivityReceiver.getInstance().start();
         GeckoNetworkManager.getInstance().start();
 
         mInBackground = false;
     }
 
+    protected boolean needsRestart() {
+        return mNeedsRestart;
+    }
+
     @Override
     public void onCreate() {
         HardwareUtils.init(getApplicationContext());
         Clipboard.init(getApplicationContext());
         GeckoLoader.loadMozGlue(getApplicationContext());
         super.onCreate();
     }