Search in sources :

Example 1 with AutofillServiceInfo

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);
}
Also used : AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 2 with AutofillServiceInfo

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);
}
Also used : AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 3 with AutofillServiceInfo

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);
    }
}
Also used : AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AppPreference(com.android.settingslib.widget.AppPreference) AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) Drawable(android.graphics.drawable.Drawable) MutableLiveData(androidx.lifecycle.MutableLiveData) Intent(android.content.Intent)

Example 4 with AutofillServiceInfo

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()));
}
Also used : Preference(androidx.preference.Preference) AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) UserHandle(android.os.UserHandle) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

AutofillServiceInfo (android.service.autofill.AutofillServiceInfo)4 UiThreadTest (androidx.test.annotation.UiThreadTest)3 Test (org.junit.Test)3 Intent (android.content.Intent)2 ComponentName (android.content.ComponentName)1 ServiceInfo (android.content.pm.ServiceInfo)1 Drawable (android.graphics.drawable.Drawable)1 UserHandle (android.os.UserHandle)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 Preference (androidx.preference.Preference)1 AppPreference (com.android.settingslib.widget.AppPreference)1