Add back dialog when disabling provider
Adds back a dialog that will ask the user to confirm their choice when disabling the last credman provider. Test: ondevice & make Bug: 267816757 Change-Id: Icefde62efe7daa9aad2da7ad9d3fd37e40b4376b
This commit is contained in:
@@ -293,8 +293,19 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// Disable the provider.
|
||||
togglePackageNameDisabled(packageName);
|
||||
// If we are disabling the last enabled provider then show a warning.
|
||||
if (mEnabledPackageNames.size() <= 1) {
|
||||
final DialogFragment fragment =
|
||||
newConfirmationDialogFragment(packageName, title, pref);
|
||||
|
||||
if (fragment == null || mFragmentManager == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fragment.show(mFragmentManager, ConfirmationDialogFragment.TAG);
|
||||
} else {
|
||||
togglePackageNameDisabled(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -337,6 +348,29 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
||||
return new ErrorDialogFragment(host);
|
||||
}
|
||||
|
||||
private @Nullable ConfirmationDialogFragment newConfirmationDialogFragment(
|
||||
@NonNull String packageName,
|
||||
@NonNull CharSequence appName,
|
||||
@NonNull SwitchPreference pref) {
|
||||
DialogHost host =
|
||||
new DialogHost() {
|
||||
@Override
|
||||
public void onDialogClick(int whichButton) {
|
||||
if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
||||
// Since the package is now enabled then we
|
||||
// should remove it from the enabled list.
|
||||
togglePackageNameDisabled(packageName);
|
||||
} else if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
|
||||
// Set the checked back to true because we
|
||||
// backed out of turning this off.
|
||||
pref.setChecked(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return new ConfirmationDialogFragment(host, packageName, appName);
|
||||
}
|
||||
|
||||
private int getUser() {
|
||||
UserHandle workUser = getWorkProfileUser();
|
||||
return workUser != null ? workUser.getIdentifier() : UserHandle.myUserId();
|
||||
@@ -386,4 +420,44 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirmation dialog fragment shows a dialog to the user to confirm that they are disabling a
|
||||
* provider.
|
||||
*/
|
||||
public static class ConfirmationDialogFragment extends CredentialManagerDialogFragment {
|
||||
|
||||
ConfirmationDialogFragment(
|
||||
DialogHost dialogHost, @NonNull String packageName, @NonNull CharSequence appName) {
|
||||
super(dialogHost);
|
||||
|
||||
final Bundle argument = new Bundle();
|
||||
argument.putString(PACKAGE_NAME_KEY, packageName);
|
||||
argument.putCharSequence(APP_NAME_KEY, appName);
|
||||
setArguments(argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Bundle bundle = getArguments();
|
||||
final String title =
|
||||
getContext()
|
||||
.getString(
|
||||
R.string.credman_confirmation_message_title,
|
||||
bundle.getCharSequence(
|
||||
CredentialManagerDialogFragment.APP_NAME_KEY));
|
||||
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle(title)
|
||||
.setMessage(getContext().getString(R.string.credman_confirmation_message))
|
||||
.setPositiveButton(R.string.credman_confirmation_message_positive_button, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getDialogHost().onDialogClick(which);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user