Add test and fix null keys in search providers.

- Add keys to some screens.
- Remove dynamic saved network/turst agent from search provider.
- Remove dynamic print services from printsettings.

Bug: 69384409
Test: atest
Change-Id: I62dce27d52585badb2a8953a05084e35dbae2f7d
This commit is contained in:
Fan Zhang
2017-11-16 09:56:03 -08:00
parent bd6fcdbd2b
commit 7d5c9ace64
15 changed files with 115 additions and 191 deletions

View File

@@ -33,6 +33,7 @@ import android.util.Xml;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.search.SearchIndexableResources;
import com.android.settings.search.XmlParserUtils;
@@ -64,7 +65,7 @@ public class UniquePreferenceTest {
"dashboard_tile_placeholder" // This is the placeholder pref for injecting dynamic
// tiles.
);
);
private Context mContext;
@@ -91,13 +92,13 @@ public class UniquePreferenceTest {
final Set<String> nullKeyClasses = new HashSet<>();
final Set<String> duplicatedKeys = new HashSet<>();
for (Class<?> clazz : SearchIndexableResources.providerValues()) {
verifyPreferenceIdInXml(uniqueKeys, duplicatedKeys, nullKeyClasses, clazz);
verifyPreferenceKeys(uniqueKeys, duplicatedKeys, nullKeyClasses, clazz);
}
if (!nullKeyClasses.isEmpty()) {
final StringBuilder nullKeyErrors = new StringBuilder()
.append("Each preference must have a key, ")
.append("the following classes have pref without keys:\n");
.append("Each preference/SearchIndexableData must have a key, ")
.append("the following classes have null keys:\n");
for (String c : nullKeyClasses) {
nullKeyErrors.append(c).append("\n");
}
@@ -114,7 +115,7 @@ public class UniquePreferenceTest {
}
}
private void verifyPreferenceIdInXml(Set<String> uniqueKeys, Set<String> duplicatedKeys,
private void verifyPreferenceKeys(Set<String> uniqueKeys, Set<String> duplicatedKeys,
Set<String> nullKeyClasses, Class<?> clazz)
throws IOException, XmlPullParserException, Resources.NotFoundException {
if (clazz == null) {
@@ -123,8 +124,16 @@ public class UniquePreferenceTest {
final String className = clazz.getName();
final Indexable.SearchIndexProvider provider =
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
final List<SearchIndexableRaw> rawsToIndex = provider.getRawDataToIndex(mContext, true);
final List<SearchIndexableResource> resourcesToIndex =
provider.getXmlResourcesToIndex(mContext, true);
verifyResources(className, resourcesToIndex, uniqueKeys, duplicatedKeys, nullKeyClasses);
verifyRaws(className, rawsToIndex, uniqueKeys, duplicatedKeys, nullKeyClasses);
}
private void verifyResources(String className, List<SearchIndexableResource> resourcesToIndex,
Set<String> uniqueKeys, Set<String> duplicatedKeys, Set<String> nullKeyClasses)
throws IOException, XmlPullParserException, Resources.NotFoundException {
if (resourcesToIndex == null) {
Log.d(TAG, className + "is not providing SearchIndexableResource, skipping");
return;
@@ -172,4 +181,25 @@ public class UniquePreferenceTest {
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
}
}
private void verifyRaws(String className, List<SearchIndexableRaw> rawsToIndex,
Set<String> uniqueKeys, Set<String> duplicatedKeys, Set<String> nullKeyClasses) {
if (rawsToIndex == null) {
Log.d(TAG, className + "is not providing SearchIndexableRaw, skipping");
return;
}
for (SearchIndexableRaw raw : rawsToIndex) {
if (TextUtils.isEmpty(raw.key)) {
Log.e(TAG, "Every SearchIndexableRaw must have an key; found null key"
+ " in " + className);
nullKeyClasses.add(className);
continue;
}
if (uniqueKeys.contains(raw.key) && !WHITELISTED_DUPLICATE_KEYS.contains(raw.key)) {
Log.e(TAG, "Every SearchIndexableRaw key must unique; found " + raw.key
+ " in " + className);
duplicatedKeys.add(raw.key);
}
}
}
}