Restrict toggle/slider slice when the preference restricted
Bug: 289980550 Test: robotest & manual Change-Id: Id87fbf12a2722344dd07886e810e7c61a9f401aa
This commit is contained in:
@@ -28,6 +28,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
@@ -50,6 +51,8 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SliderPreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -86,6 +89,16 @@ public class SliceBuilderUtils {
|
||||
return buildUnavailableSlice(context, sliceData);
|
||||
}
|
||||
|
||||
String userRestriction = sliceData.getUserRestriction();
|
||||
if (!TextUtils.isEmpty(userRestriction)) {
|
||||
RestrictedLockUtils.EnforcedAdmin admin =
|
||||
RestrictedLockUtilsInternal.checkIfRestrictionEnforced(context,
|
||||
userRestriction, UserHandle.myUserId());
|
||||
if (admin != null) {
|
||||
return buildIntentSlice(context, sliceData, controller);
|
||||
}
|
||||
}
|
||||
|
||||
switch (sliceData.getSliceType()) {
|
||||
case SliceData.SliceType.INTENT:
|
||||
return buildIntentSlice(context, sliceData, controller);
|
||||
|
@@ -73,6 +73,8 @@ public class SliceData {
|
||||
|
||||
private final int mHighlightMenuRes;
|
||||
|
||||
private final String mUserRestriction;
|
||||
|
||||
@SliceType
|
||||
private final int mSliceType;
|
||||
|
||||
@@ -132,6 +134,10 @@ public class SliceData {
|
||||
return mIsPublicSlice;
|
||||
}
|
||||
|
||||
public String getUserRestriction() {
|
||||
return mUserRestriction;
|
||||
}
|
||||
|
||||
private SliceData(Builder builder) {
|
||||
mKey = builder.mKey;
|
||||
mTitle = builder.mTitle;
|
||||
@@ -146,6 +152,7 @@ public class SliceData {
|
||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||
mIsPublicSlice = builder.mIsPublicSlice;
|
||||
mHighlightMenuRes = builder.mHighlightMenuRes;
|
||||
mUserRestriction = builder.mUserRestriction;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,6 +196,8 @@ public class SliceData {
|
||||
|
||||
private boolean mIsPublicSlice;
|
||||
|
||||
private String mUserRestriction;
|
||||
|
||||
public Builder setKey(String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
@@ -255,6 +264,11 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUserRestriction(String userRestriction) {
|
||||
mUserRestriction = userRestriction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SliceData build() {
|
||||
if (TextUtils.isEmpty(mKey)) {
|
||||
throw new InvalidSliceDataException("Key cannot be empty");
|
||||
|
@@ -22,6 +22,7 @@ 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 static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAILABLE_SLICE_SUBTITLE;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_USER_RESTRICTION;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -189,7 +190,8 @@ class SliceDataConverter {
|
||||
| MetadataFlag.FLAG_NEED_PREF_TITLE
|
||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE
|
||||
| MetadataFlag.FLAG_NEED_USER_RESTRICTION);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
|
||||
@@ -218,6 +220,7 @@ class SliceDataConverter {
|
||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
final boolean isPublicSlice = controller.isPublicSlice();
|
||||
final int highlightMenuRes = controller.getSliceHighlightMenuRes();
|
||||
final String userRestriction = bundle.getString(METADATA_USER_RESTRICTION);
|
||||
|
||||
final SliceData xmlSlice = new SliceData.Builder()
|
||||
.setKey(key)
|
||||
@@ -232,6 +235,7 @@ class SliceDataConverter {
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.setIsPublicSlice(isPublicSlice)
|
||||
.setHighlightMenuRes(highlightMenuRes)
|
||||
.setUserRestriction(userRestriction)
|
||||
.build();
|
||||
|
||||
xmlSliceData.add(xmlSlice);
|
||||
|
@@ -51,6 +51,7 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
IndexColumns.HIGHLIGHT_MENU_RESOURCE,
|
||||
IndexColumns.USER_RESTRICTION,
|
||||
};
|
||||
|
||||
private final Context mContext;
|
||||
@@ -166,6 +167,8 @@ public class SlicesDatabaseAccessor {
|
||||
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE));
|
||||
final int highlightMenuRes = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.HIGHLIGHT_MENU_RESOURCE));
|
||||
final String userRestriction = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.USER_RESTRICTION));
|
||||
|
||||
if (isIntentOnly) {
|
||||
sliceType = SliceData.SliceType.INTENT;
|
||||
@@ -184,6 +187,7 @@ public class SlicesDatabaseAccessor {
|
||||
.setSliceType(sliceType)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.setHighlightMenuRes(highlightMenuRes)
|
||||
.setUserRestriction(userRestriction)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "slices_index.db";
|
||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
||||
|
||||
private static final int DATABASE_VERSION = 9;
|
||||
private static final int DATABASE_VERSION = 10;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -108,6 +108,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
* Resource ID for the menu entry of the setting.
|
||||
*/
|
||||
String HIGHLIGHT_MENU_RESOURCE = "highlight_menu";
|
||||
|
||||
/**
|
||||
* The name of user restriction for the setting.
|
||||
*/
|
||||
String USER_RESTRICTION = "user_restriction";
|
||||
}
|
||||
|
||||
private static final String CREATE_SLICES_TABLE =
|
||||
@@ -138,6 +143,8 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
+ IndexColumns.PUBLIC_SLICE
|
||||
+ ", "
|
||||
+ IndexColumns.HIGHLIGHT_MENU_RESOURCE
|
||||
+ ", "
|
||||
+ IndexColumns.USER_RESTRICTION
|
||||
+ " INTEGER DEFAULT 0 "
|
||||
+ ");";
|
||||
|
||||
|
@@ -117,6 +117,7 @@ class SlicesIndexer implements Runnable {
|
||||
dataRow.getUnavailableSliceSubtitle());
|
||||
values.put(IndexColumns.PUBLIC_SLICE, dataRow.isPublicSlice());
|
||||
values.put(IndexColumns.HIGHLIGHT_MENU_RESOURCE, dataRow.getHighlightMenuRes());
|
||||
values.put(IndexColumns.USER_RESTRICTION, dataRow.getUserRestriction());
|
||||
|
||||
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
|
||||
values);
|
||||
|
Reference in New Issue
Block a user