Merge commit '98e12851336b7db16e583f9afac63ecc97465980' from
oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master. Change-Id: Ia7b8da4a00d215160e4a4fa40f6044208d1297b7 Merged-In: I19846d2a3ee27aecbae2367a74ee49082eea154d
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -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}
|
||||
*/
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -157,7 +157,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
* Scrub given IMSI on production builds.
|
||||
*/
|
||||
public static String scrubSubscriberId(String subscriberId) {
|
||||
if ("eng".equals(Build.TYPE)) {
|
||||
if (Build.IS_ENG) {
|
||||
return subscriberId;
|
||||
} else if (subscriberId != null) {
|
||||
// TODO: parse this as MCC+MNC instead of hard-coding
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -109,25 +109,26 @@ public class TrafficStats {
|
||||
*/
|
||||
public static final int TAG_SYSTEM_RESTORE = 0xFFFFFF04;
|
||||
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_DHCP = 0xFFFFFF05;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_NTP = 0xFFFFFF06;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_PROBE = 0xFFFFFF07;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_NEIGHBOR = 0xFFFFFF08;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_GPS = 0xFFFFFF09;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_PAC = 0xFFFFFF0A;
|
||||
|
||||
/**
|
||||
* Sockets that are strictly local on device; never hits network.
|
||||
* Default tag value for code (typically APKs) downloaded by an app store on
|
||||
* behalf of the app, such as updates.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int TAG_SYSTEM_LOCAL = 0xFFFFFFAA;
|
||||
public static final int TAG_SYSTEM_APP = 0xFFFFFF05;
|
||||
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_DHCP = 0xFFFFFF40;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_NTP = 0xFFFFFF41;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_PROBE = 0xFFFFFF42;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_NEIGHBOR = 0xFFFFFF43;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_GPS = 0xFFFFFF44;
|
||||
/** @hide */
|
||||
public static final int TAG_SYSTEM_PAC = 0xFFFFFF45;
|
||||
|
||||
private static INetworkStatsService sStatsService;
|
||||
|
||||
@@ -209,6 +210,19 @@ public class TrafficStats {
|
||||
setThreadStatsTag(TAG_SYSTEM_RESTORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set active tag to use when accounting {@link Socket} traffic originating
|
||||
* from the current thread. The tag used internally is well-defined to
|
||||
* distinguish all code (typically APKs) downloaded by an app store on
|
||||
* behalf of the app, such as updates.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public static void setThreadStatsTagApp() {
|
||||
setThreadStatsTag(TAG_SYSTEM_APP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active tag used when accounting {@link Socket} traffic originating
|
||||
* from the current thread. Only one active tag per thread is supported.
|
||||
|
||||
Reference in New Issue
Block a user