summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Android Build Coastguard Worker <android-build-coastguard-worker@google.com> 2025-03-17 16:17:13 -0700
committer Android Build Coastguard Worker <android-build-coastguard-worker@google.com> 2025-03-17 16:17:13 -0700
commita6dabe91909cf7a8a2c9b62750d887c6e6ca8c16 (patch)
tree798236c42043a5429316208c3c9802e73eeb3ec8
parent58c568d06a72763076f2df50d8ef9f87b3d89333 (diff)
parent34eaed1aa7e355c0e48acdf0b36e94cf21f9ba2a (diff)
Snap for 13226929 from 34eaed1aa7e355c0e48acdf0b36e94cf21f9ba2a to 25Q2-release
Change-Id: I2aea61da0dcfe0dddbdd993050f36571f414b93a
-rw-r--r--core/java/android/app/StatusBarManager.java4
-rw-r--r--core/java/android/companion/virtual/flags/flags.aconfig7
-rw-r--r--core/java/android/content/pm/RegisteredServicesCache.java31
-rw-r--r--core/java/android/hardware/input/IInputManager.aidl2
-rw-r--r--core/java/android/hardware/input/IKeyGestureHandler.aidl10
-rw-r--r--core/java/android/hardware/input/InputManager.java21
-rw-r--r--core/java/android/hardware/input/InputManagerGlobal.java103
-rw-r--r--core/java/android/os/CombinedMessageQueue/MessageQueue.java6
-rw-r--r--core/java/android/os/flags.aconfig9
-rw-r--r--core/java/android/view/InsetsController.java4
-rw-r--r--core/java/android/window/DesktopModeFlags.java5
-rw-r--r--core/java/android/window/flags/lse_desktop_experience.aconfig20
-rw-r--r--core/java/com/android/internal/statusbar/DisableStates.aidl19
-rw-r--r--core/java/com/android/internal/statusbar/DisableStates.java95
-rw-r--r--core/java/com/android/internal/statusbar/IStatusBar.aidl2
-rw-r--r--core/tests/FileSystemUtilsTest/OWNERS2
-rw-r--r--core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java14
-rw-r--r--core/tests/coretests/src/android/content/pm/RegisteredServicesCacheUnitTest.java95
-rw-r--r--core/tests/coretests/src/com/android/internal/statusbar/DisableStatesTest.java64
-rw-r--r--graphics/java/android/graphics/Typeface.java20
-rw-r--r--libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu.xml9
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.java122
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.kt96
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java17
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt5
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java10
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt23
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt65
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt29
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt28
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java16
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java5
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt19
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.java184
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.kt153
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java29
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandlerTest.kt18
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandlerTest.kt80
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandlerTest.kt20
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java48
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java1
-rw-r--r--media/tests/projection/Android.bp8
-rw-r--r--media/tests/projection/AndroidManifest.xml2
-rw-r--r--media/tests/projection/AndroidTest.xml9
-rw-r--r--media/tests/projection/src/android/media/projection/MediaProjectionStoppingTest.java293
-rw-r--r--packages/CredentialManager/wear/AndroidManifest.xml6
-rw-r--r--packages/CredentialManager/wear/res/values/themes.xml24
-rw-r--r--packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt17
-rw-r--r--packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/ui/Category.kt37
-rw-r--r--packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt17
-rw-r--r--packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml21
-rw-r--r--packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml2
-rw-r--r--packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt48
-rw-r--r--packages/SettingsLib/aconfig/settingslib.aconfig10
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java28
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java122
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java52
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java105
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java17
-rw-r--r--packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java6
-rw-r--r--packages/SystemUI/aconfig/desktop_users_and_accounts.aconfig9
-rw-r--r--packages/SystemUI/aconfig/systemui.aconfig18
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/animation/ActivityTransitionAnimator.kt6
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinInputDisplay.kt44
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/LockSection.kt4
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractorTest.kt15
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt23
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt24
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractorTest.kt16
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModelTest.kt12
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/model/SysUiStateExtTest.kt3
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/EditTileListStateTest.kt71
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionStateTest.kt103
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt7
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/CommandQueueTest.java32
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java41
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java36
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java3
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt47
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt86
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt21
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt22
-rw-r--r--packages/SystemUI/res/drawable/unpin_icon.xml10
-rw-r--r--packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml2
-rw-r--r--packages/SystemUI/res/layout/promoted_permission_guts.xml73
-rw-r--r--packages/SystemUI/res/values/dimens.xml2
-rw-r--r--packages/SystemUI/res/values/strings.xml15
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardViewController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/ambient/touch/scrim/BouncerScrimController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/common/ui/compose/gestures/EagerTap.kt91
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalLockIconViewModel.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java54
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWmReorderAtmsCalls.kt53
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt6
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissInteractor.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt17
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractor.kt71
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt50
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySection.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerUdfpsIconViewModel.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModel.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/model/SceneContainerPlugin.kt25
-rw-r--r--packages/SystemUI/src/com/android/systemui/model/SysUiStateExt.kt14
-rw-r--r--packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt24
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt14
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt60
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt229
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt146
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt74
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt26
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java43
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java36
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java29
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java53
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedNotificationInfo.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedPermissionGutsContent.java173
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java15
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java40
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseUserSwitcherAdapter.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyLogger.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt23
-rw-r--r--packages/SystemUI/src/com/android/systemui/unfold/data/repository/ScreenTimeoutPolicyRepository.kt61
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt22
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/legacyhelper/data/LegacyUserDataHelper.kt14
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/shared/model/UserActionModel.kt1
-rw-r--r--packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt10
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/animation/ActivityTransitionAnimatorTest.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySectionTest.kt3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt39
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropTest.kt70
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/EditModeTest.kt47
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/ResizingTest.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java55
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt13
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorKosmos.kt1
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/scene/domain/startable/SceneContainerStartableKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt1
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java33
-rw-r--r--services/core/java/com/android/server/display/DisplayManagerService.java109
-rw-r--r--services/core/java/com/android/server/display/mode/DisplayModeDirector.java29
-rw-r--r--services/core/java/com/android/server/display/mode/ModeChangeObserver.java8
-rw-r--r--services/core/java/com/android/server/input/AppLaunchShortcutManager.java2
-rw-r--r--services/core/java/com/android/server/input/InputGestureManager.java9
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java46
-rw-r--r--services/core/java/com/android/server/input/KeyGestureController.java179
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java39
-rw-r--r--services/core/java/com/android/server/media/MediaSessionService.java34
-rw-r--r--services/core/java/com/android/server/pm/InstallPackageHelper.java3
-rw-r--r--services/core/java/com/android/server/policy/PhoneWindowManager.java135
-rw-r--r--services/core/java/com/android/server/statusbar/StatusBarManagerService.java91
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java49
-rw-r--r--services/core/java/com/android/server/wm/AsyncRotationController.java42
-rw-r--r--services/core/java/com/android/server/wm/DisplayArea.java6
-rw-r--r--services/core/java/com/android/server/wm/OWNERS2
-rw-r--r--services/core/java/com/android/server/wm/Task.java117
-rw-r--r--services/core/java/com/android/server/wm/TaskDisplayArea.java30
-rw-r--r--services/core/java/com/android/server/wm/TaskFpsCallbackController.java5
-rw-r--r--services/core/java/com/android/server/wm/WindowAnimator.java34
-rw-r--r--services/core/java/com/android/server/wm/WindowContainer.java33
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java10
-rw-r--r--services/core/java/com/android/server/wm/WindowState.java12
-rw-r--r--services/tests/displayservicetests/Android.bp1
-rw-r--r--services/tests/displayservicetests/AndroidManifest.xml1
-rw-r--r--services/tests/displayservicetests/AndroidTest.xml1
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/DisplayEventDeliveryTest.java244
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/EventDeliveryTestBase.java259
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/TopologyUpdateDeliveryTest.java243
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/mode/AppRequestObserverTest.kt33
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/mode/ModeChangeObserverTest.kt187
-rw-r--r--services/tests/servicestests/Android.bp2
-rw-r--r--services/tests/servicestests/AndroidTest.xml1
-rw-r--r--services/tests/servicestests/src/com/android/server/statusbar/StatusBarManagerServiceTest.java74
-rw-r--r--services/tests/servicestests/test-apps/TopologyTestApp/Android.bp38
-rw-r--r--services/tests/servicestests/test-apps/TopologyTestApp/AndroidManifest.xml27
-rw-r--r--services/tests/servicestests/test-apps/TopologyTestApp/OWNERS3
-rw-r--r--services/tests/servicestests/test-apps/TopologyTestApp/src/com/android/servicestests/apps/topologytestapp/TopologyUpdateActivity.java87
-rw-r--r--services/tests/wmtests/src/com/android/server/policy/KeyGestureEventTests.java148
-rw-r--r--services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java3
-rw-r--r--services/tests/wmtests/src/com/android/server/policy/ShortcutKeyTestBase.java20
-rw-r--r--services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java7
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java15
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java142
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java20
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskTests.java85
-rw-r--r--tests/Input/src/android/hardware/input/KeyGestureEventHandlerTest.kt115
-rw-r--r--tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt234
-rw-r--r--tests/Input/src/com/android/test/input/AnrTest.kt86
205 files changed, 5692 insertions, 2338 deletions
diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java
index 01868cc601fe..927d46999284 100644
--- a/core/java/android/app/StatusBarManager.java
+++ b/core/java/android/app/StatusBarManager.java
@@ -58,8 +58,10 @@ import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.IUndoMediaTransferCallback;
import com.android.internal.statusbar.NotificationVisibility;
+import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -119,6 +121,7 @@ public class StatusBarManager {
| DISABLE_SEARCH | DISABLE_ONGOING_CALL_CHIP;
/** @hide */
+ @Target(ElementType.TYPE_USE)
@IntDef(flag = true, prefix = {"DISABLE_"}, value = {
DISABLE_NONE,
DISABLE_EXPAND,
@@ -161,6 +164,7 @@ public class StatusBarManager {
| DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS | DISABLE2_ROTATE_SUGGESTIONS;
/** @hide */
+ @Target(ElementType.TYPE_USE)
@IntDef(flag = true, prefix = { "DISABLE2_" }, value = {
DISABLE2_NONE,
DISABLE2_MASK,
diff --git a/core/java/android/companion/virtual/flags/flags.aconfig b/core/java/android/companion/virtual/flags/flags.aconfig
index 615a6dffdf99..161f05bc5139 100644
--- a/core/java/android/companion/virtual/flags/flags.aconfig
+++ b/core/java/android/companion/virtual/flags/flags.aconfig
@@ -166,3 +166,10 @@ flag {
bug: "393517834"
is_exported: true
}
+
+flag {
+ name: "external_virtual_cameras"
+ namespace: "virtual_devices"
+ description: "Allow external virtual cameras visible only in the Context of the virtual device"
+ bug: "375609768"
+}
diff --git a/core/java/android/content/pm/RegisteredServicesCache.java b/core/java/android/content/pm/RegisteredServicesCache.java
index ded35b23608d..1ddab2c86ec2 100644
--- a/core/java/android/content/pm/RegisteredServicesCache.java
+++ b/core/java/android/content/pm/RegisteredServicesCache.java
@@ -104,14 +104,6 @@ public abstract class RegisteredServicesCache<V> {
private final Handler mBackgroundHandler;
- private final Runnable mClearServiceInfoCachesRunnable = new Runnable() {
- public void run() {
- synchronized (mUserIdToServiceInfoCaches) {
- mUserIdToServiceInfoCaches.clear();
- }
- }
- };
-
private static class UserServices<V> {
@GuardedBy("mServicesLock")
final Map<V, Integer> persistentServices = Maps.newHashMap();
@@ -565,9 +557,11 @@ public abstract class RegisteredServicesCache<V> {
if (Flags.optimizeParsingInRegisteredServicesCache()) {
synchronized (mUserIdToServiceInfoCaches) {
- if (mUserIdToServiceInfoCaches.numMaps() > 0) {
- mBackgroundHandler.removeCallbacks(mClearServiceInfoCachesRunnable);
- mBackgroundHandler.postDelayed(mClearServiceInfoCachesRunnable,
+ if (mUserIdToServiceInfoCaches.numElementsForKey(userId) > 0) {
+ final Integer token = Integer.valueOf(userId);
+ mBackgroundHandler.removeCallbacksAndEqualMessages(token);
+ mBackgroundHandler.postDelayed(
+ new ClearServiceInfoCachesTimeoutRunnable(userId), token,
SERVICE_INFO_CACHES_TIMEOUT_MILLIS);
}
}
@@ -953,4 +947,19 @@ public abstract class RegisteredServicesCache<V> {
return BackgroundThread.getHandler();
}
}
+
+ class ClearServiceInfoCachesTimeoutRunnable implements Runnable {
+ final int mUserId;
+
+ ClearServiceInfoCachesTimeoutRunnable(int userId) {
+ this.mUserId = userId;
+ }
+
+ @Override
+ public void run() {
+ synchronized (mUserIdToServiceInfoCaches) {
+ mUserIdToServiceInfoCaches.delete(mUserId);
+ }
+ }
+ }
}
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl
index 1c2150f3c09f..5537135f7bfa 100644
--- a/core/java/android/hardware/input/IInputManager.aidl
+++ b/core/java/android/hardware/input/IInputManager.aidl
@@ -273,7 +273,7 @@ interface IInputManager {
@PermissionManuallyEnforced
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+ "android.Manifest.permission.MANAGE_KEY_GESTURES)")
- void registerKeyGestureHandler(IKeyGestureHandler handler);
+ void registerKeyGestureHandler(in int[] keyGesturesToHandle, IKeyGestureHandler handler);
@PermissionManuallyEnforced
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
diff --git a/core/java/android/hardware/input/IKeyGestureHandler.aidl b/core/java/android/hardware/input/IKeyGestureHandler.aidl
index 4da991ee85b1..08b015892710 100644
--- a/core/java/android/hardware/input/IKeyGestureHandler.aidl
+++ b/core/java/android/hardware/input/IKeyGestureHandler.aidl
@@ -20,12 +20,12 @@ import android.hardware.input.AidlKeyGestureEvent;
import android.os.IBinder;
/** @hide */
-interface IKeyGestureHandler {
+oneway interface IKeyGestureHandler {
/**
- * Called when a key gesture starts, ends, or is cancelled. If a handler returns {@code true},
- * it means they intend to handle the full gesture and should handle all the events pertaining
- * to that gesture.
+ * Called when a key gesture starts, ends, or is cancelled. It is only sent to the handler that
+ * registered the callback for that particular gesture type.
+ * {@see IInputManager#registerKeyGestureHandler(int[], IKeyGestureHandler)}
*/
- boolean handleKeyGesture(in AidlKeyGestureEvent event, in IBinder focusedToken);
+ void handleKeyGesture(in AidlKeyGestureEvent event, in IBinder focusedToken);
}
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index d6419afb2a5a..a66ac76d7597 100644
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -1446,16 +1446,18 @@ public final class InputManager {
/**
* Registers a key gesture event handler for {@link KeyGestureEvent} handling.
*
+ * @param keyGesturesToHandle list of KeyGestureTypes to listen to
* @param handler the {@link KeyGestureEventHandler}
- * @throws IllegalArgumentException if {@code handler} has already been registered previously.
+ * @throws IllegalArgumentException if {@code handler} has already been registered previously
+ * or key gestures provided are already registered by some other gesture handler.
* @throws NullPointerException if {@code handler} or {@code executor} is null.
* @hide
* @see #unregisterKeyGestureEventHandler(KeyGestureEventHandler)
*/
@RequiresPermission(Manifest.permission.MANAGE_KEY_GESTURES)
- public void registerKeyGestureEventHandler(@NonNull KeyGestureEventHandler handler)
- throws IllegalArgumentException {
- mGlobal.registerKeyGestureEventHandler(handler);
+ public void registerKeyGestureEventHandler(List<Integer> keyGesturesToHandle,
+ @NonNull KeyGestureEventHandler handler) throws IllegalArgumentException {
+ mGlobal.registerKeyGestureEventHandler(keyGesturesToHandle, handler);
}
/**
@@ -1463,7 +1465,7 @@ public final class InputManager {
*
* @param handler the {@link KeyGestureEventHandler}
* @hide
- * @see #registerKeyGestureEventHandler(KeyGestureEventHandler)
+ * @see #registerKeyGestureEventHandler(List, KeyGestureEventHandler)
*/
@RequiresPermission(Manifest.permission.MANAGE_KEY_GESTURES)
public void unregisterKeyGestureEventHandler(@NonNull KeyGestureEventHandler handler) {
@@ -1741,7 +1743,7 @@ public final class InputManager {
* {@see KeyGestureEventListener} which is to listen to successfully handled key gestures, this
* interface allows system components to register handler for handling key gestures.
*
- * @see #registerKeyGestureEventHandler(KeyGestureEventHandler)
+ * @see #registerKeyGestureEventHandler(List, KeyGestureEventHandler)
* @see #unregisterKeyGestureEventHandler(KeyGestureEventHandler)
*
* <p> NOTE: All callbacks will occur on system main and input threads, so the caller needs
@@ -1750,14 +1752,11 @@ public final class InputManager {
*/
public interface KeyGestureEventHandler {
/**
- * Called when a key gesture event starts, is completed, or is cancelled. If a handler
- * returns {@code true}, it implies that the handler intends to handle the key gesture and
- * only this handler will receive the future events for this key gesture.
+ * Called when a key gesture event starts, is completed, or is cancelled.
*
* @param event the gesture event
*/
- boolean handleKeyGestureEvent(@NonNull KeyGestureEvent event,
- @Nullable IBinder focusedToken);
+ void handleKeyGestureEvent(@NonNull KeyGestureEvent event, @Nullable IBinder focusedToken);
}
/** @hide */
diff --git a/core/java/android/hardware/input/InputManagerGlobal.java b/core/java/android/hardware/input/InputManagerGlobal.java
index c4b4831ba76e..754182ce3d11 100644
--- a/core/java/android/hardware/input/InputManagerGlobal.java
+++ b/core/java/android/hardware/input/InputManagerGlobal.java
@@ -25,8 +25,8 @@ import android.hardware.BatteryState;
import android.hardware.SensorManager;
import android.hardware.input.InputManager.InputDeviceBatteryListener;
import android.hardware.input.InputManager.InputDeviceListener;
-import android.hardware.input.InputManager.KeyGestureEventHandler;
import android.hardware.input.InputManager.KeyEventActivityListener;
+import android.hardware.input.InputManager.KeyGestureEventHandler;
import android.hardware.input.InputManager.KeyGestureEventListener;
import android.hardware.input.InputManager.KeyboardBacklightListener;
import android.hardware.input.InputManager.OnTabletModeChangedListener;
@@ -49,6 +49,7 @@ import android.os.ServiceManager;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.VibratorManager;
+import android.util.IntArray;
import android.util.Log;
import android.util.SparseArray;
import android.view.Display;
@@ -132,13 +133,13 @@ public final class InputManagerGlobal {
@Nullable
private IKeyEventActivityListener mKeyEventActivityListener;
- private final Object mKeyGestureEventHandlerLock = new Object();
- @GuardedBy("mKeyGestureEventHandlerLock")
- @Nullable
- private ArrayList<KeyGestureEventHandler> mKeyGestureEventHandlers;
- @GuardedBy("mKeyGestureEventHandlerLock")
+ @GuardedBy("mKeyGesturesToHandlerMap")
@Nullable
private IKeyGestureHandler mKeyGestureHandler;
+ @GuardedBy("mKeyGesturesToHandlerMap")
+ private final SparseArray<KeyGestureEventHandler> mKeyGesturesToHandlerMap =
+ new SparseArray<>();
+
// InputDeviceSensorManager gets notified synchronously from the binder thread when input
// devices change, so it must be synchronized with the input device listeners.
@@ -1177,50 +1178,69 @@ public final class InputManagerGlobal {
private class LocalKeyGestureHandler extends IKeyGestureHandler.Stub {
@Override
- public boolean handleKeyGesture(@NonNull AidlKeyGestureEvent ev, IBinder focusedToken) {
- synchronized (mKeyGestureEventHandlerLock) {
- if (mKeyGestureEventHandlers == null) {
- return false;
- }
- final int numHandlers = mKeyGestureEventHandlers.size();
- final KeyGestureEvent event = new KeyGestureEvent(ev);
- for (int i = 0; i < numHandlers; i++) {
- KeyGestureEventHandler handler = mKeyGestureEventHandlers.get(i);
- if (handler.handleKeyGestureEvent(event, focusedToken)) {
- return true;
- }
+ public void handleKeyGesture(@NonNull AidlKeyGestureEvent ev, IBinder focusedToken) {
+ synchronized (mKeyGesturesToHandlerMap) {
+ KeyGestureEventHandler handler = mKeyGesturesToHandlerMap.get(ev.gestureType);
+ if (handler == null) {
+ Log.w(TAG, "Key gesture event " + ev.gestureType
+ + " occurred without a registered handler!");
+ return;
}
+ handler.handleKeyGestureEvent(new KeyGestureEvent(ev), focusedToken);
}
- return false;
}
}
/**
- * @see InputManager#registerKeyGestureEventHandler(KeyGestureEventHandler)
+ * @see InputManager#registerKeyGestureEventHandler(List, KeyGestureEventHandler)
*/
@RequiresPermission(Manifest.permission.MANAGE_KEY_GESTURES)
- void registerKeyGestureEventHandler(@NonNull KeyGestureEventHandler handler)
- throws IllegalArgumentException {
+ void registerKeyGestureEventHandler(List<Integer> keyGesturesToHandle,
+ @NonNull KeyGestureEventHandler handler) throws IllegalArgumentException {
+ Objects.requireNonNull(keyGesturesToHandle, "List of gestures should not be null");
Objects.requireNonNull(handler, "handler should not be null");
- synchronized (mKeyGestureEventHandlerLock) {
- if (mKeyGestureHandler == null) {
- mKeyGestureEventHandlers = new ArrayList<>();
- mKeyGestureHandler = new LocalKeyGestureHandler();
+ if (keyGesturesToHandle.isEmpty()) {
+ throw new IllegalArgumentException("No key gestures provided!");
+ }
- try {
- mIm.registerKeyGestureHandler(mKeyGestureHandler);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
+ synchronized (mKeyGesturesToHandlerMap) {
+ IntArray newKeyGestures = new IntArray(
+ keyGesturesToHandle.size() + mKeyGesturesToHandlerMap.size());
+
+ // Check if the handler already exists
+ for (int i = 0; i < mKeyGesturesToHandlerMap.size(); i++) {
+ KeyGestureEventHandler h = mKeyGesturesToHandlerMap.valueAt(i);
+ if (h == handler) {
+ throw new IllegalArgumentException("Handler has already been registered!");
}
+ newKeyGestures.add(mKeyGesturesToHandlerMap.keyAt(i));
}
- final int numHandlers = mKeyGestureEventHandlers.size();
- for (int i = 0; i < numHandlers; i++) {
- if (mKeyGestureEventHandlers.get(i) == handler) {
- throw new IllegalArgumentException("Handler has already been registered!");
+
+ // Check if any of the key gestures are already handled by existing handlers
+ for (int gesture : keyGesturesToHandle) {
+ if (mKeyGesturesToHandlerMap.contains(gesture)) {
+ throw new IllegalArgumentException("Key gesture " + gesture
+ + " is already registered by another handler!");
+ }
+ newKeyGestures.add(gesture);
+ }
+
+ try {
+ // If handler was already registered for this process, we need to unregister and
+ // re-register it for the new set of gestures
+ if (mKeyGestureHandler != null) {
+ mIm.unregisterKeyGestureHandler(mKeyGestureHandler);
+ } else {
+ mKeyGestureHandler = new LocalKeyGestureHandler();
+ }
+ mIm.registerKeyGestureHandler(newKeyGestures.toArray(), mKeyGestureHandler);
+ for (int gesture : keyGesturesToHandle) {
+ mKeyGesturesToHandlerMap.put(gesture, handler);
}
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
}
- mKeyGestureEventHandlers.add(handler);
}
}
@@ -1231,18 +1251,21 @@ public final class InputManagerGlobal {
void unregisterKeyGestureEventHandler(@NonNull KeyGestureEventHandler handler) {
Objects.requireNonNull(handler, "handler should not be null");
- synchronized (mKeyGestureEventHandlerLock) {
- if (mKeyGestureEventHandlers == null) {
+ synchronized (mKeyGesturesToHandlerMap) {
+ if (mKeyGestureHandler == null) {
return;
}
- mKeyGestureEventHandlers.removeIf(existingHandler -> existingHandler == handler);
- if (mKeyGestureEventHandlers.isEmpty()) {
+ for (int i = mKeyGesturesToHandlerMap.size() - 1; i >= 0; i--) {
+ if (mKeyGesturesToHandlerMap.valueAt(i) == handler) {
+ mKeyGesturesToHandlerMap.removeAt(i);
+ }
+ }
+ if (mKeyGesturesToHandlerMap.size() == 0) {
try {
mIm.unregisterKeyGestureHandler(mKeyGestureHandler);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
- mKeyGestureEventHandlers = null;
mKeyGestureHandler = null;
}
}
diff --git a/core/java/android/os/CombinedMessageQueue/MessageQueue.java b/core/java/android/os/CombinedMessageQueue/MessageQueue.java
index c3ec96d17437..c21959b16fbb 100644
--- a/core/java/android/os/CombinedMessageQueue/MessageQueue.java
+++ b/core/java/android/os/CombinedMessageQueue/MessageQueue.java
@@ -144,6 +144,12 @@ public final class MessageQueue {
return;
}
+ // Holdback study.
+ if (Flags.messageQueueForceLegacy()) {
+ sIsProcessAllowedToUseConcurrent = false;
+ return;
+ }
+
if (Flags.forceConcurrentMessageQueue()) {
// b/379472827: Robolectric tests use reflection to access MessageQueue.mMessages.
// This is a hack to allow Robolectric tests to use the legacy implementation.
diff --git a/core/java/android/os/flags.aconfig b/core/java/android/os/flags.aconfig
index 0150d171d51c..b52a454ea956 100644
--- a/core/java/android/os/flags.aconfig
+++ b/core/java/android/os/flags.aconfig
@@ -4,6 +4,15 @@ container: "system"
# keep-sorted start block=yes newline_separated=yes
flag {
+ # Holdback study for concurrent MessageQueue.
+ # Do not promote beyond trunkfood.
+ namespace: "system_performance"
+ name: "message_queue_force_legacy"
+ description: "Whether to holdback concurrent MessageQueue (force legacy)."
+ bug: "336880969"
+}
+
+flag {
name: "adpf_gpu_report_actual_work_duration"
is_exported: true
namespace: "game"
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java
index 7e9dfe6d972a..4c578fb93600 100644
--- a/core/java/android/view/InsetsController.java
+++ b/core/java/android/view/InsetsController.java
@@ -2039,8 +2039,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
} else if (Flags.refactorInsetsController()) {
if ((typesToReport & ime()) != 0 && mImeSourceConsumer != null) {
InsetsSourceControl control = mImeSourceConsumer.getControl();
- if (control != null && control.getLeash() == null) {
- // If the IME was requested twice, and we didn't receive the controls
+ if (control == null || control.getLeash() == null) {
+ // If the IME was requested to show twice, and we didn't receive the controls
// yet, this request will not continue. It should be cancelled here, as
// it would time out otherwise.
ImeTracker.forLogging().onCancelled(statsToken,
diff --git a/core/java/android/window/DesktopModeFlags.java b/core/java/android/window/DesktopModeFlags.java
index 703274dd708b..4bd7d1679dcc 100644
--- a/core/java/android/window/DesktopModeFlags.java
+++ b/core/java/android/window/DesktopModeFlags.java
@@ -44,7 +44,7 @@ public enum DesktopModeFlags {
// All desktop mode related flags to be overridden by developer option toggle will be added here
// go/keep-sorted start
DISABLE_DESKTOP_LAUNCH_PARAMS_OUTSIDE_DESKTOP_BUG_FIX(
- Flags::disableDesktopLaunchParamsOutsideDesktopBugFix, false),
+ Flags::disableDesktopLaunchParamsOutsideDesktopBugFix, true),
DISABLE_NON_RESIZABLE_APP_SNAP_RESIZE(Flags::disableNonResizableAppSnapResizing, true),
ENABLE_ACCESSIBLE_CUSTOM_HEADERS(Flags::enableAccessibleCustomHeaders, true),
ENABLE_APP_HEADER_WITH_TASK_DENSITY(Flags::enableAppHeaderWithTaskDensity, true),
@@ -115,11 +115,12 @@ public enum DesktopModeFlags {
ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS(
Flags::enableOpaqueBackgroundForTransparentWindows, true),
ENABLE_QUICKSWITCH_DESKTOP_SPLIT_BUGFIX(Flags::enableQuickswitchDesktopSplitBugfix, true),
+ ENABLE_REQUEST_FULLSCREEN_BUGFIX(Flags::enableRequestFullscreenBugfix, false),
ENABLE_RESIZING_METRICS(Flags::enableResizingMetrics, true),
ENABLE_RESTORE_TO_PREVIOUS_SIZE_FROM_DESKTOP_IMMERSIVE(
Flags::enableRestoreToPreviousSizeFromDesktopImmersive, true),
ENABLE_SHELL_INITIAL_BOUNDS_REGRESSION_BUG_FIX(
- Flags::enableShellInitialBoundsRegressionBugFix, false),
+ Flags::enableShellInitialBoundsRegressionBugFix, true),
ENABLE_START_LAUNCH_TRANSITION_FROM_TASKBAR_BUGFIX(
Flags::enableStartLaunchTransitionFromTaskbarBugfix, true),
ENABLE_TASKBAR_OVERFLOW(Flags::enableTaskbarOverflow, false),
diff --git a/core/java/android/window/flags/lse_desktop_experience.aconfig b/core/java/android/window/flags/lse_desktop_experience.aconfig
index e4142a171669..0d87b73a5e03 100644
--- a/core/java/android/window/flags/lse_desktop_experience.aconfig
+++ b/core/java/android/window/flags/lse_desktop_experience.aconfig
@@ -971,6 +971,16 @@ flag {
}
flag {
+ name: "enable_request_fullscreen_bugfix"
+ namespace: "lse_desktop_experience"
+ description: "Fixes split to fullscreen restoration using the Activity#requestFullscreenMode API"
+ bug: "402973271"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+flag {
name: "enable_dynamic_radius_computation_bugfix"
namespace: "lse_desktop_experience"
description: "Enables bugfix to compute the corner/shadow radius of desktop windows dynamically with the current window context."
@@ -986,3 +996,13 @@ flag {
description: "Enables the home to be shown behind the desktop."
bug: "375644149"
}
+
+flag {
+ name: "enable_desktop_ime_bugfix"
+ namespace: "lse_desktop_experience"
+ description: "Enables bugfix to handle IME interactions in desktop windowing."
+ bug: "388570293"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/core/java/com/android/internal/statusbar/DisableStates.aidl b/core/java/com/android/internal/statusbar/DisableStates.aidl
new file mode 100644
index 000000000000..fd9882f0f7c2
--- /dev/null
+++ b/core/java/com/android/internal/statusbar/DisableStates.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.statusbar;
+
+parcelable DisableStates;
diff --git a/core/java/com/android/internal/statusbar/DisableStates.java b/core/java/com/android/internal/statusbar/DisableStates.java
new file mode 100644
index 000000000000..ca2fd6c03558
--- /dev/null
+++ b/core/java/com/android/internal/statusbar/DisableStates.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.statusbar;
+
+import android.app.StatusBarManager.Disable2Flags;
+import android.app.StatusBarManager.DisableFlags;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Pair;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Holds display ids with their disable flags.
+ */
+public class DisableStates implements Parcelable {
+
+ /**
+ * A map of display IDs (integers) with corresponding disable flags.
+ */
+ public Map<Integer, Pair<@DisableFlags Integer, @Disable2Flags Integer>> displaysWithStates;
+
+ /**
+ * Whether the disable state change should be animated.
+ */
+ public boolean animate;
+
+ public DisableStates(
+ Map<Integer, Pair<@DisableFlags Integer, @Disable2Flags Integer>> displaysWithStates,
+ boolean animate) {
+ this.displaysWithStates = displaysWithStates;
+ this.animate = animate;
+ }
+
+ public DisableStates(
+ Map<Integer, Pair<@DisableFlags Integer, @Disable2Flags Integer>> displaysWithStates) {
+ this(displaysWithStates, true);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(displaysWithStates.size()); // Write the size of the map
+ for (Map.Entry<Integer, Pair<Integer, Integer>> entry : displaysWithStates.entrySet()) {
+ dest.writeInt(entry.getKey());
+ dest.writeInt(entry.getValue().first);
+ dest.writeInt(entry.getValue().second);
+ }
+ dest.writeBoolean(animate);
+ }
+
+ /**
+ * Used to make this class parcelable.
+ */
+ public static final Parcelable.Creator<DisableStates> CREATOR = new Parcelable.Creator<>() {
+ @Override
+ public DisableStates createFromParcel(Parcel source) {
+ int size = source.readInt(); // Read the size of the map
+ Map<Integer, Pair<Integer, Integer>> displaysWithStates = new HashMap<>(size);
+ for (int i = 0; i < size; i++) {
+ int key = source.readInt();
+ int first = source.readInt();
+ int second = source.readInt();
+ displaysWithStates.put(key, new Pair<>(first, second));
+ }
+ final boolean animate = source.readBoolean();
+ return new DisableStates(displaysWithStates, animate);
+ }
+
+ @Override
+ public DisableStates[] newArray(int size) {
+ return new DisableStates[size];
+ }
+ };
+}
+
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl
index 5a180d7358dd..ce9b036f2fd7 100644
--- a/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -32,6 +32,7 @@ import android.os.UserHandle;
import android.view.KeyEvent;
import android.service.notification.StatusBarNotification;
+import com.android.internal.statusbar.DisableStates;
import com.android.internal.statusbar.IAddTileResultCallback;
import com.android.internal.statusbar.IUndoMediaTransferCallback;
import com.android.internal.statusbar.LetterboxDetails;
@@ -44,6 +45,7 @@ oneway interface IStatusBar
void setIcon(String slot, in StatusBarIcon icon);
void removeIcon(String slot);
void disable(int displayId, int state1, int state2);
+ void disableForAllDisplays(in DisableStates disableStates);
void animateExpandNotificationsPanel();
void animateExpandSettingsPanel(String subPanel);
void animateCollapsePanels();
diff --git a/core/tests/FileSystemUtilsTest/OWNERS b/core/tests/FileSystemUtilsTest/OWNERS
new file mode 100644
index 000000000000..74eeacfeb973
--- /dev/null
+++ b/core/tests/FileSystemUtilsTest/OWNERS
@@ -0,0 +1,2 @@
+waghpawan@google.com
+kaleshsingh@google.com
diff --git a/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java b/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java
index 208d74e49afe..dbfd3e8ccdaa 100644
--- a/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java
+++ b/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java
@@ -38,6 +38,8 @@ public class FileSystemUtilsTest extends BaseHostJUnit4Test {
private static final String PAGE_SIZE_COMPAT_ENABLED_BY_PLATFORM =
"app_with_4kb_elf_no_override.apk";
+ private static final int DEVICE_WAIT_TIMEOUT = 120000;
+
@Test
@AppModeFull
public void runPunchedApp_embeddedNativeLibs() throws DeviceNotAvailableException {
@@ -98,8 +100,20 @@ public class FileSystemUtilsTest extends BaseHostJUnit4Test {
@AppModeFull
public void runAppWith4KbLib_compatByAlignmentChecks()
throws DeviceNotAvailableException, TargetSetupError {
+ // make sure that device is available for UI test
+ prepareDevice();
// This test is expected to fail since compat is disabled in manifest
runPageSizeCompatTest(PAGE_SIZE_COMPAT_ENABLED_BY_PLATFORM,
"testPageSizeCompat_compatByAlignmentChecks");
}
+
+ private void prepareDevice() throws DeviceNotAvailableException {
+ // Verify that device is online before running test and enable root
+ getDevice().waitForDeviceAvailable(DEVICE_WAIT_TIMEOUT);
+ getDevice().enableAdbRoot();
+ getDevice().waitForDeviceAvailable(DEVICE_WAIT_TIMEOUT);
+
+ getDevice().executeShellCommand("input keyevent KEYCODE_WAKEUP");
+ getDevice().executeShellCommand("wm dismiss-keyguard");
+ }
}
diff --git a/core/tests/coretests/src/android/content/pm/RegisteredServicesCacheUnitTest.java b/core/tests/coretests/src/android/content/pm/RegisteredServicesCacheUnitTest.java
index 8349659517c5..b63fcdc8362f 100644
--- a/core/tests/coretests/src/android/content/pm/RegisteredServicesCacheUnitTest.java
+++ b/core/tests/coretests/src/android/content/pm/RegisteredServicesCacheUnitTest.java
@@ -68,6 +68,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
/**
* Unit tests for {@link android.content.pm.RegisteredServicesCache}
@@ -84,8 +85,8 @@ public class RegisteredServicesCacheUnitTest {
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
- private final ResolveInfo mResolveInfo1 = new ResolveInfo();
- private final ResolveInfo mResolveInfo2 = new ResolveInfo();
+ private final TestResolveInfo mResolveInfo1 = new TestResolveInfo();
+ private final TestResolveInfo mResolveInfo2 = new TestResolveInfo();
private final TestServiceType mTestServiceType1 = new TestServiceType("t1", "value1");
private final TestServiceType mTestServiceType2 = new TestServiceType("t2", "value2");
@Mock
@@ -195,13 +196,13 @@ public class RegisteredServicesCacheUnitTest {
reset(testServicesCache);
- testServicesCache.clearServicesForQuerying();
int u1uid = UserHandle.getUid(U1, UID1);
assertThat(u1uid).isNotEqualTo(UID1);
final RegisteredServicesCache.ServiceInfo<TestServiceType> serviceInfo2 = newServiceInfo(
mTestServiceType1, u1uid, mResolveInfo1.serviceInfo.getComponentName(),
1000L /* lastUpdateTime */);
+ mResolveInfo1.setResolveInfoId(U1);
testServicesCache.addServiceForQuerying(U1, mResolveInfo1, serviceInfo2);
testServicesCache.getAllServices(U1);
@@ -286,7 +287,7 @@ public class RegisteredServicesCacheUnitTest {
}
@Test
- public void testClearServiceInfoCachesAfterTimeout() throws Exception {
+ public void testClearServiceInfoCachesForSingleUserAfterTimeout() throws Exception {
PackageInfo packageInfo1 = createPackageInfo(1000L /* lastUpdateTime */);
when(mMockPackageManager.getPackageInfoAsUser(eq(mResolveInfo1.serviceInfo.packageName),
anyInt(), eq(U0))).thenReturn(packageInfo1);
@@ -316,6 +317,58 @@ public class RegisteredServicesCacheUnitTest {
verify(testServicesCache, times(1)).parseServiceInfo(eq(mResolveInfo1), eq(1000L));
}
+ @Test
+ public void testClearServiceInfoCachesForMultiUserAfterTimeout() throws Exception {
+ PackageInfo packageInfo1 = createPackageInfo(1000L /* lastUpdateTime */);
+ when(mMockPackageManager.getPackageInfoAsUser(eq(mResolveInfo1.serviceInfo.packageName),
+ anyInt(), eq(U0))).thenReturn(packageInfo1);
+ PackageInfo packageInfo2 = createPackageInfo(2000L /* lastUpdateTime */);
+ when(mMockPackageManager.getPackageInfoAsUser(eq(mResolveInfo2.serviceInfo.packageName),
+ anyInt(), eq(U1))).thenReturn(packageInfo2);
+
+ TestRegisteredServicesCache testServicesCache = spy(
+ new TestRegisteredServicesCache(mMockInjector, null /* serializerAndParser */));
+ final RegisteredServicesCache.ServiceInfo<TestServiceType> serviceInfo1 = newServiceInfo(
+ mTestServiceType1, UID1, mResolveInfo1.serviceInfo.getComponentName(),
+ 1000L /* lastUpdateTime */);
+ testServicesCache.addServiceForQuerying(U0, mResolveInfo1, serviceInfo1);
+
+ int u1uid = UserHandle.getUid(U1, UID1);
+ final RegisteredServicesCache.ServiceInfo<TestServiceType> serviceInfo2 = newServiceInfo(
+ mTestServiceType2, u1uid, mResolveInfo2.serviceInfo.getComponentName(),
+ 2000L /* lastUpdateTime */);
+ testServicesCache.addServiceForQuerying(U1, mResolveInfo2, serviceInfo2);
+
+ // Don't invoke run on the Runnable for U0 user, and it will not clear the service info of
+ // U0 user. Invoke run on the Runnable for U1 user, and it will just clear the service info
+ // of U1 user.
+ doAnswer(invocation -> {
+ Message message = invocation.getArgument(0);
+ if (!message.obj.equals(Integer.valueOf(U0))) {
+ message.getCallback().run();
+ }
+ return true;
+ }).when(mMockBackgroundHandler).sendMessageAtTime(any(Message.class), anyLong());
+
+ // It will generate the service info of U0 user into cache.
+ testServicesCache.getAllServices(U0);
+ verify(testServicesCache, times(1)).parseServiceInfo(eq(mResolveInfo1), eq(1000L));
+ // It will generate the service info of U1 user into cache.
+ testServicesCache.getAllServices(U1);
+ verify(testServicesCache, times(1)).parseServiceInfo(eq(mResolveInfo2), eq(2000L));
+ verify(mMockBackgroundHandler, times(2)).sendMessageAtTime(any(Message.class), anyLong());
+
+ reset(testServicesCache);
+
+ testServicesCache.invalidateCache(U0);
+ testServicesCache.getAllServices(U0);
+ verify(testServicesCache, never()).parseServiceInfo(eq(mResolveInfo1), eq(1000L));
+
+ testServicesCache.invalidateCache(U1);
+ testServicesCache.getAllServices(U1);
+ verify(testServicesCache, times(1)).parseServiceInfo(eq(mResolveInfo2), eq(2000L));
+ }
+
private static RegisteredServicesCache.ServiceInfo<TestServiceType> newServiceInfo(
TestServiceType type, int uid, ComponentName componentName, long lastUpdateTime) {
final ComponentInfo info = new ComponentInfo();
@@ -324,7 +377,7 @@ public class RegisteredServicesCacheUnitTest {
return new RegisteredServicesCache.ServiceInfo<>(type, info, componentName, lastUpdateTime);
}
- private void addServiceInfoIntoResolveInfo(ResolveInfo resolveInfo, String packageName,
+ private void addServiceInfoIntoResolveInfo(TestResolveInfo resolveInfo, String packageName,
String serviceName) {
final ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.packageName = packageName;
@@ -345,7 +398,7 @@ public class RegisteredServicesCacheUnitTest {
static final String SERVICE_INTERFACE = "RegisteredServicesCacheUnitTest";
static final String SERVICE_META_DATA = "RegisteredServicesCacheUnitTest";
static final String ATTRIBUTES_NAME = "test";
- private SparseArray<Map<ResolveInfo, ServiceInfo<TestServiceType>>> mServices =
+ private SparseArray<Map<TestResolveInfo, ServiceInfo<TestServiceType>>> mServices =
new SparseArray<>();
public TestRegisteredServicesCache(Injector<TestServiceType> injector,
@@ -362,14 +415,14 @@ public class RegisteredServicesCacheUnitTest {
@Override
protected List<ResolveInfo> queryIntentServices(int userId) {
- Map<ResolveInfo, ServiceInfo<TestServiceType>> map = mServices.get(userId,
- new HashMap<ResolveInfo, ServiceInfo<TestServiceType>>());
+ Map<TestResolveInfo, ServiceInfo<TestServiceType>> map = mServices.get(userId,
+ new HashMap<TestResolveInfo, ServiceInfo<TestServiceType>>());
return new ArrayList<>(map.keySet());
}
- void addServiceForQuerying(int userId, ResolveInfo resolveInfo,
+ void addServiceForQuerying(int userId, TestResolveInfo resolveInfo,
ServiceInfo<TestServiceType> serviceInfo) {
- Map<ResolveInfo, ServiceInfo<TestServiceType>> map = mServices.get(userId);
+ Map<TestResolveInfo, ServiceInfo<TestServiceType>> map = mServices.get(userId);
if (map == null) {
map = new HashMap<>();
mServices.put(userId, map);
@@ -377,16 +430,12 @@ public class RegisteredServicesCacheUnitTest {
map.put(resolveInfo, serviceInfo);
}
- void clearServicesForQuerying() {
- mServices.clear();
- }
-
@Override
protected ServiceInfo<TestServiceType> parseServiceInfo(ResolveInfo resolveInfo,
long lastUpdateTime) throws XmlPullParserException, IOException {
int size = mServices.size();
for (int i = 0; i < size; i++) {
- Map<ResolveInfo, ServiceInfo<TestServiceType>> map = mServices.valueAt(i);
+ Map<TestResolveInfo, ServiceInfo<TestServiceType>> map = mServices.valueAt(i);
ServiceInfo<TestServiceType> serviceInfo = map.get(resolveInfo);
if (serviceInfo != null) {
return serviceInfo;
@@ -400,4 +449,20 @@ public class RegisteredServicesCacheUnitTest {
super.onUserRemoved(userId);
}
}
+
+ /**
+ * Create different hash code with the same {@link android.content.pm.ResolveInfo} for testing.
+ */
+ public static class TestResolveInfo extends ResolveInfo {
+ int mResolveInfoId = 0;
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mResolveInfoId, serviceInfo);
+ }
+
+ public void setResolveInfoId(int resolveInfoId) {
+ mResolveInfoId = resolveInfoId;
+ }
+ }
}
diff --git a/core/tests/coretests/src/com/android/internal/statusbar/DisableStatesTest.java b/core/tests/coretests/src/com/android/internal/statusbar/DisableStatesTest.java
new file mode 100644
index 000000000000..5b82696b81c3
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/statusbar/DisableStatesTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.statusbar;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.os.Parcel;
+import android.util.Pair;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class DisableStatesTest {
+
+ @Test
+ public void testParcelable() {
+ Map<Integer, Pair<Integer, Integer>> displaysWithStates = new HashMap<>();
+ displaysWithStates.put(1, new Pair<>(10, 20));
+ displaysWithStates.put(2, new Pair<>(30, 40));
+ boolean animate = true;
+ DisableStates original = new DisableStates(displaysWithStates, animate);
+
+ Parcel parcel = Parcel.obtain();
+ original.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ DisableStates restored = DisableStates.CREATOR.createFromParcel(parcel);
+
+ assertNotNull(restored);
+ assertEquals(original.displaysWithStates.size(), restored.displaysWithStates.size());
+ for (Map.Entry<Integer, Pair<Integer, Integer>> entry :
+ original.displaysWithStates.entrySet()) {
+ int displayId = entry.getKey();
+ Pair<Integer, Integer> originalDisplayStates = entry.getValue();
+ Pair<Integer, Integer> restoredDisplayStates = restored.displaysWithStates.get(
+ displayId);
+ assertEquals(originalDisplayStates.first, restoredDisplayStates.first);
+ assertEquals(originalDisplayStates.second, restoredDisplayStates.second);
+ }
+ assertEquals(original.animate, restored.animate);
+ }
+}
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index d1aca34c7b8d..39cd4a89aae6 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -80,6 +80,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.function.BiConsumer;
/**
* The Typeface class specifies the typeface and intrinsic style of a font.
@@ -1550,14 +1551,21 @@ public class Typeface {
setDefault(defaults.get(0));
ArrayList<Typeface> oldGenerics = new ArrayList<>();
- oldGenerics.add(sSystemFontMap.get("sans-serif"));
- sSystemFontMap.put("sans-serif", genericFamilies.get(0));
+ BiConsumer<Typeface, String> swapTypeface = (typeface, key) -> {
+ oldGenerics.add(sSystemFontMap.get(key));
+ sSystemFontMap.put(key, typeface);
+ };
- oldGenerics.add(sSystemFontMap.get("serif"));
- sSystemFontMap.put("serif", genericFamilies.get(1));
+ Typeface sansSerif = genericFamilies.get(0);
+ swapTypeface.accept(sansSerif, "sans-serif");
+ swapTypeface.accept(Typeface.create(sansSerif, 100, false), "sans-serif-thin");
+ swapTypeface.accept(Typeface.create(sansSerif, 300, false), "sans-serif-light");
+ swapTypeface.accept(Typeface.create(sansSerif, 500, false), "sans-serif-medium");
+ swapTypeface.accept(Typeface.create(sansSerif, 700, false), "sans-serif-bold");
+ swapTypeface.accept(Typeface.create(sansSerif, 900, false), "sans-serif-black");
- oldGenerics.add(sSystemFontMap.get("monospace"));
- sSystemFontMap.put("monospace", genericFamilies.get(2));
+ swapTypeface.accept(genericFamilies.get(1), "serif");
+ swapTypeface.accept(genericFamilies.get(2), "monospace");
return new Pair<>(oldDefaults, oldGenerics);
}
diff --git a/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu.xml b/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu.xml
index bfaa40771894..c33669636be4 100644
--- a/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu.xml
+++ b/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu.xml
@@ -186,14 +186,13 @@
<ImageButton
android:id="@+id/open_by_default_button"
- android:layout_width="20dp"
- android:layout_height="20dp"
android:layout_gravity="end|center_vertical"
- android:layout_marginStart="8dp"
- android:layout_marginEnd="16dp"
+ android:paddingStart="12dp"
+ android:paddingEnd="16dp"
android:contentDescription="@string/open_by_default_settings_text"
android:src="@drawable/desktop_mode_ic_handle_menu_open_by_default_settings"
- android:tint="@androidprv:color/materialColorOnSurface"/>
+ android:tint="@androidprv:color/materialColorOnSurface"
+ style="@style/DesktopModeHandleMenuWindowingButton"/>
</LinearLayout>
</LinearLayout>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.java
deleted file mode 100644
index 1128fb2259b2..000000000000
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.wm.shell.common.pip;
-
-import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
-import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
-
-import android.window.DesktopExperienceFlags;
-import android.window.DesktopModeFlags;
-import android.window.DisplayAreaInfo;
-
-import com.android.wm.shell.Flags;
-import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
-import com.android.wm.shell.desktopmode.DesktopUserRepositories;
-import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler;
-
-import java.util.Optional;
-
-/** Helper class for PiP on Desktop Mode. */
-public class PipDesktopState {
- private final PipDisplayLayoutState mPipDisplayLayoutState;
- private final Optional<DesktopUserRepositories> mDesktopUserRepositoriesOptional;
- private final Optional<DragToDesktopTransitionHandler> mDragToDesktopTransitionHandlerOptional;
- private final RootTaskDisplayAreaOrganizer mRootTaskDisplayAreaOrganizer;
-
- public PipDesktopState(PipDisplayLayoutState pipDisplayLayoutState,
- Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
- Optional<DragToDesktopTransitionHandler> dragToDesktopTransitionHandlerOptional,
- RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
- mPipDisplayLayoutState = pipDisplayLayoutState;
- mDesktopUserRepositoriesOptional = desktopUserRepositoriesOptional;
- mDragToDesktopTransitionHandlerOptional = dragToDesktopTransitionHandlerOptional;
- mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
- }
-
- /**
- * Returns whether PiP in Desktop Windowing is enabled by checking the following:
- * - PiP in Desktop Windowing flag is enabled
- * - DesktopUserRepositories is injected
- * - DragToDesktopTransitionHandler is injected
- */
- public boolean isDesktopWindowingPipEnabled() {
- return DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PIP.isTrue()
- && mDesktopUserRepositoriesOptional.isPresent()
- && mDragToDesktopTransitionHandlerOptional.isPresent();
- }
-
- /**
- * Returns whether PiP in Connected Displays is enabled by checking the following:
- * - PiP in Connected Displays flag is enabled
- * - PiP2 flag is enabled
- */
- public boolean isConnectedDisplaysPipEnabled() {
- return DesktopExperienceFlags.ENABLE_CONNECTED_DISPLAYS_PIP.isTrue() && Flags.enablePip2();
- }
-
- /** Returns whether the display with the PiP task is in freeform windowing mode. */
- private boolean isDisplayInFreeform() {
- final DisplayAreaInfo tdaInfo = mRootTaskDisplayAreaOrganizer.getDisplayAreaInfo(
- mPipDisplayLayoutState.getDisplayId());
- if (tdaInfo != null) {
- return tdaInfo.configuration.windowConfiguration.getWindowingMode()
- == WINDOWING_MODE_FREEFORM;
- }
- return false;
- }
-
- /** Returns whether PiP is active in a display that is in active Desktop Mode session. */
- public boolean isPipInDesktopMode() {
- // Early return if PiP in Desktop Windowing is not supported.
- if (!isDesktopWindowingPipEnabled()) {
- return false;
- }
- final int displayId = mPipDisplayLayoutState.getDisplayId();
- return mDesktopUserRepositoriesOptional.get().getCurrent().isAnyDeskActive(displayId);
- }
-
- /**
- * The windowing mode to restore to when resizing out of PIP direction.
- * Defaults to undefined and can be overridden to restore to an alternate windowing mode.
- */
- public int getOutPipWindowingMode() {
- // If we are exiting PiP while the device is in Desktop mode (the task should expand to
- // freeform windowing mode):
- // 1) If the display windowing mode is freeform, set windowing mode to UNDEFINED so it will
- // resolve the windowing mode to the display's windowing mode.
- // 2) If the display windowing mode is not FREEFORM, set windowing mode to FREEFORM.
- if (isPipInDesktopMode()) {
- if (isDisplayInFreeform()) {
- return WINDOWING_MODE_UNDEFINED;
- } else {
- return WINDOWING_MODE_FREEFORM;
- }
- }
-
- // By default, or if the task is going to fullscreen, reset the windowing mode to undefined.
- return WINDOWING_MODE_UNDEFINED;
- }
-
- /** Returns whether there is a drag-to-desktop transition in progress. */
- public boolean isDragToDesktopInProgress() {
- // Early return if PiP in Desktop Windowing is not supported.
- if (!isDesktopWindowingPipEnabled()) {
- return false;
- }
- return mDragToDesktopTransitionHandlerOptional.get().getInProgress();
- }
-}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.kt
new file mode 100644
index 000000000000..55bde8906b63
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipDesktopState.kt
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.wm.shell.common.pip
+
+import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
+import android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED
+import android.window.DesktopExperienceFlags
+import android.window.DesktopModeFlags
+import com.android.wm.shell.Flags
+import com.android.wm.shell.RootTaskDisplayAreaOrganizer
+import com.android.wm.shell.desktopmode.DesktopUserRepositories
+import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler
+import java.util.Optional
+
+/** Helper class for PiP on Desktop Mode. */
+class PipDesktopState(
+ private val pipDisplayLayoutState: PipDisplayLayoutState,
+ private val desktopUserRepositoriesOptional: Optional<DesktopUserRepositories>,
+ private val dragToDesktopTransitionHandlerOptional: Optional<DragToDesktopTransitionHandler>,
+ private val rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer
+) {
+ /**
+ * Returns whether PiP in Desktop Windowing is enabled by checking the following:
+ * - PiP in Desktop Windowing flag is enabled
+ * - DesktopUserRepositories is present
+ * - DragToDesktopTransitionHandler is present
+ */
+ fun isDesktopWindowingPipEnabled(): Boolean =
+ DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PIP.isTrue &&
+ desktopUserRepositoriesOptional.isPresent &&
+ dragToDesktopTransitionHandlerOptional.isPresent
+
+ /**
+ * Returns whether PiP in Connected Displays is enabled by checking the following:
+ * - PiP in Connected Displays flag is enabled
+ * - PiP2 flag is enabled
+ */
+ fun isConnectedDisplaysPipEnabled(): Boolean =
+ DesktopExperienceFlags.ENABLE_CONNECTED_DISPLAYS_PIP.isTrue && Flags.enablePip2()
+
+ /** Returns whether the display with the PiP task is in freeform windowing mode. */
+ private fun isDisplayInFreeform(): Boolean {
+ val tdaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(
+ pipDisplayLayoutState.displayId
+ )
+
+ return tdaInfo?.configuration?.windowConfiguration?.windowingMode == WINDOWING_MODE_FREEFORM
+ }
+
+ /** Returns whether PiP is active in a display that is in active Desktop Mode session. */
+ fun isPipInDesktopMode(): Boolean {
+ if (!isDesktopWindowingPipEnabled()) {
+ return false
+ }
+
+ val displayId = pipDisplayLayoutState.displayId
+ return desktopUserRepositoriesOptional.get().current.isAnyDeskActive(displayId)
+ }
+
+ /** Returns the windowing mode to restore to when resizing out of PIP direction. */
+ // TODO(b/403345629): Update this for Multi-Desktop.
+ fun getOutPipWindowingMode(): Int {
+ // If we are exiting PiP while the device is in Desktop mode, the task should expand to
+ // freeform windowing mode.
+ // 1) If the display windowing mode is freeform, set windowing mode to UNDEFINED so it will
+ // resolve the windowing mode to the display's windowing mode.
+ // 2) If the display windowing mode is not FREEFORM, set windowing mode to FREEFORM.
+ if (isPipInDesktopMode()) {
+ return if (isDisplayInFreeform()) {
+ WINDOWING_MODE_UNDEFINED
+ } else {
+ WINDOWING_MODE_FREEFORM
+ }
+ }
+
+ // By default, or if the task is going to fullscreen, reset the windowing mode to undefined.
+ return WINDOWING_MODE_UNDEFINED
+ }
+
+ /** Returns whether there is a drag-to-desktop transition in progress. */
+ fun isDragToDesktopInProgress(): Boolean =
+ isDesktopWindowingPipEnabled() && dragToDesktopTransitionHandlerOptional.get().inProgress
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java
index 4413c8715c0d..d5f4a3885dbb 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java
@@ -112,6 +112,12 @@ public class CompatUIController implements OnDisplaysChangedListener,
new SparseArray<>(0);
/**
+ * {@link SparseArray} that maps task ids to {@link CompatUIInfo}.
+ */
+ private final SparseArray<CompatUIInfo> mTaskIdToCompatUIInfoMap =
+ new SparseArray<>(0);
+
+ /**
* {@link Set} of task ids for which we need to display a restart confirmation dialog
*/
private Set<Integer> mSetOfTaskIdsShowingRestartDialog = new HashSet<>();
@@ -261,7 +267,11 @@ public class CompatUIController implements OnDisplaysChangedListener,
private void handleDisplayCompatShowRestartDialog(
CompatUIRequests.DisplayCompatShowRestartDialog request) {
- onRestartButtonClicked(new Pair<>(request.getTaskInfo(), request.getTaskListener()));
+ final CompatUIInfo compatUIInfo = mTaskIdToCompatUIInfoMap.get(request.getTaskId());
+ if (compatUIInfo == null) {
+ return;
+ }
+ onRestartButtonClicked(new Pair<>(compatUIInfo.getTaskInfo(), compatUIInfo.getListener()));
}
/**
@@ -273,6 +283,11 @@ public class CompatUIController implements OnDisplaysChangedListener,
public void onCompatInfoChanged(@NonNull CompatUIInfo compatUIInfo) {
final TaskInfo taskInfo = compatUIInfo.getTaskInfo();
final ShellTaskOrganizer.TaskListener taskListener = compatUIInfo.getListener();
+ if (taskListener == null) {
+ mTaskIdToCompatUIInfoMap.delete(taskInfo.taskId);
+ } else {
+ mTaskIdToCompatUIInfoMap.put(taskInfo.taskId, compatUIInfo);
+ }
final boolean isInDisplayCompatMode =
taskInfo.appCompatTaskInfo.isRestartMenuEnabledForDisplayMove();
if (taskInfo != null && !taskInfo.appCompatTaskInfo.isTopActivityInSizeCompat()
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt
index da4fc99491dc..b7af596ee0ae 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt
@@ -16,8 +16,6 @@
package com.android.wm.shell.compatui.impl
-import android.app.TaskInfo
-import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.compatui.api.CompatUIRequest
internal const val DISPLAY_COMPAT_SHOW_RESTART_DIALOG = 0
@@ -27,7 +25,6 @@ internal const val DISPLAY_COMPAT_SHOW_RESTART_DIALOG = 0
*/
sealed class CompatUIRequests(override val requestId: Int) : CompatUIRequest {
/** Sent when the restart handle menu is clicked, and a restart dialog is requested. */
- data class DisplayCompatShowRestartDialog(val taskInfo: TaskInfo,
- val taskListener: ShellTaskOrganizer.TaskListener) :
+ data class DisplayCompatShowRestartDialog(val taskId: Int) :
CompatUIRequests(DISPLAY_COMPAT_SHOW_RESTART_DIALOG)
}
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 2cf671b0f446..613e78753b66 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
@@ -1213,7 +1213,8 @@ public abstract class WMShellModule {
ShellTaskOrganizer shellTaskOrganizer,
TaskStackListenerImpl taskStackListener,
ToggleResizeDesktopTaskTransitionHandler toggleResizeDesktopTaskTransitionHandler,
- @DynamicOverride DesktopUserRepositories desktopUserRepositories) {
+ @DynamicOverride DesktopUserRepositories desktopUserRepositories,
+ DisplayController displayController) {
if (DesktopModeStatus.canEnterDesktopMode(context)) {
return Optional.of(
new DesktopActivityOrientationChangeHandler(
@@ -1222,7 +1223,8 @@ public abstract class WMShellModule {
shellTaskOrganizer,
taskStackListener,
toggleResizeDesktopTaskTransitionHandler,
- desktopUserRepositories));
+ desktopUserRepositories,
+ displayController));
}
return Optional.empty();
}
@@ -1341,7 +1343,9 @@ public abstract class WMShellModule {
Context context,
ShellInit shellInit,
@ShellMainThread CoroutineScope mainScope,
+ ShellController shellController,
DisplayController displayController,
+ RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
Optional<DesktopUserRepositories> desktopUserRepositories,
Optional<DesktopTasksController> desktopTasksController,
Optional<DesktopDisplayModeController> desktopDisplayModeController,
@@ -1355,7 +1359,9 @@ public abstract class WMShellModule {
context,
shellInit,
mainScope,
+ shellController,
displayController,
+ rootTaskDisplayAreaOrganizer,
desktopRepositoryInitializer,
desktopUserRepositories.get(),
desktopTasksController.get(),
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt
index b8f4bb8d8323..39ce5d9023a6 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt
@@ -23,10 +23,10 @@ import android.content.pm.ActivityInfo.ScreenOrientation
import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.content.res.Configuration.ORIENTATION_PORTRAIT
import android.graphics.Rect
-import android.util.Size
import android.window.WindowContainerTransaction
import com.android.window.flags.Flags
import com.android.wm.shell.ShellTaskOrganizer
+import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.TaskStackListenerCallback
import com.android.wm.shell.common.TaskStackListenerImpl
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
@@ -40,6 +40,7 @@ class DesktopActivityOrientationChangeHandler(
private val taskStackListener: TaskStackListenerImpl,
private val resizeHandler: ToggleResizeDesktopTaskTransitionHandler,
private val desktopUserRepositories: DesktopUserRepositories,
+ private val displayController: DisplayController,
) {
init {
@@ -101,12 +102,24 @@ class DesktopActivityOrientationChangeHandler(
orientation == ORIENTATION_LANDSCAPE &&
ActivityInfo.isFixedOrientationPortrait(requestedOrientation)
) {
+ val displayLayout = displayController.getDisplayLayout(task.displayId) ?: return
+ val captionInsets =
+ task.configuration.windowConfiguration.appBounds?.let {
+ it.top - task.configuration.windowConfiguration.bounds.top
+ } ?: 0
+ val newOrientationBounds =
+ calculateInitialBounds(
+ displayLayout = displayLayout,
+ taskInfo = task,
+ captionInsets = captionInsets,
+ requestedScreenOrientation = requestedOrientation,
+ )
- val finalSize = Size(taskHeight, taskWidth)
// Use the center x as the resizing anchor point.
- val left = taskBounds.centerX() - finalSize.width / 2
- val right = left + finalSize.width
- val finalBounds = Rect(left, taskBounds.top, right, taskBounds.top + finalSize.height)
+ val left = taskBounds.centerX() - newOrientationBounds.width() / 2
+ val right = left + newOrientationBounds.width()
+ val finalBounds =
+ Rect(left, taskBounds.top, right, taskBounds.top + newOrientationBounds.height())
val wct = WindowContainerTransaction().setBounds(task.token, finalBounds)
resizeHandler.startTransition(wct)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt
index 683b74392fa6..3b98f8123b46 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt
@@ -17,16 +17,20 @@
package com.android.wm.shell.desktopmode
import android.content.Context
+import android.view.Display
import android.view.Display.DEFAULT_DISPLAY
import android.window.DesktopExperienceFlags
import com.android.internal.protolog.ProtoLog
+import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayController.OnDisplaysChangedListener
import com.android.wm.shell.desktopmode.multidesks.OnDeskRemovedListener
import com.android.wm.shell.desktopmode.persistence.DesktopRepositoryInitializer
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
+import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
+import com.android.wm.shell.sysui.UserChangeListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
@@ -36,7 +40,9 @@ class DesktopDisplayEventHandler(
private val context: Context,
shellInit: ShellInit,
private val mainScope: CoroutineScope,
+ private val shellController: ShellController,
private val displayController: DisplayController,
+ private val rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer,
private val desktopRepositoryInitializer: DesktopRepositoryInitializer,
private val desktopUserRepositories: DesktopUserRepositories,
private val desktopTasksController: DesktopTasksController,
@@ -53,8 +59,17 @@ class DesktopDisplayEventHandler(
private fun onInit() {
displayController.addDisplayWindowListener(this)
- if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue()) {
+ if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
desktopTasksController.onDeskRemovedListener = this
+
+ shellController.addUserChangeListener(
+ object : UserChangeListener {
+ override fun onUserChanged(newUserId: Int, userContext: Context) {
+ val displayIds = rootTaskDisplayAreaOrganizer.displayIds
+ createDefaultDesksIfNeeded(displayIds.toSet())
+ }
+ }
+ )
}
}
@@ -63,23 +78,7 @@ class DesktopDisplayEventHandler(
desktopDisplayModeController.refreshDisplayWindowingMode()
}
- if (!supportsDesks(displayId)) {
- logV("Display #$displayId does not support desks")
- return
- }
-
- mainScope.launch {
- desktopRepositoryInitializer.isInitialized.collect { initialized ->
- if (!initialized) return@collect
- if (desktopRepository.getNumberOfDesks(displayId) == 0) {
- logV("Creating new desk in new display#$displayId")
- // TODO: b/393978539 - consider activating the desk on creation when
- // applicable, such as for connected displays.
- desktopTasksController.createDesk(displayId)
- }
- cancel()
- }
- }
+ createDefaultDesksIfNeeded(displayIds = setOf(displayId))
}
override fun onDisplayRemoved(displayId: Int) {
@@ -93,8 +92,34 @@ class DesktopDisplayEventHandler(
override fun onDeskRemoved(lastDisplayId: Int, deskId: Int) {
val remainingDesks = desktopRepository.getNumberOfDesks(lastDisplayId)
if (remainingDesks == 0) {
- logV("All desks removed from display#$lastDisplayId, creating empty desk")
- desktopTasksController.createDesk(lastDisplayId)
+ logV("All desks removed from display#$lastDisplayId")
+ createDefaultDesksIfNeeded(setOf(lastDisplayId))
+ }
+ }
+
+ private fun createDefaultDesksIfNeeded(displayIds: Set<Int>) {
+ if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
+ logV("createDefaultDesksIfNeeded displays=%s", displayIds)
+ mainScope.launch {
+ desktopRepositoryInitializer.isInitialized.collect { initialized ->
+ if (!initialized) return@collect
+ displayIds
+ .filter { displayId -> displayId != Display.INVALID_DISPLAY }
+ .filter { displayId -> supportsDesks(displayId) }
+ .filter { displayId -> desktopRepository.getNumberOfDesks(displayId) == 0 }
+ .also { displaysNeedingDesk ->
+ logV(
+ "createDefaultDesksIfNeeded creating default desks in displays=%s",
+ displaysNeedingDesk,
+ )
+ }
+ .forEach { displayId ->
+ // TODO: b/393978539 - consider activating the desk on creation when
+ // applicable, such as for connected displays.
+ desktopTasksController.createDesk(displayId)
+ }
+ cancel()
+ }
}
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt
index 1ea545f3ab67..19507c17bc95 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt
@@ -23,10 +23,7 @@ import android.hardware.input.InputManager
import android.hardware.input.InputManager.KeyGestureEventHandler
import android.hardware.input.KeyGestureEvent
import android.os.IBinder
-import android.window.DesktopModeFlags
-import com.android.hardware.input.Flags.manageKeyGestures
import com.android.internal.protolog.ProtoLog
-import com.android.window.flags.Flags.enableMoveToNextDisplayShortcut
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.ShellExecutor
@@ -51,16 +48,20 @@ class DesktopModeKeyGestureHandler(
) : KeyGestureEventHandler {
init {
- inputManager.registerKeyGestureEventHandler(this)
+ if (desktopTasksController.isPresent && desktopModeWindowDecorViewModel.isPresent) {
+ val supportedGestures =
+ listOf(
+ KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY,
+ KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW,
+ KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW,
+ KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW,
+ )
+ inputManager.registerKeyGestureEventHandler(supportedGestures, this)
+ }
}
- override fun handleKeyGestureEvent(event: KeyGestureEvent, focusedToken: IBinder?): Boolean {
- if (
- !desktopTasksController.isPresent ||
- !desktopModeWindowDecorViewModel.isPresent
- ) {
- return false
- }
+ override fun handleKeyGestureEvent(event: KeyGestureEvent, focusedToken: IBinder?) {
when (event.keyGestureType) {
KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY -> {
logV("Key gesture MOVE_TO_NEXT_DISPLAY is handled")
@@ -69,7 +70,6 @@ class DesktopModeKeyGestureHandler(
desktopTasksController.get().moveToNextDisplay(it.taskId)
}
}
- return true
}
KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW -> {
logV("Key gesture SNAP_LEFT_FREEFORM_WINDOW is handled")
@@ -85,7 +85,6 @@ class DesktopModeKeyGestureHandler(
)
}
}
- return true
}
KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW -> {
logV("Key gesture SNAP_RIGHT_FREEFORM_WINDOW is handled")
@@ -101,7 +100,6 @@ class DesktopModeKeyGestureHandler(
)
}
}
- return true
}
KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW -> {
logV("Key gesture TOGGLE_MAXIMIZE_FREEFORM_WINDOW is handled")
@@ -120,7 +118,6 @@ class DesktopModeKeyGestureHandler(
)
}
}
- return true
}
KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW -> {
logV("Key gesture MINIMIZE_FREEFORM_WINDOW is handled")
@@ -129,9 +126,7 @@ class DesktopModeKeyGestureHandler(
desktopTasksController.get().minimizeTask(it, MinimizeReason.KEY_GESTURE)
}
}
- return true
}
- else -> return false
}
}
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 a8b0bafee724..3c44fe8061aa 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
@@ -69,6 +69,7 @@ fun calculateInitialBounds(
taskInfo: RunningTaskInfo,
scale: Float = DESKTOP_MODE_INITIAL_BOUNDS_SCALE,
captionInsets: Int = 0,
+ requestedScreenOrientation: Int? = null,
): Rect {
val screenBounds = Rect(0, 0, displayLayout.width(), displayLayout.height())
val appAspectRatio = calculateAspectRatio(taskInfo)
@@ -85,12 +86,13 @@ fun calculateInitialBounds(
}
val topActivityInfo =
taskInfo.topActivityInfo ?: return positionInScreen(idealSize, stableBounds)
+ val screenOrientation = requestedScreenOrientation ?: topActivityInfo.screenOrientation
val initialSize: Size =
when (taskInfo.configuration.orientation) {
ORIENTATION_LANDSCAPE -> {
if (taskInfo.canChangeAspectRatio) {
- if (isFixedOrientationPortrait(topActivityInfo.screenOrientation)) {
+ if (isFixedOrientationPortrait(screenOrientation)) {
// For portrait resizeable activities, respect apps fullscreen width but
// apply ideal size height.
Size(
@@ -104,14 +106,20 @@ fun calculateInitialBounds(
} else {
// If activity is unresizeable, regardless of orientation, calculate maximum
// size (within the ideal size) maintaining original aspect ratio.
- maximizeSizeGivenAspectRatio(taskInfo, idealSize, appAspectRatio, captionInsets)
+ maximizeSizeGivenAspectRatio(
+ taskInfo,
+ idealSize,
+ appAspectRatio,
+ captionInsets,
+ screenOrientation,
+ )
}
}
ORIENTATION_PORTRAIT -> {
val customPortraitWidthForLandscapeApp =
screenBounds.width() - (DESKTOP_MODE_LANDSCAPE_APP_PADDING * 2)
if (taskInfo.canChangeAspectRatio) {
- if (isFixedOrientationLandscape(topActivityInfo.screenOrientation)) {
+ if (isFixedOrientationLandscape(screenOrientation)) {
// For landscape resizeable activities, respect apps fullscreen height and
// apply custom app width.
Size(
@@ -123,7 +131,7 @@ fun calculateInitialBounds(
idealSize
}
} else {
- if (isFixedOrientationLandscape(topActivityInfo.screenOrientation)) {
+ if (isFixedOrientationLandscape(screenOrientation)) {
// For landscape unresizeable activities, apply custom app width to ideal
// size and calculate maximum size with this area while maintaining original
// aspect ratio.
@@ -132,6 +140,7 @@ fun calculateInitialBounds(
Size(customPortraitWidthForLandscapeApp, idealSize.height),
appAspectRatio,
captionInsets,
+ screenOrientation,
)
} else {
// For portrait unresizeable activities, calculate maximum size (within the
@@ -141,6 +150,7 @@ fun calculateInitialBounds(
idealSize,
appAspectRatio,
captionInsets,
+ screenOrientation,
)
}
}
@@ -190,13 +200,16 @@ fun maximizeSizeGivenAspectRatio(
targetArea: Size,
aspectRatio: Float,
captionInsets: Int = 0,
+ requestedScreenOrientation: Int? = null,
): Size {
val targetHeight = targetArea.height - captionInsets
val targetWidth = targetArea.width
val finalHeight: Int
val finalWidth: Int
// Get orientation either through top activity or task's orientation
- if (taskInfo.hasPortraitTopActivity()) {
+ val screenOrientation =
+ requestedScreenOrientation ?: taskInfo.topActivityInfo?.screenOrientation
+ if (taskInfo.hasPortraitTopActivity(screenOrientation)) {
val tempWidth = ceil(targetHeight / aspectRatio).toInt()
if (tempWidth <= targetWidth) {
finalHeight = targetHeight
@@ -354,9 +367,8 @@ fun centerInArea(desiredSize: Size, areaBounds: Rect, leftStart: Int, topStart:
return Rect(newLeft, newTop, newRight, newBottom)
}
-private fun TaskInfo.hasPortraitTopActivity(): Boolean {
- val topActivityScreenOrientation =
- topActivityInfo?.screenOrientation ?: SCREEN_ORIENTATION_UNSPECIFIED
+private fun TaskInfo.hasPortraitTopActivity(screenOrientation: Int?): Boolean {
+ val topActivityScreenOrientation = screenOrientation ?: SCREEN_ORIENTATION_UNSPECIFIED
val appBounds = configuration.windowConfiguration.appBounds
return when {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
index 3e03e001c49b..8e10f15a36cc 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
@@ -1135,6 +1135,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
if (openingLeafCount > 0) {
appearedTargets = new RemoteAnimationTarget[openingLeafCount];
}
+ boolean onlyOpeningPausedTasks = true;
int nextTargetIdx = 0;
for (int i = 0; i < openingTasks.size(); ++i) {
final TransitionInfo.Change change = openingTasks.get(i);
@@ -1188,6 +1189,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
" opening new leaf taskId=%d wasClosing=%b",
target.taskId, wasClosing);
mOpeningTasks.add(new TaskState(change, target.leash));
+ onlyOpeningPausedTasks = false;
} else {
ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
" opening new taskId=%d", change.getTaskInfo().taskId);
@@ -1196,10 +1198,17 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
// is only animating the leafs.
startT.show(change.getLeash());
mOpeningTasks.add(new TaskState(change, null));
+ onlyOpeningPausedTasks = false;
}
}
didMergeThings = true;
- mState = STATE_NEW_TASK;
+ if (!onlyOpeningPausedTasks) {
+ // If we are only opening paused leaf tasks, then we aren't actually quick
+ // switching or launching a new task from overview, and if Launcher requests to
+ // finish(toHome=false) as a response to the pausing tasks being opened again,
+ // we should allow that to be considered returningToApp
+ mState = STATE_NEW_TASK;
+ }
}
if (mPausingTasks.isEmpty()) {
// The pausing tasks may be removed by the incoming closing tasks.
@@ -1368,8 +1377,9 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
"[%d] RecentsController.finishInner: toHome=%b userLeave=%b "
- + "willFinishToHome=%b state=%d reason=%s",
- mInstanceId, toHome, sendUserLeaveHint, mWillFinishToHome, mState, reason);
+ + "willFinishToHome=%b state=%d hasPausingTasks=%b reason=%s",
+ mInstanceId, toHome, sendUserLeaveHint, mWillFinishToHome, mState,
+ mPausingTasks != null, reason);
final SurfaceControl.Transaction t = mFinishTransaction;
final WindowContainerTransaction wct = new WindowContainerTransaction();
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java
index 003ef1d453fc..4f49ebcd2e83 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java
@@ -602,6 +602,11 @@ public class Transitions implements RemoteCallable<Transitions>,
// Just in case there is a race with another animation (eg. recents finish()).
// Changes are visible->visible so it's a problem if it isn't visible.
t.show(leash);
+ // If there is a transient launch followed by a launch of one of the pausing tasks,
+ // we may end up with TRANSIT_TO_BACK followed by a CHANGE (w/ flag MOVE_TO_TOP),
+ // but since we are hiding the leash in the finish transaction above, we should also
+ // update the finish transaction here to reflect the change in visibility
+ finishT.show(leash);
}
}
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt
index 284fbc310cbe..2d44395b1340 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt
@@ -500,6 +500,12 @@ class HandleMenu(
t = iconButtondrawableBaseInset,
b = iconButtondrawableBaseInset, l = 0, r = iconButtondrawableShiftInset
)
+ private val iconButtonDrawableInsetStart
+ get() =
+ if (context.isRtl) iconButtonDrawableInsetsRight else iconButtonDrawableInsetsLeft
+ private val iconButtonDrawableInsetEnd
+ get() =
+ if (context.isRtl) iconButtonDrawableInsetsLeft else iconButtonDrawableInsetsRight
// App Info Pill.
private val appInfoPill = rootView.requireViewById<View>(R.id.app_info_pill)
@@ -760,16 +766,11 @@ class HandleMenu(
desktopBtn.isEnabled = !taskInfo.isFreeform
desktopBtn.imageTintList = style.windowingButtonColor
- val startInsets = if (context.isRtl) iconButtonDrawableInsetsRight
- else iconButtonDrawableInsetsLeft
- val endInsets = if (context.isRtl) iconButtonDrawableInsetsLeft
- else iconButtonDrawableInsetsRight
-
fullscreenBtn.apply {
background = createBackgroundDrawable(
color = style.textColor,
cornerRadius = iconButtonRippleRadius,
- drawableInsets = startInsets
+ drawableInsets = iconButtonDrawableInsetStart
)
}
@@ -793,7 +794,7 @@ class HandleMenu(
background = createBackgroundDrawable(
color = style.textColor,
cornerRadius = iconButtonRippleRadius,
- drawableInsets = endInsets
+ drawableInsets = iconButtonDrawableInsetEnd
)
}
}
@@ -843,6 +844,10 @@ class HandleMenu(
openByDefaultBtn.apply {
isGone = isBrowserApp
imageTintList = ColorStateList.valueOf(style.textColor)
+ background = createBackgroundDrawable(
+ color = style.textColor,
+ cornerRadius = iconButtonRippleRadius,
+ drawableInsets = iconButtonDrawableInsetEnd)
}
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.java
deleted file mode 100644
index 25dbc64f83de..000000000000
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.wm.shell.common.pip;
-
-import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
-import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
-import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
-
-import static com.android.window.flags.Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_PIP;
-import static com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_PIP;
-import static com.android.wm.shell.Flags.FLAG_ENABLE_PIP2;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-
-import static org.mockito.Mockito.when;
-
-import android.app.ActivityManager;
-import android.platform.test.annotations.EnableFlags;
-import android.testing.AndroidTestingRunner;
-import android.testing.TestableLooper;
-import android.window.DisplayAreaInfo;
-import android.window.WindowContainerToken;
-
-import androidx.test.filters.SmallTest;
-
-import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
-import com.android.wm.shell.desktopmode.DesktopRepository;
-import com.android.wm.shell.desktopmode.DesktopUserRepositories;
-import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-import java.util.Optional;
-
-/**
- * Unit test against {@link PipDesktopState}.
- */
-@SmallTest
-@TestableLooper.RunWithLooper
-@RunWith(AndroidTestingRunner.class)
-@EnableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_PIP)
-public class PipDesktopStateTest {
- @Mock private PipDisplayLayoutState mMockPipDisplayLayoutState;
- @Mock private Optional<DesktopUserRepositories> mMockDesktopUserRepositoriesOptional;
- @Mock private DesktopUserRepositories mMockDesktopUserRepositories;
- @Mock private DesktopRepository mMockDesktopRepository;
- @Mock
- private Optional<DragToDesktopTransitionHandler> mMockDragToDesktopTransitionHandlerOptional;
- @Mock private DragToDesktopTransitionHandler mMockDragToDesktopTransitionHandler;
-
- @Mock private RootTaskDisplayAreaOrganizer mMockRootTaskDisplayAreaOrganizer;
- @Mock private ActivityManager.RunningTaskInfo mMockTaskInfo;
-
- private static final int DISPLAY_ID = 1;
- private DisplayAreaInfo mDefaultTda;
- private PipDesktopState mPipDesktopState;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- when(mMockDesktopUserRepositoriesOptional.get()).thenReturn(mMockDesktopUserRepositories);
- when(mMockDesktopUserRepositories.getCurrent()).thenReturn(mMockDesktopRepository);
- when(mMockDesktopUserRepositoriesOptional.isPresent()).thenReturn(true);
-
- when(mMockDragToDesktopTransitionHandlerOptional.get()).thenReturn(
- mMockDragToDesktopTransitionHandler);
- when(mMockDragToDesktopTransitionHandlerOptional.isPresent()).thenReturn(true);
-
- when(mMockTaskInfo.getDisplayId()).thenReturn(DISPLAY_ID);
- when(mMockPipDisplayLayoutState.getDisplayId()).thenReturn(DISPLAY_ID);
-
- mDefaultTda = new DisplayAreaInfo(Mockito.mock(WindowContainerToken.class), DISPLAY_ID, 0);
- when(mMockRootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DISPLAY_ID)).thenReturn(
- mDefaultTda);
-
- mPipDesktopState = new PipDesktopState(mMockPipDisplayLayoutState,
- mMockDesktopUserRepositoriesOptional,
- mMockDragToDesktopTransitionHandlerOptional,
- mMockRootTaskDisplayAreaOrganizer);
- }
-
- @Test
- public void isDesktopWindowingPipEnabled_returnsTrue() {
- assertTrue(mPipDesktopState.isDesktopWindowingPipEnabled());
- }
-
- @Test
- public void isDesktopWindowingPipEnabled_desktopRepositoryEmpty_returnsFalse() {
- when(mMockDesktopUserRepositoriesOptional.isPresent()).thenReturn(false);
-
- assertFalse(mPipDesktopState.isDesktopWindowingPipEnabled());
- }
-
- @Test
- public void isDesktopWindowingPipEnabled_dragToDesktopTransitionHandlerEmpty_returnsFalse() {
- when(mMockDragToDesktopTransitionHandlerOptional.isPresent()).thenReturn(false);
-
- assertFalse(mPipDesktopState.isDesktopWindowingPipEnabled());
- }
-
- @Test
- @EnableFlags({
- FLAG_ENABLE_CONNECTED_DISPLAYS_PIP, FLAG_ENABLE_PIP2
- })
- public void isConnectedDisplaysPipEnabled_returnsTrue() {
- assertTrue(mPipDesktopState.isConnectedDisplaysPipEnabled());
- }
-
- @Test
- public void isPipInDesktopMode_anyDeskActive_returnsTrue() {
- when(mMockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(true);
-
- assertTrue(mPipDesktopState.isPipInDesktopMode());
- }
-
- @Test
- public void isPipInDesktopMode_noDeskActive_returnsFalse() {
- when(mMockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(false);
-
- assertFalse(mPipDesktopState.isPipInDesktopMode());
- }
-
- @Test
- public void getOutPipWindowingMode_exitToDesktop_displayFreeform_returnsUndefined() {
- when(mMockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(true);
- setDisplayWindowingMode(WINDOWING_MODE_FREEFORM);
-
- assertEquals(WINDOWING_MODE_UNDEFINED, mPipDesktopState.getOutPipWindowingMode());
- }
-
- @Test
- public void getOutPipWindowingMode_exitToDesktop_displayFullscreen_returnsFreeform() {
- when(mMockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(true);
- setDisplayWindowingMode(WINDOWING_MODE_FULLSCREEN);
-
- assertEquals(WINDOWING_MODE_FREEFORM, mPipDesktopState.getOutPipWindowingMode());
- }
-
- @Test
- public void getOutPipWindowingMode_exitToFullscreen_displayFullscreen_returnsUndefined() {
- setDisplayWindowingMode(WINDOWING_MODE_FULLSCREEN);
-
- assertEquals(WINDOWING_MODE_UNDEFINED, mPipDesktopState.getOutPipWindowingMode());
- }
-
- @Test
- public void isDragToDesktopInProgress_inProgress_returnsTrue() {
- when(mMockDragToDesktopTransitionHandler.getInProgress()).thenReturn(true);
-
- assertTrue(mPipDesktopState.isDragToDesktopInProgress());
- }
-
- @Test
- public void isDragToDesktopInProgress_notInProgress_returnsFalse() {
- when(mMockDragToDesktopTransitionHandler.getInProgress()).thenReturn(false);
-
- assertFalse(mPipDesktopState.isDragToDesktopInProgress());
- }
-
- private void setDisplayWindowingMode(int windowingMode) {
- mDefaultTda.configuration.windowConfiguration.setWindowingMode(windowingMode);
- }
-}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.kt
new file mode 100644
index 000000000000..2c50cd9d0c81
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipDesktopStateTest.kt
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.wm.shell.common.pip
+
+import android.app.ActivityManager
+import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
+import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
+import android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED
+import android.platform.test.annotations.EnableFlags
+import android.testing.AndroidTestingRunner
+import android.testing.TestableLooper.RunWithLooper
+import android.window.DisplayAreaInfo
+import android.window.WindowContainerToken
+import androidx.test.filters.SmallTest
+import com.android.window.flags.Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_PIP
+import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_PIP
+import com.android.wm.shell.Flags.FLAG_ENABLE_PIP2
+import com.android.wm.shell.RootTaskDisplayAreaOrganizer
+import com.android.wm.shell.ShellTestCase
+import com.android.wm.shell.desktopmode.DesktopRepository
+import com.android.wm.shell.desktopmode.DesktopUserRepositories
+import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler
+import com.google.common.truth.Truth.assertThat
+import java.util.Optional
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.whenever
+
+/**
+ * Unit test against [PipDesktopState].
+ */
+@SmallTest
+@RunWithLooper
+@RunWith(AndroidTestingRunner::class)
+@EnableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_PIP)
+class PipDesktopStateTest : ShellTestCase() {
+ private val mockPipDisplayLayoutState = mock<PipDisplayLayoutState>()
+ private val mockDesktopUserRepositories = mock<DesktopUserRepositories>()
+ private val mockDesktopRepository = mock<DesktopRepository>()
+ private val mockDragToDesktopTransitionHandler = mock<DragToDesktopTransitionHandler>()
+ private val mockRootTaskDisplayAreaOrganizer = mock<RootTaskDisplayAreaOrganizer>()
+ private val mockTaskInfo = mock<ActivityManager.RunningTaskInfo>()
+ private lateinit var defaultTda: DisplayAreaInfo
+ private lateinit var pipDesktopState: PipDesktopState
+
+ @Before
+ fun setUp() {
+ whenever(mockDesktopUserRepositories.current).thenReturn(mockDesktopRepository)
+ whenever(mockTaskInfo.getDisplayId()).thenReturn(DISPLAY_ID)
+ whenever(mockPipDisplayLayoutState.displayId).thenReturn(DISPLAY_ID)
+
+ defaultTda = DisplayAreaInfo(mock<WindowContainerToken>(), DISPLAY_ID, /* featureId = */ 0)
+ whenever(mockRootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DISPLAY_ID)).thenReturn(
+ defaultTda
+ )
+
+ pipDesktopState =
+ PipDesktopState(
+ mockPipDisplayLayoutState,
+ Optional.of(mockDesktopUserRepositories),
+ Optional.of(mockDragToDesktopTransitionHandler),
+ mockRootTaskDisplayAreaOrganizer
+ )
+ }
+
+ @Test
+ fun isDesktopWindowingPipEnabled_returnsTrue() {
+ assertThat(pipDesktopState.isDesktopWindowingPipEnabled()).isTrue()
+ }
+
+ @Test
+ @EnableFlags(
+ FLAG_ENABLE_CONNECTED_DISPLAYS_PIP,
+ FLAG_ENABLE_PIP2
+ )
+ fun isConnectedDisplaysPipEnabled_returnsTrue() {
+ assertThat(pipDesktopState.isConnectedDisplaysPipEnabled()).isTrue()
+ }
+
+ @Test
+ fun isPipInDesktopMode_anyDeskActive_returnsTrue() {
+ whenever(mockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(true)
+
+ assertThat(pipDesktopState.isPipInDesktopMode()).isTrue()
+ }
+
+ @Test
+ fun isPipInDesktopMode_noDeskActive_returnsFalse() {
+ whenever(mockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(false)
+
+ assertThat(pipDesktopState.isPipInDesktopMode()).isFalse()
+ }
+
+ @Test
+ fun outPipWindowingMode_exitToDesktop_displayFreeform_returnsUndefined() {
+ whenever(mockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(true)
+ setDisplayWindowingMode(WINDOWING_MODE_FREEFORM)
+
+ assertThat(pipDesktopState.getOutPipWindowingMode()).isEqualTo(WINDOWING_MODE_UNDEFINED)
+ }
+
+ @Test
+ fun outPipWindowingMode_exitToDesktop_displayFullscreen_returnsFreeform() {
+ whenever(mockDesktopRepository.isAnyDeskActive(DISPLAY_ID)).thenReturn(true)
+ setDisplayWindowingMode(WINDOWING_MODE_FULLSCREEN)
+
+ assertThat(pipDesktopState.getOutPipWindowingMode()).isEqualTo(WINDOWING_MODE_FREEFORM)
+ }
+
+ @Test
+ fun outPipWindowingMode_exitToFullscreen_displayFullscreen_returnsUndefined() {
+ setDisplayWindowingMode(WINDOWING_MODE_FULLSCREEN)
+
+ assertThat(pipDesktopState.getOutPipWindowingMode()).isEqualTo(WINDOWING_MODE_UNDEFINED)
+ }
+
+ @Test
+ fun isDragToDesktopInProgress_inProgress_returnsTrue() {
+ whenever(mockDragToDesktopTransitionHandler.inProgress).thenReturn(true)
+
+ assertThat(pipDesktopState.isDragToDesktopInProgress()).isTrue()
+ }
+
+ @Test
+ fun isDragToDesktopInProgress_notInProgress_returnsFalse() {
+ whenever(mockDragToDesktopTransitionHandler.inProgress).thenReturn(false)
+
+ assertThat(pipDesktopState.isDragToDesktopInProgress()).isFalse()
+ }
+
+ private fun setDisplayWindowingMode(windowingMode: Int) {
+ defaultTda.configuration.windowConfiguration.windowingMode = windowingMode
+ }
+
+ companion object {
+ private const val DISPLAY_ID = 1
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java
index 597e4a55ed0e..9035df28aa7c 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java
@@ -680,7 +680,8 @@ public class CompatUIControllerTest extends ShellTestCase {
// Create transparent task
final TaskInfo taskInfo1 = createTaskInfo(DISPLAY_ID, newTaskId, /* hasSizeCompat= */ true,
- /* isVisible */ true, /* isFocused */ true, /* isTopActivityTransparent */ true);
+ /* isVisible */ true, /* isFocused */ true, /* isTopActivityTransparent */ true,
+ /* isRestartMenuEnabledForDisplayMove */ true);
// Simulate new task being shown
mController.updateActiveTaskInfo(taskInfo1);
@@ -742,32 +743,38 @@ public class CompatUIControllerTest extends ShellTestCase {
@Test
@RequiresFlagsDisabled(Flags.FLAG_APP_COMPAT_UI_FRAMEWORK)
public void testSendCompatUIRequest_createRestartDialog() {
- TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ false);
- doReturn(true).when(mMockRestartDialogLayout)
- .needsToBeRecreated(any(TaskInfo.class),
- any(ShellTaskOrganizer.TaskListener.class));
+ final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true,
+ /* isVisible */ true, /* isFocused */ true, /* isTopActivityTransparent */ false,
+ /* isRestartMenuEnabledForDisplayMove */ true);
doReturn(true).when(mCompatUIConfiguration).isRestartDialogEnabled();
doReturn(true).when(mCompatUIConfiguration).shouldShowRestartDialogAgain(eq(taskInfo));
- mController.sendCompatUIRequest(new CompatUIRequests.DisplayCompatShowRestartDialog(
- taskInfo, mMockTaskListener));
+ mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));
verify(mController).createRestartDialogWindowManager(any(), eq(taskInfo),
eq(mMockTaskListener));
+ verify(mMockRestartDialogLayout).setRequestRestartDialog(false);
+
+ mController.sendCompatUIRequest(
+ new CompatUIRequests.DisplayCompatShowRestartDialog(taskInfo.taskId));
+ verify(mMockRestartDialogLayout).setRequestRestartDialog(true);
}
private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat) {
return createTaskInfo(displayId, taskId, hasSizeCompat, /* isVisible */ false,
- /* isFocused */ false, /* isTopActivityTransparent */ false);
+ /* isFocused */ false, /* isTopActivityTransparent */ false,
+ /* isRestartMenuEnabledForDisplayMove */ false);
}
private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat,
boolean isVisible, boolean isFocused) {
return createTaskInfo(displayId, taskId, hasSizeCompat,
- isVisible, isFocused, /* isTopActivityTransparent */ false);
+ isVisible, isFocused, /* isTopActivityTransparent */ false,
+ /* isRestartMenuEnabledForDisplayMove */ false);
}
private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat,
- boolean isVisible, boolean isFocused, boolean isTopActivityTransparent) {
+ boolean isVisible, boolean isFocused, boolean isTopActivityTransparent,
+ boolean isRestartMenuEnabledForDisplayMove) {
RunningTaskInfo taskInfo = new RunningTaskInfo();
taskInfo.taskId = taskId;
taskInfo.displayId = displayId;
@@ -777,6 +784,8 @@ public class CompatUIControllerTest extends ShellTestCase {
taskInfo.isTopActivityTransparent = isTopActivityTransparent;
taskInfo.appCompatTaskInfo.setLetterboxEducationEnabled(true);
taskInfo.appCompatTaskInfo.setTopActivityLetterboxed(true);
+ taskInfo.appCompatTaskInfo.setRestartMenuEnabledForDisplayMove(
+ isRestartMenuEnabledForDisplayMove);
return taskInfo;
}
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandlerTest.kt
index d58f8a34c98e..94fe03084989 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandlerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandlerTest.kt
@@ -37,6 +37,8 @@ import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE
import com.android.window.flags.Flags.FLAG_RESPECT_ORIENTATION_CHANGE_FOR_UNRESIZEABLE
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
+import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.common.DisplayLayout
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.TaskStackListenerImpl
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask
@@ -96,12 +98,15 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
@Mock lateinit var repositoryInitializer: DesktopRepositoryInitializer
@Mock lateinit var userManager: UserManager
@Mock lateinit var shellController: ShellController
+ @Mock lateinit var displayController: DisplayController
+ @Mock lateinit var displayLayout: DisplayLayout
private lateinit var mockitoSession: StaticMockitoSession
private lateinit var handler: DesktopActivityOrientationChangeHandler
private lateinit var shellInit: ShellInit
private lateinit var userRepositories: DesktopUserRepositories
private lateinit var testScope: CoroutineScope
+
// Mock running tasks are registered here so we can get the list from mock shell task organizer.
private val runningTasks = mutableListOf<RunningTaskInfo>()
@@ -131,6 +136,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
whenever(transitions.startTransition(anyInt(), any(), isNull())).thenAnswer { Binder() }
whenever(runBlocking { persistentRepository.readDesktop(any(), any()) })
.thenReturn(Desktop.getDefaultInstance())
+ whenever(displayController.getDisplayLayout(anyInt())).thenReturn(displayLayout)
handler =
DesktopActivityOrientationChangeHandler(
@@ -140,6 +146,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
taskStackListener,
resizeTransitionHandler,
userRepositories,
+ displayController,
)
shellInit.init()
@@ -171,6 +178,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
taskStackListener,
resizeTransitionHandler,
userRepositories,
+ displayController,
)
verify(shellInit, never())
@@ -251,6 +259,11 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
val oldBounds = task.configuration.windowConfiguration.bounds
val newTask =
setUpFreeformTask(isResizeable = false, orientation = SCREEN_ORIENTATION_LANDSCAPE)
+ whenever(displayLayout.height()).thenReturn(800)
+ whenever(displayLayout.width()).thenReturn(2000)
+ whenever(displayLayout.getStableBounds(any())).thenAnswer { i ->
+ (i.arguments.first() as Rect).set(Rect(0, 0, 2000, 800))
+ }
handler.handleActivityOrientationChange(task, newTask)
@@ -279,6 +292,11 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
bounds = oldBounds,
)
val newTask = setUpFreeformTask(isResizeable = false, bounds = oldBounds)
+ whenever(displayLayout.height()).thenReturn(2000)
+ whenever(displayLayout.width()).thenReturn(800)
+ whenever(displayLayout.getStableBounds(any())).thenAnswer { i ->
+ (i.arguments.first() as Rect).set(Rect(0, 0, 800, 2000))
+ }
handler.handleActivityOrientationChange(task, newTask)
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandlerTest.kt
index 2aebcdcc3bf5..9268db60aa51 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandlerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandlerTest.kt
@@ -24,13 +24,16 @@ import com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession
import com.android.dx.mockito.inline.extended.ExtendedMockito.never
import com.android.dx.mockito.inline.extended.StaticMockitoSession
import com.android.window.flags.Flags
+import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayController.OnDisplaysChangedListener
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.desktopmode.persistence.DesktopRepositoryInitializer
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
+import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
+import com.android.wm.shell.sysui.UserChangeListener
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
@@ -46,6 +49,7 @@ import org.mockito.Mockito.spy
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.kotlin.argumentCaptor
+import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.whenever
import org.mockito.quality.Strictness
@@ -60,6 +64,8 @@ import org.mockito.quality.Strictness
class DesktopDisplayEventHandlerTest : ShellTestCase() {
@Mock lateinit var testExecutor: ShellExecutor
@Mock lateinit var displayController: DisplayController
+ @Mock private lateinit var mockShellController: ShellController
+ @Mock private lateinit var mockRootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer
@Mock private lateinit var mockDesktopUserRepositories: DesktopUserRepositories
@Mock private lateinit var mockDesktopRepository: DesktopRepository
@Mock private lateinit var mockDesktopTasksController: DesktopTasksController
@@ -89,7 +95,9 @@ class DesktopDisplayEventHandlerTest : ShellTestCase() {
context,
shellInit,
testScope.backgroundScope,
+ mockShellController,
displayController,
+ mockRootTaskDisplayAreaOrganizer,
desktopRepositoryInitializer,
mockDesktopUserRepositories,
mockDesktopTasksController,
@@ -107,6 +115,7 @@ class DesktopDisplayEventHandlerTest : ShellTestCase() {
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
fun testDisplayAdded_supportsDesks_desktopRepositoryInitialized_createsDesk() =
testScope.runTest {
whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
@@ -119,6 +128,7 @@ class DesktopDisplayEventHandlerTest : ShellTestCase() {
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
fun testDisplayAdded_supportsDesks_desktopRepositoryNotInitialized_doesNotCreateDesk() =
testScope.runTest {
whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
@@ -130,6 +140,7 @@ class DesktopDisplayEventHandlerTest : ShellTestCase() {
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
fun testDisplayAdded_supportsDesks_desktopRepositoryInitializedTwice_createsDeskOnce() =
testScope.runTest {
whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
@@ -143,6 +154,7 @@ class DesktopDisplayEventHandlerTest : ShellTestCase() {
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
fun testDisplayAdded_supportsDesks_desktopRepositoryInitialized_deskExists_doesNotCreateDesk() =
testScope.runTest {
whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
@@ -156,33 +168,71 @@ class DesktopDisplayEventHandlerTest : ShellTestCase() {
}
@Test
- fun testDisplayAdded_cannotEnterDesktopMode_doesNotCreateDesk() {
- whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(false)
+ @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
+ fun testDisplayAdded_cannotEnterDesktopMode_doesNotCreateDesk() =
+ testScope.runTest {
+ whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(false)
+ desktopRepositoryInitializer.initialize(mockDesktopUserRepositories)
- onDisplaysChangedListenerCaptor.lastValue.onDisplayAdded(DEFAULT_DISPLAY)
+ onDisplaysChangedListenerCaptor.lastValue.onDisplayAdded(DEFAULT_DISPLAY)
+ runCurrent()
- verify(mockDesktopTasksController, never()).createDesk(DEFAULT_DISPLAY)
- }
+ verify(mockDesktopTasksController, never()).createDesk(DEFAULT_DISPLAY)
+ }
@Test
@EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
- fun testDeskRemoved_noDesksRemain_createsDesk() {
- whenever(mockDesktopRepository.getNumberOfDesks(DEFAULT_DISPLAY)).thenReturn(0)
+ fun testDeskRemoved_noDesksRemain_createsDesk() =
+ testScope.runTest {
+ whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
+ whenever(mockDesktopRepository.getNumberOfDesks(DEFAULT_DISPLAY)).thenReturn(0)
+ desktopRepositoryInitializer.initialize(mockDesktopUserRepositories)
- handler.onDeskRemoved(DEFAULT_DISPLAY, deskId = 1)
+ handler.onDeskRemoved(DEFAULT_DISPLAY, deskId = 1)
+ runCurrent()
- verify(mockDesktopTasksController).createDesk(DEFAULT_DISPLAY)
- }
+ verify(mockDesktopTasksController).createDesk(DEFAULT_DISPLAY)
+ }
@Test
@EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
- fun testDeskRemoved_desksRemain_doesNotCreateDesk() {
- whenever(mockDesktopRepository.getNumberOfDesks(DEFAULT_DISPLAY)).thenReturn(1)
+ fun testDeskRemoved_desksRemain_doesNotCreateDesk() =
+ testScope.runTest {
+ whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
+ whenever(mockDesktopRepository.getNumberOfDesks(DEFAULT_DISPLAY)).thenReturn(1)
+ desktopRepositoryInitializer.initialize(mockDesktopUserRepositories)
+
+ handler.onDeskRemoved(DEFAULT_DISPLAY, deskId = 1)
+ runCurrent()
- handler.onDeskRemoved(DEFAULT_DISPLAY, deskId = 1)
+ verify(mockDesktopTasksController, never()).createDesk(DEFAULT_DISPLAY)
+ }
- verify(mockDesktopTasksController, never()).createDesk(DEFAULT_DISPLAY)
- }
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
+ fun testUserChanged_createsDeskWhenNeeded() =
+ testScope.runTest {
+ whenever(DesktopModeStatus.canEnterDesktopMode(context)).thenReturn(true)
+ val userChangeListenerCaptor = argumentCaptor<UserChangeListener>()
+ verify(mockShellController).addUserChangeListener(userChangeListenerCaptor.capture())
+ whenever(mockDesktopRepository.getNumberOfDesks(displayId = 2)).thenReturn(0)
+ whenever(mockDesktopRepository.getNumberOfDesks(displayId = 3)).thenReturn(0)
+ whenever(mockDesktopRepository.getNumberOfDesks(displayId = 4)).thenReturn(1)
+ whenever(mockRootTaskDisplayAreaOrganizer.displayIds).thenReturn(intArrayOf(2, 3, 4))
+ desktopRepositoryInitializer.initialize(mockDesktopUserRepositories)
+ handler.onDisplayAdded(displayId = 2)
+ handler.onDisplayAdded(displayId = 3)
+ handler.onDisplayAdded(displayId = 4)
+ runCurrent()
+
+ clearInvocations(mockDesktopTasksController)
+ userChangeListenerCaptor.lastValue.onUserChanged(1, context)
+ runCurrent()
+
+ verify(mockDesktopTasksController).createDesk(displayId = 2)
+ verify(mockDesktopTasksController).createDesk(displayId = 3)
+ verify(mockDesktopTasksController, never()).createDesk(displayId = 4)
+ }
@Test
fun testConnectExternalDisplay() {
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandlerTest.kt
index d510570e8839..e40da5e8498d 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandlerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandlerTest.kt
@@ -50,7 +50,6 @@ import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel
-import com.google.common.truth.Truth.assertThat
import java.util.Optional
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -120,11 +119,11 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
whenever(rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)).thenReturn(tda)
doAnswer {
- keyGestureEventHandler = (it.arguments[0] as KeyGestureEventHandler)
+ keyGestureEventHandler = (it.arguments[1] as KeyGestureEventHandler)
null
}
.whenever(inputManager)
- .registerKeyGestureEventHandler(any())
+ .registerKeyGestureEventHandler(any(), any())
shellInit.init()
desktopModeKeyGestureHandler =
@@ -176,10 +175,9 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
.setKeycodes(intArrayOf(KeyEvent.KEYCODE_D))
.setModifierState(KeyEvent.META_META_ON or KeyEvent.META_CTRL_ON)
.build()
- val result = keyGestureEventHandler.handleKeyGestureEvent(event, null)
+ keyGestureEventHandler.handleKeyGestureEvent(event, null)
testExecutor.flushAll()
- assertThat(result).isTrue()
verify(desktopTasksController).moveToNextDisplay(task.taskId)
}
@@ -197,10 +195,9 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
.setKeycodes(intArrayOf(KeyEvent.KEYCODE_LEFT_BRACKET))
.setModifierState(KeyEvent.META_META_ON)
.build()
- val result = keyGestureEventHandler.handleKeyGestureEvent(event, null)
+ keyGestureEventHandler.handleKeyGestureEvent(event, null)
testExecutor.flushAll()
- assertThat(result).isTrue()
verify(desktopModeWindowDecorViewModel)
.onSnapResize(
task.taskId,
@@ -224,10 +221,9 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
.setKeycodes(intArrayOf(KeyEvent.KEYCODE_RIGHT_BRACKET))
.setModifierState(KeyEvent.META_META_ON)
.build()
- val result = keyGestureEventHandler.handleKeyGestureEvent(event, null)
+ keyGestureEventHandler.handleKeyGestureEvent(event, null)
testExecutor.flushAll()
- assertThat(result).isTrue()
verify(desktopModeWindowDecorViewModel)
.onSnapResize(
task.taskId,
@@ -251,10 +247,9 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
.setKeycodes(intArrayOf(KeyEvent.KEYCODE_EQUALS))
.setModifierState(KeyEvent.META_META_ON)
.build()
- val result = keyGestureEventHandler.handleKeyGestureEvent(event, null)
+ keyGestureEventHandler.handleKeyGestureEvent(event, null)
testExecutor.flushAll()
- assertThat(result).isTrue()
verify(desktopTasksController)
.toggleDesktopTaskSize(
task,
@@ -280,10 +275,9 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
.setKeycodes(intArrayOf(KeyEvent.KEYCODE_MINUS))
.setModifierState(KeyEvent.META_META_ON)
.build()
- val result = keyGestureEventHandler.handleKeyGestureEvent(event, null)
+ keyGestureEventHandler.handleKeyGestureEvent(event, null)
testExecutor.flushAll()
- assertThat(result).isTrue()
verify(desktopTasksController).minimizeTask(task, MinimizeReason.KEY_GESTURE)
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java
index 677330790bab..9849b1174d8e 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java
@@ -37,6 +37,7 @@ import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.window.TransitionInfo.FLAG_DISPLAY_HAS_ALERT_WINDOWS;
import static android.window.TransitionInfo.FLAG_IS_DISPLAY;
+import static android.window.TransitionInfo.FLAG_MOVED_TO_TOP;
import static android.window.TransitionInfo.FLAG_SYNC;
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;
@@ -1742,6 +1743,53 @@ public class ShellTransitionTests extends ShellTestCase {
eq(R.styleable.WindowAnimation_activityCloseEnterAnimation), anyBoolean());
}
+ @Test
+ public void testTransientHideWithMoveToTop() {
+ Transitions transitions = createTestTransitions();
+ transitions.replaceDefaultHandlerForTest(mDefaultHandler);
+ final TransitionAnimation transitionAnimation = new TransitionAnimation(mContext, false,
+ Transitions.TAG);
+ spyOn(transitionAnimation);
+
+ // Prepare for a TO_BACK transition
+ final RunningTaskInfo taskInfo = createTaskInfo(1);
+ final IBinder closeTransition = new Binder();
+ final SurfaceControl.Transaction closeTransitionFinishT =
+ mock(SurfaceControl.Transaction.class);
+
+ // Start a TO_BACK transition
+ transitions.requestStartTransition(closeTransition,
+ new TransitionRequestInfo(TRANSIT_TO_BACK, null /* trigger */, null /* remote */));
+ TransitionInfo closeInfo = new TransitionInfoBuilder(TRANSIT_TO_BACK)
+ .addChange(TRANSIT_TO_BACK, taskInfo)
+ .build();
+ transitions.onTransitionReady(closeTransition, closeInfo, new StubTransaction(),
+ closeTransitionFinishT);
+
+ // Verify that the transition hides the task surface in the finish transaction
+ verify(closeTransitionFinishT).hide(any());
+
+ // Prepare for a CHANGE transition
+ final IBinder changeTransition = new Binder();
+ final SurfaceControl.Transaction changeTransitionFinishT =
+ mock(SurfaceControl.Transaction.class);
+
+ // Start a CHANGE transition w/ MOVE_TO_FRONT that is merged into the TO_BACK
+ mDefaultHandler.setShouldMerge(changeTransition);
+ transitions.requestStartTransition(changeTransition,
+ new TransitionRequestInfo(TRANSIT_OPEN, null /* trigger */, null /* remote */));
+ TransitionInfo changeInfo = new TransitionInfoBuilder(TRANSIT_OPEN)
+ .addChange(TRANSIT_CHANGE, FLAG_MOVED_TO_TOP, taskInfo)
+ .build();
+ transitions.onTransitionReady(changeTransition, changeInfo, new StubTransaction(),
+ changeTransitionFinishT);
+
+ // Verify that the transition shows the task surface in the finish transaction so that the
+ // when the original transition finishes, the finish transaction does not clobber the
+ // visibility of the merged transition
+ verify(changeTransitionFinishT).show(any());
+ }
+
class TestTransitionHandler implements Transitions.TransitionHandler {
ArrayList<Pair<IBinder, Transitions.TransitionFinishCallback>> mFinishes =
new ArrayList<>();
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 f7b9c3352dea..dd777a5ed270 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
@@ -1916,6 +1916,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
.setTaskDescriptionBuilder(taskDescriptionBuilder)
.setVisible(visible)
.build();
+ taskInfo.isVisibleRequested = visible;
taskInfo.realActivity = new ComponentName("com.android.wm.shell.windowdecor",
"DesktopModeWindowDecorationTests");
taskInfo.baseActivity = new ComponentName("com.android.wm.shell.windowdecor",
diff --git a/media/tests/projection/Android.bp b/media/tests/projection/Android.bp
index 94db2c02eb28..48621e4e2094 100644
--- a/media/tests/projection/Android.bp
+++ b/media/tests/projection/Android.bp
@@ -16,7 +16,6 @@ android_test {
name: "MediaProjectionTests",
srcs: ["**/*.java"],
-
libs: [
"android.test.base.stubs.system",
"android.test.mock.stubs.system",
@@ -30,6 +29,7 @@ android_test {
"frameworks-base-testutils",
"mockito-target-extended-minus-junit4",
"platform-test-annotations",
+ "cts-mediaprojection-common",
"testng",
"testables",
"truth",
@@ -42,7 +42,11 @@ android_test {
"libstaticjvmtiagent",
],
- test_suites: ["device-tests"],
+ data: [
+ ":CtsMediaProjectionTestCasesHelperApp",
+ ],
+
+ test_suites: ["general-tests"],
platform_apis: true,
diff --git a/media/tests/projection/AndroidManifest.xml b/media/tests/projection/AndroidManifest.xml
index 0c9760400ce0..514fb5f689c9 100644
--- a/media/tests/projection/AndroidManifest.xml
+++ b/media/tests/projection/AndroidManifest.xml
@@ -20,6 +20,8 @@
android:sharedUserId="com.android.uid.test">
<uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG" />
<uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION" />
+ <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application android:debuggable="true"
android:testOnly="true">
diff --git a/media/tests/projection/AndroidTest.xml b/media/tests/projection/AndroidTest.xml
index f64930a0eb3f..99b42d1cd263 100644
--- a/media/tests/projection/AndroidTest.xml
+++ b/media/tests/projection/AndroidTest.xml
@@ -22,6 +22,15 @@
<option name="install-arg" value="-t" />
<option name="test-file-name" value="MediaProjectionTests.apk" />
</target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <option name="force-install-mode" value="FULL"/>ss
+ <option name="test-file-name" value="CtsMediaProjectionTestCasesHelperApp.apk" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <option name="run-command" value="input keyevent KEYCODE_WAKEUP" />
+ <option name="run-command" value="wm dismiss-keyguard" />
+ </target_preparer>
<option name="test-tag" value="MediaProjectionTests" />
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
diff --git a/media/tests/projection/src/android/media/projection/MediaProjectionStoppingTest.java b/media/tests/projection/src/android/media/projection/MediaProjectionStoppingTest.java
new file mode 100644
index 000000000000..0b84e01c4d02
--- /dev/null
+++ b/media/tests/projection/src/android/media/projection/MediaProjectionStoppingTest.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.media.projection;
+
+import static com.android.compatibility.common.util.FeatureUtil.isAutomotive;
+import static com.android.compatibility.common.util.FeatureUtil.isTV;
+import static com.android.compatibility.common.util.FeatureUtil.isWatch;
+import static com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
+
+import android.Manifest;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.media.cts.MediaProjectionRule;
+import android.os.UserHandle;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.telecom.TelecomManager;
+import android.telephony.TelephonyCallback;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.uiautomator.By;
+import androidx.test.uiautomator.UiDevice;
+import androidx.test.uiautomator.Until;
+
+import com.android.compatibility.common.util.ApiTest;
+import com.android.compatibility.common.util.FrameworkSpecificTest;
+import com.android.media.projection.flags.Flags;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Test {@link MediaProjection} stopping behavior.
+ *
+ * Run with:
+ * atest MediaProjectionTests:MediaProjectionStoppingTest
+ */
+@FrameworkSpecificTest
+public class MediaProjectionStoppingTest {
+ private static final String TAG = "MediaProjectionStoppingTest";
+ private static final int STOP_DIALOG_WAIT_TIMEOUT_MS = 5000;
+ private static final String CALL_HELPER_START_CALL = "start_call";
+ private static final String CALL_HELPER_STOP_CALL = "stop_call";
+ private static final String STOP_DIALOG_TITLE_RES_ID = "android:id/alertTitle";
+ private static final String STOP_DIALOG_CLOSE_BUTTON_RES_ID = "android:id/button2";
+
+ @Rule public MediaProjectionRule mMediaProjectionRule = new MediaProjectionRule();
+
+ private Context mContext;
+ private int mTimeoutMs;
+ private TelecomManager mTelecomManager;
+ private TelephonyManager mTelephonyManager;
+ private TestCallStateListener mTestCallStateListener;
+
+ @Before
+ public void setUp() throws InterruptedException {
+ mContext = InstrumentationRegistry.getInstrumentation().getContext();
+ runWithShellPermissionIdentity(
+ () -> {
+ mContext.getPackageManager()
+ .revokeRuntimePermission(
+ mContext.getPackageName(),
+ Manifest.permission.SYSTEM_ALERT_WINDOW,
+ new UserHandle(mContext.getUserId()));
+ });
+ mTimeoutMs = 1000;
+
+ mTestCallStateListener = new TestCallStateListener(mContext);
+ }
+
+ @After
+ public void cleanup() {
+ mTestCallStateListener.release();
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_STOP_MEDIA_PROJECTION_ON_CALL_END)
+ @ApiTest(apis = "android.media.projection.MediaProjection.Callback#onStop")
+ public void testMediaProjectionStop_callStartedAfterMediaProjection_doesNotStop()
+ throws Exception {
+ assumeTrue(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELECOM));
+
+ mMediaProjectionRule.startMediaProjection();
+
+ CountDownLatch latch = new CountDownLatch(1);
+ mMediaProjectionRule.registerCallback(
+ new MediaProjection.Callback() {
+ @Override
+ public void onStop() {
+ latch.countDown();
+ }
+ });
+ mMediaProjectionRule.createVirtualDisplay();
+
+ try {
+ startPhoneCall();
+ } finally {
+ endPhoneCall();
+ }
+
+ assertWithMessage("MediaProjection should not be stopped on call end")
+ .that(latch.await(mTimeoutMs, TimeUnit.MILLISECONDS)).isFalse();
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_STOP_MEDIA_PROJECTION_ON_CALL_END)
+ @RequiresFlagsDisabled(Flags.FLAG_SHOW_STOP_DIALOG_POST_CALL_END)
+ @ApiTest(apis = "android.media.projection.MediaProjection.Callback#onStop")
+ public void
+ testMediaProjectionStop_callStartedBeforeMediaProjection_stopDialogFlagDisabled__shouldStop()
+ throws Exception {
+ assumeTrue(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELECOM));
+ CountDownLatch latch = new CountDownLatch(1);
+ try {
+ startPhoneCall();
+
+ mMediaProjectionRule.startMediaProjection();
+
+ mMediaProjectionRule.registerCallback(
+ new MediaProjection.Callback() {
+ @Override
+ public void onStop() {
+ latch.countDown();
+ }
+ });
+ mMediaProjectionRule.createVirtualDisplay();
+
+ } finally {
+ endPhoneCall();
+ }
+
+ assertWithMessage("MediaProjection was not stopped after call end")
+ .that(latch.await(mTimeoutMs, TimeUnit.MILLISECONDS)).isTrue();
+ }
+
+ @Test
+ @RequiresFlagsEnabled({
+ Flags.FLAG_STOP_MEDIA_PROJECTION_ON_CALL_END,
+ Flags.FLAG_SHOW_STOP_DIALOG_POST_CALL_END
+ })
+ public void
+ callEnds_mediaProjectionStartedDuringCallAndIsActive_stopDialogFlagEnabled_showsStopDialog()
+ throws Exception {
+ // MediaProjection stop Dialog is only available on phones.
+ assumeFalse(isWatch());
+ assumeFalse(isAutomotive());
+ assumeFalse(isTV());
+
+ assumeTrue(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELECOM));
+
+ try {
+ startPhoneCall();
+ mMediaProjectionRule.startMediaProjection();
+
+ mMediaProjectionRule.registerCallback(
+ new MediaProjection.Callback() {
+ @Override
+ public void onStop() {
+ fail(
+ "MediaProjection should not be stopped when"
+ + " FLAG_SHOW_STOP_DIALOG_POST_CALL_END is enabled");
+ }
+ });
+ mMediaProjectionRule.createVirtualDisplay();
+
+ } finally {
+ endPhoneCall();
+ }
+
+ UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ boolean isDialogShown =
+ device.wait(
+ Until.hasObject(By.res(STOP_DIALOG_TITLE_RES_ID)),
+ STOP_DIALOG_WAIT_TIMEOUT_MS);
+ assertWithMessage("Stop dialog should be visible").that(isDialogShown).isTrue();
+
+ // Find and click the "Close" button
+ boolean hasCloseButton =
+ device.wait(
+ Until.hasObject(By.res(STOP_DIALOG_CLOSE_BUTTON_RES_ID)),
+ STOP_DIALOG_WAIT_TIMEOUT_MS);
+ if (hasCloseButton) {
+ device.findObject(By.res(STOP_DIALOG_CLOSE_BUTTON_RES_ID)).click();
+ Log.d(TAG, "Clicked on 'Close' button to dismiss the stop dialog.");
+ } else {
+ fail("Close button not found, unable to dismiss stop dialog.");
+ }
+ }
+
+ private void startPhoneCall() throws InterruptedException {
+ mTestCallStateListener.assertCallState(false);
+ mContext.startActivity(getCallHelperIntent(CALL_HELPER_START_CALL));
+ mTestCallStateListener.waitForNextCallState(true, mTimeoutMs, TimeUnit.MILLISECONDS);
+ }
+
+ private void endPhoneCall() throws InterruptedException {
+ mTestCallStateListener.assertCallState(true);
+ mContext.startActivity(getCallHelperIntent(CALL_HELPER_STOP_CALL));
+ mTestCallStateListener.waitForNextCallState(false, mTimeoutMs, TimeUnit.MILLISECONDS);
+ }
+
+ private Intent getCallHelperIntent(String action) {
+ return new Intent(action)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
+ .setComponent(
+ new ComponentName(
+ "android.media.projection.cts.helper",
+ "android.media.projection.cts.helper.CallHelperActivity"));
+ }
+
+ private static final class TestCallStateListener extends TelephonyCallback
+ implements TelephonyCallback.CallStateListener {
+ private final BlockingQueue<Boolean> mCallStates = new LinkedBlockingQueue<>();
+ private final TelecomManager mTelecomManager;
+ private final TelephonyManager mTelephonyManager;
+
+ private TestCallStateListener(Context context) throws InterruptedException {
+ mTelecomManager = context.getSystemService(TelecomManager.class);
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
+ mCallStates.offer(isInCall());
+
+ assertThat(mCallStates.take()).isFalse();
+
+ runWithShellPermissionIdentity(
+ () ->
+ mTelephonyManager.registerTelephonyCallback(
+ context.getMainExecutor(), this));
+ }
+
+ public void release() {
+ runWithShellPermissionIdentity(
+ () -> mTelephonyManager.unregisterTelephonyCallback(this));
+ }
+
+ @Override
+ public void onCallStateChanged(int state) {
+ mCallStates.offer(isInCall());
+ }
+
+ public void waitForNextCallState(boolean expectedCallState, long timeout, TimeUnit unit)
+ throws InterruptedException {
+ String message =
+ String.format(
+ "Call was not %s after timeout",
+ expectedCallState ? "started" : "ended");
+
+ boolean value;
+ do {
+ value = mCallStates.poll(timeout, unit);
+ } while (value != expectedCallState);
+ assertWithMessage(message).that(value).isEqualTo(expectedCallState);
+ }
+
+ private boolean isInCall() {
+ return runWithShellPermissionIdentity(mTelecomManager::isInCall);
+ }
+
+ public void assertCallState(boolean expected) {
+ assertWithMessage("Unexpected call state").that(isInCall()).isEqualTo(expected);
+ }
+ }
+}
diff --git a/packages/CredentialManager/wear/AndroidManifest.xml b/packages/CredentialManager/wear/AndroidManifest.xml
index b480ac30d2cb..c91bf13bf98e 100644
--- a/packages/CredentialManager/wear/AndroidManifest.xml
+++ b/packages/CredentialManager/wear/AndroidManifest.xml
@@ -32,7 +32,8 @@
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:label="@string/app_name"
- android:supportsRtl="true">
+ android:supportsRtl="true"
+ android:theme="@style/Theme.CredentialSelector">
<!-- Activity called by GMS has to be exactly:
com.android.credentialmanager.CredentialSelectorActivity -->
@@ -42,7 +43,8 @@
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTop"
- android:permission="android.permission.LAUNCH_CREDENTIAL_SELECTOR" />
+ android:permission="android.permission.LAUNCH_CREDENTIAL_SELECTOR"
+ android:theme="@style/Theme.CredentialSelector"/>
</application>
</manifest>
diff --git a/packages/CredentialManager/wear/res/values/themes.xml b/packages/CredentialManager/wear/res/values/themes.xml
new file mode 100644
index 000000000000..22329e9ff2ce
--- /dev/null
+++ b/packages/CredentialManager/wear/res/values/themes.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<resources>
+ <style name="Theme.CredentialSelector" parent="@*android:style/ThemeOverlay.DeviceDefault.Accent.DayNight">
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:windowIsTranslucent">true</item>
+ </style>
+</resources> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt
index 2672787a0519..d1c88de3f399 100644
--- a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt
+++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt
@@ -71,18 +71,27 @@ open class SettingsPreferenceGroupAdapter(preferenceGroup: PreferenceGroup) :
override fun onPreferenceHierarchyChange(preference: Preference) {
super.onPreferenceHierarchyChange(preference)
- // Post after super class has posted their sync runnable to update preferences.
- mHandler.removeCallbacks(syncRunnable)
- mHandler.post(syncRunnable)
+ if (SettingsThemeHelper.isExpressiveTheme(preference.context)) {
+ // Post after super class has posted their sync runnable to update preferences.
+ mHandler.removeCallbacks(syncRunnable)
+ mHandler.post(syncRunnable)
+ }
}
@SuppressLint("RestrictedApi")
override fun onBindViewHolder(holder: PreferenceViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
- updateBackground(holder, position)
+
+ if (SettingsThemeHelper.isExpressiveTheme(holder.itemView.context)) {
+ updateBackground(holder, position)
+ }
}
private fun updatePreferencesList() {
+ if (!SettingsThemeHelper.isExpressiveTheme(mPreferenceGroup.context)) {
+ return
+ }
+
val oldList = ArrayList(mRoundCornerMappingList)
mRoundCornerMappingList = ArrayList()
mappingPreferenceGroup(mRoundCornerMappingList, mPreferenceGroup)
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/ui/Category.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/ui/Category.kt
index f10f96afd389..395328f86047 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/ui/Category.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/ui/Category.kt
@@ -78,6 +78,8 @@ fun CategoryTitle(title: String) {
/**
* A container that is used to group similar items. A [Category] displays a [CategoryTitle] and
* visually separates groups of items.
+ *
+ * @param content The content of the category.
*/
@Composable
fun Category(
@@ -126,7 +128,8 @@ fun Category(
* be decided by the index.
* @param bottomPadding Optional. Bottom outside padding of the category.
* @param state Optional. State of LazyList.
- * @param content Optional. Content to be shown at the top of the category.
+ * @param footer Optional. Content to be shown at the bottom of the category.
+ * @param header Optional. Content to be shown at the top of the category.
*/
@Composable
fun LazyCategory(
@@ -136,7 +139,8 @@ fun LazyCategory(
title: ((Int) -> String?)? = null,
bottomPadding: Dp = SettingsDimension.paddingSmall,
state: LazyListState = rememberLazyListState(),
- content: @Composable () -> Unit,
+ footer: @Composable () -> Unit = {},
+ header: @Composable () -> Unit,
) {
Column(
Modifier.padding(
@@ -154,12 +158,14 @@ fun LazyCategory(
verticalArrangement = Arrangement.spacedBy(SettingsDimension.paddingTiny),
state = state,
) {
- item { CompositionLocalProvider(LocalIsInCategory provides true) { content() } }
+ item { CompositionLocalProvider(LocalIsInCategory provides true) { header() } }
items(count = list.size, key = key) {
title?.invoke(it)?.let { title -> CategoryTitle(title) }
CompositionLocalProvider(LocalIsInCategory provides true) { entry(it)() }
}
+
+ item { CompositionLocalProvider(LocalIsInCategory provides true) { footer() } }
}
}
}
@@ -189,3 +195,28 @@ private fun CategoryPreview() {
}
}
}
+
+@Preview
+@Composable
+private fun LazyCategoryPreview() {
+ SettingsTheme {
+ LazyCategory(
+ list = listOf(1, 2, 3),
+ entry = { key ->
+ @Composable {
+ Preference(
+ object : PreferenceModel {
+ override val title = key.toString()
+ }
+ )
+ }
+ },
+ footer = @Composable {
+ Footer("Footer")
+ },
+ header = @Composable {
+ Text("Header")
+ },
+ )
+ }
+}
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt
index 4b4a8c20b39e..7d199511044a 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt
@@ -71,10 +71,17 @@ class CategoryTest {
}
@Test
- fun lazyCategory_content_displayed() {
+ fun lazyCategory_headerDisplayed() {
composeTestRule.setContent { TestLazyCategory() }
- composeTestRule.onNodeWithText("text").assertExists()
+ composeTestRule.onNodeWithText("Header").assertExists()
+ }
+
+ @Test
+ fun lazyCategory_footerDisplayed() {
+ composeTestRule.setContent { TestLazyCategory() }
+
+ composeTestRule.onNodeWithText("Footer").assertExists()
}
@Test
@@ -102,8 +109,8 @@ private fun TestLazyCategory() {
list = list,
entry = { index: Int -> @Composable { Preference(list[index]) } },
title = { index: Int -> if (index == 0) "LazyCategory $index" else null },
- ) {
- Text("text")
- }
+ footer = @Composable { Footer("Footer") },
+ header = @Composable { Text("Header") },
+ )
}
}
diff --git a/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml b/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml
index 083b862e8a5c..c778fb03e04f 100644
--- a/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml
+++ b/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml
@@ -55,6 +55,27 @@
android:layout_gravity="center"
android:scaleType="centerInside"/>
+ <com.google.android.material.progressindicator.CircularProgressIndicator
+ android:id="@+id/progress_indicator"
+ style="@style/Widget.Material3.CircularProgressIndicator"
+ android:layout_width="@dimen/settingslib_expressive_space_medium4"
+ android:layout_height="@dimen/settingslib_expressive_space_medium4"
+ android:layout_gravity="center"
+ android:scaleType="centerInside"
+ android:indeterminate="false"
+ android:max="100"
+ android:progress="0"
+ android:visibility="gone" />
+
+ <com.google.android.material.loadingindicator.LoadingIndicator
+ android:id="@+id/loading_indicator"
+ style="@style/Widget.Material3.LoadingIndicator"
+ android:layout_width="@dimen/settingslib_expressive_space_medium4"
+ android:layout_height="@dimen/settingslib_expressive_space_medium4"
+ android:layout_gravity="center"
+ android:scaleType="centerInside"
+ android:visibility="gone" />
+
</FrameLayout>
<LinearLayout
diff --git a/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml b/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml
index deda2586c2e0..bb9a5ad689cd 100644
--- a/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml
+++ b/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml
@@ -22,6 +22,8 @@
<enum name="medium" value="2"/>
<enum name="high" value="3"/>
<enum name="off" value="4"/>
+ <enum name="loading_determinate" value="5"/>
+ <enum name="loading_indeterminate" value="6"/>
</attr>
<attr name="buttonLevel" format="enum">
<enum name="generic" value="0"/>
diff --git a/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt b/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt
index eda281c07053..e6c6638f7de4 100644
--- a/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt
+++ b/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt
@@ -28,6 +28,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.android.settingslib.widget.preference.statusbanner.R
import com.google.android.material.button.MaterialButton
+import com.google.android.material.progressindicator.CircularProgressIndicator
class StatusBannerPreference @JvmOverloads constructor(
context: Context,
@@ -41,7 +42,9 @@ class StatusBannerPreference @JvmOverloads constructor(
LOW,
MEDIUM,
HIGH,
- OFF
+ OFF,
+ LOADING_DETERMINATE, // The loading progress is set by the caller.
+ LOADING_INDETERMINATE // No loading progress. Just loading animation
}
var iconLevel: BannerStatus = BannerStatus.GENERIC
set(value) {
@@ -60,6 +63,8 @@ class StatusBannerPreference @JvmOverloads constructor(
}
private var listener: View.OnClickListener? = null
+ private var circularProgressIndicator: CircularProgressIndicator? = null
+
init {
layoutResource = R.layout.settingslib_expressive_preference_statusbanner
isSelectable = false
@@ -89,6 +94,8 @@ class StatusBannerPreference @JvmOverloads constructor(
2 -> BannerStatus.MEDIUM
3 -> BannerStatus.HIGH
4 -> BannerStatus.OFF
+ 5 -> BannerStatus.LOADING_DETERMINATE
+ 6 -> BannerStatus.LOADING_INDETERMINATE
else -> BannerStatus.GENERIC
}
@@ -102,7 +109,38 @@ class StatusBannerPreference @JvmOverloads constructor(
}
holder.findViewById(android.R.id.icon_frame)?.apply {
- visibility = if (icon != null) View.VISIBLE else View.GONE
+ visibility =
+ if (
+ icon != null || iconLevel == BannerStatus.LOADING_DETERMINATE ||
+ iconLevel == BannerStatus.LOADING_INDETERMINATE
+ )
+ View.VISIBLE
+ else View.GONE
+ }
+
+ holder.findViewById(android.R.id.icon)?.apply {
+ visibility =
+ if (iconLevel == BannerStatus.LOADING_DETERMINATE ||
+ iconLevel == BannerStatus.LOADING_INDETERMINATE)
+ View.GONE
+ else View.VISIBLE
+ }
+
+ circularProgressIndicator = holder.findViewById(R.id.progress_indicator)
+ as? CircularProgressIndicator
+
+ (circularProgressIndicator)?.apply {
+ visibility =
+ if (iconLevel == BannerStatus.LOADING_DETERMINATE)
+ View.VISIBLE
+ else View.GONE
+ }
+
+ holder.findViewById(R.id.loading_indicator)?.apply {
+ visibility =
+ if (iconLevel == BannerStatus.LOADING_INDETERMINATE)
+ View.VISIBLE
+ else View.GONE
}
(holder.findViewById(R.id.status_banner_button) as? MaterialButton)?.apply {
@@ -116,6 +154,10 @@ class StatusBannerPreference @JvmOverloads constructor(
}
}
+ fun getProgressIndicator(): CircularProgressIndicator? {
+ return circularProgressIndicator
+ }
+
/**
* Sets the text to be displayed in button.
*/
@@ -203,7 +245,7 @@ class StatusBannerPreference @JvmOverloads constructor(
R.drawable.settingslib_expressive_background_level_high
)
- // GENERIC and OFF are using the same background drawable.
+ // Using the same background drawable for other levels.
else -> ContextCompat.getDrawable(
context,
R.drawable.settingslib_expressive_background_generic
diff --git a/packages/SettingsLib/aconfig/settingslib.aconfig b/packages/SettingsLib/aconfig/settingslib.aconfig
index 349d13a29b05..90e5a010416c 100644
--- a/packages/SettingsLib/aconfig/settingslib.aconfig
+++ b/packages/SettingsLib/aconfig/settingslib.aconfig
@@ -37,16 +37,6 @@ flag {
}
flag {
- name: "enable_set_preferred_transport_for_le_audio_device"
- namespace: "bluetooth"
- description: "Enable setting preferred transport for Le Audio device"
- bug: "330581926"
- metadata {
- purpose: PURPOSE_BUGFIX
- }
-}
-
-flag {
name: "enable_determining_advanced_details_header_with_metadata"
namespace: "pixel_cross_device_control"
description: "Use metadata instead of device type to determine whether a bluetooth device should use advanced details header."
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
index ae9ad958b287..33dcb051d194 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
@@ -1068,18 +1068,42 @@ public class BluetoothUtils {
/** Get primary device Uri in broadcast. */
@NonNull
public static String getPrimaryGroupIdUriForBroadcast() {
+ // TODO: once API is stable, deprecate SettingsProvider solution
return "bluetooth_le_broadcast_fallback_active_group_id";
}
- /** Get primary device group id in broadcast. */
+ /** Get primary device group id in broadcast from SettingsProvider. */
@WorkerThread
public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver) {
+ // TODO: once API is stable, deprecate SettingsProvider solution
return Settings.Secure.getInt(
contentResolver,
getPrimaryGroupIdUriForBroadcast(),
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
}
+ /**
+ * Get primary device group id in broadcast.
+ *
+ * If Flags.adoptPrimaryGroupManagementApiV2 is enabled, get group id by API,
+ * Otherwise, still get value from SettingsProvider.
+ */
+ @WorkerThread
+ public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver,
+ @Nullable LocalBluetoothManager manager) {
+ if (Flags.adoptPrimaryGroupManagementApiV2()) {
+ LeAudioProfile leaProfile = manager == null ? null :
+ manager.getProfileManager().getLeAudioProfile();
+ if (leaProfile == null) {
+ Log.d(TAG, "getPrimaryGroupIdForBroadcast: profile is null");
+ return BluetoothCsipSetCoordinator.GROUP_ID_INVALID;
+ }
+ return leaProfile.getBroadcastToUnicastFallbackGroup();
+ } else {
+ return getPrimaryGroupIdForBroadcast(contentResolver);
+ }
+ }
+
/** Get develop option value for audio sharing preview. */
@WorkerThread
public static boolean getAudioSharingPreviewValue(@Nullable ContentResolver contentResolver) {
@@ -1101,7 +1125,7 @@ public class BluetoothUtils {
LocalBluetoothLeBroadcast broadcast =
localBtManager.getProfileManager().getLeAudioBroadcastProfile();
if (broadcast == null || !broadcast.isEnabled(null)) return null;
- int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver);
+ int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver, localBtManager);
if (primaryGroupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) return null;
LocalBluetoothLeBroadcastAssistant assistant =
localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile();
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
index 011b2fc15807..edec2e427315 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -75,6 +75,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
+import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
@@ -154,8 +155,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
private boolean mIsLeAudioProfileConnectedFail = false;
private boolean mUnpairing;
@Nullable
- private final InputDevice mInputDevice;
- private final boolean mIsDeviceStylus;
+ private InputDevice mInputDevice;
+ private boolean mIsDeviceStylus;
// Group second device for Hearing Aid
private CachedBluetoothDevice mSubDevice;
@@ -313,8 +314,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
mLocalNapRoleConnected = true;
}
}
- if (Flags.enableSetPreferredTransportForLeAudioDevice()
- && profile instanceof HidProfile) {
+ if (profile instanceof HidProfile) {
updatePreferredTransport();
}
} else if (profile instanceof MapProfile
@@ -329,8 +329,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
mLocalNapRoleConnected = false;
}
- if (Flags.enableSetPreferredTransportForLeAudioDevice()
- && profile instanceof LeAudioProfile) {
+ if (profile instanceof LeAudioProfile) {
updatePreferredTransport();
}
@@ -762,11 +761,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
* {@link BluetoothDevice#BATTERY_LEVEL_UNKNOWN}
*/
public int getMinBatteryLevelWithMemberDevices() {
- return Stream.concat(Stream.of(this), mMemberDevices.stream())
- .mapToInt(cachedDevice -> cachedDevice.getBatteryLevel())
- .filter(batteryLevel -> batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
- .min()
- .orElse(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+ return getMinBatteryLevels(Stream.concat(Stream.of(this), mMemberDevices.stream())
+ .mapToInt(CachedBluetoothDevice::getBatteryLevel));
}
/**
@@ -789,6 +785,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
: null;
}
+ private int getMinBatteryLevels(IntStream batteryLevels) {
+ return batteryLevels
+ .filter(battery -> battery > BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
+ .min()
+ .orElse(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+ }
+
void refresh() {
ListenableFuture<Void> future = ThreadUtils.getBackgroundExecutor().submit(() -> {
if (BluetoothUtils.isAdvancedDetailsHeader(mDevice)) {
@@ -1358,7 +1361,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
// Gets summary for the buds which are in the audio sharing.
int groupId = BluetoothUtils.getGroupId(this);
int primaryGroupId = BluetoothUtils.getPrimaryGroupIdForBroadcast(
- mContext.getContentResolver());
+ mContext.getContentResolver(), mBluetoothManager);
if ((primaryGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID)
? (groupId == primaryGroupId) : isActiveDevice(BluetoothProfile.LE_AUDIO)) {
// The buds are primary buds
@@ -1674,10 +1677,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
return null;
} else {
int overallBattery =
- Arrays.stream(new int[]{leftBattery, rightBattery, caseBattery})
- .filter(battery -> battery > BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
- .min()
- .orElse(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+ getMinBatteryLevels(
+ Arrays.stream(new int[]{leftBattery, rightBattery, caseBattery}));
Log.d(TAG, "Acquired battery info from metadata for untethered device "
+ mDevice.getAnonymizedAddress()
+ " left earbud battery: " + leftBattery
@@ -1711,10 +1712,75 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
@Nullable
private BatteryLevelsInfo getBatteryFromBluetoothService() {
- // TODO(b/397847825): Implement the logic to get battery from Bluetooth service.
- return null;
+ BatteryLevelsInfo batteryLevelsInfo;
+ if (isConnectedHearingAidDevice()) {
+ // If the device is hearing aid device, sides can be distinguished by HearingAidInfo.
+ batteryLevelsInfo = getBatteryOfHearingAidDeviceComponents();
+ if (batteryLevelsInfo != null) {
+ return batteryLevelsInfo;
+ }
+ }
+ if (isConnectedLeAudioDevice()) {
+ // If the device is LE Audio device, sides can be distinguished by LeAudioProfile.
+ batteryLevelsInfo = getBatteryOfLeAudioDeviceComponents();
+ if (batteryLevelsInfo != null) {
+ return batteryLevelsInfo;
+ }
+ }
+ int overallBattery = getMinBatteryLevelWithMemberDevices();
+ return overallBattery > BluetoothDevice.BATTERY_LEVEL_UNKNOWN
+ ? new BatteryLevelsInfo(
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ overallBattery)
+ : null;
}
+ @Nullable
+ private BatteryLevelsInfo getBatteryOfHearingAidDeviceComponents() {
+ if (getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) {
+ return new BatteryLevelsInfo(
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ mDevice.getBatteryLevel());
+ }
+
+ int leftBattery = getHearingAidSideBattery(HearingAidInfo.DeviceSide.SIDE_LEFT);
+ int rightBattery = getHearingAidSideBattery(HearingAidInfo.DeviceSide.SIDE_RIGHT);
+ int overallBattery = getMinBatteryLevels(
+ Arrays.stream(new int[]{leftBattery, rightBattery}));
+
+ Log.d(TAG, "Acquired battery info from Bluetooth service for hearing aid device "
+ + mDevice.getAnonymizedAddress()
+ + " left battery: " + leftBattery
+ + " right battery: " + rightBattery
+ + " overall battery: " + overallBattery);
+ return overallBattery > BluetoothDevice.BATTERY_LEVEL_UNKNOWN
+ ? new BatteryLevelsInfo(
+ leftBattery,
+ rightBattery,
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
+ overallBattery)
+ : null;
+ }
+
+ private int getHearingAidSideBattery(int side) {
+ Optional<CachedBluetoothDevice> connectedHearingAidSide = getConnectedHearingAidSide(side);
+ return connectedHearingAidSide.isPresent()
+ ? connectedHearingAidSide
+ .map(CachedBluetoothDevice::getBatteryLevel)
+ .filter(batteryLevel -> batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
+ .orElse(BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
+ : BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
+ }
+
+ @Nullable
+ private BatteryLevelsInfo getBatteryOfLeAudioDeviceComponents() {
+ // TODO(b/397847825): Implement the logic to get battery of LE audio device components.
+ return null;
+ }
private CharSequence getTvBatterySummary(int mainBattery, int leftBattery, int rightBattery,
int lowBatteryColorRes) {
// Since there doesn't seem to be a way to use format strings to add the
@@ -1833,10 +1899,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
// Retrieve hearing aids (ASHA, HAP) individual side battery level
if (leftBattery == BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
- leftBattery = getConnectedHearingAidSide(HearingAidInfo.DeviceSide.SIDE_LEFT)
- .map(CachedBluetoothDevice::getBatteryLevel)
- .filter(batteryLevel -> batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
- .orElse(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+ leftBattery = getHearingAidSideBattery(HearingAidInfo.DeviceSide.SIDE_LEFT);
}
return leftBattery;
@@ -1852,10 +1915,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
// Retrieve hearing aids (ASHA, HAP) individual side battery level
if (rightBattery == BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
- rightBattery = getConnectedHearingAidSide(HearingAidInfo.DeviceSide.SIDE_RIGHT)
- .map(CachedBluetoothDevice::getBatteryLevel)
- .filter(batteryLevel -> batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN)
- .orElse(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+ rightBattery = getHearingAidSideBattery(HearingAidInfo.DeviceSide.SIDE_RIGHT);
}
return rightBattery;
@@ -2263,6 +2323,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
mBluetoothManager = bluetoothManager;
}
+ @VisibleForTesting
+ void setIsDeviceStylus(Boolean isDeviceStylus) {
+ mIsDeviceStylus = isDeviceStylus;
+ }
+
+ @VisibleForTesting
+ void setInputDevice(@Nullable InputDevice inputDevice) {
+ mInputDevice = inputDevice;
+ }
+
private boolean isAndroidAuto() {
try {
ParcelUuid[] uuids = mDevice.getUuids();
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
index b7814127b716..8fc4aa81b53f 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
@@ -936,15 +936,60 @@ public class BluetoothUtilsTest {
}
@Test
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getSecondaryDeviceForBroadcast_adoptAPI_noSecondary_returnNull() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDevice.getGroupId()).thenReturn(1);
+ BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
+ when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of(state));
+ when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mBluetoothDevice));
+
+ assertThat(
+ BluetoothUtils.getSecondaryDeviceForBroadcast(
+ mContext.getContentResolver(), mLocalBluetoothManager))
+ .isNull();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getSecondaryDeviceForBroadcast_adoptAPI_returnCorrectDevice() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+ CachedBluetoothDevice cachedBluetoothDevice = mock(CachedBluetoothDevice.class);
+ BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
+ when(cachedBluetoothDevice.getDevice()).thenReturn(bluetoothDevice);
+ when(cachedBluetoothDevice.getGroupId()).thenReturn(1);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDevice.getGroupId()).thenReturn(2);
+ when(mDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedBluetoothDevice);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(state.getBisSyncState()).thenReturn(bisSyncState);
+ when(mAssistant.getAllSources(any(BluetoothDevice.class)))
+ .thenReturn(ImmutableList.of(state));
+ when(mAssistant.getAllConnectedDevices())
+ .thenReturn(ImmutableList.of(mBluetoothDevice, bluetoothDevice));
+
+ assertThat(
+ BluetoothUtils.getSecondaryDeviceForBroadcast(
+ mContext.getContentResolver(), mLocalBluetoothManager))
+ .isEqualTo(mCachedBluetoothDevice);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getSecondaryDeviceForBroadcast_noSecondary_returnNull() {
Settings.Secure.putInt(
mContext.getContentResolver(),
BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
- CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
- when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
- when(deviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mCachedBluetoothDevice.getGroupId()).thenReturn(1);
BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
@@ -958,6 +1003,7 @@ public class BluetoothUtilsTest {
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getSecondaryDeviceForBroadcast_returnCorrectDevice() {
Settings.Secure.putInt(
mContext.getContentResolver(),
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
index f57ee0c0930e..b4384b74ccbe 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
@@ -16,7 +16,6 @@
package com.android.settingslib.bluetooth;
import static com.android.settingslib.flags.Flags.FLAG_ENABLE_LE_AUDIO_SHARING;
-import static com.android.settingslib.flags.Flags.FLAG_ENABLE_SET_PREFERRED_TRANSPORT_FOR_LE_AUDIO_DEVICE;
import static com.android.settingslib.flags.Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI;
import static com.google.common.truth.Truth.assertThat;
@@ -42,6 +41,8 @@ import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.input.InputManager;
import android.media.AudioManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.text.Spannable;
@@ -138,7 +139,6 @@ public class CachedBluetoothDeviceTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TV_MEDIA_OUTPUT_DIALOG);
- mSetFlagsRule.enableFlags(FLAG_ENABLE_SET_PREFERRED_TRANSPORT_FOR_LE_AUDIO_DEVICE);
mSetFlagsRule.enableFlags(FLAG_ENABLE_LE_AUDIO_SHARING);
mSetFlagsRule.enableFlags(FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI);
mContext = RuntimeEnvironment.application;
@@ -163,6 +163,7 @@ public class CachedBluetoothDeviceTest {
when(mHidProfile.getProfileId()).thenReturn(BluetoothProfile.HID_HOST);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager);
when(mBroadcast.isEnabled(any())).thenReturn(false);
+ when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
when(mProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant);
mCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mDevice));
@@ -2004,6 +2005,70 @@ public class CachedBluetoothDeviceTest {
}
@Test
+ @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getConnectionSummary_adoptAPI_isBroadcastPrimary_fallbackDevice_returnActive() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mCachedDevice.getDevice()).thenReturn(mDevice);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
+ List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
+ sourceList.add(mLeBroadcastReceiveState);
+ when(mAssistant.getAllSources(any())).thenReturn(sourceList);
+
+ when(mCachedDevice.getGroupId()).thenReturn(1);
+
+ assertThat(mCachedDevice.getConnectionSummary(false))
+ .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level));
+ }
+
+ @Test
+ @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getConnectionSummary_adoptAPI_isBroadcastPrimary_activeDevice_returnActive() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mCachedDevice.getDevice()).thenReturn(mDevice);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
+ BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
+ List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
+ sourceList.add(mLeBroadcastReceiveState);
+ when(mAssistant.getAllSources(any())).thenReturn(sourceList);
+
+ when(mCachedDevice.getGroupId()).thenReturn(1);
+ when(mCachedDevice.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
+
+ assertThat(mCachedDevice.getConnectionSummary(false))
+ .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level));
+ }
+
+ @Test
+ @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getConnectionSummary_adoptAPI_isBroadcastNotPrimary_returnActiveMedia() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mCachedDevice.getDevice()).thenReturn(mDevice);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
+ List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
+ sourceList.add(mLeBroadcastReceiveState);
+ when(mAssistant.getAllSources(any())).thenReturn(sourceList);
+
+ when(mCachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+
+ assertThat(mCachedDevice.getConnectionSummary(false))
+ .isEqualTo(
+ mContext.getString(R.string.bluetooth_active_media_only_no_battery_level));
+ }
+
+ @Test
+ @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getConnectionSummary_isBroadcastPrimary_fallbackDevice_returnActive() {
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
@@ -2026,6 +2091,7 @@ public class CachedBluetoothDeviceTest {
}
@Test
+ @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getConnectionSummary_isBroadcastPrimary_activeDevice_returnActive() {
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
@@ -2049,6 +2115,7 @@ public class CachedBluetoothDeviceTest {
}
@Test
+ @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getConnectionSummary_isBroadcastNotPrimary_returnActiveMedia() {
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
@@ -2231,11 +2298,7 @@ public class CachedBluetoothDeviceTest {
"false".getBytes());
when(mDevice.getMetadata(BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn(
MAIN_BATTERY.getBytes());
- when(mContext.getSystemService(InputManager.class)).thenReturn(mInputManager);
- when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{TEST_DEVICE_ID});
- when(mInputManager.getInputDeviceBluetoothAddress(TEST_DEVICE_ID)).thenReturn(
- DEVICE_ADDRESS);
- when(mInputManager.getInputDevice(TEST_DEVICE_ID)).thenReturn(mInputDevice);
+ mCachedDevice.setInputDevice(mInputDevice);
BatteryLevelsInfo batteryLevelsInfo = mCachedDevice.getBatteryLevelsInfo();
@@ -2253,10 +2316,9 @@ public class CachedBluetoothDeviceTest {
public void getBatteryLevelsInfo_stylusDeviceWithBattery_returnBatteryLevelsInfo() {
when(mDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
"false".getBytes());
- when(mDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
- BluetoothDevice.DEVICE_TYPE_STYLUS.getBytes());
when(mDevice.getMetadata(BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn(
MAIN_BATTERY.getBytes());
+ mCachedDevice.setIsDeviceStylus(true);
BatteryLevelsInfo batteryLevelsInfo = mCachedDevice.getBatteryLevelsInfo();
@@ -2270,6 +2332,31 @@ public class CachedBluetoothDeviceTest {
Integer.parseInt(MAIN_BATTERY));
}
+ @Test
+ public void getBatteryLevelsInfo_hearingAidDeviceWithBattery_returnBatteryLevelsInfo() {
+ when(mDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
+ "false".getBytes());
+ when(mProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
+ updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
+ mSubCachedDevice.setHearingAidInfo(getLeftAshaHearingAidInfo());
+ when(mSubCachedDevice.getBatteryLevel()).thenReturn(Integer.parseInt(TWS_BATTERY_LEFT));
+ updateSubDeviceProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
+ mCachedDevice.setSubDevice(mSubCachedDevice);
+ mCachedDevice.setHearingAidInfo(getRightAshaHearingAidInfo());
+ when(mCachedDevice.getBatteryLevel()).thenReturn(Integer.parseInt(TWS_BATTERY_RIGHT));
+
+ BatteryLevelsInfo batteryLevelsInfo = mCachedDevice.getBatteryLevelsInfo();
+
+ assertThat(batteryLevelsInfo.getLeftBatteryLevel()).isEqualTo(
+ Integer.parseInt(TWS_BATTERY_LEFT));
+ assertThat(batteryLevelsInfo.getRightBatteryLevel()).isEqualTo(
+ Integer.parseInt(TWS_BATTERY_RIGHT));
+ assertThat(batteryLevelsInfo.getCaseBatteryLevel()).isEqualTo(
+ BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+ assertThat(batteryLevelsInfo.getOverallBatteryLevel()).isEqualTo(
+ Integer.parseInt(TWS_BATTERY_LEFT));
+ }
+
private void updateProfileStatus(LocalBluetoothProfile profile, int status) {
doReturn(status).when(profile).getConnectionStatus(mDevice);
mCachedDevice.onProfileStateChanged(profile, status);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index ed11e12c32ff..2273b4f81eea 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -54,6 +54,7 @@ import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManage
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
@@ -650,6 +651,10 @@ public class SettingsHelper {
* e.g. current locale "en-US,zh-CN" and backup locale "ja-JP,zh-Hans-CN,en-US" are merged to
* "en-US,zh-CN,ja-JP".
*
+ * - Same language codes and scripts are dropped.
+ * e.g. current locale "en-US, zh-Hans-TW" and backup locale "en-UK, en-GB, zh-Hans-HK" are
+ * merged to "en-US, zh-Hans-TW".
+ *
* - Unsupported locales are dropped.
* e.g. current locale "en-US" and backup locale "ja-JP,zh-CN" but the supported locales
* are "en-US,zh-CN", the merged locale list is "en-US,zh-CN".
@@ -683,13 +688,23 @@ public class SettingsHelper {
filtered.add(locale);
}
+ final HashSet<String> existingLanguageAndScript = new HashSet<>();
for (int i = 0; i < restore.size(); i++) {
final Locale restoredLocaleWithExtension = copyExtensionToTargetLocale(restoredLocale,
getFilteredLocale(restore.get(i), allLocales));
+
if (restoredLocaleWithExtension != null) {
- filtered.add(restoredLocaleWithExtension);
+ String language = restoredLocaleWithExtension.getLanguage();
+ String script = restoredLocaleWithExtension.getScript();
+
+ String restoredLanguageAndScript =
+ script == null ? language : language + "-" + script;
+ if (existingLanguageAndScript.add(restoredLanguageAndScript)) {
+ filtered.add(restoredLocaleWithExtension);
+ }
}
}
+
if (filtered.size() == current.size()) {
return current; // Nothing added to current locale list.
}
diff --git a/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java b/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java
index 40654b0e2f37..48c778542d66 100644
--- a/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java
+++ b/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java
@@ -388,7 +388,11 @@ public class SettingsHelperTest {
LocaleList.forLanguageTags("zh-Hant-TW"), // current
new String[] { "fa-Arab-AF-u-nu-latn", "zh-Hant-TW" })); // supported
-
+ assertEquals(LocaleList.forLanguageTags("en-US,zh-Hans-TW"),
+ SettingsHelper.resolveLocales(
+ LocaleList.forLanguageTags("en-UK,en-GB,zh-Hans-HK"), // restore
+ LocaleList.forLanguageTags("en-US,zh-Hans-TW"), // current
+ new String[] { "en-US,zh-Hans-TW,en-UK,en-GB,zh-Hans-HK" })); // supported
}
@Test
diff --git a/packages/SystemUI/aconfig/desktop_users_and_accounts.aconfig b/packages/SystemUI/aconfig/desktop_users_and_accounts.aconfig
new file mode 100644
index 000000000000..c7e9c9fbee2e
--- /dev/null
+++ b/packages/SystemUI/aconfig/desktop_users_and_accounts.aconfig
@@ -0,0 +1,9 @@
+package: "com.android.systemui"
+container: "system"
+
+flag {
+ name: "user_switcher_add_sign_out_option"
+ namespace: "desktop_users_and_accounts"
+ description: "Add a sign out option to the user switcher menu if sign out is possible"
+ bug: "381478261"
+} \ No newline at end of file
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index 30bce3576e4f..a4852d26ffe2 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -2012,7 +2012,14 @@ flag {
flag {
name: "permission_helper_ui_rich_ongoing"
namespace: "systemui"
- description: "[RONs] Guards inline permission helper for demoting RONs"
+ description: "[RONs] Guards inline permission helper for demoting RONs [Guts/card version]"
+ bug: "379186372"
+}
+
+flag {
+ name: "permission_helper_inline_ui_rich_ongoing"
+ namespace: "systemui"
+ description: "[RONs] Guards inline permission helper for demoting RONs [Inline version]"
bug: "379186372"
}
@@ -2138,3 +2145,12 @@ flag {
}
}
+flag {
+ name: "keyguard_wm_reorder_atms_calls"
+ namespace: "systemui"
+ description: "Calls ATMS#setLockScreenShown before default display callbacks in case they're slow"
+ bug: "399693427"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityTransitionAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityTransitionAnimator.kt
index 5599db7689c2..1fb7901dcb59 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityTransitionAnimator.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityTransitionAnimator.kt
@@ -751,7 +751,8 @@ constructor(
OriginTransition(createLongLivedRunner(controllerFactory, scope, forLaunch = true)),
"${cookie}_launchTransition",
)
- transitionRegister.register(launchFilter, launchRemoteTransition, includeTakeover = true)
+ // TODO(b/403529740): re-enable takeovers once we solve the Compose jank issues.
+ transitionRegister.register(launchFilter, launchRemoteTransition, includeTakeover = false)
// Cross-task close transitions should not use this animation, so we only register it for
// when the opening window is Launcher.
@@ -777,7 +778,8 @@ constructor(
),
"${cookie}_returnTransition",
)
- transitionRegister.register(returnFilter, returnRemoteTransition, includeTakeover = true)
+ // TODO(b/403529740): re-enable takeovers once we solve the Compose jank issues.
+ transitionRegister.register(returnFilter, returnRemoteTransition, includeTakeover = false)
longLivedTransitions[cookie] = Pair(launchRemoteTransition, returnRemoteTransition)
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinInputDisplay.kt b/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinInputDisplay.kt
index 1f98cd8e07c0..90311ed93987 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinInputDisplay.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/PinInputDisplay.kt
@@ -35,7 +35,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
@@ -83,10 +83,7 @@ import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
@Composable
-fun PinInputDisplay(
- viewModel: PinBouncerViewModel,
- modifier: Modifier = Modifier,
-) {
+fun PinInputDisplay(viewModel: PinBouncerViewModel, modifier: Modifier = Modifier) {
val hintedPinLength: Int? by viewModel.hintedPinLength.collectAsStateWithLifecycle()
val shapeAnimations = rememberShapeAnimations(viewModel.pinShapes)
@@ -173,7 +170,10 @@ private fun HintingPinInputDisplay(
LaunchedEffect(Unit) { playAnimation = true }
val dotColor = MaterialTheme.colorScheme.onSurfaceVariant
- Row(modifier = modifier.heightIn(min = shapeAnimations.shapeSize)) {
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = modifier.height(shapeAnimations.shapeSize),
+ ) {
pinEntryDrawable.forEachIndexed { index, drawable ->
// Key the loop by [index] and [drawable], so that updating a shape drawable at the same
// index will play the new animation (by remembering a new [atEnd]).
@@ -316,17 +316,15 @@ private fun SimArea(viewModel: PinBouncerViewModel) {
Box(modifier = Modifier.padding(bottom = 20.dp)) {
// If isLockedEsim is null, then we do not show anything.
if (isLockedEsim == true) {
- PlatformOutlinedButton(
- onClick = { viewModel.onDisableEsimButtonClicked() },
- ) {
+ PlatformOutlinedButton(onClick = { viewModel.onDisableEsimButtonClicked() }) {
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
- verticalAlignment = Alignment.CenterVertically
+ verticalAlignment = Alignment.CenterVertically,
) {
Image(
painter = painterResource(id = R.drawable.ic_no_sim),
contentDescription = null,
- colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface)
+ colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
)
Text(
text = stringResource(R.string.disable_carrier_button_text),
@@ -339,15 +337,13 @@ private fun SimArea(viewModel: PinBouncerViewModel) {
Image(
painter = painterResource(id = R.drawable.ic_lockscreen_sim),
contentDescription = null,
- colorFilter = ColorFilter.tint(colorResource(id = R.color.background_protected))
+ colorFilter = ColorFilter.tint(colorResource(id = R.color.background_protected)),
)
}
}
}
-private class PinInputRow(
- val shapeAnimations: ShapeAnimations,
-) {
+private class PinInputRow(val shapeAnimations: ShapeAnimations) {
private val entries = mutableStateListOf<PinInputEntry>()
@Composable
@@ -359,10 +355,11 @@ private class PinInputRow(
contentAlignment = Alignment.Center,
) {
Row(
- modifier
- .heightIn(min = shapeAnimations.shapeSize)
- // Pins overflowing horizontally should still be shown as scrolling.
- .wrapContentSize(unbounded = true)
+ verticalAlignment = Alignment.CenterVertically,
+ modifier =
+ Modifier.height(shapeAnimations.shapeSize)
+ // Pins overflowing horizontally should still be shown as scrolling.
+ .wrapContentSize(unbounded = true),
) {
entries.forEach { entry -> key(entry.digit) { entry.Content() } }
}
@@ -439,10 +436,7 @@ private class PinInputRow(
}
}
-private class PinInputEntry(
- val digit: Digit,
- val shapeAnimations: ShapeAnimations,
-) {
+private class PinInputEntry(val digit: Digit, val shapeAnimations: ShapeAnimations) {
private val shape = shapeAnimations.getShapeToDot(digit.sequenceNumber)
// horizontal space occupied, used to shift contents as individual digits are animated in/out
private val entryWidth =
@@ -474,7 +468,7 @@ private class PinInputEntry(
suspend fun animateRemoval() = coroutineScope {
awaitAll(
async { entryWidth.animateTo(0.dp, shapeAnimations.inputShiftAnimationSpec) },
- async { shapeSize.animateTo(0.dp, shapeAnimations.deleteShapeSizeAnimationSpec) }
+ async { shapeSize.animateTo(0.dp, shapeAnimations.deleteShapeSizeAnimationSpec) },
)
}
@@ -505,7 +499,7 @@ private class PinInputEntry(
layout(animatedEntryWidth.roundToPx(), shapeHeight.roundToPx()) {
placeable.place(
((animatedEntryWidth - animatedShapeSize) / 2f).roundToPx(),
- ((shapeHeight - animatedShapeSize) / 2f).roundToPx()
+ ((shapeHeight - animatedShapeSize) / 2f).roundToPx(),
)
}
},
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/LockSection.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/LockSection.kt
index 0db2bb51c971..5fac6863e931 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/LockSection.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/LockSection.kt
@@ -33,6 +33,7 @@ import com.android.compose.animation.scene.ElementKey
import com.android.systemui.biometrics.AuthController
import com.android.systemui.customization.R as customR
import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlagsClassic
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.ui.binder.DeviceEntryIconViewBinder
@@ -49,12 +50,14 @@ import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
import dagger.Lazy
import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
class LockSection
@Inject
constructor(
@Application private val applicationScope: CoroutineScope,
+ @Main private val mainDispatcher: CoroutineDispatcher,
private val windowManager: WindowManager,
private val authController: AuthController,
private val featureFlags: FeatureFlagsClassic,
@@ -80,6 +83,7 @@ constructor(
id = R.id.device_entry_icon_view
DeviceEntryIconViewBinder.bind(
applicationScope,
+ mainDispatcher,
this,
deviceEntryIconViewModel.get(),
deviceEntryForegroundViewModel.get(),
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt b/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt
index 09b8d178cc8e..3e907e87c13b 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt
@@ -574,11 +574,11 @@ fun ContentScope.NotificationScrollingStack(
) {
Column(
modifier =
- Modifier.thenIf(supportNestedScrolling) {
+ Modifier.disableSwipesWhenScrolling(NestedScrollableBound.BottomRight)
+ .thenIf(supportNestedScrolling) {
Modifier.nestedScroll(scrimNestedScrollConnection)
}
.stackVerticalOverscroll(coroutineScope) { scrollState.canScrollForward }
- .disableSwipesWhenScrolling(NestedScrollableBound.BottomRight)
.verticalScroll(scrollState)
.padding(top = stackTopPadding, bottom = stackBottomPadding)
.fillMaxWidth()
diff --git a/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java b/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java
index 2845f6a2983a..e75f60736435 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java
@@ -507,8 +507,8 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
0 /* flags */);
users.add(new UserRecord(info, null, false /* isGuest */, false /* isCurrent */,
false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */,
- false /* isAddSupervisedUser */, null /* enforcedAdmin */,
- false /* isManageUsers */));
+ false /* isAddSupervisedUser */, false /* isSignOut */,
+ null /* enforcedAdmin */, false /* isManageUsers */));
}
return users;
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractorTest.kt
index c1feca29906a..91ec1cbce8a4 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractorTest.kt
@@ -77,6 +77,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
private lateinit var resources: TestableResources
private lateinit var trustRepository: FakeTrustRepository
private lateinit var testScope: TestScope
+ private val TEST_REASON = "reason"
@Before
fun setUp() {
@@ -118,7 +119,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
mainHandler.setMode(FakeHandler.Mode.QUEUEING)
// WHEN bouncer show is requested
- underTest.show(true)
+ underTest.show(true, TEST_REASON)
// WHEN all queued messages are dispatched
mainHandler.dispatchQueuedMessages()
@@ -134,7 +135,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
@Test
fun testShow_isScrimmed() {
- underTest.show(true)
+ underTest.show(true, TEST_REASON)
verify(repository).setKeyguardAuthenticatedBiometrics(null)
verify(repository).setPrimaryStartingToHide(false)
verify(repository).setPrimaryScrimmed(true)
@@ -162,7 +163,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
@Test
fun testShowReturnsFalseWhenDelegateIsNotSet() {
whenever(bouncerView.delegate).thenReturn(null)
- assertThat(underTest.show(true)).isEqualTo(false)
+ assertThat(underTest.show(true, TEST_REASON)).isEqualTo(false)
}
@Test
@@ -171,7 +172,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
whenever(keyguardSecurityModel.getSecurityMode(anyInt()))
.thenReturn(KeyguardSecurityModel.SecurityMode.SimPuk)
- underTest.show(true)
+ underTest.show(true, TEST_REASON)
verify(repository).setPrimaryShow(false)
verify(repository).setPrimaryShow(true)
}
@@ -352,7 +353,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
whenever(faceAuthInteractor.canFaceAuthRun()).thenReturn(true)
// WHEN bouncer show is requested
- underTest.show(true)
+ underTest.show(true, TEST_REASON)
// THEN primary show & primary showing soon aren't updated immediately
verify(repository, never()).setPrimaryShow(true)
@@ -375,7 +376,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
whenever(faceAuthInteractor.canFaceAuthRun()).thenReturn(false)
// WHEN bouncer show is requested
- underTest.show(true)
+ underTest.show(true, TEST_REASON)
// THEN primary show & primary showing soon are updated immediately
verify(repository).setPrimaryShow(true)
@@ -394,7 +395,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
runCurrent()
// WHEN bouncer show is requested
- underTest.show(true)
+ underTest.show(true, TEST_REASON)
// THEN primary show & primary showing soon were scheduled to update
verify(repository, never()).setPrimaryShow(true)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt
index 0718d0d32812..83fd4c258082 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt
@@ -264,6 +264,29 @@ class KeyguardInteractorTest : SysuiTestCase() {
}
@Test
+ fun dismissAlpha_doesNotEmitWhenNotDismissible() =
+ testScope.runTest {
+ val dismissAlpha by collectValues(underTest.dismissAlpha)
+ assertThat(dismissAlpha[0]).isEqualTo(1f)
+ assertThat(dismissAlpha.size).isEqualTo(1)
+
+ keyguardTransitionRepository.sendTransitionSteps(from = AOD, to = LOCKSCREEN, testScope)
+
+ // User begins to swipe up when not dimissible, which would show bouncer
+ repository.setStatusBarState(StatusBarState.KEYGUARD)
+ repository.setKeyguardDismissible(false)
+ shadeRepository.setLegacyShadeExpansion(0.98f)
+
+ assertThat(dismissAlpha[0]).isEqualTo(1f)
+ assertThat(dismissAlpha.size).isEqualTo(1)
+
+ // Shade reset should not affect dismiss alpha when not dismissible
+ shadeRepository.setLegacyShadeExpansion(0f)
+ assertThat(dismissAlpha[0]).isEqualTo(1f)
+ assertThat(dismissAlpha.size).isEqualTo(1)
+ }
+
+ @Test
fun dismissAlpha_onGlanceableHub_doesNotEmitWhenShadeResets() =
testScope.runTest {
val dismissAlpha by collectValues(underTest.dismissAlpha)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt
index 6704d63395ad..582666561be2 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt
@@ -267,12 +267,20 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() {
// action down: does NOT collapse the shade
val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, keycode)
assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
- verify(statusBarKeyguardViewManager, never()).showPrimaryBouncer(any())
+ verify(statusBarKeyguardViewManager, never())
+ .showPrimaryBouncer(
+ any(),
+ eq("KeyguardKeyEventInteractor#collapseShadeLockedOrShowPrimaryBouncer"),
+ )
// action up: collapses the shade
val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, keycode)
assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
- verify(statusBarKeyguardViewManager).showPrimaryBouncer(eq(true))
+ verify(statusBarKeyguardViewManager)
+ .showPrimaryBouncer(
+ eq(true),
+ eq("KeyguardKeyEventInteractor#collapseShadeLockedOrShowPrimaryBouncer"),
+ )
}
private fun verifyActionsDoNothing(keycode: Int) {
@@ -280,12 +288,20 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() {
val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, keycode)
assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
verify(shadeController, never()).animateCollapseShadeForced()
- verify(statusBarKeyguardViewManager, never()).showPrimaryBouncer(any())
+ verify(statusBarKeyguardViewManager, never())
+ .showPrimaryBouncer(
+ any(),
+ eq("KeyguardKeyEventInteractor#collapseShadeLockedOrShowPrimaryBouncer"),
+ )
// action up: doesNothing
val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, keycode)
assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isFalse()
verify(shadeController, never()).animateCollapseShadeForced()
- verify(statusBarKeyguardViewManager, never()).showPrimaryBouncer(any())
+ verify(statusBarKeyguardViewManager, never())
+ .showPrimaryBouncer(
+ any(),
+ eq("KeyguardKeyEventInteractor#collapseShadeLockedOrShowPrimaryBouncer"),
+ )
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractorTest.kt
index f0eedee48e57..4f351143c793 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractorTest.kt
@@ -340,6 +340,22 @@ class WindowManagerLockscreenVisibilityInteractorTest : SysuiTestCase() {
@Test
@EnableSceneContainer
+ fun surfaceBehindVisibility_whileSceneContainerNotVisible_alwaysTrue() =
+ testScope.runTest {
+ val isSurfaceBehindVisible by collectLastValue(underTest.value.surfaceBehindVisibility)
+ val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene)
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(isSurfaceBehindVisible).isFalse()
+
+ kosmos.sceneInteractor.setVisible(false, "test")
+ runCurrent()
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(isSurfaceBehindVisible).isTrue()
+ }
+
+ @Test
+ @EnableSceneContainer
fun surfaceBehindVisibility_idleWhileLocked_alwaysFalse() =
testScope.runTest {
val isSurfaceBehindVisible by collectLastValue(underTest.value.surfaceBehindVisibility)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModelTest.kt
index e1323c166f6b..9aee4c97f214 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModelTest.kt
@@ -35,6 +35,7 @@ import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.statusbar.phone.statusBarKeyguardViewManager
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.any
+import com.android.systemui.util.mockito.eq
import com.google.common.collect.Range
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
@@ -56,7 +57,8 @@ class AlternateBouncerViewModelTest : SysuiTestCase() {
fun onTapped() =
testScope.runTest {
underTest.onTapped()
- verify(statusBarKeyguardViewManager).showPrimaryBouncer(any())
+ verify(statusBarKeyguardViewManager)
+ .showPrimaryBouncer(any(), eq("AlternateBouncerViewModel#onTapped"))
}
@Test
@@ -154,7 +156,7 @@ class AlternateBouncerViewModelTest : SysuiTestCase() {
private fun stepToAlternateBouncer(
value: Float,
- state: TransitionState = TransitionState.RUNNING
+ state: TransitionState = TransitionState.RUNNING,
): TransitionStep {
return step(
from = KeyguardState.LOCKSCREEN,
@@ -166,7 +168,7 @@ class AlternateBouncerViewModelTest : SysuiTestCase() {
private fun stepFromAlternateBouncer(
value: Float,
- state: TransitionState = TransitionState.RUNNING
+ state: TransitionState = TransitionState.RUNNING,
): TransitionStep {
return step(
from = KeyguardState.ALTERNATE_BOUNCER,
@@ -180,14 +182,14 @@ class AlternateBouncerViewModelTest : SysuiTestCase() {
from: KeyguardState,
to: KeyguardState,
value: Float,
- transitionState: TransitionState
+ transitionState: TransitionState,
): TransitionStep {
return TransitionStep(
from = from,
to = to,
value = value,
transitionState = transitionState,
- ownerName = "AlternateBouncerViewModelTest"
+ ownerName = "AlternateBouncerViewModelTest",
)
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/model/SysUiStateExtTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/model/SysUiStateExtTest.kt
index d1b552906fbb..5d4de02f9aaa 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/model/SysUiStateExtTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/model/SysUiStateExtTest.kt
@@ -16,7 +16,6 @@
package com.android.systemui.model
-import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -35,7 +34,7 @@ class SysUiStateExtTest : SysuiTestCase() {
@Test
fun updateFlags() {
- underTest.updateFlags(Display.DEFAULT_DISPLAY, 1L to true, 2L to false, 4L to true)
+ underTest.updateFlags(1L to true, 2L to false, 4L to true)
assertThat(underTest.flags and 1L).isNotEqualTo(0L)
assertThat(underTest.flags and 2L).isEqualTo(0L)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/EditTileListStateTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/EditTileListStateTest.kt
index 8b9ae9a0606d..2dd2f7c0f562 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/EditTileListStateTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/EditTileListStateTest.kt
@@ -23,6 +23,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.qs.panels.shared.model.SizedTile
import com.android.systemui.qs.panels.shared.model.SizedTileImpl
+import com.android.systemui.qs.panels.ui.compose.selection.PlacementEvent
import com.android.systemui.qs.panels.ui.model.GridCell
import com.android.systemui.qs.panels.ui.model.TileGridCell
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
@@ -108,6 +109,76 @@ class EditTileListStateTest : SysuiTestCase() {
assertThat(underTest.tiles.toStrings()).doesNotContain(TestEditTiles[0].tile.tileSpec.spec)
}
+ @Test
+ fun targetIndexForPlacementToTileSpec_returnsCorrectIndex() {
+ val placementEvent =
+ PlacementEvent.PlaceToTileSpec(
+ movingSpec = TestEditTiles[0].tile.tileSpec,
+ targetSpec = TestEditTiles[3].tile.tileSpec,
+ )
+ val index = underTest.targetIndexForPlacement(placementEvent)
+
+ assertThat(index).isEqualTo(3)
+ }
+
+ @Test
+ fun targetIndexForPlacementToIndex_indexOutOfBounds_returnsCorrectIndex() {
+ val placementEventTooLow =
+ PlacementEvent.PlaceToIndex(
+ movingSpec = TestEditTiles[0].tile.tileSpec,
+ targetIndex = -1,
+ )
+ val index1 = underTest.targetIndexForPlacement(placementEventTooLow)
+
+ assertThat(index1).isEqualTo(0)
+
+ val placementEventTooHigh =
+ PlacementEvent.PlaceToIndex(
+ movingSpec = TestEditTiles[0].tile.tileSpec,
+ targetIndex = 10,
+ )
+ val index2 = underTest.targetIndexForPlacement(placementEventTooHigh)
+ assertThat(index2).isEqualTo(TestEditTiles.size)
+ }
+
+ @Test
+ fun targetIndexForPlacementToIndex_movingBack_returnsCorrectIndex() {
+ /**
+ * With the grid: [ a ] [ b ] [ c ] [ Large D ] [ e ] [ f ]
+ *
+ * Moving 'e' to the spacer at index 3 will result in the tilespec order: a, b, c, e, d, f
+ *
+ * 'e' is now at index 3
+ */
+ val placementEvent =
+ PlacementEvent.PlaceToIndex(
+ movingSpec = TestEditTiles[4].tile.tileSpec,
+ targetIndex = 3,
+ )
+ val index = underTest.targetIndexForPlacement(placementEvent)
+
+ assertThat(index).isEqualTo(3)
+ }
+
+ @Test
+ fun targetIndexForPlacementToIndex_movingForward_returnsCorrectIndex() {
+ /**
+ * With the grid: [ a ] [ b ] [ c ] [ Large D ] [ e ] [ f ]
+ *
+ * Moving '1' to the spacer at index 3 will result in the tilespec order: b, c, a, d, e, f
+ *
+ * 'a' is now at index 2
+ */
+ val placementEvent =
+ PlacementEvent.PlaceToIndex(
+ movingSpec = TestEditTiles[0].tile.tileSpec,
+ targetIndex = 3,
+ )
+ val index = underTest.targetIndexForPlacement(placementEvent)
+
+ assertThat(index).isEqualTo(2)
+ }
+
private fun List<GridCell>.toStrings(): List<String> {
return map {
if (it is TileGridCell) {
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionStateTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionStateTest.kt
index ab217a3f50ef..33ee3379c0d6 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionStateTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionStateTest.kt
@@ -19,8 +19,14 @@ package com.android.systemui.qs.panels.ui.compose.selection
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.GreyedOut
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.None
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.Placeable
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.Removable
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.Selected
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
@@ -45,7 +51,104 @@ class MutableSelectionStateTest : SysuiTestCase() {
assertThat(underTest.selection).isEqualTo(newSpec)
}
+ @Test
+ fun placementModeEnabled_tapOnIndex_sendsCorrectPlacementEvent() {
+ // Tap while in placement mode
+ underTest.enterPlacementMode(TEST_SPEC)
+ underTest.onTap(2)
+
+ assertThat(underTest.placementEnabled).isFalse()
+ val event = underTest.placementEvent as PlacementEvent.PlaceToIndex
+ assertThat(event.movingSpec).isEqualTo(TEST_SPEC)
+ assertThat(event.targetIndex).isEqualTo(2)
+ }
+
+ @Test
+ fun placementModeDisabled_tapOnIndex_doesNotSendPlacementEvent() {
+ // Tap while placement mode is disabled
+ underTest.onTap(2)
+
+ assertThat(underTest.placementEnabled).isFalse()
+ assertThat(underTest.placementEvent).isNull()
+ }
+
+ @Test
+ fun placementModeEnabled_tapOnSelection_exitPlacementMode() {
+ // Tap while in placement mode
+ underTest.enterPlacementMode(TEST_SPEC)
+ underTest.onTap(TEST_SPEC)
+
+ assertThat(underTest.placementEnabled).isFalse()
+ assertThat(underTest.placementEvent).isNull()
+ }
+
+ @Test
+ fun placementModeEnabled_tapOnTileSpec_sendsCorrectPlacementEvent() {
+ // Tap while in placement mode
+ underTest.enterPlacementMode(TEST_SPEC)
+ underTest.onTap(TEST_SPEC_2)
+
+ assertThat(underTest.placementEnabled).isFalse()
+ val event = underTest.placementEvent as PlacementEvent.PlaceToTileSpec
+ assertThat(event.movingSpec).isEqualTo(TEST_SPEC)
+ assertThat(event.targetSpec).isEqualTo(TEST_SPEC_2)
+ }
+
+ @Test
+ fun placementModeDisabled_tapOnSelection_unselect() {
+ // Select the tile and tap on it
+ underTest.select(TEST_SPEC)
+ underTest.onTap(TEST_SPEC)
+
+ assertThat(underTest.placementEnabled).isFalse()
+ assertThat(underTest.selected).isFalse()
+ }
+
+ @Test
+ fun placementModeDisabled_tapOnTile_selects() {
+ // Select a tile but tap a second one
+ underTest.select(TEST_SPEC)
+ underTest.onTap(TEST_SPEC_2)
+
+ assertThat(underTest.placementEnabled).isFalse()
+ assertThat(underTest.selection).isEqualTo(TEST_SPEC_2)
+ }
+
+ @Test
+ fun tileStateFor_selectedTile_returnsSingleSelection() = runTest {
+ underTest.select(TEST_SPEC)
+
+ assertThat(underTest.tileStateFor(TEST_SPEC, None, canShowRemovalBadge = true))
+ .isEqualTo(Selected)
+ assertThat(underTest.tileStateFor(TEST_SPEC_2, None, canShowRemovalBadge = true))
+ .isEqualTo(Removable)
+ assertThat(underTest.tileStateFor(TEST_SPEC_3, None, canShowRemovalBadge = true))
+ .isEqualTo(Removable)
+ }
+
+ @Test
+ fun tileStateFor_placementMode_returnsSinglePlaceable() = runTest {
+ underTest.enterPlacementMode(TEST_SPEC)
+
+ assertThat(underTest.tileStateFor(TEST_SPEC, None, canShowRemovalBadge = true))
+ .isEqualTo(Placeable)
+ assertThat(underTest.tileStateFor(TEST_SPEC_2, None, canShowRemovalBadge = true))
+ .isEqualTo(GreyedOut)
+ assertThat(underTest.tileStateFor(TEST_SPEC_3, None, canShowRemovalBadge = true))
+ .isEqualTo(GreyedOut)
+ }
+
+ @Test
+ fun tileStateFor_nonRemovableTile_returnsNoneState() = runTest {
+ assertThat(underTest.tileStateFor(TEST_SPEC, None, canShowRemovalBadge = true))
+ .isEqualTo(Removable)
+ assertThat(underTest.tileStateFor(TEST_SPEC_2, None, canShowRemovalBadge = false))
+ .isEqualTo(None)
+ }
+
companion object {
private val TEST_SPEC = TileSpec.create("testSpec")
+ private val TEST_SPEC_2 = TileSpec.create("testSpec2")
+ private val TEST_SPEC_3 = TileSpec.create("testSpec3")
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt
index 1743e056b65c..6d4fffdefb1b 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt
@@ -22,7 +22,6 @@ import android.os.PowerManager
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.provider.Settings
-import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
@@ -1213,15 +1212,15 @@ class SceneContainerStartableTest : SysuiTestCase() {
fakeSceneDataSource.pause()
sceneInteractor.changeScene(sceneKey, "reason")
runCurrent()
- verify(sysUiState, times(index)).commitUpdate(Display.DEFAULT_DISPLAY)
+ verify(sysUiState, times(index)).commitUpdate()
fakeSceneDataSource.unpause(expectedScene = sceneKey)
runCurrent()
- verify(sysUiState, times(index)).commitUpdate(Display.DEFAULT_DISPLAY)
+ verify(sysUiState, times(index)).commitUpdate()
transitionStateFlow.value = ObservableTransitionState.Idle(sceneKey)
runCurrent()
- verify(sysUiState, times(index + 1)).commitUpdate(Display.DEFAULT_DISPLAY)
+ verify(sysUiState, times(index + 1)).commitUpdate()
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/CommandQueueTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/CommandQueueTest.java
index 70df82d95008..c26f18f5ab6d 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/CommandQueueTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/CommandQueueTest.java
@@ -36,7 +36,9 @@ import android.hardware.biometrics.IBiometricSysuiReceiver;
import android.hardware.biometrics.PromptInfo;
import android.hardware.fingerprint.IUdfpsRefreshRateRequestCallback;
import android.os.Bundle;
+import android.os.RemoteException;
import android.platform.test.annotations.EnableFlags;
+import android.util.Pair;
import android.view.KeyEvent;
import android.view.WindowInsets;
import android.view.WindowInsets.Type.InsetsType;
@@ -46,6 +48,7 @@ import android.view.WindowInsetsController.Behavior;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
+import com.android.internal.statusbar.DisableStates;
import com.android.internal.statusbar.LetterboxDetails;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.view.AppearanceRegion;
@@ -58,11 +61,14 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.HashMap;
+import java.util.Map;
+
@SmallTest
@RunWith(AndroidJUnit4.class)
public class CommandQueueTest extends SysuiTestCase {
- private static final LetterboxDetails[] TEST_LETTERBOX_DETAILS = new LetterboxDetails[] {
+ private static final LetterboxDetails[] TEST_LETTERBOX_DETAILS = new LetterboxDetails[]{
new LetterboxDetails(
/* letterboxInnerBounds= */ new Rect(100, 0, 200, 500),
/* letterboxFullBounds= */ new Rect(0, 0, 500, 100),
@@ -119,6 +125,27 @@ public class CommandQueueTest extends SysuiTestCase {
}
@Test
+ public void testDisableForAllDisplays() throws RemoteException {
+ int state1 = 14;
+ int state2 = 42;
+ int secondaryDisplayState1 = 16;
+ int secondaryDisplayState2 = 44;
+ Map<Integer, Pair<Integer, Integer>> displaysWithStates = new HashMap<>();
+ displaysWithStates.put(DEFAULT_DISPLAY, new Pair<>(state1, state2)); // Example values
+ displaysWithStates.put(SECONDARY_DISPLAY,
+ new Pair<>(secondaryDisplayState1, secondaryDisplayState2)); // Example values
+ DisableStates expectedDisableStates = new DisableStates(displaysWithStates, true);
+
+ mCommandQueue.disableForAllDisplays(expectedDisableStates);
+ waitForIdleSync();
+
+ verify(mCallbacks).disable(eq(DEFAULT_DISPLAY), eq(state1), eq(state2), eq(true));
+ verify(mCallbacks).disable(eq(SECONDARY_DISPLAY), eq(secondaryDisplayState1),
+ eq(secondaryDisplayState2), eq(true));
+ }
+
+
+ @Test
public void testExpandNotifications() {
mCommandQueue.animateExpandNotificationsPanel();
waitForIdleSync();
@@ -475,7 +502,8 @@ public class CommandQueueTest extends SysuiTestCase {
final long requestId = 10;
mCommandQueue.showAuthenticationDialog(promptInfo, receiver, sensorIds,
- credentialAllowed, requireConfirmation, userId, operationId, packageName, requestId);
+ credentialAllowed, requireConfirmation, userId, operationId, packageName,
+ requestId);
waitForIdleSync();
verify(mCallbacks).showAuthenticationDialog(eq(promptInfo), eq(receiver), eq(sensorIds),
eq(credentialAllowed), eq(requireConfirmation), eq(userId), eq(operationId),
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java
index 95366568a37a..5ad4a4fab056 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java
@@ -103,46 +103,6 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
row.resetMenu();
}
-
- @Test
- public void testNoAppOpsInSlowSwipe() {
- when(mRow.getShowSnooze()).thenReturn(false);
- Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 0);
-
- NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
- row.createMenu(mRow);
-
- ViewGroup container = (ViewGroup) row.getMenuView();
- // noti blocking
- assertEquals(1, container.getChildCount());
- }
-
- @Test
- public void testNoSnoozeInSlowSwipe() {
- when(mRow.getShowSnooze()).thenReturn(false);
- Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 0);
-
- NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
- row.createMenu(mRow);
-
- ViewGroup container = (ViewGroup) row.getMenuView();
- // just for noti blocking
- assertEquals(1, container.getChildCount());
- }
-
- @Test
- public void testSnoozeInSlowSwipe() {
- when(mRow.getShowSnooze()).thenReturn(true);
- Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 0);
-
- NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
- row.createMenu(mRow);
-
- ViewGroup container = (ViewGroup) row.getMenuView();
- // one for snooze and one for noti blocking
- assertEquals(2, container.getChildCount());
- }
-
@Test
public void testSlowSwipe_newDismiss() {
when(mRow.getShowSnooze()).thenReturn(true);
@@ -237,6 +197,7 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
new NotificationMenuRow(mContext, mPeopleNotificationIdentifier));
doReturn(30f).when(row).getSnapBackThreshold();
doReturn(50f).when(row).getDismissThreshold();
+ doReturn(70).when(row).getSpaceForMenu();
when(row.isMenuOnLeft()).thenReturn(true);
when(row.getTranslation()).thenReturn(40f);
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java
index 1ea41de63e64..716353945be2 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java
@@ -186,7 +186,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
.thenReturn(false);
mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
verify(mStatusBarKeyguardViewManager, never()).notifyKeyguardAuthenticated(anyBoolean());
assertThat(mBiometricUnlockController.getMode())
.isEqualTo(BiometricUnlockController.MODE_SHOW_BOUNCER);
@@ -198,7 +199,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
.thenReturn(false);
mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
BiometricSourceType.FINGERPRINT, false /* isStrongBiometric */);
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
assertThat(mBiometricUnlockController.getMode())
.isEqualTo(BiometricUnlockController.MODE_SHOW_BOUNCER);
assertThat(mBiometricUnlockController.getBiometricType())
@@ -248,7 +250,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);
- verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false));
assertThat(mBiometricUnlockController.getMode())
.isEqualTo(BiometricUnlockController.MODE_UNLOCK_COLLAPSING);
@@ -327,7 +330,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
BiometricSourceType.FACE, true /* isStrongBiometric */);
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
assertThat(mBiometricUnlockController.getMode())
.isEqualTo(BiometricUnlockController.MODE_SHOW_BOUNCER);
}
@@ -359,7 +363,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
BiometricSourceType.FACE, true /* isStrongBiometric */);
- verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
assertThat(mBiometricUnlockController.getMode())
.isEqualTo(BiometricUnlockController.MODE_NONE);
}
@@ -438,17 +443,20 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
// WHEN udfps fails once - then don't show the bouncer yet
mBiometricUnlockController.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
- verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
// WHEN udfps fails the second time - then don't show the bouncer yet
mBiometricUnlockController.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
- verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
// WHEN udpfs fails the third time
mBiometricUnlockController.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
// THEN show the bouncer
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(true);
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(true,
+ "BiometricUnlockController#MODE_SHOW_BOUNCER");
}
@Test
@@ -460,14 +468,16 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
mBiometricUnlockController.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
mBiometricUnlockController.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
mBiometricUnlockController.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
- verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager, never()).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
// WHEN lockout is received
mBiometricUnlockController.onBiometricError(FingerprintManager.FINGERPRINT_ERROR_LOCKOUT,
"Lockout", BiometricSourceType.FINGERPRINT);
// THEN show bouncer
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(true);
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(true,
+ "BiometricUnlockController#MODE_SHOW_BOUNCER");
}
@Test
@@ -544,7 +554,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);
// THEN shows primary bouncer
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
}
@Test
@@ -554,7 +565,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
BiometricSourceType.FACE, false /* isStrongBiometric */);
// THEN shows primary bouncer
- verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean());
+ verify(mStatusBarKeyguardViewManager).showPrimaryBouncer(anyBoolean(),
+ eq("BiometricUnlockController#MODE_SHOW_BOUNCER"));
}
private void givenFingerprintModeUnlockCollapsing() {
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java
index 1cc291199531..d9e256228428 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java
@@ -124,7 +124,8 @@ public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
mRemoteInputCallback.onLockedRemoteInput(
mock(ExpandableNotificationRow.class), mock(View.class));
- verify(mStatusBarKeyguardViewManager).showBouncer(true);
+ verify(mStatusBarKeyguardViewManager).showBouncer(true,
+ "StatusBarRemoteInputCallback#onLockedRemoteInput");
}
@Test
@DisableFlags(ExpandHeadsUpOnInlineReply.FLAG_NAME)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt
index 18a124cf362e..033503f9ad8e 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/unfold/DisplaySwitchLatencyTrackerTest.kt
@@ -52,6 +52,7 @@ import com.android.systemui.unfold.DisplaySwitchLatencyTracker.Companion.FOLDABL
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.Companion.FOLDABLE_DEVICE_STATE_HALF_OPEN
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.Companion.SCREEN_EVENT_TIMEOUT
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.DisplaySwitchLatencyEvent
+import com.android.systemui.unfold.data.repository.ScreenTimeoutPolicyRepository
import com.android.systemui.unfold.data.repository.UnfoldTransitionRepositoryImpl
import com.android.systemui.unfold.domain.interactor.UnfoldTransitionInteractor
import com.android.systemui.unfoldedDeviceState
@@ -97,6 +98,8 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
private val animationStatusRepository = kosmos.fakeAnimationStatusRepository
private val keyguardInteractor = mock<KeyguardInteractor>()
private val displaySwitchLatencyLogger = mock<DisplaySwitchLatencyLogger>()
+ private val screenTimeoutPolicyRepository = mock<ScreenTimeoutPolicyRepository>()
+ private val screenTimeoutActive = MutableStateFlow(true)
private val latencyTracker = mock<LatencyTracker>()
private val deviceStateManager = kosmos.deviceStateManager
@@ -136,6 +139,7 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
whenever(resources.getIntArray(R.array.config_foldedDeviceStates))
.thenReturn(nonEmptyClosedDeviceStatesArray)
whenever(keyguardInteractor.isAodAvailable).thenReturn(isAodAvailable)
+ whenever(screenTimeoutPolicyRepository.screenTimeoutActive).thenReturn(screenTimeoutActive)
animationStatusRepository.onAnimationStatusChanged(true)
powerInteractor.setAwakeForTest()
powerInteractor.setScreenPowerState(SCREEN_ON)
@@ -144,6 +148,7 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
mockContext,
foldStateRepository,
powerInteractor,
+ screenTimeoutPolicyRepository,
unfoldTransitionInteractor,
animationStatusRepository,
keyguardInteractor,
@@ -196,6 +201,7 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
mockContext,
foldStateRepository,
powerInteractor,
+ screenTimeoutPolicyRepository,
unfoldTransitionInteractorWithEmptyProgressProvider,
animationStatusRepository,
keyguardInteractor,
@@ -625,6 +631,44 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
}
}
+ @Test
+ fun displaySwitch_screenTimeoutActive_logsNoScreenWakelocks() {
+ testScope.runTest {
+ startInFoldedState(displaySwitchLatencyTracker)
+ screenTimeoutActive.value = true
+
+ startUnfolding()
+ advanceTimeBy(100.milliseconds)
+ finishUnfolding()
+
+ val event = capturedLogEvent()
+ assertThat(event.screenWakelockStatus)
+ .isEqualTo(
+ SysUiStatsLog
+ .DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_NO_WAKELOCKS
+ )
+ }
+ }
+
+ @Test
+ fun displaySwitch_screenTimeoutNotActive_logsHasScreenWakelocks() {
+ testScope.runTest {
+ startInFoldedState(displaySwitchLatencyTracker)
+ screenTimeoutActive.value = false
+
+ startUnfolding()
+ advanceTimeBy(100.milliseconds)
+ finishUnfolding()
+
+ val event = capturedLogEvent()
+ assertThat(event.screenWakelockStatus)
+ .isEqualTo(
+ SysUiStatsLog
+ .DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_HAS_SCREEN_WAKELOCKS
+ )
+ }
+ }
+
private fun capturedLogEvent(): DisplaySwitchLatencyEvent {
verify(displaySwitchLatencyLogger).log(capture(loggerArgumentCaptor))
return loggerArgumentCaptor.value
@@ -662,6 +706,9 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
fromFoldableDeviceState = fromFoldableDeviceState,
toFoldableDeviceState = toFoldableDeviceState,
toState = toState,
+ screenWakelockStatus =
+ SysUiStatsLog
+ .DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_NO_WAKELOCKS,
trackingResult = SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__TRACKING_RESULT__SUCCESS,
)
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt
index 3eada258f616..07706414393b 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt
@@ -27,6 +27,8 @@ import android.graphics.drawable.Drawable
import android.os.Process
import android.os.UserHandle
import android.os.UserManager
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -34,6 +36,7 @@ import com.android.internal.logging.UiEventLogger
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Flags as AConfigFlags
+import com.android.systemui.Flags.FLAG_USER_SWITCHER_ADD_SIGN_OUT_OPTION
import com.android.systemui.GuestResetOrExitSessionReceiver
import com.android.systemui.GuestResumeSessionReceiver
import com.android.systemui.SysuiTestCase
@@ -68,6 +71,7 @@ import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import junit.framework.Assert.assertNotNull
+import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runCurrent
@@ -101,10 +105,13 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
@Mock private lateinit var resumeSessionReceiver: GuestResumeSessionReceiver
@Mock private lateinit var resetOrExitSessionReceiver: GuestResetOrExitSessionReceiver
@Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
+ @Mock private lateinit var userLogoutInteractor: UserLogoutInteractor
private val kosmos = testKosmos()
+ private val logoutEnabledStateFlow = MutableStateFlow<Boolean>(false)
private val testScope = kosmos.testScope
private lateinit var spyContext: Context
+
private lateinit var userRepository: FakeUserRepository
private lateinit var keyguardReply: KeyguardInteractorFactory.WithDependencies
private lateinit var keyguardRepository: FakeKeyguardRepository
@@ -118,6 +125,8 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
whenever(manager.getUserIcon(anyInt())).thenReturn(ICON)
whenever(manager.canAddMoreUsers(any())).thenReturn(true)
+ whenever(userLogoutInteractor.isLogoutEnabled).thenReturn(logoutEnabledStateFlow)
+
overrideResource(com.android.settingslib.R.drawable.ic_account_circle, GUEST_ICON)
overrideResource(R.dimen.max_avatar_size, 10)
overrideResource(
@@ -493,6 +502,42 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
}
@Test
+ @DisableFlags(FLAG_USER_SWITCHER_ADD_SIGN_OUT_OPTION)
+ fun actions_logoutEnabled_flagDisabled_signOutIsNotShown() {
+ createUserInteractor()
+ testScope.runTest {
+ val userInfos = createUserInfos(count = 1, includeGuest = false)
+ userRepository.setUserInfos(userInfos)
+ userRepository.setSelectedUserInfo(userInfos[0])
+ userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = false))
+ keyguardRepository.setKeyguardShowing(true)
+ logoutEnabledStateFlow.value = true
+
+ val value = collectLastValue(underTest.actions)
+
+ assertThat(value()).isEqualTo(emptyList<UserActionModel>())
+ }
+ }
+
+ @Test
+ @EnableFlags(FLAG_USER_SWITCHER_ADD_SIGN_OUT_OPTION)
+ fun actions_logoutEnabled_flagEnabled_signOutIsShown() {
+ createUserInteractor()
+ testScope.runTest {
+ val userInfos = createUserInfos(count = 1, includeGuest = false)
+ userRepository.setUserInfos(userInfos)
+ userRepository.setSelectedUserInfo(userInfos[0])
+ userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = false))
+ keyguardRepository.setKeyguardShowing(true)
+ logoutEnabledStateFlow.value = true
+
+ val value = collectLastValue(underTest.actions)
+
+ assertThat(value()).isEqualTo(listOf(UserActionModel.SIGN_OUT))
+ }
+ }
+
+ @Test
fun executeAction_addUser_dismissesDialogAndStartsActivity() {
createUserInteractor()
testScope.runTest {
@@ -569,14 +614,23 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
verify(uiEventLogger, times(1))
.log(MultiUserActionsEvent.CREATE_GUEST_FROM_USER_SWITCHER)
assertThat(dialogRequests)
- .contains(
- ShowDialogRequestModel.ShowUserCreationDialog(isGuest = true),
- )
+ .contains(ShowDialogRequestModel.ShowUserCreationDialog(isGuest = true))
verify(activityManager).switchUser(guestUserInfo.id)
}
}
@Test
+ fun executeAction_signOut() {
+ createUserInteractor()
+ testScope.runTest {
+ underTest.executeAction(UserActionModel.SIGN_OUT)
+ runCurrent()
+
+ verify(userLogoutInteractor).logOut()
+ }
+ }
+
+ @Test
fun selectUser_alreadySelectedGuestReSelected_exitGuestDialog() {
createUserInteractor()
testScope.runTest {
@@ -739,7 +793,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
spyContext,
- Intent(Intent.ACTION_LOCALE_CHANGED)
+ Intent(Intent.ACTION_LOCALE_CHANGED),
)
runCurrent()
@@ -972,7 +1026,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
50,
"Work Profile",
/* iconPath= */ "",
- /* flags= */ UserInfo.FLAG_MANAGED_PROFILE
+ /* flags= */ UserInfo.FLAG_MANAGED_PROFILE,
)
)
userRepository.setUserInfos(userInfos)
@@ -1010,7 +1064,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
userRepository.setSettings(
UserSwitcherSettingsModel(
isUserSwitcherEnabled = true,
- isAddUsersFromLockscreen = true
+ isAddUsersFromLockscreen = true,
)
)
@@ -1034,7 +1088,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
userRepository.setSettings(
UserSwitcherSettingsModel(
isUserSwitcherEnabled = true,
- isAddUsersFromLockscreen = true
+ isAddUsersFromLockscreen = true,
)
)
@@ -1068,7 +1122,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
whenever(
manager.hasUserRestrictionForUser(
UserManager.DISALLOW_ADD_USER,
- UserHandle.of(id)
+ UserHandle.of(id),
)
)
.thenReturn(true)
@@ -1170,7 +1224,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
whenever(
manager.hasUserRestrictionForUser(
UserManager.DISALLOW_ADD_USER,
- UserHandle.of(0)
+ UserHandle.of(0),
)
)
.thenReturn(true)
@@ -1195,7 +1249,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
model = model,
id = index,
isSelected = index == selectedIndex,
- isGuest = includeGuest && index == count - 1
+ isGuest = includeGuest && index == count - 1,
)
}
}
@@ -1263,14 +1317,12 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
assertThat(record.isSwitchToEnabled).isEqualTo(isSwitchToEnabled)
}
- private fun assertRecordForAction(
- record: UserRecord,
- type: UserActionModel,
- ) {
+ private fun assertRecordForAction(record: UserRecord, type: UserActionModel) {
assertThat(record.isGuest).isEqualTo(type == UserActionModel.ENTER_GUEST_MODE)
assertThat(record.isAddUser).isEqualTo(type == UserActionModel.ADD_USER)
assertThat(record.isAddSupervisedUser)
.isEqualTo(type == UserActionModel.ADD_SUPERVISED_USER)
+ assertThat(record.isSignOut).isEqualTo(type === UserActionModel.SIGN_OUT)
}
private fun createUserInteractor(startAsProcessUser: Boolean = true) {
@@ -1317,13 +1369,11 @@ class UserSwitcherInteractorTest : SysuiTestCase() {
featureFlags = kosmos.fakeFeatureFlagsClassic,
userRestrictionChecker = mock(),
processWrapper = kosmos.processWrapper,
+ userLogoutInteractor = userLogoutInteractor,
)
}
- private fun createUserInfos(
- count: Int,
- includeGuest: Boolean,
- ): List<UserInfo> {
+ private fun createUserInfos(count: Int, includeGuest: Boolean): List<UserInfo> {
return (0 until count).map { index ->
val isGuest = includeGuest && index == count - 1
createUserInfo(
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt
index 5d51c6d16c5a..d51e66d6f3b0 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt
@@ -44,9 +44,12 @@ import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.domain.interactor.GuestUserInteractor
import com.android.systemui.user.domain.interactor.HeadlessSystemUserMode
import com.android.systemui.user.domain.interactor.RefreshUsersScheduler
+import com.android.systemui.user.domain.interactor.UserLogoutInteractor
import com.android.systemui.user.domain.interactor.UserSwitcherInteractor
import com.android.systemui.util.mockito.mock
+import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.toList
@@ -78,13 +81,13 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
@Mock private lateinit var resumeSessionReceiver: GuestResumeSessionReceiver
@Mock private lateinit var resetOrExitSessionReceiver: GuestResetOrExitSessionReceiver
@Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
+ @Mock private lateinit var userLogoutInteractor: UserLogoutInteractor
private lateinit var underTest: StatusBarUserChipViewModel
private val userRepository = FakeUserRepository()
private lateinit var guestUserInteractor: GuestUserInteractor
private lateinit var refreshUsersScheduler: RefreshUsersScheduler
-
private val testDispatcher = UnconfinedTestDispatcher()
private val testScope = TestScope(testDispatcher)
@@ -92,6 +95,9 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
fun setUp() {
MockitoAnnotations.initMocks(this)
+ val logoutEnabledStateFlow = MutableStateFlow<Boolean>(false)
+ whenever(userLogoutInteractor.isLogoutEnabled).thenReturn(logoutEnabledStateFlow)
+
doAnswer { invocation ->
val userId = invocation.arguments[0] as Int
when (userId) {
@@ -251,9 +257,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
headlessSystemUserMode = headlessSystemUserMode,
applicationScope = testScope.backgroundScope,
telephonyInteractor =
- TelephonyInteractor(
- repository = FakeTelephonyRepository(),
- ),
+ TelephonyInteractor(repository = FakeTelephonyRepository()),
broadcastDispatcher = fakeBroadcastDispatcher,
keyguardUpdateMonitor = keyguardUpdateMonitor,
backgroundDispatcher = testDispatcher,
@@ -263,7 +267,8 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
guestUserInteractor = guestUserInteractor,
uiEventLogger = uiEventLogger,
userRestrictionChecker = mock(),
- processWrapper = ProcessWrapperFake(activityManager)
+ processWrapper = ProcessWrapperFake(activityManager),
+ userLogoutInteractor = userLogoutInteractor,
)
)
}
@@ -293,7 +298,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
USER_NAME_0.text!!,
/* iconPath */ "",
/* flags */ UserInfo.FLAG_FULL,
- /* userType */ UserManager.USER_TYPE_FULL_SYSTEM
+ /* userType */ UserManager.USER_TYPE_FULL_SYSTEM,
)
private val USER_1 =
@@ -302,7 +307,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
USER_NAME_1.text!!,
/* iconPath */ "",
/* flags */ UserInfo.FLAG_FULL,
- /* userType */ UserManager.USER_TYPE_FULL_SYSTEM
+ /* userType */ UserManager.USER_TYPE_FULL_SYSTEM,
)
private val USER_2 =
@@ -311,7 +316,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
USER_NAME_2.text!!,
/* iconPath */ "",
/* flags */ UserInfo.FLAG_FULL,
- /* userType */ UserManager.USER_TYPE_FULL_SYSTEM
+ /* userType */ UserManager.USER_TYPE_FULL_SYSTEM,
)
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt
index 8ff088f5d29b..087ccb83afe5 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt
@@ -44,6 +44,7 @@ import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.domain.interactor.GuestUserInteractor
import com.android.systemui.user.domain.interactor.HeadlessSystemUserMode
import com.android.systemui.user.domain.interactor.RefreshUsersScheduler
+import com.android.systemui.user.domain.interactor.UserLogoutInteractor
import com.android.systemui.user.domain.interactor.UserSwitcherInteractor
import com.android.systemui.user.legacyhelper.ui.LegacyUserUiHelper
import com.android.systemui.user.shared.model.UserActionModel
@@ -51,6 +52,7 @@ import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@@ -79,6 +81,7 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
@Mock private lateinit var resumeSessionReceiver: GuestResumeSessionReceiver
@Mock private lateinit var resetOrExitSessionReceiver: GuestResetOrExitSessionReceiver
@Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
+ @Mock private lateinit var userLogoutInteractor: UserLogoutInteractor
private lateinit var underTest: UserSwitcherViewModel
@@ -94,6 +97,10 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
whenever(manager.canAddMoreUsers(any())).thenReturn(true)
whenever(manager.getUserSwitchability(any()))
.thenReturn(UserManager.SWITCHABILITY_STATUS_OK)
+
+ val logoutEnabledStateFlow = MutableStateFlow<Boolean>(false)
+ whenever(userLogoutInteractor.isLogoutEnabled).thenReturn(logoutEnabledStateFlow)
+
overrideResource(
com.android.internal.R.string.config_supervisedUserCreationPackage,
SUPERVISED_USER_CREATION_PACKAGE,
@@ -113,15 +120,11 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
UserInfo.FLAG_ADMIN or
UserInfo.FLAG_FULL,
UserManager.USER_TYPE_FULL_SYSTEM,
- ),
+ )
)
userRepository.setUserInfos(userInfos)
userRepository.setSelectedUserInfo(userInfos[0])
- userRepository.setSettings(
- UserSwitcherSettingsModel(
- isUserSwitcherEnabled = true,
- )
- )
+ userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
}
val refreshUsersScheduler =
@@ -163,9 +166,7 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
headlessSystemUserMode = headlessSystemUserMode,
applicationScope = testScope.backgroundScope,
telephonyInteractor =
- TelephonyInteractor(
- repository = FakeTelephonyRepository(),
- ),
+ TelephonyInteractor(repository = FakeTelephonyRepository()),
broadcastDispatcher = fakeBroadcastDispatcher,
keyguardUpdateMonitor = keyguardUpdateMonitor,
backgroundDispatcher = testDispatcher,
@@ -175,7 +176,8 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
guestUserInteractor = guestUserInteractor,
uiEventLogger = uiEventLogger,
userRestrictionChecker = mock(),
- processWrapper = ProcessWrapperFake(activityManager)
+ processWrapper = ProcessWrapperFake(activityManager),
+ userLogoutInteractor = userLogoutInteractor,
),
guestUserInteractor = guestUserInteractor,
)
diff --git a/packages/SystemUI/res/drawable/unpin_icon.xml b/packages/SystemUI/res/drawable/unpin_icon.xml
new file mode 100644
index 000000000000..4e2e15893884
--- /dev/null
+++ b/packages/SystemUI/res/drawable/unpin_icon.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M680,120L680,200L640,200L640,527L560,447L560,200L400,200L400,287L313,200L280,167L280,167L280,120L680,120ZM480,920L440,880L440,640L240,640L240,560L320,480L320,434L56,168L112,112L848,848L790,904L526,640L520,640L520,880L480,920ZM354,560L446,560L402,516L400,514L354,560ZM480,367L480,367L480,367L480,367ZM402,516L402,516L402,516L402,516Z"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml b/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml
index aec204f45aa7..7f6dc49505bb 100644
--- a/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml
+++ b/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml
@@ -38,7 +38,7 @@
<path
android:name="rect"
android:pathData="M -144.0,-5.0 l 288.0,0 l 0,10.0 l -288.0,0 Z"
- android:fillColor="?androidprv:attr/colorAccentPrimaryVariant" />
+ android:fillColor="@androidprv:color/materialColorPrimary" />
</group>
</group>
</vector> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/promoted_permission_guts.xml b/packages/SystemUI/res/layout/promoted_permission_guts.xml
new file mode 100644
index 000000000000..50e5ae3c05ed
--- /dev/null
+++ b/packages/SystemUI/res/layout/promoted_permission_guts.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2017, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<com.android.systemui.statusbar.notification.row.PromotedPermissionGutsContent
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="2dp"
+ android:paddingBottom="2dp"
+ android:background="@androidprv:color/materialColorSurfaceContainerHigh"
+ android:theme="@style/Theme.SystemUI"
+ >
+
+ <RelativeLayout
+ android:id="@+id/promoted_guts"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="@dimen/notification_2025_min_height">
+
+ <ImageView
+ android:id="@+id/unpin_icon"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:src="@drawable/unpin_icon"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:padding="@dimen/notification_importance_button_padding"
+ />
+
+ <TextView
+ android:id="@+id/demote_explain"
+ android:layout_width="400dp"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@id/unpin_icon"
+ android:layout_toLeftOf="@id/undo"
+ android:padding="@*android:dimen/notification_content_margin_end"
+ android:textColor="@androidprv:color/materialColorOnSurface"
+ android:minWidth="@dimen/min_clickable_item_size"
+ android:minHeight="@dimen/min_clickable_item_size"
+ style="@style/TextAppearance.NotificationInfo.Button" />
+
+ <TextView
+ android:id="@+id/undo"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/unpin_icon"
+ android:layout_alignParentRight="true"
+ android:padding="@*android:dimen/notification_content_margin_end"
+ android:textColor="@androidprv:color/materialColorOnSurface"
+ android:minWidth="@dimen/min_clickable_item_size"
+ android:minHeight="@dimen/min_clickable_item_size"
+ android:text="@string/snooze_undo"
+ style="@style/TextAppearance.NotificationInfo.Button" />
+ </RelativeLayout>
+
+</com.android.systemui.statusbar.notification.row.PromotedPermissionGutsContent>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index d0ae307b6919..7d983068f34e 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -989,7 +989,7 @@
<dimen name="keyguard_security_container_padding_top">20dp</dimen>
- <dimen name="keyguard_translate_distance_on_swipe_up">-200dp</dimen>
+ <dimen name="keyguard_translate_distance_on_swipe_up">-180dp</dimen>
<dimen name="keyguard_indication_margin_bottom">32dp</dimen>
<dimen name="ambient_indication_margin_bottom">71dp</dimen>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index b627bdf22a6c..681bd53f1a40 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -2551,6 +2551,9 @@
<!-- Label for header of customize QS [CHAR LIMIT=60] -->
<string name="drag_to_rearrange_tiles">Hold and drag to rearrange tiles</string>
+ <!-- Label for placing tiles in edit mode for QS [CHAR LIMIT=60] -->
+ <string name="tap_to_position_tile">Tap to position tile</string>
+
<!-- Label for area where tiles can be dragged in to [CHAR LIMIT=60] -->
<string name="drag_to_remove_tiles">Drag here to remove</string>
@@ -2592,6 +2595,12 @@
<!-- Accessibility description of action to remove QS tile on click. It will read as "Double-tap to remove tile" in screen readers [CHAR LIMIT=NONE] -->
<string name="accessibility_qs_edit_remove_tile_action">remove tile</string>
+ <!-- Accessibility description of action to select the QS tile to place on click. It will read as "Double-tap to toggle placement mode" in screen readers [CHAR LIMIT=NONE] -->
+ <string name="accessibility_qs_edit_toggle_placement_mode">toggle placement mode</string>
+
+ <!-- Accessibility description of action to toggle the QS tile selection. It will read as "Double-tap to toggle selection" in screen readers [CHAR LIMIT=NONE] -->
+ <string name="accessibility_qs_edit_toggle_selection">toggle selection</string>
+
<!-- Accessibility action of action to add QS tile to end. It will read as "Double-tap to add tile to the last position" in screen readers [CHAR LIMIT=NONE] -->
<string name="accessibility_qs_edit_tile_add_action">add tile to the last position</string>
@@ -4200,6 +4209,12 @@
All Quick Settings tiles will reset to the device’s original settings
</string>
+
+ <!-- Content of the Reset Tiles dialog in QS Edit mode. [CHAR LIMIT=NONE] -->
+ <string name="demote_explain_text">
+ <xliff:g id="application" example= "Superfast Food Delivery">%1$s</xliff:g> will no longer show Live Updates here. You can change this any time in Settings.
+ </string>
+
<!-- Template that joins disabled message with the label for the voice over. [CHAR LIMIT=NONE] -->
<string name="volume_slider_disabled_message_template"><xliff:g example="Notification" id="stream_name">%1$s</xliff:g>, <xliff:g example="Disabled because ring is muted" id="disabled_message">%2$s</xliff:g></string>
</resources>
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardViewController.java
index 892851cd7056..8a307145023d 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardViewController.java
@@ -160,7 +160,7 @@ public interface KeyguardViewController {
/**
* Shows the primary bouncer.
*/
- void showPrimaryBouncer(boolean scrimmed);
+ void showPrimaryBouncer(boolean scrimmed, String reason);
/**
* When the primary bouncer is fully visible or is showing but animation didn't finish yet.
diff --git a/packages/SystemUI/src/com/android/systemui/ambient/touch/scrim/BouncerScrimController.java b/packages/SystemUI/src/com/android/systemui/ambient/touch/scrim/BouncerScrimController.java
index 6f2dd799c409..633c13e9e94d 100644
--- a/packages/SystemUI/src/com/android/systemui/ambient/touch/scrim/BouncerScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/ambient/touch/scrim/BouncerScrimController.java
@@ -34,7 +34,7 @@ public class BouncerScrimController implements ScrimController {
@Override
public void show(boolean scrimmed) {
- mStatusBarKeyguardViewManager.showPrimaryBouncer(scrimmed);
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(scrimmed, "BouncerScrimController#show");
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
index dfe8eb28b2a6..659d3b46fea9 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
@@ -880,7 +880,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
Log.v(TAG, "aod lock icon long-press rejected by the falsing manager.");
return;
}
- mKeyguardViewManager.showPrimaryBouncer(true);
+ mKeyguardViewManager.showPrimaryBouncer(true, "UdfpsController#onAodInterrupt");
// play the same haptic as the DeviceEntryIcon longpress
if (mOverlay != null && mOverlay.getTouchOverlay() != null) {
diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt
index 0c6d7920d7f3..48e08fcd90c5 100644
--- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt
@@ -135,7 +135,7 @@ constructor(
// TODO(b/243695312): Encapsulate all of the show logic for the bouncer.
/** Show the bouncer if necessary and set the relevant states. */
@JvmOverloads
- fun show(isScrimmed: Boolean): Boolean {
+ fun show(isScrimmed: Boolean, reason: String): Boolean {
// When the scene container framework is enabled, instead of calling this, call
// SceneInteractor#changeScene(Scenes.Bouncer, ...).
SceneContainerFlag.assertInLegacyMode()
@@ -176,6 +176,7 @@ constructor(
return false
}
+ Log.i(TAG, "Show primary bouncer requested, reason: $reason")
repository.setPrimaryShowingSoon(true)
if (usePrimaryBouncerPassiveAuthDelay()) {
Log.d(TAG, "delay bouncer, passive auth may succeed")
diff --git a/packages/SystemUI/src/com/android/systemui/common/ui/compose/gestures/EagerTap.kt b/packages/SystemUI/src/com/android/systemui/common/ui/compose/gestures/EagerTap.kt
new file mode 100644
index 000000000000..078ea569a63c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/common/ui/compose/gestures/EagerTap.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.common.ui.compose.gestures
+
+import androidx.compose.foundation.gestures.awaitEachGesture
+import androidx.compose.foundation.gestures.awaitFirstDown
+import androidx.compose.foundation.gestures.waitForUpOrCancellation
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.pointer.PointerInputChange
+import androidx.compose.ui.input.pointer.PointerInputScope
+import kotlinx.coroutines.coroutineScope
+
+/**
+ * Detects taps and double taps without waiting for the double tap minimum delay in between
+ *
+ * Using [detectTapGestures] with both a single tap and a double tap defined will send only one of
+ * these event per user interaction. This variant will send the single tap at all times, with the
+ * optional double tap if the user pressed a second time in a short period of time.
+ *
+ * Warning: Use this only if you know that reporting a single tap followed by a double tap won't be
+ * a problem in your use case.
+ *
+ * @param doubleTapEnabled whether this should listen for double tap events. This value is captured
+ * at the first down movement.
+ * @param onDoubleTap the double tap callback
+ * @param onTap the single tap callback
+ */
+suspend fun PointerInputScope.detectEagerTapGestures(
+ doubleTapEnabled: () -> Boolean,
+ onDoubleTap: (Offset) -> Unit,
+ onTap: () -> Unit,
+) = coroutineScope {
+ awaitEachGesture {
+ val down = awaitFirstDown()
+ down.consume()
+
+ // Capture whether double tap is enabled on first down as this state can change following
+ // the first tap
+ val isDoubleTapEnabled = doubleTapEnabled()
+
+ // wait for first tap up or long press
+ val upOrCancel = waitForUpOrCancellation()
+
+ if (upOrCancel != null) {
+ // tap was successful.
+ upOrCancel.consume()
+ onTap.invoke()
+
+ if (isDoubleTapEnabled) {
+ // check for second tap
+ val secondDown =
+ withTimeoutOrNull(viewConfiguration.doubleTapTimeoutMillis) {
+ val minUptime =
+ upOrCancel.uptimeMillis + viewConfiguration.doubleTapMinTimeMillis
+ var change: PointerInputChange
+ // The second tap doesn't count if it happens before DoubleTapMinTime of the
+ // first tap
+ do {
+ change = awaitFirstDown()
+ } while (change.uptimeMillis < minUptime)
+ change
+ }
+
+ if (secondDown != null) {
+ // Second tap down detected
+
+ // Might have a long second press as the second tap
+ val secondUp = waitForUpOrCancellation()
+ if (secondUp != null) {
+ secondUp.consume()
+ onDoubleTap(secondUp.position)
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalLockIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalLockIconViewModel.kt
index 19eeabd98c88..931639c8b247 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalLockIconViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalLockIconViewModel.kt
@@ -130,7 +130,9 @@ constructor(
if (SceneContainerFlag.isEnabled) {
deviceEntryInteractor.attemptDeviceEntry()
} else {
- keyguardViewController.get().showPrimaryBouncer(/* scrim */ true)
+ keyguardViewController
+ .get()
+ .showPrimaryBouncer(/* scrim */ true, "CommunalLockIconViewModel#onUserInteraction")
}
deviceEntrySourceInteractor.attemptEnterDeviceFromDeviceEntryIcon()
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 6db2ebc0df2c..8da06ac14fc1 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -3765,13 +3765,7 @@ public class KeyguardViewMediator implements CoreStartable,
Log.d(TAG, "Status bar manager is disabled for visible background users");
}
} else {
- try {
- mStatusBarService.disableForUser(flags, mStatusBarDisableToken,
- mContext.getPackageName(),
- mSelectedUserInteractor.getSelectedUserId());
- } catch (RemoteException e) {
- Log.d(TAG, "Failed to force clear flags", e);
- }
+ statusBarServiceDisableForUser(flags, "Failed to force clear flags");
}
}
@@ -3807,18 +3801,29 @@ public class KeyguardViewMediator implements CoreStartable,
// Handled in StatusBarDisableFlagsInteractor.
if (!KeyguardWmStateRefactor.isEnabled()) {
- try {
- mStatusBarService.disableForUser(flags, mStatusBarDisableToken,
- mContext.getPackageName(),
- mSelectedUserInteractor.getSelectedUserId());
- } catch (RemoteException e) {
- Log.d(TAG, "Failed to set disable flags: " + flags, e);
- }
+ statusBarServiceDisableForUser(flags, "Failed to set disable flags: ");
}
}
}
}
+ private void statusBarServiceDisableForUser(int flags, String loggingContext) {
+ Runnable runnable = () -> {
+ try {
+ mStatusBarService.disableForUser(flags, mStatusBarDisableToken,
+ mContext.getPackageName(),
+ mSelectedUserInteractor.getSelectedUserId());
+ } catch (RemoteException e) {
+ Log.d(TAG, loggingContext + " " + flags, e);
+ }
+ };
+ if (com.android.systemui.Flags.bouncerUiRevamp()) {
+ mUiBgExecutor.execute(runnable);
+ } else {
+ runnable.run();
+ }
+ }
+
/**
* Handle message sent by {@link #resetStateLocked}
* @see #RESET
@@ -4099,12 +4104,23 @@ public class KeyguardViewMediator implements CoreStartable,
|| aodShowing != mAodShowing || forceCallbacks;
mShowing = showing;
mAodShowing = aodShowing;
- if (notifyDefaultDisplayCallbacks) {
- notifyDefaultDisplayCallbacks(showing);
- }
- if (updateActivityLockScreenState) {
- updateActivityLockScreenState(showing, aodShowing, reason);
+
+ if (KeyguardWmReorderAtmsCalls.isEnabled()) {
+ if (updateActivityLockScreenState) {
+ updateActivityLockScreenState(showing, aodShowing, reason);
+ }
+ if (notifyDefaultDisplayCallbacks) {
+ notifyDefaultDisplayCallbacks(showing);
+ }
+ } else {
+ if (notifyDefaultDisplayCallbacks) {
+ notifyDefaultDisplayCallbacks(showing);
+ }
+ if (updateActivityLockScreenState) {
+ updateActivityLockScreenState(showing, aodShowing, reason);
+ }
}
+
}
private void notifyDefaultDisplayCallbacks(boolean showing) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWmReorderAtmsCalls.kt b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWmReorderAtmsCalls.kt
new file mode 100644
index 000000000000..7ac52813ff71
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWmReorderAtmsCalls.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyguard
+
+import com.android.systemui.Flags
+import com.android.systemui.flags.FlagToken
+import com.android.systemui.flags.RefactorFlagUtils
+
+/** Helper for reading or using the keyguard wm state refactor flag state. */
+@Suppress("NOTHING_TO_INLINE")
+object KeyguardWmReorderAtmsCalls {
+ /** The aconfig flag name */
+ const val FLAG_NAME = Flags.FLAG_KEYGUARD_WM_REORDER_ATMS_CALLS
+
+ /** A token used for dependency declaration */
+ val token: FlagToken
+ get() = FlagToken(FLAG_NAME, isEnabled)
+
+ /** Is the refactor enabled */
+ @JvmStatic
+ inline val isEnabled
+ get() = Flags.keyguardWmReorderAtmsCalls()
+
+ /**
+ * Called to ensure code is only run when the flag is enabled. This protects users from the
+ * unintended behaviors caused by accidentally running new logic, while also crashing on an eng
+ * build to ensure that the refactor author catches issues in testing.
+ */
+ @JvmStatic
+ inline fun isUnexpectedlyInLegacyMode() =
+ RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME)
+
+ /**
+ * Called to ensure code is only run when the flag is disabled. This will throw an exception if
+ * the flag is enabled to ensure that the refactor author catches issues in testing.
+ */
+ @JvmStatic
+ inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME)
+}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt
index f8c7a86687dd..f4e804ac5abf 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt
@@ -24,6 +24,7 @@ import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.KeyguardWmStateRefactor
@@ -62,6 +63,7 @@ constructor(
override val internalTransitionInteractor: InternalKeyguardTransitionInteractor,
transitionInteractor: KeyguardTransitionInteractor,
@Background private val scope: CoroutineScope,
+ @Application private val applicationScope: CoroutineScope,
@Background bgDispatcher: CoroutineDispatcher,
@Main mainDispatcher: CoroutineDispatcher,
keyguardInteractor: KeyguardInteractor,
@@ -175,7 +177,7 @@ constructor(
private fun listenForLockscreenToPrimaryBouncerDragging() {
if (SceneContainerFlag.isEnabled) return
var transitionId: UUID? = null
- scope.launch("$TAG#listenForLockscreenToPrimaryBouncerDragging") {
+ applicationScope.launch("$TAG#listenForLockscreenToPrimaryBouncerDragging") {
shadeRepository.legacyShadeExpansion.collect { shadeExpansion ->
val statusBarState = keyguardInteractor.statusBarState.value
val isKeyguardUnlocked = keyguardInteractor.isKeyguardDismissible.value
@@ -204,7 +206,7 @@ constructor(
id,
// This maps the shadeExpansion to a much faster curve, to match
// the existing logic
- 1f - MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, shadeExpansion),
+ 1f - MathUtils.constrainedMap(0f, 1f, 0.88f, 1f, shadeExpansion),
nextState,
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissInteractor.kt
index 0a4022ad4de8..e6f8406726f0 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissInteractor.kt
@@ -159,7 +159,10 @@ constructor(
if (alternateBouncerInteractor.canShowAlternateBouncer.value) {
alternateBouncerInteractor.forceShow()
} else {
- primaryBouncerInteractor.show(true)
+ primaryBouncerInteractor.show(
+ true,
+ "KeyguardDismissInteractor#dismissKeyguardWithCallback",
+ )
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt
index 7977000ed5c8..2d5ff61a5015 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt
@@ -19,7 +19,6 @@ import android.app.StatusBarManager
import android.graphics.Point
import android.util.Log
import android.util.MathUtils
-import com.android.app.animation.Interpolators
import com.android.systemui.bouncer.data.repository.KeyguardBouncerRepository
import com.android.systemui.common.shared.model.NotificationContainerBounds
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
@@ -371,9 +370,11 @@ constructor(
currentKeyguardState == LOCKSCREEN &&
legacyShadeExpansion != 1f
) {
- emit(MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, legacyShadeExpansion))
+ emit(MathUtils.constrainedMap(0f, 1f, 0.82f, 1f, legacyShadeExpansion))
} else if (
- (legacyShadeExpansion == 0f || legacyShadeExpansion == 1f) && !onGlanceableHub
+ !onGlanceableHub &&
+ isKeyguardDismissible &&
+ (legacyShadeExpansion == 0f || legacyShadeExpansion == 1f)
) {
// Resets alpha state
emit(1f)
@@ -401,15 +402,7 @@ constructor(
// 0f and 1f need to be ignored in the legacy shade expansion. These can
// flip arbitrarily as the legacy shade is reset, and would cause the
// translation value to jump around unexpectedly.
- emit(
- MathUtils.lerp(
- translationDistance,
- 0,
- Interpolators.FAST_OUT_LINEAR_IN.getInterpolation(
- legacyShadeExpansion
- ),
- )
- )
+ emit(MathUtils.lerp(translationDistance, 0, legacyShadeExpansion))
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt
index 6d9b276031e9..ced96e93d87d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt
@@ -136,7 +136,10 @@ constructor(
return true
}
StatusBarState.KEYGUARD -> {
- statusBarKeyguardViewManager.showPrimaryBouncer(true)
+ statusBarKeyguardViewManager.showPrimaryBouncer(
+ true,
+ "KeyguardKeyEventInteractor#collapseShadeLockedOrShowPrimaryBouncer",
+ )
return true
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractor.kt
index 68d595ebf0b6..b4e9d8296a74 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/WindowManagerLockscreenVisibilityInteractor.kt
@@ -196,39 +196,50 @@ constructor(
.distinctUntilChanged()
}
- private val lockscreenVisibilityWithScenes =
- combine(
- sceneInteractor.get().transitionState.flatMapLatestConflated {
- when (it) {
- is Idle -> {
- when (it.currentScene) {
- in keyguardContent -> flowOf(true)
- in nonKeyguardContent -> flowOf(false)
- in keyguardAgnosticContent -> isDeviceNotEnteredDirectly
- else ->
- throw IllegalStateException("Unknown scene: ${it.currentScene}")
- }
- }
- is Transition -> {
- when {
- it.isTransitioningSets(from = keyguardContent) -> flowOf(true)
- it.isTransitioningSets(from = nonKeyguardContent) -> flowOf(false)
- it.isTransitioningSets(from = keyguardAgnosticContent) ->
- isDeviceNotEnteredDirectly
- else ->
- throw IllegalStateException(
- "Unknown content: ${it.fromContent}"
- )
+ private val lockscreenVisibilityWithScenes: Flow<Boolean> =
+ // The scene container visibility into account as that will be forced to false when the
+ // device isn't yet provisioned (e.g. still in the setup wizard).
+ sceneInteractor.get().isVisible.flatMapLatestConflated { isVisible ->
+ if (isVisible) {
+ combine(
+ sceneInteractor.get().transitionState.flatMapLatestConflated {
+ when (it) {
+ is Idle ->
+ when (it.currentScene) {
+ in keyguardContent -> flowOf(true)
+ in nonKeyguardContent -> flowOf(false)
+ in keyguardAgnosticContent -> isDeviceNotEnteredDirectly
+ else ->
+ throw IllegalStateException(
+ "Unknown scene: ${it.currentScene}"
+ )
+ }
+ is Transition ->
+ when {
+ it.isTransitioningSets(from = keyguardContent) ->
+ flowOf(true)
+ it.isTransitioningSets(from = nonKeyguardContent) ->
+ flowOf(false)
+ it.isTransitioningSets(from = keyguardAgnosticContent) ->
+ isDeviceNotEnteredDirectly
+ else ->
+ throw IllegalStateException(
+ "Unknown content: ${it.fromContent}"
+ )
+ }
}
- }
+ },
+ wakeToGoneInteractor.canWakeDirectlyToGone,
+ ::Pair,
+ )
+ .map { (lockscreenVisibilityByTransitionState, canWakeDirectlyToGone) ->
+ lockscreenVisibilityByTransitionState && !canWakeDirectlyToGone
}
- },
- wakeToGoneInteractor.canWakeDirectlyToGone,
- ::Pair,
- )
- .map { (lockscreenVisibilityByTransitionState, canWakeDirectlyToGone) ->
- lockscreenVisibilityByTransitionState && !canWakeDirectlyToGone
+ } else {
+ // Lockscreen is never visible when the scene container is invisible.
+ flowOf(false)
}
+ }
private val lockscreenVisibilityLegacy =
combine(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt
index 70a827d5e45b..1ea47ec670af 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt
@@ -39,6 +39,7 @@ import com.android.systemui.plugins.FalsingManager
import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.util.kotlin.DisposableHandles
+import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle
@@ -56,6 +57,7 @@ object DeviceEntryIconViewBinder {
@JvmStatic
fun bind(
applicationScope: CoroutineScope,
+ mainImmediateDispatcher: CoroutineDispatcher,
view: DeviceEntryIconView,
viewModel: DeviceEntryIconViewModel,
fgViewModel: DeviceEntryForegroundViewModel,
@@ -96,6 +98,32 @@ object DeviceEntryIconViewBinder {
}
disposables +=
+ view.repeatWhenAttached(mainImmediateDispatcher) {
+ repeatOnLifecycle(Lifecycle.State.CREATED) {
+ launch("$TAG#viewModel.useBackgroundProtection") {
+ viewModel.useBackgroundProtection.collect { useBackgroundProtection ->
+ if (useBackgroundProtection) {
+ bgView.visibility = View.VISIBLE
+ } else {
+ bgView.visibility = View.GONE
+ }
+ }
+ }
+ launch("$TAG#viewModel.burnInOffsets") {
+ viewModel.burnInOffsets.collect { burnInOffsets ->
+ view.translationX = burnInOffsets.x.toFloat()
+ view.translationY = burnInOffsets.y.toFloat()
+ view.aodFpDrawable.progress = burnInOffsets.progress
+ }
+ }
+
+ launch("$TAG#viewModel.deviceEntryViewAlpha") {
+ viewModel.deviceEntryViewAlpha.collect { alpha -> view.alpha = alpha }
+ }
+ }
+ }
+
+ disposables +=
view.repeatWhenAttached {
// Repeat on CREATED so that the view will always observe the entire
// GONE => AOD transition (even though the view may not be visible until the middle
@@ -152,26 +180,6 @@ object DeviceEntryIconViewBinder {
}
}
}
- launch("$TAG#viewModel.useBackgroundProtection") {
- viewModel.useBackgroundProtection.collect { useBackgroundProtection ->
- if (useBackgroundProtection) {
- bgView.visibility = View.VISIBLE
- } else {
- bgView.visibility = View.GONE
- }
- }
- }
- launch("$TAG#viewModel.burnInOffsets") {
- viewModel.burnInOffsets.collect { burnInOffsets ->
- view.translationX = burnInOffsets.x.toFloat()
- view.translationY = burnInOffsets.y.toFloat()
- view.aodFpDrawable.progress = burnInOffsets.progress
- }
- }
-
- launch("$TAG#viewModel.deviceEntryViewAlpha") {
- viewModel.deviceEntryViewAlpha.collect { alpha -> view.alpha = alpha }
- }
}
}
@@ -212,7 +220,7 @@ object DeviceEntryIconViewBinder {
}
disposables +=
- bgView.repeatWhenAttached {
+ bgView.repeatWhenAttached(mainImmediateDispatcher) {
repeatOnLifecycle(Lifecycle.State.CREATED) {
launch("$TAG#bgViewModel.alpha") {
bgViewModel.alpha.collect { alpha -> bgView.alpha = alpha }
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt
index aeb327035c79..60460bf68c12 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt
@@ -135,7 +135,10 @@ object KeyguardRootViewBinder {
} else if (
event.action == MotionEvent.ACTION_UP && !event.isTouchscreenSource()
) {
- statusBarKeyguardViewManager?.showBouncer(true)
+ statusBarKeyguardViewManager?.showBouncer(
+ true,
+ "KeyguardRootViewBinder: click on lockscreen",
+ )
consumed = true
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySection.kt
index 58d482b8a66f..9c8f04b419fb 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySection.kt
@@ -28,6 +28,7 @@ import androidx.constraintlayout.widget.ConstraintSet
import com.android.systemui.biometrics.AuthController
import com.android.systemui.customization.R as customR
import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.shared.model.KeyguardSection
@@ -48,6 +49,7 @@ import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.VibratorHelper
import dagger.Lazy
import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle
@@ -56,6 +58,7 @@ class DefaultDeviceEntrySection
@Inject
constructor(
@Application private val applicationScope: CoroutineScope,
+ @Main private val mainDispatcher: CoroutineDispatcher,
private val authController: AuthController,
private val windowManager: WindowManager,
@ShadeDisplayAware private val context: Context,
@@ -91,6 +94,7 @@ constructor(
disposableHandle =
DeviceEntryIconViewBinder.bind(
applicationScope,
+ mainDispatcher,
it,
deviceEntryIconViewModel.get(),
deviceEntryForegroundViewModel.get(),
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerUdfpsIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerUdfpsIconViewModel.kt
index 9038922466df..803e2c0b0f96 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerUdfpsIconViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerUdfpsIconViewModel.kt
@@ -106,7 +106,10 @@ constructor(
}
fun onTapped() {
- statusBarKeyguardViewManager.showPrimaryBouncer(/* scrimmed */ true)
+ statusBarKeyguardViewManager.showPrimaryBouncer(
+ /* scrimmed */ true,
+ "AlternateBouncerUdfpsIconViewModel#onTapped",
+ )
}
val bgColor: Flow<Int> = deviceEntryBackgroundViewModel.color
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModel.kt
index cff651114c93..45f43bb484c8 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerViewModel.kt
@@ -47,7 +47,9 @@ constructor(
/** Reports the alternate bouncer visible state if the scene container flag is enabled. */
val isVisible: Flow<Boolean> =
- alternateBouncerInteractor.get().isVisible.onEach { SceneContainerFlag.unsafeAssertInNewMode() }
+ alternateBouncerInteractor.get().isVisible.onEach {
+ SceneContainerFlag.unsafeAssertInNewMode()
+ }
/** Progress to a fully transitioned alternate bouncer. 1f represents fully transitioned. */
val transitionToAlternateBouncerProgress: Flow<Float> =
@@ -63,7 +65,10 @@ constructor(
transitionToAlternateBouncerProgress.map { it == 1f }.distinctUntilChanged()
fun onTapped() {
- statusBarKeyguardViewManager.showPrimaryBouncer(/* scrimmed */ true)
+ statusBarKeyguardViewManager.showPrimaryBouncer(
+ /* scrimmed */ true,
+ "AlternateBouncerViewModel#onTapped",
+ )
}
fun onRemovedFromWindow() {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt
index 13cd5839e1c8..9b4bd67f227e 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt
@@ -257,7 +257,9 @@ constructor(
if (SceneContainerFlag.isEnabled) {
deviceEntryInteractor.attemptDeviceEntry()
} else {
- keyguardViewController.get().showPrimaryBouncer(/* scrim */ true)
+ keyguardViewController
+ .get()
+ .showPrimaryBouncer(/* scrim */ true, "DeviceEntryIconViewModel#onUserInteraction")
}
deviceEntrySourceInteractor.attemptEnterDeviceFromDeviceEntryIcon()
}
diff --git a/packages/SystemUI/src/com/android/systemui/model/SceneContainerPlugin.kt b/packages/SystemUI/src/com/android/systemui/model/SceneContainerPlugin.kt
index 4559a7aea1a2..7b3f4c61088b 100644
--- a/packages/SystemUI/src/com/android/systemui/model/SceneContainerPlugin.kt
+++ b/packages/SystemUI/src/com/android/systemui/model/SceneContainerPlugin.kt
@@ -79,6 +79,7 @@ constructor(
SceneContainerPluginState(
scene = idleState.currentScene,
overlays = idleState.currentOverlays,
+ isVisible = sceneInteractor.get().isVisible.value,
invisibleDueToOcclusion = invisibleDueToOcclusion,
)
)
@@ -100,12 +101,17 @@ constructor(
mapOf<Long, (SceneContainerPluginState) -> Boolean>(
SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE to
{
- it.scene != Scenes.Gone || it.overlays.isNotEmpty()
+ when {
+ !it.isVisible -> false
+ it.scene != Scenes.Gone -> true
+ it.overlays.isNotEmpty() -> true
+ else -> false
+ }
},
SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED to
{
when {
- it.invisibleDueToOcclusion -> false
+ !it.isVisible -> false
it.scene == Scenes.Lockscreen -> true
it.scene == Scenes.Shade -> true
Overlays.NotificationsShade in it.overlays -> true
@@ -114,19 +120,23 @@ constructor(
},
SYSUI_STATE_QUICK_SETTINGS_EXPANDED to
{
- it.scene == Scenes.QuickSettings ||
- Overlays.QuickSettingsShade in it.overlays
+ when {
+ !it.isVisible -> false
+ it.scene == Scenes.QuickSettings -> true
+ Overlays.QuickSettingsShade in it.overlays -> true
+ else -> false
+ }
},
- SYSUI_STATE_BOUNCER_SHOWING to { Overlays.Bouncer in it.overlays },
+ SYSUI_STATE_BOUNCER_SHOWING to { it.isVisible && Overlays.Bouncer in it.overlays },
SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING to
{
- it.scene == Scenes.Lockscreen && !it.invisibleDueToOcclusion
+ it.isVisible && it.scene == Scenes.Lockscreen
},
SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED to
{
it.scene == Scenes.Lockscreen && it.invisibleDueToOcclusion
},
- SYSUI_STATE_COMMUNAL_HUB_SHOWING to { it.scene == Scenes.Communal },
+ SYSUI_STATE_COMMUNAL_HUB_SHOWING to { it.isVisible && it.scene == Scenes.Communal },
)
}
@@ -134,5 +144,6 @@ constructor(
val scene: SceneKey,
val overlays: Set<OverlayKey>,
val invisibleDueToOcclusion: Boolean,
+ val isVisible: Boolean,
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/model/SysUiStateExt.kt b/packages/SystemUI/src/com/android/systemui/model/SysUiStateExt.kt
index 1e18f24c9e65..195535669c7e 100644
--- a/packages/SystemUI/src/com/android/systemui/model/SysUiStateExt.kt
+++ b/packages/SystemUI/src/com/android/systemui/model/SysUiStateExt.kt
@@ -16,8 +16,6 @@
package com.android.systemui.model
-import com.android.systemui.dagger.qualifiers.DisplayId
-
/**
* In-bulk updates multiple flag values and commits the update.
*
@@ -32,16 +30,8 @@ import com.android.systemui.dagger.qualifiers.DisplayId
* SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING to (sceneKey == Scenes.Lockscreen),
* )
* ```
- *
- * You can inject [displayId] by injecting it using:
- * ```
- * @DisplayId private val displayId: Int`,
- * ```
*/
-fun SysUiState.updateFlags(
- @DisplayId displayId: Int,
- vararg flagValuePairs: Pair<Long, Boolean>,
-) {
+fun SysUiState.updateFlags(vararg flagValuePairs: Pair<Long, Boolean>) {
flagValuePairs.forEach { (flag, enabled) -> setFlag(flag, enabled) }
- commitUpdate(displayId)
+ commitUpdate()
}
diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt
index 8dc27bf4ac3e..080940169e46 100644
--- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt
+++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt
@@ -86,7 +86,10 @@ constructor(
*/
private fun initializeKeyGestureEventHandler() {
if (useKeyGestureEventHandler()) {
- inputManager.registerKeyGestureEventHandler(callbacks)
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES),
+ callbacks,
+ )
}
}
@@ -156,11 +159,8 @@ constructor(
controller.updateNoteTaskForCurrentUserAndManagedProfiles()
}
- override fun handleKeyGestureEvent(
- event: KeyGestureEvent,
- focusedToken: IBinder?,
- ): Boolean {
- return this@NoteTaskInitializer.handleKeyGestureEvent(event)
+ override fun handleKeyGestureEvent(event: KeyGestureEvent, focusedToken: IBinder?) {
+ this@NoteTaskInitializer.handleKeyGestureEvent(event)
}
}
@@ -202,23 +202,19 @@ constructor(
return !isMultiPress && !isLongPress
}
- private fun handleKeyGestureEvent(event: KeyGestureEvent): Boolean {
- // This method is on input hot path and should be kept lightweight. Shift all complex
- // processing onto background executor wherever possible.
+ private fun handleKeyGestureEvent(event: KeyGestureEvent) {
if (event.keyGestureType != KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES) {
- return false
+ return
}
debugLog {
"handleKeyGestureEvent: Received OPEN_NOTES gesture event from keycodes: " +
event.keycodes.contentToString()
}
if (event.keycodes.size == 1 && event.keycodes[0] == KEYCODE_STYLUS_BUTTON_TAIL) {
- debugLog { "Note task triggered by stylus tail button" }
backgroundExecutor.execute { controller.showNoteTask(TAIL_BUTTON) }
- return true
+ } else {
+ backgroundExecutor.execute { controller.showNoteTask(KEYBOARD_SHORTCUT) }
}
- backgroundExecutor.execute { controller.showNoteTask(KEYBOARD_SHORTCUT) }
- return true
}
companion object {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt
index 405ce8a8e5e0..005c8b26b0d8 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt
@@ -35,7 +35,6 @@ import androidx.compose.ui.draganddrop.mimeTypes
import androidx.compose.ui.draganddrop.toAndroidDragEvent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.IntRect
-import androidx.compose.ui.unit.center
import androidx.compose.ui.unit.toRect
import com.android.systemui.qs.panels.shared.model.SizedTile
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
@@ -44,6 +43,7 @@ import com.android.systemui.qs.pipeline.shared.TileSpec
/** Holds the [TileSpec] of the tile being moved and receives drag and drop events. */
interface DragAndDropState {
val draggedCell: SizedTile<EditTileViewModel>?
+ val isDraggedCellRemovable: Boolean
val draggedPosition: Offset
val dragInProgress: Boolean
val dragType: DragType?
@@ -76,7 +76,7 @@ enum class DragType {
@Composable
fun Modifier.dragAndDropRemoveZone(
dragAndDropState: DragAndDropState,
- onDrop: (TileSpec) -> Unit,
+ onDrop: (TileSpec, removalEnabled: Boolean) -> Unit,
): Modifier {
val target =
remember(dragAndDropState) {
@@ -87,13 +87,15 @@ fun Modifier.dragAndDropRemoveZone(
override fun onDrop(event: DragAndDropEvent): Boolean {
return dragAndDropState.draggedCell?.let {
- onDrop(it.tile.tileSpec)
+ onDrop(it.tile.tileSpec, dragAndDropState.isDraggedCellRemovable)
dragAndDropState.onDrop()
true
} ?: false
}
override fun onEntered(event: DragAndDropEvent) {
+ if (!dragAndDropState.isDraggedCellRemovable) return
+
dragAndDropState.movedOutOfBounds()
}
}
@@ -168,10 +170,10 @@ private fun DragAndDropEvent.toOffset(): Offset {
}
private fun insertAfter(item: LazyGridItemInfo, offset: Offset): Boolean {
- // We want to insert the tile after the target if we're aiming at the right side of a large tile
+ // We want to insert the tile after the target if we're aiming at the end of a large tile
// TODO(ostonge): Verify this behavior in RTL
- val itemCenter = item.offset + item.size.center
- return item.span != 1 && offset.x > itemCenter.x
+ val itemCenter = item.offset.x + item.size.width * .75
+ return item.span != 1 && offset.x > itemCenter
}
@OptIn(ExperimentalFoundationApi::class)
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
index 868855840922..70f1674acd3b 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
@@ -25,6 +25,7 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.geometry.Offset
import com.android.systemui.qs.panels.shared.model.SizedTile
+import com.android.systemui.qs.panels.ui.compose.selection.PlacementEvent
import com.android.systemui.qs.panels.ui.model.GridCell
import com.android.systemui.qs.panels.ui.model.TileGridCell
import com.android.systemui.qs.panels.ui.model.toGridCells
@@ -60,6 +61,11 @@ class EditTileListState(
override var dragType by mutableStateOf<DragType?>(null)
private set
+ // A dragged cell can be removed if it was added in the drag movement OR if it's marked as
+ // removable
+ override val isDraggedCellRemovable: Boolean
+ get() = dragType == DragType.Add || draggedCell?.tile?.isRemovable ?: false
+
override val dragInProgress: Boolean
get() = draggedCell != null
@@ -76,10 +82,16 @@ class EditTileListState(
return _tiles.indexOfFirst { it is TileGridCell && it.tile.tileSpec == tileSpec }
}
+ fun isRemovable(tileSpec: TileSpec): Boolean {
+ return _tiles.find {
+ it is TileGridCell && it.tile.tileSpec == tileSpec && it.tile.isRemovable
+ } != null
+ }
+
/** Resize the tile corresponding to the [TileSpec] to [toIcon] */
fun resizeTile(tileSpec: TileSpec, toIcon: Boolean) {
val fromIndex = indexOf(tileSpec)
- if (fromIndex != -1) {
+ if (fromIndex != INVALID_INDEX) {
val cell = _tiles[fromIndex] as TileGridCell
if (cell.isIcon == toIcon) return
@@ -97,9 +109,6 @@ class EditTileListState(
override fun onStarted(cell: SizedTile<EditTileViewModel>, dragType: DragType) {
draggedCell = cell
this.dragType = dragType
-
- // Add spacers to the grid to indicate where the user can move a tile
- regenerateGrid()
}
override fun onTargeting(target: Int, insertAfter: Boolean) {
@@ -111,7 +120,7 @@ class EditTileListState(
}
val insertionIndex = if (insertAfter) target + 1 else target
- if (fromIndex != -1) {
+ if (fromIndex != INVALID_INDEX) {
val cell = _tiles.removeAt(fromIndex)
regenerateGrid()
_tiles.add(insertionIndex.coerceIn(0, _tiles.size), cell)
@@ -149,6 +158,43 @@ class EditTileListState(
regenerateGrid()
}
+ /**
+ * Return the appropriate index to move the tile to for the placement [event]
+ *
+ * The grid includes spacers. As a result, indexes from the grid need to be translated to the
+ * corresponding index from [currentTileSpecs].
+ */
+ fun targetIndexForPlacement(event: PlacementEvent): Int {
+ val currentTileSpecs = tileSpecs()
+ return when (event) {
+ is PlacementEvent.PlaceToTileSpec -> {
+ currentTileSpecs.indexOf(event.targetSpec)
+ }
+ is PlacementEvent.PlaceToIndex -> {
+ if (event.targetIndex >= _tiles.size) {
+ currentTileSpecs.size
+ } else if (event.targetIndex <= 0) {
+ 0
+ } else {
+ // The index may point to a spacer, so first find the first tile located
+ // after index, then use its position as a target
+ val targetTile =
+ _tiles.subList(event.targetIndex, _tiles.size).firstOrNull {
+ it is TileGridCell
+ } as? TileGridCell
+
+ if (targetTile == null) {
+ currentTileSpecs.size
+ } else {
+ val targetIndex = currentTileSpecs.indexOf(targetTile.tile.tileSpec)
+ val fromIndex = currentTileSpecs.indexOf(event.movingSpec)
+ if (fromIndex < targetIndex) targetIndex - 1 else targetIndex
+ }
+ }
+ }
+ }
+ }
+
/** Regenerate the list of [GridCell] with their new potential rows */
private fun regenerateGrid() {
_tiles.filterIsInstance<TileGridCell>().toGridCells(columns).let {
@@ -170,4 +216,8 @@ class EditTileListState(
_tiles.addAll(it)
}
}
+
+ companion object {
+ const val INVALID_INDEX = -1
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt
index 46f05d0ac895..f8eaa6c3bcfb 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/EditTile.kt
@@ -19,6 +19,7 @@
package com.android.systemui.qs.panels.ui.compose.infinitegrid
import androidx.compose.animation.AnimatedContent
+import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateDpAsState
@@ -34,6 +35,7 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.clipScrollableContainer
import androidx.compose.foundation.gestures.Orientation
+import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
@@ -78,6 +80,7 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
@@ -96,6 +99,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.isSpecified
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.onGloballyPositioned
@@ -125,6 +129,7 @@ import com.android.systemui.qs.panels.shared.model.SizedTileImpl
import com.android.systemui.qs.panels.ui.compose.DragAndDropState
import com.android.systemui.qs.panels.ui.compose.DragType
import com.android.systemui.qs.panels.ui.compose.EditTileListState
+import com.android.systemui.qs.panels.ui.compose.EditTileListState.Companion.INVALID_INDEX
import com.android.systemui.qs.panels.ui.compose.dragAndDropRemoveZone
import com.android.systemui.qs.panels.ui.compose.dragAndDropTileList
import com.android.systemui.qs.panels.ui.compose.dragAndDropTileSource
@@ -152,7 +157,6 @@ import com.android.systemui.qs.panels.ui.model.AvailableTileGridCell
import com.android.systemui.qs.panels.ui.model.GridCell
import com.android.systemui.qs.panels.ui.model.SpacerGridCell
import com.android.systemui.qs.panels.ui.model.TileGridCell
-import com.android.systemui.qs.panels.ui.viewmodel.AvailableEditActions
import com.android.systemui.qs.panels.ui.viewmodel.BounceableTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
@@ -161,7 +165,6 @@ import com.android.systemui.res.R
import kotlin.math.abs
import kotlin.math.roundToInt
import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
object TileType
@@ -225,7 +228,7 @@ fun DefaultEditTileGrid(
columns: Int,
largeTilesSpan: Int,
modifier: Modifier,
- onAddTile: (TileSpec) -> Unit,
+ onAddTile: (TileSpec, Int) -> Unit,
onRemoveTile: (TileSpec) -> Unit,
onSetTiles: (List<TileSpec>) -> Unit,
onResize: (TileSpec, toIcon: Boolean) -> Unit,
@@ -243,6 +246,15 @@ fun DefaultEditTileGrid(
null
}
+ LaunchedEffect(selectionState.placementEvent) {
+ selectionState.placementEvent?.let { event ->
+ listState
+ .targetIndexForPlacement(event)
+ .takeIf { it != INVALID_INDEX }
+ ?.let { onAddTile(event.movingSpec, it) }
+ }
+ }
+
Scaffold(
containerColor = Color.Transparent,
topBar = { EditModeTopBar(onStopEditing = onStopEditing, onReset = reset) },
@@ -272,29 +284,23 @@ fun DefaultEditTileGrid(
.padding(top = innerPadding.calculateTopPadding())
.clipScrollableContainer(Orientation.Vertical)
.verticalScroll(scrollState)
- .dragAndDropRemoveZone(listState, onRemoveTile),
+ .dragAndDropRemoveZone(listState) { spec, removalEnabled ->
+ if (removalEnabled) {
+ // If removal is enabled, remove the tile
+ onRemoveTile(spec)
+ } else {
+ // Otherwise submit the new tile ordering
+ onSetTiles(listState.tileSpecs())
+ selectionState.select(spec)
+ }
+ },
) {
- AnimatedContent(
- targetState = listState.dragInProgress || selectionState.selected,
- label = "QSEditHeader",
- contentAlignment = Alignment.Center,
+ CurrentTilesGridHeader(
+ listState,
+ selectionState,
+ onRemoveTile,
modifier = Modifier.fillMaxWidth().heightIn(min = 48.dp),
- ) { showRemoveTarget ->
- EditGridHeader {
- if (showRemoveTarget) {
- RemoveTileTarget {
- selectionState.selection?.let {
- selectionState.unSelect()
- onRemoveTile(it)
- }
- }
- } else {
- EditGridCenteredText(
- text = stringResource(id = R.string.drag_to_rearrange_tiles)
- )
- }
- }
- }
+ )
CurrentTilesGrid(
listState,
@@ -315,7 +321,7 @@ fun DefaultEditTileGrid(
// Using the fully qualified name here as a workaround for AnimatedVisibility
// not being available from a Box
androidx.compose.animation.AnimatedVisibility(
- visible = !listState.dragInProgress,
+ visible = !listState.dragInProgress && !selectionState.placementEnabled,
enter = fadeIn(),
exit = fadeOut(),
) {
@@ -340,7 +346,7 @@ fun DefaultEditTileGrid(
availableTiles,
selectionState,
columns,
- onAddTile,
+ { onAddTile(it, listState.tileSpecs().size) }, // Add to the end
listState,
)
}
@@ -398,6 +404,76 @@ private fun AutoScrollGrid(
}
}
+private enum class EditModeHeaderState {
+ Remove,
+ Place,
+ Idle,
+}
+
+@Composable
+private fun rememberEditModeState(
+ listState: EditTileListState,
+ selectionState: MutableSelectionState,
+): State<EditModeHeaderState> {
+ val editGridHeaderState = remember { mutableStateOf(EditModeHeaderState.Idle) }
+ LaunchedEffect(
+ listState.dragInProgress,
+ selectionState.selected,
+ selectionState.placementEnabled,
+ ) {
+ val canRemove =
+ listState.isDraggedCellRemovable ||
+ selectionState.selection?.let { listState.isRemovable(it) } ?: false
+
+ editGridHeaderState.value =
+ when {
+ selectionState.placementEnabled -> EditModeHeaderState.Place
+ canRemove -> EditModeHeaderState.Remove
+ else -> EditModeHeaderState.Idle
+ }
+ }
+
+ return editGridHeaderState
+}
+
+@Composable
+private fun CurrentTilesGridHeader(
+ listState: EditTileListState,
+ selectionState: MutableSelectionState,
+ onRemoveTile: (TileSpec) -> Unit,
+ modifier: Modifier = Modifier,
+) {
+ val editGridHeaderState by rememberEditModeState(listState, selectionState)
+
+ AnimatedContent(
+ targetState = editGridHeaderState,
+ label = "QSEditHeader",
+ contentAlignment = Alignment.Center,
+ modifier = modifier,
+ ) { state ->
+ EditGridHeader {
+ when (state) {
+ EditModeHeaderState.Remove -> {
+ RemoveTileTarget {
+ selectionState.selection?.let {
+ selectionState.unSelect()
+ onRemoveTile(it)
+ }
+ }
+ }
+ EditModeHeaderState.Place -> {
+ EditGridCenteredText(text = stringResource(id = R.string.tap_to_position_tile))
+ }
+ EditModeHeaderState.Idle -> {
+ EditGridCenteredText(
+ text = stringResource(id = R.string.drag_to_rearrange_tiles)
+ )
+ }
+ }
+ }
+ }
+}
+
@Composable
private fun EditGridHeader(
modifier: Modifier = Modifier,
@@ -484,8 +560,14 @@ private fun CurrentTilesGrid(
}
.testTag(CURRENT_TILES_GRID_TEST_TAG),
) {
- EditTiles(cells, listState, selectionState, coroutineScope, largeTilesSpan, onRemoveTile) {
- resizingOperation ->
+ EditTiles(
+ cells,
+ listState,
+ selectionState,
+ coroutineScope,
+ largeTilesSpan,
+ onRemoveTile = onRemoveTile,
+ ) { resizingOperation ->
when (resizingOperation) {
is TemporaryResizeOperation -> {
currentListState.resizeTile(resizingOperation.spec, resizingOperation.toIcon)
@@ -585,6 +667,7 @@ private fun GridCell.key(index: Int): Any {
* @param selectionState the [MutableSelectionState] for this grid
* @param coroutineScope the [CoroutineScope] to be used for the tiles
* @param largeTilesSpan the width used for large tiles
+ * @param onRemoveTile the callback when a tile is removed from this grid
* @param onResize the callback when a tile has a new [ResizeOperation]
*/
fun LazyGridScope.EditTiles(
@@ -628,12 +711,33 @@ fun LazyGridScope.EditTiles(
modifier = Modifier.animateItem(),
)
}
- is SpacerGridCell -> SpacerGridCell()
+ is SpacerGridCell ->
+ SpacerGridCell(
+ Modifier.pointerInput(Unit) {
+ detectTapGestures(onTap = { selectionState.onTap(index) })
+ }
+ )
}
}
}
@Composable
+private fun rememberTileState(
+ tile: EditTileViewModel,
+ selectionState: MutableSelectionState,
+): State<TileState> {
+ val tileState = remember { mutableStateOf(TileState.None) }
+ val canShowRemovalBadge = tile.isRemovable
+
+ LaunchedEffect(selectionState.selection, selectionState.placementEnabled, canShowRemovalBadge) {
+ tileState.value =
+ selectionState.tileStateFor(tile.tileSpec, tileState.value, canShowRemovalBadge)
+ }
+
+ return tileState
+}
+
+@Composable
private fun TileGridCell(
cell: TileGridCell,
index: Int,
@@ -646,29 +750,7 @@ private fun TileGridCell(
modifier: Modifier = Modifier,
) {
val stateDescription = stringResource(id = R.string.accessibility_qs_edit_position, index + 1)
- val canShowRemovalBadge = cell.tile.availableEditActions.contains(AvailableEditActions.REMOVE)
- var tileState by remember { mutableStateOf(TileState.None) }
-
- LaunchedEffect(selectionState.selection, canShowRemovalBadge) {
- tileState =
- when {
- selectionState.selection == cell.tile.tileSpec -> {
- if (tileState == TileState.None && canShowRemovalBadge) {
- // The tile decoration is None if a tile is newly composed OR the removal
- // badge can't be shown.
- // For newly composed and selected tiles, such as dragged tiles or moved
- // tiles from resizing, introduce a short delay. This avoids clipping issues
- // on the border and resizing handle, as well as letting the selection
- // animation play correctly.
- delay(250)
- }
- TileState.Selected
- }
- canShowRemovalBadge -> TileState.Removable
- else -> TileState.None
- }
- }
-
+ val tileState by rememberTileState(cell.tile, selectionState)
val resizingState = rememberResizingState(cell.tile.tileSpec, cell.isIcon)
val progress: () -> Float = {
if (tileState == TileState.Selected) {
@@ -696,12 +778,16 @@ private fun TileGridCell(
with(LocalDensity.current) { (largeTilesSpan - 1) * TileArrangementPadding.roundToPx() }
val colors = EditModeTileDefaults.editTileColors()
val toggleSizeLabel = stringResource(R.string.accessibility_qs_edit_toggle_tile_size_action)
- val clickLabel =
+ val togglePlacementModeLabel =
+ stringResource(R.string.accessibility_qs_edit_toggle_placement_mode)
+ val decorationClickLabel =
when (tileState) {
- TileState.None -> null
TileState.Removable ->
stringResource(id = R.string.accessibility_qs_edit_remove_tile_action)
TileState.Selected -> toggleSizeLabel
+ TileState.None,
+ TileState.Placeable,
+ TileState.GreyedOut -> null
}
InteractiveTileContainer(
tileState = tileState,
@@ -720,8 +806,13 @@ private fun TileGridCell(
coroutineScope.launch { resizingState.toggleCurrentValue() }
}
},
- onClickLabel = clickLabel,
+ onClickLabel = decorationClickLabel,
) {
+ val placeableColor = MaterialTheme.colorScheme.primary.copy(alpha = .4f)
+ val backgroundColor by
+ animateColorAsState(
+ if (tileState == TileState.Placeable) placeableColor else colors.background
+ )
Box(
modifier
.fillMaxSize()
@@ -734,7 +825,11 @@ private fun TileGridCell(
CustomAccessibilityAction(toggleSizeLabel) {
onResize(FinalResizeOperation(cell.tile.tileSpec, !cell.isIcon))
true
- }
+ },
+ CustomAccessibilityAction(togglePlacementModeLabel) {
+ selectionState.togglePlacementMode(cell.tile.tileSpec)
+ true
+ },
)
}
.selectableTile(cell.tile.tileSpec, selectionState)
@@ -744,9 +839,14 @@ private fun TileGridCell(
DragType.Move,
selectionState::unSelect,
)
- .tileBackground(colors.background)
+ .tileBackground { backgroundColor }
) {
- EditTile(tile = cell.tile, state = resizingState, progress = progress)
+ EditTile(
+ tile = cell.tile,
+ tileState = tileState,
+ state = resizingState,
+ progress = progress,
+ )
}
}
}
@@ -791,7 +891,7 @@ private fun AvailableTileGridCell(
} else {
Modifier
}
- Box(draggableModifier.fillMaxSize().tileBackground(colors.background)) {
+ Box(draggableModifier.fillMaxSize().tileBackground { colors.background }) {
// Icon
SmallTileContent(
iconProvider = { cell.tile.icon },
@@ -834,11 +934,13 @@ private fun SpacerGridCell(modifier: Modifier = Modifier) {
@Composable
fun EditTile(
tile: EditTileViewModel,
+ tileState: TileState,
state: ResizingState,
progress: () -> Float,
colors: TileColors = EditModeTileDefaults.editTileColors(),
) {
val iconSizeDiff = CommonTileDefaults.IconSize - CommonTileDefaults.LargeTileIconSize
+ val alpha by animateFloatAsState(if (tileState == TileState.GreyedOut) .4f else 1f)
Row(
horizontalArrangement = spacedBy(6.dp),
verticalAlignment = Alignment.CenterVertically,
@@ -871,7 +973,8 @@ fun EditTile(
placeable.place(startPadding.roundToInt(), 0)
}
}
- .largeTilePadding(),
+ .largeTilePadding()
+ .graphicsLayer { this.alpha = alpha },
) {
// Icon
Box(Modifier.size(ToggleTargetSize)) {
@@ -889,7 +992,7 @@ fun EditTile(
label = tile.label.text,
secondaryLabel = tile.appName?.text,
colors = colors,
- modifier = Modifier.weight(1f).graphicsLayer { alpha = progress() },
+ modifier = Modifier.weight(1f).graphicsLayer { this.alpha = progress() },
)
}
}
@@ -908,9 +1011,9 @@ private fun MeasureScope.iconHorizontalCenter(containerSize: Int): Float {
CommonTileDefaults.TileStartPadding.toPx()
}
-private fun Modifier.tileBackground(color: Color): Modifier {
+private fun Modifier.tileBackground(color: () -> Color): Modifier {
// Clip tile contents from overflowing past the tile
- return clip(RoundedCornerShape(InactiveCornerRadius)).drawBehind { drawRect(color) }
+ return clip(RoundedCornerShape(InactiveCornerRadius)).drawBehind { drawRect(color()) }
}
private object EditModeTileDefaults {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt
index 984343a45797..233af548fff2 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/infinitegrid/InfiniteGridLayout.kt
@@ -42,7 +42,6 @@ import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModel
import com.android.systemui.qs.panels.ui.viewmodel.InfiniteGridViewModel
import com.android.systemui.qs.panels.ui.viewmodel.TileViewModel
-import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractor.Companion.POSITION_AT_END
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.ui.ElementKeys.toElementKey
import com.android.systemui.res.R
@@ -171,7 +170,7 @@ constructor(
otherTiles = otherTiles,
columns = columns,
modifier = modifier,
- onAddTile = { onAddTile(it, POSITION_AT_END) },
+ onAddTile = onAddTile,
onRemoveTile = onRemoveTile,
onSetTiles = onSetTiles,
onResize = iconTilesViewModel::resize,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt
index 3dfde86bf8d9..50b29557683d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/MutableSelectionState.kt
@@ -16,15 +16,17 @@
package com.android.systemui.qs.panels.ui.compose.selection
-import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
+import com.android.systemui.common.ui.compose.gestures.detectEagerTapGestures
import com.android.systemui.qs.pipeline.shared.TileSpec
+import kotlinx.coroutines.delay
/** Creates the state of the current selected tile that is remembered across compositions. */
@Composable
@@ -38,6 +40,17 @@ class MutableSelectionState {
var selection by mutableStateOf<TileSpec?>(null)
private set
+ /**
+ * Whether the current selection is in placement mode or not.
+ *
+ * A tile in placement mode can be positioned by tapping at the desired location in the grid.
+ */
+ var placementEnabled by mutableStateOf(false)
+ private set
+
+ /** Latest event from coming from placement mode. */
+ var placementEvent by mutableStateOf<PlacementEvent?>(null)
+
val selected: Boolean
get() = selection != null
@@ -47,37 +60,122 @@ class MutableSelectionState {
fun unSelect() {
selection = null
+ exitPlacementMode()
}
-}
-/**
- * Listens for click events to select/unselect the given [TileSpec]. Use this on current tiles as
- * they can be selected.
- */
-fun Modifier.selectableTile(
- tileSpec: TileSpec,
- selectionState: MutableSelectionState,
- onClick: () -> Unit = {},
-): Modifier {
- return pointerInput(Unit) {
- detectTapGestures(
- onTap = {
- if (selectionState.selection == tileSpec) {
- selectionState.unSelect()
- } else {
- selectionState.select(tileSpec)
+ /** Selects [tileSpec] and enable placement mode. */
+ fun enterPlacementMode(tileSpec: TileSpec) {
+ selection = tileSpec
+ placementEnabled = true
+ }
+
+ /** Disable placement mode but maintains current selection. */
+ private fun exitPlacementMode() {
+ placementEnabled = false
+ }
+
+ fun togglePlacementMode(tileSpec: TileSpec) {
+ if (placementEnabled) exitPlacementMode() else enterPlacementMode(tileSpec)
+ }
+
+ suspend fun tileStateFor(
+ tileSpec: TileSpec,
+ previousState: TileState,
+ canShowRemovalBadge: Boolean,
+ ): TileState {
+ return when {
+ placementEnabled && selection == tileSpec -> TileState.Placeable
+ placementEnabled -> TileState.GreyedOut
+ selection == tileSpec -> {
+ if (previousState == TileState.None && canShowRemovalBadge) {
+ // The tile decoration is None if a tile is newly composed OR the removal
+ // badge can't be shown.
+ // For newly composed and selected tiles, such as dragged tiles or moved
+ // tiles from resizing, introduce a short delay. This avoids clipping issues
+ // on the border and resizing handle, as well as letting the selection
+ // animation play correctly.
+ delay(250)
}
- onClick()
+ TileState.Selected
}
- )
+ canShowRemovalBadge -> TileState.Removable
+ else -> TileState.None
+ }
+ }
+
+ /**
+ * Tap callback on a tile.
+ *
+ * Tiles can be selected and placed using placement mode.
+ */
+ fun onTap(tileSpec: TileSpec) {
+ when {
+ placementEnabled && selection == tileSpec -> {
+ exitPlacementMode()
+ }
+ placementEnabled -> {
+ selection?.let { placementEvent = PlacementEvent.PlaceToTileSpec(it, tileSpec) }
+ exitPlacementMode()
+ }
+ selection == tileSpec -> {
+ unSelect()
+ }
+ else -> {
+ select(tileSpec)
+ }
+ }
+ }
+
+ /**
+ * Tap on a position.
+ *
+ * Use on grid items not associated with a [TileSpec], such as a spacer. Spacers can't be
+ * selected, but selections can be moved to their position.
+ */
+ fun onTap(index: Int) {
+ when {
+ placementEnabled -> {
+ selection?.let { placementEvent = PlacementEvent.PlaceToIndex(it, index) }
+ exitPlacementMode()
+ }
+ selected -> {
+ unSelect()
+ }
+ }
}
}
+// Not using data classes here as distinct placement events may have the same moving spec and target
+@Stable
+sealed interface PlacementEvent {
+ val movingSpec: TileSpec
+
+ /** Placement event corresponding to [movingSpec] moving to [targetSpec]'s position */
+ class PlaceToTileSpec(override val movingSpec: TileSpec, val targetSpec: TileSpec) :
+ PlacementEvent
+
+ /** Placement event corresponding to [movingSpec] moving to [targetIndex] */
+ class PlaceToIndex(override val movingSpec: TileSpec, val targetIndex: Int) : PlacementEvent
+}
+
/**
- * Listens for click events to unselect any tile. Use this on available tiles as they can't be
- * selected.
+ * Listens for click events on selectable tiles.
+ *
+ * Use this on current tiles as they can be selected.
+ *
+ * @param tileSpec the [TileSpec] of the tile this modifier is applied to
+ * @param selectionState the [MutableSelectionState] representing the grid's selection
*/
@Composable
-fun Modifier.clearSelectionTile(selectionState: MutableSelectionState): Modifier {
- return pointerInput(Unit) { detectTapGestures(onTap = { selectionState.unSelect() }) }
+fun Modifier.selectableTile(tileSpec: TileSpec, selectionState: MutableSelectionState): Modifier {
+ return pointerInput(Unit) {
+ detectEagerTapGestures(
+ doubleTapEnabled = {
+ // Double tap enabled if where not in placement mode already
+ !selectionState.placementEnabled
+ },
+ onDoubleTap = { selectionState.enterPlacementMode(tileSpec) },
+ onTap = { selectionState.onTap(tileSpec) },
+ )
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt
index 57f63c755b43..8ffc4be88e7c 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/selection/Selection.kt
@@ -17,6 +17,7 @@
package com.android.systemui.qs.panels.ui.compose.selection
import androidx.compose.animation.animateColor
+import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Transition
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.animateFloatAsState
@@ -37,9 +38,13 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
@@ -73,7 +78,9 @@ import com.android.systemui.qs.panels.ui.compose.selection.SelectionDefaults.RES
import com.android.systemui.qs.panels.ui.compose.selection.SelectionDefaults.ResizingPillHeight
import com.android.systemui.qs.panels.ui.compose.selection.SelectionDefaults.ResizingPillWidth
import com.android.systemui.qs.panels.ui.compose.selection.SelectionDefaults.SelectedBorderWidth
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.GreyedOut
import com.android.systemui.qs.panels.ui.compose.selection.TileState.None
+import com.android.systemui.qs.panels.ui.compose.selection.TileState.Placeable
import com.android.systemui.qs.panels.ui.compose.selection.TileState.Removable
import com.android.systemui.qs.panels.ui.compose.selection.TileState.Selected
import kotlin.math.cos
@@ -104,10 +111,11 @@ fun InteractiveTileContainer(
) {
val transition: Transition<TileState> = updateTransition(tileState)
val decorationColor by transition.animateColor()
- val decorationAngle by transition.animateAngle()
+ val decorationAngle by animateAngle(tileState)
val decorationSize by transition.animateSize()
val decorationOffset by transition.animateOffset()
- val decorationAlpha by transition.animateFloat { state -> if (state == None) 0f else 1f }
+ val decorationAlpha by
+ transition.animateFloat { state -> if (state == Removable || state == Selected) 1f else 0f }
val badgeIconAlpha by transition.animateFloat { state -> if (state == Removable) 1f else 0f }
val selectionBorderAlpha by
transition.animateFloat { state -> if (state == Selected) 1f else 0f }
@@ -282,27 +290,61 @@ private fun Modifier.resizable(selected: Boolean, state: ResizingState): Modifie
}
enum class TileState {
+ /** Tile is displayed as-is, no additional decoration needed. */
None,
+ /** Tile can be removed by the user. This is displayed by a badge in the upper end corner. */
Removable,
+ /**
+ * Tile is selected and resizable. One tile can be selected at a time in the grid. This is when
+ * we display the resizing handle and a highlighted border around the tile.
+ */
Selected,
+ /**
+ * Tile placeable. This state means that the grid is in placement mode and this tile is
+ * selected. It should be highlighted to stand out in the grid.
+ */
+ Placeable,
+ /**
+ * Tile is faded out. This state means that the grid is in placement mode and this tile isn't
+ * selected. It serves as a target to place the selected tile.
+ */
+ GreyedOut,
}
@Composable
private fun Transition<TileState>.animateColor(): State<Color> {
return animateColor { state ->
when (state) {
- None -> Color.Transparent
+ None,
+ GreyedOut -> Color.Transparent
Removable -> MaterialTheme.colorScheme.primaryContainer
- Selected -> MaterialTheme.colorScheme.primary
+ Selected,
+ Placeable -> MaterialTheme.colorScheme.primary
}
}
}
+/**
+ * Animate the angle of the tile decoration based on the previous state
+ *
+ * Some [TileState] don't have a visible decoration, and the angle should only animate when going
+ * between visible states.
+ */
@Composable
-private fun Transition<TileState>.animateAngle(): State<Float> {
- return animateFloat { state ->
- if (state == Removable) BADGE_ANGLE_RAD else RESIZING_PILL_ANGLE_RAD
+private fun animateAngle(tileState: TileState): State<Float> {
+ val animatable = remember { Animatable(0f) }
+ var animate by remember { mutableStateOf(false) }
+ LaunchedEffect(tileState) {
+ val targetAngle = tileState.decorationAngle()
+
+ if (targetAngle == null) {
+ animate = false
+ } else {
+ if (animate) animatable.animateTo(targetAngle) else animatable.snapTo(targetAngle)
+ animate = true
+ }
}
+ return animatable.asState()
}
@Composable
@@ -310,7 +352,9 @@ private fun Transition<TileState>.animateSize(): State<Size> {
return animateSize { state ->
with(LocalDensity.current) {
when (state) {
- None -> Size.Zero
+ None,
+ Placeable,
+ GreyedOut -> Size.Zero
Removable -> Size(BadgeSize.toPx())
Selected -> Size(ResizingPillWidth.toPx(), ResizingPillHeight.toPx())
}
@@ -323,7 +367,9 @@ private fun Transition<TileState>.animateOffset(): State<Offset> {
return animateOffset { state ->
with(LocalDensity.current) {
when (state) {
- None -> Offset.Zero
+ None,
+ Placeable,
+ GreyedOut -> Offset.Zero
Removable -> Offset(BadgeXOffset.toPx(), BadgeYOffset.toPx())
Selected -> Offset(-SelectedBorderWidth.toPx(), 0f)
}
@@ -331,6 +377,16 @@ private fun Transition<TileState>.animateOffset(): State<Offset> {
}
}
+private fun TileState.decorationAngle(): Float? {
+ return when (this) {
+ Removable -> BADGE_ANGLE_RAD
+ Selected -> RESIZING_PILL_ANGLE_RAD
+ None,
+ Placeable,
+ GreyedOut -> null // No visible decoration
+ }
+}
+
private fun Size(size: Float) = Size(size, size)
private fun offsetForAngle(angle: Float, radius: Float, center: Offset): Offset {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt
index be6ce5c5b4f4..cf325f531c38 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditTileViewModel.kt
@@ -66,6 +66,9 @@ data class EditTileViewModel(
) : CategoryAndName {
override val name
get() = label.text
+
+ val isRemovable
+ get() = availableEditActions.contains(AvailableEditActions.REMOVE)
}
enum class AvailableEditActions {
diff --git a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt
index 3ad0867192d3..06fc8610c97b 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt
@@ -33,10 +33,8 @@ import com.android.systemui.bouncer.domain.interactor.SimBouncerInteractor
import com.android.systemui.bouncer.shared.logging.BouncerUiEvent
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.classifier.FalsingCollectorActual
-import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
-import com.android.systemui.dagger.qualifiers.DisplayId
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryFaceAuthInteractor
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryHapticsInteractor
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
@@ -82,6 +80,7 @@ import com.android.systemui.util.kotlin.pairwise
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.printSection
import com.android.systemui.util.println
+import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import com.google.android.msdl.data.model.MSDLToken
import com.google.android.msdl.domain.MSDLPlayer
import dagger.Lazy
@@ -123,7 +122,6 @@ constructor(
private val bouncerInteractor: BouncerInteractor,
private val keyguardInteractor: KeyguardInteractor,
private val sysUiState: SysUiState,
- @DisplayId private val displayId: Int,
private val sceneLogger: SceneLogger,
@FalsingCollectorActual private val falsingCollector: FalsingCollector,
private val falsingManager: FalsingManager,
@@ -197,7 +195,8 @@ constructor(
return
}
- printSection("Scene state") {
+ printSection("Framework state") {
+ println("isVisible", sceneInteractor.isVisible.value)
println("currentScene", sceneInteractor.currentScene.value.debugName)
println(
"currentOverlays",
@@ -732,21 +731,26 @@ constructor(
sceneInteractor.transitionState
.mapNotNull { it as? ObservableTransitionState.Idle }
.distinctUntilChanged(),
+ sceneInteractor.isVisible,
occlusionInteractor.invisibleDueToOcclusion,
- ) { idleState, invisibleDueToOcclusion ->
+ ) { idleState, isVisible, invisibleDueToOcclusion ->
SceneContainerPlugin.SceneContainerPluginState(
scene = idleState.currentScene,
overlays = idleState.currentOverlays,
+ isVisible = isVisible,
invisibleDueToOcclusion = invisibleDueToOcclusion,
)
}
- .collect { sceneContainerPluginState ->
+ .map { sceneContainerPluginState ->
+ SceneContainerPlugin.EvaluatorByFlag.map { (flag, evaluator) ->
+ flag to evaluator(sceneContainerPluginState)
+ }
+ .toMap()
+ }
+ .distinctUntilChanged()
+ .collect { flags ->
sysUiState.updateFlags(
- displayId,
- *SceneContainerPlugin.EvaluatorByFlag.map { (flag, evaluator) ->
- flag to evaluator.invoke(sceneContainerPluginState)
- }
- .toTypedArray(),
+ *(flags.entries.map { (key, value) -> key to value }).toTypedArray()
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 24e7976011f4..b90624245cc5 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -206,6 +206,7 @@ import com.google.android.msdl.data.model.MSDLToken;
import com.google.android.msdl.domain.MSDLPlayer;
import dagger.Lazy;
+
import kotlin.Unit;
import kotlinx.coroutines.CoroutineDispatcher;
@@ -4267,7 +4268,8 @@ public final class NotificationPanelViewController implements
== AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD.getId()
|| action
== AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP.getId()) {
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true);
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true,
+ "NotificationPanelViewController#performAccessibilityAction");
return true;
}
return super.performAccessibilityAction(host, action, args);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index e44701dba87c..4daf61a895c7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -64,6 +64,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.os.SomeArgs;
+import com.android.internal.statusbar.DisableStates;
import com.android.internal.statusbar.IAddTileResultCallback;
import com.android.internal.statusbar.IStatusBar;
import com.android.internal.statusbar.IUndoMediaTransferCallback;
@@ -85,6 +86,7 @@ import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Map;
/**
* This class takes the functions from IStatusBar that come in on
@@ -184,6 +186,8 @@ public class CommandQueue extends IStatusBar.Stub implements
private static final int MSG_TOGGLE_QUICK_SETTINGS_PANEL = 82 << MSG_SHIFT;
private static final int MSG_WALLET_ACTION_LAUNCH_GESTURE = 83 << MSG_SHIFT;
private static final int MSG_DISPLAY_REMOVE_SYSTEM_DECORATIONS = 85 << MSG_SHIFT;
+ private static final int MSG_DISABLE_ALL = 86 << MSG_SHIFT;
+
public static final int FLAG_EXCLUDE_NONE = 0;
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
public static final int FLAG_EXCLUDE_RECENTS_PANEL = 1 << 1;
@@ -654,7 +658,8 @@ public class CommandQueue extends IStatusBar.Stub implements
/**
* Called to notify that disable flags are updated.
- * @see Callbacks#disable(int, int, int, boolean).
+ * @see Callbacks#disable(int, int, int, boolean)
+ * @see Callbacks#disableForAllDisplays(DisableStates)
*/
public void disable(int displayId, @DisableFlags int state1, @Disable2Flags int state2,
boolean animate) {
@@ -682,6 +687,27 @@ public class CommandQueue extends IStatusBar.Stub implements
disable(displayId, state1, state2, true);
}
+ @Override
+ public void disableForAllDisplays(DisableStates disableStates) throws RemoteException {
+ synchronized (mLock) {
+ for (Map.Entry<Integer, Pair<Integer, Integer>> displaysWithStates :
+ disableStates.displaysWithStates.entrySet()) {
+ int displayId = displaysWithStates.getKey();
+ Pair<Integer, Integer> states = displaysWithStates.getValue();
+ setDisabled(displayId, states.first, states.second);
+ }
+ mHandler.removeMessages(MSG_DISABLE_ALL);
+ Message msg = mHandler.obtainMessage(MSG_DISABLE_ALL, disableStates);
+ if (Looper.myLooper() == mHandler.getLooper()) {
+ // If its the right looper execute immediately so hides can be handled quickly.
+ mHandler.handleMessage(msg);
+ msg.recycle();
+ } else {
+ msg.sendToTarget();
+ }
+ }
+ }
+
/**
* Apply current disable flags by {@link CommandQueue#disable(int, int, int, boolean)}.
*
@@ -1552,6 +1578,21 @@ public class CommandQueue extends IStatusBar.Stub implements
args.argi4 != 0 /* animate */);
}
break;
+ case MSG_DISABLE_ALL:
+ DisableStates disableStates = (DisableStates) msg.obj;
+ boolean animate = disableStates.animate;
+ Map<Integer, Pair<Integer, Integer>> displaysWithDisableStates =
+ disableStates.displaysWithStates;
+ for (Map.Entry<Integer, Pair<Integer, Integer>> displayWithDisableStates :
+ displaysWithDisableStates.entrySet()) {
+ int displayId = displayWithDisableStates.getKey();
+ Pair<Integer, Integer> states = displayWithDisableStates.getValue();
+ for (int i = 0; i < mCallbacks.size(); i++) {
+ mCallbacks.get(i).disable(displayId, states.first, states.second,
+ animate);
+ }
+ }
+ break;
case MSG_EXPAND_NOTIFICATIONS:
for (int i = 0; i < mCallbacks.size(); i++) {
mCallbacks.get(i).animateExpandNotificationsPanel();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index dfadf74c71b1..bef3c691cb4d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -2686,30 +2686,58 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
}
/**
+ * Whether to allow dismissal with the whole-row translation animation.
+ *
+ * If true, either animation is permissible.
+ * If false, usingRTX behavior is forbidden, only clipping animation should be used.
+ *
+ * Usually either is OK, except for promoted notifications, where we always need to
+ * dismiss with content clipping/partial translation animation instead, so that we
+ * can show the demotion options.
+ * @return
+ */
+ private boolean allowDismissUsingRowTranslationX() {
+ if (Flags.permissionHelperInlineUiRichOngoing()) {
+ return !isPromotedOngoing();
+ } else {
+ // Don't change behavior unless the flag is on.
+ return true;
+ }
+ }
+
+ /**
* Set the dismiss behavior of the view.
*
* @param usingRowTranslationX {@code true} if the view should translate using regular
* translationX, otherwise the contents will be
* translated.
+ * @param forceUpdateChildren {@code true} to force initialization, {@code false} if lazy
+ * behavior is OK.
*/
@Override
- public void setDismissUsingRowTranslationX(boolean usingRowTranslationX) {
- if (usingRowTranslationX != mDismissUsingRowTranslationX) {
+ public void setDismissUsingRowTranslationX(boolean usingRowTranslationX,
+ boolean forceUpdateChildren) {
+ // Before updating dismiss behavior, make sure this is an allowable configuration for this
+ // notification.
+ usingRowTranslationX = usingRowTranslationX && allowDismissUsingRowTranslationX();
+
+ if (forceUpdateChildren || (usingRowTranslationX != mDismissUsingRowTranslationX)) {
// In case we were already transitioning, let's switch over!
float previousTranslation = getTranslation();
if (previousTranslation != 0) {
setTranslation(0);
}
- super.setDismissUsingRowTranslationX(usingRowTranslationX);
+ super.setDismissUsingRowTranslationX(usingRowTranslationX, forceUpdateChildren);
if (previousTranslation != 0) {
setTranslation(previousTranslation);
}
+
if (mChildrenContainer != null) {
List<ExpandableNotificationRow> notificationChildren =
mChildrenContainer.getAttachedChildren();
for (int i = 0; i < notificationChildren.size(); i++) {
ExpandableNotificationRow child = notificationChildren.get(i);
- child.setDismissUsingRowTranslationX(usingRowTranslationX);
+ child.setDismissUsingRowTranslationX(usingRowTranslationX, forceUpdateChildren);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java
index 80cf818e985f..6c990df5d05e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java
@@ -292,7 +292,8 @@ public abstract class ExpandableOutlineView extends ExpandableView {
* translationX, otherwise the contents will be
* translated.
*/
- public void setDismissUsingRowTranslationX(boolean usingRowTranslationX) {
+ public void setDismissUsingRowTranslationX(boolean usingRowTranslationX,
+ boolean forceUpdateChildren) {
mDismissUsingRowTranslationX = usingRowTranslationX;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
index cdb78d99538b..f4e01bf718d9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
@@ -29,6 +29,7 @@ import android.content.pm.ShortcutManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
+import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -309,6 +310,7 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
});
View gutsView = item.getGutsView();
+
try {
if (gutsView instanceof NotificationSnooze) {
initializeSnoozeView(row, (NotificationSnooze) gutsView);
@@ -322,6 +324,8 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
(PartialConversationInfo) gutsView);
} else if (gutsView instanceof FeedbackInfo) {
initializeFeedbackInfo(row, (FeedbackInfo) gutsView);
+ } else if (gutsView instanceof PromotedPermissionGutsContent) {
+ initializeDemoteView(row, (PromotedPermissionGutsContent) gutsView);
}
return true;
} catch (Exception e) {
@@ -351,6 +355,31 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
}
/**
+ * Sets up the {@link NotificationSnooze} inside the notification row's guts.
+ *
+ * @param row view to set up the guts for
+ * @param demoteGuts view to set up/bind within {@code row}
+ */
+ private void initializeDemoteView(
+ final ExpandableNotificationRow row,
+ PromotedPermissionGutsContent demoteGuts) {
+ StatusBarNotification sbn = row.getEntry().getSbn();
+ demoteGuts.setStatusBarNotification(sbn);
+ demoteGuts.setOnDemoteAction(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ // TODO(b/391661009): Signal AutomaticPromotionCoordinator here
+ mNotificationManager.setCanBePromoted(
+ sbn.getPackageName(), sbn.getUid(), false, true);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Couldn't revoke live update permission", e);
+ }
+ }
+ });
+ }
+
+ /**
* Sets up the {@link FeedbackInfo} inside the notification row's guts.
*
* @param row view to set up the guts for
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java
index c03dc279888f..f494a4ce40dd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java
@@ -272,6 +272,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
} else if (personNotifType >= PeopleNotificationIdentifier.TYPE_FULL_PERSON) {
mInfoItem = createConversationItem(mContext);
} else if (android.app.Flags.uiRichOngoing()
+ && android.app.Flags.apiRichOngoing()
&& Flags.permissionHelperUiRichOngoing()
&& sbn.getNotification().isPromotedOngoing()) {
mInfoItem = createPromotedItem(mContext);
@@ -284,6 +285,15 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
}
mRightMenuItems.add(mInfoItem);
mRightMenuItems.add(mFeedbackItem);
+ boolean isPromotedOngoing = NotificationBundleUi.isEnabled()
+ ? mParent.getEntryAdapter().isPromotedOngoing()
+ : mParent.getEntryLegacy().isPromotedOngoing();
+ if (android.app.Flags.uiRichOngoing() && Flags.permissionHelperInlineUiRichOngoing()
+ && isPromotedOngoing) {
+ mRightMenuItems.add(createDemoteItem(mContext));
+ }
+
+
mLeftMenuItems.addAll(mRightMenuItems);
populateMenuViews();
@@ -305,15 +315,19 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
} else {
mMenuContainer = new FrameLayout(mContext);
}
+
final int showDismissSetting = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.SHOW_NEW_NOTIF_DISMISS, /* default = */ 1);
final boolean newFlowHideShelf = showDismissSetting == 1;
- if (newFlowHideShelf) {
- return;
- }
- List<MenuItem> menuItems = mOnLeft ? mLeftMenuItems : mRightMenuItems;
- for (int i = 0; i < menuItems.size(); i++) {
- addMenuView(menuItems.get(i), mMenuContainer);
+
+ // Populate menu items if we are using the new permission helper (U+) or if we are using
+ // the very old dismiss setting (SC-).
+ // TODO: SHOW_NEW_NOTIF_DISMISS==0 case can likely be removed.
+ if (Flags.permissionHelperInlineUiRichOngoing() || !newFlowHideShelf) {
+ List<MenuItem> menuItems = mOnLeft ? mLeftMenuItems : mRightMenuItems;
+ for (int i = 0; i < menuItems.size(); i++) {
+ addMenuView(menuItems.get(i), mMenuContainer);
+ }
}
}
@@ -679,6 +693,15 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
return snooze;
}
+ static MenuItem createDemoteItem(Context context) {
+ PromotedPermissionGutsContent demoteContent =
+ (PromotedPermissionGutsContent) LayoutInflater.from(context).inflate(
+ R.layout.promoted_permission_guts, null, false);
+ MenuItem info = new NotificationMenuItem(context, null, demoteContent,
+ R.drawable.unpin_icon);
+ return info;
+ }
+
static NotificationMenuItem createConversationItem(Context context) {
Resources res = context.getResources();
String infoDescription = res.getString(R.string.notification_menu_gear_description);
@@ -686,7 +709,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
(NotificationConversationInfo) LayoutInflater.from(context).inflate(
R.layout.notification_conversation_info, null, false);
return new NotificationMenuItem(context, infoDescription, infoContent,
- R.drawable.ic_settings);
+ NotificationMenuItem.OMIT_FROM_SWIPE_MENU);
}
static NotificationMenuItem createPromotedItem(Context context) {
@@ -696,7 +719,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
(PromotedNotificationInfo) LayoutInflater.from(context).inflate(
R.layout.promoted_notification_info, null, false);
return new NotificationMenuItem(context, infoDescription, infoContent,
- R.drawable.ic_settings);
+ NotificationMenuItem.OMIT_FROM_SWIPE_MENU);
}
static NotificationMenuItem createPartialConversationItem(Context context) {
@@ -706,7 +729,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
(PartialConversationInfo) LayoutInflater.from(context).inflate(
R.layout.partial_conversation_info, null, false);
return new NotificationMenuItem(context, infoDescription, infoContent,
- R.drawable.ic_settings);
+ NotificationMenuItem.OMIT_FROM_SWIPE_MENU);
}
static NotificationMenuItem createInfoItem(Context context) {
@@ -718,14 +741,14 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
NotificationInfo infoContent = (NotificationInfo) LayoutInflater.from(context).inflate(
layoutId, null, false);
return new NotificationMenuItem(context, infoDescription, infoContent,
- R.drawable.ic_settings);
+ NotificationMenuItem.OMIT_FROM_SWIPE_MENU);
}
static MenuItem createFeedbackItem(Context context) {
FeedbackInfo feedbackContent = (FeedbackInfo) LayoutInflater.from(context).inflate(
R.layout.feedback_info, null, false);
MenuItem info = new NotificationMenuItem(context, null, feedbackContent,
- -1 /*don't show in slow swipe menu */);
+ NotificationMenuItem.OMIT_FROM_SWIPE_MENU);
return info;
}
@@ -762,6 +785,10 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
@Override
public boolean isWithinSnapMenuThreshold() {
+ if (getSpaceForMenu() == 0) {
+ // don't snap open if there are no items
+ return false;
+ }
float translation = getTranslation();
float snapBackThreshold = getSnapBackThreshold();
float targetRight = getDismissThreshold();
@@ -803,6 +830,10 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
}
public static class NotificationMenuItem implements MenuItem {
+
+ // Constant signaling that this MenuItem should not appear in slow swipe.
+ public static final int OMIT_FROM_SWIPE_MENU = -1;
+
View mMenuView;
GutsContent mGutsContent;
String mContentDescription;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedNotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedNotificationInfo.java
index 01ee788f7fd7..769f0b5a4fa4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedNotificationInfo.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedNotificationInfo.java
@@ -80,6 +80,7 @@ public class PromotedNotificationInfo extends NotificationInfo {
assistantFeedbackController, metricsLogger, onCloseClick);
mNotificationManager = iNotificationManager;
+
mPackageDemotionInteractor = packageDemotionInteractor;
bindDemote(entry.getSbn(), pkg);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedPermissionGutsContent.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedPermissionGutsContent.java
new file mode 100644
index 000000000000..222a1f4d8adf
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PromotedPermissionGutsContent.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.notification.row;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.service.notification.StatusBarNotification;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.systemui.res.R;
+
+/**
+ * This GutsContent shows an explanatory interstitial telling the user they've just revoked this
+ * app's permission to post Promoted/Live notifications.
+ * If the guts are dismissed without further action, the revocation is committed.
+ * If the user hits undo, the permission is not revoked.
+ */
+public class PromotedPermissionGutsContent extends LinearLayout
+ implements NotificationGuts.GutsContent, View.OnClickListener {
+
+ private static final String TAG = "SnoozyPromotedGuts";
+
+ private NotificationGuts mGutsContainer;
+ private StatusBarNotification mSbn;
+
+ private TextView mUndoButton;
+
+ private MetricsLogger mMetricsLogger = new MetricsLogger();
+ private OnClickListener mDemoteAction;
+
+ public PromotedPermissionGutsContent(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mUndoButton = (TextView) findViewById(R.id.undo);
+ mUndoButton.setOnClickListener(this);
+ mUndoButton.setContentDescription(
+ getContext().getString(R.string.snooze_undo_content_description));
+
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ dispatchConfigurationChanged(getResources().getConfiguration());
+ }
+
+ /**
+ * Update the content description of the snooze view based on the snooze option and whether the
+ * snooze options are expanded or not.
+ * For example, this will be something like "Collapsed\u2029Snooze for 1 hour". The paragraph
+ * separator is added to introduce a break in speech, to match what TalkBack does by default
+ * when you e.g. press on a notification.
+ */
+ private void updateContentDescription() {
+ //
+ }
+
+
+ @Override
+ public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
+ if (super.performAccessibilityActionInternal(action, arguments)) {
+ return true;
+ }
+ if (action == R.id.action_snooze_undo) {
+ undoDemote(mUndoButton);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * TODO docs
+ * @param sbn
+ */
+ public void setStatusBarNotification(StatusBarNotification sbn) {
+ mSbn = sbn;
+ TextView demoteExplanation = (TextView) findViewById(R.id.demote_explain);
+ demoteExplanation.setText(mContext.getResources().getString(R.string.demote_explain_text,
+ mSbn.getPackageName()));
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (mGutsContainer != null) {
+ mGutsContainer.resetFalsingCheck();
+ }
+ final int id = v.getId();
+ if (id == R.id.undo) {
+ undoDemote(v);
+ }
+
+ }
+
+ private void undoDemote(View v) {
+ // Don't commit the demote action, instead log the undo and dismiss the view.
+ mGutsContainer.closeControls(v, /* save= */ false);
+ }
+
+ @Override
+ public int getActualHeight() {
+ return getHeight();
+ }
+
+ @Override
+ public boolean willBeRemoved() {
+ return false;
+ }
+
+ @Override
+ public View getContentView() {
+ return this;
+ }
+
+ @Override
+ public void setGutsParent(NotificationGuts guts) {
+ mGutsContainer = guts;
+ }
+
+ @Override
+ public boolean handleCloseControls(boolean save, boolean force) {
+ if (!save) {
+ // Undo changes and let the guts handle closing the view
+ return false;
+ } else {
+ // Commit demote action.
+ mDemoteAction.onClick(this);
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isLeavebehind() {
+ return true;
+ }
+
+ @Override
+ public boolean shouldBeSavedOnClose() {
+ return true;
+ }
+
+ @Override
+ public boolean needsFalsingProtection() {
+ return false;
+ }
+
+ public void setOnDemoteAction(OnClickListener demoteAction) {
+ mDemoteAction = demoteAction;
+ }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index 9fea75048e3e..503256accff0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -3220,8 +3220,7 @@ public class NotificationStackScrollLayout
updateAnimationState(child);
updateChronometerForChild(child);
if (child instanceof ExpandableNotificationRow row) {
- row.setDismissUsingRowTranslationX(mDismissUsingRowTranslationX);
-
+ row.setDismissUsingRowTranslationX(mDismissUsingRowTranslationX, /* force= */ true);
}
}
@@ -6157,7 +6156,7 @@ public class NotificationStackScrollLayout
View child = getChildAt(i);
if (child instanceof ExpandableNotificationRow) {
((ExpandableNotificationRow) child).setDismissUsingRowTranslationX(
- dismissUsingRowTranslationX);
+ dismissUsingRowTranslationX, /* force= */ false);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
index e4e56c5de65b..8a5b22183563 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
@@ -527,7 +527,8 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
break;
case MODE_SHOW_BOUNCER:
Trace.beginSection("MODE_SHOW_BOUNCER");
- mKeyguardViewController.showPrimaryBouncer(true);
+ mKeyguardViewController.showPrimaryBouncer(true,
+ "BiometricUnlockController#MODE_SHOW_BOUNCER");
Trace.endSection();
break;
case MODE_WAKE_AND_UNLOCK_FROM_DREAM:
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
index 9d9f01b571a7..e617254fa288 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
@@ -2407,11 +2407,12 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
}
if (needsBouncer) {
- Log.d(TAG, "showBouncerOrLockScreenIfKeyguard, showingBouncer");
+ var reason = "CentralSurfacesImpl#showBouncerOrLockScreenIfKeyguard";
if (SceneContainerFlag.isEnabled()) {
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */,
+ reason);
} else {
- mStatusBarKeyguardViewManager.showBouncer(true /* scrimmed */);
+ mStatusBarKeyguardViewManager.showBouncer(true /* scrimmed */, reason);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
index f3d72027238f..d68f7df79cd5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
@@ -538,10 +538,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
private void handleBlurSupportedChanged(boolean isBlurSupported) {
this.mIsBlurSupported = isBlurSupported;
if (Flags.bouncerUiRevamp()) {
- // TODO: animate blur fallback when the bouncer is pulled up.
- for (ScrimState state : ScrimState.values()) {
- state.setDefaultScrimAlpha(getDefaultScrimAlpha(true));
- }
+ updateDefaultScrimAlphas();
if (isBlurSupported) {
ScrimState.BOUNCER_SCRIMMED.setNotifBlurRadius(mBlurConfig.getMaxBlurRadiusPx());
} else {
@@ -549,17 +546,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
}
}
if (Flags.notificationShadeBlur()) {
- float inFrontAlpha = mInFrontAlpha;
- float behindAlpha = mBehindAlpha;
- float notifAlpha = mNotificationsAlpha;
-
mState.prepare(mState);
- applyState();
- startScrimAnimation(mScrimBehind, behindAlpha);
- startScrimAnimation(mNotificationsScrim, notifAlpha);
- startScrimAnimation(mScrimInFront, inFrontAlpha);
- dispatchBackScrimState(mScrimBehind.getViewAlpha());
- } else if (Flags.bouncerUiRevamp()) {
applyAndDispatchState();
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index 8c44fe56d269..512340913de2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -669,7 +669,8 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
* show if any subsequent events are to be handled.
*/
if (!SceneContainerFlag.isEnabled() && beginShowingBouncer(event)) {
- mPrimaryBouncerInteractor.show(/* isScrimmed= */false);
+ mPrimaryBouncerInteractor.show(/* isScrimmed= */false,
+ TAG + "#onPanelExpansionChanged");
}
if (!primaryBouncerIsOrWillBeShowing()) {
@@ -714,7 +715,8 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
* Shows the notification keyguard or the bouncer depending on
* {@link #needsFullscreenBouncer()}.
*/
- protected void showBouncerOrKeyguard(boolean hideBouncerWhenShowing, boolean isFalsingReset) {
+ protected void showBouncerOrKeyguard(boolean hideBouncerWhenShowing, boolean isFalsingReset,
+ String reason) {
boolean showBouncer = needsFullscreenBouncer() && !mDozing;
if (Flags.simPinRaceConditionOnRestart()) {
showBouncer = showBouncer && !mIsSleeping;
@@ -726,11 +728,11 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
mCentralSurfaces.hideKeyguard();
mSceneInteractorLazy.get().showOverlay(
Overlays.Bouncer,
- "StatusBarKeyguardViewManager.showBouncerOrKeyguard"
+ TAG + "#showBouncerOrKeyguard"
);
} else {
if (Flags.simPinRaceConditionOnRestart()) {
- if (mPrimaryBouncerInteractor.show(/* isScrimmed= */ true)) {
+ if (mPrimaryBouncerInteractor.show(/* isScrimmed= */ true, reason)) {
mAttemptsToShowBouncer = 0;
mCentralSurfaces.hideKeyguard();
} else {
@@ -744,19 +746,19 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
+ mAttemptsToShowBouncer++);
mExecutor.executeDelayed(() ->
showBouncerOrKeyguard(hideBouncerWhenShowing,
- isFalsingReset),
+ isFalsingReset, reason),
500);
}
}
} else {
mCentralSurfaces.hideKeyguard();
- mPrimaryBouncerInteractor.show(/* isScrimmed= */ true);
+ mPrimaryBouncerInteractor.show(/* isScrimmed= */ true, reason);
}
}
} else if (!isFalsingReset) {
// Falsing resets can cause this to flicker, so don't reset in this case
Log.i(TAG, "Sim bouncer is already showing, issuing a refresh");
- mPrimaryBouncerInteractor.show(/* isScrimmed= */ true);
+ mPrimaryBouncerInteractor.show(/* isScrimmed= */ true, reason);
}
} else {
@@ -776,7 +778,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
* false when the user will be dragging it and translation should be deferred
* {@see KeyguardBouncer#show(boolean, boolean)}
*/
- public void showBouncer(boolean scrimmed) {
+ public void showBouncer(boolean scrimmed, String reason) {
if (SceneContainerFlag.isEnabled()) {
mDeviceEntryInteractorLazy.get().attemptDeviceEntry();
return;
@@ -787,7 +789,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
mAlternateBouncerInteractor.forceShow();
updateAlternateBouncerShowing(mAlternateBouncerInteractor.isVisibleState());
} else {
- showPrimaryBouncer(scrimmed);
+ showPrimaryBouncer(scrimmed, reason);
}
}
@@ -810,8 +812,10 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
*
* @param scrimmed true when the bouncer should show scrimmed, false when the user will be
* dragging it and translation should be deferred {@see KeyguardBouncer#show(boolean, boolean)}
+ * @param reason string description for what is causing the bouncer to be requested
*/
- public void showPrimaryBouncer(boolean scrimmed) {
+ @Override
+ public void showPrimaryBouncer(boolean scrimmed, String reason) {
hideAlternateBouncer(
/* updateScrim= */ false,
// When the scene framework is on, don't ever clear the pending dismiss action from
@@ -823,7 +827,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
"primary bouncer requested"
);
} else {
- mPrimaryBouncerInteractor.show(scrimmed);
+ mPrimaryBouncerInteractor.show(scrimmed, reason);
}
}
updateStates();
@@ -870,7 +874,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
);
}
- showBouncer(true);
+ showBouncer(true, TAG + "#dismissWithAction");
Trace.endSection();
return;
}
@@ -919,10 +923,11 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
if (SceneContainerFlag.isEnabled()) {
mSceneInteractorLazy.get().showOverlay(
Overlays.Bouncer,
- "StatusBarKeyguardViewManager.dismissWithAction"
+ TAG + "#dismissWithAction"
);
} else {
- mPrimaryBouncerInteractor.show(/* isScrimmed= */ true);
+ mPrimaryBouncerInteractor.show(/* isScrimmed= */ true,
+ TAG + "#dismissWithAction, afterKeyguardGone");
}
} else {
// after authentication success, run dismiss action with the option to defer
@@ -932,10 +937,11 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
if (SceneContainerFlag.isEnabled()) {
mSceneInteractorLazy.get().showOverlay(
Overlays.Bouncer,
- "StatusBarKeyguardViewManager.dismissWithAction"
+ TAG + "#dismissWithAction"
);
} else {
- mPrimaryBouncerInteractor.show(/* isScrimmed= */ true);
+ mPrimaryBouncerInteractor.show(/* isScrimmed= */ true,
+ TAG + "#dismissWithAction");
}
// bouncer will handle the dismiss action, so we no longer need to track it here
mAfterKeyguardGoneAction = null;
@@ -992,7 +998,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
}
}
} else {
- showBouncerOrKeyguard(hideBouncerWhenShowing, isFalsingReset);
+ showBouncerOrKeyguard(hideBouncerWhenShowing, isFalsingReset, "reset");
}
if (!SceneContainerFlag.isEnabled() && hideBouncerWhenShowing && isBouncerShowing()) {
hideAlternateBouncer(true);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java
index 8389aab4aac8..85fc9d4589c0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java
@@ -156,7 +156,8 @@ public class StatusBarRemoteInputCallback implements Callback, Callbacks,
if (!row.isPinned()) {
mStatusBarStateController.setLeaveOpenOnKeyguardHide(true);
}
- mStatusBarKeyguardViewManager.showBouncer(true /* scrimmed */);
+ mStatusBarKeyguardViewManager.showBouncer(true /* scrimmed */,
+ "StatusBarRemoteInputCallback#onLockedRemoteInput");
mPendingRemoteInputView = clicked;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseUserSwitcherAdapter.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseUserSwitcherAdapter.kt
index 4c6374b75f82..efab21fd9364 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseUserSwitcherAdapter.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseUserSwitcherAdapter.kt
@@ -37,7 +37,7 @@ protected constructor(
protected open val users: List<UserRecord>
get() = controller.users.filter {
(!controller.isKeyguardShowing || !it.isRestricted) &&
- (controller.isUserSwitcherEnabled || it.isCurrent)
+ (controller.isUserSwitcherEnabled || it.isCurrent || it.isSignOut)
}
init {
@@ -109,6 +109,7 @@ protected constructor(
item.isAddUser,
item.isGuest,
item.isAddSupervisedUser,
+ item.isSignOut,
isTablet,
item.isManageUsers,
)
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyLogger.kt b/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyLogger.kt
index 1cc7a3185a5d..5541c50fb650 100644
--- a/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyLogger.kt
@@ -50,7 +50,7 @@ class DisplaySwitchLatencyLogger {
onScreenTurningOnToOnDrawnMs,
onDrawnToOnScreenTurnedOnMs,
trackingResult,
- screenWakelockstatus
+ screenWakelockStatus,
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt b/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt
index 5800d5ed41c6..336e8d172ad4 100644
--- a/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt
+++ b/packages/SystemUI/src/com/android/systemui/unfold/DisplaySwitchLatencyTracker.kt
@@ -36,11 +36,11 @@ import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessModel
import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.shared.system.SysUiStatsLog
-import com.android.systemui.unfold.DisplaySwitchLatencyTracker.DisplaySwitchLatencyEvent
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.TrackingResult.CORRUPTED
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.TrackingResult.SUCCESS
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.TrackingResult.TIMED_OUT
import com.android.systemui.unfold.dagger.UnfoldSingleThreadBg
+import com.android.systemui.unfold.data.repository.ScreenTimeoutPolicyRepository
import com.android.systemui.unfold.data.repository.UnfoldTransitionStatus.TransitionStarted
import com.android.systemui.unfold.domain.interactor.UnfoldTransitionInteractor
import com.android.systemui.util.Compile
@@ -80,6 +80,7 @@ constructor(
private val context: Context,
private val deviceStateRepository: DeviceStateRepository,
private val powerInteractor: PowerInteractor,
+ private val screenTimeoutPolicyRepository: ScreenTimeoutPolicyRepository,
private val unfoldTransitionInteractor: UnfoldTransitionInteractor,
private val animationStatusRepository: AnimationStatusRepository,
private val keyguardInteractor: KeyguardInteractor,
@@ -287,7 +288,18 @@ constructor(
log { "fromFoldableDeviceState=$fromFoldableDeviceState" }
instantForTrack(TAG) { "fromFoldableDeviceState=$fromFoldableDeviceState" }
- return copy(fromFoldableDeviceState = fromFoldableDeviceState)
+ val screenTimeoutActive = screenTimeoutPolicyRepository.screenTimeoutActive.value
+ val screenWakelockStatus =
+ if (screenTimeoutActive) {
+ NO_SCREEN_WAKELOCKS
+ } else {
+ HAS_SCREEN_WAKELOCKS
+ }
+
+ return copy(
+ fromFoldableDeviceState = fromFoldableDeviceState,
+ screenWakelockStatus = screenWakelockStatus
+ )
}
private fun DisplaySwitchLatencyEvent.withAfterFields(
@@ -344,7 +356,7 @@ constructor(
val onDrawnToOnScreenTurnedOnMs: Int = VALUE_UNKNOWN,
val trackingResult: Int =
SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__TRACKING_RESULT__UNKNOWN_RESULT,
- val screenWakelockstatus: Int =
+ val screenWakelockStatus: Int =
SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_UNKNOWN,
)
@@ -372,5 +384,10 @@ constructor(
SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__FROM_FOLDABLE_DEVICE_STATE__STATE_OPENED
private const val FOLDABLE_DEVICE_STATE_FLIPPED =
SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__FROM_FOLDABLE_DEVICE_STATE__STATE_FLIPPED
+
+ private const val HAS_SCREEN_WAKELOCKS =
+ SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_HAS_SCREEN_WAKELOCKS
+ private const val NO_SCREEN_WAKELOCKS =
+ SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_NO_WAKELOCKS
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/data/repository/ScreenTimeoutPolicyRepository.kt b/packages/SystemUI/src/com/android/systemui/unfold/data/repository/ScreenTimeoutPolicyRepository.kt
new file mode 100644
index 000000000000..797939447464
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/unfold/data/repository/ScreenTimeoutPolicyRepository.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.systemui.unfold.data.repository
+
+import android.os.PowerManager
+import android.view.Display
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
+import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
+import java.util.concurrent.Executor
+import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.stateIn
+
+/** Repository to get screen timeout updates */
+@SysUISingleton
+class ScreenTimeoutPolicyRepository
+@Inject
+constructor(
+ private val powerManager: PowerManager,
+ @Background private val executor: Executor,
+ @Background private val scope: CoroutineScope,
+) {
+
+ /** Stores true if there is an active screen timeout */
+ val screenTimeoutActive: StateFlow<Boolean> =
+ conflatedCallbackFlow {
+ val listener =
+ PowerManager.ScreenTimeoutPolicyListener { screenTimeoutPolicy ->
+ trySend(screenTimeoutPolicy == PowerManager.SCREEN_TIMEOUT_ACTIVE)
+ }
+ powerManager.addScreenTimeoutPolicyListener(
+ Display.DEFAULT_DISPLAY,
+ executor,
+ listener,
+ )
+ awaitClose {
+ powerManager.removeScreenTimeoutPolicyListener(
+ Display.DEFAULT_DISPLAY,
+ listener,
+ )
+ }
+ }
+ .stateIn(scope, started = SharingStarted.Eagerly, initialValue = true)
+}
diff --git a/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt b/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt
index d4fb5634bd1d..e16a51a6f6fa 100644
--- a/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt
@@ -42,6 +42,8 @@ data class UserRecord(
@JvmField val isSwitchToEnabled: Boolean = false,
/** Whether this record represents an option to add another supervised user to the device. */
@JvmField val isAddSupervisedUser: Boolean = false,
+ /** Whether this record represents an option to sign out of the current user. */
+ @JvmField val isSignOut: Boolean = false,
/**
* An enforcing admin, if the user action represented by this record is disabled by the admin.
* If not disabled, this is `null`.
@@ -49,7 +51,7 @@ data class UserRecord(
@JvmField val enforcedAdmin: RestrictedLockUtils.EnforcedAdmin? = null,
/** Whether this record is to go to the Settings page to manage users. */
- @JvmField val isManageUsers: Boolean = false
+ @JvmField val isManageUsers: Boolean = false,
) {
/** Returns a new instance of [UserRecord] with its [isCurrent] set to the given value. */
fun copyWithIsCurrent(isCurrent: Boolean): UserRecord {
diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt
index 163288b25b28..b82aefc1ac1c 100644
--- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt
@@ -38,6 +38,7 @@ import com.android.internal.util.UserIcons
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Flags.switchUserOnBg
+import com.android.systemui.Flags.userSwitcherAddSignOutOption
import com.android.systemui.SystemUISecondaryUserService
import com.android.systemui.animation.Expandable
import com.android.systemui.broadcast.BroadcastDispatcher
@@ -110,6 +111,7 @@ constructor(
private val uiEventLogger: UiEventLogger,
private val userRestrictionChecker: UserRestrictionChecker,
private val processWrapper: ProcessWrapper,
+ private val userLogoutInteractor: UserLogoutInteractor,
) {
/**
* Defines interface for classes that can be notified when the state of users on the device is
@@ -242,6 +244,12 @@ constructor(
) {
add(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT)
}
+ if (
+ userSwitcherAddSignOutOption() &&
+ userLogoutInteractor.isLogoutEnabled.value
+ ) {
+ add(UserActionModel.SIGN_OUT)
+ }
}
}
.flowOn(backgroundDispatcher)
@@ -261,7 +269,8 @@ constructor(
action = it,
selectedUserId = selectedUserInfo.id,
isRestricted =
- it != UserActionModel.ENTER_GUEST_MODE &&
+ it != UserActionModel.SIGN_OUT &&
+ it != UserActionModel.ENTER_GUEST_MODE &&
it != UserActionModel.NAVIGATE_TO_USER_MANAGEMENT &&
!settings.isAddUsersFromLockscreen,
)
@@ -499,6 +508,10 @@ constructor(
Intent(Settings.ACTION_USER_SETTINGS),
/* dismissShade= */ true,
)
+ UserActionModel.SIGN_OUT -> {
+ dismissDialog()
+ applicationScope.launch { userLogoutInteractor.logOut() }
+ }
}
}
@@ -583,9 +596,10 @@ constructor(
actionType = action,
isRestricted = isRestricted,
isSwitchToEnabled =
- canSwitchUsers(selectedUserId = selectedUserId, isAction = true) &&
- // If the user is auto-created is must not be currently resetting.
- !(isGuestUserAutoCreated && isGuestUserResetting),
+ action == UserActionModel.SIGN_OUT ||
+ (canSwitchUsers(selectedUserId = selectedUserId, isAction = true) &&
+ // If the user is auto-created is must not be currently resetting.
+ !(isGuestUserAutoCreated && isGuestUserResetting)),
userRestrictionChecker = userRestrictionChecker,
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/user/legacyhelper/data/LegacyUserDataHelper.kt b/packages/SystemUI/src/com/android/systemui/user/legacyhelper/data/LegacyUserDataHelper.kt
index 80139bd6ac0c..23ca4ceda2de 100644
--- a/packages/SystemUI/src/com/android/systemui/user/legacyhelper/data/LegacyUserDataHelper.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/legacyhelper/data/LegacyUserDataHelper.kt
@@ -74,6 +74,7 @@ object LegacyUserDataHelper {
isGuest = actionType == UserActionModel.ENTER_GUEST_MODE,
isAddUser = actionType == UserActionModel.ADD_USER,
isAddSupervisedUser = actionType == UserActionModel.ADD_SUPERVISED_USER,
+ isSignOut = actionType == UserActionModel.SIGN_OUT,
isRestricted = isRestricted,
isSwitchToEnabled = isSwitchToEnabled,
enforcedAdmin =
@@ -94,6 +95,7 @@ object LegacyUserDataHelper {
record.isAddSupervisedUser -> UserActionModel.ADD_SUPERVISED_USER
record.isGuest -> UserActionModel.ENTER_GUEST_MODE
record.isManageUsers -> UserActionModel.NAVIGATE_TO_USER_MANAGEMENT
+ record.isSignOut -> UserActionModel.SIGN_OUT
else -> error("Not a known action: $record")
}
}
@@ -105,15 +107,14 @@ object LegacyUserDataHelper {
private fun getEnforcedAdmin(
context: Context,
selectedUserId: Int,
- userRestrictionChecker: UserRestrictionChecker
+ userRestrictionChecker: UserRestrictionChecker,
): EnforcedAdmin? {
val admin =
userRestrictionChecker.checkIfRestrictionEnforced(
context,
UserManager.DISALLOW_ADD_USER,
selectedUserId,
- )
- ?: return null
+ ) ?: return null
return if (
!userRestrictionChecker.hasBaseUserRestriction(
@@ -145,11 +146,6 @@ object LegacyUserDataHelper {
val unscaledOrNull = manager.getUserIcon(userInfo.id) ?: return null
val avatarSize = context.resources.getDimensionPixelSize(R.dimen.max_avatar_size)
- return Bitmap.createScaledBitmap(
- unscaledOrNull,
- avatarSize,
- avatarSize,
- /* filter= */ true,
- )
+ return Bitmap.createScaledBitmap(unscaledOrNull, avatarSize, avatarSize, /* filter= */ true)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt b/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt
index 09cef1ed64fc..e7a3c23e9119 100644
--- a/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt
@@ -41,6 +41,7 @@ object LegacyUserUiHelper {
isAddUser: Boolean,
isGuest: Boolean,
isAddSupervisedUser: Boolean,
+ isSignOut: Boolean,
isTablet: Boolean = false,
isManageUsers: Boolean,
): Int {
@@ -52,6 +53,8 @@ object LegacyUserUiHelper {
com.android.settingslib.R.drawable.ic_account_circle
} else if (isAddSupervisedUser) {
com.android.settingslib.R.drawable.ic_add_supervised_user
+ } else if (isSignOut) {
+ com.android.internal.R.drawable.ic_logout
} else if (isManageUsers) {
R.drawable.ic_manage_users
} else {
@@ -81,6 +84,7 @@ object LegacyUserUiHelper {
isGuestUserResetting = isGuestUserResetting,
isAddUser = record.isAddUser,
isAddSupervisedUser = record.isAddSupervisedUser,
+ isSignOut = record.isSignOut,
isTablet = isTablet,
isManageUsers = record.isManageUsers,
)
@@ -111,10 +115,11 @@ object LegacyUserUiHelper {
isGuestUserResetting: Boolean,
isAddUser: Boolean,
isAddSupervisedUser: Boolean,
+ isSignOut: Boolean,
isTablet: Boolean = false,
isManageUsers: Boolean,
): Int {
- check(isGuest || isAddUser || isAddSupervisedUser || isManageUsers)
+ check(isGuest || isAddUser || isAddSupervisedUser || isManageUsers || isSignOut)
return when {
isGuest && isGuestUserAutoCreated && isGuestUserResetting ->
@@ -124,6 +129,7 @@ object LegacyUserUiHelper {
isGuest -> com.android.internal.R.string.guest_name
isAddUser -> com.android.settingslib.R.string.user_add_user
isAddSupervisedUser -> R.string.add_user_supervised
+ isSignOut -> com.android.internal.R.string.global_action_logout
isManageUsers -> R.string.manage_users
else -> error("This should never happen!")
}
diff --git a/packages/SystemUI/src/com/android/systemui/user/shared/model/UserActionModel.kt b/packages/SystemUI/src/com/android/systemui/user/shared/model/UserActionModel.kt
index 823bf74dc0f0..7f67d7691bf5 100644
--- a/packages/SystemUI/src/com/android/systemui/user/shared/model/UserActionModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/shared/model/UserActionModel.kt
@@ -22,4 +22,5 @@ enum class UserActionModel {
ADD_USER,
ADD_SUPERVISED_USER,
NAVIGATE_TO_USER_MANAGEMENT,
+ SIGN_OUT,
}
diff --git a/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt b/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt
index 4089889f4b1e..2e3af1c7ad00 100644
--- a/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModel.kt
@@ -129,9 +129,7 @@ constructor(
cancelButtonClicked || executedActionFinish || userSwitched
}
- private fun toViewModel(
- model: UserModel,
- ): UserViewModel {
+ private fun toViewModel(model: UserModel): UserViewModel {
return UserViewModel(
viewKey = model.id,
name =
@@ -152,14 +150,13 @@ constructor(
)
}
- private fun toViewModel(
- model: UserActionModel,
- ): UserActionViewModel {
+ private fun toViewModel(model: UserActionModel): UserActionViewModel {
return UserActionViewModel(
viewKey = model.ordinal.toLong(),
iconResourceId =
LegacyUserUiHelper.getUserSwitcherActionIconResourceId(
isAddSupervisedUser = model == UserActionModel.ADD_SUPERVISED_USER,
+ isSignOut = model == UserActionModel.SIGN_OUT,
isAddUser = model == UserActionModel.ADD_USER,
isGuest = model == UserActionModel.ENTER_GUEST_MODE,
isManageUsers = model == UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
@@ -171,6 +168,7 @@ constructor(
isGuestUserAutoCreated = guestUserInteractor.isGuestUserAutoCreated,
isGuestUserResetting = guestUserInteractor.isGuestUserResetting,
isAddSupervisedUser = model == UserActionModel.ADD_SUPERVISED_USER,
+ isSignOut = model == UserActionModel.SIGN_OUT,
isAddUser = model == UserActionModel.ADD_USER,
isManageUsers = model == UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
isTablet = true,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityTransitionAnimatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityTransitionAnimatorTest.kt
index 60345a358bac..6cc8238f2d09 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityTransitionAnimatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityTransitionAnimatorTest.kt
@@ -249,10 +249,12 @@ class ActivityTransitionAnimatorTest : SysuiTestCase() {
var factory = controllerFactory(controller)
underTest.register(factory.cookie, factory, testScope)
assertEquals(2, testShellTransitions.remotes.size)
+ assertTrue(testShellTransitions.remotesForTakeover.isEmpty())
factory = controllerFactory(controller)
underTest.register(factory.cookie, factory, testScope)
assertEquals(4, testShellTransitions.remotes.size)
+ assertTrue(testShellTransitions.remotesForTakeover.isEmpty())
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySectionTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySectionTest.kt
index df24bff43c08..78a4fbecabe8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySectionTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultDeviceEntrySectionTest.kt
@@ -31,11 +31,13 @@ import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryBackgroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryForegroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryIconViewModel
+import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.res.R
import com.android.systemui.shade.NotificationPanelView
import com.android.systemui.statusbar.VibratorHelper
+import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
@@ -68,6 +70,7 @@ class DefaultDeviceEntrySectionTest : SysuiTestCase() {
underTest =
DefaultDeviceEntrySection(
TestScope().backgroundScope,
+ testKosmos().testDispatcher,
authController,
windowManager,
context,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt
index 8a4f1ad13b78..5596cc7ee7da 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt
@@ -38,8 +38,6 @@ import com.android.systemui.notetask.NoteTaskEntryPoint.TAIL_BUTTON
import com.android.systemui.settings.FakeUserTracker
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.util.concurrency.FakeExecutor
-import com.android.systemui.util.mockito.any
-import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.mockito.withArgCaptor
@@ -52,11 +50,14 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
+import org.mockito.Mockito.anyList
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.MockitoAnnotations.initMocks
+import org.mockito.kotlin.any
+import org.mockito.kotlin.eq
/** atest SystemUITests:NoteTaskInitializerTest */
@OptIn(InternalNoteTaskApi::class)
@@ -180,6 +181,18 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
@Test
@EnableFlags(com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER)
+ fun initialize_keyGestureTypeOpenNotes_isRegistered() {
+ val underTest = createUnderTest(isEnabled = true, bubbles = bubbles)
+ underTest.initialize()
+ verify(inputManager)
+ .registerKeyGestureEventHandler(
+ eq(listOf(KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES)),
+ any(),
+ )
+ }
+
+ @Test
+ @EnableFlags(com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER)
fun handlesShortcut_keyGestureTypeOpenNotes() {
val gestureEvent =
KeyGestureEvent.Builder()
@@ -189,12 +202,12 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
val underTest = createUnderTest(isEnabled = true, bubbles = bubbles)
underTest.initialize()
val callback = withArgCaptor {
- verify(inputManager).registerKeyGestureEventHandler(capture())
+ verify(inputManager).registerKeyGestureEventHandler(anyList(), capture())
}
- assertThat(callback.handleKeyGestureEvent(gestureEvent, null)).isTrue()
-
+ callback.handleKeyGestureEvent(gestureEvent, null)
executor.runAllReady()
+
verify(controller).showNoteTask(eq(KEYBOARD_SHORTCUT))
}
@@ -203,19 +216,19 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
fun handlesShortcut_stylusTailButton() {
val gestureEvent =
KeyGestureEvent.Builder()
- .setKeycodes(intArrayOf(KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL))
+ .setKeycodes(intArrayOf(KEYCODE_STYLUS_BUTTON_TAIL))
.setKeyGestureType(KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES)
.setAction(KeyGestureEvent.ACTION_GESTURE_COMPLETE)
.build()
val underTest = createUnderTest(isEnabled = true, bubbles = bubbles)
underTest.initialize()
val callback = withArgCaptor {
- verify(inputManager).registerKeyGestureEventHandler(capture())
+ verify(inputManager).registerKeyGestureEventHandler(anyList(), capture())
}
- assertThat(callback.handleKeyGestureEvent(gestureEvent, null)).isTrue()
-
+ callback.handleKeyGestureEvent(gestureEvent, null)
executor.runAllReady()
+
verify(controller).showNoteTask(eq(TAIL_BUTTON))
}
@@ -224,19 +237,19 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
fun ignoresUnrelatedShortcuts() {
val gestureEvent =
KeyGestureEvent.Builder()
- .setKeycodes(intArrayOf(KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL))
+ .setKeycodes(intArrayOf(KEYCODE_STYLUS_BUTTON_TAIL))
.setKeyGestureType(KeyGestureEvent.KEY_GESTURE_TYPE_HOME)
.setAction(KeyGestureEvent.ACTION_GESTURE_COMPLETE)
.build()
val underTest = createUnderTest(isEnabled = true, bubbles = bubbles)
underTest.initialize()
val callback = withArgCaptor {
- verify(inputManager).registerKeyGestureEventHandler(capture())
+ verify(inputManager).registerKeyGestureEventHandler(anyList(), capture())
}
- assertThat(callback.handleKeyGestureEvent(gestureEvent, null)).isFalse()
-
+ callback.handleKeyGestureEvent(gestureEvent, null)
executor.runAllReady()
+
verify(controller, never()).showNoteTask(any())
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropTest.kt
index 7e42ec7e83b1..1551375f6879 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropTest.kt
@@ -37,6 +37,7 @@ import com.android.systemui.common.shared.model.Icon
import com.android.systemui.qs.panels.shared.model.SizedTile
import com.android.systemui.qs.panels.shared.model.SizedTileImpl
import com.android.systemui.qs.panels.ui.compose.infinitegrid.DefaultEditTileGrid
+import com.android.systemui.qs.panels.ui.viewmodel.AvailableEditActions
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.model.TileCategory
@@ -63,7 +64,7 @@ class DragAndDropTest : SysuiTestCase() {
columns = 4,
largeTilesSpan = 4,
modifier = Modifier.fillMaxSize(),
- onAddTile = {},
+ onAddTile = { _, _ -> },
onRemoveTile = {},
onSetTiles = onSetTiles,
onResize = { _, _ -> },
@@ -84,7 +85,7 @@ class DragAndDropTest : SysuiTestCase() {
}
composeRule.waitForIdle()
- listState.onStarted(TestEditTiles[0], DragType.Add)
+ listState.onStarted(TestEditTiles[0], DragType.Move)
// Tile is being dragged, it should be replaced with a placeholder
composeRule.onNodeWithContentDescription("tileA").assertDoesNotExist()
@@ -103,6 +104,45 @@ class DragAndDropTest : SysuiTestCase() {
}
@Test
+ fun nonRemovableDraggedTile_removeHeaderShouldNotExist() {
+ val nonRemovableTile = createEditTile("tileA", isRemovable = false)
+ val listState = EditTileListState(listOf(nonRemovableTile), columns = 4, largeTilesSpan = 2)
+ composeRule.setContent { EditTileGridUnderTest(listState) {} }
+ composeRule.waitForIdle()
+
+ listState.onStarted(nonRemovableTile, DragType.Move)
+
+ // Tile is being dragged, it should be replaced with a placeholder
+ composeRule.onNodeWithContentDescription("tileA").assertDoesNotExist()
+
+ // Remove drop zone should not appear
+ composeRule.onNodeWithText("Remove").assertDoesNotExist()
+ }
+
+ @Test
+ fun droppedNonRemovableDraggedTile_shouldStayInGrid() {
+ val nonRemovableTile = createEditTile("tileA", isRemovable = false)
+ val listState = EditTileListState(listOf(nonRemovableTile), columns = 4, largeTilesSpan = 2)
+ composeRule.setContent { EditTileGridUnderTest(listState) {} }
+ composeRule.waitForIdle()
+
+ listState.onStarted(nonRemovableTile, DragType.Move)
+
+ // Tile is being dragged, it should be replaced with a placeholder
+ composeRule.onNodeWithContentDescription("tileA").assertDoesNotExist()
+
+ // Remove drop zone should not appear
+ composeRule.onNodeWithText("Remove").assertDoesNotExist()
+
+ // Drop tile outside of the grid
+ listState.movedOutOfBounds()
+ listState.onDrop()
+
+ // Tile A is still in the grid
+ composeRule.assertGridContainsExactly(CURRENT_TILES_GRID_TEST_TAG, listOf("tileA"))
+ }
+
+ @Test
fun draggedTile_shouldChangePosition() {
var tiles by mutableStateOf(TestEditTiles)
val listState = EditTileListState(tiles, columns = 4, largeTilesSpan = 2)
@@ -113,7 +153,11 @@ class DragAndDropTest : SysuiTestCase() {
}
composeRule.waitForIdle()
- listState.onStarted(TestEditTiles[0], DragType.Add)
+ listState.onStarted(TestEditTiles[0], DragType.Move)
+
+ // Remove drop zone should appear
+ composeRule.onNodeWithText("Remove").assertExists()
+
listState.onTargeting(1, false)
listState.onDrop()
@@ -141,7 +185,11 @@ class DragAndDropTest : SysuiTestCase() {
}
composeRule.waitForIdle()
- listState.onStarted(TestEditTiles[0], DragType.Add)
+ listState.onStarted(TestEditTiles[0], DragType.Move)
+
+ // Remove drop zone should appear
+ composeRule.onNodeWithText("Remove").assertExists()
+
listState.movedOutOfBounds()
listState.onDrop()
@@ -169,7 +217,11 @@ class DragAndDropTest : SysuiTestCase() {
}
composeRule.waitForIdle()
- listState.onStarted(createEditTile("tile_new"), DragType.Add)
+ listState.onStarted(createEditTile("tile_new", isRemovable = false), DragType.Add)
+
+ // Remove drop zone should appear
+ composeRule.onNodeWithText("Remove").assertExists()
+
// Insert after tileD, which is at index 4
// [ a ] [ b ] [ c ] [ empty ]
// [ tile d ] [ e ]
@@ -193,7 +245,10 @@ class DragAndDropTest : SysuiTestCase() {
private const val CURRENT_TILES_GRID_TEST_TAG = "CurrentTilesGrid"
private const val AVAILABLE_TILES_GRID_TEST_TAG = "AvailableTilesGrid"
- private fun createEditTile(tileSpec: String): SizedTile<EditTileViewModel> {
+ private fun createEditTile(
+ tileSpec: String,
+ isRemovable: Boolean = true,
+ ): SizedTile<EditTileViewModel> {
return SizedTileImpl(
EditTileViewModel(
tileSpec = TileSpec.create(tileSpec),
@@ -205,7 +260,8 @@ class DragAndDropTest : SysuiTestCase() {
label = AnnotatedString(tileSpec),
appName = null,
isCurrent = true,
- availableEditActions = emptySet(),
+ availableEditActions =
+ if (isRemovable) setOf(AvailableEditActions.REMOVE) else emptySet(),
category = TileCategory.UNKNOWN,
),
getWidth(tileSpec),
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/EditModeTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/EditModeTest.kt
index 9d4a425c678b..acb441c3765d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/EditModeTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/EditModeTest.kt
@@ -23,6 +23,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.test.doubleClick
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
@@ -30,6 +31,7 @@ import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.text.AnnotatedString
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -40,6 +42,7 @@ import com.android.systemui.common.shared.model.Icon
import com.android.systemui.qs.panels.shared.model.SizedTile
import com.android.systemui.qs.panels.shared.model.SizedTileImpl
import com.android.systemui.qs.panels.ui.compose.infinitegrid.DefaultEditTileGrid
+import com.android.systemui.qs.panels.ui.viewmodel.AvailableEditActions
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.model.TileCategory
@@ -53,8 +56,8 @@ class EditModeTest : SysuiTestCase() {
@get:Rule val composeRule = createComposeRule()
@Composable
- private fun EditTileGridUnderTest() {
- var tiles by remember { mutableStateOf(TestEditTiles) }
+ private fun EditTileGridUnderTest(sizedTiles: List<SizedTile<EditTileViewModel>>) {
+ var tiles by remember { mutableStateOf(sizedTiles) }
val (currentTiles, otherTiles) = tiles.partition { it.tile.isCurrent }
val listState = EditTileListState(currentTiles, columns = 4, largeTilesSpan = 2)
@@ -65,7 +68,7 @@ class EditModeTest : SysuiTestCase() {
columns = 4,
largeTilesSpan = 4,
modifier = Modifier.fillMaxSize(),
- onAddTile = { tiles = tiles.add(it) },
+ onAddTile = { spec, _ -> tiles = tiles.add(spec) },
onRemoveTile = { tiles = tiles.remove(it) },
onSetTiles = {},
onResize = { _, _ -> },
@@ -77,7 +80,7 @@ class EditModeTest : SysuiTestCase() {
@Test
fun clickAvailableTile_shouldAdd() {
- composeRule.setContent { EditTileGridUnderTest() }
+ composeRule.setContent { EditTileGridUnderTest(TestEditTiles) }
composeRule.waitForIdle()
composeRule.onNodeWithContentDescription("tileF").performClick() // Tap to add
@@ -93,7 +96,7 @@ class EditModeTest : SysuiTestCase() {
@Test
fun clickRemoveTarget_shouldRemoveSelection() {
- composeRule.setContent { EditTileGridUnderTest() }
+ composeRule.setContent { EditTileGridUnderTest(TestEditTiles) }
composeRule.waitForIdle()
// Selects first "tileA", i.e. the one in the current grid
@@ -110,6 +113,36 @@ class EditModeTest : SysuiTestCase() {
)
}
+ @Test
+ fun selectNonRemovableTile_removeTargetShouldHide() {
+ val nonRemovableTile = createEditTile("tileA", isRemovable = false)
+ composeRule.setContent { EditTileGridUnderTest(listOf(nonRemovableTile)) }
+ composeRule.waitForIdle()
+
+ // Selects first "tileA", i.e. the one in the current grid
+ composeRule.onAllNodesWithText("tileA").onFirst().performClick()
+
+ // Assert the remove target isn't shown
+ composeRule.onNodeWithText("Remove").assertDoesNotExist()
+ }
+
+ @Test
+ fun placementMode_shouldRepositionTile() {
+ composeRule.setContent { EditTileGridUnderTest(TestEditTiles) }
+ composeRule.waitForIdle()
+
+ // Double tap first "tileA", i.e. the one in the current grid
+ composeRule.onAllNodesWithText("tileA").onFirst().performTouchInput { doubleClick() }
+
+ // Tap on tileE to position tileA in its spot
+ composeRule.onAllNodesWithText("tileE").onFirst().performClick()
+
+ // Assert tileA moved to tileE's position
+ composeRule.assertCurrentTilesGridContainsExactly(
+ listOf("tileB", "tileC", "tileD_large", "tileE", "tileA")
+ )
+ }
+
private fun ComposeContentTestRule.assertCurrentTilesGridContainsExactly(specs: List<String>) =
assertGridContainsExactly(CURRENT_TILES_GRID_TEST_TAG, specs)
@@ -148,6 +181,7 @@ class EditModeTest : SysuiTestCase() {
private fun createEditTile(
tileSpec: String,
isCurrent: Boolean = true,
+ isRemovable: Boolean = true,
): SizedTile<EditTileViewModel> {
return SizedTileImpl(
EditTileViewModel(
@@ -160,7 +194,8 @@ class EditModeTest : SysuiTestCase() {
label = AnnotatedString(tileSpec),
appName = null,
isCurrent = isCurrent,
- availableEditActions = emptySet(),
+ availableEditActions =
+ if (isRemovable) setOf(AvailableEditActions.REMOVE) else emptySet(),
category = TileCategory.UNKNOWN,
),
getWidth(tileSpec),
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/ResizingTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/ResizingTest.kt
index 5e76000cc7f0..274c44cef949 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/ResizingTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/panels/ui/compose/ResizingTest.kt
@@ -69,7 +69,7 @@ class ResizingTest : SysuiTestCase() {
columns = 4,
largeTilesSpan = 4,
modifier = Modifier.fillMaxSize(),
- onAddTile = {},
+ onAddTile = { _, _ -> },
onRemoveTile = {},
onSetTiles = {},
onResize = onResize,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
index 2ea4e7f67b3c..bc7ab9d4fe3c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
@@ -582,7 +582,7 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
public void testIconScrollXAfterTranslationAndReset() throws Exception {
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
- group.setDismissUsingRowTranslationX(false);
+ group.setDismissUsingRowTranslationX(false, false);
group.setTranslation(50);
assertEquals(50, -group.getEntry().getIcons().getShelfIcon().getScrollX());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
index 0d99c0e8cab8..320a87e7db17 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
@@ -176,6 +176,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
private FakeKeyguardStateController mKeyguardStateController =
spy(new FakeKeyguardStateController());
private final FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
+ private final static String TEST_REASON = "reason";
@Mock
private ViewRootImpl mViewRootImpl;
@@ -272,14 +273,15 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
mStatusBarKeyguardViewManager.dismissWithAction(
action, cancelAction, false /* afterKeyguardGone */);
verify(mPrimaryBouncerInteractor).setDismissAction(eq(action), eq(cancelAction));
- verify(mPrimaryBouncerInteractor).show(eq(true));
+ verify(mPrimaryBouncerInteractor).show(eq(true),
+ eq("StatusBarKeyguardViewManager#dismissWithAction"));
}
@Test
public void showPrimaryBouncer_onlyWhenShowing() {
mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */);
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
- verify(mPrimaryBouncerInteractor, never()).show(anyBoolean());
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */, TEST_REASON);
+ verify(mPrimaryBouncerInteractor, never()).show(anyBoolean(), eq(TEST_REASON));
verify(mDeviceEntryInteractor, never()).attemptDeviceEntry();
verify(mSceneInteractor, never()).changeScene(any(), any());
}
@@ -289,8 +291,8 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */);
when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.Password);
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
- verify(mPrimaryBouncerInteractor, never()).show(anyBoolean());
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */, TEST_REASON);
+ verify(mPrimaryBouncerInteractor, never()).show(anyBoolean(), eq(TEST_REASON));
verify(mDeviceEntryInteractor, never()).attemptDeviceEntry();
verify(mSceneInteractor, never()).changeScene(any(), any());
}
@@ -298,8 +300,8 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
@Test
@DisableSceneContainer
public void showBouncer_showsTheBouncer() {
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
- verify(mPrimaryBouncerInteractor).show(eq(true));
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */, TEST_REASON);
+ verify(mPrimaryBouncerInteractor).show(eq(true), eq(TEST_REASON));
}
@Test
@@ -344,19 +346,20 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
public void onPanelExpansionChanged_showsBouncerWhenSwiping() {
mKeyguardStateController.setCanDismissLockScreen(false);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
- verify(mPrimaryBouncerInteractor).show(eq(false));
+ verify(mPrimaryBouncerInteractor).show(eq(false),
+ eq("StatusBarKeyguardViewManager#onPanelExpansionChanged"));
// But not when it's already visible
reset(mPrimaryBouncerInteractor);
when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
- verify(mPrimaryBouncerInteractor, never()).show(eq(false));
+ verify(mPrimaryBouncerInteractor, never()).show(eq(false), eq(TEST_REASON));
// Or animating away
reset(mPrimaryBouncerInteractor);
when(mPrimaryBouncerInteractor.isAnimatingAway()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
- verify(mPrimaryBouncerInteractor, never()).show(eq(false));
+ verify(mPrimaryBouncerInteractor, never()).show(eq(false), eq(TEST_REASON));
}
@Test
@@ -546,7 +549,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(true);
// WHEN showBouncer is called
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true);
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true, TEST_REASON);
// THEN alt bouncer should be hidden
verify(mAlternateBouncerInteractor).hide();
@@ -571,10 +574,10 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
// WHEN showGenericBouncer is called
final boolean scrimmed = true;
- mStatusBarKeyguardViewManager.showBouncer(scrimmed);
+ mStatusBarKeyguardViewManager.showBouncer(scrimmed, TEST_REASON);
// THEN regular bouncer is shown
- verify(mPrimaryBouncerInteractor).show(eq(scrimmed));
+ verify(mPrimaryBouncerInteractor).show(eq(scrimmed), eq(TEST_REASON));
}
@Test
@@ -835,7 +838,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(false);
// WHEN request to show primary bouncer
- mStatusBarKeyguardViewManager.showPrimaryBouncer(true);
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(true, TEST_REASON);
// THEN the scrim isn't updated from StatusBarKeyguardViewManager
verify(mCentralSurfaces, never()).updateScrimController();
@@ -847,9 +850,9 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
public void testShowBouncerOrKeyguard_needsFullScreen() {
when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.SimPin);
- mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, false);
+ mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, false, TEST_REASON);
verify(mCentralSurfaces).hideKeyguard();
- verify(mPrimaryBouncerInteractor).show(true);
+ verify(mPrimaryBouncerInteractor).show(true, TEST_REASON);
}
@Test
@@ -859,7 +862,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.SimPin);
// Returning false means unable to show the bouncer
- when(mPrimaryBouncerInteractor.show(true)).thenReturn(false);
+ when(mPrimaryBouncerInteractor.show(true, TEST_REASON)).thenReturn(false);
when(mKeyguardTransitionInteractor.getTransitionState().getValue().getTo())
.thenReturn(KeyguardState.LOCKSCREEN);
mStatusBarKeyguardViewManager.onStartedWakingUp();
@@ -868,8 +871,8 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
// Advance past reattempts
mStatusBarKeyguardViewManager.setAttemptsToShowBouncer(10);
- mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, false);
- verify(mPrimaryBouncerInteractor).show(true);
+ mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, false, TEST_REASON);
+ verify(mPrimaryBouncerInteractor).show(true, TEST_REASON);
verify(mCentralSurfaces).showKeyguard();
}
@@ -884,7 +887,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
reset(mCentralSurfaces);
reset(mPrimaryBouncerInteractor);
mStatusBarKeyguardViewManager.showBouncerOrKeyguard(
- /* hideBouncerWhenShowing= */true, false);
+ /* hideBouncerWhenShowing= */true, false, TEST_REASON);
verify(mCentralSurfaces).showKeyguard();
verify(mPrimaryBouncerInteractor).hide();
}
@@ -897,9 +900,9 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.SimPin);
when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
- mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, isFalsingReset);
+ mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, isFalsingReset, TEST_REASON);
verify(mCentralSurfaces, never()).hideKeyguard();
- verify(mPrimaryBouncerInteractor).show(true);
+ verify(mPrimaryBouncerInteractor).show(true, TEST_REASON);
}
@Test
@@ -909,24 +912,24 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.SimPin);
when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
- mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, isFalsingReset);
+ mStatusBarKeyguardViewManager.showBouncerOrKeyguard(false, isFalsingReset, TEST_REASON);
verify(mCentralSurfaces, never()).hideKeyguard();
// Do not refresh the full screen bouncer if the call is from falsing
- verify(mPrimaryBouncerInteractor, never()).show(true);
+ verify(mPrimaryBouncerInteractor, never()).show(true, TEST_REASON);
}
@Test
@EnableSceneContainer
public void showBouncer_attemptDeviceEntry() {
- mStatusBarKeyguardViewManager.showBouncer(false);
+ mStatusBarKeyguardViewManager.showBouncer(false, TEST_REASON);
verify(mDeviceEntryInteractor).attemptDeviceEntry();
}
@Test
@EnableSceneContainer
public void showPrimaryBouncer() {
- mStatusBarKeyguardViewManager.showPrimaryBouncer(false);
+ mStatusBarKeyguardViewManager.showPrimaryBouncer(false, TEST_REASON);
verify(mSceneInteractor).showOverlay(eq(Overlays.Bouncer), anyString());
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt
index d3dccb021ff8..c86ba6ccf47f 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt
@@ -18,9 +18,22 @@ package com.android.systemui
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testCase
+import com.android.systemui.kosmos.useStandardTestDispatcher
fun SysuiTestCase.testKosmos(): Kosmos = Kosmos().apply { testCase = this@testKosmos }
+/**
+ * This should not be called directly. Instead, you can use:
+ * - testKosmos() to use the default dispatcher (which will soon be unconfined, see go/thetiger)
+ * - testKosmos().useStandardTestDispatcher() to explicitly choose the standard dispatcher
+ * - testKosmos().useUnconfinedTestDispatcher() to explicitly choose the unconfined dispatcher
+ *
+ * For details, see go/thetiger
+ */
+@Deprecated("Do not call this directly. Use testKosmos() with dispatcher functions if needed.")
+fun SysuiTestCase.testKosmosLegacy(): Kosmos =
+ Kosmos().useStandardTestDispatcher().apply { testCase = this@testKosmosLegacy }
+
/** Run [f] on the main thread and return its result once completed. */
fun <T : Any> SysuiTestCase.runOnMainThreadAndWaitForIdleSync(f: () -> T): T {
lateinit var result: T
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorKosmos.kt
index 511bede7349b..41dddce77a30 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorKosmos.kt
@@ -33,6 +33,7 @@ var Kosmos.fromLockscreenTransitionInteractor by
transitionInteractor = keyguardTransitionInteractor,
internalTransitionInteractor = internalKeyguardTransitionInteractor,
scope = applicationCoroutineScope,
+ applicationScope = applicationCoroutineScope,
bgDispatcher = testDispatcher,
mainDispatcher = testDispatcher,
keyguardInteractor = keyguardInteractor,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/domain/startable/SceneContainerStartableKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/domain/startable/SceneContainerStartableKosmos.kt
index 7a9b052481cb..349e670a9af3 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/domain/startable/SceneContainerStartableKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/domain/startable/SceneContainerStartableKosmos.kt
@@ -46,7 +46,6 @@ import com.android.systemui.scene.domain.interactor.sceneContainerOcclusionInter
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.session.shared.shadeSessionStorage
import com.android.systemui.scene.shared.logger.sceneLogger
-import com.android.systemui.settings.displayTracker
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.domain.interactor.shadeModeInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor
@@ -65,7 +64,6 @@ val Kosmos.sceneContainerStartable by Fixture {
bouncerInteractor = bouncerInteractor,
keyguardInteractor = keyguardInteractor,
sysUiState = sysUiState,
- displayId = displayTracker.defaultDisplayId,
sceneLogger = sceneLogger,
falsingCollector = falsingCollector,
falsingManager = falsingManager,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt
index 1504df4ef6d0..6767300a22bc 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt
@@ -55,5 +55,6 @@ val Kosmos.userSwitcherInteractor by
uiEventLogger = uiEventLogger,
userRestrictionChecker = userRestrictionChecker,
processWrapper = processWrapper,
+ userLogoutInteractor = userLogoutInteractor,
)
}
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 69ea12d86d47..39c1fa73b7ce 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -529,14 +529,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
}
private InputManager.KeyGestureEventHandler mKeyGestureEventHandler =
- new InputManager.KeyGestureEventHandler() {
- @Override
- public boolean handleKeyGestureEvent(
- @NonNull KeyGestureEvent event,
- @Nullable IBinder focusedToken) {
- return AccessibilityManagerService.this.handleKeyGestureEvent(event);
- }
- };
+ (event, focusedToken) -> AccessibilityManagerService.this.handleKeyGestureEvent(event);
@VisibleForTesting
AccessibilityManagerService(
@@ -652,7 +645,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
new AccessibilityContentObserver(mMainHandler).register(
mContext.getContentResolver());
if (enableTalkbackAndMagnifierKeyGestures()) {
- mInputManager.registerKeyGestureEventHandler(mKeyGestureEventHandler);
+ List<Integer> supportedGestures = List.of(
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
+ KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK);
+ mInputManager.registerKeyGestureEventHandler(supportedGestures,
+ mKeyGestureEventHandler);
}
if (com.android.settingslib.flags.Flags.hearingDevicesInputRoutingControl()) {
if (mHearingDeviceNotificationController != null) {
@@ -701,13 +698,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
}
@VisibleForTesting
- boolean handleKeyGestureEvent(KeyGestureEvent event) {
+ void handleKeyGestureEvent(KeyGestureEvent event) {
final boolean complete =
event.getAction() == KeyGestureEvent.ACTION_GESTURE_COMPLETE
&& !event.isCancelled();
final int gestureType = event.getKeyGestureType();
if (!complete) {
- return false;
+ return;
}
String targetName;
@@ -718,7 +715,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
case KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK:
targetName = mContext.getString(R.string.config_defaultSelectToSpeakService);
if (targetName.isEmpty()) {
- return false;
+ return;
}
final ComponentName targetServiceComponent = TextUtils.isEmpty(targetName)
@@ -730,7 +727,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
userState.getInstalledServiceInfoLocked(targetServiceComponent);
}
if (accessibilityServiceInfo == null) {
- return false;
+ return;
}
// Skip enabling if a warning dialog is required for the feature.
@@ -740,11 +737,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
Slog.w(LOG_TAG,
"Accessibility warning is required before this service can be "
+ "activated automatically via KEY_GESTURE shortcut.");
- return false;
+ return;
}
break;
default:
- return false;
+ Slog.w(LOG_TAG, "Received a key gesture " + event
+ + " that was not registered by this handler");
+ return;
}
List<String> shortcutTargets = getAccessibilityShortcutTargets(
@@ -763,14 +762,12 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
// this will be a separate dialog that appears that requires the user to confirm
// which will resolve this race condition. For now, just require two presses the
// first time it is activated.
- return true;
+ return;
}
final int displayId = event.getDisplayId() != INVALID_DISPLAY
? event.getDisplayId() : getLastNonProxyTopFocusedDisplayId();
performAccessibilityShortcutInternal(displayId, KEY_GESTURE, targetName);
-
- return true;
}
@Override
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index a28069bbf050..95e58e1a7300 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -684,8 +684,9 @@ public final class DisplayManagerService extends SystemService {
final var backupManager = new BackupManager(mContext);
Consumer<Pair<DisplayTopology, DisplayTopologyGraph>> topologyChangedCallback =
update -> {
- if (mInputManagerInternal != null) {
- mInputManagerInternal.setDisplayTopology(update.second);
+ DisplayTopologyGraph graph = update.second;
+ if (mInputManagerInternal != null && graph != null) {
+ mInputManagerInternal.setDisplayTopology(graph);
}
deliverTopologyUpdate(update.first);
};
@@ -3647,7 +3648,7 @@ public final class DisplayManagerService extends SystemService {
private void deliverTopologyUpdate(DisplayTopology topology) {
if (DEBUG) {
- Slog.d(TAG, "Delivering topology update");
+ Slog.d(TAG, "Delivering topology update: " + topology);
}
if (Trace.isTagEnabled(Trace.TRACE_TAG_POWER)) {
Trace.instant(Trace.TRACE_TAG_POWER, "deliverTopologyUpdate");
@@ -4209,13 +4210,18 @@ public final class DisplayManagerService extends SystemService {
public boolean mWifiDisplayScanRequested;
- // A single pending event.
+ // A single pending display event.
private record Event(int displayId, @DisplayEvent int event) { };
- // The list of pending events. This is null until there is a pending event to be saved.
- // This is only used if {@link deferDisplayEventsWhenFrozen()} is true.
+ // The list of pending display events. This is null until there is a pending event to be
+ // saved. This is only used if {@link deferDisplayEventsWhenFrozen()} is true.
+ @GuardedBy("mCallback")
+ @Nullable
+ private ArrayList<Event> mPendingDisplayEvents;
+
@GuardedBy("mCallback")
- private ArrayList<Event> mPendingEvents;
+ @Nullable
+ private DisplayTopology mPendingTopology;
// Process states: a process is ready to receive events if it is neither cached nor
// frozen.
@@ -4285,7 +4291,10 @@ public final class DisplayManagerService extends SystemService {
*/
@GuardedBy("mCallback")
private boolean hasPendingAndIsReadyLocked() {
- return isReadyLocked() && mPendingEvents != null && !mPendingEvents.isEmpty() && mAlive;
+ boolean pendingDisplayEvents = mPendingDisplayEvents != null
+ && !mPendingDisplayEvents.isEmpty();
+ boolean pendingTopology = mPendingTopology != null;
+ return isReadyLocked() && (pendingDisplayEvents || pendingTopology) && mAlive;
}
/**
@@ -4366,7 +4375,8 @@ public final class DisplayManagerService extends SystemService {
// occurs as the client is transitioning to ready but pending events have not
// been dispatched. The new event must be added to the pending list to
// preserve event ordering.
- if (!isReadyLocked() || (mPendingEvents != null && !mPendingEvents.isEmpty())) {
+ if (!isReadyLocked() || (mPendingDisplayEvents != null
+ && !mPendingDisplayEvents.isEmpty())) {
// The client is interested in the event but is not ready to receive it.
// Put the event on the pending list.
addDisplayEvent(displayId, event);
@@ -4453,13 +4463,13 @@ public final class DisplayManagerService extends SystemService {
// This is only used if {@link deferDisplayEventsWhenFrozen()} is true.
@GuardedBy("mCallback")
private void addDisplayEvent(int displayId, int event) {
- if (mPendingEvents == null) {
- mPendingEvents = new ArrayList<>();
+ if (mPendingDisplayEvents == null) {
+ mPendingDisplayEvents = new ArrayList<>();
}
- if (!mPendingEvents.isEmpty()) {
+ if (!mPendingDisplayEvents.isEmpty()) {
// Ignore redundant events. Further optimization is possible by merging adjacent
// events.
- Event last = mPendingEvents.get(mPendingEvents.size() - 1);
+ Event last = mPendingDisplayEvents.get(mPendingDisplayEvents.size() - 1);
if (last.displayId == displayId && last.event == event) {
if (DEBUG) {
Slog.d(TAG, "Ignore redundant display event " + displayId + "/" + event
@@ -4468,12 +4478,13 @@ public final class DisplayManagerService extends SystemService {
return;
}
}
- mPendingEvents.add(new Event(displayId, event));
+ mPendingDisplayEvents.add(new Event(displayId, event));
}
/**
* @return {@code false} if RemoteException happens; otherwise {@code true} for
- * success.
+ * success. This returns true even if the update was deferred because the remote client is
+ * cached or frozen.
*/
boolean notifyTopologyUpdateAsync(DisplayTopology topology) {
if ((mInternalEventFlagsMask.get()
@@ -4490,6 +4501,18 @@ public final class DisplayManagerService extends SystemService {
// The client is not interested in this event, so do nothing.
return true;
}
+
+ if (deferDisplayEventsWhenFrozen()) {
+ synchronized (mCallback) {
+ // Save the new update if the client frozen or cached (not ready).
+ if (!isReadyLocked()) {
+ // The client is interested in the update but is not ready to receive it.
+ mPendingTopology = topology;
+ return true;
+ }
+ }
+ }
+
return transmitTopologyUpdate(topology);
}
@@ -4514,37 +4537,54 @@ public final class DisplayManagerService extends SystemService {
// would be unusual to do so. The method returns true on success.
// This is only used if {@link deferDisplayEventsWhenFrozen()} is true.
public boolean dispatchPending() {
- Event[] pending;
+ Event[] pendingDisplayEvents = null;
+ DisplayTopology pendingTopology;
synchronized (mCallback) {
- if (mPendingEvents == null || mPendingEvents.isEmpty() || !mAlive) {
+ if (!mAlive) {
return true;
}
if (!isReadyLocked()) {
return false;
}
- pending = new Event[mPendingEvents.size()];
- pending = mPendingEvents.toArray(pending);
- mPendingEvents.clear();
+
+ if (mPendingDisplayEvents != null && !mPendingDisplayEvents.isEmpty()) {
+ pendingDisplayEvents = new Event[mPendingDisplayEvents.size()];
+ pendingDisplayEvents = mPendingDisplayEvents.toArray(pendingDisplayEvents);
+ mPendingDisplayEvents.clear();
+ }
+
+ pendingTopology = mPendingTopology;
+ mPendingTopology = null;
}
try {
- for (int i = 0; i < pending.length; i++) {
- Event displayEvent = pending[i];
- if (DEBUG) {
- Slog.d(TAG, "Send pending display event #" + i + " "
- + displayEvent.displayId + "/"
- + displayEvent.event + " to " + mUid + "/" + mPid);
- }
+ if (pendingDisplayEvents != null) {
+ for (int i = 0; i < pendingDisplayEvents.length; i++) {
+ Event displayEvent = pendingDisplayEvents[i];
+ if (DEBUG) {
+ Slog.d(TAG, "Send pending display event #" + i + " "
+ + displayEvent.displayId + "/"
+ + displayEvent.event + " to " + mUid + "/" + mPid);
+ }
+
+ if (!shouldReceiveRefreshRateWithChangeUpdate(displayEvent.event)) {
+ continue;
+ }
- if (!shouldReceiveRefreshRateWithChangeUpdate(displayEvent.event)) {
- continue;
+ transmitDisplayEvent(displayEvent.displayId, displayEvent.event);
}
+ }
- transmitDisplayEvent(displayEvent.displayId, displayEvent.event);
+ if (pendingTopology != null) {
+ if (DEBUG) {
+ Slog.d(TAG, "Send pending topology: " + pendingTopology
+ + " to " + mUid + "/" + mPid);
+ }
+ mCallback.onTopologyChanged(pendingTopology);
}
+
return true;
} catch (RemoteException ex) {
- Slog.w(TAG, "Failed to notify process "
- + mPid + " that display topology changed, assuming it died.", ex);
+ Slog.w(TAG, "Failed to notify process " + mPid + ", assuming it died.", ex);
binderDied();
return false;
@@ -4556,11 +4596,12 @@ public final class DisplayManagerService extends SystemService {
if (deferDisplayEventsWhenFrozen()) {
final String fmt =
"mPid=%d mUid=%d mWifiDisplayScanRequested=%s"
- + " cached=%s frozen=%s pending=%d";
+ + " cached=%s frozen=%s pendingDisplayEvents=%d pendingTopology=%b";
synchronized (mCallback) {
return formatSimple(fmt,
mPid, mUid, mWifiDisplayScanRequested, mCached, mFrozen,
- (mPendingEvents == null) ? 0 : mPendingEvents.size());
+ (mPendingDisplayEvents == null) ? 0 : mPendingDisplayEvents.size(),
+ mPendingTopology != null);
}
} else {
final String fmt =
diff --git a/services/core/java/com/android/server/display/mode/DisplayModeDirector.java b/services/core/java/com/android/server/display/mode/DisplayModeDirector.java
index c37733b05fba..2c90e1919123 100644
--- a/services/core/java/com/android/server/display/mode/DisplayModeDirector.java
+++ b/services/core/java/com/android/server/display/mode/DisplayModeDirector.java
@@ -156,6 +156,8 @@ public class DisplayModeDirector {
private SparseArray<Display.Mode> mDefaultModeByDisplay;
// a map from display id to display device config
private SparseArray<DisplayDeviceConfig> mDisplayDeviceConfigByDisplay = new SparseArray<>();
+ // set containing connected external display ids
+ private final Set<Integer> mExternalDisplaysConnected = new HashSet<>();
private SparseBooleanArray mHasArrSupport;
@@ -425,7 +427,7 @@ public class DisplayModeDirector {
// Some external displays physical refresh rate modes are slightly above 60hz.
// SurfaceFlinger will not enable these display modes unless it is configured to allow
// render rate at least at this frame rate.
- if (mDisplayObserver.isExternalDisplayLocked(displayId)) {
+ if (isExternalDisplayLocked(displayId)) {
primarySummary.maxRenderFrameRate = Math.max(baseMode.getRefreshRate(),
primarySummary.maxRenderFrameRate);
appRequestSummary.maxRenderFrameRate = Math.max(baseMode.getRefreshRate(),
@@ -653,6 +655,10 @@ public class DisplayModeDirector {
}
}
+ boolean isExternalDisplayLocked(int displayId) {
+ return mExternalDisplaysConnected.contains(displayId);
+ }
+
private static String switchingTypeToString(@DisplayManager.SwitchingType int type) {
switch (type) {
case DisplayManager.SWITCHING_TYPE_NONE:
@@ -694,6 +700,11 @@ public class DisplayModeDirector {
}
@VisibleForTesting
+ void addExternalDisplayId(int externalDisplayId) {
+ mExternalDisplaysConnected.add(externalDisplayId);
+ }
+
+ @VisibleForTesting
void injectBrightnessObserver(BrightnessObserver brightnessObserver) {
mBrightnessObserver = brightnessObserver;
}
@@ -1210,7 +1221,7 @@ public class DisplayModeDirector {
@GuardedBy("mLock")
private void updateRefreshRateSettingLocked(float minRefreshRate, float peakRefreshRate,
float defaultRefreshRate, int displayId) {
- if (mDisplayObserver.isExternalDisplayLocked(displayId)) {
+ if (isExternalDisplayLocked(displayId)) {
if (mLoggingEnabled) {
Slog.d(TAG, "skip updateRefreshRateSettingLocked for external display "
+ displayId);
@@ -1309,20 +1320,25 @@ public class DisplayModeDirector {
public void setAppRequest(int displayId, int modeId, float requestedRefreshRate,
float requestedMinRefreshRateRange, float requestedMaxRefreshRateRange) {
Display.Mode requestedMode;
+ boolean isExternalDisplay;
synchronized (mLock) {
requestedMode = findModeLocked(displayId, modeId, requestedRefreshRate);
+ isExternalDisplay = isExternalDisplayLocked(displayId);
}
Vote frameRateVote = getFrameRateVote(
requestedMinRefreshRateRange, requestedMaxRefreshRateRange);
Vote baseModeRefreshRateVote = getBaseModeVote(requestedMode, requestedRefreshRate);
- Vote sizeVote = getSizeVote(requestedMode);
mVotesStorage.updateVote(displayId, Vote.PRIORITY_APP_REQUEST_RENDER_FRAME_RATE_RANGE,
frameRateVote);
mVotesStorage.updateVote(displayId, Vote.PRIORITY_APP_REQUEST_BASE_MODE_REFRESH_RATE,
baseModeRefreshRateVote);
- mVotesStorage.updateVote(displayId, Vote.PRIORITY_APP_REQUEST_SIZE, sizeVote);
+
+ if (!isExternalDisplay) {
+ Vote sizeVote = getSizeVote(requestedMode);
+ mVotesStorage.updateVote(displayId, Vote.PRIORITY_APP_REQUEST_SIZE, sizeVote);
+ }
}
private Display.Mode findModeLocked(int displayId, int modeId, float requestedRefreshRate) {
@@ -1420,7 +1436,6 @@ public class DisplayModeDirector {
private int mExternalDisplayPeakHeight;
private int mExternalDisplayPeakRefreshRate;
private final boolean mRefreshRateSynchronizationEnabled;
- private final Set<Integer> mExternalDisplaysConnected = new HashSet<>();
DisplayObserver(Context context, Handler handler, VotesStorage votesStorage,
Injector injector) {
@@ -1541,10 +1556,6 @@ public class DisplayModeDirector {
}
}
- boolean isExternalDisplayLocked(int displayId) {
- return mExternalDisplaysConnected.contains(displayId);
- }
-
@Nullable
private DisplayInfo getDisplayInfo(int displayId) {
DisplayInfo info = new DisplayInfo();
diff --git a/services/core/java/com/android/server/display/mode/ModeChangeObserver.java b/services/core/java/com/android/server/display/mode/ModeChangeObserver.java
index 50782a2f22c8..debfb067b710 100644
--- a/services/core/java/com/android/server/display/mode/ModeChangeObserver.java
+++ b/services/core/java/com/android/server/display/mode/ModeChangeObserver.java
@@ -25,6 +25,8 @@ import android.view.Display;
import android.view.DisplayAddress;
import android.view.DisplayEventReceiver;
+import androidx.annotation.VisibleForTesting;
+
import java.util.HashSet;
import java.util.Set;
@@ -35,8 +37,10 @@ final class ModeChangeObserver {
private final DisplayModeDirector.Injector mInjector;
@SuppressWarnings("unused")
- private DisplayEventReceiver mModeChangeListener;
- private DisplayManager.DisplayListener mDisplayListener;
+ @VisibleForTesting
+ DisplayEventReceiver mModeChangeListener;
+ @VisibleForTesting
+ DisplayManager.DisplayListener mDisplayListener;
private final LongSparseArray<Set<Integer>> mRejectedModesMap =
new LongSparseArray<>();
private final LongSparseArray<Integer> mPhysicalIdToLogicalIdMap = new LongSparseArray<>();
diff --git a/services/core/java/com/android/server/input/AppLaunchShortcutManager.java b/services/core/java/com/android/server/input/AppLaunchShortcutManager.java
index 8c028bc92841..eb102294ac32 100644
--- a/services/core/java/com/android/server/input/AppLaunchShortcutManager.java
+++ b/services/core/java/com/android/server/input/AppLaunchShortcutManager.java
@@ -111,7 +111,7 @@ final class AppLaunchShortcutManager {
mContext = context;
}
- public void systemRunning() {
+ public void init() {
loadShortcuts();
}
diff --git a/services/core/java/com/android/server/input/InputGestureManager.java b/services/core/java/com/android/server/input/InputGestureManager.java
index 67e1ccc6a850..e6d71900f106 100644
--- a/services/core/java/com/android/server/input/InputGestureManager.java
+++ b/services/core/java/com/android/server/input/InputGestureManager.java
@@ -94,9 +94,9 @@ final class InputGestureManager {
mContext = context;
}
- public void systemRunning() {
+ public void init(List<InputGestureData> bookmarks) {
initSystemShortcuts();
- blockListBookmarkedTriggers();
+ blockListBookmarkedTriggers(bookmarks);
}
private void initSystemShortcuts() {
@@ -263,10 +263,9 @@ final class InputGestureManager {
}
}
- private void blockListBookmarkedTriggers() {
+ private void blockListBookmarkedTriggers(List<InputGestureData> bookmarks) {
synchronized (mGestureLock) {
- InputManager im = Objects.requireNonNull(mContext.getSystemService(InputManager.class));
- for (InputGestureData bookmark : im.getAppLaunchBookmarks()) {
+ for (InputGestureData bookmark : bookmarks) {
mBlockListedTriggers.add(bookmark.getTrigger());
}
}
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 6e6d00d62819..29e04e744759 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -2751,18 +2751,23 @@ public class InputManagerService extends IInputManager.Stub
@SuppressLint("MissingPermission")
private void initKeyGestures() {
InputManager im = Objects.requireNonNull(mContext.getSystemService(InputManager.class));
- im.registerKeyGestureEventHandler(new InputManager.KeyGestureEventHandler() {
- @Override
- public boolean handleKeyGestureEvent(@NonNull KeyGestureEvent event,
- @Nullable IBinder focussedToken) {
- return InputManagerService.this.handleKeyGestureEvent(event);
- }
- });
+ List<Integer> supportedGestures = List.of(
+ KeyGestureEvent.KEY_GESTURE_TYPE_KEYBOARD_BACKLIGHT_UP,
+ KeyGestureEvent.KEY_GESTURE_TYPE_KEYBOARD_BACKLIGHT_DOWN,
+ KeyGestureEvent.KEY_GESTURE_TYPE_KEYBOARD_BACKLIGHT_TOGGLE,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_CAPS_LOCK,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS
+ );
+ im.registerKeyGestureEventHandler(supportedGestures,
+ (event, focusedToken) -> InputManagerService.this.handleKeyGestureEvent(event));
}
@SuppressLint("MissingPermission")
@VisibleForTesting
- boolean handleKeyGestureEvent(@NonNull KeyGestureEvent event) {
+ void handleKeyGestureEvent(@NonNull KeyGestureEvent event) {
int deviceId = event.getDeviceId();
boolean complete = event.getAction() == KeyGestureEvent.ACTION_GESTURE_COMPLETE
&& !event.isCancelled();
@@ -2771,20 +2776,20 @@ public class InputManagerService extends IInputManager.Stub
if (complete) {
mKeyboardBacklightController.incrementKeyboardBacklight(deviceId);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_KEYBOARD_BACKLIGHT_DOWN:
if (complete) {
mKeyboardBacklightController.decrementKeyboardBacklight(deviceId);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_KEYBOARD_BACKLIGHT_TOGGLE:
// TODO(b/367748270): Add functionality to turn keyboard backlight on/off.
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_CAPS_LOCK:
if (complete) {
mNative.toggleCapsLock(deviceId);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS:
if (complete) {
final boolean bounceKeysEnabled =
@@ -2792,7 +2797,6 @@ public class InputManagerService extends IInputManager.Stub
InputSettings.setAccessibilityBounceKeysThreshold(mContext,
bounceKeysEnabled ? 0
: InputSettings.DEFAULT_BOUNCE_KEYS_THRESHOLD_MILLIS);
- return true;
}
break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS:
@@ -2800,7 +2804,6 @@ public class InputManagerService extends IInputManager.Stub
final boolean mouseKeysEnabled = InputSettings.isAccessibilityMouseKeysEnabled(
mContext);
InputSettings.setAccessibilityMouseKeysEnabled(mContext, !mouseKeysEnabled);
- return true;
}
break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS:
@@ -2808,7 +2811,6 @@ public class InputManagerService extends IInputManager.Stub
final boolean stickyKeysEnabled =
InputSettings.isAccessibilityStickyKeysEnabled(mContext);
InputSettings.setAccessibilityStickyKeysEnabled(mContext, !stickyKeysEnabled);
- return true;
}
break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS:
@@ -2817,14 +2819,13 @@ public class InputManagerService extends IInputManager.Stub
InputSettings.isAccessibilitySlowKeysEnabled(mContext);
InputSettings.setAccessibilitySlowKeysThreshold(mContext,
slowKeysEnabled ? 0 : InputSettings.DEFAULT_SLOW_KEYS_THRESHOLD_MILLIS);
- return true;
}
break;
default:
- return false;
-
+ Log.w(TAG, "Received a key gesture " + event
+ + " that was not registered by this handler");
+ break;
}
- return false;
}
// Native callback.
@@ -3147,11 +3148,14 @@ public class InputManagerService extends IInputManager.Stub
@Override
@PermissionManuallyEnforced
- public void registerKeyGestureHandler(@NonNull IKeyGestureHandler handler) {
+ public void registerKeyGestureHandler(int[] keyGesturesToHandle,
+ @NonNull IKeyGestureHandler handler) {
enforceManageKeyGesturePermission();
Objects.requireNonNull(handler);
- mKeyGestureController.registerKeyGestureHandler(handler, Binder.getCallingPid());
+ Objects.requireNonNull(keyGesturesToHandle);
+ mKeyGestureController.registerKeyGestureHandler(keyGesturesToHandle, handler,
+ Binder.getCallingPid());
}
@Override
diff --git a/services/core/java/com/android/server/input/KeyGestureController.java b/services/core/java/com/android/server/input/KeyGestureController.java
index 395c77322c04..5de432e5849b 100644
--- a/services/core/java/com/android/server/input/KeyGestureController.java
+++ b/services/core/java/com/android/server/input/KeyGestureController.java
@@ -58,6 +58,7 @@ import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
+import android.util.SparseIntArray;
import android.view.Display;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
@@ -79,11 +80,11 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayDeque;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
-import java.util.TreeMap;
/**
* A thread-safe component of {@link InputManagerService} responsible for managing callbacks when a
@@ -166,11 +167,14 @@ final class KeyGestureController {
private final SparseArray<KeyGestureEventListenerRecord>
mKeyGestureEventListenerRecords = new SparseArray<>();
- // List of currently registered key gesture event handler keyed by process pid. The map sorts
- // in the order of preference of the handlers, and we prioritize handlers in system server
- // over external handlers..
+ // Map of currently registered key gesture event handlers keyed by pid.
@GuardedBy("mKeyGestureHandlerRecords")
- private final TreeMap<Integer, KeyGestureHandlerRecord> mKeyGestureHandlerRecords;
+ private final SparseArray<KeyGestureHandlerRecord> mKeyGestureHandlerRecords =
+ new SparseArray<>();
+
+ // Currently supported key gestures mapped to pid that registered the corresponding handler.
+ @GuardedBy("mKeyGestureHandlerRecords")
+ private final SparseIntArray mSupportedKeyGestureToPidMap = new SparseIntArray();
private final ArrayDeque<KeyGestureEvent> mLastHandledEvents = new ArrayDeque<>();
@@ -193,18 +197,6 @@ final class KeyGestureController {
mHandler = new Handler(looper, this::handleMessage);
mIoHandler = new Handler(ioLooper, this::handleIoMessage);
mSystemPid = Process.myPid();
- mKeyGestureHandlerRecords = new TreeMap<>((p1, p2) -> {
- if (Objects.equals(p1, p2)) {
- return 0;
- }
- if (p1 == mSystemPid) {
- return -1;
- } else if (p2 == mSystemPid) {
- return 1;
- } else {
- return Integer.compare(p1, p2);
- }
- });
mKeyCombinationManager = new KeyCombinationManager(mHandler);
mSettingsObserver = new SettingsObserver(mHandler);
mAppLaunchShortcutManager = new AppLaunchShortcutManager(mContext);
@@ -450,8 +442,8 @@ final class KeyGestureController {
public void systemRunning() {
mSettingsObserver.observe();
- mAppLaunchShortcutManager.systemRunning();
- mInputGestureManager.systemRunning();
+ mAppLaunchShortcutManager.init();
+ mInputGestureManager.init(mAppLaunchShortcutManager.getBookmarks());
initKeyGestures();
int userId;
@@ -465,22 +457,24 @@ final class KeyGestureController {
@SuppressLint("MissingPermission")
private void initKeyGestures() {
InputManager im = Objects.requireNonNull(mContext.getSystemService(InputManager.class));
- im.registerKeyGestureEventHandler((event, focusedToken) -> {
- switch (event.getKeyGestureType()) {
- case KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT_CHORD:
- if (event.getAction() == KeyGestureEvent.ACTION_GESTURE_START) {
- mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT);
- mHandler.sendMessageDelayed(
- mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT),
- getAccessibilityShortcutTimeout());
+ im.registerKeyGestureEventHandler(
+ List.of(KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT_CHORD),
+ (event, focusedToken) -> {
+ if (event.getKeyGestureType()
+ == KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT_CHORD) {
+ if (event.getAction() == KeyGestureEvent.ACTION_GESTURE_START) {
+ mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT);
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT),
+ getAccessibilityShortcutTimeout());
+ } else {
+ mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT);
+ }
} else {
- mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT);
+ Log.w(TAG, "Received a key gesture " + event
+ + " that was not registered by this handler");
}
- return true;
- default:
- return false;
- }
- });
+ });
}
public boolean interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
@@ -590,10 +584,11 @@ final class KeyGestureController {
return true;
}
if (result.appLaunchData() != null) {
- return handleKeyGesture(deviceId, new int[]{keyCode}, metaState,
+ handleKeyGesture(deviceId, new int[]{keyCode}, metaState,
KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION,
- KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
- focusedToken, /* flags = */0, result.appLaunchData());
+ KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId, focusedToken, /* flags = */
+ 0, result.appLaunchData());
+ return true;
}
// Handle system shortcuts
@@ -601,11 +596,11 @@ final class KeyGestureController {
InputGestureData systemShortcut = mInputGestureManager.getSystemShortcutForKeyEvent(
event);
if (systemShortcut != null) {
- return handleKeyGesture(deviceId, new int[]{keyCode}, metaState,
+ handleKeyGesture(deviceId, new int[]{keyCode}, metaState,
systemShortcut.getAction().keyGestureType(),
- KeyGestureEvent.ACTION_GESTURE_COMPLETE,
- displayId, focusedToken, /* flags = */0,
- systemShortcut.getAction().appLaunchData());
+ KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
+ focusedToken, /* flags = */0, systemShortcut.getAction().appLaunchData());
+ return true;
}
}
@@ -687,11 +682,11 @@ final class KeyGestureController {
return true;
case KeyEvent.KEYCODE_SEARCH:
if (firstDown && mSearchKeyBehavior == SEARCH_KEY_BEHAVIOR_TARGET_ACTIVITY) {
- return handleKeyGesture(deviceId, new int[]{keyCode}, /* modifierState = */0,
+ handleKeyGesture(deviceId, new int[]{keyCode}, /* modifierState = */0,
KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH,
KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
focusedToken, /* flags = */0, /* appLaunchData = */null);
-
+ return true;
}
break;
case KeyEvent.KEYCODE_SETTINGS:
@@ -782,11 +777,12 @@ final class KeyGestureController {
if (KeyEvent.metaStateHasModifiers(
shiftlessModifiers, KeyEvent.META_ALT_ON)) {
mPendingHideRecentSwitcher = true;
- return handleKeyGesture(deviceId, new int[]{keyCode},
+ handleKeyGesture(deviceId, new int[]{keyCode},
KeyEvent.META_ALT_ON,
KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER,
KeyGestureEvent.ACTION_GESTURE_START, displayId,
focusedToken, /* flags = */0, /* appLaunchData = */null);
+ return true;
}
}
}
@@ -803,21 +799,23 @@ final class KeyGestureController {
} else {
if (mPendingHideRecentSwitcher) {
mPendingHideRecentSwitcher = false;
- return handleKeyGesture(deviceId, new int[]{KeyEvent.KEYCODE_TAB},
+ handleKeyGesture(deviceId, new int[]{KeyEvent.KEYCODE_TAB},
KeyEvent.META_ALT_ON,
KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER,
KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
focusedToken, /* flags = */0, /* appLaunchData = */null);
+ return true;
}
// Toggle Caps Lock on META-ALT.
if (mPendingCapsLockToggle) {
mPendingCapsLockToggle = false;
- return handleKeyGesture(deviceId, new int[]{KeyEvent.KEYCODE_META_LEFT,
+ handleKeyGesture(deviceId, new int[]{KeyEvent.KEYCODE_META_LEFT,
KeyEvent.KEYCODE_ALT_LEFT}, /* modifierState = */0,
KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_CAPS_LOCK,
KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
focusedToken, /* flags = */0, /* appLaunchData = */null);
+ return true;
}
}
break;
@@ -885,11 +883,11 @@ final class KeyGestureController {
if (customGesture == null) {
return false;
}
- return handleKeyGesture(deviceId, new int[]{keyCode}, metaState,
+ handleKeyGesture(deviceId, new int[]{keyCode}, metaState,
customGesture.getAction().keyGestureType(),
- KeyGestureEvent.ACTION_GESTURE_COMPLETE,
- displayId, focusedToken, /* flags = */0,
- customGesture.getAction().appLaunchData());
+ KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId, focusedToken,
+ /* flags = */0, customGesture.getAction().appLaunchData());
+ return true;
}
return false;
}
@@ -908,7 +906,7 @@ final class KeyGestureController {
// Handle keyboard layout switching. (CTRL + SPACE)
if (KeyEvent.metaStateHasModifiers(metaState & ~KeyEvent.META_SHIFT_MASK,
KeyEvent.META_CTRL_ON)) {
- return handleKeyGesture(deviceId, new int[]{keyCode},
+ handleKeyGesture(deviceId, new int[]{keyCode},
KeyEvent.META_CTRL_ON | (event.isShiftPressed()
? KeyEvent.META_SHIFT_ON : 0),
KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH,
@@ -921,7 +919,7 @@ final class KeyGestureController {
if (down && KeyEvent.metaStateHasModifiers(metaState,
KeyEvent.META_CTRL_ON | KeyEvent.META_ALT_ON)) {
// Intercept the Accessibility keychord (CTRL + ALT + Z) for keyboard users.
- return handleKeyGesture(deviceId, new int[]{keyCode},
+ handleKeyGesture(deviceId, new int[]{keyCode},
KeyEvent.META_CTRL_ON | KeyEvent.META_ALT_ON,
KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT,
KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
@@ -930,7 +928,7 @@ final class KeyGestureController {
break;
case KeyEvent.KEYCODE_SYSRQ:
if (down && repeatCount == 0) {
- return handleKeyGesture(deviceId, new int[]{keyCode}, /* modifierState = */0,
+ handleKeyGesture(deviceId, new int[]{keyCode}, /* modifierState = */0,
KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT,
KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
focusedToken, /* flags = */0, /* appLaunchData = */null);
@@ -938,7 +936,7 @@ final class KeyGestureController {
break;
case KeyEvent.KEYCODE_ESCAPE:
if (down && KeyEvent.metaStateHasNoModifiers(metaState) && repeatCount == 0) {
- return handleKeyGesture(deviceId, new int[]{keyCode}, /* modifierState = */0,
+ handleKeyGesture(deviceId, new int[]{keyCode}, /* modifierState = */0,
KeyGestureEvent.KEY_GESTURE_TYPE_CLOSE_ALL_DIALOGS,
KeyGestureEvent.ACTION_GESTURE_COMPLETE, displayId,
focusedToken, /* flags = */0, /* appLaunchData = */null);
@@ -964,29 +962,31 @@ final class KeyGestureController {
}
@VisibleForTesting
- boolean handleKeyGesture(int deviceId, int[] keycodes, int modifierState,
+ void handleKeyGesture(int deviceId, int[] keycodes, int modifierState,
@KeyGestureEvent.KeyGestureType int gestureType, int action, int displayId,
@Nullable IBinder focusedToken, int flags, @Nullable AppLaunchData appLaunchData) {
- return handleKeyGesture(createKeyGestureEvent(deviceId, keycodes,
- modifierState, gestureType, action, displayId, flags, appLaunchData), focusedToken);
+ handleKeyGesture(
+ createKeyGestureEvent(deviceId, keycodes, modifierState, gestureType, action,
+ displayId, flags, appLaunchData), focusedToken);
}
- private boolean handleKeyGesture(AidlKeyGestureEvent event, @Nullable IBinder focusedToken) {
+ private void handleKeyGesture(AidlKeyGestureEvent event, @Nullable IBinder focusedToken) {
if (mVisibleBackgroundUsersEnabled && event.displayId != DEFAULT_DISPLAY
&& shouldIgnoreGestureEventForVisibleBackgroundUser(event.gestureType,
event.displayId)) {
- return false;
+ return;
}
synchronized (mKeyGestureHandlerRecords) {
- for (KeyGestureHandlerRecord handler : mKeyGestureHandlerRecords.values()) {
- if (handler.handleKeyGesture(event, focusedToken)) {
- Message msg = Message.obtain(mHandler, MSG_NOTIFY_KEY_GESTURE_EVENT, event);
- mHandler.sendMessage(msg);
- return true;
- }
+ int index = mSupportedKeyGestureToPidMap.indexOfKey(event.gestureType);
+ if (index < 0) {
+ Log.i(TAG, "Key gesture: " + event.gestureType + " is not supported");
+ return;
}
+ int pid = mSupportedKeyGestureToPidMap.valueAt(index);
+ mKeyGestureHandlerRecords.get(pid).handleKeyGesture(event, focusedToken);
+ Message msg = Message.obtain(mHandler, MSG_NOTIFY_KEY_GESTURE_EVENT, event);
+ mHandler.sendMessage(msg);
}
- return false;
}
private boolean shouldIgnoreGestureEventForVisibleBackgroundUser(
@@ -1285,12 +1285,23 @@ final class KeyGestureController {
/** Register the key gesture event handler for a process. */
@BinderThread
- public void registerKeyGestureHandler(IKeyGestureHandler handler, int pid) {
+ public void registerKeyGestureHandler(int[] keyGesturesToHandle, IKeyGestureHandler handler,
+ int pid) {
synchronized (mKeyGestureHandlerRecords) {
if (mKeyGestureHandlerRecords.get(pid) != null) {
throw new IllegalStateException("The calling process has already registered "
+ "a KeyGestureHandler.");
}
+ if (keyGesturesToHandle.length == 0) {
+ throw new IllegalArgumentException("No key gestures provided for pid = " + pid);
+ }
+ for (int gestureType : keyGesturesToHandle) {
+ if (mSupportedKeyGestureToPidMap.indexOfKey(gestureType) >= 0) {
+ throw new IllegalArgumentException(
+ "Key gesture " + gestureType + " is already registered by pid = "
+ + mSupportedKeyGestureToPidMap.get(gestureType));
+ }
+ }
KeyGestureHandlerRecord record = new KeyGestureHandlerRecord(pid, handler);
try {
handler.asBinder().linkToDeath(record, 0);
@@ -1298,6 +1309,9 @@ final class KeyGestureController {
throw new RuntimeException(ex);
}
mKeyGestureHandlerRecords.put(pid, record);
+ for (int gestureType : keyGesturesToHandle) {
+ mSupportedKeyGestureToPidMap.put(gestureType, pid);
+ }
}
}
@@ -1315,7 +1329,7 @@ final class KeyGestureController {
+ "KeyGestureHandler.");
}
record.mKeyGestureHandler.asBinder().unlinkToDeath(record, 0);
- mKeyGestureHandlerRecords.remove(pid);
+ onKeyGestureHandlerRemoved(pid);
}
}
@@ -1328,9 +1342,14 @@ final class KeyGestureController {
return mAppLaunchShortcutManager.getBookmarks();
}
- private void onKeyGestureHandlerDied(int pid) {
+ private void onKeyGestureHandlerRemoved(int pid) {
synchronized (mKeyGestureHandlerRecords) {
mKeyGestureHandlerRecords.remove(pid);
+ for (int i = mSupportedKeyGestureToPidMap.size() - 1; i >= 0; i--) {
+ if (mSupportedKeyGestureToPidMap.valueAt(i) == pid) {
+ mSupportedKeyGestureToPidMap.removeAt(i);
+ }
+ }
}
}
@@ -1369,18 +1388,17 @@ final class KeyGestureController {
if (DEBUG) {
Slog.d(TAG, "Key gesture event handler for pid " + mPid + " died.");
}
- onKeyGestureHandlerDied(mPid);
+ onKeyGestureHandlerRemoved(mPid);
}
- public boolean handleKeyGesture(AidlKeyGestureEvent event, IBinder focusedToken) {
+ public void handleKeyGesture(AidlKeyGestureEvent event, IBinder focusedToken) {
try {
- return mKeyGestureHandler.handleKeyGesture(event, focusedToken);
+ mKeyGestureHandler.handleKeyGesture(event, focusedToken);
} catch (RemoteException ex) {
Slog.w(TAG, "Failed to send key gesture to process " + mPid
+ ", assuming it died.", ex);
binderDied();
}
- return false;
}
}
@@ -1479,18 +1497,21 @@ final class KeyGestureController {
}
}
ipw.println("}");
- ipw.print("mKeyGestureHandlerRecords = {");
synchronized (mKeyGestureHandlerRecords) {
- int i = mKeyGestureHandlerRecords.size() - 1;
- for (int processId : mKeyGestureHandlerRecords.keySet()) {
- ipw.print(processId);
- if (i > 0) {
+ ipw.print("mKeyGestureHandlerRecords = {");
+ int size = mKeyGestureHandlerRecords.size();
+ for (int i = 0; i < size; i++) {
+ int pid = mKeyGestureHandlerRecords.keyAt(i);
+ ipw.print(pid);
+ if (i < size - 1) {
ipw.print(", ");
}
- i--;
}
+ ipw.println("}");
+ ipw.println("mSupportedKeyGestures = " + Arrays.toString(
+ mSupportedKeyGestureToPidMap.copyKeys()));
}
- ipw.println("}");
+
ipw.decreaseIndent();
ipw.println("Last handled KeyGestureEvents: ");
ipw.increaseIndent();
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index fde9165a84c6..2066dbc87a0d 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -1826,8 +1826,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
@NonNull UserData userData) {
final int userId = userData.mUserId;
if (userData.mCurClient == client) {
- hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow, 0 /* flags */,
- SoftInputShowHideReason.HIDE_REMOVE_CLIENT, userId);
+ if (Flags.refactorInsetsController()) {
+ final var statsToken = createStatsTokenForFocusedClient(false /* show */,
+ SoftInputShowHideReason.HIDE_REMOVE_CLIENT, userId);
+ setImeVisibilityOnFocusedWindowClient(false, userData, statsToken);
+ } else {
+ hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow, 0 /* flags */,
+ SoftInputShowHideReason.HIDE_REMOVE_CLIENT, userId);
+ }
if (userData.mBoundToMethod) {
userData.mBoundToMethod = false;
final var userBindingController = userData.mBindingController;
@@ -2097,8 +2103,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
}
if (visibilityStateComputer.getImePolicy().isImeHiddenByDisplayPolicy()) {
- hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow, 0 /* flags */,
- SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE, userId);
+ if (Flags.refactorInsetsController()) {
+ final var statsToken = createStatsTokenForFocusedClient(false /* show */,
+ SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE, userId);
+ setImeVisibilityOnFocusedWindowClient(false, userData, statsToken);
+ } else {
+ hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow, 0 /* flags */,
+ SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE, userId);
+ }
return InputBindResult.NO_IME;
}
@@ -3855,8 +3867,17 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
Slog.w(TAG, "If you need to impersonate a foreground user/profile from"
+ " a background user, use EditorInfo.targetInputMethodUser with"
+ " INTERACT_ACROSS_USERS_FULL permission.");
- hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow,
- 0 /* flags */, SoftInputShowHideReason.HIDE_INVALID_USER, userId);
+
+ if (Flags.refactorInsetsController()) {
+ final var statsToken = createStatsTokenForFocusedClient(
+ false /* show */, SoftInputShowHideReason.HIDE_INVALID_USER,
+ userId);
+ setImeVisibilityOnFocusedWindowClient(false, userData, statsToken);
+ } else {
+ hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow,
+ 0 /* flags */, SoftInputShowHideReason.HIDE_INVALID_USER,
+ userId);
+ }
return InputBindResult.INVALID_USER;
}
@@ -4993,7 +5014,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
setImeVisibilityOnFocusedWindowClient(false, userData,
null /* TODO(b/353463205) check statsToken */);
} else {
-
hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow,
0 /* flags */, reason, userId);
}
@@ -6688,8 +6708,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
final var userData = getUserData(userId);
if (Flags.refactorInsetsController()) {
- setImeVisibilityOnFocusedWindowClient(false, userData,
- null /* TODO(b329229469) initialize statsToken here? */);
+ final var statsToken = createStatsTokenForFocusedClient(false /* show */,
+ SoftInputShowHideReason.HIDE_RESET_SHELL_COMMAND, userId);
+ setImeVisibilityOnFocusedWindowClient(false, userData, statsToken);
} else {
hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow,
0 /* flags */,
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 58cf29b59961..c174451e8f5b 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -192,9 +192,15 @@ public class MediaSessionService extends SystemService implements Monitor {
private final Map<Integer, Set<MediaSessionRecordImpl>> mUserEngagedSessionsForFgs =
new HashMap<>();
- /* Maps uid with all media notifications associated to it */
+ /**
+ * Maps UIDs to their associated media notifications: UID -> (Notification ID ->
+ * {@link android.service.notification.StatusBarNotification}).
+ * Each UID maps to a collection of notifications, identified by their
+ * {@link android.service.notification.StatusBarNotification#getId()}.
+ */
@GuardedBy("mLock")
- private final Map<Integer, Set<StatusBarNotification>> mMediaNotifications = new HashMap<>();
+ private final Map<Integer, Map<String, StatusBarNotification>> mMediaNotifications =
+ new HashMap<>();
// The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile)
// It's always not null after the MediaSessionService is started.
@@ -737,7 +743,8 @@ public class MediaSessionService extends SystemService implements Monitor {
}
synchronized (mLock) {
int uid = mediaSessionRecord.getUid();
- for (StatusBarNotification sbn : mMediaNotifications.getOrDefault(uid, Set.of())) {
+ for (StatusBarNotification sbn : mMediaNotifications.getOrDefault(uid,
+ Map.of()).values()) {
if (mediaSessionRecord.isLinkedToNotification(sbn.getNotification())) {
setFgsActiveLocked(mediaSessionRecord, sbn);
return;
@@ -771,7 +778,7 @@ public class MediaSessionService extends SystemService implements Monitor {
int uid, MediaSessionRecordImpl record) {
synchronized (mLock) {
for (StatusBarNotification sbn :
- mMediaNotifications.getOrDefault(uid, Set.of())) {
+ mMediaNotifications.getOrDefault(uid, Map.of()).values()) {
if (record.isLinkedToNotification(sbn.getNotification())) {
return sbn;
}
@@ -794,7 +801,8 @@ public class MediaSessionService extends SystemService implements Monitor {
for (MediaSessionRecordImpl record :
mUserEngagedSessionsForFgs.getOrDefault(uid, Set.of())) {
for (StatusBarNotification sbn :
- mMediaNotifications.getOrDefault(uid, Set.of())) {
+ mMediaNotifications.getOrDefault(uid, Map.of()).values()) {
+ //
if (record.isLinkedToNotification(sbn.getNotification())) {
// A user engaged session linked with a media notification is found.
// We shouldn't call stop FGS in this case.
@@ -3262,8 +3270,12 @@ public class MediaSessionService extends SystemService implements Monitor {
return;
}
synchronized (mLock) {
- mMediaNotifications.putIfAbsent(uid, new HashSet<>());
- mMediaNotifications.get(uid).add(sbn);
+ Map<String, StatusBarNotification> notifications = mMediaNotifications.get(uid);
+ if (notifications == null) {
+ notifications = new HashMap<>();
+ mMediaNotifications.put(uid, notifications);
+ }
+ notifications.put(sbn.getKey(), sbn);
MediaSessionRecordImpl userEngagedRecord =
getUserEngagedMediaSessionRecordForNotification(uid, postedNotification);
if (userEngagedRecord != null) {
@@ -3287,10 +3299,10 @@ public class MediaSessionService extends SystemService implements Monitor {
return;
}
synchronized (mLock) {
- Set<StatusBarNotification> uidMediaNotifications = mMediaNotifications.get(uid);
- if (uidMediaNotifications != null) {
- uidMediaNotifications.remove(sbn);
- if (uidMediaNotifications.isEmpty()) {
+ Map<String, StatusBarNotification> notifications = mMediaNotifications.get(uid);
+ if (notifications != null) {
+ notifications.remove(sbn.getKey());
+ if (notifications.isEmpty()) {
mMediaNotifications.remove(uid);
}
}
diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java
index acdc79fb9922..e02ec6a9e3b4 100644
--- a/services/core/java/com/android/server/pm/InstallPackageHelper.java
+++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java
@@ -3077,7 +3077,8 @@ final class InstallPackageHelper {
}
if (succeeded) {
- Slog.i(TAG, "installation completed:" + packageName);
+ Slog.i(TAG, "installation completed for package:" + packageName
+ + ". Final code path: " + pkgSetting.getPath().getPath());
if (Flags.aslInApkAppMetadataSource()
&& pkgSetting.getAppMetadataSource() == APP_METADATA_SOURCE_APK) {
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 38d458767015..fcd1452b8702 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -115,7 +115,6 @@ import static com.android.server.wm.WindowManagerPolicyProto.SCREEN_ON_FULLY;
import static com.android.server.wm.WindowManagerPolicyProto.WINDOW_MANAGER_DRAW_COMPLETE;
import android.accessibilityservice.AccessibilityService;
-import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
@@ -268,6 +267,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -4240,19 +4240,51 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (!useKeyGestureEventHandler()) {
return;
}
- mInputManager.registerKeyGestureEventHandler((event, focusedToken) -> {
- boolean handled = PhoneWindowManager.this.handleKeyGestureEvent(event,
- focusedToken);
- if (handled && !event.isCancelled() && Arrays.stream(event.getKeycodes()).anyMatch(
- (keycode) -> keycode == KeyEvent.KEYCODE_POWER)) {
- mPowerKeyHandled = true;
- }
- return handled;
- });
+ List<Integer> supportedGestures = new ArrayList<>(List.of(
+ KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_APP_SWITCH,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_HOME,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TRIGGER_BUG_REPORT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_BACK,
+ KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION,
+ KeyGestureEvent.KEY_GESTURE_TYPE_DESKTOP_MODE,
+ KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER,
+ KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_UP,
+ KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_DOWN,
+ KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER,
+ KeyGestureEvent.KEY_GESTURE_TYPE_ALL_APPS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_ALL_APPS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH,
+ KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT,
+ KeyGestureEvent.KEY_GESTURE_TYPE_CLOSE_ALL_DIALOGS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB,
+ KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD,
+ KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD,
+ KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT
+ ));
+ if (enableTalkbackAndMagnifierKeyGestures()) {
+ supportedGestures.add(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK);
+ }
+ if (enableVoiceAccessKeyGestures()) {
+ supportedGestures.add(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS);
+ }
+ mInputManager.registerKeyGestureEventHandler(supportedGestures,
+ PhoneWindowManager.this::handleKeyGestureEvent);
}
@VisibleForTesting
- boolean handleKeyGestureEvent(KeyGestureEvent event, IBinder focusedToken) {
+ void handleKeyGestureEvent(KeyGestureEvent event, IBinder focusedToken) {
boolean start = event.getAction() == KeyGestureEvent.ACTION_GESTURE_START;
boolean complete = event.getAction() == KeyGestureEvent.ACTION_GESTURE_COMPLETE
&& !event.isCancelled();
@@ -4262,12 +4294,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
int modifierState = event.getModifierState();
boolean keyguardOn = keyguardOn();
boolean canLaunchApp = isUserSetupComplete() && !keyguardOn;
+ if (!event.isCancelled() && Arrays.stream(event.getKeycodes()).anyMatch(
+ (keycode) -> keycode == KeyEvent.KEYCODE_POWER)) {
+ mPowerKeyHandled = true;
+ }
switch (gestureType) {
case KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS:
if (complete) {
showRecentApps(false);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_APP_SWITCH:
if (!keyguardOn) {
if (start) {
@@ -4276,7 +4312,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
toggleRecentApps();
}
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT:
case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT:
if (complete && canLaunchApp) {
@@ -4284,33 +4320,33 @@ public class PhoneWindowManager implements WindowManagerPolicy {
deviceId, SystemClock.uptimeMillis(),
AssistUtils.INVOCATION_TYPE_UNKNOWN);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_HOME:
if (complete) {
// Post to main thread to avoid blocking input pipeline.
mHandler.post(() -> handleShortPressOnHome(displayId));
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS:
if (complete && canLaunchApp) {
showSystemSettings();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN:
if (complete) {
lockNow(null /* options */);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL:
if (complete) {
toggleNotificationPanel();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT:
if (complete) {
interceptScreenshotChord(SCREENSHOT_KEY_OTHER, 0 /*pressDelay*/);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TRIGGER_BUG_REPORT:
if (complete && mEnableBugReportKeyboardShortcut) {
try {
@@ -4321,12 +4357,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Slog.d(TAG, "Error taking bugreport", e);
}
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_BACK:
if (complete) {
injectBackGesture(SystemClock.uptimeMillis());
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION:
if (complete) {
StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
@@ -4335,7 +4371,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
getTargetDisplayIdForKeyGestureEvent(event));
}
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_DESKTOP_MODE:
if (complete) {
StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
@@ -4344,24 +4380,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
getTargetDisplayIdForKeyGestureEvent(event));
}
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT:
if (complete) {
moveFocusedTaskToStageSplit(getTargetDisplayIdForKeyGestureEvent(event),
true /* leftOrTop */);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT:
if (complete) {
moveFocusedTaskToStageSplit(getTargetDisplayIdForKeyGestureEvent(event),
false /* leftOrTop */);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER:
if (complete) {
toggleKeyboardShortcutsMenu(deviceId);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_UP:
case KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_DOWN:
if (complete) {
@@ -4369,32 +4405,32 @@ public class PhoneWindowManager implements WindowManagerPolicy {
gestureType == KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_UP ? 1 : -1;
changeDisplayBrightnessValue(displayId, direction);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER:
if (start) {
showRecentApps(true);
} else {
hideRecentApps(true, false);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_ALL_APPS:
case KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_ALL_APPS:
if (complete && isKeyEventForCurrentUser(event.getDisplayId(),
event.getKeycodes()[0], "launchAllAppsViaA11y")) {
launchAllAppsAction();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH:
if (complete && canLaunchApp) {
launchTargetSearchActivity();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH:
if (complete) {
int direction = (modifierState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
sendSwitchKeyboardLayout(displayId, focusedToken, direction);
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD:
if (start) {
// Screenshot chord is pressed: Wait for long press delay before taking
@@ -4404,14 +4440,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
} else {
cancelPendingScreenshotChordAction();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD:
if (start) {
interceptRingerToggleChord();
} else {
cancelPendingRingerToggleChordAction();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS:
if (start) {
performHapticFeedback(
@@ -4421,40 +4457,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
} else {
cancelGlobalActionsAction();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT:
if (start) {
interceptBugreportGestureTv();
} else {
cancelBugreportGestureTv();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT:
if (complete && mAccessibilityShortcutController.isAccessibilityShortcutAvailable(
isKeyguardLocked())) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT));
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_CLOSE_ALL_DIALOGS:
if (complete) {
mContext.closeSystemDialogs();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK:
- if (enableTalkbackAndMagnifierKeyGestures()) {
- if (complete) {
- mTalkbackShortcutController.toggleTalkback(mCurrentUserId,
- TalkbackShortcutController.ShortcutSource.KEYBOARD);
- }
- return true;
+ if (complete) {
+ mTalkbackShortcutController.toggleTalkback(mCurrentUserId,
+ TalkbackShortcutController.ShortcutSource.KEYBOARD);
}
break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS:
- if (enableVoiceAccessKeyGestures()) {
- if (complete) {
- mVoiceAccessShortcutController.toggleVoiceAccess(mCurrentUserId);
- }
- return true;
+ if (complete) {
+ mVoiceAccessShortcutController.toggleVoiceAccess(mCurrentUserId);
}
break;
case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION:
@@ -4463,7 +4493,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
&& mModifierShortcutManager.launchApplication(data)) {
dismissKeyboardShortcutsMenu();
}
- return true;
+ break;
case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB:
NotificationManager nm = getNotificationService();
if (nm != null) {
@@ -4472,9 +4502,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
: Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
"Key gesture DND", true);
}
- return true;
+ break;
+ default:
+ Log.w(TAG, "Received a key gesture " + event
+ + " that was not registered by this handler");
+ break;
}
- return false;
}
private void changeDisplayBrightnessValue(int displayId, int direction) {
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index 798c794edaf5..0f6cc24f1fc9 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -87,6 +87,7 @@ import android.service.quicksettings.TileService;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.IndentingPrintWriter;
+import android.util.IntArray;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
@@ -102,6 +103,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.logging.InstanceId;
import com.android.internal.os.TransferPipe;
+import com.android.internal.statusbar.DisableStates;
import com.android.internal.statusbar.IAddTileResultCallback;
import com.android.internal.statusbar.ISessionListener;
import com.android.internal.statusbar.IStatusBar;
@@ -124,6 +126,7 @@ import com.android.server.policy.GlobalActionsProvider;
import com.android.server.power.ShutdownCheckPoints;
import com.android.server.power.ShutdownThread;
import com.android.server.wm.ActivityTaskManagerInternal;
+import com.android.systemui.shared.Flags;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -1344,48 +1347,76 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
return mTracingEnabled;
}
- // TODO(b/117478341): make it aware of multi-display if needed.
+ /**
+ * Disable status bar features. Pass the bitwise-or of the {@code #DISABLE_*} flags.
+ * To re-enable everything, pass {@code #DISABLE_NONE}.
+ *
+ * Warning: Only pass {@code #DISABLE_*} flags into this function, do not use
+ * {@code #DISABLE2_*} flags.
+ */
@Override
public void disable(int what, IBinder token, String pkg) {
disableForUser(what, token, pkg, mCurrentUserId);
}
- // TODO(b/117478341): make it aware of multi-display if needed.
+ /**
+ * Disable status bar features for a given user. Pass the bitwise-or of the
+ * {@code #DISABLE_*} flags. To re-enable everything, pass {@code #DISABLE_NONE}.
+ *
+ * Warning: Only pass {@code #DISABLE_*} flags into this function, do not use
+ * {@code #DISABLE2_*} flags.
+ */
@Override
public void disableForUser(int what, IBinder token, String pkg, int userId) {
enforceStatusBar();
enforceValidCallingUser();
synchronized (mLock) {
- disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 1);
+ if (Flags.statusBarConnectedDisplays()) {
+ IntArray displayIds = new IntArray();
+ for (int i = 0; i < mDisplayUiState.size(); i++) {
+ displayIds.add(mDisplayUiState.keyAt(i));
+ }
+ disableAllDisplaysLocked(displayIds, userId, what, token, pkg, /* whichFlag= */ 1);
+ } else {
+ disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, /* whichFlag= */ 1);
+ }
}
}
- // TODO(b/117478341): make it aware of multi-display if needed.
/**
- * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
- * To re-enable everything, pass {@link #DISABLE2_NONE}.
+ * Disable additional status bar features. Pass the bitwise-or of the {@code #DISABLE2_*} flags.
+ * To re-enable everything, pass {@code #DISABLE2_NONE}.
*
- * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
+ * Warning: Only pass {@code #DISABLE2_*} flags into this function, do not use
+ * {@code #DISABLE_*} flags.
*/
@Override
public void disable2(int what, IBinder token, String pkg) {
disable2ForUser(what, token, pkg, mCurrentUserId);
}
- // TODO(b/117478341): make it aware of multi-display if needed.
/**
- * Disable additional status bar features for a given user. Pass the bitwise-or of the
- * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
+ * Disable additional status bar features for a given user. Pass the bitwise-or
+ * of the {@code #DISABLE2_*} flags. To re-enable everything, pass {@code #DISABLE2_NONE}.
*
- * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
+ * Warning: Only pass {@code #DISABLE2_*} flags into this function, do not use
+ * {@code #DISABLE_*} flags.
*/
@Override
public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
enforceStatusBar();
synchronized (mLock) {
- disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 2);
+ if (Flags.statusBarConnectedDisplays()) {
+ IntArray displayIds = new IntArray();
+ for (int i = 0; i < mDisplayUiState.size(); i++) {
+ displayIds.add(mDisplayUiState.keyAt(i));
+ }
+ disableAllDisplaysLocked(displayIds, userId, what, token, pkg, /* whichFlag= */ 2);
+ } else {
+ disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, /* whichFlag= */ 2);
+ }
}
}
@@ -1414,6 +1445,42 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
}
}
+ // This method batches disable state across all displays into a single remote call
+ // (IStatusBar#disableForAllDisplays) for efficiency and calls
+ // NotificationDelegate#onSetDisabled only if any display's disable state changes.
+ private void disableAllDisplaysLocked(IntArray displayIds, int userId, int what, IBinder token,
+ String pkg, int whichFlag) {
+ // It's important that the the callback and the call to mBar get done
+ // in the same order when multiple threads are calling this function
+ // so they are paired correctly. The messages on the handler will be
+ // handled in the order they were enqueued, but will be outside the lock.
+ manageDisableListLocked(userId, what, token, pkg, whichFlag);
+
+ // Ensure state for the current user is applied, even if passed a non-current user.
+ final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
+ final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
+
+ IStatusBar bar = mBar;
+ Map<Integer, Pair<Integer, Integer>> displaysWithNewDisableStates = new HashMap<>();
+ for (int displayId : displayIds.toArray()) {
+ final UiState state = getUiState(displayId);
+ if (!state.disableEquals(net1, net2)) {
+ state.setDisabled(net1, net2);
+ displaysWithNewDisableStates.put(displayId, new Pair(net1, net2));
+ }
+ }
+ if (bar != null) {
+ try {
+ bar.disableForAllDisplays(new DisableStates(displaysWithNewDisableStates));
+ } catch (RemoteException ex) {
+ Slog.e(TAG, "Unable to disable Status bar.", ex);
+ }
+ }
+ if (!displaysWithNewDisableStates.isEmpty()) {
+ mHandler.post(() -> mNotificationDelegate.onSetDisabled(net1));
+ }
+ }
+
/**
* Get the currently applied disable flags, in the form of one Pair<Integer, Integer>.
*
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index b76b23161e78..b9ab863a2805 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -158,7 +158,6 @@ import static com.android.server.wm.ActivityRecordProto.FRONT_OF_TASK;
import static com.android.server.wm.ActivityRecordProto.IN_SIZE_COMPAT_MODE;
import static com.android.server.wm.ActivityRecordProto.IS_ANIMATING;
import static com.android.server.wm.ActivityRecordProto.IS_USER_FULLSCREEN_OVERRIDE_ENABLED;
-import static com.android.server.wm.ActivityRecordProto.LAST_ALL_DRAWN;
import static com.android.server.wm.ActivityRecordProto.LAST_DROP_INPUT_MODE;
import static com.android.server.wm.ActivityRecordProto.LAST_SURFACE_SHOWING;
import static com.android.server.wm.ActivityRecordProto.MIN_ASPECT_RATIO;
@@ -723,7 +722,6 @@ final class ActivityRecord extends WindowToken {
private int mNumInterestingWindows;
private int mNumDrawnWindows;
boolean allDrawn;
- private boolean mLastAllDrawn;
/**
* Solely for reporting to ActivityMetricsLogger. Just tracks whether, the last time this
@@ -1148,13 +1146,11 @@ final class ActivityRecord extends WindowToken {
if (mAppStopped) {
pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
}
- if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
- || allDrawn || mLastAllDrawn) {
+ if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0 || allDrawn) {
pw.print(prefix); pw.print("mNumInterestingWindows=");
pw.print(mNumInterestingWindows);
pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
pw.print(" allDrawn="); pw.print(allDrawn);
- pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
pw.println(")");
}
if (mStartingData != null || firstWindowDrawn) {
@@ -3665,13 +3661,6 @@ final class ActivityRecord extends WindowToken {
if (endTask) {
mAtmService.getLockTaskController().clearLockedTask(task);
- // This activity was in the top focused root task and this is the last
- // activity in that task, give this activity a higher layer so it can stay on
- // top before the closing task transition be executed.
- if (mayAdjustTop) {
- mNeedsZBoost = true;
- mDisplayContent.assignWindowLayers(false /* setLayoutNeeded */);
- }
}
} else if (!isState(PAUSING)) {
if (mVisibleRequested) {
@@ -5155,7 +5144,6 @@ final class ActivityRecord extends WindowToken {
void clearAllDrawn() {
allDrawn = false;
- mLastAllDrawn = false;
}
/**
@@ -6599,35 +6587,6 @@ final class ActivityRecord extends WindowToken {
nowVisible = false;
}
- @Override
- void checkAppWindowsReadyToShow() {
- if (allDrawn == mLastAllDrawn) {
- return;
- }
-
- mLastAllDrawn = allDrawn;
- if (!allDrawn) {
- return;
- }
-
- setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
-
- // We can now show all of the drawn windows!
- if (canShowWindows()) {
- showAllWindowsLocked();
- }
- }
-
- /**
- * This must be called while inside a transaction.
- */
- void showAllWindowsLocked() {
- forAllWindows(windowState -> {
- if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
- windowState.performShowLocked();
- }, false /* traverseTopToBottom */);
- }
-
void updateReportedVisibilityLocked() {
if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
final int count = mChildren.size();
@@ -7241,11 +7200,6 @@ final class ActivityRecord extends WindowToken {
}
@Override
- boolean needsZBoost() {
- return mNeedsZBoost || super.needsZBoost();
- }
-
- @Override
public SurfaceControl getAnimationLeashParent() {
// For transitions in the root pinned task (menu activity) we just let them occur as a child
// of the root pinned task.
@@ -9393,7 +9347,6 @@ final class ActivityRecord extends WindowToken {
proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
proto.write(ALL_DRAWN, allDrawn);
- proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
if (mStartingWindow != null) {
mStartingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
}
diff --git a/services/core/java/com/android/server/wm/AsyncRotationController.java b/services/core/java/com/android/server/wm/AsyncRotationController.java
index d3fd0e3199a3..f75b17fa1569 100644
--- a/services/core/java/com/android/server/wm/AsyncRotationController.java
+++ b/services/core/java/com/android/server/wm/AsyncRotationController.java
@@ -234,7 +234,7 @@ class AsyncRotationController extends FadeAnimationController implements Consume
}
for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
final Operation op = mTargetWindowTokens.valueAt(i);
- if (op.mIsCompletionPending || op.mAction == Operation.ACTION_SEAMLESS) {
+ if (op.mIsCompletionPending || op.mActions == Operation.ACTION_SEAMLESS) {
// Skip completed target. And seamless windows use the signal from blast sync.
continue;
}
@@ -264,17 +264,18 @@ class AsyncRotationController extends FadeAnimationController implements Consume
op.mDrawTransaction = null;
if (DEBUG) Slog.d(TAG, "finishOp merge transaction " + windowToken.getTopChild());
}
- if (op.mAction == Operation.ACTION_TOGGLE_IME) {
+ if (op.mActions == Operation.ACTION_TOGGLE_IME) {
if (DEBUG) Slog.d(TAG, "finishOp fade-in IME " + windowToken.getTopChild());
fadeWindowToken(true /* show */, windowToken, ANIMATION_TYPE_TOKEN_TRANSFORM,
(type, anim) -> mDisplayContent.getInsetsStateController()
.getImeSourceProvider().reportImeDrawnForOrganizer());
- } else if (op.mAction == Operation.ACTION_FADE) {
+ } else if ((op.mActions & Operation.ACTION_FADE) != 0) {
if (DEBUG) Slog.d(TAG, "finishOp fade-in " + windowToken.getTopChild());
// The previous animation leash will be dropped when preparing fade-in animation, so
// simply apply new animation without restoring the transformation.
fadeWindowToken(true /* show */, windowToken, ANIMATION_TYPE_TOKEN_TRANSFORM);
- } else if (op.isValidSeamless()) {
+ }
+ if (op.isValidSeamless()) {
if (DEBUG) Slog.d(TAG, "finishOp undo seamless " + windowToken.getTopChild());
final SurfaceControl.Transaction t = windowToken.getSyncTransaction();
clearTransform(t, op.mLeash);
@@ -339,7 +340,7 @@ class AsyncRotationController extends FadeAnimationController implements Consume
}
if (mTransitionOp == OP_APP_SWITCH && token.mTransitionController.inTransition()) {
final Operation op = mTargetWindowTokens.get(token);
- if (op != null && op.mAction == Operation.ACTION_FADE) {
+ if (op != null && op.mActions == Operation.ACTION_FADE) {
// Defer showing to onTransitionFinished().
if (DEBUG) Slog.d(TAG, "Defer completion " + token.getTopChild());
return false;
@@ -367,11 +368,12 @@ class AsyncRotationController extends FadeAnimationController implements Consume
for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
final WindowToken windowToken = mTargetWindowTokens.keyAt(i);
final Operation op = mTargetWindowTokens.valueAt(i);
- if (op.mAction == Operation.ACTION_FADE || op.mAction == Operation.ACTION_TOGGLE_IME) {
+ if ((op.mActions & Operation.ACTION_FADE) != 0
+ || op.mActions == Operation.ACTION_TOGGLE_IME) {
fadeWindowToken(false /* show */, windowToken, ANIMATION_TYPE_TOKEN_TRANSFORM);
op.mLeash = windowToken.getAnimationLeash();
if (DEBUG) Slog.d(TAG, "Start fade-out " + windowToken.getTopChild());
- } else if (op.mAction == Operation.ACTION_SEAMLESS) {
+ } else if (op.mActions == Operation.ACTION_SEAMLESS) {
op.mLeash = windowToken.mSurfaceControl;
if (DEBUG) Slog.d(TAG, "Start seamless " + windowToken.getTopChild());
}
@@ -481,13 +483,13 @@ class AsyncRotationController extends FadeAnimationController implements Consume
/** Returns {@code true} if the controller will run fade animations on the window. */
boolean hasFadeOperation(WindowToken token) {
final Operation op = mTargetWindowTokens.get(token);
- return op != null && op.mAction == Operation.ACTION_FADE;
+ return op != null && (op.mActions & Operation.ACTION_FADE) != 0;
}
/** Returns {@code true} if the window is un-rotated to original rotation. */
boolean hasSeamlessOperation(WindowToken token) {
final Operation op = mTargetWindowTokens.get(token);
- return op != null && op.mAction == Operation.ACTION_SEAMLESS;
+ return op != null && (op.mActions & Operation.ACTION_SEAMLESS) != 0;
}
/**
@@ -541,7 +543,7 @@ class AsyncRotationController extends FadeAnimationController implements Consume
final Operation op = mTargetWindowTokens.valueAt(i);
final SurfaceControl leash = op.mLeash;
if (leash == null || !leash.isValid()) continue;
- if (mHasScreenRotationAnimation && op.mAction == Operation.ACTION_FADE) {
+ if (mHasScreenRotationAnimation && op.mActions == Operation.ACTION_FADE) {
// Hide the windows immediately because a screenshot layer should cover the screen.
t.setAlpha(leash, 0f);
if (DEBUG) {
@@ -707,7 +709,7 @@ class AsyncRotationController extends FadeAnimationController implements Consume
* start transaction of rotation transition is applied.
*/
private boolean canDrawBeforeStartTransaction(Operation op) {
- return op.mAction != Operation.ACTION_SEAMLESS;
+ return (op.mActions & Operation.ACTION_SEAMLESS) == 0;
}
void dump(PrintWriter pw, String prefix) {
@@ -723,14 +725,14 @@ class AsyncRotationController extends FadeAnimationController implements Consume
/** The operation to control the rotation appearance associated with window token. */
private static class Operation {
@Retention(RetentionPolicy.SOURCE)
- @IntDef(value = { ACTION_SEAMLESS, ACTION_FADE, ACTION_TOGGLE_IME })
+ @IntDef(flag = true, value = { ACTION_SEAMLESS, ACTION_FADE, ACTION_TOGGLE_IME })
@interface Action {}
static final int ACTION_SEAMLESS = 1;
- static final int ACTION_FADE = 2;
- /** The action to toggle the IME window appearance */
- static final int ACTION_TOGGLE_IME = 3;
- final @Action int mAction;
+ static final int ACTION_FADE = 1 << 1;
+ /** The action to toggle the IME window appearance. It can only be used exclusively. */
+ static final int ACTION_TOGGLE_IME = 1 << 2;
+ final @Action int mActions;
/** The leash of window token. It can be animation leash or the token itself. */
SurfaceControl mLeash;
/** Whether the window is drawn before the transition starts. */
@@ -744,17 +746,17 @@ class AsyncRotationController extends FadeAnimationController implements Consume
*/
SurfaceControl.Transaction mDrawTransaction;
- Operation(@Action int action) {
- mAction = action;
+ Operation(@Action int actions) {
+ mActions = actions;
}
boolean isValidSeamless() {
- return mAction == ACTION_SEAMLESS && mLeash != null && mLeash.isValid();
+ return (mActions & ACTION_SEAMLESS) != 0 && mLeash != null && mLeash.isValid();
}
@Override
public String toString() {
- return "Operation{a=" + mAction + " pending=" + mIsCompletionPending + '}';
+ return "Operation{a=" + mActions + " pending=" + mIsCompletionPending + '}';
}
}
}
diff --git a/services/core/java/com/android/server/wm/DisplayArea.java b/services/core/java/com/android/server/wm/DisplayArea.java
index 6718ae435cd9..d7d5b44ed210 100644
--- a/services/core/java/com/android/server/wm/DisplayArea.java
+++ b/services/core/java/com/android/server/wm/DisplayArea.java
@@ -332,12 +332,6 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
}
@Override
- boolean needsZBoost() {
- // Z Boost should only happen at or below the ActivityStack level.
- return false;
- }
-
- @Override
boolean fillsParent() {
return true;
}
diff --git a/services/core/java/com/android/server/wm/OWNERS b/services/core/java/com/android/server/wm/OWNERS
index 243a5326b545..0989fc05e0bb 100644
--- a/services/core/java/com/android/server/wm/OWNERS
+++ b/services/core/java/com/android/server/wm/OWNERS
@@ -26,7 +26,7 @@ mcarli@google.com
per-file Background*Start* = set noparent
per-file Background*Start* = file:/BAL_OWNERS
per-file Background*Start* = ogunwale@google.com, louischang@google.com
-per-file BackgroundLaunchProcessController.java = file:/BAL_OWNERS
+per-file BackgroundLaunchProcessController*.java = file:/BAL_OWNERS
# File related to activity callers
per-file ActivityCallerState.java = file:/core/java/android/app/COMPONENT_CALLER_OWNERS
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 0531828be6d4..ec17d131958b 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -35,8 +35,6 @@ import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
-import static android.content.pm.ActivityInfo.FORCE_NON_RESIZE_APP;
-import static android.content.pm.ActivityInfo.FORCE_RESIZE_APP;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
@@ -51,7 +49,6 @@ import static android.view.Display.INVALID_DISPLAY;
import static android.view.SurfaceControl.METADATA_TASK_ID;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
-import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED;
import static android.view.WindowManager.TRANSIT_OPEN;
@@ -132,7 +129,6 @@ import android.app.IActivityController;
import android.app.PictureInPictureParams;
import android.app.TaskInfo;
import android.app.WindowConfiguration;
-import android.app.compat.CompatChanges;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -514,10 +510,16 @@ class Task extends TaskFragment {
boolean mIsPerceptible = false;
/**
- * Whether the compatibility overrides that change the resizability of the app should be allowed
- * for the specific app.
+ * Whether the task has been forced resizable, which is determined by the
+ * activity that started this task.
*/
- boolean mAllowForceResizeOverride = true;
+ private boolean mForceResizeOverride;
+
+ /**
+ * Whether the task has been forced non-resizable, which is determined by
+ * the activity that started this task.
+ */
+ private boolean mForceNonResizeOverride;
private static final int TRANSLUCENT_TIMEOUT_MSG = FIRST_ACTIVITY_TASK_MSG + 1;
@@ -675,7 +677,6 @@ class Task extends TaskFragment {
intent = _intent;
mMinWidth = minWidth;
mMinHeight = minHeight;
- updateAllowForceResizeOverride();
}
mAtmService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity);
mHandler = new ActivityTaskHandler(mTaskSupervisor.mLooper);
@@ -946,6 +947,7 @@ class Task extends TaskFragment {
mCallingPackage = r.launchedFromPackage;
mCallingFeatureId = r.launchedFromFeatureId;
setIntent(intent != null ? intent : r.intent, info != null ? info : r.info);
+ updateForceResizeOverrides(r);
}
setLockTaskAuth(r);
}
@@ -1038,7 +1040,6 @@ class Task extends TaskFragment {
mTaskSupervisor.mRecentTasks.remove(this);
mTaskSupervisor.mRecentTasks.add(this);
}
- updateAllowForceResizeOverride();
}
/** Sets the original minimal width and height. */
@@ -1855,15 +1856,14 @@ class Task extends TaskFragment {
-1 /* don't check PID */, -1 /* don't check UID */, this);
}
- private void updateAllowForceResizeOverride() {
- try {
- mAllowForceResizeOverride = mAtmService.mContext.getPackageManager().getPropertyAsUser(
- PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES,
- getBasePackageName(), null /* className */, mUserId).getBoolean();
- } catch (PackageManager.NameNotFoundException e) {
- // Package not found or property not defined, reset to default value.
- mAllowForceResizeOverride = true;
- }
+ private void updateForceResizeOverrides(@NonNull ActivityRecord r) {
+ final AppCompatResizeOverrides resizeOverrides = r.mAppCompatController
+ .getResizeOverrides();
+ mForceResizeOverride = resizeOverrides.shouldOverrideForceResizeApp()
+ || r.isUniversalResizeable()
+ || r.mAppCompatController.getAspectRatioOverrides()
+ .hasFullscreenOverride();
+ mForceNonResizeOverride = resizeOverrides.shouldOverrideForceNonResizeApp();
}
/**
@@ -2882,17 +2882,8 @@ class Task extends TaskFragment {
final boolean forceResizable = mAtmService.mForceResizableActivities
&& getActivityType() == ACTIVITY_TYPE_STANDARD;
if (forceResizable) return true;
-
- final UserHandle userHandle = UserHandle.getUserHandleForUid(mUserId);
- final boolean forceResizableOverride = mAllowForceResizeOverride
- && CompatChanges.isChangeEnabled(
- FORCE_RESIZE_APP, getBasePackageName(), userHandle);
- final boolean forceNonResizableOverride = mAllowForceResizeOverride
- && CompatChanges.isChangeEnabled(
- FORCE_NON_RESIZE_APP, getBasePackageName(), userHandle);
-
- if (forceNonResizableOverride) return false;
- return forceResizableOverride || ActivityInfo.isResizeableMode(mResizeMode)
+ if (mForceNonResizeOverride) return false;
+ return mForceResizeOverride || ActivityInfo.isResizeableMode(mResizeMode)
|| (mSupportsPictureInPicture && checkPictureInPictureSupport);
}
@@ -3633,43 +3624,39 @@ class Task extends TaskFragment {
int layer = 0;
boolean decorSurfacePlaced = false;
- // We use two passes as a way to promote children which
- // need Z-boosting to the end of the list.
for (int j = 0; j < mChildren.size(); ++j) {
final WindowContainer wc = mChildren.get(j);
wc.assignChildLayers(t);
- if (!wc.needsZBoost()) {
- // Place the decor surface under any untrusted content.
- if (mDecorSurfaceContainer != null
- && !mDecorSurfaceContainer.mIsBoosted
- && !decorSurfacePlaced
- && shouldPlaceDecorSurfaceBelowContainer(wc)) {
- mDecorSurfaceContainer.assignLayer(t, layer++);
- decorSurfacePlaced = true;
- }
- wc.assignLayer(t, layer++);
-
- // Boost the adjacent TaskFragment for dimmer if needed.
- final TaskFragment taskFragment = wc.asTaskFragment();
- if (taskFragment != null && taskFragment.isEmbedded()
- && taskFragment.hasAdjacentTaskFragment()) {
- final int[] nextLayer = { layer };
- taskFragment.forOtherAdjacentTaskFragments(adjacentTf -> {
- if (adjacentTf.shouldBoostDimmer()) {
- adjacentTf.assignLayer(t, nextLayer[0]++);
- }
- });
- layer = nextLayer[0];
- }
+ // Place the decor surface under any untrusted content.
+ if (mDecorSurfaceContainer != null
+ && !mDecorSurfaceContainer.mIsBoosted
+ && !decorSurfacePlaced
+ && shouldPlaceDecorSurfaceBelowContainer(wc)) {
+ mDecorSurfaceContainer.assignLayer(t, layer++);
+ decorSurfacePlaced = true;
+ }
+ wc.assignLayer(t, layer++);
+
+ // Boost the adjacent TaskFragment for dimmer if needed.
+ final TaskFragment taskFragment = wc.asTaskFragment();
+ if (taskFragment != null && taskFragment.isEmbedded()
+ && taskFragment.hasAdjacentTaskFragment()) {
+ final int[] nextLayer = { layer };
+ taskFragment.forOtherAdjacentTaskFragments(adjacentTf -> {
+ if (adjacentTf.shouldBoostDimmer()) {
+ adjacentTf.assignLayer(t, nextLayer[0]++);
+ }
+ });
+ layer = nextLayer[0];
+ }
- // Place the decor surface just above the owner TaskFragment.
- if (mDecorSurfaceContainer != null
- && !mDecorSurfaceContainer.mIsBoosted
- && !decorSurfacePlaced
- && wc == mDecorSurfaceContainer.mOwnerTaskFragment) {
- mDecorSurfaceContainer.assignLayer(t, layer++);
- decorSurfacePlaced = true;
- }
+ // Place the decor surface just above the owner TaskFragment.
+ if (mDecorSurfaceContainer != null
+ && !mDecorSurfaceContainer.mIsBoosted
+ && !decorSurfacePlaced
+ && wc == mDecorSurfaceContainer.mOwnerTaskFragment) {
+ mDecorSurfaceContainer.assignLayer(t, layer++);
+ decorSurfacePlaced = true;
}
}
@@ -3679,12 +3666,6 @@ class Task extends TaskFragment {
mDecorSurfaceContainer.assignLayer(t, layer++);
}
- for (int j = 0; j < mChildren.size(); ++j) {
- final WindowContainer wc = mChildren.get(j);
- if (wc.needsZBoost()) {
- wc.assignLayer(t, layer++);
- }
- }
if (mOverlayHost != null) {
mOverlayHost.setLayer(t, layer++);
}
diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java
index fb7bab4b3e26..1de139696c07 100644
--- a/services/core/java/com/android/server/wm/TaskDisplayArea.java
+++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java
@@ -48,7 +48,6 @@ import android.content.pm.ActivityInfo.ScreenOrientation;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.UserHandle;
-import android.util.IntArray;
import android.util.Slog;
import android.view.SurfaceControl;
import android.view.WindowManager;
@@ -102,9 +101,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
private final ArrayList<WindowContainer> mTmpAlwaysOnTopChildren = new ArrayList<>();
private final ArrayList<WindowContainer> mTmpNormalChildren = new ArrayList<>();
private final ArrayList<WindowContainer> mTmpHomeChildren = new ArrayList<>();
- private final IntArray mTmpNeedsZBoostIndexes = new IntArray();
-
- private ArrayList<Task> mTmpTasks = new ArrayList<>();
private ActivityTaskManagerService mAtmService;
@@ -740,40 +736,14 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
*/
private int adjustRootTaskLayer(SurfaceControl.Transaction t,
ArrayList<WindowContainer> children, int startLayer) {
- mTmpNeedsZBoostIndexes.clear();
final int childCount = children.size();
- boolean hasAdjacentTask = false;
for (int i = 0; i < childCount; i++) {
final WindowContainer child = children.get(i);
- final TaskDisplayArea childTda = child.asTaskDisplayArea();
- final boolean childNeedsZBoost = childTda != null
- ? childTda.childrenNeedZBoost()
- : child.needsZBoost();
-
- if (childNeedsZBoost) {
- mTmpNeedsZBoostIndexes.add(i);
- continue;
- }
-
- child.assignLayer(t, startLayer++);
- }
-
- final int zBoostSize = mTmpNeedsZBoostIndexes.size();
- for (int i = 0; i < zBoostSize; i++) {
- final WindowContainer child = children.get(mTmpNeedsZBoostIndexes.get(i));
child.assignLayer(t, startLayer++);
}
return startLayer;
}
- private boolean childrenNeedZBoost() {
- final boolean[] needsZBoost = new boolean[1];
- forAllRootTasks(task -> {
- needsZBoost[0] |= task.needsZBoost();
- });
- return needsZBoost[0];
- }
-
void setBackgroundColor(@ColorInt int colorInt) {
setBackgroundColor(colorInt, false /* restore */);
}
diff --git a/services/core/java/com/android/server/wm/TaskFpsCallbackController.java b/services/core/java/com/android/server/wm/TaskFpsCallbackController.java
index 8c798759c890..665c5cffd9ff 100644
--- a/services/core/java/com/android/server/wm/TaskFpsCallbackController.java
+++ b/services/core/java/com/android/server/wm/TaskFpsCallbackController.java
@@ -16,7 +16,6 @@
package com.android.server.wm;
-import android.content.Context;
import android.os.IBinder;
import android.os.RemoteException;
import android.window.ITaskFpsCallback;
@@ -25,12 +24,10 @@ import java.util.HashMap;
final class TaskFpsCallbackController {
- private final Context mContext;
private final HashMap<IBinder, Long> mTaskFpsCallbacks;
private final HashMap<IBinder, IBinder.DeathRecipient> mDeathRecipients;
- TaskFpsCallbackController(Context context) {
- mContext = context;
+ TaskFpsCallbackController() {
mTaskFpsCallbacks = new HashMap<>();
mDeathRecipients = new HashMap<>();
}
diff --git a/services/core/java/com/android/server/wm/WindowAnimator.java b/services/core/java/com/android/server/wm/WindowAnimator.java
index 3f2b40c1d7c9..e50545d41655 100644
--- a/services/core/java/com/android/server/wm/WindowAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowAnimator.java
@@ -18,10 +18,7 @@ package com.android.server.wm;
import static com.android.internal.protolog.WmProtoLogGroups.WM_SHOW_TRANSACTIONS;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_ALL;
-import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
-import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_SCREEN_ROTATION;
import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN;
-import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
@@ -57,9 +54,6 @@ public class WindowAnimator {
/** Is any window animating? */
private boolean mLastRootAnimating;
- /** True if we are running any animations that require expensive composition. */
- private boolean mRunningExpensiveAnimations;
-
final Choreographer.FrameCallback mAnimationFrameCallback;
/** Time of current animation step. Reset on each iteration */
@@ -138,8 +132,6 @@ public class WindowAnimator {
scheduleAnimation();
final RootWindowContainer root = mService.mRoot;
- final boolean useShellTransition = root.mTransitionController.isShellTransitionsEnabled();
- final int animationFlags = useShellTransition ? CHILDREN : (TRANSITION | CHILDREN);
boolean rootAnimating = false;
mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS;
if (DEBUG_WINDOW_TRACE) {
@@ -164,17 +156,13 @@ public class WindowAnimator {
for (int i = 0; i < numDisplays; i++) {
final DisplayContent dc = root.getChildAt(i);
-
- if (!useShellTransition) {
- dc.checkAppWindowsReadyToShow();
- }
if (accessibilityController.hasCallbacks()) {
accessibilityController
.recomputeMagnifiedRegionAndDrawMagnifiedRegionBorderIfNeeded(
dc.mDisplayId);
}
- if (dc.isAnimating(animationFlags, ANIMATION_TYPE_ALL)) {
+ if (dc.isAnimating(CHILDREN, ANIMATION_TYPE_ALL)) {
rootAnimating = true;
if (!dc.mLastContainsRunningSurfaceAnimator) {
dc.mLastContainsRunningSurfaceAnimator = true;
@@ -211,11 +199,6 @@ public class WindowAnimator {
}
mLastRootAnimating = rootAnimating;
- // APP_TRANSITION, SCREEN_ROTATION, TYPE_RECENTS are handled by shell transition.
- if (!useShellTransition) {
- updateRunningExpensiveAnimationsLegacy();
- }
-
final ArrayList<Runnable> afterPrepareSurfacesRunnables = mAfterPrepareSurfacesRunnables;
if (!afterPrepareSurfacesRunnables.isEmpty()) {
mAfterPrepareSurfacesRunnables = new ArrayList<>();
@@ -244,21 +227,6 @@ public class WindowAnimator {
}
}
- private void updateRunningExpensiveAnimationsLegacy() {
- final boolean runningExpensiveAnimations =
- mService.mRoot.isAnimating(TRANSITION | CHILDREN /* flags */,
- ANIMATION_TYPE_APP_TRANSITION
- | ANIMATION_TYPE_SCREEN_ROTATION /* typesToCheck */);
- if (runningExpensiveAnimations && !mRunningExpensiveAnimations) {
- mService.mSnapshotController.setPause(true);
- mTransaction.setEarlyWakeupStart();
- } else if (!runningExpensiveAnimations && mRunningExpensiveAnimations) {
- mService.mSnapshotController.setPause(false);
- mTransaction.setEarlyWakeupEnd();
- }
- mRunningExpensiveAnimations = runningExpensiveAnimations;
- }
-
public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) {
final String subPrefix = " " + prefix;
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 5cbba355a06f..5b4870b0c0c7 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -279,9 +279,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
*/
int mTransitFlags;
- /** Whether this container should be boosted at the top of all its siblings. */
- @VisibleForTesting boolean mNeedsZBoost;
-
/** Layer used to constrain the animation to a container's stack bounds. */
SurfaceControl mAnimationBoundsLayer;
@@ -1476,14 +1473,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
return stillDeferringRemoval;
}
- /** Checks if all windows in an app are all drawn and shows them if needed. */
- void checkAppWindowsReadyToShow() {
- for (int i = mChildren.size() - 1; i >= 0; --i) {
- final WindowContainer wc = mChildren.get(i);
- wc.checkAppWindowsReadyToShow();
- }
- }
-
/**
* Called when this container or one of its descendants changed its requested orientation, and
* wants this container to handle it or pass it to its parent.
@@ -2744,15 +2733,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
for (int j = 0; j < mChildren.size(); ++j) {
final WindowContainer wc = mChildren.get(j);
wc.assignChildLayers(t);
- if (!wc.needsZBoost()) {
- wc.assignLayer(t, layer++);
- }
- }
- for (int j = 0; j < mChildren.size(); ++j) {
- final WindowContainer wc = mChildren.get(j);
- if (wc.needsZBoost()) {
- wc.assignLayer(t, layer++);
- }
+ wc.assignLayer(t, layer++);
}
if (mOverlayHost != null) {
mOverlayHost.setLayer(t, layer++);
@@ -2764,16 +2745,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
scheduleAnimation();
}
- boolean needsZBoost() {
- if (mNeedsZBoost) return true;
- for (int i = 0; i < mChildren.size(); i++) {
- if (mChildren.get(i).needsZBoost()) {
- return true;
- }
- }
- return false;
- }
-
/**
* Write to a protocol buffer output stream. Protocol buffer message definition is at
* {@link com.android.server.wm.WindowContainerProto}.
@@ -3114,7 +3085,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
public void onAnimationLeashLost(Transaction t) {
mLastLayer = -1;
mAnimationLeash = null;
- mNeedsZBoost = false;
reassignLayer(t);
updateSurfacePosition(t);
}
@@ -3140,7 +3110,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
protected void onAnimationFinished(@AnimationType int type, AnimationAdapter anim) {
doAnimationFinished(type, anim);
mWmService.onAnimationFinished();
- mNeedsZBoost = false;
}
/**
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index fb38c581d222..a9bb690d4e53 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -1449,7 +1449,7 @@ public class WindowManagerService extends IWindowManager.Stub
mPresentationController = new PresentationController();
mBlurController = new BlurController(mContext, mPowerManager);
- mTaskFpsCallbackController = new TaskFpsCallbackController(mContext);
+ mTaskFpsCallbackController = new TaskFpsCallbackController();
mAccessibilityController = new AccessibilityController(this);
mScreenRecordingCallbackController = new ScreenRecordingCallbackController(this);
mSystemPerformanceHinter = new SystemPerformanceHinter(mContext, displayId -> {
@@ -2602,6 +2602,14 @@ public class WindowManagerService extends IWindowManager.Stub
// in the new out values right now we need to force a layout.
mWindowPlacerLocked.performSurfacePlacement(true /* force */);
+ if (!win.mHaveFrame && displayContent.mWaitingForConfig) {
+ // We just forcibly triggered the layout, but this could still be intercepted by
+ // mWaitingForConfig. Here, we are forcefully marking a value for mLayoutSeq to
+ // ensure that the resize can occur properly later. Otherwise, the window's frame
+ // will remain empty forever.
+ win.mLayoutSeq = displayContent.mLayoutSeq;
+ }
+
if (shouldRelayout) {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "relayoutWindow: viewVisibility_1");
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index af5200102fc0..22ddd5f39b24 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -4995,18 +4995,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
return true;
}
- @Override
- boolean needsZBoost() {
- final InsetsControlTarget target = getDisplayContent().getImeTarget(IME_TARGET_LAYERING);
- if (mIsImWindow && target != null) {
- final ActivityRecord activity = target.getWindow().mActivityRecord;
- if (activity != null) {
- return activity.needsZBoost();
- }
- }
- return false;
- }
-
private boolean isStartingWindowAssociatedToTask() {
return mStartingData != null && mStartingData.mAssociatedTask != null;
}
diff --git a/services/tests/displayservicetests/Android.bp b/services/tests/displayservicetests/Android.bp
index 36ea24195789..c85053d13e68 100644
--- a/services/tests/displayservicetests/Android.bp
+++ b/services/tests/displayservicetests/Android.bp
@@ -51,6 +51,7 @@ android_test {
data: [
":DisplayManagerTestApp",
+ ":TopologyTestApp",
],
certificate: "platform",
diff --git a/services/tests/displayservicetests/AndroidManifest.xml b/services/tests/displayservicetests/AndroidManifest.xml
index 205ff058275a..76f219b7433b 100644
--- a/services/tests/displayservicetests/AndroidManifest.xml
+++ b/services/tests/displayservicetests/AndroidManifest.xml
@@ -29,6 +29,7 @@
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.MANAGE_USB" />
+ <uses-permission android:name="android.permission.MANAGE_DISPLAYS" />
<!-- Permissions needed for DisplayTransformManagerTest -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
diff --git a/services/tests/displayservicetests/AndroidTest.xml b/services/tests/displayservicetests/AndroidTest.xml
index f3697bbffd5c..2fe37233870f 100644
--- a/services/tests/displayservicetests/AndroidTest.xml
+++ b/services/tests/displayservicetests/AndroidTest.xml
@@ -28,6 +28,7 @@
<option name="cleanup-apks" value="true" />
<option name="install-arg" value="-t" />
<option name="test-file-name" value="DisplayManagerTestApp.apk" />
+ <option name="test-file-name" value="TopologyTestApp.apk" />
</target_preparer>
<option name="test-tag" value="DisplayServiceTests" />
diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayEventDeliveryTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayEventDeliveryTest.java
index 1f45792e5097..bf4b61347bab 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/DisplayEventDeliveryTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayEventDeliveryTest.java
@@ -16,7 +16,6 @@
package com.android.server.display;
-import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
import static android.util.DisplayMetrics.DENSITY_HIGH;
@@ -27,19 +26,11 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
-import android.app.ActivityManager;
-import android.app.Instrumentation;
-import android.content.Context;
import android.content.Intent;
-import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
-import android.os.BinderProxy;
import android.os.Handler;
-import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
-import android.os.Messenger;
-import android.platform.test.annotations.AppModeSdkSandbox;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
@@ -48,10 +39,7 @@ import android.util.SparseArray;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
-import androidx.test.platform.app.InstrumentationRegistry;
-import com.android.compatibility.common.util.SystemUtil;
-import com.android.compatibility.common.util.TestUtils;
import com.android.server.am.Flags;
import org.junit.After;
@@ -63,9 +51,7 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
-import java.io.IOException;
import java.util.Arrays;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -73,8 +59,7 @@ import java.util.concurrent.TimeUnit;
* Tests that applications can receive display events correctly.
*/
@RunWith(Parameterized.class)
-@AppModeSdkSandbox(reason = "Allow test in the SDK sandbox (does not prevent other modes).")
-public class DisplayEventDeliveryTest {
+public class DisplayEventDeliveryTest extends EventDeliveryTestBase {
private static final String TAG = "DisplayEventDeliveryTest";
@Rule
@@ -85,37 +70,17 @@ public class DisplayEventDeliveryTest {
private static final int WIDTH = 720;
private static final int HEIGHT = 480;
- private static final int MESSAGE_LAUNCHED = 1;
- private static final int MESSAGE_CALLBACK = 2;
-
private static final int DISPLAY_ADDED = 1;
private static final int DISPLAY_CHANGED = 2;
private static final int DISPLAY_REMOVED = 3;
- private static final long DISPLAY_EVENT_TIMEOUT_MSEC = 100;
- private static final long TEST_FAILURE_TIMEOUT_MSEC = 10000;
-
private static final String TEST_PACKAGE =
"com.android.servicestests.apps.displaymanagertestapp";
private static final String TEST_ACTIVITY = TEST_PACKAGE + ".DisplayEventActivity";
private static final String TEST_DISPLAYS = "DISPLAYS";
- private static final String TEST_MESSENGER = "MESSENGER";
private final Object mLock = new Object();
- private Instrumentation mInstrumentation;
- private Context mContext;
- private DisplayManager mDisplayManager;
- private ActivityManager mActivityManager;
- private ActivityManager.OnUidImportanceListener mUidImportanceListener;
- private CountDownLatch mLatchActivityLaunch;
- private CountDownLatch mLatchActivityCached;
- private HandlerThread mHandlerThread;
- private Handler mHandler;
- private Messenger mMessenger;
- private int mPid;
- private int mUid;
-
/**
* Array of DisplayBundle. The test handler uses it to check if certain display events have
* been sent to DisplayEventActivity.
@@ -167,7 +132,7 @@ public class DisplayEventDeliveryTest {
*/
public void assertNoDisplayEvents() {
try {
- assertNull(mExpectations.poll(DISPLAY_EVENT_TIMEOUT_MSEC, TimeUnit.MILLISECONDS));
+ assertNull(mExpectations.poll(EVENT_TIMEOUT_MSEC, TimeUnit.MILLISECONDS));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -239,37 +204,17 @@ public class DisplayEventDeliveryTest {
}
@Before
- public void setUp() throws Exception {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- mContext = mInstrumentation.getContext();
- mDisplayManager = mContext.getSystemService(DisplayManager.class);
- mLatchActivityLaunch = new CountDownLatch(1);
- mLatchActivityCached = new CountDownLatch(1);
- mActivityManager = mContext.getSystemService(ActivityManager.class);
- mUidImportanceListener = (uid, importance) -> {
- if (uid == mUid && importance == IMPORTANCE_CACHED) {
- Log.d(TAG, "Listener " + uid + " becomes " + importance);
- mLatchActivityCached.countDown();
- }
- };
- SystemUtil.runWithShellPermissionIdentity(() ->
- mActivityManager.addOnUidImportanceListener(mUidImportanceListener,
- IMPORTANCE_CACHED));
+ public void setUp() {
+ super.setUp();
// The lock is not functionally necessary but eliminates lint error messages.
synchronized (mLock) {
mDisplayBundles = new SparseArray<>();
}
- mHandlerThread = new HandlerThread("handler");
- mHandlerThread.start();
- mHandler = new TestHandler(mHandlerThread.getLooper());
- mMessenger = new Messenger(mHandler);
- mPid = 0;
}
@After
public void tearDown() throws Exception {
- mActivityManager.removeOnUidImportanceListener(mUidImportanceListener);
- mHandlerThread.quitSafely();
+ super.tearDown();
synchronized (mLock) {
for (int i = 0; i < mDisplayBundles.size(); i++) {
DisplayBundle bundle = mDisplayBundles.valueAt(i);
@@ -278,7 +223,31 @@ public class DisplayEventDeliveryTest {
}
mDisplayBundles.clear();
}
- SystemUtil.runShellCommand(mInstrumentation, "am force-stop " + TEST_PACKAGE);
+ }
+
+ @Override
+ protected String getTag() {
+ return TAG;
+ }
+
+ @Override
+ protected Handler getHandler(Looper looper) {
+ return new TestHandler(looper);
+ }
+
+ @Override
+ protected String getTestPackage() {
+ return TEST_PACKAGE;
+ }
+
+ @Override
+ protected String getTestActivity() {
+ return TEST_ACTIVITY;
+ }
+
+ @Override
+ protected void putExtra(Intent intent) {
+ intent.putExtra(TEST_DISPLAYS, mDisplayCount);
}
/**
@@ -291,42 +260,8 @@ public class DisplayEventDeliveryTest {
}
/**
- * Return true if the freezer is enabled on this platform and if freezer notifications are
- * supported. It is not enough to test that the freezer notification feature is enabled
- * because some devices do not have the necessary kernel support.
- */
- private boolean isAppFreezerEnabled() {
- try {
- return mActivityManager.getService().isAppFreezerEnabled()
- && android.os.Flags.binderFrozenStateChangeCallback()
- && BinderProxy.isFrozenStateChangeCallbackSupported();
- } catch (Exception e) {
- Log.e(TAG, "isAppFreezerEnabled() failed: " + e);
- return false;
- }
- }
-
- private void waitForProcessFreeze(int pid, long timeoutMs) {
- // TODO: Add a listener to monitor freezer state changes.
- SystemUtil.runWithShellPermissionIdentity(() -> {
- TestUtils.waitUntil("Timed out waiting for test process to be frozen; pid=" + pid,
- (int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs),
- () -> mActivityManager.isProcessFrozen(pid));
- });
- }
-
- private void waitForProcessUnfreeze(int pid, long timeoutMs) {
- // TODO: Add a listener to monitor freezer state changes.
- SystemUtil.runWithShellPermissionIdentity(() -> {
- TestUtils.waitUntil("Timed out waiting for test process to be frozen; pid=" + pid,
- (int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs),
- () -> !mActivityManager.isProcessFrozen(pid));
- });
- }
-
- /**
- * Create virtual displays, change their configurations and release them. The number of
- * displays is set by the {@link #mDisplays} variable.
+ * Create virtual displays, change their configurations and release them. The number of
+ * displays is set by the {@link #data()} parameter.
*/
private void testDisplayEventsInternal(boolean cached, boolean frozen) {
Log.d(TAG, "Start test testDisplayEvents " + mDisplayCount + " " + cached + " " + frozen);
@@ -445,110 +380,6 @@ public class DisplayEventDeliveryTest {
}
/**
- * Launch the test activity that would listen to display events. Return its process ID.
- */
- private int launchTestActivity() {
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.setClassName(TEST_PACKAGE, TEST_ACTIVITY);
- intent.putExtra(TEST_MESSENGER, mMessenger);
- intent.putExtra(TEST_DISPLAYS, mDisplayCount);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- SystemUtil.runWithShellPermissionIdentity(
- () -> {
- mContext.startActivity(intent);
- },
- android.Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX);
- waitLatch(mLatchActivityLaunch);
-
- try {
- String cmd = "pidof " + TEST_PACKAGE;
- String result = SystemUtil.runShellCommand(mInstrumentation, cmd);
- return Integer.parseInt(result.trim());
- } catch (IOException e) {
- fail("failed to get pid of test package");
- return 0;
- } catch (NumberFormatException e) {
- fail("failed to parse pid " + e);
- return 0;
- }
- }
-
- /**
- * Bring the test activity back to top
- */
- private void bringTestActivityTop() {
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.setClassName(TEST_PACKAGE, TEST_ACTIVITY);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- SystemUtil.runWithShellPermissionIdentity(
- () -> {
- mContext.startActivity(intent);
- },
- android.Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX);
- }
-
- /**
- * Bring the test activity into cached mode by launching another 2 apps
- */
- private void makeTestActivityCached() {
- // Launch another activity to bring the test activity into background
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.setClass(mContext, SimpleActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
-
- // Launch another activity to bring the test activity into cached mode
- Intent intent2 = new Intent(Intent.ACTION_MAIN);
- intent2.setClass(mContext, SimpleActivity2.class);
- intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- SystemUtil.runWithShellPermissionIdentity(
- () -> {
- mInstrumentation.startActivitySync(intent);
- mInstrumentation.startActivitySync(intent2);
- },
- android.Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX);
- waitLatch(mLatchActivityCached);
- }
-
- // Sleep, ignoring interrupts.
- private void pause(int s) {
- try { Thread.sleep(s * 1000); } catch (Exception e) { }
- }
-
- /**
- * Freeze the test activity.
- */
- private void makeTestActivityFrozen(int pid) {
- // The delay here is meant to allow pending binder transactions to drain. A process
- // cannot be frozen if it has pending binder transactions, and attempting to freeze such a
- // process more than a few times will result in the system killing the process.
- pause(5);
- try {
- String cmd = "am freeze --sticky ";
- SystemUtil.runShellCommand(mInstrumentation, cmd + TEST_PACKAGE);
- } catch (IOException e) {
- fail(e.toString());
- }
- // Wait for the freeze to complete in the kernel and for the frozen process
- // notification to settle out.
- waitForProcessFreeze(pid, 5 * 1000);
- }
-
- /**
- * Freeze the test activity.
- */
- private void makeTestActivityUnfrozen(int pid) {
- try {
- String cmd = "am unfreeze --sticky ";
- SystemUtil.runShellCommand(mInstrumentation, cmd + TEST_PACKAGE);
- } catch (IOException e) {
- fail(e.toString());
- }
- // Wait for the freeze to complete in the kernel and for the frozen process
- // notification to settle out.
- waitForProcessUnfreeze(pid, 5 * 1000);
- }
-
- /**
* Create a virtual display
*
* @param name The name of the new virtual display
@@ -560,15 +391,4 @@ public class DisplayEventDeliveryTest {
VIRTUAL_DISPLAY_FLAG_PUBLIC | VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
/* flags: a public virtual display that another app can access */);
}
-
- /**
- * Wait for CountDownLatch with timeout
- */
- private void waitLatch(CountDownLatch latch) {
- try {
- latch.await(TEST_FAILURE_TIMEOUT_MSEC, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
}
diff --git a/services/tests/displayservicetests/src/com/android/server/display/EventDeliveryTestBase.java b/services/tests/displayservicetests/src/com/android/server/display/EventDeliveryTestBase.java
new file mode 100644
index 000000000000..2911b9bb35c7
--- /dev/null
+++ b/services/tests/displayservicetests/src/com/android/server/display/EventDeliveryTestBase.java
@@ -0,0 +1,259 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.display;
+
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
+
+import static org.junit.Assert.fail;
+
+import android.app.ActivityManager;
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.hardware.display.DisplayManager;
+import android.os.BinderProxy;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Messenger;
+import android.platform.test.annotations.AppModeSdkSandbox;
+import android.util.Log;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.compatibility.common.util.SystemUtil;
+import com.android.compatibility.common.util.TestUtils;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+@AppModeSdkSandbox(reason = "Allow test in the SDK sandbox (does not prevent other modes).")
+public abstract class EventDeliveryTestBase {
+ protected static final int MESSAGE_LAUNCHED = 1;
+ protected static final int MESSAGE_CALLBACK = 2;
+
+ protected static final long EVENT_TIMEOUT_MSEC = 100;
+ protected static final long TEST_FAILURE_TIMEOUT_MSEC = 10000;
+
+ private static final String TEST_MESSENGER = "MESSENGER";
+
+ private Instrumentation mInstrumentation;
+ private Context mContext;
+ protected DisplayManager mDisplayManager;
+ private ActivityManager mActivityManager;
+ private ActivityManager.OnUidImportanceListener mUidImportanceListener;
+ protected CountDownLatch mLatchActivityLaunch;
+ private CountDownLatch mLatchActivityCached;
+ private HandlerThread mHandlerThread;
+ private Handler mHandler;
+ private Messenger mMessenger;
+ protected int mPid;
+ protected int mUid;
+
+ protected abstract String getTag();
+
+ protected abstract Handler getHandler(Looper looper);
+
+ protected abstract String getTestPackage();
+
+ protected abstract String getTestActivity();
+
+ protected abstract void putExtra(Intent intent);
+
+ protected void setUp() {
+ mInstrumentation = InstrumentationRegistry.getInstrumentation();
+ mContext = mInstrumentation.getContext();
+ mDisplayManager = mContext.getSystemService(DisplayManager.class);
+ mLatchActivityLaunch = new CountDownLatch(1);
+ mLatchActivityCached = new CountDownLatch(1);
+ mActivityManager = mContext.getSystemService(ActivityManager.class);
+ mUidImportanceListener = (uid, importance) -> {
+ if (uid == mUid && importance == IMPORTANCE_CACHED) {
+ Log.d(getTag(), "Listener " + uid + " becomes " + importance);
+ mLatchActivityCached.countDown();
+ }
+ };
+ SystemUtil.runWithShellPermissionIdentity(() ->
+ mActivityManager.addOnUidImportanceListener(mUidImportanceListener,
+ IMPORTANCE_CACHED));
+ mHandlerThread = new HandlerThread("handler");
+ mHandlerThread.start();
+ mHandler = getHandler(mHandlerThread.getLooper());
+ mMessenger = new Messenger(mHandler);
+ mPid = 0;
+ }
+
+ protected void tearDown() throws Exception {
+ mActivityManager.removeOnUidImportanceListener(mUidImportanceListener);
+ mHandlerThread.quitSafely();
+ SystemUtil.runShellCommand(mInstrumentation, "am force-stop " + getTestPackage());
+ }
+
+ /**
+ * Return true if the freezer is enabled on this platform and if freezer notifications are
+ * supported. It is not enough to test that the freezer notification feature is enabled
+ * because some devices do not have the necessary kernel support.
+ */
+ protected boolean isAppFreezerEnabled() {
+ try {
+ return ActivityManager.getService().isAppFreezerEnabled()
+ && android.os.Flags.binderFrozenStateChangeCallback()
+ && BinderProxy.isFrozenStateChangeCallbackSupported();
+ } catch (Exception e) {
+ Log.e(getTag(), "isAppFreezerEnabled() failed: " + e);
+ return false;
+ }
+ }
+
+ private void waitForProcessFreeze(int pid, long timeoutMs) {
+ // TODO: Add a listener to monitor freezer state changes.
+ SystemUtil.runWithShellPermissionIdentity(() -> {
+ TestUtils.waitUntil(
+ "Timed out waiting for test process to be frozen; pid=" + pid,
+ (int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs),
+ () -> mActivityManager.isProcessFrozen(pid));
+ });
+ }
+
+ private void waitForProcessUnfreeze(int pid, long timeoutMs) {
+ // TODO: Add a listener to monitor freezer state changes.
+ SystemUtil.runWithShellPermissionIdentity(() -> {
+ TestUtils.waitUntil("Timed out waiting for test process to be frozen; pid=" + pid,
+ (int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs),
+ () -> !mActivityManager.isProcessFrozen(pid));
+ });
+ }
+
+ /**
+ * Launch the test activity that would listen to events. Return its process ID.
+ */
+ protected int launchTestActivity() {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setClassName(getTestPackage(), getTestActivity());
+ intent.putExtra(TEST_MESSENGER, mMessenger);
+ putExtra(intent);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ SystemUtil.runWithShellPermissionIdentity(
+ () -> {
+ mContext.startActivity(intent);
+ },
+ android.Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX);
+ waitLatch(mLatchActivityLaunch);
+
+ try {
+ String cmd = "pidof " + getTestPackage();
+ String result = SystemUtil.runShellCommand(mInstrumentation, cmd);
+ return Integer.parseInt(result.trim());
+ } catch (IOException e) {
+ fail("failed to get pid of test package");
+ return 0;
+ } catch (NumberFormatException e) {
+ fail("failed to parse pid " + e);
+ return 0;
+ }
+ }
+
+ /**
+ * Bring the test activity back to top
+ */
+ protected void bringTestActivityTop() {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setClassName(getTestPackage(), getTestActivity());
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ SystemUtil.runWithShellPermissionIdentity(
+ () -> {
+ mContext.startActivity(intent);
+ },
+ android.Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX);
+ }
+
+
+ /**
+ * Bring the test activity into cached mode by launching another 2 apps
+ */
+ protected void makeTestActivityCached() {
+ // Launch another activity to bring the test activity into background
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setClass(mContext, SimpleActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+
+ // Launch another activity to bring the test activity into cached mode
+ Intent intent2 = new Intent(Intent.ACTION_MAIN);
+ intent2.setClass(mContext, SimpleActivity2.class);
+ intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ SystemUtil.runWithShellPermissionIdentity(
+ () -> {
+ mInstrumentation.startActivitySync(intent);
+ mInstrumentation.startActivitySync(intent2);
+ },
+ android.Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX);
+ waitLatch(mLatchActivityCached);
+ }
+
+ // Sleep, ignoring interrupts.
+ private void pause(int s) {
+ try {
+ Thread.sleep(s * 1000L);
+ } catch (Exception ignored) { }
+ }
+
+ /**
+ * Freeze the test activity.
+ */
+ protected void makeTestActivityFrozen(int pid) {
+ // The delay here is meant to allow pending binder transactions to drain. A process
+ // cannot be frozen if it has pending binder transactions, and attempting to freeze such a
+ // process more than a few times will result in the system killing the process.
+ pause(5);
+ try {
+ String cmd = "am freeze --sticky ";
+ SystemUtil.runShellCommand(mInstrumentation, cmd + getTestPackage());
+ } catch (IOException e) {
+ fail(e.toString());
+ }
+ // Wait for the freeze to complete in the kernel and for the frozen process
+ // notification to settle out.
+ waitForProcessFreeze(pid, 5 * 1000);
+ }
+
+ /**
+ * Freeze the test activity.
+ */
+ protected void makeTestActivityUnfrozen(int pid) {
+ try {
+ String cmd = "am unfreeze --sticky ";
+ SystemUtil.runShellCommand(mInstrumentation, cmd + getTestPackage());
+ } catch (IOException e) {
+ fail(e.toString());
+ }
+ // Wait for the freeze to complete in the kernel and for the frozen process
+ // notification to settle out.
+ waitForProcessUnfreeze(pid, 5 * 1000);
+ }
+
+ /**
+ * Wait for CountDownLatch with timeout
+ */
+ private void waitLatch(CountDownLatch latch) {
+ try {
+ latch.await(TEST_FAILURE_TIMEOUT_MSEC, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/services/tests/displayservicetests/src/com/android/server/display/TopologyUpdateDeliveryTest.java b/services/tests/displayservicetests/src/com/android/server/display/TopologyUpdateDeliveryTest.java
new file mode 100644
index 000000000000..5fd248dba53f
--- /dev/null
+++ b/services/tests/displayservicetests/src/com/android/server/display/TopologyUpdateDeliveryTest.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.display;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import android.content.Intent;
+import android.hardware.display.DisplayTopology;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tests that applications can receive topology updates correctly.
+ */
+public class TopologyUpdateDeliveryTest extends EventDeliveryTestBase {
+ private static final String TAG = TopologyUpdateDeliveryTest.class.getSimpleName();
+
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule =
+ DeviceFlagsValueProvider.createCheckFlagsRule();
+
+ private static final String TEST_PACKAGE = "com.android.servicestests.apps.topologytestapp";
+ private static final String TEST_ACTIVITY = TEST_PACKAGE + ".TopologyUpdateActivity";
+
+ // Topology updates we expect to receive before timeout
+ private final LinkedBlockingQueue<DisplayTopology> mExpectations = new LinkedBlockingQueue<>();
+
+ /**
+ * Add the received topology update from the test activity to the queue
+ *
+ * @param topology The corresponding topology update
+ */
+ private void addTopologyUpdate(DisplayTopology topology) {
+ Log.d(TAG, "Received " + topology);
+ mExpectations.offer(topology);
+ }
+
+ /**
+ * Assert that there isn't any unexpected display event from the test activity
+ */
+ private void assertNoTopologyUpdates() {
+ try {
+ assertNull(mExpectations.poll(EVENT_TIMEOUT_MSEC, TimeUnit.MILLISECONDS));
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Wait for the expected topology update from the test activity
+ *
+ * @param expect The expected topology update
+ */
+ private void waitTopologyUpdate(DisplayTopology expect) {
+ while (true) {
+ try {
+ DisplayTopology update = mExpectations.poll(TEST_FAILURE_TIMEOUT_MSEC,
+ TimeUnit.MILLISECONDS);
+ assertNotNull(update);
+ if (expect.equals(update)) {
+ Log.d(TAG, "Found " + update);
+ return;
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private class TestHandler extends Handler {
+ TestHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ switch (msg.what) {
+ case MESSAGE_LAUNCHED:
+ mPid = msg.arg1;
+ mUid = msg.arg2;
+ Log.d(TAG, "Launched " + mPid + " " + mUid);
+ mLatchActivityLaunch.countDown();
+ break;
+ case MESSAGE_CALLBACK:
+ DisplayTopology topology = (DisplayTopology) msg.obj;
+ Log.d(TAG, "Callback " + topology);
+ addTopologyUpdate(topology);
+ break;
+ default:
+ fail("Unexpected value: " + msg.what);
+ break;
+ }
+ }
+ }
+
+ @Before
+ public void setUp() {
+ super.setUp();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Override
+ protected String getTag() {
+ return TAG;
+ }
+
+ @Override
+ protected Handler getHandler(Looper looper) {
+ return new TestHandler(looper);
+ }
+
+ @Override
+ protected String getTestPackage() {
+ return TEST_PACKAGE;
+ }
+
+ @Override
+ protected String getTestActivity() {
+ return TEST_ACTIVITY;
+ }
+
+ @Override
+ protected void putExtra(Intent intent) { }
+
+ private void testTopologyUpdateInternal(boolean cached, boolean frozen) {
+ Log.d(TAG, "Start test testTopologyUpdate " + cached + " " + frozen);
+ // Launch activity and start listening to topology updates
+ int pid = launchTestActivity();
+
+ // The test activity in cached or frozen mode won't receive the pending topology updates.
+ if (cached) {
+ makeTestActivityCached();
+ }
+ if (frozen) {
+ makeTestActivityFrozen(pid);
+ }
+
+ // Change the topology
+ int primaryDisplayId = 3;
+ DisplayTopology.TreeNode root = new DisplayTopology.TreeNode(primaryDisplayId,
+ /* width= */ 600, /* height= */ 400, DisplayTopology.TreeNode.POSITION_LEFT,
+ /* offset= */ 0);
+ DisplayTopology.TreeNode child = new DisplayTopology.TreeNode(/* displayId= */ 1,
+ /* width= */ 800, /* height= */ 600, DisplayTopology.TreeNode.POSITION_LEFT,
+ /* offset= */ 0);
+ root.addChild(child);
+ DisplayTopology topology = new DisplayTopology(root, primaryDisplayId);
+ mDisplayManager.setDisplayTopology(topology);
+
+ if (cached || frozen) {
+ assertNoTopologyUpdates();
+ } else {
+ waitTopologyUpdate(topology);
+ }
+
+ // Unfreeze the test activity, if it was frozen.
+ if (frozen) {
+ makeTestActivityUnfrozen(pid);
+ }
+
+ if (cached || frozen) {
+ // Always ensure the test activity is not cached.
+ bringTestActivityTop();
+
+ // The test activity becomes non-cached and should receive the pending topology updates
+ waitTopologyUpdate(topology);
+ }
+ }
+
+ @Test
+ @RequiresFlagsEnabled(com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_TOPOLOGY)
+ public void testTopologyUpdate() {
+ testTopologyUpdateInternal(false, false);
+ }
+
+ /**
+ * The app is moved to cached and the test verifies that no updates are delivered to the cached
+ * app.
+ */
+ @Test
+ @RequiresFlagsEnabled(com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_TOPOLOGY)
+ public void testTopologyUpdateCached() {
+ testTopologyUpdateInternal(true, false);
+ }
+
+ /**
+ * The app is frozen and the test verifies that no updates are delivered to the frozen app.
+ */
+ @RequiresFlagsEnabled({com.android.server.am.Flags.FLAG_DEFER_DISPLAY_EVENTS_WHEN_FROZEN,
+ com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_TOPOLOGY})
+ @Test
+ public void testTopologyUpdateFrozen() {
+ assumeTrue(isAppFreezerEnabled());
+ testTopologyUpdateInternal(false, true);
+ }
+
+ /**
+ * The app is cached and frozen and the test verifies that no updates are delivered to the app.
+ */
+ @RequiresFlagsEnabled({com.android.server.am.Flags.FLAG_DEFER_DISPLAY_EVENTS_WHEN_FROZEN,
+ com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_TOPOLOGY})
+ @Test
+ public void testTopologyUpdateCachedFrozen() {
+ assumeTrue(isAppFreezerEnabled());
+ testTopologyUpdateInternal(true, true);
+ }
+}
diff --git a/services/tests/displayservicetests/src/com/android/server/display/mode/AppRequestObserverTest.kt b/services/tests/displayservicetests/src/com/android/server/display/mode/AppRequestObserverTest.kt
index 1f3f19fa3ea8..218728541774 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/mode/AppRequestObserverTest.kt
+++ b/services/tests/displayservicetests/src/com/android/server/display/mode/AppRequestObserverTest.kt
@@ -89,6 +89,39 @@ class AppRequestObserverTest {
assertThat(renderRateVote).isEqualTo(testCase.expectedRenderRateVote)
}
+ @Test
+ fun testAppRequestVote_externalDisplay() {
+ val displayModeDirector = DisplayModeDirector(
+ context, testHandler, mockInjector, mockFlags, mockDisplayDeviceConfigProvider)
+ val modes = arrayOf(
+ Display.Mode(1, 1000, 1000, 60f),
+ Display.Mode(2, 1000, 1000, 90f),
+ )
+
+ displayModeDirector.injectAppSupportedModesByDisplay(
+ SparseArray<Array<Display.Mode>>().apply {
+ append(Display.DEFAULT_DISPLAY, modes)
+ })
+ displayModeDirector.injectDefaultModeByDisplay(SparseArray<Display.Mode>().apply {
+ append(Display.DEFAULT_DISPLAY, modes[0])
+ })
+ displayModeDirector.addExternalDisplayId(Display.DEFAULT_DISPLAY)
+
+ displayModeDirector.appRequestObserver.setAppRequest(Display.DEFAULT_DISPLAY, 1, 0f, 0f, 0f)
+
+ val baseModeVote = displayModeDirector.getVote(Display.DEFAULT_DISPLAY,
+ Vote.PRIORITY_APP_REQUEST_BASE_MODE_REFRESH_RATE)
+ assertThat(baseModeVote).isEqualTo(BaseModeRefreshRateVote(60f))
+
+ val sizeVote = displayModeDirector.getVote(Display.DEFAULT_DISPLAY,
+ Vote.PRIORITY_APP_REQUEST_SIZE)
+ assertThat(sizeVote).isNull()
+
+ val renderRateVote = displayModeDirector.getVote(Display.DEFAULT_DISPLAY,
+ Vote.PRIORITY_APP_REQUEST_RENDER_FRAME_RATE_RANGE)
+ assertThat(renderRateVote).isNull()
+ }
+
enum class AppRequestTestCase(
val ignoreRefreshRateRequest: Boolean,
val modeId: Int,
diff --git a/services/tests/displayservicetests/src/com/android/server/display/mode/ModeChangeObserverTest.kt b/services/tests/displayservicetests/src/com/android/server/display/mode/ModeChangeObserverTest.kt
new file mode 100644
index 000000000000..a5fb6cdc8d4f
--- /dev/null
+++ b/services/tests/displayservicetests/src/com/android/server/display/mode/ModeChangeObserverTest.kt
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.display.mode
+
+import android.os.Looper
+import android.view.Display
+import android.view.DisplayAddress
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+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.junit.MockitoJUnit
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.whenever
+
+private const val PHYSICAL_DISPLAY_ID_1 = 1L
+private const val PHYSICAL_DISPLAY_ID_2 = 2L
+private const val MODE_ID_1 = 3
+private const val MODE_ID_2 = 4
+private const val LOGICAL_DISPLAY_ID = 5
+private val physicalAddress1 = DisplayAddress.fromPhysicalDisplayId(PHYSICAL_DISPLAY_ID_1)
+private val physicalAddress2 = DisplayAddress.fromPhysicalDisplayId(PHYSICAL_DISPLAY_ID_2)
+
+/**
+ * Tests for ModeChangeObserver, comply with changes in b/31925610
+ */
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+public class ModeChangeObserverTest {
+ @get:Rule
+ val mockitoRule = MockitoJUnit.rule()
+
+ // System Under Test
+ private lateinit var modeChangeObserver: ModeChangeObserver
+
+ // Non Mocks
+ private val looper = Looper.getMainLooper()
+ private val votesStorage = VotesStorage({}, null)
+
+ // Mocks
+ private val mockInjector = mock<DisplayModeDirector.Injector>()
+ private val mockDisplay1 = mock<Display>()
+ private val mockDisplay2 = mock<Display>()
+
+ @Before
+ fun setUp() {
+ whenever(mockInjector.getDisplay(LOGICAL_DISPLAY_ID)).thenReturn(mockDisplay1)
+ whenever(mockDisplay1.getAddress()).thenReturn(physicalAddress1)
+ whenever(mockInjector.getDisplays()).thenReturn(arrayOf<Display>())
+ modeChangeObserver = ModeChangeObserver(votesStorage, mockInjector, looper)
+ modeChangeObserver.observe()
+ }
+
+ @Test
+ fun testOnModeRejectedBeforeDisplayAdded() {
+ val rejectedModes = HashSet<Int>()
+ rejectedModes.add(MODE_ID_1)
+ rejectedModes.add(MODE_ID_2)
+
+ // ModeRejected is called before display is mapped, hence votes are null
+ modeChangeObserver.mModeChangeListener.onModeRejected(PHYSICAL_DISPLAY_ID_1, MODE_ID_1)
+ modeChangeObserver.mModeChangeListener.onModeRejected(PHYSICAL_DISPLAY_ID_1, MODE_ID_2)
+ val votes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(votes.size()).isEqualTo(0)
+
+ // Display is mapped to a Logical Display Id, now the Rejected Mode Votes get updated
+ modeChangeObserver.mDisplayListener.onDisplayAdded(LOGICAL_DISPLAY_ID)
+ val newVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(newVotes.size()).isEqualTo(1)
+ val vote = newVotes.get(Vote.PRIORITY_REJECTED_MODES)
+ assertThat(vote).isInstanceOf(RejectedModesVote::class.java)
+ val rejectedModesVote = vote as RejectedModesVote
+ assertThat(rejectedModesVote.mModeIds.size).isEqualTo(rejectedModes.size)
+ assertThat(rejectedModesVote.mModeIds).contains(MODE_ID_1)
+ assertThat(rejectedModesVote.mModeIds).contains(MODE_ID_2)
+ }
+
+ @Test
+ fun testOnDisplayAddedBeforeOnModeRejected() {
+ // Display is mapped to the corresponding Logical Id, but Mode Rejected no received yet
+ // Verify that the Vote is still Null
+ modeChangeObserver.mDisplayListener.onDisplayAdded(LOGICAL_DISPLAY_ID)
+ val votes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(votes.size()).isEqualTo(0)
+
+ // ModeRejected Event received for the mapped display
+ modeChangeObserver.mModeChangeListener.onModeRejected(PHYSICAL_DISPLAY_ID_1, MODE_ID_1)
+ val newVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(newVotes.size()).isEqualTo(1)
+ val vote = newVotes.get(Vote.PRIORITY_REJECTED_MODES)
+ assertThat(vote).isInstanceOf(RejectedModesVote::class.java)
+ val rejectedModesVote = vote as RejectedModesVote
+ assertThat(rejectedModesVote.mModeIds.size).isEqualTo(1)
+ assertThat(rejectedModesVote.mModeIds).contains(MODE_ID_1)
+ }
+
+ @Test
+ fun testOnDisplayAddedThenRejectedThenRemoved() {
+ // Display is mapped to its Logical Display Id
+ modeChangeObserver.mDisplayListener.onDisplayAdded(LOGICAL_DISPLAY_ID)
+ val votes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(votes.size()).isEqualTo(0)
+
+ // ModeRejected Event is received for mapped display
+ modeChangeObserver.mModeChangeListener.onModeRejected(PHYSICAL_DISPLAY_ID_1, MODE_ID_1)
+ val newVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(newVotes.size()).isEqualTo(1)
+ val vote = newVotes.get(Vote.PRIORITY_REJECTED_MODES)
+ assertThat(vote).isInstanceOf(RejectedModesVote::class.java)
+ val rejectedModesVote = vote as RejectedModesVote
+ assertThat(rejectedModesVote.mModeIds.size).isEqualTo(1)
+ assertThat(rejectedModesVote.mModeIds).contains(MODE_ID_1)
+
+ // Display mapping is removed, hence remove the votes
+ modeChangeObserver.mDisplayListener.onDisplayRemoved(LOGICAL_DISPLAY_ID)
+ val finalVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(finalVotes.size()).isEqualTo(0)
+ }
+
+ @Test
+ fun testForModesRejectedAfterDisplayChanged() {
+ // Mock Display 1 is mapped to logicalId
+ modeChangeObserver.mDisplayListener.onDisplayAdded(LOGICAL_DISPLAY_ID)
+ val votes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(votes.size()).isEqualTo(0)
+
+ // Mode Rejected received for PhysicalId2 not mapped yet, so votes are null
+ whenever(mockInjector.getDisplay(LOGICAL_DISPLAY_ID)).thenReturn(mockDisplay2)
+ whenever(mockDisplay2.getAddress()).thenReturn(physicalAddress2)
+ modeChangeObserver.mModeChangeListener.onModeRejected(PHYSICAL_DISPLAY_ID_2, MODE_ID_2)
+ val changedVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(changedVotes.size()).isEqualTo(0)
+
+ // Display mapping changed, now PhysicalId2 is mapped to the LogicalId, votes get updated
+ modeChangeObserver.mDisplayListener.onDisplayChanged(LOGICAL_DISPLAY_ID)
+ val finalVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(finalVotes.size()).isEqualTo(1)
+ val finalVote = finalVotes.get(Vote.PRIORITY_REJECTED_MODES)
+ assertThat(finalVote).isInstanceOf(RejectedModesVote::class.java)
+ val newRejectedModesVote = finalVote as RejectedModesVote
+ assertThat(newRejectedModesVote.mModeIds.size).isEqualTo(1)
+ assertThat(newRejectedModesVote.mModeIds).contains(MODE_ID_2)
+ }
+
+ @Test
+ fun testForModesNotRejectedAfterDisplayChanged() {
+ // Mock Display 1 is added
+ modeChangeObserver.mDisplayListener.onDisplayAdded(LOGICAL_DISPLAY_ID)
+ val votes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(votes.size()).isEqualTo(0)
+
+ // Mode Rejected received for Display 1, votes added for rejected mode
+ modeChangeObserver.mModeChangeListener.onModeRejected(PHYSICAL_DISPLAY_ID_1, MODE_ID_1)
+ val newVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(newVotes.size()).isEqualTo(1)
+ val vote = newVotes.get(Vote.PRIORITY_REJECTED_MODES)
+ assertThat(vote).isInstanceOf(RejectedModesVote::class.java)
+ val rejectedModesVote = vote as RejectedModesVote
+ assertThat(rejectedModesVote.mModeIds.size).isEqualTo(1)
+ assertThat(rejectedModesVote.mModeIds).contains(MODE_ID_1)
+
+ // Display Changed such that logical Id corresponds to PhysicalDisplayId2
+ // Rejected Modes Vote is removed
+ whenever(mockInjector.getDisplay(LOGICAL_DISPLAY_ID)).thenReturn(mockDisplay2)
+ whenever(mockDisplay2.getAddress()).thenReturn(physicalAddress2)
+ modeChangeObserver.mDisplayListener.onDisplayChanged(LOGICAL_DISPLAY_ID)
+ val finalVotes = votesStorage.getVotes(LOGICAL_DISPLAY_ID)
+ assertThat(finalVotes.size()).isEqualTo(0)
+ }
+} \ No newline at end of file
diff --git a/services/tests/servicestests/Android.bp b/services/tests/servicestests/Android.bp
index d702cae248a9..067fba9893e5 100644
--- a/services/tests/servicestests/Android.bp
+++ b/services/tests/servicestests/Android.bp
@@ -31,6 +31,7 @@ android_test {
"test-apps/SuspendTestApp/src/**/*.java",
"test-apps/DisplayManagerTestApp/src/**/*.java",
+ "test-apps/TopologyTestApp/src/**/*.java",
],
static_libs: [
@@ -141,6 +142,7 @@ android_test {
data: [
":DisplayManagerTestApp",
+ ":TopologyTestApp",
":SimpleServiceTestApp1",
":SimpleServiceTestApp2",
":SimpleServiceTestApp3",
diff --git a/services/tests/servicestests/AndroidTest.xml b/services/tests/servicestests/AndroidTest.xml
index 5298251b79f7..9a4983482522 100644
--- a/services/tests/servicestests/AndroidTest.xml
+++ b/services/tests/servicestests/AndroidTest.xml
@@ -36,6 +36,7 @@
<option name="cleanup-apks" value="true" />
<option name="install-arg" value="-t" />
<option name="test-file-name" value="DisplayManagerTestApp.apk" />
+ <option name="test-file-name" value="TopologyTestApp.apk" />
<option name="test-file-name" value="FrameworksServicesTests.apk" />
<option name="test-file-name" value="SuspendTestApp.apk" />
<option name="test-file-name" value="SimpleServiceTestApp1.apk" />
diff --git a/services/tests/servicestests/src/com/android/server/statusbar/StatusBarManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/statusbar/StatusBarManagerServiceTest.java
index 148c96850d34..6d682ccef98d 100644
--- a/services/tests/servicestests/src/com/android/server/statusbar/StatusBarManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/statusbar/StatusBarManagerServiceTest.java
@@ -36,6 +36,7 @@ import static android.app.StatusBarManager.DISABLE_SYSTEM_INFO;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.nullable;
@@ -69,16 +70,20 @@ import android.os.Binder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.platform.test.annotations.EnableFlags;
import android.service.quicksettings.TileService;
import android.testing.TestableContext;
+import android.util.Pair;
import androidx.test.InstrumentationRegistry;
+import com.android.internal.statusbar.DisableStates;
import com.android.internal.statusbar.IAddTileResultCallback;
import com.android.internal.statusbar.IStatusBar;
import com.android.server.LocalServices;
import com.android.server.policy.GlobalActionsProvider;
import com.android.server.wm.ActivityTaskManagerInternal;
+import com.android.systemui.shared.Flags;
import libcore.junit.util.compat.CoreCompatChangeRule;
@@ -105,6 +110,7 @@ public class StatusBarManagerServiceTest {
TEST_SERVICE);
private static final CharSequence APP_NAME = "AppName";
private static final CharSequence TILE_LABEL = "Tile label";
+ private static final int SECONDARY_DISPLAY_ID = 2;
@Rule
public final TestableContext mContext =
@@ -749,6 +755,40 @@ public class StatusBarManagerServiceTest {
}
@Test
+ @EnableFlags(Flags.FLAG_STATUS_BAR_CONNECTED_DISPLAYS)
+ public void testDisableForAllDisplays() throws Exception {
+ int user1Id = 0;
+ mockUidCheck();
+ mockCurrentUserCheck(user1Id);
+
+ mStatusBarManagerService.onDisplayAdded(SECONDARY_DISPLAY_ID);
+
+ int expectedFlags = DISABLE_MASK & DISABLE_BACK;
+ String pkg = mContext.getPackageName();
+
+ // before disabling
+ assertEquals(DISABLE_NONE,
+ mStatusBarManagerService.getDisableFlags(mMockStatusBar, user1Id)[0]);
+
+ // disable
+ mStatusBarManagerService.disable(expectedFlags, mMockStatusBar, pkg);
+
+ ArgumentCaptor<DisableStates> disableStatesCaptor = ArgumentCaptor.forClass(
+ DisableStates.class);
+ verify(mMockStatusBar).disableForAllDisplays(disableStatesCaptor.capture());
+ DisableStates capturedDisableStates = disableStatesCaptor.getValue();
+ assertTrue(capturedDisableStates.animate);
+ assertEquals(capturedDisableStates.displaysWithStates.size(), 2);
+ Pair<Integer, Integer> display0States = capturedDisableStates.displaysWithStates.get(0);
+ assertEquals((int) display0States.first, expectedFlags);
+ assertEquals((int) display0States.second, 0);
+ Pair<Integer, Integer> display2States = capturedDisableStates.displaysWithStates.get(
+ SECONDARY_DISPLAY_ID);
+ assertEquals((int) display2States.first, expectedFlags);
+ assertEquals((int) display2States.second, 0);
+ }
+
+ @Test
public void testSetHomeDisabled() throws Exception {
int expectedFlags = DISABLE_MASK & DISABLE_HOME;
String pkg = mContext.getPackageName();
@@ -851,6 +891,40 @@ public class StatusBarManagerServiceTest {
}
@Test
+ @EnableFlags(Flags.FLAG_STATUS_BAR_CONNECTED_DISPLAYS)
+ public void testDisable2ForAllDisplays() throws Exception {
+ int user1Id = 0;
+ mockUidCheck();
+ mockCurrentUserCheck(user1Id);
+
+ mStatusBarManagerService.onDisplayAdded(SECONDARY_DISPLAY_ID);
+
+ int expectedFlags = DISABLE2_MASK & DISABLE2_NOTIFICATION_SHADE;
+ String pkg = mContext.getPackageName();
+
+ // before disabling
+ assertEquals(DISABLE_NONE,
+ mStatusBarManagerService.getDisableFlags(mMockStatusBar, user1Id)[0]);
+
+ // disable
+ mStatusBarManagerService.disable2(expectedFlags, mMockStatusBar, pkg);
+
+ ArgumentCaptor<DisableStates> disableStatesCaptor = ArgumentCaptor.forClass(
+ DisableStates.class);
+ verify(mMockStatusBar).disableForAllDisplays(disableStatesCaptor.capture());
+ DisableStates capturedDisableStates = disableStatesCaptor.getValue();
+ assertTrue(capturedDisableStates.animate);
+ assertEquals(capturedDisableStates.displaysWithStates.size(), 2);
+ Pair<Integer, Integer> display0States = capturedDisableStates.displaysWithStates.get(0);
+ assertEquals((int) display0States.first, 0);
+ assertEquals((int) display0States.second, expectedFlags);
+ Pair<Integer, Integer> display2States = capturedDisableStates.displaysWithStates.get(
+ SECONDARY_DISPLAY_ID);
+ assertEquals((int) display2States.first, 0);
+ assertEquals((int) display2States.second, expectedFlags);
+ }
+
+ @Test
public void testSetQuickSettingsDisabled2() throws Exception {
int expectedFlags = DISABLE2_MASK & DISABLE2_QUICK_SETTINGS;
String pkg = mContext.getPackageName();
diff --git a/services/tests/servicestests/test-apps/TopologyTestApp/Android.bp b/services/tests/servicestests/test-apps/TopologyTestApp/Android.bp
new file mode 100644
index 000000000000..dcf9cc216687
--- /dev/null
+++ b/services/tests/servicestests/test-apps/TopologyTestApp/Android.bp
@@ -0,0 +1,38 @@
+// Copyright (C) 2025 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_base_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_test_helper_app {
+ name: "TopologyTestApp",
+
+ srcs: ["**/*.java"],
+
+ dex_preopt: {
+ enabled: false,
+ },
+ optimize: {
+ enabled: false,
+ },
+
+ platform_apis: true,
+ certificate: "platform",
+}
diff --git a/services/tests/servicestests/test-apps/TopologyTestApp/AndroidManifest.xml b/services/tests/servicestests/test-apps/TopologyTestApp/AndroidManifest.xml
new file mode 100644
index 000000000000..dad2315148df
--- /dev/null
+++ b/services/tests/servicestests/test-apps/TopologyTestApp/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2025 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.servicestests.apps.topologytestapp">
+
+ <uses-permission android:name="android.permission.MANAGE_DISPLAYS" />
+
+ <application android:label="TopologyUpdateTestApp">
+ <activity android:name="com.android.servicestests.apps.topologytestapp.TopologyUpdateActivity"
+ android:exported="true" />
+ </application>
+
+</manifest>
diff --git a/services/tests/servicestests/test-apps/TopologyTestApp/OWNERS b/services/tests/servicestests/test-apps/TopologyTestApp/OWNERS
new file mode 100644
index 000000000000..e9557f84f8fb
--- /dev/null
+++ b/services/tests/servicestests/test-apps/TopologyTestApp/OWNERS
@@ -0,0 +1,3 @@
+# Bug component: 345010
+
+include /services/core/java/com/android/server/display/OWNERS
diff --git a/services/tests/servicestests/test-apps/TopologyTestApp/src/com/android/servicestests/apps/topologytestapp/TopologyUpdateActivity.java b/services/tests/servicestests/test-apps/TopologyTestApp/src/com/android/servicestests/apps/topologytestapp/TopologyUpdateActivity.java
new file mode 100644
index 000000000000..b35ba3c2c60c
--- /dev/null
+++ b/services/tests/servicestests/test-apps/TopologyTestApp/src/com/android/servicestests/apps/topologytestapp/TopologyUpdateActivity.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.servicestests.apps.topologytestapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.DisplayTopology;
+import android.os.Bundle;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.Process;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.util.function.Consumer;
+
+/**
+ * A simple activity listening to topology updates
+ */
+public class TopologyUpdateActivity extends Activity {
+ public static final int MESSAGE_LAUNCHED = 1;
+ public static final int MESSAGE_CALLBACK = 2;
+
+ private static final String TAG = TopologyUpdateActivity.class.getSimpleName();
+
+ private static final String TEST_MESSENGER = "MESSENGER";
+
+ private Messenger mMessenger;
+ private DisplayManager mDisplayManager;
+ private final Consumer<DisplayTopology> mTopologyListener = this::callback;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Intent intent = getIntent();
+ mMessenger = intent.getParcelableExtra(TEST_MESSENGER, Messenger.class);
+ mDisplayManager = getApplicationContext().getSystemService(DisplayManager.class);
+ mDisplayManager.registerTopologyListener(getMainExecutor(), mTopologyListener);
+ launched();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mDisplayManager.unregisterTopologyListener(mTopologyListener);
+ }
+
+ private void launched() {
+ try {
+ Message msg = Message.obtain();
+ msg.what = MESSAGE_LAUNCHED;
+ msg.arg1 = android.os.Process.myPid();
+ msg.arg2 = Process.myUid();
+ Log.d(TAG, "Launched");
+ mMessenger.send(msg);
+ } catch (RemoteException e) {
+ e.rethrowAsRuntimeException();
+ }
+ }
+
+ private void callback(DisplayTopology topology) {
+ try {
+ Message msg = Message.obtain();
+ msg.what = MESSAGE_CALLBACK;
+ msg.obj = topology;
+ Log.d(TAG, "Msg " + topology);
+ mMessenger.send(msg);
+ } catch (RemoteException e) {
+ e.rethrowAsRuntimeException();
+ }
+ }
+}
diff --git a/services/tests/wmtests/src/com/android/server/policy/KeyGestureEventTests.java b/services/tests/wmtests/src/com/android/server/policy/KeyGestureEventTests.java
index fcdf88f16550..0495e967c0e3 100644
--- a/services/tests/wmtests/src/com/android/server/policy/KeyGestureEventTests.java
+++ b/services/tests/wmtests/src/com/android/server/policy/KeyGestureEventTests.java
@@ -39,8 +39,6 @@ import androidx.test.filters.MediumTest;
import com.android.hardware.input.Flags;
import com.android.internal.annotations.Keep;
-import junit.framework.Assert;
-
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
@@ -433,112 +431,94 @@ public class KeyGestureEventTests extends ShortcutKeyTestBase {
@Test
public void testKeyGestureRecentApps() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS);
mPhoneWindowManager.assertShowRecentApps();
}
@Test
public void testKeyGestureAppSwitch() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_APP_SWITCH));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_APP_SWITCH);
mPhoneWindowManager.assertToggleRecentApps();
}
@Test
public void testKeyGestureLaunchAssistant() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT);
mPhoneWindowManager.assertSearchManagerLaunchAssist();
}
@Test
public void testKeyGestureLaunchVoiceAssistant() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT);
mPhoneWindowManager.assertSearchManagerLaunchAssist();
}
@Test
public void testKeyGestureGoHome() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_HOME));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_HOME);
mPhoneWindowManager.assertGoToHomescreen();
}
@Test
public void testKeyGestureLaunchSystemSettings() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS);
mPhoneWindowManager.assertLaunchSystemSettings();
}
@Test
public void testKeyGestureLock() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN);
mPhoneWindowManager.assertLockedAfterAppTransitionFinished();
}
@Test
public void testKeyGestureToggleNotificationPanel() throws RemoteException {
- Assert.assertTrue(
- sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL);
mPhoneWindowManager.assertTogglePanel();
}
@Test
public void testKeyGestureScreenshot() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT);
mPhoneWindowManager.assertTakeScreenshotCalled();
}
@Test
public void testKeyGestureTriggerBugReport() throws RemoteException {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TRIGGER_BUG_REPORT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TRIGGER_BUG_REPORT);
mPhoneWindowManager.assertTakeBugreport(true);
}
@Test
public void testKeyGestureBack() {
- Assert.assertTrue(sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_BACK));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_BACK);
mPhoneWindowManager.assertBackEventInjected();
}
@Test
public void testKeyGestureMultiWindowNavigation() {
- Assert.assertTrue(sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION);
mPhoneWindowManager.assertMoveFocusedTaskToFullscreen();
}
@Test
public void testKeyGestureDesktopMode() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_DESKTOP_MODE));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_DESKTOP_MODE);
mPhoneWindowManager.assertMoveFocusedTaskToDesktop();
}
@Test
public void testKeyGestureSplitscreenNavigation() {
- Assert.assertTrue(sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT);
mPhoneWindowManager.assertMoveFocusedTaskToStageSplit(true);
- Assert.assertTrue(sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT);
mPhoneWindowManager.assertMoveFocusedTaskToStageSplit(false);
}
@Test
public void testKeyGestureShortcutHelper() {
- Assert.assertTrue(sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER);
mPhoneWindowManager.assertToggleShortcutsMenu();
}
@@ -549,173 +529,139 @@ public class KeyGestureEventTests extends ShortcutKeyTestBase {
for (int i = 0; i < currentBrightness.length; i++) {
mPhoneWindowManager.prepareBrightnessDecrease(currentBrightness[i]);
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_DOWN));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_BRIGHTNESS_DOWN);
mPhoneWindowManager.verifyNewBrightness(newBrightness[i]);
}
}
@Test
public void testKeyGestureRecentAppSwitcher() {
- Assert.assertTrue(sendKeyGestureEventStart(
- KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER);
mPhoneWindowManager.assertShowRecentApps();
-
- Assert.assertTrue(sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER);
mPhoneWindowManager.assertHideRecentApps();
}
@Test
public void testKeyGestureLanguageSwitch() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH);
mPhoneWindowManager.assertSwitchKeyboardLayout(1, DEFAULT_DISPLAY);
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH,
- KeyEvent.META_SHIFT_ON));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LANGUAGE_SWITCH,
+ KeyEvent.META_SHIFT_ON);
mPhoneWindowManager.assertSwitchKeyboardLayout(-1, DEFAULT_DISPLAY);
}
@Test
public void testKeyGestureLaunchSearch() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH);
mPhoneWindowManager.assertLaunchSearch();
}
@Test
public void testKeyGestureScreenshotChord() {
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD);
mPhoneWindowManager.moveTimeForward(500);
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD));
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD);
mPhoneWindowManager.assertTakeScreenshotCalled();
}
@Test
public void testKeyGestureScreenshotChordCancelled() {
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD));
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD);
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_SCREENSHOT_CHORD);
mPhoneWindowManager.assertTakeScreenshotNotCalled();
}
@Test
public void testKeyGestureRingerToggleChord() {
mPhoneWindowManager.overridePowerVolumeUp(POWER_VOLUME_UP_BEHAVIOR_MUTE);
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD);
mPhoneWindowManager.moveTimeForward(500);
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD));
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD);
mPhoneWindowManager.assertVolumeMute();
}
@Test
public void testKeyGestureRingerToggleChordCancelled() {
mPhoneWindowManager.overridePowerVolumeUp(POWER_VOLUME_UP_BEHAVIOR_MUTE);
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD));
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD);
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_RINGER_TOGGLE_CHORD);
mPhoneWindowManager.assertVolumeNotMuted();
}
@Test
public void testKeyGestureGlobalAction() {
mPhoneWindowManager.overridePowerVolumeUp(POWER_VOLUME_UP_BEHAVIOR_GLOBAL_ACTIONS);
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS);
mPhoneWindowManager.moveTimeForward(500);
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS));
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS);
mPhoneWindowManager.assertShowGlobalActionsCalled();
}
@Test
public void testKeyGestureGlobalActionCancelled() {
mPhoneWindowManager.overridePowerVolumeUp(POWER_VOLUME_UP_BEHAVIOR_GLOBAL_ACTIONS);
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS));
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS);
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS);
mPhoneWindowManager.assertShowGlobalActionsNotCalled();
}
@Test
public void testKeyGestureTvTriggerBugReport() {
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT);
mPhoneWindowManager.moveTimeForward(1000);
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT));
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT);
mPhoneWindowManager.assertBugReportTakenForTv();
}
@Test
public void testKeyGestureTvTriggerBugReportCancelled() {
- Assert.assertTrue(
- sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT));
- Assert.assertTrue(
- sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT));
+ sendKeyGestureEventStart(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT);
+ sendKeyGestureEventCancel(KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT);
mPhoneWindowManager.assertBugReportNotTakenForTv();
}
@Test
public void testKeyGestureAccessibilityShortcut() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT);
mPhoneWindowManager.assertAccessibilityKeychordCalled();
}
@Test
public void testKeyGestureCloseAllDialogs() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_CLOSE_ALL_DIALOGS));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_CLOSE_ALL_DIALOGS);
mPhoneWindowManager.assertCloseAllDialogs();
}
@Test
@EnableFlags(com.android.hardware.input.Flags.FLAG_ENABLE_TALKBACK_AND_MAGNIFIER_KEY_GESTURES)
public void testKeyGestureToggleTalkback() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK);
mPhoneWindowManager.assertTalkBack(true);
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK);
mPhoneWindowManager.assertTalkBack(false);
}
@Test
@EnableFlags(com.android.hardware.input.Flags.FLAG_ENABLE_VOICE_ACCESS_KEY_GESTURES)
public void testKeyGestureToggleVoiceAccess() {
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS);
mPhoneWindowManager.assertVoiceAccess(true);
- Assert.assertTrue(
- sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS);
mPhoneWindowManager.assertVoiceAccess(false);
}
@Test
public void testKeyGestureToggleDoNotDisturb() {
mPhoneWindowManager.overrideZenMode(Settings.Global.ZEN_MODE_OFF);
- Assert.assertTrue(
- sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB);
mPhoneWindowManager.assertZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
mPhoneWindowManager.overrideZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- Assert.assertTrue(
- sendKeyGestureEventComplete(
- KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB));
+ sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB);
mPhoneWindowManager.assertZenMode(Settings.Global.ZEN_MODE_OFF);
}
diff --git a/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java b/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java
index 32a3b7f2c9cc..68229688c238 100644
--- a/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java
+++ b/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java
@@ -43,6 +43,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -146,7 +147,7 @@ public class PhoneWindowManagerTests {
mPhoneWindowManager.mKeyguardDelegate = mKeyguardServiceDelegate;
final InputManager im = mock(InputManager.class);
- doNothing().when(im).registerKeyGestureEventHandler(any());
+ doNothing().when(im).registerKeyGestureEventHandler(anyList(), any());
doReturn(im).when(mContext).getSystemService(eq(Context.INPUT_SERVICE));
}
diff --git a/services/tests/wmtests/src/com/android/server/policy/ShortcutKeyTestBase.java b/services/tests/wmtests/src/com/android/server/policy/ShortcutKeyTestBase.java
index c57adfd69b06..f89c6f638384 100644
--- a/services/tests/wmtests/src/com/android/server/policy/ShortcutKeyTestBase.java
+++ b/services/tests/wmtests/src/com/android/server/policy/ShortcutKeyTestBase.java
@@ -238,33 +238,33 @@ class ShortcutKeyTestBase {
sendKeyCombination(new int[]{keyCode}, durationMillis, false, DEFAULT_DISPLAY);
}
- boolean sendKeyGestureEventStart(int gestureType) {
- return mPhoneWindowManager.sendKeyGestureEvent(
+ void sendKeyGestureEventStart(int gestureType) {
+ mPhoneWindowManager.sendKeyGestureEvent(
new KeyGestureEvent.Builder().setKeyGestureType(gestureType).setAction(
KeyGestureEvent.ACTION_GESTURE_START).build());
}
- boolean sendKeyGestureEventComplete(int gestureType) {
- return mPhoneWindowManager.sendKeyGestureEvent(
+ void sendKeyGestureEventComplete(int gestureType) {
+ mPhoneWindowManager.sendKeyGestureEvent(
new KeyGestureEvent.Builder().setKeyGestureType(gestureType).setAction(
KeyGestureEvent.ACTION_GESTURE_COMPLETE).build());
}
- boolean sendKeyGestureEventCancel(int gestureType) {
- return mPhoneWindowManager.sendKeyGestureEvent(
+ void sendKeyGestureEventCancel(int gestureType) {
+ mPhoneWindowManager.sendKeyGestureEvent(
new KeyGestureEvent.Builder().setKeyGestureType(gestureType).setAction(
KeyGestureEvent.ACTION_GESTURE_COMPLETE).setFlags(
KeyGestureEvent.FLAG_CANCELLED).build());
}
- boolean sendKeyGestureEventComplete(int gestureType, int modifierState) {
- return mPhoneWindowManager.sendKeyGestureEvent(
+ void sendKeyGestureEventComplete(int gestureType, int modifierState) {
+ mPhoneWindowManager.sendKeyGestureEvent(
new KeyGestureEvent.Builder().setModifierState(modifierState).setKeyGestureType(
gestureType).setAction(KeyGestureEvent.ACTION_GESTURE_COMPLETE).build());
}
- boolean sendKeyGestureEventComplete(int keycode, int modifierState, int gestureType) {
- return mPhoneWindowManager.sendKeyGestureEvent(
+ void sendKeyGestureEventComplete(int keycode, int modifierState, int gestureType) {
+ mPhoneWindowManager.sendKeyGestureEvent(
new KeyGestureEvent.Builder().setKeycodes(new int[]{keycode}).setModifierState(
modifierState).setKeyGestureType(gestureType).setAction(
KeyGestureEvent.ACTION_GESTURE_COMPLETE).build());
diff --git a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
index e56fd3c6272d..7b6d361c55d4 100644
--- a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
+++ b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java
@@ -49,6 +49,7 @@ import static com.android.server.policy.PhoneWindowManager.POWER_VOLUME_UP_BEHAV
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.after;
@@ -353,7 +354,7 @@ class TestPhoneWindowManager {
doReturn(mAppOpsManager).when(mContext).getSystemService(eq(AppOpsManager.class));
doReturn(mDisplayManager).when(mContext).getSystemService(eq(DisplayManager.class));
doReturn(mInputManager).when(mContext).getSystemService(eq(InputManager.class));
- doNothing().when(mInputManager).registerKeyGestureEventHandler(any());
+ doNothing().when(mInputManager).registerKeyGestureEventHandler(anyList(), any());
doNothing().when(mInputManager).unregisterKeyGestureEventHandler(any());
doReturn(mPackageManager).when(mContext).getPackageManager();
doReturn(mSensorPrivacyManager).when(mContext).getSystemService(
@@ -476,8 +477,8 @@ class TestPhoneWindowManager {
mPhoneWindowManager.interceptUnhandledKey(event, mInputToken);
}
- boolean sendKeyGestureEvent(KeyGestureEvent event) {
- return mPhoneWindowManager.handleKeyGestureEvent(event, mInputToken);
+ void sendKeyGestureEvent(KeyGestureEvent event) {
+ mPhoneWindowManager.handleKeyGestureEvent(event, mInputToken);
}
/**
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index 7f242dea9f45..773a566f6315 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -1459,21 +1459,6 @@ public class ActivityRecordTests extends WindowTestsBase {
}
/**
- * Verify that finish bottom activity from a task won't boost it to top.
- */
- @Test
- public void testFinishBottomActivityIfPossible_noZBoost() {
- final ActivityRecord bottomActivity = createActivityWithTask();
- final ActivityRecord topActivity = new ActivityBuilder(mAtm)
- .setTask(bottomActivity.getTask()).build();
- topActivity.setVisibleRequested(true);
- // simulating bottomActivity as a trampoline activity.
- bottomActivity.setState(RESUMED, "test");
- bottomActivity.finishIfPossible("test", false);
- assertFalse(bottomActivity.mNeedsZBoost);
- }
-
- /**
* Verify that complete finish request for visible activity must be delayed before the next one
* becomes visible.
*/
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java
deleted file mode 100644
index e4628c45a15b..000000000000
--- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenAnimationTests.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
-import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.intThat;
-
-import android.platform.test.annotations.Presubmit;
-import android.view.SurfaceControl;
-
-import androidx.test.filters.SmallTest;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-
-/**
- * Animation related tests for the {@link ActivityRecord} class.
- *
- * Build/Install/Run:
- * atest AppWindowTokenAnimationTests
- */
-@SmallTest
-@Presubmit
-@RunWith(WindowTestRunner.class)
-public class AppWindowTokenAnimationTests extends WindowTestsBase {
-
- private ActivityRecord mActivity;
-
- @Mock
- private AnimationAdapter mSpec;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
-
- mActivity = createActivityRecord(mDisplayContent);
- }
-
- @Test
- public void clipAfterAnim_boundsLayerIsCreated() {
- mActivity.mNeedsAnimationBoundsLayer = true;
-
- mActivity.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */,
- ANIMATION_TYPE_APP_TRANSITION);
- verify(mTransaction).reparent(eq(mActivity.getSurfaceControl()),
- eq(mActivity.mSurfaceAnimator.mLeash));
- verify(mTransaction).reparent(eq(mActivity.mSurfaceAnimator.mLeash),
- eq(mActivity.mAnimationBoundsLayer));
- }
-
- @Test
- public void clipAfterAnim_boundsLayerZBoosted() {
- final Task task = mActivity.getTask();
- final ActivityRecord topActivity = createActivityRecord(task);
- task.assignChildLayers(mTransaction);
-
- assertThat(topActivity.getLastLayer()).isGreaterThan(mActivity.getLastLayer());
-
- mActivity.mNeedsAnimationBoundsLayer = true;
- mActivity.mNeedsZBoost = true;
- mActivity.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */,
- ANIMATION_TYPE_APP_TRANSITION);
-
- verify(mTransaction).setLayer(eq(mActivity.mAnimationBoundsLayer),
- intThat(layer -> layer > topActivity.getLastLayer()));
-
- // The layer should be restored after the animation leash is removed.
- mActivity.onAnimationLeashLost(mTransaction);
- assertThat(mActivity.mNeedsZBoost).isFalse();
- assertThat(topActivity.getLastLayer()).isGreaterThan(mActivity.getLastLayer());
- }
-
- @Test
- public void clipAfterAnim_boundsLayerIsDestroyed() {
- mActivity.mNeedsAnimationBoundsLayer = true;
- mActivity.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */,
- ANIMATION_TYPE_APP_TRANSITION);
- final SurfaceControl leash = mActivity.mSurfaceAnimator.mLeash;
- final SurfaceControl animationBoundsLayer = mActivity.mAnimationBoundsLayer;
- final ArgumentCaptor<SurfaceAnimator.OnAnimationFinishedCallback> callbackCaptor =
- ArgumentCaptor.forClass(
- SurfaceAnimator.OnAnimationFinishedCallback.class);
- verify(mSpec).startAnimation(any(), any(), eq(ANIMATION_TYPE_APP_TRANSITION),
- callbackCaptor.capture());
-
- callbackCaptor.getValue().onAnimationFinished(
- ANIMATION_TYPE_APP_TRANSITION, mSpec);
- verify(mTransaction).remove(eq(leash));
- verify(mTransaction).remove(eq(animationBoundsLayer));
- assertThat(mActivity.mNeedsAnimationBoundsLayer).isFalse();
- }
-
- @Test
- public void clipAfterAnimCancelled_boundsLayerIsDestroyed() {
- mActivity.mNeedsAnimationBoundsLayer = true;
- mActivity.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */,
- ANIMATION_TYPE_APP_TRANSITION);
- final SurfaceControl leash = mActivity.mSurfaceAnimator.mLeash;
- final SurfaceControl animationBoundsLayer = mActivity.mAnimationBoundsLayer;
-
- mActivity.mSurfaceAnimator.cancelAnimation();
- verify(mTransaction).remove(eq(leash));
- verify(mTransaction).remove(eq(animationBoundsLayer));
- assertThat(mActivity.mNeedsAnimationBoundsLayer).isFalse();
- }
-
- @Test
- public void clipNoneAnim_boundsLayerIsNotCreated() {
- mActivity.mNeedsAnimationBoundsLayer = false;
-
- mActivity.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */,
- ANIMATION_TYPE_APP_TRANSITION);
- verify(mTransaction).reparent(eq(mActivity.getSurfaceControl()),
- eq(mActivity.mSurfaceAnimator.mLeash));
- assertThat(mActivity.mAnimationBoundsLayer).isNull();
- }
-}
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java
index ec83c50e95aa..1aa8681c9bfd 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java
@@ -49,10 +49,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.app.ActivityOptions;
@@ -192,24 +190,6 @@ public class TaskDisplayAreaTests extends WindowTestsBase {
}
@Test
- public void testActivityWithZBoost_taskDisplayAreaDoesNotMoveUp() {
- final Task rootTask = createTask(mDisplayContent);
- final Task task = createTaskInRootTask(rootTask, 0 /* userId */);
- final ActivityRecord activity = createNonAttachedActivityRecord(mDisplayContent);
- task.addChild(activity, 0 /* addPos */);
- final TaskDisplayArea taskDisplayArea = activity.getDisplayArea();
- activity.mNeedsAnimationBoundsLayer = true;
- activity.mNeedsZBoost = true;
- spyOn(taskDisplayArea.mSurfaceAnimator);
-
- mDisplayContent.assignChildLayers(mTransaction);
-
- assertThat(activity.needsZBoost()).isTrue();
- assertThat(taskDisplayArea.needsZBoost()).isFalse();
- verify(taskDisplayArea.mSurfaceAnimator, never()).setLayer(eq(mTransaction), anyInt());
- }
-
- @Test
public void testRootTaskPositionChildAt() {
Task pinnedTask = createTask(
mDisplayContent, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD);
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
index 044aacc4b988..b617f0285606 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
@@ -100,8 +100,6 @@ import androidx.test.filters.MediumTest;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
-import libcore.junit.util.compat.CoreCompatChangeRule;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -414,79 +412,96 @@ public class TaskTests extends WindowTestsBase {
}
@Test
- @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_RESIZE_APP})
- public void testIsResizeable_nonResizeable_forceResize_overridesEnabled_Resizeable() {
+ public void testIsResizeable_nonResizeable_forceResize_overridesEnabled_resizeable() {
final Task task = new TaskBuilder(mSupervisor)
.setCreateActivity(true)
- .setComponent(
- ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
.build();
task.setResizeMode(RESIZE_MODE_UNRESIZEABLE);
+ final ActivityRecord activity = task.getRootActivity();
+ final AppCompatResizeOverrides resizeOverrides =
+ activity.mAppCompatController.getResizeOverrides();
+ spyOn(activity);
+ spyOn(resizeOverrides);
+ doReturn(true).when(resizeOverrides).shouldOverrideForceResizeApp();
+ task.intent = null;
+ task.setIntent(activity);
// Override should take effect and task should be resizeable.
assertTrue(task.getTaskInfo().isResizeable);
}
@Test
- @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_RESIZE_APP})
- public void testIsResizeable_nonResizeable_forceResize_overridesDisabled_nonResizeable() {
+ public void testIsResizeable_resizeable_forceNonResize_overridesEnabled_nonResizeable() {
final Task task = new TaskBuilder(mSupervisor)
.setCreateActivity(true)
- .setComponent(
- ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
.build();
- task.setResizeMode(RESIZE_MODE_UNRESIZEABLE);
-
- // Disallow resize overrides.
- task.mAllowForceResizeOverride = false;
+ task.setResizeMode(RESIZE_MODE_RESIZEABLE);
+ final ActivityRecord activity = task.getRootActivity();
+ final AppCompatResizeOverrides resizeOverrides =
+ activity.mAppCompatController.getResizeOverrides();
+ spyOn(activity);
+ spyOn(resizeOverrides);
+ doReturn(true).when(resizeOverrides).shouldOverrideForceNonResizeApp();
+ task.intent = null;
+ task.setIntent(activity);
- // Override should not take effect and task should be un-resizeable.
+ // Override should take effect and task should be un-resizeable.
assertFalse(task.getTaskInfo().isResizeable);
}
@Test
- @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_NON_RESIZE_APP})
- public void testIsResizeable_resizeable_forceNonResize_overridesEnabled_nonResizeable() {
+ public void testIsResizeable_resizeableTask_fullscreenOverride_resizeable() {
final Task task = new TaskBuilder(mSupervisor)
.setCreateActivity(true)
- .setComponent(
- ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
.build();
- task.setResizeMode(RESIZE_MODE_RESIZEABLE);
+ task.setResizeMode(RESIZE_MODE_UNRESIZEABLE);
+ final ActivityRecord activity = task.getRootActivity();
+ final AppCompatAspectRatioOverrides aspectRatioOverrides =
+ activity.mAppCompatController.getAspectRatioOverrides();
+ spyOn(aspectRatioOverrides);
+ doReturn(true).when(aspectRatioOverrides).hasFullscreenOverride();
+ task.intent = null;
+ task.setIntent(activity);
- // Override should take effect and task should be un-resizeable.
- assertFalse(task.getTaskInfo().isResizeable);
+ // Override should take effect and task should be resizeable.
+ assertTrue(task.getTaskInfo().isResizeable);
}
@Test
- @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_NON_RESIZE_APP})
- public void testIsResizeable_resizeable_forceNonResize_overridesDisabled_Resizeable() {
+ public void testIsResizeable_resizeableTask_universalResizeable_resizeable() {
final Task task = new TaskBuilder(mSupervisor)
.setCreateActivity(true)
- .setComponent(
- ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
.build();
- task.setResizeMode(RESIZE_MODE_RESIZEABLE);
-
- // Disallow resize overrides.
- task.mAllowForceResizeOverride = false;
+ task.setResizeMode(RESIZE_MODE_UNRESIZEABLE);
+ final ActivityRecord activity = task.getRootActivity();
+ spyOn(activity);
+ doReturn(true).when(activity).isUniversalResizeable();
+ task.intent = null;
+ task.setIntent(activity);
- // Override should not take effect and task should be resizeable.
+ // Override should take effect and task should be resizeable.
assertTrue(task.getTaskInfo().isResizeable);
}
@Test
- @CoreCompatChangeRule.EnableCompatChanges({ActivityInfo.FORCE_NON_RESIZE_APP})
- public void testIsResizeable_systemWideForceResize_compatForceNonResize__Resizeable() {
+ public void testIsResizeable_systemWideForceResize_compatForceNonResize_resizeable() {
final Task task = new TaskBuilder(mSupervisor)
.setCreateActivity(true)
- .setComponent(
- ComponentName.createRelative(mContext, SizeCompatTests.class.getName()))
+ .setComponent(ComponentName.createRelative(mContext, TaskTests.class.getName()))
.build();
task.setResizeMode(RESIZE_MODE_RESIZEABLE);
// Set system-wide force resizeable override.
task.mAtmService.mForceResizableActivities = true;
+ final ActivityRecord activity = task.getRootActivity();
+ final AppCompatResizeOverrides resizeOverrides =
+ activity.mAppCompatController.getResizeOverrides();
+ spyOn(activity);
+ spyOn(resizeOverrides);
+ doReturn(true).when(resizeOverrides).shouldOverrideForceNonResizeApp();
+ task.intent = null;
+ task.setIntent(activity);
+
// System wide override should tak priority over app compat override so the task should
// remain resizeable.
assertTrue(task.getTaskInfo().isResizeable);
diff --git a/tests/Input/src/android/hardware/input/KeyGestureEventHandlerTest.kt b/tests/Input/src/android/hardware/input/KeyGestureEventHandlerTest.kt
index 794fd0255726..c62bd0b72584 100644
--- a/tests/Input/src/android/hardware/input/KeyGestureEventHandlerTest.kt
+++ b/tests/Input/src/android/hardware/input/KeyGestureEventHandlerTest.kt
@@ -18,12 +18,10 @@ package android.hardware.input
import android.content.Context
import android.content.ContextWrapper
-import android.os.IBinder
import android.platform.test.annotations.Presubmit
import android.platform.test.flag.junit.SetFlagsRule
import android.view.KeyEvent
import androidx.test.core.app.ApplicationProvider
-import com.android.server.testutils.any
import com.android.test.input.MockInputManagerRule
import org.junit.Before
import org.junit.Rule
@@ -37,6 +35,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.fail
+import org.junit.Assert.assertThrows
/**
* Tests for [InputManager.KeyGestureEventHandler].
@@ -82,7 +81,7 @@ class KeyGestureEventHandlerTest {
// Handle key gesture handler registration.
doAnswer {
- val listener = it.getArgument(0) as IKeyGestureHandler
+ val listener = it.getArgument(1) as IKeyGestureHandler
if (registeredListener != null &&
registeredListener!!.asBinder() != listener.asBinder()) {
// There can only be one registered key gesture handler per process.
@@ -90,7 +89,7 @@ class KeyGestureEventHandlerTest {
}
registeredListener = listener
null
- }.`when`(inputManagerRule.mock).registerKeyGestureHandler(any())
+ }.`when`(inputManagerRule.mock).registerKeyGestureHandler(Mockito.any(), Mockito.any())
// Handle key gesture handler being unregistered.
doAnswer {
@@ -101,7 +100,7 @@ class KeyGestureEventHandlerTest {
}
registeredListener = null
null
- }.`when`(inputManagerRule.mock).unregisterKeyGestureHandler(any())
+ }.`when`(inputManagerRule.mock).unregisterKeyGestureHandler(Mockito.any())
}
private fun handleKeyGestureEvent(event: KeyGestureEvent) {
@@ -121,11 +120,12 @@ class KeyGestureEventHandlerTest {
var callbackCount = 0
// Add a key gesture event listener
- inputManager.registerKeyGestureEventHandler(KeyGestureHandler { event, _ ->
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME)
+ ) { event, _ ->
assertEquals(HOME_GESTURE_EVENT, event)
callbackCount++
- true
- })
+ }
// Request handling for key gesture event will notify the handler.
handleKeyGestureEvent(HOME_GESTURE_EVENT)
@@ -135,29 +135,41 @@ class KeyGestureEventHandlerTest {
@Test
fun testAddingHandlersRegistersInternalCallbackHandler() {
// Set up two callbacks.
- val callback1 = KeyGestureHandler { _, _ -> false }
- val callback2 = KeyGestureHandler { _, _ -> false }
+ val callback1 = InputManager.KeyGestureEventHandler { _, _ -> }
+ val callback2 = InputManager.KeyGestureEventHandler { _, _ -> }
assertNull(registeredListener)
// Adding the handler should register the callback with InputManagerService.
- inputManager.registerKeyGestureEventHandler(callback1)
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ callback1
+ )
assertNotNull(registeredListener)
// Adding another handler should not register new internal listener.
val currListener = registeredListener
- inputManager.registerKeyGestureEventHandler(callback2)
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_BACK),
+ callback2
+ )
assertEquals(currListener, registeredListener)
}
@Test
fun testRemovingHandlersUnregistersInternalCallbackHandler() {
// Set up two callbacks.
- val callback1 = KeyGestureHandler { _, _ -> false }
- val callback2 = KeyGestureHandler { _, _ -> false }
+ val callback1 = InputManager.KeyGestureEventHandler { _, _ -> }
+ val callback2 = InputManager.KeyGestureEventHandler { _, _ -> }
- inputManager.registerKeyGestureEventHandler(callback1)
- inputManager.registerKeyGestureEventHandler(callback2)
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ callback1
+ )
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_BACK),
+ callback2
+ )
// Only removing all handlers should remove the internal callback
inputManager.unregisterKeyGestureEventHandler(callback1)
@@ -172,47 +184,74 @@ class KeyGestureEventHandlerTest {
var callbackCount1 = 0
var callbackCount2 = 0
// Handler 1 captures all home gestures
- val callback1 = KeyGestureHandler { event, _ ->
+ val callback1 = InputManager.KeyGestureEventHandler { event, _ ->
callbackCount1++
- event.keyGestureType == KeyGestureEvent.KEY_GESTURE_TYPE_HOME
+ assertEquals(KeyGestureEvent.KEY_GESTURE_TYPE_HOME, event.keyGestureType)
}
- // Handler 2 captures all gestures
- val callback2 = KeyGestureHandler { _, _ ->
+ // Handler 2 captures all back gestures
+ val callback2 = InputManager.KeyGestureEventHandler { event, _ ->
callbackCount2++
- true
+ assertEquals(KeyGestureEvent.KEY_GESTURE_TYPE_BACK, event.keyGestureType)
}
// Add both key gesture event handlers
- inputManager.registerKeyGestureEventHandler(callback1)
- inputManager.registerKeyGestureEventHandler(callback2)
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ callback1
+ )
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_BACK),
+ callback2
+ )
- // Request handling for key gesture event, should notify callbacks in order. So, only the
- // first handler should receive a callback since it captures the event.
+ // Request handling for home key gesture event, should notify only callback1
handleKeyGestureEvent(HOME_GESTURE_EVENT)
assertEquals(1, callbackCount1)
assertEquals(0, callbackCount2)
- // Second handler should receive the event since the first handler doesn't capture the event
+ // Request handling for back key gesture event, should notify only callback2
handleKeyGestureEvent(BACK_GESTURE_EVENT)
- assertEquals(2, callbackCount1)
+ assertEquals(1, callbackCount1)
assertEquals(1, callbackCount2)
inputManager.unregisterKeyGestureEventHandler(callback1)
- // Request handling for key gesture event, should still trigger callback2 but not callback1.
+
+ // Request handling for home key gesture event, should not trigger callback2
handleKeyGestureEvent(HOME_GESTURE_EVENT)
- assertEquals(2, callbackCount1)
- assertEquals(2, callbackCount2)
+ assertEquals(1, callbackCount1)
+ assertEquals(1, callbackCount2)
+ }
+
+ @Test
+ fun testUnableToRegisterSameHandlerTwice() {
+ val handler = InputManager.KeyGestureEventHandler { _, _ -> }
+
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ handler
+ )
+
+ assertThrows(IllegalArgumentException::class.java) {
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_BACK), handler
+ )
+ }
}
- inner class KeyGestureHandler(
- private var handler: (event: KeyGestureEvent, token: IBinder?) -> Boolean
- ) : InputManager.KeyGestureEventHandler {
+ @Test
+ fun testUnableToRegisterSameGestureTwice() {
+ val handler1 = InputManager.KeyGestureEventHandler { _, _ -> }
+ val handler2 = InputManager.KeyGestureEventHandler { _, _ -> }
+
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ handler1
+ )
- override fun handleKeyGestureEvent(
- event: KeyGestureEvent,
- focusedToken: IBinder?
- ): Boolean {
- return handler(event, focusedToken)
+ assertThrows(IllegalArgumentException::class.java) {
+ inputManager.registerKeyGestureEventHandler(
+ listOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME), handler2
+ )
}
}
}
diff --git a/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt b/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt
index 4f1fb6487b19..163dda84a71c 100644
--- a/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt
+++ b/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt
@@ -63,6 +63,7 @@ import org.junit.After
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
+import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
@@ -107,7 +108,10 @@ class KeyGestureControllerTests {
const val SETTINGS_KEY_BEHAVIOR_SETTINGS_ACTIVITY = 0
const val SETTINGS_KEY_BEHAVIOR_NOTIFICATION_PANEL = 1
const val SETTINGS_KEY_BEHAVIOR_NOTHING = 2
+ const val SYSTEM_PID = 0
const val TEST_PID = 10
+ const val RANDOM_PID1 = 11
+ const val RANDOM_PID2 = 12
}
@JvmField
@@ -170,6 +174,7 @@ class KeyGestureControllerTests {
return atomicFile
}
})
+ startNewInputGlobalTestSession()
}
@After
@@ -199,17 +204,22 @@ class KeyGestureControllerTests {
val correctIm = context.getSystemService(InputManager::class.java)!!
val virtualDevice = correctIm.getInputDevice(KeyCharacterMap.VIRTUAL_KEYBOARD)!!
val kcm = virtualDevice.keyCharacterMap!!
- inputManagerGlobalSession = InputManagerGlobal.createTestSession(iInputManager)
- val inputManager = InputManager(context)
- Mockito.`when`(context.getSystemService(Mockito.eq(Context.INPUT_SERVICE)))
- .thenReturn(inputManager)
-
val keyboardDevice = InputDevice.Builder().setId(DEVICE_ID).build()
Mockito.`when`(iInputManager.inputDeviceIds).thenReturn(intArrayOf(DEVICE_ID))
Mockito.`when`(iInputManager.getInputDevice(DEVICE_ID)).thenReturn(keyboardDevice)
ExtendedMockito.`when`(KeyCharacterMap.load(Mockito.anyInt())).thenReturn(kcm)
}
+ private fun startNewInputGlobalTestSession() {
+ if (this::inputManagerGlobalSession.isInitialized) {
+ inputManagerGlobalSession.close()
+ }
+ inputManagerGlobalSession = InputManagerGlobal.createTestSession(iInputManager)
+ val inputManager = InputManager(context)
+ Mockito.`when`(context.getSystemService(Mockito.eq(Context.INPUT_SERVICE)))
+ .thenReturn(inputManager)
+ }
+
private fun setupKeyGestureController() {
keyGestureController =
KeyGestureController(
@@ -225,13 +235,14 @@ class KeyGestureControllerTests {
return accessibilityShortcutController
}
})
- Mockito.`when`(iInputManager.registerKeyGestureHandler(Mockito.any()))
+ Mockito.`when`(iInputManager.registerKeyGestureHandler(Mockito.any(), Mockito.any()))
.thenAnswer {
val args = it.arguments
if (args[0] != null) {
keyGestureController.registerKeyGestureHandler(
- args[0] as IKeyGestureHandler,
- TEST_PID
+ args[0] as IntArray,
+ args[1] as IKeyGestureHandler,
+ SYSTEM_PID
)
}
}
@@ -285,59 +296,6 @@ class KeyGestureControllerTests {
)
}
- @Test
- fun testKeyGestureEvent_multipleGestureHandlers() {
- setupKeyGestureController()
-
- // Set up two callbacks.
- var callbackCount1 = 0
- var callbackCount2 = 0
- var selfCallback = 0
- val externalHandler1 = KeyGestureHandler { _, _ ->
- callbackCount1++
- true
- }
- val externalHandler2 = KeyGestureHandler { _, _ ->
- callbackCount2++
- true
- }
- val selfHandler = KeyGestureHandler { _, _ ->
- selfCallback++
- false
- }
-
- // Register key gesture handler: External process (last in priority)
- keyGestureController.registerKeyGestureHandler(externalHandler1, currentPid + 1)
-
- // Register key gesture handler: External process (second in priority)
- keyGestureController.registerKeyGestureHandler(externalHandler2, currentPid - 1)
-
- // Register key gesture handler: Self process (first in priority)
- keyGestureController.registerKeyGestureHandler(selfHandler, currentPid)
-
- keyGestureController.handleKeyGesture(/* deviceId = */ 0, intArrayOf(KeyEvent.KEYCODE_HOME),
- /* modifierState = */ 0, KeyGestureEvent.KEY_GESTURE_TYPE_HOME,
- KeyGestureEvent.ACTION_GESTURE_COMPLETE, /* displayId */ 0,
- /* focusedToken = */ null, /* flags = */ 0, /* appLaunchData = */null
- )
-
- assertEquals(
- "Self handler should get callbacks first",
- 1,
- selfCallback
- )
- assertEquals(
- "Higher priority handler should get callbacks first",
- 1,
- callbackCount2
- )
- assertEquals(
- "Lower priority handler should not get callbacks if already handled",
- 0,
- callbackCount1
- )
- }
-
class TestData(
val name: String,
val keys: IntArray,
@@ -789,10 +747,6 @@ class KeyGestureControllerTests {
)
fun testCustomKeyGesturesNotAllowedForSystemGestures(test: TestData) {
setupKeyGestureController()
- // Need to re-init so that bookmarks are correctly blocklisted
- Mockito.`when`(iInputManager.getAppLaunchBookmarks())
- .thenReturn(keyGestureController.appLaunchBookmarks)
- keyGestureController.systemRunning()
val builder = InputGestureData.Builder()
.setKeyGestureType(test.expectedKeyGestureType)
@@ -1163,9 +1117,6 @@ class KeyGestureControllerTests {
KeyEvent.KEYCODE_FULLSCREEN
)
- val handler = KeyGestureHandler { _, _ -> false }
- keyGestureController.registerKeyGestureHandler(handler, 0)
-
for (key in testKeys) {
sendKeys(intArrayOf(key), assertNotSentToApps = true)
}
@@ -1179,6 +1130,7 @@ class KeyGestureControllerTests {
testKeyGestureNotProduced(
"SEARCH -> Default Search",
intArrayOf(KeyEvent.KEYCODE_SEARCH),
+ intArrayOf(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH)
)
}
@@ -1207,6 +1159,10 @@ class KeyGestureControllerTests {
testKeyGestureNotProduced(
"SETTINGS -> Do Nothing",
intArrayOf(KeyEvent.KEYCODE_SETTINGS),
+ intArrayOf(
+ KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH,
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL
+ )
)
}
@@ -1290,28 +1246,6 @@ class KeyGestureControllerTests {
)
),
TestData(
- "VOLUME_DOWN + VOLUME_UP -> Accessibility Chord",
- intArrayOf(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP),
- KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT_CHORD,
- intArrayOf(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP),
- 0,
- intArrayOf(
- KeyGestureEvent.ACTION_GESTURE_START,
- KeyGestureEvent.ACTION_GESTURE_COMPLETE
- )
- ),
- TestData(
- "BACK + DPAD_DOWN -> Accessibility Chord(for TV)",
- intArrayOf(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_DPAD_DOWN),
- KeyGestureEvent.KEY_GESTURE_TYPE_ACCESSIBILITY_SHORTCUT_CHORD,
- intArrayOf(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_DPAD_DOWN),
- 0,
- intArrayOf(
- KeyGestureEvent.ACTION_GESTURE_START,
- KeyGestureEvent.ACTION_GESTURE_COMPLETE
- )
- ),
- TestData(
"BACK + DPAD_CENTER -> TV Trigger Bug Report",
intArrayOf(KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_DPAD_CENTER),
KeyGestureEvent.KEY_GESTURE_TYPE_TV_TRIGGER_BUG_REPORT,
@@ -1428,9 +1362,11 @@ class KeyGestureControllerTests {
testLooper.dispatchAll()
// Reinitialize the gesture controller simulating a login/logout for the user.
+ startNewInputGlobalTestSession()
setupKeyGestureController()
keyGestureController.setCurrentUserId(userId)
testLooper.dispatchAll()
+
val savedInputGestures = keyGestureController.getCustomInputGestures(userId, null)
assertEquals(
"Test: $test doesn't produce correct number of saved input gestures",
@@ -1469,6 +1405,7 @@ class KeyGestureControllerTests {
// Delete the old data and reinitialize the controller simulating a "fresh" install.
tempFile.delete()
+ startNewInputGlobalTestSession()
setupKeyGestureController()
keyGestureController.setCurrentUserId(userId)
testLooper.dispatchAll()
@@ -1541,9 +1478,12 @@ class KeyGestureControllerTests {
val handledEvents = mutableListOf<KeyGestureEvent>()
val handler = KeyGestureHandler { event, _ ->
handledEvents.add(KeyGestureEvent(event))
- true
}
- keyGestureController.registerKeyGestureHandler(handler, 0)
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(test.expectedKeyGestureType),
+ handler,
+ TEST_PID
+ )
handledEvents.clear()
keyGestureController.handleTouchpadGesture(test.touchpadGestureType)
@@ -1570,7 +1510,7 @@ class KeyGestureControllerTests {
event.appLaunchData
)
- keyGestureController.unregisterKeyGestureHandler(handler, 0)
+ keyGestureController.unregisterKeyGestureHandler(handler, TEST_PID)
}
@Test
@@ -1591,9 +1531,11 @@ class KeyGestureControllerTests {
testLooper.dispatchAll()
// Reinitialize the gesture controller simulating a login/logout for the user.
+ startNewInputGlobalTestSession()
setupKeyGestureController()
keyGestureController.setCurrentUserId(userId)
testLooper.dispatchAll()
+
val savedInputGestures = keyGestureController.getCustomInputGestures(userId, null)
assertEquals(
"Test: $test doesn't produce correct number of saved input gestures",
@@ -1627,6 +1569,7 @@ class KeyGestureControllerTests {
// Delete the old data and reinitialize the controller simulating a "fresh" install.
tempFile.delete()
+ startNewInputGlobalTestSession()
setupKeyGestureController()
keyGestureController.setCurrentUserId(userId)
testLooper.dispatchAll()
@@ -1699,13 +1642,97 @@ class KeyGestureControllerTests {
Mockito.verify(accessibilityShortcutController, never()).performAccessibilityShortcut()
}
+ @Test
+ fun testUnableToRegisterFromSamePidTwice() {
+ setupKeyGestureController()
+
+ val handler1 = KeyGestureHandler { _, _ -> }
+ val handler2 = KeyGestureHandler { _, _ -> }
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ handler1,
+ RANDOM_PID1
+ )
+
+ assertThrows(IllegalStateException::class.java) {
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(KeyGestureEvent.KEY_GESTURE_TYPE_BACK),
+ handler2,
+ RANDOM_PID1
+ )
+ }
+ }
+
+ @Test
+ fun testUnableToRegisterSameGestureTwice() {
+ setupKeyGestureController()
+
+ val handler1 = KeyGestureHandler { _, _ -> }
+ val handler2 = KeyGestureHandler { _, _ -> }
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ handler1,
+ RANDOM_PID1
+ )
+
+ assertThrows(IllegalArgumentException::class.java) {
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(KeyGestureEvent.KEY_GESTURE_TYPE_HOME),
+ handler2,
+ RANDOM_PID2
+ )
+ }
+ }
+
+ @Test
+ fun testUnableToRegisterEmptyListOfGestures() {
+ setupKeyGestureController()
+
+ val handler = KeyGestureHandler { _, _ -> }
+
+ assertThrows(IllegalArgumentException::class.java) {
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(),
+ handler,
+ RANDOM_PID1
+ )
+ }
+ }
+
+ @Test
+ fun testGestureHandlerNotCalledOnceUnregistered() {
+ setupKeyGestureController()
+
+ var callbackCount = 0
+ val handler1 = KeyGestureHandler { _, _ -> callbackCount++ }
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS),
+ handler1,
+ TEST_PID
+ )
+ sendKeys(intArrayOf(KeyEvent.KEYCODE_RECENT_APPS))
+ assertEquals(1, callbackCount)
+
+ keyGestureController.unregisterKeyGestureHandler(
+ handler1,
+ TEST_PID
+ )
+
+ // Callback should not be sent after unregister
+ sendKeys(intArrayOf(KeyEvent.KEYCODE_RECENT_APPS))
+ assertEquals(1, callbackCount)
+ }
+
private fun testKeyGestureInternal(test: TestData) {
val handledEvents = mutableListOf<KeyGestureEvent>()
val handler = KeyGestureHandler { event, _ ->
handledEvents.add(KeyGestureEvent(event))
- true
}
- keyGestureController.registerKeyGestureHandler(handler, 0)
+ keyGestureController.registerKeyGestureHandler(
+ intArrayOf(test.expectedKeyGestureType),
+ handler,
+ TEST_PID
+ )
handledEvents.clear()
sendKeys(test.keys)
@@ -1744,16 +1771,19 @@ class KeyGestureControllerTests {
)
}
- keyGestureController.unregisterKeyGestureHandler(handler, 0)
+ keyGestureController.unregisterKeyGestureHandler(handler, TEST_PID)
}
- private fun testKeyGestureNotProduced(testName: String, testKeys: IntArray) {
+ private fun testKeyGestureNotProduced(
+ testName: String,
+ testKeys: IntArray,
+ possibleGestures: IntArray
+ ) {
var handledEvents = mutableListOf<KeyGestureEvent>()
val handler = KeyGestureHandler { event, _ ->
handledEvents.add(KeyGestureEvent(event))
- true
}
- keyGestureController.registerKeyGestureHandler(handler, 0)
+ keyGestureController.registerKeyGestureHandler(possibleGestures, handler, TEST_PID)
handledEvents.clear()
sendKeys(testKeys)
@@ -1823,10 +1853,10 @@ class KeyGestureControllerTests {
}
inner class KeyGestureHandler(
- private var handler: (event: AidlKeyGestureEvent, token: IBinder?) -> Boolean
+ private var handler: (event: AidlKeyGestureEvent, token: IBinder?) -> Unit
) : IKeyGestureHandler.Stub() {
- override fun handleKeyGesture(event: AidlKeyGestureEvent, token: IBinder?): Boolean {
- return handler(event, token)
+ override fun handleKeyGesture(event: AidlKeyGestureEvent, token: IBinder?) {
+ handler(event, token)
}
}
}
diff --git a/tests/Input/src/com/android/test/input/AnrTest.kt b/tests/Input/src/com/android/test/input/AnrTest.kt
index f8cb86b7b1fe..3ad3763a5d20 100644
--- a/tests/Input/src/com/android/test/input/AnrTest.kt
+++ b/tests/Input/src/com/android/test/input/AnrTest.kt
@@ -16,6 +16,7 @@
package com.android.test.input
import android.app.ActivityManager
+import android.app.ActivityTaskManager
import android.app.ApplicationExitInfo
import android.app.Instrumentation
import android.content.Intent
@@ -28,6 +29,7 @@ import android.os.SystemClock
import android.server.wm.CtsWindowInfoUtils.getWindowCenter
import android.server.wm.CtsWindowInfoUtils.waitForWindowOnTop
import android.testing.PollingCheck
+import android.util.Log
import android.view.InputEvent
import android.view.MotionEvent
import android.view.MotionEvent.ACTION_DOWN
@@ -46,21 +48,19 @@ import com.android.cts.input.inputeventmatchers.withMotionAction
import java.time.Duration
import java.util.concurrent.LinkedBlockingQueue
import java.util.function.Supplier
-import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
-import org.junit.Before
+import org.junit.Assume.assumeTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
- * Click on the center of the window identified by the provided window token.
- * The click is performed using "UinputTouchScreen" device.
- * If the touchscreen device is closed too soon, it may cause the click to be dropped. Therefore,
- * the provided runnable can ensure that the click is delivered before the device is closed, thus
- * avoiding this race.
+ * Click on the center of the window identified by the provided window token. The click is performed
+ * using "UinputTouchScreen" device. If the touchscreen device is closed too soon, it may cause the
+ * click to be dropped. Therefore, the provided runnable can ensure that the click is delivered
+ * before the device is closed, thus avoiding this race.
*/
private fun clickOnWindow(
token: IBinder,
@@ -104,6 +104,10 @@ class AnrTest {
private val remoteInputEvents = LinkedBlockingQueue<InputEvent>()
private val verifier = BlockingQueueEventVerifier(remoteInputEvents)
+ // Some devices don't support ANR error dialogs, such as cars, TVs, etc.
+ private val anrDialogsAreSupported =
+ ActivityTaskManager.currentUiModeSupportsErrorDialogs(instrumentation.targetContext)
+
val binder =
object : IAnrTestService.Stub() {
override fun provideActivityInfo(token: IBinder, displayId: Int, pid: Int) {
@@ -121,34 +125,37 @@ class AnrTest {
@get:Rule val debugInputRule = DebugInputRule()
- @Before
- fun setUp() {
- startUnresponsiveActivity()
- PACKAGE_NAME = UnresponsiveGestureMonitorActivity::class.java.getPackage()!!.getName()
- }
-
- @After fun tearDown() {}
-
@Test
@DebugInputRule.DebugInput(bug = 339924248)
fun testGestureMonitorAnr_Close() {
+ startUnresponsiveActivity()
+ val timestamp = System.currentTimeMillis()
triggerAnr()
- clickCloseAppOnAnrDialog()
+ if (anrDialogsAreSupported) {
+ clickCloseAppOnAnrDialog()
+ } else {
+ Log.i(TAG, "The device does not support ANR dialogs, skipping check for ANR window")
+ // We still want to wait for the app to get killed by the ActivityManager
+ }
+ waitForNewExitReasonAfter(timestamp)
}
@Test
@DebugInputRule.DebugInput(bug = 339924248)
fun testGestureMonitorAnr_Wait() {
+ assumeTrue(anrDialogsAreSupported)
+ startUnresponsiveActivity()
triggerAnr()
clickWaitOnAnrDialog()
SystemClock.sleep(500) // Wait at least 500ms after tapping on wait
// ANR dialog should reappear after a delay - find the close button on it to verify
+ val timestamp = System.currentTimeMillis()
clickCloseAppOnAnrDialog()
+ waitForNewExitReasonAfter(timestamp)
}
private fun clickCloseAppOnAnrDialog() {
// Find anr dialog and kill app
- val timestamp = System.currentTimeMillis()
val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)
val closeAppButton: UiObject2? =
uiDevice.wait(Until.findObject(By.res("android:id/aerr_close")), 20000)
@@ -157,14 +164,6 @@ class AnrTest {
return
}
closeAppButton.click()
- /**
- * We must wait for the app to be fully closed before exiting this test. This is because
- * another test may again invoke 'am start' for the same activity. If the 1st process that
- * got ANRd isn't killed by the time second 'am start' runs, the killing logic will apply to
- * the newly launched 'am start' instance, and the second test will fail because the
- * unresponsive activity will never be launched.
- */
- waitForNewExitReasonAfter(timestamp)
}
private fun clickWaitOnAnrDialog() {
@@ -180,16 +179,27 @@ class AnrTest {
}
private fun getExitReasons(): List<ApplicationExitInfo> {
+ val packageName = UnresponsiveGestureMonitorActivity::class.java.getPackage()!!.name
lateinit var infos: List<ApplicationExitInfo>
instrumentation.runOnMainSync {
val am = instrumentation.getContext().getSystemService(ActivityManager::class.java)!!
- infos = am.getHistoricalProcessExitReasons(PACKAGE_NAME, remotePid!!, NO_MAX)
+ infos = am.getHistoricalProcessExitReasons(packageName, remotePid!!, NO_MAX)
}
return infos
}
+ /**
+ * We must wait for the app to be fully closed before exiting this test. This is because another
+ * test may again invoke 'am start' for the same activity. If the 1st process that got ANRd
+ * isn't killed by the time second 'am start' runs, the killing logic will apply to the newly
+ * launched 'am start' instance, and the second test will fail because the unresponsive activity
+ * will never be launched.
+ *
+ * Also, we must ensure that we wait until it's killed, so that the next test can launch this
+ * activity again.
+ */
private fun waitForNewExitReasonAfter(timestamp: Long) {
- PollingCheck.waitFor {
+ PollingCheck.waitFor(Duration.ofSeconds(20).toMillis() * Build.HW_TIMEOUT_MULTIPLIER) {
val reasons = getExitReasons()
!reasons.isEmpty() && reasons[0].timestamp >= timestamp
}
@@ -199,16 +209,15 @@ class AnrTest {
}
private fun triggerAnr() {
- clickOnWindow(
- remoteWindowToken!!,
- remoteDisplayId!!,
- instrumentation,
- ) { verifier.assertReceivedMotion(withMotionAction(ACTION_DOWN)) }
+ clickOnWindow(remoteWindowToken!!, remoteDisplayId!!, instrumentation) {
+ verifier.assertReceivedMotion(withMotionAction(ACTION_DOWN))
+ }
SystemClock.sleep(DISPATCHING_TIMEOUT.toLong()) // default ANR timeout for gesture monitors
}
private fun startUnresponsiveActivity() {
+ remoteWindowToken = null
val intent =
Intent(instrumentation.targetContext, UnresponsiveGestureMonitorActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
@@ -218,12 +227,17 @@ class AnrTest {
instrumentation.targetContext.startActivity(intent)
// first, wait for the token to become valid
PollingCheck.check(
- "UnresponsiveGestureMonitorActivity failed to call 'provideActivityInfo'",
- Duration.ofSeconds(5).toMillis()) { remoteWindowToken != null }
+ "UnresponsiveGestureMonitorActivity failed to call 'provideActivityInfo'",
+ Duration.ofSeconds(10).toMillis() * Build.HW_TIMEOUT_MULTIPLIER,
+ ) {
+ remoteWindowToken != null
+ }
// next, wait for the window of the activity to get on top
// we could combine the two checks above, but the current setup makes it easier to detect
// errors
- assertTrue("Remote activity window did not become visible",
- waitForWindowOnTop(Duration.ofSeconds(5), Supplier { remoteWindowToken }))
+ assertTrue(
+ "Remote activity window did not become visible",
+ waitForWindowOnTop(Duration.ofSeconds(5), Supplier { remoteWindowToken }),
+ )
}
}