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

Commit af302234 authored by Etan Cohen's avatar Etan Cohen
Browse files

[P2P] Add binder to service calls

Bug: 33040182
Test: unit tests, run-time behavior
Change-Id: Ic383efc858bb4454d99c98ab24365c63ad3e7f54
parent cd8c82a1
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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();
}
+27 −3
Original line number Diff line number Diff line
@@ -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<Channel, Binder> 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