Unhide wifi p2p API

Bug: 5247957
Change-Id: Id93e30c0cb60f361ba13a840de8f843415777336
This commit is contained in:
Irfan Sheriff
2011-09-07 00:31:20 -07:00
parent e0946eb270
commit 651cdfcbac
19 changed files with 640 additions and 435 deletions

View File

@@ -109,6 +109,7 @@ $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framew
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/media/audio/) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/media/audio/)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/nfc/) $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/nfc/)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/wifi/java) $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/wifi/java)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/wifi/java)
# ************************************************ # ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************ # ************************************************

View File

@@ -5118,6 +5118,7 @@ package android.content {
field public static final java.lang.String USB_SERVICE = "usb"; field public static final java.lang.String USB_SERVICE = "usb";
field public static final java.lang.String VIBRATOR_SERVICE = "vibrator"; field public static final java.lang.String VIBRATOR_SERVICE = "vibrator";
field public static final java.lang.String WALLPAPER_SERVICE = "wallpaper"; field public static final java.lang.String WALLPAPER_SERVICE = "wallpaper";
field public static final java.lang.String WIFI_P2P_SERVICE = "wifip2p";
field public static final java.lang.String WIFI_SERVICE = "wifi"; field public static final java.lang.String WIFI_SERVICE = "wifi";
field public static final java.lang.String WINDOW_SERVICE = "window"; field public static final java.lang.String WINDOW_SERVICE = "window";
} }
@@ -12444,6 +12445,142 @@ package android.net.wifi {
method public void setWorkSource(android.os.WorkSource); method public void setWorkSource(android.os.WorkSource);
} }
public class WpsInfo implements android.os.Parcelable {
ctor public WpsInfo();
ctor public WpsInfo(android.net.wifi.WpsInfo);
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
field public static final int DISPLAY = 1; // 0x1
field public static final int INVALID = 4; // 0x4
field public static final int KEYPAD = 2; // 0x2
field public static final int LABEL = 3; // 0x3
field public static final int PBC = 0; // 0x0
field public java.lang.String pin;
field public int setup;
}
}
package android.net.wifi.p2p {
public class WifiP2pConfig implements android.os.Parcelable {
ctor public WifiP2pConfig();
ctor public WifiP2pConfig(android.net.wifi.p2p.WifiP2pConfig);
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
field public java.lang.String deviceAddress;
field public int groupOwnerIntent;
field public android.net.wifi.WpsInfo wps;
}
public class WifiP2pDevice implements android.os.Parcelable {
ctor public WifiP2pDevice();
ctor public WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice);
method public int describeContents();
method public boolean isGroupOwner();
method public boolean isServiceDiscoveryCapable();
method public boolean wpsDisplaySupported();
method public boolean wpsKeypadSupported();
method public boolean wpsPbcSupported();
method public void writeToParcel(android.os.Parcel, int);
field public static final int AVAILABLE = 3; // 0x3
field public static final int CONNECTED = 0; // 0x0
field public static final android.os.Parcelable.Creator CREATOR;
field public static final int FAILED = 2; // 0x2
field public static final int INVITED = 1; // 0x1
field public static final int UNAVAILABLE = 4; // 0x4
field public java.lang.String deviceAddress;
field public java.lang.String deviceName;
field public java.lang.String primaryDeviceType;
field public java.lang.String secondaryDeviceType;
field public int status;
}
public class WifiP2pDeviceList implements android.os.Parcelable {
ctor public WifiP2pDeviceList();
ctor public WifiP2pDeviceList(android.net.wifi.p2p.WifiP2pDeviceList);
method public int describeContents();
method public java.util.Collection<android.net.wifi.p2p.WifiP2pDevice> getDeviceList();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
}
public class WifiP2pGroup implements android.os.Parcelable {
ctor public WifiP2pGroup();
ctor public WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup);
method public int describeContents();
method public java.util.Collection<android.net.wifi.p2p.WifiP2pDevice> getClientList();
method public java.lang.String getInterface();
method public java.lang.String getNetworkName();
method public android.net.wifi.p2p.WifiP2pDevice getOwner();
method public java.lang.String getPassphrase();
method public boolean isGroupOwner();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
}
public class WifiP2pInfo implements android.os.Parcelable {
ctor public WifiP2pInfo();
ctor public WifiP2pInfo(android.net.wifi.p2p.WifiP2pInfo);
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
field public boolean groupFormed;
field public java.net.InetAddress groupOwnerAddress;
field public boolean isGroupOwner;
}
public class WifiP2pManager {
method public void cancelConnect(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener);
method public void connect(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pConfig, android.net.wifi.p2p.WifiP2pManager.ActionListener);
method public void createGroup(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener);
method public void discoverPeers(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener);
method public android.net.wifi.p2p.WifiP2pManager.Channel initialize(android.content.Context, android.os.Looper, android.net.wifi.p2p.WifiP2pManager.ChannelListener);
method public void removeGroup(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener);
method public void requestConnectionInfo(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener);
method public void requestGroupInfo(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.GroupInfoListener);
method public void requestPeers(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.PeerListListener);
field public static final int BUSY = 2; // 0x2
field public static final int ERROR = 0; // 0x0
field public static final java.lang.String EXTRA_NETWORK_INFO = "networkInfo";
field public static final java.lang.String EXTRA_WIFI_P2P_DEVICE = "wifiP2pDevice";
field public static final java.lang.String EXTRA_WIFI_P2P_INFO = "wifiP2pInfo";
field public static final java.lang.String EXTRA_WIFI_STATE = "wifi_p2p_state";
field public static final int P2P_UNSUPPORTED = 1; // 0x1
field public static final java.lang.String WIFI_P2P_CONNECTION_CHANGED_ACTION = "android.net.wifi.p2p.CONNECTION_STATE_CHANGE";
field public static final java.lang.String WIFI_P2P_PEERS_CHANGED_ACTION = "android.net.wifi.p2p.PEERS_CHANGED";
field public static final java.lang.String WIFI_P2P_STATE_CHANGED_ACTION = "android.net.wifi.p2p.STATE_CHANGED";
field public static final int WIFI_P2P_STATE_DISABLED = 1; // 0x1
field public static final int WIFI_P2P_STATE_ENABLED = 2; // 0x2
field public static final java.lang.String WIFI_P2P_THIS_DEVICE_CHANGED_ACTION = "android.net.wifi.p2p.THIS_DEVICE_CHANGED";
}
public static abstract interface WifiP2pManager.ActionListener {
method public abstract void onFailure(int);
method public abstract void onSuccess();
}
public static class WifiP2pManager.Channel {
}
public static abstract interface WifiP2pManager.ChannelListener {
method public abstract void onChannelDisconnected();
}
public static abstract interface WifiP2pManager.ConnectionInfoListener {
method public abstract void onConnectionInfoAvailable(android.net.wifi.p2p.WifiP2pInfo);
}
public static abstract interface WifiP2pManager.GroupInfoListener {
method public abstract void onGroupInfoAvailable(android.net.wifi.p2p.WifiP2pGroup);
}
public static abstract interface WifiP2pManager.PeerListListener {
method public abstract void onPeersAvailable(android.net.wifi.p2p.WifiP2pDeviceList);
}
} }
package android.nfc { package android.nfc {

View File

@@ -1647,11 +1647,10 @@ public abstract class Context {
/** /**
* Use with {@link #getSystemService} to retrieve a {@link * Use with {@link #getSystemService} to retrieve a {@link
* android.net.wifi.p2p.WifiP2pManager} for handling management of * android.net.wifi.p2p.WifiP2pManager} for handling management of
* Wi-Fi p2p. * Wi-Fi peer-to-peer connections.
* *
* @see #getSystemService * @see #getSystemService
* @see android.net.wifi.p2p.WifiP2pManager * @see android.net.wifi.p2p.WifiP2pManager
* @hide
*/ */
public static final String WIFI_P2P_SERVICE = "wifip2p"; public static final String WIFI_P2P_SERVICE = "wifip2p";

View File

@@ -37,7 +37,7 @@ import android.net.wifi.WifiStateMachine;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiWatchdogStateMachine; import android.net.wifi.WifiWatchdogStateMachine;
import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.Wps; import android.net.wifi.WpsInfo;
import android.net.wifi.WpsResult; import android.net.wifi.WpsResult;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.DhcpInfo; import android.net.DhcpInfo;
@@ -288,7 +288,7 @@ public class WifiService extends IWifiManager.Stub {
} }
case WifiManager.CMD_START_WPS: { case WifiManager.CMD_START_WPS: {
//replyTo has the original source //replyTo has the original source
mWifiStateMachine.startWps(msg.replyTo, (Wps)msg.obj); mWifiStateMachine.startWps(msg.replyTo, (WpsInfo)msg.obj);
break; break;
} }
case WifiManager.CMD_DISABLE_NETWORK: { case WifiManager.CMD_DISABLE_NETWORK: {

View File

@@ -18,8 +18,6 @@ package android.net.wifi;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.Wps;
import android.net.wifi.WpsResult;
import android.net.wifi.ScanResult; import android.net.wifi.ScanResult;
import android.net.DhcpInfo; import android.net.DhcpInfo;

View File

@@ -397,7 +397,7 @@ class WifiConfigStore {
* Start WPS pin method configuration with pin obtained * Start WPS pin method configuration with pin obtained
* from the access point * from the access point
*/ */
static WpsResult startWpsWithPinFromAccessPoint(Wps config) { static WpsResult startWpsWithPinFromAccessPoint(WpsInfo config) {
WpsResult result = new WpsResult(); WpsResult result = new WpsResult();
if (WifiNative.startWpsWithPinFromAccessPointCommand(config.BSSID, config.pin)) { if (WifiNative.startWpsWithPinFromAccessPointCommand(config.BSSID, config.pin)) {
/* WPS leaves all networks disabled */ /* WPS leaves all networks disabled */
@@ -415,7 +415,7 @@ class WifiConfigStore {
* from the device * from the device
* @return WpsResult indicating status and pin * @return WpsResult indicating status and pin
*/ */
static WpsResult startWpsWithPinFromDevice(Wps config) { static WpsResult startWpsWithPinFromDevice(WpsInfo config) {
WpsResult result = new WpsResult(); WpsResult result = new WpsResult();
result.pin = WifiNative.startWpsWithPinFromDeviceCommand(config.BSSID); result.pin = WifiNative.startWpsWithPinFromDeviceCommand(config.BSSID);
/* WPS leaves all networks disabled */ /* WPS leaves all networks disabled */
@@ -432,7 +432,7 @@ class WifiConfigStore {
/** /**
* Start WPS push button configuration * Start WPS push button configuration
*/ */
static WpsResult startWpsPbc(Wps config) { static WpsResult startWpsPbc(WpsInfo config) {
WpsResult result = new WpsResult(); WpsResult result = new WpsResult();
if (WifiNative.startWpsPbcCommand(config.BSSID)) { if (WifiNative.startWpsPbcCommand(config.BSSID)) {
/* WPS leaves all networks disabled */ /* WPS leaves all networks disabled */
@@ -594,7 +594,7 @@ class WifiConfigStore {
sendConfiguredNetworksChangedBroadcast(); sendConfiguredNetworksChangedBroadcast();
} }
static void updateIpAndProxyFromWpsConfig(int netId, Wps wpsConfig) { static void updateIpAndProxyFromWpsConfig(int netId, WpsInfo wpsConfig) {
synchronized (sConfiguredNetworks) { synchronized (sConfiguredNetworks) {
WifiConfiguration config = sConfiguredNetworks.get(netId); WifiConfiguration config = sConfiguredNetworks.get(netId);
if (config != null) { if (config != null) {

View File

@@ -1175,7 +1175,7 @@ public class WifiManager {
* @param config WPS configuration * @param config WPS configuration
* @hide * @hide
*/ */
public void startWps(Wps config) { public void startWps(WpsInfo config) {
if (config == null) { if (config == null) {
return; return;
} }

View File

@@ -261,23 +261,23 @@ public class WifiNative {
public static String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) { public static String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) {
if (config == null) return null; if (config == null) return null;
List<String> args = new ArrayList<String>(); List<String> args = new ArrayList<String>();
Wps wps = config.wps; WpsInfo wps = config.wps;
args.add(config.deviceAddress); args.add(config.deviceAddress);
switch (wps.setup) { switch (wps.setup) {
case PBC: case WpsInfo.PBC:
args.add("pbc"); args.add("pbc");
break; break;
case DISPLAY: case WpsInfo.DISPLAY:
//TODO: pass the pin back for display //TODO: pass the pin back for display
args.add("pin"); args.add("pin");
args.add("display"); args.add("display");
break; break;
case KEYPAD: case WpsInfo.KEYPAD:
args.add(wps.pin); args.add(wps.pin);
args.add("keypad"); args.add("keypad");
break; break;
case LABEL: case WpsInfo.LABEL:
args.add(wps.pin); args.add(wps.pin);
args.add("label"); args.add("label");
default: default:
@@ -303,6 +303,10 @@ public class WifiNative {
return doStringCommand(command); return doStringCommand(command);
} }
public static boolean p2pCancelConnect() {
return doBooleanCommand("P2P_CANCEL");
}
public static boolean p2pGroupAdd() { public static boolean p2pGroupAdd() {
return doBooleanCommand("P2P_GROUP_ADD"); return doBooleanCommand("P2P_GROUP_ADD");
} }

View File

@@ -880,7 +880,7 @@ public class WifiStateMachine extends StateMachine {
sendMessage(message); sendMessage(message);
} }
public void startWps(Messenger replyTo, Wps config) { public void startWps(Messenger replyTo, WpsInfo config) {
Message msg = obtainMessage(CMD_START_WPS, config); Message msg = obtainMessage(CMD_START_WPS, config);
msg.replyTo = replyTo; msg.replyTo = replyTo;
sendMessage(msg); sendMessage(msg);

View File

@@ -1,5 +1,5 @@
/** /**
* Copyright (c) 2010, The Android Open Source Project * Copyright (c) 2011, The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,4 +16,4 @@
package android.net.wifi; package android.net.wifi;
parcelable Wps; parcelable WpsInfo;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2011 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -26,27 +26,24 @@ import java.util.BitSet;
/** /**
* A class representing Wi-Fi Protected Setup * A class representing Wi-Fi Protected Setup
* @hide
* *
* {@see WifiP2pConfig} * {@see WifiP2pConfig}
*/ */
public class Wps implements Parcelable { public class WpsInfo implements Parcelable {
/** Push button configuration */
public static final int PBC = 0;
/** Display pin method configuration - pin is generated and displayed on device */
public static final int DISPLAY = 1;
/** Keypad pin method configuration - pin is entered on device */
public static final int KEYPAD = 2;
/** Label pin method configuration - pin is labelled on device */
public static final int LABEL = 3;
/** Invalid configuration */
public static final int INVALID = 4;
/** Wi-Fi Protected Setup. www.wi-fi.org/wifi-protected-setup has details */ /** Wi-Fi Protected Setup. www.wi-fi.org/wifi-protected-setup has details */
public enum Setup { public int setup;
/* Push button configuration */
PBC,
/* Display pin method configuration - pin is generated and displayed on device */
DISPLAY,
/* Keypad pin method configuration - pin is entered on device */
KEYPAD,
/* Label pin method configuration - pin is obtained from a printed label */
LABEL,
/* Invalid config */
INVALID
}
public Setup setup;
/** @hide */ /** @hide */
public String BSSID; public String BSSID;
@@ -63,8 +60,8 @@ public class Wps implements Parcelable {
/** @hide */ /** @hide */
public LinkProperties linkProperties; public LinkProperties linkProperties;
public Wps() { public WpsInfo() {
setup = Setup.INVALID; setup = INVALID;
BSSID = null; BSSID = null;
pin = null; pin = null;
ipAssignment = IpAssignment.UNASSIGNED; ipAssignment = IpAssignment.UNASSIGNED;
@@ -72,10 +69,9 @@ public class Wps implements Parcelable {
linkProperties = new LinkProperties(); linkProperties = new LinkProperties();
} }
/** @hide */
public String toString() { public String toString() {
StringBuffer sbuf = new StringBuffer(); StringBuffer sbuf = new StringBuffer();
sbuf.append(" setup: ").append(setup.toString()); sbuf.append(" setup: ").append(setup);
sbuf.append('\n'); sbuf.append('\n');
sbuf.append(" BSSID: ").append(BSSID); sbuf.append(" BSSID: ").append(BSSID);
sbuf.append('\n'); sbuf.append('\n');
@@ -90,13 +86,13 @@ public class Wps implements Parcelable {
return sbuf.toString(); return sbuf.toString();
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
/** copy constructor {@hide} */ /* Copy constructor */
public Wps(Wps source) { public WpsInfo(WpsInfo source) {
if (source != null) { if (source != null) {
setup = source.setup; setup = source.setup;
BSSID = source.BSSID; BSSID = source.BSSID;
@@ -107,9 +103,9 @@ public class Wps implements Parcelable {
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(setup.name()); dest.writeInt(setup);
dest.writeString(BSSID); dest.writeString(BSSID);
dest.writeString(pin); dest.writeString(pin);
dest.writeString(ipAssignment.name()); dest.writeString(ipAssignment.name());
@@ -117,12 +113,12 @@ public class Wps implements Parcelable {
dest.writeParcelable(linkProperties, flags); dest.writeParcelable(linkProperties, flags);
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public static final Creator<Wps> CREATOR = public static final Creator<WpsInfo> CREATOR =
new Creator<Wps>() { new Creator<WpsInfo>() {
public Wps createFromParcel(Parcel in) { public WpsInfo createFromParcel(Parcel in) {
Wps config = new Wps(); WpsInfo config = new WpsInfo();
config.setup = Setup.valueOf(in.readString()); config.setup = in.readInt();
config.BSSID = in.readString(); config.BSSID = in.readString();
config.pin = in.readString(); config.pin = in.readString();
config.ipAssignment = IpAssignment.valueOf(in.readString()); config.ipAssignment = IpAssignment.valueOf(in.readString());
@@ -131,8 +127,8 @@ public class Wps implements Parcelable {
return config; return config;
} }
public Wps[] newArray(int size) { public WpsInfo[] newArray(int size) {
return new Wps[size]; return new WpsInfo[size];
} }
}; };
} }

View File

@@ -53,7 +53,7 @@ class WpsStateMachine extends StateMachine {
private WifiStateMachine mWifiStateMachine; private WifiStateMachine mWifiStateMachine;
private Wps mWpsConfig; private WpsInfo mWpsInfo;
private Context mContext; private Context mContext;
AsyncChannel mReplyChannel = new AsyncChannel(); AsyncChannel mReplyChannel = new AsyncChannel();
@@ -90,20 +90,20 @@ class WpsStateMachine extends StateMachine {
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
Wps wpsConfig; WpsInfo wpsConfig;
switch (message.what) { switch (message.what) {
case WifiStateMachine.CMD_START_WPS: case WifiStateMachine.CMD_START_WPS:
mWpsConfig = (Wps) message.obj; mWpsInfo = (WpsInfo) message.obj;
WpsResult result; WpsResult result;
switch (mWpsConfig.setup) { switch (mWpsInfo.setup) {
case PBC: case WpsInfo.PBC:
result = WifiConfigStore.startWpsPbc(mWpsConfig); result = WifiConfigStore.startWpsPbc(mWpsInfo);
break; break;
case KEYPAD: case WpsInfo.KEYPAD:
result = WifiConfigStore.startWpsWithPinFromAccessPoint(mWpsConfig); result = WifiConfigStore.startWpsWithPinFromAccessPoint(mWpsInfo);
break; break;
case DISPLAY: case WpsInfo.DISPLAY:
result = WifiConfigStore.startWpsWithPinFromDevice(mWpsConfig); result = WifiConfigStore.startWpsWithPinFromDevice(mWpsInfo);
break; break;
default: default:
result = new WpsResult(Status.FAILURE); result = new WpsResult(Status.FAILURE);
@@ -114,7 +114,7 @@ class WpsStateMachine extends StateMachine {
if (result.status == Status.SUCCESS) { if (result.status == Status.SUCCESS) {
transitionTo(mActiveState); transitionTo(mActiveState);
} else { } else {
Log.e(TAG, "Failed to start WPS with config " + mWpsConfig.toString()); Log.e(TAG, "Failed to start WPS with config " + mWpsInfo.toString());
} }
break; break;
case WifiStateMachine.CMD_RESET_WPS_STATE: case WifiStateMachine.CMD_RESET_WPS_STATE:
@@ -154,7 +154,7 @@ class WpsStateMachine extends StateMachine {
WifiConfigStore.enableAllNetworks(); WifiConfigStore.enableAllNetworks();
WifiConfigStore.loadConfiguredNetworks(); WifiConfigStore.loadConfiguredNetworks();
WifiConfigStore.updateIpAndProxyFromWpsConfig( WifiConfigStore.updateIpAndProxyFromWpsConfig(
stateChangeResult.networkId, mWpsConfig); stateChangeResult.networkId, mWpsInfo);
mWifiStateMachine.sendMessage(WifiStateMachine.WPS_COMPLETED_EVENT); mWifiStateMachine.sendMessage(WifiStateMachine.WPS_COMPLETED_EVENT);
transitionTo(mInactiveState); transitionTo(mInactiveState);
break; break;

View File

@@ -16,14 +16,12 @@
package android.net.wifi.p2p; package android.net.wifi.p2p;
import android.net.wifi.Wps; import android.net.wifi.WpsInfo;
import android.net.wifi.Wps.Setup;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.Parcel; import android.os.Parcel;
/** /**
* A class representing a Wi-Fi P2p configuration for setting up a connection * A class representing a Wi-Fi P2p configuration for setting up a connection
* @hide
* *
* {@see WifiP2pManager} * {@see WifiP2pManager}
*/ */
@@ -37,7 +35,7 @@ public class WifiP2pConfig implements Parcelable {
/** /**
* Wi-Fi Protected Setup information * Wi-Fi Protected Setup information
*/ */
public Wps wps; public WpsInfo wps;
/** /**
* This is an integer value between 0 and 15 where 0 indicates the least * This is an integer value between 0 and 15 where 0 indicates the least
@@ -63,8 +61,8 @@ public class WifiP2pConfig implements Parcelable {
public WifiP2pConfig() { public WifiP2pConfig() {
//set defaults //set defaults
wps = new Wps(); wps = new WpsInfo();
wps.setup = Setup.PBC; wps.setup = WpsInfo.PBC;
} }
/** P2P-GO-NEG-REQUEST 42:fc:89:a8:96:09 dev_passwd_id=4 {@hide}*/ /** P2P-GO-NEG-REQUEST 42:fc:89:a8:96:09 dev_passwd_id=4 {@hide}*/
@@ -76,7 +74,7 @@ public class WifiP2pConfig implements Parcelable {
} }
deviceAddress = tokens[1]; deviceAddress = tokens[1];
wps = new Wps(); wps = new WpsInfo();
if (tokens.length > 2) { if (tokens.length > 2) {
String[] nameVal = tokens[2].split("="); String[] nameVal = tokens[2].split("=");
@@ -89,25 +87,24 @@ public class WifiP2pConfig implements Parcelable {
//As defined in wps/wps_defs.h //As defined in wps/wps_defs.h
switch (devPasswdId) { switch (devPasswdId) {
case 0x00: case 0x00:
wps.setup = Setup.LABEL; wps.setup = WpsInfo.LABEL;
break; break;
case 0x01: case 0x01:
wps.setup = Setup.KEYPAD; wps.setup = WpsInfo.KEYPAD;
break; break;
case 0x04: case 0x04:
wps.setup = Setup.PBC; wps.setup = WpsInfo.PBC;
break; break;
case 0x05: case 0x05:
wps.setup = Setup.DISPLAY; wps.setup = WpsInfo.DISPLAY;
break; break;
default: default:
wps.setup = Setup.PBC; wps.setup = WpsInfo.PBC;
break; break;
} }
} }
} }
/** @hide */
public String toString() { public String toString() {
StringBuffer sbuf = new StringBuffer(); StringBuffer sbuf = new StringBuffer();
sbuf.append("\n address: ").append(deviceAddress); sbuf.append("\n address: ").append(deviceAddress);
@@ -117,19 +114,22 @@ public class WifiP2pConfig implements Parcelable {
return sbuf.toString(); return sbuf.toString();
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
/** copy constructor {@hide} */ /** copy constructor */
public WifiP2pConfig(WifiP2pConfig source) { public WifiP2pConfig(WifiP2pConfig source) {
if (source != null) { if (source != null) {
//TODO: implement deviceAddress = source.deviceAddress;
wps = new WpsInfo(source.wps);
groupOwnerIntent = source.groupOwnerIntent;
persist = source.persist;
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(deviceAddress); dest.writeString(deviceAddress);
dest.writeParcelable(wps, flags); dest.writeParcelable(wps, flags);
@@ -137,13 +137,13 @@ public class WifiP2pConfig implements Parcelable {
dest.writeString(persist.name()); dest.writeString(persist.name());
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public static final Creator<WifiP2pConfig> CREATOR = public static final Creator<WifiP2pConfig> CREATOR =
new Creator<WifiP2pConfig>() { new Creator<WifiP2pConfig>() {
public WifiP2pConfig createFromParcel(Parcel in) { public WifiP2pConfig createFromParcel(Parcel in) {
WifiP2pConfig config = new WifiP2pConfig(); WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = in.readString(); config.deviceAddress = in.readString();
config.wps = (Wps) in.readParcelable(null); config.wps = (WpsInfo) in.readParcelable(null);
config.groupOwnerIntent = in.readInt(); config.groupOwnerIntent = in.readInt();
config.persist = Persist.valueOf(in.readString()); config.persist = Persist.valueOf(in.readString());
return config; return config;

View File

@@ -24,7 +24,6 @@ import java.util.regex.Pattern;
/** /**
* A class representing a Wi-Fi p2p device * A class representing a Wi-Fi p2p device
* @hide
* *
* {@see WifiP2pManager} * {@see WifiP2pManager}
*/ */
@@ -109,18 +108,16 @@ public class WifiP2pDevice implements Parcelable {
*/ */
public int groupCapability; public int groupCapability;
public static final int CONNECTED = 0;
public static final int INVITED = 1;
public static final int FAILED = 2;
public static final int AVAILABLE = 3;
public static final int UNAVAILABLE = 4;
/** Device connection status */ /** Device connection status */
public enum Status { public int status = UNAVAILABLE;
CONNECTED,
INVITED,
FAILED,
AVAILABLE,
UNAVAILABLE,
}
public Status status = Status.UNAVAILABLE; public WifiP2pDevice() {
WifiP2pDevice() {
} }
/** /**
@@ -197,7 +194,7 @@ public class WifiP2pDevice implements Parcelable {
} }
if (tokens[0].startsWith("P2P-DEVICE-FOUND")) { if (tokens[0].startsWith("P2P-DEVICE-FOUND")) {
status = Status.AVAILABLE; status = AVAILABLE;
} }
} }
@@ -227,7 +224,6 @@ public class WifiP2pDevice implements Parcelable {
} }
@Override @Override
/** @hide */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) return true; if (this == obj) return true;
if (!(obj instanceof WifiP2pDevice)) return false; if (!(obj instanceof WifiP2pDevice)) return false;
@@ -239,7 +235,6 @@ public class WifiP2pDevice implements Parcelable {
return other.deviceAddress.equals(deviceAddress); return other.deviceAddress.equals(deviceAddress);
} }
/** @hide */
public String toString() { public String toString() {
StringBuffer sbuf = new StringBuffer(); StringBuffer sbuf = new StringBuffer();
sbuf.append("Device: ").append(deviceName); sbuf.append("Device: ").append(deviceName);
@@ -254,12 +249,12 @@ public class WifiP2pDevice implements Parcelable {
return sbuf.toString(); return sbuf.toString();
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
/** copy constructor {@hide} */ /** copy constructor */
public WifiP2pDevice(WifiP2pDevice source) { public WifiP2pDevice(WifiP2pDevice source) {
if (source != null) { if (source != null) {
deviceName = source.deviceName; deviceName = source.deviceName;
@@ -274,7 +269,7 @@ public class WifiP2pDevice implements Parcelable {
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(deviceName); dest.writeString(deviceName);
dest.writeString(deviceAddress); dest.writeString(deviceAddress);
@@ -284,10 +279,10 @@ public class WifiP2pDevice implements Parcelable {
dest.writeInt(wpsConfigMethodsSupported); dest.writeInt(wpsConfigMethodsSupported);
dest.writeInt(deviceCapability); dest.writeInt(deviceCapability);
dest.writeInt(groupCapability); dest.writeInt(groupCapability);
dest.writeString(status.name()); dest.writeInt(status);
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public static final Creator<WifiP2pDevice> CREATOR = public static final Creator<WifiP2pDevice> CREATOR =
new Creator<WifiP2pDevice>() { new Creator<WifiP2pDevice>() {
public WifiP2pDevice createFromParcel(Parcel in) { public WifiP2pDevice createFromParcel(Parcel in) {
@@ -300,7 +295,7 @@ public class WifiP2pDevice implements Parcelable {
device.wpsConfigMethodsSupported = in.readInt(); device.wpsConfigMethodsSupported = in.readInt();
device.deviceCapability = in.readInt(); device.deviceCapability = in.readInt();
device.groupCapability = in.readInt(); device.groupCapability = in.readInt();
device.status = Status.valueOf(in.readString()); device.status = in.readInt();
return device; return device;
} }

View File

@@ -27,7 +27,6 @@ import java.util.Collections;
/** /**
* A class representing a Wi-Fi P2p device list * A class representing a Wi-Fi P2p device list
* @hide
* *
* {@see WifiP2pManager} * {@see WifiP2pManager}
*/ */
@@ -35,11 +34,11 @@ public class WifiP2pDeviceList implements Parcelable {
private Collection<WifiP2pDevice> mDevices; private Collection<WifiP2pDevice> mDevices;
WifiP2pDeviceList() { public WifiP2pDeviceList() {
mDevices = new ArrayList<WifiP2pDevice>(); mDevices = new ArrayList<WifiP2pDevice>();
} }
/** copy constructor {@hide} */ /** copy constructor */
public WifiP2pDeviceList(WifiP2pDeviceList source) { public WifiP2pDeviceList(WifiP2pDeviceList source) {
if (source != null) { if (source != null) {
mDevices = source.getDeviceList(); mDevices = source.getDeviceList();
@@ -91,7 +90,6 @@ public class WifiP2pDeviceList implements Parcelable {
return Collections.unmodifiableCollection(mDevices); return Collections.unmodifiableCollection(mDevices);
} }
/** @hide */
public String toString() { public String toString() {
StringBuffer sbuf = new StringBuffer(); StringBuffer sbuf = new StringBuffer();
for (WifiP2pDevice device : mDevices) { for (WifiP2pDevice device : mDevices) {
@@ -100,12 +98,12 @@ public class WifiP2pDeviceList implements Parcelable {
return sbuf.toString(); return sbuf.toString();
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mDevices.size()); dest.writeInt(mDevices.size());
for(WifiP2pDevice device : mDevices) { for(WifiP2pDevice device : mDevices) {
@@ -113,7 +111,7 @@ public class WifiP2pDeviceList implements Parcelable {
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public static final Creator<WifiP2pDeviceList> CREATOR = public static final Creator<WifiP2pDeviceList> CREATOR =
new Creator<WifiP2pDeviceList>() { new Creator<WifiP2pDeviceList>() {
public WifiP2pDeviceList createFromParcel(Parcel in) { public WifiP2pDeviceList createFromParcel(Parcel in) {

View File

@@ -26,7 +26,6 @@ import java.util.Collections;
/** /**
* A class representing a Wi-Fi P2p group * A class representing a Wi-Fi P2p group
* @hide
* *
* {@see WifiP2pManager} * {@see WifiP2pManager}
*/ */
@@ -49,7 +48,7 @@ public class WifiP2pGroup implements Parcelable {
private String mInterface; private String mInterface;
WifiP2pGroup() { public WifiP2pGroup() {
} }
/** /**
@@ -202,7 +201,6 @@ public class WifiP2pGroup implements Parcelable {
return mInterface; return mInterface;
} }
/** @hide */
public String toString() { public String toString() {
StringBuffer sbuf = new StringBuffer(); StringBuffer sbuf = new StringBuffer();
sbuf.append("network: ").append(mNetworkName); sbuf.append("network: ").append(mNetworkName);
@@ -215,19 +213,24 @@ public class WifiP2pGroup implements Parcelable {
return sbuf.toString(); return sbuf.toString();
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
/** copy constructor {@hide} */ /** copy constructor */
// TODO: implement
public WifiP2pGroup(WifiP2pGroup source) { public WifiP2pGroup(WifiP2pGroup source) {
if (source != null) { if (source != null) {
mNetworkName = source.getNetworkName();
mOwner = new WifiP2pDevice(source.getOwner());
mIsGroupOwner = source.mIsGroupOwner;
for (WifiP2pDevice d : source.getClientList()) mClients.add(d);
mPassphrase = source.getPassphrase();
mInterface = source.getInterface();
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mNetworkName); dest.writeString(mNetworkName);
dest.writeParcelable(mOwner, flags); dest.writeParcelable(mOwner, flags);
@@ -240,7 +243,7 @@ public class WifiP2pGroup implements Parcelable {
dest.writeString(mInterface); dest.writeString(mInterface);
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public static final Creator<WifiP2pGroup> CREATOR = public static final Creator<WifiP2pGroup> CREATOR =
new Creator<WifiP2pGroup>() { new Creator<WifiP2pGroup>() {
public WifiP2pGroup createFromParcel(Parcel in) { public WifiP2pGroup createFromParcel(Parcel in) {

View File

@@ -24,7 +24,6 @@ import java.net.UnknownHostException;
/** /**
* A class representing connection information about a Wi-Fi p2p group * A class representing connection information about a Wi-Fi p2p group
* @hide
* *
* {@see WifiP2pManager} * {@see WifiP2pManager}
*/ */
@@ -39,11 +38,9 @@ public class WifiP2pInfo implements Parcelable {
/** Group owner address */ /** Group owner address */
public InetAddress groupOwnerAddress; public InetAddress groupOwnerAddress;
/** @hide */ public WifiP2pInfo() {
WifiP2pInfo() {
} }
/** @hide */
public String toString() { public String toString() {
StringBuffer sbuf = new StringBuffer(); StringBuffer sbuf = new StringBuffer();
sbuf.append("groupFormed: ").append(groupFormed) sbuf.append("groupFormed: ").append(groupFormed)
@@ -52,12 +49,12 @@ public class WifiP2pInfo implements Parcelable {
return sbuf.toString(); return sbuf.toString();
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
/** copy constructor {@hide} */ /** copy constructor */
public WifiP2pInfo(WifiP2pInfo source) { public WifiP2pInfo(WifiP2pInfo source) {
if (source != null) { if (source != null) {
groupFormed = source.groupFormed; groupFormed = source.groupFormed;
@@ -66,7 +63,7 @@ public class WifiP2pInfo implements Parcelable {
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(groupFormed ? (byte)1 : (byte)0); dest.writeByte(groupFormed ? (byte)1 : (byte)0);
dest.writeByte(isGroupOwner ? (byte)1 : (byte)0); dest.writeByte(isGroupOwner ? (byte)1 : (byte)0);
@@ -79,7 +76,7 @@ public class WifiP2pInfo implements Parcelable {
} }
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface */
public static final Creator<WifiP2pInfo> CREATOR = public static final Creator<WifiP2pInfo> CREATOR =
new Creator<WifiP2pInfo>() { new Creator<WifiP2pInfo>() {
public WifiP2pInfo createFromParcel(Parcel in) { public WifiP2pInfo createFromParcel(Parcel in) {

View File

@@ -24,6 +24,7 @@ import android.net.IConnectivityManager;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
@@ -34,26 +35,35 @@ import android.util.Log;
import com.android.internal.util.AsyncChannel; import com.android.internal.util.AsyncChannel;
import com.android.internal.util.Protocol; import com.android.internal.util.Protocol;
import java.util.HashMap;
/** /**
* This class provides the API for managing Wi-Fi peer-to-peer connectivity. This lets an * This class provides the API for managing Wi-Fi peer-to-peer connectivity. This lets an
* application discover available peers, setup connection to peers and query for the list of peers. * application discover available peers, setup connection to peers and query for the list of peers.
* When a p2p connection is formed over wifi, the device continues to maintain the uplink * When a p2p connection is formed over wifi, the device continues to maintain the uplink
* connection over mobile or any other available network for internet connectivity on the device. * connection over mobile or any other available network for internet connectivity on the device.
* *
* <p> The API is asynchronous and response to a request from an application is sent in the form * <p> The API is asynchronous and responses to requests from an application are on listener
* of a {@link android.os.Message} on a {@link android.os.Handler} that needs to be initialized * callbacks provided by the application. The application needs to do an initialization with
* by the application right at the beginning before any p2p operations are performed via * {@link #initialize} before doing any p2p operation.
* {@link #initialize}.
* *
* <p> An application can request for the current list of peers using {@link #requestPeers}. The * <p> Application actions {@link #discoverPeers}, {@link #connect}, {@link #cancelConnect},
* {@link #RESPONSE_PEERS} message on the handler indicates that the peer list is available. * {@link #createGroup} and {@link #removeGroup} need a {@link ActionListener} instance for
* Use {@link #peersInResponse} to extract the peer device list upon the receiving the * receiving callbacks {@link ActionListener#onSuccess} or {@link ActionListener#onFailure}.
* {@link #RESPONSE_PEERS} message. * Action callbacks indicate whether the initiation of the action was a success or a failure.
* Upon failure, the reason of failure can be one of {@link #ERROR}, {@link #P2P_UNSUPPORTED}
* or {@link #BUSY}.
* *
* <p> If an application needs to initiate a discovery, use {@link #discoverPeers} and listen * <p> An application can initiate discovery of peers with {@link #discoverPeers}. An initiated
* to {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent action to initiate a request to fetch * discovery request from an application stays active until the device starts connecting to a peer
* list of peers with {@link #requestPeers}. An initiated discovery request from an application * or forms a p2p group. The {@link ActionListener} callbacks provide feedback on whether the
* stays active until the device starts connecting to a peer or forms a p2p group. * discovery initiation was successful or failure. Additionally, applications can listen
* to {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent action to know when the peer list changes.
*
* <p> When the peer list change intent {@link #WIFI_P2P_PEERS_CHANGED_ACTION} is received
* or when an application needs to fetch the current list of peers, it can request the list
* of peers with {@link #requestPeers}. When the peer list is available
* {@link PeerListListener#onPeersAvailable} is called with the device list.
* *
* <p> An application can initiate a connection request to a peer through {@link #connect}. See * <p> An application can initiate a connection request to a peer through {@link #connect}. See
* {@link WifiP2pConfig} for details on setting up the configuration. For communication with legacy * {@link WifiP2pConfig} for details on setting up the configuration. For communication with legacy
@@ -61,9 +71,8 @@ import com.android.internal.util.Protocol;
* which creates an access point whose details can be fetched with {@link #requestGroupInfo}. * which creates an access point whose details can be fetched with {@link #requestGroupInfo}.
* *
* <p> After a successful group formation through {@link #createGroup} or through {@link #connect}, * <p> After a successful group formation through {@link #createGroup} or through {@link #connect},
* use {@link #requestConnectionInfo} to fetch the connection details. Connection information * use {@link #requestConnectionInfo} to fetch the connection details. The connection info
* can be obtained with {@link #connectionInfoInResponse} on a {@link #RESPONSE_CONNECTION_INFO} * {@link WifiP2pInfo} contains the address of the group owner
* message. The connection info {@link WifiP2pInfo} contains the address of the group owner
* {@link WifiP2pInfo#groupOwnerAddress} and a flag {@link WifiP2pInfo#isGroupOwner} to indicate * {@link WifiP2pInfo#groupOwnerAddress} and a flag {@link WifiP2pInfo#isGroupOwner} to indicate
* if the current device is a p2p group owner. A p2p client can thus communicate with * if the current device is a p2p group owner. A p2p client can thus communicate with
* the p2p group owner through a socket connection. * the p2p group owner through a socket connection.
@@ -85,10 +94,10 @@ import com.android.internal.util.Protocol;
* {@see WifiP2pGroup} * {@see WifiP2pGroup}
* {@see WifiP2pDevice} * {@see WifiP2pDevice}
* {@see WifiP2pDeviceList} * {@see WifiP2pDeviceList}
* {@see android.net.wifi.Wps} * {@see android.net.wifi.WpsInfo}
* @hide
*/ */
public class WifiP2pManager { public class WifiP2pManager {
private static final String TAG = "WifiP2pManager";
/** /**
* Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled. An * Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled. An
* extra {@link #EXTRA_WIFI_STATE} provides the state information as int. * extra {@link #EXTRA_WIFI_STATE} provides the state information as int.
@@ -97,7 +106,7 @@ public class WifiP2pManager {
*/ */
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_STATE_CHANGED_ACTION = public static final String WIFI_P2P_STATE_CHANGED_ACTION =
"android.net.wifi.P2P_STATE_CHANGED"; "android.net.wifi.p2p.STATE_CHANGED";
/** /**
* The lookup key for an int that indicates whether Wi-Fi p2p is enabled or disabled. * The lookup key for an int that indicates whether Wi-Fi p2p is enabled or disabled.
@@ -133,7 +142,7 @@ public class WifiP2pManager {
*/ */
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION = public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION =
"android.net.wifi.CONNECTION_STATE_CHANGE"; "android.net.wifi.p2p.CONNECTION_STATE_CHANGE";
/** /**
* The lookup key for a {@link android.net.wifi.p2p.WifiP2pInfo} object * The lookup key for a {@link android.net.wifi.p2p.WifiP2pInfo} object
@@ -170,27 +179,23 @@ public class WifiP2pManager {
*/ */
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_PEERS_CHANGED_ACTION = public static final String WIFI_P2P_PEERS_CHANGED_ACTION =
"android.net.wifi.PEERS_CHANGED"; "android.net.wifi.p2p.PEERS_CHANGED";
/** /**
* Activity Action: Pick a Wi-Fi p2p network to connect to. * Broadcast intent action indicating that this device details have changed.
* <p>Input: Nothing.
* <p>Output: Nothing.
* @hide
*/ */
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_PICK_WIFI_P2P_NETWORK = public static final String WIFI_P2P_THIS_DEVICE_CHANGED_ACTION =
"android.net.wifi.PICK_WIFI_P2P_NETWORK"; "android.net.wifi.p2p.THIS_DEVICE_CHANGED";
/**
* The lookup key for a {@link android.net.wifi.p2p.WifiP2pDevice} object
* Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
*/
public static final String EXTRA_WIFI_P2P_DEVICE = "wifiP2pDevice";
IWifiP2pManager mService; IWifiP2pManager mService;
/**
* Message {@link android.os.Message#what} sent on the application handler specified
* at {@link #initialize} indicating the asynchronous channel has disconnected. An
* application could choose to reconnect with {@link #initialize}
*/
public static final int HANDLER_DISCONNECTION = AsyncChannel.CMD_CHANNEL_DISCONNECTED;
private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER; private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER;
/** @hide */ /** @hide */
@@ -209,150 +214,59 @@ public class WifiP2pManager {
/** @hide */ /** @hide */
public static final int DISCOVER_PEERS = BASE + 7; public static final int DISCOVER_PEERS = BASE + 7;
/** @hide */
/**
* Message {@link android.os.Message#what} value indicating that the {@link #discoverPeers}
* operation failed.
* <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #ERROR}
* or {@link #BUSY}
*/
public static final int DISCOVER_PEERS_FAILED = BASE + 8; public static final int DISCOVER_PEERS_FAILED = BASE + 8;
/** /** @hide */
* Message {@link android.os.Message#what} value indicating that the {@link #discoverPeers}
* operation succeeded.
* <p> The application can register for {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent
* to listen for changes in the peer list as a result of the discovery process.
*/
public static final int DISCOVER_PEERS_SUCCEEDED = BASE + 9; public static final int DISCOVER_PEERS_SUCCEEDED = BASE + 9;
/** @hide */ /** @hide */
public static final int CONNECT = BASE + 10; public static final int CONNECT = BASE + 10;
/** @hide */
/**
* Message {@link android.os.Message#what} value indicating that the {@link #connect}
* operation failed.
* <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #ERROR}
* or {@link #BUSY}
*/
public static final int CONNECT_FAILED = BASE + 11; public static final int CONNECT_FAILED = BASE + 11;
/** /** @hide */
* Message {@link android.os.Message#what} value indicating that the {@link #connect}
* operation succeeded.
* <p> The application can register for {@link #WIFI_P2P_CONNECTION_CHANGED_ACTION} intent
* to listen for connectivity change as a result of the connect operation
*/
public static final int CONNECT_SUCCEEDED = BASE + 12; public static final int CONNECT_SUCCEEDED = BASE + 12;
/** @hide */ /** @hide */
public static final int CREATE_GROUP = BASE + 13; public static final int CANCEL_CONNECT = BASE + 13;
/** @hide */
/** public static final int CANCEL_CONNECT_FAILED = BASE + 14;
* Message {@link android.os.Message#what} value indicating that the {@link #createGroup} /** @hide */
* operation failed. public static final int CANCEL_CONNECT_SUCCEEDED = BASE + 15;
* <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #ERROR}
* or {@link #BUSY}
*/
public static final int CREATE_GROUP_FAILED = BASE + 14;
/**
* Message {@link android.os.Message#what} value indicating that the {@link #createGroup}
* operation succeeded.
* <p> The application can request the group details with {@link #requestGroupInfo}
*/
public static final int CREATE_GROUP_SUCCEEDED = BASE + 15;
/** @hide */ /** @hide */
public static final int REMOVE_GROUP = BASE + 16; public static final int CREATE_GROUP = BASE + 16;
/** /** @hide */
* Message {@link android.os.Message#what} value indicating that the {@link #removeGroup} public static final int CREATE_GROUP_FAILED = BASE + 17;
* operation failed. /** @hide */
* <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #ERROR} public static final int CREATE_GROUP_SUCCEEDED = BASE + 18;
* or {@link #BUSY}
*/
public static final int REMOVE_GROUP_FAILED = BASE + 17;
/**
* Message {@link android.os.Message#what} value indicating that the {@link #removeGroup}
* operation succeeded.
*/
public static final int REMOVE_GROUP_SUCCEEDED = BASE + 18;
/**
* Supported {@link android.os.Message#arg1} value on the following response messages:
* {@link #DISCOVER_PEERS_FAILED}, {@link #CONNECT_FAILED}, {@link #CREATE_GROUP_FAILED}
* and {@link #REMOVE_GROUP_FAILED}
*
* <p> This indicates that the operation failed due to an internal error
*/
public static final int ERROR = 0;
/**
* Supported {@link android.os.Message#arg1} value on the following response messages:
* {@link #DISCOVER_PEERS_FAILED}, {@link #CONNECT_FAILED}, {@link #CREATE_GROUP_FAILED}
* and {@link #REMOVE_GROUP_FAILED}
*
* <p> This indicates that the operation failed because p2p is unsupported on the
* device
*/
public static final int P2P_UNSUPPORTED = 1;
/**
* Supported {@link android.os.Message#arg1} value on the following response messages:
* {@link #DISCOVER_PEERS_FAILED}, {@link #CONNECT_FAILED}, {@link #CREATE_GROUP_FAILED}
* and {@link #REMOVE_GROUP_FAILED}
*
* <p> This indicates that the operation failed because the framework is busy and
* unable to service the request
*/
public static final int BUSY = 2;
/** @hide */ /** @hide */
public static final int REQUEST_PEERS = BASE + 19; public static final int REMOVE_GROUP = BASE + 19;
/** /** @hide */
* Message {@link android.os.Message#what} delivered on the application hander public static final int REMOVE_GROUP_FAILED = BASE + 20;
* in response to a {@link #requestPeers} call from the application. /** @hide */
* public static final int REMOVE_GROUP_SUCCEEDED = BASE + 21;
* <p> Extract a {@link WifiP2pDeviceList} object by calling {@link #peersInResponse}
* on the message object
*/
public static final int RESPONSE_PEERS = BASE + 20;
/** @hide */ /** @hide */
public static final int REQUEST_CONNECTION_INFO = BASE + 21; public static final int REQUEST_PEERS = BASE + 22;
/** @hide */
/** public static final int RESPONSE_PEERS = BASE + 23;
* Message {@link android.os.Message#what} delivered on the application hander
* in response to a {@link #requestConnectionInfo} call from the application.
*
* <p> Extract a {@link WifiP2pInfo} object by calling {@link #connectionInfoInResponse}
* on the message object
*/
public static final int RESPONSE_CONNECTION_INFO = BASE + 22;
/** @hide */ /** @hide */
public static final int REQUEST_GROUP_INFO = BASE + 23; public static final int REQUEST_CONNECTION_INFO = BASE + 24;
/** @hide */
/** public static final int RESPONSE_CONNECTION_INFO = BASE + 25;
* Message {@link android.os.Message#what} delivered on the application hander
* in response to a {@link #requestGroupInfo} call from the application.
*
* <p> Extract a {@link WifiP2pGroup} object by calling {@link #groupInfoInResponse}
* on the message object
*/
public static final int RESPONSE_GROUP_INFO = BASE + 24;
/** @hide */ /** @hide */
public static final int WPS_PBC = BASE + 25; public static final int REQUEST_GROUP_INFO = BASE + 26;
/** @hide */ /** @hide */
public static final int WPS_PIN = BASE + 26; public static final int RESPONSE_GROUP_INFO = BASE + 27;
/** @hide */
public static final int WPS_PIN_AVAILABLE = BASE + 27;
/** /**
* Create a new WifiP2pManager instance. Applications use * Create a new WifiP2pManager instance. Applications use
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
* the standard {@link android.content.Context#WIFI_P2P_SERVICE Context.WIFI_P2P_SERVICE}. * the standard {@link android.content.Context#WIFI_P2P_SERVICE Context.WIFI_P2P_SERVICE}.
* @param service the Binder interface * @param service the Binder interface
* @param handler target for messages
* @hide - hide this because it takes in a parameter of type IWifiP2pManager, which * @hide - hide this because it takes in a parameter of type IWifiP2pManager, which
* is a system private class. * is a system private class.
*/ */
@@ -361,38 +275,182 @@ public class WifiP2pManager {
} }
/** /**
* A channel that connects the application handler to the Wifi framework. * Passed with {@link ActionListener#onFailure}.
* Most p2p operations require a Channel as an argument. An instance of Channel is obtained * Indicates that the operation failed due to an internal error.
* by doing a call on {@link #initialize}
*/ */
public class Channel { public static final int ERROR = 0;
Channel(AsyncChannel c) {
mAsyncChannel = c; /**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation failed because p2p is unsupported on the device.
*/
public static final int P2P_UNSUPPORTED = 1;
/**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation failed because the framework is busy and
* unable to service the request
*/
public static final int BUSY = 2;
/** Interface for callback invocation when framework channel is lost */
public interface ChannelListener {
/**
* The channel to the framework has been disconnected.
* Application could try re-initializing using {@link #initialize}
*/
public void onChannelDisconnected();
} }
AsyncChannel mAsyncChannel;
/** Interface for callback invocation on an application action */
public interface ActionListener {
/** The operation succeeded */
public void onSuccess();
/**
* The operation failed
* @param reason The reason for failure could be one of {@link #P2P_UNSUPPORTED},
* {@link #ERROR} or {@link #BUSY}
*/
public void onFailure(int reason);
}
/** Interface for callback invocation when peer list is available */
public interface PeerListListener {
/**
* The requested peer list is available
* @param peers List of available peers
*/
public void onPeersAvailable(WifiP2pDeviceList peers);
}
/** Interface for callback invocation when connection info is available */
public interface ConnectionInfoListener {
/**
* The requested connection info is available
* @param info Wi-Fi p2p connection info
*/
public void onConnectionInfoAvailable(WifiP2pInfo info);
}
/** Interface for callback invocation when group info is available */
public interface GroupInfoListener {
/**
* The requested p2p group info is available
* @param group Wi-Fi p2p group info
*/
public void onGroupInfoAvailable(WifiP2pGroup group);
} }
/** /**
* Registers the application handler with the Wi-Fi framework. This function * A channel that connects the application to the Wifi p2p framework.
* Most p2p operations require a Channel as an argument. An instance of Channel is obtained
* by doing a call on {@link #initialize}
*/
public static class Channel {
Channel(Looper looper, ChannelListener l) {
mAsyncChannel = new AsyncChannel();
mHandler = new P2pHandler(looper);
mChannelListener = l;
}
private ChannelListener mChannelListener;
private HashMap<Integer, Object> mListenerMap = new HashMap<Integer, Object>();
private Object mListenerMapLock = new Object();
private int mListenerKey = 0;
AsyncChannel mAsyncChannel;
P2pHandler mHandler;
class P2pHandler extends Handler {
P2pHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message message) {
Object listener = getListener(message.arg2);
switch (message.what) {
case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
if (mChannelListener != null) {
mChannelListener.onChannelDisconnected();
mChannelListener = null;
}
break;
/* ActionListeners grouped together */
case WifiP2pManager.DISCOVER_PEERS_FAILED:
case WifiP2pManager.CONNECT_FAILED:
case WifiP2pManager.CANCEL_CONNECT_FAILED:
case WifiP2pManager.CREATE_GROUP_FAILED:
case WifiP2pManager.REMOVE_GROUP_FAILED:
if (listener != null) {
((ActionListener) listener).onFailure(message.arg1);
}
break;
/* ActionListeners grouped together */
case WifiP2pManager.DISCOVER_PEERS_SUCCEEDED:
case WifiP2pManager.CONNECT_SUCCEEDED:
case WifiP2pManager.CANCEL_CONNECT_SUCCEEDED:
case WifiP2pManager.CREATE_GROUP_SUCCEEDED:
case WifiP2pManager.REMOVE_GROUP_SUCCEEDED:
if (listener != null) {
((ActionListener) listener).onSuccess();
}
break;
case WifiP2pManager.RESPONSE_PEERS:
WifiP2pDeviceList peers = (WifiP2pDeviceList) message.obj;
if (listener != null) {
((PeerListListener) listener).onPeersAvailable(peers);
}
break;
case WifiP2pManager.RESPONSE_CONNECTION_INFO:
WifiP2pInfo wifiP2pInfo = (WifiP2pInfo) message.obj;
if (listener != null) {
((ConnectionInfoListener) listener).onConnectionInfoAvailable(wifiP2pInfo);
}
break;
case WifiP2pManager.RESPONSE_GROUP_INFO:
WifiP2pGroup group = (WifiP2pGroup) message.obj;
if (listener != null) {
((GroupInfoListener) listener).onGroupInfoAvailable(group);
}
break;
default:
Log.d(TAG, "Ignored " + message);
break;
}
}
}
int putListener(Object listener) {
if (listener == null) return 0;
int key;
synchronized (mListenerMapLock) {
key = mListenerKey++;
mListenerMap.put(key, listener);
}
return key;
}
Object getListener(int key) {
synchronized (mListenerMapLock) {
return mListenerMap.remove(key);
}
}
}
/**
* Registers the application with the Wi-Fi framework. This function
* must be the first to be called before any p2p operations are performed. * must be the first to be called before any p2p operations are performed.
* *
* <p class="note"><strong>Note:</strong>
* The handler registered with the framework should only handle messages
* with {@link android.os.Message#what} values defined in this file. Adding application
* specific private {@link android.os.Message#what} types should be done on a seperate handler
*
* @param srcContext is the context of the source * @param srcContext is the context of the source
* @param srcHandler is the handler on which the source will receive message responses * @param srcLooper is the Looper on which the callbacks are receivied
* asynchronously * @param listener for callback at loss of framework communication. Can be null.
* @return Channel instance that is necessary for performing any further p2p operations * @return Channel instance that is necessary for performing any further p2p operations
*/ */
public Channel initialize(Context srcContext, Handler srcHandler) { public Channel initialize(Context srcContext, Looper srcLooper, ChannelListener listener) {
Messenger messenger = getMessenger(); Messenger messenger = getMessenger();
if (messenger == null) return null; if (messenger == null) return null;
AsyncChannel asyncChannel = new AsyncChannel(); Channel c = new Channel(srcLooper, listener);
Channel c = new Channel(asyncChannel); if (c.mAsyncChannel.connectSync(srcContext, c.mHandler, messenger)
if (asyncChannel.connectSync(srcContext, srcHandler, messenger)
== AsyncChannel.STATUS_SUCCESSFUL) { == AsyncChannel.STATUS_SUCCESSFUL) {
return c; return c;
} else { } else {
@@ -425,30 +483,32 @@ public class WifiP2pManager {
* for the purpose of establishing a connection. * for the purpose of establishing a connection.
* *
* <p> The function call immediately returns after sending a discovery request * <p> The function call immediately returns after sending a discovery request
* to the framework. The application handler is notified of a success or failure to initiate * to the framework. The application is notified of a success or failure to initiate
* discovery with {@link #DISCOVER_PEERS_SUCCEEDED} or {@link #DISCOVER_PEERS_FAILED}. * discovery through listener callbacks {@link ActionListener#onSuccess} or
* {@link ActionListener#onFailure}.
* *
* <p> The discovery remains active until a connection is initiated or * <p> The discovery remains active until a connection is initiated or
* a p2p group is formed. Register for {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent to * a p2p group is formed. Register for {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent to
* determine when the framework notifies of a change as peers are discovered. * determine when the framework notifies of a change as peers are discovered.
* *
* <p> Upon receiving a {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent, an application * <p> Upon receiving a {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent, an application
* can request for the list of peers using {@link #requestPeers} which will deliver a * can request for the list of peers using {@link #requestPeers}.
* {@link #RESPONSE_PEERS} message on the application handler. The application can then *
* extract a {@link WifiP2pDeviceList} object by calling {@link #peersInResponse} * @param c is the channel created at {@link #initialize}
* on the message. * @param listener for callbacks on success or failure. Can be null.
*/ */
public void discoverPeers(Channel c) { public void discoverPeers(Channel c, ActionListener listener) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(DISCOVER_PEERS); c.mAsyncChannel.sendMessage(DISCOVER_PEERS, 0, c.putListener(listener));
} }
/** /**
* Start a p2p connection to a device with the specified configuration. * Start a p2p connection to a device with the specified configuration.
* *
* <p> The function call immediately returns after sending a connection request * <p> The function call immediately returns after sending a connection request
* to the framework. The application handler is notified of a success or failure to initiate * to the framework. The application is notified of a success or failure to initiate
* connectivity with {@link #CONNECT_SUCCEEDED} or {@link #CONNECT_FAILED}. * connect through listener callbacks {@link ActionListener#onSuccess} or
* {@link ActionListener#onFailure}.
* *
* <p> Register for {@link #WIFI_P2P_CONNECTION_CHANGED_ACTION} intent to * <p> Register for {@link #WIFI_P2P_CONNECTION_CHANGED_ACTION} intent to
* determine when the framework notifies of a change in connectivity. * determine when the framework notifies of a change in connectivity.
@@ -460,100 +520,102 @@ public class WifiP2pManager {
* a p2p group with {@link #createGroup}, an invitation to join the group is sent to * a p2p group with {@link #createGroup}, an invitation to join the group is sent to
* the peer device. * the peer device.
* *
* @param config options as described in {@link WifiP2pConfig} class. * @param c is the channel created at {@link #initialize}
* @param config options as described in {@link WifiP2pConfig} class
* @param listener for callbacks on success or failure. Can be null.
*/ */
public void connect(Channel c, WifiP2pConfig config) { public void connect(Channel c, WifiP2pConfig config, ActionListener listener) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(CONNECT, config); c.mAsyncChannel.sendMessage(CONNECT, 0, c.putListener(listener), config);
}
/**
* Cancel any ongoing p2p group negotiation
*
* <p> The function call immediately returns after sending a connection cancellation request
* to the framework. The application is notified of a success or failure to initiate
* cancellation through listener callbacks {@link ActionListener#onSuccess} or
* {@link ActionListener#onFailure}.
*
* @param c is the channel created at {@link #initialize}
* @param listener for callbacks on success or failure. Can be null.
*/
public void cancelConnect(Channel c, ActionListener listener) {
if (c == null) return;
c.mAsyncChannel.sendMessage(CANCEL_CONNECT, 0, c.putListener(listener));
} }
/** /**
* Create a p2p group with the current device as the group owner. This essentially creates * Create a p2p group with the current device as the group owner. This essentially creates
* an access point that can accept connections from legacy clients as well as other p2p * an access point that can accept connections from legacy clients as well as other p2p
* devices. * devices.
* <p> For p2p operation, this would normally not be used unless the current device needs *
* <p class="note"><strong>Note:</strong>
* This function would normally not be used unless the current device needs
* to form a p2p connection with a legacy client * to form a p2p connection with a legacy client
* *
* <p> The function call immediately returns after sending a group creation request * <p> The function call immediately returns after sending a group creation request
* to the framework. The application handler is notified of a success or failure to create * to the framework. The application is notified of a success or failure to initiate
* group with {@link #CREATE_GROUP_SUCCEEDED} or {@link #CREATE_GROUP_FAILED}. * group creation through listener callbacks {@link ActionListener#onSuccess} or
* {@link ActionListener#onFailure}.
* *
* <p> Application can request for the group details with {@link #requestGroupInfo} which will * <p> Application can request for the group details with {@link #requestGroupInfo}.
* deliver a {@link #RESPONSE_GROUP_INFO} message on the application handler. The application *
* can then extract a {@link WifiP2pGroup} object by calling {@link #groupInfoInResponse} * @param c is the channel created at {@link #initialize}
* on the message. * @param listener for callbacks on success or failure. Can be null.
*/ */
public void createGroup(Channel c) { public void createGroup(Channel c, ActionListener listener) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(CREATE_GROUP); c.mAsyncChannel.sendMessage(CREATE_GROUP, 0, c.putListener(listener));
} }
/** /**
* Remove the current p2p group. * Remove the current p2p group.
* *
* <p> The function call immediately returns after sending a group removal request * <p> The function call immediately returns after sending a group removal request
* to the framework. The application handler is notified of a success or failure to remove * to the framework. The application is notified of a success or failure to initiate
* a group with {@link #REMOVE_GROUP_SUCCEEDED} or {@link #REMOVE_GROUP_FAILED}. * group removal through listener callbacks {@link ActionListener#onSuccess} or
* {@link ActionListener#onFailure}.
*
* @param c is the channel created at {@link #initialize}
* @param listener for callbacks on success or failure. Can be null.
*/ */
public void removeGroup(Channel c) { public void removeGroup(Channel c, ActionListener listener) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(REMOVE_GROUP); c.mAsyncChannel.sendMessage(REMOVE_GROUP, 0, c.putListener(listener));
} }
/** /**
* Request the current list of peers. This returns a {@link #RESPONSE_PEERS} on the application * Request the current list of peers.
* handler. The {@link #RESPONSE_PEERS} message on the handler indicates that the peer list is *
* available. Use {@link #peersInResponse} to extract {@link WifiP2pDeviceList} from the message * @param c is the channel created at {@link #initialize}
* @param listener for callback when peer list is available. Can be null.
*/ */
public void requestPeers(Channel c) { public void requestPeers(Channel c, PeerListListener listener) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(REQUEST_PEERS); c.mAsyncChannel.sendMessage(REQUEST_PEERS, 0, c.putListener(listener));
} }
/** /**
* Upon receiving a {@link #RESPONSE_PEERS} on the application handler, an application * Request device connection info.
* can extract the peer device list using this function. *
* @param c is the channel created at {@link #initialize}
* @param listener for callback when connection info is available. Can be null.
*/ */
public WifiP2pDeviceList peersInResponse(Message msg) { public void requestConnectionInfo(Channel c, ConnectionInfoListener listener) {
return (WifiP2pDeviceList) msg.obj;
}
/**
* Request device connection info. This returns a {@link #RESPONSE_CONNECTION_INFO} on
* the application handler. The {@link #RESPONSE_CONNECTION_INFO} message on the handler
* indicates that connection info is available. Use {@link #connectionInfoInResponse} to
* extract {@link WifiP2pInfo} from the message.
*/
public void requestConnectionInfo(Channel c) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(REQUEST_CONNECTION_INFO); c.mAsyncChannel.sendMessage(REQUEST_CONNECTION_INFO, 0, c.putListener(listener));
} }
/** /**
* Upon receiving a {@link #RESPONSE_CONNECTION_INFO} on the application handler, an application * Request p2p group info.
* can extract the connection info using this function. *
* @param c is the channel created at {@link #initialize}
* @param listener for callback when group info is available. Can be null.
*/ */
public WifiP2pInfo connectionInfoInResponse(Message msg) { public void requestGroupInfo(Channel c, GroupInfoListener listener) {
return (WifiP2pInfo) msg.obj;
}
/**
* Request p2p group info. This returns a {@link #RESPONSE_GROUP_INFO} on
* the application handler. The {@link #RESPONSE_GROUP_INFO} message on the handler
* indicates that group info is available. Use {@link #groupInfoInResponse} to
* extract {@link WifiP2pGroup} from the message.
*/
public void requestGroupInfo(Channel c) {
if (c == null) return; if (c == null) return;
c.mAsyncChannel.sendMessage(REQUEST_GROUP_INFO); c.mAsyncChannel.sendMessage(REQUEST_GROUP_INFO, 0, c.putListener(listener));
}
/**
* Upon receiving a {@link #RESPONSE_GROUP_INFO} on the application handler, an application
* can extract the group info using this function.
*/
public WifiP2pGroup groupInfoInResponse(Message msg) {
return (WifiP2pGroup) msg.obj;
} }
/** /**
@@ -571,36 +633,4 @@ public class WifiP2pManager {
} }
} }
/**
* Setup DNS connectivity on the current process to the connected Wi-Fi p2p peers
*
* @return -1 on failure
* @hide
*/
public int startPeerCommunication() {
IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);
try {
return cm.startUsingNetworkFeature(ConnectivityManager.TYPE_WIFI, "p2p", new Binder());
} catch (RemoteException e) {
return -1;
}
}
/**
* Tear down connectivity to the connected Wi-Fi p2p peers
*
* @return -1 on failure
* @hide
*/
public int stopPeerCommunication() {
IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);
try {
return cm.stopUsingNetworkFeature(ConnectivityManager.TYPE_WIFI, "p2p");
} catch (RemoteException e) {
return -1;
}
}
} }

View File

@@ -41,9 +41,7 @@ import android.net.wifi.WifiManager;
import android.net.wifi.WifiMonitor; import android.net.wifi.WifiMonitor;
import android.net.wifi.WifiNative; import android.net.wifi.WifiNative;
import android.net.wifi.WifiStateMachine; import android.net.wifi.WifiStateMachine;
import android.net.wifi.Wps; import android.net.wifi.WpsInfo;
import android.net.wifi.Wps.Setup;
import android.net.wifi.p2p.WifiP2pDevice.Status;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.os.INetworkManagementService; import android.os.INetworkManagementService;
@@ -137,11 +135,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private static final int AIRPLANE_MODE_CHANGED = BASE + 6; private static final int AIRPLANE_MODE_CHANGED = BASE + 6;
/* Emergency callback mode */ /* Emergency callback mode */
private static final int EMERGENCY_CALLBACK_MODE = BASE + 7; private static final int EMERGENCY_CALLBACK_MODE = BASE + 7;
private static final int WPS_PBC = BASE + 8;
private static final int WPS_PIN = BASE + 9;
private final boolean mP2pSupported; private final boolean mP2pSupported;
private final String mDeviceType;
private String mDeviceName; private WifiP2pDevice mThisDevice = new WifiP2pDevice();
private String mDeviceAddress;
/* When a group has been explicitly created by an app, we persist the group /* When a group has been explicitly created by an app, we persist the group
* even after all clients have been disconnected until an explicit remove * even after all clients have been disconnected until an explicit remove
@@ -164,9 +163,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mP2pSupported = mContext.getPackageManager().hasSystemFeature( mP2pSupported = mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_WIFI_DIRECT); PackageManager.FEATURE_WIFI_DIRECT);
mDeviceType = mContext.getResources().getString( mThisDevice.primaryDeviceType = mContext.getResources().getString(
com.android.internal.R.string.config_wifi_p2p_device_type); com.android.internal.R.string.config_wifi_p2p_device_type);
mDeviceName = getDefaultDeviceName(); mThisDevice.deviceName = getDefaultDeviceName();
mP2pStateMachine = new P2pStateMachine(TAG, mP2pSupported); mP2pStateMachine = new P2pStateMachine(TAG, mP2pSupported);
mP2pStateMachine.start(); mP2pStateMachine.start();
@@ -350,6 +349,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.CONNECT_FAILED, replyToMessage(message, WifiP2pManager.CONNECT_FAILED,
WifiP2pManager.BUSY); WifiP2pManager.BUSY);
break; break;
case WifiP2pManager.CANCEL_CONNECT:
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
WifiP2pManager.BUSY);
break;
case WifiP2pManager.CREATE_GROUP: case WifiP2pManager.CREATE_GROUP:
replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED, replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
WifiP2pManager.BUSY); WifiP2pManager.BUSY);
@@ -410,6 +413,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.CONNECT_FAILED, replyToMessage(message, WifiP2pManager.CONNECT_FAILED,
WifiP2pManager.P2P_UNSUPPORTED); WifiP2pManager.P2P_UNSUPPORTED);
break; break;
case WifiP2pManager.CANCEL_CONNECT:
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
WifiP2pManager.P2P_UNSUPPORTED);
break;
case WifiP2pManager.CREATE_GROUP: case WifiP2pManager.CREATE_GROUP:
replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED, replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
WifiP2pManager.P2P_UNSUPPORTED); WifiP2pManager.P2P_UNSUPPORTED);
@@ -656,7 +663,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
break; break;
case WifiMonitor.P2P_DEVICE_FOUND_EVENT: case WifiMonitor.P2P_DEVICE_FOUND_EVENT:
WifiP2pDevice device = (WifiP2pDevice) message.obj; WifiP2pDevice device = (WifiP2pDevice) message.obj;
if (mDeviceAddress.equals(device.deviceAddress)) break; if (mThisDevice.deviceAddress.equals(device.deviceAddress)) break;
mPeers.update(device); mPeers.update(device);
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
break; break;
@@ -683,7 +690,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
// do nothing if p2pConnect did not return a pin // do nothing if p2pConnect did not return a pin
} }
} }
updateDeviceStatus(mSavedConnectConfig.deviceAddress, Status.INVITED); updateDeviceStatus(mSavedConnectConfig.deviceAddress, WifiP2pDevice.INVITED);
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED); replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
transitionTo(mGroupNegotiationState); transitionTo(mGroupNegotiationState);
@@ -706,7 +713,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
P2pStateMachine.this, mGroup.getInterface()); P2pStateMachine.this, mGroup.getInterface());
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP); mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
WifiP2pDevice groupOwner = mGroup.getOwner(); WifiP2pDevice groupOwner = mGroup.getOwner();
updateDeviceStatus(groupOwner.deviceAddress, Status.CONNECTED); updateDeviceStatus(groupOwner.deviceAddress, WifiP2pDevice.CONNECTED);
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
} }
transitionTo(mGroupCreatedState); transitionTo(mGroupCreatedState);
@@ -783,7 +790,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT: case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT: case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
if (DBG) logd(getName() + " go failure"); if (DBG) logd(getName() + " go failure");
updateDeviceStatus(mSavedConnectConfig.deviceAddress, Status.FAILED); updateDeviceStatus(mSavedConnectConfig.deviceAddress, WifiP2pDevice.FAILED);
mSavedConnectConfig = null; mSavedConnectConfig = null;
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
transitionTo(mInactiveState); transitionTo(mInactiveState);
@@ -791,7 +798,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case GROUP_NEGOTIATION_TIMED_OUT: case GROUP_NEGOTIATION_TIMED_OUT:
if (mGroupNegotiationTimeoutIndex == message.arg1) { if (mGroupNegotiationTimeoutIndex == message.arg1) {
if (DBG) logd("Group negotiation timed out"); if (DBG) logd("Group negotiation timed out");
updateDeviceStatus(mSavedConnectConfig.deviceAddress, Status.FAILED); updateDeviceStatus(mSavedConnectConfig.deviceAddress, WifiP2pDevice.FAILED);
mSavedConnectConfig = null; mSavedConnectConfig = null;
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
transitionTo(mInactiveState); transitionTo(mInactiveState);
@@ -802,6 +809,14 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED, replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED,
WifiP2pManager.BUSY); WifiP2pManager.BUSY);
break; break;
case WifiP2pManager.CANCEL_CONNECT:
if (WifiNative.p2pCancelConnect()) {
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
} else {
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
WifiP2pManager.ERROR);
}
break;
default: default:
return NOT_HANDLED; return NOT_HANDLED;
} }
@@ -815,6 +830,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
if (DBG) logd(getName()); if (DBG) logd(getName());
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null); mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
updateThisDevice(WifiP2pDevice.CONNECTED);
//DHCP server has already been started if I am a group owner //DHCP server has already been started if I am a group owner
if (mGroup.isGroupOwner()) { if (mGroup.isGroupOwner()) {
setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS); setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS);
@@ -832,7 +849,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
String deviceAddress = getDeviceAddress(interfaceAddress); String deviceAddress = getDeviceAddress(interfaceAddress);
if (deviceAddress != null) { if (deviceAddress != null) {
mGroup.addClient(deviceAddress); mGroup.addClient(deviceAddress);
updateDeviceStatus(deviceAddress, Status.CONNECTED); updateDeviceStatus(deviceAddress, WifiP2pDevice.CONNECTED);
if (DBG) logd(getName() + " ap sta connected"); if (DBG) logd(getName() + " ap sta connected");
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
} else { } else {
@@ -843,7 +860,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
interfaceAddress = (String) message.obj; interfaceAddress = (String) message.obj;
deviceAddress = getDeviceAddress(interfaceAddress); deviceAddress = getDeviceAddress(interfaceAddress);
if (deviceAddress != null) { if (deviceAddress != null) {
updateDeviceStatus(deviceAddress, Status.AVAILABLE); updateDeviceStatus(deviceAddress, WifiP2pDevice.AVAILABLE);
if (mGroup.removeClient(deviceAddress)) { if (mGroup.removeClient(deviceAddress)) {
if (DBG) logd("Removed client " + deviceAddress); if (DBG) logd("Removed client " + deviceAddress);
if (!mPersistGroup && mGroup.isClientListEmpty()) { if (!mPersistGroup && mGroup.isClientListEmpty()) {
@@ -888,7 +905,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
boolean changed = false; boolean changed = false;
for (WifiP2pDevice d : mPeers.getDeviceList()) { for (WifiP2pDevice d : mPeers.getDeviceList()) {
if (devices.contains(d) || mGroup.getOwner().equals(d)) { if (devices.contains(d) || mGroup.getOwner().equals(d)) {
d.status = Status.AVAILABLE; d.status = WifiP2pDevice.AVAILABLE;
changed = true; changed = true;
} }
} }
@@ -926,7 +943,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
WifiP2pConfig config = (WifiP2pConfig) message.obj; WifiP2pConfig config = (WifiP2pConfig) message.obj;
logd("Inviting device : " + config.deviceAddress); logd("Inviting device : " + config.deviceAddress);
if (WifiNative.p2pInvite(mGroup, config.deviceAddress)) { if (WifiNative.p2pInvite(mGroup, config.deviceAddress)) {
updateDeviceStatus(config.deviceAddress, Status.INVITED); updateDeviceStatus(config.deviceAddress, WifiP2pDevice.INVITED);
sendP2pPeersChangedBroadcast(); sendP2pPeersChangedBroadcast();
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED); replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
} else { } else {
@@ -947,10 +964,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiMonitor.P2P_GROUP_STARTED_EVENT: case WifiMonitor.P2P_GROUP_STARTED_EVENT:
Slog.e(TAG, "Duplicate group creation event notice, ignore"); Slog.e(TAG, "Duplicate group creation event notice, ignore");
break; break;
case WifiP2pManager.WPS_PBC: case WPS_PBC:
WifiNative.wpsPbc(); WifiNative.wpsPbc();
break; break;
case WifiP2pManager.WPS_PIN: case WPS_PIN:
WifiNative.wpsPin((String) message.obj); WifiNative.wpsPin((String) message.obj);
break; break;
default: default:
@@ -960,6 +977,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
} }
public void exit() { public void exit() {
updateThisDevice(WifiP2pDevice.AVAILABLE);
setWifiP2pInfoOnGroupTermination(); setWifiP2pInfoOnGroupTermination();
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null); mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null);
sendP2pConnectionChangedBroadcast(); sendP2pConnectionChangedBroadcast();
@@ -979,6 +997,13 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mContext.sendStickyBroadcast(intent); mContext.sendStickyBroadcast(intent);
} }
private void sendThisDeviceChangedBroadcast() {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE, new WifiP2pDevice(mThisDevice));
mContext.sendStickyBroadcast(intent);
}
private void sendP2pPeersChangedBroadcast() { private void sendP2pPeersChangedBroadcast() {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
@@ -1048,7 +1073,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private void notifyP2pGoNegotationRequest(WifiP2pConfig config) { private void notifyP2pGoNegotationRequest(WifiP2pConfig config) {
Resources r = Resources.getSystem(); Resources r = Resources.getSystem();
Wps wps = config.wps; WpsInfo wps = config.wps;
final View textEntryView = LayoutInflater.from(mContext) final View textEntryView = LayoutInflater.from(mContext)
.inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null); .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin); final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
@@ -1061,9 +1086,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
if (DBG) logd(getName() + " connect " + pin.getText()); if (DBG) logd(getName() + " connect " + pin.getText());
if (pin.getVisibility() == View.GONE) { if (pin.getVisibility() == View.GONE) {
mSavedGoNegotiationConfig.wps.setup = Setup.PBC; mSavedGoNegotiationConfig.wps.setup = WpsInfo.PBC;
} else { } else {
mSavedGoNegotiationConfig.wps.setup = Setup.KEYPAD; mSavedGoNegotiationConfig.wps.setup = WpsInfo.KEYPAD;
mSavedGoNegotiationConfig.wps.pin = pin.getText().toString(); mSavedGoNegotiationConfig.wps.pin = pin.getText().toString();
} }
sendMessage(WifiP2pManager.CONNECT, mSavedGoNegotiationConfig); sendMessage(WifiP2pManager.CONNECT, mSavedGoNegotiationConfig);
@@ -1079,7 +1104,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}) })
.create(); .create();
if (wps.setup == Setup.PBC) { if (wps.setup == WpsInfo.PBC) {
pin.setVisibility(View.GONE); pin.setVisibility(View.GONE);
dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message, dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
config.deviceAddress)); config.deviceAddress));
@@ -1104,7 +1129,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
.setPositiveButton(r.getString(R.string.ok), new OnClickListener() { .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (DBG) logd(getName() + " wps_pbc"); if (DBG) logd(getName() + " wps_pbc");
sendMessage(WifiP2pManager.WPS_PBC); sendMessage(WPS_PBC);
} }
}) })
.setNegativeButton(r.getString(R.string.cancel), null) .setNegativeButton(r.getString(R.string.cancel), null)
@@ -1130,7 +1155,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
.setPositiveButton(r.getString(R.string.ok), new OnClickListener() { .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (DBG) logd(getName() + " wps_pin"); if (DBG) logd(getName() + " wps_pin");
sendMessage(WifiP2pManager.WPS_PIN, pin.getText().toString()); sendMessage(WPS_PIN, pin.getText().toString());
} }
}) })
.setNegativeButton(r.getString(R.string.cancel), null) .setNegativeButton(r.getString(R.string.cancel), null)
@@ -1173,7 +1198,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
dialog.show(); dialog.show();
} }
private void updateDeviceStatus(String deviceAddress, Status status) { private void updateDeviceStatus(String deviceAddress, int status) {
for (WifiP2pDevice d : mPeers.getDeviceList()) { for (WifiP2pDevice d : mPeers.getDeviceList()) {
if (d.deviceAddress.equals(deviceAddress)) { if (d.deviceAddress.equals(deviceAddress)) {
d.status = status; d.status = status;
@@ -1218,28 +1243,50 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private void initializeP2pSettings() { private void initializeP2pSettings() {
WifiNative.setPersistentReconnect(true); WifiNative.setPersistentReconnect(true);
WifiNative.setDeviceName(mDeviceName); WifiNative.setDeviceName(mThisDevice.deviceName);
WifiNative.setDeviceType(mDeviceType); WifiNative.setDeviceType(mThisDevice.primaryDeviceType);
mDeviceAddress = WifiNative.p2pGetDeviceAddress(); mThisDevice.deviceAddress = WifiNative.p2pGetDeviceAddress();
if (DBG) Slog.d(TAG, "DeviceAddress: " + mDeviceAddress); updateThisDevice(WifiP2pDevice.AVAILABLE);
if (DBG) Slog.d(TAG, "DeviceAddress: " + mThisDevice.deviceAddress);
}
private void updateThisDevice(int status) {
mThisDevice.status = status;
sendThisDeviceChangedBroadcast();
} }
//State machine initiated requests can have replyTo set to null indicating //State machine initiated requests can have replyTo set to null indicating
//there are no recepients, we ignore those reply actions //there are no recepients, we ignore those reply actions
private void replyToMessage(Message msg, int what) { private void replyToMessage(Message msg, int what) {
if (msg.replyTo == null) return; if (msg.replyTo == null) return;
mReplyChannel.replyToMessage(msg, what); Message dstMsg = obtainMessage(msg);
dstMsg.what = what;
mReplyChannel.replyToMessage(msg, dstMsg);
} }
private void replyToMessage(Message msg, int what, int arg1) { private void replyToMessage(Message msg, int what, int arg1) {
if (msg.replyTo == null) return; if (msg.replyTo == null) return;
mReplyChannel.replyToMessage(msg, what, arg1); Message dstMsg = obtainMessage(msg);
dstMsg.what = what;
dstMsg.arg1 = arg1;
mReplyChannel.replyToMessage(msg, dstMsg);
} }
private void replyToMessage(Message msg, int what, Object obj) { private void replyToMessage(Message msg, int what, Object obj) {
if (msg.replyTo == null) return; if (msg.replyTo == null) return;
mReplyChannel.replyToMessage(msg, what, obj); Message dstMsg = obtainMessage(msg);
dstMsg.what = what;
dstMsg.obj = obj;
mReplyChannel.replyToMessage(msg, dstMsg);
}
/* arg2 on the source message has a hash code that needs to be retained in replies
* see WifiP2pManager for details */
private Message obtainMessage(Message srcMsg) {
Message msg = Message.obtain();
msg.arg2 = srcMsg.arg2;
return msg;
} }
private void logd(String s) { private void logd(String s) {