Bug 936756 - Part 4: restore restart-on-locale-change logic. r=mfinkle
authorRichard Newman <rnewman@mozilla.com>
Sun, 01 Dec 2013 21:53:17 -0800
changeset 172853 9cbe6533c48016afb2ec86aa96e0b99dbab0e90e
parent 172852 c46514ce6886b72bc6bce0b40026bfb790a35abc
child 172854 5cb7f65cdcaa0a90bea3fc4a045394bf69358108
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs936756
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 936756 - Part 4: restore restart-on-locale-change logic. r=mfinkle
mobile/android/base/GeckoApp.java
mobile/android/base/LocaleManager.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1188,30 +1188,42 @@ public abstract class GeckoApp
 
                 if (profileName != null || profilePath != null) {
                     mProfile = GeckoProfile.get(this, profileName, profilePath);
                 }
             }
         }
 
         BrowserDB.initialize(getProfile().getName());
-        ((GeckoApplication)getApplication()).initialize();
+        ((GeckoApplication) getApplication()).initialize();
 
         sAppContext = this;
         GeckoAppShell.setContextGetter(this);
         GeckoAppShell.setGeckoInterface(this);
         ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
 
         Tabs.getInstance().attachToContext(this);
         try {
             Favicons.attachToContext(this);
         } catch (Exception e) {
             Log.e(LOGTAG, "Exception starting favicon cache. Corrupt resources?", e);
         }
 
+        // Did the OS locale change while we were backgrounded? If so,
+        // we need to die so that Gecko will re-init add-ons that touch
+        // the UI.
+        // This is using a sledgehammer to crack a nut, but it'll do for
+        // now.
+        if (LocaleManager.systemLocaleDidChange()) {
+            Log.i(LOGTAG, "System locale changed. Restarting.");
+            doRestart();
+            System.exit(0);
+            return;
+        }
+
         if (GeckoThread.isCreated()) {
             // This happens when the GeckoApp activity is destroyed by Android
             // without killing the entire application (see Bug 769269).
             mIsRestoringActivity = true;
             Telemetry.HistogramAdd("FENNEC_RESTORING_ACTIVITY", 1);
         }
 
         // Fix for Bug 830557 on Tegra boards running Froyo.
@@ -1280,16 +1292,17 @@ public abstract class GeckoApp
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 final SharedPreferences prefs = GeckoApp.getAppSharedPreferences();
 
                 // Wait until now to set this, because we'd rather throw an exception than 
                 // have a caller of LocaleManager regress startup.
                 LocaleManager.setContextGetter(GeckoApp.this);
+                LocaleManager.initialize();
 
                 SessionInformation previousSession = SessionInformation.fromSharedPrefs(prefs);
                 if (previousSession.wasKilled()) {
                     Telemetry.HistogramAdd("FENNEC_WAS_KILLED", 1);
                 }
 
                 SharedPreferences.Editor editor = prefs.edit();
                 editor.putBoolean(GeckoApp.PREFS_OOM_EXCEPTION, false);
--- a/mobile/android/base/LocaleManager.java
+++ b/mobile/android/base/LocaleManager.java
@@ -1,16 +1,19 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.util.Log;
 
 import java.util.Locale;
 
 /**
@@ -31,20 +34,43 @@ import java.util.Locale;
 public class LocaleManager {
     private static final String LOG_TAG = "GeckoLocales";
 
     // These are both volatile because we don't impose restrictions
     // over which thread calls our methods.
     private static volatile ContextGetter getter = null;
     private static volatile Locale currentLocale = null;
 
+    private static volatile boolean inited = false;
+    private static boolean systemLocaleDidChange = false;
+    private static BroadcastReceiver receiver;
+
     public static void setContextGetter(ContextGetter getter) {
         LocaleManager.getter = getter;
     }
 
+    public static void initialize() {
+        if (inited) {
+            return;
+        }
+
+        receiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                systemLocaleDidChange = true;
+            }
+        };
+        getContext().registerReceiver(receiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
+        inited = true;
+    }
+
+    public static boolean systemLocaleDidChange() {
+        return systemLocaleDidChange;
+    }
+
     private static Context getContext() {
         if (getter == null) {
             throw new IllegalStateException("No ContextGetter; cannot fetch context.");
         }
         return getter.getContext();
     }
 
     private static SharedPreferences getSharedPreferences() {