Remove the index of the homepage category tiles
Do not index the tiles of homepage category since we would like to index their target activity for search. Fixes: 151418948 Test: visual Change-Id: I693534de006b4dbcaf192858e6f7d031bad78fef
This commit is contained in:
@@ -61,12 +61,14 @@ import android.util.Log;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.slice.SliceViewManager;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.slices.SettingsSliceProvider;
|
||||
import com.android.settingslib.drawer.ActivityTile;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
@@ -379,9 +381,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
final String currentPackageName = context.getPackageName();
|
||||
for (DashboardCategory category : dashboardFeatureProvider.getAllCategories()) {
|
||||
for (Tile tile : category.getTiles()) {
|
||||
if (currentPackageName.equals(tile.getPackageName())
|
||||
&& tile instanceof ActivityTile) {
|
||||
// Skip Settings injected items because they should be indexed in the sub-pages.
|
||||
if (!isEligibleForIndexing(currentPackageName, tile)) {
|
||||
continue;
|
||||
}
|
||||
final SearchIndexableRaw raw = new SearchIndexableRaw(context);
|
||||
@@ -402,6 +402,20 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
return rawList;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isEligibleForIndexing(String packageName, Tile tile) {
|
||||
if (TextUtils.equals(packageName, tile.getPackageName())
|
||||
&& tile instanceof ActivityTile) {
|
||||
// Skip Settings injected items because they should be indexed in the sub-pages.
|
||||
return false;
|
||||
}
|
||||
if (TextUtils.equals(tile.getCategory(), CategoryKey.CATEGORY_HOMEPAGE)) {
|
||||
// Skip homepage injected items since we would like to index their target activity.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Object[] createIndexableRawColumnObjects(SearchIndexableRaw raw) {
|
||||
final Object[] ref = new Object[INDEXABLES_RAW_COLUMNS.length];
|
||||
ref[COLUMN_INDEX_RAW_TITLE] = raw.title;
|
||||
|
@@ -6,6 +6,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@@ -13,6 +14,8 @@ import android.provider.SearchIndexablesContract;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.drawer.ActivityTile;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.search.SearchIndexableData;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -29,7 +32,8 @@ import java.util.List;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SettingsSearchIndexablesProviderTest {
|
||||
|
||||
private static final String BASE_AUTHORITY = "com.android.settings";
|
||||
private static final String PACKAGE_NAME = "com.android.settings";
|
||||
private static final String BASE_AUTHORITY = "content://" + PACKAGE_NAME + "/";
|
||||
|
||||
private SettingsSearchIndexablesProvider mProvider;
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
@@ -40,7 +44,7 @@ public class SettingsSearchIndexablesProviderTest {
|
||||
ProviderInfo info = new ProviderInfo();
|
||||
info.exported = true;
|
||||
info.grantUriPermissions = true;
|
||||
info.authority = BASE_AUTHORITY;
|
||||
info.authority = PACKAGE_NAME;
|
||||
info.readPermission = Manifest.permission.READ_SEARCH_INDEXABLES;
|
||||
mProvider.attachInfo(RuntimeEnvironment.application, info);
|
||||
|
||||
@@ -60,8 +64,7 @@ public class SettingsSearchIndexablesProviderTest {
|
||||
|
||||
@Test
|
||||
public void testRawColumnFetched() {
|
||||
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||
SearchIndexablesContract.INDEXABLES_RAW_PATH);
|
||||
Uri rawUri = Uri.parse(BASE_AUTHORITY + SearchIndexablesContract.INDEXABLES_RAW_PATH);
|
||||
|
||||
final Cursor cursor = mProvider.query(rawUri,
|
||||
SearchIndexablesContract.INDEXABLES_RAW_COLUMNS, null, null, null);
|
||||
@@ -83,8 +86,7 @@ public class SettingsSearchIndexablesProviderTest {
|
||||
|
||||
@Test
|
||||
public void testResourcesColumnFetched() {
|
||||
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||
SearchIndexablesContract.INDEXABLES_XML_RES_PATH);
|
||||
Uri rawUri = Uri.parse(BASE_AUTHORITY + SearchIndexablesContract.INDEXABLES_XML_RES_PATH);
|
||||
|
||||
final Cursor cursor = mProvider.query(rawUri,
|
||||
SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS, null, null, null);
|
||||
@@ -102,8 +104,8 @@ public class SettingsSearchIndexablesProviderTest {
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void testNonIndexablesColumnFetched() {
|
||||
final Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
|
||||
final Uri rawUri = Uri.parse(
|
||||
BASE_AUTHORITY + SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
|
||||
|
||||
final List<String> keys = new ArrayList<>();
|
||||
|
||||
@@ -117,4 +119,37 @@ public class SettingsSearchIndexablesProviderTest {
|
||||
assertThat(keys).hasSize(3);
|
||||
assertThat(keys).containsAllOf("pref_key_1", "pref_key_3", "pref_key_5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEligibleForIndexing_isSettingsInjectedItem_ShouldBeFalse() {
|
||||
final ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.packageName = PACKAGE_NAME;
|
||||
activityInfo.name = "class";
|
||||
final ActivityTile activityTile = new ActivityTile(activityInfo,
|
||||
CategoryKey.CATEGORY_SYSTEM);
|
||||
|
||||
assertThat(mProvider.isEligibleForIndexing(PACKAGE_NAME, activityTile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEligibleForIndexing_isHomepageInjectedItem_ShouldBeFalse() {
|
||||
final ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.packageName = "pkg";
|
||||
activityInfo.name = "class";
|
||||
final ActivityTile activityTile = new ActivityTile(activityInfo,
|
||||
CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
assertThat(mProvider.isEligibleForIndexing(PACKAGE_NAME, activityTile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEligibleForIndexing_normalInjectedItem_ShouldBeTrue() {
|
||||
final ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.packageName = "pkg";
|
||||
activityInfo.name = "class";
|
||||
final ActivityTile activityTile = new ActivityTile(activityInfo,
|
||||
CategoryKey.CATEGORY_CONNECT);
|
||||
|
||||
assertThat(mProvider.isEligibleForIndexing(PACKAGE_NAME, activityTile)).isTrue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user