blob: 7ec3c19bbae32e4258e96dc06470cd3cc5a3de0f [file] [log] [blame]
Makoto Onukia4f11972015-10-01 13:19:58 -07001/*
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
17package com.android.server.pm;
18
19import com.google.android.collect.Sets;
20
Makoto Onuki1a2cd742015-11-16 13:51:27 -080021import com.android.internal.util.Preconditions;
22
23import android.annotation.NonNull;
24import android.annotation.Nullable;
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -070025import android.app.ActivityManager;
Makoto Onuki4f160732015-10-27 17:15:38 -070026import android.content.ContentResolver;
27import android.content.Context;
Makoto Onuki4f160732015-10-27 17:15:38 -070028import android.os.Binder;
Makoto Onukia4f11972015-10-01 13:19:58 -070029import android.os.Bundle;
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -070030import android.os.RemoteException;
Makoto Onuki4f160732015-10-27 17:15:38 -070031import android.os.UserHandle;
Makoto Onukia4f11972015-10-01 13:19:58 -070032import android.os.UserManager;
Mahaver Chopra830e32c2016-05-17 18:53:09 +010033import android.service.persistentdata.PersistentDataBlockManager;
Mahaver Chopradea471e2015-12-17 11:02:37 +000034import android.telephony.SubscriptionInfo;
35import android.telephony.SubscriptionManager;
Makoto Onuki1a2cd742015-11-16 13:51:27 -080036import android.util.Log;
Makoto Onuki1f1ceef2016-01-28 11:32:32 -080037import android.util.Slog;
Makoto Onukia4f11972015-10-01 13:19:58 -070038
39import org.xmlpull.v1.XmlPullParser;
40import org.xmlpull.v1.XmlSerializer;
41
42import java.io.IOException;
43import java.io.PrintWriter;
Mahaver Chopradea471e2015-12-17 11:02:37 +000044import java.util.List;
Makoto Onukia4f11972015-10-01 13:19:58 -070045import java.util.Set;
46
Makoto Onukid45a4a22015-11-02 17:17:38 -080047/**
Mahaver Chopradea471e2015-12-17 11:02:37 +000048 * Utility methods for user restrictions.
Makoto Onukid45a4a22015-11-02 17:17:38 -080049 *
50 * <p>See {@link UserManagerService} for the method suffixes.
51 */
Makoto Onukia4f11972015-10-01 13:19:58 -070052public class UserRestrictionsUtils {
Makoto Onuki4f160732015-10-27 17:15:38 -070053 private static final String TAG = "UserRestrictionsUtils";
54
Makoto Onukia4f11972015-10-01 13:19:58 -070055 private UserRestrictionsUtils() {
56 }
57
Makoto Onuki1f1ceef2016-01-28 11:32:32 -080058 private static Set<String> newSetWithUniqueCheck(String[] strings) {
59 final Set<String> ret = Sets.newArraySet(strings);
60
61 // Make sure there's no overlap.
62 Preconditions.checkState(ret.size() == strings.length);
63 return ret;
64 }
65
66 public static final Set<String> USER_RESTRICTIONS = newSetWithUniqueCheck(new String[] {
Makoto Onukia4f11972015-10-01 13:19:58 -070067 UserManager.DISALLOW_CONFIG_WIFI,
68 UserManager.DISALLOW_MODIFY_ACCOUNTS,
69 UserManager.DISALLOW_INSTALL_APPS,
70 UserManager.DISALLOW_UNINSTALL_APPS,
71 UserManager.DISALLOW_SHARE_LOCATION,
72 UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
73 UserManager.DISALLOW_CONFIG_BLUETOOTH,
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +010074 UserManager.DISALLOW_BLUETOOTH,
Makoto Onukia4f11972015-10-01 13:19:58 -070075 UserManager.DISALLOW_USB_FILE_TRANSFER,
76 UserManager.DISALLOW_CONFIG_CREDENTIALS,
77 UserManager.DISALLOW_REMOVE_USER,
78 UserManager.DISALLOW_DEBUGGING_FEATURES,
79 UserManager.DISALLOW_CONFIG_VPN,
80 UserManager.DISALLOW_CONFIG_TETHERING,
81 UserManager.DISALLOW_NETWORK_RESET,
82 UserManager.DISALLOW_FACTORY_RESET,
83 UserManager.DISALLOW_ADD_USER,
84 UserManager.ENSURE_VERIFY_APPS,
85 UserManager.DISALLOW_CONFIG_CELL_BROADCASTS,
86 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,
87 UserManager.DISALLOW_APPS_CONTROL,
88 UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA,
89 UserManager.DISALLOW_UNMUTE_MICROPHONE,
90 UserManager.DISALLOW_ADJUST_VOLUME,
91 UserManager.DISALLOW_OUTGOING_CALLS,
92 UserManager.DISALLOW_SMS,
93 UserManager.DISALLOW_FUN,
94 UserManager.DISALLOW_CREATE_WINDOWS,
95 UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE,
96 UserManager.DISALLOW_OUTGOING_BEAM,
97 UserManager.DISALLOW_WALLPAPER,
98 UserManager.DISALLOW_SAFE_BOOT,
99 UserManager.ALLOW_PARENT_PROFILE_APP_LINKING,
100 UserManager.DISALLOW_RECORD_AUDIO,
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700101 UserManager.DISALLOW_CAMERA,
Mahaver Chopradea471e2015-12-17 11:02:37 +0000102 UserManager.DISALLOW_RUN_IN_BACKGROUND,
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +0100103 UserManager.DISALLOW_DATA_ROAMING,
Oleksandr Peletskyif2519812016-01-26 20:16:06 +0100104 UserManager.DISALLOW_SET_USER_ICON,
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100105 UserManager.DISALLOW_SET_WALLPAPER,
Tony Makc1205112016-07-22 16:02:59 +0100106 UserManager.DISALLOW_OEM_UNLOCK,
107 UserManager.DISALLLOW_UNMUTE_DEVICE,
Makoto Onuki1f1ceef2016-01-28 11:32:32 -0800108 });
Makoto Onukia4f11972015-10-01 13:19:58 -0700109
110 /**
111 * Set of user restriction which we don't want to persist.
112 */
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800113 private static final Set<String> NON_PERSIST_USER_RESTRICTIONS = Sets.newArraySet(
114 UserManager.DISALLOW_RECORD_AUDIO
115 );
Makoto Onukia4f11972015-10-01 13:19:58 -0700116
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800117 /**
118 * User restrictions that can not be set by profile owners.
119 */
120 private static final Set<String> DEVICE_OWNER_ONLY_RESTRICTIONS = Sets.newArraySet(
Lenka Trochtova63d5e4a72016-12-02 12:19:39 +0100121 UserManager.DISALLOW_BLUETOOTH,
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800122 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 Chopradea471e2015-12-17 11:02:37 +0000133 UserManager.DISALLOW_CREATE_WINDOWS,
134 UserManager.DISALLOW_DATA_ROAMING
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800135 );
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 Chopra3d9805d2016-07-07 16:25:05 +0100142 UserManager.DISALLOW_WALLPAPER,
143 UserManager.DISALLOW_OEM_UNLOCK
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800144 );
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 Kupolov9cbfc9e2015-10-07 15:52:33 -0700152 UserManager.DISALLOW_RUN_IN_BACKGROUND,
Tony Makc1205112016-07-22 16:02:59 +0100153 UserManager.DISALLOW_UNMUTE_MICROPHONE,
154 UserManager.DISALLLOW_UNMUTE_DEVICE
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800155 );
156
Makoto Onuki1f1ceef2016-01-28 11:32:32 -0800157 /**
158 * Throws {@link IllegalArgumentException} if the given restriction name is invalid.
159 */
160 public static boolean isValidRestriction(@NonNull String restriction) {
161 if (!USER_RESTRICTIONS.contains(restriction)) {
Makoto Onukiad5619d2016-02-10 13:41:15 -0800162 Slog.e(TAG, "Unknown restriction: " + restriction);
Makoto Onuki1f1ceef2016-01-28 11:32:32 -0800163 return false;
164 }
165 return true;
166 }
167
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800168 public static void writeRestrictions(@NonNull XmlSerializer serializer,
169 @Nullable Bundle restrictions, @NonNull String tag) throws IOException {
170 if (restrictions == null) {
171 return;
172 }
173
Makoto Onukia4f11972015-10-01 13:19:58 -0700174 serializer.startTag(null, tag);
Makoto Onukiac65e1e2015-11-20 15:33:17 -0800175 for (String key : restrictions.keySet()) {
176 if (NON_PERSIST_USER_RESTRICTIONS.contains(key)) {
177 continue; // Don't persist.
Makoto Onukia4f11972015-10-01 13:19:58 -0700178 }
Makoto Onukiac65e1e2015-11-20 15:33:17 -0800179 if (USER_RESTRICTIONS.contains(key)) {
180 if (restrictions.getBoolean(key)) {
181 serializer.attribute(null, key, "true");
182 }
183 continue;
184 }
185 Log.w(TAG, "Unknown user restriction detected: " + key);
Makoto Onukia4f11972015-10-01 13:19:58 -0700186 }
187 serializer.endTag(null, tag);
188 }
189
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100190 public static void readRestrictions(XmlPullParser parser, Bundle restrictions) {
Makoto Onukia4f11972015-10-01 13:19:58 -0700191 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 Onuki1a2cd742015-11-16 13:51:27 -0800199 /**
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 Onuki068c54a2015-10-13 14:34:03 -0700224 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 Onuki4f160732015-10-27 17:15:38 -0700234 /**
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800235 * @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 Onuki5485ed42015-12-09 11:38:23 -0800242 * @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 Onuki1a2cd742015-11-16 13:51:27 -0800244 */
Makoto Onuki5485ed42015-12-09 11:38:23 -0800245 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 Onuki1a2cd742015-11-16 13:51:27 -0800249 }
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 Onuki4f160732015-10-27 17:15:38 -0700300 * Takes a new use restriction set and the previous set, and apply the restrictions that have
301 * changed.
Makoto Onukid45a4a22015-11-02 17:17:38 -0800302 *
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700303 * <p>Note this method is called by {@link UserManagerService} without holding any locks.
Makoto Onuki4f160732015-10-27 17:15:38 -0700304 */
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700305 public static void applyUserRestrictions(Context context, int userId,
Makoto Onukid45a4a22015-11-02 17:17:38 -0800306 Bundle newRestrictions, Bundle prevRestrictions) {
Makoto Onuki4f160732015-10-27 17:15:38 -0700307 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 Kupolov9cbfc9e2015-10-07 15:52:33 -0700312 applyUserRestriction(context, userId, key, newValue);
Makoto Onuki4f160732015-10-27 17:15:38 -0700313 }
314 }
315 }
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700316
Makoto Onukid45a4a22015-11-02 17:17:38 -0800317 /**
318 * Apply each user restriction.
319 *
Makoto Onuki28da2e32015-11-20 11:30:44 -0800320 * <p>See also {@link
321 * com.android.providers.settings.SettingsProvider#isGlobalOrSecureSettingRestrictedForUser},
322 * which should be in sync with this method.
Makoto Onukid45a4a22015-11-02 17:17:38 -0800323 */
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700324 private static void applyUserRestriction(Context context, int userId, String key,
Makoto Onuki4f160732015-10-27 17:15:38 -0700325 boolean newValue) {
Makoto Onuki1a2cd742015-11-16 13:51:27 -0800326 if (UserManagerService.DBG) {
327 Log.d(TAG, "Applying user restriction: userId=" + userId
328 + " key=" + key + " value=" + newValue);
329 }
Makoto Onuki4f160732015-10-27 17:15:38 -0700330 // 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.
Benjamin Franz0ff13fc2016-07-12 13:42:21 +0100336 // WARNING: Remember that Settings.Global and Settings.Secure are changeable via adb.
337 // To prevent this from happening for a given user restriction, you have to add a check to
338 // SettingsProvider.isGlobalOrSecureSettingRestrictedForUser.
Makoto Onuki4f160732015-10-27 17:15:38 -0700339
340 final ContentResolver cr = context.getContentResolver();
341 final long id = Binder.clearCallingIdentity();
342 try {
343 switch (key) {
Makoto Onuki4f160732015-10-27 17:15:38 -0700344 case UserManager.DISALLOW_CONFIG_WIFI:
345 if (newValue) {
346 android.provider.Settings.Secure.putIntForUser(cr,
Makoto Onuki28da2e32015-11-20 11:30:44 -0800347 android.provider.Settings.Global
Makoto Onuki4f160732015-10-27 17:15:38 -0700348 .WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId);
349 }
350 break;
Mahaver Chopradea471e2015-12-17 11:02:37 +0000351 case UserManager.DISALLOW_DATA_ROAMING:
352 if (newValue) {
353 // DISALLOW_DATA_ROAMING user restriction is set.
354
355 // Multi sim device.
356 SubscriptionManager subscriptionManager = new SubscriptionManager(context);
357 final List<SubscriptionInfo> subscriptionInfoList =
358 subscriptionManager.getActiveSubscriptionInfoList();
359 if (subscriptionInfoList != null) {
360 for (SubscriptionInfo subInfo : subscriptionInfoList) {
361 android.provider.Settings.Global.putStringForUser(cr,
362 android.provider.Settings.Global.DATA_ROAMING
363 + subInfo.getSubscriptionId(), "0", userId);
364 }
365 }
366
367 // Single sim device.
368 android.provider.Settings.Global.putStringForUser(cr,
369 android.provider.Settings.Global.DATA_ROAMING, "0", userId);
370 }
371 break;
Makoto Onuki4f160732015-10-27 17:15:38 -0700372 case UserManager.DISALLOW_SHARE_LOCATION:
373 if (newValue) {
374 android.provider.Settings.Secure.putIntForUser(cr,
375 android.provider.Settings.Secure.LOCATION_MODE,
376 android.provider.Settings.Secure.LOCATION_MODE_OFF,
377 userId);
Makoto Onuki4f160732015-10-27 17:15:38 -0700378 }
Makoto Onuki4f160732015-10-27 17:15:38 -0700379 break;
380 case UserManager.DISALLOW_DEBUGGING_FEATURES:
381 if (newValue) {
382 // Only disable adb if changing for system user, since it is global
383 // TODO: should this be admin user?
384 if (userId == UserHandle.USER_SYSTEM) {
385 android.provider.Settings.Global.putStringForUser(cr,
386 android.provider.Settings.Global.ADB_ENABLED, "0",
387 userId);
388 }
389 }
390 break;
391 case UserManager.ENSURE_VERIFY_APPS:
392 if (newValue) {
393 android.provider.Settings.Global.putStringForUser(
394 context.getContentResolver(),
395 android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, "1",
396 userId);
397 android.provider.Settings.Global.putStringForUser(
398 context.getContentResolver(),
399 android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, "1",
400 userId);
401 }
402 break;
403 case UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES:
404 if (newValue) {
405 android.provider.Settings.Secure.putIntForUser(cr,
406 android.provider.Settings.Secure.INSTALL_NON_MARKET_APPS, 0,
407 userId);
408 }
409 break;
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700410 case UserManager.DISALLOW_RUN_IN_BACKGROUND:
411 if (newValue) {
412 int currentUser = ActivityManager.getCurrentUser();
413 if (currentUser != userId && userId != UserHandle.USER_SYSTEM) {
414 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800415 ActivityManager.getService().stopUser(userId, false, null);
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700416 } catch (RemoteException e) {
417 throw e.rethrowAsRuntimeException();
418 }
419 }
420 }
Lenka Trochtova6474f0e2016-03-24 16:43:10 +0100421 break;
422 case UserManager.DISALLOW_SAFE_BOOT:
423 // Unlike with the other restrictions, we want to propagate the new value to
424 // the system settings even if it is false. The other restrictions modify
425 // settings which could be manually changed by the user from the Settings app
426 // after the policies enforcing these restrictions have been revoked, so we
427 // leave re-setting of those settings to the user.
428 android.provider.Settings.Global.putInt(
429 context.getContentResolver(),
430 android.provider.Settings.Global.SAFE_BOOT_DISALLOWED,
431 newValue ? 1 : 0);
432 break;
Mahaver Chopra830e32c2016-05-17 18:53:09 +0100433 case UserManager.DISALLOW_FACTORY_RESET:
Mahaver Chopra3d9805d2016-07-07 16:25:05 +0100434 case UserManager.DISALLOW_OEM_UNLOCK:
Mahaver Chopra830e32c2016-05-17 18:53:09 +0100435 if (newValue) {
436 PersistentDataBlockManager manager = (PersistentDataBlockManager) context
437 .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
Esteban Talaverac48b20f2016-08-11 11:23:40 +0100438 if (manager != null
439 && manager.getOemUnlockEnabled()
440 && manager.getFlashLockState()
441 != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) {
442 // Only disable OEM unlock if the bootloader is locked. If it's already
443 // unlocked, setting the OEM unlock enabled flag to false has no effect
444 // (the bootloader would remain unlocked).
Mahaver Chopra830e32c2016-05-17 18:53:09 +0100445 manager.setOemUnlockEnabled(false);
446 }
447 }
Tony Makc1205112016-07-22 16:02:59 +0100448 break;
Makoto Onuki4f160732015-10-27 17:15:38 -0700449 }
Makoto Onuki4f160732015-10-27 17:15:38 -0700450 } finally {
451 Binder.restoreCallingIdentity(id);
452 }
453 }
454
Makoto Onukia4f11972015-10-01 13:19:58 -0700455 public static void dumpRestrictions(PrintWriter pw, String prefix, Bundle restrictions) {
456 boolean noneSet = true;
457 if (restrictions != null) {
458 for (String key : restrictions.keySet()) {
459 if (restrictions.getBoolean(key, false)) {
460 pw.println(prefix + key);
461 noneSet = false;
462 }
463 }
Makoto Onuki068c54a2015-10-13 14:34:03 -0700464 if (noneSet) {
465 pw.println(prefix + "none");
466 }
467 } else {
468 pw.println(prefix + "null");
Makoto Onukia4f11972015-10-01 13:19:58 -0700469 }
470 }
471}