Skip to content

Commit 07a6b2e

Browse files
committed
Added DISALLOW_SET_USER_ICON and DISALLOW_SET_WALLPAPER restrictions.
Added user restrictions DISALLOW_SET_USER_ICON and DISALLOW_SET_WALLPAPER from Android N. BUG: 27810680 Change-Id: I1f465ade705452768f1c2420c28609603351abb6 (cherry picked from commit f4602a96e930d52569dd7e2b81b980740f986935)
1 parent 1497758 commit 07a6b2e

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@
1616

1717
package com.afwsamples.testdpc.policy;
1818

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-
3719
import static android.os.UserManager.ALLOW_PARENT_PROFILE_APP_LINKING;
3820
import static android.os.UserManager.DISALLOW_ADD_USER;
3921
import static android.os.UserManager.DISALLOW_ADJUST_VOLUME;
@@ -60,13 +42,32 @@
6042
import static android.os.UserManager.DISALLOW_OUTGOING_CALLS;
6143
import static android.os.UserManager.DISALLOW_REMOVE_USER;
6244
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;
6347
import static android.os.UserManager.DISALLOW_SHARE_LOCATION;
6448
import static android.os.UserManager.DISALLOW_SMS;
6549
import static android.os.UserManager.DISALLOW_UNINSTALL_APPS;
6650
import static android.os.UserManager.DISALLOW_UNMUTE_MICROPHONE;
6751
import static android.os.UserManager.DISALLOW_USB_FILE_TRANSFER;
6852
import static android.os.UserManager.ENSURE_VERIFY_APPS;
6953

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+
7071
public class UserRestrictionsDisplayFragment extends PreferenceFragment
7172
implements Preference.OnPreferenceChangeListener {
7273
private static final String TAG = "UserRestrictions";
@@ -109,6 +110,8 @@ public class UserRestrictionsDisplayFragment extends PreferenceFragment
109110
new UserRestriction(DISALLOW_OUTGOING_CALLS, R.string.disallow_outgoing_calls),
110111
new UserRestriction(DISALLOW_REMOVE_USER, R.string.disallow_remove_user),
111112
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),
112115
new UserRestriction(DISALLOW_SHARE_LOCATION, R.string.disallow_share_location),
113116
new UserRestriction(DISALLOW_SMS, R.string.disallow_sms),
114117
new UserRestriction(DISALLOW_UNINSTALL_APPS, R.string.disallow_uninstall_apps),
@@ -150,6 +153,13 @@ public class UserRestrictionsDisplayFragment extends PreferenceFragment
150153
DISALLOW_CROSS_PROFILE_COPY_PASTE
151154
};
152155

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+
153163
/**
154164
* These user restrictions are added in MNC.
155165
*/
@@ -159,7 +169,9 @@ public class UserRestrictionsDisplayFragment extends PreferenceFragment
159169
};
160170

161171
private static String[] NYC_PLUS_RESTRICTIONS = {
162-
DISALLOW_DATA_ROAMING
172+
DISALLOW_DATA_ROAMING,
173+
DISALLOW_SET_USER_ICON,
174+
DISALLOW_SET_WALLPAPER
163175
};
164176

165177
public static UserRestrictionsDisplayFragment newInstance() {
@@ -262,6 +274,19 @@ private void disableIncompatibleRestrictionsByUserType() {
262274
findPreference(restriction).setEnabled(false);
263275
}
264276
}
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;
265290
}
266291

267292
private static class UserRestriction {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@
287287
<string name="disallow_outgoing_calls">Disallow outgoing calls</string>
288288
<string name="disallow_remove_user">Disallow remove user</string>
289289
<string name="disallow_safe_boot">Disallow safe boot</string>
290+
<string name="disallow_set_user_icon">Disallow set user icon</string>
291+
<string name="disallow_set_wallpaper">Disallow set wallpaper</string>
290292
<string name="disallow_share_location">Disallow share location</string>
291293
<string name="disallow_sms">Disallow sms</string>
292294
<string name="disallow_uninstall_apps">Disallow uninstall apps</string>

0 commit comments

Comments
 (0)