Hide provider from this list if autofill provider
Since we are merging the two lists we should hide the provider from this list to avoid duplicates. Test: local & unit Bug: 279205251 Change-Id: I70ec4a4bda13bdcd5fd8f82f6ba6045e94d5daa9
This commit is contained in:
@@ -340,6 +340,21 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public Map<ServiceInfo, SwitchPreference> buildPreferenceList(
|
public Map<ServiceInfo, SwitchPreference> buildPreferenceList(
|
||||||
Context context, PreferenceGroup group) {
|
Context context, PreferenceGroup group) {
|
||||||
|
// Group the services by package name.
|
||||||
|
Map<String, List<CredentialProviderInfo>> groupedInfos = new HashMap<>();
|
||||||
|
for (CredentialProviderInfo cpi : mServices) {
|
||||||
|
String packageName = cpi.getServiceInfo().packageName;
|
||||||
|
if (isProviderHiddenBecauseOfAutofill(packageName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!groupedInfos.containsKey(packageName)) {
|
||||||
|
groupedInfos.put(packageName, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedInfos.get(packageName).add(cpi);
|
||||||
|
}
|
||||||
|
|
||||||
// Build the pref list.
|
// Build the pref list.
|
||||||
Map<ServiceInfo, SwitchPreference> output = new HashMap<>();
|
Map<ServiceInfo, SwitchPreference> output = new HashMap<>();
|
||||||
for (CredentialProviderInfo service : mServices) {
|
for (CredentialProviderInfo service : mServices) {
|
||||||
@@ -519,6 +534,23 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
|
|||||||
return new NewProviderConfirmationDialogFragment(host, service, appName);
|
return new NewProviderConfirmationDialogFragment(host, service, appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** If the provider is also the autofill provider then hide it. */
|
||||||
|
@VisibleForTesting
|
||||||
|
public boolean isProviderHiddenBecauseOfAutofill(String packageName) {
|
||||||
|
final String autofillService = Settings.Secure.getStringForUser(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.AUTOFILL_SERVICE,
|
||||||
|
getUser());
|
||||||
|
if (autofillService == null || TextUtils.isEmpty(autofillService)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (packageName == null || TextUtils.isEmpty(packageName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return autofillService.startsWith(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void completeEnableProviderDialogBox(int whichButton, ServiceInfo service, boolean setActivityResult) {
|
void completeEnableProviderDialogBox(int whichButton, ServiceInfo service, boolean setActivityResult) {
|
||||||
int activityResult = -1;
|
int activityResult = -1;
|
||||||
|
@@ -120,6 +120,25 @@ public class CredentialManagerPreferenceControllerTest {
|
|||||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyHiddenIfAutofillSelectedProvider() {
|
||||||
|
CredentialManagerPreferenceController controller =
|
||||||
|
createControllerWithServices(Collections.emptyList());
|
||||||
|
|
||||||
|
// Set the autofill provider.
|
||||||
|
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.AUTOFILL_SERVICE, "com.example.test/AutofillClass",
|
||||||
|
UserHandle.myUserId());
|
||||||
|
|
||||||
|
// Verify the error cases
|
||||||
|
assertThat(controller.isProviderHiddenBecauseOfAutofill(null)).isFalse();
|
||||||
|
assertThat(controller.isProviderHiddenBecauseOfAutofill("")).isFalse();
|
||||||
|
assertThat(controller.isProviderHiddenBecauseOfAutofill("test")).isFalse();
|
||||||
|
|
||||||
|
// Verify the example.
|
||||||
|
assertThat(controller.isProviderHiddenBecauseOfAutofill("com.example.test")).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_noServices_noPreferencesAdded_useAutofillUri() {
|
public void displayPreference_noServices_noPreferencesAdded_useAutofillUri() {
|
||||||
Settings.Secure.putStringForUser(
|
Settings.Secure.putStringForUser(
|
||||||
|
Reference in New Issue
Block a user