summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapi/current.txt15
-rw-r--r--api/system-current.txt19
-rw-r--r--api/test-current.txt4
-rw-r--r--cmds/statsd/Android.bp6
-rw-r--r--core/java/android/app/AppComponentFactory.java18
-rw-r--r--core/java/android/app/LoadedApk.java26
-rw-r--r--core/java/android/net/ConnectivityManager.java6
-rw-r--r--core/java/android/net/SSLCertificateSocketFactory.java17
-rw-r--r--core/java/android/net/VpnService.java3
-rw-r--r--core/jni/android_net_LocalSocketImpl.cpp174
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp2
-rw-r--r--core/res/res/values/arrays.xml16
-rw-r--r--core/res/res/values/colors_device_defaults.xml2
-rw-r--r--core/res/res/values/symbols.xml2
-rw-r--r--core/res/res/values/themes_device_defaults.xml2
-rw-r--r--media/java/android/media/MediaHTTPConnection.java21
-rw-r--r--packages/CaptivePortalLogin/AndroidManifest.xml4
-rw-r--r--packages/NetworkStack/AndroidManifest.xml4
-rw-r--r--packages/NetworkStackPermissionStub/AndroidManifest.xml4
-rw-r--r--packages/Shell/AndroidManifest.xml1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java19
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java46
-rw-r--r--services/core/java/com/android/server/connectivity/Nat464Xlat.java239
-rw-r--r--services/core/java/com/android/server/connectivity/NetworkAgentInfo.java33
-rw-r--r--services/core/java/com/android/server/pm/OtaDexoptService.java2
-rw-r--r--services/core/java/com/android/server/pm/PackageDexOptimizer.java6
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java6
-rw-r--r--telecomm/java/android/telecom/ConnectionRequest.java26
-rw-r--r--telephony/java/android/telephony/CellIdentityNr.java3
-rw-r--r--telephony/java/android/telephony/CellInfo.java5
-rw-r--r--telephony/java/android/telephony/DataSpecificRegistrationStates.java23
-rw-r--r--telephony/java/android/telephony/NetworkRegistrationState.java2
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java33
-rw-r--r--telephony/java/android/telephony/UiccCardInfo.java40
-rw-r--r--telephony/java/android/telephony/UiccSlotInfo.java44
-rw-r--r--telephony/java/android/telephony/ims/ImsConferenceState.java15
-rw-r--r--telephony/java/android/telephony/ims/ImsStreamMediaProfile.java23
-rw-r--r--tests/net/java/com/android/server/ConnectivityServiceTest.java129
-rw-r--r--tests/net/java/com/android/server/connectivity/Nat464XlatTest.java195
-rw-r--r--tools/apilint/apilint.py85
-rw-r--r--tools/apilint/apilint_test.py35
42 files changed, 940 insertions, 422 deletions
diff --git a/api/current.txt b/api/current.txt
index 71bd4596832f..dd265898dbe2 100755
--- a/api/current.txt
+++ b/api/current.txt
@@ -4203,10 +4203,9 @@ package android.app {
public class AppComponentFactory {
ctor public AppComponentFactory();
- method public android.content.pm.ApplicationInfo getApplicationInfo();
method @NonNull public android.app.Activity instantiateActivity(@NonNull ClassLoader, @NonNull String, @Nullable android.content.Intent) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException;
method @NonNull public android.app.Application instantiateApplication(@NonNull ClassLoader, @NonNull String) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException;
- method @NonNull public ClassLoader instantiateClassLoader(@NonNull ClassLoader);
+ method @NonNull public ClassLoader instantiateClassLoader(@NonNull ClassLoader, @NonNull android.content.pm.ApplicationInfo);
method @NonNull public android.content.ContentProvider instantiateProvider(@NonNull ClassLoader, @NonNull String) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException;
method @NonNull public android.content.BroadcastReceiver instantiateReceiver(@NonNull ClassLoader, @NonNull String, @Nullable android.content.Intent) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException;
method @NonNull public android.app.Service instantiateService(@NonNull ClassLoader, @NonNull String, @Nullable android.content.Intent) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException;
@@ -27855,7 +27854,7 @@ package android.net {
method public android.os.ParcelFileDescriptor establish();
method public android.net.VpnService.Builder setBlocking(boolean);
method public android.net.VpnService.Builder setConfigureIntent(android.app.PendingIntent);
- method public android.net.VpnService.Builder setHttpProxy(android.net.ProxyInfo);
+ method public android.net.VpnService.Builder setHttpProxy(@NonNull android.net.ProxyInfo);
method public android.net.VpnService.Builder setMetered(boolean);
method public android.net.VpnService.Builder setMtu(int);
method public android.net.VpnService.Builder setSession(String);
@@ -40417,6 +40416,7 @@ package android.system {
method public static void chown(String, int, int) throws android.system.ErrnoException;
method public static void close(java.io.FileDescriptor) throws android.system.ErrnoException;
method public static void connect(java.io.FileDescriptor, java.net.InetAddress, int) throws android.system.ErrnoException, java.net.SocketException;
+ method public static void connect(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
method public static java.io.FileDescriptor dup(java.io.FileDescriptor) throws android.system.ErrnoException;
method public static java.io.FileDescriptor dup2(java.io.FileDescriptor, int) throws android.system.ErrnoException;
method public static String[] environ();
@@ -42382,6 +42382,7 @@ package android.telephony {
field public static final int CONNECTION_UNKNOWN = 2147483647; // 0x7fffffff
field public static final android.os.Parcelable.Creator<android.telephony.CellInfo> CREATOR;
field public static final int UNAVAILABLE = 2147483647; // 0x7fffffff
+ field public static final long UNAVAILABLE_LONG = 9223372036854775807L; // 0x7fffffffffffffffL
}
public final class CellInfoCdma extends android.telephony.CellInfo implements android.os.Parcelable {
@@ -43071,7 +43072,7 @@ package android.telephony {
method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getSubscriberId();
method public String getTypeAllocationCode();
method public String getTypeAllocationCode(int);
- method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public java.util.List<android.telephony.UiccCardInfo> getUiccCardsInfo();
+ method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") @NonNull public java.util.List<android.telephony.UiccCardInfo> getUiccCardsInfo();
method @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVisualVoicemailPackageName();
method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVoiceMailAlphaTag();
method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVoiceMailNumber();
@@ -43238,13 +43239,13 @@ package android.telephony {
}
public final class UiccCardInfo implements android.os.Parcelable {
- ctor public UiccCardInfo(boolean, int, String, String, int);
method public int describeContents();
method public int getCardId();
- method public String getEid();
- method public String getIccId();
+ method @Nullable public String getEid();
+ method @Nullable public String getIccId();
method public int getSlotIndex();
method public boolean isEuicc();
+ method public boolean isRemovable();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.telephony.UiccCardInfo> CREATOR;
}
diff --git a/api/system-current.txt b/api/system-current.txt
index 231912c06e9c..d56cdecc5ebf 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5918,6 +5918,13 @@ package android.telephony {
field public static final int VSNCP_TIMEOUT = 2236; // 0x8bc
}
+ public final class DataSpecificRegistrationStates implements android.os.Parcelable {
+ method public int describeContents();
+ method @NonNull public android.telephony.LteVopsSupportInfo getLteVopsSupportInfo();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.telephony.DataSpecificRegistrationStates> CREATOR;
+ }
+
public final class DisconnectCause {
field public static final int ALREADY_DIALING = 72; // 0x48
field public static final int ANSWERED_ELSEWHERE = 52; // 0x34
@@ -6026,6 +6033,7 @@ package android.telephony {
method public int getAccessNetworkTechnology();
method public int[] getAvailableServices();
method public android.telephony.CellIdentity getCellIdentity();
+ method @Nullable public android.telephony.DataSpecificRegistrationStates getDataSpecificStates();
method public int getDomain();
method public int getRegState();
method public int getRejectCause();
@@ -6468,7 +6476,7 @@ package android.telephony {
}
public class UiccSlotInfo implements android.os.Parcelable {
- ctor public UiccSlotInfo(boolean, boolean, String, int, int, boolean);
+ ctor @Deprecated public UiccSlotInfo(boolean, boolean, String, int, int, boolean);
method public int describeContents();
method public String getCardId();
method public int getCardStateInfo();
@@ -6476,6 +6484,7 @@ package android.telephony {
method public boolean getIsEuicc();
method public boolean getIsExtendedApduSupported();
method public int getLogicalSlotIdx();
+ method public boolean isRemovable();
method public void writeToParcel(android.os.Parcel, int);
field public static final int CARD_STATE_INFO_ABSENT = 1; // 0x1
field public static final int CARD_STATE_INFO_ERROR = 3; // 0x3
@@ -7259,12 +7268,12 @@ package android.telephony.ims {
method public int describeContents();
method public int getAudioDirection();
method public int getAudioQuality();
- method public boolean getRttAudioSpeech();
method public int getRttMode();
method public int getVideoDirection();
method public int getVideoQuality();
+ method public boolean isReceivingRttAudio();
method public boolean isRttCall();
- method public void setRttAudioSpeech(boolean);
+ method public void setReceivingRttAudio(boolean);
method public void setRttMode(int);
method public void writeToParcel(android.os.Parcel, int);
field public static final int AUDIO_QUALITY_AMR = 1; // 0x1
@@ -7667,7 +7676,7 @@ package android.telephony.mbms {
package android.telephony.mbms.vendor {
- public class MbmsDownloadServiceBase extends android.os.Binder implements android.os.IInterface {
+ public class MbmsDownloadServiceBase extends android.os.Binder {
ctor public MbmsDownloadServiceBase();
method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
@@ -7700,7 +7709,7 @@ package android.telephony.mbms.vendor {
method public void updateGroupCall(int, long, java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>);
}
- public class MbmsStreamingServiceBase extends android.os.Binder implements android.os.IInterface {
+ public class MbmsStreamingServiceBase extends android.os.Binder {
ctor public MbmsStreamingServiceBase();
method public android.os.IBinder asBinder();
method public void dispose(int) throws android.os.RemoteException;
diff --git a/api/test-current.txt b/api/test-current.txt
index 62ef0b013cb9..400046bad74a 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -1519,7 +1519,7 @@ package android.telephony.mbms {
package android.telephony.mbms.vendor {
- public class MbmsDownloadServiceBase extends android.os.Binder implements android.os.IInterface {
+ public class MbmsDownloadServiceBase extends android.os.Binder {
ctor public MbmsDownloadServiceBase();
method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
@@ -1552,7 +1552,7 @@ package android.telephony.mbms.vendor {
method public void updateGroupCall(int, long, java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>);
}
- public class MbmsStreamingServiceBase extends android.os.Binder implements android.os.IInterface {
+ public class MbmsStreamingServiceBase extends android.os.Binder {
ctor public MbmsStreamingServiceBase();
method public android.os.IBinder asBinder();
method public void dispose(int) throws android.os.RemoteException;
diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp
index 5c3d17e30585..f178fa254e69 100644
--- a/cmds/statsd/Android.bp
+++ b/cmds/statsd/Android.bp
@@ -323,4 +323,8 @@ java_library {
},
}
-
+// Filegroup for statsd config proto definition.
+filegroup {
+ name: "statsd-config-proto-def",
+ srcs: ["src/statsd_config.proto"],
+}
diff --git a/core/java/android/app/AppComponentFactory.java b/core/java/android/app/AppComponentFactory.java
index ae632915dd2d..2cec7f0fc323 100644
--- a/core/java/android/app/AppComponentFactory.java
+++ b/core/java/android/app/AppComponentFactory.java
@@ -27,6 +27,7 @@ import android.content.pm.ApplicationInfo;
*
* @see #instantiateApplication
* @see #instantiateActivity
+ * @see #instantiateClassLoader
* @see #instantiateService
* @see #instantiateReceiver
* @see #instantiateProvider
@@ -39,8 +40,10 @@ public class AppComponentFactory {
* a custom class loader hierarchy.
*
* @param cl The default classloader instantiated by platform.
+ * @param aInfo Information about the application being loaded.
*/
- public @NonNull ClassLoader instantiateClassLoader(@NonNull ClassLoader cl) {
+ public @NonNull ClassLoader instantiateClassLoader(@NonNull ClassLoader cl,
+ @NonNull ApplicationInfo aInfo) {
return cl;
}
@@ -133,19 +136,6 @@ public class AppComponentFactory {
return (ContentProvider) cl.loadClass(className).newInstance();
}
- private ApplicationInfo mApplicationInfo = null;
-
- void setApplicationInfo(ApplicationInfo info) {
- mApplicationInfo = info;
- }
-
- /**
- * Returns the ApplicationInfo associated with this package.
- */
- public ApplicationInfo getApplicationInfo() {
- return mApplicationInfo;
- }
-
/**
* @hide
*/
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index ac33c169288b..3a76de442777 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -232,7 +232,8 @@ public final class LoadedApk {
mResources = Resources.getSystem();
mDefaultClassLoader = ClassLoader.getSystemClassLoader();
mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader);
- mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader);
+ mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
+ new ApplicationInfo(mApplicationInfo));
}
/**
@@ -243,19 +244,15 @@ public final class LoadedApk {
mApplicationInfo = info;
mDefaultClassLoader = classLoader;
mAppComponentFactory = createAppFactory(info, mDefaultClassLoader);
- mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader);
+ mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
+ new ApplicationInfo(mApplicationInfo));
}
private AppComponentFactory createAppFactory(ApplicationInfo appInfo, ClassLoader cl) {
if (appInfo.appComponentFactory != null && cl != null) {
try {
- AppComponentFactory factory = (AppComponentFactory) cl.loadClass(
- appInfo.appComponentFactory).newInstance();
- // Pass a copy of ApplicationInfo to the factory. Copying protects the framework
- // from apps which would override the factory and change ApplicationInfo contents.
- // ApplicationInfo is used to set up the default class loader.
- factory.setApplicationInfo(new ApplicationInfo(appInfo));
- return factory;
+ return (AppComponentFactory)
+ cl.loadClass(appInfo.appComponentFactory).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
Slog.e(TAG, "Unable to instantiate appComponentFactory", e);
}
@@ -712,8 +709,8 @@ public final class LoadedApk {
mDefaultClassLoader = ClassLoader.getSystemClassLoader();
}
mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader);
- mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader);
-
+ mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
+ new ApplicationInfo(mApplicationInfo));
return;
}
@@ -801,7 +798,8 @@ public final class LoadedApk {
}
if (mClassLoader == null) {
- mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader);
+ mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
+ new ApplicationInfo(mApplicationInfo));
}
return;
@@ -915,8 +913,10 @@ public final class LoadedApk {
// Call AppComponentFactory to select/create the main class loader of this app.
// Since this may call code in the app, mDefaultClassLoader must be fully set up
// before invoking the factory.
+ // Invoke with a copy of ApplicationInfo to protect against the app changing it.
if (mClassLoader == null) {
- mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader);
+ mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
+ new ApplicationInfo(mApplicationInfo));
}
}
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 92b30a440d69..24a907bd929e 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -3668,7 +3668,8 @@ public class ConnectivityManager {
/**
* Registers to receive notifications about all networks which satisfy the given
* {@link NetworkRequest}. The callbacks will continue to be called until
- * either the application exits or link #unregisterNetworkCallback(NetworkCallback)} is called.
+ * either the application exits or {@link #unregisterNetworkCallback(NetworkCallback)} is
+ * called.
*
* @param request {@link NetworkRequest} describing this request.
* @param networkCallback The {@link NetworkCallback} that the system will call as suitable
@@ -3684,7 +3685,8 @@ public class ConnectivityManager {
/**
* Registers to receive notifications about all networks which satisfy the given
* {@link NetworkRequest}. The callbacks will continue to be called until
- * either the application exits or link #unregisterNetworkCallback(NetworkCallback)} is called.
+ * either the application exits or {@link #unregisterNetworkCallback(NetworkCallback)} is
+ * called.
*
* @param request {@link NetworkRequest} describing this request.
* @param networkCallback The {@link NetworkCallback} that the system will call as suitable
diff --git a/core/java/android/net/SSLCertificateSocketFactory.java b/core/java/android/net/SSLCertificateSocketFactory.java
index 90dccb5b82d5..45860b3858ce 100644
--- a/core/java/android/net/SSLCertificateSocketFactory.java
+++ b/core/java/android/net/SSLCertificateSocketFactory.java
@@ -23,8 +23,7 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.RoSystemProperties;
-import com.android.org.conscrypt.Conscrypt;
-import com.android.org.conscrypt.OpenSSLContextImpl;
+import com.android.org.conscrypt.ClientSessionContext;
import com.android.org.conscrypt.OpenSSLSocketImpl;
import com.android.org.conscrypt.SSLClientSessionCache;
@@ -33,6 +32,8 @@ import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
@@ -40,6 +41,7 @@ import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
@@ -251,11 +253,12 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory {
private SSLSocketFactory makeSocketFactory(
KeyManager[] keyManagers, TrustManager[] trustManagers) {
try {
- OpenSSLContextImpl sslContext = (OpenSSLContextImpl) Conscrypt.newPreferredSSLContextSpi();
- sslContext.engineInit(keyManagers, trustManagers, null);
- sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
- return sslContext.engineGetSocketFactory();
- } catch (KeyManagementException e) {
+ SSLContext sslContext = SSLContext.getInstance("TLS", "AndroidOpenSSL");
+ sslContext.init(keyManagers, trustManagers, null);
+ ((ClientSessionContext) sslContext.getClientSessionContext())
+ .setPersistentCache(mSessionCache);
+ return sslContext.getSocketFactory();
+ } catch (KeyManagementException | NoSuchAlgorithmException | NoSuchProviderException e) {
Log.wtf(TAG, e);
return (SSLSocketFactory) SSLSocketFactory.getDefault(); // Fallback
}
diff --git a/core/java/android/net/VpnService.java b/core/java/android/net/VpnService.java
index 784f23311103..ebb1ae4bb795 100644
--- a/core/java/android/net/VpnService.java
+++ b/core/java/android/net/VpnService.java
@@ -19,6 +19,7 @@ package android.net;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
+import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
@@ -512,7 +513,7 @@ public class VpnService extends Service {
* Sets an HTTP proxy for the VPN network. This proxy is only a recommendation
* and it is possible that some apps will ignore it.
*/
- public Builder setHttpProxy(ProxyInfo proxyInfo) {
+ public Builder setHttpProxy(@NonNull ProxyInfo proxyInfo) {
mConfig.proxyInfo = proxyInfo;
return this;
}
diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp
index a1f2377041e8..1163b860977d 100644
--- a/core/jni/android_net_LocalSocketImpl.cpp
+++ b/core/jni/android_net_LocalSocketImpl.cpp
@@ -33,14 +33,16 @@
#include <unistd.h>
#include <sys/ioctl.h>
+#include <android-base/cmsg.h>
+#include <android-base/macros.h>
#include <cutils/sockets.h>
#include <netinet/tcp.h>
#include <nativehelper/ScopedUtfChars.h>
-namespace android {
+using android::base::ReceiveFileDescriptorVector;
+using android::base::SendFileDescriptorVector;
-template <typename T>
-void UNUSED(T t) {}
+namespace android {
static jfieldID field_inboundFileDescriptors;
static jfieldID field_outboundFileDescriptors;
@@ -118,67 +120,6 @@ socket_bind_local (JNIEnv *env, jobject object, jobject fileDescriptor,
}
/**
- * Processes ancillary data, handling only
- * SCM_RIGHTS. Creates appropriate objects and sets appropriate
- * fields in the LocalSocketImpl object. Returns 0 on success
- * or -1 if an exception was thrown.
- */
-static int socket_process_cmsg(JNIEnv *env, jobject thisJ, struct msghdr * pMsg)
-{
- struct cmsghdr *cmsgptr;
-
- for (cmsgptr = CMSG_FIRSTHDR(pMsg);
- cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(pMsg, cmsgptr)) {
-
- if (cmsgptr->cmsg_level != SOL_SOCKET) {
- continue;
- }
-
- if (cmsgptr->cmsg_type == SCM_RIGHTS) {
- int *pDescriptors = (int *)CMSG_DATA(cmsgptr);
- jobjectArray fdArray;
- int count
- = ((cmsgptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
-
- if (count < 0) {
- jniThrowException(env, "java/io/IOException",
- "invalid cmsg length");
- return -1;
- }
-
- fdArray = env->NewObjectArray(count, class_FileDescriptor, NULL);
-
- if (fdArray == NULL) {
- return -1;
- }
-
- for (int i = 0; i < count; i++) {
- jobject fdObject
- = jniCreateFileDescriptor(env, pDescriptors[i]);
-
- if (env->ExceptionCheck()) {
- return -1;
- }
-
- env->SetObjectArrayElement(fdArray, i, fdObject);
-
- if (env->ExceptionCheck()) {
- return -1;
- }
- }
-
- env->SetObjectField(thisJ, field_inboundFileDescriptors, fdArray);
-
- if (env->ExceptionCheck()) {
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-/**
* Reads data from a socket into buf, processing any ancillary data
* and adding it to thisJ.
*
@@ -189,47 +130,48 @@ static ssize_t socket_read_all(JNIEnv *env, jobject thisJ, int fd,
void *buffer, size_t len)
{
ssize_t ret;
- struct msghdr msg;
- struct iovec iv;
- unsigned char *buf = (unsigned char *)buffer;
- // Enough buffer for a pile of fd's. We throw an exception if
- // this buffer is too small.
- struct cmsghdr cmsgbuf[2*sizeof(cmsghdr) + 0x100];
-
- memset(&msg, 0, sizeof(msg));
- memset(&iv, 0, sizeof(iv));
-
- iv.iov_base = buf;
- iv.iov_len = len;
+ std::vector<android::base::unique_fd> received_fds;
- msg.msg_iov = &iv;
- msg.msg_iovlen = 1;
- msg.msg_control = cmsgbuf;
- msg.msg_controllen = sizeof(cmsgbuf);
-
- ret = TEMP_FAILURE_RETRY(recvmsg(fd, &msg, MSG_NOSIGNAL | MSG_CMSG_CLOEXEC));
-
- if (ret < 0 && errno == EPIPE) {
- // Treat this as an end of stream
- return 0;
- }
+ ret = ReceiveFileDescriptorVector(fd, buffer, len, 64, &received_fds);
if (ret < 0) {
+ if (errno == EPIPE) {
+ // Treat this as an end of stream
+ return 0;
+ }
+
jniThrowIOException(env, errno);
return -1;
}
- if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
- // To us, any of the above flags are a fatal error
+ if (received_fds.size() > 0) {
+ jobjectArray fdArray = env->NewObjectArray(received_fds.size(), class_FileDescriptor, NULL);
+
+ if (fdArray == NULL) {
+ // NewObjectArray has thrown.
+ return -1;
+ }
- jniThrowException(env, "java/io/IOException",
- "Unexpected error or truncation during recvmsg()");
+ for (size_t i = 0; i < received_fds.size(); i++) {
+ jobject fdObject = jniCreateFileDescriptor(env, received_fds[i].get());
- return -1;
- }
+ if (env->ExceptionCheck()) {
+ return -1;
+ }
+
+ env->SetObjectArrayElement(fdArray, i, fdObject);
+
+ if (env->ExceptionCheck()) {
+ return -1;
+ }
+ }
- if (ret >= 0) {
- socket_process_cmsg(env, thisJ, &msg);
+ for (auto &fd : received_fds) {
+ // The fds are stored in java.io.FileDescriptors now.
+ static_cast<void>(fd.release());
+ }
+
+ env->SetObjectField(thisJ, field_inboundFileDescriptors, fdArray);
}
return ret;
@@ -243,7 +185,6 @@ static ssize_t socket_read_all(JNIEnv *env, jobject thisJ, int fd,
static int socket_write_all(JNIEnv *env, jobject object, int fd,
void *buf, size_t len)
{
- ssize_t ret;
struct msghdr msg;
unsigned char *buffer = (unsigned char *)buf;
memset(&msg, 0, sizeof(msg));
@@ -256,14 +197,11 @@ static int socket_write_all(JNIEnv *env, jobject object, int fd,
return -1;
}
- struct cmsghdr *cmsg;
int countFds = outboundFds == NULL ? 0 : env->GetArrayLength(outboundFds);
- int fds[countFds];
- char msgbuf[CMSG_SPACE(countFds)];
+ std::vector<int> fds;
// Add any pending outbound file descriptors to the message
if (outboundFds != NULL) {
-
if (env->ExceptionCheck()) {
return -1;
}
@@ -274,47 +212,25 @@ static int socket_write_all(JNIEnv *env, jobject object, int fd,
return -1;
}
- fds[i] = jniGetFDFromFileDescriptor(env, fdObject);
+ fds.push_back(jniGetFDFromFileDescriptor(env, fdObject));
if (env->ExceptionCheck()) {
return -1;
}
}
-
- // See "man cmsg" really
- msg.msg_control = msgbuf;
- msg.msg_controllen = sizeof msgbuf;
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof fds);
- memcpy(CMSG_DATA(cmsg), fds, sizeof fds);
}
- // We only write our msg_control during the first write
- while (len > 0) {
- struct iovec iv;
- memset(&iv, 0, sizeof(iv));
-
- iv.iov_base = buffer;
- iv.iov_len = len;
-
- msg.msg_iov = &iv;
- msg.msg_iovlen = 1;
-
- do {
- ret = sendmsg(fd, &msg, MSG_NOSIGNAL);
- } while (ret < 0 && errno == EINTR);
+ ssize_t rc = SendFileDescriptorVector(fd, buffer, len, fds);
- if (ret < 0) {
+ while (rc != len) {
+ if (rc == -1) {
jniThrowIOException(env, errno);
return -1;
}
- buffer += ret;
- len -= ret;
+ buffer += rc;
+ len -= rc;
- // Wipes out any msg_control too
- memset(&msg, 0, sizeof(msg));
+ rc = send(fd, buffer, len, MSG_NOSIGNAL);
}
return 0;
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index bc1332adacbc..8216b616915c 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -892,6 +892,8 @@ static pid_t ForkCommon(JNIEnv* env, bool is_system_server,
// Turn fdsan back on.
android_fdsan_set_error_level(fdsan_error_level);
+ } else {
+ ALOGD("Forked child process %d", pid);
}
// We blocked SIGCHLD prior to a fork, we unblock it here.
diff --git a/core/res/res/values/arrays.xml b/core/res/res/values/arrays.xml
index 733878b9882b..8f2d6c3e02f4 100644
--- a/core/res/res/values/arrays.xml
+++ b/core/res/res/values/arrays.xml
@@ -185,4 +185,20 @@
<item>@string/app_info</item>
</string-array>
+ <!-- Device-specific array of SIM slot indexes which are are embedded eUICCs.
+ e.g. If a device has two physical slots with indexes 0, 1, and slot 1 is an
+ eUICC, then the value of this array should be:
+ <integer-array name="non_removable_euicc_slots">
+ <item>1</item>
+ </integer-array>
+ If a device has three physical slots and slot 1 and 2 are eUICCs, then the value of
+ this array should be:
+ <integer-array name="non_removable_euicc_slots">
+ <item>1</item>
+ <item>2</item>
+ </integer-array>
+ This is used to differentiate between removable eUICCs and built in eUICCs, and should
+ be set by OEMs for devices which use eUICCs. -->
+ <integer-array name="non_removable_euicc_slots"></integer-array>
+
</resources>
diff --git a/core/res/res/values/colors_device_defaults.xml b/core/res/res/values/colors_device_defaults.xml
index 0fe80a154f7a..256c53133096 100644
--- a/core/res/res/values/colors_device_defaults.xml
+++ b/core/res/res/values/colors_device_defaults.xml
@@ -26,6 +26,8 @@
<color name="primary_dark_device_default_settings">@color/primary_dark_material_settings</color>
<color name="primary_dark_device_default_settings_light">@color/primary_dark_material_settings_light</color>
+ <color name="navigation_bar_divider_device_default_settings">#1f000000</color>
+
<color name="secondary_device_default_settings">@color/secondary_material_settings</color>
<color name="secondary_device_default_settings_light">@color/secondary_material_settings_light</color>
<color name="tertiary_device_default_settings">@color/tertiary_material_settings</color>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 76791fdef758..a69914bafabb 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2844,6 +2844,8 @@
<java-symbol type="array" name="resolver_target_actions_pin" />
<java-symbol type="array" name="resolver_target_actions_unpin" />
+ <java-symbol type="array" name="non_removable_euicc_slots" />
+
<java-symbol type="string" name="install_carrier_app_notification_title" />
<java-symbol type="string" name="install_carrier_app_notification_text" />
<java-symbol type="string" name="install_carrier_app_notification_text_app_name" />
diff --git a/core/res/res/values/themes_device_defaults.xml b/core/res/res/values/themes_device_defaults.xml
index 14e5082bdebb..83edeac00b33 100644
--- a/core/res/res/values/themes_device_defaults.xml
+++ b/core/res/res/values/themes_device_defaults.xml
@@ -1447,7 +1447,7 @@ easier.
<item name="colorEdgeEffect">@android:color/black</item>
<!-- Add white nav bar with divider that matches material -->
- <item name="navigationBarDividerColor">#1f000000</item>
+ <item name="navigationBarDividerColor">@color/navigation_bar_divider_device_default_settings</item>
<item name="navigationBarColor">@android:color/white</item>
<item name="windowLightNavigationBar">true</item>
diff --git a/media/java/android/media/MediaHTTPConnection.java b/media/java/android/media/MediaHTTPConnection.java
index 5f324f7f97ed..d72476269e18 100644
--- a/media/java/android/media/MediaHTTPConnection.java
+++ b/media/java/android/media/MediaHTTPConnection.java
@@ -37,7 +37,6 @@ import java.net.URL;
import java.net.UnknownServiceException;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
/** @hide */
public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
@@ -67,7 +66,6 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
// from com.squareup.okhttp.internal.http
private final static int HTTP_TEMP_REDIRECT = 307;
private final static int MAX_REDIRECTS = 20;
- private AtomicBoolean mIsConnected = new AtomicBoolean(false);
@UnsupportedAppUsage
public MediaHTTPConnection() {
@@ -91,7 +89,6 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
mAllowCrossDomainRedirect = true;
mURL = new URL(uri);
mHeaders = convertHeaderStringToMap(headers);
- mIsConnected.set(true);
} catch (MalformedURLException e) {
return null;
}
@@ -142,14 +139,7 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
@Override
@UnsupportedAppUsage
public void disconnect() {
- if (mIsConnected.getAndSet(false)) {
- (new Thread() {
- @Override
- public void run() {
- teardownConnection();
- }
- }).start();
- }
+ teardownConnection();
mHeaders = null;
mURL = null;
}
@@ -334,14 +324,7 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
@Override
@UnsupportedAppUsage
public int readAt(long offset, int size) {
- if (!mIsConnected.get()) {
- return -1;
- }
- int result = native_readAt(offset, size);
- if (!mIsConnected.get()) {
- return -1;
- }
- return result;
+ return native_readAt(offset, size);
}
private int readAt(long offset, byte[] data, int size) {
diff --git a/packages/CaptivePortalLogin/AndroidManifest.xml b/packages/CaptivePortalLogin/AndroidManifest.xml
index 0894ee576a2d..2a4323851068 100644
--- a/packages/CaptivePortalLogin/AndroidManifest.xml
+++ b/packages/CaptivePortalLogin/AndroidManifest.xml
@@ -17,7 +17,9 @@
*/
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.captiveportallogin" >
+ package="com.android.captiveportallogin"
+ android:versionCode="10"
+ android:versionName="Q-initial">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
diff --git a/packages/NetworkStack/AndroidManifest.xml b/packages/NetworkStack/AndroidManifest.xml
index 52c209e5f247..90521de6a453 100644
--- a/packages/NetworkStack/AndroidManifest.xml
+++ b/packages/NetworkStack/AndroidManifest.xml
@@ -18,7 +18,9 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.networkstack"
- android:sharedUserId="android.uid.networkstack">
+ android:sharedUserId="android.uid.networkstack"
+ android:versionCode="10"
+ android:versionName="Q-initial">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
diff --git a/packages/NetworkStackPermissionStub/AndroidManifest.xml b/packages/NetworkStackPermissionStub/AndroidManifest.xml
index a8742d7ab34f..ba8a178eaea4 100644
--- a/packages/NetworkStackPermissionStub/AndroidManifest.xml
+++ b/packages/NetworkStackPermissionStub/AndroidManifest.xml
@@ -18,7 +18,9 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.networkstack.permissionstub"
- android:sharedUserId="android.uid.networkstack">
+ android:sharedUserId="android.uid.networkstack"
+ android:versionCode="10"
+ android:versionName="Q-initial">
<!--
This package only exists to define the below permissions, and enforce that they are only
granted to apps sharing the same signature.
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index b277666411f9..40c8b01578b7 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -136,6 +136,7 @@
<uses-permission android:name="android.permission.SET_TIME_ZONE" />
<uses-permission android:name="android.permission.DISABLE_HIDDEN_API_CHECKS" />
<uses-permission android:name="android.permission.MANAGE_ROLE_HOLDERS" />
+ <uses-permission android:name="android.permission.OBSERVE_ROLE_HOLDERS" />
<!-- Permission needed to rename bugreport notifications (so they're not shown as Shell) -->
<uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />
<!-- Permission needed to hold a wakelock in dumpstate.cpp (drop_root_user()) -->
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java
index 24a589665600..72da591e0618 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java
@@ -43,6 +43,7 @@ import com.android.systemui.tuner.TunerService.Tunable;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import static com.android.systemui.statusbar.phone.StatusBarIconController.TAG_PRIMARY;
@@ -121,7 +122,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
// Remove all the icons.
for (int i = currentSlots.size() - 1; i >= 0; i--) {
Slot s = currentSlots.get(i);
- slotsToReAdd.put(s, s.getHolderListInViewOrder());
+ slotsToReAdd.put(s, s.getHolderList());
removeAllIconsForSlot(s.getName());
}
@@ -200,6 +201,10 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
Slot mobileSlot = getSlot(slot);
int slotIndex = getSlotIndex(slot);
+ // Reverse the sort order to show icons with left to right([Slot1][Slot2]..).
+ // StatusBarIconList has UI design that first items go to the right of second items.
+ Collections.reverse(iconStates);
+
for (MobileIconState state : iconStates) {
StatusBarIconHolder holder = mobileSlot.getHolderForTag(state.subId);
if (holder == null) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java
index b7e1cfb0097b..fc4122580c2e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java
@@ -249,6 +249,25 @@ public class StatusBarIconList {
return holders;
}
+ /**
+ * Build a list of the {@link StatusBarIconHolder}s in the same order.
+ * This provides a safe list that can be iterated and inserted into its group.
+ *
+ * @return all holders contained here
+ */
+ public List<StatusBarIconHolder> getHolderList() {
+ ArrayList<StatusBarIconHolder> holders = new ArrayList<>();
+ if (mHolder != null) {
+ holders.add(mHolder);
+ }
+
+ if (mSubSlots != null) {
+ holders.addAll(mSubSlots);
+ }
+
+ return holders;
+ }
+
@Override
public String toString() {
return String.format("(%s) %s", mName, subSlotsString());
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 1035efb80366..446d186cc123 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -71,6 +71,8 @@ import android.net.INetworkMonitorCallbacks;
import android.net.INetworkPolicyListener;
import android.net.INetworkPolicyManager;
import android.net.INetworkStatsService;
+import android.net.InetAddresses;
+import android.net.IpPrefix;
import android.net.LinkProperties;
import android.net.LinkProperties.CompareResult;
import android.net.MatchAllNetworkSpecifier;
@@ -1740,6 +1742,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
}
+
+ @Override
+ public void onNat64PrefixEvent(int netId, boolean added,
+ String prefixString, int prefixLength) {
+ mHandler.post(() -> handleNat64PrefixEvent(netId, added, prefixString, prefixLength));
+ }
};
@VisibleForTesting
@@ -2767,6 +2775,29 @@ public class ConnectivityService extends IConnectivityManager.Stub
handleUpdateLinkProperties(nai, new LinkProperties(nai.linkProperties));
}
+ private void handleNat64PrefixEvent(int netId, boolean added, String prefixString,
+ int prefixLength) {
+ NetworkAgentInfo nai = mNetworkForNetId.get(netId);
+ if (nai == null) return;
+
+ log(String.format("NAT64 prefix %s on netId %d: %s/%d",
+ (added ? "added" : "removed"), netId, prefixString, prefixLength));
+
+ IpPrefix prefix = null;
+ if (added) {
+ try {
+ prefix = new IpPrefix(InetAddresses.parseNumericAddress(prefixString),
+ prefixLength);
+ } catch (IllegalArgumentException e) {
+ loge("Invalid NAT64 prefix " + prefixString + "/" + prefixLength);
+ return;
+ }
+ }
+
+ nai.clatd.setNat64Prefix(prefix);
+ handleUpdateLinkProperties(nai, new LinkProperties(nai.linkProperties));
+ }
+
private void updateLingerState(NetworkAgentInfo nai, long now) {
// 1. Update the linger timer. If it's changed, reschedule or cancel the alarm.
// 2. If the network was lingering and there are now requests, unlinger it.
@@ -2882,7 +2913,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
e.rethrowFromSystemServer();
}
mNetworkAgentInfos.remove(nai.messenger);
- nai.maybeStopClat();
+ nai.clatd.update();
synchronized (mNetworkForNetId) {
// Remove the NetworkAgent, but don't mark the netId as
// available until we've told netd to delete it below.
@@ -5190,11 +5221,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
LinkProperties oldLp) {
int netId = networkAgent.network.netId;
- // The NetworkAgentInfo does not know whether clatd is running on its network or not. Before
- // we do anything else, make sure its LinkProperties are accurate.
- if (networkAgent.clatd != null) {
- networkAgent.clatd.fixupLinkProperties(oldLp, newLp);
- }
+ // The NetworkAgentInfo does not know whether clatd is running on its network or not, or
+ // whether there is a NAT64 prefix. Before we do anything else, make sure its LinkProperties
+ // are accurate.
+ networkAgent.clatd.fixupLinkProperties(oldLp, newLp);
updateInterfaces(newLp, oldLp, netId, networkAgent.networkCapabilities);
updateMtu(newLp, oldLp);
@@ -5224,8 +5254,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
synchronized (networkAgent) {
networkAgent.linkProperties = newLp;
}
- // Start or stop clat accordingly to network state.
- networkAgent.updateClat(mNMS);
+ // Start or stop DNS64 detection and 464xlat according to network state.
+ networkAgent.clatd.update();
notifyIfacesChangedForNetworkStats();
if (networkAgent.everConnected) {
try {
diff --git a/services/core/java/com/android/server/connectivity/Nat464Xlat.java b/services/core/java/com/android/server/connectivity/Nat464Xlat.java
index 9d9b1cfdf6e2..2646d7669d79 100644
--- a/services/core/java/com/android/server/connectivity/Nat464Xlat.java
+++ b/services/core/java/com/android/server/connectivity/Nat464Xlat.java
@@ -18,19 +18,24 @@ package com.android.server.connectivity;
import android.net.ConnectivityManager;
import android.net.INetd;
+import android.net.InetAddresses;
import android.net.InterfaceConfiguration;
+import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NetworkInfo;
import android.net.RouteInfo;
import android.os.INetworkManagementService;
import android.os.RemoteException;
+import android.os.ServiceSpecificException;
import android.util.Slog;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.server.net.BaseNetworkObserver;
import java.net.Inet4Address;
+import java.net.Inet6Address;
import java.util.Objects;
/**
@@ -67,15 +72,16 @@ public class Nat464Xlat extends BaseNetworkObserver {
private final NetworkAgentInfo mNetwork;
private enum State {
- IDLE, // start() not called. Base iface and stacked iface names are null.
- STARTING, // start() called. Base iface and stacked iface names are known.
- RUNNING, // start() called, and the stacked iface is known to be up.
- STOPPING; // stop() called, this Nat464Xlat is still registered as a network observer for
- // the stacked interface.
+ IDLE, // start() not called. Base iface and stacked iface names are null.
+ DISCOVERING, // same as IDLE, except prefix discovery in progress.
+ STARTING, // start() called. Base iface and stacked iface names are known.
+ RUNNING, // start() called, and the stacked iface is known to be up.
}
+ private IpPrefix mNat64Prefix;
private String mBaseIface;
private String mIface;
+ private Inet6Address mIPv6Address;
private State mState = State.IDLE;
public Nat464Xlat(NetworkAgentInfo nai, INetd netd, INetworkManagementService nmService) {
@@ -85,20 +91,51 @@ public class Nat464Xlat extends BaseNetworkObserver {
}
/**
- * Determines whether a network requires clat.
+ * Whether to attempt 464xlat on this network. This is true for an IPv6-only network that is
+ * currently connected and where the NetworkAgent has not disabled 464xlat. It is the signal to
+ * enable NAT64 prefix discovery.
+ *
* @param network the NetworkAgentInfo corresponding to the network.
* @return true if the network requires clat, false otherwise.
*/
- public static boolean requiresClat(NetworkAgentInfo nai) {
+ @VisibleForTesting
+ protected static boolean requiresClat(NetworkAgentInfo nai) {
// TODO: migrate to NetworkCapabilities.TRANSPORT_*.
final boolean supported = ArrayUtils.contains(NETWORK_TYPES, nai.networkInfo.getType());
final boolean connected = ArrayUtils.contains(NETWORK_STATES, nai.networkInfo.getState());
- // We only run clat on networks that don't have a native IPv4 address.
- final boolean hasIPv4Address =
- (nai.linkProperties != null) && nai.linkProperties.hasIPv4Address();
- final boolean skip464xlat =
- (nai.netMisc() != null) && nai.netMisc().skip464xlat;
- return supported && connected && !hasIPv4Address && !skip464xlat;
+
+ // Only run clat on networks that have a global IPv6 address and don't have a native IPv4
+ // address.
+ LinkProperties lp = nai.linkProperties;
+ final boolean isIpv6OnlyNetwork = (lp != null) && lp.hasGlobalIPv6Address()
+ && !lp.hasIPv4Address();
+
+ // If the network tells us it doesn't use clat, respect that.
+ final boolean skip464xlat = (nai.netMisc() != null) && nai.netMisc().skip464xlat;
+
+ return supported && connected && isIpv6OnlyNetwork && !skip464xlat;
+ }
+
+ /**
+ * Whether the clat demon should be started on this network now. This is true if requiresClat is
+ * true and a NAT64 prefix has been discovered.
+ *
+ * @param nai the NetworkAgentInfo corresponding to the network.
+ * @return true if the network should start clat, false otherwise.
+ */
+ @VisibleForTesting
+ protected static boolean shouldStartClat(NetworkAgentInfo nai) {
+ LinkProperties lp = nai.linkProperties;
+ return requiresClat(nai) && lp != null && lp.getNat64Prefix() != null;
+ }
+
+ /**
+ * @return true if we have started prefix discovery and not yet stopped it (regardless of
+ * whether it is still running or has succeeded).
+ * A true result corresponds to internal states DISCOVERING, STARTING and RUNNING.
+ */
+ public boolean isPrefixDiscoveryStarted() {
+ return mState == State.DISCOVERING || isStarted();
}
/**
@@ -106,7 +143,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
* A true result corresponds to internal states STARTING and RUNNING.
*/
public boolean isStarted() {
- return mState != State.IDLE;
+ return (mState == State.STARTING || mState == State.RUNNING);
}
/**
@@ -124,32 +161,31 @@ public class Nat464Xlat extends BaseNetworkObserver {
}
/**
- * @return true if clatd has been stopped.
- */
- public boolean isStopping() {
- return mState == State.STOPPING;
- }
-
- /**
* Start clatd, register this Nat464Xlat as a network observer for the stacked interface,
* and set internal state.
*/
private void enterStartingState(String baseIface) {
try {
mNMService.registerObserver(this);
- } catch(RemoteException e) {
- Slog.e(TAG,
- "startClat: Can't register interface observer for clat on " + mNetwork.name());
+ } catch (RemoteException e) {
+ Slog.e(TAG, "Can't register interface observer for clat on " + mNetwork.name());
return;
}
+
+ String addrStr = null;
try {
- mNetd.clatdStart(baseIface);
- } catch(RemoteException|IllegalStateException e) {
- Slog.e(TAG, "Error starting clatd on " + baseIface, e);
+ addrStr = mNetd.clatdStart(baseIface, mNat64Prefix.toString());
+ } catch (RemoteException | ServiceSpecificException e) {
+ Slog.e(TAG, "Error starting clatd on " + baseIface + ": " + e);
}
mIface = CLAT_PREFIX + baseIface;
mBaseIface = baseIface;
mState = State.STARTING;
+ try {
+ mIPv6Address = (Inet6Address) InetAddresses.parseNumericAddress(addrStr);
+ } catch (ClassCastException | IllegalArgumentException | NullPointerException e) {
+ Slog.e(TAG, "Invalid IPv6 address " + addrStr);
+ }
}
/**
@@ -161,37 +197,27 @@ public class Nat464Xlat extends BaseNetworkObserver {
}
/**
- * Stop clatd, and turn ND offload on if it had been turned off.
- */
- private void enterStoppingState() {
- try {
- mNetd.clatdStop(mBaseIface);
- } catch(RemoteException|IllegalStateException e) {
- Slog.e(TAG, "Error stopping clatd on " + mBaseIface, e);
- }
-
- mState = State.STOPPING;
- }
-
- /**
* Unregister as a base observer for the stacked interface, and clear internal state.
*/
- private void enterIdleState() {
+ private void leaveStartedState() {
try {
mNMService.unregisterObserver(this);
- } catch(RemoteException|IllegalStateException e) {
- Slog.e(TAG, "Error unregistering clatd observer on " + mBaseIface, e);
+ } catch (RemoteException | IllegalStateException e) {
+ Slog.e(TAG, "Error unregistering clatd observer on " + mBaseIface + ": " + e);
}
-
mIface = null;
mBaseIface = null;
mState = State.IDLE;
+ if (requiresClat(mNetwork)) {
+ mState = State.DISCOVERING;
+ } else {
+ stopPrefixDiscovery();
+ mState = State.IDLE;
+ }
}
- /**
- * Starts the clat daemon.
- */
- public void start() {
+ @VisibleForTesting
+ protected void start() {
if (isStarted()) {
Slog.e(TAG, "startClat: already started");
return;
@@ -212,28 +238,92 @@ public class Nat464Xlat extends BaseNetworkObserver {
enterStartingState(baseIface);
}
- /**
- * Stops the clat daemon.
- */
- public void stop() {
+ @VisibleForTesting
+ protected void stop() {
if (!isStarted()) {
+ Slog.e(TAG, "stopClat: already stopped");
return;
}
+
Slog.i(TAG, "Stopping clatd on " + mBaseIface);
+ try {
+ mNetd.clatdStop(mBaseIface);
+ } catch (RemoteException | ServiceSpecificException e) {
+ Slog.e(TAG, "Error stopping clatd on " + mBaseIface + ": " + e);
+ }
+
+ String iface = mIface;
+ boolean wasRunning = isRunning();
+
+ // Change state before updating LinkProperties. handleUpdateLinkProperties ends up calling
+ // fixupLinkProperties, and if at that time the state is still RUNNING, fixupLinkProperties
+ // would wrongly inform ConnectivityService that there is still a stacked interface.
+ leaveStartedState();
+
+ if (wasRunning) {
+ LinkProperties lp = new LinkProperties(mNetwork.linkProperties);
+ lp.removeStackedLink(iface);
+ mNetwork.connService().handleUpdateLinkProperties(mNetwork, lp);
+ }
+ }
+
+ private void startPrefixDiscovery() {
+ try {
+ mNetd.resolverStartPrefix64Discovery(getNetId());
+ mState = State.DISCOVERING;
+ } catch (RemoteException | ServiceSpecificException e) {
+ Slog.e(TAG, "Error starting prefix discovery on netId " + getNetId() + ": " + e);
+ }
+ }
- boolean wasStarting = isStarting();
- enterStoppingState();
- if (wasStarting) {
- enterIdleState();
+ private void stopPrefixDiscovery() {
+ try {
+ mNetd.resolverStopPrefix64Discovery(getNetId());
+ } catch (RemoteException | ServiceSpecificException e) {
+ Slog.e(TAG, "Error stopping prefix discovery on netId " + getNetId() + ": " + e);
}
}
/**
+ * Starts/stops NAT64 prefix discovery and clatd as necessary.
+ */
+ public void update() {
+ // TODO: turn this class into a proper StateMachine. // http://b/126113090
+ if (requiresClat(mNetwork)) {
+ if (!isPrefixDiscoveryStarted()) {
+ startPrefixDiscovery();
+ } else if (shouldStartClat(mNetwork)) {
+ // NAT64 prefix detected. Start clatd.
+ // TODO: support the NAT64 prefix changing after it's been discovered. There is no
+ // need to support this at the moment because it cannot happen without changes to
+ // the Dns64Configuration code in netd.
+ start();
+ } else {
+ // NAT64 prefix removed. Stop clatd and go back into DISCOVERING state.
+ stop();
+ }
+ } else {
+ // Network no longer requires clat. Stop clat and prefix discovery.
+ if (isStarted()) {
+ stop();
+ } else if (isPrefixDiscoveryStarted()) {
+ leaveStartedState();
+ }
+ }
+ }
+
+ public void setNat64Prefix(IpPrefix nat64Prefix) {
+ mNat64Prefix = nat64Prefix;
+ }
+
+ /**
* Copies the stacked clat link in oldLp, if any, to the passed LinkProperties.
* This is necessary because the LinkProperties in mNetwork come from the transport layer, which
* has no idea that 464xlat is running on top of it.
*/
public void fixupLinkProperties(LinkProperties oldLp, LinkProperties lp) {
+ lp.setNat64Prefix(mNat64Prefix);
+
if (!isRunning()) {
return;
}
@@ -272,7 +362,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
try {
InterfaceConfiguration config = mNMService.getInterfaceConfig(iface);
return config.getLinkAddress();
- } catch(RemoteException|IllegalStateException e) {
+ } catch (RemoteException | IllegalStateException e) {
Slog.e(TAG, "Error getting link properties: " + e);
return null;
}
@@ -282,6 +372,20 @@ public class Nat464Xlat extends BaseNetworkObserver {
* Adds stacked link on base link and transitions to RUNNING state.
*/
private void handleInterfaceLinkStateChanged(String iface, boolean up) {
+ // TODO: if we call start(), then stop(), then start() again, and the
+ // interfaceLinkStateChanged notification for the first start is delayed past the first
+ // stop, then the code becomes out of sync with system state and will behave incorrectly.
+ //
+ // This is not trivial to fix because:
+ // 1. It is not guaranteed that start() will eventually result in the interface coming up,
+ // because there could be an error starting clat (e.g., if the interface goes down before
+ // the packet socket can be bound).
+ // 2. If start is called multiple times, there is nothing in the interfaceLinkStateChanged
+ // notification that says which start() call the interface was created by.
+ //
+ // Once this code is converted to StateMachine, it will be possible to use deferMessage to
+ // ensure it stays in STARTING state until the interfaceLinkStateChanged notification fires,
+ // and possibly use a timeout (or provide some guarantees at the lower layer) to address #1.
if (!isStarting() || !up || !Objects.equals(mIface, iface)) {
return;
}
@@ -307,20 +411,16 @@ public class Nat464Xlat extends BaseNetworkObserver {
if (!Objects.equals(mIface, iface)) {
return;
}
- if (!isRunning() && !isStopping()) {
+ if (!isRunning()) {
return;
}
Slog.i(TAG, "interface " + iface + " removed");
- if (!isStopping()) {
- // Ensure clatd is stopped if stop() has not been called: this likely means that clatd
- // has crashed.
- enterStoppingState();
- }
- enterIdleState();
- LinkProperties lp = new LinkProperties(mNetwork.linkProperties);
- lp.removeStackedLink(iface);
- mNetwork.connService().handleUpdateLinkProperties(mNetwork, lp);
+ // If we're running, and the interface was removed, then we didn't call stop(), and it's
+ // likely that clatd crashed. Ensure we call stop() so we can start clatd again. Calling
+ // stop() will also update LinkProperties, and if clatd crashed, the LinkProperties update
+ // will cause ConnectivityService to call start() again.
+ stop();
}
@Override
@@ -337,4 +437,9 @@ public class Nat464Xlat extends BaseNetworkObserver {
public String toString() {
return "mBaseIface: " + mBaseIface + ", mIface: " + mIface + ", mState: " + mState;
}
+
+ @VisibleForTesting
+ protected int getNetId() {
+ return mNetwork.network.netId;
+ }
}
diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
index d0cff25dbf05..f11a0de1bf77 100644
--- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
@@ -236,7 +236,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
public final AsyncChannel asyncChannel;
// Used by ConnectivityService to keep track of 464xlat.
- public Nat464Xlat clatd;
+ public final Nat464Xlat clatd;
// Set after asynchronous creation of the NetworkMonitor.
private volatile INetworkMonitor mNetworkMonitor;
@@ -244,8 +244,6 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
private static final String TAG = ConnectivityService.class.getSimpleName();
private static final boolean VDBG = false;
private final ConnectivityService mConnService;
- private final INetd mNetd;
- private final INetworkManagementService mNMS;
private final Context mContext;
private final Handler mHandler;
@@ -260,9 +258,8 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
linkProperties = lp;
networkCapabilities = nc;
currentScore = score;
+ clatd = new Nat464Xlat(this, netd, nms);
mConnService = connService;
- mNetd = netd;
- mNMS = nms;
mContext = context;
mHandler = handler;
networkMisc = misc;
@@ -595,32 +592,6 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
for (LingerTimer timer : mLingerTimers) { pw.println(timer); }
}
- public void updateClat(INetworkManagementService netd) {
- if (Nat464Xlat.requiresClat(this)) {
- maybeStartClat();
- } else {
- maybeStopClat();
- }
- }
-
- /** Ensure clat has started for this network. */
- public void maybeStartClat() {
- if (clatd != null && clatd.isStarted()) {
- return;
- }
- clatd = new Nat464Xlat(this, mNetd, mNMS);
- clatd.start();
- }
-
- /** Ensure clat has stopped for this network. */
- public void maybeStopClat() {
- if (clatd == null) {
- return;
- }
- clatd.stop();
- clatd = null;
- }
-
public String toString() {
return "NetworkAgentInfo{ ni{" + networkInfo + "} "
+ "network{" + network + "} nethandle{" + network.getNetworkHandle() + "} "
diff --git a/services/core/java/com/android/server/pm/OtaDexoptService.java b/services/core/java/com/android/server/pm/OtaDexoptService.java
index 41eaa24d898e..1c0b78f23002 100644
--- a/services/core/java/com/android/server/pm/OtaDexoptService.java
+++ b/services/core/java/com/android/server/pm/OtaDexoptService.java
@@ -333,7 +333,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
PackageDexOptimizer optimizer = new OTADexoptPackageDexOptimizer(
collectingInstaller, mPackageManagerService.mInstallLock, mContext);
- optimizer.performDexOpt(pkg, pkg.usesLibraryInfos,
+ optimizer.performDexOpt(pkg,
null /* ISAs */,
null /* CompilerStats.PackageStats */,
mPackageManagerService.getDexManager().getPackageUseInfoOrDefault(pkg.packageName),
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index 51575a45fb94..248a2f6301cd 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -127,7 +127,7 @@ public class PackageDexOptimizer {
* <p>Calls to {@link com.android.server.pm.Installer#dexopt} on {@link #mInstaller} are
* synchronized on {@link #mInstallLock}.
*/
- int performDexOpt(PackageParser.Package pkg, List<SharedLibraryInfo> sharedLibraries,
+ int performDexOpt(PackageParser.Package pkg,
String[] instructionSets, CompilerStats.PackageStats packageStats,
PackageDexUsage.PackageUseInfo packageUseInfo, DexoptOptions options) {
if (pkg.applicationInfo.uid == -1) {
@@ -140,7 +140,7 @@ public class PackageDexOptimizer {
synchronized (mInstallLock) {
final long acquireTime = acquireWakeLockLI(pkg.applicationInfo.uid);
try {
- return performDexOptLI(pkg, sharedLibraries, instructionSets,
+ return performDexOptLI(pkg, instructionSets,
packageStats, packageUseInfo, options);
} finally {
releaseWakeLockLI(acquireTime);
@@ -154,9 +154,9 @@ public class PackageDexOptimizer {
*/
@GuardedBy("mInstallLock")
private int performDexOptLI(PackageParser.Package pkg,
- List<SharedLibraryInfo> sharedLibraries,
String[] targetInstructionSets, CompilerStats.PackageStats packageStats,
PackageDexUsage.PackageUseInfo packageUseInfo, DexoptOptions options) {
+ final List<SharedLibraryInfo> sharedLibraries = pkg.usesLibraryInfos;
final String[] instructionSets = targetInstructionSets != null ?
targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo);
final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 66fc22f39601..96441c5f7d18 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -9452,12 +9452,12 @@ public class PackageManagerService extends IPackageManager.Stub
options.getFlags() | DexoptOptions.DEXOPT_AS_SHARED_LIBRARY);
for (PackageParser.Package depPackage : deps) {
// TODO: Analyze and investigate if we (should) profile libraries.
- pdo.performDexOpt(depPackage, null /* sharedLibraries */, instructionSets,
+ pdo.performDexOpt(depPackage, instructionSets,
getOrCreateCompilerPackageStats(depPackage),
mDexManager.getPackageUseInfoOrDefault(depPackage.packageName), libraryOptions);
}
}
- return pdo.performDexOpt(p, p.usesLibraryInfos, instructionSets,
+ return pdo.performDexOpt(p, instructionSets,
getOrCreateCompilerPackageStats(p),
mDexManager.getPackageUseInfoOrDefault(p.packageName), options);
}
@@ -17806,7 +17806,7 @@ public class PackageManagerService extends IPackageManager.Stub
REASON_INSTALL,
DexoptOptions.DEXOPT_BOOT_COMPLETE |
DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE);
- mPackageDexOptimizer.performDexOpt(pkg, pkg.usesLibraryInfos,
+ mPackageDexOptimizer.performDexOpt(pkg,
null /* instructionSets */,
getOrCreateCompilerPackageStats(pkg),
mDexManager.getPackageUseInfoOrDefault(pkg.packageName),
diff --git a/telecomm/java/android/telecom/ConnectionRequest.java b/telecomm/java/android/telecom/ConnectionRequest.java
index b6e6b0ed8270..d69d2cd756dc 100644
--- a/telecomm/java/android/telecom/ConnectionRequest.java
+++ b/telecomm/java/android/telecom/ConnectionRequest.java
@@ -337,7 +337,31 @@ public final class ConnectionRequest implements Parcelable {
mAddress == null
? Uri.EMPTY
: Connection.toLogSafePhoneNumber(mAddress.toString()),
- mExtras == null ? "" : mExtras);
+ bundleToString(mExtras));
+ }
+
+ private static String bundleToString(Bundle extras){
+ if (extras == null) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append("Bundle[");
+ for (String key : extras.keySet()) {
+ sb.append(key);
+ sb.append("=");
+ switch (key) {
+ case TelecomManager.EXTRA_INCOMING_CALL_ADDRESS:
+ case TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE:
+ sb.append(Log.pii(extras.get(key)));
+ break;
+ default:
+ sb.append(extras.get(key));
+ break;
+ }
+ sb.append(", ");
+ }
+ sb.append("]");
+ return sb.toString();
}
public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
diff --git a/telephony/java/android/telephony/CellIdentityNr.java b/telephony/java/android/telephony/CellIdentityNr.java
index 856f08107fd7..19bc0ceaf00a 100644
--- a/telephony/java/android/telephony/CellIdentityNr.java
+++ b/telephony/java/android/telephony/CellIdentityNr.java
@@ -81,7 +81,8 @@ public final class CellIdentityNr extends CellIdentity {
/**
* Get the NR Cell Identity.
*
- * @return The NR Cell Identity in range [0, 68719476735] or Long.MAX_VALUE if unknown.
+ * @return The 36-bit NR Cell Identity in range [0, 68719476735] or
+ * {@link CellInfo#UNAVAILABLE_LONG} if unknown.
*/
public long getNci() {
return mNci;
diff --git a/telephony/java/android/telephony/CellInfo.java b/telephony/java/android/telephony/CellInfo.java
index 8ce5c54c810e..c7853f184407 100644
--- a/telephony/java/android/telephony/CellInfo.java
+++ b/telephony/java/android/telephony/CellInfo.java
@@ -40,6 +40,11 @@ public abstract class CellInfo implements Parcelable {
public static final int UNAVAILABLE = Integer.MAX_VALUE;
/**
+ * This value indicates that the long field is unreported.
+ */
+ public static final long UNAVAILABLE_LONG = Long.MAX_VALUE;
+
+ /**
* Cell identity type
* @hide
*/
diff --git a/telephony/java/android/telephony/DataSpecificRegistrationStates.java b/telephony/java/android/telephony/DataSpecificRegistrationStates.java
index d6a8065feabe..c3387f3f112d 100644
--- a/telephony/java/android/telephony/DataSpecificRegistrationStates.java
+++ b/telephony/java/android/telephony/DataSpecificRegistrationStates.java
@@ -1,5 +1,7 @@
package android.telephony;
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -10,14 +12,17 @@ import java.util.Objects;
* Class that stores information specific to data network registration.
* @hide
*/
-public class DataSpecificRegistrationStates implements Parcelable{
+@SystemApi
+public final class DataSpecificRegistrationStates implements Parcelable{
/**
+ * @hide
* The maximum number of simultaneous Data Calls that
* must be established using setupDataCall().
*/
public final int maxDataCalls;
/**
+ * @hide
* Indicates if the use of dual connectivity with NR is restricted.
* Reference: 3GPP TS 24.301 v15.03 section 9.3.3.12A.
*/
@@ -25,7 +30,7 @@ public class DataSpecificRegistrationStates implements Parcelable{
/**
* Indicates if NR is supported by the selected PLMN.
- *
+ * @hide
* {@code true} if the bit N is in the PLMN-InfoList-r15 is true and the selected PLMN is
* present in plmn-IdentityList at position N.
* Reference: 3GPP TS 36.331 v15.2.2 section 6.3.1 PLMN-InfoList-r15.
@@ -34,6 +39,7 @@ public class DataSpecificRegistrationStates implements Parcelable{
public final boolean isNrAvailable;
/**
+ * @hide
* Indicates that if E-UTRA-NR Dual Connectivity (EN-DC) is supported by the primary serving
* cell.
*
@@ -47,8 +53,11 @@ public class DataSpecificRegistrationStates implements Parcelable{
/**
* Provides network support info for LTE VoPS and LTE Emergency bearer support
*/
- public final LteVopsSupportInfo lteVopsSupportInfo;
+ private final LteVopsSupportInfo lteVopsSupportInfo;
+ /**
+ * @hide
+ */
DataSpecificRegistrationStates(
int maxDataCalls, boolean isDcNrRestricted, boolean isNrAvailable,
boolean isEnDcAvailable, LteVopsSupportInfo lteVops) {
@@ -126,4 +135,12 @@ public class DataSpecificRegistrationStates implements Parcelable{
return new DataSpecificRegistrationStates[size];
}
};
+
+ /**
+ * @return LteVopsSupportInfo
+ */
+ @NonNull
+ public LteVopsSupportInfo getLteVopsSupportInfo() {
+ return lteVopsSupportInfo;
+ }
}
diff --git a/telephony/java/android/telephony/NetworkRegistrationState.java b/telephony/java/android/telephony/NetworkRegistrationState.java
index 6e6d59e62148..84d6628d47d2 100644
--- a/telephony/java/android/telephony/NetworkRegistrationState.java
+++ b/telephony/java/android/telephony/NetworkRegistrationState.java
@@ -349,7 +349,7 @@ public class NetworkRegistrationState implements Parcelable {
}
/**
- * @hide
+ * @return Data registration related info
*/
@Nullable
public DataSpecificRegistrationStates getDataSpecificStates() {
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 2c87e62e2b32..29a305e8b131 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -1355,6 +1355,26 @@ public class TelephonyManager {
* Intent sent when an error occurs that debug tools should log and possibly take further
* action such as capturing vendor-specific logs.
*
+ * A privileged application that reads these events should take appropriate vendor-specific
+ * action to record the event and collect further information to assist in analysis, debugging,
+ * and resolution of any associated issue.
+ *
+ * <p>This event should not be used for generic logging or diagnostic monitoring purposes and
+ * should generally be sent at a low rate. Instead, this mechanism should be used for the
+ * framework to notify a debugging application that an event (such as a bug) has occured
+ * within the framework if that event should trigger the collection and preservation of other
+ * more detailed device state for debugging.
+ *
+ * <p>At most one application can receive these events and should register a receiver in
+ * in the application manifest. For performance reasons, if no application to receive these
+ * events is detected at boot, then these events will not be sent.
+ *
+ * <p>Each event will include an {@link EXTRA_DEBUG_EVENT_ID} that will uniquely identify the
+ * event that has occurred. Each event will be sent to the diagnostic monitor only once per
+ * boot cycle (as another optimization).
+ *
+ * @see #EXTRA_DEBUG_EVENT_ID
+ * @see #EXTRA_DEBUG_EVENT_DESCRIPTION
* @hide
*/
@SystemApi
@@ -1362,21 +1382,23 @@ public class TelephonyManager {
public static final String ACTION_DEBUG_EVENT = "android.telephony.action.DEBUG_EVENT";
/**
- * An arbitrary ParcelUuid which should be consistent for each occurrence of the same event.
+ * An arbitrary ParcelUuid which should be consistent for each occurrence of a DebugEvent.
*
- * This field must be included in all events.
+ * This field must be included in all {@link ACTION_DEBUG_EVENT} events.
*
+ * @see #ACTION_DEBUG_EVENT
* @hide
*/
@SystemApi
public static final String EXTRA_DEBUG_EVENT_ID = "android.telephony.extra.DEBUG_EVENT_ID";
/**
- * A freeform string description of the event.
+ * A freeform string description of the DebugEvent.
*
- * This field is optional for all events and as a guideline should not exceed 80 characters
- * and should be as short as possible to convey the essence of the event.
+ * This field is optional for all {@link ACTION_DEBUG_EVENT}s, as a guideline should not
+ * exceed 80 characters, and should be as short as possible to convey the essence of the event.
*
+ * @see #ACTION_DEBUG_EVENT
* @hide
*/
@SystemApi
@@ -3181,6 +3203,7 @@ public class TelephonyManager {
* the caller does not have adequate permissions for that card.
*/
@RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ @NonNull
public List<UiccCardInfo> getUiccCardsInfo() {
try {
ITelephony telephony = getITelephony();
diff --git a/telephony/java/android/telephony/UiccCardInfo.java b/telephony/java/android/telephony/UiccCardInfo.java
index 19f357a14687..d95a4992f808 100644
--- a/telephony/java/android/telephony/UiccCardInfo.java
+++ b/telephony/java/android/telephony/UiccCardInfo.java
@@ -15,6 +15,8 @@
*/
package android.telephony;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -30,6 +32,7 @@ public final class UiccCardInfo implements Parcelable {
private final String mEid;
private final String mIccId;
private final int mSlotIndex;
+ private final boolean mIsRemovable;
public static final Creator<UiccCardInfo> CREATOR = new Creator<UiccCardInfo>() {
@Override
@@ -49,6 +52,7 @@ public final class UiccCardInfo implements Parcelable {
mEid = in.readString();
mIccId = in.readString();
mSlotIndex = in.readInt();
+ mIsRemovable = in.readByte() != 0;
}
@Override
@@ -58,6 +62,7 @@ public final class UiccCardInfo implements Parcelable {
dest.writeString(mEid);
dest.writeString(mIccId);
dest.writeInt(mSlotIndex);
+ dest.writeByte((byte) (mIsRemovable ? 1 : 0));
}
@Override
@@ -65,16 +70,21 @@ public final class UiccCardInfo implements Parcelable {
return 0;
}
- public UiccCardInfo(boolean isEuicc, int cardId, String eid, String iccId, int slotIndex) {
+ /**
+ * @hide
+ */
+ public UiccCardInfo(boolean isEuicc, int cardId, String eid, String iccId, int slotIndex,
+ boolean isRemovable) {
this.mIsEuicc = isEuicc;
this.mCardId = cardId;
this.mEid = eid;
this.mIccId = iccId;
this.mSlotIndex = slotIndex;
+ this.mIsRemovable = isRemovable;
}
/**
- * Return whether the UiccCardInfo is an eUICC.
+ * Return whether the UICC is an eUICC.
* @return true if the UICC is an eUICC.
*/
public boolean isEuicc() {
@@ -96,6 +106,7 @@ public final class UiccCardInfo implements Parcelable {
* Note that this field may be omitted if the caller does not have the correct permissions
* (see {@link TelephonyManager#getUiccCardsInfo()}).
*/
+ @Nullable
public String getEid() {
if (!mIsEuicc) {
return null;
@@ -109,6 +120,7 @@ public final class UiccCardInfo implements Parcelable {
* Note that this field may be omitted if the caller does not have the correct permissions
* (see {@link TelephonyManager#getUiccCardsInfo()}).
*/
+ @Nullable
public String getIccId() {
return mIccId;
}
@@ -121,13 +133,24 @@ public final class UiccCardInfo implements Parcelable {
}
/**
- * Returns a copy of the UiccCardinfo with the clears the EID and ICCID set to null. These
- * values are generally private and require carrier privileges to view.
+ * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
+ * generally private and require carrier privileges to view.
*
* @hide
*/
+ @NonNull
public UiccCardInfo getUnprivileged() {
- return new UiccCardInfo(mIsEuicc, mCardId, null, null, mSlotIndex);
+ return new UiccCardInfo(mIsEuicc, mCardId, null, null, mSlotIndex, mIsRemovable);
+ }
+
+ /**
+ * Return whether the UICC or eUICC is removable.
+ * <p>
+ * UICCs are generally removable, but eUICCs may be removable or built in to the device.
+ * @return true if the UICC or eUICC is removable
+ */
+ public boolean isRemovable() {
+ return mIsRemovable;
}
@Override
@@ -144,12 +167,13 @@ public final class UiccCardInfo implements Parcelable {
&& (mCardId == that.mCardId)
&& (Objects.equals(mEid, that.mEid))
&& (Objects.equals(mIccId, that.mIccId))
- && (mSlotIndex == that.mSlotIndex));
+ && (mSlotIndex == that.mSlotIndex)
+ && (mIsRemovable == that.mIsRemovable));
}
@Override
public int hashCode() {
- return Objects.hash(mIsEuicc, mCardId, mEid, mIccId, mSlotIndex);
+ return Objects.hash(mIsEuicc, mCardId, mEid, mIccId, mSlotIndex, mIsRemovable);
}
@Override
@@ -164,6 +188,8 @@ public final class UiccCardInfo implements Parcelable {
+ mIccId
+ ", mSlotIndex="
+ mSlotIndex
+ + ", mIsRemovable="
+ + mIsRemovable
+ ")";
}
}
diff --git a/telephony/java/android/telephony/UiccSlotInfo.java b/telephony/java/android/telephony/UiccSlotInfo.java
index a39992b17f8e..93a7da04c56e 100644
--- a/telephony/java/android/telephony/UiccSlotInfo.java
+++ b/telephony/java/android/telephony/UiccSlotInfo.java
@@ -15,15 +15,15 @@
*/
package android.telephony;
+import android.annotation.IntDef;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
-import android.annotation.IntDef;
-
/**
* Class for the information of a UICC slot.
* @hide
@@ -61,6 +61,7 @@ public class UiccSlotInfo implements Parcelable {
private final @CardStateInfo int mCardStateInfo;
private final int mLogicalSlotIdx;
private final boolean mIsExtendedApduSupported;
+ private final boolean mIsRemovable;
public static final Creator<UiccSlotInfo> CREATOR = new Creator<UiccSlotInfo>() {
@Override
@@ -81,6 +82,7 @@ public class UiccSlotInfo implements Parcelable {
mCardStateInfo = in.readInt();
mLogicalSlotIdx = in.readInt();
mIsExtendedApduSupported = in.readByte() != 0;
+ mIsRemovable = in.readByte() != 0;
}
@Override
@@ -91,6 +93,7 @@ public class UiccSlotInfo implements Parcelable {
dest.writeInt(mCardStateInfo);
dest.writeInt(mLogicalSlotIdx);
dest.writeByte((byte) (mIsExtendedApduSupported ? 1 : 0));
+ dest.writeByte((byte) (mIsRemovable ? 1 : 0));
}
@Override
@@ -98,6 +101,11 @@ public class UiccSlotInfo implements Parcelable {
return 0;
}
+ /**
+ * Construct a UiccSlotInfo.
+ * @deprecated apps should not be constructing UiccSlotInfo objects
+ */
+ @Deprecated
public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
@CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported) {
this.mIsActive = isActive;
@@ -106,6 +114,22 @@ public class UiccSlotInfo implements Parcelable {
this.mCardStateInfo = cardStateInfo;
this.mLogicalSlotIdx = logicalSlotIdx;
this.mIsExtendedApduSupported = isExtendedApduSupported;
+ this.mIsRemovable = false;
+ }
+
+ /**
+ * @hide
+ */
+ public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
+ @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported,
+ boolean isRemovable) {
+ this.mIsActive = isActive;
+ this.mIsEuicc = isEuicc;
+ this.mCardId = cardId;
+ this.mCardStateInfo = cardStateInfo;
+ this.mLogicalSlotIdx = logicalSlotIdx;
+ this.mIsExtendedApduSupported = isExtendedApduSupported;
+ this.mIsRemovable = isRemovable;
}
public boolean getIsActive() {
@@ -136,6 +160,16 @@ public class UiccSlotInfo implements Parcelable {
return mIsExtendedApduSupported;
}
+ /**
+ * Return whether the UICC slot is for a removable UICC.
+ * <p>
+ * UICCs are generally removable, but eUICCs may be removable or built in to the device.
+ * @return true if the slot is for removable UICCs
+ */
+ public boolean isRemovable() {
+ return mIsRemovable;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -151,7 +185,8 @@ public class UiccSlotInfo implements Parcelable {
&& (Objects.equals(mCardId, that.mCardId))
&& (mCardStateInfo == that.mCardStateInfo)
&& (mLogicalSlotIdx == that.mLogicalSlotIdx)
- && (mIsExtendedApduSupported == that.mIsExtendedApduSupported);
+ && (mIsExtendedApduSupported == that.mIsExtendedApduSupported)
+ && (mIsRemovable == that.mIsRemovable);
}
@Override
@@ -163,6 +198,7 @@ public class UiccSlotInfo implements Parcelable {
result = 31 * result + mCardStateInfo;
result = 31 * result + mLogicalSlotIdx;
result = 31 * result + (mIsExtendedApduSupported ? 1 : 0);
+ result = 31 * result + (mIsRemovable ? 1 : 0);
return result;
}
@@ -180,6 +216,8 @@ public class UiccSlotInfo implements Parcelable {
+ mLogicalSlotIdx
+ ", mIsExtendedApduSupported="
+ mIsExtendedApduSupported
+ + ", mIsRemovable="
+ + mIsRemovable
+ ")";
}
}
diff --git a/telephony/java/android/telephony/ims/ImsConferenceState.java b/telephony/java/android/telephony/ims/ImsConferenceState.java
index 66d2f8d929d3..8af8cffcd878 100644
--- a/telephony/java/android/telephony/ims/ImsConferenceState.java
+++ b/telephony/java/android/telephony/ims/ImsConferenceState.java
@@ -16,17 +16,18 @@
package android.telephony.ims;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.Set;
-
import android.annotation.SystemApi;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.telecom.Call;
import android.telecom.Connection;
+import android.telecom.Log;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Set;
/**
* Provides the conference information (defined in RFC 4575) for IMS conference call.
@@ -189,7 +190,7 @@ public final class ImsConferenceState implements Parcelable {
sb.append("<");
while (iterator.hasNext()) {
Entry<String, Bundle> entry = iterator.next();
- sb.append(entry.getKey());
+ sb.append(Log.pii(entry.getKey()));
sb.append(": ");
Bundle participantData = entry.getValue();
@@ -197,7 +198,7 @@ public final class ImsConferenceState implements Parcelable {
sb.append(key);
sb.append("=");
if (ENDPOINT.equals(key) || USER.equals(key)) {
- sb.append(android.telecom.Log.pii(participantData.get(key)));
+ sb.append(Log.pii(participantData.get(key)));
} else {
sb.append(participantData.get(key));
}
diff --git a/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java b/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java
index 837ef54a2f24..d11a0de24fb5 100644
--- a/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java
+++ b/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java
@@ -99,7 +99,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
public int mRttMode;
// RTT Audio Speech Indicator
/** @hide */
- public boolean mHasRttAudioSpeech = false;
+ public boolean mIsReceivingRttAudio = false;
/** @hide */
public ImsStreamMediaProfile(Parcel in) {
@@ -201,7 +201,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
", videoQuality=" + mVideoQuality +
", videoDirection=" + mVideoDirection +
", rttMode=" + mRttMode +
- ", hasRttAudioSpeech=" + mHasRttAudioSpeech + " }";
+ ", hasRttAudioSpeech=" + mIsReceivingRttAudio + " }";
}
@Override
@@ -216,7 +216,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
out.writeInt(mVideoQuality);
out.writeInt(mVideoDirection);
out.writeInt(mRttMode);
- out.writeBoolean(mHasRttAudioSpeech);
+ out.writeBoolean(mIsReceivingRttAudio);
}
private void readFromParcel(Parcel in) {
@@ -225,7 +225,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
mVideoQuality = in.readInt();
mVideoDirection = in.readInt();
mRttMode = in.readInt();
- mHasRttAudioSpeech = in.readBoolean();
+ mIsReceivingRttAudio = in.readBoolean();
}
public static final Creator<ImsStreamMediaProfile> CREATOR =
@@ -256,8 +256,12 @@ public final class ImsStreamMediaProfile implements Parcelable {
mRttMode = rttMode;
}
- public void setRttAudioSpeech(boolean audioOn) {
- mHasRttAudioSpeech = audioOn;
+ /**
+ * Sets whether the remote party is transmitting audio over the RTT call.
+ * @param audioOn true if audio is being received, false otherwise.
+ */
+ public void setReceivingRttAudio(boolean audioOn) {
+ mIsReceivingRttAudio = audioOn;
}
public int getAudioQuality() {
@@ -280,7 +284,10 @@ public final class ImsStreamMediaProfile implements Parcelable {
return mRttMode;
}
- public boolean getRttAudioSpeech() {
- return mHasRttAudioSpeech;
+ /**
+ * @return true if remote party is transmitting audio, false otherwise.
+ */
+ public boolean isReceivingRttAudio() {
+ return mIsReceivingRttAudio;
}
}
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index d1a06925a902..c1260263e43e 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -17,10 +17,10 @@
package com.android.server;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.NETID_UNSET;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
-import static android.net.ConnectivityManager.NETID_UNSET;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
@@ -1798,6 +1798,12 @@ public class ConnectivityServiceTest {
fn.test((NetworkCapabilities) cbi.arg));
}
+ void expectLinkPropertiesLike(Predicate<LinkProperties> fn, MockNetworkAgent agent) {
+ CallbackInfo cbi = expectCallback(CallbackState.LINK_PROPERTIES, agent);
+ assertTrue("Received LinkProperties don't match expectations : " + cbi.arg,
+ fn.test((LinkProperties) cbi.arg));
+ }
+
void expectBlockedStatusCallback(boolean expectBlocked, MockNetworkAgent agent) {
CallbackInfo cbi = expectCallback(CallbackState.BLOCKED_STATUS, agent);
boolean actualBlocked = (boolean) cbi.arg;
@@ -5087,6 +5093,9 @@ public class ConnectivityServiceTest {
public void testStackedLinkProperties() throws UnknownHostException, RemoteException {
final LinkAddress myIpv4 = new LinkAddress("1.2.3.4/24");
final LinkAddress myIpv6 = new LinkAddress("2001:db8:1::1/64");
+ final String kNat64PrefixString = "2001:db8:64:64:64:64::";
+ final IpPrefix kNat64Prefix = new IpPrefix(InetAddress.getByName(kNat64PrefixString), 96);
+
final NetworkRequest networkRequest = new NetworkRequest.Builder()
.addTransportType(TRANSPORT_CELLULAR)
.addCapability(NET_CAPABILITY_INTERNET)
@@ -5094,8 +5103,9 @@ public class ConnectivityServiceTest {
final TestNetworkCallback networkCallback = new TestNetworkCallback();
mCm.registerNetworkCallback(networkRequest, networkCallback);
- // Prepare ipv6 only link properties and connect.
+ // Prepare ipv6 only link properties.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
+ final int cellNetId = mCellNetworkAgent.getNetwork().netId;
final LinkProperties cellLp = new LinkProperties();
cellLp.setInterfaceName(MOBILE_IFNAME);
cellLp.addLinkAddress(myIpv6);
@@ -5105,15 +5115,44 @@ public class ConnectivityServiceTest {
when(mNetworkManagementService.getInterfaceConfig(CLAT_PREFIX + MOBILE_IFNAME))
.thenReturn(getClatInterfaceConfig(myIpv4));
- // Connect with ipv6 link properties, then expect clat setup ipv4 and update link
- // properties properly.
+ // Connect with ipv6 link properties. Expect prefix discovery to be started.
mCellNetworkAgent.sendLinkProperties(cellLp);
mCellNetworkAgent.connect(true);
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
- verify(mMockNetd, times(1)).clatdStart(MOBILE_IFNAME);
- Nat464Xlat clat = mService.getNat464Xlat(mCellNetworkAgent);
+ verify(mMockNetd, times(1)).resolverStartPrefix64Discovery(cellNetId);
+
+ // Switching default network updates TCP buffer sizes.
+ verifyTcpBufferSizeChange(ConnectivityService.DEFAULT_TCP_BUFFER_SIZES);
+
+ // Add an IPv4 address. Expect prefix discovery to be stopped. Netd doesn't tell us that
+ // the NAT64 prefix was removed because one was never discovered.
+ cellLp.addLinkAddress(myIpv4);
+ mCellNetworkAgent.sendLinkProperties(cellLp);
+ networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
+ verify(mMockNetd, times(1)).resolverStopPrefix64Discovery(cellNetId);
+
+ verifyNoMoreInteractions(mMockNetd);
+ reset(mMockNetd);
+
+ // Remove IPv4 address. Expect prefix discovery to be started again.
+ cellLp.removeLinkAddress(myIpv4);
+ cellLp.removeRoute(new RouteInfo(myIpv4, null, MOBILE_IFNAME));
+ mCellNetworkAgent.sendLinkProperties(cellLp);
+ networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
+ verify(mMockNetd, times(1)).resolverStartPrefix64Discovery(cellNetId);
- // Clat iface up, expect stack link updated.
+ // When NAT64 prefix discovery succeeds, LinkProperties are updated and clatd is started.
+ Nat464Xlat clat = mService.getNat464Xlat(mCellNetworkAgent);
+ assertNull(mCm.getLinkProperties(mCellNetworkAgent.getNetwork()).getNat64Prefix());
+ mService.mNetdEventCallback.onNat64PrefixEvent(cellNetId, true /* added */,
+ kNat64PrefixString, 96);
+ LinkProperties lpBeforeClat = (LinkProperties) networkCallback.expectCallback(
+ CallbackState.LINK_PROPERTIES, mCellNetworkAgent).arg;
+ assertEquals(0, lpBeforeClat.getStackedLinks().size());
+ assertEquals(kNat64Prefix, lpBeforeClat.getNat64Prefix());
+ verify(mMockNetd, times(1)).clatdStart(MOBILE_IFNAME, kNat64Prefix.toString());
+
+ // Clat iface comes up. Expect stacked link to be added.
clat.interfaceLinkStateChanged(CLAT_PREFIX + MOBILE_IFNAME, true);
networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
List<LinkProperties> stackedLps = mCm.getLinkProperties(mCellNetworkAgent.getNetwork())
@@ -5130,20 +5169,66 @@ public class ConnectivityServiceTest {
assertNotEquals(stackedLpsAfterChange, Collections.EMPTY_LIST);
assertEquals(makeClatLinkProperties(myIpv4), stackedLpsAfterChange.get(0));
- // Add ipv4 address, expect stacked linkproperties be cleaned up
+ // Add ipv4 address, expect that clatd and prefix discovery are stopped and stacked
+ // linkproperties are cleaned up.
cellLp.addLinkAddress(myIpv4);
cellLp.addRoute(new RouteInfo(myIpv4, null, MOBILE_IFNAME));
mCellNetworkAgent.sendLinkProperties(cellLp);
networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
verify(mMockNetd, times(1)).clatdStop(MOBILE_IFNAME);
+ verify(mMockNetd, times(1)).resolverStopPrefix64Discovery(cellNetId);
- // Clat iface removed, expect linkproperties revert to original one
- clat.interfaceRemoved(CLAT_PREFIX + MOBILE_IFNAME);
+ // As soon as stop is called, the linkproperties lose the stacked interface.
networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
LinkProperties actualLpAfterIpv4 = mCm.getLinkProperties(mCellNetworkAgent.getNetwork());
- assertEquals(cellLp, actualLpAfterIpv4);
+ LinkProperties expected = new LinkProperties(cellLp);
+ expected.setNat64Prefix(kNat64Prefix);
+ assertEquals(expected, actualLpAfterIpv4);
+ assertEquals(0, actualLpAfterIpv4.getStackedLinks().size());
- // Clean up
+ // The interface removed callback happens but has no effect after stop is called.
+ clat.interfaceRemoved(CLAT_PREFIX + MOBILE_IFNAME);
+ networkCallback.assertNoCallback();
+
+ verifyNoMoreInteractions(mMockNetd);
+ reset(mMockNetd);
+
+ // Stopping prefix discovery causes netd to tell us that the NAT64 prefix is gone.
+ mService.mNetdEventCallback.onNat64PrefixEvent(cellNetId, false /* added */,
+ kNat64PrefixString, 96);
+ networkCallback.expectLinkPropertiesLike((lp) -> lp.getNat64Prefix() == null,
+ mCellNetworkAgent);
+
+ // Remove IPv4 address and expect prefix discovery and clatd to be started again.
+ cellLp.removeLinkAddress(myIpv4);
+ cellLp.removeRoute(new RouteInfo(myIpv4, null, MOBILE_IFNAME));
+ cellLp.removeDnsServer(InetAddress.getByName("8.8.8.8"));
+ mCellNetworkAgent.sendLinkProperties(cellLp);
+ networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
+ verify(mMockNetd, times(1)).resolverStartPrefix64Discovery(cellNetId);
+ mService.mNetdEventCallback.onNat64PrefixEvent(cellNetId, true /* added */,
+ kNat64PrefixString, 96);
+ networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
+ verify(mMockNetd, times(1)).clatdStart(MOBILE_IFNAME, kNat64Prefix.toString());
+
+
+ // Clat iface comes up. Expect stacked link to be added.
+ clat.interfaceLinkStateChanged(CLAT_PREFIX + MOBILE_IFNAME, true);
+ networkCallback.expectLinkPropertiesLike(
+ (lp) -> lp.getStackedLinks().size() == 1 && lp.getNat64Prefix() != null,
+ mCellNetworkAgent);
+
+ // NAT64 prefix is removed. Expect that clat is stopped.
+ mService.mNetdEventCallback.onNat64PrefixEvent(cellNetId, false /* added */,
+ kNat64PrefixString, 96);
+ networkCallback.expectLinkPropertiesLike(
+ (lp) -> lp.getStackedLinks().size() == 0 && lp.getNat64Prefix() == null,
+ mCellNetworkAgent);
+ verify(mMockNetd, times(1)).clatdStop(MOBILE_IFNAME);
+ networkCallback.expectLinkPropertiesLike((lp) -> lp.getStackedLinks().size() == 0,
+ mCellNetworkAgent);
+
+ // Clean up.
mCellNetworkAgent.disconnect();
networkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
networkCallback.assertNoCallback();
@@ -5224,30 +5309,34 @@ public class ConnectivityServiceTest {
mCm.unregisterNetworkCallback(networkCallback);
}
- private static final String TEST_TCP_BUFFER_SIZES = "1,2,3,4,5,6";
-
- private void verifyTcpBufferSizeChange(String tcpBufferSizes) throws Exception {
+ private void verifyTcpBufferSizeChange(String tcpBufferSizes) {
String[] values = tcpBufferSizes.split(",");
String rmemValues = String.join(" ", values[0], values[1], values[2]);
String wmemValues = String.join(" ", values[3], values[4], values[5]);
waitForIdle();
- verify(mMockNetd, atLeastOnce()).setTcpRWmemorySize(rmemValues, wmemValues);
+ try {
+ verify(mMockNetd, atLeastOnce()).setTcpRWmemorySize(rmemValues, wmemValues);
+ } catch (RemoteException e) {
+ fail("mMockNetd should never throw RemoteException");
+ }
reset(mMockNetd);
}
@Test
- public void testTcpBufferReset() throws Exception {
+ public void testTcpBufferReset() {
+ final String testTcpBufferSizes = "1,2,3,4,5,6";
+
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
reset(mMockNetd);
- // Simple connection should have updated tcp buffer size.
+ // Switching default network updates TCP buffer sizes.
mCellNetworkAgent.connect(false);
verifyTcpBufferSizeChange(ConnectivityService.DEFAULT_TCP_BUFFER_SIZES);
// Change link Properties should have updated tcp buffer size.
LinkProperties lp = new LinkProperties();
- lp.setTcpBufferSizes(TEST_TCP_BUFFER_SIZES);
+ lp.setTcpBufferSizes(testTcpBufferSizes);
mCellNetworkAgent.sendLinkProperties(lp);
- verifyTcpBufferSizeChange(TEST_TCP_BUFFER_SIZES);
+ verifyTcpBufferSizeChange(testTcpBufferSizes);
}
@Test
diff --git a/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java b/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
index 07b1d057c882..37c0df80f3e3 100644
--- a/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
+++ b/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
@@ -16,9 +16,11 @@
package com.android.server.connectivity;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -27,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.net.ConnectivityManager;
import android.net.INetd;
import android.net.InterfaceConfiguration;
+import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NetworkInfo;
@@ -43,6 +46,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -53,6 +57,8 @@ public class Nat464XlatTest {
static final String BASE_IFACE = "test0";
static final String STACKED_IFACE = "v4-test0";
static final LinkAddress ADDR = new LinkAddress("192.0.2.5/29");
+ static final String NAT64_PREFIX = "64:ff9b::/96";
+ static final int NETID = 42;
@Mock ConnectivityService mConnectivity;
@Mock NetworkMisc mMisc;
@@ -65,7 +71,11 @@ public class Nat464XlatTest {
Handler mHandler;
Nat464Xlat makeNat464Xlat() {
- return new Nat464Xlat(mNai, mNetd, mNms);
+ return new Nat464Xlat(mNai, mNetd, mNms) {
+ @Override protected int getNetId() {
+ return NETID;
+ }
+ };
}
@Before
@@ -87,6 +97,24 @@ public class Nat464XlatTest {
when(mConfig.getLinkAddress()).thenReturn(ADDR);
}
+ private void assertRequiresClat(boolean expected, NetworkAgentInfo nai) {
+ String msg = String.format("requiresClat expected %b for type=%d state=%s skip=%b "
+ + "nat64Prefix=%s addresses=%s", expected, nai.networkInfo.getType(),
+ nai.networkInfo.getDetailedState(),
+ mMisc.skip464xlat, nai.linkProperties.getNat64Prefix(),
+ nai.linkProperties.getLinkAddresses());
+ assertEquals(msg, expected, Nat464Xlat.requiresClat(nai));
+ }
+
+ private void assertShouldStartClat(boolean expected, NetworkAgentInfo nai) {
+ String msg = String.format("shouldStartClat expected %b for type=%d state=%s skip=%b "
+ + "nat64Prefix=%s addresses=%s", expected, nai.networkInfo.getType(),
+ nai.networkInfo.getDetailedState(),
+ mMisc.skip464xlat, nai.linkProperties.getNat64Prefix(),
+ nai.linkProperties.getLinkAddresses());
+ assertEquals(msg, expected, Nat464Xlat.shouldStartClat(nai));
+ }
+
@Test
public void testRequiresClat() throws Exception {
final int[] supportedTypes = {
@@ -102,20 +130,45 @@ public class Nat464XlatTest {
NetworkInfo.DetailedState.SUSPENDED,
};
+ LinkProperties oldLp = new LinkProperties(mNai.linkProperties);
for (int type : supportedTypes) {
mNai.networkInfo.setType(type);
for (NetworkInfo.DetailedState state : supportedDetailedStates) {
mNai.networkInfo.setDetailedState(state, "reason", "extraInfo");
- String msg = String.format("requiresClat expected for type=%d state=%s",
- type, state);
+
+ mNai.linkProperties.setNat64Prefix(new IpPrefix("2001:db8:0:64::/96"));
+ assertRequiresClat(false, mNai);
+ assertShouldStartClat(false, mNai);
+
+ mNai.linkProperties.addLinkAddress(new LinkAddress("fc00::1/64"));
+ assertRequiresClat(false, mNai);
+ assertShouldStartClat(false, mNai);
+
+ mNai.linkProperties.addLinkAddress(new LinkAddress("2001:db8::1/64"));
+ assertRequiresClat(true, mNai);
+ assertShouldStartClat(true, mNai);
mMisc.skip464xlat = true;
- String errorMsg = msg + String.format(" skip464xlat=%b", mMisc.skip464xlat);
- assertFalse(errorMsg, Nat464Xlat.requiresClat(mNai));
+ assertRequiresClat(false, mNai);
+ assertShouldStartClat(false, mNai);
mMisc.skip464xlat = false;
- errorMsg = msg + String.format(" skip464xlat=%b", mMisc.skip464xlat);
- assertTrue(errorMsg, Nat464Xlat.requiresClat(mNai));
+ assertRequiresClat(true, mNai);
+ assertShouldStartClat(true, mNai);
+
+ mNai.linkProperties.addLinkAddress(new LinkAddress("192.0.2.2/24"));
+ assertRequiresClat(false, mNai);
+ assertShouldStartClat(false, mNai);
+
+ mNai.linkProperties.removeLinkAddress(new LinkAddress("192.0.2.2/24"));
+ assertRequiresClat(true, mNai);
+ assertShouldStartClat(true, mNai);
+
+ mNai.linkProperties.setNat64Prefix(null);
+ assertRequiresClat(true, mNai);
+ assertShouldStartClat(false, mNai);
+
+ mNai.linkProperties = new LinkProperties(oldLp);
}
}
}
@@ -125,11 +178,13 @@ public class Nat464XlatTest {
Nat464Xlat nat = makeNat464Xlat();
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
- // ConnectivityService starts clat.
+ nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX));
+
+ // Start clat.
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNetd).clatdStart(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
// Stacked interface up notification arrives.
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
@@ -141,22 +196,109 @@ public class Nat464XlatTest {
assertTrue(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
assertRunning(nat);
- // ConnectivityService stops clat (Network disconnects, IPv4 addr appears, ...).
+ // Stop clat (Network disconnects, IPv4 addr appears, ...).
nat.stop();
verify(mNetd).clatdStop(eq(BASE_IFACE));
+ verify(mConnectivity, times(2)).handleUpdateLinkProperties(eq(mNai), c.capture());
+ verify(mNms).unregisterObserver(eq(nat));
+ assertTrue(c.getValue().getStackedLinks().isEmpty());
+ assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
+ verify(mNetd).resolverStopPrefix64Discovery(eq(NETID));
+ assertIdle(nat);
- // Stacked interface removed notification arrives.
+ // Stacked interface removed notification arrives and is ignored.
nat.interfaceRemoved(STACKED_IFACE);
mLooper.dispatchNext();
- verify(mNms).unregisterObserver(eq(nat));
- verify(mConnectivity, times(2)).handleUpdateLinkProperties(eq(mNai), c.capture());
+ verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
+ }
+
+ private void checkStartStopStart(boolean interfaceRemovedFirst) throws Exception {
+ Nat464Xlat nat = makeNat464Xlat();
+ ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
+ InOrder inOrder = inOrder(mNetd, mConnectivity);
+
+ nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX));
+
+ nat.start();
+
+ inOrder.verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
+
+ // Stacked interface up notification arrives.
+ nat.interfaceLinkStateChanged(STACKED_IFACE, true);
+ mLooper.dispatchNext();
+
+ inOrder.verify(mConnectivity).handleUpdateLinkProperties(eq(mNai), c.capture());
+ assertFalse(c.getValue().getStackedLinks().isEmpty());
+ assertTrue(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
+ assertRunning(nat);
+
+ // ConnectivityService stops clat (Network disconnects, IPv4 addr appears, ...).
+ nat.stop();
+
+ inOrder.verify(mNetd).clatdStop(eq(BASE_IFACE));
+
+ inOrder.verify(mConnectivity, times(1)).handleUpdateLinkProperties(eq(mNai), c.capture());
assertTrue(c.getValue().getStackedLinks().isEmpty());
assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
assertIdle(nat);
- verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
+ if (interfaceRemovedFirst) {
+ // Stacked interface removed notification arrives and is ignored.
+ nat.interfaceRemoved(STACKED_IFACE);
+ mLooper.dispatchNext();
+ nat.interfaceLinkStateChanged(STACKED_IFACE, false);
+ mLooper.dispatchNext();
+ }
+
+ assertTrue(c.getValue().getStackedLinks().isEmpty());
+ assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
+ assertIdle(nat);
+ inOrder.verifyNoMoreInteractions();
+
+ nat.start();
+
+ inOrder.verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
+
+ if (!interfaceRemovedFirst) {
+ // Stacked interface removed notification arrives and is ignored.
+ nat.interfaceRemoved(STACKED_IFACE);
+ mLooper.dispatchNext();
+ nat.interfaceLinkStateChanged(STACKED_IFACE, false);
+ mLooper.dispatchNext();
+ }
+
+ // Stacked interface up notification arrives.
+ nat.interfaceLinkStateChanged(STACKED_IFACE, true);
+ mLooper.dispatchNext();
+
+ inOrder.verify(mConnectivity).handleUpdateLinkProperties(eq(mNai), c.capture());
+ assertFalse(c.getValue().getStackedLinks().isEmpty());
+ assertTrue(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
+ assertRunning(nat);
+
+ // ConnectivityService stops clat again.
+ nat.stop();
+
+ inOrder.verify(mNetd).clatdStop(eq(BASE_IFACE));
+
+ inOrder.verify(mConnectivity, times(1)).handleUpdateLinkProperties(eq(mNai), c.capture());
+ assertTrue(c.getValue().getStackedLinks().isEmpty());
+ assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
+ assertIdle(nat);
+
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ @Test
+ public void testStartStopStart() throws Exception {
+ checkStartStopStart(true);
+ }
+
+ @Test
+ public void testStartStopStartBeforeInterfaceRemoved() throws Exception {
+ checkStartStopStart(false);
}
@Test
@@ -164,11 +306,12 @@ public class Nat464XlatTest {
Nat464Xlat nat = makeNat464Xlat();
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
- // ConnectivityService starts clat.
+ nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX));
+
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNetd).clatdStart(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
// Stacked interface up notification arrives.
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
@@ -184,9 +327,10 @@ public class Nat464XlatTest {
nat.interfaceRemoved(STACKED_IFACE);
mLooper.dispatchNext();
- verify(mNms).unregisterObserver(eq(nat));
verify(mNetd).clatdStop(eq(BASE_IFACE));
verify(mConnectivity, times(2)).handleUpdateLinkProperties(eq(mNai), c.capture());
+ verify(mNms).unregisterObserver(eq(nat));
+ verify(mNetd).resolverStopPrefix64Discovery(eq(NETID));
assertTrue(c.getValue().getStackedLinks().isEmpty());
assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
assertIdle(nat);
@@ -201,24 +345,25 @@ public class Nat464XlatTest {
public void testStopBeforeClatdStarts() throws Exception {
Nat464Xlat nat = makeNat464Xlat();
- // ConnectivityService starts clat.
+ nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX));
+
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNetd).clatdStart(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
nat.stop();
- verify(mNms).unregisterObserver(eq(nat));
verify(mNetd).clatdStop(eq(BASE_IFACE));
+ verify(mNms).unregisterObserver(eq(nat));
+ verify(mNetd).resolverStopPrefix64Discovery(eq(NETID));
assertIdle(nat);
// In-flight interface up notification arrives: no-op
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
mLooper.dispatchNext();
-
// Interface removed notification arrives after stopClatd() takes effect: no-op.
nat.interfaceRemoved(STACKED_IFACE);
mLooper.dispatchNext();
@@ -232,17 +377,19 @@ public class Nat464XlatTest {
public void testStopAndClatdNeverStarts() throws Exception {
Nat464Xlat nat = makeNat464Xlat();
- // ConnectivityService starts clat.
+ nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX));
+
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNetd).clatdStart(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
nat.stop();
- verify(mNms).unregisterObserver(eq(nat));
verify(mNetd).clatdStop(eq(BASE_IFACE));
+ verify(mNms).unregisterObserver(eq(nat));
+ verify(mNetd).resolverStopPrefix64Discovery(eq(NETID));
assertIdle(nat);
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py
index 59e89f515e82..295e3de544ee 100644
--- a/tools/apilint/apilint.py
+++ b/tools/apilint/apilint.py
@@ -79,6 +79,7 @@ class Field():
self.value = raw[3].strip(';"')
else:
self.value = None
+ self.annotations = []
self.ident = "-".join((self.typ, self.name, self.value or ""))
@@ -88,6 +89,18 @@ class Field():
def __repr__(self):
return self.raw
+
+class Argument(object):
+
+ __slots__ = ["type", "annotations", "name", "default"]
+
+ def __init__(self, type):
+ self.type = type
+ self.annotations = []
+ self.name = None
+ self.default = None
+
+
class Method():
def __init__(self, clazz, line, raw, blame, sig_format = 1):
self.clazz = clazz
@@ -118,21 +131,24 @@ class Method():
self.name = raw[1]
# parse args
- self.args = []
+ self.detailed_args = []
for arg in re.split(",\s*", raw_args):
arg = re.split("\s", arg)
# ignore annotations for now
arg = [ a for a in arg if not a.startswith("@") ]
if len(arg[0]) > 0:
- self.args.append(arg[0])
+ self.detailed_args.append(Argument(arg[0]))
# parse throws
self.throws = []
for throw in re.split(",\s*", raw_throws):
self.throws.append(throw)
+
+ self.annotations = []
else:
raise ValueError("Unknown signature format: " + sig_format)
+ self.args = map(lambda a: a.type, self.detailed_args)
self.ident = "-".join((self.typ, self.name, "-".join(self.args)))
def sig_matches(self, typ, name, args):
@@ -208,13 +224,14 @@ class Class():
class Package():
+ NAME = re.compile("package(?: .*)? ([A-Za-z.]+)")
+
def __init__(self, line, raw, blame):
self.line = line
self.raw = raw.strip(" {;")
self.blame = blame
- raw = raw.split()
- self.name = raw[raw.index("package")+1]
+ self.name = Package.NAME.match(raw).group(1)
self.name_path = self.name.split(".")
def __repr__(self):
@@ -311,10 +328,10 @@ class V2LineParser(object):
method.split = []
kind = self.parse_one_of("ctor", "method")
method.split.append(kind)
- annotations = self.parse_annotations()
+ method.annotations = self.parse_annotations()
method.split.extend(self.parse_modifiers())
self.parse_matching_paren("<", ">")
- if "@Deprecated" in annotations:
+ if "@Deprecated" in method.annotations:
method.split.append("deprecated")
if kind == "ctor":
method.typ = "ctor"
@@ -324,7 +341,7 @@ class V2LineParser(object):
method.name = self.parse_name()
method.split.append(method.name)
self.parse_token("(")
- method.args = self.parse_args()
+ method.detailed_args = self.parse_args()
self.parse_token(")")
method.throws = self.parse_throws()
if "@interface" in method.clazz.split:
@@ -359,8 +376,8 @@ class V2LineParser(object):
def parse_into_field(self, field):
kind = self.parse_one_of(*V2LineParser.FIELD_KINDS)
field.split = [kind]
- annotations = self.parse_annotations()
- if "@Deprecated" in annotations:
+ field.annotations = self.parse_annotations()
+ if "@Deprecated" in field.annotations:
field.split.append("deprecated")
field.split.extend(self.parse_modifiers())
field.typ = self.parse_type()
@@ -487,15 +504,16 @@ class V2LineParser(object):
def parse_arg(self):
self.parse_if("vararg") # kotlin vararg
- self.parse_annotations()
- type = self.parse_arg_type()
+ annotations = self.parse_annotations()
+ arg = Argument(self.parse_arg_type())
+ arg.annotations = annotations
l = self.lookahead()
if l != "," and l != ")":
if self.lookahead() != '=':
- self.parse_token() # kotlin argument name
+ arg.name = self.parse_token() # kotlin argument name
if self.parse_if('='): # kotlin default value
- self.parse_expression()
- return type
+ arg.default = self.parse_expression()
+ return arg
def parse_expression(self):
while not self.lookahead() in [')', ',', ';']:
@@ -592,7 +610,7 @@ def _parse_stream_to_generator(f):
blame = None
sig_format = 1
- re_blame = re.compile("^([a-z0-9]{7,}) \(<([^>]+)>.+?\) (.+?)$")
+ re_blame = re.compile(r"^(\^?[a-z0-9]{7,}) \(<([^>]+)>.+?\) (.+?)$")
field_prefixes = map(lambda kind: " %s" % (kind,), V2LineParser.FIELD_KINDS)
def startsWithFieldPrefix(raw):
@@ -607,11 +625,13 @@ def _parse_stream_to_generator(f):
match = re_blame.match(raw)
if match is not None:
blame = match.groups()[0:2]
+ if blame[0].startswith("^"): # Outside of blame range
+ blame = None
raw = match.groups()[2]
else:
blame = None
- if line == 1 and raw.startswith("// Signature format: "):
+ if line == 1 and V2Tokenizer.SIGNATURE_PREFIX in raw:
sig_format_string = raw[len(V2Tokenizer.SIGNATURE_PREFIX):]
if sig_format_string in ["2.0", "3.0"]:
sig_format = 2
@@ -1108,6 +1128,9 @@ def verify_builder(clazz):
if not has_build:
warn(clazz, None, None, "Missing build() method")
+ if "final" not in clazz.split:
+ error(clazz, None, None, "Builder should be final")
+
def verify_aidl(clazz):
"""Catch people exposing raw AIDL."""
@@ -1867,6 +1890,35 @@ def verify_numbers(clazz):
if arg in discouraged:
warn(clazz, m, "FW12", "Should avoid odd sized primitives; use int instead")
+PRIMITIVES = {"void", "int", "float", "boolean", "short", "char", "byte", "long", "double"}
+
+def verify_nullability(clazz):
+ """Catches missing nullability annotations"""
+
+ for f in clazz.fields:
+ if f.value is not None and 'static' in f.split and 'final' in f.split:
+ continue # Nullability of constants can be inferred.
+ if f.typ not in PRIMITIVES and not has_nullability(f.annotations):
+ error(clazz, f, "M12", "Field must be marked either @NonNull or @Nullable")
+
+ for c in clazz.ctors:
+ verify_nullability_args(clazz, c)
+
+ for m in clazz.methods:
+ if m.name == "writeToParcel" or m.name == "onReceive":
+ continue # Parcelable.writeToParcel() and BroadcastReceiver.onReceive() are not yet annotated
+
+ if m.typ not in PRIMITIVES and not has_nullability(m.annotations):
+ error(clazz, m, "M12", "Return value must be marked either @NonNull or @Nullable")
+ verify_nullability_args(clazz, m)
+
+def verify_nullability_args(clazz, m):
+ for i, arg in enumerate(m.detailed_args):
+ if arg.type not in PRIMITIVES and not has_nullability(arg.annotations):
+ error(clazz, m, "M12", "Argument %d must be marked either @NonNull or @Nullable" % (i+1,))
+
+def has_nullability(annotations):
+ return "@NonNull" in annotations or "@Nullable" in annotations
def verify_singleton(clazz):
"""Catch singleton objects with constructors."""
@@ -1955,6 +2007,7 @@ def examine_clazz(clazz):
verify_pfd(clazz)
verify_numbers(clazz)
verify_singleton(clazz)
+ verify_nullability(clazz)
def examine_stream(stream, base_stream=None, in_classes_with_base=[], out_classes_with_base=None):
diff --git a/tools/apilint/apilint_test.py b/tools/apilint/apilint_test.py
index 3716bf9f5d6f..f34492d644ce 100644
--- a/tools/apilint/apilint_test.py
+++ b/tools/apilint/apilint_test.py
@@ -88,20 +88,22 @@ class UtilTests(unittest.TestCase):
faulty_current_txt = """
+// Signature format: 2.0
package android.app {
public final class Activity {
}
public final class WallpaperColors implements android.os.Parcelable {
- ctor public WallpaperColors(android.os.Parcel);
+ ctor public WallpaperColors(@NonNull android.os.Parcel);
method public int describeContents();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR;
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR;
}
}
-""".split('\n')
+""".strip().split('\n')
ok_current_txt = """
+// Signature format: 2.0
package android.app {
public final class Activity {
}
@@ -109,19 +111,20 @@ package android.app {
public final class WallpaperColors implements android.os.Parcelable {
ctor public WallpaperColors();
method public int describeContents();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR;
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR;
}
}
-""".split('\n')
+""".strip().split('\n')
system_current_txt = """
+// Signature format: 2.0
package android.app {
public final class WallpaperColors implements android.os.Parcelable {
method public int getSomething();
}
}
-""".split('\n')
+""".strip().split('\n')
@@ -369,5 +372,21 @@ class V2ParserTests(unittest.TestCase):
m = self._method('method @NonNull public @NonNull String @NonNull [] split(@NonNull String, int);')
self.assertEquals('java.lang.String[]', m.typ)
+class PackageTests(unittest.TestCase):
+ def _package(self, raw):
+ return apilint.Package(123, raw, "blame")
+
+ def test_regular_package(self):
+ p = self._package("package an.pref.int {")
+ self.assertEquals('an.pref.int', p.name)
+
+ def test_annotation_package(self):
+ p = self._package("package @RestrictTo(a.b.C) an.pref.int {")
+ self.assertEquals('an.pref.int', p.name)
+
+ def test_multi_annotation_package(self):
+ p = self._package("package @Rt(a.b.L_G_P) @RestrictTo(a.b.C) an.pref.int {")
+ self.assertEquals('an.pref.int', p.name)
+
if __name__ == "__main__":
unittest.main()