Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4fe2478 authored by Rubin Xu's avatar Rubin Xu
Browse files

DPM.isUsbDataSignalingEnabled() callable on unmanaged device

Fix an issue in existing implementation where the API will
throw exception when called on a device without DO or PO: a
slight tweak of semantics such that when the API is called by
a regular app, return the device-wide policy regardless which
user the caller is from.

Bug: 190024751
Test: manual with modifed TestDPC on unmanaged device.
Change-Id: I227d01ec275bc0a074a3789bab194c76fc72b5b8
parent 50ae7cbf
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -13876,7 +13876,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.
     */
+15 −6
Original line number Diff line number Diff line
@@ -17462,10 +17462,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();
            }
        }
    }
@@ -17475,11 +17480,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        Preconditions.checkCallAuthorization(isSystemUid(caller));
        synchronized (getLockObject()) {
            return isUsbDataSignalingEnabledInternalLocked();
        }
    }
    private boolean isUsbDataSignalingEnabledInternalLocked() {
        final ActiveAdmin admin = getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
                UserHandle.USER_SYSTEM);
        return admin == null || admin.mUsbDataSignalingEnabled;
    }
    }
    @Override
    public boolean canUsbDataSignalingBeDisabled() {