Loading wifi/api/current.txt +2 −2 Original line number Original line Diff line number Diff line Loading @@ -270,7 +270,7 @@ package android.net.wifi { field public static final int SIM = 5; // 0x5 field public static final int SIM = 5; // 0x5 } } public class WifiInfo implements android.os.Parcelable { public class WifiInfo implements android.os.Parcelable android.net.TransportInfo { method public int describeContents(); method public int describeContents(); method public String getBSSID(); method public String getBSSID(); method public static android.net.NetworkInfo.DetailedState getDetailedStateOf(android.net.wifi.SupplicantState); method public static android.net.NetworkInfo.DetailedState getDetailedStateOf(android.net.wifi.SupplicantState); Loading Loading @@ -322,7 +322,7 @@ package android.net.wifi { method @Deprecated public boolean disconnect(); method @Deprecated public boolean disconnect(); method @Deprecated public boolean enableNetwork(int, boolean); method @Deprecated public boolean enableNetwork(int, boolean); method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE}) public java.util.List<android.net.wifi.WifiConfiguration> getConfiguredNetworks(); method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE}) public java.util.List<android.net.wifi.WifiConfiguration> getConfiguredNetworks(); method public android.net.wifi.WifiInfo getConnectionInfo(); method @Deprecated public android.net.wifi.WifiInfo getConnectionInfo(); method public android.net.DhcpInfo getDhcpInfo(); method public android.net.DhcpInfo getDhcpInfo(); method public int getMaxNumberOfNetworkSuggestionsPerApp(); method public int getMaxNumberOfNetworkSuggestionsPerApp(); method @IntRange(from=0) public int getMaxSignalLevel(); method @IntRange(from=0) public int getMaxSignalLevel(); Loading wifi/api/system-current.txt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -441,7 +441,7 @@ package android.net.wifi { method public static void registerServiceWrappers(); method public static void registerServiceWrappers(); } } public class WifiInfo implements android.os.Parcelable { public class WifiInfo implements android.os.Parcelable android.net.TransportInfo { method public double getLostTxPacketsPerSecond(); method public double getLostTxPacketsPerSecond(); method @Nullable public String getRequestingPackageName(); method @Nullable public String getRequestingPackageName(); method public double getRetriedTxPacketsPerSecond(); method public double getRetriedTxPacketsPerSecond(); Loading wifi/java/android/net/wifi/WifiInfo.java +103 −1 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.Nullable; import android.annotation.SystemApi; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState; import android.net.TransportInfo; import android.os.Build; import android.os.Build; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading @@ -36,12 +37,21 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.net.UnknownHostException; import java.util.EnumMap; import java.util.EnumMap; import java.util.Locale; import java.util.Locale; import java.util.Objects; /** /** * Describes the state of any Wi-Fi connection that is active or * Describes the state of any Wi-Fi connection that is active or * is in the process of being set up. * is in the process of being set up. */ * public class WifiInfo implements Parcelable { * In the connected state, access to location sensitive fields requires * the same permissions as {@link WifiManager#getScanResults}. If such access is not allowed, * {@link #getSSID} will return {@link WifiManager#UNKNOWN_SSID} and * {@link #getBSSID} will return {@code "02:00:00:00:00:00"}. * {@link #getNetworkId()} will return {@code -1}. * {@link #getPasspointFqdn()} will return null. * {@link #getPasspointProviderFriendlyName()} will return null. */ public class WifiInfo implements TransportInfo, Parcelable { private static final String TAG = "WifiInfo"; private static final String TAG = "WifiInfo"; /** /** * This is the map described in the Javadoc comment above. The positions * This is the map described in the Javadoc comment above. The positions Loading Loading @@ -1172,4 +1182,96 @@ public class WifiInfo implements Parcelable { public @Nullable String getPasspointUniqueId() { public @Nullable String getPasspointUniqueId() { return mPasspointUniqueId; return mPasspointUniqueId; } } @Override public boolean equals(Object that) { if (this == that) return true; // Potential API behavior change, so don't change behavior on older devices. if (!SdkLevel.isAtLeastS()) return false; if (!(that instanceof WifiInfo)) return false; WifiInfo thatWifiInfo = (WifiInfo) that; return Objects.equals(mWifiSsid, thatWifiInfo.mWifiSsid) && Objects.equals(mBSSID, thatWifiInfo.mBSSID) && Objects.equals(mNetworkId, thatWifiInfo.mNetworkId) && Objects.equals(mRssi, thatWifiInfo.mRssi) && Objects.equals(mSupplicantState, thatWifiInfo.mSupplicantState) && Objects.equals(mLinkSpeed, thatWifiInfo.mLinkSpeed) && Objects.equals(mTxLinkSpeed, thatWifiInfo.mTxLinkSpeed) && Objects.equals(mRxLinkSpeed, thatWifiInfo.mRxLinkSpeed) && Objects.equals(mFrequency, thatWifiInfo.mFrequency) && Objects.equals(mIpAddress, thatWifiInfo.mIpAddress) && Objects.equals(mMacAddress, thatWifiInfo.mMacAddress) && Objects.equals(mMeteredHint, thatWifiInfo.mMeteredHint) && Objects.equals(mEphemeral, thatWifiInfo.mEphemeral) && Objects.equals(mTrusted, thatWifiInfo.mTrusted) && Objects.equals(mOemPaid, thatWifiInfo.mOemPaid) && Objects.equals(mOemPrivate, thatWifiInfo.mOemPrivate) && Objects.equals(mCarrierMerged, thatWifiInfo.mCarrierMerged) && Objects.equals(mRequestingPackageName, thatWifiInfo.mRequestingPackageName) && Objects.equals(mOsuAp, thatWifiInfo.mOsuAp) && Objects.equals(mFqdn, thatWifiInfo.mFqdn) && Objects.equals(mProviderFriendlyName, thatWifiInfo.mProviderFriendlyName) && Objects.equals(mSubscriptionId, thatWifiInfo.mSubscriptionId) && Objects.equals(txBad, thatWifiInfo.txBad) && Objects.equals(txRetries, thatWifiInfo.txRetries) && Objects.equals(txSuccess, thatWifiInfo.txSuccess) && Objects.equals(rxSuccess, thatWifiInfo.rxSuccess) && Objects.equals(mLostTxPacketsPerSecond, thatWifiInfo.mLostTxPacketsPerSecond) && Objects.equals(mTxRetriedTxPacketsPerSecond, thatWifiInfo.mTxRetriedTxPacketsPerSecond) && Objects.equals(mSuccessfulTxPacketsPerSecond, thatWifiInfo.mSuccessfulTxPacketsPerSecond) && Objects.equals(mSuccessfulRxPacketsPerSecond, thatWifiInfo.mSuccessfulRxPacketsPerSecond) && Objects.equals(score, thatWifiInfo.score) && Objects.equals(mWifiStandard, thatWifiInfo.mWifiStandard) && Objects.equals(mMaxSupportedTxLinkSpeed, thatWifiInfo.mMaxSupportedTxLinkSpeed) && Objects.equals(mMaxSupportedRxLinkSpeed, thatWifiInfo.mMaxSupportedRxLinkSpeed) && Objects.equals(mPasspointUniqueId, thatWifiInfo.mPasspointUniqueId); } @Override public int hashCode() { // Potential API behavior change, so don't change behavior on older devices. if (!SdkLevel.isAtLeastS()) return System.identityHashCode(this); return Objects.hash(mWifiSsid, mBSSID, mNetworkId, mRssi, mSupplicantState, mLinkSpeed, mTxLinkSpeed, mRxLinkSpeed, mFrequency, mIpAddress, mMacAddress, mMeteredHint, mEphemeral, mTrusted, mOemPaid, mOemPrivate, mCarrierMerged, mRequestingPackageName, mOsuAp, mFqdn, mProviderFriendlyName, mSubscriptionId, txBad, txRetries, txSuccess, rxSuccess, mLostTxPacketsPerSecond, mTxRetriedTxPacketsPerSecond, mSuccessfulTxPacketsPerSecond, mSuccessfulRxPacketsPerSecond, score, mWifiStandard, mMaxSupportedTxLinkSpeed, mMaxSupportedRxLinkSpeed, mPasspointUniqueId); } } } wifi/java/android/net/wifi/WifiManager.java +46 −6 Original line number Original line Diff line number Diff line Loading @@ -35,9 +35,11 @@ import android.app.ActivityManager; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.Context; import android.net.ConnectivityManager; import android.net.ConnectivityManager; import android.net.ConnectivityManager.NetworkCallback; import android.net.DhcpInfo; import android.net.DhcpInfo; import android.net.MacAddress; import android.net.MacAddress; import android.net.Network; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkStack; import android.net.NetworkStack; import android.net.wifi.hotspot2.IProvisioningCallback; import android.net.wifi.hotspot2.IProvisioningCallback; import android.net.wifi.hotspot2.OsuProvider; import android.net.wifi.hotspot2.OsuProvider; Loading Loading @@ -2858,15 +2860,53 @@ public class WifiManager { /** /** * Return dynamic information about the current Wi-Fi connection, if any is active. * Return dynamic information about the current Wi-Fi connection, if any is active. * <p> * <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 {@link #UNKNOWN_SSID} and * {@link WifiInfo#getBSSID} will return {@code "02:00:00:00:00:00"}. * {@link WifiInfo#getPasspointFqdn()} will return null. * {@link WifiInfo#getPasspointProviderFriendlyName()} will return null. * * * @return the Wi-Fi information, contained in {@link WifiInfo}. * @return the Wi-Fi information, contained in {@link WifiInfo}. * * @deprecated Starting with {@link Build.VERSION_CODES#S}, WifiInfo retrieval is moved to * {@link ConnectivityManager} API surface. WifiInfo is attached in * {@link NetworkCapabilities#getTransportInfo()} which is available via callback in * {@link NetworkCallback#onCapabilitiesChanged(Network, NetworkCapabilities)} or on-demand from * {@link ConnectivityManager#getNetworkCapabilities(Network)}. * *</p> * Usage example: * <pre>{@code * final NetworkRequest request = * new NetworkRequest.Builder() * .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) * .build(); * final ConnectivityManager connectivityManager = * context.getSystemService(ConnectivityManager.class); * final NetworkCallback networkCallback = new NetworkCallback() { * ... * {@literal @}Override * void onAvailable(Network network) {} * * {@literal @}Override * void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) { * WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo(); * } * // etc. * }; * connectivityManager.requestNetwork(request, networkCallback); // For request * connectivityManager.registerNetworkCallback(request, networkCallback); // For listen * }</pre> * <p> * <b>Compatibility Note:</b> * <li>Apps can continue using this API, however newer features * such as ability to mask out location sensitive data in WifiInfo will not be supported * via this API. </li> * <li>On devices supporting concurrent connections (indicated via * {@link #isMultiStaConcurrencySupported()}), this API will return the details * of the internet providing connection (if any) to all apps, except for the apps that triggered * the creation of the concurrent connection. For such apps, this API will return the details of * the connection they created. For ex: apps using {@link WifiNetworkSpecifier} will * will trigger a concurrent connection on supported devices and hence this API will provide * details of their peer to peer connection (not the internet providing connection). </li> * </p> */ */ @Deprecated public WifiInfo getConnectionInfo() { public WifiInfo getConnectionInfo() { try { try { return mService.getConnectionInfo(mContext.getOpPackageName(), return mService.getConnectionInfo(mContext.getOpPackageName(), Loading wifi/tests/src/android/net/wifi/WifiInfoTest.java +81 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.net.wifi; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; Loading @@ -27,6 +28,8 @@ import android.telephony.SubscriptionManager; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; import com.android.modules.utils.build.SdkLevel; import org.junit.Test; import org.junit.Test; import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets; Loading Loading @@ -206,4 +209,82 @@ public class WifiInfoTest { assertEquals(TEST_RSSI, info2.getRssi()); assertEquals(TEST_RSSI, info2.getRssi()); assertEquals(TEST_NETWORK_ID2, info2.getNetworkId()); assertEquals(TEST_NETWORK_ID2, info2.getNetworkId()); } } @Test public void testWifiInfoEquals() throws Exception { WifiInfo.Builder builder = new WifiInfo.Builder() .setSsid(TEST_SSID.getBytes(StandardCharsets.UTF_8)) .setBssid(TEST_BSSID) .setRssi(TEST_RSSI) .setNetworkId(TEST_NETWORK_ID); WifiInfo info1 = builder.build(); WifiInfo info2 = builder.build(); if (SdkLevel.isAtLeastS()) { assertEquals(info1, info2); } else { assertNotEquals(info1, info2); } info1.setSubscriptionId(TEST_SUB_ID); // Same behavior pre-S & post-S. assertNotEquals(info1, info2); info2.setSubscriptionId(TEST_SUB_ID); if (SdkLevel.isAtLeastS()) { assertEquals(info1, info2); } else { assertNotEquals(info1, info2); } info1.setSSID(WifiSsid.createFromHex(null)); // Same behavior pre-S & post-S. assertNotEquals(info1, info2); info2.setSSID(WifiSsid.createFromHex(null)); if (SdkLevel.isAtLeastS()) { assertEquals(info1, info2); } else { assertNotEquals(info1, info2); } } @Test public void testWifiInfoHashcode() throws Exception { WifiInfo.Builder builder = new WifiInfo.Builder() .setSsid(TEST_SSID.getBytes(StandardCharsets.UTF_8)) .setBssid(TEST_BSSID) .setRssi(TEST_RSSI) .setNetworkId(TEST_NETWORK_ID); WifiInfo info1 = builder.build(); WifiInfo info2 = builder.build(); if (SdkLevel.isAtLeastS()) { assertEquals(info1.hashCode(), info2.hashCode()); } else { assertNotEquals(info1.hashCode(), info2.hashCode()); } info1.setSubscriptionId(TEST_SUB_ID); // Same behavior pre-S & post-S. assertNotEquals(info1.hashCode(), info2.hashCode()); info2.setSubscriptionId(TEST_SUB_ID); if (SdkLevel.isAtLeastS()) { assertEquals(info1.hashCode(), info2.hashCode()); } else { assertNotEquals(info1.hashCode(), info2.hashCode()); } info1.setSSID(WifiSsid.createFromHex(null)); // Same behavior pre-S & post-S. assertNotEquals(info1.hashCode(), info2.hashCode()); info2.setSSID(WifiSsid.createFromHex(null)); if (SdkLevel.isAtLeastS()) { assertEquals(info1.hashCode(), info2.hashCode()); } else { assertNotEquals(info1.hashCode(), info2.hashCode()); } } } } Loading
wifi/api/current.txt +2 −2 Original line number Original line Diff line number Diff line Loading @@ -270,7 +270,7 @@ package android.net.wifi { field public static final int SIM = 5; // 0x5 field public static final int SIM = 5; // 0x5 } } public class WifiInfo implements android.os.Parcelable { public class WifiInfo implements android.os.Parcelable android.net.TransportInfo { method public int describeContents(); method public int describeContents(); method public String getBSSID(); method public String getBSSID(); method public static android.net.NetworkInfo.DetailedState getDetailedStateOf(android.net.wifi.SupplicantState); method public static android.net.NetworkInfo.DetailedState getDetailedStateOf(android.net.wifi.SupplicantState); Loading Loading @@ -322,7 +322,7 @@ package android.net.wifi { method @Deprecated public boolean disconnect(); method @Deprecated public boolean disconnect(); method @Deprecated public boolean enableNetwork(int, boolean); method @Deprecated public boolean enableNetwork(int, boolean); method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE}) public java.util.List<android.net.wifi.WifiConfiguration> getConfiguredNetworks(); method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE}) public java.util.List<android.net.wifi.WifiConfiguration> getConfiguredNetworks(); method public android.net.wifi.WifiInfo getConnectionInfo(); method @Deprecated public android.net.wifi.WifiInfo getConnectionInfo(); method public android.net.DhcpInfo getDhcpInfo(); method public android.net.DhcpInfo getDhcpInfo(); method public int getMaxNumberOfNetworkSuggestionsPerApp(); method public int getMaxNumberOfNetworkSuggestionsPerApp(); method @IntRange(from=0) public int getMaxSignalLevel(); method @IntRange(from=0) public int getMaxSignalLevel(); Loading
wifi/api/system-current.txt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -441,7 +441,7 @@ package android.net.wifi { method public static void registerServiceWrappers(); method public static void registerServiceWrappers(); } } public class WifiInfo implements android.os.Parcelable { public class WifiInfo implements android.os.Parcelable android.net.TransportInfo { method public double getLostTxPacketsPerSecond(); method public double getLostTxPacketsPerSecond(); method @Nullable public String getRequestingPackageName(); method @Nullable public String getRequestingPackageName(); method public double getRetriedTxPacketsPerSecond(); method public double getRetriedTxPacketsPerSecond(); Loading
wifi/java/android/net/wifi/WifiInfo.java +103 −1 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.Nullable; import android.annotation.SystemApi; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState; import android.net.TransportInfo; import android.os.Build; import android.os.Build; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading @@ -36,12 +37,21 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.net.UnknownHostException; import java.util.EnumMap; import java.util.EnumMap; import java.util.Locale; import java.util.Locale; import java.util.Objects; /** /** * Describes the state of any Wi-Fi connection that is active or * Describes the state of any Wi-Fi connection that is active or * is in the process of being set up. * is in the process of being set up. */ * public class WifiInfo implements Parcelable { * In the connected state, access to location sensitive fields requires * the same permissions as {@link WifiManager#getScanResults}. If such access is not allowed, * {@link #getSSID} will return {@link WifiManager#UNKNOWN_SSID} and * {@link #getBSSID} will return {@code "02:00:00:00:00:00"}. * {@link #getNetworkId()} will return {@code -1}. * {@link #getPasspointFqdn()} will return null. * {@link #getPasspointProviderFriendlyName()} will return null. */ public class WifiInfo implements TransportInfo, Parcelable { private static final String TAG = "WifiInfo"; private static final String TAG = "WifiInfo"; /** /** * This is the map described in the Javadoc comment above. The positions * This is the map described in the Javadoc comment above. The positions Loading Loading @@ -1172,4 +1182,96 @@ public class WifiInfo implements Parcelable { public @Nullable String getPasspointUniqueId() { public @Nullable String getPasspointUniqueId() { return mPasspointUniqueId; return mPasspointUniqueId; } } @Override public boolean equals(Object that) { if (this == that) return true; // Potential API behavior change, so don't change behavior on older devices. if (!SdkLevel.isAtLeastS()) return false; if (!(that instanceof WifiInfo)) return false; WifiInfo thatWifiInfo = (WifiInfo) that; return Objects.equals(mWifiSsid, thatWifiInfo.mWifiSsid) && Objects.equals(mBSSID, thatWifiInfo.mBSSID) && Objects.equals(mNetworkId, thatWifiInfo.mNetworkId) && Objects.equals(mRssi, thatWifiInfo.mRssi) && Objects.equals(mSupplicantState, thatWifiInfo.mSupplicantState) && Objects.equals(mLinkSpeed, thatWifiInfo.mLinkSpeed) && Objects.equals(mTxLinkSpeed, thatWifiInfo.mTxLinkSpeed) && Objects.equals(mRxLinkSpeed, thatWifiInfo.mRxLinkSpeed) && Objects.equals(mFrequency, thatWifiInfo.mFrequency) && Objects.equals(mIpAddress, thatWifiInfo.mIpAddress) && Objects.equals(mMacAddress, thatWifiInfo.mMacAddress) && Objects.equals(mMeteredHint, thatWifiInfo.mMeteredHint) && Objects.equals(mEphemeral, thatWifiInfo.mEphemeral) && Objects.equals(mTrusted, thatWifiInfo.mTrusted) && Objects.equals(mOemPaid, thatWifiInfo.mOemPaid) && Objects.equals(mOemPrivate, thatWifiInfo.mOemPrivate) && Objects.equals(mCarrierMerged, thatWifiInfo.mCarrierMerged) && Objects.equals(mRequestingPackageName, thatWifiInfo.mRequestingPackageName) && Objects.equals(mOsuAp, thatWifiInfo.mOsuAp) && Objects.equals(mFqdn, thatWifiInfo.mFqdn) && Objects.equals(mProviderFriendlyName, thatWifiInfo.mProviderFriendlyName) && Objects.equals(mSubscriptionId, thatWifiInfo.mSubscriptionId) && Objects.equals(txBad, thatWifiInfo.txBad) && Objects.equals(txRetries, thatWifiInfo.txRetries) && Objects.equals(txSuccess, thatWifiInfo.txSuccess) && Objects.equals(rxSuccess, thatWifiInfo.rxSuccess) && Objects.equals(mLostTxPacketsPerSecond, thatWifiInfo.mLostTxPacketsPerSecond) && Objects.equals(mTxRetriedTxPacketsPerSecond, thatWifiInfo.mTxRetriedTxPacketsPerSecond) && Objects.equals(mSuccessfulTxPacketsPerSecond, thatWifiInfo.mSuccessfulTxPacketsPerSecond) && Objects.equals(mSuccessfulRxPacketsPerSecond, thatWifiInfo.mSuccessfulRxPacketsPerSecond) && Objects.equals(score, thatWifiInfo.score) && Objects.equals(mWifiStandard, thatWifiInfo.mWifiStandard) && Objects.equals(mMaxSupportedTxLinkSpeed, thatWifiInfo.mMaxSupportedTxLinkSpeed) && Objects.equals(mMaxSupportedRxLinkSpeed, thatWifiInfo.mMaxSupportedRxLinkSpeed) && Objects.equals(mPasspointUniqueId, thatWifiInfo.mPasspointUniqueId); } @Override public int hashCode() { // Potential API behavior change, so don't change behavior on older devices. if (!SdkLevel.isAtLeastS()) return System.identityHashCode(this); return Objects.hash(mWifiSsid, mBSSID, mNetworkId, mRssi, mSupplicantState, mLinkSpeed, mTxLinkSpeed, mRxLinkSpeed, mFrequency, mIpAddress, mMacAddress, mMeteredHint, mEphemeral, mTrusted, mOemPaid, mOemPrivate, mCarrierMerged, mRequestingPackageName, mOsuAp, mFqdn, mProviderFriendlyName, mSubscriptionId, txBad, txRetries, txSuccess, rxSuccess, mLostTxPacketsPerSecond, mTxRetriedTxPacketsPerSecond, mSuccessfulTxPacketsPerSecond, mSuccessfulRxPacketsPerSecond, score, mWifiStandard, mMaxSupportedTxLinkSpeed, mMaxSupportedRxLinkSpeed, mPasspointUniqueId); } } }
wifi/java/android/net/wifi/WifiManager.java +46 −6 Original line number Original line Diff line number Diff line Loading @@ -35,9 +35,11 @@ import android.app.ActivityManager; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.Context; import android.net.ConnectivityManager; import android.net.ConnectivityManager; import android.net.ConnectivityManager.NetworkCallback; import android.net.DhcpInfo; import android.net.DhcpInfo; import android.net.MacAddress; import android.net.MacAddress; import android.net.Network; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkStack; import android.net.NetworkStack; import android.net.wifi.hotspot2.IProvisioningCallback; import android.net.wifi.hotspot2.IProvisioningCallback; import android.net.wifi.hotspot2.OsuProvider; import android.net.wifi.hotspot2.OsuProvider; Loading Loading @@ -2858,15 +2860,53 @@ public class WifiManager { /** /** * Return dynamic information about the current Wi-Fi connection, if any is active. * Return dynamic information about the current Wi-Fi connection, if any is active. * <p> * <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 {@link #UNKNOWN_SSID} and * {@link WifiInfo#getBSSID} will return {@code "02:00:00:00:00:00"}. * {@link WifiInfo#getPasspointFqdn()} will return null. * {@link WifiInfo#getPasspointProviderFriendlyName()} will return null. * * * @return the Wi-Fi information, contained in {@link WifiInfo}. * @return the Wi-Fi information, contained in {@link WifiInfo}. * * @deprecated Starting with {@link Build.VERSION_CODES#S}, WifiInfo retrieval is moved to * {@link ConnectivityManager} API surface. WifiInfo is attached in * {@link NetworkCapabilities#getTransportInfo()} which is available via callback in * {@link NetworkCallback#onCapabilitiesChanged(Network, NetworkCapabilities)} or on-demand from * {@link ConnectivityManager#getNetworkCapabilities(Network)}. * *</p> * Usage example: * <pre>{@code * final NetworkRequest request = * new NetworkRequest.Builder() * .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) * .build(); * final ConnectivityManager connectivityManager = * context.getSystemService(ConnectivityManager.class); * final NetworkCallback networkCallback = new NetworkCallback() { * ... * {@literal @}Override * void onAvailable(Network network) {} * * {@literal @}Override * void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) { * WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo(); * } * // etc. * }; * connectivityManager.requestNetwork(request, networkCallback); // For request * connectivityManager.registerNetworkCallback(request, networkCallback); // For listen * }</pre> * <p> * <b>Compatibility Note:</b> * <li>Apps can continue using this API, however newer features * such as ability to mask out location sensitive data in WifiInfo will not be supported * via this API. </li> * <li>On devices supporting concurrent connections (indicated via * {@link #isMultiStaConcurrencySupported()}), this API will return the details * of the internet providing connection (if any) to all apps, except for the apps that triggered * the creation of the concurrent connection. For such apps, this API will return the details of * the connection they created. For ex: apps using {@link WifiNetworkSpecifier} will * will trigger a concurrent connection on supported devices and hence this API will provide * details of their peer to peer connection (not the internet providing connection). </li> * </p> */ */ @Deprecated public WifiInfo getConnectionInfo() { public WifiInfo getConnectionInfo() { try { try { return mService.getConnectionInfo(mContext.getOpPackageName(), return mService.getConnectionInfo(mContext.getOpPackageName(), Loading
wifi/tests/src/android/net/wifi/WifiInfoTest.java +81 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.net.wifi; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; Loading @@ -27,6 +28,8 @@ import android.telephony.SubscriptionManager; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; import com.android.modules.utils.build.SdkLevel; import org.junit.Test; import org.junit.Test; import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets; Loading Loading @@ -206,4 +209,82 @@ public class WifiInfoTest { assertEquals(TEST_RSSI, info2.getRssi()); assertEquals(TEST_RSSI, info2.getRssi()); assertEquals(TEST_NETWORK_ID2, info2.getNetworkId()); assertEquals(TEST_NETWORK_ID2, info2.getNetworkId()); } } @Test public void testWifiInfoEquals() throws Exception { WifiInfo.Builder builder = new WifiInfo.Builder() .setSsid(TEST_SSID.getBytes(StandardCharsets.UTF_8)) .setBssid(TEST_BSSID) .setRssi(TEST_RSSI) .setNetworkId(TEST_NETWORK_ID); WifiInfo info1 = builder.build(); WifiInfo info2 = builder.build(); if (SdkLevel.isAtLeastS()) { assertEquals(info1, info2); } else { assertNotEquals(info1, info2); } info1.setSubscriptionId(TEST_SUB_ID); // Same behavior pre-S & post-S. assertNotEquals(info1, info2); info2.setSubscriptionId(TEST_SUB_ID); if (SdkLevel.isAtLeastS()) { assertEquals(info1, info2); } else { assertNotEquals(info1, info2); } info1.setSSID(WifiSsid.createFromHex(null)); // Same behavior pre-S & post-S. assertNotEquals(info1, info2); info2.setSSID(WifiSsid.createFromHex(null)); if (SdkLevel.isAtLeastS()) { assertEquals(info1, info2); } else { assertNotEquals(info1, info2); } } @Test public void testWifiInfoHashcode() throws Exception { WifiInfo.Builder builder = new WifiInfo.Builder() .setSsid(TEST_SSID.getBytes(StandardCharsets.UTF_8)) .setBssid(TEST_BSSID) .setRssi(TEST_RSSI) .setNetworkId(TEST_NETWORK_ID); WifiInfo info1 = builder.build(); WifiInfo info2 = builder.build(); if (SdkLevel.isAtLeastS()) { assertEquals(info1.hashCode(), info2.hashCode()); } else { assertNotEquals(info1.hashCode(), info2.hashCode()); } info1.setSubscriptionId(TEST_SUB_ID); // Same behavior pre-S & post-S. assertNotEquals(info1.hashCode(), info2.hashCode()); info2.setSubscriptionId(TEST_SUB_ID); if (SdkLevel.isAtLeastS()) { assertEquals(info1.hashCode(), info2.hashCode()); } else { assertNotEquals(info1.hashCode(), info2.hashCode()); } info1.setSSID(WifiSsid.createFromHex(null)); // Same behavior pre-S & post-S. assertNotEquals(info1.hashCode(), info2.hashCode()); info2.setSSID(WifiSsid.createFromHex(null)); if (SdkLevel.isAtLeastS()) { assertEquals(info1.hashCode(), info2.hashCode()); } else { assertNotEquals(info1.hashCode(), info2.hashCode()); } } } }