Merge "Reword outdated fonts comment"
diff --git a/api/system-current.txt b/api/system-current.txt
index 5bac2b7..b674e92 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -9446,17 +9446,17 @@
 
   public class ImsSmsImplBase {
     ctor public ImsSmsImplBase();
-    method public void acknowledgeSms(int, int, int);
-    method public void acknowledgeSmsReport(int, int, int);
+    method public void acknowledgeSms(int, @IntRange(from=0, to=65535) int, int);
+    method public void acknowledgeSmsReport(int, @IntRange(from=0, to=65535) int, int);
     method public String getSmsFormat();
     method public void onReady();
-    method @Deprecated public final void onSendSmsResult(int, int, int, int) throws java.lang.RuntimeException;
-    method public final void onSendSmsResultError(int, int, int, int, int) throws java.lang.RuntimeException;
-    method public final void onSendSmsResultSuccess(int, int) throws java.lang.RuntimeException;
+    method @Deprecated public final void onSendSmsResult(int, @IntRange(from=0, to=65535) int, int, int) throws java.lang.RuntimeException;
+    method public final void onSendSmsResultError(int, @IntRange(from=0, to=65535) int, int, int, int) throws java.lang.RuntimeException;
+    method public final void onSendSmsResultSuccess(int, @IntRange(from=0, to=65535) int) throws java.lang.RuntimeException;
     method public final void onSmsReceived(int, String, byte[]) throws java.lang.RuntimeException;
-    method @Deprecated public final void onSmsStatusReportReceived(int, int, String, byte[]) throws java.lang.RuntimeException;
+    method @Deprecated public final void onSmsStatusReportReceived(int, @IntRange(from=0, to=65535) int, String, byte[]) throws java.lang.RuntimeException;
     method public final void onSmsStatusReportReceived(int, String, byte[]) throws java.lang.RuntimeException;
-    method public void sendSms(int, int, String, String, boolean, byte[]);
+    method public void sendSms(int, @IntRange(from=0, to=65535) int, String, String, boolean, byte[]);
     field public static final int DELIVER_STATUS_ERROR_GENERIC = 2; // 0x2
     field public static final int DELIVER_STATUS_ERROR_NO_MEMORY = 3; // 0x3
     field public static final int DELIVER_STATUS_ERROR_REQUEST_NOT_SUPPORTED = 4; // 0x4
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index 475f18a..69e6a11 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -119,9 +119,10 @@
          {.puller = new StatsCompanionServicePuller(android::util::BLUETOOTH_ACTIVITY_INFO)}},
         // system_elapsed_realtime
         {android::util::SYSTEM_ELAPSED_REALTIME,
-         {.pullTimeoutNs = NS_PER_SEC / 2,
-          .coolDownNs = NS_PER_SEC,
-          .puller = new StatsCompanionServicePuller(android::util::SYSTEM_ELAPSED_REALTIME)}},
+         {.coolDownNs = NS_PER_SEC,
+          .puller = new StatsCompanionServicePuller(android::util::SYSTEM_ELAPSED_REALTIME),
+          .pullTimeoutNs = NS_PER_SEC / 2,
+         }},
         // system_uptime
         {android::util::SYSTEM_UPTIME,
          {.puller = new StatsCompanionServicePuller(android::util::SYSTEM_UPTIME)}},
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index 6178b2b..357c0c9 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -1063,4 +1063,13 @@
         StrictMode.clearGatheredViolations();
         return res;
     }
+
+    /**
+     * Returns the specified service from servicemanager. If the service is not running,
+     * servicemanager will attempt to start it, and this function will wait for it to be ready.
+     * Returns nullptr only if there are permission problems or fatal errors.
+     * @hide
+     */
+    public static final native @Nullable IBinder waitForService(@NonNull String serviceName)
+            throws RemoteException;
 }
diff --git a/core/java/android/webkit/FindAddress.java b/core/java/android/webkit/FindAddress.java
index 9183227..b146e3f6 100644
--- a/core/java/android/webkit/FindAddress.java
+++ b/core/java/android/webkit/FindAddress.java
@@ -154,7 +154,7 @@
 
     // A house number component is "one" or a number, optionally
     // followed by a single alphabetic character, or
-    private static final String HOUSE_COMPONENT = "(?:one|\\d+([a-z](?=[^a-z]|$)|st|nd|rd|th)?)";
+    private static final String HOUSE_COMPONENT = "(?:one|[0-9]+([a-z](?=[^a-z]|$)|st|nd|rd|th)?)";
 
     // House numbers are a repetition of |HOUSE_COMPONENT|, separated by -, and followed by
     // a delimiter character.
@@ -253,10 +253,10 @@
             Pattern.CASE_INSENSITIVE);
 
     private static final Pattern sSuffixedNumberRe =
-            Pattern.compile("(\\d+)(st|nd|rd|th)", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("([0-9]+)(st|nd|rd|th)", Pattern.CASE_INSENSITIVE);
 
     private static final Pattern sZipCodeRe =
-            Pattern.compile("(?:\\d{5}(?:-\\d{4})?)" + WORD_END, Pattern.CASE_INSENSITIVE);
+            Pattern.compile("(?:[0-9]{5}(?:-[0-9]{4})?)" + WORD_END, Pattern.CASE_INSENSITIVE);
 
     private static boolean checkHouseNumber(String houseNumber) {
         // Make sure that there are at most 5 digits.
diff --git a/core/java/com/android/internal/compat/CompatibilityChangeConfig.aidl b/core/java/com/android/internal/compat/CompatibilityChangeConfig.aidl
new file mode 100644
index 0000000..434c1b8
--- /dev/null
+++ b/core/java/com/android/internal/compat/CompatibilityChangeConfig.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.compat;
+
+parcelable CompatibilityChangeConfig;
diff --git a/core/java/com/android/internal/compat/CompatibilityChangeConfig.java b/core/java/com/android/internal/compat/CompatibilityChangeConfig.java
new file mode 100644
index 0000000..fd2ada0
--- /dev/null
+++ b/core/java/com/android/internal/compat/CompatibilityChangeConfig.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.compat;
+
+
+import android.compat.Compatibility.ChangeConfig;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Parcelable containing compat config overrides for a given application.
+ * @hide
+ */
+public final class CompatibilityChangeConfig implements Parcelable {
+    private final ChangeConfig mChangeConfig;
+
+    public CompatibilityChangeConfig(ChangeConfig changeConfig) {
+        mChangeConfig = changeConfig;
+    }
+
+    /**
+     * Changes forced to be enabled.
+     */
+    public Set<Long> enabledChanges() {
+        return mChangeConfig.forceEnabledSet();
+    }
+
+    /**
+     * Changes forced to be disabled.
+     */
+    public Set<Long> disabledChanges() {
+        return mChangeConfig.forceDisabledSet();
+    }
+
+    private CompatibilityChangeConfig(Parcel in) {
+        long[] enabledArray = in.createLongArray();
+        long[] disabledArray = in.createLongArray();
+        Set<Long> enabled = toLongSet(enabledArray);
+        Set<Long> disabled = toLongSet(disabledArray);
+        mChangeConfig = new ChangeConfig(enabled, disabled);
+    }
+
+    private static Set<Long> toLongSet(long[] values) {
+        Set<Long> ret = new HashSet<>();
+        for (long value: values) {
+            ret.add(value);
+        }
+        return ret;
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        long[] enabled = mChangeConfig.forceEnabledChangesArray();
+        long[] disabled = mChangeConfig.forceDisabledChangesArray();
+
+        dest.writeLongArray(enabled);
+        dest.writeLongArray(disabled);
+    }
+
+    public static final Parcelable.Creator<CompatibilityChangeConfig> CREATOR =
+            new Parcelable.Creator<CompatibilityChangeConfig>() {
+
+                @Override
+                public CompatibilityChangeConfig createFromParcel(Parcel in) {
+                    return new CompatibilityChangeConfig(in);
+                }
+
+                @Override
+                public CompatibilityChangeConfig[] newArray(int size) {
+                    return new CompatibilityChangeConfig[size];
+                }
+            };
+}
diff --git a/core/java/com/android/internal/compat/IPlatformCompat.aidl b/core/java/com/android/internal/compat/IPlatformCompat.aidl
index 4d8378a..4099cfa 100644
--- a/core/java/com/android/internal/compat/IPlatformCompat.aidl
+++ b/core/java/com/android/internal/compat/IPlatformCompat.aidl
@@ -18,6 +18,8 @@
 
 import android.content.pm.ApplicationInfo;
 
+parcelable CompatibilityChangeConfig;
+
 /**
  * Platform private API for talking with the PlatformCompat service.
  *
@@ -125,4 +127,21 @@
      * @return {@code true} if the change is enabled for the current app.
      */
     boolean isChangeEnabledByUid(long changeId, int uid);
-}
\ No newline at end of file
+
+    /**
+     * Add overrides to compatibility changes.
+     *
+     * @param overrides Parcelable containing the compat change overrides to be applied.
+     * @param packageName The package name of the app whose changes will be overridden.
+     *
+     */
+    void setOverrides(in CompatibilityChangeConfig overrides, in String packageName);
+
+    /**
+     * Revert overrides to compatibility changes.
+     *
+     * @param packageName The package name of the app whose overrides will be cleared.
+     *
+     */
+    void clearOverrides(in String packageName);
+}
diff --git a/core/jni/Android.bp b/core/jni/Android.bp
index 6dd6d45..6270d89 100644
--- a/core/jni/Android.bp
+++ b/core/jni/Android.bp
@@ -294,8 +294,6 @@
         "libnativeloader_lazy",
         "libmemunreachable",
         "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
         "libvintf",
         "libnativewindow",
         "libhwui",
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 0afbaa0e..fe7e508 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -989,6 +989,31 @@
     return IPCThreadState::self()->blockUntilThreadAvailable();
 }
 
+static jobject android_os_Binder_waitForService(
+        JNIEnv *env,
+        jclass /* clazzObj */,
+        jstring serviceNameObj) {
+
+    const jchar* serviceName = env->GetStringCritical(serviceNameObj, nullptr);
+    if (!serviceName) {
+        signalExceptionForError(env, nullptr, BAD_VALUE, true /*canThrowRemoteException*/);
+        return nullptr;
+    }
+    String16 nameCopy = String16(reinterpret_cast<const char16_t *>(serviceName),
+            env->GetStringLength(serviceNameObj));
+    env->ReleaseStringCritical(serviceNameObj, serviceName);
+
+    auto sm = android::defaultServiceManager();
+    sp<IBinder> service = sm->waitForService(nameCopy);
+
+    if (!service) {
+        signalExceptionForError(env, nullptr, NAME_NOT_FOUND, true /*canThrowRemoteException*/);
+        return nullptr;
+    }
+
+    return javaObjectForIBinder(env, service);
+}
+
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod gBinderMethods[] = {
@@ -1016,7 +1041,8 @@
     { "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
     { "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
     { "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
-    { "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable }
+    { "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable },
+    { "waitForService", "(Ljava/lang/String;)Landroid/os/IBinder;", (void*)android_os_Binder_waitForService }
 };
 
 const char* const kBinderPathName = "android/os/Binder";
diff --git a/services/core/java/com/android/server/compat/CompatConfig.java b/services/core/java/com/android/server/compat/CompatConfig.java
index 027e2fb..0fabd9a 100644
--- a/services/core/java/com/android/server/compat/CompatConfig.java
+++ b/services/core/java/com/android/server/compat/CompatConfig.java
@@ -25,6 +25,7 @@
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.compat.CompatibilityChangeConfig;
 import com.android.server.compat.config.Change;
 import com.android.server.compat.config.XmlParser;
 
@@ -186,6 +187,43 @@
         }
         return overrideExists;
     }
+    /**
+     * Overrides the enabled state for a given change and app. This method is intended to be used
+     * *only* for debugging purposes.
+     *
+     * <p>Note, package overrides are not persistent and will be lost on system or runtime restart.
+     *
+     * @param overrides list of overrides to default changes config.
+     * @param packageName app for which the overrides will be applied.
+     */
+    public void addOverrides(
+            CompatibilityChangeConfig overrides, String packageName) {
+        synchronized (mChanges) {
+            for (Long changeId: overrides.enabledChanges()) {
+                addOverride(changeId, packageName, true);
+            }
+            for (Long changeId: overrides.disabledChanges()) {
+                addOverride(changeId, packageName, false);
+            }
+        }
+    }
+
+    /**
+     * Removes all overrides previously added via {@link #addOverride(long, String, boolean)} or
+     * {@link #addAppOverrides(CompatibilityChangeConfig, String)} for a certain package.
+     *
+     * <p>This restores the default behaviour for the given change and app, once any app
+     * processes have been restarted.
+     *
+     * @param packageName The package for which the overrides should be purged.
+     */
+    public void removePackageOverrides(String packageName) {
+        synchronized (mChanges) {
+            for (int i = 0; i < mChanges.size(); ++i) {
+                mChanges.valueAt(i).removePackageOverride(packageName);
+            }
+        }
+    }
 
     /**
     * Dumps the current list of compatibility config information.
diff --git a/services/core/java/com/android/server/compat/PlatformCompat.java b/services/core/java/com/android/server/compat/PlatformCompat.java
index a737888..8a7dcc1 100644
--- a/services/core/java/com/android/server/compat/PlatformCompat.java
+++ b/services/core/java/com/android/server/compat/PlatformCompat.java
@@ -23,6 +23,7 @@
 import android.util.StatsLog;
 
 import com.android.internal.compat.ChangeReporter;
+import com.android.internal.compat.CompatibilityChangeConfig;
 import com.android.internal.compat.IPlatformCompat;
 import com.android.internal.util.DumpUtils;
 
@@ -100,6 +101,17 @@
     }
 
     @Override
+    public void setOverrides(CompatibilityChangeConfig overrides, String packageName) {
+        CompatConfig.get().addOverrides(overrides, packageName);
+    }
+
+    @Override
+    public void clearOverrides(String packageName) {
+        CompatConfig config = CompatConfig.get();
+        config.removePackageOverrides(packageName);
+    }
+
+    @Override
     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, "platform_compat", pw)) return;
         CompatConfig.get().dumpConfig(pw);
diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java
index 8c14cb4..209d462 100644
--- a/telephony/java/android/telephony/SmsManager.java
+++ b/telephony/java/android/telephony/SmsManager.java
@@ -2021,6 +2021,36 @@
 
     // SMS send failure result codes
 
+    /** @hide */
+    @IntDef(prefix = { "RESULT" }, value = {
+            RESULT_ERROR_NONE,
+            RESULT_ERROR_GENERIC_FAILURE,
+            RESULT_ERROR_RADIO_OFF,
+            RESULT_ERROR_NULL_PDU,
+            RESULT_ERROR_NO_SERVICE,
+            RESULT_ERROR_LIMIT_EXCEEDED,
+            RESULT_ERROR_FDN_CHECK_FAILURE,
+            RESULT_ERROR_SHORT_CODE_NOT_ALLOWED,
+            RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED,
+            RESULT_RADIO_NOT_AVAILABLE,
+            RESULT_NETWORK_REJECT,
+            RESULT_INVALID_ARGUMENTS,
+            RESULT_INVALID_STATE,
+            RESULT_NO_MEMORY,
+            RESULT_INVALID_SMS_FORMAT,
+            RESULT_SYSTEM_ERROR,
+            RESULT_MODEM_ERROR,
+            RESULT_NETWORK_ERROR,
+            RESULT_INVALID_SMSC_ADDRESS,
+            RESULT_OPERATION_NOT_ALLOWED,
+            RESULT_INTERNAL_ERROR,
+            RESULT_NO_RESOURCES,
+            RESULT_CANCELLED,
+            RESULT_REQUEST_NOT_SUPPORTED
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface Result {}
+
     /**
      * No error.
      * @hide
diff --git a/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java b/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java
index 175769b..36ece95 100644
--- a/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java
+++ b/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java
@@ -17,6 +17,7 @@
 package android.telephony.ims.stub;
 
 import android.annotation.IntDef;
+import android.annotation.IntRange;
 import android.annotation.SystemApi;
 import android.os.RemoteException;
 import android.telephony.SmsManager;
@@ -148,14 +149,16 @@
      *
      * @param token unique token generated by the platform that should be used when triggering
      *             callbacks for this specific message.
-     * @param messageRef the message reference.
-     * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
-     *               {@link SmsMessage#FORMAT_3GPP2}.
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format (see TS.123.040) or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
+     * @param format the format of the message.
      * @param smsc the Short Message Service Center address.
      * @param isRetry whether it is a retry of an already attempted message or not.
      * @param pdu PDU representing the contents of the message.
      */
-    public void sendSms(int token, int messageRef, String format, String smsc, boolean isRetry,
+    public void sendSms(int token, @IntRange(from = 0, to = 65535) int messageRef,
+            @SmsMessage.Format String format, String smsc, boolean isRetry,
             byte[] pdu) {
         // Base implementation returns error. Should be overridden.
         try {
@@ -172,14 +175,13 @@
      * provider.
      *
      * @param token token provided in {@link #onSmsReceived(int, String, byte[])}
-     * @param messageRef the message reference
-     * @param result result of delivering the message. Valid values are:
-     *  {@link #DELIVER_STATUS_OK},
-     *  {@link #DELIVER_STATUS_ERROR_GENERIC},
-     *  {@link #DELIVER_STATUS_ERROR_NO_MEMORY},
-     *  {@link #DELIVER_STATUS_ERROR_REQUEST_NOT_SUPPORTED}
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format (see TS.123.040) or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
+     * @param result result of delivering the message.
      */
-    public void acknowledgeSms(int token, int messageRef, @DeliverStatusResult int result) {
+    public void acknowledgeSms(int token, @IntRange(from = 0, to = 65535)  int messageRef,
+            @DeliverStatusResult int result) {
         Log.e(LOG_TAG, "acknowledgeSms() not implemented.");
     }
 
@@ -191,12 +193,13 @@
      *
      * @param token token provided in {@link #onSmsStatusReportReceived(int, int, String, byte[])}
      *              or {@link #onSmsStatusReportReceived(int, String, byte[])}
-     * @param messageRef the message reference
-     * @param result result of delivering the message. Valid values are:
-     *  {@link #STATUS_REPORT_STATUS_OK},
-     *  {@link #STATUS_REPORT_STATUS_ERROR}
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format (see TS.123.040) or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
+     * @param result result of delivering the message.
      */
-    public void acknowledgeSmsReport(int token, int messageRef, @StatusReportResult int result) {
+    public void acknowledgeSmsReport(int token, @IntRange(from = 0, to = 65535) int messageRef,
+            @StatusReportResult int result) {
         Log.e(LOG_TAG, "acknowledgeSmsReport() not implemented.");
     }
 
@@ -210,12 +213,12 @@
      * {@link #DELIVER_STATUS_ERROR_GENERIC} result code.
      * @param token unique token generated by IMS providers that the platform will use to trigger
      *              callbacks for this message.
-     * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
-     * {@link SmsMessage#FORMAT_3GPP2}.
+     * @param format the format of the message.
      * @param pdu PDU representing the contents of the message.
      * @throws RuntimeException if called before {@link #onReady()} is triggered.
      */
-    public final void onSmsReceived(int token, String format, byte[] pdu) throws RuntimeException {
+    public final void onSmsReceived(int token, @SmsMessage.Format String format, byte[] pdu)
+            throws RuntimeException {
         synchronized (mLock) {
             if (mListener == null) {
                 throw new RuntimeException("Feature not ready.");
@@ -241,13 +244,16 @@
      * sent successfully.
      *
      * @param token token provided in {@link #sendSms(int, int, String, String, boolean, byte[])}
-     * @param messageRef the message reference. Should be between 0 and 255 per TS.123.040
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format (see TS.123.040) or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
      *
      * @throws RuntimeException if called before {@link #onReady()} is triggered or if the
      * connection to the framework is not available. If this happens attempting to send the SMS
      * should be aborted.
      */
-    public final void onSendSmsResultSuccess(int token, int messageRef) throws RuntimeException {
+    public final void onSendSmsResultSuccess(int token,
+            @IntRange(from = 0, to = 65535) int messageRef) throws RuntimeException {
         synchronized (mLock) {
             if (mListener == null) {
                 throw new RuntimeException("Feature not ready.");
@@ -266,34 +272,11 @@
      * to the platform.
      *
      * @param token token provided in {@link #sendSms(int, int, String, String, boolean, byte[])}
-     * @param messageRef the message reference. Should be between 0 and 255 per TS.123.040
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format (see TS.123.040) or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
      * @param status result of sending the SMS.
-     * @param reason reason in case status is failure. Valid values are:
-     *  {@link SmsManager#RESULT_ERROR_NONE},
-     *  {@link SmsManager#RESULT_ERROR_GENERIC_FAILURE},
-     *  {@link SmsManager#RESULT_ERROR_RADIO_OFF},
-     *  {@link SmsManager#RESULT_ERROR_NULL_PDU},
-     *  {@link SmsManager#RESULT_ERROR_NO_SERVICE},
-     *  {@link SmsManager#RESULT_ERROR_LIMIT_EXCEEDED},
-     *  {@link SmsManager#RESULT_ERROR_FDN_CHECK_FAILURE},
-     *  {@link SmsManager#RESULT_ERROR_SHORT_CODE_NOT_ALLOWED},
-     *  {@link SmsManager#RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED},
-     *  {@link SmsManager#RESULT_RADIO_NOT_AVAILABLE},
-     *  {@link SmsManager#RESULT_NETWORK_REJECT},
-     *  {@link SmsManager#RESULT_INVALID_ARGUMENTS},
-     *  {@link SmsManager#RESULT_INVALID_STATE},
-     *  {@link SmsManager#RESULT_NO_MEMORY},
-     *  {@link SmsManager#RESULT_INVALID_SMS_FORMAT},
-     *  {@link SmsManager#RESULT_SYSTEM_ERROR},
-     *  {@link SmsManager#RESULT_MODEM_ERROR},
-     *  {@link SmsManager#RESULT_NETWORK_ERROR},
-     *  {@link SmsManager#RESULT_ENCODING_ERROR},
-     *  {@link SmsManager#RESULT_INVALID_SMSC_ADDRESS},
-     *  {@link SmsManager#RESULT_OPERATION_NOT_ALLOWED},
-     *  {@link SmsManager#RESULT_INTERNAL_ERROR},
-     *  {@link SmsManager#RESULT_NO_RESOURCES},
-     *  {@link SmsManager#RESULT_CANCELLED},
-     *  {@link SmsManager#RESULT_REQUEST_NOT_SUPPORTED}
+     * @param reason reason in case status is failure.
      *
      * @throws RuntimeException if called before {@link #onReady()} is triggered or if the
      * connection to the framework is not available. If this happens attempting to send the SMS
@@ -303,8 +286,8 @@
      * send result.
      */
     @Deprecated
-    public final void onSendSmsResult(int token, int messageRef,  @SendStatusResult int status,
-            int reason) throws RuntimeException {
+    public final void onSendSmsResult(int token, @IntRange(from = 0, to = 65535) int messageRef,
+            @SendStatusResult int status, @SmsManager.Result int reason) throws RuntimeException {
         synchronized (mLock) {
             if (mListener == null) {
                 throw new RuntimeException("Feature not ready.");
@@ -324,34 +307,10 @@
      * network.
      *
      * @param token token provided in {@link #sendSms(int, int, String, String, boolean, byte[])}
-     * @param messageRef the message reference. Should be between 0 and 255 per TS.123.040
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format (see TS.123.040) or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
      * @param status result of sending the SMS.
-     * @param reason Valid values are:
-     *  {@link SmsManager#RESULT_ERROR_NONE},
-     *  {@link SmsManager#RESULT_ERROR_GENERIC_FAILURE},
-     *  {@link SmsManager#RESULT_ERROR_RADIO_OFF},
-     *  {@link SmsManager#RESULT_ERROR_NULL_PDU},
-     *  {@link SmsManager#RESULT_ERROR_NO_SERVICE},
-     *  {@link SmsManager#RESULT_ERROR_LIMIT_EXCEEDED},
-     *  {@link SmsManager#RESULT_ERROR_FDN_CHECK_FAILURE},
-     *  {@link SmsManager#RESULT_ERROR_SHORT_CODE_NOT_ALLOWED},
-     *  {@link SmsManager#RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED},
-     *  {@link SmsManager#RESULT_RADIO_NOT_AVAILABLE},
-     *  {@link SmsManager#RESULT_NETWORK_REJECT},
-     *  {@link SmsManager#RESULT_INVALID_ARGUMENTS},
-     *  {@link SmsManager#RESULT_INVALID_STATE},
-     *  {@link SmsManager#RESULT_NO_MEMORY},
-     *  {@link SmsManager#RESULT_INVALID_SMS_FORMAT},
-     *  {@link SmsManager#RESULT_SYSTEM_ERROR},
-     *  {@link SmsManager#RESULT_MODEM_ERROR},
-     *  {@link SmsManager#RESULT_NETWORK_ERROR},
-     *  {@link SmsManager#RESULT_ENCODING_ERROR},
-     *  {@link SmsManager#RESULT_INVALID_SMSC_ADDRESS},
-     *  {@link SmsManager#RESULT_OPERATION_NOT_ALLOWED},
-     *  {@link SmsManager#RESULT_INTERNAL_ERROR},
-     *  {@link SmsManager#RESULT_NO_RESOURCES},
-     *  {@link SmsManager#RESULT_CANCELLED},
-     *  {@link SmsManager#RESULT_REQUEST_NOT_SUPPORTED}
      * @param networkErrorCode the error code reported by the carrier network if sending this SMS
      *  has resulted in an error or {@link #RESULT_NO_NETWORK_ERROR} if no network error was
      *  generated. See 3GPP TS 24.011 Section 7.3.4 for valid error codes and more information.
@@ -360,9 +319,9 @@
      * connection to the framework is not available. If this happens attempting to send the SMS
      * should be aborted.
      */
-    public final void onSendSmsResultError(int token, int messageRef,  @SendStatusResult int status,
-            int reason, int networkErrorCode)
-            throws RuntimeException {
+    public final void onSendSmsResultError(int token,
+            @IntRange(from = 0, to = 65535) int messageRef, @SendStatusResult int status,
+            @SmsManager.Result int reason, int networkErrorCode) throws RuntimeException {
         synchronized (mLock) {
             if (mListener == null) {
                 throw new RuntimeException("Feature not ready.");
@@ -384,9 +343,10 @@
      * the platform is not available, {@link #acknowledgeSmsReport(int, int, int)} will be called
      * with the {@link #STATUS_REPORT_STATUS_ERROR} result code.
      * @param token token provided in {@link #sendSms(int, int, String, String, boolean, byte[])}
-     * @param messageRef the message reference.
-     * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
-     *               {@link SmsMessage#FORMAT_3GPP2}.
+     * @param messageRef the message reference, which may be 1 byte if it is in
+     *     {@link SmsMessage#FORMAT_3GPP} format or 2 bytes if it is in
+     *     {@link SmsMessage#FORMAT_3GPP2} format (see 3GPP2 C.S0015-B).
+     * @param format the format of the message.
      * @param pdu PDU representing the content of the status report.
      * @throws RuntimeException if called before {@link #onReady()} is triggered
      *
@@ -394,7 +354,8 @@
      * message reference.
      */
     @Deprecated
-    public final void onSmsStatusReportReceived(int token, int messageRef, String format,
+    public final void onSmsStatusReportReceived(int token,
+            @IntRange(from = 0, to = 65535) int messageRef, @SmsMessage.Format String format,
             byte[] pdu) throws RuntimeException {
         synchronized (mLock) {
             if (mListener == null) {
@@ -419,13 +380,12 @@
      * with the {@link #STATUS_REPORT_STATUS_ERROR} result code.
      * @param token unique token generated by IMS providers that the platform will use to trigger
      *              callbacks for this message.
-     * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
-     *               {@link SmsMessage#FORMAT_3GPP2}.
+     * @param format the format of the message.
      * @param pdu PDU representing the content of the status report.
      * @throws RuntimeException if called before {@link #onReady()} is triggered
      */
-    public final void onSmsStatusReportReceived(int token, String format, byte[] pdu)
-            throws RuntimeException {
+    public final void onSmsStatusReportReceived(int token, @SmsMessage.Format String format,
+            byte[] pdu) throws RuntimeException {
         synchronized (mLock) {
             if (mListener == null) {
                 throw new RuntimeException("Feature not ready.");
@@ -450,13 +410,11 @@
     }
 
     /**
-     * Returns the SMS format. Default is {@link SmsMessage#FORMAT_3GPP} unless overridden by IMS
-     * Provider.
+     * Returns the SMS format that the ImsService expects.
      *
-     * @return  the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
-     * {@link SmsMessage#FORMAT_3GPP2}.
+     * @return  The expected format of the SMS messages.
      */
-    public String getSmsFormat() {
+    public @SmsMessage.Format String getSmsFormat() {
       return SmsMessage.FORMAT_3GPP;
     }
 
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index bffbbfd..cf3fba8 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -5709,7 +5709,6 @@
     }
 
     @Test
-    @FlakyTest(bugId = 140305678)
     public void testTcpBufferReset() throws Exception {
         final String testTcpBufferSizes = "1,2,3,4,5,6";
         final NetworkRequest networkRequest = new NetworkRequest.Builder()