|
38 | 38 | import android.app.admin.PackagePolicy;
|
39 | 39 | import android.app.admin.SystemUpdateInfo;
|
40 | 40 | import android.app.admin.WifiSsidPolicy;
|
| 41 | +import android.app.role.RoleManager; |
41 | 42 | import android.content.ComponentName;
|
42 | 43 | import android.content.ContentResolver;
|
43 | 44 | import android.content.Context;
|
@@ -463,6 +464,11 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
|
463 | 464 |
|
464 | 465 | private static final SparseIntArray PASSWORD_COMPLEXITY = new SparseIntArray(4);
|
465 | 466 |
|
| 467 | + // Copied over from RoleManager.ROLE_DEVICE_POLICY_MANAGEMENT, which can't be referenced directly |
| 468 | + // since it's a @SystemAPI. |
| 469 | + private static final String ROLE_DEVICE_POLICY_MANAGEMENT = |
| 470 | + "android.app.role.DEVICE_POLICY_MANAGEMENT"; |
| 471 | + |
466 | 472 | static {
|
467 | 473 | if (Util.SDK_INT >= VERSION_CODES.Q) {
|
468 | 474 | final int[] complexityIds =
|
@@ -560,7 +566,7 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
|
560 | 566 | @Override
|
561 | 567 | public void onCreate(Bundle savedInstanceState) {
|
562 | 568 | Context context = getActivity();
|
563 |
| - if (isDelegatedApp() || isCredentialManagerApp()) { |
| 569 | + if (isDelegatedApp() || isCredentialManagerApp() || isDeviceManagementRoleHolder()) { |
564 | 570 | mAdminComponentName = null;
|
565 | 571 | } else {
|
566 | 572 | mAdminComponentName = DeviceAdminReceiver.getComponentName(context);
|
@@ -999,6 +1005,14 @@ private boolean isCredentialManagerApp() {
|
999 | 1005 | return !dpm.isDeviceOwnerApp(packageName) && !dpm.isProfileOwnerApp(packageName);
|
1000 | 1006 | }
|
1001 | 1007 |
|
| 1008 | + private boolean isDeviceManagementRoleHolder() { |
| 1009 | + if (Util.SDK_INT < VERSION_CODES.S) { |
| 1010 | + return false; |
| 1011 | + } |
| 1012 | + RoleManager rm = getActivity().getSystemService(RoleManager.class); |
| 1013 | + return rm.isRoleHeld(ROLE_DEVICE_POLICY_MANAGEMENT); |
| 1014 | + } |
| 1015 | + |
1002 | 1016 | @Override
|
1003 | 1017 | public boolean isAvailable(Context context) {
|
1004 | 1018 | return true;
|
@@ -2580,6 +2594,8 @@ private void loadAppStatus() {
|
2580 | 2594 | appStatusStringId = R.string.this_is_a_device_owner;
|
2581 | 2595 | } else if (isDelegatedApp()) {
|
2582 | 2596 | appStatusStringId = R.string.this_is_a_delegated_app;
|
| 2597 | + } else if (isDeviceManagementRoleHolder()) { |
| 2598 | + appStatusStringId = R.string.this_is_a_role_holder; |
2583 | 2599 | } else {
|
2584 | 2600 | appStatusStringId = R.string.this_is_not_an_admin;
|
2585 | 2601 | }
|
@@ -2616,7 +2632,8 @@ private void loadEnrollmentSpecificId() {
|
2616 | 2632 |
|
2617 | 2633 | String esid = mDevicePolicyManager.getEnrollmentSpecificId();
|
2618 | 2634 |
|
2619 |
| - enrollmentSpecificIdPreference.setSummary(esid); |
| 2635 | + enrollmentSpecificIdPreference.setSummary( |
| 2636 | + TextUtils.isEmpty(esid) ? getString(R.string.enrollment_specific_id_empty) : esid); |
2620 | 2637 | }
|
2621 | 2638 |
|
2622 | 2639 | @TargetApi(VERSION_CODES.P)
|
|
0 commit comments