Merge "Detect NetworkStack path in rollback test"
diff --git a/Android.bp b/Android.bp
index 30dad50..284e701 100644
--- a/Android.bp
+++ b/Android.bp
@@ -958,8 +958,7 @@
 
 metalava_framework_docs_args = "--manifest $(location core/res/AndroidManifest.xml) " +
     "--ignore-classes-on-classpath " +
-    "--hide-package com.android.okhttp " +
-    "--hide-package com.android.org.conscrypt --hide-package com.android.server " +
+    "--hide-package com.android.server " +
     "--error UnhiddenSystemApi " +
     "--hide RequiresPermission " +
     "--hide CallbackInterface " +
@@ -1021,7 +1020,6 @@
     previous_api: ":last-released-public-api",
     merge_annotations_dirs: [
         "metalava-manual",
-        "ojluni-annotated-sdk-stubs",
     ],
 }
 
@@ -1078,7 +1076,6 @@
     previous_api: ":last-released-public-api",
     merge_annotations_dirs: [
         "metalava-manual",
-        "ojluni-annotated-sdk-stubs",
     ],
     api_levels_annotations_enabled: true,
     api_levels_annotations_dirs: [
@@ -1413,7 +1410,6 @@
     previous_api: ":last-released-public-api",
     merge_annotations_dirs: [
         "metalava-manual",
-        "ojluni-annotated-sdk-stubs",
     ],
     args: " --show-annotation android.annotation.SystemApi",
 }
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index e731138..6831117 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,8 +1,6 @@
 [Hook Scripts]
 checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
 
-api_lint_hook = ${REPO_ROOT}/frameworks/base/tools/apilint/apilint_sha.sh ${PREUPLOAD_COMMIT}
-
 strings_lint_hook = ${REPO_ROOT}/frameworks/base/tools/stringslint/stringslint_sha.sh ${PREUPLOAD_COMMIT}
 
 hidden_api_txt_checksorted_hook = ${REPO_ROOT}/frameworks/base/tools/hiddenapi/checksorted_sha.sh ${PREUPLOAD_COMMIT} ${REPO_ROOT}
diff --git a/api/current.txt b/api/current.txt
index 98674f9..ce4cb25 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -33984,31 +33984,31 @@
 
 package android.os {
 
-  public abstract class AsyncTask<Params, Progress, Result> {
-    ctor public AsyncTask();
-    method public final boolean cancel(boolean);
-    method @WorkerThread protected abstract Result doInBackground(Params...);
-    method @MainThread public final android.os.AsyncTask<Params,Progress,Result> execute(Params...);
-    method @MainThread public static void execute(Runnable);
-    method @MainThread public final android.os.AsyncTask<Params,Progress,Result> executeOnExecutor(java.util.concurrent.Executor, Params...);
-    method public final Result get() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException;
-    method public final Result get(long, java.util.concurrent.TimeUnit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException;
-    method public final android.os.AsyncTask.Status getStatus();
-    method public final boolean isCancelled();
-    method @MainThread protected void onCancelled(Result);
-    method @MainThread protected void onCancelled();
-    method @MainThread protected void onPostExecute(Result);
-    method @MainThread protected void onPreExecute();
-    method @MainThread protected void onProgressUpdate(Progress...);
-    method @WorkerThread protected final void publishProgress(Progress...);
-    field public static final java.util.concurrent.Executor SERIAL_EXECUTOR;
-    field public static final java.util.concurrent.Executor THREAD_POOL_EXECUTOR;
+  @Deprecated public abstract class AsyncTask<Params, Progress, Result> {
+    ctor @Deprecated public AsyncTask();
+    method @Deprecated public final boolean cancel(boolean);
+    method @Deprecated @WorkerThread protected abstract Result doInBackground(Params...);
+    method @Deprecated @MainThread public final android.os.AsyncTask<Params,Progress,Result> execute(Params...);
+    method @Deprecated @MainThread public static void execute(Runnable);
+    method @Deprecated @MainThread public final android.os.AsyncTask<Params,Progress,Result> executeOnExecutor(java.util.concurrent.Executor, Params...);
+    method @Deprecated public final Result get() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException;
+    method @Deprecated public final Result get(long, java.util.concurrent.TimeUnit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException;
+    method @Deprecated public final android.os.AsyncTask.Status getStatus();
+    method @Deprecated public final boolean isCancelled();
+    method @Deprecated @MainThread protected void onCancelled(Result);
+    method @Deprecated @MainThread protected void onCancelled();
+    method @Deprecated @MainThread protected void onPostExecute(Result);
+    method @Deprecated @MainThread protected void onPreExecute();
+    method @Deprecated @MainThread protected void onProgressUpdate(Progress...);
+    method @Deprecated @WorkerThread protected final void publishProgress(Progress...);
+    field @Deprecated public static final java.util.concurrent.Executor SERIAL_EXECUTOR;
+    field @Deprecated public static final java.util.concurrent.Executor THREAD_POOL_EXECUTOR;
   }
 
-  public enum AsyncTask.Status {
-    enum_constant public static final android.os.AsyncTask.Status FINISHED;
-    enum_constant public static final android.os.AsyncTask.Status PENDING;
-    enum_constant public static final android.os.AsyncTask.Status RUNNING;
+  @Deprecated public enum AsyncTask.Status {
+    enum_constant @Deprecated public static final android.os.AsyncTask.Status FINISHED;
+    enum_constant @Deprecated public static final android.os.AsyncTask.Status PENDING;
+    enum_constant @Deprecated public static final android.os.AsyncTask.Status RUNNING;
   }
 
   public class BadParcelableException extends android.util.AndroidRuntimeException {
@@ -44782,13 +44782,60 @@
     field public static final int MMS_ERROR_RETRY = 6; // 0x6
     field public static final int MMS_ERROR_UNABLE_CONNECT_MMS = 3; // 0x3
     field public static final int MMS_ERROR_UNSPECIFIED = 1; // 0x1
+    field public static final int RESULT_BLUETOOTH_DISCONNECTED = 27; // 0x1b
+    field public static final int RESULT_CANCELLED = 23; // 0x17
+    field public static final int RESULT_ENCODING_ERROR = 18; // 0x12
+    field public static final int RESULT_ERROR_FDN_CHECK_FAILURE = 6; // 0x6
     field public static final int RESULT_ERROR_GENERIC_FAILURE = 1; // 0x1
     field public static final int RESULT_ERROR_LIMIT_EXCEEDED = 5; // 0x5
+    field public static final int RESULT_ERROR_NONE = 0; // 0x0
     field public static final int RESULT_ERROR_NO_SERVICE = 4; // 0x4
     field public static final int RESULT_ERROR_NULL_PDU = 3; // 0x3
     field public static final int RESULT_ERROR_RADIO_OFF = 2; // 0x2
     field public static final int RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED = 8; // 0x8
     field public static final int RESULT_ERROR_SHORT_CODE_NOT_ALLOWED = 7; // 0x7
+    field public static final int RESULT_INTERNAL_ERROR = 21; // 0x15
+    field public static final int RESULT_INVALID_ARGUMENTS = 11; // 0xb
+    field public static final int RESULT_INVALID_BLUETOOTH_ADDRESS = 26; // 0x1a
+    field public static final int RESULT_INVALID_SMSC_ADDRESS = 19; // 0x13
+    field public static final int RESULT_INVALID_SMS_FORMAT = 14; // 0xe
+    field public static final int RESULT_INVALID_STATE = 12; // 0xc
+    field public static final int RESULT_MODEM_ERROR = 16; // 0x10
+    field public static final int RESULT_NETWORK_ERROR = 17; // 0x11
+    field public static final int RESULT_NETWORK_REJECT = 10; // 0xa
+    field public static final int RESULT_NO_BLUETOOTH_SERVICE = 25; // 0x19
+    field public static final int RESULT_NO_DEFAULT_SMS_APP = 32; // 0x20
+    field public static final int RESULT_NO_MEMORY = 13; // 0xd
+    field public static final int RESULT_NO_RESOURCES = 22; // 0x16
+    field public static final int RESULT_OPERATION_NOT_ALLOWED = 20; // 0x14
+    field public static final int RESULT_RADIO_NOT_AVAILABLE = 9; // 0x9
+    field public static final int RESULT_REMOTE_EXCEPTION = 31; // 0x1f
+    field public static final int RESULT_REQUEST_NOT_SUPPORTED = 24; // 0x18
+    field public static final int RESULT_RIL_CANCELLED = 119; // 0x77
+    field public static final int RESULT_RIL_ENCODING_ERR = 109; // 0x6d
+    field public static final int RESULT_RIL_INTERNAL_ERR = 113; // 0x71
+    field public static final int RESULT_RIL_INVALID_ARGUMENTS = 104; // 0x68
+    field public static final int RESULT_RIL_INVALID_MODEM_STATE = 115; // 0x73
+    field public static final int RESULT_RIL_INVALID_SMSC_ADDRESS = 110; // 0x6e
+    field public static final int RESULT_RIL_INVALID_SMS_FORMAT = 107; // 0x6b
+    field public static final int RESULT_RIL_INVALID_STATE = 103; // 0x67
+    field public static final int RESULT_RIL_MODEM_ERR = 111; // 0x6f
+    field public static final int RESULT_RIL_NETWORK_ERR = 112; // 0x70
+    field public static final int RESULT_RIL_NETWORK_NOT_READY = 116; // 0x74
+    field public static final int RESULT_RIL_NETWORK_REJECT = 102; // 0x66
+    field public static final int RESULT_RIL_NO_MEMORY = 105; // 0x69
+    field public static final int RESULT_RIL_NO_RESOURCES = 118; // 0x76
+    field public static final int RESULT_RIL_OPERATION_NOT_ALLOWED = 117; // 0x75
+    field public static final int RESULT_RIL_RADIO_NOT_AVAILABLE = 100; // 0x64
+    field public static final int RESULT_RIL_REQUEST_NOT_SUPPORTED = 114; // 0x72
+    field public static final int RESULT_RIL_REQUEST_RATE_LIMITED = 106; // 0x6a
+    field public static final int RESULT_RIL_SIM_ABSENT = 120; // 0x78
+    field public static final int RESULT_RIL_SMS_SEND_FAIL_RETRY = 101; // 0x65
+    field public static final int RESULT_RIL_SYSTEM_ERR = 108; // 0x6c
+    field public static final int RESULT_SMS_BLOCKED_DURING_EMERGENCY = 29; // 0x1d
+    field public static final int RESULT_SMS_SEND_RETRY_FAILED = 30; // 0x1e
+    field public static final int RESULT_SYSTEM_ERROR = 15; // 0xf
+    field public static final int RESULT_UNEXPECTED_EVENT_STOP_SENDING = 28; // 0x1c
     field public static final int STATUS_ON_ICC_FREE = 0; // 0x0
     field public static final int STATUS_ON_ICC_READ = 1; // 0x1
     field public static final int STATUS_ON_ICC_SENT = 5; // 0x5
diff --git a/api/system-current.txt b/api/system-current.txt
index 7ea45dc..3393112 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -1242,9 +1242,13 @@
     method public boolean disableBLE();
     method public boolean enableBLE();
     method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean enableNoAutoConnect();
+    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean factoryReset();
+    method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public long getDiscoveryEndMillis();
     method public boolean isBleScanAlwaysAvailable();
     method public boolean isLeEnabled();
     method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
+    method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int, int);
+    method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int);
     field public static final String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED";
     field public static final String ACTION_REQUEST_BLE_SCAN_ALWAYS_AVAILABLE = "android.bluetooth.adapter.action.REQUEST_BLE_SCAN_ALWAYS_AVAILABLE";
   }
@@ -7244,13 +7248,6 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.telephony.CallQuality> CREATOR;
   }
 
-  public class CallerInfo {
-    method @Nullable public android.net.Uri getContactDisplayPhotoUri();
-    method public long getContactId();
-    method @Nullable public String getName();
-    method @Nullable public String getPhoneNumber();
-  }
-
   public class CarrierConfigManager {
     method @NonNull public static android.os.PersistableBundle getDefaultConfig();
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void overrideConfig(int, @Nullable android.os.PersistableBundle);
@@ -7288,6 +7285,7 @@
     ctor public CellBroadcastService();
     method @CallSuper @NonNull public android.os.IBinder onBind(@Nullable android.content.Intent);
     method public abstract void onCdmaCellBroadcastSms(int, @NonNull byte[], int);
+    method public abstract void onCdmaScpMessage(int, @NonNull java.util.List<android.telephony.cdma.CdmaSmsCbProgramData>, @NonNull String, @NonNull java.util.function.Consumer<android.os.Bundle>);
     method public abstract void onGsmCellBroadcastSms(int, @NonNull byte[]);
     field public static final String CELL_BROADCAST_SERVICE_INTERFACE = "android.telephony.CellBroadcastService";
   }
@@ -7832,6 +7830,12 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PhoneNumberRange> CREATOR;
   }
 
+  public class PhoneNumberUtils {
+    method @NonNull public static String getUsernameFromUriNumber(@NonNull String);
+    method public static boolean isUriNumber(@Nullable String);
+    method public static boolean isVoiceMailNumber(@NonNull android.content.Context, int, @Nullable String);
+  }
+
   public class PhoneStateListener {
     method public void onCallAttributesChanged(@NonNull android.telephony.CallAttributes);
     method @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public void onCallDisconnectCauseChanged(int, int);
@@ -8112,25 +8116,8 @@
   public final class SmsManager {
     method public boolean disableCellBroadcastRange(int, int, int);
     method public boolean enableCellBroadcastRange(int, int, int);
+    method public void sendMultipartTextMessage(@NonNull String, @NonNull String, @NonNull java.util.List<java.lang.String>, @Nullable java.util.List<android.app.PendingIntent>, @Nullable java.util.List<android.app.PendingIntent>, @NonNull String);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void sendMultipartTextMessageWithoutPersisting(String, String, java.util.List<java.lang.String>, java.util.List<android.app.PendingIntent>, java.util.List<android.app.PendingIntent>);
-    field public static final int RESULT_CANCELLED = 23; // 0x17
-    field public static final int RESULT_ENCODING_ERROR = 18; // 0x12
-    field public static final int RESULT_ERROR_FDN_CHECK_FAILURE = 6; // 0x6
-    field public static final int RESULT_ERROR_NONE = 0; // 0x0
-    field public static final int RESULT_INTERNAL_ERROR = 21; // 0x15
-    field public static final int RESULT_INVALID_ARGUMENTS = 11; // 0xb
-    field public static final int RESULT_INVALID_SMSC_ADDRESS = 19; // 0x13
-    field public static final int RESULT_INVALID_SMS_FORMAT = 14; // 0xe
-    field public static final int RESULT_INVALID_STATE = 12; // 0xc
-    field public static final int RESULT_MODEM_ERROR = 16; // 0x10
-    field public static final int RESULT_NETWORK_ERROR = 17; // 0x11
-    field public static final int RESULT_NETWORK_REJECT = 10; // 0xa
-    field public static final int RESULT_NO_MEMORY = 13; // 0xd
-    field public static final int RESULT_NO_RESOURCES = 22; // 0x16
-    field public static final int RESULT_OPERATION_NOT_ALLOWED = 20; // 0x14
-    field public static final int RESULT_RADIO_NOT_AVAILABLE = 9; // 0x9
-    field public static final int RESULT_REQUEST_NOT_SUPPORTED = 24; // 0x18
-    field public static final int RESULT_SYSTEM_ERROR = 15; // 0xf
   }
 
   public class SubscriptionInfo implements android.os.Parcelable {
@@ -8147,6 +8134,7 @@
     method public void requestEmbeddedSubscriptionInfoListRefresh(int);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultDataSubId(int);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultSmsSubId(int);
+    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultVoiceSubscriptionId(int);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setPreferredDataSubscriptionId(int, boolean, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.Consumer<java.lang.Integer>);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setSubscriptionEnabled(int, boolean);
     field @NonNull public static final android.net.Uri ADVANCED_CALLING_ENABLED_CONTENT_URI;
@@ -8200,7 +8188,6 @@
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean enableDataConnectivity();
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean enableModemForSlot(int, boolean);
     method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void enableVideoCalling(boolean);
-    method @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL) public void factoryReset(int);
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getAidForAppType(int);
     method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List<android.service.carrier.CarrierIdentifier> getAllowedCarriers(int);
     method public java.util.List<java.lang.String> getCarrierPackageNamesForIntent(android.content.Intent);
@@ -8216,10 +8203,12 @@
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getDataActivationState();
     method @Deprecated public boolean getDataEnabled();
     method @Deprecated public boolean getDataEnabled(int);
+    method @Nullable public static android.content.ComponentName getDefaultRespondViaMessageApplication(@NonNull android.content.Context, boolean);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean getEmergencyCallbackMode();
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getIsimDomain();
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getIsimIst();
     method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.Map<java.lang.Integer,java.lang.Integer> getLogicalToPhysicalSlotMapping();
+    method public int getMaxNumberOfSimultaneouslyActiveSims();
     method public static long getMaxNumberVerificationTimeoutMillis();
     method @NonNull public String getNetworkCountryIso(int);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public long getPreferredNetworkTypeBitmask();
@@ -8256,6 +8245,7 @@
     method @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.MODIFY_PHONE_STATE}) public void requestCellInfoUpdate(@NonNull android.os.WorkSource, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CellInfoCallback);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void requestNumberVerification(@NonNull android.telephony.PhoneNumberRange, long, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.NumberVerificationCallback);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean resetRadioConfig();
+    method @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL) public void resetSettings();
     method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int setAllowedCarriers(int, java.util.List<android.service.carrier.CarrierIdentifier>);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setCarrierDataEnabled(boolean);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int setCarrierRestrictionRules(@NonNull android.telephony.CarrierRestrictionRules);
@@ -8696,6 +8686,7 @@
     method public android.os.Bundle getCallExtras();
     method public int getCallType();
     method public static int getCallTypeFromVideoState(int);
+    method public int getCallerNumberVerificationStatus();
     method public int getEmergencyCallRouting();
     method public int getEmergencyServiceCategories();
     method @NonNull public java.util.List<java.lang.String> getEmergencyUrns();
@@ -8713,6 +8704,7 @@
     method public void setCallExtraBoolean(String, boolean);
     method public void setCallExtraInt(String, int);
     method public void setCallRestrictCause(int);
+    method public void setCallerNumberVerificationStatus(int);
     method public void setEmergencyCallRouting(int);
     method public void setEmergencyCallTesting(boolean);
     method public void setEmergencyServiceCategories(int);
@@ -8763,6 +8755,9 @@
     field public static final int SERVICE_TYPE_EMERGENCY = 2; // 0x2
     field public static final int SERVICE_TYPE_NONE = 0; // 0x0
     field public static final int SERVICE_TYPE_NORMAL = 1; // 0x1
+    field public static final int VERIFICATION_STATUS_FAILED = 2; // 0x2
+    field public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0; // 0x0
+    field public static final int VERIFICATION_STATUS_PASSED = 1; // 0x1
   }
 
   public class ImsCallSessionListener {
@@ -8858,20 +8853,20 @@
   public class ImsMmTelManager implements android.telephony.ims.RegistrationManager {
     method @NonNull public static android.telephony.ims.ImsMmTelManager createForSubscriptionId(int);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getFeatureState(@NonNull java.util.function.Consumer<java.lang.Integer>, @NonNull java.util.concurrent.Executor) throws android.telephony.ims.ImsException;
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationState(@NonNull java.util.function.Consumer<java.lang.Integer>, @NonNull java.util.concurrent.Executor);
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationTransportType(@NonNull java.util.function.Consumer<java.lang.Integer>, @NonNull java.util.concurrent.Executor);
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationState(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Integer>);
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationTransportType(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Integer>);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getVoWiFiModeSetting();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getVoWiFiRoamingModeSetting();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isAdvancedCallingSettingEnabled();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isAvailable(@android.telephony.ims.feature.MmTelFeature.MmTelCapabilities.MmTelCapability int, int);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isCapable(@android.telephony.ims.feature.MmTelFeature.MmTelCapabilities.MmTelCapability int, int);
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void isSupported(@android.telephony.ims.feature.MmTelFeature.MmTelCapabilities.MmTelCapability int, int, @NonNull java.util.function.Consumer<java.lang.Boolean>, @NonNull java.util.concurrent.Executor) throws android.telephony.ims.ImsException;
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void isSupported(@android.telephony.ims.feature.MmTelFeature.MmTelCapabilities.MmTelCapability int, int, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>) throws android.telephony.ims.ImsException;
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isTtyOverVolteEnabled();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isVoWiFiRoamingSettingEnabled();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isVoWiFiSettingEnabled();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isVtSettingEnabled();
     method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerImsRegistrationCallback(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.ims.ImsMmTelManager.RegistrationCallback) throws android.telephony.ims.ImsException;
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerImsRegistrationCallback(@NonNull android.telephony.ims.RegistrationManager.RegistrationCallback, @NonNull java.util.concurrent.Executor) throws android.telephony.ims.ImsException;
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerImsRegistrationCallback(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.ims.RegistrationManager.RegistrationCallback) throws android.telephony.ims.ImsException;
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerMmTelCapabilityCallback(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.ims.ImsMmTelManager.CapabilityCallback) throws android.telephony.ims.ImsException;
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setAdvancedCallingSettingEnabled(boolean);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setRttCapabilitySetting(boolean);
@@ -9331,9 +9326,9 @@
   }
 
   public interface RegistrationManager {
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationState(@NonNull java.util.function.Consumer<java.lang.Integer>, @NonNull java.util.concurrent.Executor);
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationTransportType(@NonNull java.util.function.Consumer<java.lang.Integer>, @NonNull java.util.concurrent.Executor);
-    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerImsRegistrationCallback(@NonNull android.telephony.ims.RegistrationManager.RegistrationCallback, @NonNull java.util.concurrent.Executor) throws android.telephony.ims.ImsException;
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationState(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Integer>);
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getRegistrationTransportType(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Integer>);
+    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerImsRegistrationCallback(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.ims.RegistrationManager.RegistrationCallback) throws android.telephony.ims.ImsException;
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void unregisterImsRegistrationCallback(@NonNull android.telephony.ims.RegistrationManager.RegistrationCallback);
     field public static final int REGISTRATION_STATE_NOT_REGISTERED = 0; // 0x0
     field public static final int REGISTRATION_STATE_REGISTERED = 2; // 0x2
diff --git a/api/test-current.txt b/api/test-current.txt
index a82ec4e..293ca55 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -2865,6 +2865,9 @@
 
   public class PhoneNumberUtils {
     method public static int getMinMatchForTest();
+    method @NonNull public static String getUsernameFromUriNumber(@NonNull String);
+    method public static boolean isUriNumber(@Nullable String);
+    method public static boolean isVoiceMailNumber(@NonNull android.content.Context, int, @Nullable String);
     method public static void setMinMatchForTest(int);
   }
 
@@ -2888,6 +2891,7 @@
 
   public final class SmsManager {
     method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int checkSmsShortCodeDestination(String, String);
+    method public void sendMultipartTextMessage(@NonNull String, @NonNull String, @NonNull java.util.List<java.lang.String>, @Nullable java.util.List<android.app.PendingIntent>, @Nullable java.util.List<android.app.PendingIntent>, @NonNull String);
     field public static final int SMS_CATEGORY_FREE_SHORT_CODE = 1; // 0x1
     field public static final int SMS_CATEGORY_NOT_SHORT_CODE = 0; // 0x0
     field public static final int SMS_CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE = 3; // 0x3
@@ -2895,9 +2899,14 @@
     field public static final int SMS_CATEGORY_STANDARD_SHORT_CODE = 2; // 0x2
   }
 
+  public class SubscriptionManager {
+    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultVoiceSubscriptionId(int);
+  }
+
   public class TelephonyManager {
     method public int checkCarrierPrivilegesForPackage(String);
     method public int getCarrierIdListVersion();
+    method @Nullable public static android.content.ComponentName getDefaultRespondViaMessageApplication(@NonNull android.content.Context, boolean);
     method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag();
     method @NonNull public String getNetworkCountryIso(int);
     method public android.util.Pair<java.lang.Integer,java.lang.Integer> getRadioHalVersion();
diff --git a/config/hiddenapi-greylist-max-p.txt b/config/hiddenapi-greylist-max-p.txt
index 34339d7..351e71d 100644
--- a/config/hiddenapi-greylist-max-p.txt
+++ b/config/hiddenapi-greylist-max-p.txt
@@ -1,56 +1,14 @@
 Landroid/app/IInstrumentationWatcher$Stub;->asInterface(Landroid/os/IBinder;)Landroid/app/IInstrumentationWatcher;
 Landroid/app/ISearchManager$Stub;-><init>()V
 Landroid/app/IUiModeManager$Stub;->asInterface(Landroid/os/IBinder;)Landroid/app/IUiModeManager;
-Landroid/app/IUiModeManager;->disableCarMode(I)V
 Landroid/bluetooth/IBluetooth$Stub;-><init>()V
 Landroid/bluetooth/IBluetoothA2dp$Stub;-><init>()V
 Landroid/content/IIntentReceiver$Stub;->asInterface(Landroid/os/IBinder;)Landroid/content/IIntentReceiver;
 Landroid/content/IIntentSender$Stub;->asInterface(Landroid/os/IBinder;)Landroid/content/IIntentSender;
-Landroid/net/IConnectivityManager;->getNetworkInfo(I)Landroid/net/NetworkInfo;
-Landroid/net/IConnectivityManager;->reportInetCondition(II)V
-Landroid/os/BatteryStats$Counter;-><init>()V
-Landroid/os/BatteryStats$HistoryItem;->clear()V
-Landroid/os/BatteryStats$HistoryItem;->next:Landroid/os/BatteryStats$HistoryItem;
-Landroid/os/BatteryStats$HistoryItem;->same(Landroid/os/BatteryStats$HistoryItem;)Z
-Landroid/os/BatteryStats$HistoryItem;->setTo(JBLandroid/os/BatteryStats$HistoryItem;)V
-Landroid/os/BatteryStats$HistoryItem;->setTo(Landroid/os/BatteryStats$HistoryItem;)V
-Landroid/os/BatteryStats$Timer;-><init>()V
-Landroid/os/BatteryStats$Uid$Pkg;-><init>()V
-Landroid/os/BatteryStats$Uid$Proc;-><init>()V
-Landroid/os/BatteryStats$Uid$Sensor;-><init>()V
-Landroid/os/BatteryStats$Uid$Wakelock;-><init>()V
-Landroid/os/BatteryStats;-><init>()V
-Landroid/os/BatteryStats;->getMobileRadioActiveTime(JI)J
-Landroid/os/BatteryStats;->getNetworkActivityBytes(II)J
-Landroid/os/CancellationSignal;->mCancelInProgress:Z
-Landroid/os/CancellationSignal;->mIsCanceled:Z
-Landroid/os/CancellationSignal;->mOnCancelListener:Landroid/os/CancellationSignal$OnCancelListener;
-Landroid/os/CancellationSignal;->mRemote:Landroid/os/ICancellationSignal;
-Landroid/os/CancellationSignal;->waitForCancelFinishedLocked()V
-Landroid/os/IPowerManager;->nap(J)V
-Landroid/os/Parcel;->mCreators:Ljava/util/HashMap;
-Landroid/os/PowerManager;->mHandler:Landroid/os/Handler;
-Landroid/os/Process;->sendSignalQuiet(II)V
-Landroid/os/Registrant;->getHandler()Landroid/os/Handler;
-Landroid/os/RegistrantList;->get(I)Ljava/lang/Object;
-Landroid/os/RemoteCallback;->mHandler:Landroid/os/Handler;
 Landroid/os/storage/IObbActionListener$Stub;->asInterface(Landroid/os/IBinder;)Landroid/os/storage/IObbActionListener;
-Landroid/os/SystemProperties;->native_add_change_callback()V
-Landroid/os/SystemProperties;->native_get(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
-Landroid/os/SystemProperties;->native_get_boolean(Ljava/lang/String;Z)Z
-Landroid/os/SystemProperties;->native_get_int(Ljava/lang/String;I)I
-Landroid/os/SystemProperties;->native_set(Ljava/lang/String;Ljava/lang/String;)V
-Landroid/os/UserHandle;->formatUid(Ljava/io/PrintWriter;I)V
-Landroid/os/WorkSource;->sGoneWork:Landroid/os/WorkSource;
-Landroid/os/WorkSource;->sNewbWork:Landroid/os/WorkSource;
-Landroid/os/WorkSource;->sTmpWorkSource:Landroid/os/WorkSource;
-Landroid/os/WorkSource;->updateLocked(Landroid/os/WorkSource;ZZ)Z
 Landroid/service/carrier/ICarrierMessagingCallback$Stub;-><init>()V
-Landroid/service/carrier/ICarrierMessagingService;->filterSms(Landroid/service/carrier/MessagePdu;Ljava/lang/String;IILandroid/service/carrier/ICarrierMessagingCallback;)V
 Landroid/view/IGraphicsStats$Stub$Proxy;-><init>(Landroid/os/IBinder;)V
 Landroid/view/IGraphicsStats$Stub;->asInterface(Landroid/os/IBinder;)Landroid/view/IGraphicsStats;
-Landroid/view/IWindowManager;->setInTouchMode(Z)V
-Landroid/view/IWindowManager;->showStrictModeViolation(Z)V
 Lcom/android/internal/R$styleable;->AndroidManifestActivityAlias:[I
 Lcom/android/internal/R$styleable;->AndroidManifestGrantUriPermission:[I
 Lcom/android/internal/R$styleable;->AndroidManifestInstrumentation:[I
@@ -69,10 +27,3 @@
 Lcom/android/internal/R$styleable;->Searchable:[I
 Lcom/android/internal/R$styleable;->SearchableActionKey:[I
 Lcom/android/internal/telephony/IPhoneSubInfo$Stub;-><init>()V
-Lcom/android/internal/telephony/ITelephony;->getDataActivity()I
-Lcom/android/internal/telephony/ITelephony;->getDataState()I
-Lcom/android/internal/telephony/ITelephonyRegistry;->notifyCallForwardingChanged(Z)V
-Lcom/android/internal/telephony/ITelephonyRegistry;->notifyCellLocation(Landroid/os/Bundle;)V
-Lcom/android/internal/telephony/ITelephonyRegistry;->notifyDataActivity(I)V
-Lcom/android/internal/telephony/ITelephonyRegistry;->notifyOtaspChanged(II)V
-Lcom/android/internal/view/BaseIWindow;-><init>()V
diff --git a/core/java/android/app/IUiModeManager.aidl b/core/java/android/app/IUiModeManager.aidl
index cae54b6..f2c9f61 100644
--- a/core/java/android/app/IUiModeManager.aidl
+++ b/core/java/android/app/IUiModeManager.aidl
@@ -30,6 +30,7 @@
     /**
      * Disables the car mode.
      */
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void disableCarMode(int flags);
 
     /**
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index 77647c5..646f0dc 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -173,6 +173,7 @@
 import android.telephony.TelephonyManager;
 import android.telephony.euicc.EuiccCardManager;
 import android.telephony.euicc.EuiccManager;
+import android.telephony.ims.ImsManager;
 import android.telephony.ims.RcsMessageManager;
 import android.util.ArrayMap;
 import android.util.Log;
@@ -630,6 +631,14 @@
                     }
                 });
 
+        registerService(Context.TELEPHONY_IMS_SERVICE, ImsManager.class,
+                new CachedServiceFetcher<ImsManager>() {
+                    @Override
+                    public ImsManager createService(ContextImpl ctx) {
+                        return new ImsManager(ctx.getOuterContext());
+                    }
+                });
+
         registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class,
                 new CachedServiceFetcher<CarrierConfigManager>() {
             @Override
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index e7ba85a..566b387 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -1189,13 +1189,11 @@
     /**
      * Factory reset bluetooth settings.
      *
-     * <p>Requires the {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}
-     * permission
-     *
      * @return true to indicate that the config file was successfully cleared
      * @hide
      */
-    @UnsupportedAppUsage
+    @SystemApi
+    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
     public boolean factoryReset() {
         try {
             mServiceLock.readLock().lock();
@@ -1214,13 +1212,12 @@
     /**
      * Get the UUIDs supported by the local Bluetooth adapter.
      *
-     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
-     *
      * @return the UUIDs supported by the local Bluetooth Adapter.
      * @hide
      */
     @UnsupportedAppUsage
-    public ParcelUuid[] getUuids() {
+    @RequiresPermission(Manifest.permission.BLUETOOTH)
+    public @NonNull ParcelUuid[] getUuids() {
         if (getState() != STATE_ON) {
             return null;
         }
@@ -1476,7 +1473,6 @@
      * will return false. After turning on Bluetooth,
      * wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON}
      * to get the updated value.
-     * <p>Requires {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
      * <p>Applications cannot set the scan mode. They should use
      * <code>startActivityForResult(
      * BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE})
@@ -1488,8 +1484,8 @@
      * @return true if the scan mode was set, false otherwise
      * @hide
      */
-    @UnsupportedAppUsage(publicAlternatives = "Use {@link #ACTION_REQUEST_DISCOVERABLE}, which "
-            + "shows UI that confirms the user wants to go into discoverable mode.")
+    @SystemApi
+    @RequiresPermission(Manifest.permission.BLUETOOTH)
     public boolean setScanMode(@ScanMode int mode, int duration) {
         if (getState() != STATE_ON) {
             return false;
@@ -1507,9 +1503,34 @@
         return false;
     }
 
-    /** @hide */
-    @UnsupportedAppUsage
-    public boolean setScanMode(int mode) {
+    /**
+     * Set the Bluetooth scan mode of the local Bluetooth adapter.
+     * <p>The Bluetooth scan mode determines if the local adapter is
+     * connectable and/or discoverable from remote Bluetooth devices.
+     * <p>For privacy reasons, discoverable mode is automatically turned off
+     * after <code>duration</code> seconds. For example, 120 seconds should be
+     * enough for a remote device to initiate and complete its discovery
+     * process.
+     * <p>Valid scan mode values are:
+     * {@link #SCAN_MODE_NONE},
+     * {@link #SCAN_MODE_CONNECTABLE},
+     * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
+     * <p>If Bluetooth state is not {@link #STATE_ON}, this API
+     * will return false. After turning on Bluetooth,
+     * wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON}
+     * to get the updated value.
+     * <p>Applications cannot set the scan mode. They should use
+     * <code>startActivityForResult(
+     * BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE})
+     * </code>instead.
+     *
+     * @param mode valid scan mode
+     * @return true if the scan mode was set, false otherwise
+     * @hide
+     */
+    @SystemApi
+    @RequiresPermission(Manifest.permission.BLUETOOTH)
+    public boolean setScanMode(@ScanMode int mode) {
         if (getState() != STATE_ON) {
             return false;
         }
@@ -1562,6 +1583,8 @@
      * been called recently.
      * @hide
      */
+    @SystemApi
+    @RequiresPermission(Manifest.permission.BLUETOOTH)
     public long getDiscoveryEndMillis() {
         try {
             mServiceLock.readLock().lock();
@@ -2060,7 +2083,7 @@
      * BluetoothProfile}.
      * @hide
      */
-    public List<Integer> getSupportedProfiles() {
+    public @NonNull List<Integer> getSupportedProfiles() {
         final ArrayList<Integer> supportedProfiles = new ArrayList<Integer>();
 
         try {
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index cd6acba..a8c1216 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -4726,6 +4726,13 @@
 
     /**
      * Use with {@link #getSystemService(String)} to retrieve an
+     * {@link android.telephony.ims.ImsManager}.
+     * @hide
+     */
+    public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
+
+    /**
+     * Use with {@link #getSystemService(String)} to retrieve an
      * {@link android.telephony.ims.RcsMessageManager}.
      * @hide
      */
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index f15b5d7..5c5c13d 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -618,21 +618,6 @@
     }
 
     /**
-     * Generate and return the {@link PackageInfo} for a parsed package.
-     *
-     * @param p the parsed package.
-     * @param flags indicating which optional information is included.
-     */
-    @UnsupportedAppUsage
-    public static PackageInfo generatePackageInfo(PackageParser.Package p,
-            int gids[], int flags, long firstInstallTime, long lastUpdateTime,
-            Set<String> grantedPermissions, PackageUserState state) {
-
-        return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
-                grantedPermissions, state, UserHandle.getCallingUserId());
-    }
-
-    /**
      * Returns true if the package is installed and not hidden, or if the caller
      * explicitly wanted all uninstalled and hidden packages as well.
      * @param appInfo The applicationInfo of the app being checked.
@@ -658,8 +643,45 @@
         return checkUseInstalledOrHidden(0, state, null);
     }
 
+    /**
+     * Generate and return the {@link PackageInfo} for a parsed package.
+     *
+     * @param p the parsed package.
+     * @param flags indicating which optional information is included.
+     */
     @UnsupportedAppUsage
     public static PackageInfo generatePackageInfo(PackageParser.Package p,
+            int[] gids, int flags, long firstInstallTime, long lastUpdateTime,
+            Set<String> grantedPermissions, PackageUserState state) {
+
+        return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
+                grantedPermissions, state, UserHandle.getCallingUserId());
+    }
+
+    @UnsupportedAppUsage
+    public static PackageInfo generatePackageInfo(PackageParser.Package p,
+            int[] gids, int flags, long firstInstallTime, long lastUpdateTime,
+            Set<String> grantedPermissions, PackageUserState state, int userId) {
+
+        return generatePackageInfo(p, null, gids, flags, firstInstallTime, lastUpdateTime,
+                grantedPermissions, state, userId);
+    }
+
+    /**
+     * PackageInfo generator specifically for apex files.
+     *
+     * @param pkg Package to generate info from. Should be derived from an apex.
+     * @param apexInfo Apex info relating to the package.
+     * @return PackageInfo
+     * @throws PackageParserException
+     */
+    public static PackageInfo generatePackageInfo(
+            PackageParser.Package pkg, ApexInfo apexInfo, int flags) {
+        return generatePackageInfo(pkg, apexInfo, EmptyArray.INT, flags, 0, 0,
+                Collections.emptySet(), new PackageUserState(), UserHandle.getCallingUserId());
+    }
+
+    private static PackageInfo generatePackageInfo(PackageParser.Package p, ApexInfo apexInfo,
             int gids[], int flags, long firstInstallTime, long lastUpdateTime,
             Set<String> grantedPermissions, PackageUserState state, int userId) {
         if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) {
@@ -806,8 +828,27 @@
                 }
             }
         }
+
+        if (apexInfo != null) {
+            File apexFile = new File(apexInfo.modulePath);
+
+            pi.applicationInfo.sourceDir = apexFile.getPath();
+            pi.applicationInfo.publicSourceDir = apexFile.getPath();
+            if (apexInfo.isFactory) {
+                pi.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
+            } else {
+                pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM;
+            }
+            if (apexInfo.isActive) {
+                pi.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED;
+            } else {
+                pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_INSTALLED;
+            }
+            pi.isApex = true;
+        }
+
         // deprecated method of getting signing certificates
-        if ((flags&PackageManager.GET_SIGNATURES) != 0) {
+        if ((flags & PackageManager.GET_SIGNATURES) != 0) {
             if (p.mSigningDetails.hasPastSigningCertificates()) {
                 // Package has included signing certificate rotation information.  Return the oldest
                 // cert so that programmatic checks keep working even if unaware of key rotation.
@@ -8379,61 +8420,4 @@
         }
     }
 
-    // TODO(b/129261524): Clean up API
-    /**
-     * PackageInfo parser specifically for apex files.
-     * NOTE: It will collect certificates
-     *
-     * @param apexInfo
-     * @return PackageInfo
-     * @throws PackageParserException
-     */
-    public static PackageInfo generatePackageInfoFromApex(ApexInfo apexInfo, int flags)
-            throws PackageParserException {
-        PackageParser pp = new PackageParser();
-        File apexFile = new File(apexInfo.modulePath);
-        final Package p = pp.parsePackage(apexFile, flags, false);
-        PackageUserState state = new PackageUserState();
-        PackageInfo pi = generatePackageInfo(p, EmptyArray.INT, flags, 0, 0,
-                Collections.emptySet(), state);
-        pi.applicationInfo.sourceDir = apexFile.getPath();
-        pi.applicationInfo.publicSourceDir = apexFile.getPath();
-        if (apexInfo.isFactory) {
-            pi.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
-        } else {
-            pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM;
-        }
-        if (apexInfo.isActive) {
-            pi.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED;
-        } else {
-            pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_INSTALLED;
-        }
-        pi.isApex = true;
-
-        // Collect certificates
-        if ((flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0) {
-            collectCertificates(p, apexFile, false);
-            // Keep legacy mechanism for handling signatures. While this is deprecated, it's
-            // still part of the public API and needs to be maintained
-            if (p.mSigningDetails.hasPastSigningCertificates()) {
-                // Package has included signing certificate rotation information.  Return
-                // the oldest cert so that programmatic checks keep working even if unaware
-                // of key rotation.
-                pi.signatures = new Signature[1];
-                pi.signatures[0] = p.mSigningDetails.pastSigningCertificates[0];
-            } else if (p.mSigningDetails.hasSignatures()) {
-                // otherwise keep old behavior
-                int numberOfSigs = p.mSigningDetails.signatures.length;
-                pi.signatures = new Signature[numberOfSigs];
-                System.arraycopy(p.mSigningDetails.signatures, 0, pi.signatures, 0, numberOfSigs);
-            }
-            if (p.mSigningDetails != SigningDetails.UNKNOWN) {
-                // only return a valid SigningInfo if there is signing information to report
-                pi.signingInfo = new SigningInfo(p.mSigningDetails);
-            } else {
-                pi.signingInfo = null;
-            }
-        }
-        return pi;
-    }
 }
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index 61648dc..5f662f9 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -52,6 +52,7 @@
     @UnsupportedAppUsage
     NetworkInfo getActiveNetworkInfo();
     NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked);
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     NetworkInfo getNetworkInfo(int networkType);
     NetworkInfo getNetworkInfoForUid(in Network network, int uid, boolean ignoreBlocked);
     @UnsupportedAppUsage
@@ -112,6 +113,7 @@
 
     int setUsbTethering(boolean enable, String callerPkg);
 
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void reportInetCondition(int networkType, int percentage);
 
     void reportNetworkConnectivity(in Network network, boolean hasConnectivity);
diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java
index 43ea589..ff4bf2d 100644
--- a/core/java/android/net/NetworkAgent.java
+++ b/core/java/android/net/NetworkAgent.java
@@ -16,6 +16,7 @@
 
 package android.net;
 
+import android.annotation.NonNull;
 import android.annotation.UnsupportedAppUsage;
 import android.content.Context;
 import android.os.Build;
@@ -418,7 +419,16 @@
         if (score < 0) {
             throw new IllegalArgumentException("Score must be >= 0");
         }
-        queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED,  score, 0);
+        final NetworkScore ns = new NetworkScore();
+        ns.putIntExtension(NetworkScore.LEGACY_SCORE, score);
+        updateScore(ns);
+    }
+
+    /**
+     * Called by the bearer code when it has a new NetworkScore for this network.
+     */
+    public void updateScore(@NonNull NetworkScore ns) {
+        queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, new NetworkScore(ns));
     }
 
     /**
diff --git a/core/java/android/net/NetworkScore.java b/core/java/android/net/NetworkScore.java
new file mode 100644
index 0000000..1ab6335
--- /dev/null
+++ b/core/java/android/net/NetworkScore.java
@@ -0,0 +1,157 @@
+/*
+ * 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 android.net;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Objects;
+
+/**
+ * Object representing the quality of a network as perceived by the user.
+ *
+ * A NetworkScore object represents the characteristics of a network that affects how good the
+ * network is considered for a particular use.
+ * @hide
+ */
+public final class NetworkScore implements Parcelable {
+
+    // The key of bundle which is used to get the legacy network score of NetworkAgentInfo.
+    // TODO: Remove this when the transition to NetworkScore is over.
+    public static final String LEGACY_SCORE = "LEGACY_SCORE";
+    @NonNull
+    private final Bundle mExtensions;
+
+    public NetworkScore() {
+        mExtensions = new Bundle();
+    }
+
+    public NetworkScore(@NonNull NetworkScore source) {
+        mExtensions = new Bundle(source.mExtensions);
+    }
+
+    /**
+     * Put the value of parcelable inside the bundle by key.
+     */
+    public void putExtension(@Nullable String key, @Nullable Parcelable value) {
+        mExtensions.putParcelable(key, value);
+    }
+
+    /**
+     * Put the value of int inside the bundle by key.
+     */
+    public void putIntExtension(@Nullable String key, int value) {
+        mExtensions.putInt(key, value);
+    }
+
+    /**
+     * Get the value of non primitive type by key.
+     */
+    public <T extends Parcelable> T getExtension(@Nullable String key) {
+        return mExtensions.getParcelable(key);
+    }
+
+    /**
+     * Get the value of int by key.
+     */
+    public int getIntExtension(@Nullable String key) {
+        return mExtensions.getInt(key);
+    }
+
+    /**
+     * Remove the entry by given key.
+     */
+    public void removeExtension(@Nullable String key) {
+        mExtensions.remove(key);
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        synchronized (this) {
+            dest.writeBundle(mExtensions);
+        }
+    }
+
+    public static final @NonNull Creator<NetworkScore> CREATOR = new Creator<NetworkScore>() {
+        @Override
+        public NetworkScore createFromParcel(@NonNull Parcel in) {
+            return new NetworkScore(in);
+        }
+
+        @Override
+        public NetworkScore[] newArray(int size) {
+            return new NetworkScore[size];
+        }
+    };
+
+    private NetworkScore(@NonNull Parcel in) {
+        mExtensions = in.readBundle();
+    }
+
+    // TODO: Modify this method once new fields are added into this class.
+    @Override
+    public boolean equals(@Nullable Object obj) {
+        if (!(obj instanceof NetworkScore)) {
+            return false;
+        }
+        final NetworkScore other = (NetworkScore) obj;
+        return bundlesEqual(mExtensions, other.mExtensions);
+    }
+
+    @Override
+    public int hashCode() {
+        int result = 29;
+        for (String key : mExtensions.keySet()) {
+            final Object value = mExtensions.get(key);
+            // The key may be null, so call Objects.hash() is safer.
+            result += 31 * value.hashCode() + 37 * Objects.hash(key);
+        }
+        return result;
+    }
+
+    // mExtensions won't be null since the constructor will create it.
+    private boolean bundlesEqual(@NonNull Bundle bundle1, @NonNull Bundle bundle2) {
+        if (bundle1 == bundle2) {
+            return true;
+        }
+
+        // This is unlikely but it's fine to add this clause here.
+        if (null == bundle1 || null == bundle2) {
+            return false;
+        }
+
+        if (bundle1.size() != bundle2.size()) {
+            return false;
+        }
+
+        for (String key : bundle1.keySet()) {
+            final Object value1 = bundle1.get(key);
+            final Object value2 = bundle2.get(key);
+            if (!Objects.equals(value1, value2)) {
+                return false;
+            }
+        }
+        return true;
+    }
+}
diff --git a/core/java/android/os/AsyncTask.java b/core/java/android/os/AsyncTask.java
index d259f38..b37e176 100644
--- a/core/java/android/os/AsyncTask.java
+++ b/core/java/android/os/AsyncTask.java
@@ -38,9 +38,11 @@
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
- * <p>AsyncTask enables proper and easy use of the UI thread. This class allows you
- * to perform background operations and publish results on the UI thread without
- * having to manipulate threads and/or handlers.</p>
+ * <p>AsyncTask was intended to enable proper and easy use of the UI thread. However, the most
+ * common use case was for integrating into UI, and that would cause Context leaks, missed
+ * callbacks, or crashes on configuration changes. It also has inconsistent behavior on different
+ * versions of the platform, swallows exceptions from {@code doInBackground}, and does not provide
+ * much utility over using {@link Executor}s directly.</p>
  *
  * <p>AsyncTask is designed to be a helper class around {@link Thread} and {@link Handler}
  * and does not constitute a generic threading framework. AsyncTasks should ideally be
@@ -188,7 +190,12 @@
  * <p>If you truly want parallel execution, you can invoke
  * {@link #executeOnExecutor(java.util.concurrent.Executor, Object[])} with
  * {@link #THREAD_POOL_EXECUTOR}.</p>
+ *
+ * @deprecated Use the standard <code>java.util.concurrent</code> or
+ *   <a href="https://developer.android.com/topic/libraries/architecture/coroutines">
+ *   Kotlin concurrency utilities</a> instead.
  */
+@Deprecated
 public abstract class AsyncTask<Params, Progress, Result> {
     private static final String LOG_TAG = "AsyncTask";
 
@@ -240,7 +247,13 @@
 
     /**
      * An {@link Executor} that can be used to execute tasks in parallel.
+     *
+     * @deprecated Using a single thread pool for a general purpose results in suboptimal behavior
+     *   for different tasks. Small, CPU-bound tasks benefit from a bounded pool and queueing, and
+     *   long-running blocking tasks, such as network operations, benefit from many threads. Use or
+     *   create an {@link Executor} configured for your use case.
      */
+    @Deprecated
     public static final Executor THREAD_POOL_EXECUTOR;
 
     static {
@@ -254,7 +267,10 @@
     /**
      * An {@link Executor} that executes tasks one at a time in serial
      * order.  This serialization is global to a particular process.
+     *
+     * @deprecated Globally serializing tasks results in excessive queuing for unrelated operations.
      */
+    @Deprecated
     public static final Executor SERIAL_EXECUTOR = new SerialExecutor();
 
     private static final int MESSAGE_POST_RESULT = 0x1;
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 00d522b..2d2d681 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -66,6 +66,10 @@
 public abstract class BatteryStats implements Parcelable {
     private static final String TAG = "BatteryStats";
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+    public BatteryStats() {
+    }
+
     private static final boolean LOCAL_LOGV = false;
     /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */
     protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false;
@@ -404,6 +408,10 @@
      */
     public static abstract class Counter {
 
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+        public Counter() {
+        }
+
         /**
          * Returns the count associated with this Counter for the
          * selected type of statistics.
@@ -513,6 +521,10 @@
      */
     public static abstract class Timer {
 
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+        public Timer() {
+        }
+
         /**
          * Returns the count associated with this Timer for the
          * selected type of statistics.
@@ -668,6 +680,11 @@
          * The statistics associated with a particular wake lock.
          */
         public static abstract class Wakelock {
+
+            @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+            public Wakelock(){
+            }
+
             @UnsupportedAppUsage
             public abstract Timer getWakeTime(int type);
         }
@@ -945,6 +962,11 @@
         public abstract void getDeferredJobsLineLocked(StringBuilder sb, int which);
 
         public static abstract class Sensor {
+
+            @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+            public Sensor() {
+            }
+
             /*
              * FIXME: it's not correct to use this magic value because it
              * could clash with a sensor handle (which are defined by
@@ -975,6 +997,10 @@
          */
         public static abstract class Proc {
 
+            @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+            public Proc() {
+            }
+
             public static class ExcessivePower {
                 public static final int TYPE_WAKE = 1;
                 public static final int TYPE_CPU = 2;
@@ -1050,6 +1076,10 @@
          */
         public static abstract class Pkg {
 
+            @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+            public Pkg() {
+            }
+
             /**
              * Returns information about all wakeup alarms that have been triggered for this
              * package.  The mapping keys are tag names for the alarms, the counter contains
@@ -1552,6 +1582,7 @@
     }
 
     public final static class HistoryItem implements Parcelable {
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
         public HistoryItem next;
 
         // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
@@ -1874,6 +1905,7 @@
             numReadInts += (src.dataPosition()-start)/4;
         }
 
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
         public void clear() {
             time = 0;
             cmd = CMD_NULL;
@@ -1894,12 +1926,14 @@
             eventTag = null;
         }
 
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
         public void setTo(HistoryItem o) {
             time = o.time;
             cmd = o.cmd;
             setToCommon(o);
         }
 
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
         public void setTo(long time, byte cmd, HistoryItem o) {
             this.time = time;
             this.cmd = cmd;
@@ -1955,6 +1989,7 @@
                     && currentTime == o.currentTime;
         }
 
+        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
         public boolean same(HistoryItem o) {
             if (!sameNonEvent(o) || eventCode != o.eventCode) {
                 return false;
@@ -2337,6 +2372,7 @@
      *
      * {@hide}
      */
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
 
     /**
@@ -2694,6 +2730,7 @@
     public static final int NETWORK_WIFI_BG_TX_DATA = 9;
     public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public abstract long getNetworkActivityBytes(int type, int which);
     public abstract long getNetworkActivityPackets(int type, int which);
 
diff --git a/core/java/android/os/CancellationSignal.java b/core/java/android/os/CancellationSignal.java
index e8053d5..99fb998 100644
--- a/core/java/android/os/CancellationSignal.java
+++ b/core/java/android/os/CancellationSignal.java
@@ -18,13 +18,19 @@
 
 import android.os.ICancellationSignal;
 
+import dalvik.annotation.compat.UnsupportedAppUsage;
+
 /**
  * Provides the ability to cancel an operation in progress.
  */
 public final class CancellationSignal {
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private boolean mIsCanceled;
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private OnCancelListener mOnCancelListener;
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private ICancellationSignal mRemote;
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private boolean mCancelInProgress;
 
     /**
@@ -152,6 +158,7 @@
         }
     }
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private void waitForCancelFinishedLocked() {
         while (mCancelInProgress) {
             try {
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 154e8cd..4ed7b17 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -1690,6 +1690,8 @@
      * such runtime statistic exists.
      *
      * <p>The following table lists the runtime statistics that the runtime supports.
+     * All statistics are approximate. Individual allocations may not be immediately reflected
+     * in the results.
      * Note runtime statistics may be added or removed in a future API level.</p>
      *
      * <table>
diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl
index e1d605e..185693e 100644
--- a/core/java/android/os/IPowerManager.aidl
+++ b/core/java/android/os/IPowerManager.aidl
@@ -47,6 +47,7 @@
     void wakeUp(long time, int reason, String details, String opPackageName);
     @UnsupportedAppUsage
     void goToSleep(long time, int reason, int flags);
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void nap(long time);
     @UnsupportedAppUsage
     boolean isInteractive();
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index dbe3c93..e1b5542 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -3148,6 +3148,7 @@
     // Cache of previously looked up CREATOR.createFromParcel() methods for
     // particular classes.  Keys are the names of the classes, values are
     // Method objects.
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private static final HashMap<ClassLoader,HashMap<String,Parcelable.Creator<?>>>
         mCreators = new HashMap<>();
 
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 2fff595..ab4d424 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -824,6 +824,7 @@
     final Context mContext;
     @UnsupportedAppUsage
     final IPowerManager mService;
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     final Handler mHandler;
 
     IThermalService mThermalService;
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index f852976..8d74fc5 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -1003,6 +1003,7 @@
      * your own log, or the Android Illuminati will find you some night and
      * beat you up.
      */
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public static final native void sendSignalQuiet(int pid, int signal);
     
     /** @hide */
diff --git a/core/java/android/os/Registrant.java b/core/java/android/os/Registrant.java
index 8fb123a..572b975 100644
--- a/core/java/android/os/Registrant.java
+++ b/core/java/android/os/Registrant.java
@@ -114,6 +114,7 @@
         }
     }
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public Handler
     getHandler()
     {
diff --git a/core/java/android/os/RegistrantList.java b/core/java/android/os/RegistrantList.java
index 6e562ff..e9bc637 100644
--- a/core/java/android/os/RegistrantList.java
+++ b/core/java/android/os/RegistrantList.java
@@ -70,6 +70,7 @@
         return registrants.size();
     }
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public synchronized Object
     get(int index)
     {
diff --git a/core/java/android/os/RemoteCallback.java b/core/java/android/os/RemoteCallback.java
index 047ba1d..da58d0f 100644
--- a/core/java/android/os/RemoteCallback.java
+++ b/core/java/android/os/RemoteCallback.java
@@ -21,6 +21,8 @@
 import android.annotation.SystemApi;
 import android.annotation.TestApi;
 
+import dalvik.annotation.compat.UnsupportedAppUsage;
+
 /**
  * @hide
  */
@@ -33,6 +35,7 @@
     }
 
     private final OnResultListener mListener;
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private final Handler mHandler;
     private final IRemoteCallback mCallback;
 
diff --git a/core/java/android/os/SystemProperties.java b/core/java/android/os/SystemProperties.java
index a6e5972..8b0ffe1 100644
--- a/core/java/android/os/SystemProperties.java
+++ b/core/java/android/os/SystemProperties.java
@@ -95,12 +95,17 @@
 
     @UnsupportedAppUsage
     private static native String native_get(String key);
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private static native String native_get(String key, String def);
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private static native int native_get_int(String key, int def);
     @UnsupportedAppUsage
     private static native long native_get_long(String key, long def);
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private static native boolean native_get_boolean(String key, boolean def);
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private static native void native_set(String key, String def);
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private static native void native_add_change_callback();
     private static native void native_report_sysprop_change();
 
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index d70ba99..4e17f7e 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -354,6 +354,7 @@
      * components -- user, app, isolated, etc.
      * @hide
      */
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public static void formatUid(PrintWriter pw, int uid) {
         if (uid < Process.FIRST_APPLICATION_UID) {
             pw.print(uid);
diff --git a/core/java/android/os/WorkSource.java b/core/java/android/os/WorkSource.java
index 634b2ba..9cc9aac 100644
--- a/core/java/android/os/WorkSource.java
+++ b/core/java/android/os/WorkSource.java
@@ -40,14 +40,17 @@
      * The WorkSource object itself is not thread safe, but we need to
      * hold sTmpWorkSource lock while working with these statics.
      */
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     static final WorkSource sTmpWorkSource = new WorkSource(0);
     /**
      * For returning newbie work from a modification operation.
      */
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     static WorkSource sNewbWork;
     /**
      * For returning gone work form a modification operation.
      */
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     static WorkSource sGoneWork;
 
     /**
@@ -620,6 +623,7 @@
         return changed;
     }
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     private boolean updateLocked(WorkSource other, boolean set, boolean returnNewbs) {
         if (mNames == null && other.mNames == null) {
             return updateUidsLocked(other, set, returnNewbs);
diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java
index 0973a64..3d54ba1 100644
--- a/core/java/android/provider/CallLog.java
+++ b/core/java/android/provider/CallLog.java
@@ -35,6 +35,7 @@
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.DataUsageFeedback;
+import android.telecom.CallerInfo;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
@@ -42,7 +43,6 @@
 import android.text.TextUtils;
 import android.util.Log;
 
-import android.telephony.CallerInfo;
 import com.android.internal.telephony.PhoneConstants;
 
 import java.util.List;
diff --git a/core/java/android/service/carrier/ICarrierMessagingService.aidl b/core/java/android/service/carrier/ICarrierMessagingService.aidl
index 2d96c3d..c4dfb57 100644
--- a/core/java/android/service/carrier/ICarrierMessagingService.aidl
+++ b/core/java/android/service/carrier/ICarrierMessagingService.aidl
@@ -36,6 +36,7 @@
      * @param subId SMS subscription ID of the SIM
      * @param callback the callback to notify upon completion
      */
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void filterSms(
         in MessagePdu pdu, String format, int destPort, int subId,
         in ICarrierMessagingCallback callback);
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index 39792ce..1c32948 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -151,6 +151,7 @@
     float getCurrentAnimatorScale();
 
     // For testing
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void setInTouchMode(boolean showFocus);
 
     // For StrictMode flashing a red border on violations from the UI
@@ -158,6 +159,7 @@
     // Manager uses that to determine whether or not the red border should
     // actually be shown.  (it will be ignored that pid doesn't have windows
     // on screen)
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void showStrictModeViolation(boolean on);
 
     // Proxy to set the system property for whether the flashing
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index 46e041b..3d91c37 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -114,6 +114,13 @@
      */
     public static final int DEBUG_IGNORE_APP_SIGNAL_HANDLER = 1 << 17;
 
+    /**
+     * Disable runtime access to {@link android.annotation.TestApi} annotated members.
+     *
+     * <p>This only takes effect if Hidden API access restrictions are enabled as well.
+     */
+    public static final int DISABLE_TEST_API_ENFORCEMENT_POLICY = 1 << 18;
+
     /** No external storage should be mounted. */
     public static final int MOUNT_EXTERNAL_NONE = IVold.REMOUNT_MODE_NONE;
     /** Default external storage should be mounted. */
diff --git a/core/java/com/android/internal/view/BaseIWindow.java b/core/java/com/android/internal/view/BaseIWindow.java
index f9cdf3d..f5a9fde 100644
--- a/core/java/com/android/internal/view/BaseIWindow.java
+++ b/core/java/com/android/internal/view/BaseIWindow.java
@@ -16,9 +16,11 @@
 
 package com.android.internal.view;
 
+import android.annotation.UnsupportedAppUsage;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.hardware.input.InputManager;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
@@ -37,6 +39,10 @@
     private IWindowSession mSession;
     public int mSeq;
 
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
+    public BaseIWindow() {
+    }
+
     public void setSession(IWindowSession session) {
         mSession = session;
     }
diff --git a/core/tests/coretests/src/android/content/pm/PackageParserTest.java b/core/tests/coretests/src/android/content/pm/PackageParserTest.java
index 58c43ac2..5e41355 100644
--- a/core/tests/coretests/src/android/content/pm/PackageParserTest.java
+++ b/core/tests/coretests/src/android/content/pm/PackageParserTest.java
@@ -508,7 +508,12 @@
         apexInfo.modulePath = apexFile.getPath();
         apexInfo.versionCode = 191000070;
         int flags = PackageManager.GET_META_DATA | PackageManager.GET_SIGNING_CERTIFICATES;
-        PackageInfo pi = PackageParser.generatePackageInfoFromApex(apexInfo, flags);
+
+        PackageParser pp = new PackageParser();
+        Package p = pp.parsePackage(apexFile, flags, false);
+        PackageParser.collectCertificates(p, false);
+        PackageInfo pi = PackageParser.generatePackageInfo(p, apexInfo, flags);
+
         assertEquals("com.google.android.tzdata", pi.applicationInfo.packageName);
         assertTrue(pi.applicationInfo.enabled);
         assertEquals(28, pi.applicationInfo.targetSdkVersion);
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java
index 510ee44..c9d7978 100644
--- a/media/java/android/media/MediaCodec.java
+++ b/media/java/android/media/MediaCodec.java
@@ -1702,20 +1702,22 @@
                     break;
                 }
                 case EVENT_FRAME_RENDERED:
-                    synchronized (mListenerLock) {
-                        Map<String, Object> map = (Map<String, Object>)msg.obj;
-                        for (int i = 0; ; ++i) {
-                            Object mediaTimeUs = map.get(i + "-media-time-us");
-                            Object systemNano = map.get(i + "-system-nano");
-                            if (mediaTimeUs == null || systemNano == null
-                                    || mOnFrameRenderedListener == null) {
-                                break;
-                            }
-                            mOnFrameRenderedListener.onFrameRendered(
-                                    mCodec, (long)mediaTimeUs, (long)systemNano);
+                    Map<String, Object> map = (Map<String, Object>)msg.obj;
+                    for (int i = 0; ; ++i) {
+                        Object mediaTimeUs = map.get(i + "-media-time-us");
+                        Object systemNano = map.get(i + "-system-nano");
+                        OnFrameRenderedListener onFrameRenderedListener;
+                        synchronized (mListenerLock) {
+                            onFrameRenderedListener = mOnFrameRenderedListener;
                         }
-                        break;
+                        if (mediaTimeUs == null || systemNano == null
+                                || onFrameRenderedListener == null) {
+                            break;
+                        }
+                        onFrameRenderedListener.onFrameRendered(
+                                mCodec, (long)mediaTimeUs, (long)systemNano);
                     }
+                    break;
                 default:
                 {
                     break;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarMobileView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarMobileView.java
index 689d161..239addd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarMobileView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarMobileView.java
@@ -208,11 +208,9 @@
 
     @Override
     public void onDarkChanged(Rect area, float darkIntensity, int tint) {
-        if (!isInArea(area, this)) {
-            return;
-        }
+        float intensity = isInArea(area, this) ? darkIntensity : 0;
         mMobileDrawable.setTintList(
-                ColorStateList.valueOf(mDualToneHandler.getSingleColor(darkIntensity)));
+                ColorStateList.valueOf(mDualToneHandler.getSingleColor(intensity)));
         ColorStateList color = ColorStateList.valueOf(getTint(area, this, tint));
         mIn.setImageTintList(color);
         mOut.setImageTintList(color);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarWifiView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarWifiView.java
index 23e2d27..6dbcc44 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarWifiView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarWifiView.java
@@ -236,15 +236,13 @@
 
     @Override
     public void onDarkChanged(Rect area, float darkIntensity, int tint) {
-        if (!isInArea(area, this)) {
-            return;
-        }
-
-        mWifiIcon.setImageTintList(ColorStateList.valueOf(getTint(area, this, tint)));
-        mIn.setImageTintList(ColorStateList.valueOf(getTint(area, this, tint)));
-        mOut.setImageTintList(ColorStateList.valueOf(getTint(area, this, tint)));
-        mDotView.setDecorColor(tint);
-        mDotView.setIconColor(tint, false);
+        int areaTint = getTint(area, this, tint);
+        ColorStateList color = ColorStateList.valueOf(areaTint);
+        mWifiIcon.setImageTintList(color);
+        mIn.setImageTintList(color);
+        mOut.setImageTintList(color);
+        mDotView.setDecorColor(areaTint);
+        mDotView.setIconColor(areaTint, false);
     }
 
 
diff --git a/services/core/java/com/android/server/AppStateTracker.java b/services/core/java/com/android/server/AppStateTracker.java
index 3a7b5d6..207e007 100644
--- a/services/core/java/com/android/server/AppStateTracker.java
+++ b/services/core/java/com/android/server/AppStateTracker.java
@@ -700,14 +700,16 @@
                 Slog.d(TAG,"onAppIdleStateChanged: " + packageName + " u" + userId
                         + (idle ? " idle" : " active") + " " + bucket);
             }
-            final boolean changed;
-            if (bucket == UsageStatsManager.STANDBY_BUCKET_EXEMPTED) {
-                changed = mExemptedPackages.add(userId, packageName);
-            } else {
-                changed = mExemptedPackages.remove(userId, packageName);
-            }
-            if (changed) {
-                mHandler.notifyExemptChanged();
+            synchronized (mLock) {
+                final boolean changed;
+                if (bucket == UsageStatsManager.STANDBY_BUCKET_EXEMPTED) {
+                    changed = mExemptedPackages.add(userId, packageName);
+                } else {
+                    changed = mExemptedPackages.remove(userId, packageName);
+                }
+                if (changed) {
+                    mHandler.notifyExemptChanged();
+                }
             }
         }
 
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index ce0e9e7..81eb4b3 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -97,6 +97,7 @@
 import android.net.NetworkPolicyManager;
 import android.net.NetworkQuotaInfo;
 import android.net.NetworkRequest;
+import android.net.NetworkScore;
 import android.net.NetworkSpecifier;
 import android.net.NetworkStack;
 import android.net.NetworkStackClient;
@@ -2643,7 +2644,8 @@
                     break;
                 }
                 case NetworkAgent.EVENT_NETWORK_SCORE_CHANGED: {
-                    updateNetworkScore(nai, msg.arg1);
+                    final NetworkScore ns = (NetworkScore) msg.obj;
+                    updateNetworkScore(nai, ns);
                     break;
                 }
                 case NetworkAgent.EVENT_SET_EXPLICITLY_SELECTED: {
@@ -5594,9 +5596,11 @@
         // TODO: Instead of passing mDefaultRequest, provide an API to determine whether a Network
         // satisfies mDefaultRequest.
         final NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
+        final NetworkScore ns = new NetworkScore();
+        ns.putIntExtension(NetworkScore.LEGACY_SCORE, currentScore);
         final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(),
                 new Network(mNetIdManager.reserveNetId()), new NetworkInfo(networkInfo), lp, nc,
-                currentScore, mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd,
+                ns, mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd,
                 mDnsResolver, mNMS, factorySerialNumber);
         // Make sure the network capabilities reflect what the agent info says.
         nai.setNetworkCapabilities(mixInCapabilities(nai, nc));
@@ -6729,7 +6733,8 @@
         }
     }
 
-    private void updateNetworkScore(NetworkAgentInfo nai, int score) {
+    private void updateNetworkScore(NetworkAgentInfo nai, NetworkScore ns) {
+        int score = ns.getIntExtension(NetworkScore.LEGACY_SCORE);
         if (VDBG || DDBG) log("updateNetworkScore for " + nai.name() + " to " + score);
         if (score < 0) {
             loge("updateNetworkScore for " + nai.name() + " got a negative score (" + score +
@@ -6738,7 +6743,7 @@
         }
 
         final int oldScore = nai.getCurrentScore();
-        nai.setCurrentScore(score);
+        nai.setNetworkScore(ns);
 
         rematchAllNetworksAndRequests(nai, oldScore);
 
diff --git a/services/core/java/com/android/server/Watchdog.java b/services/core/java/com/android/server/Watchdog.java
index 19ad32e..83ad4e7 100644
--- a/services/core/java/com/android/server/Watchdog.java
+++ b/services/core/java/com/android/server/Watchdog.java
@@ -103,6 +103,8 @@
     public static final List<String> HAL_INTERFACES_OF_INTEREST = Arrays.asList(
             "android.hardware.audio@2.0::IDevicesFactory",
             "android.hardware.audio@4.0::IDevicesFactory",
+            "android.hardware.audio@5.0::IDevicesFactory",
+            "android.hardware.audio@6.0::IDevicesFactory",
             "android.hardware.biometrics.face@1.0::IBiometricsFace",
             "android.hardware.bluetooth@1.0::IBluetoothHci",
             "android.hardware.camera.provider@2.4::ICameraProvider",
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 76bfc97..7609632 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -7786,10 +7786,18 @@
                 false /* mountExtStorageFull */, abiOverride);
     }
 
-    // TODO: Move to ProcessList?
     @GuardedBy("this")
     final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated,
             boolean disableHiddenApiChecks, boolean mountExtStorageFull, String abiOverride) {
+        return addAppLocked(info, customProcess, isolated, disableHiddenApiChecks,
+                false /* disableTestApiChecks */, mountExtStorageFull, abiOverride);
+    }
+
+    // TODO: Move to ProcessList?
+    @GuardedBy("this")
+    final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated,
+            boolean disableHiddenApiChecks, boolean disableTestApiChecks,
+            boolean mountExtStorageFull, String abiOverride) {
         ProcessRecord app;
         if (!isolated) {
             app = getProcessRecordLocked(customProcess != null ? customProcess : info.processName,
@@ -7824,7 +7832,7 @@
             mPersistentStartingProcesses.add(app);
             mProcessList.startProcessLocked(app, new HostingRecord("added application",
                     customProcess != null ? customProcess : app.processName),
-                    disableHiddenApiChecks, mountExtStorageFull, abiOverride);
+                    disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride);
         }
 
         return app;
@@ -15765,6 +15773,10 @@
                 enforceCallingPermission(android.Manifest.permission.DISABLE_HIDDEN_API_CHECKS,
                         "disable hidden API checks");
             }
+            // Allow instrumented processes access to test APIs.
+            // TODO(satayev): make this configurable via testing framework.
+            boolean disableTestApiChecks = true;
+
             final boolean mountExtStorageFull = isCallerShell()
                     && (flags & INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL) != 0;
 
@@ -15779,7 +15791,7 @@
             }
 
             ProcessRecord app = addAppLocked(ai, defProcess, false, disableHiddenApiChecks,
-                    mountExtStorageFull, abiOverride);
+                    disableTestApiChecks, mountExtStorageFull, abiOverride);
             app.setActiveInstrumentation(activeInstr);
             activeInstr.mFinished = false;
             activeInstr.mRunningProcesses.add(app);
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 3d598dd..4692fd4 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -1419,15 +1419,11 @@
 
     /**
      * @return {@code true} if process start is successful, false otherwise.
-     * @param app
-     * @param hostingRecord
-     * @param disableHiddenApiChecks
-     * @param abiOverride
      */
     @GuardedBy("mService")
     boolean startProcessLocked(ProcessRecord app, HostingRecord hostingRecord,
-            boolean disableHiddenApiChecks, boolean mountExtStorageFull,
-            String abiOverride) {
+            boolean disableHiddenApiChecks, boolean disableTestApiChecks,
+            boolean mountExtStorageFull, String abiOverride) {
         if (app.pendingStart) {
             return true;
         }
@@ -1572,6 +1568,10 @@
                     throw new IllegalStateException("Invalid API policy: " + policy);
                 }
                 runtimeFlags |= policyBits;
+
+                if (disableTestApiChecks) {
+                    runtimeFlags |= Zygote.DISABLE_TEST_API_ENFORCEMENT_POLICY;
+                }
             }
 
             String useAppImageCache = SystemProperties.get(
@@ -1845,7 +1845,8 @@
     final boolean startProcessLocked(ProcessRecord app, HostingRecord hostingRecord,
             String abiOverride) {
         return startProcessLocked(app, hostingRecord,
-                false /* disableHiddenApiChecks */, false /* mountExtStorageFull */, abiOverride);
+                false /* disableHiddenApiChecks */, false /* disableTestApiChecks */,
+                false /* mountExtStorageFull */, abiOverride);
     }
 
     @GuardedBy("mService")
diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
index 96b7cb3..24a5b7f 100644
--- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
@@ -28,6 +28,7 @@
 import android.net.NetworkMisc;
 import android.net.NetworkMonitorManager;
 import android.net.NetworkRequest;
+import android.net.NetworkScore;
 import android.net.NetworkState;
 import android.os.Handler;
 import android.os.INetworkManagementService;
@@ -227,8 +228,10 @@
     // validated).
     private boolean mLingering;
 
-    // This represents the last score received from the NetworkAgent.
-    private int currentScore;
+    // This represents the characteristics of a network that affects how good the network is
+    // considered for a particular use.
+    @NonNull
+    private NetworkScore mNetworkScore;
 
     // The list of NetworkRequests being satisfied by this Network.
     private final SparseArray<NetworkRequest> mNetworkRequests = new SparseArray<>();
@@ -257,8 +260,8 @@
     private final Handler mHandler;
 
     public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, Network net, NetworkInfo info,
-            LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler,
-            NetworkMisc misc, ConnectivityService connService, INetd netd,
+            LinkProperties lp, NetworkCapabilities nc, @NonNull NetworkScore ns, Context context,
+            Handler handler, NetworkMisc misc, ConnectivityService connService, INetd netd,
             IDnsResolver dnsResolver, INetworkManagementService nms, int factorySerialNumber) {
         this.messenger = messenger;
         asyncChannel = ac;
@@ -266,7 +269,7 @@
         networkInfo = info;
         linkProperties = lp;
         networkCapabilities = nc;
-        currentScore = score;
+        mNetworkScore = ns;
         clatd = new Nat464Xlat(this, netd, dnsResolver, nms);
         mConnService = connService;
         mContext = context;
@@ -483,7 +486,7 @@
             return ConnectivityConstants.EXPLICITLY_SELECTED_NETWORK_SCORE;
         }
 
-        int score = currentScore;
+        int score = mNetworkScore.getIntExtension(NetworkScore.LEGACY_SCORE);
         if (!lastValidated && !pretendValidated && !ignoreWifiUnvalidationPenalty() && !isVPN()) {
             score -= ConnectivityConstants.UNVALIDATED_SCORE_PENALTY;
         }
@@ -512,8 +515,13 @@
         return getCurrentScore(true);
     }
 
-    public void setCurrentScore(int newScore) {
-        currentScore = newScore;
+    public void setNetworkScore(@NonNull NetworkScore ns) {
+        mNetworkScore = ns;
+    }
+
+    @NonNull
+    public NetworkScore getNetworkScore() {
+        return mNetworkScore;
     }
 
     public NetworkState getNetworkState() {
diff --git a/services/core/java/com/android/server/pm/ApexManager.java b/services/core/java/com/android/server/pm/ApexManager.java
index a0c00f8..fd44cbb 100644
--- a/services/core/java/com/android/server/pm/ApexManager.java
+++ b/services/core/java/com/android/server/pm/ApexManager.java
@@ -11,7 +11,7 @@
  * 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.s
+ * limitations under the License.
  */
 
 package com.android.server.pm;
@@ -29,17 +29,17 @@
 import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
+import android.content.pm.PackageInstaller;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageParser;
-import android.content.pm.PackageParser.PackageParserException;
 import android.os.RemoteException;
 import android.os.ServiceManager;
-import android.os.ServiceManager.ServiceNotFoundException;
 import android.sysprop.ApexProperties;
-import android.util.ArrayMap;
 import android.util.Slog;
 
 import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.os.BackgroundThread;
 import com.android.internal.util.IndentingPrintWriter;
 
 import java.io.File;
@@ -56,117 +56,33 @@
  * ApexManager class handles communications with the apex service to perform operation and queries,
  * as well as providing caching to avoid unnecessary calls to the service.
  */
-class ApexManager {
-    static final String TAG = "ApexManager";
-    private final IApexService mApexService;
-    private final Context mContext;
-    private final Object mLock = new Object();
-    /**
-     * A map from {@code APEX packageName} to the {@Link PackageInfo} generated from the {@code
-     * AndroidManifest.xml}
-     *
-     * <p>Note that key of this map is {@code packageName} field of the corresponding {@code
-     * AndroidManifest.xml}.
-      */
-    @GuardedBy("mLock")
-    private List<PackageInfo> mAllPackagesCache;
-    /**
-     * A map from {@code apexName} to the {@Link PackageInfo} generated from the {@code
-     * AndroidManifest.xml}.
-     *
-     * <p>Note that key of this map is {@code apexName} field which corresponds to the {@code name}
-     * field of {@code apex_manifest.json}.
-     */
-    // TODO(b/132324953): remove.
-    @GuardedBy("mLock")
-    private ArrayMap<String, PackageInfo> mApexNameToPackageInfoCache;
+abstract class ApexManager {
 
-
-    ApexManager(Context context) {
-        mContext = context;
-        if (!isApexSupported()) {
-            mApexService = null;
-            return;
-        }
-        try {
-            mApexService = IApexService.Stub.asInterface(
-                ServiceManager.getServiceOrThrow("apexservice"));
-        } catch (ServiceNotFoundException e) {
-            throw new IllegalStateException("Required service apexservice not available");
-        }
-    }
+    private static final String TAG = "ApexManager";
 
     static final int MATCH_ACTIVE_PACKAGE = 1 << 0;
     static final int MATCH_FACTORY_PACKAGE = 1 << 1;
-    @IntDef(
-            flag = true,
-            prefix = { "MATCH_"},
-            value = {MATCH_ACTIVE_PACKAGE, MATCH_FACTORY_PACKAGE})
-    @Retention(RetentionPolicy.SOURCE)
-    @interface PackageInfoFlags{}
 
-    void systemReady() {
-        if (!isApexSupported()) return;
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                onBootCompleted();
-                mContext.unregisterReceiver(this);
-            }
-        }, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
-    }
-
-    private void populateAllPackagesCacheIfNeeded() {
-        synchronized (mLock) {
-            if (mAllPackagesCache != null) {
-                return;
-            }
-            mApexNameToPackageInfoCache = new ArrayMap<>();
+    /**
+     * Returns an instance of either {@link ApexManagerImpl} or {@link ApexManagerNoOp} depending
+     * on whenever this device supports APEX, i.e. {@link ApexProperties#updatable()} evaluates to
+     * {@code true}.
+     */
+    static ApexManager create(Context systemContext) {
+        if (ApexProperties.updatable().orElse(false)) {
             try {
-                mAllPackagesCache = new ArrayList<>();
-                HashSet<String> activePackagesSet = new HashSet<>();
-                HashSet<String> factoryPackagesSet = new HashSet<>();
-                final ApexInfo[] allPkgs = mApexService.getAllPackages();
-                for (ApexInfo ai : allPkgs) {
-                    // If the device is using flattened APEX, don't report any APEX
-                    // packages since they won't be managed or updated by PackageManager.
-                    if ((new File(ai.modulePath)).isDirectory()) {
-                        break;
-                    }
-                    try {
-                        final PackageInfo pkg = PackageParser.generatePackageInfoFromApex(
-                                ai, PackageManager.GET_META_DATA
-                                        | PackageManager.GET_SIGNING_CERTIFICATES);
-                        mAllPackagesCache.add(pkg);
-                        if (ai.isActive) {
-                            if (activePackagesSet.contains(pkg.packageName)) {
-                                throw new IllegalStateException(
-                                        "Two active packages have the same name: "
-                                                + pkg.packageName);
-                            }
-                            activePackagesSet.add(pkg.packageName);
-                            // TODO(b/132324953): remove.
-                            mApexNameToPackageInfoCache.put(ai.moduleName, pkg);
-                        }
-                        if (ai.isFactory) {
-                            if (factoryPackagesSet.contains(pkg.packageName)) {
-                                throw new IllegalStateException(
-                                        "Two factory packages have the same name: "
-                                                + pkg.packageName);
-                            }
-                            factoryPackagesSet.add(pkg.packageName);
-                        }
-                    } catch (PackageParserException pe) {
-                        throw new IllegalStateException("Unable to parse: " + ai, pe);
-                    }
-                }
-            } catch (RemoteException re) {
-                Slog.e(TAG, "Unable to retrieve packages from apexservice: " + re.toString());
-                throw new RuntimeException(re);
+                return new ApexManagerImpl(systemContext, IApexService.Stub.asInterface(
+                        ServiceManager.getServiceOrThrow("apexservice")));
+            } catch (ServiceManager.ServiceNotFoundException e) {
+                throw new IllegalStateException("Required service apexservice not available");
             }
+        } else {
+            return new ApexManagerNoOp();
         }
     }
 
+    abstract void systemReady();
+
     /**
      * Retrieves information about an APEX package.
      *
@@ -179,35 +95,8 @@
      * @return a PackageInfo object with the information about the package, or null if the package
      *         is not found.
      */
-    @Nullable PackageInfo getPackageInfo(String packageName, @PackageInfoFlags int flags) {
-        if (!isApexSupported()) return null;
-        populateAllPackagesCacheIfNeeded();
-        boolean matchActive = (flags & MATCH_ACTIVE_PACKAGE) != 0;
-        boolean matchFactory = (flags & MATCH_FACTORY_PACKAGE) != 0;
-        for (PackageInfo packageInfo: mAllPackagesCache) {
-            if (!packageInfo.packageName.equals(packageName)) {
-                continue;
-            }
-            if ((!matchActive || isActive(packageInfo))
-                    && (!matchFactory || isFactory(packageInfo))) {
-                return packageInfo;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Returns a {@link PackageInfo} for an active APEX package keyed by it's {@code apexName}.
-     *
-     * @deprecated this API will soon be deleted, please don't depend on it.
-     */
-    // TODO(b/132324953): delete.
-    @Deprecated
-    @Nullable PackageInfo getPackageInfoForApexName(String apexName) {
-        if (!isApexSupported()) return null;
-        populateAllPackagesCacheIfNeeded();
-        return mApexNameToPackageInfoCache.get(apexName);
-    }
+    @Nullable
+    abstract PackageInfo getPackageInfo(String packageName, @PackageInfoFlags int flags);
 
     /**
      * Retrieves information about all active APEX packages.
@@ -215,14 +104,7 @@
      * @return a List of PackageInfo object, each one containing information about a different
      *         active package.
      */
-    List<PackageInfo> getActivePackages() {
-        if (!isApexSupported()) return Collections.emptyList();
-        populateAllPackagesCacheIfNeeded();
-        return mAllPackagesCache
-                .stream()
-                .filter(item -> isActive(item))
-                .collect(Collectors.toList());
-    }
+    abstract List<PackageInfo> getActivePackages();
 
     /**
      * Retrieves information about all active pre-installed APEX packages.
@@ -230,14 +112,7 @@
      * @return a List of PackageInfo object, each one containing information about a different
      *         active pre-installed package.
      */
-    List<PackageInfo> getFactoryPackages() {
-        if (!isApexSupported()) return Collections.emptyList();
-        populateAllPackagesCacheIfNeeded();
-        return mAllPackagesCache
-                .stream()
-                .filter(item -> isFactory(item))
-                .collect(Collectors.toList());
-    }
+    abstract List<PackageInfo> getFactoryPackages();
 
     /**
      * Retrieves information about all inactive APEX packages.
@@ -245,14 +120,7 @@
      * @return a List of PackageInfo object, each one containing information about a different
      *         inactive package.
      */
-    List<PackageInfo> getInactivePackages() {
-        if (!isApexSupported()) return Collections.emptyList();
-        populateAllPackagesCacheIfNeeded();
-        return mAllPackagesCache
-                .stream()
-                .filter(item -> !isActive(item))
-                .collect(Collectors.toList());
-    }
+    abstract List<PackageInfo> getInactivePackages();
 
     /**
      * Checks if {@code packageName} is an apex package.
@@ -260,16 +128,7 @@
      * @param packageName package to check.
      * @return {@code true} if {@code packageName} is an apex package.
      */
-    boolean isApexPackage(String packageName) {
-        if (!isApexSupported()) return false;
-        populateAllPackagesCacheIfNeeded();
-        for (PackageInfo packageInfo : mAllPackagesCache) {
-            if (packageInfo.packageName.equals(packageName)) {
-                return true;
-            }
-        }
-        return false;
-    }
+    abstract boolean isApexPackage(String packageName);
 
     /**
      * Retrieves information about an apexd staged session i.e. the internal state used by apexd to
@@ -278,19 +137,8 @@
      * @param sessionId the identifier of the session.
      * @return an ApexSessionInfo object, or null if the session is not known.
      */
-    @Nullable ApexSessionInfo getStagedSessionInfo(int sessionId) {
-        if (!isApexSupported()) return null;
-        try {
-            ApexSessionInfo apexSessionInfo = mApexService.getStagedSessionInfo(sessionId);
-            if (apexSessionInfo.isUnknown) {
-                return null;
-            }
-            return apexSessionInfo;
-        } catch (RemoteException re) {
-            Slog.e(TAG, "Unable to contact apexservice", re);
-            throw new RuntimeException(re);
-        }
-    }
+    @Nullable
+    abstract ApexSessionInfo getStagedSessionInfo(int sessionId);
 
     /**
      * Submit a staged session to apex service. This causes the apex service to perform some initial
@@ -302,47 +150,19 @@
      * @param childSessionIds if {@code sessionId} is a multi-package session, this should contain
      *                        an array of identifiers of all the child sessions. Otherwise it should
      *                        be an empty array.
-     * @param apexInfoList this is an output parameter, which needs to be initialized by tha caller
-     *                     and will be filled with a list of {@link ApexInfo} objects, each of which
-     *                     contains metadata about one of the packages being submitted as part of
-     *                     the session.
-     * @return whether the submission of the session was successful.
+     * @throws PackageManagerException if call to apexd fails
      */
-    boolean submitStagedSession(
-            int sessionId, @NonNull int[] childSessionIds, @NonNull ApexInfoList apexInfoList) {
-        if (!isApexSupported()) return false;
-        try {
-            mApexService.submitStagedSession(sessionId, childSessionIds, apexInfoList);
-            return true;
-        } catch (RemoteException re) {
-            Slog.e(TAG, "Unable to contact apexservice", re);
-            throw new RuntimeException(re);
-        } catch (Exception e) {
-            Slog.e(TAG, "apexd verification failed", e);
-            return false;
-        }
-    }
+    abstract ApexInfoList submitStagedSession(int sessionId, @NonNull int[] childSessionIds)
+            throws PackageManagerException;
 
     /**
      * Mark a staged session previously submitted using {@code submitStagedSession} as ready to be
      * applied at next reboot.
      *
      * @param sessionId the identifier of the {@link PackageInstallerSession} being marked as ready.
-     * @return true upon success, false if the session is unknown.
+     * @throws PackageManagerException if call to apexd fails
      */
-    boolean markStagedSessionReady(int sessionId) {
-        if (!isApexSupported()) return false;
-        try {
-            mApexService.markStagedSessionReady(sessionId);
-            return true;
-        } catch (RemoteException re) {
-            Slog.e(TAG, "Unable to contact apexservice", re);
-            throw new RuntimeException(re);
-        } catch (Exception e) {
-            Slog.e(TAG, "Failed to mark session " + sessionId + " ready", e);
-            return false;
-        }
-    }
+    abstract void markStagedSessionReady(int sessionId) throws PackageManagerException;
 
     /**
      * Marks a staged session as successful.
@@ -352,44 +172,21 @@
      * @param sessionId the identifier of the {@link PackageInstallerSession} being marked as
      *                  successful.
      */
-    void markStagedSessionSuccessful(int sessionId) {
-        if (!isApexSupported()) return;
-        try {
-            mApexService.markStagedSessionSuccessful(sessionId);
-        } catch (RemoteException re) {
-            Slog.e(TAG, "Unable to contact apexservice", re);
-            throw new RuntimeException(re);
-        } catch (Exception e) {
-            // It is fine to just log an exception in this case. APEXd will be able to recover in
-            // case markStagedSessionSuccessful fails.
-            Slog.e(TAG, "Failed to mark session " + sessionId + " as successful", e);
-        }
-    }
+    abstract void markStagedSessionSuccessful(int sessionId);
 
     /**
      * Whether the current device supports the management of APEX packages.
      *
      * @return true if APEX packages can be managed on this device, false otherwise.
      */
-    boolean isApexSupported() {
-        return ApexProperties.updatable().orElse(false);
-    }
+    abstract boolean isApexSupported();
 
     /**
      * Abandons the (only) active session previously submitted.
      *
      * @return {@code true} upon success, {@code false} if any remote exception occurs
      */
-    boolean abortActiveSession() {
-        if (!isApexSupported()) return false;
-        try {
-            mApexService.abortActiveSession();
-            return true;
-        } catch (RemoteException re) {
-            Slog.e(TAG, "Unable to contact apexservice", re);
-            return false;
-        }
-    }
+    abstract boolean abortActiveSession();
 
     /**
      * Uninstalls given {@code apexPackage}.
@@ -399,64 +196,7 @@
      * @param apexPackagePath package to uninstall.
      * @return {@code true} upon successful uninstall, {@code false} otherwise.
      */
-    boolean uninstallApex(String apexPackagePath) {
-        if (!isApexSupported()) return false;
-        try {
-            mApexService.unstagePackages(Collections.singletonList(apexPackagePath));
-            return true;
-        } catch (Exception e) {
-            return false;
-        }
-    }
-
-    /**
-     * Whether an APEX package is active or not.
-     *
-     * @param packageInfo the package to check
-     * @return {@code true} if this package is active, {@code false} otherwise.
-     */
-    private static boolean isActive(PackageInfo packageInfo) {
-        return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) != 0;
-    }
-
-    /**
-     * Whether the APEX package is pre-installed or not.
-     *
-     * @param packageInfo the package to check
-     * @return {@code true} if this package is pre-installed, {@code false} otherwise.
-     */
-    private static boolean isFactory(PackageInfo packageInfo) {
-        return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-    }
-
-    /**
-     * Dump information about the packages contained in a particular cache
-     * @param packagesCache the cache to print information about.
-     * @param packageName a {@link String} containing a package name, or {@code null}. If set, only
-     *                    information about that specific package will be dumped.
-     * @param ipw the {@link IndentingPrintWriter} object to send information to.
-     */
-    void dumpFromPackagesCache(
-            List<PackageInfo> packagesCache,
-            @Nullable String packageName,
-            IndentingPrintWriter ipw) {
-        ipw.println();
-        ipw.increaseIndent();
-        for (PackageInfo pi : packagesCache) {
-            if (packageName != null && !packageName.equals(pi.packageName)) {
-                continue;
-            }
-            ipw.println(pi.packageName);
-            ipw.increaseIndent();
-            ipw.println("Version: " + pi.versionCode);
-            ipw.println("Path: " + pi.applicationInfo.sourceDir);
-            ipw.println("IsActive: " + isActive(pi));
-            ipw.println("IsFactory: " + isFactory(pi));
-            ipw.decreaseIndent();
-        }
-        ipw.decreaseIndent();
-        ipw.println();
-    }
+    abstract boolean uninstallApex(String apexPackagePath);
 
     /**
      * Dumps various state information to the provided {@link PrintWriter} object.
@@ -465,54 +205,422 @@
      * @param packageName a {@link String} containing a package name, or {@code null}. If set, only
      *                    information about that specific package will be dumped.
      */
-    void dump(PrintWriter pw, @Nullable String packageName) {
-        if (!isApexSupported()) return;
-        final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ", 120);
-        try {
-            populateAllPackagesCacheIfNeeded();
-            ipw.println();
-            ipw.println("Active APEX packages:");
-            dumpFromPackagesCache(getActivePackages(), packageName, ipw);
-            ipw.println("Inactive APEX packages:");
-            dumpFromPackagesCache(getInactivePackages(), packageName, ipw);
-            ipw.println("Factory APEX packages:");
-            dumpFromPackagesCache(getFactoryPackages(), packageName, ipw);
-            ipw.increaseIndent();
-            ipw.println("APEX session state:");
-            ipw.increaseIndent();
-            final ApexSessionInfo[] sessions = mApexService.getSessions();
-            for (ApexSessionInfo si : sessions) {
-                ipw.println("Session ID: " + si.sessionId);
-                ipw.increaseIndent();
-                if (si.isUnknown) {
-                    ipw.println("State: UNKNOWN");
-                } else if (si.isVerified) {
-                    ipw.println("State: VERIFIED");
-                } else if (si.isStaged) {
-                    ipw.println("State: STAGED");
-                } else if (si.isActivated) {
-                    ipw.println("State: ACTIVATED");
-                } else if (si.isActivationFailed) {
-                    ipw.println("State: ACTIVATION FAILED");
-                } else if (si.isSuccess) {
-                    ipw.println("State: SUCCESS");
-                } else if (si.isRollbackInProgress) {
-                    ipw.println("State: ROLLBACK IN PROGRESS");
-                } else if (si.isRolledBack) {
-                    ipw.println("State: ROLLED BACK");
-                } else if (si.isRollbackFailed) {
-                    ipw.println("State: ROLLBACK FAILED");
+    abstract void dump(PrintWriter pw, @Nullable String packageName);
+
+    @IntDef(
+            flag = true,
+            prefix = { "MATCH_"},
+            value = {MATCH_ACTIVE_PACKAGE, MATCH_FACTORY_PACKAGE})
+    @Retention(RetentionPolicy.SOURCE)
+    @interface PackageInfoFlags{}
+
+    /**
+     * An implementation of {@link ApexManager} that should be used in case device supports updating
+     * APEX packages.
+     */
+    @VisibleForTesting
+    static class ApexManagerImpl extends ApexManager {
+        private final IApexService mApexService;
+        private final Context mContext;
+        private final Object mLock = new Object();
+        /**
+         * A map from {@code APEX packageName} to the {@Link PackageInfo} generated from the {@code
+         * AndroidManifest.xml}
+         *
+         * <p>Note that key of this map is {@code packageName} field of the corresponding {@code
+         * AndroidManifest.xml}.
+          */
+        @GuardedBy("mLock")
+        private List<PackageInfo> mAllPackagesCache;
+
+        ApexManagerImpl(Context context, IApexService apexService) {
+            mContext = context;
+            mApexService = apexService;
+        }
+
+        /**
+         * Whether an APEX package is active or not.
+         *
+         * @param packageInfo the package to check
+         * @return {@code true} if this package is active, {@code false} otherwise.
+         */
+        private static boolean isActive(PackageInfo packageInfo) {
+            return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) != 0;
+        }
+
+        /**
+         * Whether the APEX package is pre-installed or not.
+         *
+         * @param packageInfo the package to check
+         * @return {@code true} if this package is pre-installed, {@code false} otherwise.
+         */
+        private static boolean isFactory(PackageInfo packageInfo) {
+            return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+        }
+
+        @Override
+        void systemReady() {
+            mContext.registerReceiver(new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    // Post populateAllPackagesCacheIfNeeded to a background thread, since it's
+                    // expensive to run it in broadcast handler thread.
+                    BackgroundThread.getHandler().post(() -> populateAllPackagesCacheIfNeeded());
+                    mContext.unregisterReceiver(this);
                 }
+            }, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
+        }
+
+        private void populateAllPackagesCacheIfNeeded() {
+            synchronized (mLock) {
+                if (mAllPackagesCache != null) {
+                    return;
+                }
+                try {
+                    mAllPackagesCache = new ArrayList<>();
+                    HashSet<String> activePackagesSet = new HashSet<>();
+                    HashSet<String> factoryPackagesSet = new HashSet<>();
+                    final ApexInfo[] allPkgs = mApexService.getAllPackages();
+                    for (ApexInfo ai : allPkgs) {
+                        // If the device is using flattened APEX, don't report any APEX
+                        // packages since they won't be managed or updated by PackageManager.
+                        if ((new File(ai.modulePath)).isDirectory()) {
+                            break;
+                        }
+                        int flags = PackageManager.GET_META_DATA
+                                | PackageManager.GET_SIGNING_CERTIFICATES
+                                | PackageManager.GET_SIGNATURES;
+                        PackageParser.Package pkg;
+                        try {
+                            File apexFile = new File(ai.modulePath);
+                            PackageParser pp = new PackageParser();
+                            pkg = pp.parsePackage(apexFile, flags, false);
+                            PackageParser.collectCertificates(pkg, false);
+                        } catch (PackageParser.PackageParserException pe) {
+                            throw new IllegalStateException("Unable to parse: " + ai, pe);
+                        }
+
+                        final PackageInfo packageInfo =
+                                PackageParser.generatePackageInfo(pkg, ai, flags);
+                        mAllPackagesCache.add(packageInfo);
+                        if (ai.isActive) {
+                            if (activePackagesSet.contains(packageInfo.packageName)) {
+                                throw new IllegalStateException(
+                                        "Two active packages have the same name: "
+                                                + packageInfo.packageName);
+                            }
+                            activePackagesSet.add(packageInfo.packageName);
+                        }
+                        if (ai.isFactory) {
+                            if (factoryPackagesSet.contains(packageInfo.packageName)) {
+                                throw new IllegalStateException(
+                                        "Two factory packages have the same name: "
+                                                + packageInfo.packageName);
+                            }
+                            factoryPackagesSet.add(packageInfo.packageName);
+                        }
+
+                    }
+                } catch (RemoteException re) {
+                    Slog.e(TAG, "Unable to retrieve packages from apexservice: " + re.toString());
+                    throw new RuntimeException(re);
+                }
+            }
+        }
+
+        @Override
+        @Nullable PackageInfo getPackageInfo(String packageName, @PackageInfoFlags int flags) {
+            populateAllPackagesCacheIfNeeded();
+            boolean matchActive = (flags & MATCH_ACTIVE_PACKAGE) != 0;
+            boolean matchFactory = (flags & MATCH_FACTORY_PACKAGE) != 0;
+            for (PackageInfo packageInfo: mAllPackagesCache) {
+                if (!packageInfo.packageName.equals(packageName)) {
+                    continue;
+                }
+                if ((matchActive && isActive(packageInfo))
+                        || (matchFactory && isFactory(packageInfo))) {
+                    return packageInfo;
+                }
+            }
+            return null;
+        }
+
+        @Override
+        List<PackageInfo> getActivePackages() {
+            populateAllPackagesCacheIfNeeded();
+            return mAllPackagesCache
+                    .stream()
+                    .filter(item -> isActive(item))
+                    .collect(Collectors.toList());
+        }
+
+        @Override
+        List<PackageInfo> getFactoryPackages() {
+            populateAllPackagesCacheIfNeeded();
+            return mAllPackagesCache
+                    .stream()
+                    .filter(item -> isFactory(item))
+                    .collect(Collectors.toList());
+        }
+
+        @Override
+        List<PackageInfo> getInactivePackages() {
+            populateAllPackagesCacheIfNeeded();
+            return mAllPackagesCache
+                    .stream()
+                    .filter(item -> !isActive(item))
+                    .collect(Collectors.toList());
+        }
+
+        @Override
+        boolean isApexPackage(String packageName) {
+            if (!isApexSupported()) return false;
+            populateAllPackagesCacheIfNeeded();
+            for (PackageInfo packageInfo : mAllPackagesCache) {
+                if (packageInfo.packageName.equals(packageName)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        @Override
+        @Nullable ApexSessionInfo getStagedSessionInfo(int sessionId) {
+            try {
+                ApexSessionInfo apexSessionInfo = mApexService.getStagedSessionInfo(sessionId);
+                if (apexSessionInfo.isUnknown) {
+                    return null;
+                }
+                return apexSessionInfo;
+            } catch (RemoteException re) {
+                Slog.e(TAG, "Unable to contact apexservice", re);
+                throw new RuntimeException(re);
+            }
+        }
+
+        @Override
+        ApexInfoList submitStagedSession(int sessionId, @NonNull int[] childSessionIds)
+                throws PackageManagerException {
+            try {
+                final ApexInfoList apexInfoList = new ApexInfoList();
+                mApexService.submitStagedSession(sessionId, childSessionIds, apexInfoList);
+                return apexInfoList;
+            } catch (RemoteException re) {
+                Slog.e(TAG, "Unable to contact apexservice", re);
+                throw new RuntimeException(re);
+            } catch (Exception e) {
+                throw new PackageManagerException(
+                        PackageInstaller.SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                        "apexd verification failed : " + e.getMessage());
+            }
+        }
+
+        @Override
+        void markStagedSessionReady(int sessionId) throws PackageManagerException {
+            try {
+                mApexService.markStagedSessionReady(sessionId);
+            } catch (RemoteException re) {
+                Slog.e(TAG, "Unable to contact apexservice", re);
+                throw new RuntimeException(re);
+            } catch (Exception e) {
+                throw new PackageManagerException(
+                        PackageInstaller.SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                        "Failed to mark apexd session as ready : " + e.getMessage());
+            }
+        }
+
+        @Override
+        void markStagedSessionSuccessful(int sessionId) {
+            try {
+                mApexService.markStagedSessionSuccessful(sessionId);
+            } catch (RemoteException re) {
+                Slog.e(TAG, "Unable to contact apexservice", re);
+                throw new RuntimeException(re);
+            } catch (Exception e) {
+                // It is fine to just log an exception in this case. APEXd will be able to recover
+                // in case markStagedSessionSuccessful fails.
+                Slog.e(TAG, "Failed to mark session " + sessionId + " as successful", e);
+            }
+        }
+
+        @Override
+        boolean isApexSupported() {
+            return true;
+        }
+
+        @Override
+        boolean abortActiveSession() {
+            try {
+                mApexService.abortActiveSession();
+                return true;
+            } catch (RemoteException re) {
+                Slog.e(TAG, "Unable to contact apexservice", re);
+                return false;
+            }
+        }
+
+        @Override
+        boolean uninstallApex(String apexPackagePath) {
+            try {
+                mApexService.unstagePackages(Collections.singletonList(apexPackagePath));
+                return true;
+            } catch (Exception e) {
+                return false;
+            }
+        }
+
+        /**
+         * Dump information about the packages contained in a particular cache
+         * @param packagesCache the cache to print information about.
+         * @param packageName a {@link String} containing a package name, or {@code null}. If set,
+         *                    only information about that specific package will be dumped.
+         * @param ipw the {@link IndentingPrintWriter} object to send information to.
+         */
+        void dumpFromPackagesCache(
+                List<PackageInfo> packagesCache,
+                @Nullable String packageName,
+                IndentingPrintWriter ipw) {
+            ipw.println();
+            ipw.increaseIndent();
+            for (PackageInfo pi : packagesCache) {
+                if (packageName != null && !packageName.equals(pi.packageName)) {
+                    continue;
+                }
+                ipw.println(pi.packageName);
+                ipw.increaseIndent();
+                ipw.println("Version: " + pi.versionCode);
+                ipw.println("Path: " + pi.applicationInfo.sourceDir);
+                ipw.println("IsActive: " + isActive(pi));
+                ipw.println("IsFactory: " + isFactory(pi));
                 ipw.decreaseIndent();
             }
             ipw.decreaseIndent();
-        } catch (RemoteException e) {
-            ipw.println("Couldn't communicate with apexd.");
+            ipw.println();
+        }
+
+        @Override
+        void dump(PrintWriter pw, @Nullable String packageName) {
+            final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ", 120);
+            try {
+                populateAllPackagesCacheIfNeeded();
+                ipw.println();
+                ipw.println("Active APEX packages:");
+                dumpFromPackagesCache(getActivePackages(), packageName, ipw);
+                ipw.println("Inactive APEX packages:");
+                dumpFromPackagesCache(getInactivePackages(), packageName, ipw);
+                ipw.println("Factory APEX packages:");
+                dumpFromPackagesCache(getFactoryPackages(), packageName, ipw);
+                ipw.increaseIndent();
+                ipw.println("APEX session state:");
+                ipw.increaseIndent();
+                final ApexSessionInfo[] sessions = mApexService.getSessions();
+                for (ApexSessionInfo si : sessions) {
+                    ipw.println("Session ID: " + si.sessionId);
+                    ipw.increaseIndent();
+                    if (si.isUnknown) {
+                        ipw.println("State: UNKNOWN");
+                    } else if (si.isVerified) {
+                        ipw.println("State: VERIFIED");
+                    } else if (si.isStaged) {
+                        ipw.println("State: STAGED");
+                    } else if (si.isActivated) {
+                        ipw.println("State: ACTIVATED");
+                    } else if (si.isActivationFailed) {
+                        ipw.println("State: ACTIVATION FAILED");
+                    } else if (si.isSuccess) {
+                        ipw.println("State: SUCCESS");
+                    } else if (si.isRollbackInProgress) {
+                        ipw.println("State: ROLLBACK IN PROGRESS");
+                    } else if (si.isRolledBack) {
+                        ipw.println("State: ROLLED BACK");
+                    } else if (si.isRollbackFailed) {
+                        ipw.println("State: ROLLBACK FAILED");
+                    }
+                    ipw.decreaseIndent();
+                }
+                ipw.decreaseIndent();
+            } catch (RemoteException e) {
+                ipw.println("Couldn't communicate with apexd.");
+            }
         }
     }
 
-    public void onBootCompleted() {
-        if (!isApexSupported()) return;
-        populateAllPackagesCacheIfNeeded();
+    /**
+     * An implementation of {@link ApexManager} that should be used in case device does not support
+     * updating APEX packages.
+     */
+    private static final class ApexManagerNoOp extends ApexManager {
+
+        @Override
+        void systemReady() {
+            // No-op
+        }
+
+        @Override
+        PackageInfo getPackageInfo(String packageName, int flags) {
+            return null;
+        }
+
+        @Override
+        List<PackageInfo> getActivePackages() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        List<PackageInfo> getFactoryPackages() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        List<PackageInfo> getInactivePackages() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        boolean isApexPackage(String packageName) {
+            return false;
+        }
+
+        @Override
+        ApexSessionInfo getStagedSessionInfo(int sessionId) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        ApexInfoList submitStagedSession(int sessionId, int[] childSessionIds)
+                throws PackageManagerException {
+            throw new PackageManagerException(PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
+                    "Device doesn't support updating APEX");
+        }
+
+        @Override
+        void markStagedSessionReady(int sessionId) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        void markStagedSessionSuccessful(int sessionId) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        boolean isApexSupported() {
+            return false;
+        }
+
+        @Override
+        boolean abortActiveSession() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        boolean uninstallApex(String apexPackagePath) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        void dump(PrintWriter pw, String packageName) {
+            // No-op
+        }
     }
 }
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 461743e..868b90a 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -2474,7 +2474,8 @@
 
         mProtectedPackages = new ProtectedPackages(mContext);
 
-        mApexManager = new ApexManager(context);
+        mApexManager = ApexManager.create(context);
+        // CHECKSTYLE:OFF IndentationCheck
         synchronized (mInstallLock) {
         // writer
         synchronized (mPackages) {
@@ -4262,7 +4263,7 @@
                 }
                 return generatePackageInfo(ps, flags, userId);
             }
-            if (!matchFactoryOnly && (flags & MATCH_APEX) != 0) {
+            if ((flags & MATCH_APEX) != 0) {
                 return mApexManager.getPackageInfo(packageName, ApexManager.MATCH_ACTIVE_PACKAGE);
             }
         }
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index 88d681f..2705455 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -30,6 +30,7 @@
 import android.content.pm.PackageInstaller;
 import android.content.pm.PackageInstaller.SessionInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageParser;
 import android.content.pm.PackageParser.PackageParserException;
 import android.content.pm.PackageParser.SigningDetails;
 import android.content.pm.PackageParser.SigningDetails.SignatureSchemeVersion;
@@ -43,6 +44,7 @@
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.util.IntArray;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.apk.ApkSignatureVerifier;
@@ -104,21 +106,22 @@
         return new ParceledListSlice<>(result);
     }
 
-    private boolean validateApexSignature(String apexPath, String apexModuleName) {
+    private void validateApexSignature(String apexPath, String packageName)
+            throws PackageManagerException {
         final SigningDetails signingDetails;
         try {
             signingDetails = ApkSignatureVerifier.verify(apexPath, SignatureSchemeVersion.JAR);
         } catch (PackageParserException e) {
-            Slog.e(TAG, "Unable to parse APEX package: " + apexPath, e);
-            return false;
+            throw new PackageManagerException(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                    "Failed to parse APEX package " + apexPath, e);
         }
 
-        final PackageInfo packageInfo = mApexManager.getPackageInfoForApexName(apexModuleName);
-
+        final PackageInfo packageInfo = mApexManager.getPackageInfo(packageName,
+                ApexManager.MATCH_ACTIVE_PACKAGE);
         if (packageInfo == null) {
-            // Don't allow installation of new APEX.
-            Slog.e(TAG, "Attempted to install a new apex " + apexModuleName + ". Rejecting");
-            return false;
+            // This should never happen, because submitSessionToApexService ensures that no new
+            // apexes were installed.
+            throw new IllegalStateException("Unknown apex package " + packageName);
         }
 
         final SigningDetails existingSigningDetails;
@@ -126,73 +129,99 @@
             existingSigningDetails = ApkSignatureVerifier.verify(
                 packageInfo.applicationInfo.sourceDir, SignatureSchemeVersion.JAR);
         } catch (PackageParserException e) {
-            Slog.e(TAG, "Unable to parse APEX package: "
-                    + packageInfo.applicationInfo.sourceDir, e);
-            return false;
+            throw new PackageManagerException(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                    "Failed to parse APEX package " + packageInfo.applicationInfo.sourceDir, e);
         }
 
         // Now that we have both sets of signatures, demand that they're an exact match.
         if (Signature.areExactMatch(existingSigningDetails.signatures, signingDetails.signatures)) {
-            return true;
+            return;
         }
 
-        return false;
+        throw new PackageManagerException(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                "APK-container signature verification failed for package "
+                        + packageName + ". Signature of file "
+                        + apexPath + " does not match the signature of "
+                        + " the package already installed.");
     }
 
-    private boolean submitSessionToApexService(@NonNull PackageInstallerSession session,
-                                               List<PackageInstallerSession> childSessions,
-                                               ApexInfoList apexInfoList) {
-        boolean submittedToApexd = mApexManager.submitStagedSession(
-                session.sessionId,
-                childSessions != null
-                        ? childSessions.stream().mapToInt(s -> s.sessionId).toArray() :
-                        new int[]{},
-                apexInfoList);
-        if (!submittedToApexd) {
-            session.setStagedSessionFailed(
-                    SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
-                    "APEX staging failed, check logcat messages from apexd for more details.");
-            return false;
-        }
-        for (ApexInfo newModule : apexInfoList.apexInfos) {
-            PackageInfo activePackage = mApexManager.getPackageInfoForApexName(
-                    newModule.moduleName);
-            if (activePackage == null) {
-                continue;
+    private List<PackageInfo> submitSessionToApexService(
+            @NonNull PackageInstallerSession session) throws PackageManagerException {
+        final IntArray childSessionsIds = new IntArray();
+        if (session.isMultiPackage()) {
+            for (int id : session.getChildSessionIds()) {
+                if (isApexSession(mStagedSessions.get(id))) {
+                    childSessionsIds.add(id);
+                }
             }
-            long activeVersion = activePackage.applicationInfo.longVersionCode;
-            if (session.params.requiredInstalledVersionCode
-                    != PackageManager.VERSION_CODE_HIGHEST) {
-                if (activeVersion != session.params.requiredInstalledVersionCode) {
-                    session.setStagedSessionFailed(
-                            SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
-                            "Installed version of APEX package " + activePackage.packageName
+        }
+        // submitStagedSession will throw a PackageManagerException if apexd verification fails,
+        // which will be propagated to populate stagedSessionErrorMessage of this session.
+        final ApexInfoList apexInfoList = mApexManager.submitStagedSession(session.sessionId,
+                childSessionsIds.toArray());
+        final List<PackageInfo> result = new ArrayList<>();
+        for (ApexInfo apexInfo : apexInfoList.apexInfos) {
+            final PackageInfo packageInfo;
+            int flags = PackageManager.GET_META_DATA;
+            PackageParser.Package pkg;
+            try {
+                File apexFile = new File(apexInfo.modulePath);
+                PackageParser pp = new PackageParser();
+                pkg = pp.parsePackage(apexFile, flags, false);
+            } catch (PackageParserException e) {
+                throw new PackageManagerException(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                        "Failed to parse APEX package " + apexInfo.modulePath, e);
+            }
+            packageInfo = PackageParser.generatePackageInfo(pkg, apexInfo, flags);
+            final PackageInfo activePackage = mApexManager.getPackageInfo(packageInfo.packageName,
+                    ApexManager.MATCH_ACTIVE_PACKAGE);
+            if (activePackage == null) {
+                Slog.w(TAG, "Attempting to install new APEX package " + packageInfo.packageName);
+                throw new PackageManagerException(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                        "It is forbidden to install new APEX packages.");
+            }
+            checkRequiredVersionCode(session, activePackage);
+            checkDowngrade(session, activePackage, packageInfo);
+            result.add(packageInfo);
+        }
+        return result;
+    }
+
+    private void checkRequiredVersionCode(final PackageInstallerSession session,
+            final PackageInfo activePackage) throws PackageManagerException {
+        if (session.params.requiredInstalledVersionCode == PackageManager.VERSION_CODE_HIGHEST) {
+            return;
+        }
+        final long activeVersion = activePackage.applicationInfo.longVersionCode;
+        if (activeVersion != session.params.requiredInstalledVersionCode) {
+            if (!mApexManager.abortActiveSession()) {
+                Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
+            }
+            throw new PackageManagerException(
+                    SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                    "Installed version of APEX package " + activePackage.packageName
                             + " does not match required. Active version: " + activeVersion
                             + " required: " + session.params.requiredInstalledVersionCode);
-
-                    if (!mApexManager.abortActiveSession()) {
-                        Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
-                    }
-                    return false;
-                }
-            }
-
-            boolean allowsDowngrade = PackageManagerServiceUtils.isDowngradePermitted(
-                    session.params.installFlags, activePackage.applicationInfo.flags);
-            if (activeVersion > newModule.versionCode && !allowsDowngrade) {
-                session.setStagedSessionFailed(
-                        SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
-                        "Downgrade of APEX package " + activePackage.packageName
-                                + " is not allowed. Active version: " + activeVersion
-                                + " attempted: " + newModule.versionCode);
-
-                if (!mApexManager.abortActiveSession()) {
-                    Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
-                }
-                return false;
-            }
         }
-        return true;
+    }
+
+    private void checkDowngrade(final PackageInstallerSession session,
+            final PackageInfo activePackage, final PackageInfo newPackage)
+            throws PackageManagerException {
+        final long activeVersion = activePackage.applicationInfo.longVersionCode;
+        final long newVersionCode = newPackage.applicationInfo.longVersionCode;
+        boolean allowsDowngrade = PackageManagerServiceUtils.isDowngradePermitted(
+                session.params.installFlags, activePackage.applicationInfo.flags);
+        if (activeVersion > newVersionCode && !allowsDowngrade) {
+            if (!mApexManager.abortActiveSession()) {
+                Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
+            }
+            throw new PackageManagerException(
+                    SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
+                    "Downgrade of APEX package " + newPackage.packageName
+                            + " is not allowed. Active version: " + activeVersion
+                            + " attempted: " + newVersionCode);
+        }
     }
 
     private static boolean isApexSession(@NonNull PackageInstallerSession session) {
@@ -200,31 +229,20 @@
     }
 
     private void preRebootVerification(@NonNull PackageInstallerSession session) {
-        boolean success = true;
-
-        final ApexInfoList apexInfoList = new ApexInfoList();
+        final boolean hasApex = sessionContainsApex(session);
         // APEX checks. For single-package sessions, check if they contain an APEX. For
         // multi-package sessions, find all the child sessions that contain an APEX.
-        if (!session.isMultiPackage()
-                && isApexSession(session)) {
-            success = submitSessionToApexService(session, null, apexInfoList);
-
-        } else if (session.isMultiPackage()) {
-            List<PackageInstallerSession> childSessions =
-                    Arrays.stream(session.getChildSessionIds())
-                            // Retrieve cached sessions matching ids.
-                            .mapToObj(i -> mStagedSessions.get(i))
-                            // Filter only the ones containing APEX.
-                            .filter(childSession -> isApexSession(childSession))
-                            .collect(Collectors.toList());
-            if (!childSessions.isEmpty()) {
-                success = submitSessionToApexService(session, childSessions, apexInfoList);
-            } // else this is a staged multi-package session with no APEX files.
-        }
-
-        if (!success) {
-            // submitSessionToApexService will populate error.
-            return;
+        if (hasApex) {
+            try {
+                final List<PackageInfo> apexPackages = submitSessionToApexService(session);
+                for (PackageInfo apexPackage : apexPackages) {
+                    validateApexSignature(apexPackage.applicationInfo.sourceDir,
+                            apexPackage.packageName);
+                }
+            } catch (PackageManagerException e) {
+                session.setStagedSessionFailed(e.error, e.getMessage());
+                return;
+            }
         }
 
         if (sessionContainsApk(session)) {
@@ -237,25 +255,6 @@
             }
         }
 
-        if (apexInfoList.apexInfos != null && apexInfoList.apexInfos.length > 0) {
-            // For APEXes, we validate the signature here before we mark the session as ready,
-            // so we fail the session early if there is a signature mismatch. For APKs, the
-            // signature verification will be done by the package manager at the point at which
-            // it applies the staged install.
-            for (ApexInfo apexModule : apexInfoList.apexInfos) {
-                if (!validateApexSignature(apexModule.modulePath,
-                        apexModule.moduleName)) {
-                    session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
-                            "APK-container signature verification failed for package "
-                                    + apexModule.moduleName + ". Signature of file "
-                                    + apexModule.modulePath + " does not match the signature of "
-                                    + " the package already installed.");
-                    // TODO(b/118865310): abort the session on apexd.
-                    return;
-                }
-            }
-        }
-
         if ((session.params.installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0) {
             // If rollback is enabled for this session, we call through to the RollbackManager
             // with the list of sessions it must enable rollback for. Note that notifyStagedSession
@@ -273,12 +272,24 @@
             }
         }
 
+        // Proactively mark session as ready before calling apexd. Although this call order looks
+        // counter-intuitive, this is the easiest way to ensure that session won't end up in the
+        // inconsistent state:
+        //  - If device gets rebooted right before call to apexd, then apexd will never activate
+        //      apex files of this staged session. This will result in StagingManager failing the
+        //      session.
+        // On the other hand, if the order of the calls was inverted (first call apexd, then mark
+        // session as ready), then if a device gets rebooted right after the call to apexd, only
+        // apex part of the train will be applied, leaving device in an inconsistent state.
         session.setStagedSessionReady();
-        if (sessionContainsApex(session)
-                && !mApexManager.markStagedSessionReady(session.sessionId)) {
-            session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
-                            "APEX staging failed, check logcat messages from apexd for more "
-                            + "details.");
+        if (!hasApex) {
+            // Session doesn't contain apex, nothing to do.
+            return;
+        }
+        try {
+            mApexManager.markStagedSessionReady(session.sessionId);
+        } catch (PackageManagerException e) {
+            session.setStagedSessionFailed(e.error, e.getMessage());
         }
     }
 
diff --git a/services/core/java/com/android/server/timezone/RulesManagerService.java b/services/core/java/com/android/server/timezone/RulesManagerService.java
index 28c171b..9347d21 100644
--- a/services/core/java/com/android/server/timezone/RulesManagerService.java
+++ b/services/core/java/com/android/server/timezone/RulesManagerService.java
@@ -32,6 +32,7 @@
 import android.app.timezone.RulesManager;
 import android.app.timezone.RulesState;
 import android.content.Context;
+import android.icu.util.TimeZone;
 import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
 import android.util.Slog;
@@ -45,7 +46,6 @@
 import com.android.timezone.distro.TimeZoneDistro;
 import com.android.timezone.distro.installer.TimeZoneDistroInstaller;
 
-import libcore.icu.ICU;
 import libcore.timezone.TimeZoneDataFiles;
 import libcore.timezone.TimeZoneFinder;
 import libcore.timezone.TzDataSetVersion;
@@ -519,7 +519,7 @@
                             // Report the active rules version (i.e. the rules in use by the current
                             // process).
                             pw.println("Active rules version (ICU, ZoneInfoDB, TimeZoneFinder): "
-                                    + ICU.getTZDataVersion() + ","
+                                    + TimeZone.getTZDataVersion() + ","
                                     + ZoneInfoDB.getInstance().getVersion() + ","
                                     + TimeZoneFinder.getInstance().getIanaVersion());
                             break;
@@ -535,7 +535,7 @@
 
         pw.println("RulesManagerService state: " + toString());
         pw.println("Active rules version (ICU, ZoneInfoDB, TimeZoneFinder): "
-                + ICU.getTZDataVersion() + ","
+                + TimeZone.getTZDataVersion() + ","
                 + ZoneInfoDB.getInstance().getVersion() + ","
                 + TimeZoneFinder.getInstance().getIanaVersion());
         pw.println("Distro state: " + rulesState.toString());
diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp
index 8ddb86b..3726228 100644
--- a/services/core/jni/com_android_server_VibratorService.cpp
+++ b/services/core/jni/com_android_server_VibratorService.cpp
@@ -67,7 +67,11 @@
     Return<bool> supportsAmplitudeControl() override {
         int32_t cap = 0;
         if (!mVib->getCapabilities(&cap).isOk()) return false;
-        return (cap & aidl::IVibrator::CAP_AMPLITUDE_CONTROL) > 0;
+        if (mUnderExternalControl) {
+           return (cap & aidl::IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL) > 0;
+        } else {
+           return (cap & aidl::IVibrator::CAP_AMPLITUDE_CONTROL) > 0;
+        }
     }
 
     Return<V1_0::Status> setAmplitude(uint8_t amplitude) override {
@@ -96,7 +100,11 @@
     }
 
     Return<V1_0::Status> setExternalControl(bool enabled) override {
-        return toHidlStatus(mVib->setExternalControl(enabled));
+        Return<V1_0::Status> status = toHidlStatus(mVib->setExternalControl(enabled));
+        if (status.isOk() && status == V1_0::Status::OK) {
+            mUnderExternalControl = enabled;
+        }
+        return status;
     }
 
     Return<void> perform_1_3(V1_3::Effect effect, V1_0::EffectStrength strength,
@@ -154,21 +162,30 @@
 
         sp<aidl::IVibratorCallback> cb = callback ? new CallbackShim(callback) : nullptr;
         int timeoutMs = 0;
-        V1_0::Status status = toHidlStatus(
+        Return<V1_0::Status> status = toHidlStatus(
             mVib->perform(static_cast<aidl::Effect>(effect),
                           static_cast<aidl::EffectStrength>(strength), cb, &timeoutMs));
-        _hidl_cb(status, timeoutMs);
-        return android::hardware::Status::ok();
+
+        if (status.isOk()) {
+            _hidl_cb(status, timeoutMs);
+            return android::hardware::Status::ok();
+        } else {
+            return android::hardware::details::StatusOf<V1_0::Status, void>(status);
+        }
     }
   private:
     sp<aidl::IVibrator> mVib;
+    bool mUnderExternalControl = false;
 
-    V1_0::Status toHidlStatus(const android::binder::Status& status) {
+    Return<V1_0::Status> toHidlStatus(const android::binder::Status& status) {
         switch(status.exceptionCode()) {
             using android::hardware::Status;
             case Status::EX_NONE: return V1_0::Status::OK;
             case Status::EX_ILLEGAL_ARGUMENT: return V1_0::Status::BAD_VALUE;
             case Status::EX_UNSUPPORTED_OPERATION: return V1_0::Status::UNSUPPORTED_OPERATION;
+            case Status::EX_TRANSACTION_FAILED: {
+                return Status::fromStatusT(status.transactionError());
+            }
         }
         return V1_0::Status::UNKNOWN_ERROR;
     }
@@ -247,8 +264,14 @@
             }
 
             ALOGE("Failed to issue command to vibrator HAL. Retrying.");
+
             // Restoring connection to the HAL.
-            mHal = I::tryGetService();
+            sp<aidl::IVibrator> aidlVib = checkVintfService<aidl::IVibrator>();
+            if (aidlVib) {
+                mHal = new VibratorShim(aidlVib);
+            } else {
+                mHal = I::tryGetService();
+            }
         }
         return ret;
     }
diff --git a/services/tests/servicestests/res/raw/apex_test.apex b/services/tests/servicestests/res/raw/apex_test.apex
new file mode 100644
index 0000000..19b1c5e
--- /dev/null
+++ b/services/tests/servicestests/res/raw/apex_test.apex
Binary files differ
diff --git a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java
new file mode 100644
index 0000000..6bb4202
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java
@@ -0,0 +1,298 @@
+/*
+ * 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.server.pm;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertThrows;
+
+import android.apex.ApexInfo;
+import android.apex.ApexSessionInfo;
+import android.apex.IApexService;
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.os.FileUtils;
+import android.os.RemoteException;
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.frameworks.servicestests.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+@SmallTest
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class ApexManagerTest {
+    private static final String TEST_APEX_PKG = "com.android.apex.test";
+    private static final int TEST_SESSION_ID = 99999999;
+    private static final int[] TEST_CHILD_SESSION_ID = {8888, 7777};
+    private ApexManager mApexManager;
+    private Context mContext;
+
+    private IApexService mApexService = mock(IApexService.class);
+
+    @Before
+    public void setUp() throws RemoteException {
+        mContext = InstrumentationRegistry.getInstrumentation().getContext();
+        mApexManager = new ApexManager.ApexManagerImpl(mContext, mApexService);
+    }
+
+    @Test
+    public void testGetPackageInfo_setFlagsMatchActivePackage() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(true, false));
+        final PackageInfo activePkgPi = mApexManager.getPackageInfo(TEST_APEX_PKG,
+                ApexManager.MATCH_ACTIVE_PACKAGE);
+
+        assertThat(activePkgPi).isNotNull();
+        assertThat(activePkgPi.packageName).contains(TEST_APEX_PKG);
+
+        final PackageInfo factoryPkgPi = mApexManager.getPackageInfo(TEST_APEX_PKG,
+                ApexManager.MATCH_FACTORY_PACKAGE);
+
+        assertThat(factoryPkgPi).isNull();
+    }
+
+    @Test
+    public void testGetPackageInfo_setFlagsMatchFactoryPackage() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(false, true));
+        PackageInfo factoryPkgPi = mApexManager.getPackageInfo(TEST_APEX_PKG,
+                ApexManager.MATCH_FACTORY_PACKAGE);
+
+        assertThat(factoryPkgPi).isNotNull();
+        assertThat(factoryPkgPi.packageName).contains(TEST_APEX_PKG);
+
+        final PackageInfo activePkgPi = mApexManager.getPackageInfo(TEST_APEX_PKG,
+                ApexManager.MATCH_ACTIVE_PACKAGE);
+
+        assertThat(activePkgPi).isNull();
+    }
+
+    @Test
+    public void testGetPackageInfo_setFlagsNone() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(false, true));
+
+        assertThat(mApexManager.getPackageInfo(TEST_APEX_PKG, 0)).isNull();
+    }
+
+    @Test
+    public void testGetActivePackages() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(true, true));
+
+        assertThat(mApexManager.getActivePackages()).isNotEmpty();
+    }
+
+    @Test
+    public void testGetActivePackages_noneActivePackages() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(false, true));
+
+        assertThat(mApexManager.getActivePackages()).isEmpty();
+    }
+
+    @Test
+    public void testGetFactoryPackages() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(false, true));
+
+        assertThat(mApexManager.getFactoryPackages()).isNotEmpty();
+    }
+
+    @Test
+    public void testGetFactoryPackages_noneFactoryPackages() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(true, false));
+
+        assertThat(mApexManager.getFactoryPackages()).isEmpty();
+    }
+
+    @Test
+    public void testGetInactivePackages() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(false, true));
+
+        assertThat(mApexManager.getInactivePackages()).isNotEmpty();
+    }
+
+    @Test
+    public void testGetInactivePackages_noneInactivePackages() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(true, false));
+
+        assertThat(mApexManager.getInactivePackages()).isEmpty();
+    }
+
+    @Test
+    public void testIsApexPackage() throws RemoteException {
+        when(mApexService.getAllPackages()).thenReturn(createApexInfo(false, true));
+
+        assertThat(mApexManager.isApexPackage(TEST_APEX_PKG)).isTrue();
+    }
+
+    @Test
+    public void testIsApexSupported() {
+        assertThat(mApexManager.isApexSupported()).isTrue();
+    }
+
+    @Test
+    public void testGetStagedSessionInfo() throws RemoteException {
+        when(mApexService.getStagedSessionInfo(anyInt())).thenReturn(
+                getFakeStagedSessionInfo());
+
+        mApexManager.getStagedSessionInfo(TEST_SESSION_ID);
+        verify(mApexService, times(1)).getStagedSessionInfo(TEST_SESSION_ID);
+    }
+
+    @Test
+    public void testGetStagedSessionInfo_unKnownStagedSessionId() throws RemoteException {
+        when(mApexService.getStagedSessionInfo(anyInt())).thenReturn(
+                getFakeUnknownSessionInfo());
+
+        assertThat(mApexManager.getStagedSessionInfo(TEST_SESSION_ID)).isNull();
+    }
+
+    @Test
+    public void testSubmitStagedSession_throwPackageManagerException() throws RemoteException {
+        doAnswer(invocation -> {
+            throw new Exception();
+        }).when(mApexService).submitStagedSession(anyInt(), any(), any());
+
+        assertThrows(PackageManagerException.class,
+                () -> mApexManager.submitStagedSession(TEST_SESSION_ID, TEST_CHILD_SESSION_ID));
+    }
+
+    @Test
+    public void testSubmitStagedSession_throwRunTimeException() throws RemoteException {
+        doThrow(RemoteException.class).when(mApexService).submitStagedSession(anyInt(), any(),
+                any());
+
+        assertThrows(RuntimeException.class,
+                () -> mApexManager.submitStagedSession(TEST_SESSION_ID, TEST_CHILD_SESSION_ID));
+    }
+
+    @Test
+    public void testMarkStagedSessionReady_throwPackageManagerException() throws RemoteException {
+        doAnswer(invocation -> {
+            throw new Exception();
+        }).when(mApexService).markStagedSessionReady(anyInt());
+
+        assertThrows(PackageManagerException.class,
+                () -> mApexManager.markStagedSessionReady(TEST_SESSION_ID));
+    }
+
+    @Test
+    public void testMarkStagedSessionReady_throwRunTimeException() throws RemoteException {
+        doThrow(RemoteException.class).when(mApexService).markStagedSessionReady(anyInt());
+
+        assertThrows(RuntimeException.class,
+                () -> mApexManager.markStagedSessionReady(TEST_SESSION_ID));
+    }
+
+    @Test
+    public void testAbortActiveSession_remoteException() throws RemoteException {
+        doThrow(RemoteException.class).when(mApexService).abortActiveSession();
+
+        try {
+            assertThat(mApexManager.abortActiveSession()).isFalse();
+        } catch (Exception e) {
+            throw new AssertionError("ApexManager should not raise Exception");
+        }
+    }
+
+    @Test
+    public void testMarkStagedSessionSuccessful_throwRemoteException() throws RemoteException {
+        doThrow(RemoteException.class).when(mApexService).markStagedSessionSuccessful(anyInt());
+
+        assertThrows(RuntimeException.class,
+                () -> mApexManager.markStagedSessionSuccessful(TEST_SESSION_ID));
+    }
+
+    @Test
+    public void testUninstallApex_throwException_returnFalse() throws RemoteException {
+        doAnswer(invocation -> {
+            throw new Exception();
+        }).when(mApexService).unstagePackages(any());
+
+        assertThat(mApexManager.uninstallApex(TEST_APEX_PKG)).isFalse();
+    }
+
+    private ApexInfo[] createApexInfo(boolean isActive, boolean isFactory) {
+        File apexFile = copyRawResourceToFile(TEST_APEX_PKG, R.raw.apex_test);
+        ApexInfo apexInfo = new ApexInfo();
+        apexInfo.isActive = isActive;
+        apexInfo.isFactory = isFactory;
+        apexInfo.moduleName = TEST_APEX_PKG;
+        apexInfo.modulePath = apexFile.getPath();
+        apexInfo.versionCode = 191000070;
+
+        return new ApexInfo[]{apexInfo};
+    }
+
+    private ApexSessionInfo getFakeStagedSessionInfo() {
+        ApexSessionInfo stagedSessionInfo = new ApexSessionInfo();
+        stagedSessionInfo.sessionId = TEST_SESSION_ID;
+        stagedSessionInfo.isStaged = true;
+
+        return stagedSessionInfo;
+    }
+
+    private ApexSessionInfo getFakeUnknownSessionInfo() {
+        ApexSessionInfo stagedSessionInfo = new ApexSessionInfo();
+        stagedSessionInfo.sessionId = TEST_SESSION_ID;
+        stagedSessionInfo.isUnknown = true;
+
+        return stagedSessionInfo;
+    }
+
+    /**
+     * Copies a specified {@code resourceId} to a temp file. Returns a non-null file if the copy
+     * succeeded
+     */
+    File copyRawResourceToFile(String baseName, int resourceId) {
+        File outFile;
+        try {
+            outFile = File.createTempFile(baseName, ".apex");
+        } catch (IOException e) {
+            throw new AssertionError("CreateTempFile IOException" + e);
+        }
+
+        try (InputStream is = mContext.getResources().openRawResource(resourceId);
+             FileOutputStream os = new FileOutputStream(outFile)) {
+            assertThat(FileUtils.copy(is, os)).isGreaterThan(0L);
+        } catch (FileNotFoundException e) {
+            throw new AssertionError("File not found exception " + e);
+        } catch (IOException e) {
+            throw new AssertionError("IOException" + e);
+        }
+
+        return outFile;
+    }
+}
diff --git a/startop/view_compiler/Android.bp b/startop/view_compiler/Android.bp
index c380d29..7cc233b 100644
--- a/startop/view_compiler/Android.bp
+++ b/startop/view_compiler/Android.bp
@@ -16,7 +16,6 @@
 
 cc_defaults {
     name: "viewcompiler_defaults",
-    defaults: ["libdexfile_static_defaults"],
     header_libs: [
         "libbase_headers",
     ],
@@ -30,6 +29,7 @@
         "liblog",
         "libutils",
         "libziparchive",
+        "libz",
     ],
     cppflags: ["-std=c++17"],
     target: {
diff --git a/startop/view_compiler/dex_builder.cc b/startop/view_compiler/dex_builder.cc
index 48b44d0..50cf5a5 100644
--- a/startop/view_compiler/dex_builder.cc
+++ b/startop/view_compiler/dex_builder.cc
@@ -16,8 +16,6 @@
 
 #include "dex_builder.h"
 
-#include "dex/descriptors_names.h"
-
 #include <fstream>
 #include <memory>
 
@@ -30,8 +28,6 @@
 using ::dex::kAccPublic;
 using Op = Instruction::Op;
 
-using Opcode = ::art::Instruction::Code;
-
 const TypeDescriptor TypeDescriptor::Int() { return TypeDescriptor{"I"}; };
 const TypeDescriptor TypeDescriptor::Void() { return TypeDescriptor{"V"}; };
 
@@ -43,22 +39,31 @@
 constexpr size_t kMaxEncodedStringLength{5};
 
 // Converts invoke-* to invoke-*/range
-constexpr Opcode InvokeToInvokeRange(Opcode opcode) {
+constexpr ::dex::Opcode InvokeToInvokeRange(::dex::Opcode opcode) {
   switch (opcode) {
-    case ::art::Instruction::INVOKE_VIRTUAL:
-      return ::art::Instruction::INVOKE_VIRTUAL_RANGE;
-    case ::art::Instruction::INVOKE_DIRECT:
-      return ::art::Instruction::INVOKE_DIRECT_RANGE;
-    case ::art::Instruction::INVOKE_STATIC:
-      return ::art::Instruction::INVOKE_STATIC_RANGE;
-    case ::art::Instruction::INVOKE_INTERFACE:
-      return ::art::Instruction::INVOKE_INTERFACE_RANGE;
+    case ::dex::Opcode::OP_INVOKE_VIRTUAL:
+      return ::dex::Opcode::OP_INVOKE_VIRTUAL_RANGE;
+    case ::dex::Opcode::OP_INVOKE_DIRECT:
+      return ::dex::Opcode::OP_INVOKE_DIRECT_RANGE;
+    case ::dex::Opcode::OP_INVOKE_STATIC:
+      return ::dex::Opcode::OP_INVOKE_STATIC_RANGE;
+    case ::dex::Opcode::OP_INVOKE_INTERFACE:
+      return ::dex::Opcode::OP_INVOKE_INTERFACE_RANGE;
     default:
       LOG(FATAL) << opcode << " is not a recognized invoke opcode.";
-      UNREACHABLE();
+      __builtin_unreachable();
   }
 }
 
+std::string DotToDescriptor(const char* class_name) {
+  std::string descriptor(class_name);
+  std::replace(descriptor.begin(), descriptor.end(), '.', '/');
+  if (descriptor.length() > 0 && descriptor[0] != '[') {
+    descriptor = "L" + descriptor + ";";
+  }
+  return descriptor;
+}
+
 }  // namespace
 
 std::ostream& operator<<(std::ostream& out, const Instruction::Op& opcode) {
@@ -178,7 +183,7 @@
 }
 
 TypeDescriptor TypeDescriptor::FromClassname(const std::string& name) {
-  return TypeDescriptor{art::DotToDescriptor(name.c_str())};
+  return TypeDescriptor{DotToDescriptor(name.c_str())};
 }
 
 DexBuilder::DexBuilder() : dex_file_{std::make_shared<ir::DexFile>()} {
@@ -219,11 +224,11 @@
 
 ClassBuilder DexBuilder::MakeClass(const std::string& name) {
   auto* class_def = Alloc<ir::Class>();
-  ir::Type* type_def = GetOrAddType(art::DotToDescriptor(name.c_str()));
+  ir::Type* type_def = GetOrAddType(DotToDescriptor(name.c_str()));
   type_def->class_def = class_def;
 
   class_def->type = type_def;
-  class_def->super_class = GetOrAddType(art::DotToDescriptor("java.lang.Object"));
+  class_def->super_class = GetOrAddType(DotToDescriptor("java.lang.Object"));
   class_def->access_flags = kAccPublic;
   return ClassBuilder{this, name, class_def};
 }
@@ -378,26 +383,26 @@
 void MethodBuilder::EncodeInstruction(const Instruction& instruction) {
   switch (instruction.opcode()) {
     case Instruction::Op::kReturn:
-      return EncodeReturn(instruction, ::art::Instruction::RETURN);
+      return EncodeReturn(instruction, ::dex::Opcode::OP_RETURN);
     case Instruction::Op::kReturnObject:
-      return EncodeReturn(instruction, ::art::Instruction::RETURN_OBJECT);
+      return EncodeReturn(instruction, ::dex::Opcode::OP_RETURN_OBJECT);
     case Instruction::Op::kMove:
     case Instruction::Op::kMoveObject:
       return EncodeMove(instruction);
     case Instruction::Op::kInvokeVirtual:
-      return EncodeInvoke(instruction, art::Instruction::INVOKE_VIRTUAL);
+      return EncodeInvoke(instruction, ::dex::Opcode::OP_INVOKE_VIRTUAL);
     case Instruction::Op::kInvokeDirect:
-      return EncodeInvoke(instruction, art::Instruction::INVOKE_DIRECT);
+      return EncodeInvoke(instruction, ::dex::Opcode::OP_INVOKE_DIRECT);
     case Instruction::Op::kInvokeStatic:
-      return EncodeInvoke(instruction, art::Instruction::INVOKE_STATIC);
+      return EncodeInvoke(instruction, ::dex::Opcode::OP_INVOKE_STATIC);
     case Instruction::Op::kInvokeInterface:
-      return EncodeInvoke(instruction, art::Instruction::INVOKE_INTERFACE);
+      return EncodeInvoke(instruction, ::dex::Opcode::OP_INVOKE_INTERFACE);
     case Instruction::Op::kBindLabel:
       return BindLabel(instruction.args()[0]);
     case Instruction::Op::kBranchEqz:
-      return EncodeBranch(art::Instruction::IF_EQZ, instruction);
+      return EncodeBranch(::dex::Opcode::OP_IF_EQZ, instruction);
     case Instruction::Op::kBranchNEqz:
-      return EncodeBranch(art::Instruction::IF_NEZ, instruction);
+      return EncodeBranch(::dex::Opcode::OP_IF_NEZ, instruction);
     case Instruction::Op::kNew:
       return EncodeNew(instruction);
     case Instruction::Op::kCheckCast:
@@ -410,10 +415,10 @@
   }
 }
 
-void MethodBuilder::EncodeReturn(const Instruction& instruction, ::art::Instruction::Code opcode) {
+void MethodBuilder::EncodeReturn(const Instruction& instruction, ::dex::Opcode opcode) {
   CHECK(!instruction.dest().has_value());
   if (instruction.args().size() == 0) {
-    Encode10x(art::Instruction::RETURN_VOID);
+    Encode10x(::dex::Opcode::OP_RETURN_VOID);
   } else {
     CHECK_EQ(1, instruction.args().size());
     size_t source = RegisterValue(instruction.args()[0]);
@@ -433,27 +438,27 @@
   if (source.is_immediate()) {
     // TODO: support more registers
     CHECK_LT(RegisterValue(*instruction.dest()), 16);
-    Encode11n(art::Instruction::CONST_4, RegisterValue(*instruction.dest()), source.value());
+    Encode11n(::dex::Opcode::OP_CONST_4, RegisterValue(*instruction.dest()), source.value());
   } else if (source.is_string()) {
     constexpr size_t kMaxRegisters = 256;
     CHECK_LT(RegisterValue(*instruction.dest()), kMaxRegisters);
     CHECK_LT(source.value(), 65536);  // make sure we don't need a jumbo string
-    Encode21c(::art::Instruction::CONST_STRING, RegisterValue(*instruction.dest()), source.value());
+    Encode21c(::dex::Opcode::OP_CONST_STRING, RegisterValue(*instruction.dest()), source.value());
   } else if (source.is_variable()) {
     // For the moment, we only use this when we need to reshuffle registers for
     // an invoke instruction, meaning we are too big for the 4-bit version.
     // We'll err on the side of caution and always generate the 16-bit form of
     // the instruction.
-    Opcode opcode = instruction.opcode() == Instruction::Op::kMove
-                        ? ::art::Instruction::MOVE_16
-                        : ::art::Instruction::MOVE_OBJECT_16;
+    auto opcode = instruction.opcode() == Instruction::Op::kMove
+                        ? ::dex::Opcode::OP_MOVE_16
+                        : ::dex::Opcode::OP_MOVE_OBJECT_16;
     Encode32x(opcode, RegisterValue(*instruction.dest()), RegisterValue(source));
   } else {
     UNIMPLEMENTED(FATAL);
   }
 }
 
-void MethodBuilder::EncodeInvoke(const Instruction& instruction, ::art::Instruction::Code opcode) {
+void MethodBuilder::EncodeInvoke(const Instruction& instruction, ::dex::Opcode opcode) {
   constexpr size_t kMaxArgs = 5;
 
   // Currently, we only support up to 5 arguments.
@@ -480,8 +485,8 @@
 
     for (size_t i = 0; i < instruction.args().size(); ++i) {
       Instruction::Op move_op;
-      if (opcode == ::art::Instruction::INVOKE_VIRTUAL ||
-          opcode == ::art::Instruction::INVOKE_DIRECT) {
+      if (opcode == ::dex::Opcode::OP_INVOKE_VIRTUAL ||
+          opcode == ::dex::Opcode::OP_INVOKE_DIRECT) {
         // In this case, there is an implicit `this` argument, which is always an object.
         if (i == 0) {
           move_op = Instruction::Op::kMoveObject;
@@ -514,8 +519,8 @@
 
   // If there is a return value, add a move-result instruction
   if (instruction.dest().has_value()) {
-    Encode11x(instruction.result_is_object() ? art::Instruction::MOVE_RESULT_OBJECT
-                                             : art::Instruction::MOVE_RESULT,
+    Encode11x(instruction.result_is_object() ? ::dex::Opcode::OP_MOVE_RESULT_OBJECT
+                                             : ::dex::Opcode::OP_MOVE_RESULT,
               RegisterValue(*instruction.dest()));
   }
 
@@ -523,7 +528,7 @@
 }
 
 // Encodes a conditional branch that tests a single argument.
-void MethodBuilder::EncodeBranch(art::Instruction::Code op, const Instruction& instruction) {
+void MethodBuilder::EncodeBranch(::dex::Opcode op, const Instruction& instruction) {
   const auto& args = instruction.args();
   const auto& test_value = args[0];
   const auto& branch_target = args[1];
@@ -546,7 +551,7 @@
   const Value& type = instruction.args()[0];
   CHECK_LT(RegisterValue(*instruction.dest()), 256);
   CHECK(type.is_type());
-  Encode21c(::art::Instruction::NEW_INSTANCE, RegisterValue(*instruction.dest()), type.value());
+  Encode21c(::dex::Opcode::OP_NEW_INSTANCE, RegisterValue(*instruction.dest()), type.value());
 }
 
 void MethodBuilder::EncodeCast(const Instruction& instruction) {
@@ -558,7 +563,7 @@
   const Value& type = instruction.args()[0];
   CHECK_LT(RegisterValue(*instruction.dest()), 256);
   CHECK(type.is_type());
-  Encode21c(::art::Instruction::CHECK_CAST, RegisterValue(*instruction.dest()), type.value());
+  Encode21c(::dex::Opcode::OP_CHECK_CAST, RegisterValue(*instruction.dest()), type.value());
 }
 
 void MethodBuilder::EncodeFieldOp(const Instruction& instruction) {
@@ -569,7 +574,7 @@
       CHECK(instruction.dest()->is_variable());
       CHECK_EQ(0, instruction.args().size());
 
-      Encode21c(::art::Instruction::SGET,
+      Encode21c(::dex::Opcode::OP_SGET,
                 RegisterValue(*instruction.dest()),
                 instruction.index_argument());
       break;
@@ -579,7 +584,7 @@
       CHECK_EQ(1, args.size());
       CHECK(args[0].is_variable());
 
-      Encode21c(::art::Instruction::SPUT, RegisterValue(args[0]), instruction.index_argument());
+      Encode21c(::dex::Opcode::OP_SPUT, RegisterValue(args[0]), instruction.index_argument());
       break;
     }
     case Instruction::Op::kGetInstanceField: {
@@ -587,7 +592,7 @@
       CHECK(instruction.dest()->is_variable());
       CHECK_EQ(1, instruction.args().size());
 
-      Encode22c(::art::Instruction::IGET,
+      Encode22c(::dex::Opcode::OP_IGET,
                 RegisterValue(*instruction.dest()),
                 RegisterValue(args[0]),
                 instruction.index_argument());
@@ -599,7 +604,7 @@
       CHECK(args[0].is_variable());
       CHECK(args[1].is_variable());
 
-      Encode22c(::art::Instruction::IPUT,
+      Encode22c(::dex::Opcode::OP_IPUT,
                 RegisterValue(args[1]),
                 RegisterValue(args[0]),
                 instruction.index_argument());
diff --git a/startop/view_compiler/dex_builder.h b/startop/view_compiler/dex_builder.h
index 3924e77..eb2dc88 100644
--- a/startop/view_compiler/dex_builder.h
+++ b/startop/view_compiler/dex_builder.h
@@ -24,7 +24,9 @@
 #include <unordered_map>
 #include <vector>
 
-#include "dex/dex_instruction.h"
+#include "android-base/logging.h"
+
+#include "slicer/dex_bytecode.h"
 #include "slicer/dex_ir.h"
 #include "slicer/writer.h"
 
@@ -364,11 +366,11 @@
   // Encodes a return instruction. For instructions with no return value, the opcode field is
   // ignored. Otherwise, this specifies which return instruction will be used (return,
   // return-object, etc.)
-  void EncodeReturn(const Instruction& instruction, ::art::Instruction::Code opcode);
+  void EncodeReturn(const Instruction& instruction, ::dex::Opcode opcode);
 
   void EncodeMove(const Instruction& instruction);
-  void EncodeInvoke(const Instruction& instruction, ::art::Instruction::Code opcode);
-  void EncodeBranch(art::Instruction::Code op, const Instruction& instruction);
+  void EncodeInvoke(const Instruction& instruction, ::dex::Opcode opcode);
+  void EncodeBranch(::dex::Opcode op, const Instruction& instruction);
   void EncodeNew(const Instruction& instruction);
   void EncodeCast(const Instruction& instruction);
   void EncodeFieldOp(const Instruction& instruction);
@@ -377,17 +379,23 @@
   // https://source.android.com/devices/tech/dalvik/instruction-formats for documentation of
   // formats.
 
-  inline void Encode10x(art::Instruction::Code opcode) {
+  inline uint8_t ToBits(::dex::Opcode opcode) {
+    static_assert(sizeof(uint8_t) == sizeof(::dex::Opcode));
+    return static_cast<uint8_t>(opcode);
+  }
+
+  inline void Encode10x(::dex::Opcode opcode) {
     // 00|op
-    buffer_.push_back(opcode);
+    static_assert(sizeof(uint8_t) == sizeof(::dex::Opcode));
+    buffer_.push_back(ToBits(opcode));
   }
 
-  inline void Encode11x(art::Instruction::Code opcode, uint8_t a) {
+  inline void Encode11x(::dex::Opcode opcode, uint8_t a) {
     // aa|op
-    buffer_.push_back((a << 8) | opcode);
+    buffer_.push_back((a << 8) | ToBits(opcode));
   }
 
-  inline void Encode11n(art::Instruction::Code opcode, uint8_t a, int8_t b) {
+  inline void Encode11n(::dex::Opcode opcode, uint8_t a, int8_t b) {
     // b|a|op
 
     // Make sure the fields are in bounds (4 bits for a, 4 bits for b).
@@ -395,30 +403,30 @@
     CHECK_LE(-8, b);
     CHECK_LT(b, 8);
 
-    buffer_.push_back(((b & 0xf) << 12) | (a << 8) | opcode);
+    buffer_.push_back(((b & 0xf) << 12) | (a << 8) | ToBits(opcode));
   }
 
-  inline void Encode21c(art::Instruction::Code opcode, uint8_t a, uint16_t b) {
+  inline void Encode21c(::dex::Opcode opcode, uint8_t a, uint16_t b) {
     // aa|op|bbbb
-    buffer_.push_back((a << 8) | opcode);
+    buffer_.push_back((a << 8) | ToBits(opcode));
     buffer_.push_back(b);
   }
 
-  inline void Encode22c(art::Instruction::Code opcode, uint8_t a, uint8_t b, uint16_t c) {
+  inline void Encode22c(::dex::Opcode opcode, uint8_t a, uint8_t b, uint16_t c) {
     // b|a|op|bbbb
     CHECK(IsShortRegister(a));
     CHECK(IsShortRegister(b));
-    buffer_.push_back((b << 12) | (a << 8) | opcode);
+    buffer_.push_back((b << 12) | (a << 8) | ToBits(opcode));
     buffer_.push_back(c);
   }
 
-  inline void Encode32x(art::Instruction::Code opcode, uint16_t a, uint16_t b) {
-    buffer_.push_back(opcode);
+  inline void Encode32x(::dex::Opcode opcode, uint16_t a, uint16_t b) {
+    buffer_.push_back(ToBits(opcode));
     buffer_.push_back(a);
     buffer_.push_back(b);
   }
 
-  inline void Encode35c(art::Instruction::Code opcode, size_t a, uint16_t b, uint8_t c, uint8_t d,
+  inline void Encode35c(::dex::Opcode opcode, size_t a, uint16_t b, uint8_t c, uint8_t d,
                         uint8_t e, uint8_t f, uint8_t g) {
     // a|g|op|bbbb|f|e|d|c
 
@@ -428,14 +436,14 @@
     CHECK(IsShortRegister(e));
     CHECK(IsShortRegister(f));
     CHECK(IsShortRegister(g));
-    buffer_.push_back((a << 12) | (g << 8) | opcode);
+    buffer_.push_back((a << 12) | (g << 8) | ToBits(opcode));
     buffer_.push_back(b);
     buffer_.push_back((f << 12) | (e << 8) | (d << 4) | c);
   }
 
-  inline void Encode3rc(art::Instruction::Code opcode, size_t a, uint16_t b, uint16_t c) {
+  inline void Encode3rc(::dex::Opcode opcode, size_t a, uint16_t b, uint16_t c) {
     CHECK_LE(a, 255);
-    buffer_.push_back((a << 8) | opcode);
+    buffer_.push_back((a << 8) | ToBits(opcode));
     buffer_.push_back(b);
     buffer_.push_back(c);
   }
diff --git a/telephony/java/android/telephony/CallerInfo.java b/telecomm/java/android/telecom/CallerInfo.java
similarity index 91%
rename from telephony/java/android/telephony/CallerInfo.java
rename to telecomm/java/android/telecom/CallerInfo.java
index f87ac50..a5d25e2 100644
--- a/telephony/java/android/telephony/CallerInfo.java
+++ b/telecomm/java/android/telecom/CallerInfo.java
@@ -14,10 +14,9 @@
  * limitations under the License.
  */
 
-package android.telephony;
+package android.telecom;
 
 import android.annotation.Nullable;
-import android.annotation.SystemApi;
 import android.annotation.UnsupportedAppUsage;
 import android.content.ComponentName;
 import android.content.ContentResolver;
@@ -33,8 +32,10 @@
 import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.PhoneLookup;
 import android.provider.ContactsContract.RawContacts;
+import android.telephony.PhoneNumberUtils;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 import android.text.TextUtils;
-import android.util.Log;
 
 import com.android.i18n.phonenumbers.NumberParseException;
 import com.android.i18n.phonenumbers.PhoneNumberUtil;
@@ -50,10 +51,9 @@
  *
  * {@hide}
  */
-@SystemApi
 public class CallerInfo {
     private static final String TAG = "CallerInfo";
-    private static final boolean VDBG = Rlog.isLoggable(TAG, Log.VERBOSE);
+    private static final boolean VDBG = Log.VERBOSE;
 
     /** @hide */
     public static final long USER_TYPE_CURRENT = 0;
@@ -215,7 +215,7 @@
         info.contactExists = false;
         info.userType = USER_TYPE_CURRENT;
 
-        if (VDBG) Rlog.v(TAG, "getCallerInfo() based on cursor...");
+        if (VDBG) Log.v(TAG, "getCallerInfo() based on cursor...");
 
         if (cursor != null) {
             if (cursor.moveToFirst()) {
@@ -263,7 +263,7 @@
                     if (contactId != 0 && !Contacts.isEnterpriseContactId(contactId)) {
                         info.contactIdOrZero = contactId;
                         if (VDBG) {
-                            Rlog.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero);
+                            Log.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero);
                         }
                     }
                     if (Contacts.isEnterpriseContactId(contactId)) {
@@ -271,7 +271,7 @@
                     }
                 } else {
                     // No valid columnIndex, so we can't look up person_id.
-                    Rlog.w(TAG, "Couldn't find contact_id column for " + contactRef);
+                    Log.w(TAG, "Couldn't find contact_id column for " + contactRef);
                     // Watch out: this means that anything that depends on
                     // person_id will be broken (like contact photo lookups in
                     // the in-call UI, for example.)
@@ -356,7 +356,7 @@
                 info = getCallerInfo(context, contactRef,
                         cr.query(contactRef, null, null, null, null));
             } catch (RuntimeException re) {
-                Rlog.e(TAG, "Error getting caller info.", re);
+                Log.e(TAG, re, "Error getting caller info.");
             }
         }
         return info;
@@ -376,7 +376,7 @@
      */
     @UnsupportedAppUsage
     public static CallerInfo getCallerInfo(Context context, String number) {
-        if (VDBG) Rlog.v(TAG, "getCallerInfo() based on number...");
+        if (VDBG) Log.v(TAG, "getCallerInfo() based on number...");
 
         int subId = SubscriptionManager.getDefaultSubscriptionId();
         return getCallerInfo(context, number, subId);
@@ -407,8 +407,8 @@
         // shortcut and skip the query.
         if (PhoneNumberUtils.isLocalEmergencyNumber(context, number)) {
             return new CallerInfo().markAsEmergency(context);
-        } else if (PhoneNumberUtils.isVoiceMailNumber(subId, number)) {
-            return new CallerInfo().markAsVoiceMail();
+        } else if (PhoneNumberUtils.isVoiceMailNumber(null, subId, number)) {
+            return new CallerInfo().markAsVoiceMail(context, subId);
         }
 
         Uri contactUri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
@@ -542,36 +542,20 @@
     }
 
 
-    /**
-     * Mark this CallerInfo as a voicemail call. The voicemail label
-     * is obtained from the telephony manager. Caller must hold the
-     * READ_PHONE_STATE permission otherwise the phoneNumber will be
-     * set to null.
-     * @return this instance.
-     */
-    // TODO: As in the emergency number handling, we end up writing a
-    // string in the phone number field.
-    /* package */ CallerInfo markAsVoiceMail() {
-
-        int subId = SubscriptionManager.getDefaultSubscriptionId();
-        return markAsVoiceMail(subId);
-
-    }
-
-    /* package */ CallerInfo markAsVoiceMail(int subId) {
+    /* package */ CallerInfo markAsVoiceMail(Context context, int subId) {
         mIsVoiceMail = true;
 
         try {
-            String voiceMailLabel = TelephonyManager.getDefault().getVoiceMailAlphaTag(subId);
-
-            phoneNumber = voiceMailLabel;
+            phoneNumber = context.getSystemService(TelephonyManager.class)
+                    .createForSubscriptionId(subId)
+                    .getVoiceMailAlphaTag();
         } catch (SecurityException se) {
             // Should never happen: if this process does not have
             // permission to retrieve VM tag, it should not have
             // permission to retrieve VM number and would not call
             // this method.
             // Leave phoneNumber untouched.
-            Rlog.e(TAG, "Cannot access VoiceMail.", se);
+            Log.e(TAG, se, "Cannot access VoiceMail.");
         }
         // TODO: There is no voicemail picture?
         // FIXME: FIND ANOTHER ICON
@@ -630,10 +614,10 @@
         // So instead, figure out the column to use for person_id by just
         // looking at the URI itself.
 
-        if (VDBG) Rlog.v(TAG, "- getColumnIndexForPersonId: contactRef URI = '"
+        if (VDBG) Log.v(TAG, "- getColumnIndexForPersonId: contactRef URI = '"
                         + contactRef + "'...");
         // Warning: Do not enable the following logging (due to ANR risk.)
-        // if (VDBG) Rlog.v(TAG, "- MIME type: "
+        // if (VDBG) Log.v(TAG, "- MIME type: "
         //                 + context.getContentResolver().getType(contactRef));
 
         String url = contactRef.toString();
@@ -641,25 +625,25 @@
         if (url.startsWith("content://com.android.contacts/data/phones")) {
             // Direct lookup in the Phone table.
             // MIME type: Phone.CONTENT_ITEM_TYPE (= "vnd.android.cursor.item/phone_v2")
-            if (VDBG) Rlog.v(TAG, "'data/phones' URI; using RawContacts.CONTACT_ID");
+            if (VDBG) Log.v(TAG, "'data/phones' URI; using RawContacts.CONTACT_ID");
             columnName = RawContacts.CONTACT_ID;
         } else if (url.startsWith("content://com.android.contacts/data")) {
             // Direct lookup in the Data table.
             // MIME type: Data.CONTENT_TYPE (= "vnd.android.cursor.dir/data")
-            if (VDBG) Rlog.v(TAG, "'data' URI; using Data.CONTACT_ID");
+            if (VDBG) Log.v(TAG, "'data' URI; using Data.CONTACT_ID");
             // (Note Data.CONTACT_ID and RawContacts.CONTACT_ID are equivalent.)
             columnName = Data.CONTACT_ID;
         } else if (url.startsWith("content://com.android.contacts/phone_lookup")) {
             // Lookup in the PhoneLookup table, which provides "fuzzy matching"
             // for phone numbers.
             // MIME type: PhoneLookup.CONTENT_TYPE (= "vnd.android.cursor.dir/phone_lookup")
-            if (VDBG) Rlog.v(TAG, "'phone_lookup' URI; using PhoneLookup._ID");
+            if (VDBG) Log.v(TAG, "'phone_lookup' URI; using PhoneLookup._ID");
             columnName = PhoneLookup._ID;
         } else {
-            Rlog.w(TAG, "Unexpected prefix for contactRef '" + url + "'");
+            Log.w(TAG, "Unexpected prefix for contactRef '" + url + "'");
         }
         int columnIndex = (columnName != null) ? cursor.getColumnIndex(columnName) : -1;
-        if (VDBG) Rlog.v(TAG, "==> Using column '" + columnName
+        if (VDBG) Log.v(TAG, "==> Using column '" + columnName
                         + "' (columnIndex = " + columnIndex + ") for person_id lookup...");
         return columnIndex;
     }
@@ -689,7 +673,7 @@
      * @hide
      */
     public static String getGeoDescription(Context context, String number) {
-        if (VDBG) Rlog.v(TAG, "getGeoDescription('" + number + "')...");
+        if (VDBG) Log.v(TAG, "getGeoDescription('" + number + "')...");
 
         if (TextUtils.isEmpty(number)) {
             return null;
@@ -702,18 +686,18 @@
         String countryIso = getCurrentCountryIso(context, locale);
         PhoneNumber pn = null;
         try {
-            if (VDBG) Rlog.v(TAG, "parsing '" + number
+            if (VDBG) Log.v(TAG, "parsing '" + number
                             + "' for countryIso '" + countryIso + "'...");
             pn = util.parse(number, countryIso);
-            if (VDBG) Rlog.v(TAG, "- parsed number: " + pn);
+            if (VDBG) Log.v(TAG, "- parsed number: " + pn);
         } catch (NumberParseException e) {
-            Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '"
-                    + Rlog.pii(TAG, number) + "'");
+            Log.w(TAG, "getGeoDescription: NumberParseException for incoming number '"
+                    + Log.pii(number) + "'");
         }
 
         if (pn != null) {
             String description = geocoder.getDescriptionForNumber(pn, locale);
-            if (VDBG) Rlog.v(TAG, "- got description: '" + description + "'");
+            if (VDBG) Log.v(TAG, "- got description: '" + description + "'");
             return description;
         } else {
             return null;
@@ -733,12 +717,12 @@
             if (country != null) {
                 countryIso = country.getCountryIso();
             } else {
-                Rlog.e(TAG, "CountryDetector.detectCountry() returned null.");
+                Log.e(TAG, new Exception(), "CountryDetector.detectCountry() returned null.");
             }
         }
         if (countryIso == null) {
             countryIso = locale.getCountry();
-            Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
+            Log.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
                     + countryIso);
         }
         return countryIso;
diff --git a/telephony/java/android/telephony/CallerInfoAsyncQuery.java b/telecomm/java/android/telecom/CallerInfoAsyncQuery.java
similarity index 91%
rename from telephony/java/android/telephony/CallerInfoAsyncQuery.java
rename to telecomm/java/android/telecom/CallerInfoAsyncQuery.java
index 87a6376..f38b34e 100644
--- a/telephony/java/android/telephony/CallerInfoAsyncQuery.java
+++ b/telecomm/java/android/telecom/CallerInfoAsyncQuery.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.telephony;
+package android.telecom;
 
 import android.app.ActivityManager;
 import android.content.AsyncQueryHandler;
@@ -31,6 +31,8 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.provider.ContactsContract.PhoneLookup;
+import android.telephony.PhoneNumberUtils;
+import android.telephony.SubscriptionManager;
 import android.text.TextUtils;
 import java.util.ArrayList;
 import java.util.List;
@@ -100,12 +102,12 @@
      */
     static ContentResolver getCurrentProfileContentResolver(Context context) {
 
-        if (DBG) Rlog.d(LOG_TAG, "Trying to get current content resolver...");
+        if (DBG) Log.d(LOG_TAG, "Trying to get current content resolver...");
 
         final int currentUser = ActivityManager.getCurrentUser();
         final int myUser = UserManager.get(context).getUserHandle();
 
-        if (DBG) Rlog.d(LOG_TAG, "myUser=" + myUser + "currentUser=" + currentUser);
+        if (DBG) Log.d(LOG_TAG, "myUser=" + myUser + "currentUser=" + currentUser);
 
         if (myUser != currentUser) {
             final Context otherContext;
@@ -114,7 +116,7 @@
                         /* flags =*/ 0, UserHandle.of(currentUser));
                 return otherContext.getContentResolver();
             } catch (NameNotFoundException e) {
-                Rlog.e(LOG_TAG, "Can't find self package", e);
+                Log.e(LOG_TAG, e, "Can't find self package");
                 // Fall back to the primary user.
             }
         }
@@ -179,13 +181,13 @@
                     // However, if there is any code that this Handler calls (such as in
                     // super.handleMessage) that DOES place unexpected messages on the
                     // queue, then we need pass these messages on.
-                    Rlog.i(LOG_TAG, "Unexpected command (CookieWrapper is null): " + msg.what +
+                    Log.i(LOG_TAG, "Unexpected command (CookieWrapper is null): " + msg.what +
                             " ignored by CallerInfoWorkerHandler, passing onto parent.");
 
                     super.handleMessage(msg);
                 } else {
 
-                    Rlog.d(LOG_TAG, "Processing event: " + cw.event + " token (arg1): " + msg.arg1 +
+                    Log.d(LOG_TAG, "Processing event: " + cw.event + " token (arg1): " + msg.arg1 +
                         " command: " + msg.what + " query URI: " + sanitizeUriToString(args.uri));
 
                     switch (cw.event) {
@@ -226,7 +228,7 @@
                     cw.geoDescription = CallerInfo.getGeoDescription(mContext, cw.number);
                     final long duration = SystemClock.elapsedRealtime() - startTimeMillis;
                     if (duration > 500) {
-                        if (DBG) Rlog.d(LOG_TAG, "[handleGeoDescription]" +
+                        if (DBG) Log.d(LOG_TAG, "[handleGeoDescription]" +
                                 "Spends long time to retrieve Geo description: " + duration);
                     }
                 }
@@ -263,7 +265,7 @@
          */
         @Override
         protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
-            Rlog.d(LOG_TAG, "##### onQueryComplete() #####   query complete for token: " + token);
+            Log.d(LOG_TAG, "##### onQueryComplete() #####   query complete for token: " + token);
 
             //get the cookie and notify the listener.
             CookieWrapper cw = (CookieWrapper) cookie;
@@ -272,7 +274,7 @@
                 // from within this code.
                 // However, if there is any code that calls this method, we should
                 // check the parameters to make sure they're viable.
-                Rlog.i(LOG_TAG, "Cookie is null, ignoring onQueryComplete() request.");
+                Log.i(LOG_TAG, "Cookie is null, ignoring onQueryComplete() request.");
                 if (cursor != null) {
                     cursor.close();
                 }
@@ -321,16 +323,16 @@
                     // comments at the top of CallerInfo class).
                     mCallerInfo = new CallerInfo().markAsEmergency(mContext);
                 } else if (cw.event == EVENT_VOICEMAIL_NUMBER) {
-                    mCallerInfo = new CallerInfo().markAsVoiceMail(cw.subId);
+                    mCallerInfo = new CallerInfo().markAsVoiceMail(mContext, cw.subId);
                 } else {
                     mCallerInfo = CallerInfo.getCallerInfo(mContext, mQueryUri, cursor);
-                    if (DBG) Rlog.d(LOG_TAG, "==> Got mCallerInfo: " + mCallerInfo);
+                    if (DBG) Log.d(LOG_TAG, "==> Got mCallerInfo: " + mCallerInfo);
 
                     CallerInfo newCallerInfo = CallerInfo.doSecondaryLookupIfNecessary(
                             mContext, cw.number, mCallerInfo);
                     if (newCallerInfo != mCallerInfo) {
                         mCallerInfo = newCallerInfo;
-                        if (DBG) Rlog.d(LOG_TAG, "#####async contact look up with numeric username"
+                        if (DBG) Log.d(LOG_TAG, "#####async contact look up with numeric username"
                                 + mCallerInfo);
                     }
 
@@ -346,7 +348,7 @@
                     // the geo description, so it would be unnecessary to query it.
                     if (ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION) {
                         if (TextUtils.isEmpty(mCallerInfo.getName())) {
-                            if (DBG) Rlog.d(LOG_TAG, "start querying geo description");
+                            if (DBG) Log.d(LOG_TAG, "start querying geo description");
                             cw.event = EVENT_GET_GEO_DESCRIPTION;
                             startQuery(token, cw, null, null, null, null, null);
                             return;
@@ -354,7 +356,7 @@
                     }
                 }
 
-                if (DBG) Rlog.d(LOG_TAG, "constructing CallerInfo object for token: " + token);
+                if (DBG) Log.d(LOG_TAG, "constructing CallerInfo object for token: " + token);
 
                 //notify that we can clean up the queue after this.
                 CookieWrapper endMarker = new CookieWrapper();
@@ -367,14 +369,14 @@
                 mPendingListenerCallbacks.add(new Runnable() {
                     @Override
                     public void run() {
-                        if (DBG) Rlog.d(LOG_TAG, "notifying listener: "
+                        if (DBG) Log.d(LOG_TAG, "notifying listener: "
                                 + cw.listener.getClass().toString() + " for token: " + token
                                 + mCallerInfo);
                         cw.listener.onQueryComplete(token, cw.cookie, mCallerInfo);
                     }
                 });
             } else {
-                Rlog.w(LOG_TAG, "There is no listener to notify for this query.");
+                Log.w(LOG_TAG, "There is no listener to notify for this query.");
             }
 
             if (cursor != null) {
@@ -399,7 +401,7 @@
         CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
         c.allocate(context, contactRef);
 
-        if (DBG) Rlog.d(LOG_TAG, "starting query for URI: " + contactRef + " handler: " + c.toString());
+        if (DBG) Log.d(LOG_TAG, "starting query for URI: " + contactRef + " handler: " + c.toString());
 
         //create cookieWrapper, start query
         CookieWrapper cw = new CookieWrapper();
@@ -445,9 +447,9 @@
             OnQueryCompleteListener listener, Object cookie, int subId) {
 
         if (DBG) {
-            Rlog.d(LOG_TAG, "##### CallerInfoAsyncQuery startQuery()... #####");
-            Rlog.d(LOG_TAG, "- number: " + /*number*/ "xxxxxxx");
-            Rlog.d(LOG_TAG, "- cookie: " + cookie);
+            Log.d(LOG_TAG, "##### CallerInfoAsyncQuery startQuery()... #####");
+            Log.d(LOG_TAG, "- number: " + /*number*/ "xxxxxxx");
+            Log.d(LOG_TAG, "- cookie: " + cookie);
         }
 
         // Construct the URI object and query params, and start the query.
@@ -459,7 +461,7 @@
                 .build();
 
         if (DBG) {
-            Rlog.d(LOG_TAG, "==> contactRef: " + sanitizeUriToString(contactRef));
+            Log.d(LOG_TAG, "==> contactRef: " + sanitizeUriToString(contactRef));
         }
 
         CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
@@ -496,8 +498,8 @@
      */
     public void addQueryListener(int token, OnQueryCompleteListener listener, Object cookie) {
 
-        if (DBG) Rlog.d(LOG_TAG, "adding listener to query: " + sanitizeUriToString(mHandler.mQueryUri) +
-                " handler: " + mHandler.toString());
+        if (DBG) Log.d(LOG_TAG, "adding listener to query: "
+                + sanitizeUriToString(mHandler.mQueryUri) + " handler: " + mHandler.toString());
 
         //create cookieWrapper, add query request to end of queue.
         CookieWrapper cw = new CookieWrapper();
diff --git a/telephony/common/com/google/android/mms/pdu/PduPersister.java b/telephony/common/com/google/android/mms/pdu/PduPersister.java
index 93f3065..95ae409 100755
--- a/telephony/common/com/google/android/mms/pdu/PduPersister.java
+++ b/telephony/common/com/google/android/mms/pdu/PduPersister.java
@@ -1548,6 +1548,7 @@
     public void release() {
         Uri uri = Uri.parse(TEMPORARY_DRM_OBJECT_URI);
         SqliteWrapper.delete(mContext, mContentResolver, uri, null, null);
+        mDrmManagerClient.release();
     }
 
     /**
diff --git a/telephony/java/android/telephony/CellBroadcastService.java b/telephony/java/android/telephony/CellBroadcastService.java
index cb342c6..f841df2 100644
--- a/telephony/java/android/telephony/CellBroadcastService.java
+++ b/telephony/java/android/telephony/CellBroadcastService.java
@@ -22,9 +22,14 @@
 import android.annotation.SystemApi;
 import android.app.Service;
 import android.content.Intent;
+import android.os.Bundle;
 import android.os.IBinder;
+import android.os.RemoteCallback;
 import android.telephony.cdma.CdmaSmsCbProgramData;
 
+import java.util.List;
+import java.util.function.Consumer;
+
 /**
  * A service which exposes the cell broadcast handling module to the system.
  * <p>
@@ -48,6 +53,7 @@
  *   </service>
  * </manifest>
  * }</pre>
+ *
  * @hide
  */
 @SystemApi
@@ -64,21 +70,38 @@
 
     /**
      * Handle a GSM cell broadcast SMS message forwarded from the system.
+     *
      * @param slotIndex the index of the slot which received the message
-     * @param message the SMS PDU
+     * @param message   the SMS PDU
      */
     public abstract void onGsmCellBroadcastSms(int slotIndex, @NonNull byte[] message);
 
     /**
      * Handle a CDMA cell broadcast SMS message forwarded from the system.
-     * @param slotIndex the index of the slot which received the message
-     * @param bearerData the CDMA SMS bearer data
+     *
+     * @param slotIndex       the index of the slot which received the message
+     * @param bearerData      the CDMA SMS bearer data
      * @param serviceCategory the CDMA SCPT service category
      */
     public abstract void onCdmaCellBroadcastSms(int slotIndex, @NonNull byte[] bearerData,
             @CdmaSmsCbProgramData.Category int serviceCategory);
 
     /**
+     * Handle a CDMA cell broadcast SMS message forwarded from the system.
+     *
+     * @param slotIndex          the index of the slot which received the message
+     * @param smsCbProgramData   the SMS CB program data of the message
+     * @param originatingAddress the originating address of the message, as a non-separated dial
+     *                           string
+     * @param callback           a callback to run after each cell broadcast receiver has handled
+     *                           the SCP message. The bundle will contain a non-separated
+     *                           dial string as and an ArrayList of {@link CdmaSmsCbProgramResults}.
+     */
+    public abstract void onCdmaScpMessage(int slotIndex,
+            @NonNull List<CdmaSmsCbProgramData> smsCbProgramData,
+            @NonNull String originatingAddress, @NonNull Consumer<Bundle> callback);
+
+    /**
      * If overriding this method, call through to the super method for any unknown actions.
      * {@inheritDoc}
      */
@@ -92,13 +115,15 @@
     /**
      * A wrapper around ICellBroadcastService that forwards calls to implementations of
      * {@link CellBroadcastService}.
+     *
      * @hide
      */
     public class ICellBroadcastServiceWrapper extends ICellBroadcastService.Stub {
         /**
          * Handle a GSM cell broadcast SMS.
+         *
          * @param slotIndex the index of the slot which received the broadcast
-         * @param message the SMS message PDU
+         * @param message   the SMS message PDU
          */
         @Override
         public void handleGsmCellBroadcastSms(int slotIndex, byte[] message) {
@@ -107,8 +132,9 @@
 
         /**
          * Handle a CDMA cell broadcast SMS.
-         * @param slotIndex the index of the slot which received the broadcast
-         * @param bearerData the CDMA SMS bearer data
+         *
+         * @param slotIndex       the index of the slot which received the broadcast
+         * @param bearerData      the CDMA SMS bearer data
          * @param serviceCategory the CDMA SCPT service category
          */
         @Override
@@ -117,5 +143,25 @@
             CellBroadcastService.this.onCdmaCellBroadcastSms(slotIndex, bearerData,
                     serviceCategory);
         }
+
+        /**
+         * Handle a CDMA Service Category Program message.
+         *
+         * @param slotIndex          the index of the slot which received the message
+         * @param smsCbProgramData   the SMS CB program data of the message
+         * @param originatingAddress the originating address of the message
+         * @param callback           a callback to run after each cell broadcast receiver has
+         *                           handled the SCP message
+         */
+        @Override
+        public void handleCdmaScpMessage(int slotIndex,
+                List<CdmaSmsCbProgramData> smsCbProgramData, String originatingAddress,
+                RemoteCallback callback) {
+            Consumer<Bundle> consumer = bundle -> {
+                callback.sendResult(bundle);
+            };
+            CellBroadcastService.this.onCdmaScpMessage(slotIndex, smsCbProgramData,
+                    originatingAddress, consumer);
+        }
     }
 }
diff --git a/telephony/java/android/telephony/DisconnectCause.java b/telephony/java/android/telephony/DisconnectCause.java
index aa7e21a..85110c2 100644
--- a/telephony/java/android/telephony/DisconnectCause.java
+++ b/telephony/java/android/telephony/DisconnectCause.java
@@ -16,6 +16,7 @@
 
 package android.telephony;
 
+import android.annotation.NonNull;
 import android.annotation.SystemApi;
 import android.annotation.UnsupportedAppUsage;
 
@@ -369,7 +370,7 @@
      * @hide
      */
     @UnsupportedAppUsage
-    public static String toString(int cause) {
+    public static @NonNull String toString(int cause) {
         switch (cause) {
         case NOT_DISCONNECTED:
             return "NOT_DISCONNECTED";
diff --git a/telephony/java/android/telephony/ICellBroadcastService.aidl b/telephony/java/android/telephony/ICellBroadcastService.aidl
index bcd6cc5..11263d9 100644
--- a/telephony/java/android/telephony/ICellBroadcastService.aidl
+++ b/telephony/java/android/telephony/ICellBroadcastService.aidl
@@ -16,6 +16,9 @@
 
 package android.telephony;
 
+import android.os.RemoteCallback;
+import android.telephony.cdma.CdmaSmsCbProgramData;
+
 /**
  * Service bound to by the system to allow custom handling of cell broadcast messages.
  * <p>
@@ -29,4 +32,8 @@
 
     /** @see android.telephony.CellBroadcastService#onCdmaCellBroadcastSms */
     oneway void handleCdmaCellBroadcastSms(int slotId, in byte[] bearerData, int serviceCategory);
+
+    /** @see android.telephony.CellBroadcastService#onCdmaScpMessage */
+    oneway void handleCdmaScpMessage(int slotId, in List<CdmaSmsCbProgramData> programData,
+            String originatingAddress, in RemoteCallback callback);
 }
diff --git a/telephony/java/android/telephony/ImsManager.java b/telephony/java/android/telephony/ImsManager.java
new file mode 100644
index 0000000..02d8be3
--- /dev/null
+++ b/telephony/java/android/telephony/ImsManager.java
@@ -0,0 +1,66 @@
+/*
+ * 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 android.telephony.ims;
+
+import android.annotation.SystemService;
+import android.content.Context;
+import android.telephony.SubscriptionManager;
+
+/**
+ * Provides access to information about Telephony IMS services on the device.
+ *
+ * @hide
+ */
+@SystemService(Context.TELEPHONY_IMS_SERVICE)
+public class ImsManager {
+
+    private Context mContext;
+
+    public ImsManager(Context context) {
+        mContext = context;
+    }
+
+    /**
+     * Create an instance of ImsRcsManager for the subscription id specified.
+     *
+     * @param subscriptionId The ID of the subscription that this ImsRcsManager will use.
+     * @throws IllegalArgumentException if the subscription is invalid.
+     * @return a ImsRcsManager instance with the specific subscription ID.
+     */
+    public ImsRcsManager getImsRcsManager(int subscriptionId) {
+        if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)) {
+            throw new IllegalArgumentException("Invalid subscription ID: " + subscriptionId);
+        }
+
+        return new ImsRcsManager(mContext, subscriptionId);
+    }
+
+    /**
+     * Create an instance of ImsMmTelManager for the subscription id specified.
+     *
+     * @param subscriptionId The ID of the subscription that this ImsMmTelManager will use.
+     * @throws IllegalArgumentException if the subscription is invalid.
+     * @return a ImsMmTelManager instance with the specific subscription ID.
+     */
+    public ImsMmTelManager getImsMmTelManager(int subscriptionId) {
+        if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)) {
+            throw new IllegalArgumentException("Invalid subscription ID: " + subscriptionId);
+        }
+
+        return new ImsMmTelManager(subscriptionId);
+    }
+}
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java
index af3ba5e..4a1bc1f 100644
--- a/telephony/java/android/telephony/PhoneNumberUtils.java
+++ b/telephony/java/android/telephony/PhoneNumberUtils.java
@@ -16,12 +16,12 @@
 
 package android.telephony;
 
-import com.android.i18n.phonenumbers.NumberParseException;
-import com.android.i18n.phonenumbers.PhoneNumberUtil;
-import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
-import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
+import static com.android.internal.telephony.TelephonyProperties.PROPERTY_OPERATOR_IDP_STRING;
 
 import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.SystemApi;
 import android.annotation.TestApi;
 import android.annotation.UnsupportedAppUsage;
 import android.content.Context;
@@ -42,7 +42,10 @@
 import android.text.style.TtsSpan;
 import android.util.SparseIntArray;
 
-import static com.android.internal.telephony.TelephonyProperties.PROPERTY_OPERATOR_IDP_STRING;
+import com.android.i18n.phonenumbers.NumberParseException;
+import com.android.i18n.phonenumbers.PhoneNumberUtil;
+import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
+import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -2247,8 +2250,10 @@
      * to read the VM number.
      * @hide
      */
-    @UnsupportedAppUsage
-    public static boolean isVoiceMailNumber(Context context, int subId, String number) {
+    @SystemApi
+    @TestApi
+    public static boolean isVoiceMailNumber(@NonNull Context context, int subId,
+            @Nullable String number) {
         String vmNumber, mdn;
         try {
             final TelephonyManager tm;
@@ -2734,8 +2739,9 @@
      * @param number
      * @return true if number contains @
      */
-    @UnsupportedAppUsage
-    public static boolean isUriNumber(String number) {
+    @SystemApi
+    @TestApi
+    public static boolean isUriNumber(@Nullable String number) {
         // Note we allow either "@" or "%40" to indicate a URI, in case
         // the passed-in string is URI-escaped.  (Neither "@" nor "%40"
         // will ever be found in a legal PSTN number.)
@@ -2752,8 +2758,9 @@
      *
      * @hide
      */
-    @UnsupportedAppUsage
-    public static String getUsernameFromUriNumber(String number) {
+    @SystemApi
+    @TestApi
+    public static @NonNull String getUsernameFromUriNumber(@NonNull String number) {
         // The delimiter between username and domain name can be
         // either "@" or "%40" (the URI-escaped equivalent.)
         int delimiterIndex = number.indexOf('@');
diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java
index 3157e12..54e87af 100644
--- a/telephony/java/android/telephony/SmsManager.java
+++ b/telephony/java/android/telephony/SmsManager.java
@@ -28,7 +28,6 @@
 import android.app.ActivityThread;
 import android.app.PendingIntent;
 import android.content.Context;
-import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.database.CursorWindow;
 import android.net.Uri;
@@ -37,7 +36,6 @@
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.ServiceManager;
-import android.provider.Telephony;
 import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Log;
@@ -289,12 +287,6 @@
      */
     public static final int SMS_MESSAGE_PERIOD_NOT_SPECIFIED = -1;
 
-    /**
-     * Extra key passed into a PendingIntent when the SMS operation failed due to there being no
-     * default set.
-     */
-    private static final String NO_DEFAULT_EXTRA = "noDefault";
-
     // result of asking the user for a subscription to perform an operation.
     private interface SubscriptionResolverResult {
         void onSuccess(int subId);
@@ -335,9 +327,59 @@
      *  <code>RESULT_ERROR_RADIO_OFF</code><br>
      *  <code>RESULT_ERROR_NULL_PDU</code><br>
      *  <code>RESULT_ERROR_NO_SERVICE</code><br>
-     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
-     *  the extra "errorCode" containing a radio technology specific value,
-     *  generally only useful for troubleshooting.<br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_LIMIT_EXCEEDED</code><br>
+     *  <code>RESULT_ERROR_FDN_CHECK_FAILURE</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NOT_ALLOWED</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED</code><br>
+     *  <code>RESULT_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_NETWORK_REJECT</code><br>
+     *  <code>RESULT_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_INVALID_STATE</code><br>
+     *  <code>RESULT_NO_MEMORY</code><br>
+     *  <code>RESULT_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_SYSTEM_ERROR</code><br>
+     *  <code>RESULT_MODEM_ERROR</code><br>
+     *  <code>RESULT_NETWORK_ERROR</code><br>
+     *  <code>RESULT_ENCODING_ERROR</code><br>
+     *  <code>RESULT_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_INTERNAL_ERROR</code><br>
+     *  <code>RESULT_NO_RESOURCES</code><br>
+     *  <code>RESULT_CANCELLED</code><br>
+     *  <code>RESULT_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_NO_BLUETOOTH_SERVICE</code><br>
+     *  <code>RESULT_INVALID_BLUETOOTH_ADDRESS</code><br>
+     *  <code>RESULT_BLUETOOTH_DISCONNECTED</code><br>
+     *  <code>RESULT_UNEXPECTED_EVENT_STOP_SENDING</code><br>
+     *  <code>RESULT_SMS_BLOCKED_DURING_EMERGENCY</code><br>
+     *  <code>RESULT_SMS_SEND_RETRY_FAILED</code><br>
+     *  <code>RESULT_REMOTE_EXCEPTION</code><br>
+     *  <code>RESULT_NO_DEFAULT_SMS_APP</code><br>
+     *  <code>RESULT_RIL_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_RIL_SMS_SEND_FAIL_RETRY</code><br>
+     *  <code>RESULT_RIL_NETWORK_REJECT</code><br>
+     *  <code>RESULT_RIL_INVALID_STATE</code><br>
+     *  <code>RESULT_RIL_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_RIL_NO_MEMORY</code><br>
+     *  <code>RESULT_RIL_REQUEST_RATE_LIMITED</code><br>
+     *  <code>RESULT_RIL_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_RIL_SYSTEM_ERR</code><br>
+     *  <code>RESULT_RIL_ENCODING_ERR</code><br>
+     *  <code>RESULT_RIL_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_RIL_MODEM_ERR</code><br>
+     *  <code>RESULT_RIL_NETWORK_ERR</code><br>
+     *  <code>RESULT_RIL_INTERNAL_ERR</code><br>
+     *  <code>RESULT_RIL_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_RIL_INVALID_MODEM_STATE</code><br>
+     *  <code>RESULT_RIL_NETWORK_NOT_READY</code><br>
+     *  <code>RESULT_RIL_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_RIL_NO_RESOURCES</code><br>
+     *  <code>RESULT_RIL_CANCELLED</code><br>
+     *  <code>RESULT_RIL_SIM_ABSENT</code><br>
+     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> or any of the RESULT_RIL errors,
+     *  the sentIntent may include the extra "errorCode" containing a radio technology specific
+     *  value, generally only useful for troubleshooting.<br>
      *  The per-application based SMS control checks sentIntent. If sentIntent
      *  is NULL the caller will be checked against all unknown applications,
      *  which cause smaller number of SMS to be sent in checking period.
@@ -377,9 +419,60 @@
      *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
      *  <code>RESULT_ERROR_RADIO_OFF</code><br>
      *  <code>RESULT_ERROR_NULL_PDU</code><br>
-     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
-     *  the extra "errorCode" containing a radio technology specific value,
-     *  generally only useful for troubleshooting.<br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_LIMIT_EXCEEDED</code><br>
+     *  <code>RESULT_ERROR_FDN_CHECK_FAILURE</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NOT_ALLOWED</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED</code><br>
+     *  <code>RESULT_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_NETWORK_REJECT</code><br>
+     *  <code>RESULT_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_INVALID_STATE</code><br>
+     *  <code>RESULT_NO_MEMORY</code><br>
+     *  <code>RESULT_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_SYSTEM_ERROR</code><br>
+     *  <code>RESULT_MODEM_ERROR</code><br>
+     *  <code>RESULT_NETWORK_ERROR</code><br>
+     *  <code>RESULT_ENCODING_ERROR</code><br>
+     *  <code>RESULT_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_INTERNAL_ERROR</code><br>
+     *  <code>RESULT_NO_RESOURCES</code><br>
+     *  <code>RESULT_CANCELLED</code><br>
+     *  <code>RESULT_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_NO_BLUETOOTH_SERVICE</code><br>
+     *  <code>RESULT_INVALID_BLUETOOTH_ADDRESS</code><br>
+     *  <code>RESULT_BLUETOOTH_DISCONNECTED</code><br>
+     *  <code>RESULT_UNEXPECTED_EVENT_STOP_SENDING</code><br>
+     *  <code>RESULT_SMS_BLOCKED_DURING_EMERGENCY</code><br>
+     *  <code>RESULT_SMS_SEND_RETRY_FAILED</code><br>
+     *  <code>RESULT_REMOTE_EXCEPTION</code><br>
+     *  <code>RESULT_NO_DEFAULT_SMS_APP</code><br>
+     *  <code>RESULT_RIL_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_RIL_SMS_SEND_FAIL_RETRY</code><br>
+     *  <code>RESULT_RIL_NETWORK_REJECT</code><br>
+     *  <code>RESULT_RIL_INVALID_STATE</code><br>
+     *  <code>RESULT_RIL_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_RIL_NO_MEMORY</code><br>
+     *  <code>RESULT_RIL_REQUEST_RATE_LIMITED</code><br>
+     *  <code>RESULT_RIL_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_RIL_SYSTEM_ERR</code><br>
+     *  <code>RESULT_RIL_ENCODING_ERR</code><br>
+     *  <code>RESULT_RIL_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_RIL_MODEM_ERR</code><br>
+     *  <code>RESULT_RIL_NETWORK_ERR</code><br>
+     *  <code>RESULT_RIL_INTERNAL_ERR</code><br>
+     *  <code>RESULT_RIL_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_RIL_INVALID_MODEM_STATE</code><br>
+     *  <code>RESULT_RIL_NETWORK_NOT_READY</code><br>
+     *  <code>RESULT_RIL_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_RIL_NO_RESOURCES</code><br>
+     *  <code>RESULT_RIL_CANCELLED</code><br>
+     *  <code>RESULT_RIL_SIM_ABSENT</code><br>
+     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> or any of the RESULT_RIL errors,
+     *  the sentIntent may include the extra "errorCode" containing a radio technology specific
+     *  value, generally only useful for troubleshooting.<br>
      *  The per-application based SMS control checks sentIntent. If sentIntent
      *  is NULL the caller will be checked against all unknown applications,
      *  which cause smaller number of SMS to be sent in checking period.
@@ -450,13 +543,13 @@
                     } catch (RemoteException e) {
                         Log.e(TAG, "sendTextMessageInternal: Couldn't send SMS, exception - "
                                 + e.getMessage());
-                        notifySmsGenericError(sentIntent);
+                        notifySmsError(sentIntent, RESULT_REMOTE_EXCEPTION);
                     }
                 }
 
                 @Override
                 public void onFailure() {
-                    notifySmsErrorNoDefaultSet(context, sentIntent);
+                    notifySmsError(sentIntent, RESULT_NO_DEFAULT_SMS_APP);
                 }
             });
         } else {
@@ -470,7 +563,7 @@
             } catch (RemoteException e) {
                 Log.e(TAG, "sendTextMessageInternal (no persist): Couldn't send SMS, exception - "
                         + e.getMessage());
-                notifySmsGenericError(sentIntent);
+                notifySmsError(sentIntent, RESULT_REMOTE_EXCEPTION);
             }
         }
     }
@@ -563,13 +656,13 @@
                     } catch (RemoteException e) {
                         Log.e(TAG, "sendTextMessageInternal: Couldn't send SMS, exception - "
                                 + e.getMessage());
-                        notifySmsGenericError(sentIntent);
+                        notifySmsError(sentIntent, RESULT_REMOTE_EXCEPTION);
                     }
                 }
 
                 @Override
                 public void onFailure() {
-                    notifySmsErrorNoDefaultSet(context, sentIntent);
+                    notifySmsError(sentIntent, RESULT_NO_DEFAULT_SMS_APP);
                 }
             });
         } else {
@@ -585,7 +678,7 @@
             } catch (RemoteException e) {
                 Log.e(TAG, "sendTextMessageInternal(no persist): Couldn't send SMS, exception - "
                         + e.getMessage());
-                notifySmsGenericError(sentIntent);
+                notifySmsError(sentIntent, RESULT_REMOTE_EXCEPTION);
             }
         }
     }
@@ -667,7 +760,7 @@
         } catch (RemoteException ex) {
             try {
                 if (receivedIntent != null) {
-                    receivedIntent.send(Telephony.Sms.Intents.RESULT_SMS_GENERIC_ERROR);
+                    receivedIntent.send(RESULT_REMOTE_EXCEPTION);
                 }
             } catch (PendingIntent.CanceledException cx) {
                 // Don't worry about it, we do not need to notify the caller if this is the case.
@@ -723,12 +816,63 @@
      *   broadcast when the corresponding message part has been sent.
      *   The result code will be <code>Activity.RESULT_OK</code> for success,
      *   or one of these errors:<br>
-     *   <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
-     *   <code>RESULT_ERROR_RADIO_OFF</code><br>
-     *   <code>RESULT_ERROR_NULL_PDU</code><br>
-     *   For <code>RESULT_ERROR_GENERIC_FAILURE</code> each sentIntent may include
-     *   the extra "errorCode" containing a radio technology specific value,
-     *   generally only useful for troubleshooting.<br>
+     *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
+     *  <code>RESULT_ERROR_RADIO_OFF</code><br>
+     *  <code>RESULT_ERROR_NULL_PDU</code><br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_LIMIT_EXCEEDED</code><br>
+     *  <code>RESULT_ERROR_FDN_CHECK_FAILURE</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NOT_ALLOWED</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED</code><br>
+     *  <code>RESULT_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_NETWORK_REJECT</code><br>
+     *  <code>RESULT_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_INVALID_STATE</code><br>
+     *  <code>RESULT_NO_MEMORY</code><br>
+     *  <code>RESULT_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_SYSTEM_ERROR</code><br>
+     *  <code>RESULT_MODEM_ERROR</code><br>
+     *  <code>RESULT_NETWORK_ERROR</code><br>
+     *  <code>RESULT_ENCODING_ERROR</code><br>
+     *  <code>RESULT_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_INTERNAL_ERROR</code><br>
+     *  <code>RESULT_NO_RESOURCES</code><br>
+     *  <code>RESULT_CANCELLED</code><br>
+     *  <code>RESULT_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_NO_BLUETOOTH_SERVICE</code><br>
+     *  <code>RESULT_INVALID_BLUETOOTH_ADDRESS</code><br>
+     *  <code>RESULT_BLUETOOTH_DISCONNECTED</code><br>
+     *  <code>RESULT_UNEXPECTED_EVENT_STOP_SENDING</code><br>
+     *  <code>RESULT_SMS_BLOCKED_DURING_EMERGENCY</code><br>
+     *  <code>RESULT_SMS_SEND_RETRY_FAILED</code><br>
+     *  <code>RESULT_REMOTE_EXCEPTION</code><br>
+     *  <code>RESULT_NO_DEFAULT_SMS_APP</code><br>
+     *  <code>RESULT_RIL_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_RIL_SMS_SEND_FAIL_RETRY</code><br>
+     *  <code>RESULT_RIL_NETWORK_REJECT</code><br>
+     *  <code>RESULT_RIL_INVALID_STATE</code><br>
+     *  <code>RESULT_RIL_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_RIL_NO_MEMORY</code><br>
+     *  <code>RESULT_RIL_REQUEST_RATE_LIMITED</code><br>
+     *  <code>RESULT_RIL_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_RIL_SYSTEM_ERR</code><br>
+     *  <code>RESULT_RIL_ENCODING_ERR</code><br>
+     *  <code>RESULT_RIL_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_RIL_MODEM_ERR</code><br>
+     *  <code>RESULT_RIL_NETWORK_ERR</code><br>
+     *  <code>RESULT_RIL_INTERNAL_ERR</code><br>
+     *  <code>RESULT_RIL_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_RIL_INVALID_MODEM_STATE</code><br>
+     *  <code>RESULT_RIL_NETWORK_NOT_READY</code><br>
+     *  <code>RESULT_RIL_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_RIL_NO_RESOURCES</code><br>
+     *  <code>RESULT_RIL_CANCELLED</code><br>
+     *  <code>RESULT_RIL_SIM_ABSENT</code><br>
+     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> or any of the RESULT_RIL errors,
+     *  the sentIntent may include the extra "errorCode" containing a radio technology specific
+     *  value, generally only useful for troubleshooting.<br>
      *   The per-application based SMS control checks sentIntent. If sentIntent
      *   is NULL the caller will be checked against all unknown applications,
      *   which cause smaller number of SMS to be sent in checking period.
@@ -765,10 +909,12 @@
      * {@link ActivityThread#currentPackageName()} is null.
      * @hide
      */
-    public void sendMultipartTextMessageExternal(
-            String destinationAddress, String scAddress, ArrayList<String> parts,
-            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents,
-            String packageName) {
+    @SystemApi
+    @TestApi
+    public void sendMultipartTextMessage(
+            @NonNull String destinationAddress, @NonNull String scAddress,
+            @NonNull List<String> parts, @Nullable List<PendingIntent> sentIntents,
+            @Nullable List<PendingIntent> deliveryIntents, @NonNull String packageName) {
         sendMultipartTextMessageInternal(destinationAddress, scAddress, parts, sentIntents,
                 deliveryIntents, true /* persistMessage*/,
                 ActivityThread.currentPackageName() == null
@@ -810,13 +956,13 @@
                         } catch (RemoteException e) {
                             Log.e(TAG, "sendMultipartTextMessageInternal: Couldn't send SMS - "
                                     + e.getMessage());
-                            notifySmsGenericError(sentIntents);
+                            notifySmsError(sentIntents, RESULT_REMOTE_EXCEPTION);
                         }
                     }
 
                     @Override
                     public void onFailure() {
-                        notifySmsErrorNoDefaultSet(context, sentIntents);
+                        notifySmsError(sentIntents, RESULT_NO_DEFAULT_SMS_APP);
                     }
                 });
             } else {
@@ -831,7 +977,7 @@
                 } catch (RemoteException e) {
                     Log.e(TAG, "sendMultipartTextMessageInternal: Couldn't send SMS - "
                             + e.getMessage());
-                    notifySmsGenericError(sentIntents);
+                    notifySmsError(sentIntents, RESULT_REMOTE_EXCEPTION);
                 }
             }
         } else {
@@ -910,12 +1056,63 @@
      *   broadcast when the corresponding message part has been sent.
      *   The result code will be <code>Activity.RESULT_OK</code> for success,
      *   or one of these errors:<br>
-     *   <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
-     *   <code>RESULT_ERROR_RADIO_OFF</code><br>
-     *   <code>RESULT_ERROR_NULL_PDU</code><br>
-     *   For <code>RESULT_ERROR_GENERIC_FAILURE</code> each sentIntent may include
-     *   the extra "errorCode" containing a radio technology specific value,
-     *   generally only useful for troubleshooting.<br>
+     *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
+     *  <code>RESULT_ERROR_RADIO_OFF</code><br>
+     *  <code>RESULT_ERROR_NULL_PDU</code><br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_LIMIT_EXCEEDED</code><br>
+     *  <code>RESULT_ERROR_FDN_CHECK_FAILURE</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NOT_ALLOWED</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED</code><br>
+     *  <code>RESULT_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_NETWORK_REJECT</code><br>
+     *  <code>RESULT_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_INVALID_STATE</code><br>
+     *  <code>RESULT_NO_MEMORY</code><br>
+     *  <code>RESULT_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_SYSTEM_ERROR</code><br>
+     *  <code>RESULT_MODEM_ERROR</code><br>
+     *  <code>RESULT_NETWORK_ERROR</code><br>
+     *  <code>RESULT_ENCODING_ERROR</code><br>
+     *  <code>RESULT_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_INTERNAL_ERROR</code><br>
+     *  <code>RESULT_NO_RESOURCES</code><br>
+     *  <code>RESULT_CANCELLED</code><br>
+     *  <code>RESULT_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_NO_BLUETOOTH_SERVICE</code><br>
+     *  <code>RESULT_INVALID_BLUETOOTH_ADDRESS</code><br>
+     *  <code>RESULT_BLUETOOTH_DISCONNECTED</code><br>
+     *  <code>RESULT_UNEXPECTED_EVENT_STOP_SENDING</code><br>
+     *  <code>RESULT_SMS_BLOCKED_DURING_EMERGENCY</code><br>
+     *  <code>RESULT_SMS_SEND_RETRY_FAILED</code><br>
+     *  <code>RESULT_REMOTE_EXCEPTION</code><br>
+     *  <code>RESULT_NO_DEFAULT_SMS_APP</code><br>
+     *  <code>RESULT_RIL_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_RIL_SMS_SEND_FAIL_RETRY</code><br>
+     *  <code>RESULT_RIL_NETWORK_REJECT</code><br>
+     *  <code>RESULT_RIL_INVALID_STATE</code><br>
+     *  <code>RESULT_RIL_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_RIL_NO_MEMORY</code><br>
+     *  <code>RESULT_RIL_REQUEST_RATE_LIMITED</code><br>
+     *  <code>RESULT_RIL_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_RIL_SYSTEM_ERR</code><br>
+     *  <code>RESULT_RIL_ENCODING_ERR</code><br>
+     *  <code>RESULT_RIL_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_RIL_MODEM_ERR</code><br>
+     *  <code>RESULT_RIL_NETWORK_ERR</code><br>
+     *  <code>RESULT_RIL_INTERNAL_ERR</code><br>
+     *  <code>RESULT_RIL_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_RIL_INVALID_MODEM_STATE</code><br>
+     *  <code>RESULT_RIL_NETWORK_NOT_READY</code><br>
+     *  <code>RESULT_RIL_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_RIL_NO_RESOURCES</code><br>
+     *  <code>RESULT_RIL_CANCELLED</code><br>
+     *  <code>RESULT_RIL_SIM_ABSENT</code><br>
+     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> or any of the RESULT_RIL errors,
+     *  the sentIntent may include the extra "errorCode" containing a radio technology specific
+     *  value, generally only useful for troubleshooting.<br>
      *   The per-application based SMS control checks sentIntent. If sentIntent
      *   is NULL the caller will be checked against all unknown applications,
      *   which cause smaller number of SMS to be sent in checking period.
@@ -993,13 +1190,13 @@
                         } catch (RemoteException e) {
                             Log.e(TAG, "sendMultipartTextMessageInternal: Couldn't send SMS - "
                                     + e.getMessage());
-                            notifySmsGenericError(sentIntents);
+                            notifySmsError(sentIntents, RESULT_REMOTE_EXCEPTION);
                         }
                     }
 
                     @Override
                     public void onFailure() {
-                        notifySmsErrorNoDefaultSet(context, sentIntents);
+                        notifySmsError(sentIntents, RESULT_NO_DEFAULT_SMS_APP);
                     }
                 });
             } else {
@@ -1015,7 +1212,7 @@
                 } catch (RemoteException e) {
                     Log.e(TAG, "sendMultipartTextMessageInternal (no persist): Couldn't send SMS - "
                             + e.getMessage());
-                    notifySmsGenericError(sentIntents);
+                    notifySmsError(sentIntents, RESULT_REMOTE_EXCEPTION);
                 }
             }
         } else {
@@ -1060,9 +1257,60 @@
      *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
      *  <code>RESULT_ERROR_RADIO_OFF</code><br>
      *  <code>RESULT_ERROR_NULL_PDU</code><br>
-     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
-     *  the extra "errorCode" containing a radio technology specific value,
-     *  generally only useful for troubleshooting.<br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
+     *  <code>RESULT_ERROR_LIMIT_EXCEEDED</code><br>
+     *  <code>RESULT_ERROR_FDN_CHECK_FAILURE</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NOT_ALLOWED</code><br>
+     *  <code>RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED</code><br>
+     *  <code>RESULT_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_NETWORK_REJECT</code><br>
+     *  <code>RESULT_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_INVALID_STATE</code><br>
+     *  <code>RESULT_NO_MEMORY</code><br>
+     *  <code>RESULT_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_SYSTEM_ERROR</code><br>
+     *  <code>RESULT_MODEM_ERROR</code><br>
+     *  <code>RESULT_NETWORK_ERROR</code><br>
+     *  <code>RESULT_ENCODING_ERROR</code><br>
+     *  <code>RESULT_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_INTERNAL_ERROR</code><br>
+     *  <code>RESULT_NO_RESOURCES</code><br>
+     *  <code>RESULT_CANCELLED</code><br>
+     *  <code>RESULT_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_NO_BLUETOOTH_SERVICE</code><br>
+     *  <code>RESULT_INVALID_BLUETOOTH_ADDRESS</code><br>
+     *  <code>RESULT_BLUETOOTH_DISCONNECTED</code><br>
+     *  <code>RESULT_UNEXPECTED_EVENT_STOP_SENDING</code><br>
+     *  <code>RESULT_SMS_BLOCKED_DURING_EMERGENCY</code><br>
+     *  <code>RESULT_SMS_SEND_RETRY_FAILED</code><br>
+     *  <code>RESULT_REMOTE_EXCEPTION</code><br>
+     *  <code>RESULT_NO_DEFAULT_SMS_APP</code><br>
+     *  <code>RESULT_RIL_RADIO_NOT_AVAILABLE</code><br>
+     *  <code>RESULT_RIL_SMS_SEND_FAIL_RETRY</code><br>
+     *  <code>RESULT_RIL_NETWORK_REJECT</code><br>
+     *  <code>RESULT_RIL_INVALID_STATE</code><br>
+     *  <code>RESULT_RIL_INVALID_ARGUMENTS</code><br>
+     *  <code>RESULT_RIL_NO_MEMORY</code><br>
+     *  <code>RESULT_RIL_REQUEST_RATE_LIMITED</code><br>
+     *  <code>RESULT_RIL_INVALID_SMS_FORMAT</code><br>
+     *  <code>RESULT_RIL_SYSTEM_ERR</code><br>
+     *  <code>RESULT_RIL_ENCODING_ERR</code><br>
+     *  <code>RESULT_RIL_INVALID_SMSC_ADDRESS</code><br>
+     *  <code>RESULT_RIL_MODEM_ERR</code><br>
+     *  <code>RESULT_RIL_NETWORK_ERR</code><br>
+     *  <code>RESULT_RIL_INTERNAL_ERR</code><br>
+     *  <code>RESULT_RIL_REQUEST_NOT_SUPPORTED</code><br>
+     *  <code>RESULT_RIL_INVALID_MODEM_STATE</code><br>
+     *  <code>RESULT_RIL_NETWORK_NOT_READY</code><br>
+     *  <code>RESULT_RIL_OPERATION_NOT_ALLOWED</code><br>
+     *  <code>RESULT_RIL_NO_RESOURCES</code><br>
+     *  <code>RESULT_RIL_CANCELLED</code><br>
+     *  <code>RESULT_RIL_SIM_ABSENT</code><br>
+     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> or any of the RESULT_RIL errors,
+     *  the sentIntent may include the extra "errorCode" containing a radio technology specific
+     *  value, generally only useful for troubleshooting.<br>
      *  The per-application based SMS control checks sentIntent. If sentIntent
      *  is NULL the caller will be checked against all unknown applications,
      *  which cause smaller number of SMS to be sent in checking period.
@@ -1094,12 +1342,12 @@
                             sentIntent, deliveryIntent);
                 } catch (RemoteException e) {
                     Log.e(TAG, "sendDataMessage: Couldn't send SMS - Exception: " + e.getMessage());
-                    notifySmsGenericError(sentIntent);
+                    notifySmsError(sentIntent, RESULT_REMOTE_EXCEPTION);
                 }
             }
             @Override
             public void onFailure() {
-                notifySmsErrorNoDefaultSet(context, sentIntent);
+                notifySmsError(sentIntent, RESULT_NO_DEFAULT_SMS_APP);
             }
         });
     }
@@ -1304,53 +1552,20 @@
         return binder;
     }
 
-    private static void notifySmsErrorNoDefaultSet(Context context, PendingIntent pendingIntent) {
+    private static void notifySmsError(PendingIntent pendingIntent, int error) {
         if (pendingIntent != null) {
-            Intent errorMessage = new Intent();
-            errorMessage.putExtra(NO_DEFAULT_EXTRA, true);
             try {
-                pendingIntent.send(context, RESULT_ERROR_GENERIC_FAILURE, errorMessage);
+                pendingIntent.send(error);
             } catch (PendingIntent.CanceledException e) {
                 // Don't worry about it, we do not need to notify the caller if this is the case.
             }
         }
     }
 
-    private static void notifySmsErrorNoDefaultSet(Context context,
-            List<PendingIntent> pendingIntents) {
+    private static void notifySmsError(List<PendingIntent> pendingIntents, int error) {
         if (pendingIntents != null) {
             for (PendingIntent pendingIntent : pendingIntents) {
-                Intent errorMessage = new Intent();
-                errorMessage.putExtra(NO_DEFAULT_EXTRA, true);
-                try {
-                    pendingIntent.send(context, RESULT_ERROR_GENERIC_FAILURE, errorMessage);
-                } catch (PendingIntent.CanceledException e) {
-                    // Don't worry about it, we do not need to notify the caller if this is the
-                    // case.
-                }
-            }
-        }
-    }
-
-    private static void notifySmsGenericError(PendingIntent pendingIntent) {
-        if (pendingIntent != null) {
-            try {
-                pendingIntent.send(RESULT_ERROR_GENERIC_FAILURE);
-            } catch (PendingIntent.CanceledException e) {
-                // Don't worry about it, we do not need to notify the caller if this is the case.
-            }
-        }
-    }
-
-    private static void notifySmsGenericError(List<PendingIntent> pendingIntents) {
-        if (pendingIntents != null) {
-            for (PendingIntent pendingIntent : pendingIntents) {
-                try {
-                    pendingIntent.send(RESULT_ERROR_GENERIC_FAILURE);
-                } catch (PendingIntent.CanceledException e) {
-                    // Don't worry about it, we do not need to notify the caller if this is the
-                    // case.
-                }
+                notifySmsError(pendingIntent, error);
             }
         }
     }
@@ -1797,19 +2012,19 @@
     // see SmsMessage.getStatusOnIcc
 
     /** Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
-    static public final int STATUS_ON_ICC_FREE      = 0;
+    public static final int STATUS_ON_ICC_FREE      = 0;
 
     /** Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
-    static public final int STATUS_ON_ICC_READ      = 1;
+    public static final int STATUS_ON_ICC_READ      = 1;
 
     /** Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
-    static public final int STATUS_ON_ICC_UNREAD    = 3;
+    public static final int STATUS_ON_ICC_UNREAD    = 3;
 
     /** Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
-    static public final int STATUS_ON_ICC_SENT      = 5;
+    public static final int STATUS_ON_ICC_SENT      = 5;
 
     /** Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
-    static public final int STATUS_ON_ICC_UNSENT    = 7;
+    public static final int STATUS_ON_ICC_UNSENT    = 7;
 
     // SMS send failure result codes
 
@@ -1845,126 +2060,263 @@
 
     /**
      * No error.
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_ERROR_NONE    = 0;
+    public static final int RESULT_ERROR_NONE    = 0;
+
     /** Generic failure cause */
-    static public final int RESULT_ERROR_GENERIC_FAILURE    = 1;
+    public static final int RESULT_ERROR_GENERIC_FAILURE    = 1;
+
     /** Failed because radio was explicitly turned off */
-    static public final int RESULT_ERROR_RADIO_OFF          = 2;
+    public static final int RESULT_ERROR_RADIO_OFF          = 2;
+
     /** Failed because no pdu provided */
-    static public final int RESULT_ERROR_NULL_PDU           = 3;
+    public static final int RESULT_ERROR_NULL_PDU           = 3;
+
     /** Failed because service is currently unavailable */
-    static public final int RESULT_ERROR_NO_SERVICE         = 4;
+    public static final int RESULT_ERROR_NO_SERVICE         = 4;
+
     /** Failed because we reached the sending queue limit. */
-    static public final int RESULT_ERROR_LIMIT_EXCEEDED     = 5;
+    public static final int RESULT_ERROR_LIMIT_EXCEEDED     = 5;
+
     /**
      * Failed because FDN is enabled.
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_ERROR_FDN_CHECK_FAILURE  = 6;
+    public static final int RESULT_ERROR_FDN_CHECK_FAILURE  = 6;
+
     /** Failed because user denied the sending of this short code. */
-    static public final int RESULT_ERROR_SHORT_CODE_NOT_ALLOWED = 7;
+    public static final int RESULT_ERROR_SHORT_CODE_NOT_ALLOWED = 7;
+
     /** Failed because the user has denied this app ever send premium short codes. */
-    static public final int RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED = 8;
+    public static final int RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED = 8;
+
     /**
      * Failed because the radio was not available
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_RADIO_NOT_AVAILABLE = 9;
+    public static final int RESULT_RADIO_NOT_AVAILABLE = 9;
+
     /**
      * Failed because of network rejection
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_NETWORK_REJECT = 10;
+    public static final int RESULT_NETWORK_REJECT = 10;
+
     /**
      * Failed because of invalid arguments
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_INVALID_ARGUMENTS = 11;
+    public static final int RESULT_INVALID_ARGUMENTS = 11;
+
     /**
      * Failed because of an invalid state
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_INVALID_STATE = 12;
+    public static final int RESULT_INVALID_STATE = 12;
+
     /**
      * Failed because there is no memory
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_NO_MEMORY = 13;
+    public static final int RESULT_NO_MEMORY = 13;
+
     /**
      * Failed because the sms format is not valid
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_INVALID_SMS_FORMAT = 14;
+    public static final int RESULT_INVALID_SMS_FORMAT = 14;
+
     /**
      * Failed because of a system error
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_SYSTEM_ERROR = 15;
+    public static final int RESULT_SYSTEM_ERROR = 15;
+
     /**
      * Failed because of a modem error
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_MODEM_ERROR = 16;
+    public static final int RESULT_MODEM_ERROR = 16;
+
     /**
      * Failed because of a network error
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_NETWORK_ERROR = 17;
+    public static final int RESULT_NETWORK_ERROR = 17;
+
     /**
      * Failed because of an encoding error
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_ENCODING_ERROR = 18;
+    public static final int RESULT_ENCODING_ERROR = 18;
+
     /**
      * Failed because of an invalid smsc address
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_INVALID_SMSC_ADDRESS = 19;
+    public static final int RESULT_INVALID_SMSC_ADDRESS = 19;
+
     /**
      * Failed because the operation is not allowed
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_OPERATION_NOT_ALLOWED = 20;
+    public static final int RESULT_OPERATION_NOT_ALLOWED = 20;
+
     /**
      * Failed because of an internal error
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_INTERNAL_ERROR = 21;
+    public static final int RESULT_INTERNAL_ERROR = 21;
+
     /**
      * Failed because there are no resources
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_NO_RESOURCES = 22;
+    public static final int RESULT_NO_RESOURCES = 22;
+
     /**
      * Failed because the operation was cancelled
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_CANCELLED = 23;
+    public static final int RESULT_CANCELLED = 23;
+
     /**
      * Failed because the request is not supported
-     * @hide
      */
-    @SystemApi
-    static public final int RESULT_REQUEST_NOT_SUPPORTED = 24;
+    public static final int RESULT_REQUEST_NOT_SUPPORTED = 24;
+
+    /**
+     * Failed sending via bluetooth because the bluetooth service is not available
+     */
+    public static final int RESULT_NO_BLUETOOTH_SERVICE = 25;
+
+    /**
+     * Failed sending via bluetooth because the bluetooth device address is invalid
+     */
+    public static final int RESULT_INVALID_BLUETOOTH_ADDRESS = 26;
+
+    /**
+     * Failed sending via bluetooth because bluetooth disconnected
+     */
+    public static final int RESULT_BLUETOOTH_DISCONNECTED = 27;
+
+    /**
+     * Failed sending because the user denied or canceled the dialog displayed for a premium
+     * shortcode sms or rate-limited sms.
+     */
+    public static final int RESULT_UNEXPECTED_EVENT_STOP_SENDING = 28;
+
+    /**
+     * Failed sending during an emergency call
+     */
+    public static final int RESULT_SMS_BLOCKED_DURING_EMERGENCY = 29;
+
+    /**
+     * Failed to send an sms retry
+     */
+    public static final int RESULT_SMS_SEND_RETRY_FAILED = 30;
+
+    /**
+     * Set by BroadcastReceiver to indicate a remote exception while handling a message.
+     */
+    public static final int RESULT_REMOTE_EXCEPTION = 31;
+
+    /**
+     * Set by BroadcastReceiver to indicate there's no default sms app.
+     */
+    public static final int RESULT_NO_DEFAULT_SMS_APP = 32;
+
+    // Radio Error results
+
+    /**
+     * The radio did not start or is resetting.
+     */
+    public static final int RESULT_RIL_RADIO_NOT_AVAILABLE = 100;
+
+    /**
+     * The radio failed to send the sms and needs to retry.
+     */
+    public static final int RESULT_RIL_SMS_SEND_FAIL_RETRY = 101;
+
+    /**
+     * The sms request was rejected by the network.
+     */
+    public static final int RESULT_RIL_NETWORK_REJECT = 102;
+
+    /**
+     * The radio returned an unexpected request for the current state.
+     */
+    public static final int RESULT_RIL_INVALID_STATE = 103;
+
+    /**
+     * The radio received invalid arguments in the request.
+     */
+    public static final int RESULT_RIL_INVALID_ARGUMENTS = 104;
+
+    /**
+     * The radio didn't have sufficient memory to process the request.
+     */
+    public static final int RESULT_RIL_NO_MEMORY = 105;
+
+    /**
+     * The radio denied the operation due to overly-frequent requests.
+     */
+    public static final int RESULT_RIL_REQUEST_RATE_LIMITED = 106;
+
+    /**
+     * The radio returned an error indicating invalid sms format.
+     */
+    public static final int RESULT_RIL_INVALID_SMS_FORMAT = 107;
+
+    /**
+     * The radio encountered a platform or system error.
+     */
+    public static final int RESULT_RIL_SYSTEM_ERR = 108;
+
+    /**
+     * The SMS message was not encoded properly.
+     */
+    public static final int RESULT_RIL_ENCODING_ERR = 109;
+
+    /**
+     * The specified SMSC address was invalid.
+     */
+    public static final int RESULT_RIL_INVALID_SMSC_ADDRESS = 110;
+
+    /**
+     * The vendor RIL received an unexpected or incorrect response.
+     */
+    public static final int RESULT_RIL_MODEM_ERR = 111;
+
+    /**
+     * The radio received an error from the network.
+     */
+    public static final int RESULT_RIL_NETWORK_ERR = 112;
+
+    /**
+     * The modem encountered an unexpected error scenario while handling the request.
+     */
+    public static final int RESULT_RIL_INTERNAL_ERR = 113;
+
+    /**
+     * The request was not supported by the radio.
+     */
+    public static final int RESULT_RIL_REQUEST_NOT_SUPPORTED = 114;
+
+    /**
+     * The radio cannot process the request in the current modem state.
+     */
+    public static final int RESULT_RIL_INVALID_MODEM_STATE = 115;
+
+    /**
+     * The network is not ready to perform the request.
+     */
+    public static final int RESULT_RIL_NETWORK_NOT_READY = 116;
+
+    /**
+     * The radio reports the request is not allowed.
+     */
+    public static final int RESULT_RIL_OPERATION_NOT_ALLOWED = 117;
+
+    /**
+     * There are not sufficient resources to process the request.
+     */
+    public static final int RESULT_RIL_NO_RESOURCES = 118;
+
+    /**
+     * The request has been cancelled.
+     */
+    public static final int RESULT_RIL_CANCELLED = 119;
+
+    /**
+     * The radio failed to set the location where the CDMA subscription
+     * can be retrieved because the SIM or RUIM is absent.
+     */
+    public static final int RESULT_RIL_SIM_ABSENT = 120;
 
     /**
      * Send an MMS message
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 3bd6578..b35549e 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -31,6 +31,7 @@
 import android.annotation.SuppressAutoDoc;
 import android.annotation.SystemApi;
 import android.annotation.SystemService;
+import android.annotation.TestApi;
 import android.annotation.UnsupportedAppUsage;
 import android.app.BroadcastOptions;
 import android.app.PendingIntent;
@@ -1868,13 +1869,27 @@
         return subId;
     }
 
-    /** @hide */
-    public void setDefaultVoiceSubId(int subId) {
-        if (VDBG) logd("setDefaultVoiceSubId sub id = " + subId);
+    /**
+     * Sets the system's default voice subscription id.
+     *
+     * On a data-only device, this is a no-op.
+     *
+     * May throw a {@link RuntimeException} if the provided subscription id is equal to
+     * {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID}
+     *
+     * @param subscriptionId A valid subscription ID to set as the system default, or
+     *                       {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}
+     * @hide
+     */
+    @SystemApi
+    @TestApi
+    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
+    public void setDefaultVoiceSubscriptionId(int subscriptionId) {
+        if (VDBG) logd("setDefaultVoiceSubId sub id = " + subscriptionId);
         try {
             ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
             if (iSub != null) {
-                iSub.setDefaultVoiceSubId(subId);
+                iSub.setDefaultVoiceSubId(subscriptionId);
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1882,6 +1897,15 @@
     }
 
     /**
+     * Same as {@link #setDefaultVoiceSubscriptionId(int)}, but preserved for backwards
+     * compatibility.
+     * @hide
+     */
+    public void setDefaultVoiceSubId(int subId) {
+        setDefaultVoiceSubscriptionId(subId);
+    }
+
+    /**
      * Return the SubscriptionInfo for default voice subscription.
      *
      * Will return null on data only devices, or on error.
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 8dfc944..c26e5b5 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -38,6 +38,7 @@
 import android.annotation.WorkerThread;
 import android.app.ActivityThread;
 import android.app.PendingIntent;
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.net.ConnectivityManager;
@@ -97,6 +98,7 @@
 import com.android.internal.telephony.OperatorInfo;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.RILConstants;
+import com.android.internal.telephony.SmsApplication;
 import com.android.internal.telephony.TelephonyProperties;
 
 import dalvik.system.VMRuntime;
@@ -429,6 +431,25 @@
                 getActiveModemCount());
     }
 
+    /**
+     * Gets the maximum number of SIMs that can be active, based on the device's multisim
+     * configuration.
+     * @return 1 for single-SIM, DSDS, and TSTS devices. 2 for DSDA devices.
+     * @hide
+     */
+    @SystemApi
+    public int getMaxNumberOfSimultaneouslyActiveSims() {
+        switch (getMultiSimConfiguration()) {
+            case UNKNOWN:
+            case DSDS:
+            case TSTS:
+                return 1;
+            case DSDA:
+                return 2;
+        }
+        return 1;
+    }
+
     /** {@hide} */
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public static TelephonyManager from(Context context) {
@@ -9284,6 +9305,21 @@
     }
 
     /**
+     * Gets the default Respond Via Message application
+     * @param context context from the calling app
+     * @param updateIfNeeded update the default app if there is no valid default app configured.
+     * @return component name of the app and class to direct Respond Via Message intent to, or
+     * {@code null} if the functionality is not supported.
+     * @hide
+     */
+    @SystemApi
+    @TestApi
+    public static @Nullable ComponentName getDefaultRespondViaMessageApplication(
+            @NonNull Context context, boolean updateIfNeeded) {
+        return SmsApplication.getDefaultRespondViaMessageApplication(context, updateIfNeeded);
+    }
+
+    /**
      * Set the alphabetic name of current registered operator.
      * @param name the alphabetic name of current registered operator.
      * @hide
@@ -9385,7 +9421,7 @@
      * @hide
      */
     @UnsupportedAppUsage
-    public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
+    public int getSubIdForPhoneAccount(@Nullable PhoneAccount phoneAccount) {
         int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
         try {
             ITelephony service = getITelephony();
@@ -9445,18 +9481,37 @@
     }
 
     /**
-     * Resets Telephony and IMS settings back to factory defaults.
+     * Resets telephony manager settings back to factory defaults.
      *
      * @hide
      */
-    @SystemApi
-    @RequiresPermission(Manifest.permission.CONNECTIVITY_INTERNAL)
     public void factoryReset(int subId) {
         try {
             Log.d(TAG, "factoryReset: subId=" + subId);
             ITelephony telephony = getITelephony();
-            if (telephony != null)
+            if (telephony != null) {
                 telephony.factoryReset(subId);
+            }
+        } catch (RemoteException e) {
+        }
+    }
+
+
+    /**
+     * Resets Telephony and IMS settings back to factory defaults only for the subscription
+     * associated with this instance.
+     * @see #createForSubscriptionId(int)
+     * @hide
+     */
+    @SystemApi
+    @RequiresPermission(Manifest.permission.CONNECTIVITY_INTERNAL)
+    public void resetSettings() {
+        try {
+            Log.d(TAG, "resetSettings: subId=" + getSubId());
+            ITelephony telephony = getITelephony();
+            if (telephony != null) {
+                telephony.factoryReset(getSubId());
+            }
         } catch (RemoteException e) {
         }
     }
diff --git a/telephony/java/android/telephony/cdma/CdmaSmsCbProgramData.aidl b/telephony/java/android/telephony/cdma/CdmaSmsCbProgramData.aidl
new file mode 100644
index 0000000..a648a0e
--- /dev/null
+++ b/telephony/java/android/telephony/cdma/CdmaSmsCbProgramData.aidl
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/** @hide */
+package android.telephony.cdma;
+
+parcelable CdmaSmsCbProgramData;
+
diff --git a/telephony/java/android/telephony/data/ApnSetting.java b/telephony/java/android/telephony/data/ApnSetting.java
index a5d6266..60774e7 100644
--- a/telephony/java/android/telephony/data/ApnSetting.java
+++ b/telephony/java/android/telephony/data/ApnSetting.java
@@ -1944,8 +1944,9 @@
          * {@link ApnSetting} built from this builder otherwise.
          */
         public ApnSetting build() {
-            if ((mApnTypeBitmask & TYPE_ALL) == 0 || TextUtils.isEmpty(mApnName)
-                || TextUtils.isEmpty(mEntryName)) {
+            if ((mApnTypeBitmask & (TYPE_DEFAULT | TYPE_MMS | TYPE_SUPL | TYPE_DUN | TYPE_HIPRI |
+                    TYPE_FOTA | TYPE_IMS | TYPE_CBS | TYPE_IA | TYPE_EMERGENCY | TYPE_MCX)) == 0
+                || TextUtils.isEmpty(mApnName) || TextUtils.isEmpty(mEntryName)) {
                 return null;
             }
             return new ApnSetting(this);
diff --git a/telephony/java/android/telephony/ims/ImsCallProfile.java b/telephony/java/android/telephony/ims/ImsCallProfile.java
index 77ee205..4ddeb90 100644
--- a/telephony/java/android/telephony/ims/ImsCallProfile.java
+++ b/telephony/java/android/telephony/ims/ImsCallProfile.java
@@ -309,6 +309,37 @@
     public @CallRestrictCause int mRestrictCause = CALL_RESTRICT_CAUSE_NONE;
 
     /**
+     * The VERSTAT for an incoming call's phone number.
+     */
+    private @VerificationStatus int mCallerNumberVerificationStatus;
+
+    /**
+     * Indicates that the network could not perform verification.
+     */
+    public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
+
+    /**
+     * Indicates that verification by the network passed.  This indicates there is a high likelihood
+     * that the call originated from a valid source.
+     */
+    public static final int VERIFICATION_STATUS_PASSED = 1;
+
+    /**
+     * Indicates that verification by the network failed.  This indicates there is a high likelihood
+     * that the call did not originate from a valid source.
+     */
+    public static final int VERIFICATION_STATUS_FAILED = 2;
+
+    /**@hide*/
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(prefix = "VERIFICATION_STATUS_", value = {
+            VERIFICATION_STATUS_NOT_VERIFIED,
+            VERIFICATION_STATUS_PASSED,
+            VERIFICATION_STATUS_FAILED
+    })
+    public @interface VerificationStatus {}
+
+    /**
      * The emergency service categories, only valid if {@link #getServiceType} returns
      * {@link #SERVICE_TYPE_EMERGENCY}
      *
@@ -539,6 +570,29 @@
         mMediaProfile = profile.mMediaProfile;
     }
 
+    /**
+     * Sets the verification status for the phone number of an incoming call as identified in
+     * ATIS-1000082.
+     * <p>
+     * The ImsService should parse the verstat information from the SIP INVITE headers for the call
+     * to determine this information.  It is typically found in the P-Asserted-Identity OR From
+     * header fields.
+     * @param callerNumberVerificationStatus the new verification status.
+     */
+    public void setCallerNumberVerificationStatus(
+            @VerificationStatus int callerNumberVerificationStatus) {
+        mCallerNumberVerificationStatus = callerNumberVerificationStatus;
+    }
+
+    /**
+     * Gets the verification status for the phone number of an incoming call as identified in
+     * ATIS-1000082.
+     * @return the verification status.
+     */
+    public @VerificationStatus int getCallerNumberVerificationStatus() {
+        return mCallerNumberVerificationStatus;
+    }
+
     @NonNull
     @Override
     public String toString() {
@@ -551,7 +605,8 @@
                 + ", emergencyCallRouting=" + mEmergencyCallRouting
                 + ", emergencyCallTesting=" + mEmergencyCallTesting
                 + ", hasKnownUserIntentEmergency=" + mHasKnownUserIntentEmergency
-                + ", mRestrictCause=" + mRestrictCause + " }";
+                + ", mRestrictCause=" + mRestrictCause
+                + ", mCallerNumberVerstat= " + mCallerNumberVerificationStatus + " }";
     }
 
     @Override
@@ -572,6 +627,7 @@
         out.writeBoolean(mEmergencyCallTesting);
         out.writeBoolean(mHasKnownUserIntentEmergency);
         out.writeInt(mRestrictCause);
+        out.writeInt(mCallerNumberVerificationStatus);
     }
 
     private void readFromParcel(Parcel in) {
@@ -585,6 +641,7 @@
         mEmergencyCallTesting = in.readBoolean();
         mHasKnownUserIntentEmergency = in.readBoolean();
         mRestrictCause = in.readInt();
+        mCallerNumberVerificationStatus = in.readInt();
     }
 
     public static final @android.annotation.NonNull Creator<ImsCallProfile> CREATOR = new Creator<ImsCallProfile>() {
diff --git a/telephony/java/android/telephony/ims/ImsMmTelManager.java b/telephony/java/android/telephony/ims/ImsMmTelManager.java
index 7cafa1e..9fc8e75 100644
--- a/telephony/java/android/telephony/ims/ImsMmTelManager.java
+++ b/telephony/java/android/telephony/ims/ImsMmTelManager.java
@@ -254,8 +254,8 @@
      * the {@link ImsService} associated with the subscription is not available. This can happen if
      * the service crashed, for example. See {@link ImsException#getCode()} for a more detailed
      * reason.
-     * @deprecated Use {@link #registerImsRegistrationCallback(
-     * RegistrationManager.RegistrationCallback, Executor)} instead.
+     * @deprecated Use {@link RegistrationManager#registerImsRegistrationCallback(Executor,
+     * RegistrationManager.RegistrationCallback)} instead.
      */
     @Deprecated
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
@@ -285,9 +285,8 @@
     /**{@inheritDoc}*/
     @Override
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    public void registerImsRegistrationCallback(
-            @NonNull RegistrationManager.RegistrationCallback c,
-            @NonNull @CallbackExecutor Executor executor) throws ImsException {
+    public void registerImsRegistrationCallback(@NonNull @CallbackExecutor Executor executor,
+            @NonNull RegistrationManager.RegistrationCallback c) throws ImsException {
         if (c == null) {
             throw new IllegalArgumentException("Must include a non-null RegistrationCallback.");
         }
@@ -348,8 +347,8 @@
     /**{@inheritDoc}*/
     @Override
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    public void getRegistrationState(@NonNull @ImsRegistrationState Consumer<Integer> stateCallback,
-            @NonNull @CallbackExecutor Executor executor) {
+    public void getRegistrationState(@NonNull @CallbackExecutor Executor executor,
+            @NonNull @ImsRegistrationState Consumer<Integer> stateCallback) {
         if (stateCallback == null) {
             throw new IllegalArgumentException("Must include a non-null callback.");
         }
@@ -371,9 +370,9 @@
     /**{@inheritDoc}*/
     @Override
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    public void getRegistrationTransportType(
-            @NonNull @AccessNetworkConstants.TransportType Consumer<Integer> transportTypeCallback,
-            @NonNull @CallbackExecutor Executor executor) {
+    public void getRegistrationTransportType(@NonNull @CallbackExecutor Executor executor,
+            @NonNull @AccessNetworkConstants.TransportType
+                    Consumer<Integer> transportTypeCallback) {
         if (transportTypeCallback == null) {
             throw new IllegalArgumentException("Must include a non-null callback.");
         }
@@ -607,17 +606,17 @@
      * {@link CarrierConfigManager#ACTION_CARRIER_CONFIG_CHANGED} broadcast for this subscription.
      * @param capability The capability that is being queried for support on the carrier network.
      * @param transportType The transport type of the capability to check support for.
+     * @param executor The executor that the callback will be called with.
      * @param callback A consumer containing a Boolean result specifying whether or not the
      *                 capability is supported on this carrier network for the transport specified.
-     * @param executor The executor that the callback will be called with.
      * @throws ImsException if the subscription is no longer valid or the IMS service is not
      * available.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     public void isSupported(@MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
             @AccessNetworkConstants.TransportType int transportType,
-            @NonNull Consumer<Boolean> callback,
-            @NonNull @CallbackExecutor Executor executor) throws ImsException {
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull Consumer<Boolean> callback) throws ImsException {
         if (callback == null) {
             throw new IllegalArgumentException("Must include a non-null Consumer.");
         }
diff --git a/telephony/java/android/telephony/ims/ImsRcsManager.java b/telephony/java/android/telephony/ims/ImsRcsManager.java
index 25bd1ca..21707b0 100644
--- a/telephony/java/android/telephony/ims/ImsRcsManager.java
+++ b/telephony/java/android/telephony/ims/ImsRcsManager.java
@@ -22,11 +22,15 @@
 import android.annotation.RequiresPermission;
 import android.content.Context;
 import android.os.Binder;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
 import android.telephony.AccessNetworkConstants;
-import android.telephony.SubscriptionManager;
 import android.telephony.ims.aidl.IImsCapabilityCallback;
+import android.telephony.ims.aidl.IImsRcsController;
 import android.telephony.ims.feature.ImsFeature;
 import android.telephony.ims.feature.RcsFeature;
+import android.util.Log;
 
 import java.util.concurrent.Executor;
 import java.util.function.Consumer;
@@ -35,10 +39,11 @@
  * Manager for interfacing with the framework RCS services, including the User Capability Exchange
  * (UCE) service, as well as managing user settings.
  *
- * Use {@link #createForSubscriptionId(Context, int)} to create an instance of this manager.
+ * Use {@link ImsManager#getImsRcsManager(int)} to create an instance of this manager.
  * @hide
  */
 public class ImsRcsManager implements RegistrationManager {
+    private static final String TAG = "ImsRcsManager";
 
     /**
      * Receives RCS availability status updates from the ImsService.
@@ -112,37 +117,30 @@
     private final int mSubId;
     private final Context mContext;
 
-
     /**
-     * Create an instance of ImsRcsManager for the subscription id specified.
-     *
-     * @param context The context to create this ImsRcsManager instance within.
-     * @param subscriptionId The ID of the subscription that this ImsRcsManager will use.
-     * @see android.telephony.SubscriptionManager#getActiveSubscriptionInfoList()
-     * @throws IllegalArgumentException if the subscription is invalid.
+     * Use {@link ImsManager#getImsRcsManager(int)} to create an instance of this class.
      * @hide
      */
-    public static ImsRcsManager createForSubscriptionId(Context context, int subscriptionId) {
-        if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)) {
-            throw new IllegalArgumentException("Invalid subscription ID");
-        }
-
-        return new ImsRcsManager(context, subscriptionId);
+    public ImsRcsManager(Context context, int subId) {
+        mSubId = subId;
+        mContext = context;
     }
 
     /**
-     * Use {@link #createForSubscriptionId(Context, int)} to create an instance of this class.
+     * @return A {@link RcsUceAdapter} used for User Capability Exchange (UCE) operations for
+     * this subscription.
+     * @hide
      */
-    private ImsRcsManager(Context context, int subId) {
-        mContext = context;
-        mSubId = subId;
+    @NonNull
+    public RcsUceAdapter getUceAdapter() {
+        return new RcsUceAdapter(mSubId);
     }
 
     /**{@inheritDoc}*/
     @Override
     public void registerImsRegistrationCallback(
-            @NonNull RegistrationManager.RegistrationCallback c,
-            @NonNull @CallbackExecutor Executor executor)
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull RegistrationCallback c)
             throws ImsException {
         if (c == null) {
             throw new IllegalArgumentException("Must include a non-null RegistrationCallback.");
@@ -168,8 +166,8 @@
 
     /**{@inheritDoc}*/
     @Override
-    public void getRegistrationState(@NonNull @ImsRegistrationState Consumer<Integer> stateCallback,
-            @NonNull @CallbackExecutor Executor executor) {
+    public void getRegistrationState(@NonNull @CallbackExecutor Executor executor,
+            @NonNull @ImsRegistrationState Consumer<Integer> stateCallback) {
         if (stateCallback == null) {
             throw new IllegalArgumentException("Must include a non-null stateCallback.");
         }
@@ -182,9 +180,9 @@
 
     /**{@inheritDoc}*/
     @Override
-    public void getRegistrationTransportType(
-            @NonNull @AccessNetworkConstants.TransportType Consumer<Integer> transportTypeCallback,
-            @NonNull @CallbackExecutor Executor executor) {
+    public void getRegistrationTransportType(@NonNull @CallbackExecutor Executor executor,
+            @NonNull @AccessNetworkConstants.TransportType
+                    Consumer<Integer> transportTypeCallback) {
         if (transportTypeCallback == null) {
             throw new IllegalArgumentException("Must include a non-null transportTypeCallback.");
         }
@@ -225,9 +223,22 @@
         if (executor == null) {
             throw new IllegalArgumentException("Must include a non-null Executor.");
         }
+
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "Register availability callback: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
         c.setExecutor(executor);
-        throw new UnsupportedOperationException("registerRcsAvailabilityCallback is not"
-                + "supported.");
+        try {
+            imsRcsController.registerRcsAvailabilityCallback(c.getBinder());
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#registerRcsAvailabilityCallback", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
 
     /**
@@ -238,14 +249,31 @@
      * inactive subscription, it will result in a no-op.
      * @param c The RCS {@link AvailabilityCallback} to be removed.
      * @see #registerRcsAvailabilityCallback(Executor, AvailabilityCallback)
+     * @throws ImsException if the IMS service is not available when calling this method
+     * {@link ImsRcsController#unregisterRcsAvailabilityCallback()}.
+     * See {@link ImsException#getCode()} for more information on the error codes.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    public void unregisterRcsAvailabilityCallback(@NonNull AvailabilityCallback c) {
+    public void unregisterRcsAvailabilityCallback(@NonNull AvailabilityCallback c)
+            throws ImsException {
         if (c == null) {
             throw new IllegalArgumentException("Must include a non-null AvailabilityCallback.");
         }
-        throw new UnsupportedOperationException("unregisterRcsAvailabilityCallback is not"
-                + "supported.");
+
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "Unregister availability callback: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        try {
+            imsRcsController.unregisterRcsAvailabilityCallback(c.getBinder());
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#unregisterRcsAvailabilityCallback", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
 
     /**
@@ -260,10 +288,27 @@
      * rather the subscription is capable of this service over IMS.
      * @see #isAvailable(int)
      * @see android.telephony.CarrierConfigManager#KEY_USE_RCS_PRESENCE_BOOL
+     * @throws ImsException if the IMS service is not available when calling this method
+     * {@link ImsRcsController#isCapable(int, int)}.
+     * See {@link ImsException#getCode()} for more information on the error codes.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    public boolean isCapable(@RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
-        throw new UnsupportedOperationException("isCapable is not supported.");
+    public boolean isCapable(@RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability)
+            throws ImsException {
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "isCapable: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        try {
+            return imsRcsController.isCapable(mSubId, capability);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#isCapable", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
 
     /**
@@ -277,18 +322,31 @@
      * false otherwise. If the capability is available, IMS is registered and the service is
      * currently available over IMS.
      * @see #isCapable(int)
+     * @throws ImsException if the IMS service is not available when calling this method
+     * {@link ImsRcsController#isAvailable(int, int)}.
+     * See {@link ImsException#getCode()} for more information on the error codes.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    public boolean isAvailable(@RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
-        throw new UnsupportedOperationException("isAvailable is not supported.");
+    public boolean isAvailable(@RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability)
+            throws ImsException {
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "isAvailable: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        try {
+            return imsRcsController.isAvailable(mSubId, capability);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#isAvailable", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
 
-    /**
-     * @return A new {@link RcsUceAdapter} used for User Capability Exchange (UCE) operations for
-     * this subscription.
-     */
-    @NonNull
-    public RcsUceAdapter getUceAdapter() {
-        return new RcsUceAdapter(mSubId);
+    private IImsRcsController getIImsRcsController() {
+        IBinder binder = ServiceManager.getService(Context.TELEPHONY_IMS_SERVICE);
+        return IImsRcsController.Stub.asInterface(binder);
     }
 }
diff --git a/telephony/java/android/telephony/ims/RcsUceAdapter.java b/telephony/java/android/telephony/ims/RcsUceAdapter.java
index a6a7a84..b47bcb9 100644
--- a/telephony/java/android/telephony/ims/RcsUceAdapter.java
+++ b/telephony/java/android/telephony/ims/RcsUceAdapter.java
@@ -23,6 +23,13 @@
 import android.annotation.RequiresPermission;
 import android.content.Context;
 import android.net.Uri;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.telephony.ims.aidl.IImsRcsController;
+import android.telephony.ims.aidl.IRcsUceControllerCallback;
+import android.util.Log;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -36,6 +43,7 @@
  * @hide
  */
 public class RcsUceAdapter {
+    private static final String TAG = "RcsUceAdapter";
 
     /**
      * An unknown error has caused the request to fail.
@@ -188,7 +196,6 @@
 
     /**
      * Not to be instantiated directly, use
-     * {@link ImsRcsManager#createForSubscriptionId(Context, int)} and
      * {@link ImsRcsManager#getUceAdapter()} to instantiate this manager class.
      */
     RcsUceAdapter(int subId) {
@@ -218,7 +225,45 @@
     public void requestCapabilities(@CallbackExecutor Executor executor,
             @NonNull List<Uri> contactNumbers,
             @NonNull CapabilitiesCallback c) throws ImsException {
-        throw new UnsupportedOperationException("isUceSettingEnabled is not supported.");
+        if (c == null) {
+            throw new IllegalArgumentException("Must include a non-null AvailabilityCallback.");
+        }
+        if (executor == null) {
+            throw new IllegalArgumentException("Must include a non-null Executor.");
+        }
+        if (contactNumbers == null) {
+            throw new IllegalArgumentException("Must include non-null contact number list.");
+        }
+
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "requestCapabilities: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        IRcsUceControllerCallback internalCallback = new IRcsUceControllerCallback.Stub() {
+            @Override
+            public void onCapabilitiesReceived(List<RcsContactUceCapability> contactCapabilities) {
+                Binder.withCleanCallingIdentity(() ->
+                        executor.execute(() ->
+                                c.onCapabilitiesReceived(contactCapabilities)));
+            }
+            @Override
+            public void onError(int errorCode) {
+                Binder.withCleanCallingIdentity(() ->
+                        executor.execute(() ->
+                                c.onError(errorCode)));
+            }
+        };
+
+        try {
+            imsRcsController.requestCapabilities(mSubId, contactNumbers, internalCallback);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#requestCapabilities", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
 
     /**
@@ -233,7 +278,20 @@
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     public @PublishState int getUcePublishState() throws ImsException {
-        throw new UnsupportedOperationException("getPublishState is not supported.");
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "getUcePublishState: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        try {
+            return imsRcsController.getUcePublishState(mSubId);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#getUcePublishState", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
 
     /**
@@ -252,9 +310,22 @@
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     public boolean isUceSettingEnabled() throws ImsException {
-        // TODO: add SubscriptionController column for this property.
-        throw new UnsupportedOperationException("isUceSettingEnabled is not supported.");
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "isUceSettingEnabled: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        try {
+            return imsRcsController.isUceSettingEnabled(mSubId);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#isUceSettingEnabled", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
     }
+
     /**
      * Change the user’s setting for whether or not UCE is enabled for the associated subscription.
      * @param isEnabled the user's setting for whether or not they wish for Presence and User
@@ -270,7 +341,24 @@
      */
     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
     public void setUceSettingEnabled(boolean isEnabled) throws ImsException {
-        // TODO: add SubscriptionController column for this property.
-        throw new UnsupportedOperationException("setUceSettingEnabled is not supported.");
+        IImsRcsController imsRcsController = getIImsRcsController();
+        if (imsRcsController == null) {
+            Log.e(TAG, "setUceSettingEnabled: IImsRcsController is null");
+            throw new ImsException("Can not find remote IMS service",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+
+        try {
+            imsRcsController.setUceSettingEnabled(mSubId, isEnabled);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling IImsRcsController#setUceSettingEnabled", e);
+            throw new ImsException("Remote IMS Service is not available",
+                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
+        }
+    }
+
+    private IImsRcsController getIImsRcsController() {
+        IBinder binder = ServiceManager.getService(Context.TELEPHONY_IMS_SERVICE);
+        return IImsRcsController.Stub.asInterface(binder);
     }
 }
diff --git a/telephony/java/android/telephony/ims/RegistrationManager.java b/telephony/java/android/telephony/ims/RegistrationManager.java
index b4c11e3..23402b8 100644
--- a/telephony/java/android/telephony/ims/RegistrationManager.java
+++ b/telephony/java/android/telephony/ims/RegistrationManager.java
@@ -90,7 +90,7 @@
 
     /**
      * Callback class for receiving IMS network Registration callback events.
-     * @see #registerImsRegistrationCallback(RegistrationCallback, Executor)
+     * @see #registerImsRegistrationCallback(Executor, RegistrationCallback)
      * @see #unregisterImsRegistrationCallback(RegistrationCallback)
      */
     class RegistrationCallback {
@@ -229,8 +229,8 @@
      * When the callback is registered, it will initiate the callback c to be called with the
      * current registration state.
      *
-     * @param c The {@link RegistrationCallback} to be added.
      * @param executor The executor the callback events should be run on.
+     * @param c The {@link RegistrationCallback} to be added.
      * @see #unregisterImsRegistrationCallback(RegistrationCallback)
      * @throws ImsException if the subscription associated with this callback is valid, but
      * the {@link ImsService} associated with the subscription is not available. This can happen if
@@ -238,8 +238,8 @@
      * reason.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    void registerImsRegistrationCallback(@NonNull RegistrationCallback c,
-            @NonNull @CallbackExecutor Executor executor) throws ImsException;
+    void registerImsRegistrationCallback(@NonNull @CallbackExecutor Executor executor,
+            @NonNull RegistrationCallback c) throws ImsException;
 
     /**
      * Removes an existing {@link RegistrationCallback}.
@@ -250,36 +250,36 @@
      *
      * @param c The {@link RegistrationCallback} to be removed.
      * @see SubscriptionManager.OnSubscriptionsChangedListener
-     * @see #registerImsRegistrationCallback(RegistrationCallback, Executor)
+     * @see #registerImsRegistrationCallback(Executor, RegistrationCallback)
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     void unregisterImsRegistrationCallback(@NonNull RegistrationCallback c);
 
     /**
      * Gets the registration state of the IMS service.
-     * @param stateCallback A callback called on the supplied {@link Executor} that will contain the
-     *                      registration state of the IMS service, which will be one of the
-     *                      following: {@link #REGISTRATION_STATE_NOT_REGISTERED},
-     *                      {@link #REGISTRATION_STATE_REGISTERING}, or
-     *                      {@link #REGISTRATION_STATE_REGISTERED}.
      * @param executor The {@link Executor} that will be used to call the IMS registration state
      *                 callback.
+     * @param stateCallback A callback called on the supplied {@link Executor} that will contain the
+ *                      registration state of the IMS service, which will be one of the
+ *                      following: {@link #REGISTRATION_STATE_NOT_REGISTERED},
+ *                      {@link #REGISTRATION_STATE_REGISTERING}, or
+ *                      {@link #REGISTRATION_STATE_REGISTERED}.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
-    void getRegistrationState(@NonNull @ImsRegistrationState Consumer<Integer> stateCallback,
-            @NonNull @CallbackExecutor Executor executor);
+    void getRegistrationState(@NonNull @CallbackExecutor Executor executor,
+            @NonNull @ImsRegistrationState Consumer<Integer> stateCallback);
 
     /**
      * Gets the Transport Type associated with the current IMS registration.
-     * @param transportTypeCallback The transport type associated with the current IMS registration,
-     *                              which will be one of following:
-     *                              {@link AccessNetworkConstants#TRANSPORT_TYPE_WWAN},
-     *                              {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}, or
-     *                              {@link AccessNetworkConstants#TRANSPORT_TYPE_INVALID}.
      * @param executor The {@link Executor} that will be used to call the transportTypeCallback.
+     * @param transportTypeCallback The transport type associated with the current IMS registration,
+ *                              which will be one of following:
+ *                              {@link AccessNetworkConstants#TRANSPORT_TYPE_WWAN},
+ *                              {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}, or
+ *                              {@link AccessNetworkConstants#TRANSPORT_TYPE_INVALID}.
      */
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     void getRegistrationTransportType(
-            @NonNull @AccessNetworkConstants.TransportType Consumer<Integer> transportTypeCallback,
-            @NonNull @CallbackExecutor Executor executor);
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull @AccessNetworkConstants.TransportType Consumer<Integer> transportTypeCallback);
 }
diff --git a/telephony/java/android/telephony/ims/aidl/IImsRcsController.aidl b/telephony/java/android/telephony/ims/aidl/IImsRcsController.aidl
new file mode 100644
index 0000000..b379bd0
--- /dev/null
+++ b/telephony/java/android/telephony/ims/aidl/IImsRcsController.aidl
@@ -0,0 +1,39 @@
+/*
+ * 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 android.telephony.ims.aidl;
+
+import android.net.Uri;
+import android.telephony.ims.aidl.IImsCapabilityCallback;
+import android.telephony.ims.aidl.IRcsUceControllerCallback;
+
+/**
+ * Interface used to interact with the Telephony IMS.
+ *
+ * {@hide}
+ */
+interface IImsRcsController {
+    void registerRcsAvailabilityCallback(IImsCapabilityCallback c);
+    void unregisterRcsAvailabilityCallback(IImsCapabilityCallback c);
+    boolean isCapable(int subId, int capability);
+    boolean isAvailable(int subId, int capability);
+
+    // ImsUceAdapter specific
+    void requestCapabilities(int subId, in List<Uri> contactNumbers, IRcsUceControllerCallback c);
+    int getUcePublishState(int subId);
+    boolean isUceSettingEnabled(int subId);
+    void setUceSettingEnabled(int subId, boolean isEnabled);
+}
diff --git a/telephony/java/android/telephony/ims/aidl/IRcsUceControllerCallback.aidl b/telephony/java/android/telephony/ims/aidl/IRcsUceControllerCallback.aidl
new file mode 100644
index 0000000..5975930
--- /dev/null
+++ b/telephony/java/android/telephony/ims/aidl/IRcsUceControllerCallback.aidl
@@ -0,0 +1,29 @@
+/*
+ * 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 android.telephony.ims.aidl;
+
+import android.telephony.ims.RcsContactUceCapability;
+
+/**
+ * Provides interface for RCS UCE when receive a change.
+ *
+ * {@hide}
+ */
+oneway interface IRcsUceControllerCallback {
+    void onCapabilitiesReceived(in List<RcsContactUceCapability> contactCapabilities);
+    void onError(int errorCode);
+}
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 414693e..39a216d 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -319,6 +319,7 @@
     /**
      * Replaced by getDataActivityForSubId.
      */
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     int getDataActivity();
 
     /**
@@ -336,6 +337,7 @@
     /**
      * Replaced by getDataStateForSubId.
      */
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     int getDataState();
 
     /**
diff --git a/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl b/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl
index 21b2f39..d7a7af1 100644
--- a/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl
@@ -49,8 +49,10 @@
     void notifySignalStrengthForPhoneId(in int phoneId, in int subId,
             in SignalStrength signalStrength);
     void notifyMessageWaitingChangedForPhoneId(in int phoneId, in int subId, in boolean mwi);
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void notifyCallForwardingChanged(boolean cfi);
     void notifyCallForwardingChangedForSubscriber(in int subId, boolean cfi);
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void notifyDataActivity(int state);
     void notifyDataActivityForSubscriber(in int subId, int state);
     void notifyDataConnection(int state, boolean isDataConnectivityPossible,
@@ -63,8 +65,10 @@
     @UnsupportedAppUsage
     void notifyDataConnectionFailed(String apnType);
     void notifyDataConnectionFailedForSubscriber(int phoneId, int subId, String apnType);
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void notifyCellLocation(in Bundle cellLocation);
     void notifyCellLocationForSubscriber(in int subId, in Bundle cellLocation);
+    @UnsupportedAppUsage(maxTargetSdk = 28)
     void notifyOtaspChanged(in int subId, in int otaspMode);
     @UnsupportedAppUsage
     void notifyCellInfo(in List<CellInfo> cellInfo);
diff --git a/tests/net/common/java/android/net/NetworkScoreTest.kt b/tests/net/common/java/android/net/NetworkScoreTest.kt
new file mode 100644
index 0000000..30836b7
--- /dev/null
+++ b/tests/net/common/java/android/net/NetworkScoreTest.kt
@@ -0,0 +1,104 @@
+/*
+ * 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 android.net
+
+import android.os.Parcelable
+import androidx.test.filters.SmallTest
+import androidx.test.runner.AndroidJUnit4
+import com.android.testutils.assertParcelSane
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertNotEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+
+private const val TEST_SCORE = 80
+private const val KEY_DEFAULT_CAPABILITIES = "DEFAULT_CAPABILITIES"
+
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+class NetworkScoreTest {
+    @Test
+    fun testParcelNetworkScore() {
+        val networkScore = NetworkScore()
+        val defaultCap = NetworkCapabilities()
+        networkScore.putExtension(KEY_DEFAULT_CAPABILITIES, defaultCap)
+        assertEquals(defaultCap, networkScore.getExtension(KEY_DEFAULT_CAPABILITIES))
+        networkScore.putIntExtension(NetworkScore.LEGACY_SCORE, TEST_SCORE)
+        assertEquals(TEST_SCORE, networkScore.getIntExtension(NetworkScore.LEGACY_SCORE))
+        assertParcelSane(networkScore, 1)
+    }
+
+    @Test
+    fun testNullKeyAndValue() {
+        val networkScore = NetworkScore()
+        val defaultCap = NetworkCapabilities()
+        networkScore.putIntExtension(null, TEST_SCORE)
+        assertEquals(TEST_SCORE, networkScore.getIntExtension(null))
+        networkScore.putExtension(null, defaultCap)
+        assertEquals(defaultCap, networkScore.getExtension(null))
+        networkScore.putExtension(null, null)
+        val result: Parcelable? = networkScore.getExtension(null)
+        assertEquals(null, result)
+    }
+
+    @Test
+    fun testRemoveExtension() {
+        val networkScore = NetworkScore()
+        val defaultCap = NetworkCapabilities()
+        networkScore.putExtension(KEY_DEFAULT_CAPABILITIES, defaultCap)
+        networkScore.putIntExtension(NetworkScore.LEGACY_SCORE, TEST_SCORE)
+        assertEquals(defaultCap, networkScore.getExtension(KEY_DEFAULT_CAPABILITIES))
+        assertEquals(TEST_SCORE, networkScore.getIntExtension(NetworkScore.LEGACY_SCORE))
+        networkScore.removeExtension(KEY_DEFAULT_CAPABILITIES)
+        networkScore.removeExtension(NetworkScore.LEGACY_SCORE)
+        val result: Parcelable? = networkScore.getExtension(KEY_DEFAULT_CAPABILITIES)
+        assertEquals(null, result)
+        assertEquals(0, networkScore.getIntExtension(NetworkScore.LEGACY_SCORE))
+    }
+
+    @Test
+    fun testEqualsNetworkScore() {
+        val ns1 = NetworkScore()
+        val ns2 = NetworkScore()
+        assertTrue(ns1.equals(ns2))
+        assertEquals(ns1.hashCode(), ns2.hashCode())
+
+        ns1.putIntExtension(NetworkScore.LEGACY_SCORE, TEST_SCORE)
+        assertFalse(ns1.equals(ns2))
+        assertNotEquals(ns1.hashCode(), ns2.hashCode())
+        ns2.putIntExtension(NetworkScore.LEGACY_SCORE, TEST_SCORE)
+        assertTrue(ns1.equals(ns2))
+        assertEquals(ns1.hashCode(), ns2.hashCode())
+
+        val defaultCap = NetworkCapabilities()
+        ns1.putExtension(KEY_DEFAULT_CAPABILITIES, defaultCap)
+        assertFalse(ns1.equals(ns2))
+        assertNotEquals(ns1.hashCode(), ns2.hashCode())
+        ns2.putExtension(KEY_DEFAULT_CAPABILITIES, defaultCap)
+        assertTrue(ns1.equals(ns2))
+        assertEquals(ns1.hashCode(), ns2.hashCode())
+
+        ns1.putIntExtension(null, 10)
+        assertFalse(ns1.equals(ns2))
+        assertNotEquals(ns1.hashCode(), ns2.hashCode())
+        ns2.putIntExtension(null, 10)
+        assertTrue(ns1.equals(ns2))
+        assertEquals(ns1.hashCode(), ns2.hashCode())
+    }
+}
diff --git a/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java b/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
index 142769f..535298f 100644
--- a/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
+++ b/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
@@ -39,6 +39,7 @@
 import android.net.NetworkFactory;
 import android.net.NetworkInfo;
 import android.net.NetworkMisc;
+import android.net.NetworkScore;
 import android.os.INetworkManagementService;
 import android.text.format.DateUtils;
 
@@ -354,8 +355,10 @@
         NetworkCapabilities caps = new NetworkCapabilities();
         caps.addCapability(0);
         caps.addTransportType(transport);
+        NetworkScore ns = new NetworkScore();
+        ns.putIntExtension(NetworkScore.LEGACY_SCORE, 50);
         NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null,
-                caps, 50, mCtx, null, mMisc, mConnService, mNetd, mDnsResolver, mNMS,
+                caps, ns, mCtx, null, mMisc, mConnService, mNetd, mDnsResolver, mNMS,
                 NetworkFactory.SerialNumber.NONE);
         nai.everValidated = true;
         return nai;
diff --git a/tools/aapt2/compile/PseudolocaleGenerator.cpp b/tools/aapt2/compile/PseudolocaleGenerator.cpp
index c5de9e0..5e0300b 100644
--- a/tools/aapt2/compile/PseudolocaleGenerator.cpp
+++ b/tools/aapt2/compile/PseudolocaleGenerator.cpp
@@ -231,7 +231,7 @@
       Visitor sub_visitor(pool_, method_);
       if (plural->values[i]) {
         plural->values[i]->Accept(&sub_visitor);
-        if (sub_visitor.value) {
+        if (sub_visitor.item) {
           localized->values[i] = std::move(sub_visitor.item);
         } else {
           localized->values[i] = std::unique_ptr<Item>(plural->values[i]->Clone(pool_));
diff --git a/tools/aapt2/compile/PseudolocaleGenerator_test.cpp b/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
index 3135802..e816c86 100644
--- a/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
+++ b/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
@@ -234,6 +234,27 @@
                                             test::ParseConfigOrDie("ar-rXB")));
 }
 
+TEST(PseudolocaleGeneratorTest, PluralsArePseudolocalized) {
+  std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
+  std::unique_ptr<ResourceTable> table =
+      test::ResourceTableBuilder().SetPackageId("com.pkg", 0x7F).Build();
+  std::unique_ptr<Plural> plural = util::make_unique<Plural>();
+  plural->values = {util::make_unique<String>(table->string_pool.MakeRef("zero")),
+                    util::make_unique<String>(table->string_pool.MakeRef("one"))};
+  ASSERT_TRUE(table->AddResource(test::ParseNameOrDie("com.pkg:plurals/foo"), ConfigDescription{},
+                                 {}, std::move(plural), context->GetDiagnostics()));
+  std::unique_ptr<Plural> expected = util::make_unique<Plural>();
+  expected->values = {util::make_unique<String>(table->string_pool.MakeRef("[žéÅ•ö one]")),
+                      util::make_unique<String>(table->string_pool.MakeRef("[öñé one]"))};
+
+  PseudolocaleGenerator generator;
+  ASSERT_TRUE(generator.Consume(context.get(), table.get()));
+
+  const auto* actual = test::GetValueForConfig<Plural>(table.get(), "com.pkg:plurals/foo",
+                                                       test::ParseConfigOrDie("en-rXA"));
+  EXPECT_TRUE(actual->Equals(expected.get()));
+}
+
 TEST(PseudolocaleGeneratorTest, RespectUntranslateableSections) {
   std::unique_ptr<IAaptContext> context =
       test::ContextBuilder().SetCompilationPackage("android").Build();
diff --git a/tools/aapt2/format/Container.cpp b/tools/aapt2/format/Container.cpp
index f189048..9cef7b3 100644
--- a/tools/aapt2/format/Container.cpp
+++ b/tools/aapt2/format/Container.cpp
@@ -30,6 +30,7 @@
 
 constexpr const static uint32_t kContainerFormatMagic = 0x54504141u;
 constexpr const static uint32_t kContainerFormatVersion = 1u;
+constexpr const static size_t kPaddingAlignment = 4u;
 
 ContainerWriter::ContainerWriter(ZeroCopyOutputStream* out, size_t entry_count)
     : out_(out), total_entry_count_(entry_count), current_entry_count_(0u) {
@@ -49,11 +50,17 @@
   }
 }
 
-inline static void WritePadding(int padding, CodedOutputStream* out) {
-  if (padding < 4) {
-    const uint32_t zero = 0u;
-    out->WriteRaw(&zero, padding);
-  }
+inline static size_t CalculatePaddingForAlignment(size_t size) {
+  size_t overage = size % kPaddingAlignment;
+  return overage == 0 ? 0 : kPaddingAlignment - overage;
+}
+
+inline static void WritePadding(size_t padding, CodedOutputStream* out) {
+  CHECK(padding < kPaddingAlignment);
+  const uint32_t zero = 0u;
+  static_assert(sizeof(zero) >= kPaddingAlignment, "Not enough source bytes for padding");
+
+  out->WriteRaw(&zero, padding);
 }
 
 bool ContainerWriter::AddResTableEntry(const pb::ResourceTable& table) {
@@ -70,7 +77,7 @@
 
   // Write the aligned size.
   const ::google::protobuf::uint64 size = table.ByteSize();
-  const int padding = 4 - (size % 4);
+  const int padding = CalculatePaddingForAlignment(size);
   coded_out.WriteLittleEndian64(size);
 
   // Write the table.
@@ -103,9 +110,9 @@
 
   // Write the aligned size.
   const ::google::protobuf::uint32 header_size = file.ByteSize();
-  const int header_padding = 4 - (header_size % 4);
+  const int header_padding = CalculatePaddingForAlignment(header_size);
   const ::google::protobuf::uint64 data_size = in->TotalSize();
-  const int data_padding = 4 - (data_size % 4);
+  const int data_padding = CalculatePaddingForAlignment(data_size);
   coded_out.WriteLittleEndian64(kResFileEntryHeaderSize + header_size + header_padding + data_size +
                                 data_padding);
 
diff --git a/tools/aapt2/formats.md b/tools/aapt2/formats.md
index bb31a00..25a0e79 100644
--- a/tools/aapt2/formats.md
+++ b/tools/aapt2/formats.md
@@ -23,7 +23,7 @@
 | Size (in bytes) | Field          | Description                                                                                               |
 |:----------------|:---------------|:----------------------------------------------------------------------------------------------------------|
 | `4`             | `entry_type`   | The type of the entry. This can be one of two types: `RES_TABLE (0x00000000)` or `RES_FILE (0x00000001)`. |
-| `8`             | `entry_length` | The length of the data that follows.                                                                      |
+| `8`             | `entry_length` | The length of the data that follows.  Do not use if `entry_type` is `RES_FILE`; this value may be wrong.  |
 | `entry_length`  | `data`         | The payload. The contents of this varies based on the `entry_type`.                                       |
 
 If the `entry_type` is equal to `RES_TABLE (0x00000000)`, the `data` field contains a serialized
@@ -32,13 +32,14 @@
 If the `entry_type` is equal to `RES_FILE (0x00000001)`, the `data` field contains the following:
 
 
-| Size (in bytes) | Field          | Description                                                                                               |
-|:----------------|:---------------|:----------------------------------------------------------------------------------------------------------|
-| `4`             | `header_size`  | The size of the `header` field.                                                                 |
-| `8`             | `data_size`    | The size of the `data` field.                                                                   |
-| `header_size`   | `header`       | The serialized Protobuf message [aapt.pb.internal.CompiledFile](ResourcesInternal.proto).       |
-| `x`             | `padding`      | Up to 4 bytes of zeros, if padding is necessary to align the `data` field on a 32-bit boundary. |
-| `data_size`     | `data`         | The payload, which is determined by the `type` field in the `aapt.pb.internal.CompiledFile`. This can be a PNG file, binary XML, or [aapt.pb.XmlNode](Resources.proto). |
+| Size (in bytes) | Field            | Description                                                                                               |
+|:----------------|:-----------------|:----------------------------------------------------------------------------------------------------------|
+| `4`             | `header_size`    | The size of the `header` field.                                                                           |
+| `8`             | `data_size`      | The size of the `data` field.                                                                             |
+| `header_size`   | `header`         | The serialized Protobuf message [aapt.pb.internal.CompiledFile](ResourcesInternal.proto).                 |
+| `x`             | `header_padding` | Up to 3 bytes of zeros, if padding is necessary to align the `data` field on a 32-bit boundary.           |
+| `data_size`     | `data`           | The payload, which is determined by the `type` field in the `aapt.pb.internal.CompiledFile`. This can be a PNG file, binary XML, or [aapt.pb.XmlNode](Resources.proto). |
+| `y`             | `data_padding`   | Up to 3 bytes of zeros, if `data_size` is not a multiple of 4.                                            |
 
 ## AAPT2 Static Library Format (extension `.sapk`)
 
diff --git a/tools/aapt2/java/ProguardRules.h b/tools/aapt2/java/ProguardRules.h
index f9656d1..b15df59 100644
--- a/tools/aapt2/java/ProguardRules.h
+++ b/tools/aapt2/java/ProguardRules.h
@@ -99,11 +99,13 @@
 //
 
 inline bool operator==(const UsageLocation& lhs, const UsageLocation& rhs) {
+  // The "source" member is ignored because we only need "name" for outputting
+  // keep rules; "source" is used for comments.
   return lhs.name == rhs.name;
 }
 
-inline int operator<(const UsageLocation& lhs, const UsageLocation& rhs) {
-  return lhs.name.compare(rhs.name);
+inline bool operator<(const UsageLocation& lhs, const UsageLocation& rhs) {
+  return lhs.name.compare(rhs.name) < 0;
 }
 
 //
diff --git a/tools/aapt2/java/ProguardRules_test.cpp b/tools/aapt2/java/ProguardRules_test.cpp
index 559b07a..25b55ab 100644
--- a/tools/aapt2/java/ProguardRules_test.cpp
+++ b/tools/aapt2/java/ProguardRules_test.cpp
@@ -364,4 +364,12 @@
     "-keep class com.foo.Bar { <init>(android.content.Context, android.util.AttributeSet); }"));
 }
 
+TEST(ProguardRulesTest, UsageLocationComparator) {
+  proguard::UsageLocation location1 = {{"pkg", ResourceType::kAttr, "x"}};
+  proguard::UsageLocation location2 = {{"pkg", ResourceType::kAttr, "y"}};
+
+  EXPECT_EQ(location1 < location2, true);
+  EXPECT_EQ(location2 < location1, false);
+}
+
 }  // namespace aapt
diff --git a/tools/apilint/apilint b/tools/apilint/apilint
deleted file mode 100755
index e42857f..0000000
--- a/tools/apilint/apilint
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/bin/bash
-
-# 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.
-
-if [ "$1" == "--help" -o "$1" == "-h" ]; then
-echo "Usage: apilint [FILTERS...]"
-echo "  Shows lint from currently open files (as diffed from HEAD), i.e. errors"
-echo "  you will receive if you upload this CL."
-echo
-echo "Usage: apilint --all [FILTERS...]"
-echo "  Shows all lint errors present in the current working directory, regardless"
-echo "  of when they were added."
-echo
-echo "Usage: apilint --level API_LEVEL [FILTERS...]"
-echo "  Shows lint as it stands in API_LEVEL"
-echo
-echo "Usage: apilint --shal SHA [FILTERS...]"
-echo "  Shows lint from locally commited git change SHA."
-echo
-echo "Usage: apilint --unreleased [FILTERS...]"
-echo "  Shows all lint errors in the current working directory directory added since"
-echo "  the last released SDK version."
-echo
-echo "FILTERS"
-echo "  List of class or package names by which to filter the results."
-echo
-exit
-fi
-
-if [ \( -z "$ANDROID_BUILD_TOP" \) \
-           -a \( ! -f frameworks/base/api/current.txt \) \
-           -a \( ! -f frameworks/base/api/system-current.txt \) \
-        ]; then
-    echo "apilint must be run either with ANDROID_BUILD_TOP set or from the" 1>&2
-    echo "root of the android source tree" 1>&2
-    exit 1
-fi
-
-if [ ${ANDROID_BUILD_TOP:0:1} != "/" ]; then
-    echo "ANDROID_BUILD_TOP must be an absolute path, not: $ANDROID_BUILD_TOP" 1>&2
-    exit 1
-fi
-
-if [ -z "$ANDROID_BUILD_TOP" ]; then
-    ANDROID_BUILD_TOP=$(pwd)
-fi
-
-FW_BASE=$ANDROID_BUILD_TOP/frameworks/base
-
-MODE=open
-
-OPTIONS=$(getopt -n apilint -o "" -l "all,sha:,unreleased" -- "$@")
-
-[ $? -eq 0 ] || { 
-    exit 1
-}
-
-eval set -- "$OPTIONS"
-while true; do
-    case "$1" in
-    --all)
-        MODE=all
-        ;;
-    --sha)
-        shift; # The arg is next in position args
-        MODE=sha
-        SHA=$1
-        ;;
-    --unreleased)
-        MODE=unreleased
-        ;;
-    --)
-        shift
-        break
-        ;;
-    esac
-    shift
-done
-FILTERS=
-for var in "$@"
-do
-    FILTERS="$FILTERS --filter $var"
-done
-
-if [ $MODE = "all" ]; then
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SDK" \
-            $FILTERS \
-            $ANDROID_BUILD_TOP/frameworks/base/api/current.txt
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SystemApi" \
-            $FILTERS \
-            --base-current $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \
-            $ANDROID_BUILD_TOP/frameworks/base/api/system-current.txt
-elif [ $MODE = "open" ]; then
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SDK" \
-            $FILTERS \
-            $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \
-            <(cd $FW_BASE ; git show HEAD:api/current.txt)
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SystemApi" \
-            $FILTERS \
-            --base-current $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \
-            --base-previous <(cd $FW_BASE ; git show HEAD:api/current.txt) \
-            $ANDROID_BUILD_TOP/frameworks/base/api/system-current.txt \
-            <(cd $FW_BASE ; git show HEAD:api/system-current.txt)
-elif [ $MODE = "sha" ]; then
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SDK" \
-            $FILTERS \
-            <(cd $FW_BASE ; git show $SHA:api/current.txt) \
-            <(cd $FW_BASE ; git show $SHA^:api/current.txt)
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SystemApi" \
-            $FILTERS \
-            --base-current <(cd $FW_BASE ; git show $SHA:api/current.txt) \
-            --base-previous <(cd $FW_BASE ; git show $SHA^:api/current.txt) \
-            <(cd $FW_BASE ; git show $SHA:api/system-current.txt) \
-            <(cd $FW_BASE ; git show $SHA^:api/system-current.txt)
-elif [ $MODE = "unreleased" ]; then
-    LAST_SDK=$(ls $ANDROID_BUILD_TOP/prebuilts/sdk | grep "^[0-9][0-9]*$" | sort -n | tail -n 1)
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SDK" \
-            $FILTERS \
-            $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \
-            $ANDROID_BUILD_TOP/prebuilts/sdk/$LAST_SDK/public/api/android.txt
-    python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \
-            --title "SystemApi" \
-            $FILTERS \
-            --base-current $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \
-            --base-previous $ANDROID_BUILD_TOP/prebuilts/sdk/$LAST_SDK/public/api/android.txt \
-            $ANDROID_BUILD_TOP/frameworks/base/api/system-current.txt \
-            $ANDROID_BUILD_TOP/prebuilts/sdk/$LAST_SDK/system/api/android.txt
-fi
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py
deleted file mode 100644
index 912c1ad..0000000
--- a/tools/apilint/apilint.py
+++ /dev/null
@@ -1,2353 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (C) 2014 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.
-
-"""
-Enforces common Android public API design patterns.  It ignores lint messages from
-a previous API level, if provided.
-
-Usage: apilint.py current.txt
-Usage: apilint.py current.txt previous.txt
-
-You can also splice in blame details like this:
-$ git blame api/current.txt -t -e > /tmp/currentblame.txt
-$ apilint.py /tmp/currentblame.txt previous.txt --no-color
-"""
-
-import re, sys, collections, traceback, argparse, itertools
-
-
-BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
-
-ALLOW_GOOGLE = False
-USE_COLOR = True
-
-def format(fg=None, bg=None, bright=False, bold=False, dim=False, reset=False):
-    # manually derived from http://en.wikipedia.org/wiki/ANSI_escape_code#Codes
-    if not USE_COLOR: return ""
-    codes = []
-    if reset: codes.append("0")
-    else:
-        if not fg is None: codes.append("3%d" % (fg))
-        if not bg is None:
-            if not bright: codes.append("4%d" % (bg))
-            else: codes.append("10%d" % (bg))
-        if bold: codes.append("1")
-        elif dim: codes.append("2")
-        else: codes.append("22")
-    return "\033[%sm" % (";".join(codes))
-
-
-class Field():
-    def __init__(self, clazz, line, raw, blame, sig_format = 1):
-        self.clazz = clazz
-        self.line = line
-        self.raw = raw.strip(" {;")
-        self.blame = blame
-
-        if sig_format == 2:
-            V2LineParser(raw).parse_into_field(self)
-        elif sig_format == 1:
-            # drop generics for now; may need multiple passes
-            raw = re.sub("<[^<]+?>", "", raw)
-            raw = re.sub("<[^<]+?>", "", raw)
-
-            raw = raw.split()
-            self.split = list(raw)
-
-            for r in ["field", "volatile", "transient", "public", "protected", "static", "final", "deprecated"]:
-                while r in raw: raw.remove(r)
-
-            # ignore annotations for now
-            raw = [ r for r in raw if not r.startswith("@") ]
-
-            self.typ = raw[0]
-            self.name = raw[1].strip(";")
-            if len(raw) >= 4 and raw[2] == "=":
-                self.value = raw[3].strip(';"')
-            else:
-                self.value = None
-            self.annotations = []
-
-        self.ident = "-".join((self.typ, self.name, self.value or ""))
-
-    def __hash__(self):
-        return hash(self.raw)
-
-    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
-        self.line = line
-        self.raw = raw.strip(" {;")
-        self.blame = blame
-
-        if sig_format == 2:
-            V2LineParser(raw).parse_into_method(self)
-        elif sig_format == 1:
-            # drop generics for now; may need multiple passes
-            raw = re.sub("<[^<]+?>", "", raw)
-            raw = re.sub("<[^<]+?>", "", raw)
-
-            # handle each clause differently
-            raw_prefix, raw_args, _, raw_throws = re.match(r"(.*?)\((.*?)\)( throws )?(.*?);$", raw).groups()
-
-            # parse prefixes
-            raw = re.split("[\s]+", raw_prefix)
-            for r in ["", ";"]:
-                while r in raw: raw.remove(r)
-            self.split = list(raw)
-
-            for r in ["method", "public", "protected", "static", "final", "deprecated", "abstract", "default", "operator", "synchronized"]:
-                while r in raw: raw.remove(r)
-
-            self.typ = raw[0]
-            self.name = raw[1]
-
-            # parse 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.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):
-        return typ == self.typ and name == self.name and args == self.args
-
-    def __hash__(self):
-        return hash(self.raw)
-
-    def __repr__(self):
-        return self.raw
-
-
-class Class():
-    def __init__(self, pkg, line, raw, blame, sig_format = 1):
-        self.pkg = pkg
-        self.line = line
-        self.raw = raw.strip(" {;")
-        self.blame = blame
-        self.ctors = []
-        self.fields = []
-        self.methods = []
-        self.annotations = []
-
-        if sig_format == 2:
-            V2LineParser(raw).parse_into_class(self)
-        elif sig_format == 1:
-            # drop generics for now; may need multiple passes
-            raw = re.sub("<[^<]+?>", "", raw)
-            raw = re.sub("<[^<]+?>", "", raw)
-
-            raw = raw.split()
-            self.split = list(raw)
-            if "class" in raw:
-                self.fullname = raw[raw.index("class")+1]
-            elif "interface" in raw:
-                self.fullname = raw[raw.index("interface")+1]
-            elif "@interface" in raw:
-                self.fullname = raw[raw.index("@interface")+1]
-            else:
-                raise ValueError("Funky class type %s" % (self.raw))
-
-            if "extends" in raw:
-                self.extends = raw[raw.index("extends")+1]
-            else:
-                self.extends = None
-
-            if "implements" in raw:
-                self.implements = raw[raw.index("implements")+1]
-                self.implements_all = [self.implements]
-            else:
-                self.implements = None
-                self.implements_all = []
-        else:
-            raise ValueError("Unknown signature format: " + sig_format)
-
-        self.fullname = self.pkg.name + "." + self.fullname
-        self.fullname_path = self.fullname.split(".")
-
-        if self.extends is not None:
-            self.extends_path = self.extends.split(".")
-        else:
-            self.extends_path = []
-
-        self.name = self.fullname[self.fullname.rindex(".")+1:]
-
-    def merge_from(self, other):
-        self.ctors.extend(other.ctors)
-        self.fields.extend(other.fields)
-        self.methods.extend(other.methods)
-
-    def __hash__(self):
-        return hash((self.raw, tuple(self.ctors), tuple(self.fields), tuple(self.methods)))
-
-    def __repr__(self):
-        return self.raw
-
-
-class Package():
-    NAME = re.compile("package(?: .*)? ([A-Za-z0-9.]+)")
-
-    def __init__(self, line, raw, blame):
-        self.line = line
-        self.raw = raw.strip(" {;")
-        self.blame = blame
-
-        self.name = Package.NAME.match(raw).group(1)
-        self.name_path = self.name.split(".")
-
-    def __repr__(self):
-        return self.raw
-
-class V2Tokenizer(object):
-    __slots__ = ["raw"]
-
-    SIGNATURE_PREFIX = "// Signature format: "
-    DELIMITER = re.compile(r'\s+|[()@<>;,={}/"!?]|\[\]|\.\.\.')
-    STRING_SPECIAL = re.compile(r'["\\]')
-
-    def __init__(self, raw):
-        self.raw = raw
-
-    def tokenize(self):
-        tokens = []
-        current = 0
-        raw = self.raw
-        length = len(raw)
-
-        while current < length:
-            while current < length:
-                start = current
-                match = V2Tokenizer.DELIMITER.search(raw, start)
-                if match is not None:
-                    match_start = match.start()
-                    if match_start == current:
-                        end = match.end()
-                    else:
-                        end = match_start
-                else:
-                    end = length
-
-                token = raw[start:end]
-                current = end
-
-                if token == "" or token[0] == " ":
-                    continue
-                else:
-                    break
-
-            if token == "@":
-                if raw[start:start+11] == "@interface ":
-                    current = start + 11
-                    tokens.append("@interface")
-                    continue
-            elif token == '/':
-                if raw[start:start+2] == "//":
-                    current = length
-                    continue
-            elif token == '"':
-                current, string_token = self.tokenize_string(raw, length, current)
-                tokens.append(token + string_token)
-                continue
-
-            tokens.append(token)
-
-        return tokens
-
-    def tokenize_string(self, raw, length, current):
-        start = current
-        end = length
-        while start < end:
-            match = V2Tokenizer.STRING_SPECIAL.search(raw, start)
-            if match:
-                if match.group() == '"':
-                    end = match.end()
-                    break
-                elif match.group() == '\\':
-                    # ignore whatever is after the slash
-                    start += 2
-                else:
-                    raise ValueError("Unexpected match: `%s`" % (match.group()))
-            else:
-                raise ValueError("Unexpected EOF tokenizing string: `%s`" % (raw[current - 1:],))
-
-        token = raw[current:end]
-        return end, token
-
-class V2LineParser(object):
-    __slots__ = ["tokenized", "current", "len"]
-
-    FIELD_KINDS = ("field", "property", "enum_constant")
-    MODIFIERS = set("public protected internal private abstract default static final transient volatile synchronized native operator sealed strictfp infix inline suspend vararg".split())
-    JAVA_LANG_TYPES = set("AbstractMethodError AbstractStringBuilder Appendable ArithmeticException ArrayIndexOutOfBoundsException ArrayStoreException AssertionError AutoCloseable Boolean BootstrapMethodError Byte Character CharSequence Class ClassCastException ClassCircularityError ClassFormatError ClassLoader ClassNotFoundException Cloneable CloneNotSupportedException Comparable Compiler Deprecated Double Enum EnumConstantNotPresentException Error Exception ExceptionInInitializerError Float FunctionalInterface IllegalAccessError IllegalAccessException IllegalArgumentException IllegalMonitorStateException IllegalStateException IllegalThreadStateException IncompatibleClassChangeError IndexOutOfBoundsException InheritableThreadLocal InstantiationError InstantiationException Integer InternalError InterruptedException Iterable LinkageError Long Math NegativeArraySizeException NoClassDefFoundError NoSuchFieldError NoSuchFieldException NoSuchMethodError NoSuchMethodException NullPointerException Number NumberFormatException Object OutOfMemoryError Override Package package-info.java Process ProcessBuilder ProcessEnvironment ProcessImpl Readable ReflectiveOperationException Runnable Runtime RuntimeException RuntimePermission SafeVarargs SecurityException SecurityManager Short StackOverflowError StackTraceElement StrictMath String StringBuffer StringBuilder StringIndexOutOfBoundsException SuppressWarnings System Thread ThreadDeath ThreadGroup ThreadLocal Throwable TypeNotPresentException UNIXProcess UnknownError UnsatisfiedLinkError UnsupportedClassVersionError UnsupportedOperationException VerifyError VirtualMachineError Void".split())
-
-    def __init__(self, raw):
-        self.tokenized = V2Tokenizer(raw).tokenize()
-        self.current = 0
-        self.len = len(self.tokenized)
-
-    def parse_into_method(self, method):
-        method.split = []
-        kind = self.parse_one_of("ctor", "method")
-        method.split.append(kind)
-        method.annotations = self.parse_annotations()
-        method.split.extend(self.parse_modifiers())
-        self.parse_matching_paren("<", ">")
-        if "@Deprecated" in method.annotations:
-            method.split.append("deprecated")
-        if kind == "ctor":
-            method.typ = "ctor"
-        else:
-            method.typ = self.parse_type()
-            method.split.append(method.typ)
-        method.name = self.parse_name()
-        method.split.append(method.name)
-        self.parse_token("(")
-        method.detailed_args = self.parse_args()
-        self.parse_token(")")
-        method.throws = self.parse_throws()
-        if "@interface" in method.clazz.split:
-            self.parse_annotation_default()
-        self.parse_token(";")
-        self.parse_eof()
-
-    def parse_into_class(self, clazz):
-        clazz.split = []
-        clazz.annotations = self.parse_annotations()
-        if "@Deprecated" in clazz.annotations:
-            clazz.split.append("deprecated")
-        clazz.split.extend(self.parse_modifiers())
-        kind = self.parse_one_of("class", "interface", "@interface", "enum")
-        if kind == "enum":
-            # enums are implicitly final
-            clazz.split.append("final")
-        clazz.split.append(kind)
-        clazz.fullname = self.parse_name()
-        self.parse_matching_paren("<", ">")
-        extends = self.parse_extends()
-        clazz.extends = extends[0] if extends else None
-        clazz.implements_all = self.parse_implements()
-        # The checks assume that interfaces are always found in implements, which isn't true for
-        # subinterfaces.
-        if not clazz.implements_all and "interface" in clazz.split:
-            clazz.implements_all = [clazz.extends]
-        clazz.implements = clazz.implements_all[0] if clazz.implements_all else None
-        self.parse_token("{")
-        self.parse_eof()
-
-    def parse_into_field(self, field):
-        kind = self.parse_one_of(*V2LineParser.FIELD_KINDS)
-        field.split = [kind]
-        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()
-        field.split.append(field.typ)
-        field.name = self.parse_name()
-        field.split.append(field.name)
-        if self.parse_if("="):
-            field.value = self.parse_value_stripped()
-        else:
-            field.value = None
-
-        self.parse_token(";")
-        self.parse_eof()
-
-    def lookahead(self):
-        return self.tokenized[self.current]
-
-    def parse_one_of(self, *options):
-        found = self.lookahead()
-        if found not in options:
-            raise ValueError("Parsing failed, expected one of `%s` but found `%s` in %s" % (options, found, repr(self.tokenized)))
-        return self.parse_token()
-
-    def parse_token(self, tok = None):
-        found = self.lookahead()
-        if tok is not None and found != tok:
-            raise ValueError("Parsing failed, expected `%s` but found `%s` in %s" % (tok, found, repr(self.tokenized)))
-        self.current += 1
-        return found
-
-    def eof(self):
-        return self.current == self.len
-
-    def parse_eof(self):
-        if not self.eof():
-            raise ValueError("Parsing failed, expected EOF, but %s has not been parsed in %s" % (self.tokenized[self.current:], self.tokenized))
-
-    def parse_if(self, tok):
-        if not self.eof() and self.lookahead() == tok:
-            self.parse_token()
-            return True
-        return False
-
-    def parse_annotations(self):
-        ret = []
-        while self.lookahead() == "@":
-            ret.append(self.parse_annotation())
-        return ret
-
-    def parse_annotation(self):
-        ret = self.parse_token("@") + self.parse_token()
-        self.parse_matching_paren("(", ")")
-        return ret
-
-    def parse_matching_paren(self, open, close):
-        start = self.current
-        if not self.parse_if(open):
-            return
-        length = len(self.tokenized)
-        count = 1
-        while count > 0:
-            if self.current == length:
-                raise ValueError("Unexpected EOF looking for closing paren: `%s`" % (self.tokenized[start:],))
-            t = self.parse_token()
-            if t == open:
-                count += 1
-            elif t == close:
-                count -= 1
-        return self.tokenized[start:self.current]
-
-    def parse_modifiers(self):
-        ret = []
-        while self.lookahead() in V2LineParser.MODIFIERS:
-            ret.append(self.parse_token())
-        return ret
-
-    def parse_kotlin_nullability(self):
-        t = self.lookahead()
-        if t == "?" or t == "!":
-            return self.parse_token()
-        return None
-
-    def parse_type(self):
-        self.parse_annotations()
-        type = self.parse_token()
-        if type[-1] == '.':
-            self.parse_annotations()
-            type += self.parse_token()
-        if type in V2LineParser.JAVA_LANG_TYPES:
-            type = "java.lang." + type
-        self.parse_matching_paren("<", ">")
-        while True:
-            t = self.lookahead()
-            if t == "@":
-                self.parse_annotation()
-            elif t == "[]":
-                type += self.parse_token()
-            elif self.parse_kotlin_nullability() is not None:
-                pass  # discard nullability for now
-            else:
-                break
-        return type
-
-    def parse_arg_type(self):
-        type = self.parse_type()
-        if self.parse_if("..."):
-            type += "..."
-        self.parse_kotlin_nullability() # discard nullability for now
-        return type
-
-    def parse_name(self):
-        return self.parse_token()
-
-    def parse_args(self):
-        args = []
-        if self.lookahead() == ")":
-            return args
-
-        while True:
-            args.append(self.parse_arg())
-            if self.lookahead() == ")":
-                return args
-            self.parse_token(",")
-
-    def parse_arg(self):
-        self.parse_if("vararg")  # kotlin vararg
-        annotations = self.parse_annotations()
-        arg = Argument(self.parse_arg_type())
-        arg.annotations = annotations
-        l = self.lookahead()
-        if l != "," and l != ")":
-            if self.lookahead() != '=':
-                arg.name = self.parse_token()  # kotlin argument name
-            if self.parse_if('='): # kotlin default value
-                arg.default = self.parse_expression()
-        return arg
-
-    def parse_expression(self):
-        while not self.lookahead() in [')', ',', ';']:
-            (self.parse_matching_paren('(', ')') or
-            self.parse_matching_paren('{', '}') or
-            self.parse_token())
-
-    def parse_throws(self):
-        ret = []
-        if self.parse_if("throws"):
-            ret.append(self.parse_type())
-            while self.parse_if(","):
-                ret.append(self.parse_type())
-        return ret
-
-    def parse_extends(self):
-        if self.parse_if("extends"):
-            return self.parse_space_delimited_type_list()
-        return []
-
-    def parse_implements(self):
-        if self.parse_if("implements"):
-            return self.parse_space_delimited_type_list()
-        return []
-
-    def parse_space_delimited_type_list(self, terminals = ["implements", "{"]):
-        types = []
-        while True:
-            types.append(self.parse_type())
-            if self.lookahead() in terminals:
-                return types
-
-    def parse_annotation_default(self):
-        if self.parse_if("default"):
-            self.parse_expression()
-
-    def parse_value(self):
-        if self.lookahead() == "{":
-            return " ".join(self.parse_matching_paren("{", "}"))
-        elif self.lookahead() == "(":
-            return " ".join(self.parse_matching_paren("(", ")"))
-        else:
-            return self.parse_token()
-
-    def parse_value_stripped(self):
-        value = self.parse_value()
-        if value[0] == '"':
-            return value[1:-1]
-        return value
-
-
-def _parse_stream(f, clazz_cb=None, base_f=None, out_classes_with_base=None,
-                  in_classes_with_base=[]):
-    api = {}
-    in_classes_with_base = _retry_iterator(in_classes_with_base)
-
-    if base_f:
-        base_classes = _retry_iterator(_parse_stream_to_generator(base_f))
-    else:
-        base_classes = []
-
-    def handle_class(clazz):
-        if clazz_cb:
-            clazz_cb(clazz)
-        else: # In callback mode, don't keep track of the full API
-            api[clazz.fullname] = clazz
-
-    def handle_missed_classes_with_base(clazz):
-        for c in _yield_until_matching_class(in_classes_with_base, clazz):
-            base_class = _skip_to_matching_class(base_classes, c)
-            if base_class:
-                handle_class(base_class)
-
-    for clazz in _parse_stream_to_generator(f):
-        # Before looking at clazz, let's see if there's some classes that were not present, but
-        # may have an entry in the base stream.
-        handle_missed_classes_with_base(clazz)
-
-        base_class = _skip_to_matching_class(base_classes, clazz)
-        if base_class:
-            clazz.merge_from(base_class)
-            if out_classes_with_base is not None:
-                out_classes_with_base.append(clazz)
-        handle_class(clazz)
-
-    handle_missed_classes_with_base(None)
-
-    return api
-
-def _parse_stream_to_generator(f):
-    line = 0
-    pkg = None
-    clazz = None
-    blame = None
-    sig_format = 1
-
-    re_blame = re.compile(r"^(\^?[a-z0-9]{7,}) \(<([^>]+)>.+?\) (.+?)$")
-
-    field_prefixes = map(lambda kind: "    %s" % (kind,), V2LineParser.FIELD_KINDS)
-    def startsWithFieldPrefix(raw):
-        for prefix in field_prefixes:
-            if raw.startswith(prefix):
-                return True
-        return False
-
-    for raw in f:
-        line += 1
-        raw = raw.rstrip()
-        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 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
-            else:
-                raise ValueError("Unknown format: %s" % (sig_format_string,))
-        elif raw.startswith("package"):
-            pkg = Package(line, raw, blame)
-        elif raw.startswith("  ") and raw.endswith("{"):
-            clazz = Class(pkg, line, raw, blame, sig_format=sig_format)
-        elif raw.startswith("    ctor"):
-            clazz.ctors.append(Method(clazz, line, raw, blame, sig_format=sig_format))
-        elif raw.startswith("    method"):
-            clazz.methods.append(Method(clazz, line, raw, blame, sig_format=sig_format))
-        elif startsWithFieldPrefix(raw):
-            clazz.fields.append(Field(clazz, line, raw, blame, sig_format=sig_format))
-        elif raw.startswith("  }") and clazz:
-            yield clazz
-
-def _retry_iterator(it):
-    """Wraps an iterator, such that calling send(True) on it will redeliver the same element"""
-    for e in it:
-        while True:
-            retry = yield e
-            if not retry:
-                break
-            # send() was called, asking us to redeliver clazz on next(). Still need to yield
-            # a dummy value to the send() first though.
-            if (yield "Returning clazz on next()"):
-                raise TypeError("send() must be followed by next(), not send()")
-
-def _skip_to_matching_class(classes, needle):
-    """Takes a classes iterator and consumes entries until it returns the class we're looking for
-
-    This relies on classes being sorted by package and class name."""
-
-    for clazz in classes:
-        if clazz.pkg.name < needle.pkg.name:
-            # We haven't reached the right package yet
-            continue
-        if clazz.pkg.name == needle.pkg.name and clazz.fullname < needle.fullname:
-            # We're in the right package, but not the right class yet
-            continue
-        if clazz.fullname == needle.fullname:
-            return clazz
-        # We ran past the right class. Send it back into the generator, then report failure.
-        classes.send(clazz)
-        return None
-
-def _yield_until_matching_class(classes, needle):
-    """Takes a class iterator and yields entries it until it reaches the class we're looking for.
-
-    This relies on classes being sorted by package and class name."""
-
-    for clazz in classes:
-        if needle is None:
-            yield clazz
-        elif clazz.pkg.name < needle.pkg.name:
-            # We haven't reached the right package yet
-            yield clazz
-        elif clazz.pkg.name == needle.pkg.name and clazz.fullname < needle.fullname:
-            # We're in the right package, but not the right class yet
-            yield clazz
-        elif clazz.fullname == needle.fullname:
-            # Class found, abort.
-            return
-        else:
-            # We ran past the right class. Send it back into the iterator, then abort.
-            classes.send(clazz)
-            return
-
-class Failure():
-    def __init__(self, sig, clazz, detail, error, rule, msg):
-        self.clazz = clazz
-        self.sig = sig
-        self.error = error
-        self.rule = rule
-        self.msg = msg
-
-        if error:
-            self.head = "Error %s" % (rule) if rule else "Error"
-            dump = "%s%s:%s %s" % (format(fg=RED, bg=BLACK, bold=True), self.head, format(reset=True), msg)
-        else:
-            self.head = "Warning %s" % (rule) if rule else "Warning"
-            dump = "%s%s:%s %s" % (format(fg=YELLOW, bg=BLACK, bold=True), self.head, format(reset=True), msg)
-
-        self.line = clazz.line
-        blame = clazz.blame
-        if detail is not None:
-            dump += "\n    in " + repr(detail)
-            self.line = detail.line
-            blame = detail.blame
-        dump += "\n    in " + repr(clazz)
-        dump += "\n    in " + repr(clazz.pkg)
-        dump += "\n    at line " + repr(self.line)
-        if blame is not None:
-            dump += "\n    last modified by %s in %s" % (blame[1], blame[0])
-
-        self.dump = dump
-
-    def __repr__(self):
-        return self.dump
-
-
-failures = {}
-
-def _fail(clazz, detail, error, rule, msg):
-    """Records an API failure to be processed later."""
-    global failures
-
-    sig = "%s-%s-%s" % (clazz.fullname, detail.ident if detail else None, msg)
-    sig = sig.replace(" deprecated ", " ")
-
-    failures[sig] = Failure(sig, clazz, detail, error, rule, msg)
-
-
-def warn(clazz, detail, rule, msg):
-    _fail(clazz, detail, False, rule, msg)
-
-def error(clazz, detail, rule, msg):
-    _fail(clazz, detail, True, rule, msg)
-
-
-noticed = {}
-
-def notice(clazz):
-    global noticed
-
-    noticed[clazz.fullname] = hash(clazz)
-
-
-verifiers = {}
-
-def verifier(f):
-    verifiers[f.__name__] = f
-    return f
-
-
-@verifier
-def verify_constants(clazz):
-    """All static final constants must be FOO_NAME style."""
-    if re.match("android\.R\.[a-z]+", clazz.fullname): return
-    if clazz.fullname.startswith("android.os.Build"): return
-    if clazz.fullname == "android.system.OsConstants": return
-
-    req = ["java.lang.String","byte","short","int","long","float","double","boolean","char"]
-    for f in clazz.fields:
-        if "static" in f.split and "final" in f.split:
-            if re.match("[A-Z0-9_]+", f.name) is None:
-                error(clazz, f, "C2", "Constant field names must be FOO_NAME")
-            if f.typ != "java.lang.String":
-                if f.name.startswith("MIN_") or f.name.startswith("MAX_"):
-                    warn(clazz, f, "C8", "If min/max could change in future, make them dynamic methods")
-            if f.typ in req and f.value is None:
-                error(clazz, f, None, "All constants must be defined at compile time")
-
-@verifier
-def verify_enums(clazz):
-    """Enums are bad, mmkay?"""
-    if clazz.extends == "java.lang.Enum" or "enum" in clazz.split:
-        error(clazz, None, "F5", "Enums are not allowed")
-
-@verifier
-def verify_class_names(clazz):
-    """Try catching malformed class names like myMtp or MTPUser."""
-    if clazz.fullname.startswith("android.opengl"): return
-    if clazz.fullname.startswith("android.renderscript"): return
-    if re.match("android\.R\.[a-z]+", clazz.fullname): return
-
-    if re.search("[A-Z]{2,}", clazz.name) is not None:
-        warn(clazz, None, "S1", "Class names with acronyms should be Mtp not MTP")
-    if re.match("[^A-Z]", clazz.name):
-        error(clazz, None, "S1", "Class must start with uppercase char")
-    if clazz.name.endswith("Impl"):
-        error(clazz, None, None, "Don't expose your implementation details")
-
-
-@verifier
-def verify_method_names(clazz):
-    """Try catching malformed method names, like Foo() or getMTU()."""
-    if clazz.fullname.startswith("android.opengl"): return
-    if clazz.fullname.startswith("android.renderscript"): return
-    if clazz.fullname == "android.system.OsConstants": return
-
-    for m in clazz.methods:
-        if re.search("[A-Z]{2,}", m.name) is not None:
-            warn(clazz, m, "S1", "Method names with acronyms should be getMtu() instead of getMTU()")
-        if re.match("[^a-z]", m.name):
-            error(clazz, m, "S1", "Method name must start with lowercase char")
-
-
-@verifier
-def verify_callbacks(clazz):
-    """Verify Callback classes.
-    All methods must follow onFoo() naming style."""
-    if clazz.fullname == "android.speech.tts.SynthesisCallback": return
-
-    if clazz.name.endswith("Callbacks"):
-        error(clazz, None, "L1", "Callback class names should be singular")
-    if clazz.name.endswith("Observer"):
-        warn(clazz, None, "L1", "Class should be named FooCallback")
-
-    if clazz.name.endswith("Callback"):
-        for m in clazz.methods:
-            if not re.match("on[A-Z][a-z]*", m.name):
-                error(clazz, m, "L1", "Callback method names must be onFoo() style")
-
-
-@verifier
-def verify_listeners(clazz):
-    """Verify Listener classes.
-    All Listener classes must be interface.
-    All methods must follow onFoo() naming style.
-    If only a single method, it must match class name:
-        interface OnFooListener { void onFoo() }"""
-
-    if clazz.name.endswith("Listener"):
-        if "abstract" in clazz.split and "class" in clazz.split:
-            error(clazz, None, "L1", "Listeners should be an interface, or otherwise renamed Callback")
-
-        for m in clazz.methods:
-            if not re.match("on[A-Z][a-z]*", m.name):
-                error(clazz, m, "L1", "Listener method names must be onFoo() style")
-
-        if len(clazz.methods) == 1 and clazz.name.startswith("On"):
-            m = clazz.methods[0]
-            if (m.name + "Listener").lower() != clazz.name.lower():
-                error(clazz, m, "L1", "Single listener method name must match class name")
-
-
-@verifier
-def verify_actions(clazz):
-    """Verify intent actions.
-    All action names must be named ACTION_FOO.
-    All action values must be scoped by package and match name:
-        package android.foo {
-            String ACTION_BAR = "android.foo.action.BAR";
-        }"""
-    for f in clazz.fields:
-        if f.value is None: continue
-        if f.name.startswith("EXTRA_"): continue
-        if f.name == "SERVICE_INTERFACE" or f.name == "PROVIDER_INTERFACE": continue
-        if "INTERACTION" in f.name: continue
-
-        if "static" in f.split and "final" in f.split and f.typ == "java.lang.String":
-            if "_ACTION" in f.name or "ACTION_" in f.name or ".action." in f.value.lower():
-                if not f.name.startswith("ACTION_"):
-                    error(clazz, f, "C3", "Intent action constant name must be ACTION_FOO")
-                else:
-                    if clazz.fullname == "android.content.Intent":
-                        prefix = "android.intent.action"
-                    elif clazz.fullname == "android.provider.Settings":
-                        prefix = "android.settings"
-                    elif clazz.fullname == "android.app.admin.DevicePolicyManager" or clazz.fullname == "android.app.admin.DeviceAdminReceiver":
-                        prefix = "android.app.action"
-                    else:
-                        prefix = clazz.pkg.name + ".action"
-                    expected = prefix + "." + f.name[7:]
-                    if f.value != expected:
-                        error(clazz, f, "C4", "Inconsistent action value; expected '%s'" % (expected))
-
-
-@verifier
-def verify_extras(clazz):
-    """Verify intent extras.
-    All extra names must be named EXTRA_FOO.
-    All extra values must be scoped by package and match name:
-        package android.foo {
-            String EXTRA_BAR = "android.foo.extra.BAR";
-        }"""
-    if clazz.fullname == "android.app.Notification": return
-    if clazz.fullname == "android.appwidget.AppWidgetManager": return
-
-    for f in clazz.fields:
-        if f.value is None: continue
-        if f.name.startswith("ACTION_"): continue
-
-        if "static" in f.split and "final" in f.split and f.typ == "java.lang.String":
-            if "_EXTRA" in f.name or "EXTRA_" in f.name or ".extra" in f.value.lower():
-                if not f.name.startswith("EXTRA_"):
-                    error(clazz, f, "C3", "Intent extra must be EXTRA_FOO")
-                else:
-                    if clazz.pkg.name == "android.content" and clazz.name == "Intent":
-                        prefix = "android.intent.extra"
-                    elif clazz.pkg.name == "android.app.admin":
-                        prefix = "android.app.extra"
-                    else:
-                        prefix = clazz.pkg.name + ".extra"
-                    expected = prefix + "." + f.name[6:]
-                    if f.value != expected:
-                        error(clazz, f, "C4", "Inconsistent extra value; expected '%s'" % (expected))
-
-
-@verifier
-def verify_equals(clazz):
-    """Verify that equals() and hashCode() must be overridden together."""
-    eq = False
-    hc = False
-    for m in clazz.methods:
-        if "static" in m.split: continue
-        if m.sig_matches("boolean", "equals", ["java.lang.Object"]): eq = True
-        if m.sig_matches("int", "hashCode", []): hc = True
-    if eq != hc:
-        error(clazz, None, "M8", "Must override both equals and hashCode; missing one")
-
-
-@verifier
-def verify_parcelable(clazz):
-    """Verify that Parcelable objects aren't hiding required bits."""
-    if clazz.implements == "android.os.Parcelable":
-        creator = [ i for i in clazz.fields if i.name == "CREATOR" ]
-        write = [ i for i in clazz.methods if i.name == "writeToParcel" ]
-        describe = [ i for i in clazz.methods if i.name == "describeContents" ]
-
-        if len(creator) == 0 or len(write) == 0 or len(describe) == 0:
-            error(clazz, None, "FW3", "Parcelable requires CREATOR, writeToParcel, and describeContents; missing one")
-
-        if "final" not in clazz.split:
-            error(clazz, None, "FW8", "Parcelable classes must be final")
-
-        for c in clazz.ctors:
-            if c.args == ["android.os.Parcel"]:
-                error(clazz, c, "FW3", "Parcelable inflation is exposed through CREATOR, not raw constructors")
-
-
-@verifier
-def verify_protected(clazz):
-    """Verify that no protected methods or fields are allowed."""
-    for m in clazz.methods:
-        if m.name == "finalize": continue
-        if "protected" in m.split:
-            error(clazz, m, "M7", "Protected methods not allowed; must be public")
-    for f in clazz.fields:
-        if "protected" in f.split:
-            error(clazz, f, "M7", "Protected fields not allowed; must be public")
-
-
-@verifier
-def verify_fields(clazz):
-    """Verify that all exposed fields are final.
-    Exposed fields must follow myName style.
-    Catch internal mFoo objects being exposed."""
-
-    IGNORE_BARE_FIELDS = [
-        "android.app.ActivityManager.RecentTaskInfo",
-        "android.app.Notification",
-        "android.content.pm.ActivityInfo",
-        "android.content.pm.ApplicationInfo",
-        "android.content.pm.ComponentInfo",
-        "android.content.pm.ResolveInfo",
-        "android.content.pm.FeatureGroupInfo",
-        "android.content.pm.InstrumentationInfo",
-        "android.content.pm.PackageInfo",
-        "android.content.pm.PackageItemInfo",
-        "android.content.res.Configuration",
-        "android.graphics.BitmapFactory.Options",
-        "android.os.Message",
-        "android.system.StructPollfd",
-    ]
-
-    for f in clazz.fields:
-        if not "final" in f.split:
-            if clazz.fullname in IGNORE_BARE_FIELDS:
-                pass
-            elif clazz.fullname.endswith("LayoutParams"):
-                pass
-            elif clazz.fullname.startswith("android.util.Mutable"):
-                pass
-            else:
-                error(clazz, f, "F2", "Bare fields must be marked final, or add accessors if mutable")
-
-        if "static" not in f.split and "property" not in f.split:
-            if not re.match("[a-z]([a-zA-Z]+)?", f.name):
-                error(clazz, f, "S1", "Non-static fields must be named using myField style")
-
-        if re.match("[ms][A-Z]", f.name):
-            error(clazz, f, "F1", "Internal objects must not be exposed")
-
-        if re.match("[A-Z_]+", f.name):
-            if "static" not in f.split or "final" not in f.split:
-                error(clazz, f, "C2", "Constants must be marked static final")
-
-
-@verifier
-def verify_register(clazz):
-    """Verify parity of registration methods.
-    Callback objects use register/unregister methods.
-    Listener objects use add/remove methods."""
-    methods = [ m.name for m in clazz.methods ]
-    for m in clazz.methods:
-        if "Callback" in m.raw:
-            if m.name.startswith("register"):
-                other = "unregister" + m.name[8:]
-                if other not in methods:
-                    error(clazz, m, "L2", "Missing unregister method")
-            if m.name.startswith("unregister"):
-                other = "register" + m.name[10:]
-                if other not in methods:
-                    error(clazz, m, "L2", "Missing register method")
-
-            if m.name.startswith("add") or m.name.startswith("remove"):
-                error(clazz, m, "L3", "Callback methods should be named register/unregister")
-
-        if "Listener" in m.raw:
-            if m.name.startswith("add"):
-                other = "remove" + m.name[3:]
-                if other not in methods:
-                    error(clazz, m, "L2", "Missing remove method")
-            if m.name.startswith("remove") and not m.name.startswith("removeAll"):
-                other = "add" + m.name[6:]
-                if other not in methods:
-                    error(clazz, m, "L2", "Missing add method")
-
-            if m.name.startswith("register") or m.name.startswith("unregister"):
-                error(clazz, m, "L3", "Listener methods should be named add/remove")
-
-
-@verifier
-def verify_sync(clazz):
-    """Verify synchronized methods aren't exposed."""
-    for m in clazz.methods:
-        if "synchronized" in m.split:
-            error(clazz, m, "M5", "Internal locks must not be exposed")
-
-
-@verifier
-def verify_intent_builder(clazz):
-    """Verify that Intent builders are createFooIntent() style."""
-    if clazz.name == "Intent": return
-
-    for m in clazz.methods:
-        if m.typ == "android.content.Intent":
-            if m.name.startswith("create") and m.name.endswith("Intent"):
-                pass
-            else:
-                warn(clazz, m, "FW1", "Methods creating an Intent should be named createFooIntent()")
-
-
-@verifier
-def verify_helper_classes(clazz):
-    """Verify that helper classes are named consistently with what they extend.
-    All developer extendable methods should be named onFoo()."""
-    test_methods = False
-    if clazz.extends == "android.app.Service":
-        test_methods = True
-        if not clazz.name.endswith("Service"):
-            error(clazz, None, "CL4", "Inconsistent class name; should be FooService")
-
-        found = False
-        for f in clazz.fields:
-            if f.name == "SERVICE_INTERFACE":
-                found = True
-                if f.value != clazz.fullname:
-                    error(clazz, f, "C4", "Inconsistent interface constant; expected '%s'" % (clazz.fullname))
-
-    if clazz.extends == "android.content.ContentProvider":
-        test_methods = True
-        if not clazz.name.endswith("Provider"):
-            error(clazz, None, "CL4", "Inconsistent class name; should be FooProvider")
-
-        found = False
-        for f in clazz.fields:
-            if f.name == "PROVIDER_INTERFACE":
-                found = True
-                if f.value != clazz.fullname:
-                    error(clazz, f, "C4", "Inconsistent interface constant; expected '%s'" % (clazz.fullname))
-
-    if clazz.extends == "android.content.BroadcastReceiver":
-        test_methods = True
-        if not clazz.name.endswith("Receiver"):
-            error(clazz, None, "CL4", "Inconsistent class name; should be FooReceiver")
-
-    if clazz.extends == "android.app.Activity":
-        test_methods = True
-        if not clazz.name.endswith("Activity"):
-            error(clazz, None, "CL4", "Inconsistent class name; should be FooActivity")
-
-    if test_methods:
-        for m in clazz.methods:
-            if "final" in m.split: continue
-            if not re.match("on[A-Z]", m.name):
-                if "abstract" in m.split:
-                    warn(clazz, m, None, "Methods implemented by developers should be named onFoo()")
-                else:
-                    warn(clazz, m, None, "If implemented by developer, should be named onFoo(); otherwise consider marking final")
-
-
-@verifier
-def verify_builder(clazz):
-    """Verify builder classes.
-    Methods should return the builder to enable chaining."""
-    if clazz.extends: return
-    if not clazz.name.endswith("Builder"): return
-
-    if clazz.name != "Builder":
-        warn(clazz, None, None, "Builder should be defined as inner class")
-
-    has_build = False
-    for m in clazz.methods:
-        if m.name == "build":
-            has_build = True
-            continue
-
-        if m.name.startswith("get"): continue
-        if m.name.startswith("clear"): continue
-
-        if m.name.startswith("with"):
-            warn(clazz, m, None, "Builder methods names should use setFoo() style")
-
-        if m.name.startswith("set"):
-            if not m.typ.endswith(clazz.fullname):
-                warn(clazz, m, "M4", "Methods must return the builder object")
-
-    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")
-
-
-@verifier
-def verify_aidl(clazz):
-    """Catch people exposing raw AIDL."""
-    if clazz.extends == "android.os.Binder" or clazz.implements == "android.os.IInterface":
-        error(clazz, None, None, "Raw AIDL interfaces must not be exposed")
-
-
-@verifier
-def verify_internal(clazz):
-    """Catch people exposing internal classes."""
-    if clazz.pkg.name.startswith("com.android"):
-        error(clazz, None, None, "Internal classes must not be exposed")
-
-def layering_build_ranking(ranking_list):
-    r = {}
-    for rank, ps in enumerate(ranking_list):
-        if not isinstance(ps, list):
-            ps = [ps]
-        for p in ps:
-            rs = r
-            for n in p.split('.'):
-                if n not in rs:
-                    rs[n] = {}
-                rs = rs[n]
-            rs['-rank'] = rank
-    return r
-
-LAYERING_PACKAGE_RANKING = layering_build_ranking([
-    ["android.service","android.accessibilityservice","android.inputmethodservice","android.printservice","android.appwidget","android.webkit","android.preference","android.gesture","android.print"],
-    "android.app",
-    "android.widget",
-    "android.view",
-    "android.animation",
-    "android.provider",
-    ["android.content","android.graphics.drawable"],
-    "android.database",
-    "android.text",
-    "android.graphics",
-    "android.os",
-    "android.util"
-])
-
-@verifier
-def verify_layering(clazz):
-    """Catch package layering violations.
-    For example, something in android.os depending on android.app."""
-
-    def rank(p):
-        r = None
-        l = LAYERING_PACKAGE_RANKING
-        for n in p.split('.'):
-            if n in l:
-                l = l[n]
-                if '-rank' in l:
-                    r = l['-rank']
-            else:
-                break
-        return r
-
-    cr = rank(clazz.pkg.name)
-    if cr is None: return
-
-    for f in clazz.fields:
-        ir = rank(f.typ)
-        if ir is not None and ir < cr:
-            warn(clazz, f, "FW6", "Field type violates package layering")
-
-    for m in itertools.chain(clazz.methods, clazz.ctors):
-        ir = rank(m.typ)
-        if ir is not None and ir < cr:
-            warn(clazz, m, "FW6", "Method return type violates package layering")
-        for arg in m.args:
-            ir = rank(arg)
-            if ir is not None and ir < cr:
-                warn(clazz, m, "FW6", "Method argument type violates package layering")
-
-
-@verifier
-def verify_boolean(clazz):
-    """Verifies that boolean accessors are named correctly.
-    For example, hasFoo() and setHasFoo()."""
-
-    def is_get(m): return len(m.args) == 0 and m.typ == "boolean"
-    def is_set(m): return len(m.args) == 1 and m.args[0] == "boolean"
-
-    gets = [ m for m in clazz.methods if is_get(m) ]
-    sets = [ m for m in clazz.methods if is_set(m) ]
-
-    def error_if_exists(methods, trigger, expected, actual):
-        for m in methods:
-            if m.name == actual:
-                error(clazz, m, "M6", "Symmetric method for %s must be named %s" % (trigger, expected))
-
-    for m in clazz.methods:
-        if is_get(m):
-            if re.match("is[A-Z]", m.name):
-                target = m.name[2:]
-                expected = "setIs" + target
-                error_if_exists(sets, m.name, expected, "setHas" + target)
-            elif re.match("has[A-Z]", m.name):
-                target = m.name[3:]
-                expected = "setHas" + target
-                error_if_exists(sets, m.name, expected, "setIs" + target)
-                error_if_exists(sets, m.name, expected, "set" + target)
-            elif re.match("get[A-Z]", m.name):
-                target = m.name[3:]
-                expected = "set" + target
-                error_if_exists(sets, m.name, expected, "setIs" + target)
-                error_if_exists(sets, m.name, expected, "setHas" + target)
-
-        if is_set(m):
-            if re.match("set[A-Z]", m.name):
-                target = m.name[3:]
-                expected = "get" + target
-                error_if_exists(sets, m.name, expected, "is" + target)
-                error_if_exists(sets, m.name, expected, "has" + target)
-
-
-@verifier
-def verify_collections(clazz):
-    """Verifies that collection types are interfaces."""
-    if clazz.fullname == "android.os.Bundle": return
-    if clazz.fullname == "android.os.Parcel": return
-
-    bad = ["java.util.Vector", "java.util.LinkedList", "java.util.ArrayList", "java.util.Stack",
-           "java.util.HashMap", "java.util.HashSet", "android.util.ArraySet", "android.util.ArrayMap"]
-    for m in clazz.methods:
-        if m.typ in bad:
-            error(clazz, m, "CL2", "Return type is concrete collection; must be higher-level interface")
-        for arg in m.args:
-            if arg in bad:
-                error(clazz, m, "CL2", "Argument is concrete collection; must be higher-level interface")
-
-
-@verifier
-def verify_uris(clazz):
-    bad = ["java.net.URL", "java.net.URI", "android.net.URL"]
-
-    for f in clazz.fields:
-        if f.typ in bad:
-            error(clazz, f, None, "Field must be android.net.Uri instead of " + f.typ)
-
-    for m in clazz.methods + clazz.ctors:
-        if m.typ in bad:
-            error(clazz, m, None, "Must return android.net.Uri instead of " + m.typ)
-        for arg in m.args:
-            if arg in bad:
-                error(clazz, m, None, "Argument must take android.net.Uri instead of " + arg)
-
-
-@verifier
-def verify_flags(clazz):
-    """Verifies that flags are non-overlapping."""
-    known = collections.defaultdict(int)
-    for f in clazz.fields:
-        if "FLAG_" in f.name:
-            try:
-                val = int(f.value)
-            except:
-                continue
-
-            scope = f.name[0:f.name.index("FLAG_")]
-            if val & known[scope]:
-                warn(clazz, f, "C1", "Found overlapping flag constant value")
-            known[scope] |= val
-
-
-@verifier
-def verify_exception(clazz):
-    """Verifies that methods don't throw generic exceptions."""
-    for m in clazz.methods:
-        for t in m.throws:
-            if t in ["java.lang.Exception", "java.lang.Throwable", "java.lang.Error"]:
-                error(clazz, m, "S1", "Methods must not throw generic exceptions")
-
-            if t in ["android.os.RemoteException"]:
-                if clazz.fullname == "android.content.ContentProviderClient": continue
-                if clazz.fullname == "android.os.Binder": continue
-                if clazz.fullname == "android.os.IBinder": continue
-
-                error(clazz, m, "FW9", "Methods calling into system server should rethrow RemoteException as RuntimeException")
-
-            if len(m.args) == 0 and t in ["java.lang.IllegalArgumentException", "java.lang.NullPointerException"]:
-                warn(clazz, m, "S1", "Methods taking no arguments should throw IllegalStateException")
-
-
-GOOGLE_IGNORECASE = re.compile("google", re.IGNORECASE)
-
-# Not marked as @verifier, because it is only conditionally applied.
-def verify_google(clazz):
-    """Verifies that APIs never reference Google."""
-
-    if GOOGLE_IGNORECASE.search(clazz.raw) is not None:
-        error(clazz, None, None, "Must never reference Google")
-
-    for test in clazz.ctors, clazz.fields, clazz.methods:
-        for t in test:
-            if GOOGLE_IGNORECASE.search(t.raw) is not None:
-                error(clazz, t, None, "Must never reference Google")
-
-
-@verifier
-def verify_bitset(clazz):
-    """Verifies that we avoid using heavy BitSet."""
-
-    for f in clazz.fields:
-        if f.typ == "java.util.BitSet":
-            error(clazz, f, None, "Field type must not be heavy BitSet")
-
-    for m in clazz.methods:
-        if m.typ == "java.util.BitSet":
-            error(clazz, m, None, "Return type must not be heavy BitSet")
-        for arg in m.args:
-            if arg == "java.util.BitSet":
-                error(clazz, m, None, "Argument type must not be heavy BitSet")
-
-
-@verifier
-def verify_manager(clazz):
-    """Verifies that FooManager is only obtained from Context."""
-
-    if not clazz.name.endswith("Manager"): return
-
-    for c in clazz.ctors:
-        error(clazz, c, None, "Managers must always be obtained from Context; no direct constructors")
-
-    for m in clazz.methods:
-        if m.typ == clazz.fullname:
-            error(clazz, m, None, "Managers must always be obtained from Context")
-
-
-@verifier
-def verify_boxed(clazz):
-    """Verifies that methods avoid boxed primitives."""
-
-    boxed = ["java.lang.Number","java.lang.Byte","java.lang.Double","java.lang.Float","java.lang.Integer","java.lang.Long","java.lang.Short"]
-
-    for c in clazz.ctors:
-        for arg in c.args:
-            if arg in boxed:
-                error(clazz, c, "M11", "Must avoid boxed primitives")
-
-    for f in clazz.fields:
-        if f.typ in boxed:
-            error(clazz, f, "M11", "Must avoid boxed primitives")
-
-    for m in clazz.methods:
-        if m.typ in boxed:
-            error(clazz, m, "M11", "Must avoid boxed primitives")
-        for arg in m.args:
-            if arg in boxed:
-                error(clazz, m, "M11", "Must avoid boxed primitives")
-
-
-@verifier
-def verify_static_utils(clazz):
-    """Verifies that helper classes can't be constructed."""
-    if clazz.fullname.startswith("android.opengl"): return
-    if clazz.fullname.startswith("android.R"): return
-
-    # Only care about classes with default constructors
-    if len(clazz.ctors) == 1 and len(clazz.ctors[0].args) == 0:
-        test = []
-        test.extend(clazz.fields)
-        test.extend(clazz.methods)
-
-        if len(test) == 0: return
-        for t in test:
-            if "static" not in t.split:
-                return
-
-        error(clazz, None, None, "Fully-static utility classes must not have constructor")
-
-
-# @verifier  # Disabled for now
-def verify_overload_args(clazz):
-    """Verifies that method overloads add new arguments at the end."""
-    if clazz.fullname.startswith("android.opengl"): return
-
-    overloads = collections.defaultdict(list)
-    for m in clazz.methods:
-        if "deprecated" in m.split: continue
-        overloads[m.name].append(m)
-
-    for name, methods in overloads.items():
-        if len(methods) <= 1: continue
-
-        # Look for arguments common across all overloads
-        def cluster(args):
-            count = collections.defaultdict(int)
-            res = set()
-            for i in range(len(args)):
-                a = args[i]
-                res.add("%s#%d" % (a, count[a]))
-                count[a] += 1
-            return res
-
-        common_args = cluster(methods[0].args)
-        for m in methods:
-            common_args = common_args & cluster(m.args)
-
-        if len(common_args) == 0: continue
-
-        # Require that all common arguments are present at start of signature
-        locked_sig = None
-        for m in methods:
-            sig = m.args[0:len(common_args)]
-            if not common_args.issubset(cluster(sig)):
-                warn(clazz, m, "M2", "Expected common arguments [%s] at beginning of overloaded method" % (", ".join(common_args)))
-            elif not locked_sig:
-                locked_sig = sig
-            elif locked_sig != sig:
-                error(clazz, m, "M2", "Expected consistent argument ordering between overloads: %s..." % (", ".join(locked_sig)))
-
-
-@verifier
-def verify_callback_handlers(clazz):
-    """Verifies that methods adding listener/callback have overload
-    for specifying delivery thread."""
-
-    # Ignore UI packages which assume main thread
-    skip = [
-        "animation",
-        "view",
-        "graphics",
-        "transition",
-        "widget",
-        "webkit",
-    ]
-    for s in skip:
-        if s in clazz.pkg.name_path: return
-        if s in clazz.extends_path: return
-
-    # Ignore UI classes which assume main thread
-    if "app" in clazz.pkg.name_path or "app" in clazz.extends_path:
-        for s in ["ActionBar","Dialog","Application","Activity","Fragment","Loader"]:
-            if s in clazz.fullname: return
-    if "content" in clazz.pkg.name_path or "content" in clazz.extends_path:
-        for s in ["Loader"]:
-            if s in clazz.fullname: return
-
-    found = {}
-    by_name = collections.defaultdict(list)
-    examine = clazz.ctors + clazz.methods
-    for m in examine:
-        if m.name.startswith("unregister"): continue
-        if m.name.startswith("remove"): continue
-        if re.match("on[A-Z]+", m.name): continue
-
-        by_name[m.name].append(m)
-
-        for a in m.args:
-            if a.endswith("Listener") or a.endswith("Callback") or a.endswith("Callbacks"):
-                found[m.name] = m
-
-    for f in found.values():
-        takes_handler = False
-        takes_exec = False
-        for m in by_name[f.name]:
-            if "android.os.Handler" in m.args:
-                takes_handler = True
-            if "java.util.concurrent.Executor" in m.args:
-                takes_exec = True
-        if not takes_exec:
-            warn(clazz, f, "L1", "Registration methods should have overload that accepts delivery Executor")
-
-
-@verifier
-def verify_context_first(clazz):
-    """Verifies that methods accepting a Context keep it the first argument."""
-    examine = clazz.ctors + clazz.methods
-    for m in examine:
-        if len(m.args) > 1 and m.args[0] != "android.content.Context":
-            if "android.content.Context" in m.args[1:]:
-                error(clazz, m, "M3", "Context is distinct, so it must be the first argument")
-        if len(m.args) > 1 and m.args[0] != "android.content.ContentResolver":
-            if "android.content.ContentResolver" in m.args[1:]:
-                error(clazz, m, "M3", "ContentResolver is distinct, so it must be the first argument")
-
-
-@verifier
-def verify_listener_last(clazz):
-    """Verifies that methods accepting a Listener or Callback keep them as last arguments."""
-    examine = clazz.ctors + clazz.methods
-    for m in examine:
-        if "Listener" in m.name or "Callback" in m.name: continue
-        found = False
-        for a in m.args:
-            if a.endswith("Callback") or a.endswith("Callbacks") or a.endswith("Listener"):
-                found = True
-            elif found:
-                warn(clazz, m, "M3", "Listeners should always be at end of argument list")
-
-
-@verifier
-def verify_resource_names(clazz):
-    """Verifies that resource names have consistent case."""
-    if not re.match("android\.R\.[a-z]+", clazz.fullname): return
-
-    # Resources defined by files are foo_bar_baz
-    if clazz.name in ["anim","animator","color","dimen","drawable","interpolator","layout","transition","menu","mipmap","string","plurals","raw","xml"]:
-        for f in clazz.fields:
-            if re.match("config_[a-z][a-zA-Z1-9]*$", f.name): continue
-            if f.name.startswith("config_"):
-                error(clazz, f, None, "Expected config name to be config_fooBarBaz style")
-
-            if re.match("[a-z1-9_]+$", f.name): continue
-            error(clazz, f, None, "Expected resource name in this class to be foo_bar_baz style")
-
-    # Resources defined inside files are fooBarBaz
-    if clazz.name in ["array","attr","id","bool","fraction","integer"]:
-        for f in clazz.fields:
-            if re.match("config_[a-z][a-zA-Z1-9]*$", f.name): continue
-            if re.match("layout_[a-z][a-zA-Z1-9]*$", f.name): continue
-            if re.match("state_[a-z_]*$", f.name): continue
-
-            if re.match("[a-z][a-zA-Z1-9]*$", f.name): continue
-            error(clazz, f, "C7", "Expected resource name in this class to be fooBarBaz style")
-
-    # Styles are FooBar_Baz
-    if clazz.name in ["style"]:
-        for f in clazz.fields:
-            if re.match("[A-Z][A-Za-z1-9]+(_[A-Z][A-Za-z1-9]+?)*$", f.name): continue
-            error(clazz, f, "C7", "Expected resource name in this class to be FooBar_Baz style")
-
-
-@verifier
-def verify_files(clazz):
-    """Verifies that methods accepting File also accept streams."""
-
-    has_file = set()
-    has_stream = set()
-
-    test = []
-    test.extend(clazz.ctors)
-    test.extend(clazz.methods)
-
-    for m in test:
-        if "java.io.File" in m.args:
-            has_file.add(m)
-        if "java.io.FileDescriptor" in m.args or "android.os.ParcelFileDescriptor" in m.args or "java.io.InputStream" in m.args or "java.io.OutputStream" in m.args:
-            has_stream.add(m.name)
-
-    for m in has_file:
-        if m.name not in has_stream:
-            warn(clazz, m, "M10", "Methods accepting File should also accept FileDescriptor or streams")
-
-
-@verifier
-def verify_manager_list(clazz):
-    """Verifies that managers return List<? extends Parcelable> instead of arrays."""
-
-    if not clazz.name.endswith("Manager"): return
-
-    for m in clazz.methods:
-        if m.typ.startswith("android.") and m.typ.endswith("[]"):
-            warn(clazz, m, None, "Methods should return List<? extends Parcelable> instead of Parcelable[] to support ParceledListSlice under the hood")
-
-
-@verifier
-def verify_abstract_inner(clazz):
-    """Verifies that abstract inner classes are static."""
-
-    if re.match(".+?\.[A-Z][^\.]+\.[A-Z]", clazz.fullname):
-        if "abstract" in clazz.split and "static" not in clazz.split:
-            warn(clazz, None, None, "Abstract inner classes should be static to improve testability")
-
-
-@verifier
-def verify_runtime_exceptions(clazz):
-    """Verifies that runtime exceptions aren't listed in throws."""
-
-    banned = [
-        "java.lang.NullPointerException",
-        "java.lang.ClassCastException",
-        "java.lang.IndexOutOfBoundsException",
-        "java.lang.reflect.UndeclaredThrowableException",
-        "java.lang.reflect.MalformedParametersException",
-        "java.lang.reflect.MalformedParameterizedTypeException",
-        "java.lang.invoke.WrongMethodTypeException",
-        "java.lang.EnumConstantNotPresentException",
-        "java.lang.IllegalMonitorStateException",
-        "java.lang.SecurityException",
-        "java.lang.UnsupportedOperationException",
-        "java.lang.annotation.AnnotationTypeMismatchException",
-        "java.lang.annotation.IncompleteAnnotationException",
-        "java.lang.TypeNotPresentException",
-        "java.lang.IllegalStateException",
-        "java.lang.ArithmeticException",
-        "java.lang.IllegalArgumentException",
-        "java.lang.ArrayStoreException",
-        "java.lang.NegativeArraySizeException",
-        "java.util.MissingResourceException",
-        "java.util.EmptyStackException",
-        "java.util.concurrent.CompletionException",
-        "java.util.concurrent.RejectedExecutionException",
-        "java.util.IllformedLocaleException",
-        "java.util.ConcurrentModificationException",
-        "java.util.NoSuchElementException",
-        "java.io.UncheckedIOException",
-        "java.time.DateTimeException",
-        "java.security.ProviderException",
-        "java.nio.BufferUnderflowException",
-        "java.nio.BufferOverflowException",
-    ]
-
-    examine = clazz.ctors + clazz.methods
-    for m in examine:
-        for t in m.throws:
-            if t in banned:
-                error(clazz, m, None, "Methods must not mention RuntimeException subclasses in throws clauses")
-
-
-@verifier
-def verify_error(clazz):
-    """Verifies that we always use Exception instead of Error."""
-    if not clazz.extends: return
-    if clazz.extends.endswith("Error"):
-        error(clazz, None, None, "Trouble must be reported through an Exception, not Error")
-    if clazz.extends.endswith("Exception") and not clazz.name.endswith("Exception"):
-        error(clazz, None, None, "Exceptions must be named FooException")
-
-
-@verifier
-def verify_units(clazz):
-    """Verifies that we use consistent naming for units."""
-
-    # If we find K, recommend replacing with V
-    bad = {
-        "Ns": "Nanos",
-        "Ms": "Millis or Micros",
-        "Sec": "Seconds", "Secs": "Seconds",
-        "Hr": "Hours", "Hrs": "Hours",
-        "Mo": "Months", "Mos": "Months",
-        "Yr": "Years", "Yrs": "Years",
-        "Byte": "Bytes", "Space": "Bytes",
-    }
-
-    for m in clazz.methods:
-        if m.typ not in ["short","int","long"]: continue
-        for k, v in bad.iteritems():
-            if m.name.endswith(k):
-                error(clazz, m, None, "Expected method name units to be " + v)
-        if m.name.endswith("Nanos") or m.name.endswith("Micros"):
-            warn(clazz, m, None, "Returned time values are strongly encouraged to be in milliseconds unless you need the extra precision")
-        if m.name.endswith("Seconds"):
-            error(clazz, m, None, "Returned time values must be in milliseconds")
-
-    for m in clazz.methods:
-        typ = m.typ
-        if typ == "void":
-            if len(m.args) != 1: continue
-            typ = m.args[0]
-
-        if m.name.endswith("Fraction") and typ != "float":
-            error(clazz, m, None, "Fractions must use floats")
-        if m.name.endswith("Percentage") and typ != "int":
-            error(clazz, m, None, "Percentage must use ints")
-
-
-@verifier
-def verify_closable(clazz):
-    """Verifies that classes are AutoClosable."""
-    if "java.lang.AutoCloseable" in clazz.implements_all: return
-    if "java.io.Closeable" in clazz.implements_all: return
-
-    for m in clazz.methods:
-        if len(m.args) > 0: continue
-        if m.name in ["close","release","destroy","finish","finalize","disconnect","shutdown","stop","free","quit"]:
-            warn(clazz, m, None, "Classes that release resources should implement AutoClosable and CloseGuard")
-            return
-
-
-@verifier
-def verify_member_name_not_kotlin_keyword(clazz):
-    """Prevent method names which are keywords in Kotlin."""
-
-    # https://kotlinlang.org/docs/reference/keyword-reference.html#hard-keywords
-    # This list does not include Java keywords as those are already impossible to use.
-    keywords = [
-        'as',
-        'fun',
-        'in',
-        'is',
-        'object',
-        'typealias',
-        'val',
-        'var',
-        'when',
-    ]
-
-    for m in clazz.methods:
-        if m.name in keywords:
-            error(clazz, m, None, "Method name must not be a Kotlin keyword")
-    for f in clazz.fields:
-        if f.name in keywords:
-            error(clazz, f, None, "Field name must not be a Kotlin keyword")
-
-
-@verifier
-def verify_method_name_not_kotlin_operator(clazz):
-    """Warn about method names which become operators in Kotlin."""
-
-    binary = set()
-
-    def unique_binary_op(m, op):
-        if op in binary:
-            error(clazz, m, None, "Only one of '{0}' and '{0}Assign' methods should be present for Kotlin".format(op))
-        binary.add(op)
-
-    for m in clazz.methods:
-        if 'static' in m.split or 'operator' in m.split:
-            continue
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#unary-prefix-operators
-        if m.name in ['unaryPlus', 'unaryMinus', 'not'] and len(m.args) == 0:
-            warn(clazz, m, None, "Method can be invoked as a unary operator from Kotlin")
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#increments-and-decrements
-        if m.name in ['inc', 'dec'] and len(m.args) == 0 and m.typ != 'void':
-            # This only applies if the return type is the same or a subtype of the enclosing class, but we have no
-            # practical way of checking that relationship here.
-            warn(clazz, m, None, "Method can be invoked as a pre/postfix inc/decrement operator from Kotlin")
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#arithmetic
-        if m.name in ['plus', 'minus', 'times', 'div', 'rem', 'mod', 'rangeTo'] and len(m.args) == 1:
-            warn(clazz, m, None, "Method can be invoked as a binary operator from Kotlin")
-            unique_binary_op(m, m.name)
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#in
-        if m.name == 'contains' and len(m.args) == 1 and m.typ == 'boolean':
-            warn(clazz, m, None, "Method can be invoked as a 'in' operator from Kotlin")
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#indexed
-        if (m.name == 'get' and len(m.args) > 0) or (m.name == 'set' and len(m.args) > 1):
-            warn(clazz, m, None, "Method can be invoked with an indexing operator from Kotlin")
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#invoke
-        if m.name == 'invoke':
-            warn(clazz, m, None, "Method can be invoked with function call syntax from Kotlin")
-
-        # https://kotlinlang.org/docs/reference/operator-overloading.html#assignments
-        if m.name in ['plusAssign', 'minusAssign', 'timesAssign', 'divAssign', 'remAssign', 'modAssign'] \
-                and len(m.args) == 1 \
-                and m.typ == 'void':
-            warn(clazz, m, None, "Method can be invoked as a compound assignment operator from Kotlin")
-            unique_binary_op(m, m.name[:-6])  # Remove 'Assign' suffix
-
-
-@verifier
-def verify_collections_over_arrays(clazz):
-    """Warn that [] should be Collections."""
-
-    if "@interface" in clazz.split:
-        return
-
-    safe = ["java.lang.String[]","byte[]","short[]","int[]","long[]","float[]","double[]","boolean[]","char[]"]
-    for m in clazz.methods:
-        if m.typ.endswith("[]") and m.typ not in safe:
-            warn(clazz, m, None, "Method should return Collection<> (or subclass) instead of raw array")
-        for arg in m.args:
-            if arg.endswith("[]") and arg not in safe:
-                warn(clazz, m, None, "Method argument should be Collection<> (or subclass) instead of raw array")
-
-
-@verifier
-def verify_user_handle(clazz):
-    """Methods taking UserHandle should be ForUser or AsUser."""
-    if clazz.name.endswith("Listener") or clazz.name.endswith("Callback") or clazz.name.endswith("Callbacks"): return
-    if clazz.fullname == "android.app.admin.DeviceAdminReceiver": return
-    if clazz.fullname == "android.content.pm.LauncherApps": return
-    if clazz.fullname == "android.os.UserHandle": return
-    if clazz.fullname == "android.os.UserManager": return
-
-    for m in clazz.methods:
-        if re.match("on[A-Z]+", m.name): continue
-
-        has_arg = "android.os.UserHandle" in m.args
-        has_name = m.name.endswith("AsUser") or m.name.endswith("ForUser")
-
-        if clazz.fullname.endswith("Manager") and has_arg:
-            warn(clazz, m, None, "When a method overload is needed to target a specific "
-                 "UserHandle, callers should be directed to use "
-                 "Context.createPackageContextAsUser() and re-obtain the relevant "
-                 "Manager, and no new API should be added")
-        elif has_arg and not has_name:
-            warn(clazz, m, None, "Method taking UserHandle should be named 'doFooAsUser' "
-                 "or 'queryFooForUser'")
-
-
-@verifier
-def verify_params(clazz):
-    """Parameter classes should be 'Params'."""
-    if clazz.name.endswith("Params"): return
-    if clazz.fullname == "android.app.ActivityOptions": return
-    if clazz.fullname == "android.app.BroadcastOptions": return
-    if clazz.fullname == "android.os.Bundle": return
-    if clazz.fullname == "android.os.BaseBundle": return
-    if clazz.fullname == "android.os.PersistableBundle": return
-
-    bad = ["Param","Parameter","Parameters","Args","Arg","Argument","Arguments","Options","Bundle"]
-    for b in bad:
-        if clazz.name.endswith(b):
-            error(clazz, None, None, "Classes holding a set of parameters should be called 'FooParams'")
-
-
-@verifier
-def verify_services(clazz):
-    """Service name should be FOO_BAR_SERVICE = 'foo_bar'."""
-    if clazz.fullname != "android.content.Context": return
-
-    for f in clazz.fields:
-        if f.typ != "java.lang.String": continue
-        found = re.match(r"([A-Z_]+)_SERVICE", f.name)
-        if found:
-            expected = found.group(1).lower()
-            if f.value != expected:
-                error(clazz, f, "C4", "Inconsistent service value; expected '%s'" % (expected))
-
-
-@verifier
-def verify_tense(clazz):
-    """Verify tenses of method names."""
-    if clazz.fullname.startswith("android.opengl"): return
-
-    for m in clazz.methods:
-        if m.name.endswith("Enable"):
-            warn(clazz, m, None, "Unexpected tense; probably meant 'enabled'")
-
-
-@verifier
-def verify_icu(clazz):
-    """Verifies that richer ICU replacements are used."""
-    better = {
-        "java.util.TimeZone": "android.icu.util.TimeZone",
-        "java.util.Calendar": "android.icu.util.Calendar",
-        "java.util.Locale": "android.icu.util.ULocale",
-        "java.util.ResourceBundle": "android.icu.util.UResourceBundle",
-        "java.util.SimpleTimeZone": "android.icu.util.SimpleTimeZone",
-        "java.util.StringTokenizer": "android.icu.util.StringTokenizer",
-        "java.util.GregorianCalendar": "android.icu.util.GregorianCalendar",
-        "java.lang.Character": "android.icu.lang.UCharacter",
-        "java.text.BreakIterator": "android.icu.text.BreakIterator",
-        "java.text.Collator": "android.icu.text.Collator",
-        "java.text.DecimalFormatSymbols": "android.icu.text.DecimalFormatSymbols",
-        "java.text.NumberFormat": "android.icu.text.NumberFormat",
-        "java.text.DateFormatSymbols": "android.icu.text.DateFormatSymbols",
-        "java.text.DateFormat": "android.icu.text.DateFormat",
-        "java.text.SimpleDateFormat": "android.icu.text.SimpleDateFormat",
-        "java.text.MessageFormat": "android.icu.text.MessageFormat",
-        "java.text.DecimalFormat": "android.icu.text.DecimalFormat",
-    }
-
-    for m in clazz.ctors + clazz.methods:
-        types = []
-        types.extend(m.typ)
-        types.extend(m.args)
-        for arg in types:
-            if arg in better:
-                warn(clazz, m, None, "Type %s should be replaced with richer ICU type %s" % (arg, better[arg]))
-
-
-@verifier
-def verify_clone(clazz):
-    """Verify that clone() isn't implemented; see EJ page 61."""
-    for m in clazz.methods:
-        if m.name == "clone":
-            error(clazz, m, None, "Provide an explicit copy constructor instead of implementing clone()")
-
-
-@verifier
-def verify_pfd(clazz):
-    """Verify that android APIs use PFD over FD."""
-    if clazz.fullname == "android.os.FileUtils" or clazz.fullname == "android.system.Os":
-        return
-
-    examine = clazz.ctors + clazz.methods
-    for m in examine:
-        if m.typ == "java.io.FileDescriptor":
-            error(clazz, m, "FW11", "Must use ParcelFileDescriptor")
-        if m.typ == "int":
-            if "Fd" in m.name or "FD" in m.name or "FileDescriptor" in m.name:
-                error(clazz, m, "FW11", "Must use ParcelFileDescriptor")
-        for arg in m.args:
-            if arg == "java.io.FileDescriptor":
-                error(clazz, m, "FW11", "Must use ParcelFileDescriptor")
-
-    for f in clazz.fields:
-        if f.typ == "java.io.FileDescriptor":
-            error(clazz, f, "FW11", "Must use ParcelFileDescriptor")
-
-
-@verifier
-def verify_numbers(clazz):
-    """Discourage small numbers types like short and byte."""
-
-    discouraged = ["short","byte"]
-
-    for c in clazz.ctors:
-        for arg in c.args:
-            if arg in discouraged:
-                warn(clazz, c, "FW12", "Should avoid odd sized primitives; use int instead")
-
-    for f in clazz.fields:
-        if f.typ in discouraged:
-            warn(clazz, f, "FW12", "Should avoid odd sized primitives; use int instead")
-
-    for m in clazz.methods:
-        if m.typ in discouraged:
-            warn(clazz, m, "FW12", "Should avoid odd sized primitives; use int instead")
-        for arg in m.args:
-            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"}
-
-@verifier
-def verify_nullability(clazz):
-    """Catches missing nullability annotations"""
-
-    for f in clazz.fields:
-        if "enum_constant" in f.split:
-            continue  # Enum constants are never null
-        if f.value is not None 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" or m.name == "onBind":
-            continue  # Parcelable.writeToParcel(), BroadcastReceiver.onReceive(), and Service.onBind() are not yet annotated
-
-        if (m.name == "equals" and m.args == ["java.lang.Object"] or
-                m.name == "toString" and m.args == []):
-            continue  # Nullability of equals and toString is implicit.
-
-        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
-
-
-@verifier
-def verify_intdef(clazz):
-    """intdefs must be @hide, because the constant names cannot be stored in
-       the stubs (only the values are, which is not useful)"""
-    if "@interface" not in clazz.split:
-        return
-    if "@IntDef" in clazz.annotations or "@LongDef" in clazz.annotations:
-        error(clazz, None, None, "@IntDef and @LongDef annotations must be @hide")
-
-
-@verifier
-def verify_singleton(clazz):
-    """Catch singleton objects with constructors."""
-
-    singleton = False
-    for m in clazz.methods:
-        if m.name.startswith("get") and m.name.endswith("Instance") and " static " in m.raw:
-            singleton = True
-
-    if singleton:
-        for c in clazz.ctors:
-            error(clazz, c, None, "Singleton classes should use getInstance() methods")
-
-
-
-def is_interesting(clazz):
-    """Test if given class is interesting from an Android PoV."""
-
-    if clazz.pkg.name.startswith("java"): return False
-    if clazz.pkg.name.startswith("junit"): return False
-    if clazz.pkg.name.startswith("org.apache"): return False
-    if clazz.pkg.name.startswith("org.xml"): return False
-    if clazz.pkg.name.startswith("org.json"): return False
-    if clazz.pkg.name.startswith("org.w3c"): return False
-    if clazz.pkg.name.startswith("android.icu."): return False
-    return True
-
-
-def examine_clazz(clazz):
-    """Find all style issues in the given class."""
-
-    notice(clazz)
-
-    if not is_interesting(clazz): return
-
-    for v in verifiers.itervalues():
-        v(clazz)
-
-    if not ALLOW_GOOGLE: verify_google(clazz)
-
-
-def examine_stream(stream, base_stream=None, in_classes_with_base=[], out_classes_with_base=None):
-    """Find all style issues in the given API stream."""
-    global failures, noticed
-    failures = {}
-    noticed = {}
-    _parse_stream(stream, examine_clazz, base_f=base_stream,
-                  in_classes_with_base=in_classes_with_base,
-                  out_classes_with_base=out_classes_with_base)
-    return (failures, noticed)
-
-
-def examine_api(api):
-    """Find all style issues in the given parsed API."""
-    global failures
-    failures = {}
-    for key in sorted(api.keys()):
-        examine_clazz(api[key])
-    return failures
-
-
-def verify_compat(cur, prev):
-    """Find any incompatible API changes between two levels."""
-    global failures
-
-    def class_exists(api, test):
-        return test.fullname in api
-
-    def ctor_exists(api, clazz, test):
-        for m in clazz.ctors:
-            if m.ident == test.ident: return True
-        return False
-
-    def all_methods(api, clazz):
-        methods = list(clazz.methods)
-        if clazz.extends is not None:
-            methods.extend(all_methods(api, api[clazz.extends]))
-        return methods
-
-    def method_exists(api, clazz, test):
-        methods = all_methods(api, clazz)
-        for m in methods:
-            if m.ident == test.ident: return True
-        return False
-
-    def field_exists(api, clazz, test):
-        for f in clazz.fields:
-            if f.ident == test.ident: return True
-        return False
-
-    failures = {}
-    for key in sorted(prev.keys()):
-        prev_clazz = prev[key]
-
-        if not class_exists(cur, prev_clazz):
-            error(prev_clazz, None, None, "Class removed or incompatible change")
-            continue
-
-        cur_clazz = cur[key]
-
-        for test in prev_clazz.ctors:
-            if not ctor_exists(cur, cur_clazz, test):
-                error(prev_clazz, prev_ctor, None, "Constructor removed or incompatible change")
-
-        methods = all_methods(prev, prev_clazz)
-        for test in methods:
-            if not method_exists(cur, cur_clazz, test):
-                error(prev_clazz, test, None, "Method removed or incompatible change")
-
-        for test in prev_clazz.fields:
-            if not field_exists(cur, cur_clazz, test):
-                error(prev_clazz, test, None, "Field removed or incompatible change")
-
-    return failures
-
-
-def match_filter(filters, fullname):
-    for f in filters:
-        if fullname == f:
-            return True
-        if fullname.startswith(f + '.'):
-            return True
-    return False
-
-
-def show_deprecations_at_birth(cur, prev):
-    """Show API deprecations at birth."""
-    global failures
-
-    # Remove all existing things so we're left with new
-    for prev_clazz in prev.values():
-        if prev_clazz.fullname not in cur:
-            # The class was removed this release; we can safely ignore it.
-            continue
-
-        cur_clazz = cur[prev_clazz.fullname]
-        if not is_interesting(cur_clazz): continue
-
-        sigs = { i.ident: i for i in prev_clazz.ctors }
-        cur_clazz.ctors = [ i for i in cur_clazz.ctors if i.ident not in sigs ]
-        sigs = { i.ident: i for i in prev_clazz.methods }
-        cur_clazz.methods = [ i for i in cur_clazz.methods if i.ident not in sigs ]
-        sigs = { i.ident: i for i in prev_clazz.fields }
-        cur_clazz.fields = [ i for i in cur_clazz.fields if i.ident not in sigs ]
-
-        # Forget about class entirely when nothing new
-        if len(cur_clazz.ctors) == 0 and len(cur_clazz.methods) == 0 and len(cur_clazz.fields) == 0:
-            del cur[prev_clazz.fullname]
-
-    for clazz in cur.values():
-        if not is_interesting(clazz): continue
-
-        if "deprecated" in clazz.split and not clazz.fullname in prev:
-            error(clazz, None, None, "Found API deprecation at birth")
-
-        for i in clazz.ctors + clazz.methods + clazz.fields:
-            if "deprecated" in i.split:
-                error(clazz, i, None, "Found API deprecation at birth")
-
-    print "%s Deprecated at birth %s\n" % ((format(fg=WHITE, bg=BLUE, bold=True),
-                                            format(reset=True)))
-    for f in sorted(failures):
-        print failures[f]
-        print
-
-
-def show_stats(cur, prev):
-    """Show API stats."""
-
-    stats = collections.defaultdict(int)
-    for cur_clazz in cur.values():
-        if not is_interesting(cur_clazz): continue
-
-        if cur_clazz.fullname not in prev:
-            stats['new_classes'] += 1
-            stats['new_ctors'] += len(cur_clazz.ctors)
-            stats['new_methods'] += len(cur_clazz.methods)
-            stats['new_fields'] += len(cur_clazz.fields)
-        else:
-            prev_clazz = prev[cur_clazz.fullname]
-
-            sigs = { i.ident: i for i in prev_clazz.ctors }
-            ctors = len([ i for i in cur_clazz.ctors if i.ident not in sigs ])
-            sigs = { i.ident: i for i in prev_clazz.methods }
-            methods = len([ i for i in cur_clazz.methods if i.ident not in sigs ])
-            sigs = { i.ident: i for i in prev_clazz.fields }
-            fields = len([ i for i in cur_clazz.fields if i.ident not in sigs ])
-
-            if ctors + methods + fields > 0:
-                stats['extend_classes'] += 1
-                stats['extend_ctors'] += ctors
-                stats['extend_methods'] += methods
-                stats['extend_fields'] += fields
-
-    print "#", "".join([ k.ljust(20) for k in sorted(stats.keys()) ])
-    print " ", "".join([ str(stats[k]).ljust(20) for k in sorted(stats.keys()) ])
-
-
-def main():
-    parser = argparse.ArgumentParser(description="Enforces common Android public API design \
-            patterns. It ignores lint messages from a previous API level, if provided.")
-    parser.add_argument("--base-current", nargs='?', type=argparse.FileType('r'), default=None,
-            help="The base current.txt to use when examining system-current.txt or"
-                 " test-current.txt")
-    parser.add_argument("--base-previous", nargs='?', type=argparse.FileType('r'), default=None,
-            help="The base previous.txt to use when examining system-previous.txt or"
-                 " test-previous.txt")
-    parser.add_argument("--no-color", action='store_const', const=True,
-            help="Disable terminal colors")
-    parser.add_argument("--color", action='store_const', const=True,
-            help="Use terminal colors")
-    parser.add_argument("--allow-google", action='store_const', const=True,
-            help="Allow references to Google")
-    parser.add_argument("--show-noticed", action='store_const', const=True,
-            help="Show API changes noticed")
-    parser.add_argument("--show-deprecations-at-birth", action='store_const', const=True,
-            help="Show API deprecations at birth")
-    parser.add_argument("--show-stats", action='store_const', const=True,
-            help="Show API stats")
-    parser.add_argument("--title", action='store', default=None,
-            help="Title to put in for display purposes")
-    parser.add_argument("--filter", action="append",
-            help="If provided, only show lint for the given packages or classes.")
-    parser.add_argument("current.txt", type=argparse.FileType('r'), help="current.txt")
-    parser.add_argument("previous.txt", nargs='?', type=argparse.FileType('r'), default=None,
-            help="previous.txt")
-    args = vars(parser.parse_args())
-
-    if args['no_color']:
-        USE_COLOR = False
-    elif args['color']:
-        USE_COLOR = True
-    else:
-        USE_COLOR = sys.stdout.isatty()
-
-    if args['allow_google']:
-        ALLOW_GOOGLE = True
-
-    current_file = args['current.txt']
-    base_current_file = args['base_current']
-    previous_file = args['previous.txt']
-    base_previous_file = args['base_previous']
-    filters = args['filter']
-    if not filters:
-        filters = []
-    title = args['title']
-    if not title:
-        title = current_file.name
-
-    if args['show_deprecations_at_birth']:
-        with current_file as f:
-            cur = _parse_stream(f)
-        with previous_file as f:
-            prev = _parse_stream(f)
-        show_deprecations_at_birth(cur, prev)
-        sys.exit()
-
-    if args['show_stats']:
-        with current_file as f:
-            cur = _parse_stream(f)
-        with previous_file as f:
-            prev = _parse_stream(f)
-        show_stats(cur, prev)
-        sys.exit()
-
-    classes_with_base = []
-
-    with current_file as f:
-        if base_current_file:
-            with base_current_file as base_f:
-                cur_fail, cur_noticed = examine_stream(f, base_f,
-                                                       out_classes_with_base=classes_with_base)
-        else:
-            cur_fail, cur_noticed = examine_stream(f, out_classes_with_base=classes_with_base)
-
-    if not previous_file is None:
-        with previous_file as f:
-            if base_previous_file:
-                with base_previous_file as base_f:
-                    prev_fail, prev_noticed = examine_stream(f, base_f,
-                                                             in_classes_with_base=classes_with_base)
-            else:
-                prev_fail, prev_noticed = examine_stream(f, in_classes_with_base=classes_with_base)
-
-        # ignore errors from previous API level
-        for p in prev_fail:
-            if p in cur_fail:
-                del cur_fail[p]
-
-        # ignore classes unchanged from previous API level
-        for k, v in prev_noticed.iteritems():
-            if k in cur_noticed and v == cur_noticed[k]:
-                del cur_noticed[k]
-
-        """
-        # NOTE: disabled because of memory pressure
-        # look for compatibility issues
-        compat_fail = verify_compat(cur, prev)
-
-        print "%s API compatibility issues %s\n" % ((format(fg=WHITE, bg=BLUE, bold=True), format(reset=True)))
-        for f in sorted(compat_fail):
-            print compat_fail[f]
-            print
-        """
-
-    # ignore everything but the given filters, if provided
-    if filters:
-        cur_fail = dict([(key, failure) for key, failure in cur_fail.iteritems()
-                if match_filter(filters, failure.clazz.fullname)])
-
-    if args['show_noticed'] and len(cur_noticed) != 0:
-        print "%s API changes noticed %s\n" % ((format(fg=WHITE, bg=BLUE, bold=True), format(reset=True)))
-        for f in sorted(cur_noticed.keys()):
-            print f
-        print
-
-    if len(cur_fail) != 0:
-        print "%s API style issues: %s %s" % ((format(fg=WHITE, bg=BLUE, bold=True),
-                    title, format(reset=True)))
-        for f in filters:
-            print "%s   filter: %s %s" % ((format(fg=WHITE, bg=BLUE, bold=True),
-                        f, format(reset=True)))
-        print
-        for f in sorted(cur_fail):
-            print cur_fail[f]
-            print
-        print "%d errors" % len(cur_fail)
-        sys.exit(77)
-
-if __name__ == "__main__":
-    try:
-        main()
-    except KeyboardInterrupt:
-        sys.exit(1)
diff --git a/tools/apilint/apilint_sha.sh b/tools/apilint/apilint_sha.sh
deleted file mode 100755
index 2a45b10..0000000
--- a/tools/apilint/apilint_sha.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-if git show --name-only --pretty=format: $1 | grep api/ > /dev/null; then
-    python tools/apilint/apilint.py <(git show $1:api/current.txt) <(git show $1^:api/current.txt)
-fi
diff --git a/tools/apilint/apilint_sha_system.sh b/tools/apilint/apilint_sha_system.sh
deleted file mode 100755
index 8538a3d..0000000
--- a/tools/apilint/apilint_sha_system.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2018 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.
-
-if git show --name-only --pretty=format: $1 | grep api/ > /dev/null; then
-  python tools/apilint/apilint.py \
-    --base-current <(git show $1:api/current.txt) \
-    --base-previous <(git show $1^:api/current.txt) \
-    <(git show $1:api/system-current.txt) \
-    <(git show $1^:api/system-current.txt)
-fi
diff --git a/tools/apilint/apilint_stats.sh b/tools/apilint/apilint_stats.sh
deleted file mode 100755
index 052d9a5..0000000
--- a/tools/apilint/apilint_stats.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-API=28
-while [ $API -gt 14 ]; do
-    echo "# Changes in API $((API))"
-    python tools/apilint/apilint.py --show-stats ../../prebuilts/sdk/$((API))/public/api/android.txt ../../prebuilts/sdk/$((API-1))/public/api/android.txt
-    let API=API-1
-done
diff --git a/tools/apilint/apilint_test.py b/tools/apilint/apilint_test.py
deleted file mode 100644
index 811cb9a..0000000
--- a/tools/apilint/apilint_test.py
+++ /dev/null
@@ -1,414 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (C) 2018 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.
-
-import unittest
-
-import apilint
-
-def cls(pkg, name):
-    return apilint.Class(apilint.Package(999, "package %s {" % pkg, None), 999,
-                  "public final class %s {" % name, None)
-
-_ri = apilint._retry_iterator
-
-c1 = cls("android.app", "ActivityManager")
-c2 = cls("android.app", "Notification")
-c3 = cls("android.app", "Notification.Action")
-c4 = cls("android.graphics", "Bitmap")
-
-class UtilTests(unittest.TestCase):
-    def test_retry_iterator(self):
-        it = apilint._retry_iterator([1, 2, 3, 4])
-        self.assertEqual(it.next(), 1)
-        self.assertEqual(it.next(), 2)
-        self.assertEqual(it.next(), 3)
-        it.send("retry")
-        self.assertEqual(it.next(), 3)
-        self.assertEqual(it.next(), 4)
-        with self.assertRaises(StopIteration):
-            it.next()
-
-    def test_retry_iterator_one(self):
-        it = apilint._retry_iterator([1])
-        self.assertEqual(it.next(), 1)
-        it.send("retry")
-        self.assertEqual(it.next(), 1)
-        with self.assertRaises(StopIteration):
-            it.next()
-
-    def test_retry_iterator_one(self):
-        it = apilint._retry_iterator([1])
-        self.assertEqual(it.next(), 1)
-        it.send("retry")
-        self.assertEqual(it.next(), 1)
-        with self.assertRaises(StopIteration):
-            it.next()
-
-    def test_skip_to_matching_class_found(self):
-        it = _ri([c1, c2, c3, c4])
-        self.assertEquals(apilint._skip_to_matching_class(it, c3),
-                          c3)
-        self.assertEqual(it.next(), c4)
-
-    def test_skip_to_matching_class_not_found(self):
-        it = _ri([c1, c2, c3, c4])
-        self.assertEquals(apilint._skip_to_matching_class(it, cls("android.content", "ContentProvider")),
-                          None)
-        self.assertEqual(it.next(), c4)
-
-    def test_yield_until_matching_class_found(self):
-        it = _ri([c1, c2, c3, c4])
-        self.assertEquals(list(apilint._yield_until_matching_class(it, c3)),
-                          [c1, c2])
-        self.assertEqual(it.next(), c4)
-
-    def test_yield_until_matching_class_not_found(self):
-        it = _ri([c1, c2, c3, c4])
-        self.assertEquals(list(apilint._yield_until_matching_class(it, cls("android.content", "ContentProvider"))),
-                          [c1, c2, c3])
-        self.assertEqual(it.next(), c4)
-
-    def test_yield_until_matching_class_None(self):
-        it = _ri([c1, c2, c3, c4])
-        self.assertEquals(list(apilint._yield_until_matching_class(it, None)),
-                          [c1, c2, c3, c4])
-
-
-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(@NonNull android.os.Parcel);
-    method public int describeContents();
-    method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR;
-  }
-}
-""".strip().split('\n')
-
-ok_current_txt = """
-// Signature format: 2.0
-package android.app {
-  public final class Activity {
-  }
-
-  public final class WallpaperColors implements android.os.Parcelable {
-    ctor public WallpaperColors();
-    method public int describeContents();
-    method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR;
-  }
-}
-""".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();
-  }
-}
-""".strip().split('\n')
-
-
-
-class BaseFileTests(unittest.TestCase):
-    def test_base_file_avoids_errors(self):
-        failures, _ = apilint.examine_stream(system_current_txt, ok_current_txt)
-        self.assertEquals(failures, {})
-
-    def test_class_with_base_finds_same_errors(self):
-        failures_with_classes_with_base, _ = apilint.examine_stream("", faulty_current_txt,
-                                                                    in_classes_with_base=[cls("android.app", "WallpaperColors")])
-        failures_with_system_txt, _ = apilint.examine_stream(system_current_txt, faulty_current_txt)
-
-        self.assertEquals(failures_with_classes_with_base.keys(), failures_with_system_txt.keys())
-
-    def test_classes_with_base_is_emited(self):
-        classes_with_base = []
-        _, _ = apilint.examine_stream(system_current_txt, faulty_current_txt,
-                                      out_classes_with_base=classes_with_base)
-        self.assertEquals(map(lambda x: x.fullname, classes_with_base), ["android.app.WallpaperColors"])
-
-class ParseV2Stream(unittest.TestCase):
-    def test_field_kinds(self):
-        api = apilint._parse_stream("""
-// Signature format: 2.0
-package android {
-  public enum SomeEnum {
-    enum_constant public static final android.SomeEnum ENUM_CONST;
-    field public static final int FIELD_CONST;
-    property public final int someProperty;
-    ctor public SomeEnum();
-    method public Object? getObject();
-  }
-}
-        """.strip().split('\n'))
-
-        self.assertEquals(api['android.SomeEnum'].fields[0].split[0], 'enum_constant')
-        self.assertEquals(api['android.SomeEnum'].fields[1].split[0], 'field')
-        self.assertEquals(api['android.SomeEnum'].fields[2].split[0], 'property')
-        self.assertEquals(api['android.SomeEnum'].ctors[0].split[0], 'ctor')
-        self.assertEquals(api['android.SomeEnum'].methods[0].split[0], 'method')
-
-class ParseV3Stream(unittest.TestCase):
-    def test_field_kinds(self):
-        api = apilint._parse_stream("""
-// Signature format: 3.0
-package a {
-
-  public final class ContextKt {
-    method public static inline <reified T> T! getSystemService(android.content.Context);
-    method public static inline void withStyledAttributes(android.content.Context, android.util.AttributeSet? set = null, int[] attrs, @AttrRes int defStyleAttr = 0, @StyleRes int defStyleRes = 0, kotlin.jvm.functions.Function1<? super android.content.res.TypedArray,kotlin.Unit> block);
-  }
-}
-        """.strip().split('\n'))
-        self.assertEquals(api['a.ContextKt'].methods[0].name, 'getSystemService')
-        self.assertEquals(api['a.ContextKt'].methods[0].split[:4], ['method', 'public', 'static', 'inline'])
-        self.assertEquals(api['a.ContextKt'].methods[1].name, 'withStyledAttributes')
-        self.assertEquals(api['a.ContextKt'].methods[1].split[:4], ['method', 'public', 'static', 'inline'])
-
-class V2TokenizerTests(unittest.TestCase):
-    def _test(self, raw, expected):
-        self.assertEquals(apilint.V2Tokenizer(raw).tokenize(), expected)
-
-    def test_simple(self):
-        self._test("  method public some.Type someName(some.Argument arg, int arg);",
-                   ['method', 'public', 'some.Type', 'someName', '(', 'some.Argument',
-                    'arg', ',', 'int', 'arg', ')', ';'])
-        self._test("class Some.Class extends SomeOther {",
-                   ['class', 'Some.Class', 'extends', 'SomeOther', '{'])
-
-    def test_varargs(self):
-        self._test("name(String...)",
-                   ['name', '(', 'String', '...', ')'])
-
-    def test_kotlin(self):
-        self._test("String? name(String!...)",
-                   ['String', '?', 'name', '(', 'String', '!',  '...', ')'])
-
-    def test_annotation(self):
-        self._test("method @Nullable public void name();",
-                   ['method', '@', 'Nullable', 'public', 'void', 'name', '(', ')', ';'])
-
-    def test_annotation_args(self):
-        self._test("@Some(val=1, other=2) class Class {",
-                   ['@', 'Some', '(', 'val', '=', '1', ',', 'other', '=', '2', ')',
-                    'class', 'Class', '{'])
-    def test_comment(self):
-        self._test("some //comment", ['some'])
-
-    def test_strings(self):
-        self._test(r'"" "foo" "\"" "\\"', ['""', '"foo"', r'"\""', r'"\\"'])
-
-    def test_at_interface(self):
-        self._test("public @interface Annotation {",
-                   ['public', '@interface', 'Annotation', '{'])
-
-    def test_array_type(self):
-        self._test("int[][]", ['int', '[]', '[]'])
-
-    def test_generics(self):
-        self._test("<>foobar<A extends Object>",
-                   ['<', '>', 'foobar', '<', 'A', 'extends', 'Object', '>'])
-
-class V2ParserTests(unittest.TestCase):
-    def _cls(self, raw):
-        pkg = apilint.Package(999, "package pkg {", None)
-        return apilint.Class(pkg, 1, raw, '', sig_format=2)
-
-    def _method(self, raw, cls=None):
-        if not cls:
-            cls = self._cls("class Class {")
-        return apilint.Method(cls, 1, raw, '', sig_format=2)
-
-    def _field(self, raw):
-        cls = self._cls("class Class {")
-        return apilint.Field(cls, 1, raw, '', sig_format=2)
-
-    def test_parse_package(self):
-        pkg = apilint.Package(999, "package wifi.p2p {", None)
-        self.assertEquals("wifi.p2p", pkg.name)
-
-    def test_class(self):
-        cls = self._cls("@Deprecated @IntRange(from=1, to=2) public static abstract class Some.Name extends Super<Class> implements Interface<Class> {")
-        self.assertTrue('deprecated' in cls.split)
-        self.assertTrue('static' in cls.split)
-        self.assertTrue('abstract' in cls.split)
-        self.assertTrue('class' in cls.split)
-        self.assertEquals('Super', cls.extends)
-        self.assertEquals('Interface', cls.implements)
-        self.assertEquals('pkg.Some.Name', cls.fullname)
-
-    def test_enum(self):
-        cls = self._cls("public enum Some.Name {")
-        self._field("enum_constant public static final android.ValueType COLOR;")
-
-    def test_interface(self):
-        cls = self._cls("@Deprecated @IntRange(from=1, to=2) public interface Some.Name extends Interface<Class> {")
-        self.assertTrue('deprecated' in cls.split)
-        self.assertTrue('interface' in cls.split)
-        self.assertEquals('Interface', cls.extends)
-        self.assertEquals('Interface', cls.implements)
-        self.assertEquals('pkg.Some.Name', cls.fullname)
-
-    def test_at_interface(self):
-        cls = self._cls("@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE, java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.PARAMETER, java.lang.annotation.ElementType.CONSTRUCTOR, java.lang.annotation.ElementType.LOCAL_VARIABLE}) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) public @interface SuppressLint {")
-        self.assertTrue('@interface' in cls.split)
-        self.assertEquals('pkg.SuppressLint', cls.fullname)
-
-    def test_parse_method(self):
-        m = self._method("method @Deprecated public static native <T> Class<T>[][] name("
-                         + "Class<T[]>[][], Class<T[][][]>[][]...) throws Exception, T;")
-        self.assertTrue('static' in m.split)
-        self.assertTrue('public' in m.split)
-        self.assertTrue('method' in m.split)
-        self.assertTrue('native' in m.split)
-        self.assertTrue('deprecated' in m.split)
-        self.assertEquals('java.lang.Class[][]', m.typ)
-        self.assertEquals('name', m.name)
-        self.assertEquals(['java.lang.Class[][]', 'java.lang.Class[][]...'], m.args)
-        self.assertEquals(['java.lang.Exception', 'T'], m.throws)
-
-    def test_ctor(self):
-        m = self._method("ctor @Deprecated <T> ClassName();")
-        self.assertTrue('ctor' in m.split)
-        self.assertTrue('deprecated' in m.split)
-        self.assertEquals('ctor', m.typ)
-        self.assertEquals('ClassName', m.name)
-
-    def test_parse_annotation_method(self):
-        cls = self._cls("@interface Annotation {")
-        self._method('method abstract String category() default "";', cls=cls)
-        self._method('method abstract boolean deepExport() default false;', cls=cls)
-        self._method('method abstract ViewDebug.FlagToString[] flagMapping() default {};', cls=cls)
-        self._method('method abstract ViewDebug.FlagToString[] flagMapping() default (double)java.lang.Float.NEGATIVE_INFINITY;', cls=cls)
-
-    def test_parse_string_field(self):
-        f = self._field('field @Deprecated public final String SOME_NAME = "value";')
-        self.assertTrue('field' in f.split)
-        self.assertTrue('deprecated' in f.split)
-        self.assertTrue('final' in f.split)
-        self.assertEquals('java.lang.String', f.typ)
-        self.assertEquals('SOME_NAME', f.name)
-        self.assertEquals('value', f.value)
-
-    def test_parse_field(self):
-        f = self._field('field public Object SOME_NAME;')
-        self.assertTrue('field' in f.split)
-        self.assertEquals('java.lang.Object', f.typ)
-        self.assertEquals('SOME_NAME', f.name)
-        self.assertEquals(None, f.value)
-
-    def test_parse_int_field(self):
-        f = self._field('field public int NAME = 123;')
-        self.assertTrue('field' in f.split)
-        self.assertEquals('int', f.typ)
-        self.assertEquals('NAME', f.name)
-        self.assertEquals('123', f.value)
-
-    def test_parse_quotient_field(self):
-        f = self._field('field public int NAME = (0.0/0.0);')
-        self.assertTrue('field' in f.split)
-        self.assertEquals('int', f.typ)
-        self.assertEquals('NAME', f.name)
-        self.assertEquals('( 0.0 / 0.0 )', f.value)
-
-    def test_kotlin_types(self):
-        self._field('field public List<Integer[]?[]!>?[]![]? NAME;')
-        self._method("method <T?> Class<T!>?[]![][]? name(Type!, Type argname,"
-                         + "Class<T?>[][]?[]!...!) throws Exception, T;")
-        self._method("method <T> T name(T a = 1, T b = A(1), Lambda f = { false }, N? n = null, "
-                         + """double c = (1/0), float d = 1.0f, String s = "heyo", char c = 'a');""")
-
-    def test_kotlin_operator(self):
-        self._method('method public operator void unaryPlus(androidx.navigation.NavDestination);')
-        self._method('method public static operator androidx.navigation.NavDestination get(androidx.navigation.NavGraph, @IdRes int id);')
-        self._method('method public static operator <T> T get(androidx.navigation.NavigatorProvider, kotlin.reflect.KClass<T> clazz);')
-
-    def test_kotlin_property(self):
-        self._field('property public VM value;')
-        self._field('property public final String? action;')
-
-    def test_kotlin_varargs(self):
-        self._method('method public void error(int p = "42", Integer int2 = "null", int p1 = "42", vararg String args);')
-
-    def test_kotlin_default_values(self):
-        self._method('method public void foo(String! = null, String! = "Hello World", int = 42);')
-        self._method('method void method(String, String firstArg = "hello", int secondArg = "42", String thirdArg = "world");')
-        self._method('method void method(String, String firstArg = "hello", int secondArg = "42");')
-        self._method('method void method(String, String firstArg = "hello");')
-        self._method('method void edit(android.Type, boolean commit = false, Function1<? super Editor,kotlin.Unit> action);')
-        self._method('method <K, V> LruCache<K,V> lruCache(int maxSize, Function2<? super K,? super V,java.lang.Integer> sizeOf = { _, _ -> 1 }, Function1<? extends V> create = { (V)null }, Function4<kotlin.Unit> onEntryRemoved = { _, _, _, _ ->  });')
-        self._method('method android.Bitmap? drawToBitmap(android.View, android.Config config = android.graphics.Bitmap.Config.ARGB_8888);')
-        self._method('method void emptyLambda(Function0<kotlin.Unit> sizeOf = {});')
-        self._method('method void method1(int p = 42, Integer? int2 = null, int p1 = 42, String str = "hello world", java.lang.String... args);')
-        self._method('method void method2(int p, int int2 = (2 * int) * some.other.pkg.Constants.Misc.SIZE);')
-        self._method('method void method3(String str, int p, int int2 = double(int) + str.length);')
-        self._method('method void print(test.pkg.Foo foo = test.pkg.Foo());')
-
-    def test_type_use_annotation(self):
-        self._method('method public static int codePointAt(char @NonNull [], int);')
-        self._method('method @NonNull public java.util.Set<java.util.Map.@NonNull Entry<K,V>> entrySet();')
-
-        m = self._method('method @NonNull public java.lang.annotation.@NonNull Annotation @NonNull [] getAnnotations();')
-        self.assertEquals('java.lang.annotation.Annotation[]', m.typ)
-
-        m = self._method('method @NonNull public abstract java.lang.annotation.@NonNull Annotation @NonNull [] @NonNull [] getParameterAnnotations();')
-        self.assertEquals('java.lang.annotation.Annotation[][]', m.typ)
-
-        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)
-
-class FilterTests(unittest.TestCase):
-    def test_filter_match_prefix(self):
-        self.assertTrue(apilint.match_filter(["a"], "a.B"))
-        self.assertTrue(apilint.match_filter(["a.B"], "a.B.C"))
-
-    def test_filter_dont_match_prefix(self):
-        self.assertFalse(apilint.match_filter(["c"], "a.B"))
-        self.assertFalse(apilint.match_filter(["a."], "a.B"))
-        self.assertFalse(apilint.match_filter(["a.B."], "a.B.C"))
-
-    def test_filter_match_exact(self):
-        self.assertTrue(apilint.match_filter(["a.B"], "a.B"))
-
-    def test_filter_dont_match_exact(self):
-        self.assertFalse(apilint.match_filter([""], "a.B"))
-        self.assertFalse(apilint.match_filter(["a.C"], "a.B"))
-        self.assertFalse(apilint.match_filter(["a.C"], "a.B"))
-        
-if __name__ == "__main__":
-    unittest.main()