Loading src/com/android/settings/overlay/SupportFeatureProvider.java +11 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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) { } } src/com/android/settings/support/SupportDashboardActivity.java +10 −1 Original line number Diff line number Diff line Loading @@ -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; Loading tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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 Loading @@ -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() { Loading Loading
src/com/android/settings/overlay/SupportFeatureProvider.java +11 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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) { } }
src/com/android/settings/support/SupportDashboardActivity.java +10 −1 Original line number Diff line number Diff line Loading @@ -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; Loading
tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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 Loading @@ -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() { Loading