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

Commit d115b75c authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Add support for BooleanState in CustomTile"

parents fa11d589 05843f07
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41917,6 +41917,7 @@ package android.service.quicksettings {
    field public static final String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
    field public static final String ACTION_QS_TILE_PREFERENCES = "android.service.quicksettings.action.QS_TILE_PREFERENCES";
    field public static final String META_DATA_ACTIVE_TILE = "android.service.quicksettings.ACTIVE_TILE";
    field public static final String META_DATA_BOOLEAN_TILE = "android.service.quicksettings.BOOLEAN_TILE";
  }
}
+20 −2
Original line number Diff line number Diff line
@@ -125,12 +125,30 @@ public class TileService extends Service {
    public static final String META_DATA_ACTIVE_TILE
            = "android.service.quicksettings.ACTIVE_TILE";

    /**
     * Meta-data for a tile to support {@code BooleanState}.
     * <p>
     * BooleanState is for tiles that should support switch tile behavior in accessibility. This is
     * the behavior of most of the framework tiles.
     *
     * To make a TileService support BooleanState, set this meta-data to true on the TileService's
     * manifest declaration.
     * <pre class="prettyprint">
     * {@literal
     * <meta-data android:name="android.service.quicksettings.BOOLEAN_TILE"
     *      android:value="true" />
     * }
     * </pre>
     */
    public static final String META_DATA_BOOLEAN_TILE =
            "android.service.quicksettings.BOOLEAN_TILE";

    /**
     * Used to notify SysUI that Listening has be requested.
     * @hide
     */
    public static final String ACTION_REQUEST_LISTENING
            = "android.service.quicksettings.action.REQUEST_LISTENING";
    public static final String ACTION_REQUEST_LISTENING =
            "android.service.quicksettings.action.REQUEST_LISTENING";

    /**
     * @hide
+2 −0
Original line number Diff line number Diff line
@@ -186,6 +186,8 @@ public interface QSTile {
            return toStringBuilder().toString();
        }

        // Used in dumps to determine current state of a tile.
        // This string may be used for CTS testing of tiles, so removing elements is discouraged.
        protected StringBuilder toStringBuilder() {
            final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
            sb.append(",icon=").append(icon);
+16 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.text.format.DateUtils;
import android.util.Log;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
import android.widget.Switch;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
@@ -82,6 +83,11 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
        mTile = new Tile();
        updateDefaultTileAndIcon();
        mServiceManager = host.getTileServices().getTileWrapper(this);
        if (mServiceManager.isBooleanTile()) {
            // Replace states with BooleanState
            resetStates();
        }

        mService = mServiceManager.getTileService();
        mServiceManager.setTileChangeListener(this);
        mUser = ActivityManager.getCurrentUser();
@@ -246,8 +252,10 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener

    @Override
    public State newTileState() {
        State state = new State();
        return state;
        if (mServiceManager != null && mServiceManager.isBooleanTile()) {
            return new BooleanState();
        }
        return new State();
    }

    @Override
@@ -336,6 +344,12 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener
        } else {
            state.contentDescription = state.label;
        }

        if (state instanceof BooleanState) {
            state.expandedAccessibilityClassName = Switch.class.getName();
            ((BooleanState) state).value = (state.state == Tile.STATE_ACTIVE);
        }

    }

    @Override
+18 −0
Original line number Diff line number Diff line
@@ -130,6 +130,24 @@ public class TileLifecycleManager extends BroadcastReceiver implements
        }
    }

    /**
     * Determines whether the associated TileService is a Boolean Tile.
     *
     * @return true if {@link TileService#META_DATA_BOOLEAN_TILE} is set to {@code true} for this
     *         tile
     * @see TileService#META_DATA_BOOLEAN_TILE
     */
    public boolean isBooleanTile() {
        try {
            ServiceInfo info = mPackageManagerAdapter.getServiceInfo(mIntent.getComponent(),
                    PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_META_DATA);
            return info.metaData != null
                    && info.metaData.getBoolean(TileService.META_DATA_BOOLEAN_TILE, false);
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }

    /**
     * Binds just long enough to send any queued messages, then unbinds.
     */
Loading