Fix leak in WifiManager
Avoid leaks from having a channel connection per manager instance Bug: 8254124 Change-Id: I2118ee1848aec9a8fb51a2ca8ee220152e4d1119
This commit is contained in:
@@ -149,7 +149,7 @@ public final class WifiService extends IWifiManager.Stub {
|
||||
/**
|
||||
* Clients receiving asynchronous messages
|
||||
*/
|
||||
private List<AsyncChannel> mClients = new ArrayList<AsyncChannel>();
|
||||
private List<Messenger> mClients = new ArrayList<Messenger>();
|
||||
|
||||
/**
|
||||
* Handles client connections
|
||||
@@ -166,7 +166,9 @@ public final class WifiService extends IWifiManager.Stub {
|
||||
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
|
||||
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
|
||||
if (DBG) Slog.d(TAG, "New client listening to asynchronous messages");
|
||||
mClients.add((AsyncChannel) msg.obj);
|
||||
// We track the clients by the Messenger
|
||||
// since it is expected to be always available
|
||||
mClients.add(msg.replyTo);
|
||||
} else {
|
||||
Slog.e(TAG, "Client connection failure, error=" + msg.arg1);
|
||||
}
|
||||
@@ -178,7 +180,7 @@ public final class WifiService extends IWifiManager.Stub {
|
||||
} else {
|
||||
if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
|
||||
}
|
||||
mClients.remove((AsyncChannel) msg.obj);
|
||||
mClients.remove(msg.replyTo);
|
||||
break;
|
||||
}
|
||||
case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: {
|
||||
|
||||
@@ -24,6 +24,9 @@ import android.net.NetworkInfo;
|
||||
import static android.net.NetworkInfo.DetailedState.CONNECTED;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
@@ -49,7 +52,7 @@ final class WifiTrafficPoller {
|
||||
/* Tracks last reported data activity */
|
||||
private int mDataActivity;
|
||||
|
||||
private final List<AsyncChannel> mClients;
|
||||
private final List<Messenger> mClients;
|
||||
// err on the side of updating at boot since screen on broadcast may be missed
|
||||
// the first time
|
||||
private AtomicBoolean mScreenOn = new AtomicBoolean(true);
|
||||
@@ -57,7 +60,7 @@ final class WifiTrafficPoller {
|
||||
private NetworkInfo mNetworkInfo;
|
||||
private final String mInterface;
|
||||
|
||||
WifiTrafficPoller(Context context, List<AsyncChannel> clients, String iface) {
|
||||
WifiTrafficPoller(Context context, List<Messenger> clients, String iface) {
|
||||
mClients = clients;
|
||||
mInterface = iface;
|
||||
mTrafficHandler = new TrafficHandler();
|
||||
@@ -145,8 +148,16 @@ final class WifiTrafficPoller {
|
||||
|
||||
if (dataActivity != mDataActivity && mScreenOn.get()) {
|
||||
mDataActivity = dataActivity;
|
||||
for (AsyncChannel client : mClients) {
|
||||
client.sendMessage(WifiManager.DATA_ACTIVITY_NOTIFICATION, mDataActivity);
|
||||
for (Messenger client : mClients) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = WifiManager.DATA_ACTIVITY_NOTIFICATION;
|
||||
msg.arg1 = mDataActivity;
|
||||
try {
|
||||
client.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
// Failed to reach, skip
|
||||
// Client removal is handled in WifiService
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user