@@ -390,7 +390,8 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
390390 private static final String UNSUSPEND_APPS_KEY = "unsuspend_apps" ;
391391 private static final String CLEAR_APP_DATA_KEY = "clear_app_data" ;
392392 private static final String KEEP_UNINSTALLED_PACKAGES = "keep_uninstalled_packages" ;
393- private static final String WIPE_DATA_KEY = "wipe_data" ;
393+ private static final String REMOVE_MANAGED_PROFILE_KEY = "remove_managed_profile" ;
394+ private static final String FACTORY_RESET_DEVICE_KEY = "factory_reset_device" ;
394395 private static final String CREATE_WIFI_CONFIGURATION_KEY = "create_wifi_configuration" ;
395396 private static final String CREATE_EAP_TLS_WIFI_CONFIGURATION_KEY =
396397 "create_eap_tls_wifi_configuration" ;
@@ -425,7 +426,6 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
425426 private static final String MANAGE_OVERRIDE_APN_KEY = "manage_override_apn" ;
426427 private static final String MANAGED_SYSTEM_UPDATES_KEY = "managed_system_updates" ;
427428 private static final String SET_PRIVATE_DNS_MODE_KEY = "set_private_dns_mode" ;
428- private static final String FACTORY_RESET_ORG_OWNED_DEVICE = "factory_reset_org_owned_device" ;
429429 private static final String SET_FACTORY_RESET_PROTECTION_POLICY_KEY =
430430 "set_factory_reset_protection_policy" ;
431431 private static final String SET_LOCATION_ENABLED_KEY = "set_location_enabled" ;
@@ -682,7 +682,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
682682 mStayOnWhilePluggedInSwitchPreference =
683683 (SwitchPreference ) findPreference (STAY_ON_WHILE_PLUGGED_IN );
684684 mStayOnWhilePluggedInSwitchPreference .setOnPreferenceChangeListener (this );
685- findPreference (WIPE_DATA_KEY ).setOnPreferenceClickListener (this );
685+ findPreference (REMOVE_MANAGED_PROFILE_KEY ).setOnPreferenceClickListener (this );
686+ findPreference (FACTORY_RESET_DEVICE_KEY ).setOnPreferenceClickListener (this );
686687 findPreference (REMOVE_DEVICE_OWNER_KEY ).setOnPreferenceClickListener (this );
687688 mEnableBackupServicePreference = (DpcSwitchPreference ) findPreference (ENABLE_BACKUP_SERVICE );
688689 mEnableBackupServicePreference .setOnPreferenceChangeListener (this );
@@ -810,7 +811,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
810811
811812 findPreference (CROSS_PROFILE_CALENDAR_KEY ).setOnPreferenceClickListener (this );
812813 findPreference (ENTERPRISE_SLICE_KEY ).setOnPreferenceClickListener (this );
813- findPreference (FACTORY_RESET_ORG_OWNED_DEVICE ).setOnPreferenceClickListener (this );
814814 findPreference (SET_FACTORY_RESET_PROTECTION_POLICY_KEY ).setOnPreferenceClickListener (this );
815815 findPreference (SET_ORGANIZATION_ID_KEY ).setOnPreferenceClickListener (this );
816816
@@ -1060,8 +1060,11 @@ public boolean onPreferenceClick(Preference preference) {
10601060 // no lock task present, ignore
10611061 }
10621062 return true ;
1063- } else if (WIPE_DATA_KEY .equals (key )) {
1064- showWipeDataPrompt ();
1063+ } else if (REMOVE_MANAGED_PROFILE_KEY .equals (key )) {
1064+ showWipeDataPrompt (/* wipeDevice */ false );
1065+ return true ;
1066+ } else if (FACTORY_RESET_DEVICE_KEY .equals (key )) {
1067+ showWipeDataPrompt (/* wipeDevice */ true );
10651068 return true ;
10661069 } else if (REMOVE_DEVICE_OWNER_KEY .equals (key )) {
10671070 showRemoveDeviceOwnerPrompt ();
@@ -1403,9 +1406,6 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
14031406 } else if (SET_PROFILE_NAME_KEY .equals (key )) {
14041407 showSetProfileNameDialog ();
14051408 return true ;
1406- } else if (FACTORY_RESET_ORG_OWNED_DEVICE .equals (key )) {
1407- factoryResetOrgOwnedDevice ();
1408- return true ;
14091409 } else if (SET_FACTORY_RESET_PROTECTION_POLICY_KEY .equals (key )) {
14101410 showFragment (new FactoryResetProtectionPolicyFragment ());
14111411 return true ;
@@ -2067,10 +2067,10 @@ public void onClick(DialogInterface dialogInterface, int which) {
20672067 }
20682068
20692069 /**
2070- * Shows a prompt to ask for confirmation on wiping the data and also provide an option to set if
2071- * external storage and factory reset protection data also needs to wiped.
2070+ * Shows a prompt to ask for confirmation on wiping the profile / device and also provide an
2071+ * option to set if external storage and factory reset protection data also needs to wiped.
20722072 */
2073- private void showWipeDataPrompt () {
2073+ private void showWipeDataPrompt (boolean wipeDevice ) {
20742074 final LayoutInflater inflater = getActivity ().getLayoutInflater ();
20752075 final View dialogView = inflater .inflate (R .layout .wipe_data_dialog_prompt , null );
20762076 final CheckBox externalStorageCheckBox =
@@ -2079,7 +2079,10 @@ private void showWipeDataPrompt() {
20792079 (CheckBox ) dialogView .findViewById (R .id .reset_protection_checkbox );
20802080
20812081 new AlertDialog .Builder (getActivity ())
2082- .setTitle (R .string .wipe_data_title )
2082+ .setTitle (
2083+ wipeDevice
2084+ ? R .string .factory_reset_device_title
2085+ : R .string .remove_managed_profile_title )
20832086 .setView (dialogView )
20842087 .setPositiveButton (
20852088 android .R .string .ok ,
@@ -2095,8 +2098,28 @@ public void onClick(DialogInterface dialogInterface, int i) {
20952098 (resetProtectionCheckBox .isChecked ()
20962099 ? DevicePolicyManager .WIPE_RESET_PROTECTION_DATA
20972100 : 0 );
2098- mDevicePolicyManagerGateway .wipeData (
2099- flags , (v ) -> onSuccessLog ("wipeData" ), (e ) -> onErrorLog ("wipeData" , e ));
2101+ if (wipeDevice ) {
2102+ if (Util .SDK_INT >= VERSION_CODES .UPSIDE_DOWN_CAKE ) {
2103+ // Since U, factory reset needs to use wipeDevice()
2104+ mDevicePolicyManagerGateway .wipeDevice (
2105+ flags , (v ) -> onSuccessLog ("wipeData" ), (e ) -> onErrorLog ("wipeData" , e ));
2106+ } else if (mIsOrganizationOwnedProfileOwner ) {
2107+ // Before U, factory reset by COPE goes via the parent DPM instance
2108+ DevicePolicyManagerGatewayImpl .forParentProfile (getActivity ())
2109+ .wipeData (
2110+ /* flags= */ 0 ,
2111+ (v ) -> onSuccessLog ("wipeData" ),
2112+ (e ) -> onErrorLog ("wipeData" , e ));
2113+ } else {
2114+ // Before U, factory reset by DO goes via the regular DPM instance
2115+ mDevicePolicyManagerGateway .wipeData (
2116+ flags , (v ) -> onSuccessLog ("wipeData" ), (e ) -> onErrorLog ("wipeData" , e ));
2117+ }
2118+ } else {
2119+ // Wipe user
2120+ mDevicePolicyManagerGateway .wipeData (
2121+ flags , (v ) -> onSuccessLog ("wipeData" ), (e ) -> onErrorLog ("wipeData" , e ));
2122+ }
21002123 }
21012124 })
21022125 .setNegativeButton (android .R .string .cancel , null )
@@ -4716,13 +4739,6 @@ private int validateAffiliatedUserAfterP() {
47164739 return NO_CUSTOM_CONSTRAINT ;
47174740 }
47184741
4719- @ TargetApi (30 )
4720- private void factoryResetOrgOwnedDevice () {
4721- DevicePolicyManagerGatewayImpl .forParentProfile (getActivity ())
4722- .wipeData (
4723- /* flags= */ 0 , (v ) -> onSuccessLog ("wipeData" ), (e ) -> onErrorLog ("wipeData" , e ));
4724- }
4725-
47264742 private boolean isOrganizationOwnedDevice () {
47274743 return mDevicePolicyManager .isDeviceOwnerApp (mPackageName )
47284744 || (mDevicePolicyManager .isProfileOwnerApp (mPackageName )
0 commit comments