From 4d68ae240bc038ba80e5ac88bbebffa3c1564280 Mon Sep 17 00:00:00 2001 From: Rubin Xu Date: Thu, 3 Jun 2021 12:05:01 +0100 Subject: [PATCH] Allow any apps to call DPM.isUsbDataSignalingEnabled() This is to allow 3p apps to query the state of the policy so they can show appropriate UX to the user in case the app's interaction with the plugged-in USB devices is disrupted by the admin policy. Bug: 190024751 Test: atest FrameworksServicesTests:DevicePolicyManagerTest Change-Id: I829ff84256e0288b88c11add53da312ee2bc2558 --- core/java/android/app/admin/DevicePolicyManager.java | 3 +-- .../server/devicepolicy/DevicePolicyManagerService.java | 9 ++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 8d747961fab1f..ad59f8f8b317c 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -13872,8 +13872,7 @@ public class DevicePolicyManager { } /** - * Called by device owner or profile owner of an organization-owned managed profile to return - * whether USB data signaling is currently enabled by the admin. + * Returns whether USB data signaling is currently enabled by the admin. Callable by any app. * * @return {@code true} if USB data signaling is enabled, {@code false} otherwise. */ diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index bc130e2c1e5bc..769971b8e0ac1 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -17415,14 +17415,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean isUsbDataSignalingEnabled(String packageName) { - final CallerIdentity caller = getCallerIdentity(packageName); - Preconditions.checkCallAuthorization( - isDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(caller), - "USB data signaling can only be controlled by a device owner or " - + "a profile owner on an organization-owned device."); - synchronized (getLockObject()) { - final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller); + final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked( + getCallerIdentity(packageName)); return admin.mUsbDataSignalingEnabled; } }