summaryrefslogtreecommitdiff
path: root/wifi/java
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-08-14 07:17:59 -0700
committerRoshan Pius <rpius@google.com>2020-12-22 23:47:46 -0800
commit36f802a060db905490f6a24aef04d4d3641fe591 (patch)
treec59702fd8aa1f447edf2af65af6696e57d2b51d3 /wifi/java
parent9fc348c9b9c4bd15e5d46ca3c0e9f694f279cdf9 (diff)
Convert WifiInfo to TransportInfo
Also, deprecate WifiManager.getConnectionInfo() and add a note to help apps to migrate. The deprecation is purely cosmetic, no plans to remove any existing functionality from the WifiManager API. (cherry-picked from aosp/1508600) Bug: 162602799 Test: Compiles Change-Id: I12c473185dc5518f5684e83c2f49e07271738cb5
Diffstat (limited to 'wifi/java')
-rw-r--r--wifi/java/android/net/wifi/WifiInfo.java12
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java52
2 files changed, 57 insertions, 7 deletions
diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java
index 6bd1ce54dc5b..39a5a7d93b5b 100644
--- a/wifi/java/android/net/wifi/WifiInfo.java
+++ b/wifi/java/android/net/wifi/WifiInfo.java
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.NetworkInfo.DetailedState;
+import android.net.TransportInfo;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
@@ -40,8 +41,17 @@ import java.util.Locale;
/**
* Describes the state of any Wi-Fi connection that is active or
* is in the process of being set up.
+ *
+ * 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 Parcelable {
+public class WifiInfo implements TransportInfo, Parcelable {
+ // TODO(b/162602799): Implement equals/hahscode methods.
private static final String TAG = "WifiInfo";
/**
* This is the map described in the Javadoc comment above. The positions
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 6496cc7a3ba3..c25e18623900 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -35,9 +35,11 @@ import android.app.ActivityManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.net.ConnectivityManager;
+import android.net.ConnectivityManager.NetworkCallback;
import android.net.DhcpInfo;
import android.net.MacAddress;
import android.net.Network;
+import android.net.NetworkCapabilities;
import android.net.NetworkStack;
import android.net.wifi.hotspot2.IProvisioningCallback;
import android.net.wifi.hotspot2.OsuProvider;
@@ -2858,15 +2860,53 @@ public class WifiManager {
/**
* Return dynamic information about the current Wi-Fi connection, if any is active.
* <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}.
+ *
+ * @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() {
try {
return mService.getConnectionInfo(mContext.getOpPackageName(),