Integrated SearchIndexableResources interface in Settings
- New SearchIndexableResources interface returns SearchIndexableBundle, we don't need reflection to get SearchIndexableProvider Bug: 135053028 Test: robolectric, check database search_index.db items Change-Id: I5ed3416ccf72ef3d38db817fcb4aff7502649ed4
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.search.Indexable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Utility class for {@like DatabaseIndexingManager} to handle the mapping between Payloads
|
||||
* and Preference controllers, and managing indexable classes.
|
||||
*/
|
||||
public class DatabaseIndexingUtils {
|
||||
|
||||
private static final String TAG = "IndexingUtil";
|
||||
|
||||
public static final String FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER =
|
||||
"SEARCH_INDEX_DATA_PROVIDER";
|
||||
|
||||
public static Indexable.SearchIndexProvider getSearchIndexProvider(final Class<?> clazz) {
|
||||
try {
|
||||
final Field f = clazz.getField(FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER);
|
||||
return (Indexable.SearchIndexProvider) f.get(null);
|
||||
} catch (NoSuchFieldException e) {
|
||||
Log.d(TAG, "Cannot find field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'");
|
||||
} catch (SecurityException se) {
|
||||
Log.d(TAG, "Security exception for field '" +
|
||||
FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'");
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.d(TAG, "Illegal access to field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'");
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(TAG, "Illegal argument when accessing field '" +
|
||||
FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -68,6 +68,7 @@ import com.android.settings.slices.SettingsSliceProvider;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.search.SearchIndexableData;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -260,14 +261,14 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
}
|
||||
|
||||
private List<String> getNonIndexableKeysFromProvider(Context context) {
|
||||
final Collection<Class> values = getIndexableProviderValues(context);
|
||||
final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context)
|
||||
.getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
|
||||
|
||||
final List<String> nonIndexableKeys = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : values) {
|
||||
for (SearchIndexableData bundle : bundles) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final Indexable.SearchIndexProvider provider =
|
||||
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
|
||||
|
||||
Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
|
||||
List<String> providerNonIndexableKeys;
|
||||
try {
|
||||
providerNonIndexableKeys = provider.getNonIndexableKeys(context);
|
||||
@@ -281,7 +282,8 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
if (System.getProperty(SYSPROP_CRASH_ON_ERROR) != null) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Log.e(TAG, "Error trying to get non-indexable keys from: " + clazz.getName(), e);
|
||||
Log.e(TAG, "Error trying to get non-indexable keys from: "
|
||||
+ bundle.getTargetClass().getName(), e);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -310,12 +312,12 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
}
|
||||
|
||||
private List<SearchIndexableResource> getSearchIndexableResourcesFromProvider(Context context) {
|
||||
final Collection<Class> values = getIndexableProviderValues(context);
|
||||
final List<SearchIndexableResource> resourceList = new ArrayList<>();
|
||||
final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context)
|
||||
.getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
|
||||
List<SearchIndexableResource> resourceList = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : values) {
|
||||
final Indexable.SearchIndexProvider provider =
|
||||
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
|
||||
for (SearchIndexableData bundle : bundles) {
|
||||
Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
|
||||
final List<SearchIndexableResource> resList =
|
||||
provider.getXmlResourcesToIndex(context, true);
|
||||
|
||||
@@ -325,7 +327,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
|
||||
for (SearchIndexableResource item : resList) {
|
||||
item.className = TextUtils.isEmpty(item.className)
|
||||
? clazz.getName()
|
||||
? bundle.getTargetClass().getName()
|
||||
: item.className;
|
||||
}
|
||||
|
||||
@@ -336,14 +338,14 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
}
|
||||
|
||||
private List<SearchIndexableRaw> getSearchIndexableRawFromProvider(Context context) {
|
||||
final Collection<Class> values = getIndexableProviderValues(context);
|
||||
final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context)
|
||||
.getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
|
||||
final List<SearchIndexableRaw> rawList = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : values) {
|
||||
final Indexable.SearchIndexProvider provider =
|
||||
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
|
||||
final List<SearchIndexableRaw> providerRaws =
|
||||
provider.getRawDataToIndex(context, true /* enabled */);
|
||||
for (SearchIndexableData bundle : bundles) {
|
||||
Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
|
||||
final List<SearchIndexableRaw> providerRaws = provider.getRawDataToIndex(context,
|
||||
true /* enabled */);
|
||||
|
||||
if (providerRaws == null) {
|
||||
continue;
|
||||
@@ -352,7 +354,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
for (SearchIndexableRaw raw : providerRaws) {
|
||||
// The classname and intent information comes from the PreIndexData
|
||||
// This will be more clear when provider conversion is done at PreIndex time.
|
||||
raw.className = clazz.getName();
|
||||
raw.className = bundle.getTargetClass().getName();
|
||||
|
||||
}
|
||||
rawList.addAll(providerRaws);
|
||||
@@ -362,12 +364,12 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
}
|
||||
|
||||
private List<SearchIndexableRaw> getDynamicSearchIndexableRawFromProvider(Context context) {
|
||||
final Collection<Class> values = getIndexableProviderValues(context);
|
||||
final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context)
|
||||
.getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
|
||||
final List<SearchIndexableRaw> rawList = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : values) {
|
||||
final Indexable.SearchIndexProvider provider =
|
||||
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
|
||||
for (SearchIndexableData bundle : bundles) {
|
||||
final Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
|
||||
final List<SearchIndexableRaw> providerRaws =
|
||||
provider.getDynamicRawDataToIndex(context, true /* enabled */);
|
||||
|
||||
@@ -378,7 +380,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
for (SearchIndexableRaw raw : providerRaws) {
|
||||
// The classname and intent information comes from the PreIndexData
|
||||
// This will be more clear when provider conversion is done at PreIndex time.
|
||||
raw.className = clazz.getName();
|
||||
raw.className = bundle.getTargetClass().getName();
|
||||
|
||||
}
|
||||
rawList.addAll(providerRaws);
|
||||
@@ -410,9 +412,4 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
|
||||
return rawList;
|
||||
}
|
||||
|
||||
private Collection<Class> getIndexableProviderValues(Context context) {
|
||||
return FeatureFactory.getFactory(context)
|
||||
.getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user