[MS37] Replace NetworkStatsManagerInternal usages in NPMS
This is done by: 1. Add NetworkStatsManagerInternal APIs directly from NetworkStatsManager, these APIs are needed by NPMS. 2. Replace all usages with these APIs. 3. Delete NetworkStatsManagerInternal implementation. Test: atest FrameworksNetTests NetworkPolicyManagerServiceTest Bug: 204830222 CTS-Coverage-Bug: 213124616 Change-Id: If51b6676915e3a0a8a9f95221d735306911442fc
This commit is contained in:
@@ -871,4 +871,74 @@ public class NetworkStatsManager {
|
|||||||
return msg.getData().getParcelable(key);
|
return msg.getData().getParcelable(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark given UID as being in foreground for stats purposes.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
// @SystemApi
|
||||||
|
@RequiresPermission(anyOf = {
|
||||||
|
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
|
||||||
|
android.Manifest.permission.NETWORK_STACK})
|
||||||
|
public void setUidForeground(int uid, boolean uidForeground) {
|
||||||
|
try {
|
||||||
|
mService.setUidForeground(uid, uidForeground);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Advise persistence threshold; may be overridden internally.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
// @SystemApi
|
||||||
|
@RequiresPermission(anyOf = {
|
||||||
|
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
|
||||||
|
android.Manifest.permission.NETWORK_STACK})
|
||||||
|
public void advisePersistThreshold(long thresholdBytes) {
|
||||||
|
try {
|
||||||
|
mService.advisePersistThreshold(thresholdBytes);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force update of statistics.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
// @SystemApi
|
||||||
|
@RequiresPermission(anyOf = {
|
||||||
|
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
|
||||||
|
android.Manifest.permission.NETWORK_STACK})
|
||||||
|
public void forceUpdate() {
|
||||||
|
try {
|
||||||
|
mService.forceUpdate();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the warning and limit to all registered custom network stats providers.
|
||||||
|
* Note that invocation of any interface will be sent to all providers.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
// @SystemApi
|
||||||
|
@RequiresPermission(anyOf = {
|
||||||
|
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
|
||||||
|
android.Manifest.permission.NETWORK_STACK})
|
||||||
|
public void setStatsProviderWarningAndLimitAsync(@NonNull String iface, long warning,
|
||||||
|
long limit) {
|
||||||
|
try {
|
||||||
|
mService.setStatsProviderWarningAndLimitAsync(iface, warning, limit);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,4 +94,16 @@ interface INetworkStatsService {
|
|||||||
/** Registers a network stats provider */
|
/** Registers a network stats provider */
|
||||||
INetworkStatsProviderCallback registerNetworkStatsProvider(String tag,
|
INetworkStatsProviderCallback registerNetworkStatsProvider(String tag,
|
||||||
in INetworkStatsProvider provider);
|
in INetworkStatsProvider provider);
|
||||||
|
|
||||||
|
/** Mark given UID as being in foreground for stats purposes. */
|
||||||
|
void setUidForeground(int uid, boolean uidForeground);
|
||||||
|
|
||||||
|
/** Advise persistence threshold; may be overridden internally. */
|
||||||
|
void advisePersistThreshold(long thresholdBytes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the warning and limit to all registered custom network stats providers.
|
||||||
|
* Note that invocation of any interface will be sent to all providers.
|
||||||
|
*/
|
||||||
|
void setStatsProviderWarningAndLimitAsync(String iface, long warning, long limit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,7 +430,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
new DefaultNetworkStatsSettings(context), new NetworkStatsFactory(netd),
|
new DefaultNetworkStatsSettings(context), new NetworkStatsFactory(netd),
|
||||||
new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir(),
|
new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir(),
|
||||||
new Dependencies());
|
new Dependencies());
|
||||||
service.registerLocalService();
|
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
@@ -511,11 +510,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerLocalService() {
|
|
||||||
LocalServices.addService(NetworkStatsManagerInternal.class,
|
|
||||||
new NetworkStatsManagerInternalImpl());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observer that watches for {@link INetdUnsolicitedEventListener} alerts.
|
* Observer that watches for {@link INetdUnsolicitedEventListener} alerts.
|
||||||
*/
|
*/
|
||||||
@@ -1006,7 +1000,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setUidForeground(int uid, boolean uidForeground) {
|
public void setUidForeground(int uid, boolean uidForeground) {
|
||||||
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
synchronized (mStatsLock) {
|
synchronized (mStatsLock) {
|
||||||
final int set = uidForeground ? SET_FOREGROUND : SET_DEFAULT;
|
final int set = uidForeground ? SET_FOREGROUND : SET_DEFAULT;
|
||||||
final int oldSet = mActiveUidCounterSet.get(uid, SET_DEFAULT);
|
final int oldSet = mActiveUidCounterSet.get(uid, SET_DEFAULT);
|
||||||
@@ -1042,7 +1037,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forceUpdate() {
|
public void forceUpdate() {
|
||||||
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -1052,7 +1047,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void advisePersistThreshold(long thresholdBytes) {
|
/** Advise persistence threshold; may be overridden internally. */
|
||||||
|
public void advisePersistThreshold(long thresholdBytes) {
|
||||||
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
// clamp threshold into safe range
|
// clamp threshold into safe range
|
||||||
mPersistThreshold = NetworkStatsUtils.constrain(thresholdBytes,
|
mPersistThreshold = NetworkStatsUtils.constrain(thresholdBytes,
|
||||||
128 * KB_IN_BYTES, 2 * MB_IN_BYTES);
|
128 * KB_IN_BYTES, 2 * MB_IN_BYTES);
|
||||||
@@ -1689,32 +1686,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
removeUidsLocked(CollectionUtils.toIntArray(uids));
|
removeUidsLocked(CollectionUtils.toIntArray(uids));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal {
|
/**
|
||||||
@Override
|
* Set the warning and limit to all registered custom network stats providers.
|
||||||
public void setUidForeground(int uid, boolean uidForeground) {
|
* Note that invocation of any interface will be sent to all providers.
|
||||||
NetworkStatsService.this.setUidForeground(uid, uidForeground);
|
*/
|
||||||
}
|
public void setStatsProviderWarningAndLimitAsync(
|
||||||
|
@NonNull String iface, long warning, long limit) {
|
||||||
@Override
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
public void advisePersistThreshold(long thresholdBytes) {
|
if (LOGV) {
|
||||||
NetworkStatsService.this.advisePersistThreshold(thresholdBytes);
|
Log.v(TAG, "setStatsProviderWarningAndLimitAsync("
|
||||||
}
|
+ iface + "," + warning + "," + limit + ")");
|
||||||
|
|
||||||
@Override
|
|
||||||
public void forceUpdate() {
|
|
||||||
NetworkStatsService.this.forceUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setStatsProviderWarningAndLimitAsync(
|
|
||||||
@NonNull String iface, long warning, long limit) {
|
|
||||||
if (LOGV) {
|
|
||||||
Log.v(TAG, "setStatsProviderWarningAndLimitAsync("
|
|
||||||
+ iface + "," + warning + "," + limit + ")");
|
|
||||||
}
|
|
||||||
invokeForAllStatsProviderCallbacks((cb) -> cb.mProvider.onSetWarningAndLimit(iface,
|
|
||||||
warning, limit));
|
|
||||||
}
|
}
|
||||||
|
invokeForAllStatsProviderCallbacks((cb) -> cb.mProvider.onSetWarningAndLimit(iface,
|
||||||
|
warning, limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user