summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Etan Cohen <etancohen@google.com> 2017-06-20 13:41:15 -0700
committer Etan Cohen <etancohen@google.com> 2017-06-22 18:26:07 +0000
commit9304be6f80afa3fc7e467ff1107233004a3dbe5c (patch)
tree0ae7e588140ecb8a69c34bce475bcc7236bb8124
parenta2f661612dbc898b93a85b5ecb5a116c358ed8fa (diff)
[P2P] Eliminate separate storage of binders - a memory leak
A global storage of binders is replaced by attaching a binder to its corresponding channel. Bug: 62905652 Test: NonConcurrencyTest:test_*p2p* acts/sl4a tests passing Test: p2p/aware behavior verified using Settings app Change-Id: I08e8d8f5d56cfd81d078e74f3cf2ccc5d06f61e3
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pManager.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
index f596eef1bf21..0d4359e878d2 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -291,7 +291,6 @@ public class WifiP2pManager {
"android.net.wifi.p2p.CALLING_PACKAGE";
IWifiP2pManager mService;
- private final Map<Channel, Binder> mBinders = new HashMap<>();
private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER;
@@ -670,11 +669,12 @@ public class WifiP2pManager {
* by doing a call on {@link #initialize}
*/
public static class Channel {
- Channel(Context context, Looper looper, ChannelListener l) {
+ Channel(Context context, Looper looper, ChannelListener l, Binder binder) {
mAsyncChannel = new AsyncChannel();
mHandler = new P2pHandler(looper);
mChannelListener = l;
mContext = context;
+ mBinder = binder;
}
private final static int INVALID_LISTENER_KEY = 0;
private ChannelListener mChannelListener;
@@ -686,6 +686,8 @@ public class WifiP2pManager {
private final Object mListenerMapLock = new Object();
private int mListenerKey = 0;
+ /* package */ final Binder mBinder;
+
private AsyncChannel mAsyncChannel;
private P2pHandler mHandler;
Context mContext;
@@ -892,8 +894,8 @@ public class WifiP2pManager {
*/
public Channel initialize(Context srcContext, Looper srcLooper, ChannelListener listener) {
Binder binder = new Binder();
- Channel channel = initalizeChannel(srcContext, srcLooper, listener, getMessenger(binder));
- mBinders.put(channel, binder);
+ Channel channel = initalizeChannel(srcContext, srcLooper, listener, getMessenger(binder),
+ binder);
return channel;
}
@@ -903,14 +905,15 @@ public class WifiP2pManager {
*/
public Channel initializeInternal(Context srcContext, Looper srcLooper,
ChannelListener listener) {
- return initalizeChannel(srcContext, srcLooper, listener, getP2pStateMachineMessenger());
+ return initalizeChannel(srcContext, srcLooper, listener, getP2pStateMachineMessenger(),
+ null);
}
private Channel initalizeChannel(Context srcContext, Looper srcLooper, ChannelListener listener,
- Messenger messenger) {
+ Messenger messenger, Binder binder) {
if (messenger == null) return null;
- Channel c = new Channel(srcContext, srcLooper, listener);
+ Channel c = new Channel(srcContext, srcLooper, listener, binder);
if (c.mAsyncChannel.connectSync(srcContext, c.mHandler, messenger)
== AsyncChannel.STATUS_SUCCESSFUL) {
return c;
@@ -1428,8 +1431,9 @@ public class WifiP2pManager {
*/
public void close(Channel c) {
try {
- mService.close(mBinders.get(c));
- mBinders.remove(c);
+ if (c != null) {
+ mService.close(c.mBinder);
+ }
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}