Loading core/java/android/app/usage/NetworkStats.java +2 −2 Original line number Diff line number Diff line Loading @@ -97,12 +97,12 @@ public final class NetworkStats implements AutoCloseable { private NetworkStatsHistory.Entry mRecycledHistoryEntry = null; /** @hide */ NetworkStats(Context context, NetworkTemplate template, long startTimestamp, NetworkStats(Context context, NetworkTemplate template, int flags, long startTimestamp, long endTimestamp) throws RemoteException, SecurityException { final INetworkStatsService statsService = INetworkStatsService.Stub.asInterface( ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); // Open network stats session mSession = statsService.openSessionForUsageStats(context.getOpPackageName()); mSession = statsService.openSessionForUsageStats(flags, context.getOpPackageName()); mCloseGuard.open("close"); mTemplate = template; mStartTimeStamp = startTimestamp; Loading core/java/android/app/usage/NetworkStatsManager.java +35 −10 Original line number Diff line number Diff line Loading @@ -24,15 +24,14 @@ import android.app.usage.NetworkStats.Bucket; import android.content.Context; import android.net.ConnectivityManager; import android.net.DataUsageRequest; import android.net.INetworkStatsService; import android.net.NetworkIdentity; import android.net.NetworkTemplate; import android.net.INetworkStatsService; import android.os.Binder; import android.os.Build; import android.os.Message; import android.os.Messenger; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; Loading Loading @@ -79,7 +78,7 @@ import android.util.Log; * In addition to tethering usage, usage by removed users and apps, and usage by the system * is also included in the results for callers with one of these higher levels of access. * <p /> * <b>NOTE:</b> Prior to API level {@value Build.VERSION_CODES#N}, all calls to these APIs required * <b>NOTE:</b> Prior to API level {@value android.os.Build.VERSION_CODES#N}, all calls to these APIs required * the above permission, even to access an app's own data usage, and carrier-privileged apps were * not included. */ Loading @@ -96,6 +95,13 @@ public class NetworkStatsManager { private final Context mContext; private final INetworkStatsService mService; /** @hide */ public static final int FLAG_POLL_ON_OPEN = 1 << 0; /** @hide */ public static final int FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN = 1 << 1; private int mFlags; /** * {@hide} */ Loading @@ -103,6 +109,25 @@ public class NetworkStatsManager { mContext = context; mService = INetworkStatsService.Stub.asInterface( ServiceManager.getServiceOrThrow(Context.NETWORK_STATS_SERVICE)); setPollOnOpen(true); } /** @hide */ public void setPollOnOpen(boolean pollOnOpen) { if (pollOnOpen) { mFlags |= FLAG_POLL_ON_OPEN; } else { mFlags &= ~FLAG_POLL_ON_OPEN; } } /** @hide */ public void setAugmentWithSubscriptionPlan(boolean augmentWithSubscriptionPlan) { if (augmentWithSubscriptionPlan) { mFlags |= FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN; } else { mFlags &= ~FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN; } } /** Loading Loading @@ -136,7 +161,7 @@ public class NetworkStatsManager { } Bucket bucket = null; NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime); NetworkStats stats = new NetworkStats(mContext, template, mFlags, startTime, endTime); bucket = stats.getDeviceSummaryForNetwork(); stats.close(); Loading Loading @@ -174,7 +199,7 @@ public class NetworkStatsManager { } NetworkStats stats; stats = new NetworkStats(mContext, template, startTime, endTime); stats = new NetworkStats(mContext, template, mFlags, startTime, endTime); stats.startSummaryEnumeration(); stats.close(); Loading Loading @@ -211,7 +236,7 @@ public class NetworkStatsManager { } NetworkStats result; result = new NetworkStats(mContext, template, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result.startSummaryEnumeration(); return result; Loading Loading @@ -260,7 +285,7 @@ public class NetworkStatsManager { NetworkStats result; try { result = new NetworkStats(mContext, template, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result.startHistoryEnumeration(uid, tag); } catch (RemoteException e) { Log.e(TAG, "Error while querying stats for uid=" + uid + " tag=" + tag, e); Loading Loading @@ -305,7 +330,7 @@ public class NetworkStatsManager { } NetworkStats result; result = new NetworkStats(mContext, template, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result.startUserUidEnumeration(); return result; } Loading core/java/android/net/INetworkStatsService.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ interface INetworkStatsService { * PACKAGE_USAGE_STATS permission is always checked. If PACKAGE_USAGE_STATS is not granted * READ_NETWORK_USAGE_STATS is checked for. */ INetworkStatsSession openSessionForUsageStats(String callingPackage); INetworkStatsSession openSessionForUsageStats(int flags, String callingPackage); /** Return network layer usage total for traffic that matches template. */ long getNetworkTotalBytes(in NetworkTemplate template, long start, long end); Loading core/java/android/net/NetworkStatsHistory.java +19 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static android.net.NetworkStatsHistory.Entry.UNKNOWN; import static android.net.NetworkStatsHistory.ParcelUtils.readLongArray; import static android.net.NetworkStatsHistory.ParcelUtils.writeLongArray; import static android.text.format.DateUtils.SECOND_IN_MILLIS; import static com.android.internal.util.ArrayUtils.total; import android.os.Parcel; Loading Loading @@ -282,6 +283,24 @@ public class NetworkStatsHistory implements Parcelable { return entry; } public void setValues(int i, Entry entry) { // Unwind old values if (rxBytes != null) totalBytes -= rxBytes[i]; if (txBytes != null) totalBytes -= txBytes[i]; bucketStart[i] = entry.bucketStart; setLong(activeTime, i, entry.activeTime); setLong(rxBytes, i, entry.rxBytes); setLong(rxPackets, i, entry.rxPackets); setLong(txBytes, i, entry.txBytes); setLong(txPackets, i, entry.txPackets); setLong(operations, i, entry.operations); // Apply new values if (rxBytes != null) totalBytes += rxBytes[i]; if (txBytes != null) totalBytes += txBytes[i]; } /** * Record that data traffic occurred in the given time range. Will * distribute across internal buckets, creating new buckets as needed. Loading core/java/android/net/NetworkTemplate.java +4 −0 Original line number Diff line number Diff line Loading @@ -326,6 +326,10 @@ public class NetworkTemplate implements Parcelable { } } public boolean matchesSubscriberId(String subscriberId) { return ArrayUtils.contains(mMatchSubscriberIds, subscriberId); } /** * Check if mobile network with matching IMSI. */ Loading Loading
core/java/android/app/usage/NetworkStats.java +2 −2 Original line number Diff line number Diff line Loading @@ -97,12 +97,12 @@ public final class NetworkStats implements AutoCloseable { private NetworkStatsHistory.Entry mRecycledHistoryEntry = null; /** @hide */ NetworkStats(Context context, NetworkTemplate template, long startTimestamp, NetworkStats(Context context, NetworkTemplate template, int flags, long startTimestamp, long endTimestamp) throws RemoteException, SecurityException { final INetworkStatsService statsService = INetworkStatsService.Stub.asInterface( ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); // Open network stats session mSession = statsService.openSessionForUsageStats(context.getOpPackageName()); mSession = statsService.openSessionForUsageStats(flags, context.getOpPackageName()); mCloseGuard.open("close"); mTemplate = template; mStartTimeStamp = startTimestamp; Loading
core/java/android/app/usage/NetworkStatsManager.java +35 −10 Original line number Diff line number Diff line Loading @@ -24,15 +24,14 @@ import android.app.usage.NetworkStats.Bucket; import android.content.Context; import android.net.ConnectivityManager; import android.net.DataUsageRequest; import android.net.INetworkStatsService; import android.net.NetworkIdentity; import android.net.NetworkTemplate; import android.net.INetworkStatsService; import android.os.Binder; import android.os.Build; import android.os.Message; import android.os.Messenger; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; Loading Loading @@ -79,7 +78,7 @@ import android.util.Log; * In addition to tethering usage, usage by removed users and apps, and usage by the system * is also included in the results for callers with one of these higher levels of access. * <p /> * <b>NOTE:</b> Prior to API level {@value Build.VERSION_CODES#N}, all calls to these APIs required * <b>NOTE:</b> Prior to API level {@value android.os.Build.VERSION_CODES#N}, all calls to these APIs required * the above permission, even to access an app's own data usage, and carrier-privileged apps were * not included. */ Loading @@ -96,6 +95,13 @@ public class NetworkStatsManager { private final Context mContext; private final INetworkStatsService mService; /** @hide */ public static final int FLAG_POLL_ON_OPEN = 1 << 0; /** @hide */ public static final int FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN = 1 << 1; private int mFlags; /** * {@hide} */ Loading @@ -103,6 +109,25 @@ public class NetworkStatsManager { mContext = context; mService = INetworkStatsService.Stub.asInterface( ServiceManager.getServiceOrThrow(Context.NETWORK_STATS_SERVICE)); setPollOnOpen(true); } /** @hide */ public void setPollOnOpen(boolean pollOnOpen) { if (pollOnOpen) { mFlags |= FLAG_POLL_ON_OPEN; } else { mFlags &= ~FLAG_POLL_ON_OPEN; } } /** @hide */ public void setAugmentWithSubscriptionPlan(boolean augmentWithSubscriptionPlan) { if (augmentWithSubscriptionPlan) { mFlags |= FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN; } else { mFlags &= ~FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN; } } /** Loading Loading @@ -136,7 +161,7 @@ public class NetworkStatsManager { } Bucket bucket = null; NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime); NetworkStats stats = new NetworkStats(mContext, template, mFlags, startTime, endTime); bucket = stats.getDeviceSummaryForNetwork(); stats.close(); Loading Loading @@ -174,7 +199,7 @@ public class NetworkStatsManager { } NetworkStats stats; stats = new NetworkStats(mContext, template, startTime, endTime); stats = new NetworkStats(mContext, template, mFlags, startTime, endTime); stats.startSummaryEnumeration(); stats.close(); Loading Loading @@ -211,7 +236,7 @@ public class NetworkStatsManager { } NetworkStats result; result = new NetworkStats(mContext, template, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result.startSummaryEnumeration(); return result; Loading Loading @@ -260,7 +285,7 @@ public class NetworkStatsManager { NetworkStats result; try { result = new NetworkStats(mContext, template, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result.startHistoryEnumeration(uid, tag); } catch (RemoteException e) { Log.e(TAG, "Error while querying stats for uid=" + uid + " tag=" + tag, e); Loading Loading @@ -305,7 +330,7 @@ public class NetworkStatsManager { } NetworkStats result; result = new NetworkStats(mContext, template, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result.startUserUidEnumeration(); return result; } Loading
core/java/android/net/INetworkStatsService.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ interface INetworkStatsService { * PACKAGE_USAGE_STATS permission is always checked. If PACKAGE_USAGE_STATS is not granted * READ_NETWORK_USAGE_STATS is checked for. */ INetworkStatsSession openSessionForUsageStats(String callingPackage); INetworkStatsSession openSessionForUsageStats(int flags, String callingPackage); /** Return network layer usage total for traffic that matches template. */ long getNetworkTotalBytes(in NetworkTemplate template, long start, long end); Loading
core/java/android/net/NetworkStatsHistory.java +19 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static android.net.NetworkStatsHistory.Entry.UNKNOWN; import static android.net.NetworkStatsHistory.ParcelUtils.readLongArray; import static android.net.NetworkStatsHistory.ParcelUtils.writeLongArray; import static android.text.format.DateUtils.SECOND_IN_MILLIS; import static com.android.internal.util.ArrayUtils.total; import android.os.Parcel; Loading Loading @@ -282,6 +283,24 @@ public class NetworkStatsHistory implements Parcelable { return entry; } public void setValues(int i, Entry entry) { // Unwind old values if (rxBytes != null) totalBytes -= rxBytes[i]; if (txBytes != null) totalBytes -= txBytes[i]; bucketStart[i] = entry.bucketStart; setLong(activeTime, i, entry.activeTime); setLong(rxBytes, i, entry.rxBytes); setLong(rxPackets, i, entry.rxPackets); setLong(txBytes, i, entry.txBytes); setLong(txPackets, i, entry.txPackets); setLong(operations, i, entry.operations); // Apply new values if (rxBytes != null) totalBytes += rxBytes[i]; if (txBytes != null) totalBytes += txBytes[i]; } /** * Record that data traffic occurred in the given time range. Will * distribute across internal buckets, creating new buckets as needed. Loading
core/java/android/net/NetworkTemplate.java +4 −0 Original line number Diff line number Diff line Loading @@ -326,6 +326,10 @@ public class NetworkTemplate implements Parcelable { } } public boolean matchesSubscriberId(String subscriberId) { return ArrayUtils.contains(mMatchSubscriberIds, subscriberId); } /** * Check if mobile network with matching IMSI. */ Loading