Merge "DPM.isUsbDataSignalingEnabled() callable on unmanaged device" into sc-dev am: 3c0f63ab97

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15042814

Change-Id: I126b354fd9a4ddb81163457d62843212fdd45e71
This commit is contained in:
Rubin Xu
2021-06-21 15:35:12 +00:00
committed by Automerger Merge Worker
2 changed files with 20 additions and 7 deletions

View File

@@ -13896,7 +13896,11 @@ public class DevicePolicyManager {
}
/**
* Returns whether USB data signaling is currently enabled by the admin. Callable by any app.
* Returns whether USB data signaling is currently enabled.
*
* <p> When called by a device owner or profile owner of an organization-owned managed profile,
* this API returns whether USB data signaling is currently enabled by that admin. When called
* by any other app, returns whether USB data signaling is currently enabled on the device.
*
* @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
*/

View File

@@ -17565,10 +17565,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
@Override
public boolean isUsbDataSignalingEnabled(String packageName) {
final CallerIdentity caller = getCallerIdentity(packageName);
synchronized (getLockObject()) {
final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(
getCallerIdentity(packageName));
return admin.mUsbDataSignalingEnabled;
// If the caller is an admin, return the policy set by itself. Otherwise
// return the device-wide policy.
if (isDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(caller)) {
return getProfileOwnerOrDeviceOwnerLocked(caller).mUsbDataSignalingEnabled;
} else {
return isUsbDataSignalingEnabledInternalLocked();
}
}
}
@@ -17578,12 +17583,16 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
Preconditions.checkCallAuthorization(isSystemUid(caller));
synchronized (getLockObject()) {
final ActiveAdmin admin = getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
UserHandle.USER_SYSTEM);
return admin == null || admin.mUsbDataSignalingEnabled;
return isUsbDataSignalingEnabledInternalLocked();
}
}
private boolean isUsbDataSignalingEnabledInternalLocked() {
final ActiveAdmin admin = getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
UserHandle.USER_SYSTEM);
return admin == null || admin.mUsbDataSignalingEnabled;
}
@Override
public boolean canUsbDataSignalingBeDisabled() {
return mInjector.binderWithCleanCallingIdentity(() ->