Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc9e4fbc authored by Junyu Lai's avatar Junyu Lai Committed by Gerrit Code Review
Browse files

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

parents 1e47a3e7 7d058ec6
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public abstract class NetworkPolicyManagerInternal {
            Set<String> packageNames, int userId);

    /**
     *  Notifies that any of the {@link AbstractNetworkStatsProvider} has reached its quota
     *  Notifies that the specified {@link AbstractNetworkStatsProvider} has reached its quota
     *  which was set through {@link AbstractNetworkStatsProvider#setLimit(String, long)}.
     *
     * @param tag the human readable identifier of the custom network stats provider.
+2 −2
Original line number Diff line number Diff line
@@ -4613,13 +4613,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                    final long quota = ((long) msg.arg1 << 32) | (msg.arg2 & 0xFFFFFFFFL);
                    removeInterfaceQuota(iface);
                    setInterfaceQuota(iface, quota);
                    mNetworkStats.setStatsProviderLimit(iface, quota);
                    mNetworkStats.setStatsProviderLimitAsync(iface, quota);
                    return true;
                }
                case MSG_REMOVE_INTERFACE_QUOTA: {
                    final String iface = (String) msg.obj;
                    removeInterfaceQuota(iface);
                    mNetworkStats.setStatsProviderLimit(iface, QUOTA_UNLIMITED);
                    mNetworkStats.setStatsProviderLimitAsync(iface, QUOTA_UNLIMITED);
                    return true;
                }
                case MSG_RESET_FIREWALL_RULES_BY_UID: {
+1 −1
Original line number Diff line number Diff line
@@ -40,5 +40,5 @@ public abstract class NetworkStatsManagerInternal {
     * Set the quota limit to all registered custom network stats providers.
     * Note that invocation of any interface will be sent to all providers.
     */
    public abstract void setStatsProviderLimit(@NonNull String iface, long quota);
    public abstract void setStatsProviderLimitAsync(@NonNull String iface, long quota);
}
+12 −10
Original line number Diff line number Diff line
@@ -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();
            }
        }
Loading