summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java286
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareStateManager.java40
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java31
3 files changed, 146 insertions, 211 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
index b0a3f027a..14d855e00 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
@@ -30,24 +30,19 @@ import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.NetworkSpecifier;
import android.net.RouteInfo;
-import android.net.StringNetworkSpecifier;
import android.net.wifi.aware.WifiAwareManager;
+import android.net.wifi.aware.WifiAwareNetworkSpecifier;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.Looper;
import android.os.ServiceManager;
-import android.text.TextUtils;
import android.util.ArrayMap;
-import android.util.Base64;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import libcore.util.HexEncoding;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.net.Inet6Address;
@@ -68,8 +63,6 @@ import java.util.Set;
* - capabilities = NET_CAPABILITY_NOT_VPN
* - network specifier generated by DiscoverySession.createNetworkSpecifier(...) or
* WifiAwareManager.createNetworkSpecifier(...).
- * The network specifier is encoded as a JSON string with the key combos described in
- * {@link WifiAwareManager} as {@code NETWORK_SPECIFIER_TYPE_*}.
*/
public class WifiAwareDataPathStateManager {
private static final String TAG = "WifiAwareDataPathStMgr";
@@ -88,8 +81,8 @@ public class WifiAwareDataPathStateManager {
private final NetworkInterfaceWrapper mNiWrapper = new NetworkInterfaceWrapper();
private final NetworkCapabilities mNetworkCapabilitiesFilter = new NetworkCapabilities();
private final Set<String> mInterfaces = new HashSet<>();
- private final Map<String, AwareNetworkRequestInformation> mNetworkRequestsCache =
- new ArrayMap<>();
+ private final Map<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation>
+ mNetworkRequestsCache = new ArrayMap<>();
private Context mContext;
private Looper mLooper;
private WifiAwareNetworkFactory mNetworkFactory;
@@ -129,9 +122,10 @@ public class WifiAwareDataPathStateManager {
mNwService = INetworkManagementService.Stub.asInterface(b);
}
- private Map.Entry<String, AwareNetworkRequestInformation> getNetworkRequestByNdpId(int ndpId) {
- for (Map.Entry<String, AwareNetworkRequestInformation> entry : mNetworkRequestsCache
- .entrySet()) {
+ private Map.Entry<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation>
+ getNetworkRequestByNdpId(int ndpId) {
+ for (Map.Entry<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation> entry :
+ mNetworkRequestsCache.entrySet()) {
if (entry.getValue().ndpId == ndpId) {
return entry;
}
@@ -211,7 +205,7 @@ public class WifiAwareDataPathStateManager {
* @param networkSpecifier The network specifier provided as part of the initiate request.
* @param ndpId The ID assigned to the data-path.
*/
- public void onDataPathInitiateSuccess(String networkSpecifier, int ndpId) {
+ public void onDataPathInitiateSuccess(WifiAwareNetworkSpecifier networkSpecifier, int ndpId) {
if (VDBG) {
Log.v(TAG,
"onDataPathInitiateSuccess: networkSpecifier=" + networkSpecifier + ", ndpId="
@@ -245,7 +239,7 @@ public class WifiAwareDataPathStateManager {
* @param networkSpecifier The network specifier provided as part of the initiate request.
* @param reason Failure reason.
*/
- public void onDataPathInitiateFail(String networkSpecifier, int reason) {
+ public void onDataPathInitiateFail(WifiAwareNetworkSpecifier networkSpecifier, int reason) {
if (VDBG) {
Log.v(TAG,
"onDataPathInitiateFail: networkSpecifier=" + networkSpecifier + ", reason="
@@ -279,17 +273,17 @@ public class WifiAwareDataPathStateManager {
* @param ndpId The locally assigned ID for the data-path.
* @return The network specifier of the data-path (or null if none/error)
*/
- public String onDataPathRequest(int pubSubId, byte[] mac, int ndpId) {
+ public WifiAwareNetworkSpecifier onDataPathRequest(int pubSubId, byte[] mac, int ndpId) {
if (VDBG) {
Log.v(TAG,
"onDataPathRequest: pubSubId=" + pubSubId + ", mac=" + String.valueOf(
HexEncoding.encode(mac)) + ", ndpId=" + ndpId);
}
- String networkSpecifier = null;
+ WifiAwareNetworkSpecifier networkSpecifier = null;
AwareNetworkRequestInformation nnri = null;
- for (Map.Entry<String, AwareNetworkRequestInformation> entry : mNetworkRequestsCache
- .entrySet()) {
+ for (Map.Entry<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation> entry :
+ mNetworkRequestsCache.entrySet()) {
/*
* Checking that the incoming request (from the Initiator) matches the request
* we (the Responder) already have set up. The rules are:
@@ -332,7 +326,8 @@ public class WifiAwareDataPathStateManager {
nnri.state = AwareNetworkRequestInformation.STATE_RESPONDER_WAIT_FOR_RESPOND_RESPONSE;
nnri.ndpId = ndpId;
nnri.interfaceName = selectInterfaceForRequest(nnri);
- mMgr.respondToDataPathRequest(true, ndpId, nnri.interfaceName, nnri.pmk, nnri.passphrase);
+ mMgr.respondToDataPathRequest(true, ndpId, nnri.interfaceName, nnri.networkSpecifier.pmk,
+ nnri.networkSpecifier.passphrase);
return networkSpecifier;
}
@@ -348,10 +343,10 @@ public class WifiAwareDataPathStateManager {
Log.v(TAG, "onRespondToDataPathRequest: ndpId=" + ndpId + ", success=" + success);
}
- String networkSpecifier = null;
+ WifiAwareNetworkSpecifier networkSpecifier = null;
AwareNetworkRequestInformation nnri = null;
- for (Map.Entry<String, AwareNetworkRequestInformation> entry : mNetworkRequestsCache
- .entrySet()) {
+ for (Map.Entry<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation> entry :
+ mNetworkRequestsCache.entrySet()) {
if (entry.getValue().ndpId == ndpId) {
networkSpecifier = entry.getKey();
nnri = entry.getValue();
@@ -406,14 +401,15 @@ public class WifiAwareDataPathStateManager {
* process.
* @return The network specifier of the data-path or a null if none/error.
*/
- public String onDataPathConfirm(int ndpId, byte[] mac, boolean accept, int reason,
- byte[] message) {
+ public WifiAwareNetworkSpecifier onDataPathConfirm(int ndpId, byte[] mac, boolean accept,
+ int reason, byte[] message) {
if (VDBG) {
Log.v(TAG, "onDataPathConfirm: ndpId=" + ndpId + ", mac=" + String.valueOf(
HexEncoding.encode(mac)) + ", accept=" + accept + ", reason=" + reason);
}
- Map.Entry<String, AwareNetworkRequestInformation> nnriE = getNetworkRequestByNdpId(ndpId);
+ Map.Entry<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation> nnriE =
+ getNetworkRequestByNdpId(ndpId);
if (nnriE == null) {
Log.w(TAG, "onDataPathConfirm: network request not found for ndpId=" + ndpId);
if (accept) {
@@ -422,11 +418,11 @@ public class WifiAwareDataPathStateManager {
return null;
}
- String networkSpecifier = nnriE.getKey();
+ WifiAwareNetworkSpecifier networkSpecifier = nnriE.getKey();
AwareNetworkRequestInformation nnri = nnriE.getValue();
// validate state
- if (nnri.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
+ if (nnri.networkSpecifier.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
&& nnri.state != AwareNetworkRequestInformation.STATE_INITIATOR_WAIT_FOR_CONFIRM) {
Log.w(TAG, "onDataPathConfirm: INITIATOR in invalid state=" + nnri.state);
mNetworkRequestsCache.remove(networkSpecifier);
@@ -435,7 +431,7 @@ public class WifiAwareDataPathStateManager {
}
return networkSpecifier;
}
- if (nnri.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER
+ if (nnri.networkSpecifier.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER
&& nnri.state != AwareNetworkRequestInformation.STATE_RESPONDER_WAIT_FOR_CONFIRM) {
Log.w(TAG, "onDataPathConfirm: RESPONDER in invalid state=" + nnri.state);
mNetworkRequestsCache.remove(networkSpecifier);
@@ -446,7 +442,8 @@ public class WifiAwareDataPathStateManager {
}
if (accept) {
- nnri.state = (nnri.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR)
+ nnri.state = (nnri.networkSpecifier.role
+ == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR)
? AwareNetworkRequestInformation.STATE_INITIATOR_CONFIRMED
: AwareNetworkRequestInformation.STATE_RESPONDER_CONFIRMED;
nnri.peerDataMac = mac;
@@ -498,7 +495,8 @@ public class WifiAwareDataPathStateManager {
public void onDataPathEnd(int ndpId) {
if (VDBG) Log.v(TAG, "onDataPathEnd: ndpId=" + ndpId);
- Map.Entry<String, AwareNetworkRequestInformation> nnriE = getNetworkRequestByNdpId(ndpId);
+ Map.Entry<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation> nnriE =
+ getNetworkRequestByNdpId(ndpId);
if (nnriE == null) {
if (DBG) {
Log.d(TAG, "onDataPathEnd: network request not found for ndpId=" + ndpId);
@@ -528,7 +526,7 @@ public class WifiAwareDataPathStateManager {
* and on the responder when received a request for data-path (in both cases only on success
* - i.e. when we're proceeding with data-path setup).
*/
- public void handleDataPathTimeout(String networkSpecifier) {
+ public void handleDataPathTimeout(NetworkSpecifier networkSpecifier) {
if (VDBG) Log.v(TAG, "handleDataPathTimeout: networkSpecifier=" + networkSpecifier);
AwareNetworkRequestInformation nnri = mNetworkRequestsCache.remove(networkSpecifier);
@@ -570,17 +568,16 @@ public class WifiAwareDataPathStateManager {
return false;
}
- NetworkSpecifier networkSpecifierObj =
+ NetworkSpecifier networkSpecifierBase =
request.networkCapabilities.getNetworkSpecifier();
- if (networkSpecifierObj == null
- || !(networkSpecifierObj instanceof StringNetworkSpecifier)
- || TextUtils.isEmpty(
- ((StringNetworkSpecifier) networkSpecifierObj).specifier)) {
+ if (!(networkSpecifierBase instanceof WifiAwareNetworkSpecifier)) {
Log.w(TAG, "WifiAwareNetworkFactory.acceptRequest: request=" + request
- + " - null, empty, or not a StringNetworkSpecifier");
+ + " - not a WifiAwareNetworkSpecifier");
return false;
}
- String networkSpecifier = ((StringNetworkSpecifier) networkSpecifierObj).specifier;
+
+ WifiAwareNetworkSpecifier networkSpecifier =
+ (WifiAwareNetworkSpecifier) networkSpecifierBase;
// look up specifier - are we being called again?
AwareNetworkRequestInformation nnri = mNetworkRequestsCache.get(networkSpecifier);
@@ -595,10 +592,9 @@ public class WifiAwareDataPathStateManager {
return true;
}
- // parse network specifier (JSON) & cache
// TODO: validate that the client ID actually comes from the correct process and is
// not faked?
- nnri = AwareNetworkRequestInformation.parseNetworkSpecifier(networkSpecifier, mMgr);
+ nnri = AwareNetworkRequestInformation.processNetworkSpecifier(networkSpecifier, mMgr);
if (nnri == null) {
Log.e(TAG, "WifiAwareNetworkFactory.acceptRequest: request=" + request
+ " - can't parse network specifier");
@@ -618,10 +614,9 @@ public class WifiAwareDataPathStateManager {
NetworkSpecifier networkSpecifierObj =
networkRequest.networkCapabilities.getNetworkSpecifier();
- String networkSpecifier = "";
- if (networkSpecifierObj != null
- && networkSpecifierObj instanceof StringNetworkSpecifier) {
- networkSpecifier = ((StringNetworkSpecifier) networkSpecifierObj).specifier;
+ WifiAwareNetworkSpecifier networkSpecifier = null;
+ if (networkSpecifierObj instanceof WifiAwareNetworkSpecifier) {
+ networkSpecifier = (WifiAwareNetworkSpecifier) networkSpecifierObj;
}
AwareNetworkRequestInformation nnri = mNetworkRequestsCache.get(networkSpecifier);
if (nnri == null) {
@@ -630,7 +625,8 @@ public class WifiAwareDataPathStateManager {
return;
}
- if (nnri.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR) {
+ if (nnri.networkSpecifier.role
+ == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR) {
if (nnri.state != AwareNetworkRequestInformation.STATE_INITIATOR_IDLE) {
if (DBG) {
Log.d(TAG, "WifiAwareNetworkFactory.needNetworkFor: networkRequest="
@@ -642,9 +638,10 @@ public class WifiAwareDataPathStateManager {
}
nnri.interfaceName = selectInterfaceForRequest(nnri);
- mMgr.initiateDataPathSetup(networkSpecifier, nnri.peerId,
+ mMgr.initiateDataPathSetup(networkSpecifier, nnri.networkSpecifier.peerId,
NanDataPathChannelCfg.REQUEST_CHANNEL_SETUP, selectChannelForRequest(nnri),
- nnri.peerDiscoveryMac, nnri.interfaceName, nnri.pmk, nnri.passphrase);
+ nnri.peerDiscoveryMac, nnri.interfaceName, nnri.networkSpecifier.pmk,
+ nnri.networkSpecifier.passphrase);
nnri.state =
AwareNetworkRequestInformation.STATE_INITIATOR_WAIT_FOR_REQUEST_RESPONSE;
} else {
@@ -671,10 +668,9 @@ public class WifiAwareDataPathStateManager {
NetworkSpecifier networkSpecifierObj =
networkRequest.networkCapabilities.getNetworkSpecifier();
- String networkSpecifier = "";
- if (networkSpecifierObj != null
- && networkSpecifierObj instanceof StringNetworkSpecifier) {
- networkSpecifier = ((StringNetworkSpecifier) networkSpecifierObj).specifier;
+ WifiAwareNetworkSpecifier networkSpecifier = null;
+ if (networkSpecifierObj instanceof WifiAwareNetworkSpecifier) {
+ networkSpecifier = (WifiAwareNetworkSpecifier) networkSpecifierObj;
}
AwareNetworkRequestInformation nnri = mNetworkRequestsCache.get(networkSpecifier);
@@ -694,11 +690,13 @@ public class WifiAwareDataPathStateManager {
return;
}
- if (nnri.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR && nnri.state
+ if (nnri.networkSpecifier.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
+ && nnri.state
> AwareNetworkRequestInformation.STATE_INITIATOR_WAIT_FOR_REQUEST_RESPONSE) {
mMgr.endDataPath(nnri.ndpId);
}
- if (nnri.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER && nnri.state
+ if (nnri.networkSpecifier.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER
+ && nnri.state
> AwareNetworkRequestInformation.STATE_RESPONDER_WAIT_FOR_REQUEST) {
mMgr.endDataPath(nnri.ndpId);
}
@@ -710,12 +708,12 @@ public class WifiAwareDataPathStateManager {
private class WifiAwareNetworkAgent extends NetworkAgent {
private NetworkInfo mNetworkInfo;
- private String mNetworkSpecifier;
+ private WifiAwareNetworkSpecifier mNetworkSpecifier;
private int mNdpId;
WifiAwareNetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
- NetworkCapabilities nc, LinkProperties lp, int score, String networkSpecifier,
- int ndpId) {
+ NetworkCapabilities nc, LinkProperties lp, int score,
+ WifiAwareNetworkSpecifier networkSpecifier, int ndpId) {
super(looper, context, logTag, ni, nc, lp, score);
mNetworkInfo = ni;
@@ -807,170 +805,99 @@ public class WifiAwareDataPathStateManager {
static final int STATE_RESPONDER_CONFIRMED = 204;
public int state;
- public int role;
public int uid;
public String interfaceName;
public int pubSubId = 0;
- public int peerId = 0;
public byte[] peerDiscoveryMac = null;
- public byte[] pmk = null;
- public String passphrase = null;
public int ndpId;
public byte[] peerDataMac;
+ public WifiAwareNetworkSpecifier networkSpecifier;
public WifiAwareNetworkAgent networkAgent;
- static AwareNetworkRequestInformation parseNetworkSpecifier(String networkSpecifier,
+ static AwareNetworkRequestInformation processNetworkSpecifier(WifiAwareNetworkSpecifier ns,
WifiAwareStateManager mgr) {
- int type, role, uid, clientId, sessionId = 0, peerId = 0, pubSubId = 0;
- byte[] peerMac = null;
- byte[] pmk = null;
- String passphrase = null;
+ int uid, pubSubId = 0;
+ byte[] peerMac = ns.peerMac;
if (VDBG) {
- Log.v(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier);
+ Log.v(TAG, "processNetworkSpecifier: networkSpecifier=" + ns);
}
- try {
- JSONObject jsonObject = new JSONObject(networkSpecifier);
-
- // type: always present
- type = jsonObject.getInt(WifiAwareManager.NETWORK_SPECIFIER_KEY_TYPE);
- if (type < 0 || type > WifiAwareManager.NETWORK_SPECIFIER_TYPE_MAX_VALID) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + ", invalid 'type' value");
- return null;
- }
-
- // role: always present
- role = jsonObject.getInt(WifiAwareManager.NETWORK_SPECIFIER_KEY_ROLE);
- if (role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
- && role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- invalid 'role' value");
- return null;
- }
-
- if (role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
- && type != WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB
- && type != WifiAwareManager.NETWORK_SPECIFIER_TYPE_OOB) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- invalid 'type' value for INITIATOR (only IB and OOB are "
- + "permitted)");
- return null;
- }
-
- // clientId: always present
- clientId = jsonObject.getInt(WifiAwareManager.NETWORK_SPECIFIER_KEY_CLIENT_ID);
-
- // sessionId: present for types IB, IB_ANY_PEER
- if (type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB
- || type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB_ANY_PEER) {
- sessionId = jsonObject.getInt(
- WifiAwareManager.NETWORK_SPECIFIER_KEY_SESSION_ID);
- }
-
- // peer Id: present for type IB
- if (type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB) {
- peerId = jsonObject.getInt(WifiAwareManager.NETWORK_SPECIFIER_KEY_PEER_ID);
- }
-
- // peerMac: present for type OOB
- if (type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_OOB) {
- try {
- peerMac = HexEncoding.decode(jsonObject.getString(
- WifiAwareManager.NETWORK_SPECIFIER_KEY_PEER_MAC).toCharArray(),
- false);
- if (peerMac == null || peerMac.length != 6) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- invalid peer MAC address - null or not 6 bytes");
- return null;
- }
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier="
- + networkSpecifier + " -- invalid peer MAC address -- e=" + e);
- return null;
- }
- }
-
- // pmk: always present (though can be an empty array - equivalent to null)
- pmk = Base64.decode(
- jsonObject.getString(WifiAwareManager.NETWORK_SPECIFIER_KEY_PMK),
- Base64.DEFAULT);
- if (pmk != null && pmk.length == 0) {
- pmk = null;
- }
+ // type: always valid
+ if (ns.type < 0
+ || ns.type > WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_MAX_VALID) {
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ + ", invalid 'type' value");
+ return null;
+ }
- // passphrase: always present (though can be an empty string - equivalent to null)
- passphrase = jsonObject.getString(
- WifiAwareManager.NETWORK_SPECIFIER_KEY_PASSPHRASE);
- if (passphrase != null && passphrase.length() == 0) {
- passphrase = null;
- }
+ // role: always valid
+ if (ns.role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
+ && ns.role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER) {
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ + " -- invalid 'role' value");
+ return null;
+ }
- if (passphrase != null) {
- if (pmk != null) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- invalid: can't specify both PMK and Passphrase");
- return null;
- }
- }
- } catch (JSONException e) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- invalid JSON format -- e=" + e);
+ if (ns.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
+ && ns.type != WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB
+ && ns.type != WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_OOB) {
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ + " -- invalid 'type' value for INITIATOR (only IB and OOB are "
+ + "permitted)");
return null;
}
// look up network specifier information in Aware state manager
- WifiAwareClientState client = mgr.getClient(clientId);
+ WifiAwareClientState client = mgr.getClient(ns.clientId);
if (client == null) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- not client with this id -- clientId=" + clientId);
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ + " -- not client with this id -- clientId=" + ns.clientId);
return null;
}
uid = client.getUid();
// validate the role (if session ID provided: i.e. session 1xx)
- if (type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB
- || type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB_ANY_PEER) {
- WifiAwareDiscoverySessionState session = client.getSession(sessionId);
+ if (ns.type == WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB
+ || ns.type == WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB_ANY_PEER) {
+ WifiAwareDiscoverySessionState session = client.getSession(ns.sessionId);
if (session == null) {
Log.e(TAG,
- "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- no session with this id -- sessionId=" + sessionId);
+ "processNetworkSpecifier: networkSpecifier=" + ns
+ + " -- no session with this id -- sessionId=" + ns.sessionId);
return null;
}
if ((session.isPublishSession()
- && role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER) || (
- !session.isPublishSession()
- && role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR)) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
+ && ns.role != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER) || (
+ !session.isPublishSession() && ns.role
+ != WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR)) {
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ " -- invalid role for session type");
return null;
}
- if (type == WifiAwareManager.NETWORK_SPECIFIER_TYPE_IB) {
+ if (ns.type == WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB) {
pubSubId = session.getPubSubId();
- String peerMacStr = session.getMac(peerId, null);
+ String peerMacStr = session.getMac(ns.peerId, null);
if (peerMacStr == null) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ " -- no MAC address associated with this peer id -- peerId="
- + peerId);
+ + ns.peerId);
return null;
}
try {
peerMac = HexEncoding.decode(peerMacStr.toCharArray(), false);
if (peerMac == null || peerMac.length != 6) {
- Log.e(TAG, "parseNetworkSpecifier: networkSpecifier="
- + networkSpecifier + " -- invalid peer MAC address");
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier="
+ + ns + " -- invalid peer MAC address");
return null;
}
} catch (IllegalArgumentException e) {
- Log.e(TAG,
- "parseNetworkSpecifier: networkSpecifier=" + networkSpecifier
- + " -- invalid peer MAC address -- e=" + e);
+ Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns
+ + " -- invalid peer MAC address -- e=" + e);
return null;
}
}
@@ -978,16 +905,13 @@ public class WifiAwareDataPathStateManager {
// create container and populate
AwareNetworkRequestInformation nnri = new AwareNetworkRequestInformation();
- nnri.state = (role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR)
+ nnri.state = (ns.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR)
? AwareNetworkRequestInformation.STATE_INITIATOR_IDLE
: AwareNetworkRequestInformation.STATE_RESPONDER_IDLE;
- nnri.role = role;
nnri.uid = uid;
nnri.pubSubId = pubSubId;
- nnri.peerId = peerId;
nnri.peerDiscoveryMac = peerMac;
- nnri.pmk = pmk;
- nnri.passphrase = passphrase;
+ nnri.networkSpecifier = ns;
return nnri;
}
@@ -995,7 +919,7 @@ public class WifiAwareDataPathStateManager {
@Override
public String toString() {
StringBuilder sb = new StringBuilder("AwareNetworkRequestInformation: ");
- sb.append("state=").append(state).append(", role=").append(role).append(
+ sb.append("state=").append(state).append(", ns=").append(networkSpecifier).append(
", uid=").append(uid).append(", interfaceName=").append(interfaceName).append(
", pubSubId=").append(pubSubId).append(", peerDiscoveryMac=").append(
peerDiscoveryMac == null ? ""
@@ -1016,7 +940,7 @@ public class WifiAwareDataPathStateManager {
* name. Delegated to enable mocking.
*/
public boolean configureAgentProperties(AwareNetworkRequestInformation nnri,
- String networkSpecifier, int ndpId, NetworkInfo networkInfo,
+ WifiAwareNetworkSpecifier networkSpecifier, int ndpId, NetworkInfo networkInfo,
NetworkCapabilities networkCapabilities, LinkProperties linkProperties) {
// find link-local address
InetAddress linkLocal = null;
@@ -1054,7 +978,7 @@ public class WifiAwareDataPathStateManager {
networkInfo.setIsAvailable(true);
networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
- networkCapabilities.setNetworkSpecifier(new StringNetworkSpecifier(networkSpecifier));
+ networkCapabilities.setNetworkSpecifier(networkSpecifier);
linkProperties.setInterfaceName(nnri.interfaceName);
linkProperties.addLinkAddress(new LinkAddress(linkLocal, 64));
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
index 76bfcea55..a35c786ee 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
@@ -27,6 +27,7 @@ import android.net.wifi.aware.IWifiAwareEventCallback;
import android.net.wifi.aware.PublishConfig;
import android.net.wifi.aware.SubscribeConfig;
import android.net.wifi.aware.WifiAwareManager;
+import android.net.wifi.aware.WifiAwareNetworkSpecifier;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
@@ -465,8 +466,9 @@ public class WifiAwareStateManager {
/**
* Command to initiate a data-path (executed by the initiator).
*/
- public void initiateDataPathSetup(String networkSpecifier, int peerId, int channelRequestType,
- int channel, byte[] peer, String interfaceName, byte[] pmk, String passphrase) {
+ public void initiateDataPathSetup(WifiAwareNetworkSpecifier networkSpecifier, int peerId,
+ int channelRequestType, int channel, byte[] peer, String interfaceName, byte[] pmk,
+ String passphrase) {
Message msg = mSm.obtainMessage(MESSAGE_TYPE_COMMAND);
msg.arg1 = COMMAND_TYPE_INITIATE_DATA_PATH_SETUP;
msg.obj = networkSpecifier;
@@ -636,8 +638,8 @@ public class WifiAwareStateManager {
}
/**
- * Response from firmware to {@link #initiateDataPathSetup(String, int, int, int, byte[],
- * String, byte[], String)}. Indicates that command has started succesfully (not completed!).
+ * Response from firmware to initiateDataPathSetup(...). Indicates that command has started
+ * succesfully (not completed!).
*/
public void onInitiateDataPathResponseSuccess(short transactionId, int ndpId) {
Message msg = mSm.obtainMessage(MESSAGE_TYPE_RESPONSE);
@@ -648,8 +650,7 @@ public class WifiAwareStateManager {
}
/**
- * Response from firmware to
- * {@link #initiateDataPathSetup(String, int, int, int, byte[], String, byte[], String)}.
+ * Response from firmware to initiateDataPathSetup(...).
* Indicates that command has failed.
*/
public void onInitiateDataPathResponseFail(short transactionId, int reason) {
@@ -856,7 +857,8 @@ public class WifiAwareStateManager {
HAL_SEND_MESSAGE_TIMEOUT_TAG, MESSAGE_TYPE_SEND_MESSAGE_TIMEOUT);
private static final long AWARE_WAIT_FOR_DP_CONFIRM_TIMEOUT = 5_000;
- private final Map<String, WakeupMessage> mDataPathConfirmTimeoutMessages = new ArrayMap<>();
+ private final Map<WifiAwareNetworkSpecifier, WakeupMessage>
+ mDataPathConfirmTimeoutMessages = new ArrayMap<>();
WifiAwareStateMachine(String name, Looper looper) {
super(name, looper);
@@ -889,7 +891,8 @@ public class WifiAwareStateManager {
processSendMessageTimeout();
return HANDLED;
case MESSAGE_TYPE_DATA_PATH_TIMEOUT: {
- String networkSpecifier = (String) msg.obj;
+ WifiAwareNetworkSpecifier networkSpecifier =
+ (WifiAwareNetworkSpecifier) msg.obj;
if (VDBG) {
Log.v(TAG, "MESSAGE_TYPE_DATA_PATH_TIMEOUT: networkSpecifier="
@@ -1127,8 +1130,8 @@ public class WifiAwareStateManager {
break;
}
case NOTIFICATION_TYPE_ON_DATA_PATH_REQUEST: {
- String networkSpecifier = mDataPathMgr.onDataPathRequest(msg.arg2,
- msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MAC_ADDRESS),
+ WifiAwareNetworkSpecifier networkSpecifier = mDataPathMgr.onDataPathRequest(
+ msg.arg2, msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MAC_ADDRESS),
(int) msg.obj);
if (networkSpecifier != null) {
@@ -1143,8 +1146,8 @@ public class WifiAwareStateManager {
break;
}
case NOTIFICATION_TYPE_ON_DATA_PATH_CONFIRM: {
- String networkSpecifier = mDataPathMgr.onDataPathConfirm(msg.arg2,
- msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MAC_ADDRESS),
+ WifiAwareNetworkSpecifier networkSpecifier = mDataPathMgr.onDataPathConfirm(
+ msg.arg2, msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MAC_ADDRESS),
msg.getData().getBoolean(MESSAGE_BUNDLE_KEY_SUCCESS_FLAG),
msg.getData().getInt(MESSAGE_BUNDLE_KEY_STATUS_CODE),
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE_DATA));
@@ -1364,7 +1367,8 @@ public class WifiAwareStateManager {
case COMMAND_TYPE_INITIATE_DATA_PATH_SETUP: {
Bundle data = msg.getData();
- String networkSpecifier = (String) msg.obj;
+ WifiAwareNetworkSpecifier networkSpecifier =
+ (WifiAwareNetworkSpecifier) msg.obj;
int peerId = data.getInt(MESSAGE_BUNDLE_KEY_PEER_ID);
int channelRequestType = data.getInt(MESSAGE_BUNDLE_KEY_CHANNEL_REQ_TYPE);
@@ -2068,9 +2072,9 @@ public class WifiAwareStateManager {
mRtt.startRanging(rangingId, client, params);
}
- private boolean initiateDataPathSetupLocal(short transactionId, String networkSpecifier,
- int peerId, int channelRequestType, int channel, byte[] peer, String interfaceName,
- byte[] pmk, String passphrase) {
+ private boolean initiateDataPathSetupLocal(short transactionId,
+ WifiAwareNetworkSpecifier networkSpecifier, int peerId, int channelRequestType,
+ int channel, byte[] peer, String interfaceName, byte[] pmk, String passphrase) {
if (VDBG) {
Log.v(TAG,
"initiateDataPathSetupLocal(): transactionId=" + transactionId
@@ -2412,7 +2416,7 @@ public class WifiAwareStateManager {
+ ndpId);
}
- mDataPathMgr.onDataPathInitiateSuccess((String) command.obj, ndpId);
+ mDataPathMgr.onDataPathInitiateSuccess((WifiAwareNetworkSpecifier) command.obj, ndpId);
}
private void onInitiateDataPathResponseFailLocal(Message command, int reason) {
@@ -2421,7 +2425,7 @@ public class WifiAwareStateManager {
+ reason);
}
- mDataPathMgr.onDataPathInitiateFail((String) command.obj, reason);
+ mDataPathMgr.onDataPathInitiateFail((WifiAwareNetworkSpecifier) command.obj, reason);
}
private void onRespondToDataPathSetupRequestResponseLocal(Message command, boolean success,
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
index 912dce2f3..e7a383c5e 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
@@ -37,7 +37,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
import android.net.NetworkRequest;
-import android.net.StringNetworkSpecifier;
+import android.net.NetworkSpecifier;
import android.net.wifi.aware.AttachCallback;
import android.net.wifi.aware.ConfigRequest;
import android.net.wifi.aware.DiscoverySession;
@@ -51,6 +51,7 @@ import android.net.wifi.aware.PublishDiscoverySession;
import android.net.wifi.aware.SubscribeConfig;
import android.net.wifi.aware.SubscribeDiscoverySession;
import android.net.wifi.aware.WifiAwareManager;
+import android.net.wifi.aware.WifiAwareNetworkSpecifier;
import android.net.wifi.aware.WifiAwareSession;
import android.os.Handler;
import android.os.INetworkManagementService;
@@ -64,7 +65,6 @@ import com.android.internal.util.AsyncChannel;
import libcore.util.HexEncoding;
-import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -418,12 +418,19 @@ public class WifiAwareDataPathStateManagerTest {
doPublish);
// corrupt the network specifier: reverse the role (so it's mis-matched)
- JSONObject jsonObject = new JSONObject(
- ((StringNetworkSpecifier) nr.networkCapabilities.getNetworkSpecifier()).specifier);
- jsonObject.put(WifiAwareManager.NETWORK_SPECIFIER_KEY_ROLE,
- 1 - jsonObject.getInt(WifiAwareManager.NETWORK_SPECIFIER_KEY_ROLE));
- nr.networkCapabilities.setNetworkSpecifier(
- new StringNetworkSpecifier(jsonObject.toString()));
+ WifiAwareNetworkSpecifier ns =
+ (WifiAwareNetworkSpecifier) nr.networkCapabilities.getNetworkSpecifier();
+ ns = new WifiAwareNetworkSpecifier(
+ ns.type,
+ 1 - ns.role, // corruption hack
+ ns.clientId,
+ ns.sessionId,
+ ns.peerId,
+ ns.peerMac,
+ ns.pmk,
+ ns.passphrase
+ );
+ nr.networkCapabilities.setNetworkSpecifier(ns);
Message reqNetworkMsg = Message.obtain();
reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK;
@@ -682,7 +689,7 @@ public class WifiAwareDataPathStateManagerTest {
(SubscribeDiscoverySession) discoverySession.capture());
}
- String ns;
+ NetworkSpecifier ns;
if (pmk == null) {
ns = discoverySession.getValue().createNetworkSpecifierOpen(peerHandle);
} else {
@@ -694,7 +701,7 @@ public class WifiAwareDataPathStateManagerTest {
nc.addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE);
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN).addCapability(
NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
- nc.setNetworkSpecifier(new StringNetworkSpecifier(ns));
+ nc.setNetworkSpecifier(ns);
nc.setLinkUpstreamBandwidthKbps(1);
nc.setLinkDownstreamBandwidthKbps(1);
nc.setSignalStrength(1);
@@ -721,7 +728,7 @@ public class WifiAwareDataPathStateManagerTest {
mMockLooper.dispatchAll();
verify(mockCallback).onAttached(sessionCaptor.capture());
- String ns;
+ NetworkSpecifier ns;
if (pmk == null) {
ns = sessionCaptor.getValue().createNetworkSpecifierOpen(role, peer);
} else {
@@ -732,7 +739,7 @@ public class WifiAwareDataPathStateManagerTest {
nc.addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE);
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN).addCapability(
NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
- nc.setNetworkSpecifier(new StringNetworkSpecifier(ns));
+ nc.setNetworkSpecifier(ns);
nc.setLinkUpstreamBandwidthKbps(1);
nc.setLinkDownstreamBandwidthKbps(1);
nc.setSignalStrength(1);