Merge "NetworkKey: migrate from ScanResult.wifiSsid to SSID"
am: 1124e240c0
Change-Id: Ia0c92f1db33b0a884da7388cd31b33d51df29288
diff --git a/api/current.txt b/api/current.txt
index af954d4..f0be639 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -29891,6 +29891,7 @@
field public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0; // 0x0
field @Deprecated public static final String SUPPLICANT_CONNECTION_CHANGE_ACTION = "android.net.wifi.supplicant.CONNECTION_CHANGE";
field @Deprecated public static final String SUPPLICANT_STATE_CHANGED_ACTION = "android.net.wifi.supplicant.STATE_CHANGE";
+ field public static final String UNKNOWN_SSID = "<unknown ssid>";
field @Deprecated public static final int WIFI_MODE_FULL = 1; // 0x1
field public static final int WIFI_MODE_FULL_HIGH_PERF = 3; // 0x3
field public static final int WIFI_MODE_FULL_LOW_LATENCY = 4; // 0x4
diff --git a/core/java/android/net/NetworkKey.java b/core/java/android/net/NetworkKey.java
index a101da7..04cb877 100644
--- a/core/java/android/net/NetworkKey.java
+++ b/core/java/android/net/NetworkKey.java
@@ -21,7 +21,7 @@
import android.annotation.SystemApi;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiSsid;
+import android.net.wifi.WifiManager;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -69,22 +69,25 @@
*/
@Nullable
public static NetworkKey createFromScanResult(@Nullable ScanResult result) {
- if (result != null && result.wifiSsid != null) {
- final String ssid = result.wifiSsid.toString();
- final String bssid = result.BSSID;
- if (!TextUtils.isEmpty(ssid) && !ssid.equals(WifiSsid.NONE)
- && !TextUtils.isEmpty(bssid)) {
- WifiKey wifiKey;
- try {
- wifiKey = new WifiKey(String.format("\"%s\"", ssid), bssid);
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "Unable to create WifiKey.", e);
- return null;
- }
- return new NetworkKey(wifiKey);
- }
+ if (result == null) {
+ return null;
}
- return null;
+ final String ssid = result.SSID;
+ if (TextUtils.isEmpty(ssid) || ssid.equals(WifiManager.UNKNOWN_SSID)) {
+ return null;
+ }
+ final String bssid = result.BSSID;
+ if (TextUtils.isEmpty(bssid)) {
+ return null;
+ }
+
+ try {
+ final WifiKey wifiKey = new WifiKey(String.format("\"%s\"", ssid), bssid);
+ return new NetworkKey(wifiKey);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Unable to create WifiKey.", e);
+ return null;
+ }
}
/**
@@ -100,7 +103,7 @@
if (wifiInfo != null) {
final String ssid = wifiInfo.getSSID();
final String bssid = wifiInfo.getBSSID();
- if (!TextUtils.isEmpty(ssid) && !ssid.equals(WifiSsid.NONE)
+ if (!TextUtils.isEmpty(ssid) && !ssid.equals(WifiManager.UNKNOWN_SSID)
&& !TextUtils.isEmpty(bssid)) {
WifiKey wifiKey;
try {
diff --git a/core/tests/coretests/src/android/net/NetworkKeyTest.java b/core/tests/coretests/src/android/net/NetworkKeyTest.java
index 0f1c71d..c6c0b46 100644
--- a/core/tests/coretests/src/android/net/NetworkKeyTest.java
+++ b/core/tests/coretests/src/android/net/NetworkKeyTest.java
@@ -22,7 +22,7 @@
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiSsid;
+import android.net.wifi.WifiManager;
import androidx.test.runner.AndroidJUnit4;
@@ -65,7 +65,7 @@
@Test
public void createFromWifi_noneSsid() throws Exception {
- when(mWifiInfo.getSSID()).thenReturn(WifiSsid.NONE);
+ when(mWifiInfo.getSSID()).thenReturn(WifiManager.UNKNOWN_SSID);
when(mWifiInfo.getBSSID()).thenReturn(VALID_BSSID);
assertNull(NetworkKey.createFromWifiInfo(mWifiInfo));
}
@@ -106,7 +106,7 @@
}
@Test
- public void createFromScanResult_nullWifiSsid() {
+ public void createFromScanResult_nullSsid() {
ScanResult scanResult = new ScanResult();
scanResult.BSSID = VALID_BSSID;
@@ -114,18 +114,18 @@
}
@Test
- public void createFromScanResult_emptyWifiSsid() {
+ public void createFromScanResult_emptySsid() {
ScanResult scanResult = new ScanResult();
- scanResult.wifiSsid = WifiSsid.createFromAsciiEncoded("");
+ scanResult.SSID = "";
scanResult.BSSID = VALID_BSSID;
assertNull(NetworkKey.createFromScanResult(scanResult));
}
@Test
- public void createFromScanResult_noneWifiSsid() {
+ public void createFromScanResult_noneSsid() {
ScanResult scanResult = new ScanResult();
- scanResult.wifiSsid = WifiSsid.createFromAsciiEncoded(WifiSsid.NONE);
+ scanResult.SSID = WifiManager.UNKNOWN_SSID;
scanResult.BSSID = VALID_BSSID;
assertNull(NetworkKey.createFromScanResult(scanResult));
@@ -134,7 +134,7 @@
@Test
public void createFromScanResult_nullBssid() {
ScanResult scanResult = new ScanResult();
- scanResult.wifiSsid = WifiSsid.createFromAsciiEncoded(VALID_UNQUOTED_SSID);
+ scanResult.SSID = VALID_UNQUOTED_SSID;
assertNull(NetworkKey.createFromScanResult(scanResult));
}
@@ -142,7 +142,7 @@
@Test
public void createFromScanResult_emptyBssid() {
ScanResult scanResult = new ScanResult();
- scanResult.wifiSsid = WifiSsid.createFromAsciiEncoded(VALID_UNQUOTED_SSID);
+ scanResult.SSID = VALID_UNQUOTED_SSID;
scanResult.BSSID = "";
assertNull(NetworkKey.createFromScanResult(scanResult));
@@ -151,16 +151,16 @@
@Test
public void createFromScanResult_invalidBssid() {
ScanResult scanResult = new ScanResult();
- scanResult.wifiSsid = WifiSsid.createFromAsciiEncoded(VALID_UNQUOTED_SSID);
+ scanResult.SSID = VALID_UNQUOTED_SSID;
scanResult.BSSID = INVALID_BSSID;
assertNull(NetworkKey.createFromScanResult(scanResult));
}
@Test
- public void createFromScanResult_validWifiSsid() {
+ public void createFromScanResult_validSsid() {
ScanResult scanResult = new ScanResult();
- scanResult.wifiSsid = WifiSsid.createFromAsciiEncoded(VALID_UNQUOTED_SSID);
+ scanResult.SSID = VALID_UNQUOTED_SSID;
scanResult.BSSID = VALID_BSSID;
NetworkKey expected = new NetworkKey(new WifiKey(VALID_SSID, VALID_BSSID));
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
index e9e96c9..8fd8d04 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
@@ -56,6 +56,7 @@
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
import android.os.Binder;
import android.os.Handler;
@@ -719,7 +720,7 @@
@Test
public void testCurrentNetworkScoreCacheFilter_invalidWifiInfo_noneSsid() throws Exception {
- when(mWifiInfo.getSSID()).thenReturn(WifiSsid.NONE);
+ when(mWifiInfo.getSSID()).thenReturn(WifiManager.UNKNOWN_SSID);
NetworkScoreService.CurrentNetworkScoreCacheFilter cacheFilter =
new NetworkScoreService.CurrentNetworkScoreCacheFilter(() -> mWifiInfo);
@@ -793,7 +794,7 @@
List<ScanResult> invalidScanResults = Lists.newArrayList(
new ScanResult(),
createScanResult("", SCORED_NETWORK.networkKey.wifiKey.bssid),
- createScanResult(WifiSsid.NONE, SCORED_NETWORK.networkKey.wifiKey.bssid),
+ createScanResult(WifiManager.UNKNOWN_SSID, SCORED_NETWORK.networkKey.wifiKey.bssid),
createScanResult(SSID, null),
createScanResult(SSID, INVALID_BSSID)
);
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 2f963ef..b53b2aa 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1128,6 +1128,9 @@
*/
private static final int MAX_ACTIVE_LOCKS = 50;
+ /** Indicates an invalid SSID. */
+ public static final String UNKNOWN_SSID = "<unknown ssid>";
+
/* Number of currently active WifiLocks and MulticastLocks */
@UnsupportedAppUsage
private int mActiveLockCount;
@@ -2326,7 +2329,7 @@
* <p>
* In the connected state, access to the SSID and BSSID requires
* the same permissions as {@link #getScanResults}. If such access is not allowed,
- * {@link WifiInfo#getSSID} will return {@code "<unknown ssid>"} and
+ * {@link WifiInfo#getSSID} will return {@link #UNKNOWN_SSID} and
* {@link WifiInfo#getBSSID} will return {@code "02:00:00:00:00:00"}.
*
* @return the Wi-Fi information, contained in {@link WifiInfo}.
diff --git a/wifi/java/android/net/wifi/WifiSsid.java b/wifi/java/android/net/wifi/WifiSsid.java
index 70ca088..f187e10 100644
--- a/wifi/java/android/net/wifi/WifiSsid.java
+++ b/wifi/java/android/net/wifi/WifiSsid.java
@@ -48,7 +48,7 @@
private static final int HEX_RADIX = 16;
@UnsupportedAppUsage
- public static final String NONE = "<unknown ssid>";
+ public static final String NONE = WifiManager.UNKNOWN_SSID;
private WifiSsid() {
}