Add isSliceable API to BasePrefController

Only support explicitly approved Settings Slices,
dictated by controllers which return true for the new
method isSliceable.

Updating the supported settings to a whitelist means that
the method to return all available slices must be updated,
and checking slicability when we index slices.

Test: robotests
Bug: 79779103
Change-Id: Ib2b9690cdd0036b5cc4a1cb846c52bce7c824ab9
This commit is contained in:
Matthew Fritze
2018-05-18 17:59:26 -07:00
parent 49d8b0a3e4
commit bf1f5b5813
47 changed files with 475 additions and 18 deletions

View File

@@ -23,9 +23,11 @@ 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.text.TextUtils;
import android.util.ArraySet;
import android.util.KeyValueListParser;
import android.util.Log;
import android.util.Pair;
@@ -42,6 +44,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
@@ -352,4 +358,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];
}
}