Allow unprivileged NetworkCallbacks to see other UIDs' networks.

Currently, unprivileged apps can call getAllNetworks() to see
all networks on the system, even networks that do not apply to
them. Allow them to do this via NetworkCallbacks as well.

This is the last piece of information that was only available
through getAllNetworks, so this CL deprecates that API.

Bug: 187921303
Test: new unit tests
Test: CTS test in other CL in topic
Change-Id: I30f1021927d3c8eae6525116c61ff4a4acecff6d
This commit is contained in:
Lorenzo Colitti
2021-05-17 20:31:21 +09:00
parent 1bbb7a7570
commit 86714b1fd2
5 changed files with 175 additions and 7 deletions

View File

@@ -1433,10 +1433,18 @@ public class ConnectivityManager {
* Returns an array of all {@link Network} currently tracked by the
* framework.
*
* @deprecated This method does not provide any notification of network state changes, forcing
* apps to call it repeatedly. This is inefficient and prone to race conditions.
* Apps should use methods such as
* {@link #registerNetworkCallback(NetworkRequest, NetworkCallback)} instead.
* Apps that desire to obtain information about networks that do not apply to them
* can use {@link NetworkRequest.Builder#setIncludeOtherUidNetworks}.
*
* @return an array of {@link Network} objects.
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@NonNull
@Deprecated
public Network[] getAllNetworks() {
try {
return mService.getAllNetworks();