Merge "Add LinkProperties common test cases" into qt-dev
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
index e3eb2a3..c2fa8b2b 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
@@ -40,6 +40,7 @@
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -411,6 +412,7 @@
         assertThat(textLanguage, isTextLanguage("ja"));
     }
 
+    @Ignore  // Doesn't work without a language-based model.
     @Test
     public void testSuggestConversationActions_textReplyOnly_maxOne() {
         if (isTextClassifierDisabled()) return;
@@ -438,6 +440,7 @@
         Truth.assertThat(conversationAction.getTextReply()).isNotNull();
     }
 
+    @Ignore  // Doesn't work without a language-based model.
     @Test
     public void testSuggestConversationActions_textReplyOnly_noMax() {
         if (isTextClassifierDisabled()) return;
@@ -493,6 +496,7 @@
         Truth.assertThat(actionIntent.getData()).isEqualTo(Uri.parse("https://www.android.com"));
     }
 
+    @Ignore  // Doesn't work without a language-based model.
     @Test
     public void testSuggestConversationActions_copy() {
         if (isTextClassifierDisabled()) return;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 98f36e4..ec6cfe9 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -1785,31 +1785,37 @@
         public void run() {
             Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
             if (DEBUG) Log.d(TAG, "keyguardGoingAway");
-            try {
-                mStatusBarKeyguardViewManager.keyguardGoingAway();
+            mStatusBarKeyguardViewManager.keyguardGoingAway();
 
-                int flags = 0;
-                if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
-                        || (mWakeAndUnlocking && !mPulsing)) {
-                    flags |= WindowManagerPolicyConstants
-                            .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
-                }
-                if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
-                        || (mWakeAndUnlocking && mPulsing)) {
-                    flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
-                }
-                if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
-                    flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
-                }
-
-                mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
-                // Don't actually hide the Keyguard at the moment, wait for window
-                // manager until it tells us it's safe to do so with
-                // startKeyguardExitAnimation.
-                ActivityTaskManager.getService().keyguardGoingAway(flags);
-            } catch (RemoteException e) {
-                Log.e(TAG, "Error while calling WindowManager", e);
+            int flags = 0;
+            if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
+                    || (mWakeAndUnlocking && !mPulsing)) {
+                flags |= WindowManagerPolicyConstants
+                        .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
             }
+            if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
+                    || (mWakeAndUnlocking && mPulsing)) {
+                flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
+            }
+            if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
+                flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
+            }
+
+            mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
+
+            // Don't actually hide the Keyguard at the moment, wait for window
+            // manager until it tells us it's safe to do so with
+            // startKeyguardExitAnimation.
+            // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in
+            // order.
+            final int keyguardFlag = flags;
+            mUiOffloadThread.submit(() -> {
+                try {
+                    ActivityTaskManager.getService().keyguardGoingAway(keyguardFlag);
+                } catch (RemoteException e) {
+                    Log.e(TAG, "Error while calling WindowManager", e);
+                }
+            });
             Trace.endSection();
         }
     };
diff --git a/services/core/java/com/android/server/wm/KeyguardController.java b/services/core/java/com/android/server/wm/KeyguardController.java
index df36b09..169f03b 100644
--- a/services/core/java/com/android/server/wm/KeyguardController.java
+++ b/services/core/java/com/android/server/wm/KeyguardController.java
@@ -133,27 +133,33 @@
      * Update the Keyguard showing state.
      */
     void setKeyguardShown(boolean keyguardShowing, boolean aodShowing) {
-        boolean showingChanged = keyguardShowing != mKeyguardShowing || aodShowing != mAodShowing;
         // If keyguard is going away, but SystemUI aborted the transition, need to reset state.
-        showingChanged |= mKeyguardGoingAway && keyguardShowing;
-        if (!showingChanged) {
+        final boolean keyguardChanged = keyguardShowing != mKeyguardShowing
+                || mKeyguardGoingAway && keyguardShowing;
+        final boolean aodChanged = aodShowing != mAodShowing;
+        if (!keyguardChanged && !aodChanged) {
             return;
         }
         mKeyguardShowing = keyguardShowing;
         mAodShowing = aodShowing;
         mWindowManager.setAodShowing(aodShowing);
-        if (showingChanged) {
+
+        if (keyguardChanged) {
+            // Irrelevant to AOD.
             dismissDockedStackIfNeeded();
             setKeyguardGoingAway(false);
-            // TODO(b/113840485): Check usage for non-default display
-            mWindowManager.setKeyguardOrAodShowingOnDefaultDisplay(
-                    isKeyguardOrAodShowing(DEFAULT_DISPLAY));
             if (keyguardShowing) {
                 mDismissalRequested = false;
             }
         }
-        mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
+        // TODO(b/113840485): Check usage for non-default display
+        mWindowManager.setKeyguardOrAodShowingOnDefaultDisplay(
+                isKeyguardOrAodShowing(DEFAULT_DISPLAY));
+
+        // Update the sleep token first such that ensureActivitiesVisible has correct sleep token
+        // state when evaluating visibilities.
         updateKeyguardSleepToken();
+        mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
     }
 
     /**