From af3022347f356d4dca278fabea2c72b90c372f63 Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Thu, 25 May 2017 11:06:40 -0700 Subject: [PATCH] [P2P] Add binder to service calls Bug: 33040182 Test: unit tests, run-time behavior Change-Id: Ic383efc858bb4454d99c98ab24365c63ad3e7f54 --- .../android/net/wifi/p2p/IWifiP2pManager.aidl | 3 +- .../android/net/wifi/p2p/WifiP2pManager.java | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl b/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl index 8b1cfaee81191..bfdd45d9f9b0f 100644 --- a/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl +++ b/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl @@ -25,8 +25,9 @@ import android.os.Messenger; */ interface IWifiP2pManager { - Messenger getMessenger(); + Messenger getMessenger(in IBinder binder); Messenger getP2pStateMachineMessenger(); + oneway void close(in IBinder binder); void setMiracastMode(int mode); void checkConfigureWifiDisplayPermission(); } diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java index 95d0a79bb28b6..7f085f71e99c1 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java @@ -28,6 +28,7 @@ import android.net.wifi.p2p.nsd.WifiP2pServiceRequest; import android.net.wifi.p2p.nsd.WifiP2pServiceResponse; import android.net.wifi.p2p.nsd.WifiP2pUpnpServiceInfo; import android.net.wifi.p2p.nsd.WifiP2pUpnpServiceResponse; +import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -290,6 +291,7 @@ public class WifiP2pManager { "android.net.wifi.p2p.CALLING_PACKAGE"; IWifiP2pManager mService; + private final Map mBinders = new HashMap<>(); private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER; @@ -889,7 +891,10 @@ public class WifiP2pManager { * @return Channel instance that is necessary for performing any further p2p operations */ public Channel initialize(Context srcContext, Looper srcLooper, ChannelListener listener) { - return initalizeChannel(srcContext, srcLooper, listener, getMessenger()); + Binder binder = new Binder(); + Channel channel = initalizeChannel(srcContext, srcLooper, listener, getMessenger(binder)); + mBinders.put(channel, binder); + return channel; } /** @@ -1385,12 +1390,14 @@ public class WifiP2pManager { * Get a reference to WifiP2pService handler. This is used to establish * an AsyncChannel communication with WifiService * + * @param binder A binder for the service to associate with this client. + * * @return Messenger pointing to the WifiP2pService handler * @hide */ - public Messenger getMessenger() { + public Messenger getMessenger(Binder binder) { try { - return mService.getMessenger(); + return mService.getMessenger(binder); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1411,6 +1418,23 @@ public class WifiP2pManager { } } + /** + * Close the current P2P connection and clean-up any configuration requested by the + * current app. Takes same action as taken when the app dies. + * + * @param c is the channel created at {@link #initialize} + * + * @hide + */ + public void close(Channel c) { + try { + mService.close(mBinders.get(c)); + mBinders.remove(c); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Get a handover request message for use in WFA NFC Handover transfer. * @hide