Merge "Workaround launching PiP task with CLEAR_TASK & NEW_TASK flag." into oc-dev
diff --git a/api/current.txt b/api/current.txt
index 157a72c..899381b 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -30508,7 +30508,7 @@
     field public static final int M = 23; // 0x17
     field public static final int N = 24; // 0x18
     field public static final int N_MR1 = 25; // 0x19
-    field public static final int O = 26; // 0x1a
+    field public static final int O = 10000; // 0x2710
   }
 
   public final class Bundle extends android.os.BaseBundle implements java.lang.Cloneable android.os.Parcelable {
diff --git a/api/system-current.txt b/api/system-current.txt
index 110d1dd..8aa6c36 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -33218,7 +33218,7 @@
     field public static final int M = 23; // 0x17
     field public static final int N = 24; // 0x18
     field public static final int N_MR1 = 25; // 0x19
-    field public static final int O = 26; // 0x1a
+    field public static final int O = 10000; // 0x2710
   }
 
   public final class Bundle extends android.os.BaseBundle implements java.lang.Cloneable android.os.Parcelable {
diff --git a/api/test-current.txt b/api/test-current.txt
index ef2fce7..944a350 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -30617,7 +30617,7 @@
     field public static final int M = 23; // 0x17
     field public static final int N = 24; // 0x18
     field public static final int N_MR1 = 25; // 0x19
-    field public static final int O = 26; // 0x1a
+    field public static final int O = 10000; // 0x2710
   }
 
   public final class Bundle extends android.os.BaseBundle implements java.lang.Cloneable android.os.Parcelable {
diff --git a/cmds/vr/src/com/android/commands/vr/Vr.java b/cmds/vr/src/com/android/commands/vr/Vr.java
index bf97bba..b765866 100644
--- a/cmds/vr/src/com/android/commands/vr/Vr.java
+++ b/cmds/vr/src/com/android/commands/vr/Vr.java
@@ -16,7 +16,7 @@
 
 package com.android.commands.vr;
 
-import android.app.CompatibilityDisplayProperties;
+import android.app.Vr2dDisplayProperties;
 import android.content.Context;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -39,7 +39,7 @@
 
     private static final String COMMAND_SET_PERSISTENT_VR_MODE_ENABLED =
         "set-persistent-vr-mode-enabled";
-    private static final String COMMAND_SET_COMPATIBILITY_DISPLAY_PROPERTIES =
+    private static final String COMMAND_SET_VR2D_DISPLAY_PROPERTIES =
         "set-display-props";
 
     private IVrManager mVrService;
@@ -63,8 +63,8 @@
 
         String command = nextArgRequired();
         switch (command) {
-            case COMMAND_SET_COMPATIBILITY_DISPLAY_PROPERTIES:
-                runSetCompatibilityDisplayProperties();
+            case COMMAND_SET_VR2D_DISPLAY_PROPERTIES:
+                runSetVr2dDisplayProperties();
                 break;
             case COMMAND_SET_PERSISTENT_VR_MODE_ENABLED:
                 runSetPersistentVrModeEnabled();
@@ -74,7 +74,7 @@
         }
     }
 
-    private void runSetCompatibilityDisplayProperties() throws RemoteException {
+    private void runSetVr2dDisplayProperties() throws RemoteException {
         String widthStr = nextArgRequired();
         int width = Integer.parseInt(widthStr);
 
@@ -84,11 +84,11 @@
         String dpiStr = nextArgRequired();
         int dpi = Integer.parseInt(dpiStr);
 
-        CompatibilityDisplayProperties compatDisplayProperties =
-                new CompatibilityDisplayProperties(width, height, dpi);
+        Vr2dDisplayProperties vr2dDisplayProperties =
+                new Vr2dDisplayProperties(width, height, dpi);
 
         try {
-            mVrService.setCompatibilityDisplayProperties(compatDisplayProperties);
+            mVrService.setVr2dDisplayProperties(vr2dDisplayProperties);
         } catch (RemoteException re) {
             System.err.println("Error: Can't set persistent mode " + re);
         }
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index 65cb5f4..0dfaf6a 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -244,8 +244,8 @@
 
     /**
      * Called after virtual display Id is updated by
-     * {@link com.android.server.vr.CompatibilityDisplay} with a specific
-     * {@param compatibilityDisplayId}.
+     * {@link com.android.server.vr.Vr2dDisplay} with a specific
+     * {@param vr2dDisplayId}.
      */
-    public abstract void setVrCompatibilityDisplayId(int vrCompatibilityDisplayId);
+    public abstract void setVr2dDisplayId(int vr2dDisplayId);
 }
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index c8b8c6c..2e56bcf 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -4358,6 +4358,8 @@
             mN.mLargeIcon = null;
             Bitmap largeIconLegacy = mN.largeIcon;
             mN.largeIcon = null;
+            ArrayList<Action> actions = mActions;
+            mActions = new ArrayList<>();
             Bundle publicExtras = new Bundle();
             publicExtras.putBoolean(EXTRA_SHOW_WHEN,
                     savedBundle.getBoolean(EXTRA_SHOW_WHEN));
@@ -4373,6 +4375,7 @@
             mN.extras = savedBundle;
             mN.mLargeIcon = largeIcon;
             mN.largeIcon = largeIconLegacy;
+            mActions = actions;
             mStyle = style;
             return view;
         }
diff --git a/core/java/android/app/CompatibilityDisplayProperties.aidl b/core/java/android/app/Vr2dDisplayProperties.aidl
similarity index 93%
rename from core/java/android/app/CompatibilityDisplayProperties.aidl
rename to core/java/android/app/Vr2dDisplayProperties.aidl
index 626a63e..1e04943 100644
--- a/core/java/android/app/CompatibilityDisplayProperties.aidl
+++ b/core/java/android/app/Vr2dDisplayProperties.aidl
@@ -17,4 +17,4 @@
 package android.app;
 
 /** @hide */
-parcelable CompatibilityDisplayProperties;
+parcelable Vr2dDisplayProperties;
diff --git a/core/java/android/app/CompatibilityDisplayProperties.java b/core/java/android/app/Vr2dDisplayProperties.java
similarity index 75%
rename from core/java/android/app/CompatibilityDisplayProperties.java
rename to core/java/android/app/Vr2dDisplayProperties.java
index 9a9bc2c..a608bb0 100644
--- a/core/java/android/app/CompatibilityDisplayProperties.java
+++ b/core/java/android/app/Vr2dDisplayProperties.java
@@ -27,7 +27,7 @@
  *
  * @hide
  */
-public class CompatibilityDisplayProperties implements Parcelable {
+public class Vr2dDisplayProperties implements Parcelable {
 
    /**
     * The actual width, height and dpi.
@@ -36,7 +36,7 @@
     private final int mHeight;
     private final int mDpi;
 
-    public CompatibilityDisplayProperties(int width, int height, int dpi) {
+    public Vr2dDisplayProperties(int width, int height, int dpi) {
         mWidth = width;
         mHeight = height;
         mDpi = dpi;
@@ -52,7 +52,7 @@
 
     @Override
     public String toString() {
-        return "CompatibilityDisplayProperties{" +
+        return "Vr2dDisplayProperties{" +
                 "mWidth=" + mWidth +
                 ", mHeight=" + mHeight +
                 ", mDpi=" + mDpi +
@@ -64,7 +64,7 @@
         if (this == o) return true;
         if (o == null || getClass() != o.getClass()) return false;
 
-        CompatibilityDisplayProperties that = (CompatibilityDisplayProperties) o;
+        Vr2dDisplayProperties that = (Vr2dDisplayProperties) o;
 
         if (getWidth() != that.getWidth()) return false;
         if (getHeight() != that.getHeight()) return false;
@@ -83,27 +83,27 @@
         dest.writeInt(mDpi);
     }
 
-    public static final Parcelable.Creator<CompatibilityDisplayProperties> CREATOR
-            = new Parcelable.Creator<CompatibilityDisplayProperties>() {
+    public static final Parcelable.Creator<Vr2dDisplayProperties> CREATOR
+            = new Parcelable.Creator<Vr2dDisplayProperties>() {
         @Override
-        public CompatibilityDisplayProperties createFromParcel(Parcel source) {
-            return new CompatibilityDisplayProperties(source);
+        public Vr2dDisplayProperties createFromParcel(Parcel source) {
+            return new Vr2dDisplayProperties(source);
         }
 
         @Override
-        public CompatibilityDisplayProperties[] newArray(int size) {
-            return new CompatibilityDisplayProperties[size];
+        public Vr2dDisplayProperties[] newArray(int size) {
+            return new Vr2dDisplayProperties[size];
         }
     };
 
-    private CompatibilityDisplayProperties(Parcel source) {
+    private Vr2dDisplayProperties(Parcel source) {
         mWidth = source.readInt();
         mHeight = source.readInt();
         mDpi = source.readInt();
     }
 
     public void dump(PrintWriter pw, String prefix) {
-        pw.println(prefix + "CompatibilityDisplayProperties:");
+        pw.println(prefix + "Vr2dDisplayProperties:");
         pw.println(prefix + "  width=" + mWidth);
         pw.println(prefix + "  height=" + mHeight);
         pw.println(prefix + "  dpi=" + mDpi);
diff --git a/core/java/android/app/VrManager.java b/core/java/android/app/VrManager.java
index 878c8c3..040b330 100644
--- a/core/java/android/app/VrManager.java
+++ b/core/java/android/app/VrManager.java
@@ -45,20 +45,20 @@
     }
 
     /**
-     * Sets the resolution and DPI of the compatibility virtual display used to display 2D
+     * Sets the resolution and DPI of the vr2d virtual display used to display 2D
      * applications in VR mode.
      *
      * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
      *
-     * @param {@link android.app.CompatibilityDisplayProperties} properties to be set to the
-     * virtual display for 2D applications in VR mode.
+     * @param vr2dDisplayProp properties to be set to the virtual display for
+     * 2D applications in VR mode.
      *
      * {@hide}
      */
-    public void setCompatibilityDisplayProperties(
-            CompatibilityDisplayProperties compatDisplayProp) {
+    public void setVr2dDisplayProperties(
+            Vr2dDisplayProperties vr2dDisplayProp) {
         try {
-            mService.setCompatibilityDisplayProperties(compatDisplayProp);
+            mService.setVr2dDisplayProperties(vr2dDisplayProp);
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java
index 3353530..7261dfa 100644
--- a/core/java/android/app/assist/AssistStructure.java
+++ b/core/java/android/app/assist/AssistStructure.java
@@ -1559,14 +1559,14 @@
         @Override
         public void setText(CharSequence text) {
             ViewNodeText t = getNodeText();
-            t.mText = text;
+            t.mText = TextUtils.trimNoCopySpans(text);
             t.mTextSelectionStart = t.mTextSelectionEnd = -1;
         }
 
         @Override
         public void setText(CharSequence text, int selectionStart, int selectionEnd) {
             ViewNodeText t = getNodeText();
-            t.mText = text;
+            t.mText = TextUtils.trimNoCopySpans(text);
             t.mTextSelectionStart = selectionStart;
             t.mTextSelectionEnd = selectionEnd;
         }
@@ -1737,13 +1737,6 @@
         }
 
         @Override
-        public void setUrl(String url) {
-            if (url == null) return;
-
-            setWebDomain(url);
-        }
-
-        @Override
         public void setWebDomain(@Nullable String domain) {
             if (domain == null) {
                 mNode.mWebDomain = null;
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java
index d1ad8de..c58eaa1 100644
--- a/core/java/android/bluetooth/BluetoothA2dp.java
+++ b/core/java/android/bluetooth/BluetoothA2dp.java
@@ -136,6 +136,38 @@
      */
     public static final int STATE_NOT_PLAYING   =  11;
 
+    /**
+     * We don't have a stored preference for whether or not the given A2DP sink device supports
+     * optional codecs.
+     * @hide */
+    public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1;
+
+    /**
+     * The given A2DP sink device does not support optional codecs.
+     * @hide */
+    public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0;
+
+    /**
+     * The given A2DP sink device does support optional codecs.
+     * @hide */
+    public static final int OPTIONAL_CODECS_SUPPORTED = 1;
+
+    /**
+     * We don't have a stored preference for whether optional codecs should be enabled or disabled
+     * for the given A2DP device.
+     * @hide */
+    public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1;
+
+    /**
+     * Optional codecs should be disabled for the given A2DP device.
+     * @hide */
+    public static final int OPTIONAL_CODECS_PREF_DISABLED = 0;
+
+    /**
+     *  Optional codecs should be enabled for the given A2DP device.
+     *  @hide */
+    public static final int OPTIONAL_CODECS_PREF_ENABLED = 1;
+
     private Context mContext;
     private ServiceListener mServiceListener;
     private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock();
@@ -655,6 +687,88 @@
     }
 
     /**
+     * Returns whether this device supports optional codecs.
+     *
+     * @param device The device to check
+     * @return one of OPTIONAL_CODECS_SUPPORT_UNKNOWN, OPTIONAL_CODECS_NOT_SUPPORTED, or
+     *         OPTIONAL_CODECS_SUPPORTED.
+     *
+     * @hide
+     */
+    public int supportsOptionalCodecs(BluetoothDevice device) {
+        try {
+            mServiceLock.readLock().lock();
+            if (mService != null && isEnabled() && isValidDevice(device)) {
+                return mService.supportsOptionalCodecs(device);
+            }
+            if (mService == null) Log.w(TAG, "Proxy not attached to service");
+            return OPTIONAL_CODECS_SUPPORT_UNKNOWN;
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e);
+            return OPTIONAL_CODECS_SUPPORT_UNKNOWN;
+        } finally {
+            mServiceLock.readLock().unlock();
+        }
+    }
+
+    /**
+     * Returns whether this device should have optional codecs enabled.
+     *
+     * @param device The device in question.
+     * @return one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or
+     *         OPTIONAL_CODECS_PREF_DISABLED.
+     *
+     * @hide
+     */
+    public int getOptionalCodecsEnabled(BluetoothDevice device) {
+        try {
+            mServiceLock.readLock().lock();
+            if (mService != null && isEnabled() && isValidDevice(device)) {
+                return mService.getOptionalCodecsEnabled(device);
+            }
+            if (mService == null) Log.w(TAG, "Proxy not attached to service");
+            return OPTIONAL_CODECS_PREF_UNKNOWN;
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e);
+            return OPTIONAL_CODECS_PREF_UNKNOWN;
+        } finally {
+            mServiceLock.readLock().unlock();
+        }
+    }
+
+    /**
+     * Sets a persistent preference for whether a given device should have optional codecs enabled.
+     *
+     * @param device The device to set this preference for.
+     * @param value Whether the optional codecs should be enabled for this device.  This should be
+     *              one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or
+     *              OPTIONAL_CODECS_PREF_DISABLED.
+     * @hide
+     */
+    public void setOptionalCodecsEnabled(BluetoothDevice device, int value) {
+        try {
+            if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN &&
+                    value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED &&
+                    value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
+                Log.e(TAG, "Invalid value passed to setOptionalCodecsEnabled: " + value);
+                return;
+            }
+            mServiceLock.readLock().lock();
+            if (mService != null && isEnabled()
+                    && isValidDevice(device)) {
+                mService.setOptionalCodecsEnabled(device, value);
+            }
+            if (mService == null) Log.w(TAG, "Proxy not attached to service");
+            return;
+        } catch (RemoteException e) {
+            Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
+            return;
+        } finally {
+            mServiceLock.readLock().unlock();
+        }
+    }
+
+    /**
      * Helper for converting a state to a string.
      *
      * For debug use only - strings are not internationalized.
diff --git a/core/java/android/bluetooth/IBluetoothA2dp.aidl b/core/java/android/bluetooth/IBluetoothA2dp.aidl
index a775a1f..1b533cb 100644
--- a/core/java/android/bluetooth/IBluetoothA2dp.aidl
+++ b/core/java/android/bluetooth/IBluetoothA2dp.aidl
@@ -42,4 +42,7 @@
     oneway void setCodecConfigPreference(in BluetoothCodecConfig codecConfig);
     oneway void enableOptionalCodecs();
     oneway void disableOptionalCodecs();
+    int supportsOptionalCodecs(in BluetoothDevice device);
+    int getOptionalCodecsEnabled(in BluetoothDevice device);
+    oneway void setOptionalCodecsEnabled(in BluetoothDevice device, int value);
 }
diff --git a/core/java/android/net/INetworkScoreService.aidl b/core/java/android/net/INetworkScoreService.aidl
index 73e52c8..d163a44 100644
--- a/core/java/android/net/INetworkScoreService.aidl
+++ b/core/java/android/net/INetworkScoreService.aidl
@@ -45,7 +45,7 @@
      * Set the active scorer and clear existing scores.
      * @param packageName the package name of the new scorer to use.
      * @return true if the operation succeeded, or false if the new package is not a valid scorer.
-     * @throws SecurityException if the caller is not the system.
+     * @throws SecurityException if the caller is not the system or a network scorer.
      */
     boolean setActiveScorer(in String packageName);
 
diff --git a/core/java/android/net/NetworkScoreManager.java b/core/java/android/net/NetworkScoreManager.java
index eeb426a..9f6e45c 100644
--- a/core/java/android/net/NetworkScoreManager.java
+++ b/core/java/android/net/NetworkScoreManager.java
@@ -16,27 +16,20 @@
 
 package android.net;
 
-import static android.net.NetworkRecommendationProvider.EXTRA_RECOMMENDATION_RESULT;
-
+import android.Manifest.permission;
 import android.annotation.IntDef;
-import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
 import android.annotation.SystemApi;
 import android.content.Context;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.RemoteCallback;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.ServiceManager.ServiceNotFoundException;
-import com.android.internal.util.Preconditions;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.List;
-import java.util.concurrent.CompletableFuture;
 
 /**
  * Class that manages communication between network subsystems and a network scorer.
@@ -49,9 +42,9 @@
  *
  * <p>A network scorer is any application which:
  * <ul>
- * <li>Declares the {@link android.Manifest.permission#SCORE_NETWORKS} permission.
+ * <li>Declares the {@link permission#SCORE_NETWORKS} permission.
  * <li>Include a Service for the {@link #ACTION_RECOMMEND_NETWORKS} action
- *     protected by the {@link android.Manifest.permission#BIND_NETWORK_RECOMMENDATION_SERVICE}
+ *     protected by the {@link permission#BIND_NETWORK_RECOMMENDATION_SERVICE}
  *     permission.
  * </ul>
  *
@@ -319,7 +312,7 @@
      *
      * @return true if the operation succeeded, or false if the new package is not a valid scorer.
      * @throws SecurityException if the caller is not a system process or does not hold the
-     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission
+     *         {@link permission#SCORE_NETWORKS} permission
      * @hide
      */
     @SystemApi
@@ -351,7 +344,7 @@
      *
      * @return true if the broadcast was sent, or false if there is no active scorer.
      * @throws SecurityException if the caller does not hold the
-     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
+     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
      * @hide
      */
     public boolean requestScores(NetworkKey[] networks) throws SecurityException {
@@ -368,7 +361,7 @@
      * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
      * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
      * @throws SecurityException if the caller does not hold the
-     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
+     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
      * @throws IllegalArgumentException if a score cache is already registered for this type.
      * @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE.
      * @hide
@@ -385,7 +378,7 @@
      * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
      * @param filterType the {@link CacheUpdateFilter} to apply
      * @throws SecurityException if the caller does not hold the
-     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
+     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
      * @throws IllegalArgumentException if a score cache is already registered for this type.
      * @hide
      */
@@ -404,7 +397,7 @@
      * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
      * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
      * @throws SecurityException if the caller does not hold the
-     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
+     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
      * @throws IllegalArgumentException if a score cache is already registered for this type.
      * @hide
      */
@@ -417,25 +410,6 @@
     }
 
     /**
-     * Request a recommendation for which network to connect to.
-     *
-     * <p>It is not safe to call this method from the main thread.
-     *
-     * @param request a {@link RecommendationRequest} instance containing additional
-     *                request details
-     * @return a {@link RecommendationResult} instance containing the recommended network
-     *         to connect to
-     * @throws SecurityException if the caller does not hold the
-     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
-     * @hide
-     * @deprecated to be removed.
-     */
-    public RecommendationResult requestRecommendation(RecommendationRequest request)
-            throws SecurityException {
-        return null;
-    }
-
-    /**
      * Determine whether the application with the given UID is the enabled scorer.
      *
      * @param callingUid the UID to check
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 4bad7ab..86fcfc8 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -758,7 +758,7 @@
         /**
          * O.
          */
-        public static final int O = 26;
+        public static final int O = CUR_DEVELOPMENT; // STOPSHIP Replace with the real version.
     }
 
     /** The type of build, like "user" or "eng". */
diff --git a/core/java/android/os/VintfObject.java b/core/java/android/os/VintfObject.java
index 1ef3916..8302ece 100644
--- a/core/java/android/os/VintfObject.java
+++ b/core/java/android/os/VintfObject.java
@@ -26,17 +26,12 @@
     private static final String LOG_TAG = "VintfObject";
 
     /**
-     * Slurps all device information (both manifests)
-     * and report it.
+     * Slurps all device information (both manifests and both matrices)
+     * and report them.
      * If any error in getting one of the manifests, it is not included in
      * the list.
      */
-    public static String[] report() {
-        ArrayList<String> ret = new ArrayList<>();
-        put(ret, getDeviceManifest(), "device manifest");
-        put(ret, getFrameworkManifest(), "framework manifest");
-        return ret.toArray(new String[0]);
-    }
+    public static native String[] report();
 
     /**
      * Verify that the given metadata for an OTA package is compatible with
@@ -50,15 +45,4 @@
      */
     public static native int verify(String[] packageInfo);
 
-    // return null if any error, otherwise XML string.
-    private static native String getDeviceManifest();
-    private static native String getFrameworkManifest();
-
-    private static void put(ArrayList<String> list, String content, String message) {
-        if (content == null || content.length() == 0) {
-            Log.e(LOG_TAG, "Cannot get;" + message + "; check native logs for details.");
-            return;
-        }
-        list.add(content);
-    }
 }
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 024738a..1f423ea 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -8981,6 +8981,12 @@
         public static final String
                 BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX = "bluetooth_a2dp_src_priority_";
         /** {@hide} */
+        public static final String BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX =
+                "bluetooth_a2dp_supports_optional_codecs_";
+        /** {@hide} */
+        public static final String BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX =
+                "bluetooth_a2dp_optional_codecs_enabled_";
+        /** {@hide} */
         public static final String
                 BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX = "bluetooth_input_device_priority_";
         /** {@hide} */
@@ -9247,6 +9253,25 @@
         }
 
         /**
+         * Get the key that retrieves a bluetooth a2dp device's ability to support optional codecs.
+         * @hide
+         */
+        public static final String getBluetoothA2dpSupportsOptionalCodecsKey(String address) {
+            return BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX +
+                    address.toUpperCase(Locale.ROOT);
+        }
+
+        /**
+         * Get the key that retrieves whether a bluetooth a2dp device should have optional codecs
+         * enabled.
+         * @hide
+         */
+        public static final String getBluetoothA2dpOptionalCodecsEnabledKey(String address) {
+            return BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX +
+                    address.toUpperCase(Locale.ROOT);
+        }
+
+        /**
          * Get the key that retrieves a bluetooth Input Device's priority.
          * @hide
          */
@@ -10389,6 +10414,15 @@
         public static final String MAX_NOTIFICATION_ENQUEUE_RATE = "max_notification_enqueue_rate";
 
         /**
+         * Displays toasts when an app posts a notification that does not specify a valid channel.
+         *
+         * The value 1 - enable, 0 - disable
+         * @hide
+         */
+        public static final String SHOW_NOTIFICATION_CHANNEL_WARNINGS =
+                "show_notification_channel_warnings";
+
+        /**
          * Whether cell is enabled/disabled
          * @hide
          */
diff --git a/core/java/android/service/vr/IVrManager.aidl b/core/java/android/service/vr/IVrManager.aidl
index 8b2d0c6..fc8afe9 100644
--- a/core/java/android/service/vr/IVrManager.aidl
+++ b/core/java/android/service/vr/IVrManager.aidl
@@ -16,7 +16,7 @@
 
 package android.service.vr;
 
-import android.app.CompatibilityDisplayProperties;
+import android.app.Vr2dDisplayProperties;
 import android.service.vr.IVrStateCallbacks;
 import android.service.vr.IPersistentVrStateCallbacks;
 
@@ -68,16 +68,16 @@
     void setPersistentVrModeEnabled(in boolean enabled);
 
     /**
-     * Sets the resolution and DPI of the compatibility virtual display used to display
+     * Sets the resolution and DPI of the vr2d virtual display used to display
      * 2D applications in VR mode.
      *
      * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
      *
-     * @param compatDisplayProperties Compatibitlity display properties to be set for
+     * @param vr2dDisplayProperties Vr2d display properties to be set for
      * the VR virtual display
      */
-    void setCompatibilityDisplayProperties(
-            in CompatibilityDisplayProperties compatDisplayProperties);
+    void setVr2dDisplayProperties(
+            in Vr2dDisplayProperties vr2dDisplayProperties);
 
     /**
      * Return current virtual display id.
@@ -85,7 +85,7 @@
      * @return {@link android.view.Display.INVALID_DISPLAY} if there is no virtual display
      * currently, else return the display id of the virtual display
      */
-    int getCompatibilityDisplayId();
+    int getVr2dDisplayId();
 
     /**
      * Initiate connection for system controller data.
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java
index 081deeb..91f43d6 100644
--- a/core/java/android/text/TextUtils.java
+++ b/core/java/android/text/TextUtils.java
@@ -1921,6 +1921,22 @@
         return false;
     }
 
+    /**
+     * If the {@code charSequence} is instance of {@link Spanned}, creates a new copy and
+     * {@link NoCopySpan}'s are removed from the copy. Otherwise the given {@code charSequence} is
+     * returned as it is.
+     *
+     * @hide
+     */
+    @Nullable
+    public static CharSequence trimNoCopySpans(@Nullable CharSequence charSequence) {
+        if (charSequence != null && charSequence instanceof Spanned) {
+            // SpannableStringBuilder copy constructor trims NoCopySpans.
+            return new SpannableStringBuilder(charSequence);
+        }
+        return charSequence;
+    }
+
     private static Object sLock = new Object();
 
     private static char[] sTemp = null;
diff --git a/core/java/android/view/ViewStructure.java b/core/java/android/view/ViewStructure.java
index f71589c..6bdc9ff 100644
--- a/core/java/android/view/ViewStructure.java
+++ b/core/java/android/view/ViewStructure.java
@@ -374,13 +374,6 @@
     public abstract Rect getTempRect();
 
     /**
-     * @deprecated - use {@link #setWebDomain(String)} instead.
-     * @hide
-     */
-    @Deprecated
-    public abstract void setUrl(String url);
-
-    /**
      * Sets the Web domain represented by this node.
      *
      * <p>Typically used when the view is a container for an HTML document.
diff --git a/core/java/android/view/autofill/AutofillValue.java b/core/java/android/view/autofill/AutofillValue.java
index b57dab5..3beae11 100644
--- a/core/java/android/view/autofill/AutofillValue.java
+++ b/core/java/android/view/autofill/AutofillValue.java
@@ -26,6 +26,7 @@
 import android.annotation.Nullable;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.TextUtils;
 import android.view.View;
 
 import com.android.internal.util.Preconditions;
@@ -257,7 +258,8 @@
      * <p>See {@link View#AUTOFILL_TYPE_TEXT} for more info.
      */
     public static AutofillValue forText(@Nullable CharSequence value) {
-        return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT, value);
+        return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT,
+                TextUtils.trimNoCopySpans(value));
     }
 
     /**
diff --git a/core/java/android/view/textclassifier/TextClassifierImpl.java b/core/java/android/view/textclassifier/TextClassifierImpl.java
index ebf1c01..209ff09 100644
--- a/core/java/android/view/textclassifier/TextClassifierImpl.java
+++ b/core/java/android/view/textclassifier/TextClassifierImpl.java
@@ -607,6 +607,7 @@
         @Nullable
         public static Intent create(Context context, String type, String text) {
             type = type.trim().toLowerCase(Locale.ENGLISH);
+            text = text.trim();
             switch (type) {
                 case TextClassifier.TYPE_EMAIL:
                     return new Intent(Intent.ACTION_SENDTO)
@@ -618,6 +619,9 @@
                     return new Intent(Intent.ACTION_VIEW)
                             .setData(Uri.parse(String.format("geo:0,0?q=%s", text)));
                 case TextClassifier.TYPE_URL:
+                    if (!text.startsWith("https://") && !text.startsWith("http://")) {
+                        text = "http://" + text;
+                    }
                     return new Intent(Intent.ACTION_VIEW, Uri.parse(text))
                             .putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
                 default:
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index ad3a99d..b0d6395 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -1404,6 +1404,11 @@
             // or double-clicks that could "dismiss" the floating toolbar.
             int delay = ViewConfiguration.getDoubleTapTimeout();
             mTextView.postDelayed(mShowFloatingToolbar, delay);
+
+            // This classifies the text and most likely returns before the toolbar is actually
+            // shown. If not, it will update the toolbar with the result when classification
+            // returns. We would rather not wait for a long running classification process.
+            invalidateActionModeAsync();
         }
     }
 
@@ -1853,7 +1858,7 @@
             mInsertionPointCursorController.invalidateHandle();
         }
         if (mTextActionMode != null) {
-            invalidateActionModeAsync();
+            invalidateActionMode();
         }
     }
 
@@ -1945,12 +1950,12 @@
                 if (mRestartActionModeOnNextRefresh) {
                     // To avoid distraction, newly start action mode only when selection action
                     // mode is being restarted.
-                    startSelectionActionMode();
+                    startSelectionActionModeAsync(false);
                 }
             } else if (selectionController == null || !selectionController.isActive()) {
                 // Insertion action mode is active. Avoid dismissing the selection.
                 stopTextActionModeWithPreservingSelection();
-                startSelectionActionMode();
+                startSelectionActionModeAsync(false);
             } else {
                 mTextActionMode.invalidateContentRect();
             }
@@ -2004,15 +2009,8 @@
     /**
      * Asynchronously starts a selection action mode using the TextClassifier.
      */
-    void startSelectionActionModeAsync() {
-        getSelectionActionModeHelper().startActionModeAsync();
-    }
-
-    /**
-     * Synchronously starts a selection action mode without the TextClassifier.
-     */
-    void startSelectionActionMode() {
-        getSelectionActionModeHelper().startActionMode();
+    void startSelectionActionModeAsync(boolean adjustSelection) {
+        getSelectionActionModeHelper().startActionModeAsync(adjustSelection);
     }
 
     /**
@@ -2022,6 +2020,15 @@
         getSelectionActionModeHelper().invalidateActionModeAsync();
     }
 
+    /**
+     * Synchronously invalidates an action mode without the TextClassifier.
+     */
+    private void invalidateActionMode() {
+        if (mTextActionMode != null) {
+            mTextActionMode.invalidate();
+        }
+    }
+
     private SelectionActionModeHelper getSelectionActionModeHelper() {
         if (mSelectionActionModeHelper == null) {
             mSelectionActionModeHelper = new SelectionActionModeHelper(this);
@@ -2075,7 +2082,7 @@
         }
         if (mTextActionMode != null) {
             // Text action mode is already started
-            invalidateActionModeAsync();
+            invalidateActionMode();
             return false;
         }
 
@@ -4703,7 +4710,7 @@
             }
             positionAtCursorOffset(offset, false);
             if (mTextActionMode != null) {
-                invalidateActionModeAsync();
+                invalidateActionMode();
             }
         }
 
@@ -4787,7 +4794,7 @@
             }
             updateDrawable();
             if (mTextActionMode != null) {
-                invalidateActionModeAsync();
+                invalidateActionMode();
             }
         }
 
@@ -5414,13 +5421,8 @@
                     resetDragAcceleratorState();
 
                     if (mTextView.hasSelection()) {
-                        // Do not invoke the text assistant if this was a drag selection.
-                        if (mHaventMovedEnoughToStartDrag) {
-                            startSelectionActionModeAsync();
-                        } else {
-                            startSelectionActionMode();
-                        }
-
+                        // Drag selection should not be adjusted by the text classifier.
+                        startSelectionActionModeAsync(mHaventMovedEnoughToStartDrag);
                     }
                     break;
             }
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 1457d02..569fe01 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -49,7 +49,6 @@
 import android.widget.RemoteViews.RemoteView;
 
 import com.android.internal.R;
-import com.android.internal.util.Preconditions;
 
 import com.google.android.collect.Lists;
 
@@ -336,11 +335,6 @@
      * @param isSelectable whether the item is selectable
      */
     public void addHeaderView(View v, Object data, boolean isSelectable) {
-        Preconditions.checkState(
-                v.getParent() == null,
-                "The specified child already has a parent. "
-                + "You must call removeView() on the child's parent first.");
-
         final FixedViewInfo info = new FixedViewInfo();
         info.view = v;
         info.data = data;
@@ -435,11 +429,6 @@
      * @param isSelectable true if the footer view can be selected
      */
     public void addFooterView(View v, Object data, boolean isSelectable) {
-        Preconditions.checkState(
-                v.getParent() == null,
-                "The specified child already has a parent. "
-                + "You must call removeView() on the child's parent first.");
-
         final FixedViewInfo info = new FixedViewInfo();
         info.view = v;
         info.data = data;
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index c9d172f..16a1087 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -65,7 +65,7 @@
                 textView.getTextClassifier(), textView.getText(), 0, 1, textView.getTextLocales());
     }
 
-    public void startActionModeAsync() {
+    public void startActionModeAsync(boolean adjustSelection) {
         cancelAsyncTask();
         if (isNoOpTextClassifier() || !hasSelection()) {
             // No need to make an async call for a no-op TextClassifier.
@@ -74,16 +74,16 @@
         } else {
             resetTextClassificationHelper();
             mTextClassificationAsyncTask = new TextClassificationAsyncTask(
-                    mEditor.getTextView(), TIMEOUT_DURATION,
-                    mTextClassificationHelper::suggestSelection, this::startActionMode)
+                    mEditor.getTextView(),
+                    TIMEOUT_DURATION,
+                    adjustSelection
+                            ? mTextClassificationHelper::suggestSelection
+                            : mTextClassificationHelper::classifyText,
+                    this::startActionMode)
                     .execute();
         }
     }
 
-    public void startActionMode() {
-        startActionMode(null);
-    }
-
     public void invalidateActionModeAsync() {
         cancelAsyncTask();
         if (isNoOpTextClassifier() || !hasSelection()) {
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 242dcf5..eaf1115 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -10579,7 +10579,7 @@
                         Selection.setSelection((Spannable) text, start, end);
                         // Make sure selection mode is engaged.
                         if (mEditor != null) {
-                            mEditor.startSelectionActionMode();
+                            mEditor.startSelectionActionModeAsync(false);
                         }
                         return true;
                     }
diff --git a/core/jni/android_os_VintfObject.cpp b/core/jni/android_os_VintfObject.cpp
index 9491a1e..033f2df 100644
--- a/core/jni/android_os_VintfObject.cpp
+++ b/core/jni/android_os_VintfObject.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2017 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.
@@ -16,6 +16,10 @@
 
 #define LOG_TAG "VintfObject"
 //#define LOG_NDEBUG 0
+#include <android-base/logging.h>
+
+#include <vector>
+#include <string>
 
 #include <JNIHelp.h>
 #include <vintf/VintfObject.h>
@@ -23,31 +27,48 @@
 
 #include "core_jni_helpers.h"
 
+static jclass gString;
+
 namespace android {
 
-using vintf::HalManifest;
-using vintf::RuntimeInfo;
 using vintf::VintfObject;
 using vintf::gHalManifestConverter;
+using vintf::gCompatibilityMatrixConverter;
+using vintf::XmlConverter;
 
-static jstring android_os_VintfObject_getDeviceManifest(JNIEnv* env, jclass clazz)
-{
-    const HalManifest *manifest = VintfObject::GetDeviceHalManifest();
-    if (manifest == nullptr) {
-        return nullptr;
+static inline jobjectArray toJavaStringArray(JNIEnv* env, const std::vector<std::string>& v) {
+    jobjectArray ret = env->NewObjectArray(v.size(), gString, NULL /* init element */);
+    for (size_t i = 0; i < v.size(); ++i) {
+        env->SetObjectArrayElement(ret, i, env->NewStringUTF(v[i].c_str()));
     }
-    std::string xml = gHalManifestConverter(*manifest);
-    return env->NewStringUTF(xml.c_str());
+    return ret;
 }
 
-static jstring android_os_VintfObject_getFrameworkManifest(JNIEnv* env, jclass clazz)
-{
-    const HalManifest *manifest = VintfObject::GetFrameworkHalManifest();
-    if (manifest == nullptr) {
-        return nullptr;
+template<typename T>
+static void tryAddSchema(const T* object, const XmlConverter<T>& converter,
+        const std::string& description,
+        std::vector<std::string>* cStrings) {
+    if (object == nullptr) {
+        LOG(WARNING) << __FUNCTION__ << "Cannot get " << description;
+    } else {
+        cStrings->push_back(converter(*object));
     }
-    std::string xml = gHalManifestConverter(*manifest);
-    return env->NewStringUTF(xml.c_str());
+}
+
+static jobjectArray android_os_VintfObject_report(JNIEnv* env, jclass clazz)
+{
+    std::vector<std::string> cStrings;
+
+    tryAddSchema(VintfObject::GetDeviceHalManifest(), gHalManifestConverter,
+            "device manifest", &cStrings);
+    tryAddSchema(VintfObject::GetFrameworkHalManifest(), gHalManifestConverter,
+            "framework manifest", &cStrings);
+    tryAddSchema(VintfObject::GetDeviceCompatibilityMatrix(), gCompatibilityMatrixConverter,
+            "device compatibility matrix", &cStrings);
+    tryAddSchema(VintfObject::GetFrameworkCompatibilityMatrix(), gCompatibilityMatrixConverter,
+            "framework compatibility matrix", &cStrings);
+
+    return toJavaStringArray(env, cStrings);
 }
 
 static jint android_os_VintfObject_verify(JNIEnv *env, jclass clazz, jobjectArray packageInfo) {
@@ -66,15 +87,18 @@
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod gVintfObjectMethods[] = {
-    {"getDeviceManifest",    "()Ljava/lang/String;",   (void*)android_os_VintfObject_getDeviceManifest},
-    {"getFrameworkManifest", "()Ljava/lang/String;",   (void*)android_os_VintfObject_getFrameworkManifest},
-    {"verify",               "([Ljava/lang/String;)I", (void*)android_os_VintfObject_verify},
+    {"report", "()[Ljava/lang/String;", (void*)android_os_VintfObject_report},
+    {"verify", "([Ljava/lang/String;)I", (void*)android_os_VintfObject_verify},
 };
 
+
 const char* const kVintfObjectPathName = "android/os/VintfObject";
 
 int register_android_os_VintfObject(JNIEnv* env)
 {
+
+    gString = MakeGlobalRefOrDie(env, FindClassOrDie(env, "java/lang/String"));
+
     return RegisterMethodsOrDie(env, kVintfObjectPathName, gVintfObjectMethods,
             NELEM(gVintfObjectMethods));
 }
diff --git a/core/proto/android/providers/settings.proto b/core/proto/android/providers/settings.proto
index ce951de..ea40fd5 100644
--- a/core/proto/android/providers/settings.proto
+++ b/core/proto/android/providers/settings.proto
@@ -329,6 +329,8 @@
     SettingProto max_notification_enqueue_rate = 284;
     SettingProto cell_on = 285;
     SettingProto network_recommendations_package = 286;
+    SettingProto bluetooth_a2dp_supports_optional_codecs_prefix = 287;
+    SettingProto bluetooth_a2dp_optional_codecs_enabled_prefix = 288;
 }
 
 message SecureSettingsProto {
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index a921fd7..8006f78 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2872,4 +2872,8 @@
 
     <!-- Additional non-platform defined secure settings exposed to Instant Apps -->
     <string-array name="config_allowedSecureInstantAppSettings"></string-array>
+
+    <!-- Handle volume keys directly in Window Manager without passing them to the foreground app -->
+    <bool name="config_handleVolumeKeysInWindowManager">false</bool>
+
 </resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 1966f6a..cff6eb1 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3010,4 +3010,5 @@
   <java-symbol type="array" name="config_allowedSystemInstantAppSettings" />
   <java-symbol type="array" name="config_allowedSecureInstantAppSettings" />
 
+  <java-symbol type="bool" name="config_handleVolumeKeysInWindowManager" />
 </resources>
diff --git a/core/tests/coretests/src/android/os/VintfObjectTest.java b/core/tests/coretests/src/android/os/VintfObjectTest.java
index aaaf55c..821ee80 100644
--- a/core/tests/coretests/src/android/os/VintfObjectTest.java
+++ b/core/tests/coretests/src/android/os/VintfObjectTest.java
@@ -26,5 +26,8 @@
         // From /system/manifest.xml
         assertTrue(String.join("", xmls).contains(
                 "<manifest version=\"1.0\" type=\"framework\">"));
+        // From /system/compatibility-matrix.xml
+        assertTrue(String.join("", xmls).contains(
+                "<compatibility-matrix version=\"1.0\" type=\"framework\">"));
     }
 }
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index 99909ac..aeed20e 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -109,6 +109,8 @@
                     Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE,
                     Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
                     Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX,
+                    Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX,
+                    Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX,
                     Settings.Global.BLUETOOTH_DISABLED_PROFILES,
                     Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
                     Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassificationManagerTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassificationManagerTest.java
index f59e4fc..742fd60 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassificationManagerTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassificationManagerTest.java
@@ -118,7 +118,7 @@
         if (isTextClassifierDisabled()) return;
 
         String text = "Visit http://www.android.com for more information";
-        String classifiedText = "http://www.android.com";
+        String classifiedText = "www.android.com";
         int startIndex = text.indexOf(classifiedText);
         int endIndex = startIndex + classifiedText.length();
         assertThat(mClassifier.classifyText(text, startIndex, endIndex, LOCALES),
@@ -193,7 +193,19 @@
             public boolean matches(Object o) {
                 if (o instanceof TextClassification) {
                     TextClassification result = (TextClassification) o;
-                    return text.equals(result.getText())
+                    final boolean typeRequirementSatisfied;
+                    switch (type) {
+                        case TextClassifier.TYPE_URL:
+                            String scheme = result.getIntent().getData().getScheme();
+                            typeRequirementSatisfied = "http".equalsIgnoreCase(scheme)
+                                    || "https".equalsIgnoreCase(scheme);
+                            break;
+                        default:
+                            typeRequirementSatisfied = true;
+                    }
+
+                    return typeRequirementSatisfied
+                            && text.equals(result.getText())
                             && result.getEntityCount() > 0
                             && type.equals(result.getEntity(0));
                     // TODO: Include other properties.
diff --git a/libs/hwui/tests/unit/FrameBuilderTests.cpp b/libs/hwui/tests/unit/FrameBuilderTests.cpp
index bd798e8..fcdd814 100644
--- a/libs/hwui/tests/unit/FrameBuilderTests.cpp
+++ b/libs/hwui/tests/unit/FrameBuilderTests.cpp
@@ -819,7 +819,7 @@
     EXPECT_EQ(1, renderer.getIndex()) << "ColorOp should not be rejected";
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, renderNode) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, renderNode) {
     class RenderNodeTestRenderer : public TestRendererBase {
     public:
         void onRectOp(const RectOp& op, const BakedOpState& state) override {
@@ -2321,7 +2321,7 @@
     EXPECT_EQ(1, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectedInMiddle) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectedInMiddle) {
     /* R is backward projected on B
                 A
                / \
@@ -2351,7 +2351,7 @@
     EXPECT_EQ(3, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectLast) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectLast) {
     /* R is backward projected on E
                   A
                 / | \
@@ -2383,7 +2383,7 @@
     EXPECT_EQ(4, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderNoReceivable) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderNoReceivable) {
     /* R is backward projected without receiver
                 A
                / \
@@ -2412,7 +2412,7 @@
     EXPECT_EQ(2, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderParentReceivable) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderParentReceivable) {
     /* R is backward projected on C
                 A
                / \
@@ -2441,7 +2441,7 @@
     EXPECT_EQ(3, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderSameNodeReceivable) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderSameNodeReceivable) {
      auto nodeA = TestUtils::createNode<RecordingCanvas>(0, 0, 100, 100,
             [](RenderProperties& props, RecordingCanvas& canvas) {
         drawOrderedNode(&canvas, 0, nullptr); //nodeB
@@ -2464,7 +2464,7 @@
     EXPECT_EQ(2, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectedSibling) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectedSibling) {
     //TODO: this test together with the next "projectionReorderProjectedSibling2" likely expose a
     //bug in HWUI. First test draws R, while the second test does not draw R for a nearly identical
     //tree setup. The correct behaviour is to not draw R, because the receiver cannot be a sibling
@@ -2497,7 +2497,7 @@
     EXPECT_EQ(3, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectedSibling2) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderProjectedSibling2) {
     /* R is set to project on B, but R is not drawn because projecting on a sibling is not allowed.
                 A
                 |
@@ -2530,7 +2530,7 @@
     EXPECT_EQ(3, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderGrandparentReceivable) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderGrandparentReceivable) {
     /* R is backward projected on B
                 A
                 |
@@ -2562,7 +2562,7 @@
     EXPECT_EQ(3, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderTwoReceivables) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderTwoReceivables) {
     /* B and G are receivables, R is backward projected
                 A
                / \
@@ -2595,7 +2595,7 @@
     EXPECT_EQ(4, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderTwoReceivablesLikelyScenario) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderTwoReceivablesLikelyScenario) {
     /* B and G are receivables, G is backward projected
                 A
                / \
@@ -2628,7 +2628,7 @@
     EXPECT_EQ(4, renderer.getIndex());
 }
 
-OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderTwoReceivablesDeeper) {
+RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, projectionReorderTwoReceivablesDeeper) {
     /* B and G are receivables, R is backward projected
                 A
                / \
diff --git a/obex/javax/obex/ServerSession.java b/obex/javax/obex/ServerSession.java
index 3831cf7..dbfeefd 100644
--- a/obex/javax/obex/ServerSession.java
+++ b/obex/javax/obex/ServerSession.java
@@ -104,7 +104,6 @@
 
                     case ObexHelper.OBEX_OPCODE_DISCONNECT:
                         handleDisconnectRequest();
-                        done = true;
                         break;
 
                     case ObexHelper.OBEX_OPCODE_GET:
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
index 646b6ba..be15e65 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
@@ -124,7 +124,8 @@
     */
     private final Object mLock = new Object();
 
-    //visible to both worker and main thread. Guarded by #mInternalAccessPoints
+    //visible to both worker and main thread.
+    @GuardedBy("mLock")
     private final AccessPointListenerAdapter mAccessPointListenerAdapter
             = new AccessPointListenerAdapter();
 
@@ -1005,12 +1006,13 @@
         if (DBG) {
             Log.d(TAG, "Starting to copy AP items on the MainHandler");
         }
-        if (notifyListeners) {
-            notificationMap = mAccessPointListenerAdapter.mPendingNotifications.clone();
-        }
-
-        mAccessPointListenerAdapter.mPendingNotifications.clear();
         synchronized (mLock) {
+            if (notifyListeners) {
+                notificationMap = mAccessPointListenerAdapter.mPendingNotifications.clone();
+            }
+
+            mAccessPointListenerAdapter.mPendingNotifications.clear();
+
             for (AccessPoint internalAccessPoint : mInternalAccessPoints) {
                 AccessPoint accessPoint = oldAccessPoints.get(internalAccessPoint.mId);
                 if (accessPoint == null) {
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
index 885573e..c7c2222 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
@@ -696,6 +696,12 @@
                 Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX,
                 GlobalSettingsProto.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX);
         dumpSetting(s, p,
+                Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX,
+                GlobalSettingsProto.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX);
+        dumpSetting(s, p,
+                Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX,
+                GlobalSettingsProto.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX);
+        dumpSetting(s, p,
                 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
                 GlobalSettingsProto.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX);
         dumpSetting(s, p,
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java
index 7d78c08..9ef05c5 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java
@@ -16,6 +16,7 @@
 
 import android.content.Context;
 import android.graphics.drawable.Drawable;
+import android.metrics.LogMaker;
 import android.service.quicksettings.Tile;
 
 import com.android.systemui.plugins.annotations.DependsOn;
@@ -66,6 +67,10 @@
 
     State getState();
 
+    default LogMaker populate(LogMaker logMaker) {
+        return logMaker;
+    }
+
     @ProvidesInterface(version = Callback.VERSION)
     public interface Callback {
         public static final int VERSION = 1;
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
index 7139d59..af02e5b 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
@@ -37,6 +37,7 @@
 
     private static final int PULSE_REASONS = 5;
 
+    public static final int PULSE_REASON_NONE = -1;
     public static final int PULSE_REASON_INTENT = 0;
     public static final int PULSE_REASON_NOTIFICATION = 1;
     public static final int PULSE_REASON_SENSOR_SIGMOTION = 2;
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java b/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java
index 38b32e9..44bb33a 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java
@@ -106,6 +106,7 @@
 
     private final ArrayList<State> mQueuedRequests = new ArrayList<>();
     private State mState = State.UNINITIALIZED;
+    private int mPulseReason;
     private boolean mWakeLockHeldForCurrentState = false;
 
     public DozeMachine(Service service, AmbientDisplayConfiguration config,
@@ -133,6 +134,20 @@
      */
     @MainThread
     public void requestState(State requestedState) {
+        Preconditions.checkArgument(requestedState != State.DOZE_REQUEST_PULSE);
+        requestState(requestedState, DozeLog.PULSE_REASON_NONE);
+    }
+
+    @MainThread
+    public void requestPulse(int pulseReason) {
+        // Must not be called during a transition. There's no inherent problem with that,
+        // but there's currently no need to execute from a transition and it simplifies the
+        // code to not have to worry about keeping the pulseReason in mQueuedRequests.
+        Preconditions.checkState(!isExecutingTransition());
+        requestState(State.DOZE_REQUEST_PULSE, pulseReason);
+    }
+
+    private void requestState(State requestedState, int pulseReason) {
         Assert.isMainThread();
         if (DEBUG) {
             Log.i(TAG, "request: current=" + mState + " req=" + requestedState,
@@ -146,7 +161,7 @@
             for (int i = 0; i < mQueuedRequests.size(); i++) {
                 // Transitions in Parts can call back into requestState, which will
                 // cause mQueuedRequests to grow.
-                transitionTo(mQueuedRequests.get(i));
+                transitionTo(mQueuedRequests.get(i), pulseReason);
             }
             mQueuedRequests.clear();
             mWakeLock.release();
@@ -165,6 +180,20 @@
         return mState;
     }
 
+    /**
+     * @return the current pulse reason.
+     *
+     * This is only valid if the machine is currently in one of the pulse states.
+     */
+    @MainThread
+    public int getPulseReason() {
+        Assert.isMainThread();
+        Preconditions.checkState(mState == State.DOZE_REQUEST_PULSE
+                || mState == State.DOZE_PULSING
+                || mState == State.DOZE_PULSE_DONE, "must be in pulsing state, but is " + mState);
+        return mPulseReason;
+    }
+
     /** Requests the PowerManager to wake up now. */
     public void wakeUp() {
         mDozeService.requestWakeUp();
@@ -174,7 +203,7 @@
         return !mQueuedRequests.isEmpty();
     }
 
-    private void transitionTo(State requestedState) {
+    private void transitionTo(State requestedState, int pulseReason) {
         State newState = transitionPolicy(requestedState);
 
         if (DEBUG) {
@@ -190,6 +219,7 @@
         State oldState = mState;
         mState = newState;
 
+        updatePulseReason(newState, oldState, pulseReason);
         performTransitionOnComponents(oldState, newState);
         updateScreenState(newState);
         updateWakeLockState(newState);
@@ -197,6 +227,14 @@
         resolveIntermediateState(newState);
     }
 
+    private void updatePulseReason(State newState, State oldState, int pulseReason) {
+        if (newState == State.DOZE_REQUEST_PULSE) {
+            mPulseReason = pulseReason;
+        } else if (oldState == State.DOZE_PULSE_DONE) {
+            mPulseReason = DozeLog.PULSE_REASON_NONE;
+        }
+    }
+
     private void performTransitionOnComponents(State oldState, State newState) {
         for (Part p : mParts) {
             p.transitionTo(oldState, newState);
@@ -280,7 +318,8 @@
             case INITIALIZED:
             case DOZE_PULSE_DONE:
                 transitionTo(mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)
-                        ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE);
+                        ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE,
+                        DozeLog.PULSE_REASON_NONE);
                 break;
             default:
                 break;
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
index 2096956..563b8fe 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
@@ -227,7 +227,7 @@
                     mDozeHost.isPulsingBlocked());
             return;
         }
-        mMachine.requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(reason);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
index 03076cc..64a152e 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
@@ -83,7 +83,7 @@
                 unscheduleTimeTick();
                 break;
             case DOZE_REQUEST_PULSE:
-                pulseWhileDozing(DozeLog.PULSE_REASON_NOTIFICATION /* TODO */);
+                pulseWhileDozing(mMachine.getPulseReason());
                 break;
             case DOZE_PULSE_DONE:
                 mHost.abortPulsing();
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index f5e096eb..c4d88ae 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -22,6 +22,7 @@
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.metrics.LogMaker;
 import android.os.Handler;
 import android.os.Message;
 import android.service.quicksettings.Tile;
@@ -30,6 +31,7 @@
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settingslib.Utils;
@@ -179,7 +181,7 @@
 
     public void openDetails(String subPanel) {
         QSTile tile = getTile(subPanel);
-        showDetailAdapter(true, tile.getDetailAdapter(), new int[] {getWidth() / 2, 0});
+        showDetailAdapter(true, tile.getDetailAdapter(), new int[]{getWidth() / 2, 0});
     }
 
     private QSTile getTile(String subPanel) {
@@ -485,8 +487,9 @@
 
     private void logTiles() {
         for (int i = 0; i < mRecords.size(); i++) {
-            TileRecord tileRecord = mRecords.get(i);
-            mMetricsLogger.visible(tileRecord.tile.getMetricsCategory());
+            QSTile tile = mRecords.get(i).tile;
+            mMetricsLogger.write(tile.populate(new LogMaker(tile.getMetricsCategory())
+                    .setType(MetricsEvent.TYPE_OPEN)));
         }
     }
 
@@ -544,12 +547,13 @@
         private static final int SHOW_DETAIL = 1;
         private static final int SET_TILE_VISIBILITY = 2;
         private static final int ANNOUNCE_FOR_ACCESSIBILITY = 3;
+
         @Override
         public void handleMessage(Message msg) {
             if (msg.what == SHOW_DETAIL) {
-                handleShowDetail((Record)msg.obj, msg.arg1 != 0);
+                handleShowDetail((Record) msg.obj, msg.arg1 != 0);
             } else if (msg.what == ANNOUNCE_FOR_ACCESSIBILITY) {
-                announceForAccessibility((CharSequence)msg.obj);
+                announceForAccessibility((CharSequence) msg.obj);
             }
         }
     }
@@ -569,8 +573,11 @@
 
     public interface QSTileLayout {
         void addTile(TileRecord tile);
+
         void removeTile(TileRecord tile);
+
         int getOffsetTop(TileRecord tile);
+
         boolean updateResources();
 
         void setListening(boolean listening);
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
index dc9176f..017365f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
@@ -157,7 +157,7 @@
     }
 
     @Override
-    protected LogMaker populate(LogMaker logMaker) {
+    public LogMaker populate(LogMaker logMaker) {
         return super.populate(logMaker).setComponentName(mComponent);
     }
 
@@ -275,7 +275,6 @@
         } catch (RemoteException e) {
             // Called through wrapper, won't happen here.
         }
-        MetricsLogger.action(mContext, getMetricsCategory(), mComponent.getPackageName());
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java
index 976efb2..32af230 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java
@@ -175,7 +175,7 @@
         mHandler.sendEmptyMessage(H.LONG_CLICK);
     }
 
-    protected LogMaker populate(LogMaker logMaker) {
+    public LogMaker populate(LogMaker logMaker) {
         if (mState instanceof BooleanState) {
             logMaker.addTaggedData(FIELD_QS_VALUE, ((BooleanState) mState).value ? 1 : 0);
         }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
index 5817e92..36be49d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
@@ -279,6 +279,7 @@
                         }
 
                         MetricsLogger.action(mSv.getContext(), MetricsEvent.OVERVIEW_SCROLL);
+                        mLastY = mDownY = y;
                     }
                 }
                 if (mIsScrolling) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java
index cdbde5e..d203602 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java
@@ -106,7 +106,7 @@
     public void testPulseDone_goesToDoze() {
         when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false);
         mMachine.requestState(INITIALIZED);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSING);
 
         mMachine.requestState(DOZE_PULSE_DONE);
@@ -119,7 +119,7 @@
     public void testPulseDone_goesToAoD() {
         when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true);
         mMachine.requestState(INITIALIZED);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSING);
 
         mMachine.requestState(DOZE_PULSE_DONE);
@@ -163,7 +163,7 @@
     public void testWakeLock_heldInPulseStates() {
         mMachine.requestState(INITIALIZED);
 
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         assertTrue(mWakeLockFake.isHeld());
 
         mMachine.requestState(DOZE_PULSING);
@@ -186,7 +186,7 @@
         mMachine.requestState(INITIALIZED);
 
         mMachine.requestState(DOZE);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSING);
         mMachine.requestState(DOZE_PULSE_DONE);
 
@@ -198,9 +198,9 @@
         mMachine.requestState(INITIALIZED);
 
         mMachine.requestState(DOZE);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSING);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSE_DONE);
     }
 
@@ -209,7 +209,7 @@
         mMachine.requestState(INITIALIZED);
 
         mMachine.requestState(DOZE);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSE_DONE);
     }
 
@@ -235,7 +235,7 @@
     public void testScreen_onInPulse() {
         mMachine.requestState(INITIALIZED);
 
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
         mMachine.requestState(DOZE_PULSING);
 
         assertEquals(Display.STATE_DOZE, mServiceFake.screenState);
@@ -246,7 +246,7 @@
         mMachine.requestState(INITIALIZED);
 
         mMachine.requestState(DOZE);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
 
         assertEquals(Display.STATE_OFF, mServiceFake.screenState);
     }
@@ -256,7 +256,7 @@
         mMachine.requestState(INITIALIZED);
 
         mMachine.requestState(DOZE_AOD);
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
 
         assertEquals(Display.STATE_DOZE, mServiceFake.screenState);
     }
@@ -270,12 +270,43 @@
             return null;
         }).when(mPartMock).transitionTo(any(), eq(DOZE_REQUEST_PULSE));
 
-        mMachine.requestState(DOZE_REQUEST_PULSE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
 
         assertEquals(DOZE_PULSING, mMachine.getState());
     }
 
     @Test
+    public void testPulseReason_getMatchesRequest() {
+        mMachine.requestState(INITIALIZED);
+        mMachine.requestState(DOZE);
+        mMachine.requestPulse(DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP);
+
+        assertEquals(DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP, mMachine.getPulseReason());
+    }
+
+    @Test
+    public void testPulseReason_getFromTransition() {
+        mMachine.requestState(INITIALIZED);
+        mMachine.requestState(DOZE);
+        doAnswer(inv -> {
+            DozeMachine.State newState = inv.getArgument(1);
+            if (newState == DOZE_REQUEST_PULSE
+                    || newState == DOZE_PULSING
+                    || newState == DOZE_PULSE_DONE) {
+                assertEquals(DozeLog.PULSE_REASON_NOTIFICATION, mMachine.getPulseReason());
+            } else {
+                assertTrue("unexpected state " + newState,
+                        newState == DOZE || newState == DOZE_AOD);
+            }
+            return null;
+        }).when(mPartMock).transitionTo(any(), any());
+
+        mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
+        mMachine.requestState(DOZE_PULSING);
+        mMachine.requestState(DOZE_PULSE_DONE);
+    }
+
+    @Test
     public void testWakeUp_wakesUp() {
         mMachine.wakeUp();
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
index 12e75a1..d57f813 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
@@ -22,7 +22,6 @@
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
 
 import android.app.Instrumentation;
 import android.content.Context;
@@ -39,8 +38,6 @@
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
-import org.mockito.Answers;
-import org.mockito.MockSettings;
 
 public class DozeTriggersTest {
     private Context mContext;
@@ -104,7 +101,7 @@
             mSensors.PROXIMITY.sendProximityResult(true); /* Far */
         });
 
-        verify(mMachine).requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
+        verify(mMachine).requestPulse(anyInt());
     }
 
 }
\ No newline at end of file
diff --git a/preloaded-classes b/preloaded-classes
index 892c593..493e980 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -1820,6 +1820,7 @@
 android.text.GetChars
 android.text.GraphicsOperations
 android.text.Html
+android.text.Html$HtmlParser
 android.text.Hyphenator
 android.text.InputFilter
 android.text.InputType
diff --git a/services/autofill/java/com/android/server/autofill/Helper.java b/services/autofill/java/com/android/server/autofill/Helper.java
index 68ade63..cbf97dd 100644
--- a/services/autofill/java/com/android/server/autofill/Helper.java
+++ b/services/autofill/java/com/android/server/autofill/Helper.java
@@ -20,7 +20,9 @@
 import android.app.assist.AssistStructure;
 import android.app.assist.AssistStructure.ViewNode;
 import android.os.Bundle;
+import android.util.DebugUtils;
 import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillManager;
 
 import java.util.Arrays;
 import java.util.Objects;
@@ -40,6 +42,10 @@
      */
     public static boolean sVerbose = false;
 
+    private Helper() {
+        throw new UnsupportedOperationException("contains static members only");
+    }
+
     static void append(StringBuilder builder, Bundle bundle) {
         if (bundle == null || !sVerbose) {
             builder.append("null");
@@ -62,8 +68,8 @@
         return builder.toString();
     }
 
-    private Helper() {
-        throw new UnsupportedOperationException("contains static members only");
+    static String getUpdateActionAsString(int action) {
+        return DebugUtils.flagsToString(AutofillManager.class, "ACTION_", action);
     }
 
     static ViewNode findViewNodeById(@NonNull AssistStructure structure, @NonNull AutofillId id) {
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 018fb68..23b734a 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -25,9 +25,13 @@
 import static android.view.autofill.AutofillManager.ACTION_VIEW_ENTERED;
 import static android.view.autofill.AutofillManager.ACTION_VIEW_EXITED;
 
+import static com.android.server.autofill.Helper.findViewNodeById;
+import static com.android.server.autofill.Helper.getUpdateActionAsString;
 import static com.android.server.autofill.Helper.sDebug;
 import static com.android.server.autofill.Helper.sVerbose;
-import static com.android.server.autofill.Helper.findViewNodeById;
+import static com.android.server.autofill.ViewState.STATE_AUTOFILLED;
+import static com.android.server.autofill.ViewState.STATE_FILLABLE;
+import static com.android.server.autofill.ViewState.STATE_RESTARTED_SESSION;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -221,7 +225,7 @@
 
                 final int numContexts = mContexts.size();
                 for (int i = 0; i < numContexts; i++) {
-                    fillStructureWithAllowedValues(mContexts.get(i).getStructure());
+                    fillStructureWithAllowedValues(mContexts.get(i).getStructure(), flags);
                 }
 
                 request = new FillRequest(requestId, mContexts, mClientState, flags);
@@ -235,10 +239,12 @@
      * Updates values of the nodes in the structure so that:
      * - proper node is focused
      * - autofillValue is sent back to service when it was previously autofilled
+     * - autofillValue is sent in the view used to force a request
      *
      * @param structure The structure to be filled
+     * @param flags The flags that started the session
      */
-    private void fillStructureWithAllowedValues(@NonNull AssistStructure structure) {
+    private void fillStructureWithAllowedValues(@NonNull AssistStructure structure, int flags) {
         final int numViewStates = mViewStates.size();
         for (int i = 0; i < numViewStates; i++) {
             final ViewState viewState = mViewStates.valueAt(i);
@@ -249,16 +255,23 @@
                 continue;
             }
 
-            final AutofillValue initialValue = viewState.getInitialValue();
+            final AutofillValue currentValue = viewState.getCurrentValue();
             final AutofillValue filledValue = viewState.getAutofilledValue();
             final AutofillOverlay overlay = new AutofillOverlay();
-            if (filledValue != null && !filledValue.equals(initialValue)) {
-                overlay.value = filledValue;
-            }
-            if (mCurrentViewId != null) {
-                overlay.focused = mCurrentViewId.equals(viewState.id);
+
+            // Sanitizes the value if the current value matches what the service sent.
+            if (filledValue != null && filledValue.equals(currentValue)) {
+                overlay.value = currentValue;
             }
 
+            if (mCurrentViewId != null) {
+                // Updates the focus value.
+                overlay.focused = mCurrentViewId.equals(viewState.id);
+                // Sanitizes the value of the focused field in a manual request.
+                if (overlay.focused && (flags & FLAG_MANUAL_REQUEST) != 0) {
+                    overlay.value = currentValue;
+                }
+            }
             node.setAutofillOverlay(overlay);
         }
     }
@@ -883,6 +896,40 @@
     }
 
     /**
+     * Starts (if necessary) a new fill request upon entering a view.
+     *
+     * <p>A new request will be started in 2 scenarios:
+     * <ol>
+     *   <li>If the user manually requested autofill after the view was already filled.
+     *   <li>If the view is part of a new partition.
+     * </ol>
+     *
+     * @param id The id of the view that is entered.
+     * @param viewState The view that is entered.
+     * @param flags The flag that was passed by the AutofillManager.
+     */
+    private void requestNewFillResponseIfNecessaryLocked(@NonNull AutofillId id,
+            @NonNull ViewState viewState, int flags) {
+        // First check if this is a manual request after view was autofilled.
+        final int state = viewState.getState();
+        final boolean restart = (state & STATE_AUTOFILLED) != 0
+                && (flags & FLAG_MANUAL_REQUEST) != 0;
+        if (restart) {
+            if (sDebug) Slog.d(TAG, "Re-starting session on view  " + id);
+            viewState.setState(STATE_RESTARTED_SESSION);
+            requestNewFillResponseLocked(flags);
+            return;
+        }
+
+        // If it's not, then check if it it should start a partition.
+        if (shouldStartNewPartitionLocked(id)) {
+            if (sDebug) Slog.d(TAG, "Starting partition for view id " + id);
+            viewState.setState(ViewState.STATE_STARTED_PARTITION);
+            requestNewFillResponseLocked(flags);
+        }
+    }
+
+    /**
      * Determines if a new partition should be started for an id.
      *
      * @param id The id of the view that is entered
@@ -938,6 +985,10 @@
                     + id + " destroyed");
             return;
         }
+        if (sVerbose) {
+            Slog.v(TAG, "updateLocked(): id=" + id + ", action=" + getUpdateActionAsString(action)
+                    + ", flags=" + flags);
+        }
         ViewState viewState = mViewStates.get(id);
 
         if (viewState == null) {
@@ -992,13 +1043,7 @@
                 }
                 break;
             case ACTION_VIEW_ENTERED:
-                if (shouldStartNewPartitionLocked(id)) {
-                    if (sDebug) {
-                        Slog.d(TAG, "Starting partition for view id " + viewState.id);
-                    }
-                    viewState.setState(ViewState.STATE_STARTED_PARTITION);
-                    requestNewFillResponseLocked(flags);
-                }
+                requestNewFillResponseIfNecessaryLocked(id, viewState, flags);
 
                 // Remove the UI if the ViewState has changed.
                 if (mCurrentViewId != viewState.id) {
diff --git a/services/autofill/java/com/android/server/autofill/ViewState.java b/services/autofill/java/com/android/server/autofill/ViewState.java
index d114e14..561c603 100644
--- a/services/autofill/java/com/android/server/autofill/ViewState.java
+++ b/services/autofill/java/com/android/server/autofill/ViewState.java
@@ -47,23 +47,25 @@
     private static final String TAG = "ViewState";
 
     // NOTE: state constants must be public because of flagstoString().
-    public static final int STATE_UNKNOWN = 0x00;
+    public static final int STATE_UNKNOWN = 0x000;
     /** Initial state. */
-    public static final int STATE_INITIAL = 0x01;
+    public static final int STATE_INITIAL = 0x001;
     /** View id is present in a dataset returned by the service. */
-    public static final int STATE_FILLABLE = 0x02;
+    public static final int STATE_FILLABLE = 0x002;
     /** View was autofilled after user selected a dataset. */
-    public static final int STATE_AUTOFILLED = 0x04;
+    public static final int STATE_AUTOFILLED = 0x004;
     /** View value was changed, but not by the service. */
-    public static final int STATE_CHANGED = 0x08;
+    public static final int STATE_CHANGED = 0x008;
     /** Set only in the View that started a session. */
-    public static final int STATE_STARTED_SESSION = 0x10;
+    public static final int STATE_STARTED_SESSION = 0x010;
     /** View that started a new partition when focused on. */
-    public static final int STATE_STARTED_PARTITION = 0x20;
+    public static final int STATE_STARTED_PARTITION = 0x020;
     /** User select a dataset in this view, but service must authenticate first. */
-    public static final int STATE_WAITING_DATASET_AUTH = 0x40;
+    public static final int STATE_WAITING_DATASET_AUTH = 0x040;
     /** Service does not care about this view. */
-    public static final int STATE_IGNORED = 0x80;
+    public static final int STATE_IGNORED = 0x080;
+    /** User manually request autofill in this view, after it was already autofilled. */
+    public static final int STATE_RESTARTED_SESSION = 0x100;
 
     public final AutofillId id;
 
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index dc2dfa8..a68a7dd 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -2387,7 +2387,7 @@
 
         long token = mAncestralToken;
         synchronized (mQueueLock) {
-            if (mEverStoredApps.contains(packageName)) {
+            if (mCurrentToken != 0 && mEverStoredApps.contains(packageName)) {
                 if (MORE_DEBUG) {
                     Slog.i(TAG, "App in ever-stored, so using current token");
                 }
@@ -10464,8 +10464,7 @@
         final long oldId = Binder.clearCallingIdentity();
         try {
             String prevTransport = mTransportManager.selectTransport(transport);
-            Settings.Secure.putString(mContext.getContentResolver(),
-                    Settings.Secure.BACKUP_TRANSPORT, transport);
+            updateStateForTransport(transport);
             Slog.v(TAG, "selectBackupTransport() set " + mTransportManager.getCurrentTransportName()
                     + " returning " + prevTransport);
             return prevTransport;
@@ -10488,9 +10487,7 @@
             @Override
             public void onSuccess(String transportName) {
                 mTransportManager.selectTransport(transportName);
-                Settings.Secure.putString(mContext.getContentResolver(),
-                        Settings.Secure.BACKUP_TRANSPORT,
-                        mTransportManager.getCurrentTransportName());
+                updateStateForTransport(mTransportManager.getCurrentTransportName());
                 Slog.v(TAG, "Transport successfully selected: " + transport.flattenToShortString());
                 try {
                     listener.onSuccess(transportName);
@@ -10513,6 +10510,28 @@
         Binder.restoreCallingIdentity(oldId);
     }
 
+    private void updateStateForTransport(String newTransportName) {
+        // Publish the name change
+        Settings.Secure.putString(mContext.getContentResolver(),
+                Settings.Secure.BACKUP_TRANSPORT, newTransportName);
+
+        // And update our current-dataset bookkeeping
+        IBackupTransport transport = mTransportManager.getTransportBinder(newTransportName);
+        if (transport != null) {
+            try {
+                mCurrentToken = transport.getCurrentRestoreSet();
+            } catch (Exception e) {
+                // Oops.  We can't know the current dataset token, so reset and figure it out
+                // when we do the next k/v backup operation on this transport.
+                mCurrentToken = 0;
+            }
+        } else {
+            // The named transport isn't bound at this particular moment, so we can't
+            // know yet what its current dataset token is.  Reset as above.
+            mCurrentToken = 0;
+        }
+    }
+
     // Supply the configuration Intent for the given transport.  If the name is not one
     // of the available transports, or if the transport does not supply any configuration
     // UI, the method returns null.
diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java
index 2c14a7c..aafa88a 100644
--- a/services/backup/java/com/android/server/backup/Trampoline.java
+++ b/services/backup/java/com/android/server/backup/Trampoline.java
@@ -304,6 +304,14 @@
         BackupManagerService svc = mService;
         if (svc != null) {
             svc.selectBackupTransportAsync(transport, listener);
+        } else {
+            if (listener != null) {
+                try {
+                    listener.onFailure(BackupManager.ERROR_BACKUP_NOT_ALLOWED);
+                } catch (RemoteException ex) {
+                    // Ignore
+                }
+            }
         }
     }
 
diff --git a/services/backup/java/com/android/server/backup/TransportManager.java b/services/backup/java/com/android/server/backup/TransportManager.java
index 67f105e..da1f32c 100644
--- a/services/backup/java/com/android/server/backup/TransportManager.java
+++ b/services/backup/java/com/android/server/backup/TransportManager.java
@@ -182,13 +182,13 @@
 
     String[] getBoundTransportNames() {
         synchronized (mTransportLock) {
-            return mBoundTransports.keySet().toArray(new String[0]);
+            return mBoundTransports.keySet().toArray(new String[mBoundTransports.size()]);
         }
     }
 
     ComponentName[] getAllTransportCompenents() {
         synchronized (mTransportLock) {
-            return mValidTransports.keySet().toArray(new ComponentName[0]);
+            return mValidTransports.keySet().toArray(new ComponentName[mValidTransports.size()]);
         }
     }
 
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index 05ffcf0..550774a 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -1049,6 +1049,7 @@
         if (timeZoneWasChanged) {
             Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
             intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
+                    | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND
                     | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
             intent.putExtra("time-zone", zone.getID());
             getContext().sendBroadcastAsUser(intent, UserHandle.ALL);
diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java
index 114d761..fdc0bba 100644
--- a/services/core/java/com/android/server/NetworkScoreService.java
+++ b/services/core/java/com/android/server/NetworkScoreService.java
@@ -631,6 +631,11 @@
                  PackageManager.PERMISSION_GRANTED;
     }
 
+    private boolean callerCanScoreNetworks() {
+        return mContext.checkCallingOrSelfPermission(permission.SCORE_NETWORKS) ==
+                PackageManager.PERMISSION_GRANTED;
+    }
+
     @Override
     public boolean clearScores() {
         // Only the active scorer or the system should be allowed to flush all scores.
@@ -651,9 +656,9 @@
     @Override
     public boolean setActiveScorer(String packageName) {
         // Only the system can set the active scorer
-        if (!isCallerSystemProcess(getCallingUid()) && !callerCanRequestScores()) {
+        if (!isCallerSystemProcess(getCallingUid()) && !callerCanScoreNetworks()) {
             throw new SecurityException(
-                    "Caller is neither the system process nor a score requester.");
+                    "Caller is neither the system process or a network scorer.");
         }
 
         return mNetworkScorerAppManager.setActiveScorer(packageName);
diff --git a/services/core/java/com/android/server/NetworkScorerAppManager.java b/services/core/java/com/android/server/NetworkScorerAppManager.java
index 8404025..42777bf 100644
--- a/services/core/java/com/android/server/NetworkScorerAppManager.java
+++ b/services/core/java/com/android/server/NetworkScorerAppManager.java
@@ -208,11 +208,11 @@
      *
      * <p>The caller must have permission to write to {@link Settings.Global}.
      *
-     * @param packageName the packageName of the new scorer to use. If null, the scoring app will
-     *                    revert back to the configured default. Otherwise, the scorer will only
-     *                    be set if it is a valid scorer application.
-     * @return true if the scorer was changed, or false if the package is not a valid scorer or
-     *         a valid network recommendation provider exists.
+     * @param packageName the packageName of the new scorer to use. If null, scoring will be forced
+     *                    off, otherwise the scorer will only be set if it is a valid scorer
+     *                    application.
+     * @return true if the package was a valid scorer (including <code>null</code>) and now
+     *         represents the active scorer, false otherwise.
      */
     @VisibleForTesting
     public boolean setActiveScorer(String packageName) {
@@ -223,16 +223,19 @@
             return true;
         }
 
-        if (packageName == null) {
-            // revert to the default setting.
-            packageName = getDefaultPackageSetting();
+        if (TextUtils.isEmpty(packageName)) {
+            Log.i(TAG, "Network scorer forced off, was: " + oldPackageName);
+            setNetworkRecommendationsPackage(null);
+            setNetworkRecommendationsEnabledSetting(
+                    NetworkScoreManager.RECOMMENDATIONS_ENABLED_FORCED_OFF);
+            return true;
         }
 
-        Log.i(TAG, "Changing network scorer from " + oldPackageName + " to " + packageName);
-
         // We only make the change if the new package is valid.
         if (getScorer(packageName) != null) {
+            Log.i(TAG, "Changing network scorer from " + oldPackageName + " to " + packageName);
             setNetworkRecommendationsPackage(packageName);
+            setNetworkRecommendationsEnabledSetting(NetworkScoreManager.RECOMMENDATIONS_ENABLED_ON);
             return true;
         } else {
             Log.w(TAG, "Requested network scorer is not valid: " + packageName);
diff --git a/services/core/java/com/android/server/vr/CompatibilityDisplay.java b/services/core/java/com/android/server/Vr2dDisplay.java
similarity index 93%
rename from services/core/java/com/android/server/vr/CompatibilityDisplay.java
rename to services/core/java/com/android/server/Vr2dDisplay.java
index d7cdf08..1116e4e 100644
--- a/services/core/java/com/android/server/vr/CompatibilityDisplay.java
+++ b/services/core/java/com/android/server/Vr2dDisplay.java
@@ -3,7 +3,7 @@
 import static android.view.Display.INVALID_DISPLAY;
 
 import android.app.ActivityManagerInternal;
-import android.app.CompatibilityDisplayProperties;
+import android.app.Vr2dDisplayProperties;
 import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -31,8 +31,8 @@
  * Creates a 2D Virtual Display while VR Mode is enabled. This display will be used to run and
  * render 2D app within a VR experience. For example, bringing up the 2D calculator app in VR.
  */
-class CompatibilityDisplay {
-    private final static String TAG = "CompatDisplay";
+class Vr2dDisplay {
+    private final static String TAG = "Vr2dDisplay";
     private final static boolean DEBUG = false;
 
     // TODO: Go over these values and figure out what is best
@@ -42,13 +42,13 @@
     private final static int STOP_VIRTUAL_DISPLAY_DELAY_MILLIS = 2000;
 
     private final static String DEBUG_ACTION_SET_MODE =
-            "com.android.server.vr.CompatibilityDisplay.SET_MODE";
+            "com.android.server.vr.Vr2dDisplay.SET_MODE";
     private final static String DEBUG_EXTRA_MODE_ON =
-            "com.android.server.vr.CompatibilityDisplay.EXTRA_MODE_ON";
+            "com.android.server.vr.Vr2dDisplay.EXTRA_MODE_ON";
     private final static String DEBUG_ACTION_SET_SURFACE =
-            "com.android.server.vr.CompatibilityDisplay.SET_SURFACE";
+            "com.android.server.vr.Vr2dDisplay.SET_SURFACE";
     private final static String DEBUG_EXTRA_SURFACE =
-            "com.android.server.vr.CompatibilityDisplay.EXTRA_SURFACE";
+            "com.android.server.vr.Vr2dDisplay.EXTRA_SURFACE";
 
     /**
      * The default width of the VR virtual display
@@ -99,7 +99,7 @@
     private boolean mIsVrModeOverrideEnabled;
     private boolean mIsVrModeEnabled;
 
-    public CompatibilityDisplay(DisplayManager displayManager,
+    public Vr2dDisplay(DisplayManager displayManager,
            ActivityManagerInternal activityManagerInternal, IVrManager vrManager) {
         mDisplayManager = displayManager;
         mActivityManagerInternal = activityManagerInternal;
@@ -190,7 +190,7 @@
     }
 
     /**
-     * Sets the resolution and DPI of the compatibility virtual display used to display
+     * Sets the resolution and DPI of the Vr2d virtual display used to display
      * 2D applications in VR mode.
      *
      * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
@@ -198,7 +198,7 @@
      * @param compatDisplayProperties Properties of the virtual display for 2D applications
      * in VR mode.
      */
-    public void setVirtualDisplayProperties(CompatibilityDisplayProperties compatDisplayProperties) {
+    public void setVirtualDisplayProperties(Vr2dDisplayProperties compatDisplayProperties) {
         synchronized(mVdLock) {
             if (DEBUG) {
                 Log.i(TAG, "VD setVirtualDisplayProperties: res = " +
@@ -273,13 +273,13 @@
                     null /* Surface */, 0 /* flags */);
 
             if (mVirtualDisplay != null) {
-                mActivityManagerInternal.setVrCompatibilityDisplayId(
+                mActivityManagerInternal.setVr2dDisplayId(
                     mVirtualDisplay.getDisplay().getDisplayId());
                 // Now create the ImageReader to supply a Surface to the new virtual display.
                 startImageReader();
             } else {
                 Log.w(TAG, "Virtual display id is null after createVirtualDisplay");
-                mActivityManagerInternal.setVrCompatibilityDisplayId(INVALID_DISPLAY);
+                mActivityManagerInternal.setVr2dDisplayId(INVALID_DISPLAY);
                 return;
             }
         }
@@ -302,7 +302,7 @@
                     } else {
                         Log.i(TAG, "Stopping Virtual Display");
                         synchronized (mVdLock) {
-                            mActivityManagerInternal.setVrCompatibilityDisplayId(INVALID_DISPLAY);
+                            mActivityManagerInternal.setVr2dDisplayId(INVALID_DISPLAY);
                             setSurfaceLocked(null); // clean up and release the surface first.
                             if (mVirtualDisplay != null) {
                                 mVirtualDisplay.release();
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index e0fc531..4313533 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -1258,6 +1258,10 @@
 
             mAm.startAssociationLocked(callerApp.uid, callerApp.processName, callerApp.curProcState,
                     s.appInfo.uid, s.name, s.processName);
+            // Once the apps have become associated, if one of them is caller is ephemeral
+            // the target app should now be able to see the calling app
+            mAm.grantEphemeralAccessLocked(callerApp.userId, service,
+                    s.appInfo.uid, UserHandle.getAppId(callerApp.uid));
 
             AppBindRecord b = s.retrieveAppBindingLocked(service, callerApp);
             ConnectionRecord c = new ConnectionRecord(b, activity,
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 4e7cb7d..6dcbe63 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -572,11 +572,10 @@
     // Determines whether to take full screen screenshots
     static final boolean TAKE_FULLSCREEN_SCREENSHOTS = true;
 
-    // STOPSHIP: Update default to a smaller value.
     /**
      * Default value for {@link Settings.Global#NETWORK_ACCESS_TIMEOUT_MS}.
      */
-    private static final long NETWORK_ACCESS_TIMEOUT_DEFAULT_MS = 2000; // 2 sec
+    private static final long NETWORK_ACCESS_TIMEOUT_DEFAULT_MS = 200; // 0.2 sec
 
     /**
      * State indicating that there is no need for any blocking for network.
@@ -627,8 +626,8 @@
 
     private final VrController mVrController;
 
-    // VR Compatibility Display Id.
-    int mVrCompatibilityDisplayId = INVALID_DISPLAY;
+    // VR Vr2d Display Id.
+    int mVr2dDisplayId = INVALID_DISPLAY;
 
     // Whether we should use SCHED_FIFO for UI and RenderThreads.
     private boolean mUseFifoUiScheduling = false;
@@ -4332,6 +4331,7 @@
                         validateUid.idle = false;
                     }
                     validateUid.curProcState = validateUid.setProcState = item.processState;
+                    validateUid.lastDispatchedProcStateSeq = item.procStateSeq;
                 }
             }
         }
@@ -23727,17 +23727,17 @@
 
         /**
          * Called after virtual display Id is updated by
-         * {@link com.android.server.vr.CompatibilityDisplay} with a specific
-         * {@param vrCompatibilityDisplayId}.
+         * {@link com.android.server.vr.Vr2dDisplay} with a specific
+         * {@param vrVr2dDisplayId}.
          */
         @Override
-        public void setVrCompatibilityDisplayId(int vrCompatibilityDisplayId) {
+        public void setVr2dDisplayId(int vr2dDisplayId) {
             if (DEBUG_STACK) {
-                Slog.d(TAG, "setVrCompatibilityDisplayId called for: " +
-                        vrCompatibilityDisplayId);
+                Slog.d(TAG, "setVr2dDisplayId called for: " +
+                        vr2dDisplayId);
             }
             synchronized (ActivityManagerService.this) {
-                mVrCompatibilityDisplayId = vrCompatibilityDisplayId;
+                mVr2dDisplayId = vr2dDisplayId;
             }
         }
     }
@@ -23801,11 +23801,8 @@
                 if (totalTime >= mWaitForNetworkTimeoutMs) {
                     Slog.wtf(TAG_NETWORK, "Total time waited for network rules to get updated: "
                             + totalTime + ". Uid: " + callingUid + " procStateSeq: "
-                            + procStateSeq);
-                } else if (DEBUG_NETWORK ||  totalTime >= mWaitForNetworkTimeoutMs / 2) {
-                    Slog.d(TAG_NETWORK, "Total time waited for network rules to get updated: "
-                            + totalTime + ". Uid: " + callingUid + " procStateSeq: "
-                            + procStateSeq);
+                            + procStateSeq + " UidRec: " + record
+                            + " validateUidRec: " + mValidateUids.get(callingUid));
                 }
             } catch (InterruptedException e) {
                 Thread.currentThread().interrupt();
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index fcc2b78..1f1aa8e 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -186,7 +186,7 @@
     private IVoiceInteractionSession mVoiceSession;
     private IVoiceInteractor mVoiceInteractor;
 
-    private boolean mUsingVrCompatibilityDisplay;
+    private boolean mUsingVr2dDisplay;
 
     private void reset() {
         mStartActivity = null;
@@ -226,14 +226,14 @@
         mVoiceSession = null;
         mVoiceInteractor = null;
 
-        mUsingVrCompatibilityDisplay = false;
+        mUsingVr2dDisplay = false;
     }
 
     ActivityStarter(ActivityManagerService service, ActivityStackSupervisor supervisor) {
         mService = service;
         mSupervisor = supervisor;
         mInterceptor = new ActivityStartInterceptor(mService, mSupervisor);
-        mUsingVrCompatibilityDisplay = false;
+        mUsingVr2dDisplay = false;
     }
 
     final int startActivityLocked(IApplicationThread caller, Intent intent, Intent ephemeralIntent,
@@ -956,7 +956,7 @@
             // If we are not able to proceed, disassociate the activity from the task. Leaving an
             // activity in an incomplete state can lead to issues, such as performing operations
             // without a window container.
-            if (result != START_SUCCESS && mStartActivity.getTask() != null) {
+            if (result < START_SUCCESS && mStartActivity.getTask() != null) {
                 mStartActivity.getTask().removeActivity(mStartActivity);
             }
             mService.mWindowManager.continueSurfaceLayout();
@@ -1062,7 +1062,7 @@
                 // We didn't do anything...  but it was needed (a.k.a., client don't use that
                 // intent!)  And for paranoia, make sure we have correctly resumed the top activity.
                 resumeTargetStackIfNeeded();
-                if (outActivity.length > 0) {
+                if (outActivity != null && outActivity.length > 0) {
                     outActivity[0] = reusedActivity;
                 }
                 return START_TASK_TO_FRONT;
@@ -1479,12 +1479,12 @@
         }
 
         // Get the virtual display id from ActivityManagerService.
-        int displayId = mService.mVrCompatibilityDisplayId;
+        int displayId = mService.mVr2dDisplayId;
         if (displayId != INVALID_DISPLAY) {
             if (DEBUG_STACK) {
                 Slog.d(TAG, "getSourceDisplayId :" + displayId);
             }
-            mUsingVrCompatibilityDisplay = true;
+            mUsingVr2dDisplay = true;
             return displayId;
         }
 
@@ -2108,8 +2108,8 @@
             return mSupervisor.getValidLaunchStackOnDisplay(launchDisplayId, r);
         }
 
-        // If we are using Vr compatibility display, find the virtual display stack.
-        if (mUsingVrCompatibilityDisplay) {
+        // If we are using Vr2d display, find the virtual display stack.
+        if (mUsingVr2dDisplay) {
             ActivityStack as = mSupervisor.getValidLaunchStackOnDisplay(mSourceDisplayId, r);
             if (DEBUG_STACK) {
                 Slog.v(TAG, "Launch stack for app: " + r.toString() +
diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java
index 91c32e4..51bebb09 100644
--- a/services/core/java/com/android/server/location/GnssLocationProvider.java
+++ b/services/core/java/com/android/server/location/GnssLocationProvider.java
@@ -382,6 +382,8 @@
     // Wakelocks
     private final static String WAKELOCK_KEY = "GnssLocationProvider";
     private final PowerManager.WakeLock mWakeLock;
+    private static final String DOWNLOAD_EXTRA_WAKELOCK_KEY = "GnssLocationProviderXtraDownload";
+    private final PowerManager.WakeLock mDownloadXtraWakeLock;
 
     // Alarms
     private final static String ALARM_WAKEUP = "com.android.internal.location.ALARM_WAKEUP";
@@ -686,6 +688,11 @@
         mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY);
         mWakeLock.setReferenceCounted(true);
 
+        // Create a separate wake lock for xtra downloader as it may be released due to timeout.
+        mDownloadXtraWakeLock = mPowerManager.newWakeLock(
+                PowerManager.PARTIAL_WAKE_LOCK, DOWNLOAD_EXTRA_WAKELOCK_KEY);
+        mDownloadXtraWakeLock.setReferenceCounted(true);
+
         mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
         mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0);
         mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0);
@@ -989,7 +996,7 @@
         mDownloadXtraDataPending = STATE_DOWNLOADING;
 
         // hold wake lock while task runs
-        mWakeLock.acquire(DOWNLOAD_XTRA_DATA_TIMEOUT_MS);
+        mDownloadXtraWakeLock.acquire(DOWNLOAD_XTRA_DATA_TIMEOUT_MS);
         Log.i(TAG, "WakeLock acquired by handleDownloadXtraData()");
         AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
             @Override
@@ -1011,13 +1018,17 @@
                             mXtraBackOff.nextBackoffMillis());
                 }
 
-                // release wake lock held by task
-                if (mWakeLock.isHeld()) {
-                    mWakeLock.release();
-                } else {
-                    Log.e(TAG, "WakeLock expired before release in handleDownloadXtraData()");
+                // Release wake lock held by task, synchronize on mLock in case multiple
+                // download tasks overrun.
+                synchronized (mLock) {
+                    if (mDownloadXtraWakeLock.isHeld()) {
+                        mDownloadXtraWakeLock.release();
+                        if (DEBUG) Log.d(TAG, "WakeLock released by handleDownloadXtraData()");
+                    } else {
+                        Log.e(TAG, "WakeLock expired before release in "
+                                + "handleDownloadXtraData()");
+                    }
                 }
-                Log.i(TAG, "WakeLock released by handleDownloadXtraData()");
             }
         });
     }
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 48d11c3..a4eccbf 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -3199,10 +3199,8 @@
                     + ", incomingUserId=" + incomingUserId
                     + ", notificationUid=" + notificationUid
                     + ", notification=" + notification;
-            // STOPSHIP TODO: should throw instead of logging or toasting.
-            // throw new IllegalArgumentException(noChannelStr);
             Log.e(TAG, noChannelStr);
-            doDebugOnlyToast("Developer warning for package \"" + pkg + "\"\n" +
+            doChannelWarningToast("Developer warning for package \"" + pkg + "\"\n" +
                     "Failed to post notification on channel \"" + channelId + "\"\n" +
                     "See log for more details");
             return;
@@ -3238,8 +3236,10 @@
         mHandler.post(new EnqueueNotificationRunnable(userId, r));
     }
 
-    private void doDebugOnlyToast(CharSequence toastText) {
-        if (Build.IS_DEBUGGABLE) {
+    private void doChannelWarningToast(CharSequence toastText) {
+        final boolean warningEnabled = Settings.System.getInt(getContext().getContentResolver(),
+                Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, 0) != 0;
+        if (warningEnabled || Build.IS_DEBUGGABLE) {
             try {
                 Toast toast = Toast.makeText(getContext(), toastText, Toast.LENGTH_LONG);
                 toast.show();
diff --git a/services/core/java/com/android/server/pm/EphemeralResolverConnection.java b/services/core/java/com/android/server/pm/EphemeralResolverConnection.java
index 9d08004..09e9433 100644
--- a/services/core/java/com/android/server/pm/EphemeralResolverConnection.java
+++ b/services/core/java/com/android/server/pm/EphemeralResolverConnection.java
@@ -43,6 +43,7 @@
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.concurrent.TimeoutException;
 
 /**
@@ -206,7 +207,9 @@
 
     private void handleBinderDiedLocked() {
         if (mRemoteInstance != null) {
-            mRemoteInstance.asBinder().unlinkToDeath(this, 0 /*flags*/);
+            try {
+                mRemoteInstance.asBinder().unlinkToDeath(this, 0 /*flags*/);
+            } catch (NoSuchElementException ignore) { }
         }
         mRemoteInstance = null;
     }
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index 4c0d9da..f94a56f 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -24,6 +24,7 @@
 import android.os.Environment;
 import android.os.FileUtils;
 import android.os.PowerManager;
+import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.WorkSource;
 import android.util.Log;
@@ -54,6 +55,7 @@
 import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
 import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
 
+import static com.android.server.pm.PackageManagerService.WATCHDOG_TIMEOUT;
 import static com.android.server.pm.PackageManagerServiceCompilerMapping.getNonProfileGuidedCompilerFilter;
 import static dalvik.system.DexFile.isProfileGuidedCompilerFilter;
 
@@ -67,13 +69,17 @@
     public static final int DEX_OPT_SKIPPED = 0;
     public static final int DEX_OPT_PERFORMED = 1;
     public static final int DEX_OPT_FAILED = -1;
+    // One minute over PM WATCHDOG_TIMEOUT
+    private static final long WAKELOCK_TIMEOUT_MS = WATCHDOG_TIMEOUT + 1000 * 60;
 
     /** Special library name that skips shared libraries check during compilation. */
     public static final String SKIP_SHARED_LIBRARY_CHECK = "&";
 
+    @GuardedBy("mInstallLock")
     private final Installer mInstaller;
     private final Object mInstallLock;
 
+    @GuardedBy("mInstallLock")
     private final PowerManager.WakeLock mDexoptWakeLock;
     private volatile boolean mSystemReady;
 
@@ -111,21 +117,12 @@
             return DEX_OPT_SKIPPED;
         }
         synchronized (mInstallLock) {
-            // During boot the system doesn't need to instantiate and obtain a wake lock.
-            // PowerManager might not be ready, but that doesn't mean that we can't proceed with
-            // dexopt.
-            final boolean useLock = mSystemReady;
-            if (useLock) {
-                mDexoptWakeLock.setWorkSource(new WorkSource(pkg.applicationInfo.uid));
-                mDexoptWakeLock.acquire();
-            }
+            final long acquireTime = acquireWakeLockLI(pkg.applicationInfo.uid);
             try {
                 return performDexOptLI(pkg, sharedLibraries, instructionSets, checkProfiles,
                         targetCompilationFilter, packageStats, isUsedByOtherApps);
             } finally {
-                if (useLock) {
-                    mDexoptWakeLock.release();
-                }
+                releaseWakeLockLI(acquireTime);
             }
         }
     }
@@ -250,26 +247,50 @@
     public int dexOptSecondaryDexPath(ApplicationInfo info, String path, Set<String> isas,
             String compilerFilter, boolean isUsedByOtherApps) {
         synchronized (mInstallLock) {
-            // During boot the system doesn't need to instantiate and obtain a wake lock.
-            // PowerManager might not be ready, but that doesn't mean that we can't proceed with
-            // dexopt.
-            final boolean useLock = mSystemReady;
-            if (useLock) {
-                mDexoptWakeLock.setWorkSource(new WorkSource(info.uid));
-                mDexoptWakeLock.acquire();
-            }
+            final long acquireTime = acquireWakeLockLI(info.uid);
             try {
                 return dexOptSecondaryDexPathLI(info, path, isas, compilerFilter,
                         isUsedByOtherApps);
             } finally {
-                if (useLock) {
-                    mDexoptWakeLock.release();
-                }
+                releaseWakeLockLI(acquireTime);
             }
         }
     }
 
     @GuardedBy("mInstallLock")
+    private long acquireWakeLockLI(final int uid) {
+        // During boot the system doesn't need to instantiate and obtain a wake lock.
+        // PowerManager might not be ready, but that doesn't mean that we can't proceed with
+        // dexopt.
+        if (!mSystemReady) {
+            return -1;
+        }
+        mDexoptWakeLock.setWorkSource(new WorkSource(uid));
+        mDexoptWakeLock.acquire(WAKELOCK_TIMEOUT_MS);
+        return SystemClock.elapsedRealtime();
+    }
+
+    @GuardedBy("mInstallLock")
+    private void releaseWakeLockLI(final long acquireTime) {
+        if (acquireTime < 0) {
+            return;
+        }
+        try {
+            if (mDexoptWakeLock.isHeld()) {
+                mDexoptWakeLock.release();
+            }
+            final long duration = SystemClock.elapsedRealtime() - acquireTime;
+            if (duration >= WAKELOCK_TIMEOUT_MS) {
+                Slog.wtf(TAG, "WakeLock " + mDexoptWakeLock.getTag()
+                        + " time out. Operation took " + duration + " ms. Thread: "
+                        + Thread.currentThread().getName());
+            }
+        } catch (Exception e) {
+            Slog.wtf(TAG, "Error while releasing " + mDexoptWakeLock.getTag() + " lock", e);
+        }
+    }
+
+    @GuardedBy("mInstallLock")
     private int dexOptSecondaryDexPathLI(ApplicationInfo info, String path, Set<String> isas,
             String compilerFilter, boolean isUsedByOtherApps) {
         compilerFilter = getRealCompilerFilter(info, compilerFilter, isUsedByOtherApps);
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 2686fcb..cfcd0a5 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -444,7 +444,7 @@
      * minute but we sometimes do very lengthy I/O operations on this thread,
      * such as installing multi-gigabyte applications, so ours needs to be longer.
      */
-    private static final long WATCHDOG_TIMEOUT = 1000*60*10;     // ten minutes
+    static final long WATCHDOG_TIMEOUT = 1000*60*10;     // ten minutes
 
     /**
      * Wall-clock timeout (in milliseconds) after which we *require* that an fstrim
diff --git a/services/core/java/com/android/server/pm/dex/DexManager.java b/services/core/java/com/android/server/pm/dex/DexManager.java
index 3d7cedc..9b44646 100644
--- a/services/core/java/com/android/server/pm/dex/DexManager.java
+++ b/services/core/java/com/android/server/pm/dex/DexManager.java
@@ -60,6 +60,7 @@
     // Maps package name to code locations.
     // It caches the code locations for the installed packages. This allows for
     // faster lookups (no locks) when finding what package owns the dex file.
+    @GuardedBy("mPackageCodeLocationsCache")
     private final Map<String, PackageCodeLocations> mPackageCodeLocationsCache;
 
     // PackageDexUsage handles the actual I/O operations. It is responsible to
@@ -204,7 +205,7 @@
         // In case there was an update, write the package use info to disk async.
         // Note that we do the writing here and not in PackageDexUsage in order to be
         // consistent with other methods in DexManager (e.g. reconcileSecondaryDexFiles performs
-        // multiple updates in PackaeDexUsage before writing it).
+        // multiple updates in PackageDexUsage before writing it).
         if (mPackageDexUsage.clearUsedByOtherApps(packageName)) {
             mPackageDexUsage.maybeWriteAsync();
         }
@@ -224,7 +225,7 @@
         // In case there was an update, write the package use info to disk async.
         // Note that we do the writing here and not in PackageDexUsage in order to be
         // consistent with other methods in DexManager (e.g. reconcileSecondaryDexFiles performs
-        // multiple updates in PackaeDexUsage before writing it).
+        // multiple updates in PackageDexUsage before writing it).
         if (updated) {
             mPackageDexUsage.maybeWriteAsync();
         }
@@ -243,17 +244,22 @@
 
     private void cachePackageCodeLocation(String packageName, String baseCodePath,
             String[] splitCodePaths, String[] dataDirs, int userId) {
-        PackageCodeLocations pcl = putIfAbsent(mPackageCodeLocationsCache, packageName,
-                new PackageCodeLocations(packageName, baseCodePath, splitCodePaths));
-        pcl.updateCodeLocation(baseCodePath, splitCodePaths);
-        if (dataDirs != null) {
-            for (String dataDir : dataDirs) {
-                // The set of data dirs includes deviceProtectedDataDir and
-                // credentialProtectedDataDir which might be null for shared
-                // libraries. Currently we don't track these but be lenient
-                // and check in case we ever decide to store their usage data.
-                if (dataDir != null) {
-                    pcl.mergeAppDataDirs(dataDir, userId);
+        synchronized (mPackageCodeLocationsCache) {
+            PackageCodeLocations pcl = putIfAbsent(mPackageCodeLocationsCache, packageName,
+                    new PackageCodeLocations(packageName, baseCodePath, splitCodePaths));
+            // TODO(calin): We are forced to extend the scope of this synchronization because
+            // the values of the cache (PackageCodeLocations) are updated in place.
+            // Make PackageCodeLocations immutable to simplify the synchronization reasoning.
+            pcl.updateCodeLocation(baseCodePath, splitCodePaths);
+            if (dataDirs != null) {
+                for (String dataDir : dataDirs) {
+                    // The set of data dirs includes deviceProtectedDataDir and
+                    // credentialProtectedDataDir which might be null for shared
+                    // libraries. Currently we don't track these but be lenient
+                    // and check in case we ever decide to store their usage data.
+                    if (dataDir != null) {
+                        pcl.mergeAppDataDirs(dataDir, userId);
+                    }
                 }
             }
         }
@@ -479,10 +485,12 @@
         // The loadingPackage does not own the dex file.
         // Perform a reverse look-up in the cache to detect if any package has ownership.
         // Note that we can have false negatives if the cache falls out of date.
-        for (PackageCodeLocations pcl : mPackageCodeLocationsCache.values()) {
-            outcome = pcl.searchDex(dexPath, userId);
-            if (outcome != DEX_SEARCH_NOT_FOUND) {
-                return new DexSearchResult(pcl.mPackageName, outcome);
+        synchronized (mPackageCodeLocationsCache) {
+            for (PackageCodeLocations pcl : mPackageCodeLocationsCache.values()) {
+                outcome = pcl.searchDex(dexPath, userId);
+                if (outcome != DEX_SEARCH_NOT_FOUND) {
+                    return new DexSearchResult(pcl.mPackageName, outcome);
+                }
             }
         }
 
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 4fb18d9..f0ae1a7 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -584,6 +584,8 @@
     boolean mTranslucentDecorEnabled = true;
     boolean mUseTvRouting;
 
+    private boolean mHandleVolumeKeysInWM;
+
     int mPointerLocationMode = 0; // guarded by mLock
 
     // The last window we were told about in focusChanged.
@@ -780,6 +782,10 @@
     private boolean mBugreportTvKey2Pressed;
     private boolean mBugreportTvScheduled;
 
+    private boolean mAccessibilityTvKey1Pressed;
+    private boolean mAccessibilityTvKey2Pressed;
+    private boolean mAccessibilityTvScheduled;
+
     /* The number of steps between min and max brightness */
     private static final int BRIGHTNESS_STEPS = 10;
 
@@ -824,6 +830,7 @@
     private static final int MSG_BACK_DELAYED_PRESS = 20;
     private static final int MSG_ACCESSIBILITY_SHORTCUT = 21;
     private static final int MSG_BUGREPORT_TV = 22;
+    private static final int MSG_ACCESSIBILITY_TV = 23;
 
     private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
     private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
@@ -905,6 +912,11 @@
                 case MSG_BUGREPORT_TV:
                     takeBugreport();
                     break;
+                case MSG_ACCESSIBILITY_TV:
+                    if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)) {
+                        accessibilityShortcutActivated();
+                    }
+                    break;
             }
         }
     }
@@ -1928,6 +1940,9 @@
 
         mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
 
+        mHandleVolumeKeysInWM = mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_handleVolumeKeysInWindowManager);
+
         readConfigurationDependentBehaviors();
 
         mAccessibilityManager = (AccessibilityManager) context.getSystemService(
@@ -3319,6 +3334,11 @@
             if (!down) {
                 cancelPreloadRecentApps();
 
+                if (mHasFeatureLeanback) {
+                    // Clear flags
+                    mAccessibilityTvKey2Pressed = down;
+                }
+
                 mHomePressed = false;
                 if (mHomeConsumed) {
                     mHomeConsumed = false;
@@ -3373,6 +3393,13 @@
                     preloadRecentApps();
                 }
             } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
+                if (mHasFeatureLeanback) {
+                    mAccessibilityTvKey2Pressed = down;
+                    if (interceptAccessibilityGestureTv()) {
+                        return -1;
+                    }
+                }
+
                 if (!keyguardOn) {
                     handleLongPressOnHome(event.getDeviceId());
                 }
@@ -3522,16 +3549,28 @@
         } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
                 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
                 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
-            if (mUseTvRouting) {
-                // On TVs volume keys never go to the foreground app.
+            if (mUseTvRouting || mHandleVolumeKeysInWM) {
+                // On TVs or when the configuration is enabled, volume keys never
+                // go to the foreground app.
                 dispatchDirectAudioEvent(event);
                 return -1;
             }
+
+            // If the device is in Vr mode, drop the volume keys and don't
+            // forward it to the application/dispatch the audio event.
+            if (mPersistentVrModeEnabled) {
+                return -1;
+            }
         } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) {
             // Pass through keyboard navigation keys.
             return 0;
         } else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) {
             return -1;
+        } else if (mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+            mAccessibilityTvKey1Pressed = down;
+            if (interceptAccessibilityGestureTv()) {
+                return -1;
+            }
         }
 
         // Toggle Caps Lock on META-ALT.
@@ -3750,6 +3789,25 @@
         return mBugreportTvScheduled;
     }
 
+    /**
+     * TV only: recognizes a remote control gesture as Accessibility shortcut.
+     * Shortcut: Long press (HOME + DPAD_CENTER)
+     */
+    private boolean interceptAccessibilityGestureTv() {
+        if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) {
+            if (!mAccessibilityTvScheduled) {
+                mAccessibilityTvScheduled = true;
+                Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV);
+                msg.setAsynchronous(true);
+                mHandler.sendMessage(msg);
+            }
+        } else if (mAccessibilityTvScheduled) {
+            mHandler.removeMessages(MSG_ACCESSIBILITY_TV);
+            mAccessibilityTvScheduled = false;
+        }
+        return mAccessibilityTvScheduled;
+    }
+
     private void takeBugreport() {
         if ("1".equals(SystemProperties.get("ro.debuggable"))
                 || Settings.Global.getInt(mContext.getContentResolver(),
@@ -5911,8 +5969,8 @@
                         }
                     }
                 }
-                if (mUseTvRouting) {
-                    // On TVs, defer special key handlings to
+                if (mUseTvRouting || mHandleVolumeKeysInWM) {
+                    // Defer special key handlings to
                     // {@link interceptKeyBeforeDispatching()}.
                     result |= ACTION_PASS_TO_USER;
                 } else if ((result & ACTION_PASS_TO_USER) == 0) {
@@ -8235,6 +8293,14 @@
         pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
                 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
         pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
+        if (mHasFeatureLeanback) {
+            pw.print(prefix);
+            pw.print("mAccessibilityTvKey1Pressed="); pw.println(mAccessibilityTvKey1Pressed);
+            pw.print(prefix);
+            pw.print("mAccessibilityTvKey2Pressed="); pw.println(mAccessibilityTvKey2Pressed);
+            pw.print(prefix);
+            pw.print("mAccessibilityTvScheduled="); pw.println(mAccessibilityTvScheduled);
+        }
 
         mGlobalKeyManager.dump(prefix, pw);
         mStatusBarController.dump(pw, prefix);
diff --git a/services/core/java/com/android/server/vr/VrManagerInternal.java b/services/core/java/com/android/server/vr/VrManagerInternal.java
index 63c6195..1f75640 100644
--- a/services/core/java/com/android/server/vr/VrManagerInternal.java
+++ b/services/core/java/com/android/server/vr/VrManagerInternal.java
@@ -16,7 +16,7 @@
 package com.android.server.vr;
 
 import android.annotation.NonNull;
-import android.app.CompatibilityDisplayProperties;
+import android.app.Vr2dDisplayProperties;
 import android.content.ComponentName;
 import android.service.vr.IPersistentVrStateCallbacks;
 
@@ -83,16 +83,16 @@
     public abstract int hasVrPackage(@NonNull ComponentName packageName, int userId);
 
     /**
-     * Sets the resolution and DPI of the compatibility virtual display used to display
+     * Sets the resolution and DPI of the vr2d virtual display used to display
      * 2D applications in VR mode.
      *
      * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
      *
-     * @param compatDisplayProp Properties of the virtual display for 2D applications
+     * @param vr2dDisplayProp Properties of the virtual display for 2D applications
      * in VR mode.
      */
-    public abstract void setCompatibilityDisplayProperties(
-            CompatibilityDisplayProperties compatDisplayProp);
+    public abstract void setVr2dDisplayProperties(
+            Vr2dDisplayProperties vr2dDisplayProp);
 
     /**
      * Sets the persistent VR mode state of a device. When a device is in persistent VR mode it will
@@ -110,7 +110,7 @@
      * @return {@link android.view.Display.INVALID_DISPLAY} if there is no virtual display
      * currently, else return the display id of the virtual display
      */
-    public abstract int getCompatibilityDisplayId();
+    public abstract int getVr2dDisplayId();
 
     /**
      * Adds listener that reports state changes to persistent VR mode.
diff --git a/services/core/java/com/android/server/vr/VrManagerService.java b/services/core/java/com/android/server/vr/VrManagerService.java
index 860b241..0e183f0 100644
--- a/services/core/java/com/android/server/vr/VrManagerService.java
+++ b/services/core/java/com/android/server/vr/VrManagerService.java
@@ -21,7 +21,7 @@
 import android.app.ActivityManagerInternal;
 import android.app.ActivityManager;
 import android.app.AppOpsManager;
-import android.app.CompatibilityDisplayProperties;
+import android.app.Vr2dDisplayProperties;
 import android.app.NotificationManager;
 import android.annotation.NonNull;
 import android.content.ComponentName;
@@ -141,7 +141,7 @@
     private final NotificationAccessManager mNotifAccessManager = new NotificationAccessManager();
     /** Tracks the state of the screen and keyguard UI.*/
     private int mSystemSleepFlags = FLAG_AWAKE;
-    private CompatibilityDisplay mCompatibilityDisplay;
+    private Vr2dDisplay mVr2dDisplay;
 
     private static final int MSG_VR_STATE_CHANGE = 0;
     private static final int MSG_PENDING_VR_STATE_CHANGE = 1;
@@ -428,15 +428,15 @@
         }
 
         @Override
-        public void setCompatibilityDisplayProperties(
-                CompatibilityDisplayProperties compatDisplayProp) {
+        public void setVr2dDisplayProperties(
+                Vr2dDisplayProperties vr2dDisplayProp) {
             enforceCallerPermission(Manifest.permission.RESTRICTED_VR_ACCESS);
-            VrManagerService.this.setCompatibilityDisplayProperties(compatDisplayProp);
+            VrManagerService.this.setVr2dDisplayProperties(vr2dDisplayProp);
         }
 
         @Override
-        public int getCompatibilityDisplayId() {
-            return VrManagerService.this.getCompatibilityDisplayId();
+        public int getVr2dDisplayId() {
+            return VrManagerService.this.getVr2dDisplayId();
         }
 
         @Override
@@ -549,14 +549,14 @@
         }
 
         @Override
-        public void setCompatibilityDisplayProperties(
-            CompatibilityDisplayProperties compatDisplayProp) {
-            VrManagerService.this.setCompatibilityDisplayProperties(compatDisplayProp);
+        public void setVr2dDisplayProperties(
+            Vr2dDisplayProperties compatDisplayProp) {
+            VrManagerService.this.setVr2dDisplayProperties(compatDisplayProp);
         }
 
         @Override
-        public int getCompatibilityDisplayId() {
-            return VrManagerService.this.getCompatibilityDisplayId();
+        public int getVr2dDisplayId() {
+            return VrManagerService.this.getVr2dDisplayId();
         }
 
         @Override
@@ -608,8 +608,8 @@
             DisplayManager dm =
                     (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
             ActivityManagerInternal ami = LocalServices.getService(ActivityManagerInternal.class);
-            mCompatibilityDisplay = new CompatibilityDisplay(dm, ami, mVrManager);
-            mCompatibilityDisplay.init(getContext());
+            mVr2dDisplay = new Vr2dDisplay(dm, ami, mVrManager);
+            mVr2dDisplay.init(getContext());
         } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
             synchronized (mLock) {
                 mVrModeAllowed = true;
@@ -1116,20 +1116,20 @@
         }
     }
 
-    public void setCompatibilityDisplayProperties(
-        CompatibilityDisplayProperties compatDisplayProp) {
-        if (mCompatibilityDisplay != null) {
-            mCompatibilityDisplay.setVirtualDisplayProperties(compatDisplayProp);
+    public void setVr2dDisplayProperties(
+        Vr2dDisplayProperties compatDisplayProp) {
+        if (mVr2dDisplay != null) {
+            mVr2dDisplay.setVirtualDisplayProperties(compatDisplayProp);
             return;
         }
-        Slog.w(TAG, "CompatibilityDisplay is null!");
+        Slog.w(TAG, "Vr2dDisplay is null!");
     }
 
-    private int getCompatibilityDisplayId() {
-        if (mCompatibilityDisplay != null) {
-            return mCompatibilityDisplay.getVirtualDisplayId();
+    private int getVr2dDisplayId() {
+        if (mVr2dDisplay != null) {
+            return mVr2dDisplay.getVirtualDisplayId();
         }
-        Slog.w(TAG, "CompatibilityDisplay is null!");
+        Slog.w(TAG, "Vr2dDisplay is null!");
         return INVALID_DISPLAY;
     }
 
diff --git a/services/core/java/com/android/server/wm/DimLayerController.java b/services/core/java/com/android/server/wm/DimLayerController.java
index 4100446..d44cd13 100644
--- a/services/core/java/com/android/server/wm/DimLayerController.java
+++ b/services/core/java/com/android/server/wm/DimLayerController.java
@@ -188,6 +188,7 @@
     boolean animateDimLayers() {
         int fullScreen = -1;
         int fullScreenAndDimming = -1;
+        int topFullScreenUserLayer = 0;
         boolean result = false;
 
         for (int i = mState.size() - 1; i >= 0; i--) {
@@ -213,8 +214,18 @@
             // and we have to make sure we always animate the layer.
             if (user.dimFullscreen() && state.dimLayer == mSharedFullScreenDimLayer) {
                 fullScreen = i;
-                if (mState.valueAt(i).continueDimming) {
+                if (!state.continueDimming) {
+                    continue;
+                }
+
+                // When choosing which user to assign the shared fullscreen layer to
+                // we need to look at Z-order.
+                if (topFullScreenUserLayer == 0 ||
+                        (state.animator != null && state.animator.mAnimLayer > topFullScreenUserLayer)) {
                     fullScreenAndDimming = i;
+                    if (state.animator != null) {
+                        topFullScreenUserLayer = state.animator.mAnimLayer;
+                    }
                 }
             } else {
                 // We always want to animate the non fullscreen windows, they don't share their
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
index f2a92df..e5c7a72 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
@@ -24,6 +24,7 @@
 import android.app.ActivityManager.TaskSnapshot;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.CompressFormat;
+import android.graphics.Bitmap.Config;
 import android.os.Process;
 import android.os.SystemClock;
 import android.util.ArraySet;
@@ -266,12 +267,13 @@
             final File file = getBitmapFile(mTaskId, mUserId);
             final File reducedFile = getReducedResolutionBitmapFile(mTaskId, mUserId);
             final Bitmap bitmap = Bitmap.createHardwareBitmap(mSnapshot.getSnapshot());
-            final Bitmap reduced = Bitmap.createScaledBitmap(bitmap,
+            final Bitmap swBitmap = bitmap.copy(Config.ARGB_8888, false /* isMutable */);
+            final Bitmap reduced = Bitmap.createScaledBitmap(swBitmap,
                     (int) (bitmap.getWidth() * REDUCED_SCALE),
                     (int) (bitmap.getHeight() * REDUCED_SCALE), true /* filter */);
             try {
                 FileOutputStream fos = new FileOutputStream(file);
-                bitmap.compress(JPEG, QUALITY, fos);
+                swBitmap.compress(JPEG, QUALITY, fos);
                 fos.close();
                 FileOutputStream reducedFos = new FileOutputStream(reducedFile);
                 reduced.compress(JPEG, QUALITY, reducedFos);
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
index c78488f..bb7e20b 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
@@ -368,8 +368,8 @@
     }
 
     @Test
-    public void testSetActiveScorer_noRequestNetworkScoresPermission() {
-        when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
+    public void testSetActiveScorer_noScoreNetworksPermission() {
+        when(mContext.checkCallingOrSelfPermission(permission.SCORE_NETWORKS))
                 .thenReturn(PackageManager.PERMISSION_DENIED);
 
         try {
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java b/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java
index 0694eae..ceb92de 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java
@@ -228,30 +228,23 @@
     }
 
     @Test
-    public void testSetActiveScorer_nullPackage_validDefault() throws Exception {
-        String packageName = "package";
-        String defaultPackage = "defaultPackage";
-        setNetworkRecoPackageSetting(packageName);
-        setDefaultNetworkRecommendationPackage(defaultPackage);
-        final ComponentName recoComponent = new ComponentName(defaultPackage, "class1");
-        mockScoreNetworksGranted(recoComponent.getPackageName());
-        mockRecommendationServiceAvailable(recoComponent, 924 /* packageUid */, null);
+    public void testSetActiveScorer_nullPackage_currentIsSet() throws Exception {
+        setNetworkRecoPackageSetting("package");
 
         assertTrue(mNetworkScorerAppManager.setActiveScorer(null));
         verify(mSettingsFacade).putString(mMockContext,
-                Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE, defaultPackage);
+                Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE, null);
+        verify(mSettingsFacade).putInt(mMockContext,
+                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
+                NetworkScoreManager.RECOMMENDATIONS_ENABLED_FORCED_OFF);
     }
 
     @Test
-    public void testSetActiveScorer_nullPackage_invalidDefault() throws Exception {
-        String packageName = "package";
-        String defaultPackage = "defaultPackage";
-        setNetworkRecoPackageSetting(packageName);
-        setDefaultNetworkRecommendationPackage(defaultPackage);
+    public void testSetActiveScorer_nullPackage_currentIsNull() throws Exception {
+        setNetworkRecoPackageSetting(null);
 
-        assertFalse(mNetworkScorerAppManager.setActiveScorer(null));
-        verify(mSettingsFacade, never()).putString(any(),
-                eq(Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE), any());
+        assertTrue(mNetworkScorerAppManager.setActiveScorer(null));
+        verify(mSettingsFacade, never()).putString(any(), any(), any());
     }
 
     @Test
@@ -266,6 +259,9 @@
         assertTrue(mNetworkScorerAppManager.setActiveScorer(newPackage));
         verify(mSettingsFacade).putString(mMockContext,
                 Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE, newPackage);
+        verify(mSettingsFacade).putInt(mMockContext,
+                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
+                NetworkScoreManager.RECOMMENDATIONS_ENABLED_ON);
     }
 
     @Test
@@ -341,6 +337,32 @@
     }
 
     @Test
+    public void testUpdateState_currentPackageNull_defaultNull() throws Exception {
+        setDefaultNetworkRecommendationPackage(null);
+        setNetworkRecoPackageSetting(null);
+
+        mNetworkScorerAppManager.updateState();
+
+        verify(mSettingsFacade, never()).putString(any(),
+                eq(Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE), anyString());
+        verify(mSettingsFacade, never()).putInt(any(),
+                eq(Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED), anyInt());
+    }
+
+    @Test
+    public void testUpdateState_currentPackageEmpty_defaultEmpty() throws Exception {
+        setDefaultNetworkRecommendationPackage("");
+        setNetworkRecoPackageSetting("");
+
+        mNetworkScorerAppManager.updateState();
+
+        verify(mSettingsFacade, never()).putString(any(),
+                eq(Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE), anyString());
+        verify(mSettingsFacade, never()).putInt(any(),
+                eq(Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED), anyInt());
+    }
+
+    @Test
     public void testUpdateState_currentPackageNotValid_sameAsDefault() throws Exception {
         String defaultPackage = "defaultPackage";
         setDefaultNetworkRecommendationPackage(defaultPackage);
diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java
index a23a6b22..649de4a 100644
--- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java
+++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotCacheTest.java
@@ -20,6 +20,7 @@
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
 
+import android.platform.test.annotations.Presubmit;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
 
@@ -33,8 +34,7 @@
  * runtest frameworks-services -c com.android.server.wm.TaskSnapshotCacheTest
  */
 @SmallTest
-// TODO(b/35196891): Add back to presubmit once the bug is fixed.
-//@Presubmit
+@Presubmit
 @RunWith(AndroidJUnit4.class)
 public class TaskSnapshotCacheTest extends TaskSnapshotPersisterTestBase {
 
diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
index 18d0c32..8146763 100644
--- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
+++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
@@ -68,7 +68,11 @@
     }
 
     private void cleanDirectory() {
-        for (File file : new File(sFilesDir, "snapshots").listFiles()) {
+        final File[] files = new File(sFilesDir, "snapshots").listFiles();
+        if (files == null) {
+            return;
+        }
+        for (File file : files) {
             if (!file.isDirectory()) {
                 file.delete();
             }
diff --git a/wifi/java/android/net/wifi/RttManager.java b/wifi/java/android/net/wifi/RttManager.java
index ff632a5..b133a44 100644
--- a/wifi/java/android/net/wifi/RttManager.java
+++ b/wifi/java/android/net/wifi/RttManager.java
@@ -660,10 +660,10 @@
         @Deprecated
         public int tx_rate;
 
-        /** average transmit rate. Unit (100kbps). */
+        /** average transmit rate. Unit (kbps). */
         public int txRate;
 
-        /** average receiving rate Unit (100kbps). */
+        /** average receiving rate Unit (kbps). */
         public int rxRate;
 
        /**
@@ -673,7 +673,7 @@
         @Deprecated
         public long rtt_ns;
 
-        /** average round trip time in 0.1 nano second. */
+        /** average round trip time in picoseconds. */
         public long rtt;
 
         /**
@@ -683,7 +683,7 @@
         @Deprecated
         public long rtt_sd_ns;
 
-        /** standard deviation of RTT in 0.1 ns. */
+        /** standard deviation of RTT in picoseconds. */
         public long rttStandardDeviation;
 
         /**
@@ -693,7 +693,7 @@
         @Deprecated
         public long rtt_spread_ns;
 
-        /** spread (i.e. max - min) RTT in 0.1 ns. */
+        /** spread (i.e. max - min) RTT in picoseconds. */
         public long rttSpread;
 
         /**
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index e31a74b..f7333e2 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -839,6 +839,10 @@
          */
         public static final int NETWORK_SELECTION_ENABLE = 0;
         /**
+         * The starting index for network selection disabled reasons
+         */
+        public static final int NETWORK_SELECTION_DISABLED_STARTING_INDEX = 1;
+        /**
          * @deprecated it is not used any more.
          * This network is disabled because higher layer (>2) network is bad
          */