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

Commit e5712bb4 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

3/N Remove UserTracker from QSPanel

Makes QSSecurityFooter injectable.

Bug: 168904199
Test: manual && atest SystemUITests
Change-Id: I34699388717e4c6744deebbccdfc9075bfed91b1
parent 11437876
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -28,12 +28,17 @@ import com.android.systemui.qs.QSHost.Callback;
import com.android.systemui.qs.QSPanel.QSTileLayout;
import com.android.systemui.qs.TouchAnimator.Builder;
import com.android.systemui.qs.TouchAnimator.Listener;
import com.android.systemui.qs.dagger.QSScope;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;

import java.util.ArrayList;
import java.util.Collection;

import javax.inject.Inject;

/** */
@QSScope
public class QSAnimator implements Callback, PageListener, Listener, OnLayoutChangeListener,
        OnAttachStateChangeListener, Tunable {

@@ -53,6 +58,7 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha
    private final ArrayList<View> mQuickQsViews = new ArrayList<>();
    private final QuickQSPanel mQuickQsPanel;
    private final QSPanel mQsPanel;
    private final QSSecurityFooter mSecurityFooter;
    private final QS mQs;

    private PagedTileLayout mPagedLayout;
@@ -78,10 +84,13 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha
    private QSTileHost mHost;
    private boolean mShowCollapsedOnKeyguard;

    public QSAnimator(QS qs, QuickQSPanel quickPanel, QSPanel panel) {
    @Inject
    public QSAnimator(QS qs, QuickQSPanel quickPanel, QSPanel panel,
            QSSecurityFooter securityFooter) {
        mQs = qs;
        mQuickQsPanel = quickPanel;
        mQsPanel = panel;
        mSecurityFooter = securityFooter;
        mQsPanel.addOnAttachStateChangeListener(this);
        qs.getView().addOnLayoutChangeListener(this);
        if (mQsPanel.isAttachedToWindow()) {
@@ -302,16 +311,12 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha

            // Fade in the security footer and the divider as we reach the final position
            builder = new Builder().setStartDelay(EXPANDED_TILE_DELAY);
            if (mQsPanel.getSecurityFooter() != null) {
                builder.addFloat(mQsPanel.getSecurityFooter().getView(), "alpha", 0, 1);
            }
            builder.addFloat(mSecurityFooter.getView(), "alpha", 0, 1);
            if (mQsPanel.getDivider() != null) {
                builder.addFloat(mQsPanel.getDivider(), "alpha", 0, 1);
            }
            mAllPagesDelayedAnimator = builder.build();
            if (mQsPanel.getSecurityFooter() != null) {
                mAllViews.add(mQsPanel.getSecurityFooter().getView());
            }
            mAllViews.add(mSecurityFooter.getView());
            if (mQsPanel.getDivider() != null) {
                mAllViews.add(mQsPanel.getDivider());
            }
+5 −3
Original line number Diff line number Diff line
@@ -150,9 +150,7 @@ public class QSFragment extends LifecycleFragment implements QS, CommandQueue.Ca
        mQSContainerImplController.init();

        mQSDetail.setQsPanel(mQSPanelController.getView(), mHeader, (View) mFooter);
        mQSAnimator = new QSAnimator(
                this, mHeader.findViewById(R.id.quick_qs_panel), mQSPanelController.getView());

        mQSAnimator = qsFragmentComponent.getQSAnimator();

        mQSCustomizer = view.findViewById(R.id.qs_customize);
        mQSCustomizer.setQs(this);
@@ -324,6 +322,10 @@ public class QSFragment extends LifecycleFragment implements QS, CommandQueue.Ca
        }
    }

    public QSPanelController getQSPanelController() {
        return mQSPanelController;
    }

    public QSPanel getQsPanel() {
        return mQSPanelController.getView();
    }
+36 −58
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.settings.BrightnessController;
import com.android.systemui.settings.ToggleSliderView;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.BrightnessMirrorController;
import com.android.systemui.statusbar.policy.BrightnessMirrorController.BrightnessMirrorListener;
import com.android.systemui.tuner.TunerService;
@@ -68,6 +67,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@@ -114,10 +114,11 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
    private final QSLogger mQSLogger;
    protected final UiEventLogger mUiEventLogger;
    protected QSTileHost mHost;
    private final UserTracker mUserTracker;
    private final List<OnConfigurationChangedListener> mOnConfigurationChangedListeners =
            new ArrayList<>();

    @Nullable
    protected QSSecurityFooter mSecurityFooter;
    protected View mSecurityFooter;

    @Nullable
    protected View mFooter;
@@ -157,8 +158,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
            DumpManager dumpManager,
            QSLogger qsLogger,
            @Named(QS_PANEL) MediaHost mediaHost,
            UiEventLogger uiEventLogger,
            UserTracker userTracker
            UiEventLogger uiEventLogger
    ) {
        super(context, attrs);
        mUsingMediaPlayer = useQsMediaPlayer(context);
@@ -173,13 +173,13 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        mQSLogger = qsLogger;
        mDumpManager = dumpManager;
        mUiEventLogger = uiEventLogger;
        mUserTracker = userTracker;

        setOrientation(VERTICAL);

        addViewsAboveTiles();
        mMovableContentStartIndex = getChildCount();
        mRegularTileLayout = createRegularTileLayout();
        mTileLayout = mRegularTileLayout;

        if (mUsingMediaPlayer) {
            mHorizontalLinearLayout = new RemeasuringLinearLayout(mContext);
@@ -205,26 +205,20 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne

            initMediaHostState();
        }
        addSecurityFooter();
        if (mRegularTileLayout instanceof PagedTileLayout) {
            mQsTileRevealController = new QSTileRevealController(mContext, this,
                    (PagedTileLayout) mRegularTileLayout);
        }
        mQSLogger.logAllTilesChangeListening(mListening, getDumpableTag(), mCachedSpecs);
        updateResources();
    }

    protected void onMediaVisibilityChanged(Boolean visible) {
        switchTileLayout();
        switchTileLayout(false);
        if (mMediaVisibilityChangedListener != null) {
            mMediaVisibilityChangedListener.accept(visible);
        }
    }

    protected void addSecurityFooter() {
        mSecurityFooter = new QSSecurityFooter(this, mContext, mUserTracker);
    }

    protected void addViewsAboveTiles() {
        mBrightnessView = LayoutInflater.from(mContext).inflate(
            R.layout.quick_settings_brightness_dialog, this, false);
@@ -432,9 +426,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        mHost = host;
        mHost.addCallback(this);
        setTiles(mHost.getTiles());
        if (mSecurityFooter != null) {
            mSecurityFooter.setHostEnvironment(host);
        }
        mCustomizePanel = customizer;
        if (mCustomizePanel != null) {
            mCustomizePanel.setHost(mHost);
@@ -477,9 +468,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne

        updatePageIndicator();

        if (mListening) {
            refreshAllTiles();
        }
        if (mTileLayout != null) {
            mTileLayout.updateResources();
        }
@@ -500,19 +488,25 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
                res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom));
    }

    void addOnConfigurationChangedListener(OnConfigurationChangedListener listener) {
        mOnConfigurationChangedListeners.add(listener);
    }

    void removeOnConfigurationChangedListener(OnConfigurationChangedListener listener) {
        mOnConfigurationChangedListeners.remove(listener);
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (mSecurityFooter != null) {
            mSecurityFooter.onConfigurationChanged();
        }
        updateResources();
        mOnConfigurationChangedListeners.forEach(
                listener -> listener.onConfigurationChange(newConfig));

        updateBrightnessMirror();

        if (newConfig.orientation != mLastOrientation) {
            mLastOrientation = newConfig.orientation;
            switchTileLayout();
            switchTileLayout(false);
        }
    }

@@ -524,11 +518,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        switchTileLayout(true /* force */);
    }

    boolean switchTileLayout() {
        return switchTileLayout(false /* force */);
    }

    private boolean switchTileLayout(boolean force) {
    boolean switchTileLayout(boolean force) {
        /** Whether or not the QuickQSPanel currently contains a media player. */
        boolean horizontal = shouldUseHorizontalLayout();
        if (mDivider != null) {
@@ -611,20 +601,20 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        index++;

        if (mSecurityFooter != null) {
            View view = mSecurityFooter.getView();
            LinearLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
            LinearLayout.LayoutParams layoutParams =
                    (LayoutParams) mSecurityFooter.getLayoutParams();
            if (mUsingHorizontalLayout && mHeaderContainer != null) {
                // Adding the security view to the header, that enables us to avoid scrolling
                layoutParams.width = 0;
                layoutParams.weight = 1.6f;
                switchToParent(view, mHeaderContainer, 1 /* always in second place */);
                switchToParent(mSecurityFooter, mHeaderContainer, 1 /* always in second place */);
            } else {
                layoutParams.width = LayoutParams.WRAP_CONTENT;
                layoutParams.weight = 0;
                switchToParent(view, parent, index);
                switchToParent(mSecurityFooter, parent, index);
                index++;
            }
            view.setLayoutParams(layoutParams);
            mSecurityFooter.setLayoutParams(layoutParams);
        }

        if (mFooter != null) {
@@ -724,9 +714,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
            mQSLogger.logAllTilesChangeListening(listening, getDumpableTag(), mCachedSpecs);
            mTileLayout.setListening(listening);
        }
        if (mListening) {
            refreshAllTiles();
        }
    }

    private String getTilesSpecs() {
@@ -735,13 +722,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
                .collect(Collectors.joining(","));
    }

    public void setListening(boolean listening, boolean expanded) {
        setListening(listening && expanded);
        if (mSecurityFooter != null) {
            mSecurityFooter.setListening(listening);
        }
    }

    public void refreshAllTiles() {
        if (mBrightnessController != null) {
            mBrightnessController.checkRestrictionAndSetEnabled();
@@ -749,9 +729,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        for (TileRecord r : mRecords) {
            r.tile.refreshState();
        }
        if (mSecurityFooter != null) {
            mSecurityFooter.refreshState();
        }
    }

    public void showDetailAdapter(boolean show, DetailAdapter adapter, int[] locationInWindow) {
@@ -1003,22 +980,11 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        return null;
    }

    @Nullable
    public QSSecurityFooter getSecurityFooter() {
        return mSecurityFooter;
    }

    @Nullable
    public View getDivider() {
        return mDivider;
    }

    public void showDeviceMonitoringDialog() {
        if (mSecurityFooter != null) {
            mSecurityFooter.showDeviceMonitoringDialog();
        }
    }

    public void setContentMargins(int startMargin, int endMargin) {
        // Only some views actually want this content padding, others want to go all the way
        // to the edge like the brightness slider
@@ -1125,6 +1091,14 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
        mBrightnessController = brightnessController;
    }

    public boolean isListening() {
        return mListening;
    }

    public void setSecurityFooter(View view) {
        mSecurityFooter = view;
    }

    private class H extends Handler {
        private static final int SHOW_DETAIL = 1;
        private static final int SET_TILE_VISIBILITY = 2;
@@ -1206,4 +1180,8 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne

        int getNumVisibleTiles();
    }

    interface OnConfigurationChangedListener {
        void onConfigurationChange(Configuration newConfig);
    }
}
+70 −3
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.qs;

import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.res.Configuration;
import android.view.ViewGroup;

import com.android.systemui.R;
@@ -24,6 +26,7 @@ import com.android.systemui.media.MediaHost;
import com.android.systemui.qs.customize.QSCustomizer;
import com.android.systemui.qs.dagger.QSScope;
import com.android.systemui.settings.BrightnessController;
import com.android.systemui.statusbar.policy.BrightnessMirrorController;
import com.android.systemui.util.ViewController;

import javax.inject.Inject;
@@ -33,11 +36,26 @@ import javax.inject.Inject;
 */
@QSScope
public class QSPanelController extends ViewController<QSPanel> {
    private final QSSecurityFooter mQsSecurityFooter;
    private final BrightnessController mBrightnessController;

    private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener =
            new QSPanel.OnConfigurationChangedListener() {
        @Override
        public void onConfigurationChange(Configuration newConfig) {
            mView.updateResources();
            mQsSecurityFooter.onConfigurationChanged();
            if (mView.isListening()) {
                refreshAllTiles();
            }
        }
    };

    @Inject
    QSPanelController(QSPanel view, BrightnessController.Factory brightnessControllerFactory) {
    QSPanelController(QSPanel view, QSSecurityFooter qsSecurityFooter,
            BrightnessController.Factory brightnessControllerFactory) {
        super(view);
        mQsSecurityFooter = qsSecurityFooter;

        mBrightnessController = brightnessControllerFactory.create(
                mView.findViewById(R.id.brightness_slider));
@@ -45,12 +63,19 @@ public class QSPanelController extends ViewController<QSPanel> {

    @Override
    protected void onViewAttached() {
        mView.updateResources();
        if (mView.isListening()) {
            refreshAllTiles();
        }
        mView.setBrightnessController(mBrightnessController);
        mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener);
        mView.setSecurityFooter(mQsSecurityFooter.getView());
        mView.switchTileLayout(true);
    }

    @Override
    protected void onViewDetached() {

        mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener);
    }

    /** TODO(b/168904199): Remove this method once view is controllerized. */
@@ -72,6 +97,7 @@ public class QSPanelController extends ViewController<QSPanel> {
    /** */
    public void setHost(QSTileHost host, QSCustomizer customizer) {
        mView.setHost(host, customizer);
        mQsSecurityFooter.setHostEnvironment(host);
    }

    /** */
@@ -91,7 +117,12 @@ public class QSPanelController extends ViewController<QSPanel> {

    /** */
    public void setListening(boolean listening, boolean expanded) {
        mView.setListening(listening, expanded);
        mView.setListening(listening && expanded);
        if (mView.isListening()) {
            refreshAllTiles();
        }

        mQsSecurityFooter.setListening(listening);

        // Set the listening as soon as the QS fragment starts listening regardless of the
        //expansion, so it will update the current brightness before the slider is visible.
@@ -116,4 +147,40 @@ public class QSPanelController extends ViewController<QSPanel> {
    public void closeDetail() {
        mView.closeDetail();
    }

    /** */
    public void setBrightnessMirror(BrightnessMirrorController brightnessMirrorController) {
        mView.setBrightnessMirror(brightnessMirrorController);
    }

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

    /** Click a tile. */
    public void clickTile(ComponentName tile) {
        mView.clickTile(tile);
    }

    /** Open the details for a specific tile.. */
    public void openDetails(String subPanel) {
        mView.openDetails(subPanel);
    }

    /** Show the device monitoring dialog. */
    public void showDeviceMonitoringDialog() {
        mQsSecurityFooter.showDeviceMonitoringDialog();
    }

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

    /** Update state of all tiles. */
    public void refreshAllTiles() {
        mView.refreshAllTiles();
        mQsSecurityFooter.refreshState();
    }
}
+8 −3
Original line number Diff line number Diff line
@@ -44,11 +44,15 @@ import com.android.systemui.Dependency;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.qs.dagger.QSScope;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.SecurityController;

public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListener {
import javax.inject.Inject;

@QSScope
class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListener {
    protected static final String TAG = "QSSecurityFooter";
    protected static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean DEBUG_FORCE_VISIBLE = false;
@@ -72,12 +76,13 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
    private int mFooterTextId;
    private int mFooterIconId;

    @Inject
    public QSSecurityFooter(QSPanel qsPanel, Context context, UserTracker userTracker) {
        mRootView = LayoutInflater.from(context)
                .inflate(R.layout.quick_settings_footer, qsPanel, false);
        mRootView.setOnClickListener(this);
        mFooterText = (TextView) mRootView.findViewById(R.id.footer_text);
        mFooterIcon = (ImageView) mRootView.findViewById(R.id.footer_icon);
        mFooterText = mRootView.findViewById(R.id.footer_text);
        mFooterIcon = mRootView.findViewById(R.id.footer_icon);
        mFooterIconId = R.drawable.ic_info_outline;
        mContext = context;
        mMainHandler = new Handler(Looper.myLooper());
Loading