Move xmlParserUtils to core
This class is currently used by both search and slice, in the future
will be used by DashboardFragment to build controller list. So the scope
of this class is beyond search now.
Test: rerun robotests
Change-Id: If43ebca065aac31ad24f95a94bfe5be784109605
diff --git a/src/com/android/settings/search/XmlParserUtils.java b/src/com/android/settings/core/PreferenceXmlParserUtils.java
similarity index 97%
rename from src/com/android/settings/search/XmlParserUtils.java
rename to src/com/android/settings/core/PreferenceXmlParserUtils.java
index 27c5cd3..4d6e840 100644
--- a/src/com/android/settings/search/XmlParserUtils.java
+++ b/src/com/android/settings/core/PreferenceXmlParserUtils.java
@@ -12,10 +12,9 @@
* 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;
+package com.android.settings.core;
import android.annotation.Nullable;
import android.content.Context;
@@ -27,7 +26,7 @@
/**
* Utility class to parse elements of XML preferences
*/
-public class XmlParserUtils {
+public class PreferenceXmlParserUtils {
private static final String ENTRIES_SEPARATOR = "|";
diff --git a/src/com/android/settings/search/BaseSearchIndexProvider.java b/src/com/android/settings/search/BaseSearchIndexProvider.java
index 5723300..f75aa85 100644
--- a/src/com/android/settings/search/BaseSearchIndexProvider.java
+++ b/src/com/android/settings/search/BaseSearchIndexProvider.java
@@ -29,6 +29,7 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import org.xmlpull.v1.XmlPullParser;
@@ -119,7 +120,7 @@
final AttributeSet attrs = Xml.asAttributeSet(parser);
try {
while (parser.next() != XmlPullParser.END_DOCUMENT) {
- final String key = XmlParserUtils.getDataKey(context, attrs);
+ final String key = PreferenceXmlParserUtils.getDataKey(context, attrs);
if (!TextUtils.isEmpty(key)) {
nonIndexableKeys.add(key);
}
diff --git a/src/com/android/settings/search/indexing/IndexDataConverter.java b/src/com/android/settings/search/indexing/IndexDataConverter.java
index c40a466..5d20704 100644
--- a/src/com/android/settings/search/indexing/IndexDataConverter.java
+++ b/src/com/android/settings/search/indexing/IndexDataConverter.java
@@ -29,11 +29,10 @@
import android.util.Log;
import android.util.Xml;
-import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.search.ResultPayload;
import com.android.settings.search.SearchIndexableRaw;
-import com.android.settings.search.XmlParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -161,8 +160,8 @@
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
- final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
- String key = XmlParserUtils.getDataKey(context, attrs);
+ final String screenTitle = PreferenceXmlParserUtils.getDataTitle(context, attrs);
+ String key = PreferenceXmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
@@ -186,9 +185,9 @@
.getPayloadKeyMap(fragmentName, context);
}
- headerTitle = XmlParserUtils.getDataTitle(context, attrs);
- headerSummary = XmlParserUtils.getDataSummary(context, attrs);
- headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
+ headerTitle = PreferenceXmlParserUtils.getDataTitle(context, attrs);
+ headerSummary = PreferenceXmlParserUtils.getDataSummary(context, attrs);
+ headerKeywords = PreferenceXmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
@@ -217,11 +216,11 @@
nodeName = parser.getName();
- title = XmlParserUtils.getDataTitle(context, attrs);
- key = XmlParserUtils.getDataKey(context, attrs);
+ title = PreferenceXmlParserUtils.getDataTitle(context, attrs);
+ key = PreferenceXmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
- keywords = XmlParserUtils.getDataKeywords(context, attrs);
- iconResId = XmlParserUtils.getDataIcon(context, attrs);
+ keywords = PreferenceXmlParserUtils.getDataKeywords(context, attrs);
+ iconResId = PreferenceXmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
@@ -241,17 +240,17 @@
.setUserId(-1 /* default user id */);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
- summary = XmlParserUtils.getDataSummary(context, attrs);
+ summary = PreferenceXmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
- entries = XmlParserUtils.getDataEntries(context, attrs);
+ entries = PreferenceXmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = controllerUriMap.get(key);
- childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
+ childFragment = PreferenceXmlParserUtils.getDataChildFragment(context, attrs);
builder.setSummaryOn(summary)
.setEntries(entries)
@@ -263,11 +262,11 @@
// TODO (b/33577327) We removed summary off here. We should check if we can
// merge this 'else' section with the one above. Put a break point to
// investigate.
- String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
- String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
+ String summaryOn = PreferenceXmlParserUtils.getDataSummaryOn(context, attrs);
+ String summaryOff = PreferenceXmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
- summaryOn = XmlParserUtils.getDataSummary(context, attrs);
+ summaryOn = PreferenceXmlParserUtils.getDataSummary(context, attrs);
}
builder.setSummaryOn(summaryOn);
diff --git a/src/com/android/settings/slices/SliceDataConverter.java b/src/com/android/settings/slices/SliceDataConverter.java
index e5a21e4..a023b16 100644
--- a/src/com/android/settings/slices/SliceDataConverter.java
+++ b/src/com/android/settings/slices/SliceDataConverter.java
@@ -30,7 +30,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.Indexable.SearchIndexProvider;
-import com.android.settings.search.XmlParserUtils;
+import com.android.settings.core.PreferenceXmlParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -151,7 +151,7 @@
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
- final String screenTitle = XmlParserUtils.getDataTitle(mContext, attrs);
+ final String screenTitle = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
// TODO (b/67996923) Investigate if we need headers for Slices, since they never
// correspond to an actual setting.
@@ -168,15 +168,15 @@
// TODO (b/67996923) This will not work if preferences have nested intents:
// <pref ....>
// <intent action="blab"/> </pref>
- controllerClassName = XmlParserUtils.getController(mContext, attrs);
+ controllerClassName = PreferenceXmlParserUtils.getController(mContext, attrs);
if (TextUtils.isEmpty(controllerClassName)) {
continue;
}
- title = XmlParserUtils.getDataTitle(mContext, attrs);
- key = XmlParserUtils.getDataKey(mContext, attrs);
- iconResId = XmlParserUtils.getDataIcon(mContext, attrs);
- summary = XmlParserUtils.getDataSummary(mContext, attrs);
+ title = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
+ key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
+ iconResId = PreferenceXmlParserUtils.getDataIcon(mContext, attrs);
+ summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
xmlSlice = new SliceData.Builder()
.setKey(key)
diff --git a/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java b/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java
index e69b97e..4939cca 100644
--- a/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java
+++ b/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java
@@ -17,7 +17,6 @@
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.search.SearchFeatureProviderImpl;
-import com.android.settings.search.XmlParserUtils;
import com.android.settings.security.SecuritySettings;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -183,7 +182,7 @@
continue;
}
- controllerClassName = XmlParserUtils.getController(mContext, attrs);
+ controllerClassName = PreferenceXmlParserUtils.getController(mContext, attrs);
// If controller is not indexed, then it is not compatible with
if (!TextUtils.isEmpty(controllerClassName)) {
xmlControllers.add(controllerClassName);
diff --git a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
index af7a462..2d1a232 100644
--- a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
+++ b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
@@ -26,6 +26,7 @@
import com.android.settings.R;
import com.android.settings.TestConfig;
+import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -58,7 +59,7 @@
XmlResourceParser parser = getChildByType(R.xml.display_settings,
"com.android.settings.TimeoutListPreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String title = XmlParserUtils.getDataTitle(mContext, attrs);
+ String title = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
String expTitle = mContext.getString(R.string.screen_timeout);
assertThat(title).isEqualTo(expTitle);
}
@@ -67,7 +68,7 @@
public void testDataKeywordsValid_ReturnsPreferenceKeywords() {
XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String keywords = XmlParserUtils.getDataKeywords(mContext, attrs);
+ String keywords = PreferenceXmlParserUtils.getDataKeywords(mContext, attrs);
String expKeywords = mContext.getString(R.string.keywords_display);
assertThat(keywords).isEqualTo(expKeywords);
}
@@ -77,7 +78,7 @@
XmlResourceParser parser = getChildByType(R.xml.display_settings,
"com.android.settings.TimeoutListPreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String key = XmlParserUtils.getDataKey(mContext, attrs);
+ String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
String expKey = "screen_timeout";
assertThat(key).isEqualTo(expKey);
}
@@ -87,7 +88,7 @@
XmlResourceParser parser = getChildByType(R.xml.display_settings,
"com.android.settings.TimeoutListPreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String summary = XmlParserUtils.getDataSummary(mContext, attrs);
+ String summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
String expSummary = mContext.getString(R.string.summary_placeholder);
assertThat(summary).isEqualTo(expSummary);
@@ -99,9 +100,9 @@
XmlResourceParser parser = getChildByType(R.xml.display_settings, "CheckBoxPreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
- assertThat(XmlParserUtils.getDataSummaryOn(mContext, attrs))
+ assertThat(PreferenceXmlParserUtils.getDataSummaryOn(mContext, attrs))
.isEqualTo("summary_on");
- assertThat(XmlParserUtils.getDataSummaryOff(mContext, attrs))
+ assertThat(PreferenceXmlParserUtils.getDataSummaryOff(mContext, attrs))
.isEqualTo("summary_off");
}
@@ -110,7 +111,7 @@
public void testDataEntriesValid_ReturnsPreferenceEntries() {
XmlResourceParser parser = getChildByType(R.xml.display_settings, "ListPreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String entries = XmlParserUtils.getDataEntries(mContext, attrs);
+ String entries = PreferenceXmlParserUtils.getDataEntries(mContext, attrs);
String[] expEntries = mContext.getResources()
.getStringArray(R.array.app_install_location_entries);
for (int i = 0; i < expEntries.length; i++) {
@@ -124,7 +125,7 @@
public void testDataKeyInvalid_ReturnsNull() {
XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String key = XmlParserUtils.getDataKey(mContext, attrs);
+ String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
assertThat(key).isNull();
}
@@ -134,7 +135,7 @@
XmlResourceParser parser = getChildByType(R.xml.about_legal, "Preference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String controller = XmlParserUtils.getController(mContext, attrs);
+ String controller = PreferenceXmlParserUtils.getController(mContext, attrs);
assertThat(controller).isEqualTo("mind_flayer");
}
@@ -142,7 +143,7 @@
public void testDataSummaryInvalid_ReturnsNull() {
XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String summary = XmlParserUtils.getDataSummary(mContext, attrs);
+ String summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
assertThat(summary).isNull();
}
@@ -150,7 +151,7 @@
public void testDataSummaryOffInvalid_ReturnsNull() {
XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String summaryOff = XmlParserUtils.getDataSummaryOff(mContext, attrs);
+ String summaryOff = PreferenceXmlParserUtils.getDataSummaryOff(mContext, attrs);
assertThat(summaryOff).isNull();
}
@@ -158,7 +159,7 @@
public void testDataEntriesInvalid_ReturnsNull() {
XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
final AttributeSet attrs = Xml.asAttributeSet(parser);
- String entries = XmlParserUtils.getDataEntries(mContext, attrs);
+ String entries = PreferenceXmlParserUtils.getDataEntries(mContext, attrs);
assertThat(entries).isNull();
}
diff --git a/tests/robotests/src/com/android/settings/slices/SliceControllerInXmlTest.java b/tests/robotests/src/com/android/settings/slices/SliceControllerInXmlTest.java
index 66ed459..9c079a7 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceControllerInXmlTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceControllerInXmlTest.java
@@ -38,7 +38,7 @@
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.search.SearchFeatureProviderImpl;
-import com.android.settings.search.XmlParserUtils;
+import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -111,7 +111,7 @@
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
- controllerClassName = XmlParserUtils.getController(mContext, attrs);
+ controllerClassName = PreferenceXmlParserUtils.getController(mContext, attrs);
if (!TextUtils.isEmpty(controllerClassName)) {
mXmlDeclaredControllers.add(controllerClassName);
diff --git a/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java b/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
index 4f560022..2b27649 100644
--- a/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
@@ -7,7 +7,7 @@
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Xml;
-import com.android.settings.search.XmlParserUtils;
+import com.android.settings.core.PreferenceXmlParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -35,7 +35,7 @@
try {
while (parser.next() != XmlPullParser.END_DOCUMENT) {
try {
- key = XmlParserUtils.getDataKey(context, attrs);
+ key = PreferenceXmlParserUtils.getDataKey(context, attrs);
if (!TextUtils.isEmpty(key)) {
keys.add(key);
}
diff --git a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
index dd27591..e208709 100644
--- a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
+++ b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
@@ -36,7 +36,6 @@
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.search.SearchIndexableResources;
-import com.android.settings.search.XmlParserUtils;
import org.junit.Before;
import org.junit.Test;
@@ -203,7 +202,7 @@
continue;
}
final AttributeSet attrs = Xml.asAttributeSet(parser);
- final String key = XmlParserUtils.getDataKey(mContext, attrs);
+ final String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
if (TextUtils.isEmpty(key)) {
Log.e(TAG, "Every preference must have an key; found null key"
+ " in " + className