16
16
17
17
package com .afwsamples .testdpc .policy ;
18
18
19
- import android .app .AlertDialog ;
20
- import android .app .admin .DevicePolicyManager ;
21
- import android .content .ComponentName ;
22
- import android .content .Context ;
23
- import android .os .Build ;
24
- import android .os .Bundle ;
25
- import android .os .UserManager ;
26
- import android .preference .Preference ;
27
- import android .preference .PreferenceFragment ;
28
- import android .preference .PreferenceScreen ;
29
- import android .preference .SwitchPreference ;
30
- import android .util .Log ;
31
- import android .widget .Toast ;
32
-
33
- import com .afwsamples .testdpc .DeviceAdminReceiver ;
34
- import com .afwsamples .testdpc .R ;
35
- import com .afwsamples .testdpc .common .Util ;
36
-
37
19
import static android .os .UserManager .ALLOW_PARENT_PROFILE_APP_LINKING ;
38
20
import static android .os .UserManager .DISALLOW_ADD_USER ;
39
21
import static android .os .UserManager .DISALLOW_ADJUST_VOLUME ;
60
42
import static android .os .UserManager .DISALLOW_OUTGOING_CALLS ;
61
43
import static android .os .UserManager .DISALLOW_REMOVE_USER ;
62
44
import static android .os .UserManager .DISALLOW_SAFE_BOOT ;
45
+ import static android .os .UserManager .DISALLOW_SET_USER_ICON ;
46
+ import static android .os .UserManager .DISALLOW_SET_WALLPAPER ;
63
47
import static android .os .UserManager .DISALLOW_SHARE_LOCATION ;
64
48
import static android .os .UserManager .DISALLOW_SMS ;
65
49
import static android .os .UserManager .DISALLOW_UNINSTALL_APPS ;
66
50
import static android .os .UserManager .DISALLOW_UNMUTE_MICROPHONE ;
67
51
import static android .os .UserManager .DISALLOW_USB_FILE_TRANSFER ;
68
52
import static android .os .UserManager .ENSURE_VERIFY_APPS ;
69
53
54
+ import android .app .AlertDialog ;
55
+ import android .app .admin .DevicePolicyManager ;
56
+ import android .content .ComponentName ;
57
+ import android .content .Context ;
58
+ import android .os .Bundle ;
59
+ import android .os .UserManager ;
60
+ import android .preference .Preference ;
61
+ import android .preference .PreferenceFragment ;
62
+ import android .preference .PreferenceScreen ;
63
+ import android .preference .SwitchPreference ;
64
+ import android .util .Log ;
65
+ import android .widget .Toast ;
66
+
67
+ import com .afwsamples .testdpc .DeviceAdminReceiver ;
68
+ import com .afwsamples .testdpc .R ;
69
+ import com .afwsamples .testdpc .common .Util ;
70
+
70
71
public class UserRestrictionsDisplayFragment extends PreferenceFragment
71
72
implements Preference .OnPreferenceChangeListener {
72
73
private static final String TAG = "UserRestrictions" ;
@@ -109,6 +110,8 @@ public class UserRestrictionsDisplayFragment extends PreferenceFragment
109
110
new UserRestriction (DISALLOW_OUTGOING_CALLS , R .string .disallow_outgoing_calls ),
110
111
new UserRestriction (DISALLOW_REMOVE_USER , R .string .disallow_remove_user ),
111
112
new UserRestriction (DISALLOW_SAFE_BOOT , R .string .disallow_safe_boot ),
113
+ new UserRestriction (DISALLOW_SET_USER_ICON , R .string .disallow_set_user_icon ),
114
+ new UserRestriction (DISALLOW_SET_WALLPAPER , R .string .disallow_set_wallpaper ),
112
115
new UserRestriction (DISALLOW_SHARE_LOCATION , R .string .disallow_share_location ),
113
116
new UserRestriction (DISALLOW_SMS , R .string .disallow_sms ),
114
117
new UserRestriction (DISALLOW_UNINSTALL_APPS , R .string .disallow_uninstall_apps ),
@@ -150,6 +153,13 @@ public class UserRestrictionsDisplayFragment extends PreferenceFragment
150
153
DISALLOW_CROSS_PROFILE_COPY_PASTE
151
154
};
152
155
156
+ /**
157
+ * These restrictions are not meant to be used with managed profiles.
158
+ */
159
+ private static String [] NON_MANAGED_PROFILE_RESTRICTIONS = {
160
+ DISALLOW_SET_WALLPAPER
161
+ };
162
+
153
163
/**
154
164
* These user restrictions are added in MNC.
155
165
*/
@@ -159,7 +169,9 @@ public class UserRestrictionsDisplayFragment extends PreferenceFragment
159
169
};
160
170
161
171
private static String [] NYC_PLUS_RESTRICTIONS = {
162
- DISALLOW_DATA_ROAMING
172
+ DISALLOW_DATA_ROAMING ,
173
+ DISALLOW_SET_USER_ICON ,
174
+ DISALLOW_SET_WALLPAPER
163
175
};
164
176
165
177
public static UserRestrictionsDisplayFragment newInstance () {
@@ -262,6 +274,19 @@ private void disableIncompatibleRestrictionsByUserType() {
262
274
findPreference (restriction ).setEnabled (false );
263
275
}
264
276
}
277
+
278
+ if (isManagedProfile ()) {
279
+ for (String restriction : NON_MANAGED_PROFILE_RESTRICTIONS ) {
280
+ findPreference (restriction ).setEnabled (false );
281
+ }
282
+ }
283
+ }
284
+
285
+ private boolean isManagedProfile () {
286
+ // If user has more than one profile, then we deal with managed profile.
287
+ // Unfortunately there is no public API available to distinguish user profile owner
288
+ // and managed profile owner. Thus using this hack.
289
+ return mUserManager .getUserProfiles ().size () > 1 ;
265
290
}
266
291
267
292
private static class UserRestriction {
0 commit comments