Merge "ConnectivityManager: Provide API's to include location sensitive info"
This commit is contained in:
@@ -143,6 +143,7 @@ package android.net {
|
|||||||
|
|
||||||
public static class ConnectivityManager.NetworkCallback {
|
public static class ConnectivityManager.NetworkCallback {
|
||||||
ctor public ConnectivityManager.NetworkCallback();
|
ctor public ConnectivityManager.NetworkCallback();
|
||||||
|
ctor public ConnectivityManager.NetworkCallback(int);
|
||||||
method public void onAvailable(@NonNull android.net.Network);
|
method public void onAvailable(@NonNull android.net.Network);
|
||||||
method public void onBlockedStatusChanged(@NonNull android.net.Network, boolean);
|
method public void onBlockedStatusChanged(@NonNull android.net.Network, boolean);
|
||||||
method public void onCapabilitiesChanged(@NonNull android.net.Network, @NonNull android.net.NetworkCapabilities);
|
method public void onCapabilitiesChanged(@NonNull android.net.Network, @NonNull android.net.NetworkCapabilities);
|
||||||
@@ -150,6 +151,7 @@ package android.net {
|
|||||||
method public void onLosing(@NonNull android.net.Network, int);
|
method public void onLosing(@NonNull android.net.Network, int);
|
||||||
method public void onLost(@NonNull android.net.Network);
|
method public void onLost(@NonNull android.net.Network);
|
||||||
method public void onUnavailable();
|
method public void onUnavailable();
|
||||||
|
field public static final int FLAG_INCLUDE_LOCATION_INFO = 1; // 0x1
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface ConnectivityManager.OnNetworkActiveListener {
|
public static interface ConnectivityManager.OnNetworkActiveListener {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import android.net.SocketKeepalive.Callback;
|
|||||||
import android.net.TetheringManager.StartTetheringCallback;
|
import android.net.TetheringManager.StartTetheringCallback;
|
||||||
import android.net.TetheringManager.TetheringEventCallback;
|
import android.net.TetheringManager.TetheringEventCallback;
|
||||||
import android.net.TetheringManager.TetheringRequest;
|
import android.net.TetheringManager.TetheringRequest;
|
||||||
|
import android.net.wifi.WifiNetworkSuggestion;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
@@ -1315,7 +1316,7 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of {@link android.net.NetworkCapabilities} objects, representing
|
* Returns an array of {@link NetworkCapabilities} objects, representing
|
||||||
* the Networks that applications run by the given user will use by default.
|
* the Networks that applications run by the given user will use by default.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -1395,11 +1396,19 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link android.net.NetworkCapabilities} for the given {@link Network}. This
|
* Get the {@link NetworkCapabilities} for the given {@link Network}. This
|
||||||
* will return {@code null} if the network is unknown.
|
* will return {@code null} if the network is unknown.
|
||||||
*
|
*
|
||||||
|
* This will remove any location sensitive data in {@link TransportInfo} embedded in
|
||||||
|
* {@link NetworkCapabilities#getTransportInfo()}. Some transport info instances like
|
||||||
|
* {@link android.net.wifi.WifiInfo} contain location sensitive information. Retrieving
|
||||||
|
* this location sensitive information (subject to app's location permissions) will be
|
||||||
|
* noted by system. To include any location sensitive data in {@link TransportInfo},
|
||||||
|
* use a {@link NetworkCallback} with
|
||||||
|
* {@link NetworkCallback#FLAG_INCLUDE_LOCATION_INFO} flag.
|
||||||
|
*
|
||||||
* @param network The {@link Network} object identifying the network in question.
|
* @param network The {@link Network} object identifying the network in question.
|
||||||
* @return The {@link android.net.NetworkCapabilities} for the network, or {@code null}.
|
* @return The {@link NetworkCapabilities} for the network, or {@code null}.
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -3244,6 +3253,54 @@ public class ConnectivityManager {
|
|||||||
* A {@code NetworkCallback} that has been unregistered can be registered again.
|
* A {@code NetworkCallback} that has been unregistered can be registered again.
|
||||||
*/
|
*/
|
||||||
public static class NetworkCallback {
|
public static class NetworkCallback {
|
||||||
|
/**
|
||||||
|
* No flags associated with this callback.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int FLAG_NONE = 0;
|
||||||
|
/**
|
||||||
|
* Use this flag to include any location sensitive data in {@link NetworkCapabilities} sent
|
||||||
|
* via {@link #onCapabilitiesChanged(Network, NetworkCapabilities)}.
|
||||||
|
* <p>
|
||||||
|
* These include:
|
||||||
|
* <li> Some transport info instances (retrieved via
|
||||||
|
* {@link NetworkCapabilities#getTransportInfo()}) like {@link android.net.wifi.WifiInfo}
|
||||||
|
* contain location sensitive information.
|
||||||
|
* <li> OwnerUid (retrieved via {@link NetworkCapabilities#getOwnerUid()} is location
|
||||||
|
* sensitive for wifi suggestor apps (i.e using {@link WifiNetworkSuggestion}).</li>
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Note:
|
||||||
|
* <li> Retrieving this location sensitive information (subject to app's location
|
||||||
|
* permissions) will be noted by system. </li>
|
||||||
|
* <li> Without this flag any {@link NetworkCapabilities} provided via the callback does
|
||||||
|
* not include location sensitive info.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public static final int FLAG_INCLUDE_LOCATION_INFO = 1 << 0;
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@IntDef(flag = true, prefix = "FLAG_", value = {
|
||||||
|
FLAG_NONE,
|
||||||
|
FLAG_INCLUDE_LOCATION_INFO
|
||||||
|
})
|
||||||
|
public @interface Flag { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All the valid flags for error checking.
|
||||||
|
*/
|
||||||
|
private static final int VALID_FLAGS = FLAG_INCLUDE_LOCATION_INFO;
|
||||||
|
|
||||||
|
public NetworkCallback() {
|
||||||
|
this(FLAG_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkCallback(@Flag int flags) {
|
||||||
|
Preconditions.checkArgument((flags & VALID_FLAGS) == flags);
|
||||||
|
mFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the framework connects to a new network to evaluate whether it satisfies this
|
* Called when the framework connects to a new network to evaluate whether it satisfies this
|
||||||
* request. If evaluation succeeds, this callback may be followed by an {@link #onAvailable}
|
* request. If evaluation succeeds, this callback may be followed by an {@link #onAvailable}
|
||||||
@@ -3381,7 +3438,7 @@ public class ConnectivityManager {
|
|||||||
* calling these methods while in a callback may return an outdated or even a null object.
|
* calling these methods while in a callback may return an outdated or even a null object.
|
||||||
*
|
*
|
||||||
* @param network The {@link Network} whose capabilities have changed.
|
* @param network The {@link Network} whose capabilities have changed.
|
||||||
* @param networkCapabilities The new {@link android.net.NetworkCapabilities} for this
|
* @param networkCapabilities The new {@link NetworkCapabilities} for this
|
||||||
* network.
|
* network.
|
||||||
*/
|
*/
|
||||||
public void onCapabilitiesChanged(@NonNull Network network,
|
public void onCapabilitiesChanged(@NonNull Network network,
|
||||||
@@ -3450,6 +3507,7 @@ public class ConnectivityManager {
|
|||||||
public void onBlockedStatusChanged(@NonNull Network network, boolean blocked) {}
|
public void onBlockedStatusChanged(@NonNull Network network, boolean blocked) {}
|
||||||
|
|
||||||
private NetworkRequest networkRequest;
|
private NetworkRequest networkRequest;
|
||||||
|
private final int mFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3639,14 +3697,15 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
Messenger messenger = new Messenger(handler);
|
Messenger messenger = new Messenger(handler);
|
||||||
Binder binder = new Binder();
|
Binder binder = new Binder();
|
||||||
|
final int callbackFlags = callback.mFlags;
|
||||||
if (reqType == LISTEN) {
|
if (reqType == LISTEN) {
|
||||||
request = mService.listenForNetwork(
|
request = mService.listenForNetwork(
|
||||||
need, messenger, binder, callingPackageName,
|
need, messenger, binder, callbackFlags, callingPackageName,
|
||||||
getAttributionTag());
|
getAttributionTag());
|
||||||
} else {
|
} else {
|
||||||
request = mService.requestNetwork(
|
request = mService.requestNetwork(
|
||||||
need, reqType.ordinal(), messenger, timeoutMs, binder, legacyType,
|
need, reqType.ordinal(), messenger, timeoutMs, binder, legacyType,
|
||||||
callingPackageName, getAttributionTag());
|
callbackFlags, callingPackageName, getAttributionTag());
|
||||||
}
|
}
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
sCallbacks.put(request, callback);
|
sCallbacks.put(request, callback);
|
||||||
@@ -3693,7 +3752,7 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a network to satisfy a set of {@link android.net.NetworkCapabilities}.
|
* Request a network to satisfy a set of {@link NetworkCapabilities}.
|
||||||
*
|
*
|
||||||
* <p>This method will attempt to find the best network that matches the passed
|
* <p>This method will attempt to find the best network that matches the passed
|
||||||
* {@link NetworkRequest}, and to bring up one that does if none currently satisfies the
|
* {@link NetworkRequest}, and to bring up one that does if none currently satisfies the
|
||||||
@@ -3777,7 +3836,7 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a network to satisfy a set of {@link android.net.NetworkCapabilities}.
|
* Request a network to satisfy a set of {@link NetworkCapabilities}.
|
||||||
*
|
*
|
||||||
* This method behaves identically to {@link #requestNetwork(NetworkRequest, NetworkCallback)}
|
* This method behaves identically to {@link #requestNetwork(NetworkRequest, NetworkCallback)}
|
||||||
* but runs all the callbacks on the passed Handler.
|
* but runs all the callbacks on the passed Handler.
|
||||||
@@ -3799,7 +3858,7 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a network to satisfy a set of {@link android.net.NetworkCapabilities}, limited
|
* Request a network to satisfy a set of {@link NetworkCapabilities}, limited
|
||||||
* by a timeout.
|
* by a timeout.
|
||||||
*
|
*
|
||||||
* This function behaves identically to the non-timed-out version
|
* This function behaves identically to the non-timed-out version
|
||||||
@@ -3834,7 +3893,7 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a network to satisfy a set of {@link android.net.NetworkCapabilities}, limited
|
* Request a network to satisfy a set of {@link NetworkCapabilities}, limited
|
||||||
* by a timeout.
|
* by a timeout.
|
||||||
*
|
*
|
||||||
* This method behaves identically to
|
* This method behaves identically to
|
||||||
@@ -3879,7 +3938,7 @@ public class ConnectivityManager {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a network to satisfy a set of {@link android.net.NetworkCapabilities}.
|
* Request a network to satisfy a set of {@link NetworkCapabilities}.
|
||||||
*
|
*
|
||||||
* This function behaves identically to the version that takes a NetworkCallback, but instead
|
* This function behaves identically to the version that takes a NetworkCallback, but instead
|
||||||
* of {@link NetworkCallback} a {@link PendingIntent} is used. This means
|
* of {@link NetworkCallback} a {@link PendingIntent} is used. This means
|
||||||
@@ -4911,7 +4970,7 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a network to satisfy a set of {@link android.net.NetworkCapabilities}, but
|
* Request a network to satisfy a set of {@link NetworkCapabilities}, but
|
||||||
* does not cause any networks to retain the NET_CAPABILITY_FOREGROUND capability. This can
|
* does not cause any networks to retain the NET_CAPABILITY_FOREGROUND capability. This can
|
||||||
* be used to request that the system provide a network without causing the network to be
|
* be used to request that the system provide a network without causing the network to be
|
||||||
* in the foreground.
|
* in the foreground.
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities, int reqType,
|
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities, int reqType,
|
||||||
in Messenger messenger, int timeoutSec, in IBinder binder, int legacy,
|
in Messenger messenger, int timeoutSec, in IBinder binder, int legacy,
|
||||||
String callingPackageName, String callingAttributionTag);
|
int callbackFlags, String callingPackageName, String callingAttributionTag);
|
||||||
|
|
||||||
NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities,
|
NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
in PendingIntent operation, String callingPackageName, String callingAttributionTag);
|
in PendingIntent operation, String callingPackageName, String callingAttributionTag);
|
||||||
@@ -151,7 +151,7 @@ interface IConnectivityManager
|
|||||||
void releasePendingNetworkRequest(in PendingIntent operation);
|
void releasePendingNetworkRequest(in PendingIntent operation);
|
||||||
|
|
||||||
NetworkRequest listenForNetwork(in NetworkCapabilities networkCapabilities,
|
NetworkRequest listenForNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
in Messenger messenger, in IBinder binder, String callingPackageName,
|
in Messenger messenger, in IBinder binder, int callbackFlags, String callingPackageName,
|
||||||
String callingAttributionTag);
|
String callingAttributionTag);
|
||||||
|
|
||||||
void pendingListenForNetwork(in NetworkCapabilities networkCapabilities,
|
void pendingListenForNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.annotation.RequiresPermission;
|
|||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.net.ConnectivityManager.NetworkCallback;
|
import android.net.ConnectivityManager.NetworkCallback;
|
||||||
|
import android.net.wifi.WifiNetworkSuggestion;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -1048,6 +1049,16 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
*
|
*
|
||||||
* Instances of NetworkCapabilities sent to apps without the appropriate permissions will have
|
* Instances of NetworkCapabilities sent to apps without the appropriate permissions will have
|
||||||
* this field cleared out.
|
* this field cleared out.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* This field will only be populated for VPN and wifi network suggestor apps (i.e using
|
||||||
|
* {@link WifiNetworkSuggestion}), and only for the network they own.
|
||||||
|
* In the case of wifi network suggestors apps, this field is also location sensitive, so the
|
||||||
|
* app needs to hold {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission. If the
|
||||||
|
* app targets SDK version greater than or equal to {@link Build.VERSION_CODES#S}, then they
|
||||||
|
* also need to use {@link NetworkCallback#FLAG_INCLUDE_LOCATION_INFO} to get the info in their
|
||||||
|
* callback. The app will be blamed for location access if this field is included.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public int getOwnerUid() {
|
public int getOwnerUid() {
|
||||||
return mOwnerUid;
|
return mOwnerUid;
|
||||||
|
|||||||
Reference in New Issue
Block a user