diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java index 1c850099554..324b5097b06 100644 --- a/src/com/android/settings/core/BasePreferenceController.java +++ b/src/com/android/settings/core/BasePreferenceController.java @@ -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"; @@ -119,7 +120,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl final Class clazz = Class.forName(controllerName); final Constructor preferenceConstructor = clazz.getConstructor(Context.class, String.class); - final Object[] params = new Object[] {context, key}; + final Object[] params = new Object[]{context, key}; return (BasePreferenceController) preferenceConstructor.newInstance(params); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { @@ -137,7 +138,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl try { final Class clazz = Class.forName(controllerName); final Constructor preferenceConstructor = clazz.getConstructor(Context.class); - final Object[] params = new Object[] {context}; + final Object[] params = new Object[]{context}; return (BasePreferenceController) preferenceConstructor.newInstance(params); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { @@ -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. - *

- * Important criteria for a Slice are: - * - Must be secure - * - Must not be a privacy leak - * - Must be understandable as a stand-alone Setting. - *

- * 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. - *

- * 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 { + } } \ No newline at end of file diff --git a/src/com/android/settings/slices/CustomSliceable.java b/src/com/android/settings/slices/CustomSliceable.java index 220cdc80dbf..d32e2665d1c 100644 --- a/src/com/android/settings/slices/CustomSliceable.java +++ b/src/com/android/settings/slices/CustomSliceable.java @@ -52,7 +52,7 @@ import java.lang.reflect.InvocationTargetException; *

* 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 sliceableClass) { try { - //final Class clazz = Class.forName(sliceableClassName); final Constructor sliceable = sliceableClass.getConstructor(Context.class); final Object[] params = new Object[]{context}; diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java index f22948668f5..5c662e5c7e0 100644 --- a/src/com/android/settings/slices/SettingsSliceProvider.java +++ b/src/com/android/settings/slices/SettingsSliceProvider.java @@ -411,9 +411,7 @@ public class SettingsSliceProvider extends SliceProvider { @VisibleForTesting void loadSliceInBackground(Uri uri) { - ThreadUtils.postOnBackgroundThread(() -> { - loadSlice(uri); - }); + ThreadUtils.postOnBackgroundThread(() -> loadSlice(uri)); } /** diff --git a/src/com/android/settings/slices/Sliceable.java b/src/com/android/settings/slices/Sliceable.java new file mode 100644 index 00000000000..ddec2e1a973 --- /dev/null +++ b/src/com/android/settings/slices/Sliceable.java @@ -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. + *

+ * Important criteria for a Slice are: + * - Must be secure + * - Must not be a privacy leak + * - Must be understandable as a stand-alone Setting. + *

+ * 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. + *

+ * 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; + } +}