2020import android .os .Parcel ;
2121import android .net .NetworkInfo .DetailedState ;
2222import android .net .NetworkUtils ;
23+ import android .text .TextUtils ;
2324
2425import java .net .InetAddress ;
2526import java .net .Inet6Address ;
3132 * is in the process of being set up.
3233 */
3334public 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 ;
0 commit comments