Loading core/java/android/net/netstats/provider/INetworkStatsProvider.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,6 @@ package android.net.netstats.provider; */ oneway interface INetworkStatsProvider { void onRequestStatsUpdate(int token); void onSetLimit(String iface, long quotaBytes); void onSetAlert(long quotaBytes); void onSetWarningAndLimit(String iface, long warningBytes, long limitBytes); } core/java/android/net/netstats/provider/INetworkStatsProviderCallback.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,6 @@ import android.net.NetworkStats; oneway interface INetworkStatsProviderCallback { void notifyStatsUpdated(int token, in NetworkStats ifaceStats, in NetworkStats uidStats); void notifyAlertReached(); void notifyLimitReached(); void notifyWarningOrLimitReached(); void unregister(); } core/java/android/net/netstats/provider/NetworkStatsProvider.java +51 −7 Original line number Diff line number Diff line Loading @@ -29,7 +29,8 @@ import android.os.RemoteException; @SystemApi public abstract class NetworkStatsProvider { /** * A value used by {@link #onSetLimit} and {@link #onSetAlert} indicates there is no limit. * A value used by {@link #onSetLimit}, {@link #onSetAlert} and {@link #onSetWarningAndLimit} * indicates there is no limit. */ public static final int QUOTA_UNLIMITED = -1; Loading @@ -42,13 +43,13 @@ public abstract class NetworkStatsProvider { } @Override public void onSetLimit(String iface, long quotaBytes) { NetworkStatsProvider.this.onSetLimit(iface, quotaBytes); public void onSetAlert(long quotaBytes) { NetworkStatsProvider.this.onSetAlert(quotaBytes); } @Override public void onSetAlert(long quotaBytes) { NetworkStatsProvider.this.onSetAlert(quotaBytes); public void onSetWarningAndLimit(String iface, long warningBytes, long limitBytes) { NetworkStatsProvider.this.onSetWarningAndLimit(iface, warningBytes, limitBytes); } }; Loading Loading @@ -145,11 +146,28 @@ public abstract class NetworkStatsProvider { } /** * Notify system that the quota set by {@code onSetLimit} has been reached. * Notify system that the warning set by {@link #onSetWarningAndLimit} has been reached. * * @hide */ // TODO: Expose as system API. public void notifyWarningReached() { try { // Reuse the code path to notify warning reached with limit reached // since framework handles them in the same way. getProviderCallbackBinderOrThrow().notifyWarningOrLimitReached(); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } } /** * Notify system that the quota set by {@link #onSetLimit} or limit set by * {@link #onSetWarningAndLimit} has been reached. */ public void notifyLimitReached() { try { getProviderCallbackBinderOrThrow().notifyLimitReached(); getProviderCallbackBinderOrThrow().notifyWarningOrLimitReached(); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } Loading Loading @@ -180,8 +198,34 @@ public abstract class NetworkStatsProvider { * @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. */ // TODO: deprecate this once onSetWarningAndLimit is ready. public abstract void onSetLimit(@NonNull String iface, long quotaBytes); /** * Called by {@code NetworkStatsService} when setting the interface quotas for the specified * upstream interface. If a provider implements {@link #onSetWarningAndLimit}, the system * will not call {@link #onSetLimit}. When this method is called, the implementation * should behave as follows: * 1. If {@code warningBytes} is reached on {@code iface}, block all further traffic on * {@code iface} and call {@link NetworkStatsProvider@notifyWarningReached()}. * 2. If {@code limitBytes} is reached on {@code iface}, block all further traffic on * {@code iface} and call {@link NetworkStatsProvider#notifyLimitReached()}. * * @param iface the interface requiring the operation. * @param warningBytes the warning defined as the number of bytes, starting from zero and * counting from now. A value of {@link #QUOTA_UNLIMITED} indicates * there is no warning. * @param limitBytes the limit defined as the number of bytes, starting from zero and counting * from now. A value of {@link #QUOTA_UNLIMITED} indicates there is no limit. * * @hide */ // TODO: Expose as system API. public void onSetWarningAndLimit(@NonNull String iface, long warningBytes, long limitBytes) { // Backward compatibility for those who didn't override this function. onSetLimit(iface, limitBytes); } /** * Called by {@code NetworkStatsService} when setting the alert bytes. Custom implementations * MUST call {@link NetworkStatsProvider#notifyAlertReached()} when {@code quotaBytes} bytes Loading services/core/java/com/android/server/net/NetworkPolicyManagerInternal.java +3 −2 Original line number Diff line number Diff line Loading @@ -96,9 +96,10 @@ public abstract class NetworkPolicyManagerInternal { /** * Notifies that the specified {@link NetworkStatsProvider} has reached its quota * which was set through {@link NetworkStatsProvider#onSetLimit(String, long)}. * which was set through {@link NetworkStatsProvider#onSetLimit(String, long)} or * {@link NetworkStatsProvider#onSetWarningAndLimit(String, long, long)}. * * @param tag the human readable identifier of the custom network stats provider. */ public abstract void onStatsProviderLimitReached(@NonNull String tag); public abstract void onStatsProviderWarningOrLimitReached(@NonNull String tag); } services/core/java/com/android/server/net/NetworkPolicyManagerService.java +5 −5 Original line number Diff line number Diff line Loading @@ -430,7 +430,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private static final int MSG_METERED_RESTRICTED_PACKAGES_CHANGED = 17; private static final int MSG_SET_NETWORK_TEMPLATE_ENABLED = 18; private static final int MSG_SUBSCRIPTION_PLANS_CHANGED = 19; private static final int MSG_STATS_PROVIDER_LIMIT_REACHED = 20; private static final int MSG_STATS_PROVIDER_WARNING_OR_LIMIT_REACHED = 20; // TODO: Add similar docs for other messages. /** * Message to indicate that reasons for why an uid is blocked changed. Loading Loading @@ -4970,7 +4970,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { mListeners.finishBroadcast(); return true; } case MSG_STATS_PROVIDER_LIMIT_REACHED: { case MSG_STATS_PROVIDER_WARNING_OR_LIMIT_REACHED: { mNetworkStats.forceUpdate(); synchronized (mNetworkPoliciesSecondLock) { Loading Loading @@ -5726,9 +5726,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } @Override public void onStatsProviderLimitReached(@NonNull String tag) { Log.v(TAG, "onStatsProviderLimitReached: " + tag); mHandler.obtainMessage(MSG_STATS_PROVIDER_LIMIT_REACHED).sendToTarget(); public void onStatsProviderWarningOrLimitReached(@NonNull String tag) { Log.v(TAG, "onStatsProviderWarningOrLimitReached: " + tag); mHandler.obtainMessage(MSG_STATS_PROVIDER_WARNING_OR_LIMIT_REACHED).sendToTarget(); } } Loading Loading
core/java/android/net/netstats/provider/INetworkStatsProvider.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,6 @@ package android.net.netstats.provider; */ oneway interface INetworkStatsProvider { void onRequestStatsUpdate(int token); void onSetLimit(String iface, long quotaBytes); void onSetAlert(long quotaBytes); void onSetWarningAndLimit(String iface, long warningBytes, long limitBytes); }
core/java/android/net/netstats/provider/INetworkStatsProviderCallback.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,6 @@ import android.net.NetworkStats; oneway interface INetworkStatsProviderCallback { void notifyStatsUpdated(int token, in NetworkStats ifaceStats, in NetworkStats uidStats); void notifyAlertReached(); void notifyLimitReached(); void notifyWarningOrLimitReached(); void unregister(); }
core/java/android/net/netstats/provider/NetworkStatsProvider.java +51 −7 Original line number Diff line number Diff line Loading @@ -29,7 +29,8 @@ import android.os.RemoteException; @SystemApi public abstract class NetworkStatsProvider { /** * A value used by {@link #onSetLimit} and {@link #onSetAlert} indicates there is no limit. * A value used by {@link #onSetLimit}, {@link #onSetAlert} and {@link #onSetWarningAndLimit} * indicates there is no limit. */ public static final int QUOTA_UNLIMITED = -1; Loading @@ -42,13 +43,13 @@ public abstract class NetworkStatsProvider { } @Override public void onSetLimit(String iface, long quotaBytes) { NetworkStatsProvider.this.onSetLimit(iface, quotaBytes); public void onSetAlert(long quotaBytes) { NetworkStatsProvider.this.onSetAlert(quotaBytes); } @Override public void onSetAlert(long quotaBytes) { NetworkStatsProvider.this.onSetAlert(quotaBytes); public void onSetWarningAndLimit(String iface, long warningBytes, long limitBytes) { NetworkStatsProvider.this.onSetWarningAndLimit(iface, warningBytes, limitBytes); } }; Loading Loading @@ -145,11 +146,28 @@ public abstract class NetworkStatsProvider { } /** * Notify system that the quota set by {@code onSetLimit} has been reached. * Notify system that the warning set by {@link #onSetWarningAndLimit} has been reached. * * @hide */ // TODO: Expose as system API. public void notifyWarningReached() { try { // Reuse the code path to notify warning reached with limit reached // since framework handles them in the same way. getProviderCallbackBinderOrThrow().notifyWarningOrLimitReached(); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } } /** * Notify system that the quota set by {@link #onSetLimit} or limit set by * {@link #onSetWarningAndLimit} has been reached. */ public void notifyLimitReached() { try { getProviderCallbackBinderOrThrow().notifyLimitReached(); getProviderCallbackBinderOrThrow().notifyWarningOrLimitReached(); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } Loading Loading @@ -180,8 +198,34 @@ public abstract class NetworkStatsProvider { * @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. */ // TODO: deprecate this once onSetWarningAndLimit is ready. public abstract void onSetLimit(@NonNull String iface, long quotaBytes); /** * Called by {@code NetworkStatsService} when setting the interface quotas for the specified * upstream interface. If a provider implements {@link #onSetWarningAndLimit}, the system * will not call {@link #onSetLimit}. When this method is called, the implementation * should behave as follows: * 1. If {@code warningBytes} is reached on {@code iface}, block all further traffic on * {@code iface} and call {@link NetworkStatsProvider@notifyWarningReached()}. * 2. If {@code limitBytes} is reached on {@code iface}, block all further traffic on * {@code iface} and call {@link NetworkStatsProvider#notifyLimitReached()}. * * @param iface the interface requiring the operation. * @param warningBytes the warning defined as the number of bytes, starting from zero and * counting from now. A value of {@link #QUOTA_UNLIMITED} indicates * there is no warning. * @param limitBytes the limit defined as the number of bytes, starting from zero and counting * from now. A value of {@link #QUOTA_UNLIMITED} indicates there is no limit. * * @hide */ // TODO: Expose as system API. public void onSetWarningAndLimit(@NonNull String iface, long warningBytes, long limitBytes) { // Backward compatibility for those who didn't override this function. onSetLimit(iface, limitBytes); } /** * Called by {@code NetworkStatsService} when setting the alert bytes. Custom implementations * MUST call {@link NetworkStatsProvider#notifyAlertReached()} when {@code quotaBytes} bytes Loading
services/core/java/com/android/server/net/NetworkPolicyManagerInternal.java +3 −2 Original line number Diff line number Diff line Loading @@ -96,9 +96,10 @@ public abstract class NetworkPolicyManagerInternal { /** * Notifies that the specified {@link NetworkStatsProvider} has reached its quota * which was set through {@link NetworkStatsProvider#onSetLimit(String, long)}. * which was set through {@link NetworkStatsProvider#onSetLimit(String, long)} or * {@link NetworkStatsProvider#onSetWarningAndLimit(String, long, long)}. * * @param tag the human readable identifier of the custom network stats provider. */ public abstract void onStatsProviderLimitReached(@NonNull String tag); public abstract void onStatsProviderWarningOrLimitReached(@NonNull String tag); }
services/core/java/com/android/server/net/NetworkPolicyManagerService.java +5 −5 Original line number Diff line number Diff line Loading @@ -430,7 +430,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private static final int MSG_METERED_RESTRICTED_PACKAGES_CHANGED = 17; private static final int MSG_SET_NETWORK_TEMPLATE_ENABLED = 18; private static final int MSG_SUBSCRIPTION_PLANS_CHANGED = 19; private static final int MSG_STATS_PROVIDER_LIMIT_REACHED = 20; private static final int MSG_STATS_PROVIDER_WARNING_OR_LIMIT_REACHED = 20; // TODO: Add similar docs for other messages. /** * Message to indicate that reasons for why an uid is blocked changed. Loading Loading @@ -4970,7 +4970,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { mListeners.finishBroadcast(); return true; } case MSG_STATS_PROVIDER_LIMIT_REACHED: { case MSG_STATS_PROVIDER_WARNING_OR_LIMIT_REACHED: { mNetworkStats.forceUpdate(); synchronized (mNetworkPoliciesSecondLock) { Loading Loading @@ -5726,9 +5726,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } @Override public void onStatsProviderLimitReached(@NonNull String tag) { Log.v(TAG, "onStatsProviderLimitReached: " + tag); mHandler.obtainMessage(MSG_STATS_PROVIDER_LIMIT_REACHED).sendToTarget(); public void onStatsProviderWarningOrLimitReached(@NonNull String tag) { Log.v(TAG, "onStatsProviderWarningOrLimitReached: " + tag); mHandler.obtainMessage(MSG_STATS_PROVIDER_WARNING_OR_LIMIT_REACHED).sendToTarget(); } } Loading