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

Commit db4ded5c authored by Nick Croll's avatar Nick Croll
Browse files

Make support search index provider customizable in SupportDashboardActivity

This commit allows the SearchIndexableRaw data to be overriden by the
support feature provider.

Similar to work in ag/31971633 allowing SupportFeatureProvider to apply overrides on the Preference

Bug: 420354473
Flag: EXEMPT no-op new APIs for partner override
Test: manual

Change-Id: I34530bbf279f551543e64216e94d8846873bfd59
parent 9c0c5a8f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.preference.Preference;

import com.android.settingslib.search.SearchIndexableRaw;

/**
 * Feature provider for support tab.
 */
@@ -42,4 +44,13 @@ public interface SupportFeatureProvider {
     */
    default void applyOverrides(@NonNull Context context, @NonNull Preference pref) {
    }

    /**
     * Applies overrides to the support search indexable, if needed.
     *
     * @param context support dashboard activity context.
     * @param data The support search indexable.
     */
    default void applyOverrides(@NonNull Context context, @NonNull SearchIndexableRaw data) {
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -74,6 +74,15 @@ public class SupportDashboardActivity extends Activity implements Indexable {
                    data.intentTargetClass = SupportDashboardActivity.class.getName();
                    data.intentAction = ACTION_SUPPORT_SETTINGS;
                    data.key = SUPPORT_SEARCH_INDEX_KEY;

                    SupportFeatureProvider supportFeatureProvider =
                            FeatureFactory.getFeatureFactory().getSupportFeatureProvider();
                    // If the support feature provider is available, allow it
                    // to override values on the search indexable.
                    if (supportFeatureProvider != null) {
                        supportFeatureProvider.applyOverrides(context, data);
                    }

                    result.add(data);

                    return result;
+42 −0
Original line number Diff line number Diff line
@@ -20,12 +20,17 @@ import static com.android.settings.support.SupportDashboardActivity.ACTION_SUPPO

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.android.settings.R;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.search.SearchIndexableRaw;

import org.junit.Before;
@@ -34,6 +39,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;

import java.util.List;

@@ -41,10 +47,12 @@ import java.util.List;
public class SupportDashboardActivityTest {

    private Context mContext;
    private FakeFeatureFactory mFeatureFactory;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        mFeatureFactory = FakeFeatureFactory.setupForTest();
    }

    @Test
@@ -65,6 +73,40 @@ public class SupportDashboardActivityTest {
        assertThat(value.intentAction).isEqualTo(ACTION_SUPPORT_SETTINGS);
    }

    @Test
    public void getRawDataToIndex_handlesNullSupportFeatureProvider() {
        ReflectionHelpers.setField(mFeatureFactory, "supportFeatureProvider", null);
        final List<SearchIndexableRaw> indexables =
                SupportDashboardActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
                        mContext, true /* enabled */);

        assertThat(indexables).hasSize(1);

        final SearchIndexableRaw value = indexables.get(0);

        assertThat(value.title).isEqualTo(mContext.getString(R.string.page_tab_title_support));
        assertThat(value.screenTitle)
                .isEqualTo(mContext.getString(R.string.page_tab_title_support));
        assertThat(value.intentTargetPackage).isEqualTo(mContext.getPackageName());
        assertThat(value.intentTargetClass).isEqualTo(SupportDashboardActivity.class.getName());
        assertThat(value.intentAction).isEqualTo(ACTION_SUPPORT_SETTINGS);
    }

    @Test
    public void getRawDataToIndex_callsSupportFeatureProviderApplyOverrides() {
        final List<SearchIndexableRaw> indexables =
                SupportDashboardActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
                        mContext, true /* enabled */);

        assertThat(indexables).hasSize(1);

        final SearchIndexableRaw value = indexables.get(0);
        final SupportFeatureProvider supportFeatureProvider =
                mFeatureFactory.getSupportFeatureProvider();

        verify(supportFeatureProvider).applyOverrides(eq(mContext), eq(value));
    }

    @Ignore("b/314927625")
    @Test
    public void shouldHandleIntentAction() {