From e62d8d11175862b3fc062cd01e7bcb81d9871611 Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Tue, 21 Apr 2020 15:03:02 +0100 Subject: [PATCH] Add factory reset protection policy Test API to DPM * Add @TestApi isFactoryResetProtectionPolicySupported() to DevicePolicyManager which returns whether factory reset protection policy is supported on the device. Bug: 153696811 Test: atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testFactoryResetProtectionPolicy Change-Id: Id0bd6cdacf33f0fb2f795e1ead5127b79f42960e --- api/test-current.txt | 1 + .../android/app/admin/DevicePolicyManager.java | 16 ++++++++++++++++ .../android/app/admin/IDevicePolicyManager.aidl | 1 + .../devicepolicy/DevicePolicyManagerService.java | 16 +++++++++++++--- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/api/test-current.txt b/api/test-current.txt index 777cbc540b540..86f38baddc3bc 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -575,6 +575,7 @@ package android.app.admin { method public java.util.List getOwnerInstalledCaCerts(@NonNull android.os.UserHandle); method public boolean isCurrentInputMethodSetByOwner(); method public boolean isDeviceManaged(); + method public boolean isFactoryResetProtectionPolicySupported(); field public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; field public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; field public static final String ACTION_DATA_SHARING_RESTRICTION_APPLIED = "android.app.action.DATA_SHARING_RESTRICTION_APPLIED"; diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 41e2dc0de4d65..4b050455eef2b 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -10952,6 +10952,22 @@ public class DevicePolicyManager { } } + /** + * Returns whether factory reset protection policy is supported on the device. + * + * @return {@code true} if the device support factory reset protection policy. + * + * @hide + */ + @TestApi + public boolean isFactoryResetProtectionPolicySupported() { + try { + return mService.isFactoryResetProtectionPolicySupported(); + } catch (RemoteException re) { + throw re.rethrowFromSystemServer(); + } + } + /** * Called by the device owner or profile owner to clear application user data of a given * package. The behaviour of this is equivalent to the target application calling diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index d10153c117235..9c6a274ccf8cf 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -108,6 +108,7 @@ interface IDevicePolicyManager { void setFactoryResetProtectionPolicy(in ComponentName who, in FactoryResetProtectionPolicy policy); FactoryResetProtectionPolicy getFactoryResetProtectionPolicy(in ComponentName who); + boolean isFactoryResetProtectionPolicySupported(); ComponentName setGlobalProxy(in ComponentName admin, String proxySpec, String exclusionList); ComponentName getGlobalProxyAdmin(int userHandle); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 22b0b62a819d1..733ba5423eccb 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -7252,13 +7252,23 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return admin != null ? admin.mFactoryResetProtectionPolicy : null; } - private int getFrpManagementAgentUidOrThrow() { + private int getFrpManagementAgentUid() { PersistentDataBlockManagerInternal pdb = mInjector.getPersistentDataBlockManagerInternal(); - if ((pdb == null) || (pdb.getAllowedUid() == -1)) { + return pdb != null ? pdb.getAllowedUid() : -1; + } + + private int getFrpManagementAgentUidOrThrow() { + int uid = getFrpManagementAgentUid(); + if (uid == -1) { throw new UnsupportedOperationException( "The persistent data block service is not supported on this device"); } - return pdb.getAllowedUid(); + return uid; + } + + @Override + public boolean isFactoryResetProtectionPolicySupported() { + return getFrpManagementAgentUid() != -1; } @Override