diff options
| author | 2018-01-17 11:03:30 +0100 | |
|---|---|---|
| committer | 2018-01-19 20:01:24 +0100 | |
| commit | 16a91c0ca7ca8a8f8496a23a957f610fba72794c (patch) | |
| tree | c0b5ff9cfa2e2cba6d10f1a60c040c2cb70cb1d8 | |
| parent | a17274fb0521e500554a94b6c7cc6a46ea4c49b1 (diff) | |
Policy transparency for mandatory backups.
Bug: 64012357
Test: atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testCreateAdminSupportIntent
Change-Id: I54140d676285eb78345bda28427aa02339f65e5b
4 files changed, 32 insertions, 6 deletions
diff --git a/api/current.txt b/api/current.txt index 86f1a3b52583..8cf04f316f16 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6672,6 +6672,7 @@ package android.app.admin {      field public static final int PERMISSION_POLICY_PROMPT = 0; // 0x0      field public static final java.lang.String POLICY_DISABLE_CAMERA = "policy_disable_camera";      field public static final java.lang.String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture"; +    field public static final java.lang.String POLICY_MANDATORY_BACKUPS = "policy_mandatory_backups";      field public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 2; // 0x2      field public static final int RESET_PASSWORD_REQUIRE_ENTRY = 1; // 0x1      field public static final int SKIP_SETUP_WIZARD = 1; // 0x1 diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 0be55642d4cf..d465e0df6406 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -1157,9 +1157,17 @@ public class DevicePolicyManager {      public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";      /** +     * Constant to indicate the feature of mandatory backups. Used as argument to +     * {@link #createAdminSupportIntent(String)}. +     * @see #setMandatoryBackupTransport(ComponentName, ComponentName) +     */ +    public static final String POLICY_MANDATORY_BACKUPS = "policy_mandatory_backups"; + +    /**       * A String indicating a specific restricted feature. Can be a user restriction from the       * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values -     * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. +     * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE} or +     * {@link #POLICY_MANDATORY_BACKUPS}.       * @see #createAdminSupportIntent(String)       * @hide       */ @@ -6806,7 +6814,8 @@ public class DevicePolicyManager {       * @param restriction Indicates for which feature the dialog should be displayed. Can be a       *            user restriction from {@link UserManager}, e.g.       *            {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants -     *            {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}. +     *            {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE} or +     *            {@link #POLICY_MANDATORY_BACKUPS}.       * @return Intent An intent to be used to start the dialog-activity if the restriction is       *            set by an admin, or null if the restriction does not exist or no admin set it.       */ diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 77b87b6394b4..02f62a5e8bda 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -10216,7 +10216,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {          final int userId = UserHandle.getUserId(uid);          Intent intent = null;          if (DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction) || -                DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction)) { +                DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction) || +                DevicePolicyManager.POLICY_MANDATORY_BACKUPS.equals(restriction)) {              synchronized(this) {                  final DevicePolicyData policy = getUserData(userId);                  final int N = policy.mAdminList.size(); @@ -10225,7 +10226,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {                      if ((admin.disableCamera &&                                  DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction)) ||                          (admin.disableScreenCapture && DevicePolicyManager -                                .POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction))) { +                                .POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction)) || +                        (admin.mandatoryBackupTransport != null && DevicePolicyManager +                                .POLICY_MANDATORY_BACKUPS.equals(restriction))) {                          intent = createShowAdminSupportIntent(admin.info.getComponent(), userId);                          break;                      } diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index 1df0ff23f847..a2622a7a5957 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -2119,8 +2119,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {          assertEquals(UserManager.DISALLOW_ADJUST_VOLUME,                  intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION)); -        // Try with POLICY_DISABLE_CAMERA and POLICY_DISABLE_SCREEN_CAPTURE, which are not -        // user restrictions +        // Try with POLICY_DISABLE_CAMERA, POLICY_DISABLE_SCREEN_CAPTURE and +        // POLICY_MANDATORY_BACKUPS, which are not user restrictions          // Camera is not disabled          intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_CAMERA); @@ -2144,6 +2144,19 @@ public class DevicePolicyManagerTest extends DpmTestBase {          assertEquals(DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE,                  intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION)); +        // Backups are not mandatory +        intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_MANDATORY_BACKUPS); +        assertNull(intent); + +        // Backups are mandatory +        ComponentName transportComponent = ComponentName.unflattenFromString( +                "android/com.android.internal.backup.LocalTransport"); +        dpm.setMandatoryBackupTransport(admin1, transportComponent); +        intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_MANDATORY_BACKUPS); +        assertNotNull(intent); +        assertEquals(DevicePolicyManager.POLICY_MANDATORY_BACKUPS, +                intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION)); +          // Same checks for different user          mContext.binder.callingUid = DpmMockContext.CALLER_UID;          // Camera should be disabled by device owner  |