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:
Becca Hughes
2023-04-21 20:10:03 +00:00
parent 5ba22651c4
commit 02ca65edaa
2 changed files with 51 additions and 0 deletions

View File

@@ -340,6 +340,21 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
@VisibleForTesting
public Map<ServiceInfo, SwitchPreference> buildPreferenceList(
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.
Map<ServiceInfo, SwitchPreference> output = new HashMap<>();
for (CredentialProviderInfo service : mServices) {
@@ -519,6 +534,23 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
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
void completeEnableProviderDialogBox(int whichButton, ServiceInfo service, boolean setActivityResult) {
int activityResult = -1;