Skip to content

Commit 9e94bb5

Browse files
Mahaver ChopraAndroid (Google) Code Review
authored andcommitted
Merge "Change KEYGUARD_PREFERENCES to KEYGUARD_FEATURES" into ub-testdpc-nyc
2 parents 8036358 + da455bb commit 9e94bb5

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ public class PolicyManagementFragment extends PreferenceFragment implements
216216
private static final String INSTALL_KEY_CERTIFICATE_KEY = "install_key_certificate";
217217
private static final String INSTALL_NONMARKET_APPS_KEY
218218
= "install_nonmarket_apps";
219-
private static final String KEYGUARD_PREFERENCES = "keyguard_preferences";
220219
private static final String LOCK_SCREEN_POLICY_KEY = "lock_screen_policy";
221220
private static final String MANAGE_APP_PERMISSIONS_KEY = "manage_app_permissions";
222221
private static final String MANAGE_APP_RESTRICTIONS_KEY = "manage_app_restrictions";
@@ -295,13 +294,9 @@ public class PolicyManagementFragment extends PreferenceFragment implements
295294
};
296295

297296
/**
298-
* Preferences that are allowed only in MNC+ if it profile owner. This does not restrict device
299-
* owner.
297+
* Preferences that are allowed only in NYC+ if it is profile owner. This does not restrict
298+
* device owner.
300299
*/
301-
private static String[] MANAGED_PROFILE_MNC_PLUS_PREFERENCES = {
302-
KEYGUARD_PREFERENCES
303-
};
304-
305300
private static String[] MANAGED_PROFILE_NYC_PLUS_PREFERENCES = {
306301
RESET_PASSWORD_KEY
307302
};
@@ -1027,11 +1022,6 @@ private void disableIncompatibleManagementOptionsInCurrentProfile() {
10271022
for (String preference : PRIMARY_USER_ONLY_PREFERENCES) {
10281023
findPreference(preference).setEnabled(false);
10291024
}
1030-
if (Util.isBeforeM()) {
1031-
for (String preference : MANAGED_PROFILE_MNC_PLUS_PREFERENCES) {
1032-
findPreference(preference).setEnabled(false);
1033-
}
1034-
}
10351025
if (Util.isBeforeN()) {
10361026
for (String preference : MANAGED_PROFILE_NYC_PLUS_PREFERENCES) {
10371027
findPreference(preference).setEnabled(false);

app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ abstract static class Keys {
9090
LOCK_SCREEN_MESSAGE
9191
}));
9292

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+
93102
static final Set<String> NYC_PLUS
94103
= new HashSet<>(Arrays.asList(new String[] {
95104
LOCK_SCREEN_MESSAGE
@@ -134,6 +143,7 @@ public void onCreate(Bundle savedInstanceState) {
134143
setup(Keys.MAX_TIME_SCREEN_LOCK,
135144
TimeUnit.MILLISECONDS.toSeconds(getDpm().getMaximumTimeToLock(getAdmin())));
136145

146+
disableIncompatibleManagementOptionsInCurrentProfile();
137147
final int disabledFeatures = getDpm().getKeyguardDisabledFeatures(getAdmin());
138148
for (Map.Entry<String, Integer> flag : KEYGUARD_FEATURES.entrySet()) {
139149
setup(flag.getKey(), (disabledFeatures & flag.getValue()) != 0 ? true : false);
@@ -219,7 +229,9 @@ private void updateAggregates() {
219229
*/
220230
private void setup(String key, Object adminSetting) {
221231
Preference pref = findPreference(key);
222-
232+
if (!pref.isEnabled()) {
233+
return;
234+
}
223235
// If the preference is not applicable, just hide it instead.
224236
if ((Keys.NOT_APPLICABLE_TO_PARENT.contains(key) && isParentProfileInstance())
225237
|| (Keys.NOT_APPLICABLE_TO_PROFILE.contains(key) && isManagedProfileInstance())
@@ -245,6 +257,14 @@ private void setup(String key, Object adminSetting) {
245257
pref.setOnPreferenceChangeListener(this);
246258
}
247259

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+
248268
private int parseInt(String value) throws NumberFormatException {
249269
return value.length() != 0 ? Integer.parseInt(value) : 0;
250270
}
@@ -257,6 +277,10 @@ private boolean isDeviceOwner() {
257277
return getDpm().isDeviceOwnerApp(getContext().getPackageName());
258278
}
259279

280+
private boolean isProfileOwner() {
281+
return getDpm().isProfileOwnerApp(getContext().getPackageName());
282+
}
283+
260284
private void showToast(int titleId) {
261285
Toast.makeText(getActivity(), titleId, Toast.LENGTH_SHORT).show();
262286
}

0 commit comments

Comments
 (0)