diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index d74e8c2cb84..5219caaa447 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -29,32 +29,37 @@
android:summaryOn="@string/date_time_auto_summaryOn"
android:summaryOff="@string/date_time_auto_summaryOff"
settings:useAdditionalSummary="true"
- settings:restrictedSwitchSummary="@string/enabled_by_admin" />
+ settings:restrictedSwitchSummary="@string/enabled_by_admin"
+ settings:userRestriction="no_config_date_time" />
-
+ android:summary="@string/summary_placeholder"
+ settings:userRestriction="no_config_date_time" />
-
+ android:summary="@string/summary_placeholder"
+ settings:userRestriction="no_config_date_time" />
-
+ android:summaryOff="@string/zone_auto_summaryOff"
+ settings:userRestriction="no_config_date_time" />
-
+ android:summary="GMT-8:00"
+ settings:userRestriction="no_config_date_time" />
USER_RESTRICTIONS = Sets.newHashSet(
+ UserManager.DISALLOW_CONFIG_DATE_TIME,
+ UserManager.DISALLOW_CONFIG_CREDENTIALS,
+ UserManager.DISALLOW_NETWORK_RESET,
+ UserManager.DISALLOW_FACTORY_RESET,
+ UserManager.DISALLOW_CONFIG_TETHERING,
+ UserManager.DISALLOW_CONFIG_VPN,
+ UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS
+ );
+
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getTargetContext();
+ }
+
+ /**
+ * Verity that userRestriction attributes are entered and parsed successfully.
+ */
+ @Test
+ public void userRestrictionAttributeShouldBeValid()
+ throws IOException, XmlPullParserException, Resources.NotFoundException {
+ for (Class> clazz : SearchIndexableResources.providerValues()) {
+ verifyUserRestriction(clazz);
+ }
+ }
+
+ private void verifyUserRestriction(Class> clazz)
+ throws IOException, XmlPullParserException, Resources.NotFoundException {
+ if (clazz == null) {
+ return;
+ }
+ final String className = clazz.getName();
+ final Indexable.SearchIndexProvider provider =
+ DatabaseIndexingUtils.getSearchIndexProvider(clazz);
+ final List resourcesToIndex =
+ provider.getXmlResourcesToIndex(mContext, true);
+
+ if (resourcesToIndex == null) {
+ Log.d(TAG, className + "is not providing SearchIndexableResource, skipping");
+ return;
+ }
+
+ for (SearchIndexableResource sir : resourcesToIndex) {
+ if (sir.xmlResId <= 0) {
+ Log.d(TAG, className + " doesn't have a valid xml to index.");
+ continue;
+ }
+ final XmlResourceParser parser = mContext.getResources().getXml(sir.xmlResId);
+
+ int type;
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && type != XmlPullParser.START_TAG) {
+ // Parse next until start tag is found
+ }
+ final int outerDepth = parser.getDepth();
+
+ do {
+ if (type != XmlPullParser.START_TAG) {
+ continue;
+ }
+ final String nodeName = parser.getName();
+ if (!nodeName.endsWith("Preference")) {
+ continue;
+ }
+ final AttributeSet attrs = Xml.asAttributeSet(parser);
+ final String userRestriction = getDataUserRestrictions(mContext, attrs);
+ if (userRestriction != null) {
+ if(!isValidRestriction(userRestriction)) {
+ fail("userRestriction in " + className + " not valid.");
+ }
+ }
+ } while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
+ }
+ }
+
+ boolean isValidRestriction(String userRestriction) {
+ return USER_RESTRICTIONS.contains(userRestriction);
+ }
+
+ private String getDataUserRestrictions(Context context, AttributeSet attrs) {
+ return getData(context, attrs,
+ com.android.settingslib.R.styleable.RestrictedPreference,
+ com.android.settingslib.R.styleable.RestrictedPreference_userRestriction);
+ }
+
+ private String getData(Context context, AttributeSet set, int[] attrs, int resId) {
+ final TypedArray ta = context.obtainStyledAttributes(set, attrs);
+ String data = ta.getString(resId);
+ ta.recycle();
+ return data;
+ }
+}