Bug 1551614 - Call BrowserApp's onCreate() before finish(); r=VladBaicu
authorPetru Lingurar <petru.lingurar@softvision.ro>
Fri, 21 Jun 2019 06:24:43 +0000
changeset 539442 819d3061b8fb3cbc3143ac68e8f521b7e32f362c
parent 539425 b8c319d5968f957d34e359829690614a9b69b95a
child 539443 0e1180cd2a89aa974ae7190839631249727cfca4
push id11522
push userffxbld-merge
push dateMon, 01 Jul 2019 09:00:55 +0000
treeherdermozilla-beta@53ea74d2bd09 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu
bugs1551614
milestone69.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 1551614 - Call BrowserApp's onCreate() before finish(); r=VladBaicu Fix for the following scenario: - "Don't keep activities" checked - Change system language Upon detecting a locale change in BrowserApp's onCreate() we would call finish() and then return before calling super.onCreate(). This patch introdues the call to super.onCreate() before returning and ensures that the app will die cleanly so that upon restarting Gecko can reinit add-ons that touch the UI. Differential Revision: https://phabricator.services.mozilla.com/D35402
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -1017,17 +1017,23 @@ public abstract class GeckoApp extends G
         // the UI.
         // This is using a sledgehammer to crack a nut, but it'll do for
         // now.
         // Our OS locale pref will be detected as invalid after the
         // restart, and will be propagated to Gecko accordingly, so there's
         // no need to touch that here.
         if (BrowserLocaleManager.getInstance().systemLocaleDidChange()) {
             Log.i(LOGTAG, "System locale changed. Restarting.");
+
+            mIsAbortingAppLaunch = true;
+
+            // Call finish() asap so that other classes would know BrowserApp isFinishing()
             finishAndShutdown(/* restart */ true);
+            super.onCreate(savedInstanceState);
+
             return;
         }
 
         // To prevent races, register startup events before launching the Gecko thread.
         EventDispatcher.getInstance().registerGeckoThreadListener(this,
                 "Gecko:Ready",
                 null);
 
@@ -2114,16 +2120,22 @@ public abstract class GeckoApp extends G
     }
 
     @Override
     public void onDestroy() {
         if (mIsAbortingAppLaunch) {
             // This build does not support the Android version of the device:
             // We did not initialize anything, so skip cleaning up.
             super.onDestroy();
+
+            if (mShutdownOnDestroy) {
+                GeckoApplication.shutdown(!mRestartOnShutdown ? null : new Intent(
+                        Intent.ACTION_MAIN, /* uri */ null, getApplicationContext(), getClass()));
+            }
+
             return;
         }
 
         if (mFormAssistPopup != null) {
             mFormAssistPopup.destroy();
             mFormAssistPopup = null;
         }
 
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -9,16 +9,17 @@ import android.accounts.Account;
 import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.support.annotation.UiThread;
+import android.support.v4.app.FragmentActivity;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.widget.DefaultItemAnimator;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.text.SpannableStringBuilder;
 import android.text.TextPaint;
@@ -107,16 +108,25 @@ public class CombinedHistoryPanel extend
          */
         boolean changeLevel(PanelLevel level);
     }
 
     @Override
     public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
 
+        // BrowserApp's super.onCreate() as a FragmentActivity would dispatchCreate()
+        // for all fragments in it's savedInstanceState. This Fragment will be created.
+        // When BrowserApp does not complete it's onCreate() - like when finishing early and restarting
+        // our onCreate would try to access not yet initialized resources and would get a NPE.
+        final FragmentActivity parent = getActivity();
+        if (parent != null && parent.isFinishing()) {
+            return;
+        }
+
         int cachedRecentTabsCount = 0;
         if (mPanelStateChangeListener != null ) {
             cachedRecentTabsCount = mPanelStateChangeListener.getCachedRecentTabsCount();
         }
         mHistoryAdapter = new CombinedHistoryAdapter(getResources(), cachedRecentTabsCount);
         if (mPanelStateChangeListener != null) {
             mHistoryAdapter.setPanelStateChangeListener(mPanelStateChangeListener);
         }