Merge "[DU04-2]Appropriate changes to the NetworkPolicyManager API" am: c48d90e91b

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2007132

Change-Id: I95ac7442751dca1f4e469edbe950b38aca6c720a
This commit is contained in:
Frank Li
2022-03-16 12:54:39 +00:00
committed by Automerger Merge Worker
5 changed files with 36 additions and 9 deletions

View File

@@ -219,7 +219,8 @@ package android.net {
method @Nullable @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public android.telephony.SubscriptionPlan getSubscriptionPlan(@NonNull android.net.NetworkTemplate);
method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public boolean isUidNetworkingBlocked(int, boolean);
method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public boolean isUidRestrictedOnMeteredNetworks(int);
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyStatsProviderWarningOrLimitReached();
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyStatsProviderLimitReached();
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public void notifyStatsProviderWarningReached();
method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public void registerNetworkPolicyCallback(@Nullable java.util.concurrent.Executor, @NonNull android.net.NetworkPolicyManager.NetworkPolicyCallback);
method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public void unregisterNetworkPolicyCallback(@NonNull android.net.NetworkPolicyManager.NetworkPolicyCallback);
}

View File

@@ -557,6 +557,24 @@ public class NetworkPolicyManager {
}
}
/**
* Notifies that the specified {@link NetworkStatsProvider} has reached its warning threshold
* which was set through {@link NetworkStatsProvider#onSetWarningAndLimit(String, long, long)}.
*
* @hide
*/
@RequiresPermission(anyOf = {
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
android.Manifest.permission.NETWORK_STACK})
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public void notifyStatsProviderWarningReached() {
try {
mService.notifyStatsProviderWarningOrLimitReached();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Notifies that the specified {@link NetworkStatsProvider} has reached its quota
* which was set through {@link NetworkStatsProvider#onSetLimit(String, long)} or
@@ -568,7 +586,7 @@ public class NetworkPolicyManager {
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
android.Manifest.permission.NETWORK_STACK})
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public void notifyStatsProviderWarningOrLimitReached() {
public void notifyStatsProviderLimitReached() {
try {
mService.notifyStatsProviderWarningOrLimitReached();
} catch (RemoteException e) {

View File

@@ -26,6 +26,7 @@ import android.net.NetworkStats;
oneway interface INetworkStatsProviderCallback {
void notifyStatsUpdated(int token, in NetworkStats ifaceStats, in NetworkStats uidStats);
void notifyAlertReached();
void notifyWarningOrLimitReached();
void notifyWarningReached();
void notifyLimitReached();
void unregister();
}

View File

@@ -152,19 +152,19 @@ public abstract class NetworkStatsProvider {
try {
// Reuse the code path to notify warning reached with limit reached
// since framework handles them in the same way.
getProviderCallbackBinderOrThrow().notifyWarningOrLimitReached();
getProviderCallbackBinderOrThrow().notifyWarningReached();
} catch (RemoteException e) {
e.rethrowAsRuntimeException();
}
}
/**
* Notify system that the quota set by {@link #onSetLimit} or limit set by
* Notify system that the limit set by {@link #onSetLimit} or limit set by
* {@link #onSetWarningAndLimit} has been reached.
*/
public void notifyLimitReached() {
try {
getProviderCallbackBinderOrThrow().notifyWarningOrLimitReached();
getProviderCallbackBinderOrThrow().notifyLimitReached();
} catch (RemoteException e) {
e.rethrowAsRuntimeException();
}

View File

@@ -2393,10 +2393,17 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
@Override
public void notifyWarningOrLimitReached() {
Log.d(TAG, mTag + ": notifyWarningOrLimitReached");
public void notifyWarningReached() {
Log.d(TAG, mTag + ": notifyWarningReached");
BinderUtils.withCleanCallingIdentity(() ->
mNetworkPolicyManager.notifyStatsProviderWarningOrLimitReached());
mNetworkPolicyManager.notifyStatsProviderWarningReached());
}
@Override
public void notifyLimitReached() {
Log.d(TAG, mTag + ": notifyLimitReached");
BinderUtils.withCleanCallingIdentity(() ->
mNetworkPolicyManager.notifyStatsProviderLimitReached());
}
@Override