Merge "Expose more details in broadcasts"
This commit is contained in:
committed by
Android (Google) Code Review
commit
fdb9138c40
@@ -13563,6 +13563,7 @@ package android.net.wifi.p2p {
|
||||
ctor public WifiP2pDeviceList();
|
||||
ctor public WifiP2pDeviceList(android.net.wifi.p2p.WifiP2pDeviceList);
|
||||
method public int describeContents();
|
||||
method public android.net.wifi.p2p.WifiP2pDevice get(java.lang.String);
|
||||
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;
|
||||
@@ -13618,7 +13619,9 @@ package android.net.wifi.p2p {
|
||||
field public static final int ERROR = 0; // 0x0
|
||||
field public static final java.lang.String EXTRA_DISCOVERY_STATE = "discoveryState";
|
||||
field public static final java.lang.String EXTRA_NETWORK_INFO = "networkInfo";
|
||||
field public static final java.lang.String EXTRA_P2P_DEVICE_LIST = "wifiP2pDeviceList";
|
||||
field public static final java.lang.String EXTRA_WIFI_P2P_DEVICE = "wifiP2pDevice";
|
||||
field public static final java.lang.String EXTRA_WIFI_P2P_GROUP = "p2pGroupInfo";
|
||||
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 NO_SERVICE_REQUESTS = 3; // 0x3
|
||||
@@ -41394,8 +41397,8 @@ package java.util.zip {
|
||||
|
||||
public class ZipFile {
|
||||
ctor public ZipFile(java.io.File) throws java.io.IOException, java.util.zip.ZipException;
|
||||
ctor public ZipFile(java.io.File, int) throws java.io.IOException;
|
||||
ctor public ZipFile(java.lang.String) throws java.io.IOException;
|
||||
ctor public ZipFile(java.io.File, int) throws java.io.IOException;
|
||||
method public void close() throws java.io.IOException;
|
||||
method public java.util.Enumeration<? extends java.util.zip.ZipEntry> entries();
|
||||
method public java.util.zip.ZipEntry getEntry(java.lang.String);
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.regex.Matcher;
|
||||
/**
|
||||
* A class representing a Wi-Fi p2p device
|
||||
*
|
||||
* Note that the operations are not thread safe
|
||||
* {@see WifiP2pManager}
|
||||
*/
|
||||
public class WifiP2pDevice implements Parcelable {
|
||||
@@ -260,9 +261,29 @@ public class WifiP2pDevice implements Parcelable {
|
||||
return (groupCapability & GROUP_CAPAB_GROUP_LIMIT) != 0;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
/**
|
||||
* Update device details. This will be throw an exception if the device address
|
||||
* does not match.
|
||||
* @param device to be updated
|
||||
* @throws IllegalArgumentException if the device is null or device address does not match
|
||||
* @hide
|
||||
*/
|
||||
public void update(WifiP2pDevice device) {
|
||||
if (device == null || device.deviceAddress == null) return;
|
||||
updateSupplicantDetails(device);
|
||||
status = device.status;
|
||||
}
|
||||
|
||||
/** Updates details obtained from supplicant @hide */
|
||||
void updateSupplicantDetails(WifiP2pDevice device) {
|
||||
if (device == null) {
|
||||
throw new IllegalArgumentException("device is null");
|
||||
}
|
||||
if (device.deviceAddress == null) {
|
||||
throw new IllegalArgumentException("deviceAddress is null");
|
||||
}
|
||||
if (!deviceAddress.equals(device.deviceAddress)) {
|
||||
throw new IllegalArgumentException("deviceAddress does not match");
|
||||
}
|
||||
deviceName = device.deviceName;
|
||||
primaryDeviceType = device.primaryDeviceType;
|
||||
secondaryDeviceType = device.secondaryDeviceType;
|
||||
|
||||
@@ -58,15 +58,27 @@ public class WifiP2pDeviceList implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
/** Clear the list @hide */
|
||||
public boolean clear() {
|
||||
if (mDevices.isEmpty()) return false;
|
||||
mDevices.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
/**
|
||||
* Add/update a device to the list. If the device is not found, a new device entry
|
||||
* is created. If the device is already found, the device details are updated
|
||||
* @param device to be updated
|
||||
* @hide
|
||||
*/
|
||||
public void update(WifiP2pDevice device) {
|
||||
if (device == null || device.deviceAddress == null) return;
|
||||
updateSupplicantDetails(device);
|
||||
mDevices.get(device.deviceAddress).status = device.status;
|
||||
}
|
||||
|
||||
/** Only updates details fetched from the supplicant @hide */
|
||||
void updateSupplicantDetails(WifiP2pDevice device) {
|
||||
if (device == null || device.deviceAddress == null) return;
|
||||
WifiP2pDevice d = mDevices.get(device.deviceAddress);
|
||||
if (d != null) {
|
||||
@@ -84,7 +96,7 @@ public class WifiP2pDeviceList implements Parcelable {
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void updateGroupCapability(String deviceAddress, int groupCapab) {
|
||||
void updateGroupCapability(String deviceAddress, int groupCapab) {
|
||||
if (TextUtils.isEmpty(deviceAddress)) return;
|
||||
WifiP2pDevice d = mDevices.get(deviceAddress);
|
||||
if (d != null) {
|
||||
@@ -93,7 +105,7 @@ public class WifiP2pDeviceList implements Parcelable {
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void updateStatus(String deviceAddress, int status) {
|
||||
void updateStatus(String deviceAddress, int status) {
|
||||
if (TextUtils.isEmpty(deviceAddress)) return;
|
||||
WifiP2pDevice d = mDevices.get(deviceAddress);
|
||||
if (d != null) {
|
||||
@@ -101,7 +113,11 @@ public class WifiP2pDeviceList implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
/**
|
||||
* Fetch a device from the list
|
||||
* @param deviceAddress is the address of the device
|
||||
* @return WifiP2pDevice device found, or null if none found
|
||||
*/
|
||||
public WifiP2pDevice get(String deviceAddress) {
|
||||
if (deviceAddress == null) return null;
|
||||
|
||||
@@ -114,6 +130,17 @@ public class WifiP2pDeviceList implements Parcelable {
|
||||
return mDevices.remove(device.deviceAddress) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a device from the list
|
||||
* @param deviceAddress is the address of the device
|
||||
* @return WifiP2pDevice device removed, or null if none removed
|
||||
* @hide
|
||||
*/
|
||||
public WifiP2pDevice remove(String deviceAddress) {
|
||||
if (deviceAddress == null) return null;
|
||||
return mDevices.remove(deviceAddress);
|
||||
}
|
||||
|
||||
/** Returns true if any device the list was removed @hide */
|
||||
public boolean remove(WifiP2pDeviceList list) {
|
||||
boolean ret = false;
|
||||
|
||||
@@ -27,7 +27,9 @@ import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* A class representing a Wi-Fi P2p group
|
||||
* A class representing a Wi-Fi P2p group. A p2p group consists of a single group
|
||||
* owner and one or more clients. In the case of a group with only two devices, one
|
||||
* will be the group owner and the other will be a group client.
|
||||
*
|
||||
* {@see WifiP2pManager}
|
||||
*/
|
||||
|
||||
@@ -171,10 +171,12 @@ public class WifiP2pManager {
|
||||
* Broadcast intent action indicating that the state of Wi-Fi p2p connectivity
|
||||
* has changed. One extra {@link #EXTRA_WIFI_P2P_INFO} provides the p2p connection info in
|
||||
* the form of a {@link WifiP2pInfo} object. Another extra {@link #EXTRA_NETWORK_INFO} provides
|
||||
* the network info in the form of a {@link android.net.NetworkInfo}.
|
||||
* the network info in the form of a {@link android.net.NetworkInfo}. A third extra provides
|
||||
* the details of the group.
|
||||
*
|
||||
* @see #EXTRA_WIFI_P2P_INFO
|
||||
* @see #EXTRA_NETWORK_INFO
|
||||
* @see #EXTRA_WIFI_P2P_GROUP
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||
public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION =
|
||||
@@ -188,41 +190,46 @@ public class WifiP2pManager {
|
||||
|
||||
/**
|
||||
* The lookup key for a {@link android.net.NetworkInfo} object associated with the
|
||||
* Wi-Fi network. Retrieve with
|
||||
* p2p network. Retrieve with
|
||||
* {@link android.content.Intent#getParcelableExtra(String)}.
|
||||
*/
|
||||
public static final String EXTRA_NETWORK_INFO = "networkInfo";
|
||||
|
||||
/**
|
||||
* The lookup key for a {@link android.net.LinkProperties} object associated with the
|
||||
* network. Retrieve with
|
||||
* The lookup key for a {@link android.net.wifi.p2p.WifiP2pGroup} object
|
||||
* associated with the p2p network. Retrieve with
|
||||
* {@link android.content.Intent#getParcelableExtra(String)}.
|
||||
* @hide
|
||||
*/
|
||||
public static final String EXTRA_LINK_PROPERTIES = "linkProperties";
|
||||
public static final String EXTRA_WIFI_P2P_GROUP = "p2pGroupInfo";
|
||||
|
||||
/**
|
||||
* The lookup key for a {@link android.net.LinkCapabilities} object associated with the
|
||||
* network. Retrieve with
|
||||
* {@link android.content.Intent#getParcelableExtra(String)}.
|
||||
* @hide
|
||||
*/
|
||||
public static final String EXTRA_LINK_CAPABILITIES = "linkCapabilities";
|
||||
|
||||
/**
|
||||
* Broadcast intent action indicating that the available peer list has changed. Fetch
|
||||
* the changed list of peers with {@link #requestPeers}
|
||||
* Broadcast intent action indicating that the available peer list has changed. This
|
||||
* can be sent as a result of peers being found, lost or updated.
|
||||
*
|
||||
* <p> An extra {@link #EXTRA_P2P_DEVICE_LIST} provides the full list of
|
||||
* current peers. The full list of peers can also be obtained any time with
|
||||
* {@link #requestPeers}.
|
||||
*
|
||||
* @see #EXTRA_P2P_DEVICE_LIST
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||
public static final String WIFI_P2P_PEERS_CHANGED_ACTION =
|
||||
"android.net.wifi.p2p.PEERS_CHANGED";
|
||||
|
||||
/**
|
||||
* The lookup key for a {@link android.net.wifi.p2p.WifiP2pDeviceList} object representing
|
||||
* the new peer list when {@link #WIFI_P2P_PEERS_CHANGED_ACTION} broadcast is sent.
|
||||
*
|
||||
* <p>Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
|
||||
*/
|
||||
public static final String EXTRA_P2P_DEVICE_LIST = "wifiP2pDeviceList";
|
||||
|
||||
/**
|
||||
* Broadcast intent action indicating that peer discovery has either started or stopped.
|
||||
* One extra {@link #EXTRA_DISCOVERY_STATE} indicates whether discovery has started
|
||||
* or stopped.
|
||||
*
|
||||
* Note that discovery will be stopped during a connection setup. If the application tries
|
||||
* <p>Note that discovery will be stopped during a connection setup. If the application tries
|
||||
* to re-initiate discovery during this time, it can fail.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||
|
||||
@@ -791,7 +791,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
//Nothing to do
|
||||
break;
|
||||
case WifiStateMachine.CMD_DISABLE_P2P_REQ:
|
||||
if (mPeers.clear()) sendP2pPeersChangedBroadcast();
|
||||
if (mPeers.clear()) {
|
||||
sendPeersChangedBroadcast();
|
||||
}
|
||||
if (mGroups.clear()) sendP2pPersistentGroupsChangedBroadcast();
|
||||
|
||||
mWifiNative.closeSupplicantConnection();
|
||||
@@ -859,12 +861,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
case WifiMonitor.P2P_DEVICE_FOUND_EVENT:
|
||||
WifiP2pDevice device = (WifiP2pDevice) message.obj;
|
||||
if (mThisDevice.deviceAddress.equals(device.deviceAddress)) break;
|
||||
mPeers.update(device);
|
||||
sendP2pPeersChangedBroadcast();
|
||||
mPeers.updateSupplicantDetails(device);
|
||||
sendPeersChangedBroadcast();
|
||||
break;
|
||||
case WifiMonitor.P2P_DEVICE_LOST_EVENT:
|
||||
device = (WifiP2pDevice) message.obj;
|
||||
if (mPeers.remove(device)) sendP2pPeersChangedBroadcast();
|
||||
// Gets current details for the one removed
|
||||
device = mPeers.remove(device.deviceAddress);
|
||||
if (device != null) {
|
||||
sendPeersChangedBroadcast();
|
||||
}
|
||||
break;
|
||||
case WifiP2pManager.ADD_LOCAL_SERVICE:
|
||||
if (DBG) logd(getName() + " add service");
|
||||
@@ -960,7 +966,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
break;
|
||||
}
|
||||
mPeers.updateStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
|
||||
sendP2pPeersChangedBroadcast();
|
||||
sendPeersChangedBroadcast();
|
||||
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
|
||||
if (connectRet == NEEDS_PROVISION_REQ) {
|
||||
if (DBG) logd("Sending prov disc");
|
||||
@@ -1106,7 +1112,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
}
|
||||
// Do nothing
|
||||
if (DBG) logd("Add device to lost list " + device);
|
||||
mPeersLostDuringConnection.update(device);
|
||||
mPeersLostDuringConnection.updateSupplicantDetails(device);
|
||||
break;
|
||||
case WifiP2pManager.DISCOVER_PEERS:
|
||||
/* Discovery will break negotiation */
|
||||
@@ -1150,7 +1156,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
break;
|
||||
}
|
||||
mPeers.updateStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED);
|
||||
sendP2pPeersChangedBroadcast();
|
||||
sendPeersChangedBroadcast();
|
||||
transitionTo(mGroupNegotiationState);
|
||||
break;
|
||||
case PEER_CONNECTION_USER_REJECT:
|
||||
@@ -1282,9 +1288,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
|
||||
WifiP2pDevice groupOwner = mGroup.getOwner();
|
||||
/* update group owner details with the ones found at discovery */
|
||||
groupOwner.update(mPeers.get(groupOwner.deviceAddress));
|
||||
groupOwner.updateSupplicantDetails(mPeers.get(groupOwner.deviceAddress));
|
||||
mPeers.updateStatus(groupOwner.deviceAddress, WifiP2pDevice.CONNECTED);
|
||||
sendP2pPeersChangedBroadcast();
|
||||
sendPeersChangedBroadcast();
|
||||
}
|
||||
mSavedPeerConfig = null;
|
||||
transitionTo(mGroupCreatedState);
|
||||
@@ -1477,7 +1483,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
}
|
||||
mPeers.updateStatus(deviceAddress, WifiP2pDevice.CONNECTED);
|
||||
if (DBG) logd(getName() + " ap sta connected");
|
||||
sendP2pPeersChangedBroadcast();
|
||||
sendPeersChangedBroadcast();
|
||||
} else {
|
||||
loge("Connect on null device address, ignore");
|
||||
}
|
||||
@@ -1505,7 +1511,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
if (DBG) logd("client " + c.deviceAddress);
|
||||
}
|
||||
}
|
||||
sendP2pPeersChangedBroadcast();
|
||||
sendPeersChangedBroadcast();
|
||||
if (DBG) logd(getName() + " ap sta disconnected");
|
||||
} else {
|
||||
loge("Disconnect on unknown device: " + device);
|
||||
@@ -1558,7 +1564,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
//Device loss for a connected device indicates it is not in discovery any more
|
||||
if (mGroup.contains(device)) {
|
||||
if (DBG) logd("Add device to lost list " + device);
|
||||
mPeersLostDuringConnection.update(device);
|
||||
mPeersLostDuringConnection.updateSupplicantDetails(device);
|
||||
return HANDLED;
|
||||
}
|
||||
// Do the regular device lost handling
|
||||
@@ -1595,7 +1601,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
mSavedPeerConfig = config;
|
||||
if (mWifiNative.p2pInvite(mGroup, config.deviceAddress)) {
|
||||
mPeers.updateStatus(config.deviceAddress, WifiP2pDevice.INVITED);
|
||||
sendP2pPeersChangedBroadcast();
|
||||
sendPeersChangedBroadcast();
|
||||
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.CONNECT_FAILED,
|
||||
@@ -1771,8 +1777,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
|
||||
}
|
||||
|
||||
private void sendP2pPeersChangedBroadcast() {
|
||||
private void sendPeersChangedBroadcast() {
|
||||
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
|
||||
intent.putExtra(WifiP2pManager.EXTRA_P2P_DEVICE_LIST, mPeers);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
|
||||
}
|
||||
@@ -1784,6 +1791,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
| Intent.FLAG_RECEIVER_REPLACE_PENDING);
|
||||
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO, new WifiP2pInfo(mWifiP2pInfo));
|
||||
intent.putExtra(WifiP2pManager.EXTRA_NETWORK_INFO, new NetworkInfo(mNetworkInfo));
|
||||
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP, new WifiP2pGroup(mGroup));
|
||||
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
|
||||
mWifiChannel.sendMessage(WifiP2pService.P2P_CONNECTION_CHANGED,
|
||||
new NetworkInfo(mNetworkInfo));
|
||||
@@ -2311,26 +2319,24 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
resetWifiP2pInfo();
|
||||
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.FAILED, null, null);
|
||||
sendP2pConnectionChangedBroadcast();
|
||||
|
||||
// Remove only the peer we failed to connect to so that other devices discovered
|
||||
// that have not timed out still remain in list for connection
|
||||
boolean peersChanged = mPeers.remove(mPeersLostDuringConnection);
|
||||
if (mSavedPeerConfig != null && mPeers.remove(mSavedPeerConfig.deviceAddress) != null) {
|
||||
peersChanged = true;
|
||||
}
|
||||
if (peersChanged) {
|
||||
sendPeersChangedBroadcast();
|
||||
}
|
||||
|
||||
mSavedPeerConfig = null;
|
||||
/* After cancelling group formation, new connections on existing peers can fail
|
||||
* at supplicant. Flush and restart discovery */
|
||||
mWifiNative.p2pFlush();
|
||||
if (mPeers.remove(mPeersLostDuringConnection)) sendP2pPeersChangedBroadcast();
|
||||
mPeersLostDuringConnection.clear();
|
||||
mServiceDiscReqId = null;
|
||||
sendMessage(WifiP2pManager.DISCOVER_PEERS);
|
||||
}
|
||||
|
||||
private void handleGroupRemoved() {
|
||||
Collection <WifiP2pDevice> devices = mGroup.getClientList();
|
||||
boolean changed = false;
|
||||
for (WifiP2pDevice d : mPeers.getDeviceList()) {
|
||||
if (devices.contains(d) || mGroup.getOwner().equals(d)) {
|
||||
d.status = WifiP2pDevice.AVAILABLE;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mGroup.isGroupOwner()) {
|
||||
stopDhcpServer(mGroup.getInterface());
|
||||
} else {
|
||||
@@ -2351,12 +2357,21 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
// that reuse the main p2p interface for a created group.
|
||||
mWifiNative.setP2pGroupIdle(mGroup.getInterface(), 0);
|
||||
|
||||
boolean peersChanged = false;
|
||||
// Remove only peers part of the group, so that other devices discovered
|
||||
// that have not timed out still remain in list for connection
|
||||
for (WifiP2pDevice d : mGroup.getClientList()) {
|
||||
if (mPeers.remove(d)) peersChanged = true;
|
||||
}
|
||||
if (mPeers.remove(mGroup.getOwner())) peersChanged = true;
|
||||
if (mPeers.remove(mPeersLostDuringConnection)) peersChanged = true;
|
||||
if (peersChanged) {
|
||||
sendPeersChangedBroadcast();
|
||||
}
|
||||
|
||||
mGroup = null;
|
||||
mWifiNative.p2pFlush();
|
||||
if (mPeers.remove(mPeersLostDuringConnection)) sendP2pPeersChangedBroadcast();
|
||||
mPeersLostDuringConnection.clear();
|
||||
mServiceDiscReqId = null;
|
||||
if (changed) sendP2pPeersChangedBroadcast();
|
||||
|
||||
if (mTempoarilyDisconnectedWifi) {
|
||||
mWifiChannel.sendMessage(WifiP2pService.DISCONNECT_WIFI_REQUEST, 0);
|
||||
|
||||
Reference in New Issue
Block a user