Loading core/java/android/net/NetworkStateSnapshot.java +13 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import com.android.net.module.util.NetworkIdentityUtils; import java.util.Objects; /** Loading Loading @@ -124,4 +126,15 @@ public final class NetworkStateSnapshot implements Parcelable { public int hashCode() { return Objects.hash(network, networkCapabilities, linkProperties, subscriberId, legacyType); } @Override public String toString() { return "NetworkStateSnapshot{" + "network=" + network + ", networkCapabilities=" + networkCapabilities + ", linkProperties=" + linkProperties + ", subscriberId='" + NetworkIdentityUtils.scrubSubscriberId(subscriberId) + '\'' + ", legacyType=" + legacyType + '}'; } } packages/Connectivity/framework/api/module-lib-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ package android.net { } public class ConnectivityManager { method @NonNull @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public java.util.List<android.net.NetworkStateSnapshot> getAllNetworkStateSnapshot(); method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerSystemDefaultNetworkCallback(@NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler); method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void requestBackgroundNetwork(@NonNull android.net.NetworkRequest, @Nullable android.os.Handler, @NonNull android.net.ConnectivityManager.NetworkCallback); method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_TEST_NETWORKS, android.Manifest.permission.NETWORK_STACK}) public void simulateDataStall(int, long, @NonNull android.net.Network, @NonNull android.os.PersistableBundle); Loading packages/Connectivity/framework/src/android/net/ConnectivityManager.java +19 −0 Original line number Diff line number Diff line Loading @@ -1258,6 +1258,25 @@ public class ConnectivityManager { } } /** * Return a list of {@link NetworkStateSnapshot}s, one for each network that is currently * connected. * @hide */ @SystemApi(client = MODULE_LIBRARIES) @RequiresPermission(anyOf = { NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) @NonNull public List<NetworkStateSnapshot> getAllNetworkStateSnapshot() { try { return mService.getAllNetworkStateSnapshot(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Returns the {@link Network} object currently serving a given type, or * null if the given type is not connected. Loading packages/Connectivity/framework/src/android/net/IConnectivityManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkRequest; import android.net.NetworkState; import android.net.NetworkStateSnapshot; import android.net.OemNetworkPreferences; import android.net.ProxyInfo; import android.net.UidRange; Loading Loading @@ -79,6 +80,8 @@ interface IConnectivityManager @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) NetworkState[] getAllNetworkState(); List<NetworkStateSnapshot> getAllNetworkStateSnapshot(); boolean isActiveNetworkMetered(); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress, Loading services/core/java/com/android/server/ConnectivityService.java +26 −4 Original line number Diff line number Diff line Loading @@ -1886,24 +1886,46 @@ public class ConnectivityService extends IConnectivityManager.Stub } } // TODO: Consider delete this function or turn it into a no-op method. @Override public NetworkState[] getAllNetworkState() { // This contains IMSI details, so make sure the caller is privileged. PermissionUtils.enforceNetworkStackPermission(mContext); final ArrayList<NetworkState> result = new ArrayList<>(); for (NetworkStateSnapshot snapshot : getAllNetworkStateSnapshot()) { // NetworkStateSnapshot doesn't contain NetworkInfo, so need to fetch it from the // NetworkAgentInfo. final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.network); if (nai != null && nai.networkInfo.isConnected()) { result.add(new NetworkState(new NetworkInfo(nai.networkInfo), snapshot.linkProperties, snapshot.networkCapabilities, snapshot.network, snapshot.subscriberId)); } } return result.toArray(new NetworkState[result.size()]); } @Override @NonNull public List<NetworkStateSnapshot> getAllNetworkStateSnapshot() { // This contains IMSI details, so make sure the caller is privileged. PermissionUtils.enforceNetworkStackPermission(mContext); final ArrayList<NetworkStateSnapshot> result = new ArrayList<>(); for (Network network : getAllNetworks()) { final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network); // TODO: Consider include SUSPENDED networks. // TODO: Consider include SUSPENDED networks, which should be considered as // temporary shortage of connectivity of a connected network. if (nai != null && nai.networkInfo.isConnected()) { // TODO (b/73321673) : NetworkState contains a copy of the // TODO (b/73321673) : NetworkStateSnapshot contains a copy of the // NetworkCapabilities, which may contain UIDs of apps to which the // network applies. Should the UIDs be cleared so as not to leak or // interfere ? result.add(nai.getNetworkState()); result.add(nai.getNetworkStateSnapshot()); } } return result.toArray(new NetworkState[result.size()]); return result; } @Override Loading Loading
core/java/android/net/NetworkStateSnapshot.java +13 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import com.android.net.module.util.NetworkIdentityUtils; import java.util.Objects; /** Loading Loading @@ -124,4 +126,15 @@ public final class NetworkStateSnapshot implements Parcelable { public int hashCode() { return Objects.hash(network, networkCapabilities, linkProperties, subscriberId, legacyType); } @Override public String toString() { return "NetworkStateSnapshot{" + "network=" + network + ", networkCapabilities=" + networkCapabilities + ", linkProperties=" + linkProperties + ", subscriberId='" + NetworkIdentityUtils.scrubSubscriberId(subscriberId) + '\'' + ", legacyType=" + legacyType + '}'; } }
packages/Connectivity/framework/api/module-lib-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ package android.net { } public class ConnectivityManager { method @NonNull @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public java.util.List<android.net.NetworkStateSnapshot> getAllNetworkStateSnapshot(); method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerSystemDefaultNetworkCallback(@NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler); method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void requestBackgroundNetwork(@NonNull android.net.NetworkRequest, @Nullable android.os.Handler, @NonNull android.net.ConnectivityManager.NetworkCallback); method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_TEST_NETWORKS, android.Manifest.permission.NETWORK_STACK}) public void simulateDataStall(int, long, @NonNull android.net.Network, @NonNull android.os.PersistableBundle); Loading
packages/Connectivity/framework/src/android/net/ConnectivityManager.java +19 −0 Original line number Diff line number Diff line Loading @@ -1258,6 +1258,25 @@ public class ConnectivityManager { } } /** * Return a list of {@link NetworkStateSnapshot}s, one for each network that is currently * connected. * @hide */ @SystemApi(client = MODULE_LIBRARIES) @RequiresPermission(anyOf = { NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) @NonNull public List<NetworkStateSnapshot> getAllNetworkStateSnapshot() { try { return mService.getAllNetworkStateSnapshot(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Returns the {@link Network} object currently serving a given type, or * null if the given type is not connected. Loading
packages/Connectivity/framework/src/android/net/IConnectivityManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkRequest; import android.net.NetworkState; import android.net.NetworkStateSnapshot; import android.net.OemNetworkPreferences; import android.net.ProxyInfo; import android.net.UidRange; Loading Loading @@ -79,6 +80,8 @@ interface IConnectivityManager @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) NetworkState[] getAllNetworkState(); List<NetworkStateSnapshot> getAllNetworkStateSnapshot(); boolean isActiveNetworkMetered(); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress, Loading
services/core/java/com/android/server/ConnectivityService.java +26 −4 Original line number Diff line number Diff line Loading @@ -1886,24 +1886,46 @@ public class ConnectivityService extends IConnectivityManager.Stub } } // TODO: Consider delete this function or turn it into a no-op method. @Override public NetworkState[] getAllNetworkState() { // This contains IMSI details, so make sure the caller is privileged. PermissionUtils.enforceNetworkStackPermission(mContext); final ArrayList<NetworkState> result = new ArrayList<>(); for (NetworkStateSnapshot snapshot : getAllNetworkStateSnapshot()) { // NetworkStateSnapshot doesn't contain NetworkInfo, so need to fetch it from the // NetworkAgentInfo. final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.network); if (nai != null && nai.networkInfo.isConnected()) { result.add(new NetworkState(new NetworkInfo(nai.networkInfo), snapshot.linkProperties, snapshot.networkCapabilities, snapshot.network, snapshot.subscriberId)); } } return result.toArray(new NetworkState[result.size()]); } @Override @NonNull public List<NetworkStateSnapshot> getAllNetworkStateSnapshot() { // This contains IMSI details, so make sure the caller is privileged. PermissionUtils.enforceNetworkStackPermission(mContext); final ArrayList<NetworkStateSnapshot> result = new ArrayList<>(); for (Network network : getAllNetworks()) { final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network); // TODO: Consider include SUSPENDED networks. // TODO: Consider include SUSPENDED networks, which should be considered as // temporary shortage of connectivity of a connected network. if (nai != null && nai.networkInfo.isConnected()) { // TODO (b/73321673) : NetworkState contains a copy of the // TODO (b/73321673) : NetworkStateSnapshot contains a copy of the // NetworkCapabilities, which may contain UIDs of apps to which the // network applies. Should the UIDs be cleared so as not to leak or // interfere ? result.add(nai.getNetworkState()); result.add(nai.getNetworkStateSnapshot()); } } return result.toArray(new NetworkState[result.size()]); return result; } @Override Loading