Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.pm; |
| 18 | |
| 19 | import com.google.android.collect.Sets; |
| 20 | |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 21 | import com.android.internal.util.Preconditions; |
| 22 | |
| 23 | import android.annotation.NonNull; |
| 24 | import android.annotation.Nullable; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
| 26 | import android.app.ActivityManagerNative; |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 27 | import android.content.ContentResolver; |
| 28 | import android.content.Context; |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
| 30 | import android.os.Binder; |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 32 | import android.os.RemoteException; |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 33 | import android.os.SystemProperties; |
| 34 | import android.os.UserHandle; |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 35 | import android.os.UserManager; |
Mahaver Chopra | 830e32c | 2016-05-17 18:53:09 +0100 | [diff] [blame] | 36 | import android.service.persistentdata.PersistentDataBlockManager; |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 37 | import android.telephony.SubscriptionInfo; |
| 38 | import android.telephony.SubscriptionManager; |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 39 | import android.util.Log; |
Makoto Onuki | 1f1ceef | 2016-01-28 11:32:32 -0800 | [diff] [blame] | 40 | import android.util.Slog; |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 41 | |
| 42 | import org.xmlpull.v1.XmlPullParser; |
| 43 | import org.xmlpull.v1.XmlSerializer; |
| 44 | |
| 45 | import java.io.IOException; |
| 46 | import java.io.PrintWriter; |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 47 | import java.util.List; |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 48 | import java.util.Set; |
| 49 | |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 50 | /** |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 51 | * Utility methods for user restrictions. |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 52 | * |
| 53 | * <p>See {@link UserManagerService} for the method suffixes. |
| 54 | */ |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 55 | public class UserRestrictionsUtils { |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 56 | private static final String TAG = "UserRestrictionsUtils"; |
| 57 | |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 58 | private UserRestrictionsUtils() { |
| 59 | } |
| 60 | |
Makoto Onuki | 1f1ceef | 2016-01-28 11:32:32 -0800 | [diff] [blame] | 61 | private static Set<String> newSetWithUniqueCheck(String[] strings) { |
| 62 | final Set<String> ret = Sets.newArraySet(strings); |
| 63 | |
| 64 | // Make sure there's no overlap. |
| 65 | Preconditions.checkState(ret.size() == strings.length); |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | public static final Set<String> USER_RESTRICTIONS = newSetWithUniqueCheck(new String[] { |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 70 | UserManager.DISALLOW_CONFIG_WIFI, |
| 71 | UserManager.DISALLOW_MODIFY_ACCOUNTS, |
| 72 | UserManager.DISALLOW_INSTALL_APPS, |
| 73 | UserManager.DISALLOW_UNINSTALL_APPS, |
| 74 | UserManager.DISALLOW_SHARE_LOCATION, |
| 75 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, |
| 76 | UserManager.DISALLOW_CONFIG_BLUETOOTH, |
| 77 | UserManager.DISALLOW_USB_FILE_TRANSFER, |
| 78 | UserManager.DISALLOW_CONFIG_CREDENTIALS, |
| 79 | UserManager.DISALLOW_REMOVE_USER, |
| 80 | UserManager.DISALLOW_DEBUGGING_FEATURES, |
| 81 | UserManager.DISALLOW_CONFIG_VPN, |
| 82 | UserManager.DISALLOW_CONFIG_TETHERING, |
| 83 | UserManager.DISALLOW_NETWORK_RESET, |
| 84 | UserManager.DISALLOW_FACTORY_RESET, |
| 85 | UserManager.DISALLOW_ADD_USER, |
| 86 | UserManager.ENSURE_VERIFY_APPS, |
| 87 | UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, |
| 88 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, |
| 89 | UserManager.DISALLOW_APPS_CONTROL, |
| 90 | UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, |
| 91 | UserManager.DISALLOW_UNMUTE_MICROPHONE, |
| 92 | UserManager.DISALLOW_ADJUST_VOLUME, |
| 93 | UserManager.DISALLOW_OUTGOING_CALLS, |
| 94 | UserManager.DISALLOW_SMS, |
| 95 | UserManager.DISALLOW_FUN, |
| 96 | UserManager.DISALLOW_CREATE_WINDOWS, |
| 97 | UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE, |
| 98 | UserManager.DISALLOW_OUTGOING_BEAM, |
| 99 | UserManager.DISALLOW_WALLPAPER, |
| 100 | UserManager.DISALLOW_SAFE_BOOT, |
| 101 | UserManager.ALLOW_PARENT_PROFILE_APP_LINKING, |
| 102 | UserManager.DISALLOW_RECORD_AUDIO, |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 103 | UserManager.DISALLOW_CAMERA, |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 104 | UserManager.DISALLOW_RUN_IN_BACKGROUND, |
Oleksandr Peletskyi | 7f1f1df | 2016-01-18 15:40:21 +0100 | [diff] [blame] | 105 | UserManager.DISALLOW_DATA_ROAMING, |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 106 | UserManager.DISALLOW_SET_USER_ICON, |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame^] | 107 | UserManager.DISALLOW_SET_WALLPAPER, |
| 108 | UserManager.DISALLOW_OEM_UNLOCK |
Makoto Onuki | 1f1ceef | 2016-01-28 11:32:32 -0800 | [diff] [blame] | 109 | }); |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Set of user restriction which we don't want to persist. |
| 113 | */ |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 114 | private static final Set<String> NON_PERSIST_USER_RESTRICTIONS = Sets.newArraySet( |
| 115 | UserManager.DISALLOW_RECORD_AUDIO |
| 116 | ); |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 117 | |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 118 | /** |
| 119 | * User restrictions that can not be set by profile owners. |
| 120 | */ |
| 121 | private static final Set<String> DEVICE_OWNER_ONLY_RESTRICTIONS = Sets.newArraySet( |
| 122 | UserManager.DISALLOW_USB_FILE_TRANSFER, |
| 123 | UserManager.DISALLOW_CONFIG_TETHERING, |
| 124 | UserManager.DISALLOW_NETWORK_RESET, |
| 125 | UserManager.DISALLOW_FACTORY_RESET, |
| 126 | UserManager.DISALLOW_ADD_USER, |
| 127 | UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, |
| 128 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, |
| 129 | UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, |
| 130 | UserManager.DISALLOW_SMS, |
| 131 | UserManager.DISALLOW_FUN, |
| 132 | UserManager.DISALLOW_SAFE_BOOT, |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 133 | UserManager.DISALLOW_CREATE_WINDOWS, |
| 134 | UserManager.DISALLOW_DATA_ROAMING |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 135 | ); |
| 136 | |
| 137 | /** |
| 138 | * User restrictions that can't be changed by device owner or profile owner. |
| 139 | */ |
| 140 | private static final Set<String> IMMUTABLE_BY_OWNERS = Sets.newArraySet( |
| 141 | UserManager.DISALLOW_RECORD_AUDIO, |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame^] | 142 | UserManager.DISALLOW_WALLPAPER, |
| 143 | UserManager.DISALLOW_OEM_UNLOCK |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 144 | ); |
| 145 | |
| 146 | /** |
| 147 | * Special user restrictions that can be applied to a user as well as to all users globally, |
| 148 | * depending on callers. When device owner sets them, they'll be applied to all users. |
| 149 | */ |
| 150 | private static final Set<String> GLOBAL_RESTRICTIONS = Sets.newArraySet( |
| 151 | UserManager.DISALLOW_ADJUST_VOLUME, |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 152 | UserManager.DISALLOW_RUN_IN_BACKGROUND, |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 153 | UserManager.DISALLOW_UNMUTE_MICROPHONE |
| 154 | ); |
| 155 | |
Makoto Onuki | 1f1ceef | 2016-01-28 11:32:32 -0800 | [diff] [blame] | 156 | /** |
| 157 | * Throws {@link IllegalArgumentException} if the given restriction name is invalid. |
| 158 | */ |
| 159 | public static boolean isValidRestriction(@NonNull String restriction) { |
| 160 | if (!USER_RESTRICTIONS.contains(restriction)) { |
Makoto Onuki | ad5619d | 2016-02-10 13:41:15 -0800 | [diff] [blame] | 161 | Slog.e(TAG, "Unknown restriction: " + restriction); |
Makoto Onuki | 1f1ceef | 2016-01-28 11:32:32 -0800 | [diff] [blame] | 162 | return false; |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 | |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 167 | public static void writeRestrictions(@NonNull XmlSerializer serializer, |
| 168 | @Nullable Bundle restrictions, @NonNull String tag) throws IOException { |
| 169 | if (restrictions == null) { |
| 170 | return; |
| 171 | } |
| 172 | |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 173 | serializer.startTag(null, tag); |
Makoto Onuki | ac65e1e | 2015-11-20 15:33:17 -0800 | [diff] [blame] | 174 | for (String key : restrictions.keySet()) { |
| 175 | if (NON_PERSIST_USER_RESTRICTIONS.contains(key)) { |
| 176 | continue; // Don't persist. |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 177 | } |
Makoto Onuki | ac65e1e | 2015-11-20 15:33:17 -0800 | [diff] [blame] | 178 | if (USER_RESTRICTIONS.contains(key)) { |
| 179 | if (restrictions.getBoolean(key)) { |
| 180 | serializer.attribute(null, key, "true"); |
| 181 | } |
| 182 | continue; |
| 183 | } |
| 184 | Log.w(TAG, "Unknown user restriction detected: " + key); |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 185 | } |
| 186 | serializer.endTag(null, tag); |
| 187 | } |
| 188 | |
| 189 | public static void readRestrictions(XmlPullParser parser, Bundle restrictions) |
| 190 | throws IOException { |
| 191 | for (String key : USER_RESTRICTIONS) { |
| 192 | final String value = parser.getAttributeValue(null, key); |
| 193 | if (value != null) { |
| 194 | restrictions.putBoolean(key, Boolean.parseBoolean(value)); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 199 | /** |
| 200 | * @return {@code in} itself when it's not null, or an empty bundle (which can writable). |
| 201 | */ |
| 202 | public static Bundle nonNull(@Nullable Bundle in) { |
| 203 | return in != null ? in : new Bundle(); |
| 204 | } |
| 205 | |
| 206 | public static boolean isEmpty(@Nullable Bundle in) { |
| 207 | return (in == null) || (in.size() == 0); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Creates a copy of the {@code in} Bundle. If {@code in} is null, it'll return an empty |
| 212 | * bundle. |
| 213 | * |
| 214 | * <p>The resulting {@link Bundle} is always writable. (i.e. it won't return |
| 215 | * {@link Bundle#EMPTY}) |
| 216 | */ |
| 217 | public static @NonNull Bundle clone(@Nullable Bundle in) { |
| 218 | return (in != null) ? new Bundle(in) : new Bundle(); |
| 219 | } |
| 220 | |
| 221 | public static void merge(@NonNull Bundle dest, @Nullable Bundle in) { |
| 222 | Preconditions.checkNotNull(dest); |
| 223 | Preconditions.checkArgument(dest != in); |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 224 | if (in == null) { |
| 225 | return; |
| 226 | } |
| 227 | for (String key : in.keySet()) { |
| 228 | if (in.getBoolean(key, false)) { |
| 229 | dest.putBoolean(key, true); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 234 | /** |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 235 | * @return true if a restriction is settable by device owner. |
| 236 | */ |
| 237 | public static boolean canDeviceOwnerChange(String restriction) { |
| 238 | return !IMMUTABLE_BY_OWNERS.contains(restriction); |
| 239 | } |
| 240 | |
| 241 | /** |
Makoto Onuki | 5485ed4 | 2015-12-09 11:38:23 -0800 | [diff] [blame] | 242 | * @return true if a restriction is settable by profile owner. Note it takes a user ID because |
| 243 | * some restrictions can be changed by PO only when it's running on the system user. |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 244 | */ |
Makoto Onuki | 5485ed4 | 2015-12-09 11:38:23 -0800 | [diff] [blame] | 245 | public static boolean canProfileOwnerChange(String restriction, int userId) { |
| 246 | return !IMMUTABLE_BY_OWNERS.contains(restriction) |
| 247 | && !(userId != UserHandle.USER_SYSTEM |
| 248 | && DEVICE_OWNER_ONLY_RESTRICTIONS.contains(restriction)); |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Takes restrictions that can be set by device owner, and sort them into what should be applied |
| 253 | * globally and what should be applied only on the current user. |
| 254 | */ |
| 255 | public static void sortToGlobalAndLocal(@Nullable Bundle in, @NonNull Bundle global, |
| 256 | @NonNull Bundle local) { |
| 257 | if (in == null || in.size() == 0) { |
| 258 | return; |
| 259 | } |
| 260 | for (String key : in.keySet()) { |
| 261 | if (!in.getBoolean(key)) { |
| 262 | continue; |
| 263 | } |
| 264 | if (DEVICE_OWNER_ONLY_RESTRICTIONS.contains(key) || GLOBAL_RESTRICTIONS.contains(key)) { |
| 265 | global.putBoolean(key, true); |
| 266 | } else { |
| 267 | local.putBoolean(key, true); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * @return true if two Bundles contain the same user restriction. |
| 274 | * A null bundle and an empty bundle are considered to be equal. |
| 275 | */ |
| 276 | public static boolean areEqual(@Nullable Bundle a, @Nullable Bundle b) { |
| 277 | if (a == b) { |
| 278 | return true; |
| 279 | } |
| 280 | if (isEmpty(a)) { |
| 281 | return isEmpty(b); |
| 282 | } |
| 283 | if (isEmpty(b)) { |
| 284 | return false; |
| 285 | } |
| 286 | for (String key : a.keySet()) { |
| 287 | if (a.getBoolean(key) != b.getBoolean(key)) { |
| 288 | return false; |
| 289 | } |
| 290 | } |
| 291 | for (String key : b.keySet()) { |
| 292 | if (a.getBoolean(key) != b.getBoolean(key)) { |
| 293 | return false; |
| 294 | } |
| 295 | } |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | /** |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 300 | * Takes a new use restriction set and the previous set, and apply the restrictions that have |
| 301 | * changed. |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 302 | * |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 303 | * <p>Note this method is called by {@link UserManagerService} without holding any locks. |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 304 | */ |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 305 | public static void applyUserRestrictions(Context context, int userId, |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 306 | Bundle newRestrictions, Bundle prevRestrictions) { |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 307 | for (String key : USER_RESTRICTIONS) { |
| 308 | final boolean newValue = newRestrictions.getBoolean(key); |
| 309 | final boolean prevValue = prevRestrictions.getBoolean(key); |
| 310 | |
| 311 | if (newValue != prevValue) { |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 312 | applyUserRestriction(context, userId, key, newValue); |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | } |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 316 | |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 317 | /** |
| 318 | * Apply each user restriction. |
| 319 | * |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 320 | * <p>See also {@link |
| 321 | * com.android.providers.settings.SettingsProvider#isGlobalOrSecureSettingRestrictedForUser}, |
| 322 | * which should be in sync with this method. |
Makoto Onuki | d45a4a2 | 2015-11-02 17:17:38 -0800 | [diff] [blame] | 323 | */ |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 324 | private static void applyUserRestriction(Context context, int userId, String key, |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 325 | boolean newValue) { |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 326 | if (UserManagerService.DBG) { |
| 327 | Log.d(TAG, "Applying user restriction: userId=" + userId |
| 328 | + " key=" + key + " value=" + newValue); |
| 329 | } |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 330 | // When certain restrictions are cleared, we don't update the system settings, |
| 331 | // because these settings are changeable on the Settings UI and we don't know the original |
| 332 | // value -- for example LOCATION_MODE might have been off already when the restriction was |
| 333 | // set, and in that case even if the restriction is lifted, changing it to ON would be |
| 334 | // wrong. So just don't do anything in such a case. If the user hopes to enable location |
| 335 | // later, they can do it on the Settings UI. |
| 336 | |
| 337 | final ContentResolver cr = context.getContentResolver(); |
| 338 | final long id = Binder.clearCallingIdentity(); |
| 339 | try { |
| 340 | switch (key) { |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 341 | case UserManager.DISALLOW_CONFIG_WIFI: |
| 342 | if (newValue) { |
| 343 | android.provider.Settings.Secure.putIntForUser(cr, |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 344 | android.provider.Settings.Global |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 345 | .WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId); |
| 346 | } |
| 347 | break; |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 348 | case UserManager.DISALLOW_DATA_ROAMING: |
| 349 | if (newValue) { |
| 350 | // DISALLOW_DATA_ROAMING user restriction is set. |
| 351 | |
| 352 | // Multi sim device. |
| 353 | SubscriptionManager subscriptionManager = new SubscriptionManager(context); |
| 354 | final List<SubscriptionInfo> subscriptionInfoList = |
| 355 | subscriptionManager.getActiveSubscriptionInfoList(); |
| 356 | if (subscriptionInfoList != null) { |
| 357 | for (SubscriptionInfo subInfo : subscriptionInfoList) { |
| 358 | android.provider.Settings.Global.putStringForUser(cr, |
| 359 | android.provider.Settings.Global.DATA_ROAMING |
| 360 | + subInfo.getSubscriptionId(), "0", userId); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | // Single sim device. |
| 365 | android.provider.Settings.Global.putStringForUser(cr, |
| 366 | android.provider.Settings.Global.DATA_ROAMING, "0", userId); |
| 367 | } |
| 368 | break; |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 369 | case UserManager.DISALLOW_SHARE_LOCATION: |
| 370 | if (newValue) { |
| 371 | android.provider.Settings.Secure.putIntForUser(cr, |
| 372 | android.provider.Settings.Secure.LOCATION_MODE, |
| 373 | android.provider.Settings.Secure.LOCATION_MODE_OFF, |
| 374 | userId); |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 375 | } |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 376 | break; |
| 377 | case UserManager.DISALLOW_DEBUGGING_FEATURES: |
| 378 | if (newValue) { |
| 379 | // Only disable adb if changing for system user, since it is global |
| 380 | // TODO: should this be admin user? |
| 381 | if (userId == UserHandle.USER_SYSTEM) { |
| 382 | android.provider.Settings.Global.putStringForUser(cr, |
| 383 | android.provider.Settings.Global.ADB_ENABLED, "0", |
| 384 | userId); |
| 385 | } |
| 386 | } |
| 387 | break; |
| 388 | case UserManager.ENSURE_VERIFY_APPS: |
| 389 | if (newValue) { |
| 390 | android.provider.Settings.Global.putStringForUser( |
| 391 | context.getContentResolver(), |
| 392 | android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, "1", |
| 393 | userId); |
| 394 | android.provider.Settings.Global.putStringForUser( |
| 395 | context.getContentResolver(), |
| 396 | android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, "1", |
| 397 | userId); |
| 398 | } |
| 399 | break; |
| 400 | case UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES: |
| 401 | if (newValue) { |
| 402 | android.provider.Settings.Secure.putIntForUser(cr, |
| 403 | android.provider.Settings.Secure.INSTALL_NON_MARKET_APPS, 0, |
| 404 | userId); |
| 405 | } |
| 406 | break; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 407 | case UserManager.DISALLOW_RUN_IN_BACKGROUND: |
| 408 | if (newValue) { |
| 409 | int currentUser = ActivityManager.getCurrentUser(); |
| 410 | if (currentUser != userId && userId != UserHandle.USER_SYSTEM) { |
| 411 | try { |
| 412 | ActivityManagerNative.getDefault().stopUser(userId, false, null); |
| 413 | } catch (RemoteException e) { |
| 414 | throw e.rethrowAsRuntimeException(); |
| 415 | } |
| 416 | } |
| 417 | } |
Lenka Trochtova | 6474f0e | 2016-03-24 16:43:10 +0100 | [diff] [blame] | 418 | break; |
| 419 | case UserManager.DISALLOW_SAFE_BOOT: |
| 420 | // Unlike with the other restrictions, we want to propagate the new value to |
| 421 | // the system settings even if it is false. The other restrictions modify |
| 422 | // settings which could be manually changed by the user from the Settings app |
| 423 | // after the policies enforcing these restrictions have been revoked, so we |
| 424 | // leave re-setting of those settings to the user. |
| 425 | android.provider.Settings.Global.putInt( |
| 426 | context.getContentResolver(), |
| 427 | android.provider.Settings.Global.SAFE_BOOT_DISALLOWED, |
| 428 | newValue ? 1 : 0); |
| 429 | break; |
Mahaver Chopra | 830e32c | 2016-05-17 18:53:09 +0100 | [diff] [blame] | 430 | case UserManager.DISALLOW_FACTORY_RESET: |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame^] | 431 | case UserManager.DISALLOW_OEM_UNLOCK: |
Mahaver Chopra | 830e32c | 2016-05-17 18:53:09 +0100 | [diff] [blame] | 432 | if (newValue) { |
| 433 | PersistentDataBlockManager manager = (PersistentDataBlockManager) context |
| 434 | .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
Mahaver Chopra | d444ff1 | 2016-06-16 14:05:58 +0100 | [diff] [blame] | 435 | if (manager != null && manager.getOemUnlockEnabled()) { |
Mahaver Chopra | 830e32c | 2016-05-17 18:53:09 +0100 | [diff] [blame] | 436 | manager.setOemUnlockEnabled(false); |
| 437 | } |
| 438 | } |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 439 | } |
Makoto Onuki | 4f16073 | 2015-10-27 17:15:38 -0700 | [diff] [blame] | 440 | } finally { |
| 441 | Binder.restoreCallingIdentity(id); |
| 442 | } |
| 443 | } |
| 444 | |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 445 | public static void dumpRestrictions(PrintWriter pw, String prefix, Bundle restrictions) { |
| 446 | boolean noneSet = true; |
| 447 | if (restrictions != null) { |
| 448 | for (String key : restrictions.keySet()) { |
| 449 | if (restrictions.getBoolean(key, false)) { |
| 450 | pw.println(prefix + key); |
| 451 | noneSet = false; |
| 452 | } |
| 453 | } |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 454 | if (noneSet) { |
| 455 | pw.println(prefix + "none"); |
| 456 | } |
| 457 | } else { |
| 458 | pw.println(prefix + "null"); |
Makoto Onuki | a4f1197 | 2015-10-01 13:19:58 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | } |