OSDN Git Service

Added Data roaming user restriction
authorMahaver Chopra <mahaver@google.com>
Thu, 17 Dec 2015 11:02:37 +0000 (11:02 +0000)
committerMahaver Chopra <mahaver@google.com>
Fri, 8 Jan 2016 18:07:31 +0000 (18:07 +0000)
Added new user restriction DISALLOW_DATA_ROAMING, can only be set
by device owners.

Bug: 24890464
Change-Id: Ic4cb37dd5f9bbffa35f921751488ef7c7ff99452

api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/os/UserManager.java
packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
services/core/java/com/android/server/pm/UserRestrictionsUtils.java

index e2b1556..6687539 100644 (file)
@@ -28415,6 +28415,7 @@ package android.os {
     field public static final java.lang.String DISALLOW_CONFIG_WIFI = "no_config_wifi";
     field public static final java.lang.String DISALLOW_CREATE_WINDOWS = "no_create_windows";
     field public static final java.lang.String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
+    field public static final java.lang.String DISALLOW_DATA_ROAMING = "no_data_roaming";
     field public static final java.lang.String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
     field public static final java.lang.String DISALLOW_FACTORY_RESET = "no_factory_reset";
     field public static final java.lang.String DISALLOW_FUN = "no_fun";
index d50a6c9..c296388 100644 (file)
@@ -30418,6 +30418,7 @@ package android.os {
     field public static final java.lang.String DISALLOW_CONFIG_WIFI = "no_config_wifi";
     field public static final java.lang.String DISALLOW_CREATE_WINDOWS = "no_create_windows";
     field public static final java.lang.String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
+    field public static final java.lang.String DISALLOW_DATA_ROAMING = "no_data_roaming";
     field public static final java.lang.String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
     field public static final java.lang.String DISALLOW_FACTORY_RESET = "no_factory_reset";
     field public static final java.lang.String DISALLOW_FUN = "no_fun";
index 80f250a..ebb7337 100644 (file)
@@ -28424,6 +28424,7 @@ package android.os {
     field public static final java.lang.String DISALLOW_CONFIG_WIFI = "no_config_wifi";
     field public static final java.lang.String DISALLOW_CREATE_WINDOWS = "no_create_windows";
     field public static final java.lang.String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
+    field public static final java.lang.String DISALLOW_DATA_ROAMING = "no_data_roaming";
     field public static final java.lang.String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
     field public static final java.lang.String DISALLOW_FACTORY_RESET = "no_factory_reset";
     field public static final java.lang.String DISALLOW_FUN = "no_fun";
index 887dd17..d1b3f59 100644 (file)
@@ -518,6 +518,16 @@ public class UserManager {
     public static final String DISALLOW_CAMERA = "no_camera";
 
     /**
+     * Specifies if a user is not allowed to use cellular data when roaming. This can only be set by
+     * device owners. The default value is <code>false</code>.
+     *
+     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
+     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
+     * @see #getUserRestrictions()
+     */
+    public static final String DISALLOW_DATA_ROAMING = "no_data_roaming";
+
+    /**
      * Allows apps in the parent profile to handle web links from the managed profile.
      *
      * This user restriction has an effect only in a managed profile.
index bcb459a..1896bbb 100644 (file)
@@ -1010,6 +1010,11 @@ public class SettingsProvider extends ContentProvider {
                 break;
 
             default:
+                if (setting.startsWith(Settings.Global.DATA_ROAMING)) {
+                    if ("0".equals(value)) return false;
+                    restriction = UserManager.DISALLOW_DATA_ROAMING;
+                    break;
+                }
                 return false;
         }
 
index 9bbc3c1..f0ed790 100644 (file)
@@ -33,6 +33,8 @@ import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
 import android.util.Log;
 
 import org.xmlpull.v1.XmlPullParser;
@@ -40,10 +42,11 @@ import org.xmlpull.v1.XmlSerializer;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.List;
 import java.util.Set;
 
 /**
- * Utility methods for uesr restrictions.
+ * Utility methods for user restrictions.
  *
  * <p>See {@link UserManagerService} for the method suffixes.
  */
@@ -88,7 +91,8 @@ public class UserRestrictionsUtils {
             UserManager.ALLOW_PARENT_PROFILE_APP_LINKING,
             UserManager.DISALLOW_RECORD_AUDIO,
             UserManager.DISALLOW_CAMERA,
-            UserManager.DISALLOW_RUN_IN_BACKGROUND
+            UserManager.DISALLOW_RUN_IN_BACKGROUND,
+            UserManager.DISALLOW_DATA_ROAMING
     );
 
     /**
@@ -113,7 +117,8 @@ public class UserRestrictionsUtils {
             UserManager.DISALLOW_SMS,
             UserManager.DISALLOW_FUN,
             UserManager.DISALLOW_SAFE_BOOT,
-            UserManager.DISALLOW_CREATE_WINDOWS
+            UserManager.DISALLOW_CREATE_WINDOWS,
+            UserManager.DISALLOW_DATA_ROAMING
     );
 
     /**
@@ -315,6 +320,27 @@ public class UserRestrictionsUtils {
                                         .WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId);
                     }
                     break;
+                case UserManager.DISALLOW_DATA_ROAMING:
+                    if (newValue) {
+                        // DISALLOW_DATA_ROAMING user restriction is set.
+
+                        // Multi sim device.
+                        SubscriptionManager subscriptionManager = new SubscriptionManager(context);
+                        final List<SubscriptionInfo> subscriptionInfoList =
+                            subscriptionManager.getActiveSubscriptionInfoList();
+                        if (subscriptionInfoList != null) {
+                            for (SubscriptionInfo subInfo : subscriptionInfoList) {
+                                android.provider.Settings.Global.putStringForUser(cr,
+                                    android.provider.Settings.Global.DATA_ROAMING
+                                    + subInfo.getSubscriptionId(), "0", userId);
+                            }
+                        }
+
+                        // Single sim device.
+                        android.provider.Settings.Global.putStringForUser(cr,
+                            android.provider.Settings.Global.DATA_ROAMING, "0", userId);
+                    }
+                    break;
                 case UserManager.DISALLOW_SHARE_LOCATION:
                     if (newValue) {
                         android.provider.Settings.Secure.putIntForUser(cr,