Loading src/com/android/settings/applications/credentials/CredentialManagerPreferenceController.java +21 −0 Original line number Diff line number Diff line Loading @@ -376,6 +376,10 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl 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<>()); } Loading Loading @@ -579,6 +583,23 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl return new NewProviderConfirmationDialogFragment(host, packageName, 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, String packageName, boolean setActivityResult) { Loading tests/unit/src/com/android/settings/applications/credentials/CredentialManagerPreferenceControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,25 @@ public class CredentialManagerPreferenceControllerTest { 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 public void displayPreference_noServices_noPreferencesAdded_useAutofillUri() { Settings.Secure.putStringForUser( Loading Loading
src/com/android/settings/applications/credentials/CredentialManagerPreferenceController.java +21 −0 Original line number Diff line number Diff line Loading @@ -376,6 +376,10 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl 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<>()); } Loading Loading @@ -579,6 +583,23 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl return new NewProviderConfirmationDialogFragment(host, packageName, 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, String packageName, boolean setActivityResult) { Loading
tests/unit/src/com/android/settings/applications/credentials/CredentialManagerPreferenceControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,25 @@ public class CredentialManagerPreferenceControllerTest { 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 public void displayPreference_noServices_noPreferencesAdded_useAutofillUri() { Settings.Secure.putStringForUser( Loading