@@ -90,6 +90,15 @@ abstract static class Keys {
90
90
LOCK_SCREEN_MESSAGE
91
91
}));
92
92
93
+ /**
94
+ * Preferences that are allowed only in MNC+ if it is profile owner. This does not restrict
95
+ * device owner.
96
+ */
97
+ static final Set <String > PROFILE_OWNER_ONLY_MNC_PLUS
98
+ = new HashSet <>(Arrays .asList (new String [] {
99
+ KEYGUARD_FEATURES_CATEGORY
100
+ }));
101
+
93
102
static final Set <String > NYC_PLUS
94
103
= new HashSet <>(Arrays .asList (new String [] {
95
104
LOCK_SCREEN_MESSAGE
@@ -134,6 +143,7 @@ public void onCreate(Bundle savedInstanceState) {
134
143
setup (Keys .MAX_TIME_SCREEN_LOCK ,
135
144
TimeUnit .MILLISECONDS .toSeconds (getDpm ().getMaximumTimeToLock (getAdmin ())));
136
145
146
+ disableIncompatibleManagementOptionsInCurrentProfile ();
137
147
final int disabledFeatures = getDpm ().getKeyguardDisabledFeatures (getAdmin ());
138
148
for (Map .Entry <String , Integer > flag : KEYGUARD_FEATURES .entrySet ()) {
139
149
setup (flag .getKey (), (disabledFeatures & flag .getValue ()) != 0 ? true : false );
@@ -219,7 +229,9 @@ private void updateAggregates() {
219
229
*/
220
230
private void setup (String key , Object adminSetting ) {
221
231
Preference pref = findPreference (key );
222
-
232
+ if (!pref .isEnabled ()) {
233
+ return ;
234
+ }
223
235
// If the preference is not applicable, just hide it instead.
224
236
if ((Keys .NOT_APPLICABLE_TO_PARENT .contains (key ) && isParentProfileInstance ())
225
237
|| (Keys .NOT_APPLICABLE_TO_PROFILE .contains (key ) && isManagedProfileInstance ())
@@ -245,6 +257,14 @@ private void setup(String key, Object adminSetting) {
245
257
pref .setOnPreferenceChangeListener (this );
246
258
}
247
259
260
+ private void disableIncompatibleManagementOptionsInCurrentProfile () {
261
+ if (isProfileOwner () && Util .isBeforeM ()) {
262
+ for (String preference : Keys .PROFILE_OWNER_ONLY_MNC_PLUS ) {
263
+ findPreference (preference ).setEnabled (false );
264
+ }
265
+ }
266
+ }
267
+
248
268
private int parseInt (String value ) throws NumberFormatException {
249
269
return value .length () != 0 ? Integer .parseInt (value ) : 0 ;
250
270
}
@@ -257,6 +277,10 @@ private boolean isDeviceOwner() {
257
277
return getDpm ().isDeviceOwnerApp (getContext ().getPackageName ());
258
278
}
259
279
280
+ private boolean isProfileOwner () {
281
+ return getDpm ().isProfileOwnerApp (getContext ().getPackageName ());
282
+ }
283
+
260
284
private void showToast (int titleId ) {
261
285
Toast .makeText (getActivity (), titleId , Toast .LENGTH_SHORT ).show ();
262
286
}
0 commit comments