Bug 896281 - Part 2: Remove Sync pref for guest session. r=wesj, a=akeybl
authorBrian Nicholson <bnicholson@mozilla.com>
Thu, 19 Sep 2013 13:40:48 -0400
changeset 160385 8de790b4863acaca0f8012bea80c11049e40c544
parent 160384 2ac0639bf26733ded42f0ef6765a9613f81bb776
child 160386 51cf3d1d796826459f1c80e819e2cc7927e8549b
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj, akeybl
bugs896281
milestone26.0a2
Bug 896281 - Part 2: Remove Sync pref for guest session. r=wesj, a=akeybl
mobile/android/base/GeckoPreferences.java
mobile/android/base/GeckoProfile.java
mobile/android/base/resources/xml-v11/preferences.xml
mobile/android/base/resources/xml-v11/preferences_customize_tablet.xml
mobile/android/base/resources/xml/preferences.xml.in
--- a/mobile/android/base/GeckoPreferences.java
+++ b/mobile/android/base/GeckoPreferences.java
@@ -72,16 +72,17 @@ public class GeckoPreferences
     private static String PREFS_CRASHREPORTER_ENABLED = "datareporting.crashreporter.submitEnabled";
     private static String PREFS_MENU_CHAR_ENCODING = "browser.menu.showCharacterEncoding";
     private static String PREFS_MP_ENABLED = "privacy.masterpassword.enabled";
     private static String PREFS_UPDATER_AUTODOWNLOAD = "app.update.autodownload";
     private static String PREFS_GEO_REPORTING = "app.geo.reportdata";
     private static String PREFS_HEALTHREPORT_LINK = NON_PREF_PREFIX + "healthreport.link";
     private static String PREFS_DEVTOOLS_REMOTE_ENABLED = "devtools.debugger.remote-enabled";
     private static String PREFS_DISPLAY_REFLOW_ON_ZOOM = "browser.zoom.reflowOnZoom";
+    private static String PREFS_SYNC = NON_PREF_PREFIX + "sync";
 
     public static String PREFS_RESTORE_SESSION = NON_PREF_PREFIX + "restoreSession3";
 
     // These values are chosen to be distinct from other Activity constants.
     private static int REQUEST_CODE_PREF_SCREEN = 5;
     private static int RESULT_CODE_EXIT_SETTINGS = 6;
 
     @Override
@@ -337,16 +338,21 @@ public class GeckoPreferences
                     // Set the summary string to the current entry. The summary
                     // for other list prefs will be set in the PrefsHelper
                     // callback, but since this pref doesn't live in Gecko, we
                     // need to handle it separately.
                     ListPreference listPref = (ListPreference) pref;
                     CharSequence selectedEntry = listPref.getEntry();
                     listPref.setSummary(selectedEntry);
                     continue;
+                } else if (PREFS_SYNC.equals(key) && GeckoProfile.get(this).inGuestMode()) {
+                    // Don't show sync prefs while in guest mode.
+                    preferences.removePreference(pref);
+                    i--;
+                    continue;
                 }
 
                 // Some Preference UI elements are not actually preferences,
                 // but they require a key to work correctly. For example,
                 // "Clear private data" requires a key for its state to be
                 // saved when the orientation changes. It uses the
                 // "android.not_a_preference.privacy.clear" key - which doesn't
                 // exist in Gecko - to satisfy this requirement.
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -61,23 +61,25 @@ public final class GeckoProfile {
 
     public static GeckoProfile get(Context context) {
         if (context instanceof GeckoApp) {
             // Check for a cached profile on this context already
             // TODO: We should not be caching profile information on the Activity context
             if (((GeckoApp)context).mProfile != null) {
                 return ((GeckoApp)context).mProfile;
             }
+        }
 
-            GeckoProfile guest = GeckoProfile.getGuestProfile(context);
-            // if the guest profile is locked, return it
-            if (guest != null && guest.locked()) {
-                return guest;
-            }
+        // If the guest profile exists and is locked, return it
+        GeckoProfile guest = GeckoProfile.getGuestProfile(context);
+        if (guest != null && guest.locked()) {
+            return guest;
+        }
 
+        if (context instanceof GeckoApp) {
             // Otherwise, get the default profile for the Activity
             return get(context, ((GeckoApp)context).getDefaultProfileName());
         }
 
         return get(context, "");
     }
 
     public static GeckoProfile get(Context context, String profileName) {
--- a/mobile/android/base/resources/xml-v11/preferences.xml
+++ b/mobile/android/base/resources/xml-v11/preferences.xml
@@ -6,17 +6,18 @@
 <!-- Phone v11+ only: Sync is a top-level menu item.
      See xml-v11/preference_headers.xml for tablet layout.
      Preference changes here should be mirrored to xml/preferences.xml.in. -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                   xmlns:gecko="http://schemas.android.com/apk/res-auto"
                   android:enabled="false">
 
-    <org.mozilla.gecko.SyncPreference android:title="@string/pref_sync"
+    <org.mozilla.gecko.SyncPreference android:key="android.not_a_preference.sync"
+                                      android:title="@string/pref_sync"
                                       android:persistent="false" />
 
     <PreferenceScreen android:title="@string/pref_category_customize"
                       android:fragment="org.mozilla.gecko.GeckoPreferenceFragment" >
         <extra android:name="resource"
                android:value="preferences_customize"/>
     </PreferenceScreen>
 
--- a/mobile/android/base/resources/xml-v11/preferences_customize_tablet.xml
+++ b/mobile/android/base/resources/xml-v11/preferences_customize_tablet.xml
@@ -7,17 +7,18 @@
      See xml-v11/preferences.xml for single-pane v11+ phone layout.
      Changes to preferences shoudl be mirrored to preferences_customize.xml. -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                   xmlns:gecko="http://schemas.android.com/apk/res-auto"
                   android:title="@string/pref_category_customize"
                   android:enabled="false">
 
-    <org.mozilla.gecko.SyncPreference android:title="@string/pref_sync"
+    <org.mozilla.gecko.SyncPreference android:key="android.not_a_preference.sync"
+                                      android:title="@string/pref_sync"
                                       android:persistent="false" />
 
     <PreferenceScreen android:title="@string/pref_category_search"
                       android:fragment="org.mozilla.gecko.GeckoPreferenceFragment" >
         <extra android:name="resource"
                android:value="preferences_search"/>
     </PreferenceScreen>
 
--- a/mobile/android/base/resources/xml/preferences.xml.in
+++ b/mobile/android/base/resources/xml/preferences.xml.in
@@ -7,17 +7,18 @@
 <!-- Preferences screen for pre-v11 Android devices that do not support
      PreferenceFragment or ActionBar. Preference changes here should be mirrored
      to xml-v11/preferences.xml. -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                   xmlns:gecko="http://schemas.android.com/apk/res-auto"
                   android:enabled="false">
 
-    <org.mozilla.gecko.SyncPreference android:title="@string/pref_sync"
+    <org.mozilla.gecko.SyncPreference android:key="android.not_a_preference.sync"
+                                      android:title="@string/pref_sync"
                                       android:persistent="false" />
 
     <PreferenceScreen android:title="@string/pref_category_customize" >
         <intent android:action="android.intent.action.VIEW"
                 android:targetPackage="@ANDROID_PACKAGE_NAME@"
                 android:targetClass="org.mozilla.gecko.GeckoPreferences" >
             <extra
                 android:name="resource"