Implement querySiteMapPairs for indexableProvider.

Query sitemap will return a list of pairs [parent class name, child
class name]. It's up to consumer to figure out the display name later
so the provider doesn't have dependency on localizing any display names.

- Removed SiteMapManagerTest. We will perform the test in
  SettingsIntelligence instead.
- Added test for the new provider in instrumentation test (robolectric
  doesn't recognize the new constants in framework yet)

Bug: 67359411
Bug: 64938328
Test: atest
Change-Id: Ia973115320e6b7c8cf84d4756db1763ae7010aed
This commit is contained in:
Fan Zhang
2017-11-27 15:50:19 -08:00
parent 65ec66e394
commit 518e648acf
6 changed files with 118 additions and 181 deletions

View File

@@ -40,16 +40,24 @@ import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RES
import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS;
import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS;
import static android.provider.SearchIndexablesContract.SITE_MAP_COLUMNS;
import static com.android.settings.dashboard.DashboardFragmentRegistry.CATEGORY_KEY_TO_PARENT_MAP;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.provider.SearchIndexableResource;
import android.provider.SearchIndexablesContract;
import android.provider.SearchIndexablesProvider;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import com.android.settings.SettingsActivity;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -134,6 +142,38 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
return cursor;
}
@Override
public Cursor querySiteMapPairs() {
final MatrixCursor cursor = new MatrixCursor(SITE_MAP_COLUMNS);
final Context context = getContext();
// Loop through all IA categories and pages and build additional SiteMapPairs
final List<DashboardCategory> categories = FeatureFactory.getFactory(context)
.getDashboardFeatureProvider(context).getAllCategories();
for (DashboardCategory category : categories) {
// Use the category key to look up parent (which page hosts this key)
final String parentClass = CATEGORY_KEY_TO_PARENT_MAP.get(category.key);
if (parentClass == null) {
continue;
}
// Build parent-child class pairs for all children listed under this key.
for (Tile tile : category.tiles) {
String childClass = null;
if (tile.metaData != null) {
childClass = tile.metaData.getString(
SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
}
if (childClass == null) {
continue;
}
cursor.newRow()
.add(SearchIndexablesContract.SiteMapColumns.PARENT_CLASS, parentClass)
.add(SearchIndexablesContract.SiteMapColumns.CHILD_CLASS, childClass);
}
}
// Done.
return cursor;
}
private List<String> getNonIndexableKeysFromProvider(Context context) {
final Collection<Class> values = SearchIndexableResources.providerValues();
final List<String> nonIndexableKeys = new ArrayList<>();