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

Commit d4ad5497 authored by Alex Chau's avatar Alex Chau
Browse files

Add back @NonNull to DevicePolicyManager.wipeData

- Added WIPE_SILENTLY to skip notifying user

Bug: 114711242
Test: cts-tradefed run singleCommand cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.ManagedProfileTest#testWipeDataWithoutReason
Change-Id: I163e0f3e1ab1e6feef668070a73b1f86db9691b3
parent 448fb122
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -6787,7 +6787,7 @@ package android.app.admin {
    method public void uninstallCaCert(@Nullable android.content.ComponentName, byte[]);
    method public boolean updateOverrideApn(@NonNull android.content.ComponentName, int, @NonNull android.telephony.data.ApnSetting);
    method public void wipeData(int);
    method public void wipeData(int, CharSequence);
    method public void wipeData(int, @NonNull CharSequence);
    field public static final String ACTION_ADD_DEVICE_ADMIN = "android.app.action.ADD_DEVICE_ADMIN";
    field public static final String ACTION_ADMIN_POLICY_COMPLIANCE = "android.app.action.ADMIN_POLICY_COMPLIANCE";
    field public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
@@ -6930,6 +6930,7 @@ package android.app.admin {
    field public static final int WIPE_EUICC = 4; // 0x4
    field public static final int WIPE_EXTERNAL_STORAGE = 1; // 0x1
    field public static final int WIPE_RESET_PROTECTION_DATA = 2; // 0x2
    field public static final int WIPE_SILENTLY = 8; // 0x8
  }
  public abstract static class DevicePolicyManager.InstallUpdateCallback {
+19 −9
Original line number Diff line number Diff line
@@ -3955,6 +3955,10 @@ public class DevicePolicyManager {
     */
    public static final int WIPE_EUICC = 0x0004;

    /**
     * Flag for {@link #wipeData(int)}: won't show reason for wiping to the user.
     */
    public static final int WIPE_SILENTLY = 0x0008;

    /**
     * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
@@ -3966,7 +3970,8 @@ public class DevicePolicyManager {
     * be able to call this method; if it has not, a security exception will be thrown.
     *
     * @param flags Bit mask of additional options: currently supported flags are
     *            {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
     *            {@link #WIPE_EXTERNAL_STORAGE}, {@link #WIPE_RESET_PROTECTION_DATA},
     *            {@link #WIPE_EUICC} and {@link #WIPE_SILENTLY}.
     * @throws SecurityException if the calling application does not own an active administrator
     *            that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
     */
@@ -3988,16 +3993,21 @@ public class DevicePolicyManager {
     * be able to call this method; if it has not, a security exception will be thrown.
     *
     * @param flags Bit mask of additional options: currently supported flags are
     *            {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
     *            {@link #WIPE_EXTERNAL_STORAGE}, {@link #WIPE_RESET_PROTECTION_DATA} and
     *            {@link #WIPE_EUICC}.
     * @param reason a string that contains the reason for wiping data, which can be
     *            presented to the user. If the string is null or empty, user won't be notified.
     *            presented to the user.
     * @throws SecurityException if the calling application does not own an active administrator
     *            that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
     * @throws IllegalArgumentException if the input reason string is null or empty.
     * @throws IllegalArgumentException if the input reason string is null or empty, or if
     *            {@link #WIPE_SILENTLY} is set.
     */
    public void wipeData(int flags, CharSequence reason) {
    public void wipeData(int flags, @NonNull CharSequence reason) {
        throwIfParentInstance("wipeData");
        wipeDataInternal(flags, reason != null ? reason.toString() : null);
        Preconditions.checkNotNull(reason, "reason string is null");
        Preconditions.checkStringNotEmpty(reason, "reason string is empty");
        Preconditions.checkArgument((flags & WIPE_SILENTLY) == 0, "WIPE_SILENTLY cannot be set");
        wipeDataInternal(flags, reason.toString());
    }

    /**
@@ -4008,7 +4018,7 @@ public class DevicePolicyManager {
     * @see #wipeData(int, CharSequence)
     * @hide
     */
    private void wipeDataInternal(int flags, String wipeReasonForUser) {
    private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) {
        if (mService != null) {
            try {
                mService.wipeDataWithReason(flags, wipeReasonForUser);
+5 −3
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import static android.app.admin.DevicePolicyManager.PROFILE_KEYGUARD_FEATURES_AF
import static android.app.admin.DevicePolicyManager.WIPE_EUICC;
import static android.app.admin.DevicePolicyManager.WIPE_EXTERNAL_STORAGE;
import static android.app.admin.DevicePolicyManager.WIPE_RESET_PROTECTION_DATA;
import static android.app.admin.DevicePolicyManager.WIPE_SILENTLY;
import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
import static android.provider.Settings.Global.PRIVATE_DNS_MODE;
import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER;
@@ -6362,7 +6363,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    private void forceWipeUser(int userId, String wipeReasonForUser) {
    private void forceWipeUser(int userId, String wipeReasonForUser, boolean wipeSilently) {
        boolean success = false;
        try {
            IActivityManager am = mInjector.getIActivityManager();
@@ -6373,7 +6374,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            success = mUserManagerInternal.removeUserEvenWhenDisallowed(userId);
            if (!success) {
                Slog.w(LOG_TAG, "Couldn't remove user " + userId);
            } else if (isManagedProfile(userId) && !TextUtils.isEmpty(wipeReasonForUser)) {
            } else if (isManagedProfile(userId) && !wipeSilently) {
                sendWipeProfileNotification(wipeReasonForUser);
            }
        } catch (RemoteException re) {
@@ -6388,6 +6389,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        if (!mHasFeature) {
            return;
        }
        Preconditions.checkStringNotEmpty(wipeReasonForUser, "wipeReasonForUser is null or empty");
        enforceFullCrossUsersPermission(mInjector.userHandleGetCallingUserId());
        final ActiveAdmin admin;
@@ -6447,7 +6449,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                        internalReason,
                        /*wipeEuicc=*/ (flags & WIPE_EUICC) != 0);
            } else {
                forceWipeUser(userId, wipeReasonForUser);
                forceWipeUser(userId, wipeReasonForUser, (flags & WIPE_SILENTLY) != 0);
            }
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);