Merge "Add dialog for enabling a provider in settings" into udc-dev am: e18613ccc6

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22605959

Change-Id: Ifd7a9e4a9aa944b320db9f92add53accc7be9478
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Becca Hughes
2023-04-17 20:11:44 +00:00
committed by Automerger Merge Worker
3 changed files with 42 additions and 36 deletions

View File

@@ -10284,13 +10284,10 @@
<string name="credman_confirmation_message">Saved info like addresses or payment methods won\'t be filled in when you sign in. To keep your saved info filled in, set enable a password, passkey and data/or service.</string>
<!-- Title of the warning dialog for enabling the credential provider. [CHAR_LIMIT=NONE] -->
<string name="credman_enable_confirmation_message_title">Turn on %1$s\?</string>
<string name="credman_enable_confirmation_message_title">Use %1$s\?</string>
<!-- Message of the warning dialog for enabling the credential provider. [CHAR_LIMIT=NONE] -->
<string name="credman_enable_confirmation_message">Saved info like addresses or payment methods will be shared with this provider.</string>
<!-- Positive button to turn on credential manager provider (confirmation). [CHAR LIMIT=60] -->
<string name="credman_enable_confirmation_message_positive_button">Turn on</string>
<string name="credman_enable_confirmation_message">%1$s uses what\'s on your screen to determine what can be autofilled.</string>
<!-- Title of the error dialog when too many credential providers are selected. [CHAR_LIMIT=NONE] -->
<string name="credman_error_message_title">Passwords, passkeys and data services limit</string>

View File

@@ -153,8 +153,7 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
}
final String action = launchIntent.getAction();
final boolean isCredProviderAction =
TextUtils.equals(action, PRIMARY_INTENT);
final boolean isCredProviderAction = TextUtils.equals(action, PRIMARY_INTENT);
final boolean isExistingAction = TextUtils.equals(action, ALTERNATE_INTENT);
final boolean isValid = isCredProviderAction || isExistingAction;
@@ -226,7 +225,8 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
}
NewProviderConfirmationDialogFragment fragment =
newNewProviderConfirmationDialogFragment(serviceInfo.packageName, appName);
newNewProviderConfirmationDialogFragment(
serviceInfo.packageName, appName, /* setActivityResult= */ true);
if (fragment == null || mFragmentManager == null) {
return;
}
@@ -482,20 +482,17 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
boolean isChecked = pref.isChecked();
if (isChecked) {
// Show the error if too many enabled.
if (!togglePackageNameEnabled(packageName)) {
final DialogFragment fragment = newErrorDialogFragment();
if (fragment == null || mFragmentManager == null) {
return true;
}
fragment.show(mFragmentManager, ErrorDialogFragment.TAG);
// The user set the check to true so we need to set it back.
pref.setChecked(false);
// Since we are enabling it we should confirm the user decision with a
// dialog box.
NewProviderConfirmationDialogFragment fragment =
newNewProviderConfirmationDialogFragment(
packageName, title, /* setActivityResult= */ false);
if (fragment == null || mFragmentManager == null) {
return true;
}
fragment.show(mFragmentManager, NewProviderConfirmationDialogFragment.TAG);
return true;
} else {
// If we are disabling the last enabled provider then show a warning.
@@ -546,12 +543,15 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
/** Create the new provider confirmation dialog. */
private @Nullable NewProviderConfirmationDialogFragment
newNewProviderConfirmationDialogFragment(
@NonNull String packageName, @NonNull CharSequence appName) {
@NonNull String packageName,
@NonNull CharSequence appName,
boolean setActivityResult) {
DialogHost host =
new DialogHost() {
@Override
public void onDialogClick(int whichButton) {
completeEnableProviderDialogBox(whichButton, packageName);
completeEnableProviderDialogBox(
whichButton, packageName, setActivityResult);
}
};
@@ -559,17 +559,19 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
}
@VisibleForTesting
void completeEnableProviderDialogBox(int whichButton, String packageName) {
void completeEnableProviderDialogBox(
int whichButton, String packageName, boolean setActivityResult) {
int activityResult = -1;
if (whichButton == DialogInterface.BUTTON_POSITIVE) {
if (togglePackageNameEnabled(packageName)) {
// Enable all prefs.
if (mPrefs.containsKey(packageName)) {
mPrefs.get(packageName).setChecked(true);
}
setActivityResult(Activity.RESULT_OK);
activityResult = Activity.RESULT_OK;
} else {
// There are too many providers so set the result as cancelled.
setActivityResult(Activity.RESULT_CANCELED);
activityResult = Activity.RESULT_CANCELED;
// Show the error if too many enabled.
final DialogFragment fragment = newErrorDialogFragment();
@@ -582,7 +584,13 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
}
} else {
// The user clicked the cancel button so send that result back.
setActivityResult(Activity.RESULT_CANCELED);
activityResult = Activity.RESULT_CANCELED;
}
// If the dialog is being shown because of the intent we should
// return a result.
if (activityResult == -1 || !setActivityResult) {
setActivityResult(activityResult);
}
}
@@ -735,16 +743,17 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Bundle bundle = getArguments();
final Context context = getContext();
final CharSequence appName =
bundle.getCharSequence(CredentialManagerDialogFragment.APP_NAME_KEY);
final String title =
context.getString(
R.string.credman_enable_confirmation_message_title,
bundle.getCharSequence(CredentialManagerDialogFragment.APP_NAME_KEY));
context.getString(R.string.credman_enable_confirmation_message_title, appName);
final String message =
context.getString(R.string.credman_enable_confirmation_message, appName);
return new AlertDialog.Builder(getActivity())
.setTitle(title)
.setMessage(context.getString(R.string.credman_enable_confirmation_message))
.setPositiveButton(
R.string.credman_enable_confirmation_message_positive_button, this)
.setMessage(message)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, this)
.create();
}

View File

@@ -389,7 +389,7 @@ public class CredentialManagerPreferenceControllerTest {
Intent intent = new Intent(PRIMARY_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName);
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
}
@@ -404,7 +404,7 @@ public class CredentialManagerPreferenceControllerTest {
Intent intent = new Intent(PRIMARY_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName);
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
}
@@ -430,7 +430,7 @@ public class CredentialManagerPreferenceControllerTest {
Intent intent = new Intent(ALTERNATE_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName);
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
}
@@ -445,7 +445,7 @@ public class CredentialManagerPreferenceControllerTest {
Intent intent = new Intent(ALTERNATE_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName);
controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
}