Merge "Add dialog for enabling a provider in settings" into udc-dev
This commit is contained in:
@@ -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>
|
<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] -->
|
<!-- 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] -->
|
<!-- 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>
|
<string name="credman_enable_confirmation_message">%1$s uses what\'s on your screen to determine what can be autofilled.</string>
|
||||||
|
|
||||||
<!-- Positive button to turn on credential manager provider (confirmation). [CHAR LIMIT=60] -->
|
|
||||||
<string name="credman_enable_confirmation_message_positive_button">Turn on</string>
|
|
||||||
|
|
||||||
<!-- Title of the error dialog when too many credential providers are selected. [CHAR_LIMIT=NONE] -->
|
<!-- 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>
|
<string name="credman_error_message_title">Passwords, passkeys and data services limit</string>
|
||||||
|
@@ -153,8 +153,7 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String action = launchIntent.getAction();
|
final String action = launchIntent.getAction();
|
||||||
final boolean isCredProviderAction =
|
final boolean isCredProviderAction = TextUtils.equals(action, PRIMARY_INTENT);
|
||||||
TextUtils.equals(action, PRIMARY_INTENT);
|
|
||||||
final boolean isExistingAction = TextUtils.equals(action, ALTERNATE_INTENT);
|
final boolean isExistingAction = TextUtils.equals(action, ALTERNATE_INTENT);
|
||||||
final boolean isValid = isCredProviderAction || isExistingAction;
|
final boolean isValid = isCredProviderAction || isExistingAction;
|
||||||
|
|
||||||
@@ -226,7 +225,8 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
NewProviderConfirmationDialogFragment fragment =
|
NewProviderConfirmationDialogFragment fragment =
|
||||||
newNewProviderConfirmationDialogFragment(serviceInfo.packageName, appName);
|
newNewProviderConfirmationDialogFragment(
|
||||||
|
serviceInfo.packageName, appName, /* setActivityResult= */ true);
|
||||||
if (fragment == null || mFragmentManager == null) {
|
if (fragment == null || mFragmentManager == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -482,19 +482,16 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
boolean isChecked = pref.isChecked();
|
boolean isChecked = pref.isChecked();
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
// Show the error if too many enabled.
|
// Since we are enabling it we should confirm the user decision with a
|
||||||
if (!togglePackageNameEnabled(packageName)) {
|
// dialog box.
|
||||||
final DialogFragment fragment = newErrorDialogFragment();
|
NewProviderConfirmationDialogFragment fragment =
|
||||||
|
newNewProviderConfirmationDialogFragment(
|
||||||
|
packageName, title, /* setActivityResult= */ false);
|
||||||
if (fragment == null || mFragmentManager == null) {
|
if (fragment == null || mFragmentManager == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment.show(mFragmentManager, ErrorDialogFragment.TAG);
|
fragment.show(mFragmentManager, NewProviderConfirmationDialogFragment.TAG);
|
||||||
|
|
||||||
// The user set the check to true so we need to set it back.
|
|
||||||
pref.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -546,12 +543,15 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
/** Create the new provider confirmation dialog. */
|
/** Create the new provider confirmation dialog. */
|
||||||
private @Nullable NewProviderConfirmationDialogFragment
|
private @Nullable NewProviderConfirmationDialogFragment
|
||||||
newNewProviderConfirmationDialogFragment(
|
newNewProviderConfirmationDialogFragment(
|
||||||
@NonNull String packageName, @NonNull CharSequence appName) {
|
@NonNull String packageName,
|
||||||
|
@NonNull CharSequence appName,
|
||||||
|
boolean setActivityResult) {
|
||||||
DialogHost host =
|
DialogHost host =
|
||||||
new DialogHost() {
|
new DialogHost() {
|
||||||
@Override
|
@Override
|
||||||
public void onDialogClick(int whichButton) {
|
public void onDialogClick(int whichButton) {
|
||||||
completeEnableProviderDialogBox(whichButton, packageName);
|
completeEnableProviderDialogBox(
|
||||||
|
whichButton, packageName, setActivityResult);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -559,17 +559,19 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void completeEnableProviderDialogBox(int whichButton, String packageName) {
|
void completeEnableProviderDialogBox(
|
||||||
|
int whichButton, String packageName, boolean setActivityResult) {
|
||||||
|
int activityResult = -1;
|
||||||
if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
||||||
if (togglePackageNameEnabled(packageName)) {
|
if (togglePackageNameEnabled(packageName)) {
|
||||||
// Enable all prefs.
|
// Enable all prefs.
|
||||||
if (mPrefs.containsKey(packageName)) {
|
if (mPrefs.containsKey(packageName)) {
|
||||||
mPrefs.get(packageName).setChecked(true);
|
mPrefs.get(packageName).setChecked(true);
|
||||||
}
|
}
|
||||||
setActivityResult(Activity.RESULT_OK);
|
activityResult = Activity.RESULT_OK;
|
||||||
} else {
|
} else {
|
||||||
// There are too many providers so set the result as cancelled.
|
// 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.
|
// Show the error if too many enabled.
|
||||||
final DialogFragment fragment = newErrorDialogFragment();
|
final DialogFragment fragment = newErrorDialogFragment();
|
||||||
@@ -582,7 +584,13 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The user clicked the cancel button so send that result back.
|
// 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) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Bundle bundle = getArguments();
|
final Bundle bundle = getArguments();
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
|
final CharSequence appName =
|
||||||
|
bundle.getCharSequence(CredentialManagerDialogFragment.APP_NAME_KEY);
|
||||||
final String title =
|
final String title =
|
||||||
context.getString(
|
context.getString(R.string.credman_enable_confirmation_message_title, appName);
|
||||||
R.string.credman_enable_confirmation_message_title,
|
final String message =
|
||||||
bundle.getCharSequence(CredentialManagerDialogFragment.APP_NAME_KEY));
|
context.getString(R.string.credman_enable_confirmation_message, appName);
|
||||||
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setMessage(context.getString(R.string.credman_enable_confirmation_message))
|
.setMessage(message)
|
||||||
.setPositiveButton(
|
.setPositiveButton(android.R.string.ok, this)
|
||||||
R.string.credman_enable_confirmation_message_positive_button, this)
|
|
||||||
.setNegativeButton(android.R.string.cancel, this)
|
.setNegativeButton(android.R.string.cancel, this)
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
@@ -389,7 +389,7 @@ public class CredentialManagerPreferenceControllerTest {
|
|||||||
Intent intent = new Intent(PRIMARY_INTENT);
|
Intent intent = new Intent(PRIMARY_INTENT);
|
||||||
intent.setData(Uri.parse("package:" + packageName));
|
intent.setData(Uri.parse("package:" + packageName));
|
||||||
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
|
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);
|
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ public class CredentialManagerPreferenceControllerTest {
|
|||||||
Intent intent = new Intent(PRIMARY_INTENT);
|
Intent intent = new Intent(PRIMARY_INTENT);
|
||||||
intent.setData(Uri.parse("package:" + packageName));
|
intent.setData(Uri.parse("package:" + packageName));
|
||||||
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
|
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);
|
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,7 +430,7 @@ public class CredentialManagerPreferenceControllerTest {
|
|||||||
Intent intent = new Intent(ALTERNATE_INTENT);
|
Intent intent = new Intent(ALTERNATE_INTENT);
|
||||||
intent.setData(Uri.parse("package:" + packageName));
|
intent.setData(Uri.parse("package:" + packageName));
|
||||||
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
|
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);
|
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +445,7 @@ public class CredentialManagerPreferenceControllerTest {
|
|||||||
Intent intent = new Intent(ALTERNATE_INTENT);
|
Intent intent = new Intent(ALTERNATE_INTENT);
|
||||||
intent.setData(Uri.parse("package:" + packageName));
|
intent.setData(Uri.parse("package:" + packageName));
|
||||||
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
|
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);
|
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user