summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Shell/AndroidManifest.xml1
-rw-r--r--libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_confirm_button_background.xml (renamed from libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_dismiss_button_background.xml)0
-rw-r--r--libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml4
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt29
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt32
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt10
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt78
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java19
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt171
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt23
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt4
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt79
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt55
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl2
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java3
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java2
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java32
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java14
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java51
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java49
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java2
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java2
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java44
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/AppHeaderViewHolder.kt37
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt285
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt9
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt294
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt75
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java1
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java2
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorationTests.kt9
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt44
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java103
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt6
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt6
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java81
-rw-r--r--libs/appfunctions/api/current.txt3
-rw-r--r--libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java50
-rw-r--r--libs/appfunctions/java/com/google/android/appfunctions/sidecar/ExecuteAppFunctionResponse.java13
39 files changed, 1348 insertions, 376 deletions
diff --git a/libs/WindowManager/Shell/AndroidManifest.xml b/libs/WindowManager/Shell/AndroidManifest.xml
index 3b739c3d5817..1260796810c2 100644
--- a/libs/WindowManager/Shell/AndroidManifest.xml
+++ b/libs/WindowManager/Shell/AndroidManifest.xml
@@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.WAKEUP_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE" />
+ <uses-permission android:name="android.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION" />
<application>
<activity
diff --git a/libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_dismiss_button_background.xml b/libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_confirm_button_background.xml
index 2b2e9df07dce..2b2e9df07dce 100644
--- a/libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_dismiss_button_background.xml
+++ b/libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_confirm_button_background.xml
diff --git a/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml b/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml
index 8ff382bbc7b4..b5bceda9a623 100644
--- a/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml
+++ b/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml
@@ -111,7 +111,7 @@
</RadioGroup>
<Button
- android:id="@+id/open_by_default_settings_dialog_dismiss_button"
+ android:id="@+id/open_by_default_settings_dialog_confirm_button"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:text="@string/open_by_default_dialog_dismiss_button_text"
@@ -122,7 +122,7 @@
android:textSize="14sp"
android:textFontWeight="500"
android:textColor="?androidprv:attr/materialColorOnPrimary"
- android:background="@drawable/open_by_default_settings_dialog_dismiss_button_background"/>
+ android:background="@drawable/open_by_default_settings_dialog_confirm_button_background"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt
index 71bcb590ae23..65132fe89063 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt
@@ -22,7 +22,13 @@ import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.pm.PackageManager
+import android.content.pm.verify.domain.DomainVerificationManager
+import android.content.pm.verify.domain.DomainVerificationUserState
import android.net.Uri
+import com.android.internal.protolog.ProtoLog
+import com.android.wm.shell.protolog.ShellProtoLogGroup
+
+private const val TAG = "AppToWebUtils"
private val GenericBrowserIntent = Intent()
.setAction(Intent.ACTION_VIEW)
@@ -58,4 +64,25 @@ fun getBrowserIntent(uri: Uri, packageManager: PackageManager): Intent? {
val component = intent.resolveActivity(packageManager) ?: return null
intent.setComponent(component)
return intent
-} \ No newline at end of file
+}
+
+/**
+ * Returns the [DomainVerificationUserState] of the user associated with the given
+ * [DomainVerificationManager] and the given package.
+ */
+fun getDomainVerificationUserState(
+ manager: DomainVerificationManager,
+ packageName: String
+): DomainVerificationUserState? {
+ try {
+ return manager.getDomainVerificationUserState(packageName)
+ } catch (e: PackageManager.NameNotFoundException) {
+ ProtoLog.w(
+ ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
+ "%s: Failed to get domain verification user state: %s",
+ TAG,
+ e.message!!
+ )
+ return null
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt
index 4926cbdbe9fb..a727b54b3a3f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt
@@ -19,6 +19,7 @@ package com.android.wm.shell.apptoweb
import android.app.ActivityManager.RunningTaskInfo
import android.app.TaskInfo
import android.content.Context
+import android.content.pm.verify.domain.DomainVerificationManager
import android.graphics.Bitmap
import android.graphics.PixelFormat
import android.view.LayoutInflater
@@ -30,6 +31,7 @@ import android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL
import android.view.WindowlessWindowManager
import android.widget.ImageView
+import android.widget.RadioButton
import android.widget.TextView
import android.window.TaskConstants
import com.android.wm.shell.R
@@ -58,8 +60,17 @@ internal class OpenByDefaultDialog(
private lateinit var appIconView: ImageView
private lateinit var appNameView: TextView
+ private lateinit var openInAppButton: RadioButton
+ private lateinit var openInBrowserButton: RadioButton
+
+ private val domainVerificationManager =
+ context.getSystemService(DomainVerificationManager::class.java)!!
+ private val packageName = taskInfo.baseActivity?.packageName!!
+
+
init {
createDialog()
+ initializeRadioButtons()
bindAppInfo(appIconBitmap, appName)
}
@@ -111,9 +122,30 @@ internal class OpenByDefaultDialog(
closeMenu()
}
+ dialog.setConfirmButtonClickListener {
+ setDefaultLinkHandlingSetting()
+ closeMenu()
+ }
+
listener.onDialogCreated()
}
+ private fun initializeRadioButtons() {
+ openInAppButton = dialog.requireViewById(R.id.open_in_app_button)
+ openInBrowserButton = dialog.requireViewById(R.id.open_in_browser_button)
+
+ val userState =
+ getDomainVerificationUserState(domainVerificationManager, packageName) ?: return
+ val openInApp = userState.isLinkHandlingAllowed
+ openInAppButton.isChecked = openInApp
+ openInBrowserButton.isChecked = !openInApp
+ }
+
+ private fun setDefaultLinkHandlingSetting() {
+ domainVerificationManager.setDomainVerificationLinkHandlingAllowed(
+ packageName, openInAppButton.isChecked)
+ }
+
private fun closeMenu() {
dialogContainer?.releaseView()
dialogContainer = null
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt
index d03a38e8699a..1b914f419d94 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt
@@ -36,9 +36,6 @@ class OpenByDefaultDialogView @JvmOverloads constructor(
private lateinit var backgroundDim: Drawable
fun setDismissOnClickListener(callback: (View) -> Unit) {
- val dismissButton = dialogContainer.requireViewById<Button>(
- R.id.open_by_default_settings_dialog_dismiss_button)
- dismissButton.setOnClickListener(callback)
// Clicks on the background dim should also dismiss the dialog.
setOnClickListener(callback)
// We add a no-op on-click listener to the dialog container so that clicks on it won't
@@ -46,6 +43,13 @@ class OpenByDefaultDialogView @JvmOverloads constructor(
dialogContainer.setOnClickListener { }
}
+ fun setConfirmButtonClickListener(callback: (View) -> Unit) {
+ val dismissButton = dialogContainer.requireViewById<Button>(
+ R.id.open_by_default_settings_dialog_confirm_button
+ )
+ dismissButton.setOnClickListener(callback)
+ }
+
override fun onFinishInflate() {
super.onFinishInflate()
dialogContainer = requireViewById(R.id.open_by_default_dialog_container)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
index b3491baa629d..b83b5f341dda 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
@@ -177,26 +177,84 @@ object PipUtils {
}
/**
+ * Calculates the transform to apply on a UNTRANSFORMED (config-at-end) Activity surface in
+ * order for it's hint-rect to occupy the same task-relative position/dimensions as it would
+ * have at the end of the transition (post-configuration).
+ *
+ * This is intended to be used in tandem with [calcStartTransform] below applied to the parent
+ * task. Applying both transforms simultaneously should result in the appearance of nothing
+ * having happened yet.
+ *
+ * Only the task should be animated (into it's identity state) and then WMCore will reset the
+ * activity transform in sync with its new configuration upon finish.
+ *
+ * Usage example:
+ * calcEndTransform(pipActivity, pipTask, scale, pos);
+ * t.setScale(pipActivity.getLeash(), scale.x, scale.y);
+ * t.setPosition(pipActivity.getLeash(), pos.x, pos.y);
+ *
+ * @see calcStartTransform
+ */
+ @JvmStatic
+ fun calcEndTransform(pipActivity: TransitionInfo.Change, pipTask: TransitionInfo.Change,
+ outScale: PointF, outPos: PointF) {
+ val actStartBounds = pipActivity.startAbsBounds
+ val actEndBounds = pipActivity.endAbsBounds
+ val taskEndBounds = pipTask.endAbsBounds
+
+ var hintRect = pipTask.taskInfo?.pictureInPictureParams?.sourceRectHint
+ if (hintRect == null) {
+ hintRect = Rect(actStartBounds)
+ hintRect.offsetTo(0, 0)
+ }
+
+ // FA = final activity bounds (absolute)
+ // FT = final task bounds (absolute)
+ // SA = start activity bounds (absolute)
+ // H = source hint (relative to start activity bounds)
+ // We want to transform the activity so that when the task is at FT, H overlaps with FA
+
+ // This scales the activity such that the hint rect has the same dimensions
+ // as the final activity bounds.
+ val hintToEndScaleX = (actEndBounds.width().toFloat()) / (hintRect.width().toFloat())
+ val hintToEndScaleY = (actEndBounds.height().toFloat()) / (hintRect.height().toFloat())
+ // top-left needs to be (FA.tl - FT.tl) - H.tl * hintToEnd . H is relative to the
+ // activity; so, for example, if shrinking H to FA (hintToEnd < 1), then the tl of the
+ // shrunk SA is closer to H than expected, so we need to reduce how much we offset SA
+ // to get H.tl to match.
+ val startActPosInTaskEndX =
+ (actEndBounds.left - taskEndBounds.left) - hintRect.left * hintToEndScaleX
+ val startActPosInTaskEndY =
+ (actEndBounds.top - taskEndBounds.top) - hintRect.top * hintToEndScaleY
+ outScale.set(hintToEndScaleX, hintToEndScaleY)
+ outPos.set(startActPosInTaskEndX, startActPosInTaskEndY)
+ }
+
+ /**
* Calculates the transform and crop to apply on a Task surface in order for the config-at-end
* activity inside it (original-size activity transformed to match it's hint rect to the final
* Task bounds) to occupy the same world-space position/dimensions as it had before the
* transition.
*
+ * Intended to be used in tandem with [calcEndTransform].
+ *
* Usage example:
- * calcStartTransform(pipChange, scale, pos, crop);
- * t.setScale(pipChange.getLeash(), scale.x, scale.y);
- * t.setPosition(pipChange.getLeash(), pos.x, pos.y);
- * t.setCrop(pipChange.getLeash(), crop);
+ * calcStartTransform(pipTask, scale, pos, crop);
+ * t.setScale(pipTask.getLeash(), scale.x, scale.y);
+ * t.setPosition(pipTask.getLeash(), pos.x, pos.y);
+ * t.setCrop(pipTask.getLeash(), crop);
+ *
+ * @see calcEndTransform
*/
@JvmStatic
- fun calcStartTransform(pipChange: TransitionInfo.Change, outScale: PointF,
+ fun calcStartTransform(pipTask: TransitionInfo.Change, outScale: PointF,
outPos: PointF, outCrop: Rect) {
- val startBounds = pipChange.startAbsBounds
- val taskEndBounds = pipChange.endAbsBounds
+ val startBounds = pipTask.startAbsBounds
+ val taskEndBounds = pipTask.endAbsBounds
// For now, pip activity bounds always matches task bounds. If this ever changes, we'll
// need to get the activity offset.
val endBounds = taskEndBounds
- var hintRect = pipChange.taskInfo?.pictureInPictureParams?.sourceRectHint
+ var hintRect = pipTask.taskInfo?.pictureInPictureParams?.sourceRectHint
if (hintRect == null) {
hintRect = Rect(startBounds)
hintRect.offsetTo(0, 0)
@@ -226,8 +284,8 @@ object PipUtils {
+ startBounds.left + hintRect.left)
val endTaskPosForStartY = (-(endBounds.top - taskEndBounds.top) * endToHintScaleY
+ startBounds.top + hintRect.top)
- outScale[endToHintScaleX] = endToHintScaleY
- outPos[endTaskPosForStartX] = endTaskPosForStartY
+ outScale.set(endToHintScaleX, endToHintScaleY)
+ outPos.set(endTaskPosForStartX, endTaskPosForStartY)
// now need to set crop to reveal the non-hint stuff. Again, hintrect is relative, so
// we must apply outsets to reveal the *activity* content which is *inside* the task
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
index 75adef4d4327..52262e68c401 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
@@ -264,7 +264,8 @@ public abstract class WMShellModule {
Optional<DesktopTasksLimiter> desktopTasksLimiter,
AppHandleEducationController appHandleEducationController,
WindowDecorCaptionHandleRepository windowDecorCaptionHandleRepository,
- Optional<DesktopActivityOrientationChangeHandler> desktopActivityOrientationHandler) {
+ Optional<DesktopActivityOrientationChangeHandler> desktopActivityOrientationHandler,
+ FocusTransitionObserver focusTransitionObserver) {
if (DesktopModeStatus.canEnterDesktopMode(context)) {
return new DesktopModeWindowDecorViewModel(
context,
@@ -291,7 +292,8 @@ public abstract class WMShellModule {
desktopTasksLimiter,
appHandleEducationController,
windowDecorCaptionHandleRepository,
- desktopActivityOrientationHandler);
+ desktopActivityOrientationHandler,
+ focusTransitionObserver);
}
return new CaptionWindowDecorViewModel(
context,
@@ -305,7 +307,8 @@ public abstract class WMShellModule {
displayController,
rootTaskDisplayAreaOrganizer,
syncQueue,
- transitions);
+ transitions,
+ focusTransitionObserver);
}
@WMSingleton
@@ -695,10 +698,16 @@ public abstract class WMShellModule {
static Optional<DesktopFullImmersiveTransitionHandler> provideDesktopImmersiveHandler(
Context context,
Transitions transitions,
- @DynamicOverride DesktopRepository desktopRepository) {
+ @DynamicOverride DesktopRepository desktopRepository,
+ DisplayController displayController,
+ ShellTaskOrganizer shellTaskOrganizer) {
if (DesktopModeStatus.canEnterDesktopMode(context)) {
return Optional.of(
- new DesktopFullImmersiveTransitionHandler(transitions, desktopRepository));
+ new DesktopFullImmersiveTransitionHandler(
+ transitions,
+ desktopRepository,
+ displayController,
+ shellTaskOrganizer));
}
return Optional.empty();
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt
index f749aa1edd92..679179a7ff68 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt
@@ -27,8 +27,12 @@ import android.window.TransitionInfo
import android.window.TransitionRequestInfo
import android.window.WindowContainerTransaction
import androidx.core.animation.addListener
+import com.android.internal.annotations.VisibleForTesting
import com.android.internal.protolog.ProtoLog
-import com.android.wm.shell.protolog.ShellProtoLogGroup
+import com.android.window.flags.Flags
+import com.android.wm.shell.ShellTaskOrganizer
+import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions.TransitionHandler
import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener
@@ -41,16 +45,29 @@ import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener
class DesktopFullImmersiveTransitionHandler(
private val transitions: Transitions,
private val desktopRepository: DesktopRepository,
+ private val displayController: DisplayController,
+ private val shellTaskOrganizer: ShellTaskOrganizer,
private val transactionSupplier: () -> SurfaceControl.Transaction,
) : TransitionHandler {
constructor(
transitions: Transitions,
desktopRepository: DesktopRepository,
- ) : this(transitions, desktopRepository, { SurfaceControl.Transaction() })
+ displayController: DisplayController,
+ shellTaskOrganizer: ShellTaskOrganizer,
+ ) : this(
+ transitions,
+ desktopRepository,
+ displayController,
+ shellTaskOrganizer,
+ { SurfaceControl.Transaction() }
+ )
private var state: TransitionState? = null
+ @VisibleForTesting
+ val pendingExternalExitTransitions = mutableSetOf<ExternalPendingExit>()
+
/** Whether there is an immersive transition that hasn't completed yet. */
private val inProgress: Boolean
get() = state != null
@@ -61,15 +78,15 @@ class DesktopFullImmersiveTransitionHandler(
var onTaskResizeAnimationListener: OnTaskResizeAnimationListener? = null
/** Starts a transition to enter full immersive state inside the desktop. */
- fun enterImmersive(taskInfo: RunningTaskInfo, wct: WindowContainerTransaction) {
+ fun moveTaskToImmersive(taskInfo: RunningTaskInfo) {
if (inProgress) {
- ProtoLog.v(
- ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
- "FullImmersive: cannot start entry because transition already in progress."
- )
+ logV("Cannot start entry because transition already in progress.")
return
}
-
+ val wct = WindowContainerTransaction().apply {
+ setBounds(taskInfo.token, Rect())
+ }
+ logV("Moving task ${taskInfo.taskId} into immersive mode")
val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ this)
state = TransitionState(
transition = transition,
@@ -79,15 +96,18 @@ class DesktopFullImmersiveTransitionHandler(
)
}
- fun exitImmersive(taskInfo: RunningTaskInfo, wct: WindowContainerTransaction) {
+ fun moveTaskToNonImmersive(taskInfo: RunningTaskInfo) {
if (inProgress) {
- ProtoLog.v(
- ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
- "$TAG: cannot start exit because transition already in progress."
- )
+ logV("Cannot start exit because transition already in progress.")
return
}
+ val displayLayout = displayController.getDisplayLayout(taskInfo.displayId) ?: return
+ val destinationBounds = calculateMaximizeBounds(displayLayout, taskInfo)
+ val wct = WindowContainerTransaction().apply {
+ setBounds(taskInfo.token, destinationBounds)
+ }
+ logV("Moving task ${taskInfo.taskId} out of immersive mode")
val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ this)
state = TransitionState(
transition = transition,
@@ -97,6 +117,82 @@ class DesktopFullImmersiveTransitionHandler(
)
}
+ /**
+ * Bring the immersive app of the given [displayId] out of immersive mode, if applicable.
+ *
+ * @param transition that will apply this transaction
+ * @param wct that will apply these changes
+ * @param displayId of the display that should exit immersive mode
+ */
+ fun exitImmersiveIfApplicable(
+ transition: IBinder,
+ wct: WindowContainerTransaction,
+ displayId: Int
+ ) {
+ if (!Flags.enableFullyImmersiveInDesktop()) return
+ exitImmersiveIfApplicable(wct, displayId)?.invoke(transition)
+ }
+
+ /**
+ * Bring the immersive app of the given [displayId] out of immersive mode, if applicable.
+ *
+ * @param wct that will apply these changes
+ * @param displayId of the display that should exit immersive mode
+ * @return a function to apply once the transition that will apply these changes is started
+ */
+ fun exitImmersiveIfApplicable(
+ wct: WindowContainerTransaction,
+ displayId: Int
+ ): ((IBinder) -> Unit)? {
+ if (!Flags.enableFullyImmersiveInDesktop()) return null
+ val displayLayout = displayController.getDisplayLayout(displayId) ?: return null
+ val immersiveTask = desktopRepository.getTaskInFullImmersiveState(displayId) ?: return null
+ val taskInfo = shellTaskOrganizer.getRunningTaskInfo(immersiveTask) ?: return null
+ logV("Appending immersive exit for task: $immersiveTask in display: $displayId")
+ wct.setBounds(taskInfo.token, calculateMaximizeBounds(displayLayout, taskInfo))
+ return { transition -> addPendingImmersiveExit(immersiveTask, displayId, transition) }
+ }
+
+ /**
+ * Bring the given [taskInfo] out of immersive mode, if applicable.
+ *
+ * @param wct that will apply these changes
+ * @param taskInfo of the task that should exit immersive mode
+ * @return a function to apply once the transition that will apply these changes is started
+ */
+ fun exitImmersiveIfApplicable(
+ wct: WindowContainerTransaction,
+ taskInfo: RunningTaskInfo
+ ): ((IBinder) -> Unit)? {
+ if (!Flags.enableFullyImmersiveInDesktop()) return null
+ if (desktopRepository.isTaskInFullImmersiveState(taskInfo.taskId)) {
+ // A full immersive task is being minimized, make sure the immersive state is broken
+ // (i.e. resize back to max bounds).
+ displayController.getDisplayLayout(taskInfo.displayId)?.let { displayLayout ->
+ wct.setBounds(taskInfo.token, calculateMaximizeBounds(displayLayout, taskInfo))
+ logV("Appending immersive exit for task: ${taskInfo.taskId}")
+ return { transition ->
+ addPendingImmersiveExit(
+ taskId = taskInfo.taskId,
+ displayId = taskInfo.displayId,
+ transition = transition
+ )
+ }
+ }
+ }
+ return null
+ }
+
+ private fun addPendingImmersiveExit(taskId: Int, displayId: Int, transition: IBinder) {
+ pendingExternalExitTransitions.add(
+ ExternalPendingExit(
+ taskId = taskId,
+ displayId = displayId,
+ transition = transition
+ )
+ )
+ }
+
override fun startAnimation(
transition: IBinder,
info: TransitionInfo,
@@ -190,15 +286,31 @@ class DesktopFullImmersiveTransitionHandler(
* Called when any transition in the system is ready to play. This is needed to update the
* repository state before window decorations are drawn (which happens immediately after
* |onTransitionReady|, before this transition actually animates) because drawing decorations
- * depends in whether the task is in full immersive state or not.
+ * depends on whether the task is in full immersive state or not.
*/
- fun onTransitionReady(transition: IBinder) {
+ fun onTransitionReady(transition: IBinder, info: TransitionInfo) {
+ // Check if this is a pending external exit transition.
+ val pendingExit = pendingExternalExitTransitions
+ .firstOrNull { pendingExit -> pendingExit.transition == transition }
+ if (pendingExit != null) {
+ pendingExternalExitTransitions.remove(pendingExit)
+ if (info.hasTaskChange(taskId = pendingExit.taskId)) {
+ if (desktopRepository.isTaskInFullImmersiveState(pendingExit.taskId)) {
+ logV("Pending external exit for task ${pendingExit.taskId} verified")
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = pendingExit.displayId,
+ taskId = pendingExit.taskId,
+ immersive = false
+ )
+ }
+ }
+ return
+ }
+
+ // Check if this is a direct immersive enter/exit transition.
val state = this.state ?: return
- // TODO: b/369443668 - this assumes invoking the exit transition is the only way to exit
- // immersive, which isn't realistic. The app could crash, the user could dismiss it from
- // overview, etc. This (or its caller) should search all transitions to look for any
- // immersive task exiting that state to keep the repository properly updated.
if (transition == state.transition) {
+ logV("Direct move for task ${state.taskId} in ${state.direction} direction verified")
when (state.direction) {
Direction.ENTER -> {
desktopRepository.setTaskInFullImmersiveState(
@@ -225,6 +337,9 @@ class DesktopFullImmersiveTransitionHandler(
private fun requireState(): TransitionState =
state ?: error("Expected non-null transition state")
+ private fun TransitionInfo.hasTaskChange(taskId: Int): Boolean =
+ changes.any { c -> c.taskInfo?.taskId == taskId }
+
/** The state of the currently running transition. */
private data class TransitionState(
val transition: IBinder,
@@ -233,12 +348,28 @@ class DesktopFullImmersiveTransitionHandler(
val direction: Direction
)
+ /**
+ * Tracks state of a transition involving an immersive exit that is external to this class' own
+ * transitions. This usually means transitions that exit immersive mode as a side-effect and
+ * not the primary action (for example, minimizing the immersive task or launching a new task
+ * on top of the immersive task).
+ */
+ data class ExternalPendingExit(
+ val taskId: Int,
+ val displayId: Int,
+ val transition: IBinder,
+ )
+
private enum class Direction {
ENTER, EXIT
}
+ private fun logV(msg: String, vararg arguments: Any?) {
+ ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
+ }
+
private companion object {
- private const val TAG = "FullImmersiveHandler"
+ private const val TAG = "DesktopImmersive"
private const val FULL_IMMERSIVE_ANIM_DURATION_MS = 336L
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
index bd6172226cf2..6d4792250be2 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
@@ -123,6 +123,29 @@ fun calculateInitialBounds(
}
/**
+ * Calculates the maximized bounds of a task given in the given [DisplayLayout], taking
+ * resizability into consideration.
+ */
+fun calculateMaximizeBounds(
+ displayLayout: DisplayLayout,
+ taskInfo: RunningTaskInfo,
+): Rect {
+ val stableBounds = Rect()
+ displayLayout.getStableBounds(stableBounds)
+ if (taskInfo.isResizeable) {
+ // if resizable then expand to entire stable bounds (full display minus insets)
+ return Rect(stableBounds)
+ } else {
+ // if non-resizable then calculate max bounds according to aspect ratio
+ val activityAspectRatio = calculateAspectRatio(taskInfo)
+ val newSize = maximizeSizeGivenAspectRatio(taskInfo,
+ Size(stableBounds.width(), stableBounds.height()), activityAspectRatio)
+ return centerInArea(
+ newSize, stableBounds, stableBounds.left, stableBounds.top)
+ }
+}
+
+/**
* Calculates the largest size that can fit in a given area while maintaining a specific aspect
* ratio.
*/
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
index c175133dd37b..5ac4ef5cf049 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
@@ -328,6 +328,10 @@ class DesktopRepository (
return desktopTaskDataSequence().any { taskId == it.fullImmersiveTaskId }
}
+ /** Returns the task that is currently in immersive mode in this display, or null. */
+ fun getTaskInFullImmersiveState(displayId: Int): Int? =
+ desktopTaskDataByDisplayId.getOrCreate(displayId).fullImmersiveTaskId
+
private fun notifyVisibleTaskListeners(displayId: Int, visibleTasksCount: Int) {
visibleTasksListeners.forEach { (listener, executor) ->
executor.execute { listener.onTasksVisibilityChanged(displayId, visibleTasksCount) }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index 75c795b70378..92535f37094a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -91,6 +91,7 @@ import com.android.wm.shell.shared.ShellSharedConstants
import com.android.wm.shell.shared.TransitionUtil
import com.android.wm.shell.shared.annotations.ExternalThread
import com.android.wm.shell.shared.annotations.ShellMainThread
+import com.android.wm.shell.freeform.FreeformTaskTransitionStarter
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.DESKTOP_DENSITY_OVERRIDE
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.useDesktopOverrideDensity
@@ -190,6 +191,7 @@ class DesktopTasksController(
private var recentsAnimationRunning = false
private lateinit var splitScreenController: SplitScreenController
+ lateinit var freeformTaskTransitionStarter: FreeformTaskTransitionStarter
// Launch cookie used to identify a drag and drop transition to fullscreen after it has begun.
// Used to prevent handleRequest from moving the new fullscreen task to freeform.
private var dragAndDropFullscreenCookie: Binder? = null
@@ -354,6 +356,8 @@ class DesktopTasksController(
// TODO(342378842): Instead of using default display, support multiple displays
val taskToMinimize = bringDesktopAppsToFrontBeforeShowingNewTask(
DEFAULT_DISPLAY, wct, taskId)
+ val runOnTransit = immersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, DEFAULT_DISPLAY)
wct.startTask(
taskId,
ActivityOptions.makeBasic().apply {
@@ -363,6 +367,7 @@ class DesktopTasksController(
// TODO(343149901): Add DPI changes for task launch
val transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
return true
}
@@ -379,6 +384,7 @@ class DesktopTasksController(
}
logV("moveRunningTaskToDesktop taskId=%d", task.taskId)
exitSplitIfApplicable(wct, task)
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(wct, task.displayId)
// Bring other apps to front first
val taskToMinimize =
bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
@@ -386,6 +392,7 @@ class DesktopTasksController(
val transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
}
/**
@@ -422,8 +429,13 @@ class DesktopTasksController(
val taskToMinimize =
bringDesktopAppsToFrontBeforeShowingNewTask(taskInfo.displayId, wct, taskInfo.taskId)
addMoveToDesktopChanges(wct, taskInfo)
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(
+ wct, taskInfo.displayId)
val transition = dragToDesktopTransitionHandler.finishDragToDesktopTransition(wct)
- transition?.let { addPendingMinimizeTransition(it, taskToMinimize) }
+ transition?.let {
+ addPendingMinimizeTransition(it, taskToMinimize)
+ runOnTransit?.invoke(transition)
+ }
}
/**
@@ -453,20 +465,36 @@ class DesktopTasksController(
removeWallpaperActivity(wct)
}
taskRepository.addClosingTask(displayId, taskId)
+ taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
+ doesAnyTaskRequireTaskbarRounding(
+ displayId,
+ taskId
+ )
+ )
}
- /**
- * Perform clean up of the desktop wallpaper activity if the minimized window task is the last
- * active task.
- *
- * @param wct transaction to modify if the last active task is minimized
- * @param taskId task id of the window that's being minimized
- */
- fun onDesktopWindowMinimize(wct: WindowContainerTransaction, taskId: Int) {
+ fun minimizeTask(taskInfo: RunningTaskInfo) {
+ val taskId = taskInfo.taskId
+ val displayId = taskInfo.displayId
+ val wct = WindowContainerTransaction()
if (taskRepository.isOnlyVisibleNonClosingTask(taskId)) {
+ // Perform clean up of the desktop wallpaper activity if the minimized window task is
+ // the last active task.
removeWallpaperActivity(wct)
}
- // Do not call taskRepository.minimizeTask because it will be called by DekstopTasksLimiter.
+ // Notify immersive handler as it might need to exit immersive state.
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(wct, taskInfo)
+
+ wct.reorder(taskInfo.token, false)
+ val transition = freeformTaskTransitionStarter.startMinimizedModeTransition(wct)
+ desktopTasksLimiter.ifPresent {
+ it.addPendingMinimizeChange(
+ transition = transition,
+ displayId = displayId,
+ taskId = taskId
+ )
+ }
+ runOnTransit?.invoke(transition)
}
/** Move a task with given `taskId` to fullscreen */
@@ -552,6 +580,8 @@ class DesktopTasksController(
// TODO: b/342378842 - Instead of using default display, support multiple displays
val taskToMinimize: RunningTaskInfo? =
addAndGetMinimizeChangesIfNeeded(DEFAULT_DISPLAY, wct, taskId)
+ val runOnTransit = immersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, DEFAULT_DISPLAY)
wct.startTask(
taskId,
ActivityOptions.makeBasic().apply {
@@ -560,6 +590,7 @@ class DesktopTasksController(
)
val transition = transitions.startTransition(TRANSIT_OPEN, wct, null /* handler */)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
}
/** Move a task to the front */
@@ -567,11 +598,14 @@ class DesktopTasksController(
logV("moveTaskToFront taskId=%s", taskInfo.taskId)
val wct = WindowContainerTransaction()
wct.reorder(taskInfo.token, true /* onTop */, true /* includingParents */)
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(
+ wct, taskInfo.displayId)
val taskToMinimize =
addAndGetMinimizeChangesIfNeeded(taskInfo.displayId, wct, taskInfo.taskId)
val transition = transitions.startTransition(TRANSIT_TO_FRONT, wct, null /* handler */)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
}
/**
@@ -643,22 +677,12 @@ class DesktopTasksController(
private fun moveDesktopTaskToFullImmersive(taskInfo: RunningTaskInfo) {
check(taskInfo.isFreeform) { "Task must already be in freeform" }
- val wct = WindowContainerTransaction().apply {
- setBounds(taskInfo.token, Rect())
- }
- immersiveTransitionHandler.enterImmersive(taskInfo, wct)
+ immersiveTransitionHandler.moveTaskToImmersive(taskInfo)
}
private fun exitDesktopTaskFromFullImmersive(taskInfo: RunningTaskInfo) {
check(taskInfo.isFreeform) { "Task must already be in freeform" }
- val displayLayout = displayController.getDisplayLayout(taskInfo.displayId) ?: return
- val stableBounds = Rect().apply { displayLayout.getStableBounds(this) }
- val destinationBounds = getMaximizeBounds(taskInfo, stableBounds)
-
- val wct = WindowContainerTransaction().apply {
- setBounds(taskInfo.token, destinationBounds)
- }
- immersiveTransitionHandler.exitImmersive(taskInfo, wct)
+ immersiveTransitionHandler.moveTaskToNonImmersive(taskInfo)
}
/**
@@ -697,7 +721,7 @@ class DesktopTasksController(
// and toggle to the stable bounds.
taskRepository.saveBoundsBeforeMaximize(taskInfo.taskId, currentTaskBounds)
- destinationBounds.set(getMaximizeBounds(taskInfo, stableBounds))
+ destinationBounds.set(calculateMaximizeBounds(displayLayout, taskInfo))
}
@@ -1285,8 +1309,10 @@ class DesktopTasksController(
if (useDesktopOverrideDensity()) {
wct.setDensityDpi(task.token, DESKTOP_DENSITY_OVERRIDE)
}
- // Desktop Mode is showing and we're launching a new Task - we might need to minimize
- // a Task.
+ // Desktop Mode is showing and we're launching a new Task:
+ // 1) Exit immersive if needed.
+ immersiveTransitionHandler.exitImmersiveIfApplicable(transition, wct, task.displayId)
+ // 2) minimize a Task if needed.
val taskToMinimize = addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task.taskId)
if (taskToMinimize != null) {
addPendingMinimizeTransition(transition, taskToMinimize)
@@ -1316,6 +1342,9 @@ class DesktopTasksController(
val taskToMinimize =
addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task.taskId)
addPendingMinimizeTransition(transition, taskToMinimize)
+ immersiveTransitionHandler.exitImmersiveIfApplicable(
+ transition, wct, task.displayId
+ )
}
}
return null
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
index a4bc2fe9460b..0b1bb8f36fa8 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
@@ -21,6 +21,7 @@ import android.content.Context
import android.os.IBinder
import android.view.SurfaceControl
import android.view.WindowManager
+import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_TO_BACK
import android.window.TransitionInfo
import android.window.WindowContainerTransaction
@@ -36,8 +37,8 @@ import com.android.wm.shell.transition.Transitions
/**
* A [Transitions.TransitionObserver] that observes shell transitions and updates the
- * [DesktopRepository] state TODO: b/332682201 This observes transitions related to desktop
- * mode and other transitions that originate both within and outside shell.
+ * [DesktopRepository] state TODO: b/332682201 This observes transitions related to desktop mode and
+ * other transitions that originate both within and outside shell.
*/
class DesktopTasksTransitionObserver(
private val context: Context,
@@ -47,6 +48,8 @@ class DesktopTasksTransitionObserver(
shellInit: ShellInit
) : Transitions.TransitionObserver {
+ private var transitionToCloseWallpaper: IBinder? = null
+
init {
if (DesktopModeStatus.canEnterDesktopMode(context)) {
shellInit.addInitCallback(::onInit, this)
@@ -70,6 +73,7 @@ class DesktopTasksTransitionObserver(
handleBackNavigation(info)
removeTaskIfNeeded(info)
}
+ removeWallpaperOnLastTaskClosingIfNeeded(transition, info)
}
private fun removeTaskIfNeeded(info: TransitionInfo) {
@@ -81,13 +85,9 @@ class DesktopTasksTransitionObserver(
val taskInfo = change.taskInfo
if (taskInfo == null || taskInfo.taskId == -1) continue
- if (desktopRepository.isActiveTask(taskInfo.taskId)
- && taskInfo.windowingMode != WINDOWING_MODE_FREEFORM
- ) {
- desktopRepository.removeFreeformTask(
- taskInfo.displayId,
- taskInfo.taskId
- )
+ if (desktopRepository.isActiveTask(taskInfo.taskId) &&
+ taskInfo.windowingMode != WINDOWING_MODE_FREEFORM) {
+ desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
}
}
}
@@ -104,14 +104,32 @@ class DesktopTasksTransitionObserver(
if (desktopRepository.getVisibleTaskCount(taskInfo.displayId) > 0 &&
change.mode == TRANSIT_TO_BACK &&
- taskInfo.windowingMode == WINDOWING_MODE_FREEFORM
- ) {
+ taskInfo.windowingMode == WINDOWING_MODE_FREEFORM) {
desktopRepository.minimizeTask(taskInfo.displayId, taskInfo.taskId)
}
}
}
}
+ private fun removeWallpaperOnLastTaskClosingIfNeeded(
+ transition: IBinder,
+ info: TransitionInfo
+ ) {
+ for (change in info.changes) {
+ val taskInfo = change.taskInfo
+ if (taskInfo == null || taskInfo.taskId == -1) {
+ continue
+ }
+
+ if (desktopRepository.getVisibleTaskCount(taskInfo.displayId) == 1 &&
+ change.mode == TRANSIT_CLOSE &&
+ taskInfo.windowingMode == WINDOWING_MODE_FREEFORM &&
+ desktopRepository.wallpaperActivityToken != null) {
+ transitionToCloseWallpaper = transition
+ }
+ }
+ }
+
override fun onTransitionStarting(transition: IBinder) {
// TODO: b/332682201 Update repository state
}
@@ -122,6 +140,16 @@ class DesktopTasksTransitionObserver(
override fun onTransitionFinished(transition: IBinder, aborted: Boolean) {
// TODO: b/332682201 Update repository state
+ if (transitionToCloseWallpaper == transition) {
+ // TODO: b/362469671 - Handle merging the animation when desktop is also closing.
+ desktopRepository.wallpaperActivityToken?.let { wallpaperActivityToken ->
+ transitions.startTransition(
+ TRANSIT_CLOSE,
+ WindowContainerTransaction().removeTask(wallpaperActivityToken),
+ null)
+ }
+ transitionToCloseWallpaper = null
+ }
}
private fun updateWallpaperToken(info: TransitionInfo) {
@@ -139,10 +167,9 @@ class DesktopTasksTransitionObserver(
// task.
shellTaskOrganizer.applyTransaction(
WindowContainerTransaction()
- .setTaskTrimmableFromRecents(taskInfo.token, false)
- )
+ .setTaskTrimmableFromRecents(taskInfo.token, false))
}
- WindowManager.TRANSIT_CLOSE ->
+ TRANSIT_CLOSE ->
desktopRepository.wallpaperActivityToken = null
else -> {}
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl
index 1090a4690a5d..86351e364cdd 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl
@@ -51,5 +51,5 @@ interface IDesktopMode {
void moveToDesktop(int taskId, in DesktopModeTransitionSource transitionSource);
/** Remove desktop on the given display */
- void removeDesktop(int displayId);
+ oneway void removeDesktop(int displayId);
} \ No newline at end of file
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
index ae65892ef6c1..a16446fffa15 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
@@ -126,6 +126,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
|| repository.isClosingTask(taskInfo.taskId)) {
// A task that's vanishing should be removed:
// - If it's closed by the X button which means it's marked as a closing task.
+ repository.removeClosingTask(taskInfo.taskId);
repository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId);
} else {
repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId, false);
@@ -150,8 +151,6 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
mDesktopRepository.ifPresent(repository -> {
if (taskInfo.isVisible) {
repository.addActiveTask(taskInfo.displayId, taskInfo.taskId);
- } else if (repository.isClosingTask(taskInfo.taskId)) {
- repository.removeClosingTask(taskInfo.taskId);
}
repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId,
taskInfo.isVisible);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java
index 4106a10996ed..771573d48e45 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java
@@ -89,7 +89,7 @@ public class FreeformTaskTransitionObserver implements Transitions.TransitionObs
// TODO(b/367268953): Remove when DesktopTaskListener is introduced and the repository
// is updated from there **before** the |mWindowDecorViewModel| methods are invoked.
// Otherwise window decoration relayout won't run with the immersive state up to date.
- mImmersiveTransitionHandler.ifPresent(h -> h.onTransitionReady(transition));
+ mImmersiveTransitionHandler.ifPresent(h -> h.onTransitionReady(transition, info));
}
// Update focus state first to ensure the correct state can be queried from listeners.
// TODO(371503964): Remove this once the unified task repository is ready.
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java
index c540edef32c4..be4fd7c5eeec 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java
@@ -58,9 +58,11 @@ import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.freeform.FreeformTaskTransitionStarter;
+import com.android.wm.shell.shared.FocusTransitionListener;
import com.android.wm.shell.shared.annotations.ShellBackgroundThread;
import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.sysui.ShellInit;
+import com.android.wm.shell.transition.FocusTransitionObserver;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.extension.TaskInfoKt;
@@ -68,7 +70,7 @@ import com.android.wm.shell.windowdecor.extension.TaskInfoKt;
* View model for the window decoration with a caption and shadows. Works with
* {@link CaptionWindowDecoration}.
*/
-public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
+public class CaptionWindowDecorViewModel implements WindowDecorViewModel, FocusTransitionListener {
private static final String TAG = "CaptionWindowDecorViewModel";
private final ShellTaskOrganizer mTaskOrganizer;
@@ -85,6 +87,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
private final Region mExclusionRegion = Region.obtain();
private final InputManager mInputManager;
private TaskOperations mTaskOperations;
+ private FocusTransitionObserver mFocusTransitionObserver;
/**
* Whether to pilfer the next motion event to send cancellations to the windows below.
@@ -121,7 +124,8 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
DisplayController displayController,
RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
SyncTransactionQueue syncQueue,
- Transitions transitions) {
+ Transitions transitions,
+ FocusTransitionObserver focusTransitionObserver) {
mContext = context;
mMainExecutor = shellExecutor;
mMainHandler = mainHandler;
@@ -133,6 +137,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
mSyncQueue = syncQueue;
mTransitions = transitions;
+ mFocusTransitionObserver = focusTransitionObserver;
if (!Transitions.ENABLE_SHELL_TRANSITIONS) {
mTaskOperations = new TaskOperations(null, mContext, mSyncQueue);
}
@@ -148,6 +153,16 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
} catch (RemoteException e) {
Log.e(TAG, "Failed to register window manager callbacks", e);
}
+ mFocusTransitionObserver.setLocalFocusTransitionListener(this, mMainExecutor);
+ }
+
+ @Override
+ public void onFocusedTaskChanged(int taskId, boolean isFocusedOnDisplay,
+ boolean isFocusedGlobally) {
+ final WindowDecoration decor = mWindowDecorByTaskId.get(taskId);
+ if (decor != null) {
+ decor.relayout(decor.mTaskInfo, isFocusedGlobally);
+ }
}
@Override
@@ -180,7 +195,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
return;
}
- decoration.relayout(taskInfo);
+ decoration.relayout(taskInfo, decoration.mHasGlobalFocus);
}
@Override
@@ -217,7 +232,8 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
createWindowDecoration(taskInfo, taskSurface, startT, finishT);
} else {
decoration.relayout(taskInfo, startT, finishT, false /* applyStartTransactionOnDraw */,
- false /* setTaskCropAndPosition */);
+ false /* setTaskCropAndPosition */,
+ mFocusTransitionObserver.hasGlobalFocus(taskInfo));
}
}
@@ -230,7 +246,8 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
if (decoration == null) return;
decoration.relayout(taskInfo, startT, finishT, false /* applyStartTransactionOnDraw */,
- false /* setTaskCropAndPosition */);
+ false /* setTaskCropAndPosition */,
+ mFocusTransitionObserver.hasGlobalFocus(taskInfo));
}
@Override
@@ -308,7 +325,8 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
windowDecoration.setDragPositioningCallback(taskPositioner);
windowDecoration.setTaskDragResizer(taskPositioner);
windowDecoration.relayout(taskInfo, startT, finishT,
- false /* applyStartTransactionOnDraw */, false /* setTaskCropAndPosition */);
+ false /* applyStartTransactionOnDraw */, false /* setTaskCropAndPosition */,
+ mFocusTransitionObserver.hasGlobalFocus(taskInfo));
}
private class CaptionTouchEventListener implements
@@ -359,7 +377,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
}
if (e.getAction() == MotionEvent.ACTION_DOWN) {
final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
- if (!taskInfo.isFocused) {
+ if (!mFocusTransitionObserver.hasGlobalFocus(taskInfo)) {
final WindowContainerTransaction wct = new WindowContainerTransaction();
wct.reorder(mTaskToken, true /* onTop */, true /* includingParents */);
mSyncQueue.queue(wct);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java
index 576c911d4459..509cb85c96cd 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java
@@ -174,7 +174,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
}
@Override
- void relayout(RunningTaskInfo taskInfo) {
+ void relayout(RunningTaskInfo taskInfo, boolean hasGlobalFocus) {
final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
// The crop and position of the task should only be set when a task is fluid resizing. In
// all other cases, it is expected that the transition handler positions and crops the task
@@ -185,7 +185,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
// synced with the buffer transaction (that draws the View). Both will be shown on screen
// at the same, whereas applying them independently causes flickering. See b/270202228.
relayout(taskInfo, t, t, true /* applyStartTransactionOnDraw */,
- shouldSetTaskPositionAndCrop);
+ shouldSetTaskPositionAndCrop, hasGlobalFocus);
}
@VisibleForTesting
@@ -196,12 +196,13 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
boolean setTaskCropAndPosition,
boolean isStatusBarVisible,
boolean isKeyguardVisibleAndOccluded,
- InsetsState displayInsetsState) {
+ InsetsState displayInsetsState,
+ boolean hasGlobalFocus) {
relayoutParams.reset();
relayoutParams.mRunningTaskInfo = taskInfo;
relayoutParams.mLayoutResId = R.layout.caption_window_decor;
relayoutParams.mCaptionHeightId = getCaptionHeightIdStatic(taskInfo.getWindowingMode());
- relayoutParams.mShadowRadiusId = taskInfo.isFocused
+ relayoutParams.mShadowRadiusId = hasGlobalFocus
? R.dimen.freeform_decor_shadow_focused_thickness
: R.dimen.freeform_decor_shadow_unfocused_thickness;
relayoutParams.mApplyStartTransactionOnDraw = applyStartTransactionOnDraw;
@@ -233,7 +234,8 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
@SuppressLint("MissingPermission")
void relayout(RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
- boolean applyStartTransactionOnDraw, boolean setTaskCropAndPosition) {
+ boolean applyStartTransactionOnDraw, boolean setTaskCropAndPosition,
+ boolean hasGlobalFocus) {
final boolean isFreeform =
taskInfo.getWindowingMode() == WindowConfiguration.WINDOWING_MODE_FREEFORM;
final boolean isDragResizeable = ENABLE_WINDOWING_SCALED_RESIZING.isTrue()
@@ -245,7 +247,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
updateRelayoutParams(mRelayoutParams, taskInfo, applyStartTransactionOnDraw,
setTaskCropAndPosition, mIsStatusBarVisible, mIsKeyguardVisibleAndOccluded,
- mDisplayController.getInsetsState(taskInfo.displayId));
+ mDisplayController.getInsetsState(taskInfo.displayId), hasGlobalFocus);
relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
// After this line, mTaskInfo is up-to-date and should be used instead of taskInfo
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
index e55bc67ba41b..9e089b2460f6 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
@@ -56,7 +56,6 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.input.InputManager;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -112,6 +111,7 @@ import com.android.wm.shell.desktopmode.DesktopWallpaperActivity;
import com.android.wm.shell.desktopmode.WindowDecorCaptionHandleRepository;
import com.android.wm.shell.desktopmode.education.AppHandleEducationController;
import com.android.wm.shell.freeform.FreeformTaskTransitionStarter;
+import com.android.wm.shell.shared.FocusTransitionListener;
import com.android.wm.shell.shared.annotations.ShellBackgroundThread;
import com.android.wm.shell.shared.annotations.ShellMainThread;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
@@ -124,6 +124,7 @@ import com.android.wm.shell.sysui.KeyguardChangeListener;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
+import com.android.wm.shell.transition.FocusTransitionObserver;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration.ExclusionRegionListener;
import com.android.wm.shell.windowdecor.extension.InsetsStateKt;
@@ -133,20 +134,21 @@ import com.android.wm.shell.windowdecor.viewholder.AppHeaderViewHolder;
import kotlin.Pair;
import kotlin.Unit;
+import kotlinx.coroutines.ExperimentalCoroutinesApi;
+
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
-import kotlinx.coroutines.ExperimentalCoroutinesApi;
-
/**
* View model for the window decoration with a caption and shadows. Works with
* {@link DesktopModeWindowDecoration}.
*/
-public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
+public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
+ FocusTransitionListener {
private static final String TAG = "DesktopModeWindowDecorViewModel";
private final DesktopModeWindowDecoration.Factory mDesktopModeWindowDecorFactory;
@@ -216,6 +218,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
}
};
private final TaskPositionerFactory mTaskPositionerFactory;
+ private final FocusTransitionObserver mFocusTransitionObserver;
public DesktopModeWindowDecorViewModel(
Context context,
@@ -242,7 +245,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
Optional<DesktopTasksLimiter> desktopTasksLimiter,
AppHandleEducationController appHandleEducationController,
WindowDecorCaptionHandleRepository windowDecorCaptionHandleRepository,
- Optional<DesktopActivityOrientationChangeHandler> activityOrientationChangeHandler) {
+ Optional<DesktopActivityOrientationChangeHandler> activityOrientationChangeHandler,
+ FocusTransitionObserver focusTransitionObserver) {
this(
context,
shellExecutor,
@@ -274,7 +278,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
appHandleEducationController,
windowDecorCaptionHandleRepository,
activityOrientationChangeHandler,
- new TaskPositionerFactory());
+ new TaskPositionerFactory(),
+ focusTransitionObserver);
}
@VisibleForTesting
@@ -309,7 +314,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
AppHandleEducationController appHandleEducationController,
WindowDecorCaptionHandleRepository windowDecorCaptionHandleRepository,
Optional<DesktopActivityOrientationChangeHandler> activityOrientationChangeHandler,
- TaskPositionerFactory taskPositionerFactory) {
+ TaskPositionerFactory taskPositionerFactory,
+ FocusTransitionObserver focusTransitionObserver) {
mContext = context;
mMainExecutor = shellExecutor;
mMainHandler = mainHandler;
@@ -369,6 +375,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
}
};
mTaskPositionerFactory = taskPositionerFactory;
+ mFocusTransitionObserver = focusTransitionObserver;
shellInit.addInitCallback(this::onInit, this);
}
@@ -402,11 +409,22 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
return Unit.INSTANCE;
});
}
+ mFocusTransitionObserver.setLocalFocusTransitionListener(this, mMainExecutor);
+ }
+
+ @Override
+ public void onFocusedTaskChanged(int taskId, boolean isFocusedOnDisplay,
+ boolean isFocusedGlobally) {
+ final WindowDecoration decor = mWindowDecorByTaskId.get(taskId);
+ if (decor != null) {
+ decor.relayout(decor.mTaskInfo, isFocusedGlobally);
+ }
}
@Override
public void setFreeformTaskTransitionStarter(FreeformTaskTransitionStarter transitionStarter) {
mTaskOperations = new TaskOperations(transitionStarter, mContext, mSyncQueue);
+ mDesktopTasksController.setFreeformTaskTransitionStarter(transitionStarter);
}
@Override
@@ -447,7 +465,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
removeTaskFromEventReceiver(oldTaskInfo.displayId);
incrementEventReceiverTasks(taskInfo.displayId);
}
- decoration.relayout(taskInfo);
+ decoration.relayout(taskInfo, decoration.mHasGlobalFocus);
mActivityOrientationChangeHandler.ifPresent(handler ->
handler.handleActivityOrientationChange(oldTaskInfo, taskInfo));
}
@@ -486,7 +504,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
createWindowDecoration(taskInfo, taskSurface, startT, finishT);
} else {
decoration.relayout(taskInfo, startT, finishT, false /* applyStartTransactionOnDraw */,
- false /* shouldSetTaskPositionAndCrop */);
+ false /* shouldSetTaskPositionAndCrop */,
+ mFocusTransitionObserver.hasGlobalFocus(taskInfo));
}
}
@@ -499,7 +518,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
if (decoration == null) return;
decoration.relayout(taskInfo, startT, finishT, false /* applyStartTransactionOnDraw */,
- false /* shouldSetTaskPositionAndCrop */);
+ false /* shouldSetTaskPositionAndCrop */,
+ mFocusTransitionObserver.hasGlobalFocus(taskInfo));
}
@Override
@@ -774,11 +794,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
onMaximizeOrRestore(decoration.mTaskInfo.taskId, "caption_bar_button");
}
} else if (id == R.id.minimize_window) {
- final WindowContainerTransaction wct = new WindowContainerTransaction();
- mDesktopTasksController.onDesktopWindowMinimize(wct, mTaskId);
- final IBinder transition = mTaskOperations.minimizeTask(mTaskToken, wct);
- mDesktopTasksLimiter.ifPresent(limiter ->
- limiter.addPendingMinimizeChange(transition, mDisplayId, mTaskId));
+ mDesktopTasksController.minimizeTask(decoration.mTaskInfo);
}
}
@@ -895,7 +911,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
}
private void moveTaskToFront(RunningTaskInfo taskInfo) {
- if (!taskInfo.isFocused) {
+ if (!mFocusTransitionObserver.hasGlobalFocus(taskInfo)) {
mDesktopTasksController.moveTaskToFront(taskInfo);
}
}
@@ -1516,7 +1532,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
windowDecoration.setExclusionRegionListener(mExclusionRegionListener);
windowDecoration.setDragPositioningCallback(taskPositioner);
windowDecoration.relayout(taskInfo, startT, finishT,
- false /* applyStartTransactionOnDraw */, false /* shouldSetTaskPositionAndCrop */);
+ false /* applyStartTransactionOnDraw */, false /* shouldSetTaskPositionAndCrop */,
+ mFocusTransitionObserver.hasGlobalFocus(taskInfo));
if (!Flags.enableHandleInputFix()) {
incrementEventReceiverTasks(taskInfo.displayId);
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java
index a78fb9b5e245..2c621b1f1a52 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java
@@ -352,7 +352,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
}
@Override
- void relayout(ActivityManager.RunningTaskInfo taskInfo) {
+ void relayout(ActivityManager.RunningTaskInfo taskInfo, boolean hasGlobalFocus) {
final SurfaceControl.Transaction t = mSurfaceControlTransactionSupplier.get();
// The crop and position of the task should only be set when a task is fluid resizing. In
// all other cases, it is expected that the transition handler positions and crops the task
@@ -365,7 +365,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
// the View). Both will be shown on screen at the same, whereas applying them independently
// causes flickering. See b/270202228.
final boolean applyTransactionOnDraw = taskInfo.isFreeform();
- relayout(taskInfo, t, t, applyTransactionOnDraw, shouldSetTaskPositionAndCrop);
+ relayout(taskInfo, t, t, applyTransactionOnDraw, shouldSetTaskPositionAndCrop,
+ hasGlobalFocus);
if (!applyTransactionOnDraw) {
t.apply();
}
@@ -373,18 +374,19 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
void relayout(ActivityManager.RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
- boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop) {
+ boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop,
+ boolean hasGlobalFocus) {
Trace.beginSection("DesktopModeWindowDecoration#relayout");
if (taskInfo.isFreeform()) {
// The Task is in Freeform mode -> show its header in sync since it's an integral part
// of the window itself - a delayed header might cause bad UX.
relayoutInSync(taskInfo, startT, finishT, applyStartTransactionOnDraw,
- shouldSetTaskPositionAndCrop);
+ shouldSetTaskPositionAndCrop, hasGlobalFocus);
} else {
// The Task is outside Freeform mode -> allow the handle view to be delayed since the
// handle is just a small addition to the window.
relayoutWithDelayedViewHost(taskInfo, startT, finishT, applyStartTransactionOnDraw,
- shouldSetTaskPositionAndCrop);
+ shouldSetTaskPositionAndCrop, hasGlobalFocus);
}
Trace.endSection();
}
@@ -392,11 +394,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
/** Run the whole relayout phase immediately without delay. */
private void relayoutInSync(ActivityManager.RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
- boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop) {
+ boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop,
+ boolean hasGlobalFocus) {
// Clear the current ViewHost runnable as we will update the ViewHost here
clearCurrentViewHostRunnable();
updateRelayoutParamsAndSurfaces(taskInfo, startT, finishT, applyStartTransactionOnDraw,
- shouldSetTaskPositionAndCrop);
+ shouldSetTaskPositionAndCrop, hasGlobalFocus);
if (mResult.mRootView != null) {
updateViewHost(mRelayoutParams, startT, mResult);
}
@@ -418,7 +421,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
*/
private void relayoutWithDelayedViewHost(ActivityManager.RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
- boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop) {
+ boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop,
+ boolean hasGlobalFocus) {
if (applyStartTransactionOnDraw) {
throw new IllegalArgumentException(
"We cannot both sync viewhost ondraw and delay viewhost creation.");
@@ -426,7 +430,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
// Clear the current ViewHost runnable as we will update the ViewHost here
clearCurrentViewHostRunnable();
updateRelayoutParamsAndSurfaces(taskInfo, startT, finishT,
- false /* applyStartTransactionOnDraw */, shouldSetTaskPositionAndCrop);
+ false /* applyStartTransactionOnDraw */, shouldSetTaskPositionAndCrop,
+ hasGlobalFocus);
if (mResult.mRootView == null) {
// This means something blocks the window decor from showing, e.g. the task is hidden.
// Nothing is set up in this case including the decoration surface.
@@ -440,7 +445,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
@SuppressLint("MissingPermission")
private void updateRelayoutParamsAndSurfaces(ActivityManager.RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
- boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop) {
+ boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop,
+ boolean hasGlobalFocus) {
Trace.beginSection("DesktopModeWindowDecoration#updateRelayoutParamsAndSurfaces");
if (Flags.enableDesktopWindowingAppToWeb()) {
@@ -459,7 +465,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
.isTaskInFullImmersiveState(taskInfo.taskId);
updateRelayoutParams(mRelayoutParams, mContext, taskInfo, applyStartTransactionOnDraw,
shouldSetTaskPositionAndCrop, mIsStatusBarVisible, mIsKeyguardVisibleAndOccluded,
- inFullImmersive, mDisplayController.getInsetsState(taskInfo.displayId));
+ inFullImmersive, mDisplayController.getInsetsState(taskInfo.displayId),
+ hasGlobalFocus);
final WindowDecorLinearLayout oldRootView = mResult.mRootView;
final SurfaceControl oldDecorationSurface = mDecorationContainerSurface;
@@ -507,12 +514,13 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
));
} else {
mWindowDecorViewHolder.bindData(new AppHeaderViewHolder.HeaderData(
- mTaskInfo, TaskInfoKt.getRequestingImmersive(mTaskInfo), inFullImmersive
+ mTaskInfo, TaskInfoKt.getRequestingImmersive(mTaskInfo), inFullImmersive,
+ hasGlobalFocus
));
}
Trace.endSection();
- if (!mTaskInfo.isFocused) {
+ if (!hasGlobalFocus) {
closeHandleMenu();
closeManageWindowsMenu();
closeMaximizeMenu();
@@ -780,7 +788,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
boolean isStatusBarVisible,
boolean isKeyguardVisibleAndOccluded,
boolean inFullImmersiveMode,
- @NonNull InsetsState displayInsetsState) {
+ @NonNull InsetsState displayInsetsState,
+ boolean hasGlobalFocus) {
final int captionLayoutId = getDesktopModeWindowDecorLayoutId(taskInfo.getWindowingMode());
final boolean isAppHeader =
captionLayoutId == R.layout.desktop_mode_app_header;
@@ -790,6 +799,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
relayoutParams.mLayoutResId = captionLayoutId;
relayoutParams.mCaptionHeightId = getCaptionHeightIdStatic(taskInfo.getWindowingMode());
relayoutParams.mCaptionWidthId = getCaptionWidthId(relayoutParams.mLayoutResId);
+ relayoutParams.mHasGlobalFocus = hasGlobalFocus;
final boolean showCaption;
if (Flags.enableFullyImmersiveInDesktop()) {
@@ -812,7 +822,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
|| (isStatusBarVisible && !isKeyguardVisibleAndOccluded);
}
relayoutParams.mIsCaptionVisible = showCaption;
-
+ relayoutParams.mIsInsetSource = isAppHeader && !inFullImmersiveMode;
if (isAppHeader) {
if (TaskInfoKt.isTransparentCaptionBarAppearance(taskInfo)) {
// If the app is requesting to customize the caption bar, allow input to fall
@@ -837,7 +847,6 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
WindowInsets.Type.systemBars() & ~WindowInsets.Type.captionBar(),
false /* ignoreVisibility */);
relayoutParams.mCaptionTopPadding = systemBarInsets.top;
- relayoutParams.mIsInsetSource = false;
}
// Report occluding elements as bounding rects to the insets system so that apps can
// draw in the empty space in the center:
@@ -865,8 +874,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
relayoutParams.mInputFeatures
|= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
}
- if (DesktopModeStatus.useWindowShadow(/* isFocusedWindow= */ taskInfo.isFocused)) {
- relayoutParams.mShadowRadiusId = taskInfo.isFocused
+ if (DesktopModeStatus.useWindowShadow(/* isFocusedWindow= */ hasGlobalFocus)) {
+ relayoutParams.mShadowRadiusId = hasGlobalFocus
? R.dimen.freeform_decor_shadow_focused_thickness
: R.dimen.freeform_decor_shadow_unfocused_thickness;
}
@@ -1408,7 +1417,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
}
boolean isFocused() {
- return mTaskInfo.isFocused;
+ return mHasGlobalFocus;
}
/**
@@ -1592,7 +1601,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
private static int getCaptionHeightIdStatic(@WindowingMode int windowingMode) {
return windowingMode == WINDOWING_MODE_FULLSCREEN
- ? R.dimen.desktop_mode_fullscreen_decor_caption_height
+ ? com.android.internal.R.dimen.status_bar_height_default
: R.dimen.desktop_mode_freeform_decor_caption_height;
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java
index f4c7fe3eac0c..ccf329c2bb22 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java
@@ -93,7 +93,7 @@ class FluidResizeTaskPositioner implements TaskPositioner, Transitions.Transitio
mWindowDecoration.mTaskInfo.configuration.windowConfiguration.getBounds());
mRepositionStartPoint.set(x, y);
mDragStartListener.onDragStart(mWindowDecoration.mTaskInfo.taskId);
- if (mCtrlType != CTRL_TYPE_UNDEFINED && !mWindowDecoration.mTaskInfo.isFocused) {
+ if (mCtrlType != CTRL_TYPE_UNDEFINED && !mWindowDecoration.mHasGlobalFocus) {
WindowContainerTransaction wct = new WindowContainerTransaction();
wct.reorder(mWindowDecoration.mTaskInfo.token, true /* onTop */,
true /* includingParents */);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
index a1f76d2d1597..ff3b45555bce 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
@@ -106,7 +106,7 @@ public class VeiledResizeTaskPositioner implements TaskPositioner, Transitions.T
// Capture CUJ for re-sizing window in DW mode.
mInteractionJankMonitor.begin(mDesktopWindowDecoration.mTaskSurface,
mDesktopWindowDecoration.mContext, mHandler, CUJ_DESKTOP_MODE_RESIZE_WINDOW);
- if (!mDesktopWindowDecoration.mTaskInfo.isFocused) {
+ if (!mDesktopWindowDecoration.mHasGlobalFocus) {
WindowContainerTransaction wct = new WindowContainerTransaction();
wct.reorder(mDesktopWindowDecoration.mTaskInfo.token, true /* onTop */,
true /* includingParents */);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java
index f8aed412e3fb..ce5cfd0bdc36 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java
@@ -125,7 +125,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
}
mDisplayController.removeDisplayWindowListener(this);
- relayout(mTaskInfo);
+ relayout(mTaskInfo, mHasGlobalFocus);
}
};
@@ -146,6 +146,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
boolean mIsStatusBarVisible;
boolean mIsKeyguardVisibleAndOccluded;
+ boolean mHasGlobalFocus;
/** The most recent set of insets applied to this window decoration. */
private WindowDecorationInsets mWindowDecorationInsets;
@@ -199,8 +200,9 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
*
* @param taskInfo The previous {@link RunningTaskInfo} passed into {@link #relayout} or the
* constructor.
+ * @param hasGlobalFocus Whether the task is focused
*/
- abstract void relayout(RunningTaskInfo taskInfo);
+ abstract void relayout(RunningTaskInfo taskInfo, boolean hasGlobalFocus);
/**
* Used by the {@link DragPositioningCallback} associated with the implementing class to
@@ -225,6 +227,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
if (params.mRunningTaskInfo != null) {
mTaskInfo = params.mRunningTaskInfo;
}
+ mHasGlobalFocus = params.mHasGlobalFocus;
final int oldLayoutResId = mLayoutResId;
mLayoutResId = params.mLayoutResId;
@@ -246,7 +249,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
final Rect taskBounds = mTaskInfo.getConfiguration().windowConfiguration.getBounds();
outResult.mWidth = taskBounds.width();
outResult.mHeight = taskBounds.height();
- outResult.mRootView.setTaskFocusState(mTaskInfo.isFocused);
+ outResult.mRootView.setTaskFocusState(mHasGlobalFocus);
final Resources resources = mDecorWindowContext.getResources();
outResult.mCaptionHeight = loadDimensionPixelSize(resources, params.mCaptionHeightId)
+ params.mCaptionTopPadding;
@@ -391,11 +394,11 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
final WindowDecorationInsets newInsets = new WindowDecorationInsets(
mTaskInfo.token, mOwner, captionInsetsRect, boundingRects,
- params.mInsetSourceFlags);
+ params.mInsetSourceFlags, params.mIsInsetSource);
if (!newInsets.equals(mWindowDecorationInsets)) {
// Add or update this caption as an insets source.
mWindowDecorationInsets = newInsets;
- mWindowDecorationInsets.addOrUpdate(wct);
+ mWindowDecorationInsets.update(wct);
}
}
@@ -512,7 +515,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
mIsKeyguardVisibleAndOccluded = visible && occluded;
final boolean changed = prevVisAndOccluded != mIsKeyguardVisibleAndOccluded;
if (changed) {
- relayout(mTaskInfo);
+ relayout(mTaskInfo, mHasGlobalFocus);
}
}
@@ -522,7 +525,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
final boolean changed = prevStatusBarVisibility != mIsStatusBarVisible;
if (changed) {
- relayout(mTaskInfo);
+ relayout(mTaskInfo, mHasGlobalFocus);
}
}
@@ -710,10 +713,11 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
final int captionHeight = loadDimensionPixelSize(mContext.getResources(), captionHeightId);
final Rect captionInsets = new Rect(0, 0, 0, captionHeight);
final WindowDecorationInsets newInsets = new WindowDecorationInsets(mTaskInfo.token,
- mOwner, captionInsets, null /* boundingRets */, 0 /* flags */);
+ mOwner, captionInsets, null /* boundingRets */, 0 /* flags */,
+ true /* shouldAddCaptionInset */);
if (!newInsets.equals(mWindowDecorationInsets)) {
mWindowDecorationInsets = newInsets;
- mWindowDecorationInsets.addOrUpdate(wct);
+ mWindowDecorationInsets.update(wct);
}
}
@@ -737,6 +741,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
boolean mApplyStartTransactionOnDraw;
boolean mSetTaskPositionAndCrop;
+ boolean mHasGlobalFocus;
void reset() {
mLayoutResId = Resources.ID_NULL;
@@ -756,6 +761,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
mApplyStartTransactionOnDraw = false;
mSetTaskPositionAndCrop = false;
mWindowDecorConfig = null;
+ mHasGlobalFocus = false;
}
boolean hasInputFeatureSpy() {
@@ -814,21 +820,26 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
private final Rect mFrame;
private final Rect[] mBoundingRects;
private final @InsetsSource.Flags int mFlags;
+ private final boolean mShouldAddCaptionInset;
private WindowDecorationInsets(WindowContainerToken token, Binder owner, Rect frame,
- Rect[] boundingRects, @InsetsSource.Flags int flags) {
+ Rect[] boundingRects, @InsetsSource.Flags int flags,
+ boolean shouldAddCaptionInset) {
mToken = token;
mOwner = owner;
mFrame = frame;
mBoundingRects = boundingRects;
mFlags = flags;
+ mShouldAddCaptionInset = shouldAddCaptionInset;
}
- void addOrUpdate(WindowContainerTransaction wct) {
- wct.addInsetsSource(mToken, mOwner, INDEX, captionBar(), mFrame, mBoundingRects,
- mFlags);
- wct.addInsetsSource(mToken, mOwner, INDEX, mandatorySystemGestures(), mFrame,
- mBoundingRects, 0 /* flags */);
+ void update(WindowContainerTransaction wct) {
+ if (mShouldAddCaptionInset) {
+ wct.addInsetsSource(mToken, mOwner, INDEX, captionBar(), mFrame, mBoundingRects,
+ mFlags);
+ wct.addInsetsSource(mToken, mOwner, INDEX, mandatorySystemGestures(), mFrame,
+ mBoundingRects, 0 /* flags */);
+ }
}
void remove(WindowContainerTransaction wct) {
@@ -843,7 +854,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
return Objects.equals(mToken, that.mToken) && Objects.equals(mOwner,
that.mOwner) && Objects.equals(mFrame, that.mFrame)
&& Objects.deepEquals(mBoundingRects, that.mBoundingRects)
- && mFlags == that.mFlags;
+ && mFlags == that.mFlags
+ && mShouldAddCaptionInset == that.mShouldAddCaptionInset;
}
@Override
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/AppHeaderViewHolder.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/AppHeaderViewHolder.kt
index c2af1d45e76f..cf03b3f74dc7 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/AppHeaderViewHolder.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/AppHeaderViewHolder.kt
@@ -81,6 +81,7 @@ class AppHeaderViewHolder(
val taskInfo: RunningTaskInfo,
val isRequestingImmersive: Boolean,
val inFullImmersiveState: Boolean,
+ val hasGlobalFocus: Boolean
) : Data()
private val decorThemeUtil = DecorThemeUtil(context)
@@ -159,24 +160,27 @@ class AppHeaderViewHolder(
}
override fun bindData(data: HeaderData) {
- bindData(data.taskInfo, data.isRequestingImmersive, data.inFullImmersiveState)
+ bindData(data.taskInfo, data.isRequestingImmersive, data.inFullImmersiveState,
+ data.hasGlobalFocus)
}
private fun bindData(
taskInfo: RunningTaskInfo,
isRequestingImmersive: Boolean,
inFullImmersiveState: Boolean,
+ hasGlobalFocus: Boolean
) {
if (DesktopModeFlags.ENABLE_THEMED_APP_HEADERS.isTrue()) {
- bindDataWithThemedHeaders(taskInfo, isRequestingImmersive, inFullImmersiveState)
+ bindDataWithThemedHeaders(taskInfo, isRequestingImmersive, inFullImmersiveState,
+ hasGlobalFocus)
} else {
- bindDataLegacy(taskInfo)
+ bindDataLegacy(taskInfo, hasGlobalFocus)
}
}
- private fun bindDataLegacy(taskInfo: RunningTaskInfo) {
- captionView.setBackgroundColor(getCaptionBackgroundColor(taskInfo))
- val color = getAppNameAndButtonColor(taskInfo)
+ private fun bindDataLegacy(taskInfo: RunningTaskInfo, hasGlobalFocus: Boolean) {
+ captionView.setBackgroundColor(getCaptionBackgroundColor(taskInfo, hasGlobalFocus))
+ val color = getAppNameAndButtonColor(taskInfo, hasGlobalFocus)
val alpha = Color.alpha(color)
closeWindowButton.imageTintList = ColorStateList.valueOf(color)
maximizeWindowButton.imageTintList = ColorStateList.valueOf(color)
@@ -210,9 +214,10 @@ class AppHeaderViewHolder(
private fun bindDataWithThemedHeaders(
taskInfo: RunningTaskInfo,
requestingImmersive: Boolean,
- inFullImmersiveState: Boolean
+ inFullImmersiveState: Boolean,
+ hasGlobalFocus: Boolean
) {
- val header = fillHeaderInfo(taskInfo)
+ val header = fillHeaderInfo(taskInfo, hasGlobalFocus)
val headerStyle = getHeaderStyle(header)
// Caption Background
@@ -455,7 +460,7 @@ class AppHeaderViewHolder(
}
}
- private fun fillHeaderInfo(taskInfo: RunningTaskInfo): Header {
+ private fun fillHeaderInfo(taskInfo: RunningTaskInfo, hasGlobalFocus: Boolean): Header {
return Header(
type = if (taskInfo.isTransparentCaptionBarAppearance) {
Header.Type.CUSTOM
@@ -463,7 +468,7 @@ class AppHeaderViewHolder(
Header.Type.DEFAULT
},
appTheme = decorThemeUtil.getAppTheme(taskInfo),
- isFocused = taskInfo.isFocused,
+ isFocused = hasGlobalFocus,
isAppearanceCaptionLight = taskInfo.isLightCaptionBarAppearance
)
}
@@ -544,19 +549,19 @@ class AppHeaderViewHolder(
}
@ColorInt
- private fun getCaptionBackgroundColor(taskInfo: RunningTaskInfo): Int {
+ private fun getCaptionBackgroundColor(taskInfo: RunningTaskInfo, hasGlobalFocus: Boolean): Int {
if (taskInfo.isTransparentCaptionBarAppearance) {
return Color.TRANSPARENT
}
val materialColorAttr: Int =
if (isDarkMode()) {
- if (!taskInfo.isFocused) {
+ if (!hasGlobalFocus) {
materialColorSurfaceContainerHigh
} else {
materialColorSurfaceDim
}
} else {
- if (!taskInfo.isFocused) {
+ if (!hasGlobalFocus) {
materialColorSurfaceContainerLow
} else {
materialColorSecondaryContainer
@@ -569,7 +574,7 @@ class AppHeaderViewHolder(
}
@ColorInt
- private fun getAppNameAndButtonColor(taskInfo: RunningTaskInfo): Int {
+ private fun getAppNameAndButtonColor(taskInfo: RunningTaskInfo, hasGlobalFocus: Boolean): Int {
val materialColorAttr = when {
taskInfo.isTransparentCaptionBarAppearance &&
taskInfo.isLightCaptionBarAppearance -> materialColorOnSecondaryContainer
@@ -579,8 +584,8 @@ class AppHeaderViewHolder(
else -> materialColorOnSecondaryContainer
}
val appDetailsOpacity = when {
- isDarkMode() && !taskInfo.isFocused -> DARK_THEME_UNFOCUSED_OPACITY
- !isDarkMode() && !taskInfo.isFocused -> LIGHT_THEME_UNFOCUSED_OPACITY
+ isDarkMode() && !hasGlobalFocus -> DARK_THEME_UNFOCUSED_OPACITY
+ !isDarkMode() && !hasGlobalFocus -> LIGHT_THEME_UNFOCUSED_OPACITY
else -> FOCUSED_OPACITY
}
context.withStyledAttributes(null, intArrayOf(materialColorAttr), 0, 0) {
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt
index cae609526c65..2e9effb44d67 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt
@@ -15,23 +15,39 @@
*/
package com.android.wm.shell.desktopmode
+import android.app.WindowConfiguration.WINDOW_CONFIG_BOUNDS
+import android.os.Binder
import android.os.IBinder
+import android.platform.test.annotations.EnableFlags
+import android.platform.test.flag.junit.SetFlagsRule
import android.testing.AndroidTestingRunner
+import android.view.Display.DEFAULT_DISPLAY
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
+import android.view.WindowManager.TransitionFlags
+import android.view.WindowManager.TransitionType
+import android.window.TransitionInfo
+import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.test.filters.SmallTest
+import com.android.window.flags.Flags
+import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestShellExecutor
+import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.common.DisplayLayout
import com.android.wm.shell.desktopmode.DesktopTestHelpers.Companion.createFreeformTask
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
import com.google.common.truth.Truth.assertThat
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.mock
+import org.mockito.kotlin.any
+import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
@@ -40,14 +56,18 @@ import org.mockito.kotlin.whenever
/**
* Tests for [DesktopFullImmersiveTransitionHandler].
*
- * Usage: atest WMShellUnitTests:DesktopFullImmersiveTransitionHandler
+ * Usage: atest WMShellUnitTests:DesktopFullImmersiveTransitionHandlerTest
*/
@SmallTest
@RunWith(AndroidTestingRunner::class)
class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
+ @JvmField @Rule val setFlagsRule = SetFlagsRule()
+
@Mock private lateinit var mockTransitions: Transitions
private lateinit var desktopRepository: DesktopRepository
+ @Mock private lateinit var mockDisplayController: DisplayController
+ @Mock private lateinit var mockShellTaskOrganizer: ShellTaskOrganizer
private val transactionSupplier = { SurfaceControl.Transaction() }
private lateinit var immersiveHandler: DesktopFullImmersiveTransitionHandler
@@ -57,19 +77,22 @@ class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
desktopRepository = DesktopRepository(
context, ShellInit(TestShellExecutor()), mock(), mock()
)
+ whenever(mockDisplayController.getDisplayLayout(DEFAULT_DISPLAY))
+ .thenReturn(DisplayLayout())
immersiveHandler = DesktopFullImmersiveTransitionHandler(
transitions = mockTransitions,
desktopRepository = desktopRepository,
- transactionSupplier = transactionSupplier
+ displayController = mockDisplayController,
+ shellTaskOrganizer = mockShellTaskOrganizer,
+ transactionSupplier = transactionSupplier,
)
}
@Test
fun enterImmersive_transitionReady_updatesRepository() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
desktopRepository.setTaskInFullImmersiveState(
displayId = task.displayId,
@@ -77,8 +100,8 @@ class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
immersive = false
)
- immersiveHandler.enterImmersive(task, wct)
- immersiveHandler.onTransitionReady(mockBinder)
+ immersiveHandler.moveTaskToImmersive(task)
+ immersiveHandler.onTransitionReady(mockBinder, createTransitionInfo())
assertThat(desktopRepository.isTaskInFullImmersiveState(task.taskId)).isTrue()
}
@@ -86,9 +109,8 @@ class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
@Test
fun exitImmersive_transitionReady_updatesRepository() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
desktopRepository.setTaskInFullImmersiveState(
displayId = task.displayId,
@@ -96,8 +118,8 @@ class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
immersive = true
)
- immersiveHandler.exitImmersive(task, wct)
- immersiveHandler.onTransitionReady(mockBinder)
+ immersiveHandler.moveTaskToNonImmersive(task)
+ immersiveHandler.onTransitionReady(mockBinder, createTransitionInfo())
assertThat(desktopRepository.isTaskInFullImmersiveState(task.taskId)).isFalse()
}
@@ -105,28 +127,251 @@ class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
@Test
fun enterImmersive_inProgress_ignores() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
- immersiveHandler.enterImmersive(task, wct)
- immersiveHandler.enterImmersive(task, wct)
+ immersiveHandler.moveTaskToImmersive(task)
+ immersiveHandler.moveTaskToImmersive(task)
- verify(mockTransitions, times(1)).startTransition(TRANSIT_CHANGE, wct, immersiveHandler)
+ verify(mockTransitions, times(1))
+ .startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler))
}
@Test
fun exitImmersive_inProgress_ignores() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
- immersiveHandler.exitImmersive(task, wct)
- immersiveHandler.exitImmersive(task, wct)
+ immersiveHandler.moveTaskToNonImmersive(task)
+ immersiveHandler.moveTaskToNonImmersive(task)
+
+ verify(mockTransitions, times(1))
+ .startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler))
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_inImmersive_addsPendingExit() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
- verify(mockTransitions, times(1)).startTransition(TRANSIT_CHANGE, wct, immersiveHandler)
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isTrue()
}
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_notInImmersive_doesNotAddPendingExit() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byDisplay_inImmersive_changesTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(wct.hasBoundsChange(task.token)).isTrue()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byDisplay_notInImmersive_doesNotChangeTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(wct.hasBoundsChange(task.token)).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_inImmersive_changesTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct = wct, taskInfo = task)
+
+ assertThat(wct.hasBoundsChange(task.token)).isTrue()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_notInImmersive_doesNotChangeTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct, task.taskId)
+
+ assertThat(wct.hasBoundsChange(task.token)).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_inImmersive_addsPendingExitOnRun() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct, task.taskId)?.invoke(transition)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_notInImmersive_doesNotAddPendingExitOnRun() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct, task.taskId)?.invoke(transition)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun onTransitionReady_pendingExit_removesPendingExit() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ immersiveHandler.onTransitionReady(
+ transition = transition,
+ info = createTransitionInfo(
+ changes = listOf(
+ TransitionInfo.Change(task.token, SurfaceControl()).apply { taskInfo = task }
+ )
+ )
+ )
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun onTransitionReady_pendingExit_updatesRepository() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ immersiveHandler.onTransitionReady(
+ transition = transition,
+ info = createTransitionInfo(
+ changes = listOf(
+ TransitionInfo.Change(task.token, SurfaceControl()).apply { taskInfo = task }
+ )
+ )
+ )
+
+ assertThat(desktopRepository.isTaskInFullImmersiveState(task.taskId)).isFalse()
+ }
+
+ private fun createTransitionInfo(
+ @TransitionType type: Int = TRANSIT_CHANGE,
+ @TransitionFlags flags: Int = 0,
+ changes: List<TransitionInfo.Change> = emptyList()
+ ): TransitionInfo = TransitionInfo(type, flags).apply {
+ changes.forEach { change -> addChange(change) }
+ }
+
+ private fun WindowContainerTransaction.hasBoundsChange(token: WindowContainerToken): Boolean =
+ this.changes.any { change ->
+ change.key == token.asBinder()
+ && (change.value.windowSetMask and WINDOW_CONFIG_BOUNDS) != 0
+ }
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt
index 1308114febbc..e20f0ecb1f3b 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt
@@ -957,6 +957,15 @@ class DesktopRepositoryTest : ShellTestCase() {
assertThat(repo.getActiveTasks(displayId = DEFAULT_DISPLAY)).isEmpty()
}
+ @Test
+ fun getTaskInFullImmersiveState_byDisplay() {
+ repo.setTaskInFullImmersiveState(DEFAULT_DESKTOP_ID, taskId = 1, immersive = true)
+ repo.setTaskInFullImmersiveState(DEFAULT_DESKTOP_ID + 1, taskId = 2, immersive = true)
+
+ assertThat(repo.getTaskInFullImmersiveState(DEFAULT_DESKTOP_ID)).isEqualTo(1)
+ assertThat(repo.getTaskInFullImmersiveState(DEFAULT_DESKTOP_ID + 1)).isEqualTo(2)
+ }
+
class TestListener : DesktopRepository.ActiveTasksListener {
var activeChangesOnDefaultDisplay = 0
var activeChangesOnSecondaryDisplay = 0
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
index 27deb0b6abf6..b3c10d64c3a3 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
@@ -42,6 +42,7 @@ import android.graphics.Rect
import android.os.Binder
import android.os.Bundle
import android.os.Handler
+import android.os.IBinder
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
@@ -99,6 +100,7 @@ import com.android.wm.shell.desktopmode.DesktopTestHelpers.Companion.createSplit
import com.android.wm.shell.desktopmode.persistence.Desktop
import com.android.wm.shell.desktopmode.persistence.DesktopPersistentRepository
import com.android.wm.shell.draganddrop.DragAndDropController
+import com.android.wm.shell.freeform.FreeformTaskTransitionStarter
import com.android.wm.shell.recents.RecentTasksController
import com.android.wm.shell.recents.RecentsTransitionHandler
import com.android.wm.shell.recents.RecentsTransitionStateListener
@@ -144,13 +146,11 @@ import org.mockito.Mockito
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.mock
-import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import org.mockito.Mockito.times
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
-import org.mockito.kotlin.argThat
import org.mockito.kotlin.atLeastOnce
import org.mockito.kotlin.capture
import org.mockito.kotlin.eq
@@ -201,6 +201,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
private lateinit var mockInteractionJankMonitor: InteractionJankMonitor
@Mock private lateinit var mockSurface: SurfaceControl
@Mock private lateinit var taskbarDesktopTaskListener: TaskbarDesktopTaskListener
+ @Mock private lateinit var freeformTaskTransitionStarter: FreeformTaskTransitionStarter
@Mock private lateinit var mockHandler: Handler
@Mock lateinit var persistentRepository: DesktopPersistentRepository
@@ -266,6 +267,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
controller = createController()
controller.setSplitScreenController(splitScreenController)
+ controller.freeformTaskTransitionStarter = freeformTaskTransitionStarter
shellInit.init()
@@ -1542,75 +1544,142 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
- fun onDesktopWindowMinimize_noActiveTask_doesntUpdateTransaction() {
- val wct = WindowContainerTransaction()
- controller.onDesktopWindowMinimize(wct, taskId = 1)
- // Nothing happens.
- assertThat(wct.hierarchyOps).isEmpty()
+ fun onDesktopWindowMinimize_noActiveTask_doesntRemoveWallpaper() {
+ val task = setUpFreeformTask(active = false)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+ val wallpaperToken = MockToken().token()
+ taskRepository.wallpaperActivityToken = wallpaperToken
+
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK && hop.container == wallpaperToken.asBinder()
+ }
}
@Test
- fun onDesktopWindowMinimize_singleActiveTask_noWallpaperActivityToken_doesntUpdateTransaction() {
- val task = setUpFreeformTask()
- val wct = WindowContainerTransaction()
- controller.onDesktopWindowMinimize(wct, taskId = task.taskId)
- // Nothing happens.
- assertThat(wct.hierarchyOps).isEmpty()
+ fun onDesktopWindowMinimize_singleActiveTask_noWallpaperActivityToken_doesntRemoveWallpaper() {
+ val task = setUpFreeformTask(active = true)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK
+ }
}
@Test
fun onDesktopWindowMinimize_singleActiveTask_hasWallpaperActivityToken_removesWallpaper() {
val task = setUpFreeformTask()
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
- val wct = WindowContainerTransaction()
// The only active task is being minimized.
- controller.onDesktopWindowMinimize(wct, taskId = task.taskId)
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
// Adds remove wallpaper operation
- wct.assertRemoveAt(index = 0, wallpaperToken)
+ captor.value.assertRemoveAt(index = 0, wallpaperToken)
}
@Test
- fun onDesktopWindowMinimize_singleActiveTask_alreadyMinimized_doesntUpdateTransaction() {
+ fun onDesktopWindowMinimize_singleActiveTask_alreadyMinimized_doesntRemoveWallpaper() {
val task = setUpFreeformTask()
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
taskRepository.minimizeTask(DEFAULT_DISPLAY, task.taskId)
- val wct = WindowContainerTransaction()
// The only active task is already minimized.
- controller.onDesktopWindowMinimize(wct, taskId = task.taskId)
- // Doesn't modify transaction
- assertThat(wct.hierarchyOps).isEmpty()
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK && hop.container == wallpaperToken.asBinder()
+ }
}
@Test
- fun onDesktopWindowMinimize_multipleActiveTasks_doesntUpdateTransaction() {
- val task1 = setUpFreeformTask()
- setUpFreeformTask()
+ fun onDesktopWindowMinimize_multipleActiveTasks_doesntRemoveWallpaper() {
+ val task1 = setUpFreeformTask(active = true)
+ setUpFreeformTask(active = true)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
- val wct = WindowContainerTransaction()
- controller.onDesktopWindowMinimize(wct, taskId = task1.taskId)
- // Doesn't modify transaction
- assertThat(wct.hierarchyOps).isEmpty()
+ controller.minimizeTask(task1)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK && hop.container == wallpaperToken.asBinder()
+ }
}
@Test
fun onDesktopWindowMinimize_multipleActiveTasks_minimizesTheOnlyVisibleTask_removesWallpaper() {
- val task1 = setUpFreeformTask()
- val task2 = setUpFreeformTask()
+ val task1 = setUpFreeformTask(active = true)
+ val task2 = setUpFreeformTask(active = true)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
taskRepository.minimizeTask(DEFAULT_DISPLAY, task2.taskId)
- val wct = WindowContainerTransaction()
// task1 is the only visible task as task2 is minimized.
- controller.onDesktopWindowMinimize(wct, taskId = task1.taskId)
+ controller.minimizeTask(task1)
// Adds remove wallpaper operation
- wct.assertRemoveAt(index = 0, wallpaperToken)
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ // Adds remove wallpaper operation
+ captor.value.assertRemoveAt(index = 0, wallpaperToken)
+ }
+
+ @Test
+ fun onDesktopWindowMinimize_triesToExitImmersive() {
+ val task = setUpFreeformTask()
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+
+ controller.minimizeTask(task)
+
+ verify(mockDesktopFullImmersiveTransitionHandler).exitImmersiveIfApplicable(any(), eq(task))
+ }
+
+ @Test
+ fun onDesktopWindowMinimize_invokesImmersiveTransitionStartCallback() {
+ val task = setUpFreeformTask()
+ val transition = Binder()
+ val runOnTransit = RunOnStartTransitionCallback()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+ whenever(mockDesktopFullImmersiveTransitionHandler.exitImmersiveIfApplicable(any(), eq(task)))
+ .thenReturn(runOnTransit)
+
+ controller.minimizeTask(task)
+
+ assertThat(runOnTransit.invocations).isEqualTo(1)
+ assertThat(runOnTransit.lastInvoked).isEqualTo(transition)
}
@Test
@@ -3166,27 +3235,23 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
- fun toggleImmersive_enter_resizesToDisplayBounds() {
+ fun toggleImmersive_enter_movesToImmersive() {
val task = setUpFreeformTask(DEFAULT_DISPLAY)
taskRepository.setTaskInFullImmersiveState(DEFAULT_DISPLAY, task.taskId, false /* immersive */)
controller.toggleDesktopTaskFullImmersiveState(task)
- verify(mockDesktopFullImmersiveTransitionHandler).enterImmersive(eq(task), argThat { wct ->
- wct.hasBoundsChange(task.token, Rect())
- })
+ verify(mockDesktopFullImmersiveTransitionHandler).moveTaskToImmersive(task)
}
@Test
- fun toggleImmersive_exit_resizesToStableBounds() {
+ fun toggleImmersive_exit_movesToNonImmersive() {
val task = setUpFreeformTask(DEFAULT_DISPLAY)
taskRepository.setTaskInFullImmersiveState(DEFAULT_DISPLAY, task.taskId, true /* immersive */)
controller.toggleDesktopTaskFullImmersiveState(task)
- verify(mockDesktopFullImmersiveTransitionHandler).exitImmersive(eq(task), argThat { wct ->
- wct.hasBoundsChange(task.token, STABLE_BOUNDS)
- })
+ verify(mockDesktopFullImmersiveTransitionHandler).moveTaskToNonImmersive(task)
}
@Test
@@ -3198,7 +3263,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
task.requestedVisibleTypes = WindowInsets.Type.statusBars()
controller.onTaskInfoChanged(task)
- verify(mockDesktopFullImmersiveTransitionHandler).exitImmersive(eq(task), any())
+ verify(mockDesktopFullImmersiveTransitionHandler).moveTaskToNonImmersive(task)
}
@Test
@@ -3210,7 +3275,113 @@ class DesktopTasksControllerTest : ShellTestCase() {
task.requestedVisibleTypes = WindowInsets.Type.statusBars()
controller.onTaskInfoChanged(task)
- verify(mockDesktopFullImmersiveTransitionHandler, never()).exitImmersive(eq(task), any())
+ verify(mockDesktopFullImmersiveTransitionHandler, never()).moveTaskToNonImmersive(task)
+ }
+
+ @Test
+ fun moveTaskToDesktop_background_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = true)
+ val wct = WindowContainerTransaction()
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, task.displayId)).thenReturn(runOnStartTransit)
+ whenever(enterDesktopTransitionHandler.moveToDesktop(wct, UNKNOWN)).thenReturn(transition)
+
+ controller.moveTaskToDesktop(taskId = task.taskId, wct = wct, transitionSource = UNKNOWN)
+
+ verify(mockDesktopFullImmersiveTransitionHandler).exitImmersiveIfApplicable(wct, task.displayId)
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun moveTaskToDesktop_foreground_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = false)
+ val wct = WindowContainerTransaction()
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, task.displayId)).thenReturn(runOnStartTransit)
+ whenever(enterDesktopTransitionHandler.moveToDesktop(wct, UNKNOWN)).thenReturn(transition)
+
+ controller.moveTaskToDesktop(taskId = task.taskId, wct = wct, transitionSource = UNKNOWN)
+
+ verify(mockDesktopFullImmersiveTransitionHandler).exitImmersiveIfApplicable(wct, task.displayId)
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun moveTaskToFront_background_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = true)
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))).thenReturn(runOnStartTransit)
+ whenever(transitions.startTransition(any(), any(), anyOrNull())).thenReturn(transition)
+
+ controller.moveTaskToFront(task.taskId)
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun moveTaskToFront_foreground_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = false)
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))).thenReturn(runOnStartTransit)
+ whenever(transitions.startTransition(any(), any(), anyOrNull())).thenReturn(transition)
+
+ controller.moveTaskToFront(task.taskId)
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun handleRequest_freeformLaunchToDesktop_attemptsImmersiveExit() {
+ markTaskVisible(setUpFreeformTask())
+ val task = setUpFreeformTask()
+ markTaskVisible(task)
+ val binder = Binder()
+
+ controller.handleRequest(binder, createTransition(task))
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(eq(binder), any(), eq(task.displayId))
+ }
+
+ @Test
+ fun handleRequest_fullscreenLaunchToDesktop_attemptsImmersiveExit() {
+ setUpFreeformTask()
+ val task = setUpFullscreenTask()
+ val binder = Binder()
+
+ controller.handleRequest(binder, createTransition(task))
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(eq(binder), any(), eq(task.displayId))
+ }
+
+ private class RunOnStartTransitionCallback : ((IBinder) -> Unit) {
+ var invocations = 0
+ private set
+ var lastInvoked: IBinder? = null
+ private set
+
+ override fun invoke(transition: IBinder) {
+ invocations++
+ lastInvoked = transition
+ }
+ }
+
+ private fun RunOnStartTransitionCallback.assertOnlyInvocation(transition: IBinder) {
+ assertThat(invocations).isEqualTo(1)
+ assertThat(lastInvoked).isEqualTo(transition)
}
/**
@@ -3291,18 +3462,27 @@ class DesktopTasksControllerTest : ShellTestCase() {
private fun setUpFreeformTask(
displayId: Int = DEFAULT_DISPLAY,
bounds: Rect? = null,
- active: Boolean = true
+ active: Boolean = true,
+ background: Boolean = false,
): RunningTaskInfo {
val task = createFreeformTask(displayId, bounds)
val activityInfo = ActivityInfo()
task.topActivityInfo = activityInfo
- whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ if (background) {
+ whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(null)
+ whenever(recentTasksController.findTaskInBackground(task.taskId))
+ .thenReturn(createTaskInfo(task.taskId))
+ } else {
+ whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ }
if (active) {
taskRepository.addActiveTask(displayId, task.taskId)
taskRepository.updateTaskVisibility(displayId, task.taskId, visible = true)
}
taskRepository.addOrMoveFreeformTaskToTop(displayId, task.taskId)
- runningTasks.add(task)
+ if (!background) {
+ runningTasks.add(task)
+ }
return task
}
@@ -3556,6 +3736,21 @@ private fun WindowContainerTransaction.assertRemoveAt(index: Int, token: WindowC
assertThat(op.container).isEqualTo(token.asBinder())
}
+private fun WindowContainerTransaction.assertNoRemoveAt(index: Int, token: WindowContainerToken) {
+ assertIndexInBounds(index)
+ val op = hierarchyOps[index]
+ assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_REMOVE_TASK)
+ assertThat(op.container).isEqualTo(token.asBinder())
+}
+
+private fun WindowContainerTransaction.hasRemoveAt(index: Int, token: WindowContainerToken) {
+
+ assertIndexInBounds(index)
+ val op = hierarchyOps[index]
+ assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_REMOVE_TASK)
+ assertThat(op.container).isEqualTo(token.asBinder())
+}
+
private fun WindowContainerTransaction.assertPendingIntentAt(index: Int, intent: Intent) {
assertIndexInBounds(index)
val op = hierarchyOps[index]
@@ -3578,13 +3773,6 @@ private fun WindowContainerTransaction.assertLaunchTaskAt(
.isEqualTo(windowingMode)
}
-private fun WindowContainerTransaction.hasBoundsChange(
- token: WindowContainerToken,
- bounds: Rect
-): Boolean = this.changes.any { change ->
- change.key == token.asBinder() && change.value.configuration.windowConfiguration.bounds == bounds
-}
-
private fun WindowContainerTransaction?.anyDensityConfigChange(
token: WindowContainerToken
): Boolean {
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt
index 598df34a310d..fe87aa88a8db 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt
@@ -22,26 +22,38 @@ import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.content.ComponentName
import android.content.Context
import android.content.Intent
+import android.os.IBinder
import android.platform.test.annotations.EnableFlags
import android.view.Display.DEFAULT_DISPLAY
+import android.view.WindowManager
+import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_BACK
import android.window.IWindowContainerToken
import android.window.TransitionInfo
import android.window.TransitionInfo.Change
import android.window.WindowContainerToken
+import android.window.WindowContainerTransaction
+import android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_TASK
import com.android.modules.utils.testing.ExtendedMockitoRule
import com.android.window.flags.Flags
+import com.android.wm.shell.MockToken
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
+import com.google.common.truth.Truth.assertThat
+import com.google.common.truth.Truth.assertWithMessage
import org.junit.Before
import org.junit.Rule
import org.junit.Test
+import org.mockito.ArgumentCaptor
+import org.mockito.ArgumentMatchers.eq
+import org.mockito.ArgumentMatchers.isA
import org.mockito.Mockito
import org.mockito.kotlin.any
+import org.mockito.kotlin.isNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.spy
@@ -130,6 +142,27 @@ class DesktopTasksTransitionObserverTest {
verify(taskRepository).removeFreeformTask(task.displayId, task.taskId)
}
+ @Test
+ fun closeLastTask_wallpaperTokenExists_wallpaperIsRemoved() {
+ val mockTransition = Mockito.mock(IBinder::class.java)
+ val task = createTaskInfo(1, WINDOWING_MODE_FREEFORM)
+ val wallpaperToken = MockToken().token()
+ whenever(taskRepository.getVisibleTaskCount(task.displayId)).thenReturn(1)
+ whenever(taskRepository.wallpaperActivityToken).thenReturn(wallpaperToken)
+
+ transitionObserver.onTransitionReady(
+ transition = mockTransition,
+ info = createCloseTransition(task),
+ startTransaction = mock(),
+ finishTransaction = mock(),
+ )
+ transitionObserver.onTransitionFinished(mockTransition, false)
+
+ val wct = getLatestWct(type = TRANSIT_CLOSE)
+ assertThat(wct.hierarchyOps).hasSize(1)
+ wct.assertRemoveAt(index = 0, wallpaperToken)
+ }
+
private fun createBackNavigationTransition(
task: RunningTaskInfo?
): TransitionInfo {
@@ -160,6 +193,48 @@ class DesktopTasksTransitionObserverTest {
}
}
+ private fun createCloseTransition(
+ task: RunningTaskInfo?
+ ): TransitionInfo {
+ return TransitionInfo(TRANSIT_CLOSE, 0 /* flags */).apply {
+ addChange(
+ Change(mock(), mock()).apply {
+ mode = TRANSIT_CLOSE
+ parent = null
+ taskInfo = task
+ flags = flags
+ }
+ )
+ }
+ }
+
+ private fun getLatestWct(
+ @WindowManager.TransitionType type: Int = TRANSIT_OPEN,
+ handlerClass: Class<out Transitions.TransitionHandler>? = null
+ ): WindowContainerTransaction {
+ val arg = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ if (handlerClass == null) {
+ Mockito.verify(transitions).startTransition(eq(type), arg.capture(), isNull())
+ } else {
+ Mockito.verify(transitions)
+ .startTransition(eq(type), arg.capture(), isA(handlerClass))
+ }
+ return arg.value
+ }
+
+ private fun WindowContainerTransaction.assertRemoveAt(index: Int, token: WindowContainerToken) {
+ assertIndexInBounds(index)
+ val op = hierarchyOps[index]
+ assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_REMOVE_TASK)
+ assertThat(op.container).isEqualTo(token.asBinder())
+ }
+
+ private fun WindowContainerTransaction.assertIndexInBounds(index: Int) {
+ assertWithMessage("WCT does not have a hierarchy operation at index $index")
+ .that(hierarchyOps.size)
+ .isGreaterThan(index)
+ }
+
private fun createTaskInfo(id: Int, windowingMode: Int = WINDOWING_MODE_FREEFORM) =
RunningTaskInfo().apply {
taskId = id
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java
index 36e0427a7e22..f95b0d1e7287 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java
@@ -178,6 +178,7 @@ public final class FreeformTaskListenerTests extends ShellTestCase {
mFreeformTaskListener.onTaskVanished(task);
verify(mDesktopRepository, never()).minimizeTask(task.displayId, task.taskId);
+ verify(mDesktopRepository).removeClosingTask(task.taskId);
verify(mDesktopRepository).removeFreeformTask(task.displayId, task.taskId);
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java
index 145819f3f727..7ae0bcd13681 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java
@@ -329,7 +329,7 @@ public class FreeformTaskTransitionObserverTest {
mTransitionObserver.onTransitionReady(transition, info, startT, finishT);
- verify(mDesktopFullImmersiveTransitionHandler).onTransitionReady(transition);
+ verify(mDesktopFullImmersiveTransitionHandler).onTransitionReady(transition, info);
}
private static TransitionInfo.Change createChange(int mode, int taskId, int windowingMode) {
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorationTests.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorationTests.kt
index 0f16b9d0fa7e..5ebf5170bf86 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorationTests.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorationTests.kt
@@ -49,7 +49,8 @@ class CaptionWindowDecorationTests : ShellTestCase() {
false,
true /* isStatusBarVisible */,
false /* isKeyguardVisibleAndOccluded */,
- InsetsState()
+ InsetsState(),
+ true /* hasGlobalFocus */
)
Truth.assertThat(relayoutParams.hasInputFeatureSpy()).isTrue()
@@ -70,7 +71,8 @@ class CaptionWindowDecorationTests : ShellTestCase() {
false,
true /* isStatusBarVisible */,
false /* isKeyguardVisibleAndOccluded */,
- InsetsState()
+ InsetsState(),
+ true /* hasGlobalFocus */
)
Truth.assertThat(relayoutParams.hasInputFeatureSpy()).isFalse()
@@ -87,7 +89,8 @@ class CaptionWindowDecorationTests : ShellTestCase() {
false,
true /* isStatusBarVisible */,
false /* isKeyguardVisibleAndOccluded */,
- InsetsState()
+ InsetsState(),
+ true /* hasGlobalFocus */
)
Truth.assertThat(relayoutParams.mOccludingCaptionElements.size).isEqualTo(2)
Truth.assertThat(relayoutParams.mOccludingCaptionElements[0].mAlignment).isEqualTo(
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
index 4aa7e18b4b84..175fbd2396e3 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
@@ -100,6 +100,7 @@ import com.android.wm.shell.splitscreen.SplitScreenController
import com.android.wm.shell.sysui.ShellCommandHandler
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
+import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel.DesktopModeKeyguardChangeListener
import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel.DesktopModeOnInsetsChangedListener
@@ -126,7 +127,6 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.any
-import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.argThat
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doNothing
@@ -192,6 +192,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
DesktopModeWindowDecorViewModel.TaskPositionerFactory
@Mock private lateinit var mockTaskPositioner: TaskPositioner
@Mock private lateinit var mockAppHandleEducationController: AppHandleEducationController
+ @Mock private lateinit var mockFocusTransitionObserver: FocusTransitionObserver
@Mock private lateinit var mockCaptionHandleRepository: WindowDecorCaptionHandleRepository
private lateinit var spyContext: TestableContext
@@ -254,7 +255,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
mockAppHandleEducationController,
mockCaptionHandleRepository,
Optional.of(mockActivityOrientationChangeHandler),
- mockTaskPositionerFactory
+ mockTaskPositionerFactory,
+ mockFocusTransitionObserver
)
desktopModeWindowDecorViewModel.setSplitScreenController(mockSplitScreenController)
whenever(mockDisplayController.getDisplayLayout(any())).thenReturn(mockDisplayLayout)
@@ -455,24 +457,13 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
onClickListenerCaptor.value.onClick(view)
- val transactionCaptor = argumentCaptor<WindowContainerTransaction>()
- verify(mockFreeformTaskTransitionStarter)
- .startMinimizedModeTransition(transactionCaptor.capture())
- val wct = transactionCaptor.firstValue
-
- verify(mockTasksLimiter).addPendingMinimizeChange(
- anyOrNull(), eq(DEFAULT_DISPLAY), eq(decor.mTaskInfo.taskId))
-
- assertEquals(1, wct.getHierarchyOps().size)
- assertEquals(HierarchyOp.HIERARCHY_OP_TYPE_REORDER, wct.getHierarchyOps().get(0).getType())
- assertFalse(wct.getHierarchyOps().get(0).getToTop())
- assertEquals(decor.mTaskInfo.token.asBinder(), wct.getHierarchyOps().get(0).getContainer())
+ verify(mockDesktopTasksController).minimizeTask(decor.mTaskInfo)
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY)
fun testDecorationIsCreatedForTopTranslucentActivitiesWithStyleFloating() {
- val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN, focused = true).apply {
+ val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN).apply {
isTopActivityTransparent = true
isTopActivityStyleFloating = true
numActivities = 1
@@ -487,7 +478,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY)
fun testDecorationIsNotCreatedForTopTranslucentActivitiesWithoutStyleFloating() {
- val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN, focused = true).apply {
+ val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN).apply {
isTopActivityTransparent = true
isTopActivityStyleFloating = false
numActivities = 1
@@ -500,7 +491,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY)
fun testDecorationIsNotCreatedForSystemUIActivities() {
- val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN, focused = true)
+ val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN)
// Set task as systemUI package
val systemUIPackageName = context.resources.getString(
@@ -573,7 +564,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
// Simulate default enforce device restrictions system property
whenever(DesktopModeStatus.enforceDeviceRestrictions()).thenReturn(true)
- val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN, focused = true)
+ val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN)
// Simulate device that doesn't support desktop mode
doReturn(false).`when` { DesktopModeStatus.isDesktopModeSupported(any()) }
@@ -589,7 +580,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
// Simulate device that doesn't support desktop mode
doReturn(false).`when` { DesktopModeStatus.isDesktopModeSupported(any()) }
- val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN, focused = true)
+ val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN)
setUpMockDecorationsForTasks(task)
onTaskOpening(task)
@@ -602,7 +593,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
// Simulate default enforce device restrictions system property
whenever(DesktopModeStatus.enforceDeviceRestrictions()).thenReturn(true)
- val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN, focused = true)
+ val task = createTask(windowingMode = WINDOWING_MODE_FULLSCREEN)
doReturn(true).`when` { DesktopModeStatus.isDesktopModeSupported(any()) }
setUpMockDecorationsForTasks(task)
@@ -1045,7 +1036,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
fun testOnDisplayRotation_tasksOutOfValidArea_taskBoundsUpdated() {
- val task = createTask(focused = true, windowingMode = WINDOWING_MODE_FREEFORM)
+ val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
val secondTask =
createTask(displayId = task.displayId, windowingMode = WINDOWING_MODE_FREEFORM)
val thirdTask =
@@ -1073,7 +1064,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
fun testOnDisplayRotation_taskInValidArea_taskBoundsNotUpdated() {
- val task = createTask(focused = true, windowingMode = WINDOWING_MODE_FREEFORM)
+ val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
val secondTask =
createTask(displayId = task.displayId, windowingMode = WINDOWING_MODE_FREEFORM)
val thirdTask =
@@ -1100,7 +1091,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
fun testOnDisplayRotation_sameOrientationRotation_taskBoundsNotUpdated() {
- val task = createTask(focused = true, windowingMode = WINDOWING_MODE_FREEFORM)
+ val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
val secondTask =
createTask(displayId = task.displayId, windowingMode = WINDOWING_MODE_FREEFORM)
val thirdTask =
@@ -1124,7 +1115,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
fun testOnDisplayRotation_differentDisplayId_taskBoundsNotUpdated() {
- val task = createTask(focused = true, windowingMode = WINDOWING_MODE_FREEFORM)
+ val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
val secondTask = createTask(displayId = -2, windowingMode = WINDOWING_MODE_FREEFORM)
val thirdTask = createTask(displayId = -3, windowingMode = WINDOWING_MODE_FREEFORM)
@@ -1149,7 +1140,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
@Test
fun testOnDisplayRotation_nonFreeformTask_taskBoundsNotUpdated() {
- val task = createTask(focused = true, windowingMode = WINDOWING_MODE_FREEFORM)
+ val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
val secondTask = createTask(displayId = -2, windowingMode = WINDOWING_MODE_FULLSCREEN)
val thirdTask = createTask(displayId = -3, windowingMode = WINDOWING_MODE_PINNED)
@@ -1322,7 +1313,6 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
displayId: Int = DEFAULT_DISPLAY,
@WindowingMode windowingMode: Int,
activityType: Int = ACTIVITY_TYPE_STANDARD,
- focused: Boolean = true,
activityInfo: ActivityInfo = ActivityInfo(),
requestingImmersive: Boolean = false
): RunningTaskInfo {
@@ -1333,7 +1323,6 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
.setActivityType(activityType)
.build().apply {
topActivityInfo = activityInfo
- isFocused = focused
isResizeable = true
requestedVisibleTypes = if (requestingImmersive) {
statusBars().inv()
@@ -1351,7 +1340,6 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
any(), any(), any(), any(), any(), any(), any())
).thenReturn(decoration)
decoration.mTaskInfo = task
- whenever(decoration.isFocused).thenReturn(task.isFocused)
whenever(decoration.user).thenReturn(mockUserHandle)
if (task.windowingMode == WINDOWING_MODE_MULTI_WINDOW) {
whenever(mockSplitScreenController.isTaskInSplitScreen(task.taskId))
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java
index 35be80e87ecd..1d11d2e8ff06 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java
@@ -279,7 +279,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
final DesktopModeWindowDecoration spyWindowDecor =
spy(createWindowDecoration(taskInfo));
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, false /* hasGlobalFocus */);
// Menus should close if open before the task being invisible causes relayout to return.
verify(spyWindowDecor).closeHandleMenu();
@@ -298,7 +298,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mShadowRadiusId).isNotEqualTo(Resources.ID_NULL);
}
@@ -318,7 +319,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mCornerRadius).isGreaterThan(0);
}
@@ -343,7 +345,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mWindowDecorConfig.densityDpi).isEqualTo(customTaskDensity);
}
@@ -369,7 +372,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mWindowDecorConfig.densityDpi).isEqualTo(systemDensity);
}
@@ -391,7 +395,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.hasInputFeatureSpy()).isTrue();
}
@@ -412,7 +417,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.hasInputFeatureSpy()).isFalse();
}
@@ -432,7 +438,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.hasInputFeatureSpy()).isFalse();
}
@@ -452,7 +459,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(hasNoInputChannelFeature(relayoutParams)).isFalse();
}
@@ -473,7 +481,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(hasNoInputChannelFeature(relayoutParams)).isTrue();
}
@@ -494,7 +503,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(hasNoInputChannelFeature(relayoutParams)).isTrue();
}
@@ -516,7 +526,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat((relayoutParams.mInsetSourceFlags & FLAG_FORCE_CONSUMING) != 0).isTrue();
}
@@ -539,7 +550,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat((relayoutParams.mInsetSourceFlags & FLAG_FORCE_CONSUMING) == 0).isTrue();
}
@@ -560,7 +572,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(
(relayoutParams.mInsetSourceFlags & FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR) != 0)
@@ -583,7 +596,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(
(relayoutParams.mInsetSourceFlags & FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR) == 0)
@@ -612,7 +626,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ true,
- insetsState);
+ insetsState,
+ /* hasGlobalFocus= */ true);
// Takes status bar inset as padding, ignores caption bar inset.
assertThat(relayoutParams.mCaptionTopPadding).isEqualTo(50);
@@ -634,7 +649,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ true,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsInsetSource).isFalse();
}
@@ -655,7 +671,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ false,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
// Header is always shown because it's assumed the status bar is always visible.
assertThat(relayoutParams.mIsCaptionVisible).isTrue();
@@ -676,7 +693,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsCaptionVisible).isTrue();
}
@@ -696,7 +714,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ false,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsCaptionVisible).isFalse();
}
@@ -716,7 +735,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ true,
/* inFullImmersiveMode */ false,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsCaptionVisible).isFalse();
}
@@ -737,7 +757,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ true,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsCaptionVisible).isTrue();
@@ -750,7 +771,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ false,
/* isKeyguardVisibleAndOccluded */ false,
/* inFullImmersiveMode */ true,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsCaptionVisible).isFalse();
}
@@ -771,7 +793,8 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
/* isStatusBarVisible */ true,
/* isKeyguardVisibleAndOccluded */ true,
/* inFullImmersiveMode */ true,
- new InsetsState());
+ new InsetsState(),
+ /* hasGlobalFocus= */ true);
assertThat(relayoutParams.mIsCaptionVisible).isFalse();
}
@@ -782,7 +805,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
final DesktopModeWindowDecoration spyWindowDecor = spy(createWindowDecoration(taskInfo));
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockTransaction).apply();
verify(mMockRootSurfaceControl, never()).applyTransactionOnDraw(any());
@@ -797,7 +820,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
// Make non-resizable to avoid dealing with input-permissions (MONITOR_INPUT)
taskInfo.isResizeable = false;
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockTransaction, never()).apply();
verify(mMockRootSurfaceControl).applyTransactionOnDraw(mMockTransaction);
@@ -809,7 +832,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
final DesktopModeWindowDecoration spyWindowDecor = spy(createWindowDecoration(taskInfo));
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlViewHostFactory, never()).create(any(), any(), any());
}
@@ -821,7 +844,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
ArgumentCaptor<Runnable> runnableArgument = ArgumentCaptor.forClass(Runnable.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Once for view host, the other for the AppHandle input layer.
verify(mMockHandler, times(2)).post(runnableArgument.capture());
@@ -838,7 +861,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
// Make non-resizable to avoid dealing with input-permissions (MONITOR_INPUT)
taskInfo.isResizeable = false;
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlViewHostFactory).create(any(), any(), any());
verify(mMockHandler, never()).post(any());
@@ -850,11 +873,11 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
final DesktopModeWindowDecoration spyWindowDecor = spy(createWindowDecoration(taskInfo));
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
ArgumentCaptor<Runnable> runnableArgument = ArgumentCaptor.forClass(Runnable.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Once for view host, the other for the AppHandle input layer.
verify(mMockHandler, times(2)).post(runnableArgument.capture());
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockHandler).removeCallbacks(runnableArgument.getValue());
}
@@ -865,7 +888,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
final DesktopModeWindowDecoration spyWindowDecor = spy(createWindowDecoration(taskInfo));
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
ArgumentCaptor<Runnable> runnableArgument = ArgumentCaptor.forClass(Runnable.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Once for view host, the other for the AppHandle input layer.
verify(mMockHandler, times(2)).post(runnableArgument.capture());
@@ -998,7 +1021,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
runnableArgument.getValue().run();
// Relayout decor with same captured link
- decor.relayout(taskInfo);
+ decor.relayout(taskInfo, true /* hasGlobalFocus */);
// Verify handle menu's browser link not set to captured link since link is expired
createHandleMenu(decor);
@@ -1147,7 +1170,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
final DesktopModeWindowDecoration spyWindowDecor = spy(createWindowDecoration(taskInfo));
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockCaptionHandleRepository, never()).notifyCaptionChanged(any());
}
@@ -1164,7 +1187,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
ArgumentCaptor<CaptionState> captionStateArgumentCaptor = ArgumentCaptor.forClass(
CaptionState.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockCaptionHandleRepository, atLeastOnce()).notifyCaptionChanged(
captionStateArgumentCaptor.capture());
@@ -1191,7 +1214,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
ArgumentCaptor<CaptionState> captionStateArgumentCaptor = ArgumentCaptor.forClass(
CaptionState.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockAppHeaderViewHolder, atLeastOnce()).runOnAppChipGlobalLayout(
runnableArgumentCaptor.capture());
runnableArgumentCaptor.getValue().invoke();
@@ -1214,7 +1237,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
ArgumentCaptor<CaptionState> captionStateArgumentCaptor = ArgumentCaptor.forClass(
CaptionState.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, false /* hasGlobalFocus */);
verify(mMockCaptionHandleRepository, atLeastOnce()).notifyCaptionChanged(
captionStateArgumentCaptor.capture());
@@ -1234,7 +1257,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
ArgumentCaptor<CaptionState> captionStateArgumentCaptor = ArgumentCaptor.forClass(
CaptionState.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
createHandleMenu(spyWindowDecor);
verify(mMockCaptionHandleRepository, atLeastOnce()).notifyCaptionChanged(
@@ -1259,7 +1282,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
ArgumentCaptor<CaptionState> captionStateArgumentCaptor = ArgumentCaptor.forClass(
CaptionState.class);
- spyWindowDecor.relayout(taskInfo);
+ spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
createHandleMenu(spyWindowDecor);
spyWindowDecor.closeHandleMenu();
@@ -1356,7 +1379,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
windowDecor.setOpenInBrowserClickListener(mMockOpenInBrowserClickListener);
windowDecor.mDecorWindowContext = mContext;
if (relayout) {
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
}
return windowDecor;
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt
index 7543fed4b085..ca1f9abed09e 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt
@@ -624,7 +624,7 @@ class FluidResizeTaskPositionerTest : ShellTestCase() {
@Test
fun testDragResize_resize_resizingTaskReorderedToTopWhenNotFocused() {
- mockWindowDecoration.mTaskInfo.isFocused = false
+ mockWindowDecoration.mHasGlobalFocus = false
taskPositioner.onDragPositioningStart(
CTRL_TYPE_RIGHT, // Resize right
STARTING_BOUNDS.left.toFloat(),
@@ -640,7 +640,7 @@ class FluidResizeTaskPositionerTest : ShellTestCase() {
@Test
fun testDragResize_resize_resizingTaskNotReorderedToTopWhenFocused() {
- mockWindowDecoration.mTaskInfo.isFocused = true
+ mockWindowDecoration.mHasGlobalFocus = true
taskPositioner.onDragPositioningStart(
CTRL_TYPE_RIGHT, // Resize right
STARTING_BOUNDS.left.toFloat(),
@@ -656,7 +656,7 @@ class FluidResizeTaskPositionerTest : ShellTestCase() {
@Test
fun testDragResize_drag_draggedTaskNotReorderedToTop() {
- mockWindowDecoration.mTaskInfo.isFocused = false
+ mockWindowDecoration.mHasGlobalFocus = false
taskPositioner.onDragPositioningStart(
CTRL_TYPE_UNDEFINED, // drag
STARTING_BOUNDS.left.toFloat(),
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt
index 1273ee823159..1dfbd6705bf4 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt
@@ -323,7 +323,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
@Test
fun testDragResize_resize_resizingTaskReorderedToTopWhenNotFocused() = runOnUiThread {
- mockDesktopWindowDecoration.mTaskInfo.isFocused = false
+ mockDesktopWindowDecoration.mHasGlobalFocus = false
taskPositioner.onDragPositioningStart(
CTRL_TYPE_RIGHT, // Resize right
STARTING_BOUNDS.left.toFloat(),
@@ -339,7 +339,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
@Test
fun testDragResize_resize_resizingTaskNotReorderedToTopWhenFocused() = runOnUiThread {
- mockDesktopWindowDecoration.mTaskInfo.isFocused = true
+ mockDesktopWindowDecoration.mHasGlobalFocus = true
taskPositioner.onDragPositioningStart(
CTRL_TYPE_RIGHT, // Resize right
STARTING_BOUNDS.left.toFloat(),
@@ -355,7 +355,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
@Test
fun testDragResize_drag_draggedTaskNotReorderedToTop() = runOnUiThread {
- mockDesktopWindowDecoration.mTaskInfo.isFocused = false
+ mockDesktopWindowDecoration.mHasGlobalFocus = false
taskPositioner.onDragPositioningStart(
CTRL_TYPE_UNDEFINED, // drag
STARTING_BOUNDS.left.toFloat(),
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java
index 54dd15baa4c0..bb41e9c81ece 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java
@@ -203,13 +203,12 @@ public class WindowDecorationTests extends ShellTestCase {
.setPositionInParent(TASK_POSITION_IN_PARENT.x, TASK_POSITION_IN_PARENT.y)
.setVisible(false)
.build();
- taskInfo.isFocused = false;
// Density is 2. Shadow radius is 10px. Caption height is 64px.
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, false /* hasGlobalFocus */);
verify(decorContainerSurfaceBuilder, never()).build();
verify(taskBackgroundSurfaceBuilder, never()).build();
@@ -243,13 +242,12 @@ public class WindowDecorationTests extends ShellTestCase {
.setVisible(true)
.setWindowingMode(WINDOWING_MODE_FREEFORM)
.build();
- taskInfo.isFocused = true;
// Density is 2. Shadow radius is 10px. Caption height is 64px.
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mIsCaptionVisible = true;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(decorContainerSurfaceBuilder).setParent(mMockTaskSurface);
verify(decorContainerSurfaceBuilder).setContainerLayer();
@@ -316,14 +314,13 @@ public class WindowDecorationTests extends ShellTestCase {
.setPositionInParent(TASK_POSITION_IN_PARENT.x, TASK_POSITION_IN_PARENT.y)
.setVisible(true)
.build();
- taskInfo.isFocused = true;
// Density is 2. Shadow radius is 10px. Caption height is 64px.
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mIsCaptionVisible = true;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlViewHost, never()).release();
verify(t, never()).apply();
@@ -333,7 +330,7 @@ public class WindowDecorationTests extends ShellTestCase {
final SurfaceControl.Transaction t2 = mock(SurfaceControl.Transaction.class);
mMockSurfaceControlTransactions.add(t2);
taskInfo.isVisible = false;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, false /* hasGlobalFocus */);
final InOrder releaseOrder = inOrder(t2, mMockSurfaceControlViewHost);
releaseOrder.verify(mMockSurfaceControlViewHost).release();
@@ -361,7 +358,7 @@ public class WindowDecorationTests extends ShellTestCase {
.build();
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// It shouldn't show the window decoration when it can't obtain the display instance.
assertThat(mRelayoutResult.mRootView).isNull();
@@ -417,10 +414,9 @@ public class WindowDecorationTests extends ShellTestCase {
.setPositionInParent(TASK_POSITION_IN_PARENT.x, TASK_POSITION_IN_PARENT.y)
.setVisible(true)
.build();
- taskInfo.isFocused = true;
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
final SurfaceControl additionalWindowSurface = mock(SurfaceControl.class);
final SurfaceControl.Builder additionalWindowSurfaceBuilder =
@@ -470,11 +466,10 @@ public class WindowDecorationTests extends ShellTestCase {
.setPositionInParent(TASK_POSITION_IN_PARENT.x, TASK_POSITION_IN_PARENT.y)
.setVisible(true)
.build();
- taskInfo.isFocused = true;
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(captionContainerSurfaceBuilder).setParent(decorContainerSurface);
verify(captionContainerSurfaceBuilder).setContainerLayer();
@@ -510,11 +505,11 @@ public class WindowDecorationTests extends ShellTestCase {
.setPositionInParent(TASK_POSITION_IN_PARENT.x, TASK_POSITION_IN_PARENT.y)
.setVisible(true)
.build();
- taskInfo.isFocused = true;
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo, true /* applyStartTransactionOnDraw */);
+ windowDecor.relayout(taskInfo, true /* applyStartTransactionOnDraw */,
+ true /* hasGlobalFocus */);
verify(mMockRootSurfaceControl).applyTransactionOnDraw(mMockSurfaceControlStartT);
}
@@ -549,10 +544,9 @@ public class WindowDecorationTests extends ShellTestCase {
.setVisible(true)
.setWindowingMode(WINDOWING_MODE_FREEFORM)
.build();
- taskInfo.isFocused = true;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlStartT).setColor(mMockTaskSurface, new float[]{1.f, 1.f, 0.f});
@@ -575,7 +569,7 @@ public class WindowDecorationTests extends ShellTestCase {
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mIsCaptionVisible = true;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockWindowContainerTransaction).addInsetsSource(eq(taskInfo.token), any(),
eq(0) /* index */, eq(captionBar()), any(), any(), anyInt());
@@ -611,10 +605,9 @@ public class WindowDecorationTests extends ShellTestCase {
.setVisible(true)
.setWindowingMode(WINDOWING_MODE_FULLSCREEN)
.build();
- taskInfo.isFocused = true;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlStartT).unsetColor(mMockTaskSurface);
@@ -635,7 +628,7 @@ public class WindowDecorationTests extends ShellTestCase {
// Hidden from the beginning, so no insets were ever added.
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mIsCaptionVisible = false;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Never added.
verify(mMockWindowContainerTransaction, never()).addInsetsSource(eq(taskInfo.token), any(),
@@ -663,7 +656,7 @@ public class WindowDecorationTests extends ShellTestCase {
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mIsInsetSource = false;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Never added.
verify(mMockWindowContainerTransaction, never()).addInsetsSource(eq(taskInfo.token), any(),
@@ -687,11 +680,11 @@ public class WindowDecorationTests extends ShellTestCase {
mRelayoutParams.mIsCaptionVisible = true;
mRelayoutParams.mIsInsetSource = true;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
mRelayoutParams.mIsCaptionVisible = true;
mRelayoutParams.mIsInsetSource = false;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Insets should be removed.
verify(mMockWindowContainerTransaction).removeInsetsSource(eq(taskInfo.token), any(),
@@ -715,7 +708,7 @@ public class WindowDecorationTests extends ShellTestCase {
// Relayout will add insets.
mRelayoutParams.mIsCaptionVisible = true;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockWindowContainerTransaction).addInsetsSource(eq(taskInfo.token), any(),
eq(0) /* index */, eq(captionBar()), any(), any(), anyInt());
verify(mMockWindowContainerTransaction).addInsetsSource(eq(taskInfo.token), any(),
@@ -768,10 +761,10 @@ public class WindowDecorationTests extends ShellTestCase {
final ActivityManager.RunningTaskInfo firstTaskInfo =
builder.setToken(token).setBounds(new Rect(0, 0, 1000, 1000)).build();
final TestWindowDecoration windowDecor = createWindowDecoration(firstTaskInfo);
- windowDecor.relayout(firstTaskInfo);
+ windowDecor.relayout(firstTaskInfo, true /* hasGlobalFocus */);
final ActivityManager.RunningTaskInfo secondTaskInfo =
builder.setToken(token).setBounds(new Rect(50, 50, 1000, 1000)).build();
- windowDecor.relayout(secondTaskInfo);
+ windowDecor.relayout(secondTaskInfo, true /* hasGlobalFocus */);
// Insets should be applied twice.
verify(mMockWindowContainerTransaction, times(2)).addInsetsSource(eq(token), any(),
@@ -796,10 +789,10 @@ public class WindowDecorationTests extends ShellTestCase {
final ActivityManager.RunningTaskInfo firstTaskInfo =
builder.setToken(token).setBounds(new Rect(0, 0, 1000, 1000)).build();
final TestWindowDecoration windowDecor = createWindowDecoration(firstTaskInfo);
- windowDecor.relayout(firstTaskInfo);
+ windowDecor.relayout(firstTaskInfo, true /* hasGlobalFocus */);
final ActivityManager.RunningTaskInfo secondTaskInfo =
builder.setToken(token).setBounds(new Rect(0, 0, 1000, 1000)).build();
- windowDecor.relayout(secondTaskInfo);
+ windowDecor.relayout(secondTaskInfo, true /* hasGlobalFocus */);
// Insets should only need to be applied once.
verify(mMockWindowContainerTransaction, times(1)).addInsetsSource(eq(token), any(),
@@ -824,7 +817,7 @@ public class WindowDecorationTests extends ShellTestCase {
mRelayoutParams.mIsCaptionVisible = true;
mRelayoutParams.mInsetSourceFlags =
FLAG_FORCE_CONSUMING | FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
// Caption inset source should add params' flags.
verify(mMockWindowContainerTransaction).addInsetsSource(eq(token), any(),
@@ -845,14 +838,13 @@ public class WindowDecorationTests extends ShellTestCase {
.setVisible(true)
.setWindowingMode(WINDOWING_MODE_FREEFORM)
.build();
- taskInfo.isFocused = true;
// Density is 2. Shadow radius is 10px. Caption height is 64px.
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mSetTaskPositionAndCrop = false;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlStartT, never()).setWindowCrop(
eq(mMockTaskSurface), anyInt(), anyInt());
@@ -875,13 +867,12 @@ public class WindowDecorationTests extends ShellTestCase {
.setVisible(true)
.setWindowingMode(WINDOWING_MODE_FREEFORM)
.build();
- taskInfo.isFocused = true;
// Density is 2. Shadow radius is 10px. Caption height is 64px.
taskInfo.configuration.densityDpi = DisplayMetrics.DENSITY_DEFAULT * 2;
final TestWindowDecoration windowDecor = createWindowDecoration(taskInfo);
mRelayoutParams.mSetTaskPositionAndCrop = true;
- windowDecor.relayout(taskInfo);
+ windowDecor.relayout(taskInfo, true /* hasGlobalFocus */);
verify(mMockSurfaceControlStartT).setWindowCrop(
eq(mMockTaskSurface), anyInt(), anyInt());
@@ -932,12 +923,12 @@ public class WindowDecorationTests extends ShellTestCase {
when(mMockDisplayController.getInsetsState(task.displayId))
.thenReturn(createInsetsState(statusBars(), true /* visible */));
final TestWindowDecoration decor = spy(createWindowDecoration(task));
- decor.relayout(task);
+ decor.relayout(task, true /* hasGlobalFocus */);
assertTrue(decor.mIsStatusBarVisible);
decor.onInsetsStateChanged(createInsetsState(statusBars(), false /* visible */));
- verify(decor, times(2)).relayout(task);
+ verify(decor, times(2)).relayout(task, true /* hasGlobalFocus */);
}
@Test
@@ -947,11 +938,11 @@ public class WindowDecorationTests extends ShellTestCase {
when(mMockDisplayController.getInsetsState(task.displayId))
.thenReturn(createInsetsState(statusBars(), true /* visible */));
final TestWindowDecoration decor = spy(createWindowDecoration(task));
- decor.relayout(task);
+ decor.relayout(task, true /* hasGlobalFocus */);
decor.onInsetsStateChanged(createInsetsState(statusBars(), true /* visible */));
- verify(decor, times(1)).relayout(task);
+ verify(decor, times(1)).relayout(task, true /* hasGlobalFocus */);
}
@Test
@@ -960,13 +951,13 @@ public class WindowDecorationTests extends ShellTestCase {
when(mMockDisplayController.getInsetsState(task.displayId))
.thenReturn(createInsetsState(statusBars(), true /* visible */));
final TestWindowDecoration decor = spy(createWindowDecoration(task));
- decor.relayout(task);
+ decor.relayout(task, true /* hasGlobalFocus */);
assertFalse(decor.mIsKeyguardVisibleAndOccluded);
decor.onKeyguardStateChanged(true /* visible */, true /* occluding */);
assertTrue(decor.mIsKeyguardVisibleAndOccluded);
- verify(decor, times(2)).relayout(task);
+ verify(decor, times(2)).relayout(task, true /* hasGlobalFocus */);
}
@Test
@@ -975,19 +966,18 @@ public class WindowDecorationTests extends ShellTestCase {
when(mMockDisplayController.getInsetsState(task.displayId))
.thenReturn(createInsetsState(statusBars(), true /* visible */));
final TestWindowDecoration decor = spy(createWindowDecoration(task));
- decor.relayout(task);
+ decor.relayout(task, true /* hasGlobalFocus */);
assertFalse(decor.mIsKeyguardVisibleAndOccluded);
decor.onKeyguardStateChanged(false /* visible */, true /* occluding */);
- verify(decor, times(1)).relayout(task);
+ verify(decor, times(1)).relayout(task, true /* hasGlobalFocus */);
}
private ActivityManager.RunningTaskInfo createTaskInfo() {
final ActivityManager.RunningTaskInfo taskInfo = new TestRunningTaskInfoBuilder()
.setVisible(true)
.build();
- taskInfo.isFocused = true;
return taskInfo;
}
@@ -1055,8 +1045,8 @@ public class WindowDecorationTests extends ShellTestCase {
}
@Override
- void relayout(ActivityManager.RunningTaskInfo taskInfo) {
- relayout(taskInfo, false /* applyStartTransactionOnDraw */);
+ void relayout(ActivityManager.RunningTaskInfo taskInfo, boolean hasGlobalFocus) {
+ relayout(taskInfo, false /* applyStartTransactionOnDraw */, hasGlobalFocus);
}
@Override
@@ -1078,10 +1068,11 @@ public class WindowDecorationTests extends ShellTestCase {
}
void relayout(ActivityManager.RunningTaskInfo taskInfo,
- boolean applyStartTransactionOnDraw) {
+ boolean applyStartTransactionOnDraw, boolean hasGlobalFocus) {
mRelayoutParams.mRunningTaskInfo = taskInfo;
mRelayoutParams.mApplyStartTransactionOnDraw = applyStartTransactionOnDraw;
mRelayoutParams.mLayoutResId = R.layout.caption_layout;
+ mRelayoutParams.mHasGlobalFocus = hasGlobalFocus;
relayout(mRelayoutParams, mMockSurfaceControlStartT, mMockSurfaceControlFinishT,
mMockWindowContainerTransaction, mMockView, mRelayoutResult);
}
diff --git a/libs/appfunctions/api/current.txt b/libs/appfunctions/api/current.txt
index bc269fedddfe..e9845c1d9f13 100644
--- a/libs/appfunctions/api/current.txt
+++ b/libs/appfunctions/api/current.txt
@@ -15,7 +15,8 @@ package com.google.android.appfunctions.sidecar {
public abstract class AppFunctionService extends android.app.Service {
ctor public AppFunctionService();
method @NonNull public final android.os.IBinder onBind(@Nullable android.content.Intent);
- method @MainThread public void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
+ method @MainThread public void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull String, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
+ method @Deprecated @MainThread public void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
method @Deprecated @MainThread public void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
field @NonNull public static final String BIND_APP_FUNCTION_SERVICE = "android.permission.BIND_APP_FUNCTION_SERVICE";
field @NonNull public static final String SERVICE_INTERFACE = "android.app.appfunctions.AppFunctionService";
diff --git a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java
index 6e91de6bbcf2..2a168e871713 100644
--- a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java
+++ b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java
@@ -24,8 +24,8 @@ import android.annotation.Nullable;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
-import android.os.IBinder;
import android.os.CancellationSignal;
+import android.os.IBinder;
import android.util.Log;
import java.util.function.Consumer;
@@ -71,18 +71,21 @@ public abstract class AppFunctionService extends Service {
private final Binder mBinder =
android.app.appfunctions.AppFunctionService.createBinder(
/* context= */ this,
- /* onExecuteFunction= */ (platformRequest, cancellationSignal, callback) -> {
+ /* onExecuteFunction= */ (platformRequest,
+ callingPackage,
+ cancellationSignal,
+ callback) -> {
AppFunctionService.this.onExecuteFunction(
SidecarConverter.getSidecarExecuteAppFunctionRequest(
platformRequest),
+ callingPackage,
cancellationSignal,
(sidecarResponse) -> {
callback.accept(
SidecarConverter.getPlatformExecuteAppFunctionResponse(
sidecarResponse));
});
- }
- );
+ });
@NonNull
@Override
@@ -107,11 +110,49 @@ public abstract class AppFunctionService extends Service {
* thread and dispatch the result with the given callback. You should always report back the
* result using the callback, no matter if the execution was successful or not.
*
+ * <p>This method also accepts a {@link CancellationSignal} that the app should listen to cancel
+ * the execution of function if requested by the system.
+ *
+ * @param request The function execution request.
+ * @param callingPackage The package name of the app that is requesting the execution.
+ * @param cancellationSignal A signal to cancel the execution.
+ * @param callback A callback to report back the result.
+ */
+ @MainThread
+ public void onExecuteFunction(
+ @NonNull ExecuteAppFunctionRequest request,
+ @NonNull String callingPackage,
+ @NonNull CancellationSignal cancellationSignal,
+ @NonNull Consumer<ExecuteAppFunctionResponse> callback) {
+ onExecuteFunction(request, cancellationSignal, callback);
+ }
+
+ /**
+ * Called by the system to execute a specific app function.
+ *
+ * <p>This method is triggered when the system requests your AppFunctionService to handle a
+ * particular function you have registered and made available.
+ *
+ * <p>To ensure proper routing of function requests, assign a unique identifier to each
+ * function. This identifier doesn't need to be globally unique, but it must be unique within
+ * your app. For example, a function to order food could be identified as "orderFood". In most
+ * cases this identifier should come from the ID automatically generated by the AppFunctions
+ * SDK. You can determine the specific function to invoke by calling {@link
+ * ExecuteAppFunctionRequest#getFunctionIdentifier()}.
+ *
+ * <p>This method is always triggered in the main thread. You should run heavy tasks on a worker
+ * thread and dispatch the result with the given callback. You should always report back the
+ * result using the callback, no matter if the execution was successful or not.
+ *
* @param request The function execution request.
* @param cancellationSignal A {@link CancellationSignal} to cancel the request.
* @param callback A callback to report back the result.
+ * @deprecated Use {@link #onExecuteFunction(ExecuteAppFunctionRequest, String,
+ * CancellationSignal, Consumer)} instead. This method will be removed once usage references
+ * are updated.
*/
@MainThread
+ @Deprecated
public void onExecuteFunction(
@NonNull ExecuteAppFunctionRequest request,
@NonNull CancellationSignal cancellationSignal,
@@ -138,7 +179,6 @@ public abstract class AppFunctionService extends Service {
*
* @param request The function execution request.
* @param callback A callback to report back the result.
- *
* @deprecated Use {@link #onExecuteFunction(ExecuteAppFunctionRequest, CancellationSignal,
* Consumer)} instead. This method will be removed once usage references are updated.
*/
diff --git a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/ExecuteAppFunctionResponse.java b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/ExecuteAppFunctionResponse.java
index d87fec7985e9..969e5d58b909 100644
--- a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/ExecuteAppFunctionResponse.java
+++ b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/ExecuteAppFunctionResponse.java
@@ -234,12 +234,13 @@ public final class ExecuteAppFunctionResponse {
@IntDef(
prefix = {"RESULT_"},
value = {
- RESULT_OK,
- RESULT_DENIED,
- RESULT_APP_UNKNOWN_ERROR,
- RESULT_INTERNAL_ERROR,
- RESULT_INVALID_ARGUMENT,
- RESULT_DISABLED
+ RESULT_OK,
+ RESULT_DENIED,
+ RESULT_APP_UNKNOWN_ERROR,
+ RESULT_INTERNAL_ERROR,
+ RESULT_INVALID_ARGUMENT,
+ RESULT_DISABLED,
+ RESULT_CANCELLED
})
@Retention(RetentionPolicy.SOURCE)
public @interface ResultCode {}