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

Commit 09070e31 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Extract QSHost interface

In preparation for refactor, extract the QSHost interface everywhere so
access is done through it. This determines also the surface we may need
to provide.

Test: atest SystemUITests
Test: atest android.host.systemui
Test: atest CtsTileServiceTestCases
Bug: 249804331
Change-Id: I660311eb60336ead6e5694c4e3e6099151dbaecc
parent 36c26294
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ class AutoAddTracker @VisibleForTesting constructor(
    }

    fun getRestoredTilePosition(tile: String): Int =
        restoredTiles?.get(tile)?.index ?: QSTileHost.POSITION_AT_END
        restoredTiles?.get(tile)?.index ?: QSHost.POSITION_AT_END

    /**
     * Returns `true` if the tile has been auto-added before
+3 −3
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class QSAnimator implements QSHost.Callback, PagedTileLayout.PageListener
    private int mNumQuickTiles;
    private int mLastQQSTileHeight;
    private float mLastPosition;
    private final QSTileHost mHost;
    private final QSHost mHost;
    private final Executor mExecutor;
    private boolean mShowCollapsedOnKeyguard;
    private int mQQSTop;
@@ -146,7 +146,7 @@ public class QSAnimator implements QSHost.Callback, PagedTileLayout.PageListener
    @Inject
    public QSAnimator(QS qs, QuickQSPanel quickPanel, QuickStatusBarHeader quickStatusBarHeader,
            QSPanelController qsPanelController,
            QuickQSPanelController quickQSPanelController, QSTileHost qsTileHost,
            QuickQSPanelController quickQSPanelController, QSHost qsTileHost,
            @Main Executor executor, TunerService tunerService,
            QSExpansionPathInterpolator qsExpansionPathInterpolator) {
        mQs = qs;
@@ -485,7 +485,7 @@ public class QSAnimator implements QSHost.Callback, PagedTileLayout.PageListener
        if (specs.isEmpty()) {
            // specs should not be empty in a valid secondary page, as we scrolled to it.
            // We may crash later on because there's a null animator.
            specs = mQsPanelController.getHost().mTileSpecs;
            specs = mHost.getSpecs();
            Log.e(TAG, "Trying to create animators for empty page " + page + ". Tiles: " + specs);
            // return null;
        }
+71 −0
Original line number Diff line number Diff line
@@ -14,15 +14,48 @@

package com.android.systemui.qs;

import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.provider.Settings;

import com.android.internal.logging.InstanceId;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSFactory;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTileView;
import com.android.systemui.util.leak.GarbageMonitor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public interface QSHost {
    String TILES_SETTING = Settings.Secure.QS_TILES;
    int POSITION_AT_END = -1;

    /**
     * Returns the default QS tiles for the context.
     * @param context the context to obtain the resources from
     * @return a list of specs of the default tiles
     */
    static List<String> getDefaultSpecs(Context context) {
        final ArrayList<String> tiles = new ArrayList();

        final Resources res = context.getResources();
        final String defaultTileList = res.getString(R.string.quick_settings_tiles_default);

        tiles.addAll(Arrays.asList(defaultTileList.split(",")));
        if (Build.IS_DEBUGGABLE
                && GarbageMonitor.ADD_MEMORY_TILE_TO_DEFAULT_ON_DEBUGGABLE_BUILDS) {
            tiles.add(GarbageMonitor.MemoryTile.TILE_SPEC);
        }
        return tiles;
    }

    void warn(String message, Throwable t);
    void collapsePanels();
    void forceCollapsePanels();
@@ -37,6 +70,44 @@ public interface QSHost {
    void removeTile(String tileSpec);
    void removeTiles(Collection<String> specs);

    List<String> getSpecs();
    /**
     * Create a view for a tile, iterating over all possible {@link QSFactory}.
     *
     * @see QSFactory#createTileView
     */
    QSTileView createTileView(Context themedContext, QSTile tile, boolean collapsedView);
    /** Create a {@link QSTile} of a {@code tileSpec} type. */
    QSTile createTile(String tileSpec);

    /**
     * Add a tile to the end
     *
     * @param spec string matching a pre-defined tilespec
     */
    void addTile(String spec);

    /**
     * Add a tile into the requested spot, or at the end if the position is greater than the number
     * of tiles.
     * @param spec string matching a pre-defined tilespec
     * @param requestPosition -1 for end, 0 for beginning, or X for insertion at position X
     */
    void addTile(String spec, int requestPosition);
    void addTile(ComponentName tile);

    /**
     * Adds a custom tile to the set of current tiles.
     * @param tile the component name of the {@link android.service.quicksettings.TileService}
     * @param end if true, the tile will be added at the end. If false, at the beginning.
     */
    void addTile(ComponentName tile, boolean end);
    void removeTileByUser(ComponentName tile);
    void changeTilesByUser(List<String> previousTiles, List<String> newTiles);

    boolean isTileAdded(ComponentName componentName, int userId);
    void setTileAdded(ComponentName componentName, int userId, boolean added);

    int indexOf(String tileSpec);

    InstanceId getNewInstanceId();
+0 −6
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ public class QSPanel extends LinearLayout implements Tunable {
    protected boolean mExpanded;
    protected boolean mListening;

    @Nullable protected QSTileHost mHost;
    private final List<OnConfigurationChangedListener> mOnConfigurationChangedListeners =
            new ArrayList<>();

@@ -359,11 +358,6 @@ public class QSPanel extends LinearLayout implements Tunable {
        }
    }

    @Nullable
    public QSTileHost getHost() {
        return mHost;
    }

    public void updateResources() {
        updatePadding();

+2 −8
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {

    @Inject
    QSPanelController(QSPanel view, TunerService tunerService,
            QSTileHost qstileHost, QSCustomizerController qsCustomizerController,
            QSHost qsHost, QSCustomizerController qsCustomizerController,
            @Named(QS_USING_MEDIA_PLAYER) boolean usingMediaPlayer,
            @Named(QS_PANEL) MediaHost mediaHost,
            QSTileRevealController.Factory qsTileRevealControllerFactory,
@@ -80,7 +80,7 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
            BrightnessSliderController.Factory brightnessSliderFactory,
            FalsingManager falsingManager,
            StatusBarKeyguardViewManager statusBarKeyguardViewManager) {
        super(view, qstileHost, qsCustomizerController, usingMediaPlayer, mediaHost,
        super(view, qsHost, qsCustomizerController, usingMediaPlayer, mediaHost,
                metricsLogger, uiEventLogger, qsLogger, dumpManager);
        mTunerService = tunerService;
        mQsCustomizerController = qsCustomizerController;
@@ -172,12 +172,6 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
        mBrightnessMirrorHandler.setController(brightnessMirrorController);
    }

    /** Get the QSTileHost this panel uses. */
    public QSTileHost getHost() {
        return mHost;
    }


    /** Update appearance of QSPanel. */
    public void updateResources() {
        mView.updateResources();
Loading