1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os;
import android.annotation.SystemApi;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.content.Context;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.util.Log;
import android.view.WindowManager.LayoutParams;
import com.android.internal.R;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Manages users and user details on a multi-user system.
*/
public class UserManager {
private static String TAG = "UserManager";
private final IUserManager mService;
private final Context mContext;
/**
* Specifies if a user is disallowed from adding and removing accounts.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
/**
* Specifies if a user is disallowed from changing Wi-Fi
* access points. The default value is <code>false</code>.
* <p/>This restriction has no effect in a managed profile.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
/**
* Specifies if a user is disallowed from installing applications.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
/**
* Specifies if a user is disallowed from uninstalling applications.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
/**
* Specifies if a user is disallowed from turning on location sharing.
* The default value is <code>false</code>.
* <p/>In a managed profile, location sharing always reflects the primary user's setting, but
* can be overridden and forced off by setting this restriction to true in the managed profile.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
/**
* Specifies if a user is disallowed from enabling the
* "Unknown Sources" setting, that allows installation of apps from unknown sources.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
/**
* Specifies if a user is disallowed from configuring bluetooth.
* This does <em>not</em> restrict the user from turning bluetooth on or off.
* The default value is <code>false</code>.
* <p/>This restriction has no effect in a managed profile.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
/**
* Specifies if a user is disallowed from transferring files over
* USB. This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
/**
* Specifies if a user is disallowed from configuring user
* credentials. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
/**
* When set on the primary user this specifies if the user can remove other users.
* When set on a secondary user, this specifies if the user can remove itself.
* This restriction has no effect on managed profiles.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_REMOVE_USER = "no_remove_user";
/**
* Specifies if a user is disallowed from enabling or
* accessing debugging features. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features";
/**
* Specifies if a user is disallowed from configuring VPN.
* The default value is <code>false</code>.
* This restriction has an effect in a managed profile only from
* {@link android.os.Build.VERSION_CODES#MNC}
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_VPN = "no_config_vpn";
/**
* Specifies if a user is disallowed from configuring Tethering
* & portable hotspots. This can only be set by device owners and profile owners on the
* primary user. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";
/**
* Specifies if a user is disallowed from resetting network settings
* from Settings. This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
* <p/>This restriction has no effect on secondary users and managed profiles since only the
* primary user can reset the network settings of the device.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_NETWORK_RESET = "no_network_reset";
/**
* Specifies if a user is disallowed from factory resetting
* from Settings. This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
* <p/>This restriction has no effect on secondary users and managed profiles since only the
* primary user can factory reset the device.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_FACTORY_RESET = "no_factory_reset";
/**
* Specifies if a user is disallowed from adding new users and
* profiles. This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
* <p/>This restriction has no effect on secondary users and managed profiles since only the
* primary user can add other users.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_ADD_USER = "no_add_user";
/**
* Specifies if a user is disallowed from disabling application
* verification. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps";
/**
* Specifies if a user is disallowed from configuring cell
* broadcasts. This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
* <p/>This restriction has no effect on secondary users and managed profiles since only the
* primary user can configure cell broadcasts.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts";
/**
* Specifies if a user is disallowed from configuring mobile
* networks. This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
* <p/>This restriction has no effect on secondary users and managed profiles since only the
* primary user can configure mobile networks.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks";
/**
* Specifies if a user is disallowed from modifying
* applications in Settings or launchers. The following actions will not be allowed when this
* restriction is enabled:
* <li>uninstalling apps</li>
* <li>disabling apps</li>
* <li>clearing app caches</li>
* <li>clearing app data</li>
* <li>force stopping apps</li>
* <li>clearing app defaults</li>
* <p>
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_APPS_CONTROL = "no_control_apps";
/**
* Specifies if a user is disallowed from mounting
* physical external media. This can only be set by device owners and profile owners on the
* primary user. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
/**
* Specifies if a user is disallowed from adjusting microphone
* volume. If set, the microphone will be muted. This can only be set by device owners
* and profile owners on the primary user. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
/**
* Specifies if a user is disallowed from adjusting the master
* volume. If set, the master volume will be muted. This can only be set by device owners
* and profile owners on the primary user. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume";
/**
* Specifies that the user is not allowed to make outgoing
* phone calls. Emergency calls are still permitted.
* The default value is <code>false</code>.
* <p/>This restriction has no effect on managed profiles since call intents are normally
* forwarded to the primary user.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
/**
* Specifies that the user is not allowed to send or receive
* SMS messages. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_SMS = "no_sms";
/**
* Specifies if the user is not allowed to have fun. In some cases, the
* device owner may wish to prevent the user from experiencing amusement or
* joy while using the device. The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_FUN = "no_fun";
/**
* Specifies that windows besides app windows should not be
* created. This will block the creation of the following types of windows.
* <li>{@link LayoutParams#TYPE_TOAST}</li>
* <li>{@link LayoutParams#TYPE_PHONE}</li>
* <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li>
* <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li>
* <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li>
* <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li>
*
* <p>This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows";
/**
* Specifies if what is copied in the clipboard of this profile can
* be pasted in related profiles. Does not restrict if the clipboard of related profiles can be
* pasted in this profile.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste";
/**
* Specifies if the user is not allowed to use NFC to beam out data from apps.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
/**
* Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction
* is always set for managed profiles.
* @hide
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_WALLPAPER = "no_wallpaper";
/**
* Specifies if the user is not allowed to reboot the device into safe boot mode.
* This can only be set by device owners and profile owners on the primary user.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_SAFE_BOOT = "no_safe_boot";
/**
* Specifies if a user is not allowed to record audio. This restriction is always enabled for
* background users. The default value is <code>false</code>.
*
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
* @hide
*/
public static final String DISALLOW_RECORD_AUDIO = "no_record_audio";
/**
* 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.
* If set:
* Intent filters of activities in the parent profile with action
* {@link android.content.Intent#ACTION_VIEW},
* category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which
* define a host can handle intents from the managed profile.
* The default value is <code>false</code>.
*
* <p/>Key for user restrictions.
* <p/>Type: Boolean
* @see #setUserRestrictions(Bundle)
* @see #getUserRestrictions()
*/
public static final String ALLOW_PARENT_PROFILE_APP_LINKING
= "allow_parent_profile_app_linking";
/**
* Application restriction key that is used to indicate the pending arrival
* of real restrictions for the app.
*
* <p>
* Applications that support restrictions should check for the presence of this key.
* A <code>true</code> value indicates that restrictions may be applied in the near
* future but are not available yet. It is the responsibility of any
* management application that sets this flag to update it when the final
* restrictions are enforced.
*
* <p/>Key for application restrictions.
* <p/>Type: Boolean
* @see android.app.admin.DevicePolicyManager#setApplicationRestrictions(
* android.content.ComponentName, String, Bundle)
* @see android.app.admin.DevicePolicyManager#getApplicationRestrictions(
* android.content.ComponentName, String)
*/
public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
/** @hide */
public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
/** @hide */
public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
/** @hide */
public static final int PIN_VERIFICATION_SUCCESS = -1;
private static UserManager sInstance = null;
/** @hide */
public synchronized static UserManager get(Context context) {
if (sInstance == null) {
sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
}
return sInstance;
}
/** @hide */
public UserManager(Context context, IUserManager service) {
mService = service;
mContext = context;
}
/**
* Returns whether the system supports multiple users.
* @return true if multiple users can be created by user, false if it is a single user device.
* @hide
*/
public static boolean supportsMultipleUsers() {
return getMaxSupportedUsers() > 1
&& SystemProperties.getBoolean("fw.show_multiuserui",
Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
}
/**
* Returns the user handle for the user that this process is running under.
*
* @return the user handle of this process.
* @hide
*/
public int getUserHandle() {
return UserHandle.myUserId();
}
/**
* Returns the user name of the user making this call. This call is only
* available to applications on the system image; it requires the
* MANAGE_USERS permission.
* @return the user name
*/
public String getUserName() {
try {
return mService.getUserInfo(getUserHandle()).name;
} catch (RemoteException re) {
Log.w(TAG, "Could not get user name", re);
return "";
}
}
/**
* Used to determine whether the user making this call is subject to
* teleportations.
*
* <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
* now automatically identify goats using advanced goat recognition technology.</p>
*
* @return Returns true if the user making this call is a goat.
*/
public boolean isUserAGoat() {
return mContext.getPackageManager()
.isPackageAvailable("com.coffeestainstudios.goatsimulator");
}
/**
* Used to check if this process is running under the system user. The system user
* is the initial user that is implicitly created on first boot and hosts most of the
* system services.
*
* @return whether this process is running under the system user.
*/
public boolean isSystemUser() {
return UserHandle.myUserId() == UserHandle.USER_OWNER;
}
/**
* @hide
* Returns whether the caller is running as an admin user. There can be more than one admin
* user.
*/
public boolean isAdminUser() {
UserInfo user = getUserInfo(UserHandle.myUserId());
return user != null ? user.isAdmin() : false;
}
/**
* Used to check if the user making this call is linked to another user. Linked users may have
* a reduced number of available apps, app restrictions and account restrictions.
* @return whether the user making this call is a linked user
* @hide
*/
public boolean isLinkedUser() {
try {
return mService.isRestricted();
} catch (RemoteException re) {
Log.w(TAG, "Could not check if user is limited ", re);
return false;
}
}
/**
* Checks if the calling app is running as a guest user.
* @return whether the caller is a guest user.
* @hide
*/
public boolean isGuestUser() {
UserInfo user = getUserInfo(UserHandle.myUserId());
return user != null ? user.isGuest() : false;
}
/**
* Checks if the calling app is running in a managed profile.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @return whether the caller is in a managed profile.
* @hide
*/
@SystemApi
public boolean isManagedProfile() {
UserInfo user = getUserInfo(UserHandle.myUserId());
return user != null ? user.isManagedProfile() : false;
}
/**
* Return whether the given user is actively running. This means that
* the user is in the "started" state, not "stopped" -- it is currently
* allowed to run code through scheduled alarms, receiving broadcasts,
* etc. A started user may be either the current foreground user or a
* background user; the result here does not distinguish between the two.
* @param user The user to retrieve the running state for.
*/
public boolean isUserRunning(UserHandle user) {
try {
return ActivityManagerNative.getDefault().isUserRunning(
user.getIdentifier(), false);
} catch (RemoteException e) {
return false;
}
}
/**
* Return whether the given user is actively running <em>or</em> stopping.
* This is like {@link #isUserRunning(UserHandle)}, but will also return
* true if the user had been running but is in the process of being stopped
* (but is not yet fully stopped, and still running some code).
* @param user The user to retrieve the running state for.
*/
public boolean isUserRunningOrStopping(UserHandle user) {
try {
return ActivityManagerNative.getDefault().isUserRunning(
user.getIdentifier(), true);
} catch (RemoteException e) {
return false;
}
}
/**
* Returns the UserInfo object describing a specific user.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle the user handle of the user whose information is being requested.
* @return the UserInfo object for a specific user.
* @hide
*/
public UserInfo getUserInfo(int userHandle) {
try {
return mService.getUserInfo(userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Could not get user info", re);
return null;
}
}
/**
* Returns the user-wide restrictions imposed on this user.
* @return a Bundle containing all the restrictions.
*/
public Bundle getUserRestrictions() {
return getUserRestrictions(Process.myUserHandle());
}
/**
* Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
* @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
* @return a Bundle containing all the restrictions.
*/
public Bundle getUserRestrictions(UserHandle userHandle) {
try {
return mService.getUserRestrictions(userHandle.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not get user restrictions", re);
return Bundle.EMPTY;
}
}
/**
* Sets all the user-wide restrictions for this user.
* Requires the MANAGE_USERS permission.
* @param restrictions the Bundle containing all the restrictions.
* @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
* android.content.ComponentName, String)} or
* {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
* android.content.ComponentName, String)} instead.
*/
@Deprecated
public void setUserRestrictions(Bundle restrictions) {
setUserRestrictions(restrictions, Process.myUserHandle());
}
/**
* Sets all the user-wide restrictions for the specified user.
* Requires the MANAGE_USERS permission.
* @param restrictions the Bundle containing all the restrictions.
* @param userHandle the UserHandle of the user for whom to set the restrictions.
* @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
* android.content.ComponentName, String)} or
* {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
* android.content.ComponentName, String)} instead.
*/
@Deprecated
public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
try {
mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not set user restrictions", re);
}
}
/**
* Sets the value of a specific restriction.
* Requires the MANAGE_USERS permission.
* @param key the key of the restriction
* @param value the value for the restriction
* @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
* android.content.ComponentName, String)} or
* {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
* android.content.ComponentName, String)} instead.
*/
@Deprecated
public void setUserRestriction(String key, boolean value) {
Bundle bundle = getUserRestrictions();
bundle.putBoolean(key, value);
setUserRestrictions(bundle);
}
/**
* @hide
* Sets the value of a specific restriction on a specific user.
* Requires the MANAGE_USERS permission.
* @param key the key of the restriction
* @param value the value for the restriction
* @param userHandle the user whose restriction is to be changed.
* @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction(
* android.content.ComponentName, String)} or
* {@link android.app.admin.DevicePolicyManager#clearUserRestriction(
* android.content.ComponentName, String)} instead.
*/
@Deprecated
public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
try {
mService.setUserRestriction(key, value, userHandle.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not set user restriction", re);
}
}
/**
* Returns whether the current user has been disallowed from performing certain actions
* or setting certain settings.
*
* @param restrictionKey The string key representing the restriction.
* @return {@code true} if the current user has the given restriction, {@code false} otherwise.
*/
public boolean hasUserRestriction(String restrictionKey) {
return hasUserRestriction(restrictionKey, Process.myUserHandle());
}
/**
* @hide
* Returns whether the given user has been disallowed from performing certain actions
* or setting certain settings.
* @param restrictionKey the string key representing the restriction
* @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
*/
public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
try {
return mService.hasUserRestriction(restrictionKey,
userHandle.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not check user restrictions", re);
return false;
}
}
/**
* Return the serial number for a user. This is a device-unique
* number assigned to that user; if the user is deleted and then a new
* user created, the new users will not be given the same serial number.
* @param user The user whose serial number is to be retrieved.
* @return The serial number of the given user; returns -1 if the
* given UserHandle does not exist.
* @see #getUserForSerialNumber(long)
*/
public long getSerialNumberForUser(UserHandle user) {
return getUserSerialNumber(user.getIdentifier());
}
/**
* Return the user associated with a serial number previously
* returned by {@link #getSerialNumberForUser(UserHandle)}.
* @param serialNumber The serial number of the user that is being
* retrieved.
* @return Return the user associated with the serial number, or null
* if there is not one.
* @see #getSerialNumberForUser(UserHandle)
*/
public UserHandle getUserForSerialNumber(long serialNumber) {
int ident = getUserHandle((int) serialNumber);
return ident >= 0 ? new UserHandle(ident) : null;
}
/**
* Creates a user with the specified name and options.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @param name the user's name
* @param flags flags that identify the type of user and other properties.
* @see UserInfo
*
* @return the UserInfo object for the created user, or null if the user could not be created.
* @hide
*/
public UserInfo createUser(String name, int flags) {
try {
return mService.createUser(name, flags);
} catch (RemoteException re) {
Log.w(TAG, "Could not create a user", re);
return null;
}
}
/**
* Creates a guest user and configures it.
* @param context an application context
* @param name the name to set for the user
* @hide
*/
public UserInfo createGuest(Context context, String name) {
UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
if (guest != null) {
Settings.Secure.putStringForUser(context.getContentResolver(),
Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
try {
Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
guestRestrictions.putBoolean(DISALLOW_SMS, true);
guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
mService.setUserRestrictions(guestRestrictions, guest.id);
} catch (RemoteException re) {
Log.w(TAG, "Could not update guest restrictions");
}
}
return guest;
}
/**
* Creates a secondary user with the specified name and options and configures it with default
* restrictions.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @param name the user's name
* @param flags flags that identify the type of user and other properties.
* @see UserInfo
*
* @return the UserInfo object for the created user, or null if the user could not be created.
* @hide
*/
public UserInfo createSecondaryUser(String name, int flags) {
try {
UserInfo user = mService.createUser(name, flags);
if (user == null) {
return null;
}
Bundle userRestrictions = mService.getUserRestrictions(user.id);
addDefaultUserRestrictions(userRestrictions);
mService.setUserRestrictions(userRestrictions, user.id);
return user;
} catch (RemoteException re) {
Log.w(TAG, "Could not create a user", re);
return null;
}
}
private static void addDefaultUserRestrictions(Bundle restrictions) {
restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
restrictions.putBoolean(DISALLOW_SMS, true);
}
/**
* Creates a user with the specified name and options as a profile of another user.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @param name the user's name
* @param flags flags that identify the type of user and other properties.
* @see UserInfo
* @param userHandle new user will be a profile of this use.
*
* @return the UserInfo object for the created user, or null if the user could not be created.
* @hide
*/
public UserInfo createProfileForUser(String name, int flags, int userHandle) {
try {
return mService.createProfileForUser(name, flags, userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Could not create a user", re);
return null;
}
}
/**
* @hide
* Marks the guest user for deletion to allow a new guest to be created before deleting
* the current user who is a guest.
* @param userHandle
* @return
*/
public boolean markGuestForDeletion(int userHandle) {
try {
return mService.markGuestForDeletion(userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Could not mark guest for deletion", re);
return false;
}
}
/**
* Sets the user as enabled, if such an user exists.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* Note that the default is true, it's only that managed profiles might not be enabled.
*
* @param userHandle the id of the profile to enable
* @hide
*/
public void setUserEnabled(int userHandle) {
try {
mService.setUserEnabled(userHandle);
} catch (RemoteException e) {
Log.w(TAG, "Could not enable the profile", e);
}
}
/**
* Return the number of users currently created on the device.
*/
public int getUserCount() {
List<UserInfo> users = getUsers();
return users != null ? users.size() : 1;
}
/**
* Returns information for all users on this device.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @return the list of users that were created.
* @hide
*/
public List<UserInfo> getUsers() {
try {
return mService.getUsers(false);
} catch (RemoteException re) {
Log.w(TAG, "Could not get user list", re);
return null;
}
}
/**
* Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS
* permission.
*
* @return true if more users can be added, false if limit has been reached.
* @hide
*/
public boolean canAddMoreUsers() {
final List<UserInfo> users = getUsers(true);
final int totalUserCount = users.size();
int aliveUserCount = 0;
for (int i = 0; i < totalUserCount; i++) {
UserInfo user = users.get(i);
if (!user.isGuest()) {
aliveUserCount++;
}
}
return aliveUserCount < getMaxSupportedUsers();
}
/**
* Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS
* permission.
*
* @return true if more managed profiles can be added, false if limit has been reached.
* @hide
*/
public boolean canAddMoreManagedProfiles() {
try {
return mService.canAddMoreManagedProfiles();
} catch (RemoteException re) {
Log.w(TAG, "Could not check if we can add more managed profiles", re);
return false;
}
}
/**
* Returns list of the profiles of userHandle including
* userHandle itself.
* Note that this returns both enabled and not enabled profiles. See
* {@link #getEnabledProfiles(int)} if you need only the enabled ones.
*
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle profiles of this user will be returned.
* @return the list of profiles.
* @hide
*/
public List<UserInfo> getProfiles(int userHandle) {
try {
return mService.getProfiles(userHandle, false /* enabledOnly */);
} catch (RemoteException re) {
Log.w(TAG, "Could not get user list", re);
return null;
}
}
/**
* Returns list of the profiles of userHandle including
* userHandle itself.
* Note that this returns only enabled.
*
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle profiles of this user will be returned.
* @return the list of profiles.
* @hide
*/
public List<UserInfo> getEnabledProfiles(int userHandle) {
try {
return mService.getProfiles(userHandle, true /* enabledOnly */);
} catch (RemoteException re) {
Log.w(TAG, "Could not get user list", re);
return null;
}
}
/**
* Returns a list of UserHandles for profiles associated with the user that the calling process
* is running on, including the user itself.
*
* @return A non-empty list of UserHandles associated with the calling user.
*/
public List<UserHandle> getUserProfiles() {
ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
List<UserInfo> users = new ArrayList<UserInfo>();
try {
users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
} catch (RemoteException re) {
Log.w(TAG, "Could not get user list", re);
return null;
}
for (UserInfo info : users) {
UserHandle userHandle = new UserHandle(info.id);
profiles.add(userHandle);
}
return profiles;
}
/**
* Returns the parent of the profile which this method is called from
* or null if called from a user that is not a profile.
*
* @hide
*/
public UserInfo getProfileParent(int userHandle) {
try {
return mService.getProfileParent(userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Could not get profile parent", re);
return null;
}
}
/**
* If the target user is a managed profile of the calling user or the caller
* is itself a managed profile, then this returns a badged copy of the given
* icon to be able to distinguish it from the original icon. For badging an
* arbitrary drawable use {@link #getBadgedDrawableForUser(
* android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
* <p>
* If the original drawable is a BitmapDrawable and the backing bitmap is
* mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
* is performed in place and the original drawable is returned.
* </p>
*
* @param icon The icon to badge.
* @param user The target user.
* @return A drawable that combines the original icon and a badge as
* determined by the system.
* @removed
*/
public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) {
return mContext.getPackageManager().getUserBadgedIcon(icon, user);
}
/**
* If the target user is a managed profile of the calling user or the caller
* is itself a managed profile, then this returns a badged copy of the given
* drawable allowing the user to distinguish it from the original drawable.
* The caller can specify the location in the bounds of the drawable to be
* badged where the badge should be applied as well as the density of the
* badge to be used.
* <p>
* If the original drawable is a BitmapDrawable and the backing bitmap is
* mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
* is performed in place and the original drawable is returned.
* </p>
*
* @param badgedDrawable The drawable to badge.
* @param user The target user.
* @param badgeLocation Where in the bounds of the badged drawable to place
* the badge. If not provided, the badge is applied on top of the entire
* drawable being badged.
* @param badgeDensity The optional desired density for the badge as per
* {@link android.util.DisplayMetrics#densityDpi}. If not provided,
* the density of the display is used.
* @return A drawable that combines the original drawable and a badge as
* determined by the system.
* @removed
*/
public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user,
Rect badgeLocation, int badgeDensity) {
return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
badgeLocation, badgeDensity);
}
/**
* If the target user is a managed profile of the calling user or the caller
* is itself a managed profile, then this returns a copy of the label with
* badging for accessibility services like talkback. E.g. passing in "Email"
* and it might return "Work Email" for Email in the work profile.
*
* @param label The label to change.
* @param user The target user.
* @return A label that combines the original label and a badge as
* determined by the system.
* @removed
*/
public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) {
return mContext.getPackageManager().getUserBadgedLabel(label, user);
}
/**
* Returns information for all users on this device. Requires
* {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @param excludeDying specify if the list should exclude users being
* removed.
* @return the list of users that were created.
* @hide
*/
public List<UserInfo> getUsers(boolean excludeDying) {
try {
return mService.getUsers(excludeDying);
} catch (RemoteException re) {
Log.w(TAG, "Could not get user list", re);
return null;
}
}
/**
* Removes a user and all associated data.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle the integer handle of the user, where 0 is the primary user.
* @hide
*/
public boolean removeUser(int userHandle) {
try {
return mService.removeUser(userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Could not remove user ", re);
return false;
}
}
/**
* Updates the user's name.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @param userHandle the user's integer handle
* @param name the new name for the user
* @hide
*/
public void setUserName(int userHandle, String name) {
try {
mService.setUserName(userHandle, name);
} catch (RemoteException re) {
Log.w(TAG, "Could not set the user name ", re);
}
}
/**
* Sets the user's photo.
* @param userHandle the user for whom to change the photo.
* @param icon the bitmap to set as the photo.
* @hide
*/
public void setUserIcon(int userHandle, Bitmap icon) {
try {
mService.setUserIcon(userHandle, icon);
} catch (RemoteException re) {
Log.w(TAG, "Could not set the user icon ", re);
}
}
/**
* Returns a file descriptor for the user's photo. PNG data can be read from this file.
* @param userHandle the user whose photo we want to read.
* @return a {@link Bitmap} of the user's photo, or null if there's no photo.
* @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
* @hide
*/
public Bitmap getUserIcon(int userHandle) {
try {
ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
if (fd != null) {
try {
return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
} finally {
try {
fd.close();
} catch (IOException e) {
}
}
}
} catch (RemoteException re) {
Log.w(TAG, "Could not get the user icon ", re);
}
return null;
}
/**
* Returns the maximum number of users that can be created on this device. A return value
* of 1 means that it is a single user device.
* @hide
* @return a value greater than or equal to 1
*/
public static int getMaxSupportedUsers() {
// Don't allow multiple users on certain builds
if (android.os.Build.ID.startsWith("JVP")) return 1;
// Svelte devices don't get multi-user.
if (ActivityManager.isLowRamDeviceStatic()) return 1;
return SystemProperties.getInt("fw.max_users",
Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
}
/**
* Returns true if the user switcher should be shown, this will be if there
* are multiple users that aren't managed profiles.
* @hide
* @return true if user switcher should be shown.
*/
public boolean isUserSwitcherEnabled() {
List<UserInfo> users = getUsers(true);
if (users == null) {
return false;
}
int switchableUserCount = 0;
for (UserInfo user : users) {
if (user.supportsSwitchTo()) {
++switchableUserCount;
}
}
final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.GUEST_USER_ENABLED, 0) == 1;
return switchableUserCount > 1 || guestEnabled;
}
/**
* Returns a serial number on this device for a given userHandle. User handles can be recycled
* when deleting and creating users, but serial numbers are not reused until the device is wiped.
* @param userHandle
* @return a serial number associated with that user, or -1 if the userHandle is not valid.
* @hide
*/
public int getUserSerialNumber(int userHandle) {
try {
return mService.getUserSerialNumber(userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Could not get serial number for user " + userHandle);
}
return -1;
}
/**
* Returns a userHandle on this device for a given user serial number. User handles can be
* recycled when deleting and creating users, but serial numbers are not reused until the device
* is wiped.
* @param userSerialNumber
* @return the userHandle associated with that user serial number, or -1 if the serial number
* is not valid.
* @hide
*/
public int getUserHandle(int userSerialNumber) {
try {
return mService.getUserHandle(userSerialNumber);
} catch (RemoteException re) {
Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
}
return -1;
}
/**
* Returns a Bundle containing any saved application restrictions for this user, for the
* given package name. Only an application with this package name can call this method.
* @param packageName the package name of the calling application
* @return a Bundle with the restrictions as key/value pairs, or null if there are no
* saved restrictions. The values can be of type Boolean, String or String[], depending
* on the restriction type, as defined by the application.
*/
public Bundle getApplicationRestrictions(String packageName) {
try {
return mService.getApplicationRestrictions(packageName);
} catch (RemoteException re) {
Log.w(TAG, "Could not get application restrictions for package " + packageName);
}
return null;
}
/**
* @hide
*/
public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
try {
return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
}
return null;
}
/**
* @hide
*/
public void setApplicationRestrictions(String packageName, Bundle restrictions,
UserHandle user) {
try {
mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
}
}
/**
* Sets a new challenge PIN for restrictions. This is only for use by pre-installed
* apps and requires the MANAGE_USERS permission.
* @param newPin the PIN to use for challenge dialogs.
* @return Returns true if the challenge PIN was set successfully.
* @deprecated The restrictions PIN functionality is no longer provided by the system.
* This method is preserved for backwards compatibility reasons and always returns false.
*/
public boolean setRestrictionsChallenge(String newPin) {
return false;
}
/** @hide */
public void removeRestrictions() {
try {
mService.removeRestrictions();
} catch (RemoteException re) {
Log.w(TAG, "Could not change restrictions pin");
}
}
/**
* @hide
* Set restrictions that should apply to any future guest user that's created.
*/
public void setDefaultGuestRestrictions(Bundle restrictions) {
try {
mService.setDefaultGuestRestrictions(restrictions);
} catch (RemoteException re) {
Log.w(TAG, "Could not set guest restrictions");
}
}
/**
* @hide
* Gets the default guest restrictions.
*/
public Bundle getDefaultGuestRestrictions() {
try {
return mService.getDefaultGuestRestrictions();
} catch (RemoteException re) {
Log.w(TAG, "Could not set guest restrictions");
}
return new Bundle();
}
/**
* Returns creation time of the user or of a managed profile associated with the calling user.
* @param userHandle user handle of the user or a managed profile associated with the
* calling user.
* @return creation time in milliseconds since Epoch time.
*/
public long getUserCreationTime(UserHandle userHandle) {
try {
return mService.getUserCreationTime(userHandle.getIdentifier());
} catch (RemoteException re) {
Log.w(TAG, "Could not get user creation time", re);
return 0;
}
}
}
|