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

Commit 3c731be6 authored by Ilyas Sung's avatar Ilyas Sung
Browse files

Migrate the setUsbDataSignalingEnabled api to the device policy engine

Bug: 283934505
Test: btest android.devicepolicy.cts.SetUsbDataSignalingTest
Change-Id: I86d8a5d5b719cfeab32383828cfc2f43f5ae9f65
parent 829498b2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -540,6 +540,7 @@ package android.app.admin {
    field public static final String PERMITTED_INPUT_METHODS_POLICY = "permittedInputMethods";
    field public static final String PERSONAL_APPS_SUSPENDED_POLICY = "personalAppsSuspended";
    field public static final String SCREEN_CAPTURE_DISABLED_POLICY = "screenCaptureDisabled";
    field public static final String USB_DATA_SIGNALING_POLICY = "usbDataSignaling";
  }

  public class DevicePolicyManager {
+8 −0
Original line number Diff line number Diff line
@@ -159,6 +159,14 @@ public final class DevicePolicyIdentifiers {
     */
    public static final String CROSS_PROFILE_WIDGET_PROVIDER_POLICY = "crossProfileWidgetProvider";

    /**
     * String identifier for {@link DevicePolicyManager#setUsbDataSignalingEnabled}.
     *
     * @hide
     */
    @TestApi
    public static final String USB_DATA_SIGNALING_POLICY = "usbDataSignaling";

    /**
     * @hide
     */
+19 −20
Original line number Diff line number Diff line
@@ -16583,6 +16583,24 @@ public class DevicePolicyManager {
     * {@link #canUsbDataSignalingBeDisabled()} to check whether enabling or disabling USB data
     * signaling is supported on the device.
     *
     * Starting from {@link Build.VERSION_CODES#VANILLA_ICE_CREAM}, after the USB data signaling
     * policy has been set, {@link PolicyUpdateReceiver#onPolicySetResult(Context, String,
     * Bundle, TargetUser, PolicyUpdateResult)} will notify the admin on whether the policy was
     * successfully set or not. This callback will contain:
     * <ul>
     * li> The policy identifier {@link DevicePolicyIdentifiers#USB_DATA_SIGNALING_POLICY}
     * <li> The {@link TargetUser} that this policy relates to
     * <li> The {@link PolicyUpdateResult}, which will be
     * {@link PolicyUpdateResult#RESULT_POLICY_SET} if the policy was successfully set or the
     * reason the policy failed to be set
     * e.g. {@link PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY})
     * </ul>
     * If there has been a change to the policy,
     * {@link PolicyUpdateReceiver#onPolicyChanged(Context, String, Bundle, TargetUser,
     * PolicyUpdateResult)} will notify the admin of this change. This callback will contain the
     * same parameters as PolicyUpdateReceiver#onPolicySetResult and the {@link PolicyUpdateResult}
     * will contain the reason why the policy changed.
     *
     * @param enabled whether USB data signaling should be enabled or not.
     * @throws SecurityException if the caller is not permitted to set this policy
     * @throws IllegalStateException if disabling USB data signaling is not supported or
@@ -16621,25 +16639,6 @@ public class DevicePolicyManager {
        return true;
    }
    /**
     * Called by the system to check whether USB data signaling is currently enabled for this user.
     *
     * @param userId which user to check for.
     * @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
     * @hide
     */
    public boolean isUsbDataSignalingEnabledForUser(@UserIdInt int userId) {
        throwIfParentInstance("isUsbDataSignalingEnabledForUser");
        if (mService != null) {
            try {
                return mService.isUsbDataSignalingEnabledForUser(userId);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return true;
    }
    /**
     * Returns whether enabling or disabling USB data signaling is supported on the device.
     *
+0 −1
Original line number Diff line number Diff line
@@ -565,7 +565,6 @@ interface IDevicePolicyManager {

    void setUsbDataSignalingEnabled(String callerPackage, boolean enabled);
    boolean isUsbDataSignalingEnabled(String callerPackage);
    boolean isUsbDataSignalingEnabledForUser(int userId);
    boolean canUsbDataSignalingBeDisabled();

    void setMinimumRequiredWifiSecurityLevel(String callerPackageName, int level);
+1 −1
Original line number Diff line number Diff line
@@ -409,7 +409,7 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
     */
    public static EnforcedAdmin checkIfUsbDataSignalingIsDisabled(Context context, int userId) {
        DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
        if (dpm == null || dpm.isUsbDataSignalingEnabledForUser(userId)) {
        if (dpm == null || dpm.isUsbDataSignalingEnabled()) {
            return null;
        } else {
            EnforcedAdmin admin = getProfileOrDeviceOwner(context, getUserHandleOf(userId));
Loading