Restrict toggle/slider slice when the preference restricted

Bug: 289980550
Test: robotest & manual
Change-Id: Id87fbf12a2722344dd07886e810e7c61a9f401aa
This commit is contained in:
Edgar Wang
2023-07-05 17:10:34 +08:00
parent 1ac510e4b1
commit ab75ea8099
9 changed files with 125 additions and 15 deletions

View File

@@ -74,7 +74,8 @@ public class PreferenceXmlParserUtils {
MetadataFlag.FLAG_NEED_SEARCHABLE,
MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE,
MetadataFlag.FLAG_FOR_WORK,
MetadataFlag.FLAG_NEED_HIGHLIGHTABLE_MENU_KEY})
MetadataFlag.FLAG_NEED_HIGHLIGHTABLE_MENU_KEY,
MetadataFlag.FLAG_NEED_USER_RESTRICTION})
@Retention(RetentionPolicy.SOURCE)
public @interface MetadataFlag {
@@ -91,6 +92,7 @@ public class PreferenceXmlParserUtils {
int FLAG_UNAVAILABLE_SLICE_SUBTITLE = 1 << 11;
int FLAG_FOR_WORK = 1 << 12;
int FLAG_NEED_HIGHLIGHTABLE_MENU_KEY = 1 << 13;
int FLAG_NEED_USER_RESTRICTION = 1 << 14;
}
public static final String METADATA_PREF_TYPE = "type";
@@ -105,6 +107,7 @@ public class PreferenceXmlParserUtils {
public static final String METADATA_UNAVAILABLE_SLICE_SUBTITLE = "unavailable_slice_subtitle";
public static final String METADATA_FOR_WORK = "for_work";
public static final String METADATA_HIGHLIGHTABLE_MENU_KEY = "highlightable_menu_key";
public static final String METADATA_USER_RESTRICTION = "userRestriction";
private static final String ENTRIES_SEPARATOR = "|";
@@ -257,9 +260,16 @@ public class PreferenceXmlParserUtils {
preferenceMetadata.putString(METADATA_HIGHLIGHTABLE_MENU_KEY,
getHighlightableMenuKey(preferenceAttributes));
}
if (hasFlag(flags, MetadataFlag.FLAG_NEED_USER_RESTRICTION)) {
preferenceMetadata.putString(METADATA_USER_RESTRICTION,
getUserRestriction(context, attrs));
}
metadata.add(preferenceMetadata);
preferenceAttributes.recycle();
if (preferenceScreenAttributes != null) {
preferenceScreenAttributes.recycle();
}
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
parser.close();
@@ -351,4 +361,13 @@ public class PreferenceXmlParserUtils {
return styledAttributes.getBoolean(
R.styleable.Preference_forWork, false);
}
private static String getUserRestriction(Context context, AttributeSet attrs) {
TypedArray preferenceAttributes = context.obtainStyledAttributes(attrs,
R.styleable.RestrictedPreference);
String userRestriction = preferenceAttributes.getString(
R.styleable.RestrictedPreference_userRestriction);
preferenceAttributes.recycle();
return userRestriction;
}
}