Declare official platform slice

Create the notion of an official platform slice.
This includes:
- Adding a second authority to the provider
- tagging slices in xml with a platform slice flag
- Including authority in the getUri method

Bug:73359139
Test: robotests
Change-Id: I5382be138a262dbc5a8324c34aab131c5d0d5516
Merged-In: I581ee6dfcdf935f452a15e89e5d055e375ff1877
This commit is contained in:
Matthew Fritze
2018-02-28 08:15:55 -08:00
parent e8acc0c4bd
commit a4a3dfffa2
15 changed files with 201 additions and 53 deletions

View File

@@ -24,6 +24,7 @@ import android.content.Intent;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.provider.SettingsSlicesContract;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
@@ -63,6 +64,10 @@ public class SettingsSliceProvider extends SliceProvider {
private static final String TAG = "SettingsSliceProvider";
/**
* Authority for Settings slices not officially supported by the platform, but extensible for
* OEMs.
*/
public static final String SLICE_AUTHORITY = "com.android.settings.slices";
public static final String PATH_WIFI = "wifi";
@@ -82,13 +87,6 @@ public class SettingsSliceProvider extends SliceProvider {
@VisibleForTesting
Map<Uri, SliceData> mSliceDataCache;
public static Uri getUri(String path) {
return new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SLICE_AUTHORITY)
.appendPath(path).build();
}
@Override
public boolean onCreateSliceProvider() {
mSlicesDatabaseAccessor = new SlicesDatabaseAccessor(getContext());
@@ -176,7 +174,8 @@ public class SettingsSliceProvider extends SliceProvider {
.setSubtitle(state)
.addEndItem(new SliceAction(getBroadcastIntent(ACTION_WIFI_CHANGED),
null, finalWifiEnabled))
.setPrimaryAction(new SliceAction(getIntent(Intent.ACTION_MAIN), null, null)))
.setPrimaryAction(
new SliceAction(getIntent(Intent.ACTION_MAIN), null, null)))
.build();
}

View File

@@ -59,7 +59,8 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
// Wait a bit for wifi to update (TODO: is there a better way to do this?)
Handler h = new Handler();
h.postDelayed(() -> {
Uri uri = SettingsSliceProvider.getUri(SettingsSliceProvider.PATH_WIFI);
Uri uri = SliceBuilderUtils.getUri(SettingsSliceProvider.PATH_WIFI,
false /* isPlatformSlice */);
context.getContentResolver().notifyChange(uri, null);
}, 1000);
break;

View File

@@ -19,9 +19,12 @@ package com.android.settings.slices;
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.provider.SettingsSlicesContract;
import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
@@ -98,6 +101,17 @@ public class SliceBuilderUtils {
sliceData.getKey());
}
public static Uri getUri(String path, boolean isPlatformSlice) {
final String authority = isPlatformSlice
? SettingsSlicesContract.AUTHORITY
: SettingsSliceProvider.SLICE_AUTHORITY;
return new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(authority)
.appendPath(path)
.build();
}
private static BasePreferenceController getPreferenceController(Context context,
String controllerClassName, String controllerKey) {
try {

View File

@@ -70,6 +70,8 @@ public class SliceData {
@SliceType
private final int mSliceType;
private final boolean mIsPlatformDefined;
public String getKey() {
return mKey;
}
@@ -106,6 +108,10 @@ public class SliceData {
return mSliceType;
}
public boolean isPlatformDefined() {
return mIsPlatformDefined;
}
private SliceData(Builder builder) {
mKey = builder.mKey;
mTitle = builder.mTitle;
@@ -116,6 +122,7 @@ public class SliceData {
mUri = builder.mUri;
mPreferenceController = builder.mPrefControllerClassName;
mSliceType = builder.mSliceType;
mIsPlatformDefined = builder.mIsPlatformDefined;
}
@Override
@@ -151,6 +158,8 @@ public class SliceData {
private int mSliceType;
private boolean mIsPlatformDefined;
public Builder setKey(String key) {
mKey = key;
return this;
@@ -196,6 +205,11 @@ public class SliceData {
return this;
}
public Builder setPlatformDefined(boolean isPlatformDefined) {
mIsPlatformDefined = isPlatformDefined;
return this;
}
public SliceData build() {
if (TextUtils.isEmpty(mKey)) {
throw new IllegalStateException("Key cannot be empty");

View File

@@ -19,6 +19,7 @@ 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_PLATFORM_SLICE_FLAG;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
@@ -164,7 +165,8 @@ class SliceDataConverter {
| MetadataFlag.FLAG_NEED_PREF_TYPE
| MetadataFlag.FLAG_NEED_PREF_TITLE
| MetadataFlag.FLAG_NEED_PREF_ICON
| MetadataFlag.FLAG_NEED_PREF_SUMMARY);
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG);
for (Bundle bundle : metadata) {
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
@@ -179,6 +181,7 @@ class SliceDataConverter {
final int iconResId = bundle.getInt(METADATA_ICON);
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
key);
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
final SliceData xmlSlice = new SliceData.Builder()
.setKey(key)
@@ -189,6 +192,7 @@ class SliceDataConverter {
.setPreferenceControllerClassName(controllerClassName)
.setFragmentName(fragmentName)
.setSliceType(sliceType)
.setPlatformDefined(isPlatformSlice)
.build();
xmlSliceData.add(xmlSlice);