Move some slice related api out of BasePreferenceController

And share with CustomSliceable.

Bug: 121150258
Test: rebuild
Change-Id: Ia5aed9c156fb168c1f001da6e37f7f12f191b385
This commit is contained in:
Fan Zhang
2019-02-14 15:06:23 -08:00
parent 1aa75aa71a
commit 45f961b624
4 changed files with 74 additions and 56 deletions

View File

@@ -15,7 +15,6 @@ package com.android.settings.core;
import android.annotation.IntDef;
import android.content.Context;
import android.content.IntentFilter;
import android.text.TextUtils;
import android.util.Log;
@@ -24,6 +23,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.slices.SliceData;
import com.android.settings.slices.Sliceable;
import com.android.settingslib.core.AbstractPreferenceController;
import java.lang.annotation.Retention;
@@ -37,7 +37,8 @@ import java.util.List;
* for Slices. The abstract classes that inherit from this class will act as the direct interfaces
* for each type when plugging into Slices.
*/
public abstract class BasePreferenceController extends AbstractPreferenceController {
public abstract class BasePreferenceController extends AbstractPreferenceController implements
Sliceable {
private static final String TAG = "SettingsPrefController";
@@ -226,41 +227,6 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
return SliceData.SliceType.INTENT;
}
/**
* @return an {@link IntentFilter} that includes all broadcasts which can affect the state of
* this Setting.
*/
public IntentFilter getIntentFilter() {
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;
}
/**
* @return {@code true} if the setting update asynchronously.
* <p>
* For example, a Wifi controller would return true, because it needs to update the radio
* and wait for it to turn on.
*/
public boolean hasAsyncUpdate() {
return false;
}
/**
* Updates non-indexable keys for search provider.
*
@@ -293,6 +259,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
/**
* Set {@link UiBlockListener}
*
* @param uiBlockListener listener to set
*/
public void setUiBlockListener(UiBlockListener uiBlockListener) {
@@ -306,6 +273,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
/**
* To notify client that UI related background work is finished.
* (i.e. Slice is fully loaded.)
*
* @param controller Controller that contains background work
*/
void onBlockerWorkFinished(BasePreferenceController controller);
@@ -321,5 +289,6 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
*
* This music be used in {@link BasePreferenceController}
*/
public interface UiBlocker {}
public interface UiBlocker {
}
}

View File

@@ -52,7 +52,7 @@ import java.lang.reflect.InvocationTargetException;
* <p>
* If you implement this interface, you should add your Slice to {@link CustomSliceManager}.
*/
public interface CustomSliceable {
public interface CustomSliceable extends Sliceable {
/**
* @return an complete instance of the {@link Slice}.
@@ -78,17 +78,6 @@ public interface CustomSliceable {
*/
Intent getIntent();
/**
* Settings Slices which can represent components that are updatable by the framework should
* listen to changes matched to the {@link IntentFilter} returned here.
*
* @return an {@link IntentFilter} for updates related to the {@link Slice} returned by
* {@link #getSlice()}.
*/
default IntentFilter getIntentFilter() {
return null;
}
/**
* Settings Slices which require background work, such as updating lists should implement a
* {@link SliceBackgroundWorker} and return it here. An example of background work is updating
@@ -116,12 +105,16 @@ public interface CustomSliceable {
PendingIntent.FLAG_CANCEL_CURRENT);
}
@Override
default boolean isSliceable() {
return true;
}
/**
* Build an instance of a {@link CustomSliceable} which has a {@link Context}-only constructor.
*/
static CustomSliceable createInstance(Context context, Class<CustomSliceable> sliceableClass) {
try {
//final Class<CustomSliceable> clazz = Class.forName(sliceableClassName);
final Constructor<CustomSliceable> sliceable =
sliceableClass.getConstructor(Context.class);
final Object[] params = new Object[]{context};

View File

@@ -411,9 +411,7 @@ public class SettingsSliceProvider extends SliceProvider {
@VisibleForTesting
void loadSliceInBackground(Uri uri) {
ThreadUtils.postOnBackgroundThread(() -> {
loadSlice(uri);
});
ThreadUtils.postOnBackgroundThread(() -> loadSlice(uri));
}
/**

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.slices;
import android.content.IntentFilter;
/**
* A collection of API making a PreferenceController "sliceable"
*/
public interface Sliceable {
/**
* @return an {@link IntentFilter} that includes all broadcasts which can affect the state of
* this Setting.
*/
default IntentFilter getIntentFilter() {
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.
*
* @return {@code true} if the controller should be used externally as a Slice.
*/
default boolean isSliceable() {
return false;
}
/**
* @return {@code true} if the setting update asynchronously.
* <p>
* For example, a Wifi controller would return true, because it needs to update the radio
* and wait for it to turn on.
*/
default boolean hasAsyncUpdate() {
return false;
}
}