diff --git a/res/values/strings.xml b/res/values/strings.xml index 75884fade5e..9724b021ffd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11481,8 +11481,10 @@ Autofill service + + Passwords - auto, fill, autofill + auto, fill, autofill, password diff --git a/res/xml/default_autofill_picker_settings.xml b/res/xml/default_autofill_picker_settings.xml index bfc285bf5ee..392f733ba56 100644 --- a/res/xml/default_autofill_picker_settings.xml +++ b/res/xml/default_autofill_picker_settings.xml @@ -22,14 +22,27 @@ android:title="@string/autofill_app" settings:keywords="@string/autofill_keywords"> - - - + + + + + + + + + + mServices; + + public PasswordsPreferenceController(Context context, String preferenceKey) { + super(context, preferenceKey); + mPm = context.getPackageManager(); + mIconFactory = IconDrawableFactory.newInstance(mContext); + mServices = AutofillServiceInfo.getAvailableServices(mContext, UserHandle.myUserId()); + for (int i = mServices.size() - 1; i >= 0; i--) { + final String passwordsActivity = mServices.get(i).getPasswordsActivity(); + if (TextUtils.isEmpty(passwordsActivity)) { + mServices.remove(i); + } + } + } + + @Override + public int getAvailabilityStatus() { + return mServices.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE; + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + final PreferenceGroup group = screen.findPreference(getPreferenceKey()); + // TODO(b/169455298): Show work profile passwords too. + addPasswordPreferences(screen.getContext(), UserHandle.myUserId(), group); + } + + private void addPasswordPreferences( + Context prefContext, @UserIdInt int user, PreferenceGroup group) { + for (int i = 0; i < mServices.size(); i++) { + final AutofillServiceInfo service = mServices.get(i); + final Preference pref = new Preference(prefContext); + final ServiceInfo serviceInfo = service.getServiceInfo(); + pref.setTitle(serviceInfo.loadLabel(mPm)); + final Drawable icon = + mIconFactory.getBadgedIcon( + serviceInfo, + serviceInfo.applicationInfo, + user); + Utils.setSafeIcon(pref, icon); + pref.setIntent( + new Intent(Intent.ACTION_MAIN) + .setClassName(serviceInfo.packageName, service.getPasswordsActivity())); + group.addPreference(pref); + } + } +}