Skip to content

Commit 369bb97

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "P2p API for WFD" into jb-mr1-dev
2 parents c67fb6c + ab4cd45 commit 369bb97

File tree

6 files changed

+271
-7
lines changed

6 files changed

+271
-7
lines changed

wifi/java/android/net/wifi/WifiNative.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,14 @@ public boolean setP2pPowerSave(String iface, boolean enabled) {
500500
}
501501
}
502502

503+
public boolean setWfdEnable(boolean enable) {
504+
return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0"));
505+
}
506+
507+
public boolean setWfdDeviceInfo(String hex) {
508+
return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex);
509+
}
510+
503511
/**
504512
* "sta" prioritizes STA connection over P2P and "p2p" prioritizes
505513
* P2P connection over STA

wifi/java/android/net/wifi/p2p/WifiP2pDevice.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ public class WifiP2pDevice implements Parcelable {
107107
/** Device connection status */
108108
public int status = UNAVAILABLE;
109109

110-
/** Detailed device string pattern
110+
/** @hide */
111+
public WifiP2pWfdInfo wfdInfo;
112+
113+
/** Detailed device string pattern with WFD info
111114
* Example:
112-
* P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13
113-
* pri_dev_type=1-0050F204-1 name='p2p-TEST1' config_methods=0x188 dev_capab=0x27
114-
* group_capab=0x0
115-
*
115+
* P2P-DEVICE-FOUND 00:18:6b:de:a3:6e p2p_dev_addr=00:18:6b:de:a3:6e
116+
* pri_dev_type=1-0050F204-1 name='DWD-300-DEA36E' config_methods=0x188
117+
* dev_capab=0x21 group_capab=0x9
116118
*/
117119
private static final Pattern detailedDevicePattern = Pattern.compile(
118120
"((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) " +
@@ -273,6 +275,7 @@ public String toString() {
273275
sbuf.append("\n grpcapab: ").append(groupCapability);
274276
sbuf.append("\n devcapab: ").append(deviceCapability);
275277
sbuf.append("\n status: ").append(status);
278+
sbuf.append("\n wfdInfo: ").append(wfdInfo);
276279
return sbuf.toString();
277280
}
278281

@@ -292,6 +295,7 @@ public WifiP2pDevice(WifiP2pDevice source) {
292295
deviceCapability = source.deviceCapability;
293296
groupCapability = source.groupCapability;
294297
status = source.status;
298+
wfdInfo = source.wfdInfo;
295299
}
296300
}
297301

@@ -305,6 +309,12 @@ public void writeToParcel(Parcel dest, int flags) {
305309
dest.writeInt(deviceCapability);
306310
dest.writeInt(groupCapability);
307311
dest.writeInt(status);
312+
if (wfdInfo != null) {
313+
dest.writeInt(1);
314+
wfdInfo.writeToParcel(dest, flags);
315+
} else {
316+
dest.writeInt(0);
317+
}
308318
}
309319

310320
/** Implement the Parcelable interface */
@@ -320,6 +330,9 @@ public WifiP2pDevice createFromParcel(Parcel in) {
320330
device.deviceCapability = in.readInt();
321331
device.groupCapability = in.readInt();
322332
device.status = in.readInt();
333+
if (in.readInt() == 1) {
334+
device.wfdInfo = WifiP2pWfdInfo.CREATOR.createFromParcel(in);
335+
}
323336
return device;
324337
}
325338

wifi/java/android/net/wifi/p2p/WifiP2pInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public WifiP2pInfo() {
4444
public String toString() {
4545
StringBuffer sbuf = new StringBuffer();
4646
sbuf.append("groupFormed: ").append(groupFormed)
47-
.append("isGroupOwner: ").append(isGroupOwner)
48-
.append("groupOwnerAddress: ").append(groupOwnerAddress);
47+
.append(" isGroupOwner: ").append(isGroupOwner)
48+
.append(" groupOwnerAddress: ").append(groupOwnerAddress);
4949
return sbuf.toString();
5050
}
5151

wifi/java/android/net/wifi/p2p/WifiP2pManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ public class WifiP2pManager {
455455
/** @hide */
456456
public static final int RESPONSE_PERSISTENT_GROUP_INFO = BASE + 63;
457457

458+
/** @hide */
459+
public static final int SET_WFD_INFO = BASE + 64;
460+
/** @hide */
461+
public static final int SET_WFD_INFO_FAILED = BASE + 65;
462+
/** @hide */
463+
public static final int SET_WFD_INFO_SUCCEEDED = BASE + 66;
464+
458465
/**
459466
* Create a new WifiP2pManager instance. Applications use
460467
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
@@ -742,6 +749,7 @@ public void handleMessage(Message message) {
742749
case WifiP2pManager.CLEAR_SERVICE_REQUESTS_FAILED:
743750
case WifiP2pManager.SET_DEVICE_NAME_FAILED:
744751
case WifiP2pManager.DELETE_PERSISTENT_GROUP_FAILED:
752+
case WifiP2pManager.SET_WFD_INFO_FAILED:
745753
if (listener != null) {
746754
((ActionListener) listener).onFailure(message.arg1);
747755
}
@@ -762,6 +770,7 @@ public void handleMessage(Message message) {
762770
case WifiP2pManager.CLEAR_SERVICE_REQUESTS_SUCCEEDED:
763771
case WifiP2pManager.SET_DEVICE_NAME_SUCCEEDED:
764772
case WifiP2pManager.DELETE_PERSISTENT_GROUP_SUCCEEDED:
773+
case WifiP2pManager.SET_WFD_INFO_SUCCEEDED:
765774
if (listener != null) {
766775
((ActionListener) listener).onSuccess();
767776
}
@@ -1297,6 +1306,13 @@ public void setDeviceName(Channel c, String devName, ActionListener listener) {
12971306
c.mAsyncChannel.sendMessage(SET_DEVICE_NAME, 0, c.putListener(listener), d);
12981307
}
12991308

1309+
/** @hide */
1310+
public void setWFDInfo(
1311+
Channel c, WifiP2pWfdInfo wfdInfo,
1312+
ActionListener listener) {
1313+
checkChannel(c);
1314+
c.mAsyncChannel.sendMessage(SET_WFD_INFO, 0, c.putListener(listener), wfdInfo);
1315+
}
13001316

13011317
/**
13021318
* Set dialog listener to over-ride system dialogs on p2p events. This function

wifi/java/android/net/wifi/p2p/WifiP2pService.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ public boolean processMessage(Message message) {
496496
replyToMessage(message, WifiP2pManager.DELETE_PERSISTENT_GROUP,
497497
WifiP2pManager.BUSY);
498498
break;
499+
case WifiP2pManager.SET_WFD_INFO:
500+
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED,
501+
WifiP2pManager.BUSY);
502+
break;
499503
case WifiP2pManager.REQUEST_PEERS:
500504
replyToMessage(message, WifiP2pManager.RESPONSE_PEERS, mPeers);
501505
break;
@@ -629,6 +633,10 @@ public boolean processMessage(Message message) {
629633
replyToMessage(message, WifiP2pManager.DELETE_PERSISTENT_GROUP,
630634
WifiP2pManager.P2P_UNSUPPORTED);
631635
break;
636+
case WifiP2pManager.SET_WFD_INFO:
637+
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED,
638+
WifiP2pManager.P2P_UNSUPPORTED);
639+
break;
632640
default:
633641
return NOT_HANDLED;
634642
}
@@ -741,6 +749,7 @@ public boolean processMessage(Message message) {
741749
transitionTo(mP2pDisablingState);
742750
break;
743751
case WifiP2pManager.SET_DEVICE_NAME:
752+
{
744753
WifiP2pDevice d = (WifiP2pDevice) message.obj;
745754
if (d != null && setAndPersistDeviceName(d.deviceName)) {
746755
if (DBG) logd("set device name " + d.deviceName);
@@ -750,6 +759,18 @@ public boolean processMessage(Message message) {
750759
WifiP2pManager.ERROR);
751760
}
752761
break;
762+
}
763+
case WifiP2pManager.SET_WFD_INFO:
764+
{
765+
WifiP2pWfdInfo d = (WifiP2pWfdInfo) message.obj;
766+
if (d != null && setWfdInfo(d)) {
767+
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_SUCCEEDED);
768+
} else {
769+
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED,
770+
WifiP2pManager.ERROR);
771+
}
772+
break;
773+
}
753774
case WifiP2pManager.DISCOVER_PEERS:
754775
// do not send service discovery request while normal find operation.
755776
clearSupplicantServiceRequest();
@@ -2018,6 +2039,27 @@ private boolean setAndPersistDeviceName(String devName) {
20182039
return true;
20192040
}
20202041

2042+
private boolean setWfdInfo(WifiP2pWfdInfo wfdInfo) {
2043+
boolean success;
2044+
2045+
if (!wfdInfo.isWfdEnabled()) {
2046+
success = mWifiNative.setWfdEnable(false);
2047+
} else {
2048+
success =
2049+
mWifiNative.setWfdEnable(true)
2050+
&& mWifiNative.setWfdDeviceInfo(wfdInfo.getDeviceInfoHex());
2051+
}
2052+
2053+
if (!success) {
2054+
loge("Failed to set wfd properties");
2055+
return false;
2056+
}
2057+
2058+
mThisDevice.wfdInfo = wfdInfo;
2059+
sendThisDeviceChangedBroadcast();
2060+
return true;
2061+
}
2062+
20212063
private void initializeP2pSettings() {
20222064
mWifiNative.setPersistentReconnect(true);
20232065
mThisDevice.deviceName = getPersistedDeviceName();
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.net.wifi.p2p;
18+
19+
import android.os.Parcelable;
20+
import android.os.Parcel;
21+
22+
/**
23+
* A class representing Wifi Display information for a device
24+
* @hide
25+
*/
26+
public class WifiP2pWfdInfo implements Parcelable {
27+
28+
private static final String TAG = "WifiP2pWfdInfo";
29+
30+
private boolean mWfdEnabled;
31+
32+
private int mDeviceInfo;
33+
34+
public static final int WFD_SOURCE = 0;
35+
public static final int PRIMARY_SINK = 1;
36+
public static final int SECONDARY_SINK = 2;
37+
public static final int SOURCE_OR_PRIMARY_SINK = 3;
38+
39+
/* Device information bitmap */
40+
/** One of {@link #WFD_SOURCE}, {@link #PRIMARY_SINK}, {@link #SECONDARY_SINK}
41+
* or {@link #SOURCE_OR_PRIMARY_SINK}
42+
*/
43+
private static final int DEVICE_TYPE = 0x3;
44+
private static final int COUPLED_SINK_SUPPORT_AT_SOURCE = 0x4;
45+
private static final int COUPLED_SINK_SUPPORT_AT_SINK = 0x8;
46+
private static final int SESSION_AVAILABLE = 0x30;
47+
private static final int SESSION_AVAILABLE_BIT1 = 0x10;
48+
private static final int SESSION_AVAILABLE_BIT2 = 0x20;
49+
50+
private int mCtrlPort;
51+
52+
private int mMaxThroughput;
53+
54+
public WifiP2pWfdInfo() {
55+
}
56+
57+
public boolean isWfdEnabled() {
58+
return mWfdEnabled;
59+
}
60+
61+
public void setWfdEnabled(boolean enabled) {
62+
mWfdEnabled = enabled;
63+
}
64+
65+
public int getDeviceType() {
66+
return (mDeviceInfo & DEVICE_TYPE);
67+
}
68+
69+
public boolean setDeviceType(int deviceType) {
70+
if (deviceType >= WFD_SOURCE && deviceType <= SOURCE_OR_PRIMARY_SINK) {
71+
mDeviceInfo |= deviceType;
72+
return true;
73+
}
74+
return false;
75+
}
76+
77+
public boolean isCoupledSinkSupportedAtSource() {
78+
return (mDeviceInfo & COUPLED_SINK_SUPPORT_AT_SINK) != 0;
79+
}
80+
81+
public void setCoupledSinkSupportAtSource(boolean enabled) {
82+
if (enabled ) {
83+
mDeviceInfo |= COUPLED_SINK_SUPPORT_AT_SINK;
84+
} else {
85+
mDeviceInfo &= ~COUPLED_SINK_SUPPORT_AT_SINK;
86+
}
87+
}
88+
89+
public boolean isCoupledSinkSupportedAtSink() {
90+
return (mDeviceInfo & COUPLED_SINK_SUPPORT_AT_SINK) != 0;
91+
}
92+
93+
public void setCoupledSinkSupportAtSink(boolean enabled) {
94+
if (enabled ) {
95+
mDeviceInfo |= COUPLED_SINK_SUPPORT_AT_SINK;
96+
} else {
97+
mDeviceInfo &= ~COUPLED_SINK_SUPPORT_AT_SINK;
98+
}
99+
}
100+
101+
public boolean isSessionAvailable() {
102+
return (mDeviceInfo & SESSION_AVAILABLE) != 0;
103+
}
104+
105+
public void setSessionAvailable(boolean enabled) {
106+
if (enabled) {
107+
mDeviceInfo |= SESSION_AVAILABLE_BIT1;
108+
mDeviceInfo &= ~SESSION_AVAILABLE_BIT2;
109+
} else {
110+
mDeviceInfo &= ~SESSION_AVAILABLE;
111+
}
112+
}
113+
114+
public int getControlPort() {
115+
return mCtrlPort;
116+
}
117+
118+
public void setControlPort(int port) {
119+
mCtrlPort = port;
120+
}
121+
122+
public void setMaxThroughput(int maxThroughput) {
123+
mMaxThroughput = maxThroughput;
124+
}
125+
126+
public int getMaxThroughput() {
127+
return mMaxThroughput;
128+
}
129+
130+
public String getDeviceInfoHex() {
131+
return String.format("%04x%04x%04x%04x", 6, mDeviceInfo, mCtrlPort, mMaxThroughput);
132+
}
133+
134+
public String toString() {
135+
StringBuffer sbuf = new StringBuffer();
136+
sbuf.append("WFD enabled: ").append(mWfdEnabled);
137+
sbuf.append("WFD DeviceInfo: ").append(mDeviceInfo);
138+
sbuf.append("\n WFD CtrlPort: ").append(mCtrlPort);
139+
sbuf.append("\n WFD MaxThroughput: ").append(mMaxThroughput);
140+
return sbuf.toString();
141+
}
142+
143+
/** Implement the Parcelable interface */
144+
public int describeContents() {
145+
return 0;
146+
}
147+
148+
/** copy constructor */
149+
public WifiP2pWfdInfo(WifiP2pWfdInfo source) {
150+
if (source != null) {
151+
mDeviceInfo = source.mDeviceInfo;
152+
mCtrlPort = source.mCtrlPort;
153+
mMaxThroughput = source.mMaxThroughput;
154+
}
155+
}
156+
157+
/** Implement the Parcelable interface */
158+
public void writeToParcel(Parcel dest, int flags) {
159+
dest.writeInt(mWfdEnabled ? 1 : 0);
160+
dest.writeInt(mDeviceInfo);
161+
dest.writeInt(mCtrlPort);
162+
dest.writeInt(mMaxThroughput);
163+
}
164+
165+
public void readFromParcel(Parcel in) {
166+
mWfdEnabled = (in.readInt() == 1);
167+
mDeviceInfo = in.readInt();
168+
mCtrlPort = in.readInt();
169+
mMaxThroughput = in.readInt();
170+
}
171+
172+
/** Implement the Parcelable interface */
173+
public static final Creator<WifiP2pWfdInfo> CREATOR =
174+
new Creator<WifiP2pWfdInfo>() {
175+
public WifiP2pWfdInfo createFromParcel(Parcel in) {
176+
WifiP2pWfdInfo device = new WifiP2pWfdInfo();
177+
device.readFromParcel(in);
178+
return device;
179+
}
180+
181+
public WifiP2pWfdInfo[] newArray(int size) {
182+
return new WifiP2pWfdInfo[size];
183+
}
184+
};
185+
}

0 commit comments

Comments
 (0)