Merge changes from topic "ms16-querysummary" am: b4ac36e28d

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

Change-Id: I3c51ec1fb523958b6adebe68f19a4d6a60346a62
This commit is contained in:
Junyu Lai
2021-12-27 05:55:02 +00:00
committed by Automerger Merge Worker

View File

@@ -170,16 +170,44 @@ public class NetworkStatsManager {
} }
} }
/** @hide */ /**
public Bucket querySummaryForDevice(NetworkTemplate template, * Query network usage statistics summaries.
long startTime, long endTime) throws SecurityException, RemoteException { *
Bucket bucket = null; * Result is summarised data usage for the whole
NetworkStats stats = new NetworkStats(mContext, template, mFlags, startTime, endTime, * device. Result is a single Bucket aggregated over time, state, uid, tag, metered, and
mService); * roaming. This means the bucket's start and end timestamp will be the same as the
bucket = stats.getDeviceSummaryForNetwork(); * 'startTime' and 'endTime' arguments. State is going to be
* {@link NetworkStats.Bucket#STATE_ALL}, uid {@link NetworkStats.Bucket#UID_ALL},
stats.close(); * tag {@link NetworkStats.Bucket#TAG_NONE},
return bucket; * default network {@link NetworkStats.Bucket#DEFAULT_NETWORK_ALL},
* metered {@link NetworkStats.Bucket#METERED_ALL},
* and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
* 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 java.lang.System#currentTimeMillis}.
* @param endTime End of period, in milliseconds since the Unix epoch, see
* {@link java.lang.System#currentTimeMillis}.
* @return Bucket Summarised data usage.
*
* @hide
*/
@NonNull
@WorkerThread
// @SystemApi(client = MODULE_LIBRARIES)
public Bucket querySummaryForDevice(@NonNull NetworkTemplate template,
long startTime, long endTime) {
try {
NetworkStats stats =
new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
Bucket bucket = stats.getDeviceSummaryForNetwork();
stats.close();
return bucket;
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
return null; // To make the compiler happy.
} }
/** /**
@@ -323,14 +351,37 @@ public class NetworkStatsManager {
return querySummary(template, startTime, endTime); return querySummary(template, startTime, endTime);
} }
/** @hide */ /**
public NetworkStats querySummary(NetworkTemplate template, long startTime, * Query network usage statistics summaries.
long endTime) throws SecurityException, RemoteException { *
NetworkStats result; * The results will only include traffic made by UIDs belonging to the calling user profile.
result = new NetworkStats(mContext, template, mFlags, startTime, endTime, mService); * The results are aggregated over time, so that all buckets will have the same start and
result.startSummaryEnumeration(); * end timestamps as the passed arguments. Not aggregated over state, uid, default network,
* metered, or roaming.
return result; * 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 java.lang.System#currentTimeMillis}.
* @param endTime End of period, in milliseconds since the Unix epoch, see
* {@link java.lang.System#currentTimeMillis}.
* @return Statistics which is described above.
* @hide
*/
@Nullable
// @SystemApi(client = MODULE_LIBRARIES)
@WorkerThread
public NetworkStats querySummary(@NonNull NetworkTemplate template, long startTime,
long endTime) throws SecurityException {
try {
NetworkStats result =
new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
result.startSummaryEnumeration();
return result;
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
return null; // To make the compiler happy.
} }
/** /**