summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/current.txt1
-rw-r--r--api/system-current.txt10
-rw-r--r--core/java/android/net/NetworkKey.java37
-rw-r--r--core/tests/coretests/src/android/net/NetworkKeyTest.java24
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java2
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/wifi/WifiStatusTracker.java3
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java10
-rw-r--r--packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java4
-rw-r--r--packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java2
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java6
-rw-r--r--wifi/java/android/net/wifi/ScanResult.java32
-rw-r--r--wifi/java/android/net/wifi/WifiInfo.java169
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java5
-rw-r--r--wifi/java/android/net/wifi/WifiSsid.java62
-rw-r--r--wifi/java/android/net/wifi/hotspot2/OsuProvider.java9
-rw-r--r--wifi/tests/src/android/net/wifi/WifiInfoTest.java4
-rw-r--r--wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java4
17 files changed, 253 insertions, 131 deletions
diff --git a/api/current.txt b/api/current.txt
index ee9363751a00..03e615689675 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -30136,6 +30136,7 @@ package android.net.wifi {
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_UNKNOWN = 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/api/system-current.txt b/api/system-current.txt
index aa639409cbb6..3a125f60801d 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -4855,8 +4855,18 @@ package android.net.wifi {
}
public class WifiInfo implements android.os.Parcelable {
+ method @Nullable public String getAppPackageName();
+ method public double getRxSuccessRate();
+ method public int getScore();
+ method public double getTxBadRate();
+ method public double getTxRetriesRate();
+ method public double getTxSuccessRate();
+ method public boolean isEphemeral();
method public boolean isOsuAp();
method public boolean isPasspointAp();
+ method @Nullable public static String removeDoubleQuotes(@Nullable String);
+ field public static final String DEFAULT_MAC_ADDRESS = "02:00:00:00:00:00";
+ field public static final int INVALID_RSSI = -127; // 0xffffff81
}
public class WifiManager {
diff --git a/core/java/android/net/NetworkKey.java b/core/java/android/net/NetworkKey.java
index a101da7b4b9c..425424041354 100644
--- a/core/java/android/net/NetworkKey.java
+++ b/core/java/android/net/NetworkKey.java
@@ -21,7 +21,7 @@ import android.annotation.Nullable;
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 @@ public class NetworkKey implements Parcelable {
*/
@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;
+ }
+ 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 {
+ 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;
}
- return null;
}
/**
@@ -100,7 +103,7 @@ public class NetworkKey implements Parcelable {
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 0f1c71d7c601..c6c0b46d0505 100644
--- a/core/tests/coretests/src/android/net/NetworkKeyTest.java
+++ b/core/tests/coretests/src/android/net/NetworkKeyTest.java
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.when;
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 @@ public class NetworkKeyTest {
@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 @@ public class NetworkKeyTest {
}
@Test
- public void createFromScanResult_nullWifiSsid() {
+ public void createFromScanResult_nullSsid() {
ScanResult scanResult = new ScanResult();
scanResult.BSSID = VALID_BSSID;
@@ -114,18 +114,18 @@ public class NetworkKeyTest {
}
@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 @@ public class NetworkKeyTest {
@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 @@ public class NetworkKeyTest {
@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 @@ public class NetworkKeyTest {
@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/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index 9518f5c4ab8d..d619300f2492 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -1066,7 +1066,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
} else {
summary.append(getSummary(mContext, /* ssid */ null, getDetailedState(),
mInfo != null && mInfo.isEphemeral(),
- mInfo != null ? mInfo.getNetworkSuggestionOrSpecifierPackageName() : null));
+ mInfo != null ? mInfo.getAppPackageName() : null));
}
} else { // not active
if (mConfig != null && mConfig.hasNoInternetAccess()) {
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiStatusTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiStatusTracker.java
index b11585a73946..51e37d1e0771 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiStatusTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiStatusTracker.java
@@ -28,7 +28,6 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkScoreCache;
-import android.net.wifi.WifiSsid;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
@@ -189,7 +188,7 @@ public class WifiStatusTracker extends ConnectivityManager.NetworkCallback {
private String getValidSsid(WifiInfo info) {
String ssid = info.getSSID();
- if (ssid != null && !WifiSsid.NONE.equals(ssid)) {
+ if (ssid != null && !WifiManager.UNKNOWN_SSID.equals(ssid)) {
return ssid;
}
// OK, it's not in the connectionInfo; we have to go hunting for it
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java
index 6f19559bcbd1..ee8973841c73 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java
@@ -96,14 +96,14 @@ public class WifiUtils {
visibility.append(" standard = ").append(info.getWifiStandard());
visibility.append(" rssi=").append(info.getRssi());
visibility.append(" ");
- visibility.append(" score=").append(info.score);
+ visibility.append(" score=").append(info.getScore());
if (accessPoint.getSpeed() != AccessPoint.Speed.NONE) {
visibility.append(" speed=").append(accessPoint.getSpeedLabel());
}
- visibility.append(String.format(" tx=%.1f,", info.txSuccessRate));
- visibility.append(String.format("%.1f,", info.txRetriesRate));
- visibility.append(String.format("%.1f ", info.txBadRate));
- visibility.append(String.format("rx=%.1f", info.rxSuccessRate));
+ visibility.append(String.format(" tx=%.1f,", info.getTxSuccessRate()));
+ visibility.append(String.format("%.1f,", info.getTxRetriesRate()));
+ visibility.append(String.format("%.1f ", info.getTxBadRate()));
+ visibility.append(String.format("rx=%.1f", info.getRxSuccessRate()));
}
int maxRssi5 = WifiConfiguration.INVALID_RSSI;
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java
index 0a16ec2e5bd8..7139a4f2282e 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java
@@ -120,7 +120,7 @@ public class AccessPointTest {
private OsuProvider createOsuProvider() {
Map<String, String> friendlyNames = new HashMap<>();
friendlyNames.put("en", OSU_FRIENDLY_NAME);
- return new OsuProvider(null, friendlyNames, null, null, null, null, null);
+ return new OsuProvider((WifiSsid) null, friendlyNames, null, null, null, null, null);
}
@Before
@@ -549,7 +549,7 @@ public class AccessPointTest {
WifiInfo wifiInfo = new WifiInfo();
wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_SSID));
wifiInfo.setEphemeral(true);
- wifiInfo.setNetworkSuggestionOrSpecifierPackageName(appPackageName);
+ wifiInfo.setAppPackageName(appPackageName);
wifiInfo.setRssi(rssi);
Context context = mock(Context.class);
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java
index 942ee4f7404c..37fdc340ab80 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java
@@ -336,7 +336,7 @@ public class WifiTrackerTest {
private static OsuProvider buildOsuProvider(String friendlyName) {
Map<String, String> friendlyNames = new HashMap<>();
friendlyNames.put("en", friendlyName);
- return new OsuProvider(null, friendlyNames, null, null, null, null, null);
+ return new OsuProvider((WifiSsid) null, friendlyNames, null, null, null, null, null);
}
private WifiTracker createTrackerWithImmediateBroadcastsAndInjectInitialScanResults(
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
index 79af34d80686..1829fb79699f 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
@@ -43,7 +43,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.content.pm.PackageManagerInternal;
import android.content.res.Resources;
import android.net.INetworkRecommendationProvider;
import android.net.INetworkScoreCache;
@@ -56,6 +55,7 @@ import android.net.WifiKey;
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;
@@ -722,7 +722,7 @@ public class NetworkScoreServiceTest {
@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);
@@ -796,7 +796,7 @@ public class NetworkScoreServiceTest {
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/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java
index ed1a2f9f16ca..9956901434d0 100644
--- a/wifi/java/android/net/wifi/ScanResult.java
+++ b/wifi/java/android/net/wifi/ScanResult.java
@@ -585,6 +585,7 @@ public class ScanResult implements Parcelable {
*
* @hide
*/
+ // TODO(b/144431927): remove once migrated to Suggestions
public boolean isCarrierAp;
/**
@@ -592,6 +593,7 @@ public class ScanResult implements Parcelable {
*
* @hide
*/
+ // TODO(b/144431927): remove once migrated to Suggestions
public int carrierApEapType;
/**
@@ -599,13 +601,14 @@ public class ScanResult implements Parcelable {
*
* @hide
*/
+ // TODO(b/144431927): remove once migrated to Suggestions
public String carrierName;
/** {@hide} */
public ScanResult(WifiSsid wifiSsid, String BSSID, long hessid, int anqpDomainId,
byte[] osuProviders, String caps, int level, int frequency, long tsf) {
this.wifiSsid = wifiSsid;
- this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE;
+ this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiManager.UNKNOWN_SSID;
this.BSSID = BSSID;
this.hessid = hessid;
this.anqpDomainId = anqpDomainId;
@@ -636,7 +639,7 @@ public class ScanResult implements Parcelable {
public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency,
long tsf, int distCm, int distSdCm) {
this.wifiSsid = wifiSsid;
- this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE;
+ this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiManager.UNKNOWN_SSID;
this.BSSID = BSSID;
this.capabilities = caps;
this.level = level;
@@ -740,19 +743,18 @@ public class ScanResult implements Parcelable {
StringBuffer sb = new StringBuffer();
String none = "<none>";
- sb.append("SSID: ").
- append(wifiSsid == null ? WifiSsid.NONE : wifiSsid).
- append(", BSSID: ").
- append(BSSID == null ? none : BSSID).
- append(", capabilities: ").
- append(capabilities == null ? none : capabilities).
- append(", level: ").
- append(level).
- append(", frequency: ").
- append(frequency).
- append(", timestamp: ").
- append(timestamp);
-
+ sb.append("SSID: ")
+ .append(wifiSsid == null ? WifiManager.UNKNOWN_SSID : wifiSsid)
+ .append(", BSSID: ")
+ .append(BSSID == null ? none : BSSID)
+ .append(", capabilities: ")
+ .append(capabilities == null ? none : capabilities)
+ .append(", level: ")
+ .append(level)
+ .append(", frequency: ")
+ .append(frequency)
+ .append(", timestamp: ")
+ .append(timestamp);
sb.append(", distance: ").append((distanceCm != UNSPECIFIED ? distanceCm : "?")).
append("(cm)");
sb.append(", distanceSd: ").append((distanceSdCm != UNSPECIFIED ? distanceSdCm : "?")).
diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java
index 86e51227575b..f3f873b4ead8 100644
--- a/wifi/java/android/net/wifi/WifiInfo.java
+++ b/wifi/java/android/net/wifi/WifiInfo.java
@@ -53,7 +53,7 @@ public class WifiInfo implements Parcelable {
*
* @hide
*/
- @UnsupportedAppUsage
+ @SystemApi
public static final String DEFAULT_MAC_ADDRESS = "02:00:00:00:00:00";
static {
@@ -79,8 +79,12 @@ public class WifiInfo implements Parcelable {
private WifiSsid mWifiSsid;
private int mNetworkId;
- /** @hide **/
- @UnsupportedAppUsage
+ /**
+ * Used to indicate that the RSSI is invalid, for example if no RSSI measurements are available
+ * yet.
+ * @hide
+ */
+ @SystemApi
public static final int INVALID_RSSI = -127;
/** @hide **/
@@ -161,7 +165,7 @@ public class WifiInfo implements Parcelable {
* If connected to a network suggestion or specifier, store the package name of the app,
* else null.
*/
- private String mNetworkSuggestionOrSpecifierPackageName;
+ private String mAppPackageName;
/**
* Running total count of lost (not ACKed) transmitted unicast data packets.
@@ -184,32 +188,89 @@ public class WifiInfo implements Parcelable {
*/
public long rxSuccess;
+ private double mTxBadRate;
+
/**
* Average rate of lost transmitted packets, in units of packets per second.
* @hide
*/
- public double txBadRate;
+ @SystemApi
+ public double getTxBadRate() {
+ return mTxBadRate;
+ }
+
+ /** @hide */
+ public void setTxBadRate(double txBadRate) {
+ mTxBadRate = txBadRate;
+ }
+
+ private double mTxRetriesRate;
+
/**
* Average rate of transmitted retry packets, in units of packets per second.
* @hide
*/
- public double txRetriesRate;
+ @SystemApi
+ public double getTxRetriesRate() {
+ return mTxRetriesRate;
+ }
+
+ /** @hide */
+ public void setTxRetriesRate(double txRetriesRate) {
+ mTxRetriesRate = txRetriesRate;
+ }
+
+ private double mTxSuccessRate;
+
/**
* Average rate of successfully transmitted unicast packets, in units of packets per second.
* @hide
*/
- public double txSuccessRate;
+ @SystemApi
+ public double getTxSuccessRate() {
+ return mTxSuccessRate;
+ }
+
+ /** @hide */
+ public void setTxSuccessRate(double txSuccessRate) {
+ mTxSuccessRate = txSuccessRate;
+ }
+
+ private double mRxSuccessRate;
+
/**
* Average rate of received unicast data packets, in units of packets per second.
* @hide
*/
- public double rxSuccessRate;
+ @SystemApi
+ public double getRxSuccessRate() {
+ return mRxSuccessRate;
+ }
+
+ /** @hide */
+ public void setRxSuccessRate(double rxSuccessRate) {
+ mRxSuccessRate = rxSuccessRate;
+ }
+
+ /** @hide */
+ @UnsupportedAppUsage
+ public int score;
/**
+ * The current Wifi score.
+ * NOTE: this value should only be used for debugging purposes. Do not rely on this value for
+ * any computations. The meaning of this value can and will change at any time without warning.
* @hide
*/
- @UnsupportedAppUsage
- public int score;
+ @SystemApi
+ public int getScore() {
+ return score;
+ }
+
+ /** @hide */
+ public void setScore(int score) {
+ this.score = score;
+ }
/**
* Flag indicating that AP has hinted that upstream connection is metered,
@@ -243,17 +304,17 @@ public class WifiInfo implements Parcelable {
setMeteredHint(false);
setEphemeral(false);
setOsuAp(false);
- setNetworkSuggestionOrSpecifierPackageName(null);
+ setAppPackageName(null);
setFQDN(null);
setProviderFriendlyName(null);
txBad = 0;
txSuccess = 0;
rxSuccess = 0;
txRetries = 0;
- txBadRate = 0;
- txSuccessRate = 0;
- rxSuccessRate = 0;
- txRetriesRate = 0;
+ mTxBadRate = 0;
+ mTxSuccessRate = 0;
+ mRxSuccessRate = 0;
+ mTxRetriesRate = 0;
score = 0;
}
@@ -277,8 +338,8 @@ public class WifiInfo implements Parcelable {
mMeteredHint = source.mMeteredHint;
mEphemeral = source.mEphemeral;
mTrusted = source.mTrusted;
- mNetworkSuggestionOrSpecifierPackageName =
- source.mNetworkSuggestionOrSpecifierPackageName;
+ mAppPackageName =
+ source.mAppPackageName;
mOsuAp = source.mOsuAp;
mFqdn = source.mFqdn;
mProviderFriendlyName = source.mProviderFriendlyName;
@@ -286,10 +347,10 @@ public class WifiInfo implements Parcelable {
txRetries = source.txRetries;
txSuccess = source.txSuccess;
rxSuccess = source.rxSuccess;
- txBadRate = source.txBadRate;
- txRetriesRate = source.txRetriesRate;
- txSuccessRate = source.txSuccessRate;
- rxSuccessRate = source.rxSuccessRate;
+ mTxBadRate = source.mTxBadRate;
+ mTxRetriesRate = source.mTxRetriesRate;
+ mTxSuccessRate = source.mTxSuccessRate;
+ mRxSuccessRate = source.mRxSuccessRate;
score = source.score;
mWifiStandard = source.mWifiStandard;
}
@@ -323,10 +384,10 @@ public class WifiInfo implements Parcelable {
return "\"" + unicode + "\"";
} else {
String hex = mWifiSsid.getHexString();
- return (hex != null) ? hex : WifiSsid.NONE;
+ return (hex != null) ? hex : WifiManager.UNKNOWN_SSID;
}
}
- return WifiSsid.NONE;
+ return WifiManager.UNKNOWN_SSID;
}
/** @hide */
@@ -523,8 +584,15 @@ public class WifiInfo implements Parcelable {
mEphemeral = ephemeral;
}
- /** {@hide} */
- @UnsupportedAppUsage
+ /**
+ * Returns true if the current Wifi network is ephemeral, false otherwise.
+ * An ephemeral network is a network that is temporary and not persisted in the system.
+ * Ephemeral networks cannot be forgotten, only disabled with
+ * {@link WifiManager#disableEphemeralNetwork(String)}.
+ *
+ * @hide
+ */
+ @SystemApi
public boolean isEphemeral() {
return mEphemeral;
}
@@ -581,13 +649,19 @@ public class WifiInfo implements Parcelable {
}
/** {@hide} */
- public void setNetworkSuggestionOrSpecifierPackageName(@Nullable String packageName) {
- mNetworkSuggestionOrSpecifierPackageName = packageName;
+ public void setAppPackageName(@Nullable String packageName) {
+ mAppPackageName = packageName;
}
- /** {@hide} */
- public @Nullable String getNetworkSuggestionOrSpecifierPackageName() {
- return mNetworkSuggestionOrSpecifierPackageName;
+ /**
+ * If this network was created in response to an app request (e.g. through Network Suggestion
+ * or Network Specifier), return the package name of the app that made the request.
+ * Null otherwise.
+ * @hide
+ */
+ @SystemApi
+ public @Nullable String getAppPackageName() {
+ return mAppPackageName;
}
@@ -648,7 +722,7 @@ public class WifiInfo implements Parcelable {
return mWifiSsid.isHidden();
}
- /**
+ /**
* Map a supplicant state into a fine-grained network connectivity state.
* @param suppState the supplicant state
* @return the corresponding {@link DetailedState}
@@ -680,9 +754,14 @@ public class WifiInfo implements Parcelable {
}
}
- /** {@hide} */
- @UnsupportedAppUsage
- public static String removeDoubleQuotes(String string) {
+ /**
+ * Remove double quotes (") surrounding a SSID string, if present. Otherwise, return the
+ * string unmodified. Return null if the input string was null.
+ * @hide
+ */
+ @Nullable
+ @SystemApi
+ public static String removeDoubleQuotes(@Nullable String string) {
if (string == null) return null;
final int length = string.length();
if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) {
@@ -696,7 +775,7 @@ public class WifiInfo implements Parcelable {
StringBuffer sb = new StringBuffer();
String none = "<none>";
- sb.append("SSID: ").append(mWifiSsid == null ? WifiSsid.NONE : mWifiSsid)
+ sb.append("SSID: ").append(mWifiSsid == null ? WifiManager.UNKNOWN_SSID : mWifiSsid)
.append(", BSSID: ").append(mBSSID == null ? none : mBSSID)
.append(", MAC: ").append(mMacAddress == null ? none : mMacAddress)
.append(", Supplicant state: ")
@@ -745,16 +824,16 @@ public class WifiInfo implements Parcelable {
dest.writeInt(mTrusted ? 1 : 0);
dest.writeInt(score);
dest.writeLong(txSuccess);
- dest.writeDouble(txSuccessRate);
+ dest.writeDouble(mTxSuccessRate);
dest.writeLong(txRetries);
- dest.writeDouble(txRetriesRate);
+ dest.writeDouble(mTxRetriesRate);
dest.writeLong(txBad);
- dest.writeDouble(txBadRate);
+ dest.writeDouble(mTxBadRate);
dest.writeLong(rxSuccess);
- dest.writeDouble(rxSuccessRate);
+ dest.writeDouble(mRxSuccessRate);
mSupplicantState.writeToParcel(dest, flags);
dest.writeInt(mOsuAp ? 1 : 0);
- dest.writeString(mNetworkSuggestionOrSpecifierPackageName);
+ dest.writeString(mAppPackageName);
dest.writeString(mFqdn);
dest.writeString(mProviderFriendlyName);
dest.writeInt(mWifiStandard);
@@ -787,16 +866,16 @@ public class WifiInfo implements Parcelable {
info.mTrusted = in.readInt() != 0;
info.score = in.readInt();
info.txSuccess = in.readLong();
- info.txSuccessRate = in.readDouble();
+ info.mTxSuccessRate = in.readDouble();
info.txRetries = in.readLong();
- info.txRetriesRate = in.readDouble();
+ info.mTxRetriesRate = in.readDouble();
info.txBad = in.readLong();
- info.txBadRate = in.readDouble();
+ info.mTxBadRate = in.readDouble();
info.rxSuccess = in.readLong();
- info.rxSuccessRate = in.readDouble();
+ info.mRxSuccessRate = in.readDouble();
info.mSupplicantState = SupplicantState.CREATOR.createFromParcel(in);
info.mOsuAp = in.readInt() != 0;
- info.mNetworkSuggestionOrSpecifierPackageName = in.readString();
+ info.mAppPackageName = in.readString();
info.mFqdn = in.readString();
info.mProviderFriendlyName = in.readString();
info.mWifiStandard = in.readInt();
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 16cb964901bf..56f152eebb3e 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1189,6 +1189,9 @@ public class WifiManager {
*/
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;
@@ -2547,7 +2550,7 @@ public class WifiManager {
* <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 70ca0882d7da..90756d860a21 100644
--- a/wifi/java/android/net/wifi/WifiSsid.java
+++ b/wifi/java/android/net/wifi/WifiSsid.java
@@ -16,6 +16,8 @@
package android.net.wifi;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
@@ -40,23 +42,29 @@ import java.util.Locale;
*
* @hide
*/
-public class WifiSsid implements Parcelable {
+public final class WifiSsid implements Parcelable {
private static final String TAG = "WifiSsid";
@UnsupportedAppUsage
public final ByteArrayOutputStream octets = new ByteArrayOutputStream(32);
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() {
}
- public static WifiSsid createFromByteArray(byte ssid[]) {
+ /**
+ * Create a WifiSsid from a raw byte array. If the byte array is null, return an empty WifiSsid
+ * object.
+ */
+ @NonNull
+ public static WifiSsid createFromByteArray(@Nullable byte[] ssid) {
WifiSsid wifiSsid = new WifiSsid();
if (ssid != null) {
- wifiSsid.octets.write(ssid, 0/* the start offset */, ssid.length);;
+ wifiSsid.octets.write(ssid, 0 /* the start offset */, ssid.length);
}
return wifiSsid;
}
@@ -174,6 +182,10 @@ public class WifiSsid implements Parcelable {
}
}
+ /**
+ * Converts this SSID to an unquoted UTF-8 String representation.
+ * @return the SSID string, or {@link WifiManager#UNKNOWN_SSID} if there was an error.
+ */
@Override
public String toString() {
byte[] ssidBytes = octets.toByteArray();
@@ -191,7 +203,7 @@ public class WifiSsid implements Parcelable {
CoderResult result = decoder.decode(ByteBuffer.wrap(ssidBytes), out, true);
out.flip();
if (result.isError()) {
- return NONE;
+ return WifiManager.UNKNOWN_SSID;
}
return out.toString();
}
@@ -241,32 +253,36 @@ public class WifiSsid implements Parcelable {
return (octets.size() > 0) ? out : null;
}
- /** Implement the Parcelable interface {@hide} */
+ /** Implement the Parcelable interface */
+ @Override
public int describeContents() {
return 0;
}
- /** Implement the Parcelable interface {@hide} */
- public void writeToParcel(Parcel dest, int flags) {
+ /** Implement the Parcelable interface */
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(octets.size());
dest.writeByteArray(octets.toByteArray());
}
- /** Implement the Parcelable interface {@hide} */
+ /** Implement the Parcelable interface */
@UnsupportedAppUsage
- public static final @android.annotation.NonNull Creator<WifiSsid> CREATOR =
- new Creator<WifiSsid>() {
- public WifiSsid createFromParcel(Parcel in) {
- WifiSsid ssid = new WifiSsid();
- int length = in.readInt();
- byte b[] = new byte[length];
- in.readByteArray(b);
- ssid.octets.write(b, 0, length);
- return ssid;
- }
+ public static final @NonNull Creator<WifiSsid> CREATOR =
+ new Creator<WifiSsid>() {
+ @Override
+ public WifiSsid createFromParcel(Parcel in) {
+ WifiSsid ssid = new WifiSsid();
+ int length = in.readInt();
+ byte[] b = new byte[length];
+ in.readByteArray(b);
+ ssid.octets.write(b, 0, length);
+ return ssid;
+ }
- public WifiSsid[] newArray(int size) {
- return new WifiSsid[size];
- }
- };
+ @Override
+ public WifiSsid[] newArray(int size) {
+ return new WifiSsid[size];
+ }
+ };
}
diff --git a/wifi/java/android/net/wifi/hotspot2/OsuProvider.java b/wifi/java/android/net/wifi/hotspot2/OsuProvider.java
index a32bd547e1e2..3bef50211015 100644
--- a/wifi/java/android/net/wifi/hotspot2/OsuProvider.java
+++ b/wifi/java/android/net/wifi/hotspot2/OsuProvider.java
@@ -27,6 +27,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -91,6 +92,14 @@ public final class OsuProvider implements Parcelable {
private final Icon mIcon;
/** @hide */
+ public OsuProvider(String osuSsid, Map<String, String> friendlyNames,
+ String serviceDescription, Uri serverUri, String nai, List<Integer> methodList,
+ Icon icon) {
+ this(WifiSsid.createFromByteArray(osuSsid.getBytes(StandardCharsets.UTF_8)),
+ friendlyNames, serviceDescription, serverUri, nai, methodList, icon);
+ }
+
+ /** @hide */
public OsuProvider(WifiSsid osuSsid, Map<String, String> friendlyNames,
String serviceDescription, Uri serverUri, String nai, List<Integer> methodList,
Icon icon) {
diff --git a/wifi/tests/src/android/net/wifi/WifiInfoTest.java b/wifi/tests/src/android/net/wifi/WifiInfoTest.java
index 22a5faaac112..f7612341d4b3 100644
--- a/wifi/tests/src/android/net/wifi/WifiInfoTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiInfoTest.java
@@ -54,7 +54,7 @@ public class WifiInfoTest {
writeWifiInfo.setOsuAp(true);
writeWifiInfo.setFQDN(TEST_FQDN);
writeWifiInfo.setProviderFriendlyName(TEST_PROVIDER_NAME);
- writeWifiInfo.setNetworkSuggestionOrSpecifierPackageName(TEST_PACKAGE_NAME);
+ writeWifiInfo.setAppPackageName(TEST_PACKAGE_NAME);
writeWifiInfo.setWifiStandard(TEST_WIFI_STANDARD);
Parcel parcel = Parcel.obtain();
@@ -71,7 +71,7 @@ public class WifiInfoTest {
assertTrue(readWifiInfo.isTrusted());
assertTrue(readWifiInfo.isOsuAp());
assertTrue(readWifiInfo.isPasspointAp());
- assertEquals(TEST_PACKAGE_NAME, readWifiInfo.getNetworkSuggestionOrSpecifierPackageName());
+ assertEquals(TEST_PACKAGE_NAME, readWifiInfo.getAppPackageName());
assertEquals(TEST_FQDN, readWifiInfo.getPasspointFqdn());
assertEquals(TEST_PROVIDER_NAME, readWifiInfo.getPasspointProviderFriendlyName());
assertEquals(TEST_WIFI_STANDARD, readWifiInfo.getWifiStandard());
diff --git a/wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java b/wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java
index c7e009ee9864..43ee24943e12 100644
--- a/wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java
+++ b/wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java
@@ -82,7 +82,7 @@ public class OsuProviderTest {
*/
@Test
public void verifyParcelWithEmptyProviderInfo() throws Exception {
- verifyParcel(new OsuProvider(null, null, null, null, null, null, null));
+ verifyParcel(new OsuProvider((WifiSsid) null, null, null, null, null, null, null));
}
/**
@@ -102,7 +102,7 @@ public class OsuProviderTest {
*/
@Test
public void verifyCopyConstructorWithNullSource() throws Exception {
- OsuProvider expected = new OsuProvider(null, null, null, null, null, null, null);
+ OsuProvider expected = new OsuProvider((WifiSsid) null, null, null, null, null, null, null);
assertEquals(expected, new OsuProvider(null));
}