Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01f992a6 authored by Jason Chiu's avatar Jason Chiu
Browse files

Support "Add account" search indexing

Implement a default getRawDataToIndex method of preference controller
base for indexing preference's raw data.

Test: manual, robotest
Fix: 243899250
Change-Id: I3fb4f88c881edcbaa3c5bfc7f78cc2e169b0380f
parent dd61b6bb
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -187,6 +187,11 @@ public class AccountPreferenceController extends AbstractPreferenceController
        updateUi();
    }

    @Override
    public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
        rawData.add(newAddAccountRawData());
    }

    @Override
    public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
        if (!isAvailable()) {
@@ -428,6 +433,14 @@ public class AccountPreferenceController extends AbstractPreferenceController
        }));
    }

    private SearchIndexableRaw newAddAccountRawData() {
        SearchIndexableRaw data = new SearchIndexableRaw(mContext);
        data.key = PREF_KEY_ADD_ACCOUNT;
        data.title = mContext.getString(R.string.add_account_label);
        data.iconResId = R.drawable.ic_add_24dp;
        return data;
    }

    private RestrictedPreference newAddAccountPreference() {
        RestrictedPreference preference =
                new RestrictedPreference(mFragment.getPreferenceManager().getContext());
+13 −1
Original line number Diff line number Diff line
@@ -73,7 +73,19 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {

    @Override
    public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
        return null;
        final List<SearchIndexableRaw> raws = new ArrayList<>();
        final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
        if (controllers == null || controllers.isEmpty()) {
            return raws;
        }
        for (AbstractPreferenceController controller : controllers) {
            if (controller instanceof PreferenceControllerMixin) {
                ((PreferenceControllerMixin) controller).updateRawDataToIndex(raws);
            } else if (controller instanceof BasePreferenceController) {
                ((BasePreferenceController) controller).updateRawDataToIndex(raws);
            }
        }
        return raws;
    }

    @Override
+10 −9
Original line number Diff line number Diff line
@@ -254,25 +254,26 @@ public class AccountPreferenceControllerTest {
    }

    @Test
    public void updateRawDataToIndex_ManagedProfile_shouldNotUpdate() {
    public void updateRawDataToIndex_noManagedProfile_shouldContainAddAccount() {
        final List<SearchIndexableRaw> data = new ArrayList<>();
        when(mUserManager.isManagedProfile()).thenReturn(true);
        when(mUserManager.isManagedProfile()).thenReturn(false);

        mController.updateRawDataToIndex(data);

        assertThat(data).isEmpty();
        assertThat(data).hasSize(1);
        assertThat(data.get(0).key).isEqualTo("add_account");
    }


    @Test
    public void updateRawDataToIndex_DisabledUser_shouldNotUpdate() {
    public void updateRawDataToIndex_ManagedProfile_shouldContainAddAccount() {
        final List<SearchIndexableRaw> data = new ArrayList<>();
        final List<UserInfo> infos = new ArrayList<>();
        infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_DISABLED));
        when(mUserManager.isManagedProfile()).thenReturn(false);
        when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
        when(mUserManager.isManagedProfile()).thenReturn(true);

        mController.updateRawDataToIndex(data);

        assertThat(data).isEmpty();
        assertThat(data).hasSize(1);
        assertThat(data.get(0).key).isEqualTo("add_account");
    }

    @Test