4
4
import android .content .ComponentName ;
5
5
import android .content .Context ;
6
6
import android .os .Bundle ;
7
- import android .os .UserManager ;
8
7
import android .util .Log ;
9
8
import android .widget .Toast ;
10
9
@@ -24,22 +23,21 @@ public class UserRestrictionsParentDisplayFragment extends BaseSearchablePolicyP
24
23
private static final String TAG = "UserRestrictionsParent" ;
25
24
26
25
private DevicePolicyManager mParentDevicePolicyManager ;
27
- private UserManager mUserManager ;
28
26
private ComponentName mAdminComponentName ;
29
27
30
28
@ RequiresApi (api = Util .R_VERSION_CODE )
31
29
@ Override
32
30
public void onCreate (Bundle savedInstanceState ) {
33
31
DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager )
34
32
getActivity ().getSystemService (Context .DEVICE_POLICY_SERVICE );
35
- mUserManager = (UserManager ) getActivity ().getSystemService (Context .USER_SERVICE );
36
33
mAdminComponentName = DeviceAdminReceiver .getComponentName (getActivity ());
37
34
mParentDevicePolicyManager = mDevicePolicyManager
38
35
.getParentProfileInstance (mAdminComponentName );
39
36
super .onCreate (savedInstanceState );
40
37
getActivity ().getActionBar ().setTitle (R .string .user_restrictions_management_title );
41
38
}
42
39
40
+ @ RequiresApi (api = Util .R_VERSION_CODE )
43
41
@ Override
44
42
public void onCreatePreferences (Bundle savedInstanceState , String rootKey ) {
45
43
PreferenceScreen preferenceScreen = getPreferenceManager ().createPreferenceScreen (
@@ -59,6 +57,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
59
57
constrainPreferences ();
60
58
}
61
59
60
+ @ RequiresApi (api = Util .R_VERSION_CODE )
62
61
@ Override
63
62
public void onResume () {
64
63
super .onResume ();
@@ -70,6 +69,7 @@ public boolean isAvailable(Context context) {
70
69
return true ;
71
70
}
72
71
72
+ @ RequiresApi (api = Util .R_VERSION_CODE )
73
73
@ Override
74
74
public boolean onPreferenceChange (Preference preference , Object newValue ) {
75
75
String restriction = preference .getKey ();
@@ -89,16 +89,18 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
89
89
}
90
90
}
91
91
92
+ @ RequiresApi (api = Util .R_VERSION_CODE )
92
93
private void updateAllUserRestrictions () {
93
94
for (UserRestriction restriction : UserRestriction .PROFILE_OWNER_ORG_DEVICE_RESTRICTIONS ) {
94
95
updateUserRestriction (restriction .key );
95
96
}
96
97
}
97
98
99
+ @ RequiresApi (api = Util .R_VERSION_CODE )
98
100
private void updateUserRestriction (String userRestriction ) {
99
101
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 ) );
102
104
}
103
105
104
106
private void constrainPreferences () {
0 commit comments