Merge Android R
Bug: 168057903 Merged-In: Ice3e441cc9c0df8d0a6acc016bb74375e081bd67 Change-Id: I1d85742f594be2007c99841b290e502b6ede624e
This commit is contained in:
@@ -41,6 +41,7 @@ import android.os.Messenger;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.ServiceManager.ServiceNotFoundException;
|
import android.os.ServiceManager.ServiceNotFoundException;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.DataUnit;
|
import android.util.DataUnit;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -198,6 +199,12 @@ public class NetworkStatsManager {
|
|||||||
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
||||||
* etc.
|
* etc.
|
||||||
* @param subscriberId If applicable, the subscriber id of the network interface.
|
* @param subscriberId If applicable, the subscriber id of the network interface.
|
||||||
|
* <p>Starting with API level 29, the {@code subscriberId} is guarded by
|
||||||
|
* additional restrictions. Calling apps that do not meet the new
|
||||||
|
* requirements to access the {@code subscriberId} can provide a {@code
|
||||||
|
* null} value when querying for the mobile network type to receive usage
|
||||||
|
* for all mobile networks. For additional details see {@link
|
||||||
|
* TelephonyManager#getSubscriberId()}.
|
||||||
* @param startTime Start of period. Defined in terms of "Unix time", see
|
* @param startTime Start of period. Defined in terms of "Unix time", see
|
||||||
* {@link java.lang.System#currentTimeMillis}.
|
* {@link java.lang.System#currentTimeMillis}.
|
||||||
* @param endTime End of period. Defined in terms of "Unix time", see
|
* @param endTime End of period. Defined in terms of "Unix time", see
|
||||||
@@ -231,6 +238,12 @@ public class NetworkStatsManager {
|
|||||||
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
||||||
* etc.
|
* etc.
|
||||||
* @param subscriberId If applicable, the subscriber id of the network interface.
|
* @param subscriberId If applicable, the subscriber id of the network interface.
|
||||||
|
* <p>Starting with API level 29, the {@code subscriberId} is guarded by
|
||||||
|
* additional restrictions. Calling apps that do not meet the new
|
||||||
|
* requirements to access the {@code subscriberId} can provide a {@code
|
||||||
|
* null} value when querying for the mobile network type to receive usage
|
||||||
|
* for all mobile networks. For additional details see {@link
|
||||||
|
* TelephonyManager#getSubscriberId()}.
|
||||||
* @param startTime Start of period. Defined in terms of "Unix time", see
|
* @param startTime Start of period. Defined in terms of "Unix time", see
|
||||||
* {@link java.lang.System#currentTimeMillis}.
|
* {@link java.lang.System#currentTimeMillis}.
|
||||||
* @param endTime End of period. Defined in terms of "Unix time", see
|
* @param endTime End of period. Defined in terms of "Unix time", see
|
||||||
@@ -268,6 +281,12 @@ public class NetworkStatsManager {
|
|||||||
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
||||||
* etc.
|
* etc.
|
||||||
* @param subscriberId If applicable, the subscriber id of the network interface.
|
* @param subscriberId If applicable, the subscriber id of the network interface.
|
||||||
|
* <p>Starting with API level 29, the {@code subscriberId} is guarded by
|
||||||
|
* additional restrictions. Calling apps that do not meet the new
|
||||||
|
* requirements to access the {@code subscriberId} can provide a {@code
|
||||||
|
* null} value when querying for the mobile network type to receive usage
|
||||||
|
* for all mobile networks. For additional details see {@link
|
||||||
|
* TelephonyManager#getSubscriberId()}.
|
||||||
* @param startTime Start of period. Defined in terms of "Unix time", see
|
* @param startTime Start of period. Defined in terms of "Unix time", see
|
||||||
* {@link java.lang.System#currentTimeMillis}.
|
* {@link java.lang.System#currentTimeMillis}.
|
||||||
* @param endTime End of period. Defined in terms of "Unix time", see
|
* @param endTime End of period. Defined in terms of "Unix time", see
|
||||||
@@ -301,7 +320,7 @@ public class NetworkStatsManager {
|
|||||||
/**
|
/**
|
||||||
* Query network usage statistics details for a given uid.
|
* Query network usage statistics details for a given uid.
|
||||||
*
|
*
|
||||||
* #see queryDetailsForUidTagState(int, String, long, long, int, int, int)
|
* @see #queryDetailsForUidTagState(int, String, long, long, int, int, int)
|
||||||
*/
|
*/
|
||||||
public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
|
public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
|
||||||
long startTime, long endTime, int uid) throws SecurityException {
|
long startTime, long endTime, int uid) throws SecurityException {
|
||||||
@@ -319,7 +338,7 @@ public class NetworkStatsManager {
|
|||||||
/**
|
/**
|
||||||
* Query network usage statistics details for a given uid and tag.
|
* Query network usage statistics details for a given uid and tag.
|
||||||
*
|
*
|
||||||
* #see queryDetailsForUidTagState(int, String, long, long, int, int, int)
|
* @see #queryDetailsForUidTagState(int, String, long, long, int, int, int)
|
||||||
*/
|
*/
|
||||||
public NetworkStats queryDetailsForUidTag(int networkType, String subscriberId,
|
public NetworkStats queryDetailsForUidTag(int networkType, String subscriberId,
|
||||||
long startTime, long endTime, int uid, int tag) throws SecurityException {
|
long startTime, long endTime, int uid, int tag) throws SecurityException {
|
||||||
@@ -344,6 +363,12 @@ public class NetworkStatsManager {
|
|||||||
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
||||||
* etc.
|
* etc.
|
||||||
* @param subscriberId If applicable, the subscriber id of the network interface.
|
* @param subscriberId If applicable, the subscriber id of the network interface.
|
||||||
|
* <p>Starting with API level 29, the {@code subscriberId} is guarded by
|
||||||
|
* additional restrictions. Calling apps that do not meet the new
|
||||||
|
* requirements to access the {@code subscriberId} can provide a {@code
|
||||||
|
* null} value when querying for the mobile network type to receive usage
|
||||||
|
* for all mobile networks. For additional details see {@link
|
||||||
|
* TelephonyManager#getSubscriberId()}.
|
||||||
* @param startTime Start of period. Defined in terms of "Unix time", see
|
* @param startTime Start of period. Defined in terms of "Unix time", see
|
||||||
* {@link java.lang.System#currentTimeMillis}.
|
* {@link java.lang.System#currentTimeMillis}.
|
||||||
* @param endTime End of period. Defined in terms of "Unix time", see
|
* @param endTime End of period. Defined in terms of "Unix time", see
|
||||||
@@ -398,6 +423,12 @@ public class NetworkStatsManager {
|
|||||||
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
|
||||||
* etc.
|
* etc.
|
||||||
* @param subscriberId If applicable, the subscriber id of the network interface.
|
* @param subscriberId If applicable, the subscriber id of the network interface.
|
||||||
|
* <p>Starting with API level 29, the {@code subscriberId} is guarded by
|
||||||
|
* additional restrictions. Calling apps that do not meet the new
|
||||||
|
* requirements to access the {@code subscriberId} can provide a {@code
|
||||||
|
* null} value when querying for the mobile network type to receive usage
|
||||||
|
* for all mobile networks. For additional details see {@link
|
||||||
|
* TelephonyManager#getSubscriberId()}.
|
||||||
* @param startTime Start of period. Defined in terms of "Unix time", see
|
* @param startTime Start of period. Defined in terms of "Unix time", see
|
||||||
* {@link java.lang.System#currentTimeMillis}.
|
* {@link java.lang.System#currentTimeMillis}.
|
||||||
* @param endTime End of period. Defined in terms of "Unix time", see
|
* @param endTime End of period. Defined in terms of "Unix time", see
|
||||||
@@ -455,7 +486,7 @@ public class NetworkStatsManager {
|
|||||||
/**
|
/**
|
||||||
* Registers to receive notifications about data usage on specified networks.
|
* Registers to receive notifications about data usage on specified networks.
|
||||||
*
|
*
|
||||||
* #see registerUsageCallback(int, String[], long, UsageCallback, Handler)
|
* @see #registerUsageCallback(int, String, long, UsageCallback, Handler)
|
||||||
*/
|
*/
|
||||||
public void registerUsageCallback(int networkType, String subscriberId, long thresholdBytes,
|
public void registerUsageCallback(int networkType, String subscriberId, long thresholdBytes,
|
||||||
UsageCallback callback) {
|
UsageCallback callback) {
|
||||||
@@ -472,6 +503,12 @@ public class NetworkStatsManager {
|
|||||||
* @param networkType Type of network to monitor. Either
|
* @param networkType Type of network to monitor. Either
|
||||||
{@link ConnectivityManager#TYPE_MOBILE} or {@link ConnectivityManager#TYPE_WIFI}.
|
{@link ConnectivityManager#TYPE_MOBILE} or {@link ConnectivityManager#TYPE_WIFI}.
|
||||||
* @param subscriberId If applicable, the subscriber id of the network interface.
|
* @param subscriberId If applicable, the subscriber id of the network interface.
|
||||||
|
* <p>Starting with API level 29, the {@code subscriberId} is guarded by
|
||||||
|
* additional restrictions. Calling apps that do not meet the new
|
||||||
|
* requirements to access the {@code subscriberId} can provide a {@code
|
||||||
|
* null} value when registering for the mobile network type to receive
|
||||||
|
* notifications for all mobile networks. For additional details see {@link
|
||||||
|
* TelephonyManager#getSubscriberId()}.
|
||||||
* @param thresholdBytes Threshold in bytes to be notified on.
|
* @param thresholdBytes Threshold in bytes to be notified on.
|
||||||
* @param callback The {@link UsageCallback} that the system will call when data usage
|
* @param callback The {@link UsageCallback} that the system will call when data usage
|
||||||
* has exceeded the specified threshold.
|
* has exceeded the specified threshold.
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
|||||||
return builder.append("}").toString();
|
return builder.append("}").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToProto(ProtoOutputStream proto, long tag) {
|
public void dumpDebug(ProtoOutputStream proto, long tag) {
|
||||||
final long start = proto.start(tag);
|
final long start = proto.start(tag);
|
||||||
|
|
||||||
proto.write(NetworkIdentityProto.TYPE, mType);
|
proto.write(NetworkIdentityProto.TYPE, mType);
|
||||||
|
|||||||
@@ -698,7 +698,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToProto(ProtoOutputStream proto, long tag) {
|
public void dumpDebug(ProtoOutputStream proto, long tag) {
|
||||||
final long start = proto.start(tag);
|
final long start = proto.start(tag);
|
||||||
|
|
||||||
proto.write(NetworkStatsHistoryProto.BUCKET_DURATION_MS, bucketDuration);
|
proto.write(NetworkStatsHistoryProto.BUCKET_DURATION_MS, bucketDuration);
|
||||||
@@ -707,11 +707,11 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
final long startBucket = proto.start(NetworkStatsHistoryProto.BUCKETS);
|
final long startBucket = proto.start(NetworkStatsHistoryProto.BUCKETS);
|
||||||
|
|
||||||
proto.write(NetworkStatsHistoryBucketProto.BUCKET_START_MS, bucketStart[i]);
|
proto.write(NetworkStatsHistoryBucketProto.BUCKET_START_MS, bucketStart[i]);
|
||||||
writeToProto(proto, NetworkStatsHistoryBucketProto.RX_BYTES, rxBytes, i);
|
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_BYTES, rxBytes, i);
|
||||||
writeToProto(proto, NetworkStatsHistoryBucketProto.RX_PACKETS, rxPackets, i);
|
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_PACKETS, rxPackets, i);
|
||||||
writeToProto(proto, NetworkStatsHistoryBucketProto.TX_BYTES, txBytes, i);
|
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_BYTES, txBytes, i);
|
||||||
writeToProto(proto, NetworkStatsHistoryBucketProto.TX_PACKETS, txPackets, i);
|
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_PACKETS, txPackets, i);
|
||||||
writeToProto(proto, NetworkStatsHistoryBucketProto.OPERATIONS, operations, i);
|
dumpDebug(proto, NetworkStatsHistoryBucketProto.OPERATIONS, operations, i);
|
||||||
|
|
||||||
proto.end(startBucket);
|
proto.end(startBucket);
|
||||||
}
|
}
|
||||||
@@ -719,7 +719,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
proto.end(start);
|
proto.end(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeToProto(ProtoOutputStream proto, long tag, long[] array, int index) {
|
private static void dumpDebug(ProtoOutputStream proto, long tag, long[] array, int index) {
|
||||||
if (array != null) {
|
if (array != null) {
|
||||||
proto.write(tag, array[index]);
|
proto.write(tag, array[index]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -775,17 +775,10 @@ public class TrafficStats {
|
|||||||
* @see android.content.pm.ApplicationInfo#uid
|
* @see android.content.pm.ApplicationInfo#uid
|
||||||
*/
|
*/
|
||||||
public static long getUidTxBytes(int uid) {
|
public static long getUidTxBytes(int uid) {
|
||||||
// This isn't actually enforcing any security; it just returns the
|
try {
|
||||||
// unsupported value. The real filtering is done at the kernel level.
|
return getStatsService().getUidStats(uid, TYPE_TX_BYTES);
|
||||||
final int callingUid = android.os.Process.myUid();
|
} catch (RemoteException e) {
|
||||||
if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
|
throw e.rethrowFromSystemServer();
|
||||||
try {
|
|
||||||
return getStatsService().getUidStats(uid, TYPE_TX_BYTES);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return UNSUPPORTED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,17 +801,10 @@ public class TrafficStats {
|
|||||||
* @see android.content.pm.ApplicationInfo#uid
|
* @see android.content.pm.ApplicationInfo#uid
|
||||||
*/
|
*/
|
||||||
public static long getUidRxBytes(int uid) {
|
public static long getUidRxBytes(int uid) {
|
||||||
// This isn't actually enforcing any security; it just returns the
|
try {
|
||||||
// unsupported value. The real filtering is done at the kernel level.
|
return getStatsService().getUidStats(uid, TYPE_RX_BYTES);
|
||||||
final int callingUid = android.os.Process.myUid();
|
} catch (RemoteException e) {
|
||||||
if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
|
throw e.rethrowFromSystemServer();
|
||||||
try {
|
|
||||||
return getStatsService().getUidStats(uid, TYPE_RX_BYTES);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return UNSUPPORTED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,17 +827,10 @@ public class TrafficStats {
|
|||||||
* @see android.content.pm.ApplicationInfo#uid
|
* @see android.content.pm.ApplicationInfo#uid
|
||||||
*/
|
*/
|
||||||
public static long getUidTxPackets(int uid) {
|
public static long getUidTxPackets(int uid) {
|
||||||
// This isn't actually enforcing any security; it just returns the
|
try {
|
||||||
// unsupported value. The real filtering is done at the kernel level.
|
return getStatsService().getUidStats(uid, TYPE_TX_PACKETS);
|
||||||
final int callingUid = android.os.Process.myUid();
|
} catch (RemoteException e) {
|
||||||
if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
|
throw e.rethrowFromSystemServer();
|
||||||
try {
|
|
||||||
return getStatsService().getUidStats(uid, TYPE_TX_PACKETS);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return UNSUPPORTED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,17 +853,10 @@ public class TrafficStats {
|
|||||||
* @see android.content.pm.ApplicationInfo#uid
|
* @see android.content.pm.ApplicationInfo#uid
|
||||||
*/
|
*/
|
||||||
public static long getUidRxPackets(int uid) {
|
public static long getUidRxPackets(int uid) {
|
||||||
// This isn't actually enforcing any security; it just returns the
|
try {
|
||||||
// unsupported value. The real filtering is done at the kernel level.
|
return getStatsService().getUidStats(uid, TYPE_RX_PACKETS);
|
||||||
final int callingUid = android.os.Process.myUid();
|
} catch (RemoteException e) {
|
||||||
if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
|
throw e.rethrowFromSystemServer();
|
||||||
try {
|
|
||||||
return getStatsService().getUidStats(uid, TYPE_RX_PACKETS);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return UNSUPPORTED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,11 +170,11 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
|||||||
return ident.compareTo(anotherIdent);
|
return ident.compareTo(anotherIdent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToProto(ProtoOutputStream proto, long tag) {
|
public void dumpDebug(ProtoOutputStream proto, long tag) {
|
||||||
final long start = proto.start(tag);
|
final long start = proto.start(tag);
|
||||||
|
|
||||||
for (NetworkIdentity ident : this) {
|
for (NetworkIdentity ident : this) {
|
||||||
ident.writeToProto(proto, NetworkIdentitySetProto.IDENTITIES);
|
ident.dumpDebug(proto, NetworkIdentitySetProto.IDENTITIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
proto.end(start);
|
proto.end(start);
|
||||||
|
|||||||
@@ -663,7 +663,7 @@ public class NetworkStatsCollection implements FileRotator.Reader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToProto(ProtoOutputStream proto, long tag) {
|
public void dumpDebug(ProtoOutputStream proto, long tag) {
|
||||||
final long start = proto.start(tag);
|
final long start = proto.start(tag);
|
||||||
|
|
||||||
for (Key key : getSortedKeys()) {
|
for (Key key : getSortedKeys()) {
|
||||||
@@ -671,7 +671,7 @@ public class NetworkStatsCollection implements FileRotator.Reader {
|
|||||||
|
|
||||||
// Key
|
// Key
|
||||||
final long startKey = proto.start(NetworkStatsCollectionStatsProto.KEY);
|
final long startKey = proto.start(NetworkStatsCollectionStatsProto.KEY);
|
||||||
key.ident.writeToProto(proto, NetworkStatsCollectionKeyProto.IDENTITY);
|
key.ident.dumpDebug(proto, NetworkStatsCollectionKeyProto.IDENTITY);
|
||||||
proto.write(NetworkStatsCollectionKeyProto.UID, key.uid);
|
proto.write(NetworkStatsCollectionKeyProto.UID, key.uid);
|
||||||
proto.write(NetworkStatsCollectionKeyProto.SET, key.set);
|
proto.write(NetworkStatsCollectionKeyProto.SET, key.set);
|
||||||
proto.write(NetworkStatsCollectionKeyProto.TAG, key.tag);
|
proto.write(NetworkStatsCollectionKeyProto.TAG, key.tag);
|
||||||
@@ -679,7 +679,7 @@ public class NetworkStatsCollection implements FileRotator.Reader {
|
|||||||
|
|
||||||
// Value
|
// Value
|
||||||
final NetworkStatsHistory history = mStats.get(key);
|
final NetworkStatsHistory history = mStats.get(key);
|
||||||
history.writeToProto(proto, NetworkStatsCollectionStatsProto.HISTORY);
|
history.dumpDebug(proto, NetworkStatsCollectionStatsProto.HISTORY);
|
||||||
proto.end(startStats);
|
proto.end(startStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -469,12 +469,12 @@ public class NetworkStatsRecorder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToProtoLocked(ProtoOutputStream proto, long tag) {
|
public void dumpDebugLocked(ProtoOutputStream proto, long tag) {
|
||||||
final long start = proto.start(tag);
|
final long start = proto.start(tag);
|
||||||
if (mPending != null) {
|
if (mPending != null) {
|
||||||
proto.write(NetworkStatsRecorderProto.PENDING_TOTAL_BYTES, mPending.getTotalBytes());
|
proto.write(NetworkStatsRecorderProto.PENDING_TOTAL_BYTES, mPending.getTotalBytes());
|
||||||
}
|
}
|
||||||
getOrLoadCompleteLocked().writeToProto(proto, NetworkStatsRecorderProto.COMPLETE_HISTORY);
|
getOrLoadCompleteLocked().dumpDebug(proto, NetworkStatsRecorderProto.COMPLETE_HISTORY);
|
||||||
proto.end(start);
|
proto.end(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.server.net;
|
package com.android.server.net;
|
||||||
|
|
||||||
import static android.Manifest.permission.ACCESS_NETWORK_STATE;
|
|
||||||
import static android.Manifest.permission.NETWORK_STATS_PROVIDER;
|
import static android.Manifest.permission.NETWORK_STATS_PROVIDER;
|
||||||
import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
|
import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
|
||||||
import static android.Manifest.permission.UPDATE_DEVICE_STATS;
|
import static android.Manifest.permission.UPDATE_DEVICE_STATS;
|
||||||
@@ -48,6 +47,7 @@ import static android.net.NetworkTemplate.buildTemplateMobileWildcard;
|
|||||||
import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
|
import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
|
||||||
import static android.net.TrafficStats.KB_IN_BYTES;
|
import static android.net.TrafficStats.KB_IN_BYTES;
|
||||||
import static android.net.TrafficStats.MB_IN_BYTES;
|
import static android.net.TrafficStats.MB_IN_BYTES;
|
||||||
|
import static android.net.TrafficStats.UNSUPPORTED;
|
||||||
import static android.os.Trace.TRACE_TAG_NETWORK;
|
import static android.os.Trace.TRACE_TAG_NETWORK;
|
||||||
import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED;
|
import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED;
|
||||||
import static android.provider.Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED;
|
import static android.provider.Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED;
|
||||||
@@ -892,7 +892,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public NetworkStats getDataLayerSnapshotForUid(int uid) throws RemoteException {
|
public NetworkStats getDataLayerSnapshotForUid(int uid) throws RemoteException {
|
||||||
if (Binder.getCallingUid() != uid) {
|
if (Binder.getCallingUid() != uid) {
|
||||||
mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
|
Log.w(TAG, "Snapshots only available for calling UID");
|
||||||
|
return new NetworkStats(SystemClock.elapsedRealtime(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: switch to data layer stats once kernel exports
|
// TODO: switch to data layer stats once kernel exports
|
||||||
@@ -1068,6 +1069,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getUidStats(int uid, int type) {
|
public long getUidStats(int uid, int type) {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
|
if (callingUid != android.os.Process.SYSTEM_UID && callingUid != uid) {
|
||||||
|
return UNSUPPORTED;
|
||||||
|
}
|
||||||
return nativeGetUidStat(uid, type, checkBpfStatsEnable());
|
return nativeGetUidStat(uid, type, checkBpfStatsEnable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1851,10 +1856,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
dumpInterfaces(proto, NetworkStatsServiceDumpProto.ACTIVE_INTERFACES, mActiveIfaces);
|
dumpInterfaces(proto, NetworkStatsServiceDumpProto.ACTIVE_INTERFACES, mActiveIfaces);
|
||||||
dumpInterfaces(proto, NetworkStatsServiceDumpProto.ACTIVE_UID_INTERFACES, mActiveUidIfaces);
|
dumpInterfaces(proto, NetworkStatsServiceDumpProto.ACTIVE_UID_INTERFACES, mActiveUidIfaces);
|
||||||
mDevRecorder.writeToProtoLocked(proto, NetworkStatsServiceDumpProto.DEV_STATS);
|
mDevRecorder.dumpDebugLocked(proto, NetworkStatsServiceDumpProto.DEV_STATS);
|
||||||
mXtRecorder.writeToProtoLocked(proto, NetworkStatsServiceDumpProto.XT_STATS);
|
mXtRecorder.dumpDebugLocked(proto, NetworkStatsServiceDumpProto.XT_STATS);
|
||||||
mUidRecorder.writeToProtoLocked(proto, NetworkStatsServiceDumpProto.UID_STATS);
|
mUidRecorder.dumpDebugLocked(proto, NetworkStatsServiceDumpProto.UID_STATS);
|
||||||
mUidTagRecorder.writeToProtoLocked(proto, NetworkStatsServiceDumpProto.UID_TAG_STATS);
|
mUidTagRecorder.dumpDebugLocked(proto, NetworkStatsServiceDumpProto.UID_TAG_STATS);
|
||||||
|
|
||||||
proto.flush();
|
proto.flush();
|
||||||
}
|
}
|
||||||
@@ -1865,7 +1870,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final long start = proto.start(tag);
|
final long start = proto.start(tag);
|
||||||
|
|
||||||
proto.write(NetworkInterfaceProto.INTERFACE, ifaces.keyAt(i));
|
proto.write(NetworkInterfaceProto.INTERFACE, ifaces.keyAt(i));
|
||||||
ifaces.valueAt(i).writeToProto(proto, NetworkInterfaceProto.IDENTITIES);
|
ifaces.valueAt(i).dumpDebug(proto, NetworkInterfaceProto.IDENTITIES);
|
||||||
|
|
||||||
proto.end(start);
|
proto.end(start);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user