use of android.service.autofill.AutofillServiceInfo in project android_packages_apps_Settings by omnirom.
the class PasswordsPreferenceControllerTest method getAvailabilityStatus_noPasswords_returnsUnavailable.
@Test
public void getAvailabilityStatus_noPasswords_returnsUnavailable() {
AutofillServiceInfo service = new AutofillServiceInfo.TestDataBuilder().build();
PasswordsPreferenceController controller = createControllerWithServices(Lists.newArrayList(service));
assertThat(controller.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
use of android.service.autofill.AutofillServiceInfo in project android_packages_apps_Settings by omnirom.
the class PasswordsPreferenceControllerTest method displayPreference_noPasswords_noPreferencesAdded.
@Test
public void displayPreference_noPasswords_noPreferencesAdded() {
AutofillServiceInfo service = new AutofillServiceInfo.TestDataBuilder().build();
PasswordsPreferenceController controller = createControllerWithServices(Lists.newArrayList(service));
controller.displayPreference(mScreen);
assertThat(mPasswordsPreferenceCategory.getPreferenceCount()).isEqualTo(0);
}
use of android.service.autofill.AutofillServiceInfo in project android_packages_apps_Settings by omnirom.
the class PasswordsPreferenceController method addPasswordPreferences.
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 AppPreference pref = new AppPreference(prefContext);
final ServiceInfo serviceInfo = service.getServiceInfo();
pref.setTitle(serviceInfo.loadLabel(mPm));
final Drawable icon = mIconFactory.getBadgedIcon(serviceInfo, serviceInfo.applicationInfo, user);
pref.setIcon(Utils.getSafeIcon(icon));
pref.setOnPreferenceClickListener(p -> {
final Intent intent = new Intent(Intent.ACTION_MAIN).setClassName(serviceInfo.packageName, service.getPasswordsActivity());
prefContext.startActivityAsUser(intent, UserHandle.of(user));
return true;
});
// Set a placeholder summary to avoid a UI flicker when the value loads.
pref.setSummary(R.string.autofill_passwords_count_placeholder);
final MutableLiveData<Integer> passwordCount = new MutableLiveData<>();
passwordCount.observe(mLifecycleOwner, count -> {
// TODO(b/169455298): Validate the result.
final CharSequence summary = mContext.getResources().getQuantityString(R.plurals.autofill_passwords_count, count, count);
pref.setSummary(summary);
});
// TODO(b/169455298): Limit the number of concurrent queries.
// TODO(b/169455298): Cache the results for some time.
requestSavedPasswordCount(service, user, passwordCount);
group.addPreference(pref);
}
}
use of android.service.autofill.AutofillServiceInfo in project android_packages_apps_Settings by omnirom.
the class PasswordsPreferenceControllerTest method displayPreference_withPasswords_addsPreference.
@Test
@UiThreadTest
public void displayPreference_withPasswords_addsPreference() {
AutofillServiceInfo service = createServiceWithPasswords();
service.getServiceInfo().packageName = "";
service.getServiceInfo().name = "";
PasswordsPreferenceController controller = createControllerWithServices(Lists.newArrayList(service));
doReturn(false).when(mContext).bindServiceAsUser(any(), any(), anyInt(), any());
controller.displayPreference(mScreen);
assertThat(mPasswordsPreferenceCategory.getPreferenceCount()).isEqualTo(1);
Preference pref = mPasswordsPreferenceCategory.getPreference(0);
assertThat(pref.getIcon()).isNotNull();
pref.performClick();
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
UserHandle user = mContext.getUser();
verify(mContext).startActivityAsUser(intentCaptor.capture(), eq(user));
assertThat(intentCaptor.getValue().getComponent()).isEqualTo(new ComponentName(service.getServiceInfo().packageName, service.getPasswordsActivity()));
}
Aggregations