Skip to content

Commit f625436

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Handle ascii encoded SSID" into jb-mr1-dev
2 parents 25da937 + b6deeed commit f625436

File tree

8 files changed

+326
-40
lines changed

8 files changed

+326
-40
lines changed

wifi/java/android/net/wifi/ScanResult.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
public class ScanResult implements Parcelable {
2929
/** The network name. */
3030
public String SSID;
31+
32+
/** Ascii encoded SSID. This will replace SSID when we deprecate it. @hide */
33+
public WifiSsid wifiSsid;
34+
3135
/** The address of the access point. */
3236
public String BSSID;
3337
/**
@@ -52,25 +56,23 @@ public class ScanResult implements Parcelable {
5256
*/
5357
public long timestamp;
5458

55-
/**
56-
* We'd like to obtain the following attributes,
57-
* but they are not reported via the socket
58-
* interface, even though they are known
59-
* internally by wpa_supplicant.
60-
* {@hide}
61-
*/
62-
public ScanResult(String SSID, String BSSID, String caps, int level, int frequency, long tsf) {
63-
this.SSID = SSID;
59+
/** {@hide} */
60+
public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency,
61+
long tsf) {
62+
this.wifiSsid = wifiSsid;
63+
this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE;
6464
this.BSSID = BSSID;
6565
this.capabilities = caps;
6666
this.level = level;
6767
this.frequency = frequency;
6868
this.timestamp = tsf;
6969
}
7070

71+
7172
/** copy constructor {@hide} */
7273
public ScanResult(ScanResult source) {
7374
if (source != null) {
75+
wifiSsid = source.wifiSsid;
7476
SSID = source.SSID;
7577
BSSID = source.BSSID;
7678
capabilities = source.capabilities;
@@ -86,7 +88,7 @@ public String toString() {
8688
String none = "<none>";
8789

8890
sb.append("SSID: ").
89-
append(SSID == null ? none : SSID).
91+
append(wifiSsid == null ? WifiSsid.NONE : wifiSsid).
9092
append(", BSSID: ").
9193
append(BSSID == null ? none : BSSID).
9294
append(", capabilities: ").
@@ -108,7 +110,12 @@ public int describeContents() {
108110

109111
/** Implement the Parcelable interface {@hide} */
110112
public void writeToParcel(Parcel dest, int flags) {
111-
dest.writeString(SSID);
113+
if (wifiSsid != null) {
114+
dest.writeInt(1);
115+
wifiSsid.writeToParcel(dest, flags);
116+
} else {
117+
dest.writeInt(0);
118+
}
112119
dest.writeString(BSSID);
113120
dest.writeString(capabilities);
114121
dest.writeInt(level);
@@ -120,8 +127,12 @@ public void writeToParcel(Parcel dest, int flags) {
120127
public static final Creator<ScanResult> CREATOR =
121128
new Creator<ScanResult>() {
122129
public ScanResult createFromParcel(Parcel in) {
130+
WifiSsid wifiSsid = null;
131+
if (in.readInt() == 1) {
132+
wifiSsid = WifiSsid.CREATOR.createFromParcel(in);
133+
}
123134
return new ScanResult(
124-
in.readString(),
135+
wifiSsid,
125136
in.readString(),
126137
in.readString(),
127138
in.readInt(),

wifi/java/android/net/wifi/StateChangeResult.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
* @hide
2424
*/
2525
public class StateChangeResult {
26-
StateChangeResult(int networkId, String SSID, String BSSID, SupplicantState state) {
26+
StateChangeResult(int networkId, WifiSsid wifiSsid, String BSSID,
27+
SupplicantState state) {
2728
this.state = state;
28-
this.SSID = SSID;
29+
this.wifiSsid= wifiSsid;
2930
this.BSSID = BSSID;
3031
this.networkId = networkId;
3132
}
3233

3334
int networkId;
34-
String SSID;
35+
WifiSsid wifiSsid;
3536
String BSSID;
3637
SupplicantState state;
3738
}

wifi/java/android/net/wifi/WifiConfigStore.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,13 @@ private void readNetworkVariables(WifiConfiguration config) {
13181318

13191319
value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.ssidVarName);
13201320
if (!TextUtils.isEmpty(value)) {
1321-
config.SSID = value;
1321+
if (value.charAt(0) != '"') {
1322+
config.SSID = "\"" + WifiSsid.createFromHex(value).toString() + "\"";
1323+
//TODO: convert a hex string that is not UTF-8 decodable to a P-formatted
1324+
//supplicant string
1325+
} else {
1326+
config.SSID = value;
1327+
}
13221328
} else {
13231329
config.SSID = null;
13241330
}

wifi/java/android/net/wifi/WifiConfiguration.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,27 @@ public WifiConfiguration(ScanResult scannedAP) {
524524
}
525525
*/
526526

527+
/** {@hide} */
528+
public String getPrintableSsid() {
529+
if (SSID == null) return "";
530+
final int length = SSID.length();
531+
if (length > 2 && (SSID.charAt(0) == '"') && SSID.charAt(length - 1) == '"') {
532+
return SSID.substring(1, length - 1);
533+
}
534+
535+
/** The ascii-encoded string format is P"<ascii-encoded-string>"
536+
* The decoding is implemented in the supplicant for a newly configured
537+
* network.
538+
*/
539+
if (length > 3 && (SSID.charAt(0) == 'P') && (SSID.charAt(1) == '"') &&
540+
(SSID.charAt(length-1) == '"')) {
541+
WifiSsid wifiSsid = WifiSsid.createFromAsciiEncoded(
542+
SSID.substring(2, length - 1));
543+
return wifiSsid.toString();
544+
}
545+
return SSID;
546+
}
547+
527548
private static BitSet readBitSet(Parcel src) {
528549
int cardinality = src.readInt();
529550

wifi/java/android/net/wifi/WifiInfo.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.os.Parcel;
2121
import android.net.NetworkInfo.DetailedState;
2222
import android.net.NetworkUtils;
23+
import android.text.TextUtils;
2324

2425
import java.net.InetAddress;
2526
import java.net.Inet6Address;
@@ -31,6 +32,7 @@
3132
* is in the process of being set up.
3233
*/
3334
public class WifiInfo implements Parcelable {
35+
private static final String TAG = "WifiInfo";
3436
/**
3537
* This is the map described in the Javadoc comment above. The positions
3638
* of the elements of the array must correspond to the ordinal values
@@ -57,7 +59,7 @@ public class WifiInfo implements Parcelable {
5759

5860
private SupplicantState mSupplicantState;
5961
private String mBSSID;
60-
private String mSSID;
62+
private WifiSsid mWifiSsid;
6163
private int mNetworkId;
6264
private boolean mHiddenSSID;
6365
/** Received Signal Strength Indicator */
@@ -77,7 +79,7 @@ public class WifiInfo implements Parcelable {
7779
private boolean mMeteredHint;
7880

7981
WifiInfo() {
80-
mSSID = null;
82+
mWifiSsid = null;
8183
mBSSID = null;
8284
mNetworkId = -1;
8385
mSupplicantState = SupplicantState.UNINITIALIZED;
@@ -94,7 +96,7 @@ public WifiInfo(WifiInfo source) {
9496
if (source != null) {
9597
mSupplicantState = source.mSupplicantState;
9698
mBSSID = source.mBSSID;
97-
mSSID = source.mSSID;
99+
mWifiSsid = source.mWifiSsid;
98100
mNetworkId = source.mNetworkId;
99101
mHiddenSSID = source.mHiddenSSID;
100102
mRssi = source.mRssi;
@@ -105,21 +107,34 @@ public WifiInfo(WifiInfo source) {
105107
}
106108
}
107109

108-
void setSSID(String SSID) {
109-
mSSID = SSID;
110+
void setSSID(WifiSsid wifiSsid) {
111+
mWifiSsid = wifiSsid;
110112
// network is considered not hidden by default
111113
mHiddenSSID = false;
112114
}
113115

114116
/**
115117
* Returns the service set identifier (SSID) of the current 802.11 network.
116-
* If the SSID is an ASCII string, it will be returned surrounded by double
117-
* quotation marks.Otherwise, it is returned as a string of hex digits. The
118+
* If the SSID can be decoded as UTF-8, it will be returned surrounded by double
119+
* quotation marks. Otherwise, it is returned as a string of hex digits. The
118120
* SSID may be {@code null} if there is no network currently connected.
119121
* @return the SSID
120122
*/
121123
public String getSSID() {
122-
return mSSID;
124+
if (mWifiSsid != null) {
125+
String unicode = mWifiSsid.toString();
126+
if (!TextUtils.isEmpty(unicode)) {
127+
return "\"" + unicode + "\"";
128+
} else {
129+
return mWifiSsid.getHexString();
130+
}
131+
}
132+
return WifiSsid.NONE;
133+
}
134+
135+
/** @hide */
136+
public WifiSsid getWifiSsid() {
137+
return mWifiSsid;
123138
}
124139

125140
void setBSSID(String BSSID) {
@@ -279,7 +294,7 @@ public String toString() {
279294
StringBuffer sb = new StringBuffer();
280295
String none = "<none>";
281296

282-
sb.append("SSID: ").append(mSSID == null ? none : mSSID).
297+
sb.append("SSID: ").append(mWifiSsid == null ? WifiSsid.NONE : mWifiSsid).
283298
append(", BSSID: ").append(mBSSID == null ? none : mBSSID).
284299
append(", MAC: ").append(mMacAddress == null ? none : mMacAddress).
285300
append(", Supplicant state: ").
@@ -308,7 +323,12 @@ public void writeToParcel(Parcel dest, int flags) {
308323
} else {
309324
dest.writeByte((byte)0);
310325
}
311-
dest.writeString(getSSID());
326+
if (mWifiSsid != null) {
327+
dest.writeInt(1);
328+
mWifiSsid.writeToParcel(dest, flags);
329+
} else {
330+
dest.writeInt(0);
331+
}
312332
dest.writeString(mBSSID);
313333
dest.writeString(mMacAddress);
314334
dest.writeInt(mMeteredHint ? 1 : 0);
@@ -328,7 +348,9 @@ public WifiInfo createFromParcel(Parcel in) {
328348
info.setInetAddress(InetAddress.getByAddress(in.createByteArray()));
329349
} catch (UnknownHostException e) {}
330350
}
331-
info.setSSID(in.readString());
351+
if (in.readInt() == 1) {
352+
info.mWifiSsid = WifiSsid.CREATOR.createFromParcel(in);
353+
}
332354
info.mBSSID = in.readString();
333355
info.mMacAddress = in.readString();
334356
info.mMeteredHint = in.readInt() != 0;

wifi/java/android/net/wifi/WifiMonitor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,12 @@ private void handleHostApEvents(String dataString) {
645645
* id=network-id state=new-state
646646
*/
647647
private void handleSupplicantStateChange(String dataString) {
648-
String SSID = null;
648+
WifiSsid wifiSsid = null;
649649
int index = dataString.lastIndexOf("SSID=");
650-
if (index != -1) SSID = dataString.substring(index + 5);
650+
if (index != -1) {
651+
wifiSsid = WifiSsid.createFromAsciiEncoded(
652+
dataString.substring(index + 5));
653+
}
651654
String[] dataTokens = dataString.split(" ");
652655

653656
String BSSID = null;
@@ -690,7 +693,7 @@ private void handleSupplicantStateChange(String dataString) {
690693
if (newSupplicantState == SupplicantState.INVALID) {
691694
Log.w(TAG, "Invalid supplicant state: " + newState);
692695
}
693-
notifySupplicantStateChange(networkId, SSID, BSSID, newSupplicantState);
696+
notifySupplicantStateChange(networkId, wifiSsid, BSSID, newSupplicantState);
694697
}
695698
}
696699

@@ -739,13 +742,14 @@ void notifyNetworkStateChange(NetworkInfo.DetailedState newState, String BSSID,
739742
* Send the state machine a notification that the state of the supplicant
740743
* has changed.
741744
* @param networkId the configured network on which the state change occurred
742-
* @param SSID network name
745+
* @param wifiSsid network name
743746
* @param BSSID network address
744747
* @param newState the new {@code SupplicantState}
745748
*/
746-
void notifySupplicantStateChange(int networkId, String SSID, String BSSID, SupplicantState newState) {
749+
void notifySupplicantStateChange(int networkId, WifiSsid wifiSsid, String BSSID,
750+
SupplicantState newState) {
747751
mStateMachine.sendMessage(mStateMachine.obtainMessage(SUPPLICANT_STATE_CHANGE_EVENT,
748-
new StateChangeResult(networkId, SSID, BSSID, newState)));
752+
new StateChangeResult(networkId, wifiSsid, BSSID, newState)));
749753
}
750754

751755
/**

0 commit comments

Comments
 (0)