Loading core/api/module-lib-current.txt +8 −0 Original line number Original line Diff line number Diff line Loading @@ -8,6 +8,14 @@ package android.app { } } package android.app.usage { public class NetworkStatsManager { method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyNetworkStatus(@NonNull java.util.List<android.net.Network>, @NonNull java.util.List<android.net.NetworkStateSnapshot>, @Nullable String, @NonNull java.util.List<android.net.UnderlyingNetworkInfo>); } } package android.net { package android.net { public static final class IpSecManager.UdpEncapsulationSocket implements java.lang.AutoCloseable { public static final class IpSecManager.UdpEncapsulationSocket implements java.lang.AutoCloseable { Loading core/java/android/app/usage/NetworkStatsManager.java +50 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.app.usage; package android.app.usage; import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.RequiresPermission; Loading @@ -28,8 +30,11 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.ConnectivityManager; import android.net.DataUsageRequest; import android.net.DataUsageRequest; import android.net.INetworkStatsService; import android.net.INetworkStatsService; import android.net.Network; import android.net.NetworkStack; import android.net.NetworkStack; import android.net.NetworkStateSnapshot; import android.net.NetworkTemplate; import android.net.NetworkTemplate; import android.net.UnderlyingNetworkInfo; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.net.netstats.provider.NetworkStatsProvider; import android.net.netstats.provider.NetworkStatsProvider; import android.os.Binder; import android.os.Binder; Loading @@ -48,6 +53,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.net.module.util.NetworkIdentityUtils; import com.android.net.module.util.NetworkIdentityUtils; import java.util.List; import java.util.Objects; import java.util.Objects; /** /** Loading Loading @@ -633,6 +639,50 @@ public class NetworkStatsManager { return template; return template; } } /** * Notify {@code NetworkStatsService} about network status changed. * * Notifies NetworkStatsService of network state changes for data usage accounting purposes. * * To avoid races that attribute data usage to wrong network, such as new network with * the same interface after SIM hot-swap, this function will not return until * {@code NetworkStatsService} finishes its work of retrieving traffic statistics from * all data sources. * * @param defaultNetworks the list of all networks that could be used by network traffic that * does not explicitly select a network. * @param networkStateSnapshots a list of {@link NetworkStateSnapshot}s, one for * each network that is currently connected. * @param activeIface the active (i.e., connected) default network interface for the calling * uid. Used to determine on which network future calls to * {@link android.net.TrafficStats#incrementOperationCount} applies to. * @param underlyingNetworkInfos the list of underlying network information for all * currently-connected VPNs. * * @hide */ @SystemApi(client = MODULE_LIBRARIES) @RequiresPermission(anyOf = { NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyNetworkStatus( @NonNull List<Network> defaultNetworks, @NonNull List<NetworkStateSnapshot> networkStateSnapshots, @Nullable String activeIface, @NonNull List<UnderlyingNetworkInfo> underlyingNetworkInfos) { try { Objects.requireNonNull(defaultNetworks); Objects.requireNonNull(networkStateSnapshots); Objects.requireNonNull(underlyingNetworkInfos); // TODO: Change internal namings after the name is decided. mService.forceUpdateIfaces(defaultNetworks.toArray(new Network[0]), networkStateSnapshots.toArray(new NetworkStateSnapshot[0]), activeIface, underlyingNetworkInfos.toArray(new UnderlyingNetworkInfo[0])); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } private static class CallbackHandler extends Handler { private static class CallbackHandler extends Handler { private final int mNetworkType; private final int mNetworkType; private final String mSubscriberId; private final String mSubscriberId; Loading services/core/java/com/android/server/net/NetworkStatsService.java +4 −5 Original line number Original line Diff line number Diff line Loading @@ -379,6 +379,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { case MSG_UPDATE_IFACES: { case MSG_UPDATE_IFACES: { // If no cached states, ignore. // If no cached states, ignore. if (mLastNetworkStateSnapshots == null) break; if (mLastNetworkStateSnapshots == null) break; // TODO (b/181642673): Protect mDefaultNetworks from concurrent accessing. updateIfaces(mDefaultNetworks, mLastNetworkStateSnapshots, mActiveIface); updateIfaces(mDefaultNetworks, mLastNetworkStateSnapshots, mActiveIface); break; break; } } Loading Loading @@ -1266,7 +1267,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { * they are combined under a single {@link NetworkIdentitySet}. * they are combined under a single {@link NetworkIdentitySet}. */ */ @GuardedBy("mStatsLock") @GuardedBy("mStatsLock") private void updateIfacesLocked(@Nullable Network[] defaultNetworks, private void updateIfacesLocked(@NonNull Network[] defaultNetworks, @NonNull NetworkStateSnapshot[] snapshots) { @NonNull NetworkStateSnapshot[] snapshots) { if (!mSystemReady) return; if (!mSystemReady) return; if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); Loading @@ -1282,10 +1283,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // Rebuild active interfaces based on connected networks // Rebuild active interfaces based on connected networks mActiveIfaces.clear(); mActiveIfaces.clear(); mActiveUidIfaces.clear(); mActiveUidIfaces.clear(); if (defaultNetworks != null) { // Update the list of default networks. // Caller is ConnectivityService. Update the list of default networks. mDefaultNetworks = defaultNetworks; mDefaultNetworks = defaultNetworks; } mLastNetworkStateSnapshots = snapshots; mLastNetworkStateSnapshots = snapshots; Loading Loading
core/api/module-lib-current.txt +8 −0 Original line number Original line Diff line number Diff line Loading @@ -8,6 +8,14 @@ package android.app { } } package android.app.usage { public class NetworkStatsManager { method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyNetworkStatus(@NonNull java.util.List<android.net.Network>, @NonNull java.util.List<android.net.NetworkStateSnapshot>, @Nullable String, @NonNull java.util.List<android.net.UnderlyingNetworkInfo>); } } package android.net { package android.net { public static final class IpSecManager.UdpEncapsulationSocket implements java.lang.AutoCloseable { public static final class IpSecManager.UdpEncapsulationSocket implements java.lang.AutoCloseable { Loading
core/java/android/app/usage/NetworkStatsManager.java +50 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.app.usage; package android.app.usage; import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.RequiresPermission; Loading @@ -28,8 +30,11 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.ConnectivityManager; import android.net.DataUsageRequest; import android.net.DataUsageRequest; import android.net.INetworkStatsService; import android.net.INetworkStatsService; import android.net.Network; import android.net.NetworkStack; import android.net.NetworkStack; import android.net.NetworkStateSnapshot; import android.net.NetworkTemplate; import android.net.NetworkTemplate; import android.net.UnderlyingNetworkInfo; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.net.netstats.provider.NetworkStatsProvider; import android.net.netstats.provider.NetworkStatsProvider; import android.os.Binder; import android.os.Binder; Loading @@ -48,6 +53,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.net.module.util.NetworkIdentityUtils; import com.android.net.module.util.NetworkIdentityUtils; import java.util.List; import java.util.Objects; import java.util.Objects; /** /** Loading Loading @@ -633,6 +639,50 @@ public class NetworkStatsManager { return template; return template; } } /** * Notify {@code NetworkStatsService} about network status changed. * * Notifies NetworkStatsService of network state changes for data usage accounting purposes. * * To avoid races that attribute data usage to wrong network, such as new network with * the same interface after SIM hot-swap, this function will not return until * {@code NetworkStatsService} finishes its work of retrieving traffic statistics from * all data sources. * * @param defaultNetworks the list of all networks that could be used by network traffic that * does not explicitly select a network. * @param networkStateSnapshots a list of {@link NetworkStateSnapshot}s, one for * each network that is currently connected. * @param activeIface the active (i.e., connected) default network interface for the calling * uid. Used to determine on which network future calls to * {@link android.net.TrafficStats#incrementOperationCount} applies to. * @param underlyingNetworkInfos the list of underlying network information for all * currently-connected VPNs. * * @hide */ @SystemApi(client = MODULE_LIBRARIES) @RequiresPermission(anyOf = { NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyNetworkStatus( @NonNull List<Network> defaultNetworks, @NonNull List<NetworkStateSnapshot> networkStateSnapshots, @Nullable String activeIface, @NonNull List<UnderlyingNetworkInfo> underlyingNetworkInfos) { try { Objects.requireNonNull(defaultNetworks); Objects.requireNonNull(networkStateSnapshots); Objects.requireNonNull(underlyingNetworkInfos); // TODO: Change internal namings after the name is decided. mService.forceUpdateIfaces(defaultNetworks.toArray(new Network[0]), networkStateSnapshots.toArray(new NetworkStateSnapshot[0]), activeIface, underlyingNetworkInfos.toArray(new UnderlyingNetworkInfo[0])); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } private static class CallbackHandler extends Handler { private static class CallbackHandler extends Handler { private final int mNetworkType; private final int mNetworkType; private final String mSubscriberId; private final String mSubscriberId; Loading
services/core/java/com/android/server/net/NetworkStatsService.java +4 −5 Original line number Original line Diff line number Diff line Loading @@ -379,6 +379,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { case MSG_UPDATE_IFACES: { case MSG_UPDATE_IFACES: { // If no cached states, ignore. // If no cached states, ignore. if (mLastNetworkStateSnapshots == null) break; if (mLastNetworkStateSnapshots == null) break; // TODO (b/181642673): Protect mDefaultNetworks from concurrent accessing. updateIfaces(mDefaultNetworks, mLastNetworkStateSnapshots, mActiveIface); updateIfaces(mDefaultNetworks, mLastNetworkStateSnapshots, mActiveIface); break; break; } } Loading Loading @@ -1266,7 +1267,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { * they are combined under a single {@link NetworkIdentitySet}. * they are combined under a single {@link NetworkIdentitySet}. */ */ @GuardedBy("mStatsLock") @GuardedBy("mStatsLock") private void updateIfacesLocked(@Nullable Network[] defaultNetworks, private void updateIfacesLocked(@NonNull Network[] defaultNetworks, @NonNull NetworkStateSnapshot[] snapshots) { @NonNull NetworkStateSnapshot[] snapshots) { if (!mSystemReady) return; if (!mSystemReady) return; if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); Loading @@ -1282,10 +1283,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // Rebuild active interfaces based on connected networks // Rebuild active interfaces based on connected networks mActiveIfaces.clear(); mActiveIfaces.clear(); mActiveUidIfaces.clear(); mActiveUidIfaces.clear(); if (defaultNetworks != null) { // Update the list of default networks. // Caller is ConnectivityService. Update the list of default networks. mDefaultNetworks = defaultNetworks; mDefaultNetworks = defaultNetworks; } mLastNetworkStateSnapshots = snapshots; mLastNetworkStateSnapshots = snapshots; Loading