Merge changes from topic "ms52-movenetstats"

* changes:
  Expose MATCH_PROXY as a module-lib API.
  Add setPollForce to module API
  Move networkstats JNI to connectivity module
  [MS54.1] Move NetworkStats to updatable sources
  [MS62.1] Start NetworkStatsService from the module
This commit is contained in:
Lorenzo Colitti
2022-02-28 05:32:23 +00:00
committed by Gerrit Code Review
15 changed files with 100 additions and 45 deletions

View File

@@ -27,7 +27,6 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.WorkerThread;
import android.app.usage.NetworkStats.Bucket;
import android.compat.annotation.UnsupportedAppUsage;
@@ -192,9 +191,13 @@ public class NetworkStatsManager {
}
}
/** @hide */
/**
* Set poll force flag to indicate that calling any subsequent query method will force a stats
* poll.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@TestApi
@SystemApi(client = MODULE_LIBRARIES)
public void setPollForce(boolean pollForce) {
if (pollForce) {
mFlags |= FLAG_POLL_FORCE;

View File

@@ -18,6 +18,7 @@ package android.net;
import android.annotation.SystemApi;
import android.app.SystemServiceRegistry;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.net.nsd.INsdManager;
import android.net.nsd.NsdManager;
@@ -57,5 +58,15 @@ public final class ConnectivityFrameworkInitializerTiramisu {
return new IpSecManager(context, service);
}
);
SystemServiceRegistry.registerContextAwareService(
Context.NETWORK_STATS_SERVICE,
NetworkStatsManager.class,
(context, serviceBinder) -> {
INetworkStatsService service =
INetworkStatsService.Stub.asInterface(serviceBinder);
return new NetworkStatsManager(context, service);
}
);
}
}

View File

@@ -184,14 +184,14 @@ public class NetworkIdentity {
public void dumpDebug(ProtoOutputStream proto, long tag) {
final long start = proto.start(tag);
proto.write(NetworkIdentityProto.TYPE, mType);
proto.write(NetworkIdentityProto.TYPE_FIELD_NUMBER, mType);
// TODO: dump mRatType as well.
proto.write(NetworkIdentityProto.ROAMING, mRoaming);
proto.write(NetworkIdentityProto.METERED, mMetered);
proto.write(NetworkIdentityProto.DEFAULT_NETWORK, mDefaultNetwork);
proto.write(NetworkIdentityProto.OEM_MANAGED_NETWORK, mOemManaged);
proto.write(NetworkIdentityProto.ROAMING_FIELD_NUMBER, mRoaming);
proto.write(NetworkIdentityProto.METERED_FIELD_NUMBER, mMetered);
proto.write(NetworkIdentityProto.DEFAULT_NETWORK_FIELD_NUMBER, mDefaultNetwork);
proto.write(NetworkIdentityProto.OEM_MANAGED_NETWORK_FIELD_NUMBER, mOemManaged);
proto.end(start);
}

View File

@@ -212,7 +212,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
final long start = proto.start(tag);
for (NetworkIdentity ident : this) {
ident.dumpDebug(proto, NetworkIdentitySetProto.IDENTITIES);
ident.dumpDebug(proto, NetworkIdentitySetProto.IDENTITIES_FIELD_NUMBER);
}
proto.end(start);

View File

@@ -732,19 +732,19 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
final long start = proto.start(tag);
for (Key key : getSortedKeys()) {
final long startStats = proto.start(NetworkStatsCollectionProto.STATS);
final long startStats = proto.start(NetworkStatsCollectionProto.STATS_FIELD_NUMBER);
// Key
final long startKey = proto.start(NetworkStatsCollectionStatsProto.KEY);
key.ident.dumpDebug(proto, NetworkStatsCollectionKeyProto.IDENTITY);
proto.write(NetworkStatsCollectionKeyProto.UID, key.uid);
proto.write(NetworkStatsCollectionKeyProto.SET, key.set);
proto.write(NetworkStatsCollectionKeyProto.TAG, key.tag);
final long startKey = proto.start(NetworkStatsCollectionStatsProto.KEY_FIELD_NUMBER);
key.ident.dumpDebug(proto, NetworkStatsCollectionKeyProto.IDENTITY_FIELD_NUMBER);
proto.write(NetworkStatsCollectionKeyProto.UID_FIELD_NUMBER, key.uid);
proto.write(NetworkStatsCollectionKeyProto.SET_FIELD_NUMBER, key.set);
proto.write(NetworkStatsCollectionKeyProto.TAG_FIELD_NUMBER, key.tag);
proto.end(startKey);
// Value
final NetworkStatsHistory history = mStats.get(key);
history.dumpDebug(proto, NetworkStatsCollectionStatsProto.HISTORY);
history.dumpDebug(proto, NetworkStatsCollectionStatsProto.HISTORY_FIELD_NUMBER);
proto.end(startStats);
}

View File

@@ -915,17 +915,18 @@ public final class NetworkStatsHistory implements Parcelable {
public void dumpDebug(ProtoOutputStream proto, long tag) {
final long start = proto.start(tag);
proto.write(NetworkStatsHistoryProto.BUCKET_DURATION_MS, bucketDuration);
proto.write(NetworkStatsHistoryProto.BUCKET_DURATION_MS_FIELD_NUMBER, bucketDuration);
for (int i = 0; i < bucketCount; i++) {
final long startBucket = proto.start(NetworkStatsHistoryProto.BUCKETS);
final long startBucket = proto.start(NetworkStatsHistoryProto.BUCKETS_FIELD_NUMBER);
proto.write(NetworkStatsHistoryBucketProto.BUCKET_START_MS, bucketStart[i]);
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_BYTES, rxBytes, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_PACKETS, rxPackets, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_BYTES, txBytes, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_PACKETS, txPackets, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.OPERATIONS, operations, i);
proto.write(NetworkStatsHistoryBucketProto.BUCKET_START_MS_FIELD_NUMBER,
bucketStart[i]);
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_BYTES_FIELD_NUMBER, rxBytes, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_PACKETS_FIELD_NUMBER, rxPackets, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_BYTES_FIELD_NUMBER, txBytes, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_PACKETS_FIELD_NUMBER, txPackets, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.OPERATIONS_FIELD_NUMBER, operations, i);
proto.end(startBucket);
}

View File

@@ -79,7 +79,8 @@ public final class NetworkTemplate implements Parcelable {
MATCH_WIFI,
MATCH_ETHERNET,
MATCH_BLUETOOTH,
MATCH_CARRIER
MATCH_PROXY,
MATCH_CARRIER,
})
public @interface TemplateMatchRule{}
@@ -104,9 +105,8 @@ public final class NetworkTemplate implements Parcelable {
/** Match rule to match bluetooth networks. */
public static final int MATCH_BLUETOOTH = 8;
/**
* Match rule to match networks with {@link Connectivity#TYPE_PROXY} as the legacy network type.
*
* @hide
* Match rule to match networks with {@link ConnectivityManager#TYPE_PROXY} as the legacy
* network type.
*/
public static final int MATCH_PROXY = 9;
/**