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

Commit e4071127 authored by Rohan Shah's avatar Rohan Shah
Browse files

[QS] Add secondary label to Hotspot tile

Added info to callback and leveraged WifiManager API to get the number
of connected devices. There's some minor state cleanup done and the
fire callback mechanism was slightly updated.

The secondary label is updated based on the connected devices & enabled
state.

Screenshot: https://screenshot.googleplex.com/jHMKmg2nO08

Test: manual
Bug:68058038
Change-Id: Iafcebd3476d2c13e25939b45e78f32a5bd24cb68
parent a14cde6e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -753,6 +753,11 @@
    <string name="quick_settings_tethering_label">Tethering</string>
    <!-- QuickSettings: Hotspot. [CHAR LIMIT=NONE] -->
    <string name="quick_settings_hotspot_label">Hotspot</string>
    <!-- QuickSettings: Hotspot: Secondary label for how many devices are connected to the hotspot [CHAR LIMIT=NONE] -->
    <plurals name="quick_settings_hotspot_num_devices">
        <item quantity="one">%d device</item>
        <item quantity="other">%d devices</item>
    </plurals>
    <!-- QuickSettings: Notifications [CHAR LIMIT=NONE] -->
    <string name="quick_settings_notifications_label">Notifications</string>
    <!-- QuickSettings: Flashlight [CHAR LIMIT=NONE] -->
+48 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.tiles;

import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
@@ -115,11 +116,19 @@ public class HotspotTile extends QSTileImpl<AirplaneBooleanState> {
        state.label = mContext.getString(R.string.quick_settings_hotspot_label);

        checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_TETHERING);
        if (arg instanceof Boolean) {
            state.value = (boolean) arg;

        final int numConnectedDevices;
        if (arg instanceof CallbackInfo) {
            CallbackInfo info = (CallbackInfo) arg;
            state.value = info.enabled;
            numConnectedDevices = info.numConnectedDevices;
        } else {
            state.value = mController.isHotspotEnabled();
            numConnectedDevices = mController.getNumConnectedDevices();
        }

        state.secondaryLabel = getSecondaryLabel(state.value, numConnectedDevices);

        state.icon = mEnabledStatic;
        state.isAirplaneMode = mAirplaneMode.getValue() != 0;
        state.isTransient = mController.isHotspotTransient();
@@ -133,6 +142,18 @@ public class HotspotTile extends QSTileImpl<AirplaneBooleanState> {
                : state.value || state.isTransient ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
    }

    @Nullable
    private String getSecondaryLabel(boolean enabled, int numConnectedDevices) {
        if (numConnectedDevices > 0 && enabled) {
            return mContext.getResources().getQuantityString(
                    R.plurals.quick_settings_hotspot_num_devices,
                    numConnectedDevices,
                    numConnectedDevices);
        }

        return null;
    }

    @Override
    public int getMetricsCategory() {
        return MetricsEvent.QS_HOTSPOT;
@@ -148,9 +169,30 @@ public class HotspotTile extends QSTileImpl<AirplaneBooleanState> {
    }

    private final class Callback implements HotspotController.Callback {
        final CallbackInfo mCallbackInfo = new CallbackInfo();

        @Override
        public void onHotspotChanged(boolean enabled) {
            refreshState(enabled);
        public void onHotspotChanged(boolean enabled, int numConnectedDevices) {
            mCallbackInfo.enabled = enabled;
            mCallbackInfo.numConnectedDevices = numConnectedDevices;
            refreshState(mCallbackInfo);
        }
    }

    /**
     * Holder for any hotspot state info that needs to passed from the callback to
     * {@link #handleUpdateState(State, Object)}.
     */
    protected static final class CallbackInfo {
        boolean enabled;
        int numConnectedDevices;

        @Override
        public String toString() {
            return new StringBuilder("CallbackInfo[")
                    .append("enabled=").append(enabled)
                    .append(",numConnectedDevices=").append(numConnectedDevices)
                    .append(']').toString();
        }
    }
    };
}
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ public class AutoTileManager {

    private final HotspotController.Callback mHotspotCallback = new Callback() {
        @Override
        public void onHotspotChanged(boolean enabled) {
        public void onHotspotChanged(boolean enabled, int numDevices) {
            if (mAutoTracker.isAdded(HOTSPOT)) return;
            if (enabled) {
                mHost.addTile(HOTSPOT);
+1 −1
Original line number Diff line number Diff line
@@ -665,7 +665,7 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,

    private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
        @Override
        public void onHotspotChanged(boolean enabled) {
        public void onHotspotChanged(boolean enabled, int numDevices) {
            mIconController.setIconVisibility(mSlotHotspot, enabled);
        }
    };
+4 −2
Original line number Diff line number Diff line
@@ -26,7 +26,9 @@ public interface HotspotController extends CallbackController<Callback>, Dumpabl
    void setHotspotEnabled(boolean enabled);
    boolean isHotspotSupported();

    public interface Callback {
        void onHotspotChanged(boolean enabled);
    int getNumConnectedDevices();

    interface Callback {
        void onHotspotChanged(boolean enabled, int numDevices);
    }
}
Loading