Remove duplicates between battery and display settings

Change preference keys of duplicate settings between
display and battery to avoid duplication in search.

Bug: 33701673
Test: make RunSettingsRoboTests
Change-Id: Iaad52f16ce33c478c64bcec656cc8edbe0c97283
Merged-In: I56c82e9e7f163d345065ca478849de9b14c173fe
This commit is contained in:
Matthew Fritze
2017-04-11 13:22:40 -07:00
parent eb62407114
commit 3266e3d712
14 changed files with 279 additions and 22 deletions

View File

@@ -0,0 +1,57 @@
package com.android.settings.testutils;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Xml;
import com.android.settings.search2.XmlParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.util.ArrayList;
import java.util.List;
/**
* Util class for parsing XML
*/
public class XmlTestUtils {
/**
* Parses a preference screen's xml, collects and returns all keys used by preferences
* on the screen.
*
* @param context of the preference screen.
* @param xmlId of the Preference Xml to be parsed.
* @return List of all keys in the preference Xml
*/
public static List<String> getKeysFromPreferenceXml(Context context, int xmlId) {
final XmlResourceParser parser = context.getResources().getXml(xmlId);
final AttributeSet attrs = Xml.asAttributeSet(parser);
final List<String> keys = new ArrayList<>();
String key;
try {
while (parser.next() != XmlPullParser.END_DOCUMENT) {
try {
key = XmlParserUtils.getDataKey(context, attrs);
if (!TextUtils.isEmpty(key)) {
keys.add(key);
}
} catch (NullPointerException e) {
continue;
} catch (Resources.NotFoundException e) {
continue;
}
}
} catch (java.io.IOException e) {
return null;
} catch (XmlPullParserException e) {
return null;
}
return keys;
}
}