@@ -390,7 +390,8 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
390
390
private static final String UNSUSPEND_APPS_KEY = "unsuspend_apps" ;
391
391
private static final String CLEAR_APP_DATA_KEY = "clear_app_data" ;
392
392
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" ;
394
395
private static final String CREATE_WIFI_CONFIGURATION_KEY = "create_wifi_configuration" ;
395
396
private static final String CREATE_EAP_TLS_WIFI_CONFIGURATION_KEY =
396
397
"create_eap_tls_wifi_configuration" ;
@@ -425,7 +426,6 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
425
426
private static final String MANAGE_OVERRIDE_APN_KEY = "manage_override_apn" ;
426
427
private static final String MANAGED_SYSTEM_UPDATES_KEY = "managed_system_updates" ;
427
428
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" ;
429
429
private static final String SET_FACTORY_RESET_PROTECTION_POLICY_KEY =
430
430
"set_factory_reset_protection_policy" ;
431
431
private static final String SET_LOCATION_ENABLED_KEY = "set_location_enabled" ;
@@ -682,7 +682,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
682
682
mStayOnWhilePluggedInSwitchPreference =
683
683
(SwitchPreference ) findPreference (STAY_ON_WHILE_PLUGGED_IN );
684
684
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 );
686
687
findPreference (REMOVE_DEVICE_OWNER_KEY ).setOnPreferenceClickListener (this );
687
688
mEnableBackupServicePreference = (DpcSwitchPreference ) findPreference (ENABLE_BACKUP_SERVICE );
688
689
mEnableBackupServicePreference .setOnPreferenceChangeListener (this );
@@ -810,7 +811,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
810
811
811
812
findPreference (CROSS_PROFILE_CALENDAR_KEY ).setOnPreferenceClickListener (this );
812
813
findPreference (ENTERPRISE_SLICE_KEY ).setOnPreferenceClickListener (this );
813
- findPreference (FACTORY_RESET_ORG_OWNED_DEVICE ).setOnPreferenceClickListener (this );
814
814
findPreference (SET_FACTORY_RESET_PROTECTION_POLICY_KEY ).setOnPreferenceClickListener (this );
815
815
findPreference (SET_ORGANIZATION_ID_KEY ).setOnPreferenceClickListener (this );
816
816
@@ -1060,8 +1060,11 @@ public boolean onPreferenceClick(Preference preference) {
1060
1060
// no lock task present, ignore
1061
1061
}
1062
1062
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 );
1065
1068
return true ;
1066
1069
} else if (REMOVE_DEVICE_OWNER_KEY .equals (key )) {
1067
1070
showRemoveDeviceOwnerPrompt ();
@@ -1403,9 +1406,6 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
1403
1406
} else if (SET_PROFILE_NAME_KEY .equals (key )) {
1404
1407
showSetProfileNameDialog ();
1405
1408
return true ;
1406
- } else if (FACTORY_RESET_ORG_OWNED_DEVICE .equals (key )) {
1407
- factoryResetOrgOwnedDevice ();
1408
- return true ;
1409
1409
} else if (SET_FACTORY_RESET_PROTECTION_POLICY_KEY .equals (key )) {
1410
1410
showFragment (new FactoryResetProtectionPolicyFragment ());
1411
1411
return true ;
@@ -2067,10 +2067,10 @@ public void onClick(DialogInterface dialogInterface, int which) {
2067
2067
}
2068
2068
2069
2069
/**
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.
2072
2072
*/
2073
- private void showWipeDataPrompt () {
2073
+ private void showWipeDataPrompt (boolean wipeDevice ) {
2074
2074
final LayoutInflater inflater = getActivity ().getLayoutInflater ();
2075
2075
final View dialogView = inflater .inflate (R .layout .wipe_data_dialog_prompt , null );
2076
2076
final CheckBox externalStorageCheckBox =
@@ -2079,7 +2079,10 @@ private void showWipeDataPrompt() {
2079
2079
(CheckBox ) dialogView .findViewById (R .id .reset_protection_checkbox );
2080
2080
2081
2081
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 )
2083
2086
.setView (dialogView )
2084
2087
.setPositiveButton (
2085
2088
android .R .string .ok ,
@@ -2095,8 +2098,28 @@ public void onClick(DialogInterface dialogInterface, int i) {
2095
2098
(resetProtectionCheckBox .isChecked ()
2096
2099
? DevicePolicyManager .WIPE_RESET_PROTECTION_DATA
2097
2100
: 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
+ }
2100
2123
}
2101
2124
})
2102
2125
.setNegativeButton (android .R .string .cancel , null )
@@ -4716,13 +4739,6 @@ private int validateAffiliatedUserAfterP() {
4716
4739
return NO_CUSTOM_CONSTRAINT ;
4717
4740
}
4718
4741
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
-
4726
4742
private boolean isOrganizationOwnedDevice () {
4727
4743
return mDevicePolicyManager .isDeviceOwnerApp (mPackageName )
4728
4744
|| (mDevicePolicyManager .isProfileOwnerApp (mPackageName )
0 commit comments