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

Commit c7ede61f authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Fix client tracking" into jb-mr2-dev

parents 43abdc48 c808a195
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -146,11 +146,6 @@ public final class WifiService extends IWifiManager.Stub {
     */
    private AsyncChannel mWifiStateMachineChannel;

    /**
     * Clients receiving asynchronous messages
     */
    private List<Messenger> mClients = new ArrayList<Messenger>();

    /**
     * Handles client connections
     */
@@ -168,7 +163,7 @@ public final class WifiService extends IWifiManager.Stub {
                        if (DBG) Slog.d(TAG, "New client listening to asynchronous messages");
                        // We track the clients by the Messenger
                        // since it is expected to be always available
                        mClients.add(msg.replyTo);
                        mTrafficPoller.addClient(msg.replyTo);
                    } else {
                        Slog.e(TAG, "Client connection failure, error=" + msg.arg1);
                    }
@@ -180,7 +175,7 @@ public final class WifiService extends IWifiManager.Stub {
                    } else {
                        if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
                    }
                    mClients.remove(msg.replyTo);
                    mTrafficPoller.removeClient(msg.replyTo);
                    break;
                }
                case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: {
@@ -270,7 +265,7 @@ public final class WifiService extends IWifiManager.Stub {
        mIdleIntent = PendingIntent.getBroadcast(mContext, IDLE_REQUEST, idleIntent, 0);

        mNotificationController = new WifiNotificationController(mContext, mWifiStateMachine);
        mTrafficPoller = new WifiTrafficPoller(mContext, mClients, mInterfaceName);
        mTrafficPoller = new WifiTrafficPoller(mContext, mInterfaceName);
        mSettingsStore = new WifiSettingsStore(mContext);

        mContext.registerReceiver(
+28 −11
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Message;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

@@ -45,6 +46,11 @@ final class WifiTrafficPoller {
     */
    private static final int POLL_TRAFFIC_STATS_INTERVAL_MSECS = 1000;

    private static final int ENABLE_TRAFFIC_STATS_POLL  = 1;
    private static final int TRAFFIC_STATS_POLL         = 2;
    private static final int ADD_CLIENT                 = 3;
    private static final int REMOVE_CLIENT              = 4;

    private boolean mEnableTrafficStatsPoll = false;
    private int mTrafficStatsPollToken = 0;
    private long mTxPkts;
@@ -52,7 +58,7 @@ final class WifiTrafficPoller {
    /* Tracks last reported data activity */
    private int mDataActivity;

    private final List<Messenger> mClients;
    private final List<Messenger> mClients = new ArrayList<Messenger>();
    // err on the side of updating at boot since screen on broadcast may be missed
    // the first time
    private AtomicBoolean mScreenOn = new AtomicBoolean(true);
@@ -60,8 +66,7 @@ final class WifiTrafficPoller {
    private NetworkInfo mNetworkInfo;
    private final String mInterface;

    WifiTrafficPoller(Context context, List<Messenger> clients, String iface) {
        mClients = clients;
    WifiTrafficPoller(Context context, String iface) {
        mInterface = iface;
        mTrafficHandler = new TrafficHandler();

@@ -88,28 +93,40 @@ final class WifiTrafficPoller {
                }, filter);
    }

    void addClient(Messenger client) {
        Message.obtain(mTrafficHandler, ADD_CLIENT, client).sendToTarget();
    }

    void removeClient(Messenger client) {
        Message.obtain(mTrafficHandler, REMOVE_CLIENT, client).sendToTarget();
    }


    private class TrafficHandler extends Handler {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case WifiManager.ENABLE_TRAFFIC_STATS_POLL: {
                case ENABLE_TRAFFIC_STATS_POLL:
                    mEnableTrafficStatsPoll = (msg.arg1 == 1);
                    mTrafficStatsPollToken++;
                    if (mEnableTrafficStatsPoll) {
                        notifyOnDataActivity();
                        sendMessageDelayed(Message.obtain(this, WifiManager.TRAFFIC_STATS_POLL,
                        sendMessageDelayed(Message.obtain(this, TRAFFIC_STATS_POLL,
                                mTrafficStatsPollToken, 0), POLL_TRAFFIC_STATS_INTERVAL_MSECS);
                    }
                    break;
                }
                case WifiManager.TRAFFIC_STATS_POLL: {
                case TRAFFIC_STATS_POLL:
                    if (msg.arg1 == mTrafficStatsPollToken) {
                        notifyOnDataActivity();
                        sendMessageDelayed(Message.obtain(this, WifiManager.TRAFFIC_STATS_POLL,
                        sendMessageDelayed(Message.obtain(this, TRAFFIC_STATS_POLL,
                                mTrafficStatsPollToken, 0), POLL_TRAFFIC_STATS_INTERVAL_MSECS);
                    }
                    break;
                }
                case ADD_CLIENT:
                    mClients.add((Messenger) msg.obj);
                    break;
                case REMOVE_CLIENT:
                    mClients.remove(msg.obj);
                    break;
            }

        }
@@ -120,10 +137,10 @@ final class WifiTrafficPoller {
        if (mNetworkInfo == null) return;
        if (mNetworkInfo.getDetailedState() == CONNECTED && mScreenOn.get()) {
            msg = Message.obtain(mTrafficHandler,
                    WifiManager.ENABLE_TRAFFIC_STATS_POLL, 1, 0);
                    ENABLE_TRAFFIC_STATS_POLL, 1, 0);
        } else {
            msg = Message.obtain(mTrafficHandler,
                    WifiManager.ENABLE_TRAFFIC_STATS_POLL, 0, 0);
                    ENABLE_TRAFFIC_STATS_POLL, 0, 0);
        }
        msg.sendToTarget();
    }
+0 −6
Original line number Diff line number Diff line
@@ -1145,12 +1145,6 @@ public class WifiManager {
    /** @hide */
    public static final int RSSI_PKTCNT_FETCH_FAILED        = BASE + 22;

    /* For system use only */
    /** @hide */
    public static final int ENABLE_TRAFFIC_STATS_POLL       = BASE + 31;
    /** @hide */
    public static final int TRAFFIC_STATS_POLL              = BASE + 32;


    /**
     * Passed with {@link ActionListener#onFailure}.