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

Commit 15ad1251 authored by Jason Monk's avatar Jason Monk Committed by android-build-merger
Browse files

Merge "Update QS if the content gets stale" into oc-mr1-dev

am: b98eeb25

Change-Id: I863d105e3a3f36f595cff9f439a77e8e37382dac
parents d6af052a b98eeb25
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.provider.Settings;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
@@ -51,6 +52,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
public class CustomTile extends QSTileImpl<State> implements TileChangeListener {
    public static final String PREFIX = "custom(";

    private static final long CUSTOM_STALE_TIMEOUT = DateUtils.HOUR_IN_MILLIS;

    private static final boolean DEBUG = false;

    // We don't want to thrash binding and unbinding if the user opens and closes the panel a lot.
@@ -83,6 +86,11 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
        mUser = ActivityManager.getCurrentUser();
    }

    @Override
    protected long getStaleTimeout() {
        return CUSTOM_STALE_TIMEOUT + DateUtils.MINUTE_IN_MILLIS * mHost.indexOf(getTileSpec());
    }

    private void setTileIcon() {
        try {
            PackageManager pm = mContext.getPackageManager();
@@ -186,7 +194,7 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
    }

    @Override
    public void setListening(boolean listening) {
    public void handleSetListening(boolean listening) {
        if (mListening == listening) return;
        mListening = listening;
        try {
+32 −8
Original line number Diff line number Diff line
@@ -32,10 +32,12 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.service.quicksettings.Tile;
import android.text.format.DateUtils;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.Utils;
@@ -45,7 +47,6 @@ import com.android.systemui.plugins.qs.DetailAdapter;
import com.android.systemui.plugins.qs.QSIconView;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTile.State;
import com.android.systemui.qs.PagedTileLayout;
import com.android.systemui.qs.PagedTileLayout.TilePage;
import com.android.systemui.qs.QSHost;

@@ -62,14 +63,18 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
    protected final String TAG = "Tile." + getClass().getSimpleName();
    protected static final boolean DEBUG = Log.isLoggable("Tile", Log.DEBUG);

    private static final long DEFAULT_STALE_TIMEOUT = 10 * DateUtils.MINUTE_IN_MILLIS;

    protected final QSHost mHost;
    protected final Context mContext;
    protected final H mHandler = new H(Dependency.get(Dependency.BG_LOOPER));
    // @NonFinalForTesting
    protected H mHandler = new H(Dependency.get(Dependency.BG_LOOPER));
    protected final Handler mUiHandler = new Handler(Looper.getMainLooper());
    private final ArraySet<Object> mListeners = new ArraySet<>();
    private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);

    private final ArrayList<Callback> mCallbacks = new ArrayList<>();
    private final Object mStaleListener = new Object();
    protected TState mState = newTileState();
    private TState mTmpState = newTileState();
    private boolean mAnnounceNextStateChange;
@@ -95,6 +100,7 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
    protected QSTileImpl(QSHost host) {
        mHost = host;
        mContext = host.getContext();
        handleStale(); // Tile was just created, must be stale.
    }

    /**
@@ -106,6 +112,7 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
            if (mListeners.add(listener) && mListeners.size() == 1) {
                if (DEBUG) Log.d(TAG, "setListening " + true);
                mHandler.obtainMessage(H.SET_LISTENING, 1, 0).sendToTarget();
                refreshState(); // Ensure we get at least one refresh after listening.
            }
        } else {
            if (mListeners.remove(listener) && mListeners.size() == 0) {
@@ -115,6 +122,15 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
        }
    }

    protected long getStaleTimeout() {
        return DEFAULT_STALE_TIMEOUT;
    }

    @VisibleForTesting
    protected void handleStale() {
        setListening(mStaleListener, true);
    }

    public String getTileSpec() {
        return mTileSpec;
    }
@@ -273,6 +289,9 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
        if (changed) {
            handleStateChanged();
        }
        mHandler.removeMessages(H.STALE);
        mHandler.sendEmptyMessageDelayed(H.STALE, getStaleTimeout());
        setListening(mStaleListener, false);
    }

    private void handleStateChanged() {
@@ -326,11 +345,11 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
        handleRefreshState(null);
    }

    protected abstract void setListening(boolean listening);
    protected abstract void handleSetListening(boolean listening);

    protected void handleDestroy() {
        if (mListeners.size() != 0) {
            setListening(false);
            handleSetListening(false);
        }
        mCallbacks.clear();
    }
@@ -380,8 +399,10 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
        private static final int REMOVE_CALLBACKS = 12;
        private static final int REMOVE_CALLBACK = 13;
        private static final int SET_LISTENING = 14;
        private static final int STALE = 15;

        private H(Looper looper) {
        @VisibleForTesting
        protected H(Looper looper) {
            super(looper);
        }

@@ -436,8 +457,11 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
                    name = "handleClearState";
                    handleClearState();
                } else if (msg.what == SET_LISTENING) {
                    name = "setListening";
                    setListening(msg.arg1 != 0);
                    name = "handleSetListening";
                    handleSetListening(msg.arg1 != 0);
                } else if (msg.what == STALE) {
                    name = "handleStale";
                    handleStale();
                } else {
                    throw new IllegalArgumentException("Unknown msg: " + msg.what);
                }
@@ -522,7 +546,7 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
        }
    }

    protected class AnimationIcon extends ResourceIcon {
    protected static class AnimationIcon extends ResourceIcon {
        private final int mAnimatedResId;

        public AnimationIcon(int resId, int staticResId) {
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class AirplaneModeTile extends QSTileImpl<BooleanState> {
        }
    }

    public void setListening(boolean listening) {
    public void handleSetListening(boolean listening) {
        if (mListening == listening) return;
        mListening = listening;
        if (listening) {
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class BatterySaverTile extends QSTileImpl<BooleanState> implements
    }

    @Override
    public void setListening(boolean listening) {
    public void handleSetListening(boolean listening) {
        if (listening) {
            mBatteryController.addCallback(this);
        } else {
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
    }

    @Override
    public void setListening(boolean listening) {
    public void handleSetListening(boolean listening) {
        if (listening) {
            mController.addCallback(mCallback);
        } else {
Loading