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

Commit 32f0742e authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Only wipe device if primary user (for failed password attempts)

When a DeviceAdmin requests a device wipe due to a number of incorrect
password attempts, only primary user can wipe the device. Secondary users
can only remove themselves from the device.

Bug: 7554445
Change-Id: I24331cb4eff37571fcd792abb2efc794f7b3f2d2
parent acddb72c
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -1875,6 +1875,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                    DeviceAdminInfo.USES_POLICY_WIPE_DATA);
            long ident = Binder.clearCallingIdentity();
            try {
                wipeDeviceOrUserLocked(flags, userHandle);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    }

    private void wipeDeviceOrUserLocked(int flags, final int userHandle) {
        if (userHandle == UserHandle.USER_OWNER) {
            wipeDataLocked(flags);
        } else {
@@ -1891,10 +1899,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                }
            });
        }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    }

    public void getRemoveWarning(ComponentName comp, final RemoteCallback result, int userHandle) {
@@ -1996,7 +2000,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                saveSettingsLocked(userHandle);
                int max = getMaximumFailedPasswordsForWipe(null, userHandle);
                if (max > 0 && policy.mFailedPasswordAttempts >= max) {
                    wipeDataLocked(0);
                    wipeDeviceOrUserLocked(0, userHandle);
                }
                sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED,
                        DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle);