Merge "Add isSliceable API to BasePrefController" into pi-dev
am: ef950c24bd
Change-Id: Idbcc5c9960270b5713478aa5f22d524dc52fba91
This commit is contained in:
@@ -90,6 +90,11 @@ public class AccessibilitySlicePreferenceController extends TogglePreferenceCont
|
||||
return getAccessibilityServiceInfo() == null ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private AccessibilityServiceInfo getAccessibilityServiceInfo() {
|
||||
final AccessibilityManager accessibilityManager = mContext.getSystemService(
|
||||
AccessibilityManager.class);
|
||||
|
@@ -229,6 +229,23 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the controller should be used as a Slice.
|
||||
* <p>
|
||||
* Important criteria for a Slice are:
|
||||
* - Must be secure
|
||||
* - Must not be a privacy leak
|
||||
* - Must be understandable as a stand-alone Setting.
|
||||
* <p>
|
||||
* This does not guarantee the setting is available. {@link #isAvailable()} should sill be
|
||||
* called.
|
||||
*
|
||||
* @return {@code true} if the controller should be used externally as a Slice.
|
||||
*/
|
||||
public boolean isSliceable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates non-indexable keys for search provider.
|
||||
*
|
||||
|
@@ -19,6 +19,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
@@ -53,6 +54,11 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
|
||||
return isAvailable(mConfig) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "ambient_display_always_on");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mConfig.alwaysOnEnabled(MY_USER);
|
||||
|
@@ -23,6 +23,7 @@ import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
@@ -89,6 +90,11 @@ public class AmbientDisplayNotificationsPreferenceController extends
|
||||
return mConfig.pulseOnNotificationAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "ambient_display_notification");
|
||||
}
|
||||
|
||||
@Override
|
||||
//TODO (b/69808376): Remove result payload
|
||||
public ResultPayload getResultPayload() {
|
||||
|
@@ -16,6 +16,7 @@ package com.android.settings.display;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.DisplaySettings;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
@@ -60,6 +61,11 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "auto_brightness");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
// TODO remove result payload
|
||||
|
@@ -15,6 +15,7 @@ package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
@@ -71,7 +72,12 @@ public class AutoRotatePreferenceController extends TogglePreferenceController i
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return RotationPolicy.isRotationLockToggleVisible(mContext)
|
||||
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "auto_rotate");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.display;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
@@ -53,6 +54,11 @@ public class NightDisplayActivationPreferenceController extends TogglePreference
|
||||
return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "night_display_activated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
@@ -19,6 +19,8 @@ package com.android.settings.display;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.core.SliderPreferenceController;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
@@ -42,6 +44,11 @@ public class NightDisplayIntensityPreferenceController extends SliderPreferenceC
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "night_display_temperature");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
@@ -23,6 +23,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.DatabaseIndexingUtils;
|
||||
@@ -61,6 +62,11 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|
||||
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
|
@@ -89,6 +89,11 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_screen");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
|
||||
|
@@ -71,6 +71,11 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
|
||||
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_double_twist");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
|
@@ -83,6 +83,11 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_pick_up");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
|
@@ -21,6 +21,7 @@ import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
@@ -59,6 +60,11 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
|
||||
return isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_swipe_down_fingerprint");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
setSwipeToNotification(mContext, isChecked);
|
||||
|
@@ -23,6 +23,7 @@ import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
@@ -61,6 +62,11 @@ public class SwipeUpPreferenceController extends GesturePreferenceController {
|
||||
return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_swipe_up");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
|
@@ -23,6 +23,7 @@ import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.internal.telephony.TelephonyProperties;
|
||||
@@ -90,6 +91,11 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
&& !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "toggle_airplane");
|
||||
}
|
||||
|
||||
@Override
|
||||
@AvailabilityStatus
|
||||
public int getAvailabilityStatus() {
|
||||
|
@@ -27,6 +27,7 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
@@ -87,6 +88,11 @@ public class BadgingNotificationPreferenceController extends TogglePreferenceCon
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "notification_badging");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
@@ -37,6 +38,11 @@ public class CallVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
&& !mHelper.isSingleVolume() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "call_volume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioStream() {
|
||||
if (mAudioManager.isBluetoothScoOn()) {
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
@@ -37,6 +38,11 @@ public class MediaVolumePreferenceController extends
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), KEY_MEDIA_VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_MEDIA_VOLUME;
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
@@ -38,6 +39,11 @@ public class NotificationVolumePreferenceController extends
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), KEY_NOTIFICATION_VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_NOTIFICATION_VOLUME;
|
||||
|
@@ -28,6 +28,7 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
@@ -88,6 +89,11 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), KEY_RING_VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioStream() {
|
||||
return AudioManager.STREAM_RING;
|
||||
|
@@ -26,6 +26,7 @@ import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
@@ -63,6 +64,11 @@ public class VibrateWhenRingPreferenceController extends TogglePreferenceControl
|
||||
return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "vibrate_when_ringing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
@@ -23,11 +23,13 @@ import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v4.graphics.drawable.IconCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.KeyValueListParser;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
@@ -44,6 +46,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -115,10 +118,13 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
@VisibleForTesting
|
||||
Map<Uri, SliceData> mSliceDataCache;
|
||||
|
||||
private final KeyValueListParser mParser;
|
||||
|
||||
final Set<Uri> mRegisteredUris = new ArraySet<>();
|
||||
|
||||
public SettingsSliceProvider() {
|
||||
super(READ_SEARCH_INDEXABLES);
|
||||
mParser = new KeyValueListParser(',');
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,4 +357,32 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
SliceBroadcastRelay.registerReceiver(getContext(), sliceUri, SliceBroadcastReceiver.class,
|
||||
intentFilter);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Set<String> getBlockedKeys() {
|
||||
final String value = Settings.Global.getString(getContext().getContentResolver(),
|
||||
Settings.Global.BLOCKED_SLICES);
|
||||
final Set<String> set = new ArraySet<>();
|
||||
|
||||
try {
|
||||
mParser.setString(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(TAG, "Bad Settings Slices Whitelist flags", e);
|
||||
return set;
|
||||
}
|
||||
|
||||
final String[] parsedValues = parseStringArray(value);
|
||||
Collections.addAll(set, parsedValues);
|
||||
return set;
|
||||
}
|
||||
|
||||
private String[] parseStringArray(String value) {
|
||||
if (value != null) {
|
||||
String[] parts = value.split(":");
|
||||
if (parts.length > 0) {
|
||||
return parts;
|
||||
}
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ 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_KEYWORDS;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_PLATFORM_SLICE_FLAG;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||
@@ -44,6 +43,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilitySettings;
|
||||
import com.android.settings.accessibility.AccessibilitySlicePreferenceController;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceXmlParserUtils;
|
||||
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
@@ -194,6 +194,7 @@ class SliceDataConverter {
|
||||
if (TextUtils.isEmpty(controllerClassName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String key = bundle.getString(METADATA_KEY);
|
||||
final String title = bundle.getString(METADATA_TITLE);
|
||||
final String summary = bundle.getString(METADATA_SUMMARY);
|
||||
@@ -214,7 +215,13 @@ class SliceDataConverter {
|
||||
.setPlatformDefined(isPlatformSlice)
|
||||
.build();
|
||||
|
||||
xmlSliceData.add(xmlSlice);
|
||||
final BasePreferenceController controller =
|
||||
SliceBuilderUtils.getPreferenceController(mContext, xmlSlice);
|
||||
|
||||
// Only add pre-approved Slices available on the device.
|
||||
if (controller.isAvailable() && controller.isSliceable()) {
|
||||
xmlSliceData.add(xmlSlice);
|
||||
}
|
||||
}
|
||||
} catch (SliceData.InvalidSliceDataException e) {
|
||||
Log.w(TAG, "Invalid data when building SliceData for " + fragmentName, e);
|
||||
|
Reference in New Issue
Block a user