Snap for 4693621 from 07a75e0f9f93980ea52e3ff337c8f4da504fb8e2 to pi-release

Change-Id: I8e050f7507a6553a58714dc85fcfbf9c30f18b81
This commit is contained in:
android-build-team Robot
2018-04-01 07:24:29 +00:00
5 changed files with 79 additions and 31 deletions

View File

@@ -24,7 +24,6 @@ import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.IntArray; import android.util.IntArray;
import android.util.Log; import android.util.Log;
@@ -98,9 +97,8 @@ public final class NetworkStats implements AutoCloseable {
/** @hide */ /** @hide */
NetworkStats(Context context, NetworkTemplate template, int flags, long startTimestamp, NetworkStats(Context context, NetworkTemplate template, int flags, long startTimestamp,
long endTimestamp) throws RemoteException, SecurityException { long endTimestamp, INetworkStatsService statsService)
final INetworkStatsService statsService = INetworkStatsService.Stub.asInterface( throws RemoteException, SecurityException {
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
// Open network stats session // Open network stats session
mSession = statsService.openSessionForUsageStats(flags, context.getOpPackageName()); mSession = statsService.openSessionForUsageStats(flags, context.getOpPackageName());
mCloseGuard.open("close"); mCloseGuard.open("close");

View File

@@ -37,6 +37,8 @@ import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException; import android.os.ServiceManager.ServiceNotFoundException;
import android.util.Log; import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
/** /**
* Provides access to network usage history and statistics. Usage data is collected in * Provides access to network usage history and statistics. Usage data is collected in
* discrete bins of time called 'Buckets'. See {@link NetworkStats.Bucket} for details. * discrete bins of time called 'Buckets'. See {@link NetworkStats.Bucket} for details.
@@ -107,9 +109,15 @@ public class NetworkStatsManager {
* {@hide} * {@hide}
*/ */
public NetworkStatsManager(Context context) throws ServiceNotFoundException { public NetworkStatsManager(Context context) throws ServiceNotFoundException {
this(context, INetworkStatsService.Stub.asInterface(
ServiceManager.getServiceOrThrow(Context.NETWORK_STATS_SERVICE)));
}
/** @hide */
@VisibleForTesting
public NetworkStatsManager(Context context, INetworkStatsService service) {
mContext = context; mContext = context;
mService = INetworkStatsService.Stub.asInterface( mService = service;
ServiceManager.getServiceOrThrow(Context.NETWORK_STATS_SERVICE));
setPollOnOpen(true); setPollOnOpen(true);
} }
@@ -135,7 +143,8 @@ public class NetworkStatsManager {
public Bucket querySummaryForDevice(NetworkTemplate template, public Bucket querySummaryForDevice(NetworkTemplate template,
long startTime, long endTime) throws SecurityException, RemoteException { long startTime, long endTime) throws SecurityException, RemoteException {
Bucket bucket = null; Bucket bucket = null;
NetworkStats stats = new NetworkStats(mContext, template, mFlags, startTime, endTime); NetworkStats stats = new NetworkStats(mContext, template, mFlags, startTime, endTime,
mService);
bucket = stats.getDeviceSummaryForNetwork(); bucket = stats.getDeviceSummaryForNetwork();
stats.close(); stats.close();
@@ -208,7 +217,7 @@ public class NetworkStatsManager {
} }
NetworkStats stats; NetworkStats stats;
stats = new NetworkStats(mContext, template, mFlags, startTime, endTime); stats = new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
stats.startSummaryEnumeration(); stats.startSummaryEnumeration();
stats.close(); stats.close();
@@ -245,7 +254,7 @@ public class NetworkStatsManager {
} }
NetworkStats result; NetworkStats result;
result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
result.startSummaryEnumeration(); result.startSummaryEnumeration();
return result; return result;
@@ -295,7 +304,7 @@ public class NetworkStatsManager {
NetworkStats result; NetworkStats result;
try { try {
result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
result.startHistoryEnumeration(uid, tag); result.startHistoryEnumeration(uid, tag);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Error while querying stats for uid=" + uid + " tag=" + tag, e); Log.e(TAG, "Error while querying stats for uid=" + uid + " tag=" + tag, e);
@@ -341,7 +350,7 @@ public class NetworkStatsManager {
} }
NetworkStats result; NetworkStats result;
result = new NetworkStats(mContext, template, mFlags, startTime, endTime); result = new NetworkStats(mContext, template, mFlags, startTime, endTime, mService);
result.startUserUidEnumeration(); result.startUserUidEnumeration();
return result; return result;
} }
@@ -451,19 +460,20 @@ public class NetworkStatsManager {
} }
private static NetworkTemplate createTemplate(int networkType, String subscriberId) { private static NetworkTemplate createTemplate(int networkType, String subscriberId) {
NetworkTemplate template = null; final NetworkTemplate template;
switch (networkType) { switch (networkType) {
case ConnectivityManager.TYPE_MOBILE: { case ConnectivityManager.TYPE_MOBILE:
template = NetworkTemplate.buildTemplateMobileAll(subscriberId); template = subscriberId == null
} break; ? NetworkTemplate.buildTemplateMobileWildcard()
case ConnectivityManager.TYPE_WIFI: { : NetworkTemplate.buildTemplateMobileAll(subscriberId);
break;
case ConnectivityManager.TYPE_WIFI:
template = NetworkTemplate.buildTemplateWifiWildcard(); template = NetworkTemplate.buildTemplateWifiWildcard();
} break; break;
default: { default:
throw new IllegalArgumentException("Cannot create template for network type " throw new IllegalArgumentException("Cannot create template for network type "
+ networkType + ", subscriberId '" + networkType + ", subscriberId '"
+ NetworkIdentity.scrubSubscriberId(subscriberId) + "'."); + NetworkIdentity.scrubSubscriberId(subscriberId) + "'.");
}
} }
return template; return template;
} }

View File

@@ -56,7 +56,8 @@ public final class IpSecAlgorithm implements Parcelable {
* new applications and is provided for legacy compatibility with 3gpp infrastructure.</b> * new applications and is provided for legacy compatibility with 3gpp infrastructure.</b>
* *
* <p>Keys for this algorithm must be 128 bits in length. * <p>Keys for this algorithm must be 128 bits in length.
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 128. *
* <p>Valid truncation lengths are multiples of 8 bits from 96 to 128.
*/ */
public static final String AUTH_HMAC_MD5 = "hmac(md5)"; public static final String AUTH_HMAC_MD5 = "hmac(md5)";
@@ -65,7 +66,8 @@ public final class IpSecAlgorithm implements Parcelable {
* new applications and is provided for legacy compatibility with 3gpp infrastructure.</b> * new applications and is provided for legacy compatibility with 3gpp infrastructure.</b>
* *
* <p>Keys for this algorithm must be 160 bits in length. * <p>Keys for this algorithm must be 160 bits in length.
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 160. *
* <p>Valid truncation lengths are multiples of 8 bits from 96 to 160.
*/ */
public static final String AUTH_HMAC_SHA1 = "hmac(sha1)"; public static final String AUTH_HMAC_SHA1 = "hmac(sha1)";
@@ -73,7 +75,8 @@ public final class IpSecAlgorithm implements Parcelable {
* SHA256 HMAC Authentication/Integrity Algorithm. * SHA256 HMAC Authentication/Integrity Algorithm.
* *
* <p>Keys for this algorithm must be 256 bits in length. * <p>Keys for this algorithm must be 256 bits in length.
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 256. *
* <p>Valid truncation lengths are multiples of 8 bits from 96 to 256.
*/ */
public static final String AUTH_HMAC_SHA256 = "hmac(sha256)"; public static final String AUTH_HMAC_SHA256 = "hmac(sha256)";
@@ -81,7 +84,8 @@ public final class IpSecAlgorithm implements Parcelable {
* SHA384 HMAC Authentication/Integrity Algorithm. * SHA384 HMAC Authentication/Integrity Algorithm.
* *
* <p>Keys for this algorithm must be 384 bits in length. * <p>Keys for this algorithm must be 384 bits in length.
* <p>Valid truncation lengths are multiples of 8 bits from 192 to (default) 384. *
* <p>Valid truncation lengths are multiples of 8 bits from 192 to 384.
*/ */
public static final String AUTH_HMAC_SHA384 = "hmac(sha384)"; public static final String AUTH_HMAC_SHA384 = "hmac(sha384)";
@@ -89,7 +93,8 @@ public final class IpSecAlgorithm implements Parcelable {
* SHA512 HMAC Authentication/Integrity Algorithm. * SHA512 HMAC Authentication/Integrity Algorithm.
* *
* <p>Keys for this algorithm must be 512 bits in length. * <p>Keys for this algorithm must be 512 bits in length.
* <p>Valid truncation lengths are multiples of 8 bits from 256 to (default) 512. *
* <p>Valid truncation lengths are multiples of 8 bits from 256 to 512.
*/ */
public static final String AUTH_HMAC_SHA512 = "hmac(sha512)"; public static final String AUTH_HMAC_SHA512 = "hmac(sha512)";
@@ -112,6 +117,7 @@ public final class IpSecAlgorithm implements Parcelable {
AUTH_HMAC_MD5, AUTH_HMAC_MD5,
AUTH_HMAC_SHA1, AUTH_HMAC_SHA1,
AUTH_HMAC_SHA256, AUTH_HMAC_SHA256,
AUTH_HMAC_SHA384,
AUTH_HMAC_SHA512, AUTH_HMAC_SHA512,
AUTH_CRYPT_AES_GCM AUTH_CRYPT_AES_GCM
}) })
@@ -126,11 +132,14 @@ public final class IpSecAlgorithm implements Parcelable {
* Creates an IpSecAlgorithm of one of the supported types. Supported algorithm names are * Creates an IpSecAlgorithm of one of the supported types. Supported algorithm names are
* defined as constants in this class. * defined as constants in this class.
* *
* <p>For algorithms that produce an integrity check value, the truncation length is a required
* parameter. See {@link #IpSecAlgorithm(String algorithm, byte[] key, int truncLenBits)}
*
* @param algorithm name of the algorithm. * @param algorithm name of the algorithm.
* @param key key padded to a multiple of 8 bits. * @param key key padded to a multiple of 8 bits.
*/ */
public IpSecAlgorithm(@NonNull @AlgorithmName String algorithm, @NonNull byte[] key) { public IpSecAlgorithm(@NonNull @AlgorithmName String algorithm, @NonNull byte[] key) {
this(algorithm, key, key.length * 8); this(algorithm, key, 0);
} }
/** /**
@@ -228,6 +237,7 @@ public final class IpSecAlgorithm implements Parcelable {
case AUTH_CRYPT_AES_GCM: case AUTH_CRYPT_AES_GCM:
// The keying material for GCM is a key plus a 32-bit salt // The keying material for GCM is a key plus a 32-bit salt
isValidLen = keyLen == 128 + 32 || keyLen == 192 + 32 || keyLen == 256 + 32; isValidLen = keyLen == 128 + 32 || keyLen == 192 + 32 || keyLen == 256 + 32;
isValidTruncLen = truncLen == 64 || truncLen == 96 || truncLen == 128;
break; break;
default: default:
throw new IllegalArgumentException("Couldn't find an algorithm: " + name); throw new IllegalArgumentException("Couldn't find an algorithm: " + name);

View File

@@ -274,7 +274,8 @@ public final class IpSecManager {
* *
* @param destinationAddress the destination address for traffic bearing the requested SPI. * @param destinationAddress the destination address for traffic bearing the requested SPI.
* For inbound traffic, the destination should be an address currently assigned on-device. * For inbound traffic, the destination should be an address currently assigned on-device.
* @param requestedSpi the requested SPI, or '0' to allocate a random SPI * @param requestedSpi the requested SPI, or '0' to allocate a random SPI. The range 1-255 is
* reserved and may not be used. See RFC 4303 Section 2.1.
* @return the reserved SecurityParameterIndex * @return the reserved SecurityParameterIndex
* @throws {@link #ResourceUnavailableException} indicating that too many SPIs are * @throws {@link #ResourceUnavailableException} indicating that too many SPIs are
* currently allocated for this user * currently allocated for this user
@@ -305,6 +306,19 @@ public final class IpSecManager {
* will throw IOException if the user deactivates the transform (by calling {@link * will throw IOException if the user deactivates the transform (by calling {@link
* IpSecTransform#close()}) without calling {@link #removeTransportModeTransforms}. * IpSecTransform#close()}) without calling {@link #removeTransportModeTransforms}.
* *
* <p>Note that when applied to TCP sockets, calling {@link IpSecTransform#close()} on an
* applied transform before completion of graceful shutdown may result in the shutdown sequence
* failing to complete. As such, applications requiring graceful shutdown MUST close the socket
* prior to deactivating the applied transform. Socket closure may be performed asynchronously
* (in batches), so the returning of a close function does not guarantee shutdown of a socket.
* Setting an SO_LINGER timeout results in socket closure being performed synchronously, and is
* sufficient to ensure shutdown.
*
* Specifically, if the transform is deactivated (by calling {@link IpSecTransform#close()}),
* prior to the socket being closed, the standard [FIN - FIN/ACK - ACK], or the reset [RST]
* packets are dropped due to the lack of a valid Transform. Similarly, if a socket without the
* SO_LINGER option set is closed, the delayed/batched FIN packets may be dropped.
*
* <h4>Rekey Procedure</h4> * <h4>Rekey Procedure</h4>
* *
* <p>When applying a new tranform to a socket in the outbound direction, the previous transform * <p>When applying a new tranform to a socket in the outbound direction, the previous transform
@@ -373,6 +387,19 @@ public final class IpSecManager {
* will throw IOException if the user deactivates the transform (by calling {@link * will throw IOException if the user deactivates the transform (by calling {@link
* IpSecTransform#close()}) without calling {@link #removeTransportModeTransforms}. * IpSecTransform#close()}) without calling {@link #removeTransportModeTransforms}.
* *
* <p>Note that when applied to TCP sockets, calling {@link IpSecTransform#close()} on an
* applied transform before completion of graceful shutdown may result in the shutdown sequence
* failing to complete. As such, applications requiring graceful shutdown MUST close the socket
* prior to deactivating the applied transform. Socket closure may be performed asynchronously
* (in batches), so the returning of a close function does not guarantee shutdown of a socket.
* Setting an SO_LINGER timeout results in socket closure being performed synchronously, and is
* sufficient to ensure shutdown.
*
* Specifically, if the transform is deactivated (by calling {@link IpSecTransform#close()}),
* prior to the socket being closed, the standard [FIN - FIN/ACK - ACK], or the reset [RST]
* packets are dropped due to the lack of a valid Transform. Similarly, if a socket without the
* SO_LINGER option set is closed, the delayed/batched FIN packets may be dropped.
*
* <h4>Rekey Procedure</h4> * <h4>Rekey Procedure</h4>
* *
* <p>When applying a new tranform to a socket in the outbound direction, the previous transform * <p>When applying a new tranform to a socket in the outbound direction, the previous transform
@@ -476,7 +503,7 @@ public final class IpSecManager {
* signalling and UDP encapsulated IPsec traffic. Instances can be obtained by calling {@link * signalling and UDP encapsulated IPsec traffic. Instances can be obtained by calling {@link
* IpSecManager#openUdpEncapsulationSocket}. The provided socket cannot be re-bound by the * IpSecManager#openUdpEncapsulationSocket}. The provided socket cannot be re-bound by the
* caller. The caller should not close the {@code FileDescriptor} returned by {@link * caller. The caller should not close the {@code FileDescriptor} returned by {@link
* #getSocket}, but should use {@link #close} instead. * #getFileDescriptor}, but should use {@link #close} instead.
* *
* <p>Allowing the user to close or unbind a UDP encapsulation socket could impact the traffic * <p>Allowing the user to close or unbind a UDP encapsulation socket could impact the traffic
* of the next user who binds to that port. To prevent this scenario, these sockets are held * of the next user who binds to that port. To prevent this scenario, these sockets are held
@@ -515,8 +542,8 @@ public final class IpSecManager {
mCloseGuard.open("constructor"); mCloseGuard.open("constructor");
} }
/** Get the wrapped socket. */ /** Get the encapsulation socket's file descriptor. */
public FileDescriptor getSocket() { public FileDescriptor getFileDescriptor() {
if (mPfd == null) { if (mPfd == null) {
return null; return null;
} }

View File

@@ -931,7 +931,7 @@ public class IpSecService extends IIpSecService.Stub {
return mPort; return mPort;
} }
public FileDescriptor getSocket() { public FileDescriptor getFileDescriptor() {
return mSocket; return mSocket;
} }
@@ -1065,7 +1065,10 @@ public class IpSecService extends IIpSecService.Stub {
public synchronized IpSecSpiResponse allocateSecurityParameterIndex( public synchronized IpSecSpiResponse allocateSecurityParameterIndex(
String destinationAddress, int requestedSpi, IBinder binder) throws RemoteException { String destinationAddress, int requestedSpi, IBinder binder) throws RemoteException {
checkInetAddress(destinationAddress); checkInetAddress(destinationAddress);
/* requestedSpi can be anything in the int range, so no check is needed. */ // RFC 4303 Section 2.1 - 0=local, 1-255=reserved.
if (requestedSpi > 0 && requestedSpi < 256) {
throw new IllegalArgumentException("ESP SPI must not be in the range of 0-255.");
}
checkNotNull(binder, "Null Binder passed to allocateSecurityParameterIndex"); checkNotNull(binder, "Null Binder passed to allocateSecurityParameterIndex");
UserRecord userRecord = mUserResourceTracker.getUserRecord(Binder.getCallingUid()); UserRecord userRecord = mUserResourceTracker.getUserRecord(Binder.getCallingUid());