Add a new WipeData API that allows an input string for the reason to wipe user.
Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest
Fix: 31177807
Change-Id: I0b46f4d029d285d5018875f03285551f6b822376
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 6bccad9..d4fd675 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -63,7 +63,9 @@
import android.util.ArraySet;
import android.util.Log;
+import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.Preconditions;
import com.android.org.conscrypt.TrustedCertificateStore;
import java.io.ByteArrayInputStream;
@@ -3142,6 +3144,7 @@
*/
public static final int WIPE_EUICC = 0x0004;
+
/**
* Ask that all user data be wiped. If called as a secondary user, the user will be removed and
* other users will remain unaffected. Calling from the primary user will cause the device to
@@ -3157,10 +3160,47 @@
* that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
*/
public void wipeData(int flags) {
- throwIfParentInstance("wipeData");
+ final String wipeReasonForUser = mContext.getString(
+ R.string.work_profile_deleted_description_dpm_wipe);
+ wipeDataInternal(flags, wipeReasonForUser);
+ }
+
+ /**
+ * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
+ * other users will remain unaffected, the provided reason for wiping data can be shown to
+ * user. Calling from the primary user will cause the device to reboot, erasing all device data
+ * - including all the secondary users and their data - while booting up. In this case, we don't
+ * show the reason to the user since the device would be factory reset.
+ * <p>
+ * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
+ * 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}.
+ * @param reason a string that contains the reason for wiping data, which can be
+ * 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.
+ */
+ public void wipeDataWithReason(int flags, @NonNull CharSequence reason) {
+ Preconditions.checkNotNull(reason, "CharSequence is null");
+ wipeDataInternal(flags, reason.toString());
+ }
+
+ /**
+ * Internal function for both {@link #wipeData(int)} and
+ * {@link #wipeDataWithReason(int, CharSequence)} to call.
+ *
+ * @see #wipeData(int)
+ * @see #wipeDataWithReason(int, CharSequence)
+ * @hide
+ */
+ private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) {
+ throwIfParentInstance("wipeDataWithReason");
if (mService != null) {
try {
- mService.wipeData(flags);
+ mService.wipeDataWithReason(flags, wipeReasonForUser);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index acfb602..8865a05 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -95,7 +95,7 @@
void lockNow(int flags, boolean parent);
- void wipeData(int flags);
+ void wipeDataWithReason(int flags, String wipeReasonForUser);
ComponentName setGlobalProxy(in ComponentName admin, String proxySpec, String exclusionList);
ComponentName getGlobalProxyAdmin(int userHandle);
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 6807e13..085f8dd 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -340,18 +340,19 @@
<!-- Work profile deleted notification--> <skip />
<!-- Shows up in the notification's title when the system deletes the work profile. [CHAR LIMIT=NONE] -->
<string name="work_profile_deleted">Work profile deleted</string>
- <!-- Content text for a notification. The Title of the notification is "work_profile_deleted",
- i.e. "Work profile deleted". This says that the profile is deleted by the system as a result of
- the current profile owner gone missing. [CHAR LIMIT=100]-->
+ <!-- Content text for a notification. The Title of the notification is "Work profile deleted".
+ This says that the profile is deleted by the system as a result of the current profile owner gone missing. [CHAR LIMIT=100]-->
<string name="work_profile_deleted_description">Work profile deleted due to missing admin app</string>
- <!-- Content text for an expanded notification. The Title of the notification is "work_profile_deleted",
- i.e. "Work profile deleted". This further explains that the profile is deleted by the system
- as a result of the current profile admin gone missing. [CHAR LIMIT=NONE]-->
+ <!-- Content text for an expanded notification. The Title of the notification is "Work profile deleted".
+ This further explains that the profile is deleted by the system as a result of the current profile admin gone missing. [CHAR LIMIT=NONE]-->
<string name="work_profile_deleted_details">The work profile admin app is either missing or corrupted.
As a result, your work profile and related data have been deleted. Contact your admin for assistance.</string>
- <!-- Content text for a notification. The Title of the notification is "work_profile_deleted",
+ <!-- Content text for a notification. The Title of the notification is "Work profile deleted",
This indicates that a work profile has been deleted. [CHAR LIMIT=NONE]-->
<string name="work_profile_deleted_description_dpm_wipe">Your work profile is no longer available on this device</string>
+ <!-- Content text for a notification. The Title of the notification is "Work profile deleted",
+ This indicates that a work profile has been deleted because the maximum failed password attempts as been reached. [CHAR LIMIT=NONE]-->
+ <string name="work_profile_deleted_reason_maximum_password_failure">Too many password attempts</string>
<!-- Content title for a notification. This notification indicates that the device is managed
and network logging was activated by a device owner. [CHAR LIMIT=NONE]-->
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 0732f0d..ce1cccf 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1155,6 +1155,7 @@
<java-symbol type="string" name="work_profile_deleted_description" />
<java-symbol type="string" name="work_profile_deleted_details" />
<java-symbol type="string" name="work_profile_deleted_description_dpm_wipe" />
+ <java-symbol type="string" name="work_profile_deleted_reason_maximum_password_failure" />
<java-symbol type="string" name="network_logging_notification_title" />
<java-symbol type="string" name="network_logging_notification_text" />
<java-symbol type="string" name="factory_reset_warning" />