Bug 1189336 - (Part 4) Migrate old restrictions if needed. r=ally
authorSebastian Kaspari <s.kaspari@gmail.com>
Tue, 17 Nov 2015 15:28:40 +0100
changeset 274484 2a711953a62c00ee3ddc753592ccffac7876c966
parent 274483 6d38b37d27a44859fcda808e8c7f17980da88376
child 274485 958669938c10f37112896f1f47e8ed8074c1495d
push id29733
push usercbook@mozilla.com
push dateMon, 30 Nov 2015 12:16:19 +0000
treeherdermozilla-central@2d385f1302a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersally
bugs1189336
milestone45.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 1189336 - (Part 4) Migrate old restrictions if needed. r=ally
mobile/android/base/restrictions/RestrictedProfileConfiguration.java
mobile/android/base/restrictions/RestrictionProvider.java
--- a/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
+++ b/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
@@ -56,20 +56,21 @@ public class RestrictedProfileConfigurat
     }
 
     private void readRestrictions() {
         final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
 
         StrictMode.ThreadPolicy policy = StrictMode.allowThreadDiskReads();
 
         try {
-            cachedAppRestrictions = mgr.getApplicationRestrictions(context.getPackageName());
+            Bundle appRestrictions = mgr.getApplicationRestrictions(context.getPackageName());
+            migrateRestrictionsIfNeeded(appRestrictions);
+
+            cachedAppRestrictions = appRestrictions;
             cachedUserRestrictions = mgr.getUserRestrictions();
-
-
         } finally {
             StrictMode.setThreadPolicy(policy);
         }
     }
 
     @Override
     public boolean canLoadUrl(String url) {
         if (!isAllowed(Restrictable.INSTALL_EXTENSION) && AboutPages.isAboutAddons(url)) {
@@ -92,9 +93,42 @@ public class RestrictedProfileConfigurat
     public boolean isRestricted() {
         return true;
     }
 
     @Override
     public synchronized void update() {
         isCacheInvalid = true;
     }
-}
\ No newline at end of file
+
+    /**
+     * This method migrates the old set of DISALLOW_ restrictions to the new restrictable feature ones (Bug 1189336).
+     */
+    public static void migrateRestrictionsIfNeeded(Bundle bundle) {
+        if (!bundle.containsKey(Restrictable.INSTALL_EXTENSION.name) && bundle.containsKey("no_install_extensions")) {
+            bundle.putBoolean(Restrictable.INSTALL_EXTENSION.name, !bundle.getBoolean("no_install_extensions"));
+        }
+
+        if (!bundle.containsKey(Restrictable.PRIVATE_BROWSING.name) && bundle.containsKey("no_private_browsing")) {
+            bundle.putBoolean(Restrictable.PRIVATE_BROWSING.name, !bundle.getBoolean("no_private_browsing"));
+        }
+
+        if (!bundle.containsKey(Restrictable.LOCATION_SERVICE.name) && bundle.containsKey("no_location_service")) {
+            bundle.putBoolean(Restrictable.LOCATION_SERVICE.name, !bundle.getBoolean("no_location_service"));
+        }
+
+        if (!bundle.containsKey(Restrictable.CLEAR_HISTORY.name) && bundle.containsKey("no_clear_history")) {
+            bundle.putBoolean(Restrictable.CLEAR_HISTORY.name, !bundle.getBoolean("no_clear_history"));
+        }
+
+        if (!bundle.containsKey(Restrictable.MASTER_PASSWORD.name) && bundle.containsKey("no_master_password")) {
+            bundle.putBoolean(Restrictable.MASTER_PASSWORD.name, !bundle.getBoolean("no_master_password"));
+        }
+
+        if (!bundle.containsKey(Restrictable.GUEST_BROWSING.name) && bundle.containsKey("no_guest_browsing")) {
+            bundle.putBoolean(Restrictable.GUEST_BROWSING.name, !bundle.getBoolean("no_guest_browsing"));
+        }
+
+        if (!bundle.containsKey(Restrictable.ADVANCED_SETTINGS.name) && bundle.containsKey("no_advanced_settings")) {
+            bundle.putBoolean(Restrictable.ADVANCED_SETTINGS.name, !bundle.getBoolean("no_advanced_settings"));
+        }
+    }
+}
--- a/mobile/android/base/restrictions/RestrictionProvider.java
+++ b/mobile/android/base/restrictions/RestrictionProvider.java
@@ -31,16 +31,18 @@ public class RestrictionProvider extends
         }
 
         final PendingResult result = goAsync();
 
         new Thread() {
             @Override
             public void run() {
                 final Bundle oldRestrictions = intent.getBundleExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE);
+                RestrictedProfileConfiguration.migrateRestrictionsIfNeeded(oldRestrictions);
+
                 final Bundle extras = new Bundle();
 
                 ArrayList<RestrictionEntry> entries = initRestrictions(context, oldRestrictions);
                 extras.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS_LIST, entries);
 
                 result.setResult(Activity.RESULT_OK, null, extras);
                 result.finish();
             }