summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2011-11-29 14:52:18 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-11-29 14:52:18 -0800
commita5d24d42ff8b99383a8c3051b9459e5248cf8536 (patch)
tree6f74251da1e37ad992581d335159e2d2f03a0dbf /wifi
parentb7a4db0a53cff6162d6981f9657a2ac70925ad73 (diff)
parent618455f7e7255019c8cc08a734ba7c52b67a7dc8 (diff)
downloadframeworks_base-a5d24d42ff8b99383a8c3051b9459e5248cf8536.zip
frameworks_base-a5d24d42ff8b99383a8c3051b9459e5248cf8536.tar.gz
frameworks_base-a5d24d42ff8b99383a8c3051b9459e5248cf8536.tar.bz2
Merge "Redesign p2p around provision discovery"
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiMonitor.java20
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java30
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pConfig.java12
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDevice.java20
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java161
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java577
6 files changed, 543 insertions, 277 deletions
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java
index 2ccc8a2..80963a8 100644
--- a/wifi/java/android/net/wifi/WifiMonitor.java
+++ b/wifi/java/android/net/wifi/WifiMonitor.java
@@ -20,6 +20,7 @@ import android.net.NetworkInfo;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pGroup;
+import android.net.wifi.p2p.WifiP2pProvDiscEvent;
import android.net.wifi.StateChangeResult;
import android.os.Message;
import android.util.Log;
@@ -181,6 +182,10 @@ public class WifiMonitor {
pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
group_capab=0x0 */
private static final String P2P_PROV_DISC_PBC_REQ_STR = "P2P-PROV-DISC-PBC-REQ";
+
+ /* P2P-PROV-DISC-PBC-RESP 02:12:47:f2:5a:36 */
+ private static final String P2P_PROV_DISC_PBC_RSP_STR = "P2P-PROV-DISC-PBC-RESP";
+
/* P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
group_capab=0x0 */
@@ -233,8 +238,9 @@ public class WifiMonitor {
public static final int P2P_INVITATION_RECEIVED_EVENT = BASE + 31;
public static final int P2P_INVITATION_RESULT_EVENT = BASE + 32;
public static final int P2P_PROV_DISC_PBC_REQ_EVENT = BASE + 33;
- public static final int P2P_PROV_DISC_ENTER_PIN_EVENT = BASE + 34;
- public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 35;
+ public static final int P2P_PROV_DISC_PBC_RSP_EVENT = BASE + 34;
+ public static final int P2P_PROV_DISC_ENTER_PIN_EVENT = BASE + 35;
+ public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 36;
/* hostap events */
public static final int AP_STA_DISCONNECTED_EVENT = BASE + 41;
@@ -480,10 +486,16 @@ public class WifiMonitor {
mStateMachine.sendMessage(P2P_INVITATION_RESULT_EVENT, nameValue[1]);
} else if (dataString.startsWith(P2P_PROV_DISC_PBC_REQ_STR)) {
mStateMachine.sendMessage(P2P_PROV_DISC_PBC_REQ_EVENT,
- new WifiP2pDevice(dataString));
+ new WifiP2pProvDiscEvent(dataString));
+ } else if (dataString.startsWith(P2P_PROV_DISC_PBC_RSP_STR)) {
+ mStateMachine.sendMessage(P2P_PROV_DISC_PBC_RSP_EVENT,
+ new WifiP2pProvDiscEvent(dataString));
} else if (dataString.startsWith(P2P_PROV_DISC_ENTER_PIN_STR)) {
mStateMachine.sendMessage(P2P_PROV_DISC_ENTER_PIN_EVENT,
- new WifiP2pDevice(dataString));
+ new WifiP2pProvDiscEvent(dataString));
+ } else if (dataString.startsWith(P2P_PROV_DISC_SHOW_PIN_STR)) {
+ mStateMachine.sendMessage(P2P_PROV_DISC_SHOW_PIN_EVENT,
+ new WifiP2pProvDiscEvent(dataString));
}
}
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 6ff1bc2..65caa51 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -19,6 +19,7 @@ package android.net.wifi;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pGroup;
import android.net.wifi.p2p.WifiP2pDevice;
+import android.text.TextUtils;
import android.util.Log;
import java.io.InputStream;
@@ -234,6 +235,10 @@ public class WifiNative {
return WifiNative.doBooleanCommand("SET device_type " + type);
}
+ public static boolean setConfigMethods(String cfg) {
+ return WifiNative.doBooleanCommand("SET config_methods " + cfg);
+ }
+
public static boolean p2pFind() {
return doBooleanCommand("P2P_FIND");
}
@@ -273,8 +278,11 @@ public class WifiNative {
args.add("pbc");
break;
case WpsInfo.DISPLAY:
- //TODO: pass the pin back for display
- args.add("pin");
+ if (TextUtils.isEmpty(wps.pin)) {
+ args.add("pin");
+ } else {
+ args.add(wps.pin);
+ }
args.add("display");
break;
case WpsInfo.KEYPAD:
@@ -311,6 +319,24 @@ public class WifiNative {
return doBooleanCommand("P2P_CANCEL");
}
+ public static boolean p2pProvisionDiscovery(WifiP2pConfig config) {
+ if (config == null) return false;
+
+ switch (config.wps.setup) {
+ case WpsInfo.PBC:
+ return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " pbc");
+ case WpsInfo.DISPLAY:
+ //We are doing display, so provision discovery is keypad
+ return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " keypad");
+ case WpsInfo.KEYPAD:
+ //We are doing keypad, so provision discovery is display
+ return doBooleanCommand("P2P_PROV_DISC " + config.deviceAddress + " display");
+ default:
+ break;
+ }
+ return false;
+ }
+
public static boolean p2pGroupAdd() {
return doBooleanCommand("P2P_GROUP_ADD");
}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
index e0c1b13..6aea090 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
@@ -84,19 +84,19 @@ public class WifiP2pConfig implements Parcelable {
} catch (NumberFormatException e) {
devPasswdId = 0;
}
- //As defined in wps/wps_defs.h
+ //Based on definitions in wps/wps_defs.h
switch (devPasswdId) {
- case 0x00:
- wps.setup = WpsInfo.LABEL;
- break;
+ //DEV_PW_USER_SPECIFIED = 0x0001,
case 0x01:
- wps.setup = WpsInfo.KEYPAD;
+ wps.setup = WpsInfo.DISPLAY;
break;
+ //DEV_PW_PUSHBUTTON = 0x0004,
case 0x04:
wps.setup = WpsInfo.PBC;
break;
+ //DEV_PW_REGISTRAR_SPECIFIED = 0x0005
case 0x05:
- wps.setup = WpsInfo.DISPLAY;
+ wps.setup = WpsInfo.KEYPAD;
break;
default:
wps.setup = WpsInfo.PBC;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
index 1b0c301..b47e098 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
@@ -130,18 +130,6 @@ public class WifiP2pDevice implements Parcelable {
*
* fa:7b:7a:42:02:13
*
- * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
- * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
- * group_capab=0x0
- *
- * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
- * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
- * group_capab=0x0
- *
- * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27
- * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
- * group_capab=0x0
- *
* Note: The events formats can be looked up in the wpa_supplicant code
* @hide
*/
@@ -160,7 +148,13 @@ public class WifiP2pDevice implements Parcelable {
for (String token : tokens) {
String[] nameValue = token.split("=");
- if (nameValue.length != 2) continue;
+ if (nameValue.length != 2) {
+ //mac address without key is device address
+ if (token.matches("(([0-9a-f]{2}:){5}[0-9a-f]{2})")) {
+ deviceAddress = token;
+ }
+ continue;
+ }
if (nameValue[0].equals("p2p_dev_addr")) {
deviceAddress = nameValue[1];
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java b/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java
new file mode 100644
index 0000000..f70abe8
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.os.Parcelable;
+import android.os.Parcel;
+import android.util.Log;
+
+/**
+ * A class representing a Wi-Fi p2p provisional discovery request/response
+ * See {@link #WifiP2pProvDiscEvent} for supported types
+ *
+ * @hide
+ */
+public class WifiP2pProvDiscEvent {
+
+ private static final String TAG = "WifiP2pProvDiscEvent";
+
+ public static final int PBC_REQ = 1;
+ public static final int PBC_RSP = 2;
+ public static final int ENTER_PIN = 3;
+ public static final int SHOW_PIN = 4;
+
+ /* One of PBC_REQ, PBC_RSP, ENTER_PIN or SHOW_PIN */
+ public int event;
+
+ public WifiP2pDevice device;
+
+ /* Valid when event = SHOW_PIN */
+ public String pin;
+
+ public WifiP2pProvDiscEvent() {
+ device = new WifiP2pDevice();
+ }
+
+ /**
+ * @param string formats supported include
+ *
+ * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * P2P-PROV-DISC-PBC-RESP 02:12:47:f2:5a:36
+ *
+ * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * Note: The events formats can be looked up in the wpa_supplicant code
+ * @hide
+ */
+ public WifiP2pProvDiscEvent(String string) throws IllegalArgumentException {
+ String[] tokens = string.split(" ");
+
+ if (tokens.length < 2) {
+ throw new IllegalArgumentException("Malformed event " + string);
+ }
+
+ if (tokens[0].endsWith("PBC-REQ")) event = PBC_REQ;
+ else if (tokens[0].endsWith("PBC-RESP")) event = PBC_RSP;
+ else if (tokens[0].endsWith("ENTER-PIN")) event = ENTER_PIN;
+ else if (tokens[0].endsWith("SHOW-PIN")) event = SHOW_PIN;
+ else throw new IllegalArgumentException("Malformed event " + string);
+
+ device = new WifiP2pDevice();
+
+ for (String token : tokens) {
+ String[] nameValue = token.split("=");
+ if (nameValue.length != 2) {
+ //mac address without key is device address
+ if (token.matches("(([0-9a-f]{2}:){5}[0-9a-f]{2})")) {
+ device.deviceAddress = token;
+ } else if (token.matches("[0-9]+")) {
+ pin = token;
+ } else {
+ //ignore;
+ }
+ continue;
+ }
+
+ if (nameValue[0].equals("p2p_dev_addr")) {
+ device.deviceAddress = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("pri_dev_type")) {
+ device.primaryDeviceType = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("name")) {
+ device.deviceName = trimQuotes(nameValue[1]);
+ continue;
+ }
+
+ if (nameValue[0].equals("config_methods")) {
+ device.wpsConfigMethodsSupported = parseHex(nameValue[1]);
+ continue;
+ }
+
+ if (nameValue[0].equals("dev_capab")) {
+ device.deviceCapability = parseHex(nameValue[1]);
+ continue;
+ }
+
+ if (nameValue[0].equals("group_capab")) {
+ device.groupCapability = parseHex(nameValue[1]);
+ continue;
+ }
+ }
+ }
+
+ public String toString() {
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append(device);
+ sbuf.append("\n event: ").append(event);
+ sbuf.append("\n pin: ").append(pin);
+ return sbuf.toString();
+ }
+
+ private String trimQuotes(String str) {
+ str = str.trim();
+ if (str.startsWith("'") && str.endsWith("'")) {
+ return str.substring(1, str.length()-1);
+ }
+ return str;
+ }
+
+ //supported formats: 0x1abc, 0X1abc, 1abc
+ private int parseHex(String hexString) {
+ int num = 0;
+ if (hexString.startsWith("0x") || hexString.startsWith("0X")) {
+ hexString = hexString.substring(2);
+ }
+
+ try {
+ num = Integer.parseInt(hexString, 16);
+ } catch(NumberFormatException e) {
+ Log.e(TAG, "Failed to parse hex string " + hexString);
+ }
+ return num;
+ }
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index 6bb22a4..f7e79b3 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -52,11 +52,14 @@ import android.os.Messenger;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
+import android.text.TextUtils;
import android.util.Slog;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
+import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.telephony.TelephonyIntents;
@@ -81,7 +84,7 @@ import java.util.Collection;
*/
public class WifiP2pService extends IWifiP2pManager.Stub {
private static final String TAG = "WifiP2pService";
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
private static final String NETWORKTYPE = "WIFI_P2P";
private Context mContext;
@@ -100,9 +103,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private AsyncChannel mReplyChannel = new AsyncChannel();
private AsyncChannel mWifiChannel;
+ private static final Boolean JOIN_GROUP = true;
+ private static final Boolean FORM_GROUP = false;
+
/* Two minutes comes from the wpa_supplicant setting */
- private static final int GROUP_NEGOTIATION_WAIT_TIME_MS = 120 * 1000;
- private static int mGroupNegotiationTimeoutIndex = 0;
+ private static final int GROUP_CREATING_WAIT_TIME_MS = 120 * 1000;
+ private static int mGroupCreatingTimeoutIndex = 0;
/**
* Delay between restarts upon failure to setup connection with supplicant
@@ -123,30 +129,23 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
/* Message sent to WifiStateMachine to indicate Wi-Fi client/hotspot operation can proceed */
public static final int WIFI_ENABLE_PROCEED = BASE + 2;
- /* Delayed message to timeout of group negotiation */
- public static final int GROUP_NEGOTIATION_TIMED_OUT = BASE + 3;
+ /* Delayed message to timeout group creation */
+ public static final int GROUP_CREATING_TIMED_OUT = BASE + 3;
/* User accepted to disable Wi-Fi in order to enable p2p */
private static final int WIFI_DISABLE_USER_ACCEPT = BASE + 4;
/* User rejected to disable Wi-Fi in order to enable p2p */
private static final int WIFI_DISABLE_USER_REJECT = BASE + 5;
- /* User accepted a group negotiation request */
- private static final int GROUP_NEGOTIATION_USER_ACCEPT = BASE + 6;
- /* User rejected a group negotiation request */
- private static final int GROUP_NEGOTIATION_USER_REJECT = BASE + 7;
-
- /* User accepted a group invitation request */
- private static final int GROUP_INVITATION_USER_ACCEPT = BASE + 8;
- /* User rejected a group invitation request */
- private static final int GROUP_INVITATION_USER_REJECT = BASE + 9;
+ /* User accepted a peer request */
+ private static final int PEER_CONNECTION_USER_ACCEPT = BASE + 6;
+ /* User rejected a peer request */
+ private static final int PEER_CONNECTION_USER_REJECT = BASE + 7;
/* Airplane mode changed */
- private static final int AIRPLANE_MODE_CHANGED = BASE + 10;
+ private static final int AIRPLANE_MODE_CHANGED = BASE + 8;
/* Emergency callback mode */
- private static final int EMERGENCY_CALLBACK_MODE = BASE + 11;
- private static final int WPS_PBC = BASE + 12;
- private static final int WPS_PIN = BASE + 13;
+ private static final int EMERGENCY_CALLBACK_MODE = BASE + 9;
private final boolean mP2pSupported;
@@ -270,12 +269,14 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private P2pEnabledState mP2pEnabledState = new P2pEnabledState();
// Inactive is when p2p is enabled with no connectivity
private InactiveState mInactiveState = new InactiveState();
- private UserAuthorizingGroupNegotiationState mUserAuthorizingGroupNegotiationState
- = new UserAuthorizingGroupNegotiationState();
- private UserAuthorizingGroupInvitationState mUserAuthorizingGroupInvitationState
- = new UserAuthorizingGroupInvitationState();
+ private GroupCreatingState mGroupCreatingState = new GroupCreatingState();
+ private UserAuthorizingInvitationState mUserAuthorizingInvitationState
+ = new UserAuthorizingInvitationState();
+ private ProvisionDiscoveryState mProvisionDiscoveryState = new ProvisionDiscoveryState();
private GroupNegotiationState mGroupNegotiationState = new GroupNegotiationState();
+
private GroupCreatedState mGroupCreatedState = new GroupCreatedState();
+ private UserAuthorizingJoinState mUserAuthorizingJoinState = new UserAuthorizingJoinState();
private WifiMonitor mWifiMonitor = new WifiMonitor(this);
@@ -283,11 +284,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private WifiP2pInfo mWifiP2pInfo = new WifiP2pInfo();
private WifiP2pGroup mGroup;
- // Saved WifiP2pConfig from GO negotiation request
- private WifiP2pConfig mSavedGoNegotiationConfig;
-
- // Saved WifiP2pConfig from connect request
- private WifiP2pConfig mSavedConnectConfig;
+ // Saved WifiP2pConfig for a peer connection
+ private WifiP2pConfig mSavedPeerConfig;
// Saved WifiP2pGroup from invitation request
private WifiP2pGroup mSavedP2pGroup;
@@ -304,10 +302,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
addState(mP2pEnablingState, mDefaultState);
addState(mP2pEnabledState, mDefaultState);
addState(mInactiveState, mP2pEnabledState);
- addState(mUserAuthorizingGroupNegotiationState, mInactiveState);
- addState(mUserAuthorizingGroupInvitationState, mInactiveState);
- addState(mGroupNegotiationState, mP2pEnabledState);
+ addState(mGroupCreatingState, mP2pEnabledState);
+ addState(mUserAuthorizingInvitationState, mGroupCreatingState);
+ addState(mProvisionDiscoveryState, mGroupCreatingState);
+ addState(mGroupNegotiationState, mGroupCreatingState);
addState(mGroupCreatedState, mP2pEnabledState);
+ addState(mUserAuthorizingJoinState, mGroupCreatedState);
if (p2pSupported) {
setInitialState(mP2pDisabledState);
@@ -393,13 +393,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
sendMessage(WifiP2pManager.DISABLE_P2P);
break;
// Ignore
+ case WifiMonitor.P2P_INVITATION_RESULT_EVENT:
case WIFI_DISABLE_USER_ACCEPT:
case WIFI_DISABLE_USER_REJECT:
- case GROUP_NEGOTIATION_USER_ACCEPT:
- case GROUP_NEGOTIATION_USER_REJECT:
- case GROUP_INVITATION_USER_ACCEPT:
- case GROUP_INVITATION_USER_REJECT:
- case GROUP_NEGOTIATION_TIMED_OUT:
+ case PEER_CONNECTION_USER_ACCEPT:
+ case PEER_CONNECTION_USER_REJECT:
+ case GROUP_CREATING_TIMED_OUT:
break;
default:
loge("Unhandled message " + message);
@@ -691,31 +690,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
device = (WifiP2pDevice) message.obj;
if (mPeers.remove(device)) sendP2pPeersChangedBroadcast();
break;
- case WifiP2pManager.CONNECT:
- if (DBG) logd(getName() + " sending connect");
- mSavedConnectConfig = (WifiP2pConfig) message.obj;
- mPersistGroup = false;
- int netId = configuredNetworkId(mSavedConnectConfig.deviceAddress);
- if (netId >= 0) {
- //TODO: if failure, remove config and do a regular p2pConnect()
- WifiNative.p2pReinvoke(netId, mSavedConnectConfig.deviceAddress);
- } else {
- boolean join = false;
- if (isGroupOwner(mSavedConnectConfig.deviceAddress)) join = true;
- String pin = WifiNative.p2pConnect(mSavedConnectConfig, join);
- try {
- Integer.parseInt(pin);
- notifyWpsPin(pin, mSavedConnectConfig.deviceAddress);
- } catch (NumberFormatException ignore) {
- // do nothing if p2pConnect did not return a pin
- }
- }
- updateDeviceStatus(mSavedConnectConfig.deviceAddress, WifiP2pDevice.INVITED);
- sendP2pPeersChangedBroadcast();
- replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
- transitionTo(mGroupNegotiationState);
- break;
- case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant died */
+ case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant died */
loge("Connection lost, restart p2p");
WifiNative.killSupplicant();
WifiNative.closeSupplicantConnection();
@@ -723,21 +698,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
transitionTo(mP2pDisabledState);
sendMessageDelayed(WifiP2pManager.ENABLE_P2P, P2P_RESTART_INTERVAL_MSECS);
break;
- case WifiMonitor.P2P_GROUP_STARTED_EVENT:
- mGroup = (WifiP2pGroup) message.obj;
- if (DBG) logd(getName() + " group started");
- if (mGroup.isGroupOwner()) {
- startDhcpServer(mGroup.getInterface());
- } else {
- mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(mContext,
- P2pStateMachine.this, mGroup.getInterface());
- mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
- WifiP2pDevice groupOwner = mGroup.getOwner();
- updateDeviceStatus(groupOwner.deviceAddress, WifiP2pDevice.CONNECTED);
- sendP2pPeersChangedBroadcast();
- }
- transitionTo(mGroupCreatedState);
- break;
default:
return NOT_HANDLED;
}
@@ -764,10 +724,62 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
public boolean processMessage(Message message) {
if (DBG) logd(getName() + message.toString());
switch (message.what) {
+ case WifiP2pManager.CONNECT:
+ if (DBG) logd(getName() + " sending connect");
+ mSavedPeerConfig = (WifiP2pConfig) message.obj;
+ mPersistGroup = false;
+ int netId = configuredNetworkId(mSavedPeerConfig.deviceAddress);
+ if (netId >= 0) {
+ //TODO: if failure, remove config and do a regular p2pConnect()
+ WifiNative.p2pReinvoke(netId, mSavedPeerConfig.deviceAddress);
+ } else {
+ //If peer is a GO, we do not need to send provisional discovery,
+ //the supplicant takes care of it.
+ if (isGroupOwner(mSavedPeerConfig.deviceAddress)) {
+ String pin = WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP);
+ try {
+ Integer.parseInt(pin);
+ notifyInvitationSent(pin, mSavedPeerConfig.deviceAddress);
+ } catch (NumberFormatException ignore) {
+ // do nothing if p2pConnect did not return a pin
+ }
+ transitionTo(mGroupNegotiationState);
+ } else {
+ transitionTo(mProvisionDiscoveryState);
+ }
+ }
+ updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
+ sendP2pPeersChangedBroadcast();
+ replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
+ break;
case WifiMonitor.P2P_GO_NEGOTIATION_REQUEST_EVENT:
- mSavedGoNegotiationConfig = (WifiP2pConfig) message.obj;
- notifyP2pGoNegotationRequest(mSavedGoNegotiationConfig);
- transitionTo(mUserAuthorizingGroupNegotiationState);
+ mSavedPeerConfig = (WifiP2pConfig) message.obj;
+ transitionTo(mUserAuthorizingInvitationState);
+ break;
+ case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
+ WifiP2pGroup group = (WifiP2pGroup) message.obj;
+ //TODO: fix p2p invitation to handle as a regular config
+ //and update mSavedPeerConfig
+ transitionTo(mUserAuthorizingInvitationState);
+ break;
+ case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
+ case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
+ case WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT:
+ WifiP2pProvDiscEvent provDisc = (WifiP2pProvDiscEvent) message.obj;
+ mSavedPeerConfig = new WifiP2pConfig();
+ mSavedPeerConfig.deviceAddress = provDisc.device.deviceAddress;
+ if (message.what == WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT) {
+ mSavedPeerConfig.wps.setup = WpsInfo.KEYPAD;
+ if (DBG) logd("Keypad prov disc request");
+ } else if (message.what == WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT) {
+ mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY;
+ mSavedPeerConfig.wps.pin = provDisc.pin;
+ if (DBG) logd("Display prov disc request");
+ } else {
+ mSavedPeerConfig.wps.setup = WpsInfo.PBC;
+ if (DBG) logd("PBC prov disc request");
+ }
+ transitionTo(mUserAuthorizingInvitationState);
break;
case WifiP2pManager.CREATE_GROUP:
mPersistGroup = true;
@@ -779,40 +791,46 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
transitionTo(mGroupNegotiationState);
break;
- case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
- WifiP2pGroup group = (WifiP2pGroup) message.obj;
- notifyP2pInvitationReceived(group);
- transitionTo(mUserAuthorizingGroupInvitationState);
- break;
- default:
+ default:
return NOT_HANDLED;
}
return HANDLED;
}
}
- class UserAuthorizingGroupNegotiationState extends State {
+ class GroupCreatingState extends State {
@Override
public void enter() {
if (DBG) logd(getName());
+ sendMessageDelayed(obtainMessage(GROUP_CREATING_TIMED_OUT,
+ ++mGroupCreatingTimeoutIndex, 0), GROUP_CREATING_WAIT_TIME_MS);
}
@Override
public boolean processMessage(Message message) {
if (DBG) logd(getName() + message.toString());
switch (message.what) {
- case WifiMonitor.P2P_GO_NEGOTIATION_REQUEST_EVENT:
- case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
- //Ignore additional connection requests
+ case GROUP_CREATING_TIMED_OUT:
+ if (mGroupCreatingTimeoutIndex == message.arg1) {
+ if (DBG) logd("Group negotiation timed out");
+ updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.FAILED);
+ mSavedPeerConfig = null;
+ sendP2pPeersChangedBroadcast();
+ transitionTo(mInactiveState);
+ }
break;
- case GROUP_NEGOTIATION_USER_ACCEPT:
- sendMessage(WifiP2pManager.CONNECT, mSavedGoNegotiationConfig);
- mSavedGoNegotiationConfig = null;
+ case WifiP2pManager.DISCOVER_PEERS:
+ /* Discovery will break negotiation */
+ replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED,
+ WifiP2pManager.BUSY);
break;
- case GROUP_NEGOTIATION_USER_REJECT:
- if (DBG) logd("User rejected incoming negotiation request");
- mSavedGoNegotiationConfig = null;
- transitionTo(mInactiveState);
+ case WifiP2pManager.CANCEL_CONNECT:
+ if (WifiNative.p2pCancelConnect()) {
+ replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
+ } else {
+ replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
+ WifiP2pManager.ERROR);
+ }
break;
default:
return NOT_HANDLED;
@@ -821,30 +839,31 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
}
- class UserAuthorizingGroupInvitationState extends State {
+ class UserAuthorizingInvitationState extends State {
@Override
public void enter() {
if (DBG) logd(getName());
+ notifyInvitationReceived();
}
@Override
public boolean processMessage(Message message) {
if (DBG) logd(getName() + message.toString());
switch (message.what) {
- case WifiMonitor.P2P_GO_NEGOTIATION_REQUEST_EVENT:
- case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
- //Ignore additional connection requests
- break;
- case GROUP_INVITATION_USER_ACCEPT:
- if (DBG) logd(getName() + " connect to invited group");
- WifiP2pConfig config = new WifiP2pConfig();
- config.deviceAddress = mSavedP2pGroup.getOwner().deviceAddress;
- sendMessage(WifiP2pManager.CONNECT, config);
- mSavedP2pGroup = null;
- break;
- case GROUP_INVITATION_USER_REJECT:
- if (DBG) logd("User rejected incoming invitation request");
- mSavedP2pGroup = null;
+ case PEER_CONNECTION_USER_ACCEPT:
+ //TODO: handle persistence
+ if (isGroupOwner(mSavedPeerConfig.deviceAddress)) {
+ WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP);
+ } else {
+ WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
+ }
+ updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
+ sendP2pPeersChangedBroadcast();
+ transitionTo(mGroupNegotiationState);
+ break;
+ case PEER_CONNECTION_USER_REJECT:
+ if (DBG) logd("User rejected invitation " + mSavedPeerConfig);
+ mSavedPeerConfig = null;
transitionTo(mInactiveState);
break;
default:
@@ -852,15 +871,77 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
return HANDLED;
}
+
+ @Override
+ public void exit() {
+ //TODO: dismiss dialog if not already done
+ }
}
+ class ProvisionDiscoveryState extends State {
+ @Override
+ public void enter() {
+ if (DBG) logd(getName());
+ WifiNative.p2pProvisionDiscovery(mSavedPeerConfig);
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) logd(getName() + message.toString());
+ WifiP2pProvDiscEvent provDisc;
+ WifiP2pDevice device;
+ switch (message.what) {
+ case WifiMonitor.P2P_PROV_DISC_PBC_RSP_EVENT:
+ provDisc = (WifiP2pProvDiscEvent) message.obj;
+ device = provDisc.device;
+ if (!device.deviceAddress.equals(mSavedPeerConfig.deviceAddress)) break;
+
+ if (mSavedPeerConfig.wps.setup == WpsInfo.PBC) {
+ if (DBG) logd("Found a match " + mSavedPeerConfig);
+ WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
+ transitionTo(mGroupNegotiationState);
+ }
+ break;
+ case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
+ provDisc = (WifiP2pProvDiscEvent) message.obj;
+ device = provDisc.device;
+ if (!device.deviceAddress.equals(mSavedPeerConfig.deviceAddress)) break;
+
+ if (mSavedPeerConfig.wps.setup == WpsInfo.KEYPAD) {
+ if (DBG) logd("Found a match " + mSavedPeerConfig);
+ /* we already have the pin */
+ if (!TextUtils.isEmpty(mSavedPeerConfig.wps.pin)) {
+ WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
+ transitionTo(mGroupNegotiationState);
+ } else {
+ transitionTo(mUserAuthorizingInvitationState);
+ }
+ }
+ break;
+ case WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT:
+ provDisc = (WifiP2pProvDiscEvent) message.obj;
+ device = provDisc.device;
+ if (!device.deviceAddress.equals(mSavedPeerConfig.deviceAddress)) break;
+
+ if (mSavedPeerConfig.wps.setup == WpsInfo.DISPLAY) {
+ if (DBG) logd("Found a match " + mSavedPeerConfig);
+ mSavedPeerConfig.wps.pin = provDisc.pin;
+ WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP);
+ notifyInvitationSent(provDisc.pin, device.deviceAddress);
+ transitionTo(mGroupNegotiationState);
+ }
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
class GroupNegotiationState extends State {
@Override
public void enter() {
if (DBG) logd(getName());
- sendMessageDelayed(obtainMessage(GROUP_NEGOTIATION_TIMED_OUT,
- ++mGroupNegotiationTimeoutIndex, 0), GROUP_NEGOTIATION_WAIT_TIME_MS);
}
@Override
@@ -873,36 +954,30 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiMonitor.P2P_GROUP_FORMATION_SUCCESS_EVENT:
if (DBG) logd(getName() + " go success");
break;
+ case WifiMonitor.P2P_GROUP_STARTED_EVENT:
+ mGroup = (WifiP2pGroup) message.obj;
+ if (DBG) logd(getName() + " group started");
+ if (mGroup.isGroupOwner()) {
+ startDhcpServer(mGroup.getInterface());
+ } else {
+ mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(mContext,
+ P2pStateMachine.this, mGroup.getInterface());
+ mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
+ WifiP2pDevice groupOwner = mGroup.getOwner();
+ updateDeviceStatus(groupOwner.deviceAddress, WifiP2pDevice.CONNECTED);
+ sendP2pPeersChangedBroadcast();
+ }
+ mSavedPeerConfig = null;
+ transitionTo(mGroupCreatedState);
+ break;
case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
if (DBG) logd(getName() + " go failure");
- updateDeviceStatus(mSavedConnectConfig.deviceAddress, WifiP2pDevice.FAILED);
- mSavedConnectConfig = null;
+ updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.FAILED);
+ mSavedPeerConfig = null;
sendP2pPeersChangedBroadcast();
transitionTo(mInactiveState);
break;
- case GROUP_NEGOTIATION_TIMED_OUT:
- if (mGroupNegotiationTimeoutIndex == message.arg1) {
- if (DBG) logd("Group negotiation timed out");
- updateDeviceStatus(mSavedConnectConfig.deviceAddress, WifiP2pDevice.FAILED);
- mSavedConnectConfig = null;
- sendP2pPeersChangedBroadcast();
- transitionTo(mInactiveState);
- }
- break;
- case WifiP2pManager.DISCOVER_PEERS:
- /* Discovery will break negotiation */
- replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED,
- WifiP2pManager.BUSY);
- 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:
return NOT_HANDLED;
}
@@ -910,6 +985,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
}
+
+
class GroupCreatedState extends State {
@Override
public void enter() {
@@ -1038,24 +1115,25 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
// TODO: figure out updating the status to declined when invitation is rejected
break;
- case WifiMonitor.P2P_INVITATION_RESULT_EVENT:
- logd("===> INVITATION RESULT EVENT : " + message.obj);
- break;
case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
- notifyP2pProvDiscPbcRequest((WifiP2pDevice) message.obj);
- break;
case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
- notifyP2pProvDiscPinRequest((WifiP2pDevice) message.obj);
+ case WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT:
+ WifiP2pProvDiscEvent provDisc = (WifiP2pProvDiscEvent) message.obj;
+ mSavedPeerConfig = new WifiP2pConfig();
+ mSavedPeerConfig.deviceAddress = provDisc.device.deviceAddress;
+ if (message.what == WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT) {
+ mSavedPeerConfig.wps.setup = WpsInfo.KEYPAD;
+ } else if (message.what == WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT) {
+ mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY;
+ mSavedPeerConfig.wps.pin = provDisc.pin;
+ } else {
+ mSavedPeerConfig.wps.setup = WpsInfo.PBC;
+ }
+ transitionTo(mUserAuthorizingJoinState);
break;
case WifiMonitor.P2P_GROUP_STARTED_EVENT:
Slog.e(TAG, "Duplicate group creation event notice, ignore");
break;
- case WPS_PBC:
- WifiNative.wpsPbc();
- break;
- case WPS_PIN:
- WifiNative.wpsPin((String) message.obj);
- break;
default:
return NOT_HANDLED;
}
@@ -1070,6 +1148,48 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
}
+ class UserAuthorizingJoinState extends State {
+ @Override
+ public void enter() {
+ if (DBG) logd(getName());
+ notifyInvitationReceived();
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) logd(getName() + message.toString());
+ switch (message.what) {
+ case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
+ case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
+ case WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT:
+ //Ignore more client requests
+ break;
+ case PEER_CONNECTION_USER_ACCEPT:
+ if (mSavedPeerConfig.wps.setup == WpsInfo.PBC) {
+ WifiNative.wpsPbc();
+ } else {
+ WifiNative.wpsPin(mSavedPeerConfig.wps.pin);
+ }
+ mSavedPeerConfig = null;
+ transitionTo(mGroupCreatedState);
+ break;
+ case PEER_CONNECTION_USER_REJECT:
+ if (DBG) logd("User rejected incoming request");
+ mSavedPeerConfig = null;
+ transitionTo(mGroupCreatedState);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+
+ @Override
+ public void exit() {
+ //TODO: dismiss dialog if not already done
+ }
+ }
+
private void sendP2pStateChangedBroadcast(boolean enabled) {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
@@ -1146,140 +1266,80 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
dialog.show();
}
- private void notifyWpsPin(String pin, String peerAddress) {
+ private void addRowToDialog(ViewGroup group, int stringId, String value) {
Resources r = Resources.getSystem();
- AlertDialog dialog = new AlertDialog.Builder(mContext)
- .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
- .setMessage(r.getString(R.string.wifi_p2p_pin_display_message, pin, peerAddress))
- .setPositiveButton(r.getString(R.string.ok), null)
- .create();
- dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
- dialog.show();
+ View row = LayoutInflater.from(mContext).inflate(R.layout.wifi_p2p_dialog_row,
+ group, false);
+ ((TextView) row.findViewById(R.id.name)).setText(r.getString(stringId));
+ ((TextView) row.findViewById(R.id.value)).setText(value);
+ group.addView(row);
}
- private void notifyP2pGoNegotationRequest(WifiP2pConfig config) {
+ private void notifyInvitationSent(String pin, String peerAddress) {
Resources r = Resources.getSystem();
- WpsInfo wps = config.wps;
- final View textEntryView = LayoutInflater.from(mContext)
- .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
- final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
-
- AlertDialog dialog = new AlertDialog.Builder(mContext)
- .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
- .setView(textEntryView)
- .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (DBG) logd(getName() + " connect " + pin.getText());
- if (pin.getVisibility() == View.GONE) {
- mSavedGoNegotiationConfig.wps.setup = WpsInfo.PBC;
- } else {
- mSavedGoNegotiationConfig.wps.setup = WpsInfo.KEYPAD;
- mSavedGoNegotiationConfig.wps.pin = pin.getText().toString();
- }
- sendMessage(GROUP_NEGOTIATION_USER_ACCEPT);
- }
- })
- .setNegativeButton(r.getString(R.string.cancel), new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (DBG) logd(getName() + " ignore connect");
- sendMessage(GROUP_NEGOTIATION_USER_REJECT);
- }
- })
- .create();
-
- if (wps.setup == WpsInfo.PBC) {
- pin.setVisibility(View.GONE);
- dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
- config.deviceAddress));
- } else {
- dialog.setMessage(r.getString(R.string.wifi_p2p_pin_go_negotiation_request_message,
- config.deviceAddress));
- }
-
- dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
- dialog.show();
- }
-
- private void notifyP2pProvDiscPbcRequest(WifiP2pDevice peer) {
- Resources r = Resources.getSystem();
final View textEntryView = LayoutInflater.from(mContext)
- .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
- final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
+ .inflate(R.layout.wifi_p2p_dialog, null);
+
+ ViewGroup group = (ViewGroup) textEntryView.findViewById(R.id.info);
+ addRowToDialog(group, R.string.wifi_p2p_to_message, getDeviceName(peerAddress));
+ addRowToDialog(group, R.string.wifi_p2p_show_pin_message, pin);
AlertDialog dialog = new AlertDialog.Builder(mContext)
- .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setTitle(r.getString(R.string.wifi_p2p_invitation_sent_title))
.setView(textEntryView)
- .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (DBG) logd(getName() + " wps_pbc");
- sendMessage(WPS_PBC);
- }
- })
- .setNegativeButton(r.getString(R.string.cancel), null)
+ .setPositiveButton(r.getString(R.string.ok), null)
.create();
-
- pin.setVisibility(View.GONE);
- dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
- peer.deviceAddress));
-
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
}
- private void notifyP2pProvDiscPinRequest(WifiP2pDevice peer) {
+ private void notifyInvitationReceived() {
Resources r = Resources.getSystem();
+ final WpsInfo wps = mSavedPeerConfig.wps;
final View textEntryView = LayoutInflater.from(mContext)
- .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
- final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
-
- AlertDialog dialog = new AlertDialog.Builder(mContext)
- .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
- .setView(textEntryView)
- .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (DBG) logd(getName() + " wps_pin");
- sendMessage(WPS_PIN, pin.getText().toString());
- }
- })
- .setNegativeButton(r.getString(R.string.cancel), null)
- .create();
-
- dialog.setMessage(r.getString(R.string.wifi_p2p_pin_go_negotiation_request_message,
- peer.deviceAddress));
+ .inflate(R.layout.wifi_p2p_dialog, null);
- dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
- dialog.show();
- }
+ ViewGroup group = (ViewGroup) textEntryView.findViewById(R.id.info);
+ addRowToDialog(group, R.string.wifi_p2p_from_message, getDeviceName(
+ mSavedPeerConfig.deviceAddress));
- private void notifyP2pInvitationReceived(WifiP2pGroup group) {
- mSavedP2pGroup = group;
- Resources r = Resources.getSystem();
- final View textEntryView = LayoutInflater.from(mContext)
- .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);
AlertDialog dialog = new AlertDialog.Builder(mContext)
- .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setTitle(r.getString(R.string.wifi_p2p_invitation_to_connect_title))
.setView(textEntryView)
- .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
+ .setPositiveButton(r.getString(R.string.accept), new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
- sendMessage(GROUP_INVITATION_USER_ACCEPT);
+ if (wps.setup == WpsInfo.KEYPAD) {
+ mSavedPeerConfig.wps.pin = pin.getText().toString();
+ }
+ if (DBG) logd(getName() + " accept invitation " + mSavedPeerConfig);
+ sendMessage(PEER_CONNECTION_USER_ACCEPT);
}
})
- .setNegativeButton(r.getString(R.string.cancel), new OnClickListener() {
+ .setNegativeButton(r.getString(R.string.decline), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- if (DBG) logd(getName() + " ignore invite");
- sendMessage(GROUP_INVITATION_USER_REJECT);
+ if (DBG) logd(getName() + " ignore connect");
+ sendMessage(PEER_CONNECTION_USER_REJECT);
}
})
.create();
- pin.setVisibility(View.GONE);
- dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
- group.getOwner().deviceAddress));
+ //make the enter pin area or the display pin area visible
+ switch (wps.setup) {
+ case WpsInfo.KEYPAD:
+ if (DBG) logd("Enter pin section visible");
+ textEntryView.findViewById(R.id.enter_pin_section).setVisibility(View.VISIBLE);
+ break;
+ case WpsInfo.DISPLAY:
+ if (DBG) logd("Shown pin section visible");
+ addRowToDialog(group, R.string.wifi_p2p_show_pin_message, wps.pin);
+ break;
+ default:
+ break;
+ }
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
@@ -1319,6 +1379,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mWifiP2pInfo.groupOwnerAddress = null;
}
+ private String getDeviceName(String deviceAddress) {
+ for (WifiP2pDevice d : mPeers.getDeviceList()) {
+ if (d.deviceAddress.equals(deviceAddress)) {
+ return d.deviceName;
+ }
+ }
+ //Treat the address as name if there is no match
+ return deviceAddress;
+ }
+
private String getDeviceAddress(String interfaceAddress) {
for (WifiP2pDevice d : mPeers.getDeviceList()) {
if (interfaceAddress.equals(WifiNative.p2pGetInterfaceAddress(d.deviceAddress))) {
@@ -1332,6 +1402,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
WifiNative.setPersistentReconnect(true);
WifiNative.setDeviceName(mThisDevice.deviceName);
WifiNative.setDeviceType(mThisDevice.primaryDeviceType);
+ //The supplicant default is to support everything, but a bug necessitates
+ //the framework to specify this explicitly
+ WifiNative.setConfigMethods("keypad display push_button");
mThisDevice.deviceAddress = WifiNative.p2pGetDeviceAddress();
updateThisDevice(WifiP2pDevice.AVAILABLE);