summaryrefslogtreecommitdiff
path: root/framework-t/src
diff options
context:
space:
mode:
authorJunyu Lai <junyulai@google.com>2022-01-07 11:28:54 +0000
committerJunyu Lai <junyulai@google.com>2022-01-13 01:01:46 +0000
commitf577b2248b32e1ed0bdd2aa9c910fdddf7bb10df (patch)
tree06887c5e82644ee6cf9dfcea1e2f6b9cb5f79d9f /framework-t/src
parente6490468111cb2d2b2be74cd8a83589ad9c4b2f2 (diff)
[MS44.1] Add API to query tagged UID summary
Query tagged UID summary is currently needed by StatsPullAtomService to collect tagged traffic statistics. Add an Api via NetworkStatsManager to support this functionality. Test: atest NetworkStatsManagerTest Bug: 204830222 Change-Id: Iaa54482a8109b56e66e829c5bec5a8a8f466641a
Diffstat (limited to 'framework-t/src')
-rw-r--r--framework-t/src/android/app/usage/NetworkStats.java9
-rw-r--r--framework-t/src/android/app/usage/NetworkStatsManager.java35
-rw-r--r--framework-t/src/android/net/INetworkStatsSession.aidl4
3 files changed, 47 insertions, 1 deletions
diff --git a/framework-t/src/android/app/usage/NetworkStats.java b/framework-t/src/android/app/usage/NetworkStats.java
index f684a4d9d8..d33666d744 100644
--- a/framework-t/src/android/app/usage/NetworkStats.java
+++ b/framework-t/src/android/app/usage/NetworkStats.java
@@ -545,6 +545,15 @@ public final class NetworkStats implements AutoCloseable {
}
/**
+ * Collects tagged summary results and sets summary enumeration mode.
+ * @throws RemoteException
+ */
+ void startTaggedSummaryEnumeration() throws RemoteException {
+ mSummary = mSession.getTaggedSummaryForAllUid(mTemplate, mStartTimeStamp, mEndTimeStamp);
+ mEnumerationIndex = 0;
+ }
+
+ /**
* Collects history results for uid and resets history enumeration index.
*/
void startHistoryEnumeration(int uid, int tag, int state) {
diff --git a/framework-t/src/android/app/usage/NetworkStatsManager.java b/framework-t/src/android/app/usage/NetworkStatsManager.java
index a316b8a617..8043a374bd 100644
--- a/framework-t/src/android/app/usage/NetworkStatsManager.java
+++ b/framework-t/src/android/app/usage/NetworkStatsManager.java
@@ -368,7 +368,7 @@ public class NetworkStatsManager {
* @return Statistics which is described above.
* @hide
*/
- @Nullable
+ @NonNull
// @SystemApi(client = MODULE_LIBRARIES)
@WorkerThread
public NetworkStats querySummary(@NonNull NetworkTemplate template, long startTime,
@@ -385,6 +385,39 @@ public class NetworkStatsManager {
}
/**
+ * Query tagged network usage statistics summaries.
+ *
+ * The results will only include tagged traffic made by UIDs belonging to the calling user
+ * profile. The results are aggregated over time, so that all buckets will have the same
+ * start and end timestamps as the passed arguments. Not aggregated over state, uid,
+ * default network, metered, or roaming.
+ * This may take a long time, and apps should avoid calling this on their main thread.
+ *
+ * @param template Template used to match networks. See {@link NetworkTemplate}.
+ * @param startTime Start of period, in milliseconds since the Unix epoch, see
+ * {@link System#currentTimeMillis}.
+ * @param endTime End of period, in milliseconds since the Unix epoch, see
+ * {@link System#currentTimeMillis}.
+ * @return Statistics which is described above.
+ * @hide
+ */
+ @NonNull
+ // @SystemApi(client = MODULE_LIBRARIES)
+ @WorkerThread
+ public NetworkStats queryTaggedSummary(@NonNull NetworkTemplate template, long startTime,
+ long endTime) throws SecurityException {
+ try {
+ NetworkStats result =
+ new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
+ result.startTaggedSummaryEnumeration();
+ return result;
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ return null; // To make the compiler happy.
+ }
+
+ /**
* Query network usage statistics details for a given uid.
* This may take a long time, and apps should avoid calling this on their main thread.
*
diff --git a/framework-t/src/android/net/INetworkStatsSession.aidl b/framework-t/src/android/net/INetworkStatsSession.aidl
index dfedf6633d..babe0bfb97 100644
--- a/framework-t/src/android/net/INetworkStatsSession.aidl
+++ b/framework-t/src/android/net/INetworkStatsSession.aidl
@@ -46,6 +46,10 @@ interface INetworkStatsSession {
*/
@UnsupportedAppUsage
NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags);
+
+ /** Return network layer usage summary per UID for tagged traffic that matches template. */
+ NetworkStats getTaggedSummaryForAllUid(in NetworkTemplate template, long start, long end);
+
/** Return historical network layer stats for specific UID traffic that matches template. */
@UnsupportedAppUsage
NetworkStatsHistory getHistoryForUid(in NetworkTemplate template, int uid, int set, int tag, int fields);