Bug 1546889 - Refresh Settings layout if default browser was changed while in background; r=petru
authordiana.iacos <diana.iacos@softvision.ro>
Thu, 25 Apr 2019 13:59:49 +0000
changeset 530224 181f0144ce7aa2b434675baca3dbcc3dd22f016d
parent 530223 e97cf660ef3c6dfafa042fccc3bfcc6607e8c3eb
child 530225 510c23dc30c614f2fabc4759d187737c5232e9fe
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1546889
milestone68.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 1546889 - Refresh Settings layout if default browser was changed while in background; r=petru Handle 2 specific edge-cases: - The user presses to change default browser, when he returns to the app the app settings button to do so should not be displayed anymore. - With the app in background showing the app settings the user changes to a different default browser. When resuming the app it should show the option to set Fennec as default. All this without otherwise requiring the user to close app settings and opening them again. Depends on D28831 Differential Revision: https://phabricator.services.mozilla.com/D28832
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferenceFragment.java
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferenceFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferenceFragment.java
@@ -13,25 +13,27 @@ import org.mozilla.gecko.GeckoSharedPref
 import org.mozilla.gecko.LocaleManager;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
 import org.mozilla.gecko.fxa.AccountLoader;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
+import org.mozilla.gecko.util.PackageUtil;
 
 import android.accounts.Account;
 import android.app.Activity;
 import android.app.LoaderManager;
 import android.content.Context;
 import android.content.Loader;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Bundle;
+import android.preference.Preference;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 
 /* A simple implementation of PreferenceFragment for large screen devices
  * This will strip category headers (so that they aren't shown to the user twice)
@@ -63,36 +65,17 @@ public class GeckoPreferenceFragment ext
     private Locale lastLocale = Locale.getDefault();
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         // Write prefs to our custom GeckoSharedPrefs file.
         getPreferenceManager().setSharedPreferencesName(GeckoSharedPrefs.APP_PREFS_NAME);
-
-        int res = getResource();
-        if (res == R.xml.preferences) {
-            Telemetry.startUISession(TelemetryContract.Session.SETTINGS);
-        } else {
-            final String resourceName = getArguments().getString("resource");
-            Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, resourceName);
-        }
-
-        // Display a menu for Search preferences.
-        if (res == R.xml.preferences_search) {
-            setHasOptionsMenu(true);
-        }
-
-        addPreferencesFromResource(res);
-
-        PreferenceScreen screen = getPreferenceScreen();
-        setPreferenceScreen(screen);
-        mPrefsRequest = ((GeckoPreferences)getActivity()).setupPreferences(screen);
-        syncPreference = (SyncPreference) findPreference(GeckoPreferences.PREFS_SYNC);
+        loadPreferences();
     }
 
     /**
      * Return the title to use for this preference fragment.
      *
      * The result will be used to set the title that you see on non-multi-pane devices.
      */
     private String getTitle() {
@@ -181,16 +164,46 @@ public class GeckoPreferenceFragment ext
         // This is a little delicate. Ensure that you do nothing prior to
         // super.onResume that you wouldn't do in onCreate.
         // This will also set the title in the parent activity's ActionBar to the title of the current PreferenceScreen
         applyLocale(Locale.getDefault());
         super.onResume();
 
         // Force reload as the account may have been deleted while the app was in background.
         getLoaderManager().restartLoader(ACCOUNT_LOADER_ID, null, accountLoaderCallbacks);
+
+        PreferenceScreen screen = getPreferenceScreen();
+
+        Preference defaultBrowser = screen.findPreference(GeckoPreferences.PREFS_DEFAULT_BROWSER);
+        if (defaultBrowser == null && !PackageUtil.isDefaultBrowser(this.getActivity().getBaseContext())) {
+            // force a reload of all preferences to add/remove the default browser one if conditions were changed while the app was backgrounded
+            getPreferenceScreen().removeAll();
+            loadPreferences();
+        }
+
+        setPreferenceScreen(screen);
+        mPrefsRequest = ((GeckoPreferences)getActivity()).setupPreferences(screen);
+        syncPreference = (SyncPreference) findPreference(GeckoPreferences.PREFS_SYNC);
+    }
+
+    private void loadPreferences() {
+        int res = getResource();
+        if (res == R.xml.preferences) {
+            Telemetry.startUISession(TelemetryContract.Session.SETTINGS);
+        } else {
+            final String resourceName = getArguments().getString("resource");
+            Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, resourceName);
+        }
+
+        // Display a menu for Search preferences.
+        if (res == R.xml.preferences_search) {
+            setHasOptionsMenu(true);
+        }
+
+        addPreferencesFromResource(res);
     }
 
     private void applyLocale(final Locale currentLocale) {
         final Context context = getActivity().getApplicationContext();
 
         BrowserLocaleManager.getInstance().updateConfiguration(context, currentLocale);
 
         if (!currentLocale.equals(lastLocale)) {