@@ -157,6 +157,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
157
157
setup (Keys .MIN_UPPERCASE , getDpm ().getPasswordMinimumUpperCase (getAdmin ()));
158
158
setup (Keys .MIN_SYMBOLS , getDpm ().getPasswordMinimumSymbols (getAdmin ()));
159
159
setup (Keys .MIN_NONLETTER , getDpm ().getPasswordMinimumNonLetter (getAdmin ()));
160
+
161
+ enableMinimumsForQuality ();
160
162
}
161
163
162
164
@ Override
@@ -199,6 +201,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
199
201
list .setValue ((String ) newValue );
200
202
summary = list .getEntry ();
201
203
getDpm ().setPasswordQuality (getAdmin (), value );
204
+ enableMinimumsForQuality ();
202
205
break ;
203
206
}
204
207
case Keys .MIN_LENGTH :
@@ -231,6 +234,55 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
231
234
return true ;
232
235
}
233
236
237
+ /**
238
+ * Enable and disable password constraint preferences based on the current password quality.
239
+ */
240
+ private void enableMinimumsForQuality () {
241
+ final int currentQuality = getDpm ().getPasswordQuality (getAdmin ());
242
+
243
+ // Minimum length can be set for most qualities
244
+ final EditTextPreference minLength = (EditTextPreference ) findPreference (Keys .MIN_LENGTH );
245
+ if (currentQuality >= DevicePolicyManager .PASSWORD_QUALITY_NUMERIC ) {
246
+ minLength .setEnabled (true );
247
+ enableEditTextPreference (minLength );
248
+ } else {
249
+ Util .disablePreference (minLength , R .string .not_for_password_quality );
250
+ }
251
+
252
+ // Other minimums are only active for the highest quality
253
+ final EditTextPreference minLetters = (EditTextPreference ) findPreference (Keys .MIN_LETTERS );
254
+ final EditTextPreference minNumeric = (EditTextPreference ) findPreference (Keys .MIN_NUMERIC );
255
+ final EditTextPreference minLower = (EditTextPreference ) findPreference (Keys .MIN_LOWERCASE );
256
+ final EditTextPreference minUpper = (EditTextPreference ) findPreference (Keys .MIN_UPPERCASE );
257
+ final EditTextPreference minSymbols = (EditTextPreference ) findPreference (Keys .MIN_SYMBOLS );
258
+ final EditTextPreference minNonLetter =
259
+ (EditTextPreference ) findPreference (Keys .MIN_NONLETTER );
260
+
261
+ if (currentQuality == DevicePolicyManager .PASSWORD_QUALITY_COMPLEX ) {
262
+ enableEditTextPreference (minLetters );
263
+ enableEditTextPreference (minNumeric );
264
+ enableEditTextPreference (minLower );
265
+ enableEditTextPreference (minUpper );
266
+ enableEditTextPreference (minSymbols );
267
+ enableEditTextPreference (minNonLetter );
268
+ } else {
269
+ Util .disablePreference (minLetters , R .string .not_for_password_quality );
270
+ Util .disablePreference (minNumeric , R .string .not_for_password_quality );
271
+ Util .disablePreference (minLower , R .string .not_for_password_quality );
272
+ Util .disablePreference (minUpper , R .string .not_for_password_quality );
273
+ Util .disablePreference (minSymbols , R .string .not_for_password_quality );
274
+ Util .disablePreference (minNonLetter , R .string .not_for_password_quality );
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Enable the preference and display the value in the summary.
280
+ */
281
+ private void enableEditTextPreference (EditTextPreference preference ) {
282
+ preference .setEnabled (true );
283
+ preference .setSummary (preference .getText ());
284
+ }
285
+
234
286
/**
235
287
* Set an initial value. Updates the summary to match.
236
288
*/
0 commit comments