Merge "P2p API for WFD" into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
369bb97d02
@@ -500,6 +500,14 @@ public class WifiNative {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setWfdEnable(boolean enable) {
|
||||
return doBooleanCommand("SET wifi_display " + (enable ? "1" : "0"));
|
||||
}
|
||||
|
||||
public boolean setWfdDeviceInfo(String hex) {
|
||||
return doBooleanCommand("WFD_SUBELEM_SET 0 " + hex);
|
||||
}
|
||||
|
||||
/**
|
||||
* "sta" prioritizes STA connection over P2P and "p2p" prioritizes
|
||||
* P2P connection over STA
|
||||
|
||||
@@ -107,12 +107,14 @@ public class WifiP2pDevice implements Parcelable {
|
||||
/** Device connection status */
|
||||
public int status = UNAVAILABLE;
|
||||
|
||||
/** Detailed device string pattern
|
||||
/** @hide */
|
||||
public WifiP2pWfdInfo wfdInfo;
|
||||
|
||||
/** Detailed device string pattern with WFD info
|
||||
* Example:
|
||||
* P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13
|
||||
* pri_dev_type=1-0050F204-1 name='p2p-TEST1' config_methods=0x188 dev_capab=0x27
|
||||
* group_capab=0x0
|
||||
*
|
||||
* P2P-DEVICE-FOUND 00:18:6b:de:a3:6e p2p_dev_addr=00:18:6b:de:a3:6e
|
||||
* pri_dev_type=1-0050F204-1 name='DWD-300-DEA36E' config_methods=0x188
|
||||
* dev_capab=0x21 group_capab=0x9
|
||||
*/
|
||||
private static final Pattern detailedDevicePattern = Pattern.compile(
|
||||
"((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) " +
|
||||
@@ -273,6 +275,7 @@ public class WifiP2pDevice implements Parcelable {
|
||||
sbuf.append("\n grpcapab: ").append(groupCapability);
|
||||
sbuf.append("\n devcapab: ").append(deviceCapability);
|
||||
sbuf.append("\n status: ").append(status);
|
||||
sbuf.append("\n wfdInfo: ").append(wfdInfo);
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
@@ -292,6 +295,7 @@ public class WifiP2pDevice implements Parcelable {
|
||||
deviceCapability = source.deviceCapability;
|
||||
groupCapability = source.groupCapability;
|
||||
status = source.status;
|
||||
wfdInfo = source.wfdInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,6 +309,12 @@ public class WifiP2pDevice implements Parcelable {
|
||||
dest.writeInt(deviceCapability);
|
||||
dest.writeInt(groupCapability);
|
||||
dest.writeInt(status);
|
||||
if (wfdInfo != null) {
|
||||
dest.writeInt(1);
|
||||
wfdInfo.writeToParcel(dest, flags);
|
||||
} else {
|
||||
dest.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
@@ -320,6 +330,9 @@ public class WifiP2pDevice implements Parcelable {
|
||||
device.deviceCapability = in.readInt();
|
||||
device.groupCapability = in.readInt();
|
||||
device.status = in.readInt();
|
||||
if (in.readInt() == 1) {
|
||||
device.wfdInfo = WifiP2pWfdInfo.CREATOR.createFromParcel(in);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public class WifiP2pInfo implements Parcelable {
|
||||
public String toString() {
|
||||
StringBuffer sbuf = new StringBuffer();
|
||||
sbuf.append("groupFormed: ").append(groupFormed)
|
||||
.append("isGroupOwner: ").append(isGroupOwner)
|
||||
.append("groupOwnerAddress: ").append(groupOwnerAddress);
|
||||
.append(" isGroupOwner: ").append(isGroupOwner)
|
||||
.append(" groupOwnerAddress: ").append(groupOwnerAddress);
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -455,6 +455,13 @@ public class WifiP2pManager {
|
||||
/** @hide */
|
||||
public static final int RESPONSE_PERSISTENT_GROUP_INFO = BASE + 63;
|
||||
|
||||
/** @hide */
|
||||
public static final int SET_WFD_INFO = BASE + 64;
|
||||
/** @hide */
|
||||
public static final int SET_WFD_INFO_FAILED = BASE + 65;
|
||||
/** @hide */
|
||||
public static final int SET_WFD_INFO_SUCCEEDED = BASE + 66;
|
||||
|
||||
/**
|
||||
* Create a new WifiP2pManager instance. Applications use
|
||||
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
|
||||
@@ -742,6 +749,7 @@ public class WifiP2pManager {
|
||||
case WifiP2pManager.CLEAR_SERVICE_REQUESTS_FAILED:
|
||||
case WifiP2pManager.SET_DEVICE_NAME_FAILED:
|
||||
case WifiP2pManager.DELETE_PERSISTENT_GROUP_FAILED:
|
||||
case WifiP2pManager.SET_WFD_INFO_FAILED:
|
||||
if (listener != null) {
|
||||
((ActionListener) listener).onFailure(message.arg1);
|
||||
}
|
||||
@@ -762,6 +770,7 @@ public class WifiP2pManager {
|
||||
case WifiP2pManager.CLEAR_SERVICE_REQUESTS_SUCCEEDED:
|
||||
case WifiP2pManager.SET_DEVICE_NAME_SUCCEEDED:
|
||||
case WifiP2pManager.DELETE_PERSISTENT_GROUP_SUCCEEDED:
|
||||
case WifiP2pManager.SET_WFD_INFO_SUCCEEDED:
|
||||
if (listener != null) {
|
||||
((ActionListener) listener).onSuccess();
|
||||
}
|
||||
@@ -1297,6 +1306,13 @@ public class WifiP2pManager {
|
||||
c.mAsyncChannel.sendMessage(SET_DEVICE_NAME, 0, c.putListener(listener), d);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void setWFDInfo(
|
||||
Channel c, WifiP2pWfdInfo wfdInfo,
|
||||
ActionListener listener) {
|
||||
checkChannel(c);
|
||||
c.mAsyncChannel.sendMessage(SET_WFD_INFO, 0, c.putListener(listener), wfdInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set dialog listener to over-ride system dialogs on p2p events. This function
|
||||
|
||||
@@ -496,6 +496,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
replyToMessage(message, WifiP2pManager.DELETE_PERSISTENT_GROUP,
|
||||
WifiP2pManager.BUSY);
|
||||
break;
|
||||
case WifiP2pManager.SET_WFD_INFO:
|
||||
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED,
|
||||
WifiP2pManager.BUSY);
|
||||
break;
|
||||
case WifiP2pManager.REQUEST_PEERS:
|
||||
replyToMessage(message, WifiP2pManager.RESPONSE_PEERS, mPeers);
|
||||
break;
|
||||
@@ -629,6 +633,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
replyToMessage(message, WifiP2pManager.DELETE_PERSISTENT_GROUP,
|
||||
WifiP2pManager.P2P_UNSUPPORTED);
|
||||
break;
|
||||
case WifiP2pManager.SET_WFD_INFO:
|
||||
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED,
|
||||
WifiP2pManager.P2P_UNSUPPORTED);
|
||||
break;
|
||||
default:
|
||||
return NOT_HANDLED;
|
||||
}
|
||||
@@ -741,6 +749,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
transitionTo(mP2pDisablingState);
|
||||
break;
|
||||
case WifiP2pManager.SET_DEVICE_NAME:
|
||||
{
|
||||
WifiP2pDevice d = (WifiP2pDevice) message.obj;
|
||||
if (d != null && setAndPersistDeviceName(d.deviceName)) {
|
||||
if (DBG) logd("set device name " + d.deviceName);
|
||||
@@ -750,6 +759,18 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
WifiP2pManager.ERROR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WifiP2pManager.SET_WFD_INFO:
|
||||
{
|
||||
WifiP2pWfdInfo d = (WifiP2pWfdInfo) message.obj;
|
||||
if (d != null && setWfdInfo(d)) {
|
||||
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_SUCCEEDED);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.SET_WFD_INFO_FAILED,
|
||||
WifiP2pManager.ERROR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WifiP2pManager.DISCOVER_PEERS:
|
||||
// do not send service discovery request while normal find operation.
|
||||
clearSupplicantServiceRequest();
|
||||
@@ -2018,6 +2039,27 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setWfdInfo(WifiP2pWfdInfo wfdInfo) {
|
||||
boolean success;
|
||||
|
||||
if (!wfdInfo.isWfdEnabled()) {
|
||||
success = mWifiNative.setWfdEnable(false);
|
||||
} else {
|
||||
success =
|
||||
mWifiNative.setWfdEnable(true)
|
||||
&& mWifiNative.setWfdDeviceInfo(wfdInfo.getDeviceInfoHex());
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
loge("Failed to set wfd properties");
|
||||
return false;
|
||||
}
|
||||
|
||||
mThisDevice.wfdInfo = wfdInfo;
|
||||
sendThisDeviceChangedBroadcast();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initializeP2pSettings() {
|
||||
mWifiNative.setPersistentReconnect(true);
|
||||
mThisDevice.deviceName = getPersistedDeviceName();
|
||||
|
||||
185
wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java
Normal file
185
wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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;
|
||||
|
||||
/**
|
||||
* A class representing Wifi Display information for a device
|
||||
* @hide
|
||||
*/
|
||||
public class WifiP2pWfdInfo implements Parcelable {
|
||||
|
||||
private static final String TAG = "WifiP2pWfdInfo";
|
||||
|
||||
private boolean mWfdEnabled;
|
||||
|
||||
private int mDeviceInfo;
|
||||
|
||||
public static final int WFD_SOURCE = 0;
|
||||
public static final int PRIMARY_SINK = 1;
|
||||
public static final int SECONDARY_SINK = 2;
|
||||
public static final int SOURCE_OR_PRIMARY_SINK = 3;
|
||||
|
||||
/* Device information bitmap */
|
||||
/** One of {@link #WFD_SOURCE}, {@link #PRIMARY_SINK}, {@link #SECONDARY_SINK}
|
||||
* or {@link #SOURCE_OR_PRIMARY_SINK}
|
||||
*/
|
||||
private static final int DEVICE_TYPE = 0x3;
|
||||
private static final int COUPLED_SINK_SUPPORT_AT_SOURCE = 0x4;
|
||||
private static final int COUPLED_SINK_SUPPORT_AT_SINK = 0x8;
|
||||
private static final int SESSION_AVAILABLE = 0x30;
|
||||
private static final int SESSION_AVAILABLE_BIT1 = 0x10;
|
||||
private static final int SESSION_AVAILABLE_BIT2 = 0x20;
|
||||
|
||||
private int mCtrlPort;
|
||||
|
||||
private int mMaxThroughput;
|
||||
|
||||
public WifiP2pWfdInfo() {
|
||||
}
|
||||
|
||||
public boolean isWfdEnabled() {
|
||||
return mWfdEnabled;
|
||||
}
|
||||
|
||||
public void setWfdEnabled(boolean enabled) {
|
||||
mWfdEnabled = enabled;
|
||||
}
|
||||
|
||||
public int getDeviceType() {
|
||||
return (mDeviceInfo & DEVICE_TYPE);
|
||||
}
|
||||
|
||||
public boolean setDeviceType(int deviceType) {
|
||||
if (deviceType >= WFD_SOURCE && deviceType <= SOURCE_OR_PRIMARY_SINK) {
|
||||
mDeviceInfo |= deviceType;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCoupledSinkSupportedAtSource() {
|
||||
return (mDeviceInfo & COUPLED_SINK_SUPPORT_AT_SINK) != 0;
|
||||
}
|
||||
|
||||
public void setCoupledSinkSupportAtSource(boolean enabled) {
|
||||
if (enabled ) {
|
||||
mDeviceInfo |= COUPLED_SINK_SUPPORT_AT_SINK;
|
||||
} else {
|
||||
mDeviceInfo &= ~COUPLED_SINK_SUPPORT_AT_SINK;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCoupledSinkSupportedAtSink() {
|
||||
return (mDeviceInfo & COUPLED_SINK_SUPPORT_AT_SINK) != 0;
|
||||
}
|
||||
|
||||
public void setCoupledSinkSupportAtSink(boolean enabled) {
|
||||
if (enabled ) {
|
||||
mDeviceInfo |= COUPLED_SINK_SUPPORT_AT_SINK;
|
||||
} else {
|
||||
mDeviceInfo &= ~COUPLED_SINK_SUPPORT_AT_SINK;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSessionAvailable() {
|
||||
return (mDeviceInfo & SESSION_AVAILABLE) != 0;
|
||||
}
|
||||
|
||||
public void setSessionAvailable(boolean enabled) {
|
||||
if (enabled) {
|
||||
mDeviceInfo |= SESSION_AVAILABLE_BIT1;
|
||||
mDeviceInfo &= ~SESSION_AVAILABLE_BIT2;
|
||||
} else {
|
||||
mDeviceInfo &= ~SESSION_AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
public int getControlPort() {
|
||||
return mCtrlPort;
|
||||
}
|
||||
|
||||
public void setControlPort(int port) {
|
||||
mCtrlPort = port;
|
||||
}
|
||||
|
||||
public void setMaxThroughput(int maxThroughput) {
|
||||
mMaxThroughput = maxThroughput;
|
||||
}
|
||||
|
||||
public int getMaxThroughput() {
|
||||
return mMaxThroughput;
|
||||
}
|
||||
|
||||
public String getDeviceInfoHex() {
|
||||
return String.format("%04x%04x%04x%04x", 6, mDeviceInfo, mCtrlPort, mMaxThroughput);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sbuf = new StringBuffer();
|
||||
sbuf.append("WFD enabled: ").append(mWfdEnabled);
|
||||
sbuf.append("WFD DeviceInfo: ").append(mDeviceInfo);
|
||||
sbuf.append("\n WFD CtrlPort: ").append(mCtrlPort);
|
||||
sbuf.append("\n WFD MaxThroughput: ").append(mMaxThroughput);
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** copy constructor */
|
||||
public WifiP2pWfdInfo(WifiP2pWfdInfo source) {
|
||||
if (source != null) {
|
||||
mDeviceInfo = source.mDeviceInfo;
|
||||
mCtrlPort = source.mCtrlPort;
|
||||
mMaxThroughput = source.mMaxThroughput;
|
||||
}
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mWfdEnabled ? 1 : 0);
|
||||
dest.writeInt(mDeviceInfo);
|
||||
dest.writeInt(mCtrlPort);
|
||||
dest.writeInt(mMaxThroughput);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
mWfdEnabled = (in.readInt() == 1);
|
||||
mDeviceInfo = in.readInt();
|
||||
mCtrlPort = in.readInt();
|
||||
mMaxThroughput = in.readInt();
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
public static final Creator<WifiP2pWfdInfo> CREATOR =
|
||||
new Creator<WifiP2pWfdInfo>() {
|
||||
public WifiP2pWfdInfo createFromParcel(Parcel in) {
|
||||
WifiP2pWfdInfo device = new WifiP2pWfdInfo();
|
||||
device.readFromParcel(in);
|
||||
return device;
|
||||
}
|
||||
|
||||
public WifiP2pWfdInfo[] newArray(int size) {
|
||||
return new WifiP2pWfdInfo[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user