Loading core/java/android/app/usage/NetworkStats.java +9 −12 Original line number Diff line number Diff line Loading @@ -309,12 +309,10 @@ public final class NetworkStats implements AutoCloseable { /** * Collects device summary results into a Bucket. * @param startTime * @param endTime * @throws RemoteException */ Bucket getDeviceSummaryForNetwork(long startTime, long endTime) throws RemoteException { mSummary = mSession.getDeviceSummaryForNetwork(mTemplate, startTime, endTime); Bucket getDeviceSummaryForNetwork() throws RemoteException { mSummary = mSession.getDeviceSummaryForNetwork(mTemplate, mStartTimeStamp, mEndTimeStamp); // Setting enumeration index beyond end to avoid accidental enumeration over data that does // not belong to the calling user. Loading @@ -325,12 +323,10 @@ public final class NetworkStats implements AutoCloseable { /** * Collects summary results and sets summary enumeration mode. * @param startTime * @param endTime * @throws RemoteException */ void startSummaryEnumeration(long startTime, long endTime) throws RemoteException { mSummary = mSession.getSummaryForAllUid(mTemplate, startTime, endTime, false); void startSummaryEnumeration() throws RemoteException { mSummary = mSession.getSummaryForAllUid(mTemplate, mStartTimeStamp, mEndTimeStamp, false); mEnumerationIndex = 0; } Loading @@ -341,8 +337,9 @@ public final class NetworkStats implements AutoCloseable { void startHistoryEnumeration(int uid) { mHistory = null; try { mHistory = mSession.getHistoryForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL); mHistory = mSession.getHistoryIntervalForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp); setSingleUid(uid); } catch (RemoteException e) { Log.w(TAG, e); Loading @@ -368,9 +365,9 @@ public final class NetworkStats implements AutoCloseable { stepUid(); mHistory = null; try { mHistory = mSession.getHistoryForUid(mTemplate, getUid(), mHistory = mSession.getHistoryIntervalForUid(mTemplate, getUid(), android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL); NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp); } catch (RemoteException e) { Log.w(TAG, e); // Leaving mHistory null Loading core/java/android/app/usage/NetworkStatsManager.java +11 −5 Original line number Diff line number Diff line Loading @@ -97,7 +97,7 @@ public class NetworkStatsManager { Bucket bucket = null; NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime); bucket = stats.getDeviceSummaryForNetwork(startTime, endTime); bucket = stats.getDeviceSummaryForNetwork(); stats.close(); return bucket; Loading Loading @@ -130,7 +130,7 @@ public class NetworkStatsManager { NetworkStats stats; stats = new NetworkStats(mContext, template, startTime, endTime); stats.startSummaryEnumeration(startTime, endTime); stats.startSummaryEnumeration(); stats.close(); return stats.getSummaryAggregate(); Loading Loading @@ -163,7 +163,7 @@ public class NetworkStatsManager { NetworkStats result; result = new NetworkStats(mContext, template, startTime, endTime); result.startSummaryEnumeration(startTime, endTime); result.startSummaryEnumeration(); return result; } Loading @@ -173,6 +173,9 @@ public class NetworkStatsManager { * Result is aggregated over state but not aggregated over time. This means buckets' start and * end timestamps are going to be between 'startTime' and 'endTime' parameters, state is going * to be {@link NetworkStats.Bucket#STATE_ALL} and uid the same as the 'uid' parameter. * <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't * interpolate across partial buckets. Since bucket length is in the order of hours, this * method cannot be used to measure data usage on a fine grained time scale. * * @param networkType As defined in {@link ConnectivityManager}, e.g. * {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI} Loading Loading @@ -205,6 +208,9 @@ public class NetworkStatsManager { * calling user. Result is aggregated over state but not aggregated over time or uid. This means * buckets' start and end timestamps are going to be between 'startTime' and 'endTime' * parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid will vary. * <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't * interpolate across partial buckets. Since bucket length is in the order of hours, this * method cannot be used to measure data usage on a fine grained time scale. * * @param networkType As defined in {@link ConnectivityManager}, e.g. * {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI} Loading core/java/android/net/INetworkStatsSession.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ interface INetworkStatsSession { NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags); /** Return historical network layer stats for specific UID traffic that matches template. */ NetworkStatsHistory getHistoryForUid(in NetworkTemplate template, int uid, int set, int tag, int fields); /** Return historical network layer stats for specific UID traffic that matches template. */ NetworkStatsHistory getHistoryIntervalForUid(in NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end); /** Return array of uids that have stats and are accessible to the calling user */ int[] getRelevantUids(); Loading services/core/java/com/android/server/net/NetworkStatsService.java +27 −1 Original line number Diff line number Diff line Loading @@ -436,13 +436,26 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public INetworkStatsSession openSession() { return openSessionForUsageStats(null); return createSession(null, /* poll on create */ false); } @Override public INetworkStatsSession openSessionForUsageStats(final String callingPackage) { return createSession(callingPackage, /* poll on create */ true); } private INetworkStatsSession createSession(final String callingPackage, boolean pollOnCreate) { assertBandwidthControlEnabled(); if (pollOnCreate) { final long ident = Binder.clearCallingIdentity(); try { performPoll(FLAG_PERSIST_ALL); } finally { Binder.restoreCallingIdentity(ident); } } // return an IBinder which holds strong references to any loaded stats // for its lifetime; when caller closes only weak references remain. Loading Loading @@ -525,6 +538,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } @Override public NetworkStatsHistory getHistoryIntervalForUid( NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end) { enforcePermissionForManagedAdmin(mCallingPackage); if (tag == TAG_NONE) { return getUidComplete().getHistory(template, uid, set, tag, fields, start, end); } else { return getUidTagComplete().getHistory(template, uid, set, tag, fields, start, end); } } @Override public void close() { mUidComplete = null; Loading Loading
core/java/android/app/usage/NetworkStats.java +9 −12 Original line number Diff line number Diff line Loading @@ -309,12 +309,10 @@ public final class NetworkStats implements AutoCloseable { /** * Collects device summary results into a Bucket. * @param startTime * @param endTime * @throws RemoteException */ Bucket getDeviceSummaryForNetwork(long startTime, long endTime) throws RemoteException { mSummary = mSession.getDeviceSummaryForNetwork(mTemplate, startTime, endTime); Bucket getDeviceSummaryForNetwork() throws RemoteException { mSummary = mSession.getDeviceSummaryForNetwork(mTemplate, mStartTimeStamp, mEndTimeStamp); // Setting enumeration index beyond end to avoid accidental enumeration over data that does // not belong to the calling user. Loading @@ -325,12 +323,10 @@ public final class NetworkStats implements AutoCloseable { /** * Collects summary results and sets summary enumeration mode. * @param startTime * @param endTime * @throws RemoteException */ void startSummaryEnumeration(long startTime, long endTime) throws RemoteException { mSummary = mSession.getSummaryForAllUid(mTemplate, startTime, endTime, false); void startSummaryEnumeration() throws RemoteException { mSummary = mSession.getSummaryForAllUid(mTemplate, mStartTimeStamp, mEndTimeStamp, false); mEnumerationIndex = 0; } Loading @@ -341,8 +337,9 @@ public final class NetworkStats implements AutoCloseable { void startHistoryEnumeration(int uid) { mHistory = null; try { mHistory = mSession.getHistoryForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL); mHistory = mSession.getHistoryIntervalForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp); setSingleUid(uid); } catch (RemoteException e) { Log.w(TAG, e); Loading @@ -368,9 +365,9 @@ public final class NetworkStats implements AutoCloseable { stepUid(); mHistory = null; try { mHistory = mSession.getHistoryForUid(mTemplate, getUid(), mHistory = mSession.getHistoryIntervalForUid(mTemplate, getUid(), android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL); NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp); } catch (RemoteException e) { Log.w(TAG, e); // Leaving mHistory null Loading
core/java/android/app/usage/NetworkStatsManager.java +11 −5 Original line number Diff line number Diff line Loading @@ -97,7 +97,7 @@ public class NetworkStatsManager { Bucket bucket = null; NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime); bucket = stats.getDeviceSummaryForNetwork(startTime, endTime); bucket = stats.getDeviceSummaryForNetwork(); stats.close(); return bucket; Loading Loading @@ -130,7 +130,7 @@ public class NetworkStatsManager { NetworkStats stats; stats = new NetworkStats(mContext, template, startTime, endTime); stats.startSummaryEnumeration(startTime, endTime); stats.startSummaryEnumeration(); stats.close(); return stats.getSummaryAggregate(); Loading Loading @@ -163,7 +163,7 @@ public class NetworkStatsManager { NetworkStats result; result = new NetworkStats(mContext, template, startTime, endTime); result.startSummaryEnumeration(startTime, endTime); result.startSummaryEnumeration(); return result; } Loading @@ -173,6 +173,9 @@ public class NetworkStatsManager { * Result is aggregated over state but not aggregated over time. This means buckets' start and * end timestamps are going to be between 'startTime' and 'endTime' parameters, state is going * to be {@link NetworkStats.Bucket#STATE_ALL} and uid the same as the 'uid' parameter. * <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't * interpolate across partial buckets. Since bucket length is in the order of hours, this * method cannot be used to measure data usage on a fine grained time scale. * * @param networkType As defined in {@link ConnectivityManager}, e.g. * {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI} Loading Loading @@ -205,6 +208,9 @@ public class NetworkStatsManager { * calling user. Result is aggregated over state but not aggregated over time or uid. This means * buckets' start and end timestamps are going to be between 'startTime' and 'endTime' * parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid will vary. * <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't * interpolate across partial buckets. Since bucket length is in the order of hours, this * method cannot be used to measure data usage on a fine grained time scale. * * @param networkType As defined in {@link ConnectivityManager}, e.g. * {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI} Loading
core/java/android/net/INetworkStatsSession.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ interface INetworkStatsSession { NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags); /** Return historical network layer stats for specific UID traffic that matches template. */ NetworkStatsHistory getHistoryForUid(in NetworkTemplate template, int uid, int set, int tag, int fields); /** Return historical network layer stats for specific UID traffic that matches template. */ NetworkStatsHistory getHistoryIntervalForUid(in NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end); /** Return array of uids that have stats and are accessible to the calling user */ int[] getRelevantUids(); Loading
services/core/java/com/android/server/net/NetworkStatsService.java +27 −1 Original line number Diff line number Diff line Loading @@ -436,13 +436,26 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public INetworkStatsSession openSession() { return openSessionForUsageStats(null); return createSession(null, /* poll on create */ false); } @Override public INetworkStatsSession openSessionForUsageStats(final String callingPackage) { return createSession(callingPackage, /* poll on create */ true); } private INetworkStatsSession createSession(final String callingPackage, boolean pollOnCreate) { assertBandwidthControlEnabled(); if (pollOnCreate) { final long ident = Binder.clearCallingIdentity(); try { performPoll(FLAG_PERSIST_ALL); } finally { Binder.restoreCallingIdentity(ident); } } // return an IBinder which holds strong references to any loaded stats // for its lifetime; when caller closes only weak references remain. Loading Loading @@ -525,6 +538,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } @Override public NetworkStatsHistory getHistoryIntervalForUid( NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end) { enforcePermissionForManagedAdmin(mCallingPackage); if (tag == TAG_NONE) { return getUidComplete().getHistory(template, uid, set, tag, fields, start, end); } else { return getUidTagComplete().getHistory(template, uid, set, tag, fields, start, end); } } @Override public void close() { mUidComplete = null; Loading