Snap for 4635315 from e8acc0c4bd to pi-release
Change-Id: Icabb4830eb8e2395865d8061eadf081c4c139054
This commit is contained in:
@@ -523,7 +523,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
if (startingFragment != null) {
|
if (startingFragment != null) {
|
||||||
Intent modIntent = new Intent(superIntent);
|
Intent modIntent = new Intent(superIntent);
|
||||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
|
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
|
||||||
Bundle args = superIntent.getExtras();
|
Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
args = new Bundle(args);
|
args = new Bundle(args);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.os.Bundle;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
@@ -52,7 +53,8 @@ public class PreferenceControllerListHelper {
|
|||||||
final List<BasePreferenceController> controllers = new ArrayList<>();
|
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||||
List<Bundle> preferenceMetadata;
|
List<Bundle> preferenceMetadata;
|
||||||
try {
|
try {
|
||||||
preferenceMetadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId);
|
preferenceMetadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId,
|
||||||
|
MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER);
|
||||||
} catch (IOException | XmlPullParserException e) {
|
} catch (IOException | XmlPullParserException e) {
|
||||||
Log.e(TAG, "Failed to parse preference xml for getting controllers");
|
Log.e(TAG, "Failed to parse preference xml for getting controllers");
|
||||||
return controllers;
|
return controllers;
|
||||||
|
|||||||
@@ -18,10 +18,14 @@ package com.android.settings.core;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.XmlRes;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.IntDef;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@@ -33,6 +37,8 @@ import org.xmlpull.v1.XmlPullParser;
|
|||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,12 +49,41 @@ import java.util.List;
|
|||||||
public class PreferenceXmlParserUtils {
|
public class PreferenceXmlParserUtils {
|
||||||
|
|
||||||
private static final String TAG = "PreferenceXmlParserUtil";
|
private static final String TAG = "PreferenceXmlParserUtil";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String PREF_SCREEN_TAG = "PreferenceScreen";
|
||||||
private static final List<String> SUPPORTED_PREF_TYPES = Arrays.asList(
|
private static final List<String> SUPPORTED_PREF_TYPES = Arrays.asList(
|
||||||
"Preference", "PreferenceCategory", "PreferenceScreen");
|
"Preference", "PreferenceCategory", "PreferenceScreen");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag definition to indicate which metadata should be extracted when
|
||||||
|
* {@link #extractMetadata(Context, int, int)} is called. The flags can be combined by using |
|
||||||
|
* (binary or).
|
||||||
|
*/
|
||||||
|
@IntDef(flag = true, value = {
|
||||||
|
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN,
|
||||||
|
MetadataFlag.FLAG_NEED_KEY,
|
||||||
|
MetadataFlag.FLAG_NEED_PREF_TYPE,
|
||||||
|
MetadataFlag.FLAG_NEED_PREF_CONTROLLER,
|
||||||
|
MetadataFlag.FLAG_NEED_PREF_TITLE,
|
||||||
|
MetadataFlag.FLAG_NEED_PREF_SUMMARY,
|
||||||
|
MetadataFlag.FLAG_NEED_PREF_ICON})
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
public @interface MetadataFlag {
|
||||||
|
int FLAG_INCLUDE_PREF_SCREEN = 1;
|
||||||
|
int FLAG_NEED_KEY = 1 << 1;
|
||||||
|
int FLAG_NEED_PREF_TYPE = 1 << 2;
|
||||||
|
int FLAG_NEED_PREF_CONTROLLER = 1 << 3;
|
||||||
|
int FLAG_NEED_PREF_TITLE = 1 << 4;
|
||||||
|
int FLAG_NEED_PREF_SUMMARY = 1 << 5;
|
||||||
|
int FLAG_NEED_PREF_ICON = 1 << 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String METADATA_PREF_TYPE = "type";
|
||||||
public static final String METADATA_KEY = "key";
|
public static final String METADATA_KEY = "key";
|
||||||
public static final String METADATA_CONTROLLER = "controller";
|
public static final String METADATA_CONTROLLER = "controller";
|
||||||
|
public static final String METADATA_TITLE = "title";
|
||||||
|
public static final String METADATA_SUMMARY = "summary";
|
||||||
|
public static final String METADATA_ICON = "icon";
|
||||||
|
|
||||||
private static final String ENTRIES_SEPARATOR = "|";
|
private static final String ENTRIES_SEPARATOR = "|";
|
||||||
|
|
||||||
@@ -107,11 +142,11 @@ public class PreferenceXmlParserUtils {
|
|||||||
/**
|
/**
|
||||||
* Extracts metadata from preference xml and put them into a {@link Bundle}.
|
* Extracts metadata from preference xml and put them into a {@link Bundle}.
|
||||||
*
|
*
|
||||||
* TODO(zhfan): Similar logic exists in {@link SliceBuilderUtils} and
|
* @param xmlResId xml res id of a preference screen
|
||||||
* {@link UniquePreferenceTest}. Need refactoring to consolidate them all.
|
* @param flags Should be one or more of {@link MetadataFlag}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public static List<Bundle> extractMetadata(Context context, int xmlResId)
|
public static List<Bundle> extractMetadata(Context context, @XmlRes int xmlResId, int flags)
|
||||||
throws IOException, XmlPullParserException {
|
throws IOException, XmlPullParserException {
|
||||||
final List<Bundle> metadata = new ArrayList<>();
|
final List<Bundle> metadata = new ArrayList<>();
|
||||||
if (xmlResId <= 0) {
|
if (xmlResId <= 0) {
|
||||||
@@ -132,16 +167,37 @@ public class PreferenceXmlParserUtils {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String nodeName = parser.getName();
|
final String nodeName = parser.getName();
|
||||||
|
if (!hasFlag(flags, MetadataFlag.FLAG_INCLUDE_PREF_SCREEN)
|
||||||
|
&& TextUtils.equals(PREF_SCREEN_TAG, nodeName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!SUPPORTED_PREF_TYPES.contains(nodeName) && !nodeName.endsWith("Preference")) {
|
if (!SUPPORTED_PREF_TYPES.contains(nodeName) && !nodeName.endsWith("Preference")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Bundle preferenceMetadata = new Bundle();
|
final Bundle preferenceMetadata = new Bundle();
|
||||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||||
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_TYPE)) {
|
||||||
|
preferenceMetadata.putString(METADATA_PREF_TYPE, nodeName);
|
||||||
|
}
|
||||||
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_KEY)) {
|
||||||
preferenceMetadata.putString(METADATA_KEY, getDataKey(context, attrs));
|
preferenceMetadata.putString(METADATA_KEY, getDataKey(context, attrs));
|
||||||
|
}
|
||||||
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_CONTROLLER)) {
|
||||||
preferenceMetadata.putString(METADATA_CONTROLLER, getController(context, attrs));
|
preferenceMetadata.putString(METADATA_CONTROLLER, getController(context, attrs));
|
||||||
|
}
|
||||||
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_TITLE)) {
|
||||||
|
preferenceMetadata.putString(METADATA_TITLE, getDataTitle(context, attrs));
|
||||||
|
}
|
||||||
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_SUMMARY)) {
|
||||||
|
preferenceMetadata.putString(METADATA_SUMMARY, getDataSummary(context, attrs));
|
||||||
|
}
|
||||||
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_ICON)) {
|
||||||
|
preferenceMetadata.putInt(METADATA_ICON, getDataIcon(context, attrs));
|
||||||
|
}
|
||||||
metadata.add(preferenceMetadata);
|
metadata.add(preferenceMetadata);
|
||||||
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||||
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
|
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
|
||||||
|
parser.close();
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +217,10 @@ public class PreferenceXmlParserUtils {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean hasFlag(int flags, @MetadataFlag int flag) {
|
||||||
|
return (flags & flag) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static String getDataEntries(Context context, AttributeSet set, int[] attrs,
|
private static String getDataEntries(Context context, AttributeSet set, int[] attrs,
|
||||||
int resId) {
|
int resId) {
|
||||||
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
|
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
|
||||||
|
|||||||
@@ -16,21 +16,28 @@
|
|||||||
|
|
||||||
package com.android.settings.slices;
|
package com.android.settings.slices;
|
||||||
|
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.support.annotation.DrawableRes;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceXmlParserUtils;
|
||||||
|
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.DatabaseIndexingUtils;
|
import com.android.settings.search.DatabaseIndexingUtils;
|
||||||
import com.android.settings.search.Indexable.SearchIndexProvider;
|
import com.android.settings.search.Indexable.SearchIndexProvider;
|
||||||
import com.android.settings.core.PreferenceXmlParserUtils;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
@@ -144,35 +151,32 @@ class SliceDataConverter {
|
|||||||
+ nodeName + " at " + parser.getPositionDescription());
|
+ nodeName + " at " + parser.getPositionDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
final int outerDepth = parser.getDepth();
|
|
||||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||||
final String screenTitle = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
|
final String screenTitle = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
|
||||||
|
|
||||||
// TODO (b/67996923) Investigate if we need headers for Slices, since they never
|
// TODO (b/67996923) Investigate if we need headers for Slices, since they never
|
||||||
// correspond to an actual setting.
|
// correspond to an actual setting.
|
||||||
|
|
||||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
|
xmlResId,
|
||||||
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
|
MetadataFlag.FLAG_NEED_KEY
|
||||||
continue;
|
| MetadataFlag.FLAG_NEED_PREF_CONTROLLER
|
||||||
}
|
| MetadataFlag.FLAG_NEED_PREF_TYPE
|
||||||
|
| MetadataFlag.FLAG_NEED_PREF_TITLE
|
||||||
|
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||||
|
| MetadataFlag.FLAG_NEED_PREF_SUMMARY);
|
||||||
|
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
|
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
|
||||||
// Note that without a controller, dynamic summaries are impossible.
|
// Note that without a controller, dynamic summaries are impossible.
|
||||||
// TODO (b/67996923) This will not work if preferences have nested intents:
|
final String controllerClassName = bundle.getString(METADATA_CONTROLLER);
|
||||||
// <pref ....>
|
|
||||||
// <intent action="blab"/> </pref>
|
|
||||||
final String controllerClassName = PreferenceXmlParserUtils.getController(mContext,
|
|
||||||
attrs);
|
|
||||||
if (TextUtils.isEmpty(controllerClassName)) {
|
if (TextUtils.isEmpty(controllerClassName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
final String key = bundle.getString(METADATA_KEY);
|
||||||
final String title = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
|
final String title = bundle.getString(METADATA_TITLE);
|
||||||
final String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
|
final String summary = bundle.getString(METADATA_SUMMARY);
|
||||||
@DrawableRes final int iconResId = PreferenceXmlParserUtils.getDataIcon(mContext,
|
final int iconResId = bundle.getInt(METADATA_ICON);
|
||||||
attrs);
|
|
||||||
final String summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
|
|
||||||
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
|
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
|
||||||
key);
|
key);
|
||||||
|
|
||||||
@@ -194,7 +198,7 @@ class SliceDataConverter {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, "IO Error parsing PreferenceScreen: ", e);
|
Log.w(TAG, "IO Error parsing PreferenceScreen: ", e);
|
||||||
} catch (Resources.NotFoundException e) {
|
} catch (Resources.NotFoundException e) {
|
||||||
Log.w(TAG, "Resoucre not found error parsing PreferenceScreen: ", e);
|
Log.w(TAG, "Resource not found error parsing PreferenceScreen: ", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (parser != null) parser.close();
|
if (parser != null) parser.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
|
||||||
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
|
mEmptyView = getView().findViewById(android.R.id.empty);
|
||||||
setEmptyView(mEmptyView);
|
setEmptyView(mEmptyView);
|
||||||
String emptyViewText = activity.getString(R.string.wifi_calling_off_explanation)
|
String emptyViewText = activity.getString(R.string.wifi_calling_off_explanation)
|
||||||
+ activity.getString(R.string.wifi_calling_off_explanation_2);
|
+ activity.getString(R.string.wifi_calling_off_explanation_2);
|
||||||
@@ -216,6 +216,12 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
return MetricsEvent.WIFI_CALLING_FOR_SUB;
|
return MetricsEvent.WIFI_CALLING_FOR_SUB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
// Return 0 to suppress help icon. The help will be populated by parent page.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -12,21 +12,21 @@
|
|||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.core;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceXmlParserUtils;
|
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -169,8 +169,9 @@ public class PreferenceXmlParserUtilTest {
|
|||||||
@Config(qualifiers = "mcc999")
|
@Config(qualifiers = "mcc999")
|
||||||
public void extractMetadata_shouldContainKeyAndControllerName()
|
public void extractMetadata_shouldContainKeyAndControllerName()
|
||||||
throws IOException, XmlPullParserException {
|
throws IOException, XmlPullParserException {
|
||||||
final List<Bundle> metadata =
|
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
PreferenceXmlParserUtils.extractMetadata(mContext, R.xml.location_settings);
|
R.xml.location_settings,
|
||||||
|
MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER);
|
||||||
|
|
||||||
assertThat(metadata).isNotEmpty();
|
assertThat(metadata).isNotEmpty();
|
||||||
for (Bundle bundle : metadata) {
|
for (Bundle bundle : metadata) {
|
||||||
@@ -179,6 +180,70 @@ public class PreferenceXmlParserUtilTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void extractMetadata_requestTitle_shouldContainTitle()
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
|
R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_TITLE);
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
|
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_TITLE)).isNotNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void extractMetadata_requestSummary_shouldContainSummary()
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
|
R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_SUMMARY);
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
|
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_SUMMARY)).isNotNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void extractMetadata_requestIcon_shouldContainIcon()
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
|
R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_ICON);
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
|
assertThat(bundle.getInt(PreferenceXmlParserUtils.METADATA_ICON)).isNotEqualTo(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void extractMetadata_requestPrefType_shouldContainPrefType()
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
|
R.xml.location_settings, MetadataFlag.FLAG_NEED_PREF_TYPE);
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
|
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_PREF_TYPE)).isNotNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void extractMetadata_requestIncludeScreen_shouldContainScreen()
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
|
R.xml.location_settings,
|
||||||
|
MetadataFlag.FLAG_NEED_PREF_TYPE | MetadataFlag.FLAG_INCLUDE_PREF_SCREEN);
|
||||||
|
|
||||||
|
boolean hasPreferenceScreen = false;
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
|
if (TextUtils.equals(bundle.getString(PreferenceXmlParserUtils.METADATA_PREF_TYPE),
|
||||||
|
PreferenceXmlParserUtils.PREF_SCREEN_TAG)) {
|
||||||
|
hasPreferenceScreen = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(hasPreferenceScreen).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param resId the ID for the XML preference
|
* @param resId the ID for the XML preference
|
||||||
* @return an XML resource parser that points to the start tag
|
* @return an XML resource parser that points to the start tag
|
||||||
@@ -73,13 +73,13 @@ public class TimeZoneDataTest {
|
|||||||
CountryTimeZones US = mock(CountryTimeZones.class);
|
CountryTimeZones US = mock(CountryTimeZones.class);
|
||||||
when(US.getCountryIso()).thenReturn("us");
|
when(US.getCountryIso()).thenReturn("us");
|
||||||
when(US.getTimeZoneMappings()).thenReturn(Arrays.asList(
|
when(US.getTimeZoneMappings()).thenReturn(Arrays.asList(
|
||||||
TimeZoneMapping.createForTests("Unknown/Secret_City", true),
|
new CountryTimeZones.TimeZoneMapping("Unknown/Secret_City", true),
|
||||||
TimeZoneMapping.createForTests("Unknown/Secret_City2", false)
|
new CountryTimeZones.TimeZoneMapping("Unknown/Secret_City2", false)
|
||||||
));
|
));
|
||||||
CountryTimeZones GB = mock(CountryTimeZones.class);
|
CountryTimeZones GB = mock(CountryTimeZones.class);
|
||||||
when(GB.getCountryIso()).thenReturn("gb");
|
when(GB.getCountryIso()).thenReturn("gb");
|
||||||
when(GB.getTimeZoneMappings()).thenReturn(Collections.singletonList(
|
when(GB.getTimeZoneMappings()).thenReturn(Collections.singletonList(
|
||||||
TimeZoneMapping.createForTests("Unknown/Secret_City", true)
|
new TimeZoneMapping("Unknown/Secret_City", true)
|
||||||
));
|
));
|
||||||
when(mCountryZonesFinder.lookupCountryTimeZonesForZoneId("Unknown/Secret_City"))
|
when(mCountryZonesFinder.lookupCountryTimeZonesForZoneId("Unknown/Secret_City"))
|
||||||
.thenReturn(Arrays.asList(US, GB));
|
.thenReturn(Arrays.asList(US, GB));
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.wifi.calling;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
public class WifiCallingSettingsForSubTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getHelpResource_shouldReturn0() {
|
||||||
|
assertThat(new WifiCallingSettingsForSub().getHelpResource())
|
||||||
|
.isEqualTo(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
tests/robotests/src/libcore/util/CountryTimeZones.java
Normal file
45
tests/robotests/src/libcore/util/CountryTimeZones.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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 libcore.util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty implementation of CountryTimeZones for Robolectric test.
|
||||||
|
*/
|
||||||
|
public class CountryTimeZones {
|
||||||
|
public CountryTimeZones() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class TimeZoneMapping {
|
||||||
|
public final String timeZoneId;
|
||||||
|
public final boolean showInPicker;
|
||||||
|
|
||||||
|
public TimeZoneMapping(String timeZoneId, boolean showInPicker) {
|
||||||
|
this.timeZoneId = timeZoneId;
|
||||||
|
this.showInPicker = showInPicker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TimeZoneMapping> getTimeZoneMappings() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCountryIso() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/robotests/src/libcore/util/CountryZonesFinder.java
Normal file
38
tests/robotests/src/libcore/util/CountryZonesFinder.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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 libcore.util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty implementation of CountryZonesFinder for Robolectric test.
|
||||||
|
*/
|
||||||
|
public class CountryZonesFinder {
|
||||||
|
public CountryZonesFinder(List<CountryTimeZones> countryTimeZonesList) {}
|
||||||
|
|
||||||
|
public List<String> lookupAllCountryIsoCodes() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CountryTimeZones> lookupCountryTimeZonesForZoneId(String zoneId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CountryTimeZones lookupCountryTimeZones(String countryIso) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,17 +20,16 @@ import static junit.framework.Assert.fail;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.os.Bundle;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.InstrumentationRegistry;
|
||||||
import android.support.test.filters.MediumTest;
|
import android.support.test.filters.MediumTest;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.DatabaseIndexingUtils;
|
import com.android.settings.search.DatabaseIndexingUtils;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
@@ -40,7 +39,6 @@ import com.android.settings.search.SearchIndexableResources;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -56,8 +54,7 @@ public class UniquePreferenceTest {
|
|||||||
private static final String TAG = "UniquePreferenceTest";
|
private static final String TAG = "UniquePreferenceTest";
|
||||||
private static final List<String> IGNORE_PREF_TYPES = Arrays.asList(
|
private static final List<String> IGNORE_PREF_TYPES = Arrays.asList(
|
||||||
"com.android.settingslib.widget.FooterPreference");
|
"com.android.settingslib.widget.FooterPreference");
|
||||||
private static final List<String> SUPPORTED_PREF_TYPES = Arrays.asList(
|
|
||||||
"Preference", "PreferenceCategory", "PreferenceScreen");
|
|
||||||
private static final List<String> WHITELISTED_DUPLICATE_KEYS = Arrays.asList(
|
private static final List<String> WHITELISTED_DUPLICATE_KEYS = Arrays.asList(
|
||||||
"owner_info_settings", // Lock screen message in security - multiple xml files
|
"owner_info_settings", // Lock screen message in security - multiple xml files
|
||||||
// contain this because security page is constructed by
|
// contain this because security page is constructed by
|
||||||
@@ -177,48 +174,32 @@ public class UniquePreferenceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (SearchIndexableResource sir : resourcesToIndex) {
|
for (SearchIndexableResource sir : resourcesToIndex) {
|
||||||
if (sir.xmlResId <= 0) {
|
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
Log.d(TAG, className + " doesn't have a valid xml to index.");
|
sir.xmlResId,
|
||||||
continue;
|
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN
|
||||||
}
|
| MetadataFlag.FLAG_NEED_KEY
|
||||||
final XmlResourceParser parser = mContext.getResources().getXml(sir.xmlResId);
|
| MetadataFlag.FLAG_NEED_PREF_TYPE);
|
||||||
|
|
||||||
int type;
|
for (Bundle bundle : metadata) {
|
||||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
final String type = bundle.getString(PreferenceXmlParserUtils.METADATA_PREF_TYPE);
|
||||||
&& type != XmlPullParser.START_TAG) {
|
if (IGNORE_PREF_TYPES.contains(type)) {
|
||||||
// Parse next until start tag is found
|
|
||||||
}
|
|
||||||
final int outerDepth = parser.getDepth();
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (type != XmlPullParser.START_TAG) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String nodeName = parser.getName();
|
final String key = bundle.getString(PreferenceXmlParserUtils.METADATA_KEY);
|
||||||
if (IGNORE_PREF_TYPES.contains(nodeName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!SUPPORTED_PREF_TYPES.contains(nodeName) && !nodeName.endsWith("Preference")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
|
||||||
final String key = PreferenceXmlParserUtils.getDataKey(mContext, attrs);
|
|
||||||
if (TextUtils.isEmpty(key)) {
|
if (TextUtils.isEmpty(key)) {
|
||||||
Log.e(TAG, "Every preference must have an key; found null key"
|
Log.e(TAG, "Every preference must have an key; found null key"
|
||||||
+ " in " + className
|
+ " in " + className);
|
||||||
+ " at " + parser.getPositionDescription());
|
|
||||||
nullKeyClasses.add(className);
|
nullKeyClasses.add(className);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (uniqueKeys.contains(key) && !WHITELISTED_DUPLICATE_KEYS.contains(key)) {
|
if (uniqueKeys.contains(key) && !WHITELISTED_DUPLICATE_KEYS.contains(key)) {
|
||||||
Log.e(TAG, "Every preference key must unique; found " + nodeName
|
Log.e(TAG, "Every preference key must unique; found "
|
||||||
+ " in " + className
|
+ " in " + className
|
||||||
+ " at " + parser.getPositionDescription());
|
+ " / " + key);
|
||||||
duplicatedKeys.add(key);
|
duplicatedKeys.add(key);
|
||||||
}
|
}
|
||||||
uniqueKeys.add(key);
|
uniqueKeys.add(key);
|
||||||
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
}
|
||||||
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user