Bug 1125293 - Restricted profiles: Check global restrictions in isAllowed(). r=ally
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 30 Jul 2015 20:00:16 +0200
changeset 287156 9372bf0fd83e8fdd3c1229874f2e84dc53c3500d
parent 287155 8bdfb76f8a081d570dd6cbbb4f3e73bbe38ee204
child 287157 4a0743e93d6f2caf2c48031b1f74f89d1f855bef
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersally
bugs1125293
milestone42.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 1125293 - Restricted profiles: Check global restrictions in isAllowed(). r=ally This effectively hides all sync features and related UI for restricted profiles because this is controlled by the DISALLOW_MODIFY_ACCOUNTS restriction of the system.
mobile/android/base/restrictions/RestrictedProfileConfiguration.java
--- a/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
+++ b/mobile/android/base/restrictions/RestrictedProfileConfiguration.java
@@ -32,17 +32,25 @@ public class RestrictedProfileConfigurat
     private Context context;
 
     public RestrictedProfileConfiguration(Context context) {
         this.context = context.getApplicationContext();
     }
 
     @Override
     public boolean isAllowed(Restriction restriction) {
-        return !getAppRestrictions(context).getBoolean(restriction.name, DEFAULT_RESTRICTIONS.contains(restriction));
+        boolean isAllowed = !getAppRestrictions(context).getBoolean(restriction.name, DEFAULT_RESTRICTIONS.contains(restriction));
+
+        if (isAllowed) {
+            // If this restriction is not enforced by the app setup then check wether this is a restriction that is
+            // enforced by the system.
+            isAllowed = !getUserRestrictions(context).getBoolean(restriction.name, false);
+        }
+
+        return isAllowed;
     }
 
     @Override
     public boolean canLoadUrl(String url) {
         if (!isAllowed(Restriction.DISALLOW_INSTALL_EXTENSION) && url.toLowerCase().startsWith(ABOUT_ADDONS)) {
             return false;
         }
 
@@ -58,9 +66,15 @@ public class RestrictedProfileConfigurat
         return true;
     }
 
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
     private Bundle getAppRestrictions(final Context context) {
         final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
         return mgr.getApplicationRestrictions(context.getPackageName());
     }
+
+    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
+    private Bundle getUserRestrictions(final Context context) {
+        final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        return mgr.getUserRestrictions();
+    }
 }