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

Commit ea8f185b authored by junyulai's avatar junyulai Committed by Junyu Lai
Browse files

[SP21] Address comments for API council review about aosp/1172143

Test: atest FrameworksNetTests ImsPhoneCallTrackerTest
Test: atest TetheringTests NetworkStackTests
Test: m doc-comment-check-docs
Fix: 148552904

Change-Id: I141393f229e772d2eb9f7c156849e379bd71b845
Merged-In: I141393f229e772d2eb9f7c156849e379bd71b845
(cherry picked from aosp/1253717)
parent af8d85fa
Loading
Loading
Loading
Loading
+10 −13
Original line number Original line Diff line number Diff line
@@ -1411,7 +1411,8 @@ package android.app.usage {
  }
  }
  public class NetworkStatsManager {
  public class NetworkStatsManager {
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_STATS_PROVIDER, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public android.net.netstats.provider.NetworkStatsProviderCallback registerNetworkStatsProvider(@NonNull String, @NonNull android.net.netstats.provider.AbstractNetworkStatsProvider);
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_STATS_PROVIDER, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void registerNetworkStatsProvider(@NonNull String, @NonNull android.net.netstats.provider.NetworkStatsProvider);
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_STATS_PROVIDER, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void unregisterNetworkStatsProvider(@NonNull android.net.netstats.provider.NetworkStatsProvider);
  }
  }
  public static final class UsageEvents.Event {
  public static final class UsageEvents.Event {
@@ -6822,21 +6823,17 @@ package android.net.metrics {
package android.net.netstats.provider {
package android.net.netstats.provider {
  public abstract class AbstractNetworkStatsProvider {
  public abstract class NetworkStatsProvider {
    ctor public AbstractNetworkStatsProvider();
    ctor public NetworkStatsProvider();
    method public abstract void requestStatsUpdate(int);
    method public void notifyAlertReached();
    method public abstract void setAlert(long);
    method public void notifyLimitReached();
    method public abstract void setLimit(@NonNull String, long);
    method public void notifyStatsUpdated(int, @NonNull android.net.NetworkStats, @NonNull android.net.NetworkStats);
    method public abstract void onRequestStatsUpdate(int);
    method public abstract void onSetAlert(long);
    method public abstract void onSetLimit(@NonNull String, long);
    field public static final int QUOTA_UNLIMITED = -1; // 0xffffffff
    field public static final int QUOTA_UNLIMITED = -1; // 0xffffffff
  }
  }
  public class NetworkStatsProviderCallback {
    method public void onAlertReached();
    method public void onLimitReached();
    method public void onStatsUpdated(int, @NonNull android.net.NetworkStats, @NonNull android.net.NetworkStats);
    method public void unregister();
  }
}
}
package android.net.sip {
package android.net.sip {
+33 −15
Original line number Original line Diff line number Diff line
@@ -31,9 +31,8 @@ import android.net.INetworkStatsService;
import android.net.NetworkIdentity;
import android.net.NetworkIdentity;
import android.net.NetworkStack;
import android.net.NetworkStack;
import android.net.NetworkTemplate;
import android.net.NetworkTemplate;
import android.net.netstats.provider.AbstractNetworkStatsProvider;
import android.net.netstats.provider.INetworkStatsProviderCallback;
import android.net.netstats.provider.NetworkStatsProviderCallback;
import android.net.netstats.provider.NetworkStatsProvider;
import android.net.netstats.provider.NetworkStatsProviderWrapper;
import android.os.Binder;
import android.os.Binder;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
@@ -528,34 +527,53 @@ public class NetworkStatsManager {


    /**
    /**
     * Registers a custom provider of {@link android.net.NetworkStats} to provide network statistics
     * Registers a custom provider of {@link android.net.NetworkStats} to provide network statistics
     * to the system. To unregister, invoke {@link NetworkStatsProviderCallback#unregister()}.
     * to the system. To unregister, invoke {@link #unregisterNetworkStatsProvider}.
     * Note that no de-duplication of statistics between providers is performed, so each provider
     * 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.
     * must only report network traffic that is not being reported by any other provider. Also note
     * that the provider cannot be re-registered after unregistering.
     *
     *
     * @param tag a human readable identifier of the custom network stats provider. This is only
     * @param tag a human readable identifier of the custom network stats provider. This is only
     *            used for debugging.
     *            used for debugging.
     * @param provider the subclass of {@link AbstractNetworkStatsProvider} that needs to be
     * @param provider the subclass of {@link NetworkStatsProvider} that needs to be
     *                 registered to the system.
     *                 registered to the system.
     * @return a {@link NetworkStatsProviderCallback}, which can be used to report events to the
     *         system or unregister the provider.
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @RequiresPermission(anyOf = {
    @RequiresPermission(anyOf = {
            android.Manifest.permission.NETWORK_STATS_PROVIDER,
            android.Manifest.permission.NETWORK_STATS_PROVIDER,
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK})
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK})
    @NonNull public NetworkStatsProviderCallback registerNetworkStatsProvider(
    @NonNull public void registerNetworkStatsProvider(
            @NonNull String tag,
            @NonNull String tag,
            @NonNull AbstractNetworkStatsProvider provider) {
            @NonNull NetworkStatsProvider provider) {
        try {
        try {
            final NetworkStatsProviderWrapper wrapper = new NetworkStatsProviderWrapper(provider);
            if (provider.getProviderCallbackBinder() != null) {
            return new NetworkStatsProviderCallback(
                throw new IllegalArgumentException("provider is already registered");
                    mService.registerNetworkStatsProvider(tag, wrapper));
            }
            final INetworkStatsProviderCallback cbBinder =
                    mService.registerNetworkStatsProvider(tag, provider.getProviderBinder());
            provider.setProviderCallbackBinder(cbBinder);
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
    }

    /**
     * Unregisters an instance of {@link NetworkStatsProvider}.
     *
     * @param provider the subclass of {@link NetworkStatsProvider} that needs to be
     *                 unregistered to the system.
     * @hide
     */
    @SystemApi
    @RequiresPermission(anyOf = {
            android.Manifest.permission.NETWORK_STATS_PROVIDER,
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK})
    @NonNull public void unregisterNetworkStatsProvider(@NonNull NetworkStatsProvider provider) {
        try {
            provider.getProviderCallbackBinderOrThrow().unregister();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
            e.rethrowAsRuntimeException();
        }
        }
        // Unreachable code, but compiler doesn't know about it.
        return null;
    }
    }


    private static NetworkTemplate createTemplate(int networkType, String subscriberId) {
    private static NetworkTemplate createTemplate(int networkType, String subscriberId) {
+0 −70
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.netstats.provider;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.net.NetworkStats;

/**
 * A base class that allows external modules to implement a custom network statistics provider.
 * @hide
 */
@SystemApi
public abstract class AbstractNetworkStatsProvider {
    /**
     * A value used by {@link #setLimit} and {@link #setAlert} indicates there is no limit.
     */
    public static final int QUOTA_UNLIMITED = -1;

    /**
     * Called by {@code NetworkStatsService} when global polling is needed. Custom
     * implementation of providers MUST respond to it by calling
     * {@link NetworkStatsProviderCallback#onStatsUpdated} within one minute. Responding
     * later than this may cause the stats to be dropped.
     *
     * @param token a positive number identifying the new state of the system under which
     *              {@link NetworkStats} have to be gathered from now on. When this is called,
     *              custom implementations of providers MUST report the latest stats with the
     *              previous token, under which stats were being gathered so far.
     */
    public abstract void requestStatsUpdate(int token);

    /**
     * Called by {@code NetworkStatsService} when setting the interface quota for the specified
     * upstream interface. When this is called, the custom implementation should block all egress
     * packets on the {@code iface} associated with the provider when {@code quotaBytes} bytes have
     * been reached, and MUST respond to it by calling
     * {@link NetworkStatsProviderCallback#onLimitReached()}.
     *
     * @param iface the interface requiring the operation.
     * @param quotaBytes the quota defined as the number of bytes, starting from zero and counting
     *                   from now. A value of {@link #QUOTA_UNLIMITED} indicates there is no limit.
     */
    public abstract void setLimit(@NonNull String iface, long quotaBytes);

    /**
     * Called by {@code NetworkStatsService} when setting the alert bytes. Custom implementations
     * MUST call {@link NetworkStatsProviderCallback#onAlertReached()} when {@code quotaBytes} bytes
     * have been reached. Unlike {@link #setLimit(String, long)}, the custom implementation should
     * not block all egress packets.
     *
     * @param quotaBytes the quota defined as the number of bytes, starting from zero and counting
     *                   from now. A value of {@link #QUOTA_UNLIMITED} indicates there is no alert.
     */
    public abstract void setAlert(long quotaBytes);
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ package android.net.netstats.provider;
 * @hide
 * @hide
 */
 */
oneway interface INetworkStatsProvider {
oneway interface INetworkStatsProvider {
    void requestStatsUpdate(int token);
    void onRequestStatsUpdate(int token);
    void setLimit(String iface, long quotaBytes);
    void onSetLimit(String iface, long quotaBytes);
    void setAlert(long quotaBytes);
    void onSetAlert(long quotaBytes);
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -24,8 +24,8 @@ import android.net.NetworkStats;
 * @hide
 * @hide
 */
 */
oneway interface INetworkStatsProviderCallback {
oneway interface INetworkStatsProviderCallback {
    void onStatsUpdated(int token, in NetworkStats ifaceStats, in NetworkStats uidStats);
    void notifyStatsUpdated(int token, in NetworkStats ifaceStats, in NetworkStats uidStats);
    void onAlertReached();
    void notifyAlertReached();
    void onLimitReached();
    void notifyLimitReached();
    void unregister();
    void unregister();
}
}
Loading