|
17 | 17 | package com.afwsamples.testdpc.policy;
|
18 | 18 |
|
19 | 19 | import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES;
|
20 |
| -import static com.afwsamples.testdpc.common.ReflectionUtil.intConstant; |
21 |
| -import static com.afwsamples.testdpc.common.ReflectionUtil.invoke; |
22 |
| -import static com.afwsamples.testdpc.common.ReflectionUtil.stringConstant; |
23 | 20 | import static com.afwsamples.testdpc.common.Util.isAtLeastQ;
|
24 | 21 | import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT;
|
25 | 22 |
|
|
99 | 96 | import com.afwsamples.testdpc.common.CertificateUtil;
|
100 | 97 | import com.afwsamples.testdpc.common.MediaDisplayFragment;
|
101 | 98 | import com.afwsamples.testdpc.common.PackageInstallationUtils;
|
102 |
| -import com.afwsamples.testdpc.common.ReflectionUtil.ReflectionIsTemporaryException; |
103 | 99 | import com.afwsamples.testdpc.common.UserArrayAdapter;
|
104 | 100 | import com.afwsamples.testdpc.common.Util;
|
105 | 101 | import com.afwsamples.testdpc.common.preference.CustomConstraint;
|
@@ -401,26 +397,22 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
|
401 | 397 | private static final SparseIntArray PASSWORD_COMPLEXITY = new SparseIntArray(4);
|
402 | 398 | static {
|
403 | 399 | if (isAtLeastQ()) {
|
404 |
| - try { |
405 |
| - final int[] complexityIds = new int[]{ |
406 |
| - intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_NONE"), |
407 |
| - intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_LOW"), |
408 |
| - intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_MEDIUM"), |
409 |
| - intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_HIGH") |
410 |
| - }; |
411 |
| - |
412 |
| - // Strings to show for each password complexity setting. |
413 |
| - final int[] complexityNames = new int[]{ |
414 |
| - R.string.password_complexity_none, |
415 |
| - R.string.password_complexity_low, |
416 |
| - R.string.password_complexity_medium, |
417 |
| - R.string.password_complexity_high |
418 |
| - }; |
419 |
| - for (int i = 0; i < complexityIds.length; i++) { |
420 |
| - PASSWORD_COMPLEXITY.put(complexityIds[i], complexityNames[i]); |
421 |
| - } |
422 |
| - } catch (ReflectionIsTemporaryException e) { |
423 |
| - Log.e(TAG, "Cannot get password complexity constants.", e); |
| 400 | + final int[] complexityIds = new int[]{ |
| 401 | + DevicePolicyManager.PASSWORD_COMPLEXITY_NONE, |
| 402 | + DevicePolicyManager.PASSWORD_COMPLEXITY_LOW, |
| 403 | + DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM, |
| 404 | + DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH |
| 405 | + }; |
| 406 | + |
| 407 | + // Strings to show for each password complexity setting. |
| 408 | + final int[] complexityNames = new int[]{ |
| 409 | + R.string.password_complexity_none, |
| 410 | + R.string.password_complexity_low, |
| 411 | + R.string.password_complexity_medium, |
| 412 | + R.string.password_complexity_high |
| 413 | + }; |
| 414 | + for (int i = 0; i < complexityIds.length; i++) { |
| 415 | + PASSWORD_COMPLEXITY.put(complexityIds[i], complexityNames[i]); |
424 | 416 | }
|
425 | 417 | }
|
426 | 418 | }
|
@@ -1329,13 +1321,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
|
1329 | 1321 | return true;
|
1330 | 1322 | case SET_NEW_PASSWORD_WITH_COMPLEXITY:
|
1331 | 1323 | Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
|
1332 |
| - try { |
1333 |
| - intent.putExtra( |
1334 |
| - stringConstant(DevicePolicyManager.class, "EXTRA_PASSWORD_COMPLEXITY"), |
1335 |
| - Integer.parseInt((String) newValue)); |
1336 |
| - } catch (ReflectionIsTemporaryException e) { |
1337 |
| - Log.e(TAG, "Cannot get EXTRA_PASSWORD_COMPLEXITY.", e); |
1338 |
| - } |
| 1324 | + intent.putExtra( |
| 1325 | + DevicePolicyManager.EXTRA_PASSWORD_COMPLEXITY, |
| 1326 | + Integer.parseInt((String) newValue)); |
1339 | 1327 | startActivity(intent);
|
1340 | 1328 | return true;
|
1341 | 1329 | }
|
@@ -2145,13 +2133,8 @@ private void loadPasswordComplexity() {
|
2145 | 2133 | return;
|
2146 | 2134 | }
|
2147 | 2135 |
|
2148 |
| - try { |
2149 |
| - int complexity = |
2150 |
| - (int) invoke(mDevicePolicyManager, "getPasswordComplexity"); |
2151 |
| - passwordComplexityPreference.setSummary(PASSWORD_COMPLEXITY.get(complexity)); |
2152 |
| - } catch (ReflectionIsTemporaryException e) { |
2153 |
| - Log.e(TAG, "Cannot get password complexity.", e); |
2154 |
| - } |
| 2136 | + int complexity = mDevicePolicyManager.getPasswordComplexity(); |
| 2137 | + passwordComplexityPreference.setSummary(PASSWORD_COMPLEXITY.get(complexity)); |
2155 | 2138 | }
|
2156 | 2139 |
|
2157 | 2140 | @TargetApi(Build.VERSION_CODES.N)
|
|
0 commit comments