Merge "[SP16] Address comments on aosp/1172143"

This commit is contained in:
Junyu Lai
2020-02-15 02:21:30 +00:00
committed by Gerrit Code Review
2 changed files with 21 additions and 17 deletions

View File

@@ -526,15 +526,17 @@ public class NetworkStatsManager {
}
/**
* Registers a custom provider of {@link android.net.NetworkStats} to combine the network
* statistics that cannot be seen by the kernel to system. To unregister, invoke
* {@link NetworkStatsProviderCallback#unregister()}.
* Registers a custom provider of {@link android.net.NetworkStats} to provide network statistics
* to the system. To unregister, invoke {@link NetworkStatsProviderCallback#unregister()}.
* Note that no de-duplication of statistics between providers is performed, so each provider
* must only report network traffic that is not being reported by any other provider.
*
* @param tag a human readable identifier of the custom network stats provider.
* @param provider a custom implementation of {@link AbstractNetworkStatsProvider} that needs to
* be registered to the system.
* @param tag a human readable identifier of the custom network stats provider. This is only
* used for debugging.
* @param provider the subclass of {@link AbstractNetworkStatsProvider} that needs to be
* registered to the system.
* @return a {@link NetworkStatsProviderCallback}, which can be used to report events to the
* system.
* system or unregister the provider.
* @hide
*/
@SystemApi

View File

@@ -257,7 +257,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
private final Object mStatsLock = new Object();
private final Object mStatsProviderLock = new Object();
/** Set of currently active ifaces. */
@GuardedBy("mStatsLock")
@@ -1521,8 +1520,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
@Override
public void setStatsProviderLimit(@NonNull String iface, long quota) {
Slog.v(TAG, "setStatsProviderLimit(" + iface + "," + quota + ")");
public void setStatsProviderLimitAsync(@NonNull String iface, long quota) {
Slog.v(TAG, "setStatsProviderLimitAsync(" + iface + "," + quota + ")");
invokeForAllStatsProviderCallbacks((cb) -> cb.mProvider.setLimit(iface, quota));
}
}
@@ -1803,9 +1802,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
* {@code unregister()} of the returned callback.
*
* @param tag a human readable identifier of the custom network stats provider.
* @param provider the binder interface of
* {@link android.net.netstats.provider.AbstractNetworkStatsProvider} that
* needs to be registered to the system.
* @param provider the {@link INetworkStatsProvider} binder corresponding to the
* {@link android.net.netstats.provider.AbstractNetworkStatsProvider} to be
* registered.
*
* @return a binder interface of
* {@link android.net.netstats.provider.NetworkStatsProviderCallback}, which can be
@@ -1844,7 +1843,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private void invokeForAllStatsProviderCallbacks(
@NonNull ThrowingConsumer<NetworkStatsProviderCallbackImpl, RemoteException> task) {
synchronized (mStatsProviderCbList) {
synchronized (mStatsLock) {
final int length = mStatsProviderCbList.beginBroadcast();
try {
for (int i = 0; i < length; i++) {
@@ -1865,14 +1864,16 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private static class NetworkStatsProviderCallbackImpl extends INetworkStatsProviderCallback.Stub
implements IBinder.DeathRecipient {
@NonNull final String mTag;
@NonNull private final Object mProviderStatsLock = new Object();
@NonNull final INetworkStatsProvider mProvider;
@NonNull private final Semaphore mSemaphore;
@NonNull final INetworkManagementEventObserver mAlertObserver;
@NonNull final RemoteCallbackList<NetworkStatsProviderCallbackImpl> mStatsProviderCbList;
@NonNull private final Object mProviderStatsLock = new Object();
@GuardedBy("mProviderStatsLock")
// STATS_PER_IFACE and STATS_PER_UID
// Track STATS_PER_IFACE and STATS_PER_UID separately.
private final NetworkStats mIfaceStats = new NetworkStats(0L, 0);
@GuardedBy("mProviderStatsLock")
private final NetworkStats mUidStats = new NetworkStats(0L, 0);
@@ -1905,7 +1906,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
default:
throw new IllegalArgumentException("Invalid type: " + how);
}
// Return a defensive copy instead of local reference.
// Callers might be able to mutate the returned object. Return a defensive copy
// instead of local reference.
return stats.clone();
}
}