Merge "add process ID to LogMaker"
diff --git a/api/current.txt b/api/current.txt
index 6a62fde..d837786 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -48766,6 +48766,7 @@
     field public static final int ERROR_TIMEOUT = -8; // 0xfffffff8
     field public static final int ERROR_TOO_MANY_REQUESTS = -15; // 0xfffffff1
     field public static final int ERROR_UNKNOWN = -1; // 0xffffffff
+    field public static final int ERROR_UNSAFE_RESOURCE = -16; // 0xfffffff0
     field public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; // 0xfffffffd
     field public static final int ERROR_UNSUPPORTED_SCHEME = -10; // 0xfffffff6
   }
diff --git a/api/system-current.txt b/api/system-current.txt
index e9fc9d2..b95f27a8 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -52351,6 +52351,7 @@
     field public static final int ERROR_TIMEOUT = -8; // 0xfffffff8
     field public static final int ERROR_TOO_MANY_REQUESTS = -15; // 0xfffffff1
     field public static final int ERROR_UNKNOWN = -1; // 0xffffffff
+    field public static final int ERROR_UNSAFE_RESOURCE = -16; // 0xfffffff0
     field public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; // 0xfffffffd
     field public static final int ERROR_UNSUPPORTED_SCHEME = -10; // 0xfffffff6
   }
diff --git a/api/test-current.txt b/api/test-current.txt
index fc96532..51ff912 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -49135,6 +49135,7 @@
     field public static final int ERROR_TIMEOUT = -8; // 0xfffffff8
     field public static final int ERROR_TOO_MANY_REQUESTS = -15; // 0xfffffff1
     field public static final int ERROR_UNKNOWN = -1; // 0xffffffff
+    field public static final int ERROR_UNSAFE_RESOURCE = -16; // 0xfffffff0
     field public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; // 0xfffffffd
     field public static final int ERROR_UNSUPPORTED_SCHEME = -10; // 0xfffffff6
   }
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index dad2061..152d514 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -475,7 +475,7 @@
     void reportSizeConfigurations(in IBinder token, in int[] horizontalSizeConfiguration,
             in int[] verticalSizeConfigurations, in int[] smallestWidthConfigurations);
     boolean moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
-            in Rect initialBounds, boolean moveHomeStackFront);
+            in Rect initialBounds);
     void suppressResizeConfigChanges(boolean suppress);
     void moveTasksToFullscreenStack(int fromStackId, boolean onTop);
     boolean moveTopActivityToPinnedStack(int stackId, in Rect bounds);
diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java
index ad06141..61c9201 100644
--- a/core/java/android/view/FocusFinder.java
+++ b/core/java/android/view/FocusFinder.java
@@ -732,17 +732,27 @@
             getRect(first, mFirstRect);
             getRect(second, mSecondRect);
 
-            boolean overlapsVertically = (mFirstRect.top < mSecondRect.top
-                    && mFirstRect.bottom > mSecondRect.top)
-                    || (mFirstRect.top > mSecondRect.top
-                    && mFirstRect.top < mSecondRect.bottom);
-            boolean alignedVertically = (mFirstRect.left > mSecondRect.left)
-                    == (mFirstRect.right < mSecondRect.right);
-            if (overlapsVertically && !alignedVertically) {
-                int rtl = mIsLayoutRtl ? -1 : 1;
-                return rtl * (mFirstRect.left - mSecondRect.left);
+            if (mFirstRect.top < mSecondRect.top) {
+                return -1;
+            } else if (mFirstRect.top > mSecondRect.top) {
+                return 1;
+            } else if (mFirstRect.left < mSecondRect.left) {
+                return mIsLayoutRtl ? 1 : -1;
+            } else if (mFirstRect.left > mSecondRect.left) {
+                return mIsLayoutRtl ? -1 : 1;
+            } else if (mFirstRect.bottom < mSecondRect.bottom) {
+                return -1;
+            } else if (mFirstRect.bottom > mSecondRect.bottom) {
+                return 1;
+            } else if (mFirstRect.right < mSecondRect.right) {
+                return mIsLayoutRtl ? 1 : -1;
+            } else if (mFirstRect.right > mSecondRect.right) {
+                return mIsLayoutRtl ? -1 : 1;
             } else {
-                return mFirstRect.top - mSecondRect.top;
+                // The view are distinct but completely coincident so we consider
+                // them equal for our purposes.  Since the sort is stable, this
+                // means that the views will retain their layout order relative to one another.
+                return 0;
             }
         }
 
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java
index 0a73e17d..788908a 100644
--- a/core/java/android/webkit/WebViewClient.java
+++ b/core/java/android/webkit/WebViewClient.java
@@ -234,6 +234,8 @@
     public static final int ERROR_FILE_NOT_FOUND = -14;
     /** Too many requests during this load */
     public static final int ERROR_TOO_MANY_REQUESTS = -15;
+    /** Resource load was cancelled by Safe Browsing */
+    public static final int ERROR_UNSAFE_RESOURCE = -16;
 
     /**
      * Report an error to the host application. These errors are unrecoverable
diff --git a/core/java/com/android/internal/logging/MetricsLogger.java b/core/java/com/android/internal/logging/MetricsLogger.java
index 949e7ac..a482929 100644
--- a/core/java/com/android/internal/logging/MetricsLogger.java
+++ b/core/java/com/android/internal/logging/MetricsLogger.java
@@ -31,109 +31,188 @@
     // define metric categories in frameworks/base/proto/src/metrics_constants.proto.
     // mirror changes in native version at system/core/libmetricslogger/metrics_logger.cpp
 
+    private static MetricsLogger sMetricsLogger;
+
+    private static MetricsLogger getLogger() {
+        if (sMetricsLogger == null) {
+            sMetricsLogger = new MetricsLogger();
+        }
+        return sMetricsLogger;
+    }
+
+    protected void saveLog(Object[] rep) {
+        EventLogTags.writeSysuiMultiAction(rep);
+    }
+
     public static final int VIEW_UNKNOWN = MetricsEvent.VIEW_UNKNOWN;
     public static final int LOGTAG = EventLogTags.SYSUI_MULTI_ACTION;
 
-    public static void visible(Context context, int category) throws IllegalArgumentException {
+    public void write(LogMaker content) {
+        if (content.getType() == MetricsEvent.TYPE_UNKNOWN) {
+            content.setType(MetricsEvent.TYPE_ACTION);
+        }
+        saveLog(content.serialize());
+    }
+
+    public void visible(int category) throws IllegalArgumentException {
         if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) {
             throw new IllegalArgumentException("Must define metric category");
         }
         EventLogTags.writeSysuiViewVisibility(category, 100);
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(category)
+        saveLog(new LogMaker(category)
                         .setType(MetricsEvent.TYPE_OPEN)
                         .serialize());
     }
 
-    public static void hidden(Context context, int category) throws IllegalArgumentException {
+    public void hidden(int category) throws IllegalArgumentException {
         if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) {
             throw new IllegalArgumentException("Must define metric category");
         }
         EventLogTags.writeSysuiViewVisibility(category, 0);
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(category)
+        saveLog(new LogMaker(category)
                         .setType(MetricsEvent.TYPE_CLOSE)
                         .serialize());
     }
 
-    public static void visibility(Context context, int category, boolean visibile)
+    public void visibility(int category, boolean visibile)
             throws IllegalArgumentException {
         if (visibile) {
-            visible(context, category);
+            visible(category);
         } else {
-            hidden(context, category);
+            hidden(category);
         }
     }
 
-    public static void visibility(Context context, int category, int vis)
+    public void visibility(int category, int vis)
             throws IllegalArgumentException {
-        visibility(context, category, vis == View.VISIBLE);
+        visibility(category, vis == View.VISIBLE);
     }
 
-    public static void action(Context context, int category) {
+    public void action(int category) {
         EventLogTags.writeSysuiAction(category, "");
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(category)
+        saveLog(new LogMaker(category)
                         .setType(MetricsEvent.TYPE_ACTION)
                         .serialize());
     }
 
-    public static void action(Context context, int category, int value) {
+    public void action(int category, int value) {
         EventLogTags.writeSysuiAction(category, Integer.toString(value));
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(category)
+        saveLog(new LogMaker(category)
                         .setType(MetricsEvent.TYPE_ACTION)
                         .setSubtype(value)
                         .serialize());
     }
 
-    public static void action(Context context, int category, boolean value) {
+    public void action(int category, boolean value) {
         EventLogTags.writeSysuiAction(category, Boolean.toString(value));
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(category)
+        saveLog(new LogMaker(category)
                         .setType(MetricsEvent.TYPE_ACTION)
                         .setSubtype(value ? 1 : 0)
                         .serialize());
     }
 
-    public static void action(LogMaker content) {
-        if (content.getType() == MetricsEvent.TYPE_UNKNOWN) {
-            content.setType(MetricsEvent.TYPE_ACTION);
-        }
-        EventLogTags.writeSysuiMultiAction(content.serialize());
-    }
-
-
-    public static void action(Context context, int category, String pkg) {
+    public void action(int category, String pkg) {
         if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) {
             throw new IllegalArgumentException("Must define metric category");
         }
         EventLogTags.writeSysuiAction(category, pkg);
-        EventLogTags.writeSysuiMultiAction(new LogMaker(category)
+        saveLog(new LogMaker(category)
                 .setType(MetricsEvent.TYPE_ACTION)
                 .setPackageName(pkg)
                 .serialize());
     }
 
     /** Add an integer value to the monotonically increasing counter with the given name. */
-    public static void count(Context context, String name, int value) {
+    public void count(String name, int value) {
         EventLogTags.writeSysuiCount(name, value);
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_COUNTER)
+        saveLog(new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_COUNTER)
                         .setCounterName(name)
                         .setCounterValue(value)
                         .serialize());
     }
 
     /** Increment the bucket with the integer label on the histogram with the given name. */
-    public static void histogram(Context context, String name, int bucket) {
+    public void histogram(String name, int bucket) {
         // see LogHistogram in system/core/libmetricslogger/metrics_logger.cpp
         EventLogTags.writeSysuiHistogram(name, bucket);
-        EventLogTags.writeSysuiMultiAction(
-                new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_HISTOGRAM)
+        saveLog(new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_HISTOGRAM)
                         .setCounterName(name)
                         .setCounterBucket(bucket)
                         .setCounterValue(1)
                         .serialize());
     }
+
+    /** @deprecated use {@link #visible(int)} */
+    @Deprecated
+    public static void visible(Context context, int category) throws IllegalArgumentException {
+        getLogger().visible(category);
+    }
+
+    /** @deprecated use {@link #hidden(int)} */
+    @Deprecated
+    public static void hidden(Context context, int category) throws IllegalArgumentException {
+        getLogger().hidden(category);
+    }
+
+    /** @deprecated use {@link #visibility(int, boolean)} */
+    @Deprecated
+    public static void visibility(Context context, int category, boolean visibile)
+            throws IllegalArgumentException {
+        getLogger().visibility(category, visibile);
+    }
+
+    /** @deprecated use {@link #visibility(int, int)} */
+    @Deprecated
+    public static void visibility(Context context, int category, int vis)
+            throws IllegalArgumentException {
+        visibility(context, category, vis == View.VISIBLE);
+    }
+
+    /** @deprecated use {@link #action(int)} */
+    @Deprecated
+    public static void action(Context context, int category) {
+        getLogger().action(category);
+    }
+
+    /** @deprecated use {@link #action(int, int)} */
+    @Deprecated
+    public static void action(Context context, int category, int value) {
+        getLogger().action(category, value);
+    }
+
+    /** @deprecated use {@link #action(int, boolean)} */
+    @Deprecated
+    public static void action(Context context, int category, boolean value) {
+        getLogger().action(category, value);
+    }
+
+    /** @deprecated use {@link #write(LogMaker)} */
+    @Deprecated
+    public static void action(LogMaker content) {
+        getLogger().write(content);
+    }
+
+    /** @deprecated use {@link #action(int, String)} */
+    @Deprecated
+    public static void action(Context context, int category, String pkg) {
+        getLogger().action(category, pkg);
+    }
+
+    /**
+     * Add an integer value to the monotonically increasing counter with the given name.
+     * @deprecated use {@link #count(String, int)}
+     */
+    @Deprecated
+    public static void count(Context context, String name, int value) {
+        getLogger().count(name, value);
+    }
+
+    /**
+     * Increment the bucket with the integer label on the histogram with the given name.
+     * @deprecated use {@link #histogram(String, int)}
+     */
+    @Deprecated
+    public static void histogram(Context context, String name, int bucket) {
+        getLogger().histogram(name, bucket);
+    }
 }
diff --git a/core/java/com/android/internal/logging/testing/FakeMetricsLogger.java b/core/java/com/android/internal/logging/testing/FakeMetricsLogger.java
new file mode 100644
index 0000000..fbaf87a
--- /dev/null
+++ b/core/java/com/android/internal/logging/testing/FakeMetricsLogger.java
@@ -0,0 +1,30 @@
+package com.android.internal.logging.testing;
+
+import android.metrics.LogMaker;
+
+import com.android.internal.logging.MetricsLogger;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * Fake logger that queues up logged events for inspection.
+ *
+ * @hide.
+ */
+public class FakeMetricsLogger extends MetricsLogger {
+    private Queue<LogMaker> logs = new LinkedList<>();
+
+    @Override
+    protected void saveLog(Object[] rep) {
+        logs.offer(new LogMaker(rep));
+    }
+
+    public Queue<LogMaker> getLogs() {
+        return logs;
+    }
+
+    public void reset() {
+        logs.clear();
+    }
+}
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index fa71a62..e065843 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -100,6 +100,8 @@
           int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
           int[] fdsToIgnore, String instructionSet, String appDataDir) {
         VM_HOOKS.preFork();
+        // Resets nice priority for zygote process.
+        resetNicePriority();
         int pid = nativeForkAndSpecialize(
                   uid, gid, gids, debugFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                   fdsToIgnore, instructionSet, appDataDir);
@@ -144,6 +146,8 @@
     public static int forkSystemServer(int uid, int gid, int[] gids, int debugFlags,
             int[][] rlimits, long permittedCapabilities, long effectiveCapabilities) {
         VM_HOOKS.preFork();
+        // Resets nice priority for zygote process.
+        resetNicePriority();
         int pid = nativeForkSystemServer(
                 uid, gid, gids, debugFlags, rlimits, permittedCapabilities, effectiveCapabilities);
         // Enable tracing as soon as we enter the system_server.
@@ -174,9 +178,13 @@
     }
 
     /**
-     * Resets this process' priority to the default value (0).
+     * Resets the calling thread priority to the default value (Thread.NORM_PRIORITY
+     * or nice value 0). This updates both the priority value in java.lang.Thread and
+     * the nice value (setpriority).
      */
-    native static void nativeResetNicePriority();
+    static void resetNicePriority() {
+        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
+    }
 
     /**
      * Executes "/system/bin/sh -c &lt;command&gt;" using the exec() system call.
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 310cbc7..a7e900a 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -715,7 +715,7 @@
                     SystemClock.uptimeMillis());
                 bootTimingsTraceLog.traceEnd(); // ZygotePreload
             } else {
-                Zygote.nativeResetNicePriority();
+                Zygote.resetNicePriority();
             }
 
             // Finish profiling the zygote initialization.
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index c3f0e9d..0ab27f2 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -155,24 +155,6 @@
   }
 }
 
-// Resets nice priority for zygote process. Zygote priority can be set
-// to high value during boot phase to speed it up. We want to ensure
-// zygote is running at normal priority before childs are forked from it.
-//
-// This ends up being called repeatedly before each fork(), but there's
-// no real harm in that.
-static void ResetNicePriority(JNIEnv* env) {
-  errno = 0;
-  int prio = getpriority(PRIO_PROCESS, 0);
-  if (prio == -1 && errno != 0) {
-    ALOGW("getpriority failed: %s\n", strerror(errno));
-  }
-  if (prio != 0 && setpriority(PRIO_PROCESS, 0, 0) != 0) {
-    ALOGE("setpriority(%d, 0, 0) failed: %s", PRIO_PROCESS, strerror(errno));
-    RuntimeAbort(env, __LINE__, "setpriority failed");
-  }
-}
-
 // Sets the SIGCHLD handler back to default behavior in zygote children.
 static void UnsetSigChldHandler() {
   struct sigaction sa;
@@ -526,8 +508,6 @@
     RuntimeAbort(env, __LINE__, "Unable to restat file descriptor table.");
   }
 
-  ResetNicePriority(env);
-
   pid_t pid = fork();
 
   if (pid == 0) {
@@ -806,10 +786,6 @@
     UnmountTree("/storage");
 }
 
-static void com_android_internal_os_Zygote_nativeResetNicePriority(JNIEnv* env, jclass) {
-    ResetNicePriority(env);
-}
-
 static const JNINativeMethod gMethods[] = {
     { "nativeForkAndSpecialize",
       "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[ILjava/lang/String;Ljava/lang/String;)I",
@@ -819,9 +795,7 @@
     { "nativeAllowFileAcrossFork", "(Ljava/lang/String;)V",
       (void *) com_android_internal_os_Zygote_nativeAllowFileAcrossFork },
     { "nativeUnmountStorageOnInit", "()V",
-      (void *) com_android_internal_os_Zygote_nativeUnmountStorageOnInit },
-    { "nativeResetNicePriority", "()V",
-      (void *) com_android_internal_os_Zygote_nativeResetNicePriority }
+      (void *) com_android_internal_os_Zygote_nativeUnmountStorageOnInit }
 };
 
 int register_com_android_internal_os_Zygote(JNIEnv* env) {
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index 51a7d00..812e4d8 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -512,15 +512,7 @@
 
 void SkiaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
     if (CC_UNLIKELY(paint.nothingToDraw())) return;
-    SkRect rect;
-    SkRRect roundRect;
-    if (path.isOval(&rect)) {
-        mCanvas->drawOval(rect, paint);
-    } else if (path.isRRect(&roundRect)) {
-        mCanvas->drawRRect(roundRect, paint);
-    } else {
-        mCanvas->drawPath(path, paint);
-    }
+    mCanvas->drawPath(path, paint);
 }
 
 void SkiaCanvas::drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index 31f9ba4..12332fb 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -519,7 +519,7 @@
 
         try {
             return mIam.moveTaskToDockedStack(taskId, createMode, true /* onTop */,
-                    false /* animate */, initialBounds, true /* moveHomeStackFront */ );
+                    false /* animate */, initialBounds);
         } catch (RemoteException e) {
             e.printStackTrace();
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 005b701..6c729dc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -487,6 +487,8 @@
 
     private ScreenPinningRequest mScreenPinningRequest;
 
+    MetricsLogger mMetricsLogger = new MetricsLogger();
+
     // ensure quick settings is disabled until the current user makes it through the setup wizard
     private boolean mUserSetup = false;
     private DeviceProvisionedListener mUserSetupObserver = new DeviceProvisionedListener() {
@@ -1360,7 +1362,7 @@
         mDismissView.setOnButtonClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                MetricsLogger.action(mContext, MetricsEvent.ACTION_DISMISS_ALL_NOTES);
+                mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES);
                 clearAllNotifications();
             }
         });
@@ -1539,7 +1541,7 @@
             } else {
                 EventBus.getDefault().send(new UndockingTaskEvent());
                 if (metricsUndockAction != -1) {
-                    MetricsLogger.action(mContext, metricsUndockAction);
+                    mMetricsLogger.action(metricsUndockAction);
                 }
             }
         }
@@ -1597,7 +1599,7 @@
                             notification.getKey());
                     notification.getNotification().fullScreenIntent.send();
                     shadeEntry.notifyFullScreenIntentLaunched();
-                    MetricsLogger.count(mContext, "note_fullscreen", 1);
+                    mMetricsLogger.count("note_fullscreen", 1);
                 } catch (PendingIntent.CanceledException e) {
                 }
             }
@@ -2801,16 +2803,16 @@
         if (!mUserSetup) return;
 
         if (KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP == key) {
-            MetricsLogger.action(mContext, MetricsEvent.ACTION_SYSTEM_NAVIGATION_KEY_UP);
+            mMetricsLogger.action(MetricsEvent.ACTION_SYSTEM_NAVIGATION_KEY_UP);
             mNotificationPanel.collapse(false /* delayed */, 1.0f /* speedUpFactor */);
         } else if (KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN == key) {
-            MetricsLogger.action(mContext, MetricsEvent.ACTION_SYSTEM_NAVIGATION_KEY_DOWN);
+            mMetricsLogger.action(MetricsEvent.ACTION_SYSTEM_NAVIGATION_KEY_DOWN);
             if (mNotificationPanel.isFullyCollapsed()) {
                 mNotificationPanel.expand(true /* animate */);
-                MetricsLogger.count(mContext, NotificationPanelView.COUNTER_PANEL_OPEN, 1);
+                mMetricsLogger.count(NotificationPanelView.COUNTER_PANEL_OPEN, 1);
             } else if (!mNotificationPanel.isInSettings() && !mNotificationPanel.isExpanding()){
                 mNotificationPanel.flingSettings(0 /* velocity */, true /* expand */);
-                MetricsLogger.count(mContext, NotificationPanelView.COUNTER_PANEL_OPEN_QS, 1);
+                mMetricsLogger.count(NotificationPanelView.COUNTER_PANEL_OPEN_QS, 1);
             }
         }
 
@@ -3689,7 +3691,7 @@
                 if (pinnedHeadsUp && isPanelFullyCollapsed())  {
                     notificationLoad = 1;
                 } else {
-                    MetricsLogger.histogram(mContext, "note_load", notificationLoad);
+                    mMetricsLogger.histogram("note_load", notificationLoad);
                 }
                 mBarService.onPanelRevealed(clearNotificationEffects, notificationLoad);
             } else {
@@ -3772,7 +3774,7 @@
             if (mStatusBarStateLog == null) {
                 mStatusBarStateLog = new LogMaker(MetricsEvent.VIEW_UNKNOWN);
             }
-            MetricsLogger.action(mStatusBarStateLog
+            mMetricsLogger.write(mStatusBarStateLog
                     .setCategory(isBouncerShowing ? MetricsEvent.BOUNCER : MetricsEvent.LOCKSCREEN)
                     .setType(isShowing ? MetricsEvent.TYPE_OPEN : MetricsEvent.TYPE_CLOSE)
                     .setSubtype(isSecure ? 1 : 0));
@@ -5776,7 +5778,7 @@
             NotificationInfo info = (NotificationInfo) item.gutsContent;
             final NotificationInfo.OnSettingsClickListener onSettingsClick = (View v,
                     int appUid) -> {
-                MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTE_INFO);
+                mMetricsLogger.action(MetricsEvent.ACTION_NOTE_INFO);
                 guts.resetFalsingCheck();
                 startAppNotificationSettingsActivity(pkg, appUid, channel.getId());
             };
@@ -5848,7 +5850,7 @@
                     return false;
                 }
 
-                MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTE_CONTROLS);
+                mMetricsLogger.action(MetricsEvent.ACTION_NOTE_CONTROLS);
 
                 // ensure that it's laid but not visible until actually laid out
                 guts.setVisibility(View.INVISIBLE);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index 9f56da7..09f6b55 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -23,14 +23,15 @@
 import static org.mockito.Mockito.when;
 
 import android.metrics.LogMaker;
-import android.metrics.MetricsReader;
 import android.support.test.filters.FlakyTest;
 import android.support.test.filters.SmallTest;
 import android.support.test.metricshelper.MetricsAsserts;
 import android.support.test.runner.AndroidJUnit4;
 import android.util.DisplayMetrics;
 
+import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.logging.testing.FakeMetricsLogger;
 import com.android.keyguard.KeyguardHostView.OnDismissAction;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.statusbar.ActivatableNotificationView;
@@ -43,9 +44,6 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-// TODO(gpitsch): We have seen some flakes in these tests, needs some investigation.
-// Q: How is mMetricsReader being used by the tested code?
-// A: StatusBar uses MetricsLogger to write to the event log, then read back by MetricsReader
 @SmallTest
 @RunWith(AndroidJUnit4.class)
 public class StatusBarTest extends SysuiTestCase {
@@ -55,8 +53,8 @@
     KeyguardIndicationController mKeyguardIndicationController;
     NotificationStackScrollLayout mStackScroller;
     StatusBar mStatusBar;
+    FakeMetricsLogger mMetricsLogger;
 
-    private MetricsReader mMetricsReader;
     private DisplayMetrics mDisplayMetrics = new DisplayMetrics();
 
     @Before
@@ -65,8 +63,9 @@
         mUnlockMethodCache = mock(UnlockMethodCache.class);
         mKeyguardIndicationController = mock(KeyguardIndicationController.class);
         mStackScroller = mock(NotificationStackScrollLayout.class);
+        mMetricsLogger = new FakeMetricsLogger();
         mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache,
-                mKeyguardIndicationController, mStackScroller);
+                mKeyguardIndicationController, mStackScroller, mMetricsLogger);
 
         doAnswer(invocation -> {
             OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0];
@@ -81,15 +80,6 @@
         }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any());
 
         when(mStackScroller.getActivatedChild()).thenReturn(null);
-
-        mMetricsReader = new MetricsReader();
-        mMetricsReader.checkpoint(); // clear out old logs
-        try {
-            // pause so that no new events arrive in the rest of this millisecond.
-            Thread.sleep(2);
-        } catch (InterruptedException e) {
-            // pass
-        }
     }
 
     @Test
@@ -127,10 +117,10 @@
         when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false);
         when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false);
         when(mUnlockMethodCache.isMethodSecure()).thenReturn(false);
-
         mStatusBar.onKeyguardViewManagerStatesUpdated();
 
-        MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", mMetricsReader,
+        MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log",
+                mMetricsLogger.getLogs(),
                 new LogMaker(MetricsEvent.LOCKSCREEN)
                         .setType(MetricsEvent.TYPE_CLOSE)
                         .setSubtype(0));
@@ -150,7 +140,8 @@
 
         mStatusBar.onKeyguardViewManagerStatesUpdated();
 
-        MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", mMetricsReader,
+        MetricsAsserts.assertHasLog("missing hidden secure lockscreen log",
+                mMetricsLogger.getLogs(),
                 new LogMaker(MetricsEvent.LOCKSCREEN)
                         .setType(MetricsEvent.TYPE_CLOSE)
                         .setSubtype(1));
@@ -170,7 +161,8 @@
 
         mStatusBar.onKeyguardViewManagerStatesUpdated();
 
-        MetricsAsserts.assertHasLog("missing insecure lockscreen showing", mMetricsReader,
+        MetricsAsserts.assertHasLog("missing insecure lockscreen showing",
+                mMetricsLogger.getLogs(),
                 new LogMaker(MetricsEvent.LOCKSCREEN)
                         .setType(MetricsEvent.TYPE_OPEN)
                         .setSubtype(0));
@@ -190,7 +182,8 @@
 
         mStatusBar.onKeyguardViewManagerStatesUpdated();
 
-        MetricsAsserts.assertHasLog("missing secure lockscreen showing log", mMetricsReader,
+        MetricsAsserts.assertHasLog("missing secure lockscreen showing log",
+                mMetricsLogger.getLogs(),
                 new LogMaker(MetricsEvent.LOCKSCREEN)
                         .setType(MetricsEvent.TYPE_OPEN)
                         .setSubtype(1));
@@ -210,7 +203,8 @@
 
         mStatusBar.onKeyguardViewManagerStatesUpdated();
 
-        MetricsAsserts.assertHasLog("missing bouncer log", mMetricsReader,
+        MetricsAsserts.assertHasLog("missing bouncer log",
+                mMetricsLogger.getLogs(),
                 new LogMaker(MetricsEvent.BOUNCER)
                         .setType(MetricsEvent.TYPE_OPEN)
                         .setSubtype(1));
@@ -223,7 +217,8 @@
         ActivatableNotificationView view =  mock(ActivatableNotificationView.class);
         mStatusBar.onActivated(view);
 
-        MetricsAsserts.assertHasLog("missing lockscreen note tap log", mMetricsReader,
+        MetricsAsserts.assertHasLog("missing lockscreen note tap log",
+                mMetricsLogger.getLogs(),
                 new LogMaker(MetricsEvent.ACTION_LS_NOTE)
                         .setType(MetricsEvent.TYPE_ACTION));
     }
@@ -231,11 +226,12 @@
     static class TestableStatusBar extends StatusBar {
         public TestableStatusBar(StatusBarKeyguardViewManager man,
                 UnlockMethodCache unlock, KeyguardIndicationController key,
-                NotificationStackScrollLayout stack) {
+                NotificationStackScrollLayout stack, MetricsLogger logger) {
             mStatusBarKeyguardViewManager = man;
             mUnlockMethodCache = unlock;
             mKeyguardIndicationController = key;
             mStackScroller = stack;
+            mMetricsLogger = logger;
         }
 
         @Override
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
index ea9b651..0d5a3e0 100644
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -289,7 +289,7 @@
                      * and then rebuild the cache. All under the cache lock. But that change is too
                      * large at this point.
                      */
-                    final String removedPackageName = intent.getData().toString();
+                    final String removedPackageName = intent.getData().getSchemeSpecificPart();
                     Runnable purgingRunnable = new Runnable() {
                         @Override
                         public void run() {
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 10b1f2b..0a65cab 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -10247,13 +10247,8 @@
                     mWindowManager.setDockedStackCreateState(DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT,
                             null /* initialBounds */);
                 }
-
-                final boolean successful = task.reparent(stackId, toTop,
+                task.reparent(stackId, toTop,
                         REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, "moveTaskToStack");
-                if (successful && stackId == DOCKED_STACK_ID) {
-                    // If task moved to docked stack - show recents if needed.
-                    mWindowManager.showRecentApps(false /* fromHome */);
-                }
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
@@ -10326,7 +10321,7 @@
      */
     @Override
     public boolean moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
-            Rect initialBounds, boolean moveHomeStackFront) {
+            Rect initialBounds) {
         enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToDockedStack()");
         synchronized (this) {
             long ident = Binder.clearCallingIdentity();
@@ -10343,12 +10338,9 @@
 
                 // Defer resuming until we move the home stack to the front below
                 final boolean moved = task.reparent(DOCKED_STACK_ID, toTop,
-                        REPARENT_KEEP_STACK_AT_FRONT, animate, DEFER_RESUME,
+                        REPARENT_KEEP_STACK_AT_FRONT, animate, !DEFER_RESUME,
                         "moveTaskToDockedStack");
                 if (moved) {
-                    if (moveHomeStackFront) {
-                        mStackSupervisor.moveHomeStackToFront("moveTaskToDockedStack");
-                    }
                     mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                 }
                 return moved;
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index a679a31..15a9efc 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -1582,6 +1582,16 @@
                     : STACK_INVISIBLE;
         }
 
+        // Set home stack to invisible when it is below but not immediately below the docked stack
+        // A case would be if recents stack exists but has no tasks and is below the docked stack
+        // and home stack is below recents
+        if (mStackId == HOME_STACK_ID) {
+            int dockedStackIndex = mStacks.indexOf(mStackSupervisor.getStack(DOCKED_STACK_ID));
+            if (dockedStackIndex > stackIndex && stackIndex != dockedStackIndex - 1) {
+                return STACK_INVISIBLE;
+            }
+        }
+
         // Find the first stack behind front stack that actually got something visible.
         int stackBehindTopIndex = mStacks.indexOf(topStack) - 1;
         while (stackBehindTopIndex >= 0 &&
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index bd70861..59f58d7 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -33,6 +33,7 @@
 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
 import static android.app.ActivityManager.StackId.LAST_STATIC_STACK_ID;
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
 import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -670,6 +671,13 @@
         mHomeStack.moveToFront(reason);
     }
 
+    void moveRecentsStackToFront(String reason) {
+        final ActivityStack recentsStack = getStack(RECENTS_STACK_ID);
+        if (recentsStack != null) {
+            recentsStack.moveToFront(reason);
+        }
+    }
+
     /** Returns true if the focus activity was adjusted to the home stack top activity. */
     boolean moveHomeStackTaskToTop(String reason) {
         mHomeStack.moveHomeStackTaskToTop();
@@ -2048,6 +2056,11 @@
         if (!createStaticStackIfNeeded || !StackId.isStaticStack(stackId)) {
             return null;
         }
+        if (stackId == DOCKED_STACK_ID) {
+            // Make sure recents stack exist when creating a dock stack as it normally need to be on
+            // the other side of the docked stack and we make visibility decisions based on that.
+            getStack(RECENTS_STACK_ID, CREATE_IF_NEEDED, createOnTop);
+        }
         return (T) createStackOnDisplay(stackId, DEFAULT_DISPLAY, createOnTop);
     }
 
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 3f33f41..c0c433e 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -690,6 +690,11 @@
                 }
                 kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume);
             } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) {
+                if (stackId == DOCKED_STACK_ID && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) {
+                    // Move recents to front so it is not behind home stack when going into docked
+                    // mode
+                    mService.mStackSupervisor.moveRecentsStackToFront(reason);
+                }
                 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
                         deferResume);
             }
@@ -713,7 +718,12 @@
 
         supervisor.handleNonResizableTaskIfNeeded(this, preferredStackId, stackId);
 
-        return (preferredStackId == stackId);
+        boolean successful = (preferredStackId == stackId);
+        if (successful && stackId == DOCKED_STACK_ID) {
+            // If task moved to docked stack - show recents if needed.
+            mService.mWindowManager.showRecentApps(false /* fromHome */);
+        }
+        return successful;
     }
 
     void cancelWindowTransition() {
diff --git a/services/core/java/com/android/server/vr/CompatibilityDisplay.java b/services/core/java/com/android/server/vr/CompatibilityDisplay.java
index 15edaaf..c54fd9a 100644
--- a/services/core/java/com/android/server/vr/CompatibilityDisplay.java
+++ b/services/core/java/com/android/server/vr/CompatibilityDisplay.java
@@ -2,8 +2,10 @@
 package com.android.server.vr;
 
 import android.app.Service;
+import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.hardware.display.DisplayManager;
 import android.hardware.display.VirtualDisplay;
 import android.os.Build;
@@ -14,6 +16,7 @@
 import android.service.vr.IVrStateCallbacks;
 import android.service.vr.IVrManager;
 import android.util.Log;
+import android.view.Surface;
 
 import com.android.server.vr.VrManagerService;
 
@@ -26,10 +29,19 @@
     private final static boolean DEBUG = false;
 
     // TODO: Go over these values and figure out what is best
-    private final static int HEIGHT = 960;
-    private final static int WIDTH = 720;
+    private final static int HEIGHT = 1800;
+    private final static int WIDTH = 1400;
     private final static int DPI = 320;
 
+    private final static String DEBUG_ACTION_SET_MODE =
+            "com.android.server.vr.CompatibilityDisplay.SET_MODE";
+    private final static String DEBUG_EXTRA_MODE_ON =
+            "com.android.servier.vr.CompatibilityDisplay.EXTRA_MODE_ON";
+    private final static String DEBUG_ACTION_SET_SURFACE =
+            "com.android.server.vr.CompatibilityDisplay.SET_SURFACE";
+    private final static String DEBUG_EXTRA_SURFACE =
+            "com.android.server.vr.CompatibilityDisplay.EXTRA_SURFACE";
+
     private final DisplayManager mDisplayManager;
     private final IVrManager mVrManager;
 
@@ -42,18 +54,14 @@
         public void onVrStateChanged(boolean enabled) {
             if (enabled != mIsVrModeEnabled) {
                 mIsVrModeEnabled = enabled;
-                if (enabled) {
-                    // TODO: Consider not creating the display until ActivityManager needs one on
-                    // which to display a 2D application.
-                    startVirtualDisplay();
-                } else {
-                    stopVirtualDisplay();
-                }
+                updateVirtualDisplay();
             }
         }
     };
 
     private VirtualDisplay mVirtualDisplay;
+    private Surface mSurface;
+    private boolean mIsDebugOverrideEnabled;
     private boolean mIsVrModeEnabled;
 
     public CompatibilityDisplay(DisplayManager displayManager, IVrManager vrManager) {
@@ -64,8 +72,60 @@
     /**
      * Initializes the compabilitiy display by listening to VR mode changes.
      */
-    public void init() {
+    public void init(Context context) {
         startVrModeListener();
+        startDebugOnlyBroadcastReceiver(context);
+    }
+
+    private void updateVirtualDisplay() {
+        if (mIsVrModeEnabled || (DEBUG && mIsDebugOverrideEnabled)) {
+            // TODO: Consider not creating the display until ActivityManager needs one on
+            // which to display a 2D application.
+            // TODO: STOPSHIP Remove DEBUG conditional before launching.
+            if (DEBUG) {
+                startVirtualDisplay();
+            }
+        } else {
+            // TODO: Remove conditional when launching apps 2D doesn't force VrMode to stop.
+            if (!DEBUG) {
+                stopVirtualDisplay();
+            }
+        }
+    }
+
+    private void startDebugOnlyBroadcastReceiver(Context context) {
+        if (DEBUG) {
+            IntentFilter intentFilter = new IntentFilter(DEBUG_ACTION_SET_MODE);
+            intentFilter.addAction(DEBUG_ACTION_SET_SURFACE);
+
+            context.registerReceiver(new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    final String action = intent.getAction();
+                    if (DEBUG_ACTION_SET_MODE.equals(action)) {
+                        mIsDebugOverrideEnabled =
+                                intent.getBooleanExtra(DEBUG_EXTRA_MODE_ON, false);
+                        updateVirtualDisplay();
+                    } else if (DEBUG_ACTION_SET_SURFACE.equals(action)) {
+                        if (mVirtualDisplay != null) {
+                            final Surface newSurface =
+                                    intent.getParcelableExtra(DEBUG_EXTRA_SURFACE);
+
+                            Log.i(TAG, "Setting the new surface from " + mSurface + " to " + newSurface);
+                            if (newSurface != mSurface) {
+                                mVirtualDisplay.setSurface(newSurface);
+                                if (mSurface != null) {
+                                    mSurface.release();
+                                }
+                                mSurface = newSurface;
+                            }
+                        } else {
+                            Log.w(TAG, "Cannot set the surface because the VD is null.");
+                        }
+                    }
+                }
+            }, intentFilter);
+        }
     }
 
     private void startVrModeListener() {
@@ -80,7 +140,7 @@
 
     private void startVirtualDisplay() {
         if (DEBUG) {
-            Log.d(TAG, "Starting VD, DM:" + mDisplayManager);
+            Log.d(TAG, "Request to start VD, DM:" + mDisplayManager);
         }
 
         if (mDisplayManager == null) {
@@ -90,13 +150,16 @@
 
         synchronized (vdLock) {
             if (mVirtualDisplay != null) {
-                Log.e(TAG, "Starting the virtual display when one already exists", new Exception());
+                Log.i(TAG, "VD already exists, ignoring request");
                 return;
             }
 
             mVirtualDisplay = mDisplayManager.createVirtualDisplay("VR 2D Display", WIDTH, HEIGHT,
-                    DPI,
-                    null /* Surface */, 0 /* flags */);
+                    DPI, null /* Surface */, 0 /* flags */);
+            if (mSurface != null && mSurface.isValid()) {
+              // TODO: Need to protect all setSurface calls with a lock.
+              mVirtualDisplay.setSurface(mSurface);
+            }
         }
 
         if (DEBUG) {
diff --git a/services/core/java/com/android/server/vr/VrManagerService.java b/services/core/java/com/android/server/vr/VrManagerService.java
index 3df4d24..8a23173 100644
--- a/services/core/java/com/android/server/vr/VrManagerService.java
+++ b/services/core/java/com/android/server/vr/VrManagerService.java
@@ -26,6 +26,7 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.hardware.display.DisplayManager;
 import android.os.Binder;
 import android.os.Handler;
 import android.os.IBinder;
@@ -131,6 +132,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 static final int MSG_VR_STATE_CHANGE = 0;
     private static final int MSG_PENDING_VR_STATE_CHANGE = 1;
@@ -537,6 +539,11 @@
             } else {
                 Slog.i(TAG, "No default vr listener service found.");
             }
+
+            DisplayManager dm =
+                    (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
+            mCompatibilityDisplay = new CompatibilityDisplay(dm, mVrManager);
+            mCompatibilityDisplay.init(getContext());
         } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
             synchronized (mLock) {
                 mVrModeAllowed = true;
@@ -680,10 +687,10 @@
                 }
             }
 
+            mCurrentVrModeComponent = calling;
             if (calling != null && !Objects.equals(calling, mCurrentVrModeComponent)) {
                 sendUpdatedCaller = true;
             }
-            mCurrentVrModeComponent = calling;
 
             if (mCurrentVrModeUser != userId) {
                 mCurrentVrModeUser = userId;
diff --git a/services/core/java/com/android/server/wm/TaskPositioner.java b/services/core/java/com/android/server/wm/TaskPositioner.java
index 90106a9..53c24e1 100644
--- a/services/core/java/com/android/server/wm/TaskPositioner.java
+++ b/services/core/java/com/android/server/wm/TaskPositioner.java
@@ -215,7 +215,7 @@
                                     : DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
                             mService.mActivityManager.moveTaskToDockedStack(
                                     mTask.mTaskId, createMode, true /*toTop*/, true /* animate */,
-                                    null /* initialBounds */, false /* moveHomeStackFront */);
+                                    null /* initialBounds */);
                         }
                     } catch(RemoteException e) {}