Skip to content

Commit 7d4a447

Browse files
Alex JohnstonAndroid (Google) Code Review
authored andcommitted
Merge "Update user restrictions on parent in TestDPC" into ub-testdpc-rvc
2 parents 9abe9d9 + 8926f86 commit 7d4a447

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.ComponentName;
55
import android.content.Context;
66
import android.os.Bundle;
7-
import android.os.UserManager;
87
import android.util.Log;
98
import android.widget.Toast;
109

@@ -24,22 +23,21 @@ public class UserRestrictionsParentDisplayFragment extends BaseSearchablePolicyP
2423
private static final String TAG = "UserRestrictionsParent";
2524

2625
private DevicePolicyManager mParentDevicePolicyManager;
27-
private UserManager mUserManager;
2826
private ComponentName mAdminComponentName;
2927

3028
@RequiresApi(api = Util.R_VERSION_CODE)
3129
@Override
3230
public void onCreate(Bundle savedInstanceState) {
3331
DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager)
3432
getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
35-
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
3633
mAdminComponentName = DeviceAdminReceiver.getComponentName(getActivity());
3734
mParentDevicePolicyManager = mDevicePolicyManager
3835
.getParentProfileInstance(mAdminComponentName);
3936
super.onCreate(savedInstanceState);
4037
getActivity().getActionBar().setTitle(R.string.user_restrictions_management_title);
4138
}
4239

40+
@RequiresApi(api = Util.R_VERSION_CODE)
4341
@Override
4442
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
4543
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
@@ -59,6 +57,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
5957
constrainPreferences();
6058
}
6159

60+
@RequiresApi(api = Util.R_VERSION_CODE)
6261
@Override
6362
public void onResume() {
6463
super.onResume();
@@ -70,6 +69,7 @@ public boolean isAvailable(Context context) {
7069
return true;
7170
}
7271

72+
@RequiresApi(api = Util.R_VERSION_CODE)
7373
@Override
7474
public boolean onPreferenceChange(Preference preference, Object newValue) {
7575
String restriction = preference.getKey();
@@ -89,16 +89,18 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
8989
}
9090
}
9191

92+
@RequiresApi(api = Util.R_VERSION_CODE)
9293
private void updateAllUserRestrictions() {
9394
for (UserRestriction restriction : UserRestriction.PROFILE_OWNER_ORG_DEVICE_RESTRICTIONS) {
9495
updateUserRestriction(restriction.key);
9596
}
9697
}
9798

99+
@RequiresApi(api = Util.R_VERSION_CODE)
98100
private void updateUserRestriction(String userRestriction) {
99101
DpcSwitchPreference preference = (DpcSwitchPreference) findPreference(userRestriction);
100-
boolean disallowed = mUserManager.hasUserRestriction(userRestriction);
101-
preference.setChecked(disallowed);
102+
Bundle restrictions = mParentDevicePolicyManager.getUserRestrictions(mAdminComponentName);
103+
preference.setChecked(restrictions.containsKey(userRestriction));
102104
}
103105

104106
private void constrainPreferences() {

0 commit comments

Comments
 (0)