Skip to content

Add "Remove profile owner" #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
private static final String RELAUNCH_IN_LOCK_TASK = "relaunch_in_lock_task";
private static final String REMOVE_ALL_CERTIFICATES_KEY = "remove_all_ca_certificates";
private static final String REMOVE_DEVICE_OWNER_KEY = "remove_device_owner";
private static final String REMOVE_PROFILE_OWNER_KEY = "remove_profile_owner";
private static final String REMOVE_KEY_CERTIFICATE_KEY = "remove_key_certificate";
private static final String REMOVE_USER_KEY = "remove_user";
private static final String SWITCH_USER_KEY = "switch_user";
Expand Down Expand Up @@ -685,6 +686,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
findPreference(REMOVE_MANAGED_PROFILE_KEY).setOnPreferenceClickListener(this);
findPreference(FACTORY_RESET_DEVICE_KEY).setOnPreferenceClickListener(this);
findPreference(REMOVE_DEVICE_OWNER_KEY).setOnPreferenceClickListener(this);
findPreference(REMOVE_PROFILE_OWNER_KEY).setOnPreferenceClickListener(this);
mEnableBackupServicePreference = (DpcSwitchPreference) findPreference(ENABLE_BACKUP_SERVICE);
mEnableBackupServicePreference.setOnPreferenceChangeListener(this);
mEnableBackupServicePreference.setCustomConstraint(this::validateDeviceOwnerBeforeQ);
Expand Down Expand Up @@ -1069,6 +1071,9 @@ public boolean onPreferenceClick(Preference preference) {
} else if (REMOVE_DEVICE_OWNER_KEY.equals(key)) {
showRemoveDeviceOwnerPrompt();
return true;
} else if (REMOVE_PROFILE_OWNER_KEY.equals(key)) {
showRemoveProfileOwnerPrompt();
return true;
} else if (REQUEST_BUGREPORT_KEY.equals(key)) {
requestBugReport();
return true;
Expand Down Expand Up @@ -2149,6 +2154,26 @@ private void showRemoveDeviceOwnerPrompt() {
.show();
}

/** Shows a prompt to ask for confirmation on removing profile owner. */
private void showRemoveProfileOwnerPrompt() {
new AlertDialog.Builder(getActivity())
.setTitle(R.string.remove_profile_owner_title)
.setMessage(R.string.remove_device_owner_confirmation)
.setPositiveButton(
android.R.string.ok,
(d, i) ->
mDevicePolicyManagerGateway.clearProfileOwner(
(v) -> {
if (getActivity() != null && !getActivity().isFinishing()) {
showToast(R.string.profile_owner_removed);
getActivity().finish();
}
},
(e) -> onErrorLog("clearProfileOwner", e)))
.setNegativeButton(android.R.string.cancel, null)
.show();
}

/** Shows a message box with the device wifi mac address. */
@TargetApi(VERSION_CODES.N)
private void showWifiMacAddress() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
<string name="remove_device_owner_confirmation">Policies and restrictions will continue to be
active and may require a factory reset to clear.</string>
<string name="device_owner_removed">This app is no longer a device owner.</string>
<string name="remove_profile_owner">Remove this profile owner</string>
<string name="remove_profile_owner_title">Remove profile owner?</string>
<string name="profile_owner_removed">This app is no longer a profile owner.</string>
<string name="set_factory_reset_protection_policy">Set factory reset protection policy</string>
<string name="factory_reset_protection_policy">Factory reset protection policy</string>
<string name="factory_reset_protection_policy_accounts">Account IDs</string>
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/xml/device_policy_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,11 @@
android:title="@string/remove_device_owner"
testdpc:admin="deviceOwner"
testdpc:minSdkVersion="L" />
<com.afwsamples.testdpc.common.preference.DpcPreference
android:key="remove_profile_owner"
android:title="@string/remove_profile_owner"
testdpc:admin="profileOwner|orgOwnedProfileOwner"
testdpc:minSdkVersion="L" />
<com.afwsamples.testdpc.common.preference.DpcPreference
android:key="reboot"
android:title="@string/reboot"
Expand Down
Loading