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

Commit 572a159a authored by Roman Birg's avatar Roman Birg Committed by Matt Garnes
Browse files

SystemUI: add a disabled state for Quick Tiles



Some tiles may want to be visible, but not allow any user interaction
due to security reasons. Add a visual disabled state for tiles which are
not enabled.

With this patch, the Profiles tile and the Lockscreen toggle tile
disable themselves on a secure lock screen.

Change-Id: I65ec7837661483d238d8dc3fa18419f76c8029dd
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 400bb578
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -50,4 +50,7 @@

    <!-- Navigation button ripple color -->
    <color name="navbutton_ripple_color">#FFFFFFFF</color>

    <!-- Quick tile text color when the tile is disabled -->
    <color name="qs_tile_text_disabled">#ff747474</color>
</resources>
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyguard;

import android.Manifest;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
@@ -68,6 +69,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.keyguard.MultiUserAvatarCache;
import com.android.keyguard.ViewMediatorCallback;
import com.android.systemui.SystemUI;
import com.android.systemui.qs.tiles.LockscreenToggleTile;
import com.android.systemui.statusbar.phone.PhoneStatusBar;
import com.android.systemui.statusbar.phone.ScrimController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
@@ -136,6 +138,10 @@ public class KeyguardViewMediator extends SystemUI {
    private static final String DISMISS_KEYGUARD_SECURELY_ACTION =
        "com.android.keyguard.action.DISMISS_KEYGUARD_SECURELY";

    private static final String KEYGUARD_SERVICE_ACTION_STATE_CHANGE =
            "com.android.internal.action.KEYGUARD_SERVICE_STATE_CHANGED";
    private static final String KEYGUARD_SERVICE_EXTRA_ACTIVE = "active";

    // used for handler messages
    private static final int SHOW = 2;
    private static final int HIDE = 3;
@@ -274,6 +280,11 @@ public class KeyguardViewMediator extends SystemUI {
     */
    private boolean mInternallyDisabled = false;

    /**
     * Whether we are bound to the service delegate
     */
    private boolean mKeyguardBound;

    /**
     * we send this intent when the keyguard is dismissed.
     */
@@ -537,6 +548,8 @@ public class KeyguardViewMediator extends SystemUI {
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DISMISS_KEYGUARD_SECURELY_ACTION),
                android.Manifest.permission.CONTROL_KEYGUARD, null);
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(KEYGUARD_SERVICE_ACTION_STATE_CHANGE),
                android.Manifest.permission.CONTROL_KEYGUARD, null);

        mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);

@@ -773,6 +786,10 @@ public class KeyguardViewMediator extends SystemUI {
        return false;
    }

    public boolean isKeyguardBound() {
        return mKeyguardBound;
    }

    /**
     * A dream started.  We should lock after the usual screen-off lock timeout but only
     * if there is a secure lock pattern.
@@ -1213,6 +1230,10 @@ public class KeyguardViewMediator extends SystemUI {
                        mDismissSecurelyOnScreenOn = true;
                    }
                }
            } else if (KEYGUARD_SERVICE_ACTION_STATE_CHANGE.equals(intent.getAction())) {
                mKeyguardBound = intent.getBooleanExtra(KEYGUARD_SERVICE_EXTRA_ACTIVE, false);
                context.sendBroadcast(new Intent(LockscreenToggleTile.ACTION_APPLY_LOCKSCREEN_STATE)
                        .setPackage(context.getPackageName()));
            }
        }
    };
+13 −0
Original line number Diff line number Diff line
@@ -270,6 +270,15 @@ public class QSPanel extends ViewGroup {
        v.setVisibility(visibility);
    }

    private void setTileEnabled(View v, boolean enabled) {
        mHandler.obtainMessage(H.SET_TILE_ENABLED, enabled ? 1 : 0, 0, v).sendToTarget();
    }

    private void handleSetTileEnabled(View v, boolean enabled) {
        if (enabled == v.isEnabled()) return;
        v.setEnabled(enabled);
    }

    public void setTiles(Collection<QSTile<?>> tiles) {
        for (TileRecord record : mRecords) {
            removeView(record.tileView);
@@ -299,6 +308,7 @@ public class QSPanel extends ViewGroup {
                    visibility = INVISIBLE;
                }
                setTileVisibility(r.tileView, visibility);
                setTileEnabled(r.tileView, state.enabled);
                r.tileView.onStateChanged(state);
            }
            @Override
@@ -584,12 +594,15 @@ public class QSPanel extends ViewGroup {
    private class H extends Handler {
        private static final int SHOW_DETAIL = 1;
        private static final int SET_TILE_VISIBILITY = 2;
        private static final int SET_TILE_ENABLED = 3;
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == SHOW_DETAIL) {
                handleShowDetail((Record)msg.obj, msg.arg1 != 0);
            } else if (msg.what == SET_TILE_VISIBILITY) {
                handleSetTileVisibility((View)msg.obj, msg.arg1);
            } else if (msg.what == SET_TILE_ENABLED) {
                handleSetTileEnabled((View)msg.obj, msg.arg1 == 1);
            }
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -398,6 +398,7 @@ public abstract class QSTile<TState extends State> implements Listenable {

    public static class State {
        public boolean visible;
        public boolean enabled = true;
        public int iconId;
        public Icon icon;
        public String label;
@@ -409,6 +410,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
            if (other == null) throw new IllegalArgumentException();
            if (!other.getClass().equals(getClass())) throw new IllegalArgumentException();
            final boolean changed = other.visible != visible
                    || !Objects.equals(other.enabled, enabled)
                    || !Objects.equals(other.icon, icon)
                    || !Objects.equals(other.label, label)
                    || !Objects.equals(other.contentDescription, contentDescription)
@@ -416,6 +418,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
                    || !Objects.equals(other.dualLabelContentDescription,
                    dualLabelContentDescription);
            other.visible = visible;
            other.enabled = enabled;
            other.icon = icon;
            other.label = label;
            other.contentDescription = contentDescription;
@@ -432,6 +435,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
        protected StringBuilder toStringBuilder() {
            final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
            sb.append("visible=").append(visible);
            sb.append(",enabled=").append(enabled);
            sb.append(",icon=").append(icon);
            sb.append(",label=").append(label);
            sb.append(",contentDescription=").append(contentDescription);
+21 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
@@ -304,9 +306,20 @@ public class QSTileView extends ViewGroup {
            mDualLabel.setText(state.label);
            mDualLabel.setContentDescription(state.dualLabelContentDescription);
            mTopBackgroundView.setContentDescription(state.contentDescription);
            if (!Objects.equals(state.enabled, mDualLabel.isEnabled())) {
                mTopBackgroundView.setEnabled(state.enabled);
                mDualLabel.setEnabled(state.enabled);
                mDualLabel.setTextColor(mContext.getResources().getColor(state.enabled ?
                        R.color.qs_tile_text : R.color.qs_tile_text_disabled));
            }
        } else {
            mLabel.setText(state.label);
            setContentDescription(state.contentDescription);
            if (!Objects.equals(state.enabled, mLabel.isEnabled())) {
                mLabel.setEnabled(state.enabled);
                mLabel.setTextColor(mContext.getResources().getColor(state.enabled ?
                        R.color.qs_tile_text : R.color.qs_tile_text_disabled));
            }
        }
    }

@@ -324,6 +337,14 @@ public class QSTileView extends ViewGroup {
                }
            }
        }
        if (!Objects.equals(state.enabled, iv.isEnabled())) {
            iv.setEnabled(state.enabled);
            if (state.enabled) {
                iv.setColorFilter(null);
            } else {
                iv.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
            }
        }
    }

    public void onStateChanged(QSTile.State state) {
Loading