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

Commit 28585cd4 authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

QS: Show # of clients connected to hotspot

Since we no longer post a notification showing that the wifi hotspot
is on and the # of connected clients, we now show the # of clients
connected in the label of the hotspot QS tile.

Change-Id: I9ed37b96db9b5b4320a7260524f69733ea70d030
parent fadfc45d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -252,4 +252,10 @@
    <!-- Notification which notifies user flashlight is enabled -->
    <string name="quick_settings_tile_flashlight_not_title">Flashlight is on</string>
    <string name="quick_settings_tile_flashlight_not_summary">Tap to turn off</string>

    <!-- Wi-Fi hotspot label when enabled -->
    <plurals name="wifi_hotspot_connected_clients_label">
        <item quantity="one">%1$d client</item>
        <item quantity="other">%1$d clients</item>
    </plurals>
</resources>
+28 −1
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiDevice;
import android.provider.Settings;

import com.android.internal.logging.MetricsLogger;
@@ -31,6 +34,8 @@ import com.android.systemui.qs.UsageTracker;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.HotspotController;

import java.util.List;

/** Quick settings tile: Hotspot **/
public class HotspotTile extends QSTile<QSTile.BooleanState> {

@@ -44,12 +49,15 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
    private final HotspotController mController;
    private final Callback mCallback = new Callback();
    private final UsageTracker mUsageTracker;
    private final ConnectivityManager mConnectivityManager;
    private boolean mListening;

    public HotspotTile(Host host) {
        super(host);
        mController = host.getHotspotController();
        mUsageTracker = newUsageTracker(host.getContext());
        mUsageTracker.setListening(true);
        mConnectivityManager = host.getContext().getSystemService(ConnectivityManager.class);
    }

    @Override
@@ -65,11 +73,16 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {

    @Override
    public void setListening(boolean listening) {
        if (mListening == listening) return;
        if (listening) {
            mController.addCallback(mCallback);
            mContext.registerReceiver(mTetherConnectStateChangedReceiver,
                    new IntentFilter(ConnectivityManager.TETHER_CONNECT_STATE_CHANGED));
        } else {
            mController.removeCallback(mCallback);
            mContext.unregisterReceiver(mTetherConnectStateChangedReceiver);
        }
        mListening = listening;
    }

    @Override
@@ -111,13 +124,20 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.visible = mController.isHotspotSupported() && mUsageTracker.isRecentlyUsed();
        state.label = mContext.getString(R.string.quick_settings_hotspot_label);

        if (arg instanceof Boolean) {
            state.value = (boolean) arg;
        } else {
            state.value = mController.isHotspotEnabled();
        }
        if (state.visible && state.value) {
            final List<WifiDevice> clients = mConnectivityManager.getTetherConnectedSta();
            final int count = clients != null ? clients.size() : 0;
            state.label = mContext.getResources().getQuantityString(
                    R.plurals.wifi_hotspot_connected_clients_label, count, count);
        } else {
            state.label = mContext.getString(R.string.quick_settings_hotspot_label);
        }
        state.icon = state.visible && state.value ? mEnable : mDisable;
    }

@@ -140,6 +160,13 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
                R.integer.days_to_show_hotspot_tile);
    }

    private BroadcastReceiver mTetherConnectStateChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            refreshState();
        }
    };

    private final class Callback implements HotspotController.Callback {
        @Override
        public void onHotspotChanged(boolean enabled) {