Merge changes If51b6676,Ia6863a70,I802d2316 am: ada2a7fb3a am: 5c31d240c8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1936181 Change-Id: Ibb4cfb5be191efe6e6e821eb17d905fb96b02ebb
This commit is contained in:
@@ -142,7 +142,15 @@ public class NetworkStatsManager {
|
||||
setAugmentWithSubscriptionPlan(true);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
/**
|
||||
* Set poll on open flag to indicate the poll is needed before service gets statistics
|
||||
* result. This is default enabled. However, for any non-privileged caller, the poll might
|
||||
* be omitted in case of rate limiting.
|
||||
*
|
||||
* @param pollOnOpen true if poll is needed.
|
||||
* @hide
|
||||
*/
|
||||
// @SystemApi(client = MODULE_LIBRARIES)
|
||||
public void setPollOnOpen(boolean pollOnOpen) {
|
||||
if (pollOnOpen) {
|
||||
mFlags |= FLAG_POLL_ON_OPEN;
|
||||
@@ -863,4 +871,74 @@ public class NetworkStatsManager {
|
||||
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 */
|
||||
INetworkStatsProviderCallback registerNetworkStatsProvider(String tag,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -431,7 +431,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
new DefaultNetworkStatsSettings(context), new NetworkStatsFactory(netd),
|
||||
new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir(),
|
||||
new Dependencies());
|
||||
service.registerLocalService();
|
||||
|
||||
return service;
|
||||
}
|
||||
@@ -512,11 +511,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerLocalService() {
|
||||
LocalServices.addService(NetworkStatsManagerInternal.class,
|
||||
new NetworkStatsManagerInternalImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Observer that watches for {@link INetdUnsolicitedEventListener} alerts.
|
||||
*/
|
||||
@@ -1007,7 +1001,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setUidForeground(int uid, boolean uidForeground) {
|
||||
public void setUidForeground(int uid, boolean uidForeground) {
|
||||
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||
synchronized (mStatsLock) {
|
||||
final int set = uidForeground ? SET_FOREGROUND : SET_DEFAULT;
|
||||
final int oldSet = mActiveUidCounterSet.get(uid, SET_DEFAULT);
|
||||
@@ -1043,7 +1038,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
|
||||
@Override
|
||||
public void forceUpdate() {
|
||||
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
|
||||
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -1053,7 +1048,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
|
||||
mPersistThreshold = NetworkStatsUtils.constrain(thresholdBytes,
|
||||
128 * KB_IN_BYTES, 2 * MB_IN_BYTES);
|
||||
@@ -1690,52 +1687,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
removeUidsLocked(CollectionUtils.toIntArray(uids));
|
||||
}
|
||||
|
||||
private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal {
|
||||
@Override
|
||||
public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) {
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkTotalBytes");
|
||||
try {
|
||||
return NetworkStatsService.this.getNetworkTotalBytes(template, start, end);
|
||||
} finally {
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) {
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkUidBytes");
|
||||
try {
|
||||
return NetworkStatsService.this.getNetworkUidBytes(template, start, end);
|
||||
} finally {
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUidForeground(int uid, boolean uidForeground) {
|
||||
NetworkStatsService.this.setUidForeground(uid, uidForeground);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void advisePersistThreshold(long thresholdBytes) {
|
||||
NetworkStatsService.this.advisePersistThreshold(thresholdBytes);
|
||||
}
|
||||
|
||||
@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));
|
||||
/**
|
||||
* Set the warning and limit to all registered custom network stats providers.
|
||||
* Note that invocation of any interface will be sent to all providers.
|
||||
*/
|
||||
public void setStatsProviderWarningAndLimitAsync(
|
||||
@NonNull String iface, long warning, long limit) {
|
||||
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||
if (LOGV) {
|
||||
Log.v(TAG, "setStatsProviderWarningAndLimitAsync("
|
||||
+ iface + "," + warning + "," + limit + ")");
|
||||
}
|
||||
invokeForAllStatsProviderCallbacks((cb) -> cb.mProvider.onSetWarningAndLimit(iface,
|
||||
warning, limit));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user