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

Commit b98eeb25 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 9555ed12 1c6116cb
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.provider.Settings;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.Tile;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.service.quicksettings.TileService;
import android.text.format.DateUtils;
import android.util.Log;
import android.util.Log;
import android.view.IWindowManager;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
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 class CustomTile extends QSTileImpl<State> implements TileChangeListener {
    public static final String PREFIX = "custom(";
    public static final String PREFIX = "custom(";


    private static final long CUSTOM_STALE_TIMEOUT = DateUtils.HOUR_IN_MILLIS;

    private static final boolean DEBUG = false;
    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.
    // 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();
        mUser = ActivityManager.getCurrentUser();
    }
    }


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

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


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


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsLogger;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.Utils;
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.QSIconView;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTile.State;
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.PagedTileLayout.TilePage;
import com.android.systemui.qs.QSHost;
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 final String TAG = "Tile." + getClass().getSimpleName();
    protected static final boolean DEBUG = Log.isLoggable("Tile", Log.DEBUG);
    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 QSHost mHost;
    protected final Context mContext;
    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());
    protected final Handler mUiHandler = new Handler(Looper.getMainLooper());
    private final ArraySet<Object> mListeners = new ArraySet<>();
    private final ArraySet<Object> mListeners = new ArraySet<>();
    private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
    private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);


    private final ArrayList<Callback> mCallbacks = new ArrayList<>();
    private final ArrayList<Callback> mCallbacks = new ArrayList<>();
    private final Object mStaleListener = new Object();
    protected TState mState = newTileState();
    protected TState mState = newTileState();
    private TState mTmpState = newTileState();
    private TState mTmpState = newTileState();
    private boolean mAnnounceNextStateChange;
    private boolean mAnnounceNextStateChange;
@@ -95,6 +100,7 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
    protected QSTileImpl(QSHost host) {
    protected QSTileImpl(QSHost host) {
        mHost = host;
        mHost = host;
        mContext = host.getContext();
        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 (mListeners.add(listener) && mListeners.size() == 1) {
                if (DEBUG) Log.d(TAG, "setListening " + true);
                if (DEBUG) Log.d(TAG, "setListening " + true);
                mHandler.obtainMessage(H.SET_LISTENING, 1, 0).sendToTarget();
                mHandler.obtainMessage(H.SET_LISTENING, 1, 0).sendToTarget();
                refreshState(); // Ensure we get at least one refresh after listening.
            }
            }
        } else {
        } else {
            if (mListeners.remove(listener) && mListeners.size() == 0) {
            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() {
    public String getTileSpec() {
        return mTileSpec;
        return mTileSpec;
    }
    }
@@ -273,6 +289,9 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
        if (changed) {
        if (changed) {
            handleStateChanged();
            handleStateChanged();
        }
        }
        mHandler.removeMessages(H.STALE);
        mHandler.sendEmptyMessageDelayed(H.STALE, getStaleTimeout());
        setListening(mStaleListener, false);
    }
    }


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


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


    protected void handleDestroy() {
    protected void handleDestroy() {
        if (mListeners.size() != 0) {
        if (mListeners.size() != 0) {
            setListening(false);
            handleSetListening(false);
        }
        }
        mCallbacks.clear();
        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_CALLBACKS = 12;
        private static final int REMOVE_CALLBACK = 13;
        private static final int REMOVE_CALLBACK = 13;
        private static final int SET_LISTENING = 14;
        private static final int SET_LISTENING = 14;
        private static final int STALE = 15;


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


@@ -436,8 +457,11 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
                    name = "handleClearState";
                    name = "handleClearState";
                    handleClearState();
                    handleClearState();
                } else if (msg.what == SET_LISTENING) {
                } else if (msg.what == SET_LISTENING) {
                    name = "setListening";
                    name = "handleSetListening";
                    setListening(msg.arg1 != 0);
                    handleSetListening(msg.arg1 != 0);
                } else if (msg.what == STALE) {
                    name = "handleStale";
                    handleStale();
                } else {
                } else {
                    throw new IllegalArgumentException("Unknown msg: " + msg.what);
                    throw new IllegalArgumentException("Unknown msg: " + msg.what);
                }
                }
@@ -515,7 +539,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;
        private final int mAnimatedResId;


        public AnimationIcon(int resId, int staticResId) {
        public AnimationIcon(int resId, int staticResId) {
+1 −1
Original line number Original line 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;
        if (mListening == listening) return;
        mListening = listening;
        mListening = listening;
        if (listening) {
        if (listening) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -55,7 +55,7 @@ public class BatterySaverTile extends QSTileImpl<BooleanState> implements
    }
    }


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


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