Skip to content

Commit c636254

Browse files
jscott1989pfmaggi
authored andcommitted
No public description
PiperOrigin-RevId: 634690620
1 parent 7af5e3a commit c636254

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/main/java/com/afwsamples/testdpc/ShellCommand.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ public void run() {
247247
ordinalParam(String.class, "restriction"),
248248
ordinalParam(boolean.class, "enabled"))
249249
.setDescription("Set the given user restriction."));
250+
flags.addCommand(
251+
command(
252+
"set-user-restriction-on-parent",
253+
this::setUserRestrictionOnParent,
254+
ordinalParam(String.class, "restriction"),
255+
ordinalParam(boolean.class, "enabled"))
256+
.setDescription("Set the given user restriction on the parent user."));
250257
flags.addCommand(
251258
command("lock-now", this::lockNow, optional(namedParam(int.class, "flags")))
252259
.setDescription("Lock the device (now! :-)."));
@@ -789,6 +796,19 @@ private void setUserRestriction(String userRestriction, boolean enabled) {
789796
(e) -> onError(e, "Error setting user restriction '%s' to %b", userRestriction, enabled));
790797
}
791798

799+
private void setUserRestrictionOnParent(String userRestriction, boolean enabled) {
800+
Log.i(TAG, "setUserRestrictionOnParent(" + userRestriction + ", " + enabled + ")");
801+
DevicePolicyManagerGateway parentDpmGateway =
802+
DevicePolicyManagerGatewayImpl.forParentProfile(mContext);
803+
parentDpmGateway.setUserRestriction(
804+
userRestriction,
805+
enabled,
806+
(v) -> onSuccess("User restriction '%s' set to %b", userRestriction, enabled),
807+
(e) ->
808+
onError(
809+
e, "Error setting parent user restriction '%s' to %b", userRestriction, enabled));
810+
}
811+
792812
private void lockNow(Integer flags) {
793813
if (flags == null) {
794814
Log.i(TAG, "lockNow()");

src/main/java/com/afwsamples/testdpc/policy/UserRestriction.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_LOCK_CREDENTIALS;
1111
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_MOBILE_NETWORK;
1212
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_MODIFY_USERS;
13+
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_PROFILES;
1314
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_RESTRICT_PRIVATE_DNS;
1415
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_SAFE_BOOT;
1516
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_SMS;
@@ -19,6 +20,7 @@
1920
import static android.Manifest.permission.MANAGE_DEVICE_POLICY_WIFI;
2021
import static android.os.UserManager.ALLOW_PARENT_PROFILE_APP_LINKING;
2122
import static android.os.UserManager.DISALLOW_ADD_MANAGED_PROFILE;
23+
import static android.os.UserManager.DISALLOW_ADD_PRIVATE_PROFILE;
2224
import static android.os.UserManager.DISALLOW_ADD_USER;
2325
import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
2426
import static android.os.UserManager.DISALLOW_ADJUST_VOLUME;
@@ -221,6 +223,10 @@ public UserRestriction(String key, int titleResId, String permission) {
221223
new UserRestriction(DISALLOW_ULTRA_WIDEBAND_RADIO, R.string.disallow_ultra_wideband_radio),
222224
new UserRestriction(DISALLOW_ASSIST_CONTENT, R.string.disallow_assist_content),
223225
new UserRestriction(DISALLOW_SIM_GLOBALLY, R.string.disallow_sim_globally),
226+
new UserRestriction(
227+
DISALLOW_ADD_PRIVATE_PROFILE,
228+
R.string.disallow_add_private_profile,
229+
MANAGE_DEVICE_POLICY_PROFILES),
224230
};
225231

226232
/**
@@ -259,6 +265,7 @@ public UserRestriction(String key, int titleResId, String permission) {
259265
DISALLOW_ULTRA_WIDEBAND_RADIO,
260266
DISALLOW_CONFIG_BRIGHTNESS,
261267
DISALLOW_CONFIG_SCREEN_TIMEOUT,
268+
DISALLOW_ADD_PRIVATE_PROFILE,
262269
};
263270

264271
/** Setting these user restrictions only have effect on primary users. */
@@ -318,7 +325,8 @@ public UserRestriction(String key, int titleResId, String permission) {
318325
DISALLOW_AIRPLANE_MODE,
319326
DISALLOW_CONFIG_SCREEN_TIMEOUT,
320327
DISALLOW_CONFIG_BRIGHTNESS,
321-
DISALLOW_AMBIENT_DISPLAY
328+
DISALLOW_AMBIENT_DISPLAY,
329+
DISALLOW_ADD_PRIVATE_PROFILE,
322330
};
323331

324332
/** These user restrictions are added in MNC. */
@@ -376,7 +384,10 @@ public UserRestriction(String key, int titleResId, String permission) {
376384
public static String[] VIC_PLUS_RESTRICTIONS = {DISALLOW_SIM_GLOBALLY};
377385

378386
public static String[] VIC_PLUS_PARENT_RESTRICTIONS = {
379-
DISALLOW_CONFIG_BRIGHTNESS, DISALLOW_CONFIG_SCREEN_TIMEOUT, DISALLOW_ASSIST_CONTENT
387+
DISALLOW_CONFIG_BRIGHTNESS,
388+
DISALLOW_CONFIG_SCREEN_TIMEOUT,
389+
DISALLOW_ASSIST_CONTENT,
390+
DISALLOW_ADD_PRIVATE_PROFILE
380391
};
381392

382393
public static UserRestriction getRestriction(String restrictionKey) {

src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@
547547
<string name="disallow_ultra_wideband_radio">Disallow ultra wideband radio</string>
548548
<string name="disallow_assist_content">Disallow assist content</string>
549549
<string name="disallow_sim_globally">Disallow sim globally</string>
550+
<string name="disallow_add_private_profile">Disallow add private profile</string>
550551
<string name="user_restriction_error_msg">Operation not allowed</string>
551552

552553
<!-- Strings for select app -->

0 commit comments

Comments
 (0)