diff options
Diffstat (limited to 'android/app/usage')
-rw-r--r-- | android/app/usage/NetworkStats.java | 34 | ||||
-rw-r--r-- | android/app/usage/NetworkStatsManager.java | 12 | ||||
-rw-r--r-- | android/app/usage/TimeSparseArray.java | 2 | ||||
-rw-r--r-- | android/app/usage/UsageEvents.java | 14 |
4 files changed, 44 insertions, 18 deletions
diff --git a/android/app/usage/NetworkStats.java b/android/app/usage/NetworkStats.java index 7252f028..216a4a09 100644 --- a/android/app/usage/NetworkStats.java +++ b/android/app/usage/NetworkStats.java @@ -237,20 +237,26 @@ public final class NetworkStats implements AutoCloseable { DEFAULT_NETWORK_YES }) @Retention(RetentionPolicy.SOURCE) - public @interface DefaultNetwork {} + public @interface DefaultNetworkStatus {} /** - * Combined usage for this network regardless of whether it was the active default network. + * Combined usage for this network regardless of default network status. */ public static final int DEFAULT_NETWORK_ALL = -1; /** - * Usage that occurs while this network is not the active default network. + * Usage that occurs while this network is not a default network. + * + * <p>This implies that the app responsible for this usage requested that it occur on a + * specific network different from the one(s) the system would have selected for it. */ public static final int DEFAULT_NETWORK_NO = 0x1; /** - * Usage that occurs while this network is the active default network. + * Usage that occurs while this network is a default network. + * + * <p>This implies that the app either did not select a specific network for this usage, + * or it selected a network that the system could have selected for app traffic. */ public static final int DEFAULT_NETWORK_YES = 0x2; @@ -262,7 +268,7 @@ public final class NetworkStats implements AutoCloseable { private int mUid; private int mTag; private int mState; - private int mDefaultNetwork; + private int mDefaultNetworkStatus; private int mMetered; private int mRoaming; private long mBeginTimeStamp; @@ -323,8 +329,9 @@ public final class NetworkStats implements AutoCloseable { return 0; } - private static @DefaultNetwork int convertDefaultNetwork(int defaultNetwork) { - switch (defaultNetwork) { + private static @DefaultNetworkStatus int convertDefaultNetworkStatus( + int defaultNetworkStatus) { + switch (defaultNetworkStatus) { case android.net.NetworkStats.DEFAULT_NETWORK_ALL : return DEFAULT_NETWORK_ALL; case android.net.NetworkStats.DEFAULT_NETWORK_NO: return DEFAULT_NETWORK_NO; case android.net.NetworkStats.DEFAULT_NETWORK_YES: return DEFAULT_NETWORK_YES; @@ -397,18 +404,15 @@ public final class NetworkStats implements AutoCloseable { } /** - * Default network state. One of the following values:<p/> + * Default network status. One of the following values:<p/> * <ul> * <li>{@link #DEFAULT_NETWORK_ALL}</li> * <li>{@link #DEFAULT_NETWORK_NO}</li> * <li>{@link #DEFAULT_NETWORK_YES}</li> * </ul> - * <p>Indicates whether the network usage occurred on the system default network for this - * type of traffic, or whether the application chose to send this traffic on a network that - * was not the one selected by the system. */ - public @DefaultNetwork int getDefaultNetwork() { - return mDefaultNetwork; + public @DefaultNetworkStatus int getDefaultNetworkStatus() { + return mDefaultNetworkStatus; } /** @@ -605,7 +609,7 @@ public final class NetworkStats implements AutoCloseable { bucketOut.mUid = Bucket.convertUid(mRecycledSummaryEntry.uid); bucketOut.mTag = Bucket.convertTag(mRecycledSummaryEntry.tag); bucketOut.mState = Bucket.convertState(mRecycledSummaryEntry.set); - bucketOut.mDefaultNetwork = Bucket.convertDefaultNetwork( + bucketOut.mDefaultNetworkStatus = Bucket.convertDefaultNetworkStatus( mRecycledSummaryEntry.defaultNetwork); bucketOut.mMetered = Bucket.convertMetered(mRecycledSummaryEntry.metered); bucketOut.mRoaming = Bucket.convertRoaming(mRecycledSummaryEntry.roaming); @@ -657,7 +661,7 @@ public final class NetworkStats implements AutoCloseable { bucketOut.mUid = Bucket.convertUid(getUid()); bucketOut.mTag = Bucket.convertTag(mTag); bucketOut.mState = mState; - bucketOut.mDefaultNetwork = Bucket.DEFAULT_NETWORK_ALL; + bucketOut.mDefaultNetworkStatus = Bucket.DEFAULT_NETWORK_ALL; bucketOut.mMetered = Bucket.METERED_ALL; bucketOut.mRoaming = Bucket.ROAMING_ALL; bucketOut.mBeginTimeStamp = mRecycledHistoryEntry.bucketStart; diff --git a/android/app/usage/NetworkStatsManager.java b/android/app/usage/NetworkStatsManager.java index b2fe9586..0b21196f 100644 --- a/android/app/usage/NetworkStatsManager.java +++ b/android/app/usage/NetworkStatsManager.java @@ -35,6 +35,7 @@ import android.os.Messenger; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; +import android.util.DataUnit; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; @@ -95,6 +96,15 @@ public class NetworkStatsManager { /** @hide */ public static final int CALLBACK_RELEASED = 1; + /** + * Minimum data usage threshold for registering usage callbacks. + * + * Requests registered with a threshold lower than this will only be triggered once this minimum + * is reached. + * @hide + */ + public static final long MIN_THRESHOLD_BYTES = DataUnit.MEBIBYTES.toBytes(2); + private final Context mContext; private final INetworkStatsService mService; @@ -305,6 +315,8 @@ public class NetworkStatsManager { * {@link java.lang.System#currentTimeMillis}. * @param uid UID of app * @param tag TAG of interest. Use {@link NetworkStats.Bucket#TAG_NONE} for no tags. + * @param state state of interest. Use {@link NetworkStats.Bucket#STATE_ALL} to aggregate + * traffic from all states. * @return Statistics object or null if an error happened during statistics collection. * @throws SecurityException if permissions are insufficient to read network statistics. */ diff --git a/android/app/usage/TimeSparseArray.java b/android/app/usage/TimeSparseArray.java index 9ef88e41..4ec0e9e4 100644 --- a/android/app/usage/TimeSparseArray.java +++ b/android/app/usage/TimeSparseArray.java @@ -88,7 +88,7 @@ public class TimeSparseArray<E> extends LongSparseArray<E> { key++; keyIndex++; } - if (key >= origKey + 10) { + if (key >= origKey + 100) { Slog.w(TAG, "Value " + value + " supposed to be inserted at " + origKey + " displaced to " + key); } diff --git a/android/app/usage/UsageEvents.java b/android/app/usage/UsageEvents.java index 84f57a30..503ca6c3 100644 --- a/android/app/usage/UsageEvents.java +++ b/android/app/usage/UsageEvents.java @@ -111,7 +111,7 @@ public final class UsageEvents implements Parcelable { /** * An event type denoting a change in App Standby Bucket. The new bucket can be - * retrieved by calling {@link #getStandbyBucket()}. + * retrieved by calling {@link #getAppStandbyBucket()}. * * @see UsageStatsManager#getAppStandbyBucket() */ @@ -326,13 +326,23 @@ public final class UsageEvents implements Parcelable { * Returns the standby bucket of the app, if the event is of type * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. * @return the standby bucket associated with the event. - * + * @hide */ public int getStandbyBucket() { return (mBucketAndReason & 0xFFFF0000) >>> 16; } /** + * Returns the standby bucket of the app, if the event is of type + * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. + * @return the standby bucket associated with the event. + * + */ + public int getAppStandbyBucket() { + return (mBucketAndReason & 0xFFFF0000) >>> 16; + } + + /** * Returns the reason for the bucketing, if the event is of type * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. Reason values include * the main reason which is one of REASON_MAIN_*, OR'ed with REASON_SUB_*, if there |