Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45f961b6 authored by Fan Zhang's avatar Fan Zhang
Browse files

Move some slice related api out of BasePreferenceController

And share with CustomSliceable.

Bug: 121150258
Test: rebuild
Change-Id: Ia5aed9c156fb168c1f001da6e37f7f12f191b385
parent 1aa75aa7
Loading
Loading
Loading
Loading
+9 −40
Original line number Diff line number Diff line
@@ -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 {
    }
}
 No newline at end of file
+6 −13
Original line number Diff line number Diff line
@@ -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};
+1 −3
Original line number Diff line number Diff line
@@ -411,9 +411,7 @@ public class SettingsSliceProvider extends SliceProvider {

    @VisibleForTesting
    void loadSliceInBackground(Uri uri) {
        ThreadUtils.postOnBackgroundThread(() -> {
            loadSlice(uri);
        });
        ThreadUtils.postOnBackgroundThread(() -> loadSlice(uri));
    }

    /**
+58 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}