Merge "[MS44.1] Add API to query tagged UID summary"
This commit is contained in:
@@ -544,6 +544,15 @@ public final class NetworkStats implements AutoCloseable {
|
|||||||
mEnumerationIndex = 0;
|
mEnumerationIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Collects history results for uid and resets history enumeration index.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ public class NetworkStatsManager {
|
|||||||
* @return Statistics which is described above.
|
* @return Statistics which is described above.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NonNull
|
||||||
// @SystemApi(client = MODULE_LIBRARIES)
|
// @SystemApi(client = MODULE_LIBRARIES)
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public NetworkStats querySummary(@NonNull NetworkTemplate template, long startTime,
|
public NetworkStats querySummary(@NonNull NetworkTemplate template, long startTime,
|
||||||
@@ -385,6 +385,39 @@ public class NetworkStatsManager {
|
|||||||
return null; // To make the compiler happy.
|
return null; // To make the compiler happy.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* 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.
|
* This may take a long time, and apps should avoid calling this on their main thread.
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ interface INetworkStatsSession {
|
|||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags);
|
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. */
|
/** Return historical network layer stats for specific UID traffic that matches template. */
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
NetworkStatsHistory getHistoryForUid(in NetworkTemplate template, int uid, int set, int tag, int fields);
|
NetworkStatsHistory getHistoryForUid(in NetworkTemplate template, int uid, int set, int tag, int fields);
|
||||||
|
|||||||
@@ -789,8 +789,18 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
return stats;
|
return stats;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// TODO: Track down and fix the cause of this crash and remove this catch block.
|
throw e;
|
||||||
Log.wtf(TAG, "NullPointerException in getSummaryForAllUid", e);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkStats getTaggedSummaryForAllUid(
|
||||||
|
NetworkTemplate template, long start, long end) {
|
||||||
|
try {
|
||||||
|
final NetworkStats tagStats = getUidTagComplete()
|
||||||
|
.getSummary(template, start, end, mAccessLevel, mCallingUid);
|
||||||
|
return tagStats;
|
||||||
|
} catch (NullPointerException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user