summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java6
-rw-r--r--core/api/current.txt49
-rw-r--r--core/api/system-current.txt12
-rw-r--r--core/api/test-current.txt10
-rw-r--r--core/java/android/app/Notification.java820
-rw-r--r--core/java/android/app/PropertyInvalidatedCache.java194
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java25
-rw-r--r--core/java/android/app/appfunctions/AppFunctionManager.java81
-rw-r--r--core/java/android/app/appfunctions/AppFunctionService.java64
-rw-r--r--core/java/android/app/appfunctions/GenericDocumentWrapper.java95
-rw-r--r--core/java/android/app/appfunctions/IAppFunctionManager.aidl5
-rw-r--r--core/java/android/app/appfunctions/IAppFunctionService.aidl4
-rw-r--r--core/java/android/app/appfunctions/ICancellationCallback.aidl24
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java9
-rw-r--r--core/java/android/content/Intent.java89
-rw-r--r--core/java/android/content/pm/flags.aconfig9
-rw-r--r--core/java/android/hardware/camera2/CameraManager.java10
-rw-r--r--core/java/android/hardware/display/DisplayManagerInternal.java5
-rw-r--r--core/java/android/hardware/soundtrigger/SoundTrigger.java87
-rw-r--r--core/java/android/os/Binder.java20
-rw-r--r--core/java/android/os/IpcDataCache.java24
-rw-r--r--core/java/android/provider/Settings.java10
-rw-r--r--core/java/android/security/responsible_apis_flags.aconfig19
-rw-r--r--core/java/android/view/WindowLayout.java17
-rw-r--r--core/java/android/view/accessibility/AccessibilityWindowInfo.java10
-rw-r--r--core/proto/android/server/vibrator/vibratormanagerservice.proto4
-rw-r--r--core/res/res/values/config.xml5
-rw-r--r--core/res/res/values/dimens.xml6
-rw-r--r--core/res/res/values/symbols.xml4
-rw-r--r--core/tests/coretests/Android.bp3
-rw-r--r--core/tests/coretests/AndroidTest.xml1
-rw-r--r--core/tests/coretests/AppThatCallsBinderMethods/Android.bp20
-rw-r--r--core/tests/coretests/AppThatCallsBinderMethods/AndroidManifest.xml26
-rw-r--r--core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/CallMethodsReceiver.kt57
-rw-r--r--core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/Constants.kt23
-rw-r--r--core/tests/coretests/aidl/com/android/frameworks/coretests/aidl/ITestInterface.aidl27
-rw-r--r--core/tests/coretests/src/android/app/NotificationTest.java303
-rw-r--r--core/tests/coretests/src/android/content/IntentTest.java99
-rw-r--r--core/tests/coretests/src/android/os/BinderUncaughtExceptionHandlerTest.kt247
-rw-r--r--core/tests/coretests/src/android/view/WindowLayoutTests.java15
-rw-r--r--core/tests/resourceflaggingtests/src/com/android/resourceflaggingtests/ResourceFlaggingTest.java49
-rw-r--r--graphics/java/android/graphics/PathIterator.java19
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java270
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java12
-rw-r--r--libs/WindowManager/Jetpack/tests/unittest/Android.bp2
-rw-r--r--libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducerTest.kt341
-rw-r--r--libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java3
-rw-r--r--libs/WindowManager/Shell/aconfig/multitasking.aconfig7
-rw-r--r--libs/WindowManager/Shell/res/drawable/app_handle_education_tooltip_icon.xml27
-rw-r--r--libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_background.xml25
-rw-r--r--libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_left_arrow.xml27
-rw-r--r--libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_top_arrow.xml26
-rw-r--r--libs/WindowManager/Shell/res/layout/desktop_windowing_education_left_arrow_tooltip.xml36
-rw-r--r--libs/WindowManager/Shell/res/layout/desktop_windowing_education_tooltip_container.xml43
-rw-r--r--libs/WindowManager/Shell/res/layout/desktop_windowing_education_top_arrow_tooltip.xml35
-rw-r--r--libs/WindowManager/Shell/res/layout/letterbox_restart_dialog_layout.xml8
-rw-r--r--libs/WindowManager/Shell/res/values/dimen.xml3
-rw-r--r--libs/WindowManager/Shell/res/values/strings.xml12
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/FocusTransitionListener.java30
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IFocusTransitionListener.aidl28
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IShellTransitions.aidl6
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/ShellTransitions.java13
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/split/OWNERS4
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java12
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt1
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt16
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt29
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java3
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/transition/FocusTransitionObserver.java142
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java42
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/additionalviewcontainer/AdditionalSystemViewContainer.kt23
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipController.kt249
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt183
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt138
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java4
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/FocusTransitionObserverTest.java155
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/HomeTransitionObserverTest.java3
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java12
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipControllerTest.kt237
-rw-r--r--libs/appfunctions/api/current.txt6
-rw-r--r--libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionManager.java42
-rw-r--r--libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java37
-rw-r--r--libs/hwui/Properties.cpp6
-rw-r--r--libs/hwui/Properties.h1
-rw-r--r--libs/hwui/aconfig/hwui_flags.aconfig10
-rw-r--r--libs/hwui/jni/PathIterator.cpp14
-rw-r--r--libs/hwui/renderthread/VulkanManager.cpp85
-rw-r--r--libs/hwui/renderthread/VulkanManager.h2
-rw-r--r--media/java/android/media/tv/flags/media_tv.aconfig8
-rw-r--r--media/jni/android_media_ImageWriter.cpp14
-rw-r--r--packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml24
-rw-r--r--packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java10
-rw-r--r--packages/SettingsLib/Android.bp1
-rw-r--r--packages/SettingsLib/CardPreference/Android.bp33
-rw-r--r--packages/SettingsLib/CardPreference/AndroidManifest.xml23
-rw-r--r--packages/SettingsLib/CardPreference/res/layout/settingslib_expressive_preference_card.xml88
-rw-r--r--packages/SettingsLib/CardPreference/res/values/styles_expressive.xml30
-rw-r--r--packages/SettingsLib/CardPreference/src/com/android/settingslib/widget/CardPreference.kt58
-rw-r--r--packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_collapse.xml36
-rw-r--r--packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_expand.xml37
-rw-r--r--packages/SettingsLib/SettingsTheme/res/layout-v35/settingslib_expressive_collapsable_textview.xml51
-rw-r--r--packages/SettingsLib/SettingsTheme/res/values-v35/attrs_expressive.xml25
-rw-r--r--packages/SettingsLib/SettingsTheme/res/values-v35/strings.xml24
-rw-r--r--packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml103
-rw-r--r--packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt150
-rw-r--r--packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsTypography.kt3
-rw-r--r--packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/button/ActionButtons.kt2
-rw-r--r--packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/Actions.kt36
-rw-r--r--packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt80
-rw-r--r--packages/SettingsLib/TopIntroPreference/Android.bp5
-rw-r--r--packages/SettingsLib/TopIntroPreference/res/layout-v35/settingslib_expressive_top_intro.xml27
-rw-r--r--packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java51
-rw-r--r--packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.kt108
-rw-r--r--packages/SettingsLib/res/values/strings.xml4
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java4
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingItem.kt14
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.aidl19
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.kt60
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsProviderServiceStatus.kt2
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IDeviceSettingsConfigProviderService.aidl4
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IGetDeviceSettingsConfigCallback.aidl24
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt91
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/graph/SignalDrawable.java19
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java2
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatusTest.kt51
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt38
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/PhoneMediaDeviceTest.java2
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java1
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java1
-rw-r--r--packages/SystemUI/aconfig/systemui.aconfig22
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java374
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginTransitionSession.java40
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/SurfaceUIComponent.java169
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/Transactions.java86
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/UIComponent.java72
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java278
-rw-r--r--packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt24
-rw-r--r--packages/SystemUI/compose/facade/enabled/src/com/android/systemui/scene/LockscreenSceneModule.kt20
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/dialog/ui/composable/AlertDialogContent.kt9
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/LockscreenContent.kt19
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/NotificationLockscreenScrim.kt119
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt53
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt19
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/transitions/FromLockscreenToBouncerTransition.kt6
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt2
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneTransitionInteractorTest.kt4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractorTest.kt7
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorTest.kt2
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelTest.kt2
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModelTest.kt43
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelTest.kt94
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModelTest.kt94
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tileimpl/QSIconViewImplTest.java36
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapperTest.kt95
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractorTest.kt131
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelTest.kt94
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/recordissue/IssueRecordingServiceSessionTest.kt (renamed from packages/SystemUI/multivalentTests/src/com/android/systemui/recordissue/IssueRecordingServiceCommandHandlerTest.kt)20
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt2
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt34
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt41
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelTest.kt56
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorTest.kt11
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorTest.kt17
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt82
-rw-r--r--packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java5
-rw-r--r--packages/SystemUI/shared/Android.bp1
-rw-r--r--packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java17
-rw-r--r--packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerActionButtonInteractor.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt7
-rw-r--r--packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/flags/FlagDependencies.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/haptics/msdl/MSDLCoreStartable.kt34
-rw-r--r--packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialMetricsLogger.kt55
-rw-r--r--packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/TutorialNotificationCoordinator.kt17
-rw-r--r--packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java15
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt91
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromOccludedTransitionInteractor.kt14
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractor.kt20
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionBootInteractor.kt7
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionCoreStartable.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt94
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/transitions/IntraBlueprintTransition.kt15
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt13
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerToOccludedTransitionViewModel.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryBackgroundViewModel.kt29
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModel.kt44
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt16
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModel.kt26
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModel.kt49
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModel.kt25
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListener.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt201
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHostStatesManager.kt18
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt35
-rw-r--r--packages/SystemUI/src/com/android/systemui/mediaprojection/permission/MediaProjectionPermissionActivity.java42
-rw-r--r--packages/SystemUI/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModel.kt48
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt60
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSIconViewImpl.java30
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt1
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java31
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapper.kt53
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractor.kt62
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/model/InternetTileModel.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModel.kt47
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java6
-rw-r--r--packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt14
-rw-r--r--packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingServiceSession.kt (renamed from packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingServiceCommandHandler.kt)14
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKeys.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/ShadeControllerSceneImpl.kt35
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractor.kt52
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorEmptyImpl.kt16
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImpl.kt6
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImpl.kt27
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt89
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeLockscreenInteractorImpl.kt21
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeModeInteractor.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModel.kt18
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/core/StatusBarConntectedDisplays.kt61
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.kt59
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManager.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinator.kt35
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorLogger.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/OriginalUnseenKeyguardCoordinator.kt7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt27
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/VisualStabilityCoordinator.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractor.kt35
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewbinder/EmptyShadeViewBinder.kt13
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt26
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewbinder/FooterViewBinder.kt26
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt31
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/shared/NotificationMinimalism.kt (renamed from packages/SystemUI/src/com/android/systemui/statusbar/notification/shared/NotificationMinimalismPrototype.kt)10
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java25
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java31
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt6
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/data/repository/NotificationPlaceholderRepository.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/NotificationStackAppearanceInteractor.kt18
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/view/NotificationScrollView.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationScrollViewBinder.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationLockscreenScrimViewModel.kt53
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationScrollViewModel.kt39
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java70
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/model/InternetTileIconModel.kt27
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/ModesDialogDelegate.kt65
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepositoryTest.java (renamed from packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepositoryTest.java)0
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java41
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/authentication/data/repository/AuthenticationRepositoryTest.kt (renamed from packages/SystemUI/multivalentTests/src/com/android/systemui/authentication/data/repository/AuthenticationRepositoryTest.kt)0
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt (renamed from packages/SystemUI/multivalentTests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt)0
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/scenetransition/LockscreenSceneTransitionInteractorTest.kt103
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListenerTest.kt33
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt186
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java29
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt188
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt61
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/HeadsUpNotificationInteractorTest.kt15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelTest.kt34
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt5
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardTransitionRepository.kt34
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt5
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModelKosmos.kt28
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelKosmos.kt28
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt6
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/NotificationsShadeOverlayContentViewModelKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorKosmos.kt14
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt2
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java237
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java15
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java86
-rw-r--r--services/accessibility/java/com/android/server/accessibility/ProxyAccessibilityServiceConnection.java13
-rw-r--r--services/accessibility/java/com/android/server/accessibility/ProxyManager.java6
-rw-r--r--services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java93
-rw-r--r--services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java31
-rw-r--r--services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java281
-rw-r--r--services/core/java/android/os/BatteryStatsInternal.java10
-rw-r--r--services/core/java/com/android/server/StorageManagerService.java4
-rw-r--r--services/core/java/com/android/server/accounts/AccountManagerService.java88
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java88
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java11
-rw-r--r--services/core/java/com/android/server/am/SettingsToPropertiesMapper.java9
-rw-r--r--services/core/java/com/android/server/am/flags.aconfig10
-rw-r--r--services/core/java/com/android/server/appop/AppOpsService.java3
-rw-r--r--services/core/java/com/android/server/display/DisplayManagerService.java32
-rw-r--r--services/core/java/com/android/server/flags/pinner.aconfig13
-rw-r--r--services/core/java/com/android/server/input/InputManagerInternal.java7
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java21
-rw-r--r--services/core/java/com/android/server/input/NativeInputManagerService.java4
-rw-r--r--services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java3
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java1
-rw-r--r--services/core/java/com/android/server/inputmethod/ZeroJankProxy.java1
-rw-r--r--services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java7
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java38
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java56
-rw-r--r--services/core/java/com/android/server/notification/PermissionHelper.java21
-rw-r--r--services/core/java/com/android/server/notification/PreferencesHelper.java11
-rw-r--r--services/core/java/com/android/server/notification/flags.aconfig17
-rw-r--r--services/core/java/com/android/server/pinner/PinRangeSource.java27
-rw-r--r--services/core/java/com/android/server/pinner/PinRangeSourceStatic.java37
-rw-r--r--services/core/java/com/android/server/pinner/PinRangeSourceStream.java43
-rw-r--r--services/core/java/com/android/server/pinner/PinnedFile.java61
-rw-r--r--services/core/java/com/android/server/pinner/PinnerService.java (renamed from services/core/java/com/android/server/PinnerService.java)572
-rw-r--r--services/core/java/com/android/server/pinner/PinnerUtils.java75
-rw-r--r--services/core/java/com/android/server/pm/DexOptHelper.java2
-rw-r--r--services/core/java/com/android/server/pm/PackageInstallerService.java33
-rw-r--r--services/core/java/com/android/server/pm/permission/PermissionManagerService.java3
-rw-r--r--services/core/java/com/android/server/power/Notifier.java12
-rw-r--r--services/core/java/com/android/server/power/feature/PowerManagerFlags.java13
-rw-r--r--services/core/java/com/android/server/power/feature/power_flags.aconfig10
-rw-r--r--services/core/java/com/android/server/power/stats/wakeups/CpuWakeupStats.java6
-rw-r--r--services/core/java/com/android/server/stats/pull/StatsPullAtomService.java4
-rw-r--r--services/core/java/com/android/server/vibrator/VibratorController.java62
-rw-r--r--services/core/java/com/android/server/vibrator/VibratorManagerService.java8
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerService.java4
-rw-r--r--services/core/java/com/android/server/webkit/SystemImpl.java8
-rw-r--r--services/core/java/com/android/server/wm/ActivityStarter.java3
-rw-r--r--services/core/java/com/android/server/wm/AppCompatCameraOverrides.java2
-rw-r--r--services/core/java/com/android/server/wm/AppCompatCameraPolicy.java5
-rw-r--r--services/core/java/com/android/server/wm/BackgroundActivityStartController.java15
-rw-r--r--services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java2
-rw-r--r--services/core/java/com/android/server/wm/InputMonitor.java3
-rw-r--r--services/core/java/com/android/server/wm/Task.java3
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java4
-rw-r--r--services/core/java/com/android/server/wm/WindowOrganizerController.java7
-rw-r--r--services/core/java/com/android/server/wm/WindowState.java7
-rw-r--r--services/core/jni/com_android_server_input_InputManagerService.cpp58
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java30
-rw-r--r--services/java/com/android/server/SystemServer.java1
-rw-r--r--services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/pkg/PackageStateTest.kt1
-rw-r--r--services/tests/RemoteProvisioningServiceTests/Android.bp1
-rw-r--r--services/tests/RemoteProvisioningServiceTests/src/com/android/server/security/rkp/RemoteProvisioningShellCommandTest.java1
-rw-r--r--services/tests/appfunctions/src/android/app/appfunctions/GenericDocumentWrapperTest.kt78
-rw-r--r--services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java64
-rw-r--r--services/tests/powerstatstests/res/xml/irq_device_map_3.xml3
-rw-r--r--services/tests/powerstatstests/src/com/android/server/power/stats/wakeups/CpuWakeupStatsTest.java87
-rw-r--r--services/tests/servicestests/Android.bp2
-rw-r--r--services/tests/servicestests/src/com/android/server/PinnerServiceTest.java138
-rw-r--r--services/tests/servicestests/src/com/android/server/accessibility/AbstractAccessibilityServiceConnectionTest.java12
-rw-r--r--services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java37
-rw-r--r--services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java62
-rw-r--r--services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java130
-rw-r--r--services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java26
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java92
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java84
-rw-r--r--services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerTest.java42
-rw-r--r--services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java23
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java10
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppCompatCameraPolicyTest.java18
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/AppCompatUtilsTest.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java14
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java8
-rw-r--r--services/usb/java/com/android/server/usb/UsbDeviceManager.java16
-rw-r--r--telephony/java/android/telephony/data/ApnSetting.java38
-rw-r--r--telephony/java/android/telephony/satellite/SatelliteManager.java9
-rw-r--r--tests/testables/Android.bp5
-rw-r--r--tests/testables/src/android/testing/TestWithLooperRule.java5
-rw-r--r--tests/testables/tests/Android.bp1
-rw-r--r--tests/testables/tests/src/android/testing/TestableLooperJUnit4Test.java42
-rw-r--r--tools/aapt2/Debug.cpp15
-rw-r--r--tools/aapt2/Resource.h17
-rw-r--r--tools/aapt2/ResourceParser.cpp79
-rw-r--r--tools/aapt2/ResourceParser.h7
-rw-r--r--tools/aapt2/ResourceTable.cpp101
-rw-r--r--tools/aapt2/ResourceTable.h17
-rw-r--r--tools/aapt2/ResourceValues.cpp1
-rw-r--r--tools/aapt2/ResourceValues.h12
-rw-r--r--tools/aapt2/Resources.proto5
-rw-r--r--tools/aapt2/ResourcesInternal.proto5
-rw-r--r--tools/aapt2/cmd/Compile.cpp67
-rw-r--r--tools/aapt2/cmd/Diff.cpp28
-rw-r--r--tools/aapt2/cmd/Util.cpp38
-rw-r--r--tools/aapt2/cmd/Util.h6
-rw-r--r--tools/aapt2/format/proto/ProtoDeserialize.cpp41
-rw-r--r--tools/aapt2/format/proto/ProtoSerialize.cpp23
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/Android.bp16
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/drawable/removedpng.pngbin0 -> 5634 bytes
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/layout/layout2.xml6
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/values/bools.xml4
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.trueFlag)/layout/layout3.xml10
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/layout/layout3.xml6
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/bools.xml11
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.falseFlag)/bools.xml4
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.trueFlag)/bools.xml4
-rw-r--r--tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(test.package.trueFlag)/bools.xml4
-rw-r--r--tools/aapt2/link/FlaggedResources_test.cpp50
-rw-r--r--tools/aapt2/link/TableMerger.cpp26
-rw-r--r--tools/aapt2/test/Common.cpp17
-rw-r--r--tools/aapt2/test/Common.h26
-rw-r--r--tools/aapt2/test/Fixture.cpp7
-rw-r--r--tools/aapt2/test/Fixture.h3
408 files changed, 12959 insertions, 2844 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java b/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java
index 0f3b1c366fb0..033da2df9bf6 100644
--- a/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java
+++ b/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java
@@ -4944,10 +4944,14 @@ public class AlarmManagerService extends SystemService {
@Override
public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (action == null) {
+ return;
+ }
final int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
synchronized (mLock) {
String pkgList[] = null;
- switch (intent.getAction()) {
+ switch (action) {
case Intent.ACTION_QUERY_PACKAGE_RESTART:
pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
for (String packageName : pkgList) {
diff --git a/core/api/current.txt b/core/api/current.txt
index 8eb881139b34..3ffab902f18d 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -6854,6 +6854,47 @@ package android.app {
method public android.app.Notification.MessagingStyle.Message setData(String, android.net.Uri);
}
+ @FlaggedApi("android.app.api_rich_ongoing") public static class Notification.ProgressStyle extends android.app.Notification.Style {
+ ctor public Notification.ProgressStyle();
+ method @NonNull public android.app.Notification.ProgressStyle addProgressSegment(@NonNull android.app.Notification.ProgressStyle.Segment);
+ method @NonNull public android.app.Notification.ProgressStyle addProgressStep(@NonNull android.app.Notification.ProgressStyle.Step);
+ method public int getProgress();
+ method @Nullable public android.graphics.drawable.Icon getProgressEndIcon();
+ method public int getProgressMax();
+ method @NonNull public java.util.List<android.app.Notification.ProgressStyle.Segment> getProgressSegments();
+ method @Nullable public android.graphics.drawable.Icon getProgressStartIcon();
+ method @NonNull public java.util.List<android.app.Notification.ProgressStyle.Step> getProgressSteps();
+ method @Nullable public android.graphics.drawable.Icon getProgressTrackerIcon();
+ method public boolean isProgressIndeterminate();
+ method public boolean isStyledByProgress();
+ method @NonNull public android.app.Notification.ProgressStyle setProgress(int);
+ method @NonNull public android.app.Notification.ProgressStyle setProgressEndIcon(@Nullable android.graphics.drawable.Icon);
+ method @NonNull public android.app.Notification.ProgressStyle setProgressIndeterminate(boolean);
+ method @NonNull public android.app.Notification.ProgressStyle setProgressSegments(@NonNull java.util.List<android.app.Notification.ProgressStyle.Segment>);
+ method @NonNull public android.app.Notification.ProgressStyle setProgressStartIcon(@Nullable android.graphics.drawable.Icon);
+ method @NonNull public android.app.Notification.ProgressStyle setProgressSteps(@NonNull java.util.List<android.app.Notification.ProgressStyle.Step>);
+ method @NonNull public android.app.Notification.ProgressStyle setProgressTrackerIcon(@Nullable android.graphics.drawable.Icon);
+ method @NonNull public android.app.Notification.ProgressStyle setStyledByProgress(boolean);
+ }
+
+ public static final class Notification.ProgressStyle.Segment {
+ ctor public Notification.ProgressStyle.Segment(int);
+ method @ColorInt public int getColor();
+ method public int getLength();
+ method public int getStableId();
+ method @NonNull public android.app.Notification.ProgressStyle.Segment setColor(@ColorInt int);
+ method @NonNull public android.app.Notification.ProgressStyle.Segment setStableId(int);
+ }
+
+ public static final class Notification.ProgressStyle.Step {
+ ctor public Notification.ProgressStyle.Step(int);
+ method @ColorInt public int getColor();
+ method public int getPosition();
+ method public int getStableId();
+ method @NonNull public android.app.Notification.ProgressStyle.Step setColor(@ColorInt int);
+ method @NonNull public android.app.Notification.ProgressStyle.Step setStableId(int);
+ }
+
public abstract static class Notification.Style {
ctor @Deprecated public Notification.Style();
method public android.app.Notification build();
@@ -8732,13 +8773,15 @@ package android.app.admin {
package android.app.appfunctions {
@FlaggedApi("android.app.appfunctions.flags.enable_app_function_manager") public final class AppFunctionManager {
- method @RequiresPermission(anyOf={"android.permission.EXECUTE_APP_FUNCTIONS_TRUSTED", "android.permission.EXECUTE_APP_FUNCTIONS"}, conditional=true) public void executeAppFunction(@NonNull android.app.appfunctions.ExecuteAppFunctionRequest, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.app.appfunctions.ExecuteAppFunctionResponse>);
+ method @Deprecated @RequiresPermission(anyOf={"android.permission.EXECUTE_APP_FUNCTIONS_TRUSTED", "android.permission.EXECUTE_APP_FUNCTIONS"}, conditional=true) public void executeAppFunction(@NonNull android.app.appfunctions.ExecuteAppFunctionRequest, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.app.appfunctions.ExecuteAppFunctionResponse>);
+ method @RequiresPermission(anyOf={"android.permission.EXECUTE_APP_FUNCTIONS_TRUSTED", "android.permission.EXECUTE_APP_FUNCTIONS"}, conditional=true) public void executeAppFunction(@NonNull android.app.appfunctions.ExecuteAppFunctionRequest, @NonNull java.util.concurrent.Executor, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<android.app.appfunctions.ExecuteAppFunctionResponse>);
}
@FlaggedApi("android.app.appfunctions.flags.enable_app_function_manager") public abstract class AppFunctionService extends android.app.Service {
ctor public AppFunctionService();
method @NonNull public final android.os.IBinder onBind(@Nullable android.content.Intent);
- method @MainThread public abstract void onExecuteFunction(@NonNull android.app.appfunctions.ExecuteAppFunctionRequest, @NonNull java.util.function.Consumer<android.app.appfunctions.ExecuteAppFunctionResponse>);
+ method @Deprecated @MainThread public abstract void onExecuteFunction(@NonNull android.app.appfunctions.ExecuteAppFunctionRequest, @NonNull java.util.function.Consumer<android.app.appfunctions.ExecuteAppFunctionResponse>);
+ method @MainThread public void onExecuteFunction(@NonNull android.app.appfunctions.ExecuteAppFunctionRequest, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<android.app.appfunctions.ExecuteAppFunctionResponse>);
field @NonNull public static final String SERVICE_INTERFACE = "android.app.appfunctions.AppFunctionService";
}
@@ -46655,6 +46698,8 @@ package android.telephony.data {
field public static final int TYPE_IMS = 64; // 0x40
field public static final int TYPE_MCX = 1024; // 0x400
field public static final int TYPE_MMS = 2; // 0x2
+ field @FlaggedApi("com.android.internal.telephony.flags.oem_paid_private") public static final int TYPE_OEM_PAID = 65536; // 0x10000
+ field @FlaggedApi("com.android.internal.telephony.flags.oem_paid_private") public static final int TYPE_OEM_PRIVATE = 131072; // 0x20000
field @FlaggedApi("com.android.internal.telephony.flags.carrier_enabled_satellite_flag") public static final int TYPE_RCS = 32768; // 0x8000
field public static final int TYPE_SUPL = 4; // 0x4
field public static final int TYPE_VSIM = 4096; // 0x1000
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index bfddf4fb5fac..bc34f5bfe13f 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -6833,6 +6833,16 @@ package android.hardware.soundtrigger {
field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.RecognitionConfig> CREATOR;
}
+ public static final class SoundTrigger.RecognitionConfig.Builder {
+ ctor public SoundTrigger.RecognitionConfig.Builder();
+ method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig build();
+ method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setAllowMultipleTriggers(boolean);
+ method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setAudioCapabilities(int);
+ method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setCaptureRequested(boolean);
+ method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setData(@Nullable byte[]);
+ method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setKeyphrases(@NonNull java.util.Collection<android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra>);
+ }
+
public static class SoundTrigger.RecognitionEvent {
method @Nullable public android.media.AudioFormat getCaptureFormat();
method public int getCaptureSession();
@@ -15878,6 +15888,8 @@ package android.telephony.data {
field public static final String TYPE_IMS_STRING = "ims";
field public static final String TYPE_MCX_STRING = "mcx";
field public static final String TYPE_MMS_STRING = "mms";
+ field @FlaggedApi("com.android.internal.telephony.flags.oem_paid_private") public static final String TYPE_OEM_PAID_STRING = "oem_paid";
+ field @FlaggedApi("com.android.internal.telephony.flags.oem_paid_private") public static final String TYPE_OEM_PRIVATE_STRING = "oem_private";
field @FlaggedApi("com.android.internal.telephony.flags.carrier_enabled_satellite_flag") public static final String TYPE_RCS_STRING = "rcs";
field public static final String TYPE_SUPL_STRING = "supl";
field public static final String TYPE_VSIM_STRING = "vsim";
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index cc9e8367dc3d..0a10920154b8 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -1614,15 +1614,15 @@ package android.hardware.camera2 {
public final class CameraManager {
method @NonNull public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(@NonNull String, boolean) throws android.hardware.camera2.CameraAccessException;
method public String[] getCameraIdListNoLazy() throws android.hardware.camera2.CameraAccessException;
- method @FlaggedApi("com.android.window.flags.camera_compat_for_freeform") public static int getRotationOverrideInternal(@Nullable android.content.Context, @Nullable android.content.pm.PackageManager, @Nullable String);
+ method @FlaggedApi("com.android.window.flags.enable_camera_compat_for_desktop_windowing") public static int getRotationOverrideInternal(@Nullable android.content.Context, @Nullable android.content.pm.PackageManager, @Nullable String);
method @RequiresPermission(android.Manifest.permission.CAMERA) public void openCamera(@NonNull String, boolean, @Nullable android.os.Handler, @NonNull android.hardware.camera2.CameraDevice.StateCallback) throws android.hardware.camera2.CameraAccessException;
method @RequiresPermission(allOf={android.Manifest.permission.SYSTEM_CAMERA, android.Manifest.permission.CAMERA}) public void openCamera(@NonNull String, int, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraDevice.StateCallback) throws android.hardware.camera2.CameraAccessException;
method public static boolean shouldOverrideToPortrait(@Nullable android.content.pm.PackageManager, @Nullable String);
field public static final String LANDSCAPE_TO_PORTRAIT_PROP = "camera.enable_landscape_to_portrait";
field public static final long OVERRIDE_CAMERA_LANDSCAPE_TO_PORTRAIT = 250678880L; // 0xef10e60L
- field @FlaggedApi("com.android.window.flags.camera_compat_for_freeform") public static final int ROTATION_OVERRIDE_NONE = 0; // 0x0
- field @FlaggedApi("com.android.window.flags.camera_compat_for_freeform") public static final int ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT = 1; // 0x1
- field @FlaggedApi("com.android.window.flags.camera_compat_for_freeform") public static final int ROTATION_OVERRIDE_ROTATION_ONLY = 2; // 0x2
+ field @FlaggedApi("com.android.window.flags.enable_camera_compat_for_desktop_windowing") public static final int ROTATION_OVERRIDE_NONE = 0; // 0x0
+ field @FlaggedApi("com.android.window.flags.enable_camera_compat_for_desktop_windowing") public static final int ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT = 1; // 0x1
+ field @FlaggedApi("com.android.window.flags.enable_camera_compat_for_desktop_windowing") public static final int ROTATION_OVERRIDE_ROTATION_ONLY = 2; // 0x2
}
public abstract static class CameraManager.AvailabilityCallback {
@@ -1887,7 +1887,7 @@ package android.hardware.soundtrigger {
}
@FlaggedApi("android.media.soundtrigger.manager_api") public static final class SoundTrigger.RecognitionConfig implements android.os.Parcelable {
- ctor public SoundTrigger.RecognitionConfig(boolean, boolean, @Nullable android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra[], @Nullable byte[], int);
+ ctor @Deprecated public SoundTrigger.RecognitionConfig(boolean, boolean, @Nullable android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra[], @Nullable byte[], int);
ctor public SoundTrigger.RecognitionConfig(boolean, boolean, @Nullable android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra[], @Nullable byte[]);
}
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 392a1f113c23..a39f216d033e 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -121,7 +121,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -783,10 +782,32 @@ public class Notification implements Parcelable
@FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
public static final int FLAG_PROMOTED_ONGOING = 0x00040000;
- private static final List<Class<? extends Style>> PLATFORM_STYLE_CLASSES = Arrays.asList(
- BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class,
- DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class,
- MessagingStyle.class, CallStyle.class);
+ private static final Set<Class<? extends Style>> PLATFORM_STYLE_CLASSES = Set.of(
+ BigTextStyle.class,
+ BigPictureStyle.class,
+ InboxStyle.class,
+ MediaStyle.class,
+ DecoratedCustomViewStyle.class,
+ DecoratedMediaCustomViewStyle.class,
+ MessagingStyle.class,
+ CallStyle.class
+ );
+
+ private static boolean isPlatformStyle(Style style) {
+ if (style == null) {
+ return false;
+ }
+
+ if (PLATFORM_STYLE_CLASSES.contains(style.getClass())) {
+ return true;
+ }
+
+ if (Flags.apiRichOngoing()) {
+ return style.getClass() == ProgressStyle.class;
+ }
+
+ return false;
+ }
/** @hide */
@IntDef(flag = true, prefix = {"FLAG_"}, value = {
@@ -1620,6 +1641,66 @@ public class Notification implements Parcelable
public static final String EXTRA_COLORIZED = "android.colorized";
/**
+ * {@link #extras} key: an arraylist of {@link android.app.Notification.ProgressStyle.Segment}
+ * bundles provided by a
+ * {@link android.app.Notification.ProgressStyle} notification as supplied to
+ * {@link ProgressStyle#setProgressSegments}
+ * or {@link ProgressStyle#addProgressSegment(ProgressStyle.Segment)}.
+ * This extra is a parcelable array list of bundles.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static final String EXTRA_PROGRESS_SEGMENTS = "android.progressSegments";
+
+ /**
+ * {@link #extras} key: an arraylist of {@link android.app.Notification.ProgressStyle.Step}
+ * bundles provided by a
+ * {@link android.app.Notification.ProgressStyle} notification as supplied to
+ * {@link ProgressStyle#setProgressSteps}
+ * or {@link ProgressStyle#addProgressStep(ProgressStyle.Step)}.
+ * This extra is a parcelable array list of bundles.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static final String EXTRA_PROGRESS_STEPS = "android.progressSteps";
+
+ /**
+ * {@link #extras} key: whether the progress bar should be styled by its progress as
+ * supplied to {@link ProgressStyle#setStyledByProgress}.
+ * This extra is a boolean.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static final String EXTRA_STYLED_BY_PROGRESS = "android.styledByProgress";
+
+ /**
+ * {@link #extras} key: this is an {@link Icon} of an image to be
+ * shown as progress bar progress tracker icon in {@link ProgressStyle}, supplied to
+ *{@link ProgressStyle#setProgressTrackerIcon(Icon)}.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static final String EXTRA_PROGRESS_TRACKER_ICON = "android.progressTrackerIcon";
+
+ /**
+ * {@link #extras} key: this is an {@link Icon} of an image to be
+ * shown at the beginning of the progress bar in {@link ProgressStyle}, supplied to
+ *{@link ProgressStyle#setProgressStartIcon(Icon)}.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static final String EXTRA_PROGRESS_START_ICON = "android.progressStartIcon";
+
+ /**
+ * {@link #extras} key: this is an {@link Icon} of an image to be
+ * shown at the end of the progress bar in {@link ProgressStyle}, supplied to
+ *{@link ProgressStyle#setProgressEndIcon(Icon)}.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static final String EXTRA_PROGRESS_END_ICON = "android.progressEndIcon";
+
+ /**
* @hide
*/
public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo";
@@ -3072,6 +3153,9 @@ public class Notification implements Parcelable
if (Flags.apiRichOngoing()) {
visitIconUri(visitor, extras.getParcelable(EXTRA_ENROUTE_OVERLAY_ICON, Icon.class));
+ visitIconUri(visitor, extras.getParcelable(EXTRA_PROGRESS_TRACKER_ICON, Icon.class));
+ visitIconUri(visitor, extras.getParcelable(EXTRA_PROGRESS_START_ICON, Icon.class));
+ visitIconUri(visitor, extras.getParcelable(EXTRA_PROGRESS_END_ICON, Icon.class));
}
if (mBubbleMetadata != null) {
@@ -6630,7 +6714,7 @@ public class Notification implements Parcelable
// Custom views which come from a platform style class are safe, and thus do not need to
// be wrapped. Any subclass of those styles has the opportunity to make arbitrary
// changes to the RemoteViews, and thus can't be trusted as a fully vetted view.
- if (fromStyle && PLATFORM_STYLE_CLASSES.contains(mStyle.getClass())) {
+ if (fromStyle && isPlatformStyle(mStyle)) {
return false;
}
return mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S;
@@ -7971,6 +8055,12 @@ public class Notification implements Parcelable
return innerClass;
}
}
+
+ if (Flags.apiRichOngoing()) {
+ if (templateClass.equals(ProgressStyle.class.getName())) {
+ return ProgressStyle.class;
+ }
+ }
return null;
}
@@ -11220,6 +11310,724 @@ public class Notification implements Parcelable
}
}
+
+ /**
+ * A Notification Style used to to define a notification whose expanded state includes
+ * a highly customizable progress bar with segments, steps, a custom tracker icon,
+ * and custom icons at the start and end of the progress bar.
+ *
+ * This style is suggested for use cases where the app is showing a tracker to the
+ * user of a thing they are interested in: the location of a car on its way
+ * to pick them up, food being delivered, or their own progress in a navigation
+ * journey.
+ *
+ * To use this style with your Notification, feed it to
+ * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so:
+ * <pre class="prettyprint">
+ * new Notification.Builder(context)
+ * .setSmallIcon(R.drawable.ic_notification)
+ * .setColor(Color.GREEN)
+ * .setColorized(true)
+ * .setContentTitle("Arrive 10:08 AM").
+ * .setContentText("Dominique Ansel Bakery Soho")
+ * .addAction(new Notification.Action("Exit navigation",...))
+ * .setStyle(new Notification.ProgressStyle()
+ * .setStyledByProgress(false)
+ * .setProgress(456)
+ * .setProgressTrackerIcon(Icon.createWithResource(R.drawable.ic_driving_tracker))
+ * .addProgressSegment(new Segment(41).setColor(Color.BLACK))
+ * .addProgressSegment(new Segment(552).setColor(Color.YELLOW))
+ * .addProgressSegment(new Segment(253).setColor(Color.YELLOW))
+ * .addProgressSegment(new Segment(94).setColor(Color.BLUE))
+ * .addProgressStep(new Step(60).setColor(Color.RED))
+ * .addProgressStep(new Step(560).setColor(Color.YELLOW))
+ * )
+ * </pre>
+ *
+ *
+ *
+ * NOTE: The progress bar layout will be mirrored for RTL layout.
+ * NOTE: The extras set by {@link Notification.Builder#setProgress} will be overridden by
+ * the values set on this style object when the notification is built.
+ *
+ */
+ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
+ public static class ProgressStyle extends Notification.Style {
+ private static final String KEY_ELEMENT_STABLE_ID = "stableId";
+ private static final String KEY_ELEMENT_COLOR = "colorInt";
+ private static final String KEY_SEGMENT_LENGTH = "length";
+ private static final String KEY_STEP_POSITION = "position";
+
+ private static final int MAX_PROGRESS_SEGMENT_LIMIT = 15;
+ private static final int MAX_PROGRESS_STEP_LIMIT = 5;
+ private static final int DEFAULT_PROGRESS_MAX = 100;
+
+ private List<Segment> mProgressSegments = new ArrayList<>();
+ private List<Step> mProgressSteps = new ArrayList<>();
+
+ private int mProgress = 0;
+
+ private boolean mIndeterminate;
+
+ private boolean mIsStyledByProgress = true;
+
+ @Nullable
+ private Icon mTrackerIcon;
+ @Nullable
+ private Icon mStartIcon;
+ @Nullable
+ private Icon mEndIcon;
+
+ /**
+ * @hide
+ */
+ @Override
+ public boolean areNotificationsVisiblyDifferent(Style other) {
+ if (other == null || getClass() != other.getClass()) {
+ return true;
+ }
+
+ final ProgressStyle progressStyle = (ProgressStyle) other;
+
+ /**
+ * @see #setProgressIndeterminate
+ */
+ if (!Objects.equals(mIndeterminate, progressStyle.mIndeterminate)) {
+ return true;
+ }
+ boolean nonIndeterminateCheckResult = false;
+ if (!mIndeterminate) {
+ nonIndeterminateCheckResult = !Objects.equals(mProgress, progressStyle.mProgress)
+ || !Objects.equals(mIsStyledByProgress, progressStyle.mIsStyledByProgress)
+ || !Objects.equals(mProgressSegments, progressStyle.mProgressSegments)
+ || !Objects.equals(mProgressSteps, progressStyle.mProgressSteps)
+ || !Objects.equals(mTrackerIcon, progressStyle.mTrackerIcon);
+ }
+
+ return !Objects.equals(mStartIcon, progressStyle.mStartIcon)
+ || !Objects.equals(mEndIcon, progressStyle.mEndIcon)
+ || nonIndeterminateCheckResult;
+ }
+
+ /**
+ * Gets the segments that define the background layer of the progress bar.
+ *
+ * If no segments are provided, the progress bar will be rendered with a single segment
+ * with length 100 and default color.
+ *
+ * @see #setProgressSegments
+ * @see #addProgressSegment
+ * @see Segment
+ */
+ public @NonNull List<Segment> getProgressSegments() {
+ return mProgressSegments;
+ }
+
+ /**
+ * Sets or replaces the segments of the progress bar.
+ *
+ * Segments allow for creating progress bars with multiple colors or sections
+ * to represent different stages or categories of progress.
+ * For example, Traffic conditions along a navigation journey.
+ * @see Segment
+ */
+ public @NonNull ProgressStyle setProgressSegments(@NonNull List<Segment> progressSegments) {
+ mProgressSegments = new ArrayList<>(progressSegments.size());
+ return this;
+ }
+
+ /**
+ * Appends a segment to the end of the progress bar.
+ *
+ * Segments allow for creating progress bars with multiple colors or sections
+ * to represent different stages or categories of progress.
+ * For example, Traffic conditions along a navigation journey.
+ * @see Segment
+ */
+ public @NonNull ProgressStyle addProgressSegment(@NonNull Segment segment) {
+ if (mProgressSegments == null) {
+ mProgressSegments = new ArrayList<>();
+ }
+ mProgressSegments.add(segment);
+
+ return this;
+ }
+
+ /**
+ * Gets the steps that are displayed on the progress bar.
+ *.
+ * @see #setProgressSteps
+ * @see #addProgressStep
+ * @see Step
+ */
+ public @NonNull List<Step> getProgressSteps() {
+ return mProgressSteps;
+ }
+
+ /**
+ * Replaces all the progress steps.
+ *
+ * Steps are designated points within a progressbar to visualize
+ * distinct stages or milestones.
+ * For example, you might use steps to mark stops in a multi-stop
+ * navigation journey, where each step represents a destination.
+ * @see Step
+ */
+ public @NonNull ProgressStyle setProgressSteps(@NonNull List<Step> steps) {
+ mProgressSteps = new ArrayList<>(steps);
+ return this;
+ }
+
+ /**
+ * Adds another step.
+ *
+ * Steps are designated points within a progressbar to visualize
+ * distinct stages or milestones.
+ * For example, you might use steps to mark stops in a multi-stop
+ * navigation journey, where each step represents a destination.
+ *
+ * Steps can be added in any order, as their
+ * position within the progress bar is determined by their individual
+ * {@link Step#getPosition()}.
+ * @see Step
+ */
+ public @NonNull ProgressStyle addProgressStep(@NonNull Step step) {
+ if (mProgressSteps == null) {
+ mProgressSteps = new ArrayList<>();
+ }
+ mProgressSteps.add(step);
+
+ return this;
+ }
+
+ /**
+ * Gets the progress value of the progress bar.
+ * @see #setProgress
+ */
+ public int getProgress() {
+ return mProgress;
+ }
+
+ /**
+ * Specifies the progress (in the same units as {@link Segment#getLength()})
+ * of the tracker along the length of the bar.
+ *
+ * The max progress value is the sum of all Segment lengths.
+ * The default value is 0.
+ */
+ public @NonNull ProgressStyle setProgress(int progress) {
+ mProgress = progress;
+ return this;
+ }
+
+ /**
+ * Gets the sum of the lengths of all Segments in the style, which
+ * defines the maximum progress. Defaults to 100 when segments are omitted.
+ */
+ public int getProgressMax() {
+ final List<Segment> progressSegment = mProgressSegments;
+ if (progressSegment == null || progressSegment.isEmpty()) {
+ return DEFAULT_PROGRESS_MAX;
+ } else {
+ int progressMax = 0;
+ int validSegmentCount = 0;
+ for (int i = 0; i < progressSegment.size()
+ && validSegmentCount < MAX_PROGRESS_SEGMENT_LIMIT; i++) {
+ int segmentLength = progressSegment.get(i).getLength();
+ if (segmentLength > 0) {
+ try {
+ progressMax = Math.addExact(progressMax, segmentLength);
+ validSegmentCount++;
+ } catch (ArithmeticException e) {
+ Log.e(TAG,
+ "Notification.ProgressStyle segment total overflowed.", e);
+ return DEFAULT_PROGRESS_MAX;
+ }
+ }
+ }
+
+ if (validSegmentCount == 0) {
+ return DEFAULT_PROGRESS_MAX;
+ }
+
+ return progressMax;
+ }
+
+ }
+
+ /**
+ * Get indeterminate value of the progress bar.
+ * @see #setProgressIndeterminate
+ */
+ public boolean isProgressIndeterminate() {
+ return mIndeterminate;
+ }
+
+ /**
+ * Used to indicate an initialization state without a known progress amount.
+ * When specified, the following fields are ignored:
+ * @see #setProgress
+ * @see #setProgressSegments
+ * @see #setProgressSteps
+ * @see #setProgressTrackerIcon
+ * @see #setStyledByProgress
+ *
+ * If the app provides exactly one Segment, that segment's color will be
+ * used to style the indeterminate bar.
+ */
+ public @NonNull ProgressStyle setProgressIndeterminate(boolean indeterminate) {
+ mIndeterminate = indeterminate;
+ return this;
+ }
+
+ /**
+ * Gets whether the progress bar's style is based on its progress.
+ * @see #setStyledByProgress
+ */
+ public boolean isStyledByProgress() {
+ return mIsStyledByProgress;
+ }
+
+ /**
+ * Indicates whether the segments and steps will be styled differently
+ * based on whether they are behind or ahead of the current progress.
+ * When true, segments appearing ahead of the current progress will be given a
+ * slightly different appearance to indicate that it is part of the progress bar
+ * that is not "filled".
+ * When false, all segments will be given the filled appearance, and it will be
+ * the app's responsibility to use #setProgressTrackerIcon or segment colors
+ * to make the current progress clear to the user.
+ * the default value is true.
+ */
+ public @NonNull ProgressStyle setStyledByProgress(boolean enabled) {
+ mIsStyledByProgress = enabled;
+ return this;
+ }
+
+
+ /**
+ * Gets the progress tracker icon for the progress bar.
+ * @see #setProgressTrackerIcon
+ */
+ public @Nullable Icon getProgressTrackerIcon() {
+ return mTrackerIcon;
+ }
+
+ /**
+ * An optional icon that can appear as an overlay on the bar at the point of
+ * current progress.
+ * Aspect ratio may be anywhere from 2:1 to 1:2; content outside that
+ * aspect ratio range will be cropped.
+ * This icon will be mirrored in RTL.
+ */
+ public @NonNull ProgressStyle setProgressTrackerIcon(@Nullable Icon trackerIcon) {
+ mTrackerIcon = trackerIcon;
+ return this;
+ }
+
+ /**
+ * Gets the progress bar start icon.
+ * @see #setProgressStartIcon
+ */
+ public @Nullable Icon getProgressStartIcon() {
+ return mStartIcon;
+ }
+
+ /**
+ * An optional square icon that appears at the start of the progress bar.
+ * This icon will be cropped to its central square.
+ * This icon will NOT be mirrored in RTL layouts.
+ */
+ public @NonNull ProgressStyle setProgressStartIcon(@Nullable Icon startIcon) {
+ mStartIcon = startIcon;
+ return this;
+ }
+
+ /**
+ * Gets the progress bar end icon.
+ * @see #setProgressEndIcon(Icon)
+ */
+ public @Nullable Icon getProgressEndIcon() {
+ return mEndIcon;
+ }
+
+ /**
+ * An optional square icon that appears at the end of the progress bar.
+ * This icon will be cropped to its central square.
+ * This icon will NOT be mirrored in RTL layouts.
+ */
+ public @NonNull ProgressStyle setProgressEndIcon(@Nullable Icon endIcon) {
+ mEndIcon = endIcon;
+ return this;
+ }
+
+ /**
+ * @hide
+ */
+ @Override
+ public void purgeResources() {
+ super.purgeResources();
+ if (mTrackerIcon != null) {
+ mTrackerIcon.convertToAshmem();
+ }
+ if (mStartIcon != null) {
+ mStartIcon.convertToAshmem();
+ }
+ if (mEndIcon != null) {
+ mEndIcon.convertToAshmem();
+ }
+ }
+
+ /**
+ * @hide
+ */
+ @Override
+ public void reduceImageSizes(Context context) {
+ super.reduceImageSizes(context);
+
+ final Resources resources = context.getResources();
+
+ int progressIconSize =
+ resources.getDimensionPixelSize(R.dimen.notification_progress_icon_size);
+ if (mStartIcon != null) {
+ mStartIcon.scaleDownIfNecessary(progressIconSize, progressIconSize);
+ }
+ if (mEndIcon != null) {
+ mEndIcon.scaleDownIfNecessary(progressIconSize, progressIconSize);
+ }
+ if (mTrackerIcon != null) {
+ int progressTrackerWidth = resources.getDimensionPixelSize(
+ R.dimen.notification_progress_tracker_width);
+ int progressTrackerHeight = resources.getDimensionPixelSize(
+ R.dimen.notification_progress_tracker_height);
+ mTrackerIcon.scaleDownIfNecessary(progressTrackerWidth, progressTrackerHeight);
+ }
+ }
+
+ /**
+ * @hide
+ */
+ @Override
+ public void addExtras(Bundle extras) {
+ super.addExtras(extras);
+ extras.putParcelableArrayList(EXTRA_PROGRESS_SEGMENTS,
+ getProgressSegmentsAsBundleList(mProgressSegments));
+ extras.putParcelableArrayList(EXTRA_PROGRESS_STEPS,
+ getProgressStepsAsBundleList(mProgressSteps));
+
+ extras.putInt(EXTRA_PROGRESS, mProgress);
+ extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mIndeterminate);
+ extras.putInt(EXTRA_PROGRESS_MAX, getProgressMax());
+ extras.putBoolean(EXTRA_STYLED_BY_PROGRESS, mIsStyledByProgress);
+
+ if (mTrackerIcon != null) {
+ extras.putParcelable(EXTRA_PROGRESS_TRACKER_ICON, mTrackerIcon);
+ } else {
+ extras.remove(EXTRA_PROGRESS_TRACKER_ICON);
+ }
+
+ if (mStartIcon != null) {
+ extras.putParcelable(EXTRA_PROGRESS_START_ICON, mStartIcon);
+ } else {
+ extras.remove(EXTRA_PROGRESS_START_ICON);
+ }
+
+ if (mEndIcon != null) {
+ extras.putParcelable(EXTRA_PROGRESS_END_ICON, mEndIcon);
+ } else {
+ extras.remove(EXTRA_PROGRESS_END_ICON);
+ }
+ }
+
+ /**
+ * @hide
+ */
+ @Override
+ protected void restoreFromExtras(Bundle extras) {
+ super.restoreFromExtras(extras);
+ mProgressSegments = getProgressSegmentsFromBundleList(
+ extras.getParcelableArrayList(EXTRA_PROGRESS_SEGMENTS, Bundle.class));
+ mProgress = extras.getInt(EXTRA_PROGRESS, 0);
+ mIndeterminate = extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE, false);
+ mIsStyledByProgress = extras.getBoolean(EXTRA_STYLED_BY_PROGRESS, true);
+ mTrackerIcon = extras.getParcelable(EXTRA_PROGRESS_TRACKER_ICON, Icon.class);
+ mStartIcon = extras.getParcelable(EXTRA_PROGRESS_START_ICON, Icon.class);
+ mEndIcon = extras.getParcelable(EXTRA_PROGRESS_END_ICON, Icon.class);
+ mProgressSteps = getProgressStepsFromBundleList(
+ extras.getParcelableArrayList(EXTRA_PROGRESS_STEPS, Bundle.class));
+ }
+
+ /**
+ * @hide
+ */
+ @Override
+ public boolean displayCustomViewInline() {
+ // This is a lie; True is returned for progress notifications to make sure
+ // that the custom view is not used instead of the template, but it will not
+ // actually be included.
+ return true;
+ }
+
+ private static @NonNull ArrayList<Bundle> getProgressSegmentsAsBundleList(
+ @Nullable List<Segment> progressSegments) {
+ final ArrayList<Bundle> segments = new ArrayList<>();
+ if (progressSegments != null && !progressSegments.isEmpty()) {
+ for (int i = 0; i < progressSegments.size(); i++) {
+ final Segment segment = progressSegments.get(i);
+ if (segment.getLength() <= 0) {
+ continue;
+ }
+
+ final Bundle bundle = new Bundle();
+ bundle.putInt(KEY_SEGMENT_LENGTH, segment.getLength());
+ bundle.putInt(KEY_ELEMENT_STABLE_ID, segment.getStableId());
+ bundle.putInt(KEY_ELEMENT_COLOR, segment.getColor());
+
+ segments.add(bundle);
+ }
+ }
+
+ return segments;
+ }
+
+ private static @NonNull List<Segment> getProgressSegmentsFromBundleList(
+ @Nullable List<Bundle> segmentBundleList) {
+ final ArrayList<Segment> segments = new ArrayList<>();
+ if (segmentBundleList != null && !segmentBundleList.isEmpty()) {
+ for (int i = 0; i < segmentBundleList.size(); i++) {
+ final Bundle segmentBundle = segmentBundleList.get(i);
+ final int length = segmentBundle.getInt(KEY_SEGMENT_LENGTH);
+ if (length <= 0) {
+ continue;
+ }
+
+ final int stableId = segmentBundle.getInt(KEY_ELEMENT_STABLE_ID);
+ final int color = segmentBundle.getInt(KEY_ELEMENT_COLOR,
+ Notification.COLOR_DEFAULT);
+ final Segment segment = new Segment(length)
+ .setStableId(stableId).setColor(color);
+
+ segments.add(segment);
+ }
+ }
+
+ return segments;
+ }
+
+ private static @NonNull ArrayList<Bundle> getProgressStepsAsBundleList(
+ @Nullable List<Step> progressSteps) {
+ final ArrayList<Bundle> steps = new ArrayList<>();
+ if (progressSteps != null && !progressSteps.isEmpty()) {
+ for (int i = 0; i < progressSteps.size(); i++) {
+ final Step step = progressSteps.get(i);
+ if (step.getPosition() < 0) {
+ continue;
+ }
+
+ final Bundle bundle = new Bundle();
+ bundle.putInt(KEY_STEP_POSITION, step.getPosition());
+ bundle.putInt(KEY_ELEMENT_STABLE_ID, step.getStableId());
+ bundle.putInt(KEY_ELEMENT_COLOR, step.getColor());
+
+ steps.add(bundle);
+ }
+ }
+
+ return steps;
+ }
+
+ private static @NonNull List<Step> getProgressStepsFromBundleList(
+ @Nullable List<Bundle> stepBundleList) {
+ final ArrayList<Step> steps = new ArrayList<>();
+
+ if (stepBundleList != null && !stepBundleList.isEmpty()) {
+ for (int i = 0; i < stepBundleList.size(); i++) {
+ final Bundle segmentBundle = stepBundleList.get(i);
+ final int position = segmentBundle.getInt(KEY_STEP_POSITION);
+ if (position < 0) {
+ continue;
+ }
+ final int stableId = segmentBundle.getInt(KEY_ELEMENT_STABLE_ID);
+ final int color = segmentBundle.getInt(KEY_ELEMENT_COLOR,
+ Notification.COLOR_DEFAULT);
+ final Step step = new Step(position).setStableId(stableId).setColor(color);
+ steps.add(step);
+ }
+ }
+
+ return steps;
+ }
+
+ /**
+ * A segment of the progress bar, which defines its length and color.
+ * Segments allow for creating progress bars with multiple colors or sections
+ * to represent different stages or categories of progress.
+ * For example, Traffic conditions along a navigation journey.
+ */
+ public static final class Segment {
+ private int mLength;
+ private int mStableId = 0;
+ @ColorInt
+ private int mColor = Notification.COLOR_DEFAULT;
+
+ /**
+ * Create a segment with a non-zero length.
+ * @param length
+ * See {@link #getLength}
+ */
+ public Segment(int length) {
+ mLength = length;
+ }
+
+ /**
+ * The length of this Segment within the progress bar.
+ * This value has no units, it is just relative to the length of other segments,
+ * and the value provided to {@link ProgressStyle#setProgress}.
+ */
+ public int getLength() {
+ return mLength;
+ }
+
+ /**
+ * Gets the stable id of this Segment.
+ *
+ * @see #setStableId
+ */
+ public int getStableId() {
+ return mStableId;
+ }
+
+ /**
+ * Optional ID used to uniquely identify the element across updates.
+ */
+ public @NonNull Segment setStableId(int stableId) {
+ mStableId = stableId;
+ return this;
+ }
+
+ /**
+ * Returns the color of this Segment.
+ *
+ * @see #setColor
+ */
+ @ColorInt
+ public int getColor() {
+ return mColor;
+ }
+
+ /**
+ * Optional color of this Segment
+ */
+ public @NonNull Segment setColor(@ColorInt int color) {
+ mColor = color;
+ return this;
+ }
+
+ /**
+ * Needed for {@link Notification.Style#areNotificationsVisiblyDifferent}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Segment segment = (Segment) o;
+ return mLength == segment.mLength && mStableId == segment.mStableId
+ && mColor == segment.mColor;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mLength, mStableId, mColor);
+ }
+ }
+
+ /**
+ * A step within the progress bar, defining its position and color.
+ * Steps are designated points within a progressbar to visualize
+ * distinct stages or milestones.
+ * For example, you might use steps to mark stops in a multi-stop
+ * navigation journey, where each step represents a destination.
+ */
+ public static final class Step {
+
+ private int mPosition;
+ private int mStableId;
+ @ColorInt
+ private int mColor = Notification.COLOR_DEFAULT;
+
+ /**
+ * Create a step element.
+ * The position of this step on the progress bar
+ * relative to {@link ProgressStyle#getProgressMax}
+ * @param position
+ * See {@link #getPosition}
+ */
+ public Step(int position) {
+ mPosition = position;
+ }
+
+ /**
+ * Gets the position of this Step.
+ * The position of this step on the progress bar
+ * relative to {@link ProgressStyle#getProgressMax}.
+ */
+ public int getPosition() {
+ return mPosition;
+ }
+
+
+ /**
+ * Optional ID used to uniqurely identify the element across updates.
+ */
+ public int getStableId() {
+ return mStableId;
+ }
+
+ /**
+ * Optional ID used to uniqurely identify the element across updates.
+ */
+ public @NonNull Step setStableId(int stableId) {
+ mStableId = stableId;
+ return this;
+ }
+
+ /**
+ * Returns the color of this Segment.
+ *
+ * @see #setColor
+ */
+ @ColorInt
+ public int getColor() {
+ return mColor;
+ }
+
+ /**
+ * Optional color of this Segment
+ */
+ public @NonNull Step setColor(@ColorInt int color) {
+ mColor = color;
+ return this;
+ }
+
+ /**
+ * Needed for {@link Notification.Style#areNotificationsVisiblyDifferent}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Step step = (Step) o;
+ return mPosition == step.mPosition && mStableId == step.mStableId
+ && mColor == step.mColor;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mPosition, mStableId, mColor);
+ }
+ }
+ }
+
/**
* Notification style for custom views that are decorated by the system
*
diff --git a/core/java/android/app/PropertyInvalidatedCache.java b/core/java/android/app/PropertyInvalidatedCache.java
index 0e761fce9346..c17da249f322 100644
--- a/core/java/android/app/PropertyInvalidatedCache.java
+++ b/core/java/android/app/PropertyInvalidatedCache.java
@@ -54,198 +54,8 @@ import java.util.concurrent.atomic.AtomicLong;
* LRU cache that's invalidated when an opaque value in a property changes. Self-synchronizing,
* but doesn't hold a lock across data fetches on query misses.
*
- * The intended use case is caching frequently-read, seldom-changed information normally
- * retrieved across interprocess communication. Imagine that you've written a user birthday
- * information daemon called "birthdayd" that exposes an {@code IUserBirthdayService} interface
- * over binder. That binder interface looks something like this:
- *
- * <pre>
- * parcelable Birthday {
- * int month;
- * int day;
- * }
- * interface IUserBirthdayService {
- * Birthday getUserBirthday(int userId);
- * }
- * </pre>
- *
- * Suppose the service implementation itself looks like this...
- *
- * <pre>
- * public class UserBirthdayServiceImpl implements IUserBirthdayService {
- * private final HashMap&lt;Integer, Birthday%&gt; mUidToBirthday;
- * {@literal @}Override
- * public synchronized Birthday getUserBirthday(int userId) {
- * return mUidToBirthday.get(userId);
- * }
- * private synchronized void updateBirthdays(Map&lt;Integer, Birthday%&gt; uidToBirthday) {
- * mUidToBirthday.clear();
- * mUidToBirthday.putAll(uidToBirthday);
- * }
- * }
- * </pre>
- *
- * ... and we have a client in frameworks (loaded into every app process) that looks
- * like this:
- *
- * <pre>
- * public class ActivityThread {
- * ...
- * public Birthday getUserBirthday(int userId) {
- * return GetService("birthdayd").getUserBirthday(userId);
- * }
- * ...
- * }
- * </pre>
- *
- * With this code, every time an app calls {@code getUserBirthday(uid)}, we make a binder call
- * to the birthdayd process and consult its database of birthdays. If we query user birthdays
- * frequently, we do a lot of work that we don't have to do, since user birthdays
- * change infrequently.
- *
- * PropertyInvalidatedCache is part of a pattern for optimizing this kind of
- * information-querying code. Using {@code PropertyInvalidatedCache}, you'd write the client
- * this way:
- *
- * <pre>
- * public class ActivityThread {
- * ...
- * private final PropertyInvalidatedCache.QueryHandler&lt;Integer, Birthday&gt; mBirthdayQuery =
- * new PropertyInvalidatedCache.QueryHandler&lt;Integer, Birthday&gt;() {
- * {@literal @}Override
- * public Birthday apply(Integer) {
- * return GetService("birthdayd").getUserBirthday(userId);
- * }
- * };
- * private static final int BDAY_CACHE_MAX = 8; // Maximum birthdays to cache
- * private static final String BDAY_CACHE_KEY = "cache_key.birthdayd";
- * private final PropertyInvalidatedCache&lt;Integer, Birthday%&gt; mBirthdayCache = new
- * PropertyInvalidatedCache&lt;Integer, Birthday%&gt;(
- * BDAY_CACHE_MAX, MODULE_SYSTEM, "getUserBirthday", mBirthdayQuery);
- *
- * public void disableUserBirthdayCache() {
- * mBirthdayCache.disableForCurrentProcess();
- * }
- * public void invalidateUserBirthdayCache() {
- * mBirthdayCache.invalidateCache();
- * }
- * public Birthday getUserBirthday(int userId) {
- * return mBirthdayCache.query(userId);
- * }
- * ...
- * }
- * </pre>
- *
- * With this cache, clients perform a binder call to birthdayd if asking for a user's birthday
- * for the first time; on subsequent queries, we return the already-known Birthday object.
- *
- * The second parameter to the IpcDataCache constructor is a string that identifies the "module"
- * that owns the cache. There are some well-known modules (such as {@code MODULE_SYSTEM} but any
- * string is permitted. The third parameters is the name of the API being cached; this, too, can
- * any value. The fourth is the name of the cache. The cache is usually named after th API.
- * Some things you must know about the three strings:
- * <list>
- * <ul> The system property that controls the cache is named {@code cache_key.<module>.<api>}.
- * Usually, the SELinux rules permit a process to write a system property (and therefore
- * invalidate a cache) based on the wildcard {@code cache_key.<module>.*}. This means that
- * although the cache can be constructed with any module string, whatever string is chosen must be
- * consistent with the SELinux configuration.
- * <ul> The API name can be any string of alphanumeric characters. All caches with the same API
- * are invalidated at the same time. If a server supports several caches and all are invalidated
- * in common, then it is most efficient to assign the same API string to every cache.
- * <ul> The cache name can be any string. In debug output, the name is used to distiguish between
- * caches with the same API name. The cache name is also used when disabling caches in the
- * current process. So, invalidation is based on the module+api but disabling (which is generally
- * a once-per-process operation) is based on the cache name.
- * </list>
- *
- * User birthdays do occasionally change, so we have to modify the server to invalidate this
- * cache when necessary. That invalidation code looks like this:
- *
- * <pre>
- * public class UserBirthdayServiceImpl {
- * ...
- * public UserBirthdayServiceImpl() {
- * ...
- * ActivityThread.currentActivityThread().disableUserBirthdayCache();
- * ActivityThread.currentActivityThread().invalidateUserBirthdayCache();
- * }
- *
- * private synchronized void updateBirthdays(Map&lt;Integer, Birthday%&gt; uidToBirthday) {
- * mUidToBirthday.clear();
- * mUidToBirthday.putAll(uidToBirthday);
- * ActivityThread.currentActivityThread().invalidateUserBirthdayCache();
- * }
- * ...
- * }
- * </pre>
- *
- * The call to {@code PropertyInvalidatedCache.invalidateCache()} guarantees that all clients
- * will re-fetch birthdays from binder during consequent calls to
- * {@code ActivityThread.getUserBirthday()}. Because the invalidate call happens with the lock
- * held, we maintain consistency between different client views of the birthday state. The use
- * of PropertyInvalidatedCache in this idiomatic way introduces no new race conditions.
- *
- * PropertyInvalidatedCache has a few other features for doing things like incremental
- * enhancement of cached values and invalidation of multiple caches (that all share the same
- * property key) at once.
- *
- * {@code BDAY_CACHE_KEY} is the name of a property that we set to an opaque unique value each
- * time we update the cache. SELinux configuration must allow everyone to read this property
- * and it must allow any process that needs to invalidate the cache (here, birthdayd) to write
- * the property. (These properties conventionally begin with the "cache_key." prefix.)
- *
- * The {@code UserBirthdayServiceImpl} constructor calls {@code disableUserBirthdayCache()} so
- * that calls to {@code getUserBirthday} from inside birthdayd don't go through the cache. In
- * this local case, there's no IPC, so use of the cache is (depending on exact
- * circumstance) unnecessary.
- *
- * There may be queries for which it is more efficient to bypass the cache than to cache
- * the result. This would be true, for example, if some queries would require frequent
- * cache invalidation while other queries require infrequent invalidation. To expand on
- * the birthday example, suppose that there is a userId that signifies "the next
- * birthday". When passed this userId, the server returns the next birthday among all
- * users - this value changes as time advances. The userId value can be cached, but the
- * cache must be invalidated whenever a birthday occurs, and this invalidates all
- * birthdays. If there is a large number of users, invalidation will happen so often that
- * the cache provides no value.
- *
- * The class provides a bypass mechanism to handle this situation.
- * <pre>
- * public class ActivityThread {
- * ...
- * private final IpcDataCache.QueryHandler&lt;Integer, Birthday&gt; mBirthdayQuery =
- * new IpcDataCache.QueryHandler&lt;Integer, Birthday&gt;() {
- * {@literal @}Override
- * public Birthday apply(Integer) {
- * return GetService("birthdayd").getUserBirthday(userId);
- * }
- * {@literal @}Override
- * public boolean shouldBypassQuery(Integer userId) {
- * return userId == NEXT_BIRTHDAY;
- * }
- * };
- * ...
- * }
- * </pre>
- *
- * If the {@code shouldBypassQuery()} method returns true then the cache is not used for that
- * particular query. The {@code shouldBypassQuery()} method is not abstract and the default
- * implementation returns false.
- *
- * For security, there is a allowlist of processes that are allowed to invalidate a cache.
- * The allowlist includes normal runtime processes but does not include test processes.
- * Test processes must call {@code PropertyInvalidatedCache.disableForTestMode()} to disable
- * all cache activity in that process.
- *
- * Caching can be disabled completely by initializing {@code sEnabled} to false and rebuilding.
- *
- * To test a binder cache, create one or more tests that exercise the binder method. This
- * should be done twice: once with production code and once with a special image that sets
- * {@code DEBUG} and {@code VERIFY} true. In the latter case, verify that no cache
- * inconsistencies are reported. If a cache inconsistency is reported, however, it might be a
- * false positive. This happens if the server side data can be read and written non-atomically
- * with respect to cache invalidation.
+ * This interface is deprecated. New clients should use {@link IpcDataCache} instead. Internally,
+ * that class uses {@link PropertyInvalidatedCache} , but that design may change in the future.
*
* @param <Query> The class used to index cache entries: must be hashable and comparable
* @param <Result> The class holding cache entries; use a boxed primitive if possible
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index daa15f05d942..9be928f7efd0 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -213,19 +213,17 @@ import java.util.function.Consumer;
* <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
* developer guide.
*
- * <p id="devicepolicycontroller">Through <a href="#managed_provisioning">Managed Provisioning</a>,
- * Device Administrator apps can also be recognised as <b>
- Device Policy Controllers</b>. Device Policy Controllers can be one of
+ * <p id="devicepolicycontroller">Device Administrator apps can also be recognised as <b>
+ * Device Policy Controllers</b>. Device Policy Controllers can be one of
* two types:
* <ul>
* <li>A <i id="deviceowner">Device Owner</i>, which only ever exists on the
- * {@link UserManager#isSystemUser System User} or {@link UserManager#isMainUser Main User}, is
+ * {@link UserManager#isSystemUser System User} or Main User, is
* the most powerful type of Device Policy Controller and can affect policy across the device.
* <li>A <i id="profileowner">Profile Owner<i>, which can exist on any user, can
* affect policy on the user it is on, and when it is running on
* {@link UserManager#isProfile a profile} has
- * <a href="#profile-on-parent">limited</a> ability to affect policy on its
- * {@link UserManager#getProfileParent parent}.
+ * <a href="#profile-on-parent">limited</a> ability to affect policy on its parent.
* </ul>
*
* <p>Additional capabilities can be provided to Device Policy Controllers in
@@ -233,7 +231,7 @@ import java.util.function.Consumer;
* <ul>
* <li>A Profile Owner on an <a href="#organization-owned">organization owned</a> device has access
* to additional abilities, both <a href="#profile-on-parent-organization-owned">affecting policy on the profile's</a>
- * {@link UserManager#getProfileParent parent} and also the profile itself.
+ * parent and also the profile itself.
* <li>A Profile Owner running on the {@link UserManager#isSystemUser System User} has access to
* additional capabilities which affect the {@link UserManager#isSystemUser System User} and
* also the whole device.
@@ -245,13 +243,12 @@ import java.util.function.Consumer;
* Controller</a>.
*
* <p><a href="#permissions">Permissions</a> are generally only given to apps
- * fulfilling particular key roles on the device (such as managing {@link DeviceLockManager
-device locks}).
+ * fulfilling particular key roles on the device (such as managing
+ * {@link android.devicelock.DeviceLockManager device locks}).
*
* <p id="roleholder"><b>Device Policy Management Role Holder</b>
- * <p>One app on the device fulfills the {@link RoleManager#ROLE_DEVICE_POLICY_MANAGEMENT Device
-Policy Management Role} and is trusted with managing the overall state of
- * Device Policy. This has access to much more powerful methods than
+ * <p>One app on the device fulfills the Device Policy Management Role and is trusted with managing
+ * the overall state of Device Policy. This has access to much more powerful methods than
* <a href="#managingapps">managing apps</a>.
*
* <p id="querying"><b>Querying Device Policy</b>
@@ -273,7 +270,7 @@ Policy Management Role} and is trusted with managing the overall state of
*
* <p id="managed_profile">A <b>Managed Profile</b> enables data separation. For example to use
* a device both for personal and corporate usage. The managed profile and its
- * {@link UserManager#getProfileParent parent} share a launcher.
+ * parent share a launcher.
*
* <p id="affiliated"><b>Affiliation</b>
* <p>Using the {@link #setAffiliationIds} method, a
@@ -6643,7 +6640,7 @@ public class DevicePolicyManager {
* @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
* @throws SecurityException if the calling application does not own an active administrator
* that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} and the does not hold
- * the {@link android.Manifest.permission#LOCK_DEVICE} permission, or
+ * the LOCK_DEVICE permission, or
* the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an
* application that is not a profile owner of a managed profile.
* @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
diff --git a/core/java/android/app/appfunctions/AppFunctionManager.java b/core/java/android/app/appfunctions/AppFunctionManager.java
index 4682f3d30e1e..216ba5d994ec 100644
--- a/core/java/android/app/appfunctions/AppFunctionManager.java
+++ b/core/java/android/app/appfunctions/AppFunctionManager.java
@@ -27,6 +27,8 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.UserHandleAware;
import android.content.Context;
+import android.os.CancellationSignal;
+import android.os.ICancellationSignal;
import android.os.RemoteException;
import java.util.Objects;
@@ -73,7 +75,43 @@ public final class AppFunctionManager {
* android.permission.EXECUTE_APP_FUNCTIONS_TRUSTED} or {@code
* android.permission.EXECUTE_APP_FUNCTIONS}, the execution result will contain {@code
* ExecuteAppFunctionResponse.RESULT_DENIED}.
+ * @deprecated Use {@link #executeAppFunction(ExecuteAppFunctionRequest, Executor,
+ * CancellationSignal, Consumer)} instead. This method will be removed once usage references
+ * are updated.
*/
+ @RequiresPermission(
+ anyOf = {
+ Manifest.permission.EXECUTE_APP_FUNCTIONS_TRUSTED,
+ Manifest.permission.EXECUTE_APP_FUNCTIONS
+ },
+ conditional = true)
+ @UserHandleAware
+ @Deprecated
+ public void executeAppFunction(
+ @NonNull ExecuteAppFunctionRequest request,
+ @NonNull @CallbackExecutor Executor executor,
+ @NonNull Consumer<ExecuteAppFunctionResponse> callback) {
+ executeAppFunction(request, executor, new CancellationSignal(), callback);
+ }
+
+ /**
+ * Executes the app function.
+ *
+ * <p>Note: Applications can execute functions they define. To execute functions defined in
+ * another component, apps would need to have {@code
+ * android.permission.EXECUTE_APP_FUNCTIONS_TRUSTED} or {@code
+ * android.permission.EXECUTE_APP_FUNCTIONS}.
+ *
+ * @param request the request to execute the app function
+ * @param executor the executor to run the callback
+ * @param cancellationSignal the cancellation signal to cancel the execution.
+ * @param callback the callback to receive the function execution result. if the calling app
+ * does not own the app function or does not have {@code
+ * android.permission.EXECUTE_APP_FUNCTIONS_TRUSTED} or {@code
+ * android.permission.EXECUTE_APP_FUNCTIONS}, the execution result will contain {@code
+ * ExecuteAppFunctionResponse.RESULT_DENIED}.
+ */
+ // TODO(b/357551503): Document the behavior when the cancellation signal is issued.
// TODO(b/360864791): Document that apps can opt-out from being executed by callers with
// EXECUTE_APP_FUNCTIONS and how a caller knows whether a function is opted out.
// TODO(b/357551503): Update documentation when get / set APIs are implemented that this will
@@ -88,6 +126,7 @@ public final class AppFunctionManager {
public void executeAppFunction(
@NonNull ExecuteAppFunctionRequest request,
@NonNull @CallbackExecutor Executor executor,
+ @NonNull CancellationSignal cancellationSignal,
@NonNull Consumer<ExecuteAppFunctionResponse> callback) {
Objects.requireNonNull(request);
Objects.requireNonNull(executor);
@@ -96,25 +135,31 @@ public final class AppFunctionManager {
ExecuteAppFunctionAidlRequest aidlRequest =
new ExecuteAppFunctionAidlRequest(
request, mContext.getUser(), mContext.getPackageName());
+
try {
- mService.executeAppFunction(
- aidlRequest,
- new IExecuteAppFunctionCallback.Stub() {
- @Override
- public void onResult(ExecuteAppFunctionResponse result) {
- try {
- executor.execute(() -> callback.accept(result));
- } catch (RuntimeException e) {
- // Ideally shouldn't happen since errors are wrapped into the
- // response, but we catch it here for additional safety.
- callback.accept(
- ExecuteAppFunctionResponse.newFailure(
- getResultCode(e),
- e.getMessage(),
- /* extras= */ null));
- }
- }
- });
+ ICancellationSignal cancellationTransport =
+ mService.executeAppFunction(
+ aidlRequest,
+ new IExecuteAppFunctionCallback.Stub() {
+ @Override
+ public void onResult(ExecuteAppFunctionResponse result) {
+ try {
+ executor.execute(() -> callback.accept(result));
+ } catch (RuntimeException e) {
+ // Ideally shouldn't happen since errors are wrapped into
+ // the
+ // response, but we catch it here for additional safety.
+ callback.accept(
+ ExecuteAppFunctionResponse.newFailure(
+ getResultCode(e),
+ e.getMessage(),
+ /* extras= */ null));
+ }
+ }
+ });
+ if (cancellationTransport != null) {
+ cancellationSignal.setRemote(cancellationTransport);
+ }
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/app/appfunctions/AppFunctionService.java b/core/java/android/app/appfunctions/AppFunctionService.java
index 0d981ea5a679..8e417737515e 100644
--- a/core/java/android/app/appfunctions/AppFunctionService.java
+++ b/core/java/android/app/appfunctions/AppFunctionService.java
@@ -29,7 +29,12 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
+import android.os.Bundle;
import android.os.IBinder;
+import android.os.ICancellationSignal;
+import android.os.CancellationSignal;
+import android.os.RemoteCallback;
+import android.os.RemoteException;
import java.util.function.Consumer;
@@ -74,6 +79,7 @@ public abstract class AppFunctionService extends Service {
*/
void perform(
@NonNull ExecuteAppFunctionRequest request,
+ @NonNull CancellationSignal cancellationSignal,
@NonNull Consumer<ExecuteAppFunctionResponse> callback);
}
@@ -85,6 +91,7 @@ public abstract class AppFunctionService extends Service {
@Override
public void executeAppFunction(
@NonNull ExecuteAppFunctionRequest request,
+ @NonNull ICancellationCallback cancellationCallback,
@NonNull IExecuteAppFunctionCallback callback) {
if (context.checkCallingPermission(BIND_APP_FUNCTION_SERVICE)
== PERMISSION_DENIED) {
@@ -93,7 +100,10 @@ public abstract class AppFunctionService extends Service {
SafeOneTimeExecuteAppFunctionCallback safeCallback =
new SafeOneTimeExecuteAppFunctionCallback(callback);
try {
- onExecuteFunction.perform(request, safeCallback::onResult);
+ onExecuteFunction.perform(
+ request,
+ buildCancellationSignal(cancellationCallback),
+ safeCallback::onResult);
} catch (Exception ex) {
// Apps should handle exceptions. But if they don't, report the error on
// behalf of them.
@@ -105,6 +115,21 @@ public abstract class AppFunctionService extends Service {
};
}
+ private static CancellationSignal buildCancellationSignal(
+ @NonNull ICancellationCallback cancellationCallback) {
+ final ICancellationSignal cancellationSignalTransport =
+ CancellationSignal.createTransport();
+ CancellationSignal cancellationSignal =
+ CancellationSignal.fromTransport(cancellationSignalTransport);
+ try {
+ cancellationCallback.sendCancellationTransport(cancellationSignalTransport);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+
+ return cancellationSignal ;
+ }
+
private final Binder mBinder = createBinder(
AppFunctionService.this,
AppFunctionService.this::onExecuteFunction);
@@ -115,6 +140,7 @@ public abstract class AppFunctionService extends Service {
return mBinder;
}
+
/**
* Called by the system to execute a specific app function.
*
@@ -134,9 +160,45 @@ public abstract class AppFunctionService extends Service {
*
* @param request The function execution request.
* @param callback A callback to report back the result.
+ *
+ * @deprecated Use {@link #onExecuteFunction(ExecuteAppFunctionRequest, CancellationSignal,
+ * Consumer)} instead. This method will be removed once usage references are updated.
*/
@MainThread
+ @Deprecated
public abstract void onExecuteFunction(
@NonNull ExecuteAppFunctionRequest request,
@NonNull Consumer<ExecuteAppFunctionResponse> callback);
+
+ /**
+ * Called by the system to execute a specific app function.
+ *
+ * <p>This method is triggered when the system requests your AppFunctionService to handle a
+ * particular function you have registered and made available.
+ *
+ * <p>To ensure proper routing of function requests, assign a unique identifier to each
+ * function. This identifier doesn't need to be globally unique, but it must be unique within
+ * your app. For example, a function to order food could be identified as "orderFood". In most
+ * cases this identifier should come from the ID automatically generated by the AppFunctions
+ * SDK. You can determine the specific function to invoke by calling {@link
+ * ExecuteAppFunctionRequest#getFunctionIdentifier()}.
+ *
+ * <p>This method is always triggered in the main thread. You should run heavy tasks on a worker
+ * thread and dispatch the result with the given callback. You should always report back the
+ * result using the callback, no matter if the execution was successful or not.
+ *
+ * <p>This method also accepts a {@link CancellationSignal} that the app should listen to cancel
+ * the execution of function if requested by the system.
+ *
+ * @param request The function execution request.
+ * @param cancellationSignal A signal to cancel the execution.
+ * @param callback A callback to report back the result.
+ */
+ @MainThread
+ public void onExecuteFunction(
+ @NonNull ExecuteAppFunctionRequest request,
+ @NonNull CancellationSignal cancellationSignal,
+ @NonNull Consumer<ExecuteAppFunctionResponse> callback) {
+ onExecuteFunction(request, callback);
+ }
}
diff --git a/core/java/android/app/appfunctions/GenericDocumentWrapper.java b/core/java/android/app/appfunctions/GenericDocumentWrapper.java
index 84b1837f4a2f..b29b64e44d21 100644
--- a/core/java/android/app/appfunctions/GenericDocumentWrapper.java
+++ b/core/java/android/app/appfunctions/GenericDocumentWrapper.java
@@ -16,10 +16,13 @@
package android.app.appfunctions;
+import android.annotation.Nullable;
import android.app.appsearch.GenericDocument;
import android.os.Parcel;
import android.os.Parcelable;
+import android.util.MathUtils;
+import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import java.util.Objects;
@@ -31,24 +34,33 @@ import java.util.Objects;
* <p>{#link {@link Parcel#writeBlob(byte[])}} could take care of whether to pass data via binder
* directly or Android shared memory if the data is large.
*
+ * <p>This class performs lazy unparcelling. The `GenericDocument` is only unparcelled
+ * from the underlying `Parcel` when {@link #getValue()} is called. This optimization
+ * allows the system server to pass through the generic document, without unparcel and parcel it.
+ *
* @hide
* @see Parcel#writeBlob(byte[])
*/
public final class GenericDocumentWrapper implements Parcelable {
+ @Nullable
+ @GuardedBy("mLock")
+ private GenericDocument mGenericDocument;
+ @GuardedBy("mLock")
+ @Nullable private Parcel mParcel;
+ private final Object mLock = new Object();
+
public static final Creator<GenericDocumentWrapper> CREATOR =
new Creator<>() {
@Override
public GenericDocumentWrapper createFromParcel(Parcel in) {
- byte[] dataBlob = Objects.requireNonNull(in.readBlob());
- Parcel unmarshallParcel = Parcel.obtain();
- try {
- unmarshallParcel.unmarshall(dataBlob, 0, dataBlob.length);
- unmarshallParcel.setDataPosition(0);
- return new GenericDocumentWrapper(
- GenericDocument.createFromParcel(unmarshallParcel));
- } finally {
- unmarshallParcel.recycle();
- }
+ int length = in.readInt();
+ int offset = in.dataPosition();
+ in.setDataPosition(MathUtils.addOrThrow(offset, length));
+
+ Parcel p = Parcel.obtain();
+ p.appendFrom(in, offset, length);
+ p.setDataPosition(0);
+ return new GenericDocumentWrapper(p);
}
@Override
@@ -56,16 +68,42 @@ public final class GenericDocumentWrapper implements Parcelable {
return new GenericDocumentWrapper[size];
}
};
- @NonNull private final GenericDocument mGenericDocument;
public GenericDocumentWrapper(@NonNull GenericDocument genericDocument) {
mGenericDocument = Objects.requireNonNull(genericDocument);
+ mParcel = null;
+ }
+
+ public GenericDocumentWrapper(@NonNull Parcel parcel) {
+ mGenericDocument = null;
+ mParcel = Objects.requireNonNull(parcel);
}
/** Returns the wrapped {@link android.app.appsearch.GenericDocument} */
@NonNull
public GenericDocument getValue() {
- return mGenericDocument;
+ unparcel();
+ synchronized (mLock) {
+ return Objects.requireNonNull(mGenericDocument);
+ }
+ }
+
+ private void unparcel() {
+ synchronized (mLock) {
+ if (mGenericDocument != null) {
+ return;
+ }
+ byte[] dataBlob = Objects.requireNonNull(Objects.requireNonNull(mParcel).readBlob());
+ Parcel unmarshallParcel = Parcel.obtain();
+ try {
+ unmarshallParcel.unmarshall(dataBlob, 0, dataBlob.length);
+ unmarshallParcel.setDataPosition(0);
+ mGenericDocument = GenericDocument.createFromParcel(unmarshallParcel);
+ mParcel = null;
+ } finally {
+ unmarshallParcel.recycle();
+ }
+ }
}
@Override
@@ -75,13 +113,32 @@ public final class GenericDocumentWrapper implements Parcelable {
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
- Parcel parcel = Parcel.obtain();
- try {
- mGenericDocument.writeToParcel(parcel, flags);
- byte[] bytes = parcel.marshall();
- dest.writeBlob(bytes);
- } finally {
- parcel.recycle();
+ synchronized (mLock) {
+ if (mGenericDocument != null) {
+ int lengthPos = dest.dataPosition();
+ // write a placeholder for length
+ dest.writeInt(-1);
+ Parcel tempParcel = Parcel.obtain();
+ byte[] bytes;
+ try {
+ mGenericDocument.writeToParcel(tempParcel, flags);
+ bytes = tempParcel.marshall();
+ } finally {
+ tempParcel.recycle();
+ }
+ int startPos = dest.dataPosition();
+ dest.writeBlob(bytes);
+ int endPos = dest.dataPosition();
+ dest.setDataPosition(lengthPos);
+ // Overwrite the length placeholder
+ dest.writeInt(endPos - startPos);
+ dest.setDataPosition(endPos);
+
+ } else {
+ Parcel originalParcel = Objects.requireNonNull(mParcel);
+ dest.writeInt(originalParcel.dataSize());
+ dest.appendFrom(originalParcel, 0, originalParcel.dataSize());
+ }
}
}
}
diff --git a/core/java/android/app/appfunctions/IAppFunctionManager.aidl b/core/java/android/app/appfunctions/IAppFunctionManager.aidl
index 28827bb3052c..c63217ffe850 100644
--- a/core/java/android/app/appfunctions/IAppFunctionManager.aidl
+++ b/core/java/android/app/appfunctions/IAppFunctionManager.aidl
@@ -18,6 +18,7 @@ package android.app.appfunctions;
import android.app.appfunctions.ExecuteAppFunctionAidlRequest;
import android.app.appfunctions.IExecuteAppFunctionCallback;
+import android.os.ICancellationSignal;
/**
* Defines the interface for apps to interact with the app function execution service
@@ -32,8 +33,8 @@ interface IAppFunctionManager {
* @param callback the callback to report the result.
*/
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(anyOf = {android.Manifest.permission.EXECUTE_APP_FUNCTIONS_TRUSTED,android.Manifest.permission.EXECUTE_APP_FUNCTIONS}, conditional = true)")
- void executeAppFunction(
+ ICancellationSignal executeAppFunction(
in ExecuteAppFunctionAidlRequest request,
in IExecuteAppFunctionCallback callback
);
-} \ No newline at end of file
+}
diff --git a/core/java/android/app/appfunctions/IAppFunctionService.aidl b/core/java/android/app/appfunctions/IAppFunctionService.aidl
index cc5a20cfa194..291f33ccb1b8 100644
--- a/core/java/android/app/appfunctions/IAppFunctionService.aidl
+++ b/core/java/android/app/appfunctions/IAppFunctionService.aidl
@@ -16,7 +16,7 @@
package android.app.appfunctions;
-import android.os.Bundle;
+import android.app.appfunctions.ICancellationCallback;
import android.app.appfunctions.IExecuteAppFunctionCallback;
import android.app.appfunctions.ExecuteAppFunctionRequest;
@@ -34,10 +34,12 @@ oneway interface IAppFunctionService {
* Called by the system to execute a specific app function.
*
* @param request the function execution request.
+ * @param cancellationCallback a callback to send back the cancellation transport.
* @param callback a callback to report back the result.
*/
void executeAppFunction(
in ExecuteAppFunctionRequest request,
+ in ICancellationCallback cancellationCallback,
in IExecuteAppFunctionCallback callback
);
}
diff --git a/core/java/android/app/appfunctions/ICancellationCallback.aidl b/core/java/android/app/appfunctions/ICancellationCallback.aidl
new file mode 100644
index 000000000000..03235aca017a
--- /dev/null
+++ b/core/java/android/app/appfunctions/ICancellationCallback.aidl
@@ -0,0 +1,24 @@
+/*
+ * 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 android.app.appfunctions;
+
+import android.os.ICancellationSignal;
+
+/** {@hide} */
+oneway interface ICancellationCallback {
+ void sendCancellationTransport(in ICancellationSignal cancellationTransport);
+} \ No newline at end of file
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index abb562d8ddaf..d8142fd9687c 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -1042,10 +1042,11 @@ public class AppWidgetManager {
}
/**
- * Get the available info about the AppWidget.
+ * Returns the {@link AppWidgetProviderInfo} for the specified AppWidget.
*
- * @return A appWidgetId. If the appWidgetId has not been bound to a provider yet, or
- * you don't have access to that appWidgetId, null is returned.
+ * @return Information regarding the provider of speficied widget, returns null if the
+ * appWidgetId has not been bound to a provider yet, or you don't have access
+ * to that widget.
*/
public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
if (mService == null) {
@@ -1390,7 +1391,7 @@ public class AppWidgetManager {
*
* @param provider The {@link ComponentName} for the {@link
* android.content.BroadcastReceiver BroadcastReceiver} provider for your AppWidget.
- * @param extras In not null, this is passed to the launcher app. For eg {@link
+ * @param extras IF not null, this is passed to the launcher app. e.g. {@link
* #EXTRA_APPWIDGET_PREVIEW} can be used for a custom preview.
* @param successCallback If not null, this intent will be sent when the widget is created.
*
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 031380dc1962..044178c4f6aa 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -20,6 +20,7 @@ import static android.app.sdksandbox.SdkSandboxManager.ACTION_START_SANDBOXED_AC
import static android.content.ContentProvider.maybeAddUserId;
import static android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE;
import static android.security.Flags.FLAG_FRP_ENFORCEMENT;
+import static android.security.Flags.preventIntentRedirect;
import android.Manifest;
import android.accessibilityservice.AccessibilityService;
@@ -7687,9 +7688,17 @@ public class Intent implements Parcelable, Cloneable {
/** @hide */
public static final int LOCAL_FLAG_FROM_SYSTEM = 1 << 5;
+ /**
+ * This flag indicates the creator token of this intent has been verified.
+ *
+ * @hide
+ */
+ public static final int LOCAL_FLAG_CREATOR_TOKEN_VERIFIED = 1 << 6;
+
/** @hide */
@IntDef(flag = true, prefix = { "EXTENDED_FLAG_" }, value = {
EXTENDED_FLAG_FILTER_MISMATCH,
+ EXTENDED_FLAG_MISSING_CREATOR_OR_INVALID_TOKEN,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ExtendedFlags {}
@@ -7703,6 +7712,13 @@ public class Intent implements Parcelable, Cloneable {
@TestApi
public static final int EXTENDED_FLAG_FILTER_MISMATCH = 1 << 0;
+ /**
+ * This flag indicates the creator token of this intent is either missing or invalid.
+ *
+ * @hide
+ */
+ public static final int EXTENDED_FLAG_MISSING_CREATOR_OR_INVALID_TOKEN = 1 << 1;
+
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// toUri() and parseUri() options.
@@ -7870,6 +7886,7 @@ public class Intent implements Parcelable, Cloneable {
this.mPackage = o.mPackage;
this.mComponent = o.mComponent;
this.mOriginalIntent = o.mOriginalIntent;
+ this.mCreatorTokenInfo = o.mCreatorTokenInfo;
if (o.mCategories != null) {
this.mCategories = new ArraySet<>(o.mCategories);
@@ -12176,6 +12193,60 @@ public class Intent implements Parcelable, Cloneable {
return (mExtras != null) ? mExtras.describeContents() : 0;
}
+ private static class CreatorTokenInfo {
+ // Stores a creator token for an intent embedded as an extra intent in a top level intent,
+ private IBinder mCreatorToken;
+ // Stores all extra keys whose values are intents for a top level intent.
+ private ArraySet<String> mExtraIntentKeys;
+ }
+
+ private @Nullable CreatorTokenInfo mCreatorTokenInfo;
+
+ /** @hide */
+ public void removeCreatorTokenInfo() {
+ mCreatorTokenInfo = null;
+ }
+
+ /** @hide */
+ public @Nullable IBinder getCreatorToken() {
+ return mCreatorTokenInfo == null ? null : mCreatorTokenInfo.mCreatorToken;
+ }
+
+ /** @hide */
+ public Set<String> getExtraIntentKeys() {
+ return mCreatorTokenInfo == null ? null : mCreatorTokenInfo.mExtraIntentKeys;
+ }
+
+ /** @hide */
+ public void setCreatorToken(@NonNull IBinder creatorToken) {
+ if (mCreatorTokenInfo == null) {
+ mCreatorTokenInfo = new CreatorTokenInfo();
+ }
+ mCreatorTokenInfo.mCreatorToken = creatorToken;
+ }
+
+ /**
+ * Collects keys in the extra bundle whose value are intents.
+ * @hide
+ */
+ public void collectExtraIntentKeys() {
+ if (!preventIntentRedirect()) return;
+
+ if (mExtras != null && !mExtras.isParcelled() && !mExtras.isEmpty()) {
+ for (String key : mExtras.keySet()) {
+ if (mExtras.get(key) instanceof Intent) {
+ if (mCreatorTokenInfo == null) {
+ mCreatorTokenInfo = new CreatorTokenInfo();
+ }
+ if (mCreatorTokenInfo.mExtraIntentKeys == null) {
+ mCreatorTokenInfo.mExtraIntentKeys = new ArraySet<>();
+ }
+ mCreatorTokenInfo.mExtraIntentKeys.add(key);
+ }
+ }
+ }
+ }
+
public void writeToParcel(Parcel out, int flags) {
out.writeString8(mAction);
Uri.writeToParcel(out, mData);
@@ -12225,6 +12296,16 @@ public class Intent implements Parcelable, Cloneable {
} else {
out.writeInt(0);
}
+
+ if (preventIntentRedirect()) {
+ if (mCreatorTokenInfo == null) {
+ out.writeInt(0);
+ } else {
+ out.writeInt(1);
+ out.writeStrongBinder(mCreatorTokenInfo.mCreatorToken);
+ out.writeArraySet(mCreatorTokenInfo.mExtraIntentKeys);
+ }
+ }
}
public static final @android.annotation.NonNull Parcelable.Creator<Intent> CREATOR
@@ -12282,6 +12363,14 @@ public class Intent implements Parcelable, Cloneable {
if (in.readInt() != 0) {
mOriginalIntent = new Intent(in);
}
+
+ if (preventIntentRedirect()) {
+ if (in.readInt() != 0) {
+ mCreatorTokenInfo = new CreatorTokenInfo();
+ mCreatorTokenInfo.mCreatorToken = in.readStrongBinder();
+ mCreatorTokenInfo.mExtraIntentKeys = (ArraySet<String>) in.readArraySet(null);
+ }
+ }
}
/**
diff --git a/core/java/android/content/pm/flags.aconfig b/core/java/android/content/pm/flags.aconfig
index 60b409ac6346..160cbdffe5bb 100644
--- a/core/java/android/content/pm/flags.aconfig
+++ b/core/java/android/content/pm/flags.aconfig
@@ -301,4 +301,11 @@ flag {
description: "Feature flag to remove hack code of using PackageManager.MATCH_ANY_USER flag without cross user permission."
bug: "332664521"
is_fixed_read_only: true
-} \ No newline at end of file
+}
+
+flag {
+ name: "delete_packages_silently_backport"
+ namespace: "package_manager_service"
+ description: "Feature flag to enable the holder of SYSTEM_APP_PROTECTION_SERVICE role to silently delete packages. To be deprecated by delete_packages_silently."
+ bug: "361776825"
+}
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index 21627920f598..1b21bdf7ba45 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -181,7 +181,7 @@ public final class CameraManager {
* @hide
*/
@TestApi
- @FlaggedApi(com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public static final int ROTATION_OVERRIDE_NONE = ICameraService.ROTATION_OVERRIDE_NONE;
/**
@@ -191,7 +191,7 @@ public final class CameraManager {
* @hide
*/
@TestApi
- @FlaggedApi(com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public static final int ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT =
ICameraService.ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT;
@@ -201,7 +201,7 @@ public final class CameraManager {
* @hide
*/
@TestApi
- @FlaggedApi(com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public static final int ROTATION_OVERRIDE_ROTATION_ONLY =
ICameraService.ROTATION_OVERRIDE_ROTATION_ONLY;
@@ -1562,7 +1562,7 @@ public final class CameraManager {
*/
public static int getRotationOverride(@Nullable Context context,
@Nullable PackageManager packageManager, @Nullable String packageName) {
- if (com.android.window.flags.Flags.cameraCompatForFreeform()) {
+ if (com.android.window.flags.Flags.enableCameraCompatForDesktopWindowing()) {
return getRotationOverrideInternal(context, packageManager, packageName);
} else {
return shouldOverrideToPortrait(packageManager, packageName)
@@ -1574,7 +1574,7 @@ public final class CameraManager {
/**
* @hide
*/
- @FlaggedApi(com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@TestApi
public static int getRotationOverrideInternal(@Nullable Context context,
@Nullable PackageManager packageManager, @Nullable String packageName) {
diff --git a/core/java/android/hardware/display/DisplayManagerInternal.java b/core/java/android/hardware/display/DisplayManagerInternal.java
index a2d24f643bfb..73b5d947c0fe 100644
--- a/core/java/android/hardware/display/DisplayManagerInternal.java
+++ b/core/java/android/hardware/display/DisplayManagerInternal.java
@@ -432,6 +432,11 @@ public abstract class DisplayManagerInternal {
public abstract IntArray getDisplayGroupIds();
/**
+ * Get all available display ids.
+ */
+ public abstract IntArray getDisplayIds();
+
+ /**
* Called upon presentation started/ended on the display.
* @param displayId the id of the display where presentation started.
* @param isShown whether presentation is shown.
diff --git a/core/java/android/hardware/soundtrigger/SoundTrigger.java b/core/java/android/hardware/soundtrigger/SoundTrigger.java
index 79cbd19b248d..05e91e447a43 100644
--- a/core/java/android/hardware/soundtrigger/SoundTrigger.java
+++ b/core/java/android/hardware/soundtrigger/SoundTrigger.java
@@ -1529,6 +1529,8 @@ public class SoundTrigger {
* config that can be used by
* {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)}
*
+ * @deprecated should use builder-based constructor instead.
+ * TODO(b/368042125): remove this method.
* @param captureRequested Whether the DSP should capture the trigger sound.
* @param allowMultipleTriggers Whether the service should restart listening after the DSP
* triggers.
@@ -1539,6 +1541,8 @@ public class SoundTrigger {
*
* @hide
*/
+ @Deprecated
+ @SuppressWarnings("Todo")
@TestApi
public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers,
@SuppressLint("ArrayReturn") @Nullable KeyphraseRecognitionExtra[] keyphrases,
@@ -1695,6 +1699,89 @@ public class SoundTrigger {
result = prime * result + mAudioCapabilities;
return result;
}
+
+ /**
+ * Builder class for {@link RecognitionConfig} objects.
+ */
+ public static final class Builder {
+ private boolean mCaptureRequested;
+ private boolean mAllowMultipleTriggers;
+ @Nullable private KeyphraseRecognitionExtra[] mKeyphrases;
+ @Nullable private byte[] mData;
+ private int mAudioCapabilities;
+
+ /**
+ * Constructs a new Builder with the default values.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Sets capture requested state.
+ * @param captureRequested The new requested state.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setCaptureRequested(boolean captureRequested) {
+ mCaptureRequested = captureRequested;
+ return this;
+ }
+
+ /**
+ * Sets allow multiple triggers state.
+ * @param allowMultipleTriggers The new allow multiple triggers state.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setAllowMultipleTriggers(boolean allowMultipleTriggers) {
+ mAllowMultipleTriggers = allowMultipleTriggers;
+ return this;
+ }
+
+ /**
+ * Sets the keyphrases field.
+ * @param keyphrases The new keyphrases.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setKeyphrases(
+ @NonNull Collection<KeyphraseRecognitionExtra> keyphrases) {
+ mKeyphrases = keyphrases.toArray(new KeyphraseRecognitionExtra[keyphrases.size()]);
+ return this;
+ }
+
+ /**
+ * Sets the data field.
+ * @param data The new data.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setData(@Nullable byte[] data) {
+ mData = data;
+ return this;
+ }
+
+ /**
+ * Sets the audio capabilities field.
+ * @param audioCapabilities The new audio capabilities.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setAudioCapabilities(int audioCapabilities) {
+ mAudioCapabilities = audioCapabilities;
+ return this;
+ }
+
+ /**
+ * Combines all of the parameters that have been set and return a new
+ * {@link RecognitionConfig} object.
+ * @return a new {@link RecognitionConfig} object
+ */
+ public @NonNull RecognitionConfig build() {
+ RecognitionConfig config = new RecognitionConfig(
+ /* captureRequested= */ mCaptureRequested,
+ /* allowMultipleTriggers= */ mAllowMultipleTriggers,
+ /* keyphrases= */ mKeyphrases,
+ /* data= */ mData,
+ /* audioCapabilities= */ mAudioCapabilities);
+ return config;
+ }
+ };
}
/**
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index 97e9f34064ba..ed75491b8e21 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -1111,6 +1111,21 @@ public class Binder implements IBinder {
}
/**
+ * Called whenever the stub implementation throws an exception which isn't propagated to the
+ * remote caller by the binder. If this method isn't overridden, this exception is swallowed,
+ * and some default return values are propagated to the caller.
+ *
+ * <br> <b> This should not throw. </b> Doing so would defeat the purpose of this handler, and
+ * suppress the exception it is handling.
+ *
+ * @param code The transaction code being handled
+ * @param e The exception which was thrown.
+ * @hide
+ */
+ protected void onUnhandledException(int code, int flags, Exception e) {
+ }
+
+ /**
* @param in The raw file descriptor that an input data stream can be read from.
* @param out The raw file descriptor that normal command messages should be written to.
* @param err The raw file descriptor that command error messages should be written to.
@@ -1408,10 +1423,15 @@ public class Binder implements IBinder {
} else {
Log.w(TAG, "Caught a RuntimeException from the binder stub implementation.", e);
}
+ onUnhandledException(code, flags, e);
} else {
// Clear the parcel before writing the exception.
reply.setDataSize(0);
reply.setDataPosition(0);
+ // The writeException below won't do anything useful if this is the case.
+ if (Parcel.getExceptionCode(e) == 0) {
+ onUnhandledException(code, flags, e);
+ }
reply.writeException(e);
}
res = true;
diff --git a/core/java/android/os/IpcDataCache.java b/core/java/android/os/IpcDataCache.java
index 0776cf405cfe..e2a72dd5e385 100644
--- a/core/java/android/os/IpcDataCache.java
+++ b/core/java/android/os/IpcDataCache.java
@@ -48,6 +48,20 @@ import java.util.concurrent.atomic.AtomicLong;
* LRU cache that's invalidated when an opaque value in a property changes. Self-synchronizing,
* but doesn't hold a lock across data fetches on query misses.
*
+ * Clients should be aware of the following commonly-seen issues:
+ * <ul>
+ *
+ * <li>Client calls will not go through the cache before the first invalidation signal is
+ * received. Therefore, servers should signal an invalidation as soon as they have data to offer to
+ * clients.
+ *
+ * <li>Cache invalidation is restricted to well-known processes, which means that test code cannot
+ * invalidate a cache. {@link #disableForTestMode()} and {@link #testPropertyName} must be used in
+ * test processes that attempt cache invalidation. See
+ * {@link PropertyInvalidatedCacheTest#testBasicCache()} for an example.
+ *
+ * </ul>
+ *
* The intended use case is caching frequently-read, seldom-changed information normally retrieved
* across interprocess communication. Imagine that you've written a user birthday information
* daemon called "birthdayd" that exposes an {@code IUserBirthdayService} interface over
@@ -136,20 +150,20 @@ import java.util.concurrent.atomic.AtomicLong;
* string is permitted. The third parameters is the name of the API being cached; this, too, can
* any value. The fourth is the name of the cache. The cache is usually named after th API.
* Some things you must know about the three strings:
- * <list>
- * <ul> The system property that controls the cache is named {@code cache_key.<module>.<api>}.
+ * <ul>
+ * <li> The system property that controls the cache is named {@code cache_key.<module>.<api>}.
* Usually, the SELinux rules permit a process to write a system property (and therefore
* invalidate a cache) based on the wildcard {@code cache_key.<module>.*}. This means that
* although the cache can be constructed with any module string, whatever string is chosen must be
* consistent with the SELinux configuration.
- * <ul> The API name can be any string of alphanumeric characters. All caches with the same API
+ * <li> The API name can be any string of alphanumeric characters. All caches with the same API
* are invalidated at the same time. If a server supports several caches and all are invalidated
* in common, then it is most efficient to assign the same API string to every cache.
- * <ul> The cache name can be any string. In debug output, the name is used to distiguish between
+ * <li> The cache name can be any string. In debug output, the name is used to distiguish between
* caches with the same API name. The cache name is also used when disabling caches in the
* current process. So, invalidation is based on the module+api but disabling (which is generally
* a once-per-process operation) is based on the cache name.
- * </list>
+ * </ul>
*
* User birthdays do occasionally change, so we have to modify the server to invalidate this
* cache when necessary. That invalidation code looks like this:
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index b8a8be159d12..d82af55e2771 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -10750,6 +10750,16 @@ public final class Settings {
"lock_screen_show_only_unseen_notifications";
/**
+ * Indicates whether to minimalize the number of notifications to show on the lockscreen.
+ * <p>
+ * Type: int (0 for false, 1 for true)
+ *
+ * @hide
+ */
+ public static final String LOCK_SCREEN_NOTIFICATION_MINIMALISM =
+ "lock_screen_notification_minimalism";
+
+ /**
* Indicates whether snooze options should be shown on notifications
* <p>
* Type: int (0 for false, 1 for true)
diff --git a/core/java/android/security/responsible_apis_flags.aconfig b/core/java/android/security/responsible_apis_flags.aconfig
index 56d3669ac50c..5457bbee8ad3 100644
--- a/core/java/android/security/responsible_apis_flags.aconfig
+++ b/core/java/android/security/responsible_apis_flags.aconfig
@@ -24,6 +24,17 @@ flag {
}
flag {
+ name: "asm_reintroduce_grace_period"
+ namespace: "responsible_apis"
+ description: "Allow launches within the grace period for ASM apps"
+ bug: "367702727"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+
+flag {
name: "content_uri_permission_apis"
is_exported: true
namespace: "responsible_apis"
@@ -52,3 +63,11 @@ flag {
description: "Opt the system into enforcement of BAL"
bug: "339403750"
}
+
+flag {
+ name: "prevent_intent_redirect"
+ namespace: "responsible_apis"
+ description: "Prevent intent redirect attacks"
+ bug: "361143368"
+ is_fixed_read_only: true
+} \ No newline at end of file
diff --git a/core/java/android/view/WindowLayout.java b/core/java/android/view/WindowLayout.java
index dda399357d8c..d5ccca992b4f 100644
--- a/core/java/android/view/WindowLayout.java
+++ b/core/java/android/view/WindowLayout.java
@@ -157,10 +157,10 @@ public class WindowLayout {
// which prevents overlap with the DisplayCutout.
if (!attachedInParent && !floatingInScreenWindow) {
mTempRect.set(outParentFrame);
- outParentFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
+ intersectOrClamp(outParentFrame, displayCutoutSafeExceptMaybeBars);
frames.isParentFrameClippedByDisplayCutout = !mTempRect.equals(outParentFrame);
}
- outDisplayFrame.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
+ intersectOrClamp(outDisplayFrame, displayCutoutSafeExceptMaybeBars);
}
final boolean noLimits = (attrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
@@ -283,6 +283,19 @@ public class WindowLayout {
+ " requestedInvisibleTypes=" + WindowInsets.Type.toString(~requestedVisibleTypes));
}
+ /**
+ * If both rectangles intersect, set inOutRect to that intersection. Otherwise, clamp inOutRect
+ * to the side (or the corner) that the other rectangle is away from.
+ * Unlike {@link Rect#intersectUnchecked(Rect)}, this method guarantees that the new rectangle
+ * is valid and contained in inOutRect if rectangles involved are valid.
+ */
+ private static void intersectOrClamp(Rect inOutRect, Rect other) {
+ inOutRect.left = Math.min(Math.max(inOutRect.left, other.left), inOutRect.right);
+ inOutRect.top = Math.min(Math.max(inOutRect.top, other.top), inOutRect.bottom);
+ inOutRect.right = Math.max(Math.min(inOutRect.right, other.right), inOutRect.left);
+ inOutRect.bottom = Math.max(Math.min(inOutRect.bottom, other.bottom), inOutRect.top);
+ }
+
public static void extendFrameByCutout(Rect displayCutoutSafe,
Rect displayFrame, Rect inOutFrame, Rect tempRect) {
if (displayCutoutSafe.contains(inOutFrame)) {
diff --git a/core/java/android/view/accessibility/AccessibilityWindowInfo.java b/core/java/android/view/accessibility/AccessibilityWindowInfo.java
index c92593f81558..7b6e070f0008 100644
--- a/core/java/android/view/accessibility/AccessibilityWindowInfo.java
+++ b/core/java/android/view/accessibility/AccessibilityWindowInfo.java
@@ -880,10 +880,6 @@ public final class AccessibilityWindowInfo implements Parcelable {
* @hide
*/
public static String typeToString(int type) {
- if (Flags.enableTypeWindowControl() && type == TYPE_WINDOW_CONTROL) {
- return "TYPE_WINDOW_CONTROL";
- }
-
switch (type) {
case TYPE_APPLICATION: {
return "TYPE_APPLICATION";
@@ -903,8 +899,12 @@ public final class AccessibilityWindowInfo implements Parcelable {
case TYPE_MAGNIFICATION_OVERLAY: {
return "TYPE_MAGNIFICATION_OVERLAY";
}
- default:
+ default: {
+ if (Flags.enableTypeWindowControl() && type == TYPE_WINDOW_CONTROL) {
+ return "TYPE_WINDOW_CONTROL";
+ }
return "<UNKNOWN:" + type + ">";
+ }
}
}
diff --git a/core/proto/android/server/vibrator/vibratormanagerservice.proto b/core/proto/android/server/vibrator/vibratormanagerservice.proto
index e7f0560612cc..258832e3e7ff 100644
--- a/core/proto/android/server/vibrator/vibratormanagerservice.proto
+++ b/core/proto/android/server/vibrator/vibratormanagerservice.proto
@@ -157,10 +157,8 @@ message VibratorManagerServiceDumpProto {
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
repeated int32 vibrator_ids = 1;
optional VibrationProto current_vibration = 2;
- optional bool is_vibrating = 3;
optional int32 is_vibrator_controller_registered = 27;
optional VibrationProto current_external_vibration = 4;
- optional bool vibrator_under_external_control = 5;
optional bool low_power_mode = 6;
optional bool vibrate_on = 24;
reserved 25; // prev keyboard_vibration_on
@@ -183,4 +181,6 @@ message VibratorManagerServiceDumpProto {
repeated VibrationProto previous_vibrations = 16;
repeated VibrationParamProto previous_vibration_params = 28;
reserved 17; // prev previous_external_vibrations
+ reserved 3; // prev is_vibrating, check current_vibration instead
+ reserved 5; // prev vibrator_under_external_control, check current_external_vibration instead
} \ No newline at end of file
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 07efad89010a..92c390656da5 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -4457,6 +4457,11 @@
<!-- Bytes that the PinnerService will pin for WebView -->
<integer name="config_pinnerWebviewPinBytes">0</integer>
+ <!-- Maximum memory that PinnerService will pin for apps expressed
+ as a percentage of total device memory [0,100].
+ Example: 10, means 10% of total memory will be the maximum pinned memory -->
+ <integer name="config_pinnerMaxPinnedMemoryPercentage">10</integer>
+
<!-- Number of days preloaded file cache should be preserved on a device before it can be
deleted -->
<integer name="config_keepPreloadsMinDays">7</integer>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index f397ef2b151c..6683dc044c9a 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -808,6 +808,12 @@
This is bigger than displayed because listeners can use it for other displays
e.g. wearables. -->
<dimen name="notification_person_icon_max_size">144dp</dimen>
+ <!-- The size of the progress bar icon -->
+ <dimen name="notification_progress_icon_size">20dp</dimen>
+ <!-- The size of the progress tracker width -->
+ <dimen name="notification_progress_tracker_width">40dp</dimen>
+ <!-- The size of the progress tracker height -->
+ <dimen name="notification_progress_tracker_height">20dp</dimen>
<!-- The maximum size of the small notification icon on low memory devices. -->
<dimen name="notification_small_icon_size_low_ram">@dimen/notification_small_icon_size</dimen>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 06b36b8f74af..5f40a6c7eba4 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3467,6 +3467,7 @@
<java-symbol type="integer" name="config_pinnerHomePinBytes" />
<java-symbol type="bool" name="config_pinnerAssistantApp" />
<java-symbol type="integer" name="config_pinnerWebviewPinBytes" />
+ <java-symbol type="integer" name="config_pinnerMaxPinnedMemoryPercentage" />
<java-symbol type="string" name="config_doubleTouchGestureEnableFile" />
@@ -3854,6 +3855,9 @@
<java-symbol type="dimen" name="notification_custom_view_max_image_height"/>
<java-symbol type="dimen" name="notification_custom_view_max_image_width"/>
<java-symbol type="dimen" name="notification_person_icon_max_size" />
+ <java-symbol type="dimen" name="notification_progress_icon_size" />
+ <java-symbol type="dimen" name="notification_progress_tracker_width" />
+ <java-symbol type="dimen" name="notification_progress_tracker_height" />
<java-symbol type="dimen" name="notification_small_icon_size_low_ram"/>
<java-symbol type="dimen" name="notification_big_picture_max_height_low_ram"/>
diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp
index d98836f8ce20..9821d433500f 100644
--- a/core/tests/coretests/Android.bp
+++ b/core/tests/coretests/Android.bp
@@ -25,6 +25,7 @@ filegroup {
"BinderProxyCountingTestApp/src/**/*.java",
"BinderProxyCountingTestService/src/**/*.java",
"BinderDeathRecipientHelperApp/src/**/*.java",
+ "AppThatCallsBinderMethods/src/**/*.kt",
],
visibility: ["//visibility:private"],
}
@@ -104,6 +105,7 @@ android_test {
"mockito-target-extended-minus-junit4",
"TestParameterInjector",
"android.content.res.flags-aconfig-java",
+ "android.security.flags-aconfig-java",
],
libs: [
@@ -143,6 +145,7 @@ android_test {
":BinderProxyCountingTestApp",
":BinderProxyCountingTestService",
":AppThatUsesAppOps",
+ ":AppThatCallsBinderMethods",
],
}
diff --git a/core/tests/coretests/AndroidTest.xml b/core/tests/coretests/AndroidTest.xml
index b1f1e2c2db05..05ab783c01bb 100644
--- a/core/tests/coretests/AndroidTest.xml
+++ b/core/tests/coretests/AndroidTest.xml
@@ -26,6 +26,7 @@
<option name="test-file-name" value="BinderProxyCountingTestApp.apk" />
<option name="test-file-name" value="BinderProxyCountingTestService.apk" />
<option name="test-file-name" value="AppThatUsesAppOps.apk" />
+ <option name="test-file-name" value="AppThatCallsBinderMethods.apk" />
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
diff --git a/core/tests/coretests/AppThatCallsBinderMethods/Android.bp b/core/tests/coretests/AppThatCallsBinderMethods/Android.bp
new file mode 100644
index 000000000000..dcc0d4f76bf2
--- /dev/null
+++ b/core/tests/coretests/AppThatCallsBinderMethods/Android.bp
@@ -0,0 +1,20 @@
+// 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.
+
+android_test_helper_app {
+ name: "AppThatCallsBinderMethods",
+ srcs: ["src/**/*.kt"],
+ platform_apis: true,
+ static_libs: ["coretests-aidl"],
+}
diff --git a/core/tests/coretests/AppThatCallsBinderMethods/AndroidManifest.xml b/core/tests/coretests/AppThatCallsBinderMethods/AndroidManifest.xml
new file mode 100644
index 000000000000..b2f6d7897681
--- /dev/null
+++ b/core/tests/coretests/AppThatCallsBinderMethods/AndroidManifest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.frameworks.coretests.methodcallerhelperapp">
+ <application>
+ <receiver android:name="com.android.frameworks.coretests.methodcallerhelperapp.CallMethodsReceiver"
+ android:exported="true"/>
+ </application>
+
+</manifest>
diff --git a/core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/CallMethodsReceiver.kt b/core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/CallMethodsReceiver.kt
new file mode 100644
index 000000000000..638cc3b7692f
--- /dev/null
+++ b/core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/CallMethodsReceiver.kt
@@ -0,0 +1,57 @@
+/*
+ * 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.frameworks.coretests.methodcallerhelperapp
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.util.Log
+
+import com.android.frameworks.coretests.aidl.ITestInterface
+
+/**
+ * Receiver used to call methods when a binder is received
+ * {@link android.os.BinderUncaughtExceptionHandlerTest}.
+ */
+class CallMethodsReceiver : BroadcastReceiver() {
+ private val TAG = "CallMethodsReceiver"
+
+ override fun onReceive(context: Context, intent: Intent) {
+ try {
+ when (intent.getAction()) {
+ ACTION_CALL_METHOD -> intent.getExtras()!!.let {
+ Log.i(TAG, "Received ACTION_CALL_METHOD with extras: $it")
+ val iface = it.getBinder(EXTRA_BINDER)!!.let(ITestInterface.Stub::asInterface)!!
+ val name = it.getString(EXTRA_METHOD_NAME)!!
+ try {
+ when (name) {
+ "foo" -> iface.foo(5)
+ "onewayFoo" -> iface.onewayFoo(5)
+ "bar" -> iface.bar(5)
+ else -> Log.e(TAG, "Unknown method name")
+ }
+ } catch (e: Exception) {
+ // Exceptions expected
+ }
+ }
+ else -> Log.e(TAG, "Unknown action " + intent.getAction())
+ }
+ } catch (e: Exception) {
+ Log.e(TAG, "Exception: ", e)
+ }
+ }
+}
diff --git a/core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/Constants.kt b/core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/Constants.kt
new file mode 100644
index 000000000000..37c6268164a7
--- /dev/null
+++ b/core/tests/coretests/AppThatCallsBinderMethods/src/com/android/frameworks/coretests/methodcallerhelperapp/Constants.kt
@@ -0,0 +1,23 @@
+/*
+ * 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.frameworks.coretests.methodcallerhelperapp
+
+const val PACKAGE_NAME = "com.android.frameworks.coretests.methodcallerhelperapp"
+const val RECEIVER_NAME = "CallMethodsReceiver"
+const val ACTION_CALL_METHOD = PACKAGE_NAME + ".ACTION_CALL_METHOD"
+const val EXTRA_METHOD_NAME = PACKAGE_NAME + ".EXTRA_METHOD_NAME"
+const val EXTRA_BINDER = PACKAGE_NAME + ".EXTRA_BINDER"
diff --git a/core/tests/coretests/aidl/com/android/frameworks/coretests/aidl/ITestInterface.aidl b/core/tests/coretests/aidl/com/android/frameworks/coretests/aidl/ITestInterface.aidl
new file mode 100644
index 000000000000..ffcf178beda4
--- /dev/null
+++ b/core/tests/coretests/aidl/com/android/frameworks/coretests/aidl/ITestInterface.aidl
@@ -0,0 +1,27 @@
+/*
+ * 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.frameworks.coretests.aidl;
+
+/**
+ * Just an interface with a oneway, void and non-oneway method.
+ */
+interface ITestInterface {
+ // Method order matters, since we verify transaction codes
+ int foo(int a);
+ oneway void onewayFoo(int a);
+ void bar(int a);
+}
diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java
index 0f73df92ca93..edcea241e620 100644
--- a/core/tests/coretests/src/android/app/NotificationTest.java
+++ b/core/tests/coretests/src/android/app/NotificationTest.java
@@ -97,7 +97,6 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.TextAppearanceSpan;
import android.util.Pair;
-import android.util.Slog;
import android.widget.RemoteViews;
import androidx.test.InstrumentationRegistry;
@@ -118,6 +117,7 @@ import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
+import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
@@ -2114,6 +2114,300 @@ public class NotificationTest {
assertThat(n.getWhen()).isEqualTo(9);
}
+ @Test
+ public void getNotificationStyleClass_forPlatformClassName_returnsPlatformClass() {
+ final List<Class<? extends Notification.Style>> platformStyleClasses = List.of(
+ Notification.BigTextStyle.class, Notification.BigPictureStyle.class,
+ Notification.MessagingStyle.class, Notification.CallStyle.class,
+ Notification.InboxStyle.class, Notification.MediaStyle.class,
+ Notification.DecoratedCustomViewStyle.class,
+ Notification.DecoratedMediaCustomViewStyle.class
+ );
+
+ for (Class<? extends Notification.Style> platformStyleClass : platformStyleClasses) {
+ assertThat(Notification.getNotificationStyleClass(platformStyleClass.getName()))
+ .isEqualTo(platformStyleClass);
+ }
+ }
+
+ @Test
+ public void getNotificationStyleClass_forNotPlatformClassName_returnsNull() {
+ assertThat(Notification.getNotificationStyleClass(NotAPlatformStyle.class.getName()))
+ .isNull();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_richOngoingEnabled_platformClass() {
+ assertThat(
+ Notification.getNotificationStyleClass(Notification.ProgressStyle.class.getName()))
+ .isEqualTo(Notification.ProgressStyle.class);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_richOngoingDisabled_notPlatformClass() {
+ assertThat(
+ Notification.getNotificationStyleClass(Notification.ProgressStyle.class.getName()))
+ .isNull();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onSegmentChange_visiblyDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .addProgressSegment(new Notification.ProgressStyle.Segment(100))
+ .addProgressSegment(new Notification.ProgressStyle.Segment(50)
+ .setColor(Color.RED)));
+
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .addProgressSegment(new Notification.ProgressStyle.Segment(100))
+ .addProgressSegment(new Notification.ProgressStyle.Segment(50)
+ .setColor(Color.BLUE)));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void indeterminateProgressStyle_onSegmentChange_visiblyNotDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(true)
+ .addProgressSegment(new Notification.ProgressStyle.Segment(100))
+ .addProgressSegment(new Notification.ProgressStyle.Segment(50)
+ .setColor(Color.RED)));
+
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(true)
+ .addProgressSegment(new Notification.ProgressStyle.Segment(100))
+ .addProgressSegment(new Notification.ProgressStyle.Segment(50)
+ .setColor(Color.BLUE)));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onStartIconChange_visiblyDifferent() {
+ final Icon icon1 = Icon.createWithBitmap(BitmapFactory.decodeResource(
+ mContext.getResources(), com.android.frameworks.coretests.R.drawable.test128x96));
+
+ final Icon icon2 = Icon.createWithBitmap(
+ Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888));
+
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressStartIcon(icon1));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressStartIcon(icon2));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onEndIconChange_visiblyDifferent() {
+ final Icon icon1 = Icon.createWithBitmap(BitmapFactory.decodeResource(
+ mContext.getResources(), com.android.frameworks.coretests.R.drawable.test128x96));
+
+ final Icon icon2 = Icon.createWithBitmap(
+ Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888));
+
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressEndIcon(icon1));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressEndIcon(icon2));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onProgressChange_visiblyDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgress(20));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgress(21));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void indeterminateProgressStyle_onProgressChange_visiblyNotDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .setProgressIndeterminate(true).setProgress(20));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .setProgressIndeterminate(true).setProgress(21));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onIsStyledByProgressChange_visiblyDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setStyledByProgress(true));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setStyledByProgress(false));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void indeterminateProgressStyle_onIsStyledByProgressChange_visiblyNotDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .setProgressIndeterminate(true).setStyledByProgress(true));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .setProgressIndeterminate(true).setStyledByProgress(false));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onProgressStepChange_visiblyDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .addProgressStep(new Notification.ProgressStyle.Step(10)));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .addProgressStep(new Notification.ProgressStyle.Step(12)));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void indeterminateProgressStyle_onProgressStepChange_visiblyNotDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(true)
+ .addProgressStep(new Notification.ProgressStyle.Step(10)));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(true)
+ .addProgressStep(new Notification.ProgressStyle.Step(12)));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onTrackerIconChange_visiblyDifferent() {
+ final Icon icon1 = Icon.createWithBitmap(BitmapFactory.decodeResource(
+ mContext.getResources(), com.android.frameworks.coretests.R.drawable.test128x96));
+
+ final Icon icon2 = Icon.createWithBitmap(
+ Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888));
+
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressTrackerIcon(icon1));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressTrackerIcon(icon2));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void indeterminateProgressStyle_onTrackerIconChange_visiblyNotDifferent() {
+ final Icon icon1 = Icon.createWithBitmap(BitmapFactory.decodeResource(
+ mContext.getResources(), com.android.frameworks.coretests.R.drawable.test128x96));
+
+ final Icon icon2 = Icon.createWithBitmap(
+ Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888));
+
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(true)
+ .setProgressTrackerIcon(icon1));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle()
+ .setProgressIndeterminate(true).setProgressTrackerIcon(icon2));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_onIndeterminateChange_visiblyDifferent() {
+ final Notification.Builder nProgress1 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(true));
+ final Notification.Builder nProgress2 = new Notification.Builder(mContext, "test")
+ .setStyle(new Notification.ProgressStyle().setProgressIndeterminate(false));
+
+ assertThat(Notification.areStyledNotificationsVisiblyDifferent(nProgress1, nProgress2))
+ .isTrue();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_getProgressMax_default100() {
+ final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
+ assertThat(progressStyle.getProgressMax()).isEqualTo(100);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_getProgressMax_nooSegments_returnsDefault() {
+ final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
+ progressStyle.setProgressSegments(Collections.emptyList());
+ assertThat(progressStyle.getProgressMax()).isEqualTo(100);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_getProgressMax_returnsSumOfSegmentLength() {
+ final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
+ progressStyle
+ .addProgressSegment(new Notification.ProgressStyle.Segment(10))
+ .addProgressSegment(new Notification.ProgressStyle.Segment(20));
+
+ assertThat(progressStyle.getProgressMax()).isEqualTo(30);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_getProgressMax_onSegmentOverflow_returnsDefault() {
+ final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
+ progressStyle
+ .addProgressSegment(new Notification.ProgressStyle.Segment(Integer.MAX_VALUE))
+ .addProgressSegment(new Notification.ProgressStyle.Segment(10));
+
+ assertThat(progressStyle.getProgressMax()).isEqualTo(100);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_indeterminate_defaultValueFalse() {
+ final Notification.ProgressStyle progressStyle1 = new Notification.ProgressStyle();
+
+ assertThat(progressStyle1.isProgressIndeterminate()).isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
+ public void progressStyle_styledByProgress_defaultValueTrue() {
+ final Notification.ProgressStyle progressStyle1 = new Notification.ProgressStyle();
+
+ assertThat(progressStyle1.isStyledByProgress()).isTrue();
+ }
private void assertValid(Notification.Colors c) {
// Assert that all colors are populated
assertThat(c.getBackgroundColor()).isNotEqualTo(Notification.COLOR_INVALID);
@@ -2214,4 +2508,11 @@ public class NotificationTest {
new Intent(action).setPackage(mContext.getPackageName()),
PendingIntent.FLAG_MUTABLE);
}
+
+ private static class NotAPlatformStyle extends Notification.Style {
+ @Override
+ public boolean areNotificationsVisiblyDifferent(Notification.Style other) {
+ return false;
+ }
+ }
}
diff --git a/core/tests/coretests/src/android/content/IntentTest.java b/core/tests/coretests/src/android/content/IntentTest.java
new file mode 100644
index 000000000000..d169ce3c07d0
--- /dev/null
+++ b/core/tests/coretests/src/android/content/IntentTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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 android.content;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assert.assertEquals;
+
+import android.net.Uri;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.platform.test.annotations.Presubmit;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import android.security.Flags;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Build/Install/Run:
+ * atest FrameworksCoreTests:IntentTest
+ */
+@Presubmit
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class IntentTest {
+ private static final String TEST_ACTION = "android.content.IntentTest_test";
+ private static final String TEST_EXTRA_NAME = "testExtraName";
+ private static final Uri TEST_URI = Uri.parse("content://com.example/people");
+
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_PREVENT_INTENT_REDIRECT)
+ public void testReadFromParcelWithExtraIntentKeys() {
+ Intent intent = new Intent("TEST_ACTION");
+ intent.putExtra(TEST_EXTRA_NAME, new Intent(TEST_ACTION));
+ intent.putExtra(TEST_EXTRA_NAME + "2", 1);
+
+ intent.collectExtraIntentKeys();
+ final Parcel parcel = Parcel.obtain();
+ intent.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ final Intent target = new Intent();
+ target.readFromParcel(parcel);
+
+ assertEquals(intent.getAction(), target.getAction());
+ assertEquals(intent.getExtraIntentKeys(), target.getExtraIntentKeys());
+ assertThat(intent.getExtraIntentKeys()).hasSize(1);
+ }
+
+ @Test
+ public void testCreatorTokenInfo() {
+ Intent intent = new Intent(TEST_ACTION);
+ IBinder creatorToken = new Binder();
+
+ intent.setCreatorToken(creatorToken);
+ assertThat(intent.getCreatorToken()).isEqualTo(creatorToken);
+
+ intent.removeCreatorTokenInfo();
+ assertThat(intent.getCreatorToken()).isNull();
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_PREVENT_INTENT_REDIRECT)
+ public void testCollectExtraIntentKeys() {
+ Intent intent = new Intent(TEST_ACTION);
+ Intent extraIntent = new Intent(TEST_ACTION, TEST_URI);
+ intent.putExtra(TEST_EXTRA_NAME, extraIntent);
+
+ intent.collectExtraIntentKeys();
+
+ assertThat(intent.getExtraIntentKeys()).hasSize(1);
+ assertThat(intent.getExtraIntentKeys()).contains(TEST_EXTRA_NAME);
+ }
+
+}
diff --git a/core/tests/coretests/src/android/os/BinderUncaughtExceptionHandlerTest.kt b/core/tests/coretests/src/android/os/BinderUncaughtExceptionHandlerTest.kt
new file mode 100644
index 000000000000..791c209e4473
--- /dev/null
+++ b/core/tests/coretests/src/android/os/BinderUncaughtExceptionHandlerTest.kt
@@ -0,0 +1,247 @@
+/*
+ * 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 android.os
+
+import android.content.Intent
+import android.platform.test.annotations.DisabledOnRavenwood
+import android.platform.test.annotations.Presubmit
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+
+import com.android.frameworks.coretests.aidl.ITestInterface
+import com.android.frameworks.coretests.methodcallerhelperapp.*
+
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.mockito.ArgumentMatcher
+import org.mockito.ArgumentMatchers.any
+import org.mockito.ArgumentMatchers.anyInt
+import org.mockito.ArgumentMatchers.eq
+import org.mockito.ArgumentMatchers.intThat
+import org.mockito.Mockito.after
+import org.mockito.Mockito.doThrow
+import org.mockito.Mockito.never
+import org.mockito.Mockito.timeout
+import org.mockito.Mockito.verify
+import org.mockito.Mockito.`when`
+import org.mockito.Spy
+import org.mockito.junit.MockitoJUnit
+import org.mockito.quality.Strictness.STRICT_STUBS
+
+private const val TIMEOUT_DURATION_MS = 2000L
+private const val FALSE_NEG_DURATION_MS = 500L
+private const val FLAG_ONEWAY = 1
+// From ITestInterface.Stub class, these values are package private
+private const val TRANSACTION_foo = 1
+private const val TRANSACTION_onewayFoo = 2
+private const val TRANSACTION_bar = 3
+
+/** Tests functionality of {@link android.os.Binder.onUnhandledException}. */
+@DisabledOnRavenwood(reason = "multi-app")
+@Presubmit
+@RunWith(AndroidJUnit4::class)
+class BinderUncaughtExceptionHandlerTest {
+
+ val mContext = InstrumentationRegistry.getInstrumentation().getTargetContext()
+
+ @Rule @JvmField val rule = MockitoJUnit.rule().strictness(STRICT_STUBS)
+
+ @Spy var mInterfaceImpl: ITestImpl = ITestImpl()
+
+ // This subclass is needed for visibility issues (via protected), since the method we are
+ // verifying lives on the boot classpath, it is not enough to be in the same package.
+ open class ITestImpl : ITestInterface.Stub() {
+ override fun onUnhandledException(code: Int, flags: Int, e: Exception?) =
+ onUnhandledExceptionVisible(code, flags, e)
+
+ public open fun onUnhandledExceptionVisible(code: Int, flags: Int, e: Exception?) {}
+
+ @Throws(RemoteException::class)
+ override open fun foo(x: Int): Int = throw UnsupportedOperationException()
+
+ @Throws(RemoteException::class)
+ override open fun onewayFoo(x: Int): Unit = throw UnsupportedOperationException()
+
+ @Throws(RemoteException::class)
+ override open fun bar(x: Int): Unit = throw UnsupportedOperationException()
+ }
+
+ class OnewayMatcher(private val isOneway: Boolean) : ArgumentMatcher<Int> {
+ override fun matches(argument: Int?) =
+ (argument!! and FLAG_ONEWAY) == if (isOneway) 1 else 0
+
+ override fun toString() = "Expected oneway: $isOneway"
+ }
+
+ @Test
+ fun testRegularMethod_ifThrowsRuntimeException_HandlerCalled() {
+ val myException = RuntimeException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).foo(anyInt())
+
+ dispatchActionCall("foo")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_foo),
+ /* flags= */ intThat(OnewayMatcher(false)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testRegularMethod_ifThrowsRemoteException_HandlerCalled() {
+ val myException = RemoteException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).foo(anyInt())
+
+ dispatchActionCall("foo")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_foo),
+ /* flags= */ intThat(OnewayMatcher(false)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testRegularMethod_ifThrowsSecurityException_HandlerNotCalled() {
+ val myException = SecurityException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).foo(anyInt())
+
+ dispatchActionCall("foo")
+
+ // No unexpected calls
+ verify(mInterfaceImpl, after(FALSE_NEG_DURATION_MS).never())
+ .onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testVoidMethod_ifThrowsRuntimeException_HandlerCalled() {
+ val myException = RuntimeException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).bar(anyInt())
+
+ dispatchActionCall("bar")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_bar),
+ /* flags= */ intThat(OnewayMatcher(false)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testVoidMethod_ifThrowsRemoteException_HandlerCalled() {
+ val myException = RemoteException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).bar(anyInt())
+
+ dispatchActionCall("bar")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_bar),
+ /* flags= */ intThat(OnewayMatcher(false)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testVoidMethod_ifThrowsSecurityException_HandlerNotCalled() {
+ val myException = SecurityException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).bar(anyInt())
+
+ dispatchActionCall("bar")
+
+ // No unexpected calls
+ verify(mInterfaceImpl, after(FALSE_NEG_DURATION_MS).never())
+ .onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testOnewayMethod_ifThrowsRuntimeException_HandlerCalled() {
+ val myException = RuntimeException("Test exception")
+ doThrow(myException).doNothing().`when`(mInterfaceImpl).onewayFoo(anyInt())
+
+ dispatchActionCall("onewayFoo")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_onewayFoo),
+ /* flags= */ intThat(OnewayMatcher(true)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ @Test
+ fun testOnewayMethod_ifThrowsRemoteException_HandlerCalled() {
+ val myException = RemoteException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).onewayFoo(anyInt())
+
+ dispatchActionCall("onewayFoo")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_onewayFoo),
+ /* flags= */ intThat(OnewayMatcher(true)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ // All exceptions are uncaught for oneway
+ @Test
+ fun testOnewayMethod_ifThrowsSecurityException_HandlerCalled() {
+ val myException = SecurityException("Test exception")
+ doThrow(myException).`when`(mInterfaceImpl).onewayFoo(anyInt())
+
+ dispatchActionCall("onewayFoo")
+
+ verify(mInterfaceImpl, timeout(TIMEOUT_DURATION_MS))
+ .onUnhandledExceptionVisible(
+ /* transactionCode = */ eq(TRANSACTION_onewayFoo),
+ /* flags= */ intThat(OnewayMatcher(true)),
+ /* exception= */ eq(myException),
+ )
+ // No unexpected calls
+ verify(mInterfaceImpl).onUnhandledExceptionVisible(anyInt(), anyInt(), any())
+ }
+
+ private fun dispatchActionCall(methodName: String) =
+ Intent(ACTION_CALL_METHOD).apply {
+ putExtras(
+ Bundle().apply {
+ putBinder(EXTRA_BINDER, mInterfaceImpl as IBinder)
+ putString(EXTRA_METHOD_NAME, methodName)
+ }
+ )
+ setClassName(PACKAGE_NAME, CallMethodsReceiver::class.java.getName())
+ }.let { mContext.sendBroadcast(it) }
+}
diff --git a/core/tests/coretests/src/android/view/WindowLayoutTests.java b/core/tests/coretests/src/android/view/WindowLayoutTests.java
index 5cac98daee80..d4693e6e7130 100644
--- a/core/tests/coretests/src/android/view/WindowLayoutTests.java
+++ b/core/tests/coretests/src/android/view/WindowLayoutTests.java
@@ -413,4 +413,19 @@ public class WindowLayoutTests {
assertInsetByTopBottom(0, 0, mFrames.parentFrame);
assertInsetByTopBottom(0, 0, mFrames.frame);
}
+
+ @Test
+ public void windowBoundsOutsideDisplayCutoutSafe() {
+ addDisplayCutout();
+ mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
+ mWindowBounds.set(0, -1000, DISPLAY_WIDTH, 0);
+ computeFrames();
+
+ assertRect(WATERFALL_INSETS.left, 0, DISPLAY_WIDTH - WATERFALL_INSETS.right, 0,
+ mFrames.displayFrame);
+ assertRect(WATERFALL_INSETS.left, 0, DISPLAY_WIDTH - WATERFALL_INSETS.right, 0,
+ mFrames.parentFrame);
+ assertRect(WATERFALL_INSETS.left, 0, DISPLAY_WIDTH - WATERFALL_INSETS.right, 0,
+ mFrames.frame);
+ }
}
diff --git a/core/tests/resourceflaggingtests/src/com/android/resourceflaggingtests/ResourceFlaggingTest.java b/core/tests/resourceflaggingtests/src/com/android/resourceflaggingtests/ResourceFlaggingTest.java
index 005538a4d401..d9e90fa001c5 100644
--- a/core/tests/resourceflaggingtests/src/com/android/resourceflaggingtests/ResourceFlaggingTest.java
+++ b/core/tests/resourceflaggingtests/src/com/android/resourceflaggingtests/ResourceFlaggingTest.java
@@ -29,6 +29,7 @@ import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
+import android.widget.TextView;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -78,6 +79,16 @@ public class ResourceFlaggingTest {
}
@Test
+ public void testNegatedDisabledFlag() {
+ assertThat(mResources.getBoolean(R.bool.bool5)).isTrue();
+ }
+
+ @Test
+ public void testNegatedEnabledFlag() {
+ assertThat(mResources.getBoolean(R.bool.bool6)).isTrue();
+ }
+
+ @Test
public void testFlagEnabledDifferentCompilationUnit() {
assertThat(mResources.getBoolean(R.bool.bool3)).isTrue();
}
@@ -94,6 +105,26 @@ public class ResourceFlaggingTest {
}
@Test
+ public void testDirectoryEnabledFlag() {
+ assertThat(mResources.getBoolean(R.bool.bool8)).isTrue();
+ }
+
+ @Test
+ public void testDirectoryDisabledFlag() {
+ assertThat(mResources.getBoolean(R.bool.bool7)).isTrue();
+ }
+
+ @Test
+ public void testDirectoryNegatedEnabledFlag() {
+ assertThat(mResources.getBoolean(R.bool.bool9)).isTrue();
+ }
+
+ @Test
+ public void testDirectoryNegatedDisabledFlag() {
+ assertThat(mResources.getBoolean(R.bool.bool10)).isTrue();
+ }
+
+ @Test
public void testLayoutWithDisabledElements() {
LinearLayout ll = (LinearLayout) getLayoutInflater().inflate(R.layout.layout1, null);
assertThat(ll).isNotNull();
@@ -102,6 +133,24 @@ public class ResourceFlaggingTest {
assertThat((View) ll.findViewById(R.id.text2)).isNotNull();
}
+ @Test
+ public void testEnabledFlagLayoutOverrides() {
+ LinearLayout ll = (LinearLayout) getLayoutInflater().inflate(R.layout.layout3, null);
+ assertThat(ll).isNotNull();
+ assertThat((View) ll.findViewById(R.id.text1)).isNotNull();
+ assertThat(((TextView) ll.findViewById(R.id.text1)).getText()).isEqualTo("foobar");
+ }
+
+ @Test(expected = Resources.NotFoundException.class)
+ public void testDisabledLayout() {
+ getLayoutInflater().inflate(R.layout.layout2, null);
+ }
+
+ @Test(expected = Resources.NotFoundException.class)
+ public void testDisabledDrawable() {
+ mResources.getDrawable(R.drawable.removedpng);
+ }
+
private LayoutInflater getLayoutInflater() {
ContextWrapper c = new ContextWrapper(mContext) {
private LayoutInflater mInflater;
diff --git a/graphics/java/android/graphics/PathIterator.java b/graphics/java/android/graphics/PathIterator.java
index 48b29f4e81f4..d7caabf9f91b 100644
--- a/graphics/java/android/graphics/PathIterator.java
+++ b/graphics/java/android/graphics/PathIterator.java
@@ -44,6 +44,8 @@ public class PathIterator implements Iterator<PathIterator.Segment> {
private final Path mPath;
private final int mPathGenerationId;
private static final int POINT_ARRAY_SIZE = 8;
+ private static final boolean IS_DALVIK = "dalvik".equalsIgnoreCase(
+ System.getProperty("java.vm.name"));
private static final NativeAllocationRegistry sRegistry =
NativeAllocationRegistry.createMalloced(
@@ -80,9 +82,14 @@ public class PathIterator implements Iterator<PathIterator.Segment> {
mPath = path;
mNativeIterator = nCreate(mPath.mNativePath);
mPathGenerationId = mPath.getGenerationId();
- final VMRuntime runtime = VMRuntime.getRuntime();
- mPointsArray = (float[]) runtime.newNonMovableArray(float.class, POINT_ARRAY_SIZE);
- mPointsAddress = runtime.addressOf(mPointsArray);
+ if (IS_DALVIK) {
+ final VMRuntime runtime = VMRuntime.getRuntime();
+ mPointsArray = (float[]) runtime.newNonMovableArray(float.class, POINT_ARRAY_SIZE);
+ mPointsAddress = runtime.addressOf(mPointsArray);
+ } else {
+ mPointsArray = new float[POINT_ARRAY_SIZE];
+ mPointsAddress = 0;
+ }
sRegistry.registerNativeAllocation(this, mNativeIterator);
}
@@ -177,7 +184,8 @@ public class PathIterator implements Iterator<PathIterator.Segment> {
throw new ConcurrentModificationException(
"Iterator cannot be used on modified Path");
}
- @Verb int verb = nNext(mNativeIterator, mPointsAddress);
+ @Verb int verb = IS_DALVIK
+ ? nNext(mNativeIterator, mPointsAddress) : nNextHost(mNativeIterator, mPointsArray);
if (verb == VERB_DONE) {
mDone = true;
}
@@ -287,6 +295,9 @@ public class PathIterator implements Iterator<PathIterator.Segment> {
private static native long nCreate(long nativePath);
private static native long nGetFinalizer();
+ /* nNextHost should be used for host runtimes, e.g. LayoutLib */
+ private static native int nNextHost(long nativeIterator, float[] points);
+
// ------------------ Critical JNI ------------------------
@CriticalNative
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java b/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java
index 37f0067de453..089613853555 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducer.java
@@ -16,12 +16,11 @@
package androidx.window.common;
-import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE_IDENTIFIER;
+import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE;
import static androidx.window.common.layout.CommonFoldingFeature.COMMON_STATE_UNKNOWN;
import static androidx.window.common.layout.CommonFoldingFeature.parseListFromString;
-import android.annotation.NonNull;
import android.content.Context;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
@@ -31,16 +30,23 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.SparseIntArray;
+import androidx.annotation.BinderThread;
+import androidx.annotation.GuardedBy;
+import androidx.annotation.MainThread;
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
import androidx.window.common.layout.CommonFoldingFeature;
import androidx.window.common.layout.DisplayFoldFeatureCommon;
import com.android.internal.R;
+import com.android.window.flags.Flags;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import java.util.concurrent.Executor;
import java.util.function.Consumer;
/**
@@ -55,13 +61,6 @@ public final class DeviceStateManagerFoldingFeatureProducer
private static final boolean DEBUG = false;
/**
- * Emulated device state
- * {@link DeviceStateManager.DeviceStateCallback#onDeviceStateChanged(DeviceState)} to
- * {@link CommonFoldingFeature.State} map.
- */
- private final SparseIntArray mDeviceStateToPostureMap = new SparseIntArray();
-
- /**
* Device state received via
* {@link DeviceStateManager.DeviceStateCallback#onDeviceStateChanged(DeviceState)}.
* The identifier returned through {@link DeviceState#getIdentifier()} may not correspond 1:1
@@ -71,23 +70,40 @@ public final class DeviceStateManagerFoldingFeatureProducer
* "rear display". Concurrent mode for example is activated via public API and can be active in
* both the "open" and "half folded" device states.
*/
- private DeviceState mCurrentDeviceState = new DeviceState(
- new DeviceState.Configuration.Builder(INVALID_DEVICE_STATE_IDENTIFIER,
- "INVALID").build());
+ // TODO: b/337820752 - Add @GuardedBy("mCurrentDeviceStateLock") after flag cleanup.
+ private DeviceState mCurrentDeviceState = INVALID_DEVICE_STATE;
- private List<DeviceState> mSupportedStates;
+ /**
+ * Lock to synchronize access to {@link #mCurrentDeviceState}.
+ *
+ * <p>This lock is used to ensure thread-safety when accessing and modifying the
+ * {@link #mCurrentDeviceState} field. It is acquired by both the binder thread (if
+ * {@link Flags#wlinfoOncreate()} is enabled) and the main thread (if
+ * {@link Flags#wlinfoOncreate()} is disabled) to prevent race conditions and
+ * ensure data consistency.
+ */
+ private final Object mCurrentDeviceStateLock = new Object();
@NonNull
private final RawFoldingFeatureProducer mRawFoldSupplier;
- private final boolean mIsHalfOpenedSupported;
-
- private final DeviceStateCallback mDeviceStateCallback = new DeviceStateCallback() {
+ @NonNull
+ private final DeviceStateMapper mDeviceStateMapper;
+
+ @VisibleForTesting
+ final DeviceStateCallback mDeviceStateCallback = new DeviceStateCallback() {
+ // The GuardedBy analysis is intra-procedural, meaning it doesn’t consider the getData()
+ // implementation. See https://errorprone.info/bugpattern/GuardedBy for limitations.
+ @SuppressWarnings("GuardedBy")
+ @BinderThread // When Flags.wlinfoOncreate() is enabled.
+ @MainThread // When Flags.wlinfoOncreate() is disabled.
@Override
public void onDeviceStateChanged(@NonNull DeviceState state) {
- mCurrentDeviceState = state;
- mRawFoldSupplier.getData(DeviceStateManagerFoldingFeatureProducer
- .this::notifyFoldingFeatureChange);
+ synchronized (mCurrentDeviceStateLock) {
+ mCurrentDeviceState = state;
+ mRawFoldSupplier.getData(DeviceStateManagerFoldingFeatureProducer.this
+ ::notifyFoldingFeatureChangeLocked);
+ }
}
};
@@ -95,41 +111,14 @@ public final class DeviceStateManagerFoldingFeatureProducer
@NonNull RawFoldingFeatureProducer rawFoldSupplier,
@NonNull DeviceStateManager deviceStateManager) {
mRawFoldSupplier = rawFoldSupplier;
- String[] deviceStatePosturePairs = context.getResources()
- .getStringArray(R.array.config_device_state_postures);
- mSupportedStates = deviceStateManager.getSupportedDeviceStates();
- boolean isHalfOpenedSupported = false;
- for (String deviceStatePosturePair : deviceStatePosturePairs) {
- String[] deviceStatePostureMapping = deviceStatePosturePair.split(":");
- if (deviceStatePostureMapping.length != 2) {
- if (DEBUG) {
- Log.e(TAG, "Malformed device state posture pair: "
- + deviceStatePosturePair);
- }
- continue;
- }
+ mDeviceStateMapper =
+ new DeviceStateMapper(context, deviceStateManager.getSupportedDeviceStates());
- int deviceState;
- int posture;
- try {
- deviceState = Integer.parseInt(deviceStatePostureMapping[0]);
- posture = Integer.parseInt(deviceStatePostureMapping[1]);
- } catch (NumberFormatException e) {
- if (DEBUG) {
- Log.e(TAG, "Failed to parse device state or posture: "
- + deviceStatePosturePair,
- e);
- }
- continue;
- }
- isHalfOpenedSupported = isHalfOpenedSupported
- || posture == CommonFoldingFeature.COMMON_STATE_HALF_OPENED;
- mDeviceStateToPostureMap.put(deviceState, posture);
- }
- mIsHalfOpenedSupported = isHalfOpenedSupported;
- if (mDeviceStateToPostureMap.size() > 0) {
+ if (!mDeviceStateMapper.isDeviceStateToPostureMapEmpty()) {
+ final Executor executor =
+ Flags.wlinfoOncreate() ? Runnable::run : context.getMainExecutor();
Objects.requireNonNull(deviceStateManager)
- .registerCallback(context.getMainExecutor(), mDeviceStateCallback);
+ .registerCallback(executor, mDeviceStateCallback);
}
}
@@ -137,50 +126,51 @@ public final class DeviceStateManagerFoldingFeatureProducer
* Add a callback to mCallbacks if there is no device state. This callback will be run
* once a device state is set. Otherwise,run the callback immediately.
*/
- private void runCallbackWhenValidState(@NonNull Consumer<List<CommonFoldingFeature>> callback,
- String displayFeaturesString) {
- if (isCurrentStateValid()) {
- callback.accept(calculateFoldingFeature(displayFeaturesString));
+ private void runCallbackWhenValidState(@NonNull DeviceState state,
+ @NonNull Consumer<List<CommonFoldingFeature>> callback,
+ @NonNull String displayFeaturesString) {
+ if (mDeviceStateMapper.isDeviceStateValid(state)) {
+ callback.accept(calculateFoldingFeature(state, displayFeaturesString));
} else {
// This callback will be added to mCallbacks and removed once it runs once.
- AcceptOnceConsumer<List<CommonFoldingFeature>> singleRunCallback =
+ final AcceptOnceConsumer<List<CommonFoldingFeature>> singleRunCallback =
new AcceptOnceConsumer<>(this, callback);
addDataChangedCallback(singleRunCallback);
}
}
- /**
- * Checks to find {@link DeviceStateManagerFoldingFeatureProducer#mCurrentDeviceState} in the
- * {@link DeviceStateManagerFoldingFeatureProducer#mDeviceStateToPostureMap} which was
- * initialized in the constructor of {@link DeviceStateManagerFoldingFeatureProducer}.
- * Returns a boolean value of whether the device state is valid.
- */
- private boolean isCurrentStateValid() {
- // If the device state is not found in the map, indexOfKey returns a negative number.
- return mDeviceStateToPostureMap.indexOfKey(mCurrentDeviceState.getIdentifier()) >= 0;
- }
-
+ // The GuardedBy analysis is intra-procedural, meaning it doesn’t consider the implementation of
+ // addDataChangedCallback(). See https://errorprone.info/bugpattern/GuardedBy for limitations.
+ @SuppressWarnings("GuardedBy")
@Override
protected void onListenersChanged() {
super.onListenersChanged();
- if (hasListeners()) {
- mRawFoldSupplier.addDataChangedCallback(this::notifyFoldingFeatureChange);
- } else {
- mCurrentDeviceState = new DeviceState(
- new DeviceState.Configuration.Builder(INVALID_DEVICE_STATE_IDENTIFIER,
- "INVALID").build());
- mRawFoldSupplier.removeDataChangedCallback(this::notifyFoldingFeatureChange);
+ synchronized (mCurrentDeviceStateLock) {
+ if (hasListeners()) {
+ mRawFoldSupplier.addDataChangedCallback(this::notifyFoldingFeatureChangeLocked);
+ } else {
+ mCurrentDeviceState = INVALID_DEVICE_STATE;
+ mRawFoldSupplier.removeDataChangedCallback(this::notifyFoldingFeatureChangeLocked);
+ }
+ }
+ }
+
+ @NonNull
+ private DeviceState getCurrentDeviceState() {
+ synchronized (mCurrentDeviceStateLock) {
+ return mCurrentDeviceState;
}
}
@NonNull
@Override
public Optional<List<CommonFoldingFeature>> getCurrentData() {
- Optional<String> displayFeaturesString = mRawFoldSupplier.getCurrentData();
- if (!isCurrentStateValid()) {
+ final Optional<String> displayFeaturesString = mRawFoldSupplier.getCurrentData();
+ final DeviceState state = getCurrentDeviceState();
+ if (!mDeviceStateMapper.isDeviceStateValid(state) || displayFeaturesString.isEmpty()) {
return Optional.empty();
} else {
- return displayFeaturesString.map(this::calculateFoldingFeature);
+ return Optional.of(calculateFoldingFeature(state, displayFeaturesString.get()));
}
}
@@ -191,7 +181,7 @@ public final class DeviceStateManagerFoldingFeatureProducer
*/
@NonNull
public List<CommonFoldingFeature> getFoldsWithUnknownState() {
- Optional<String> optionalFoldingFeatureString = mRawFoldSupplier.getCurrentData();
+ final Optional<String> optionalFoldingFeatureString = mRawFoldSupplier.getCurrentData();
if (optionalFoldingFeatureString.isPresent()) {
return CommonFoldingFeature.parseListFromString(
@@ -201,7 +191,6 @@ public final class DeviceStateManagerFoldingFeatureProducer
return Collections.emptyList();
}
-
/**
* Returns the list of supported {@link DisplayFoldFeatureCommon} calculated from the
* {@link DeviceStateManagerFoldingFeatureProducer}.
@@ -218,16 +207,16 @@ public final class DeviceStateManagerFoldingFeatureProducer
return foldFeatures;
}
-
/**
* Returns {@code true} if the device supports half-opened mode, {@code false} otherwise.
*/
public boolean isHalfOpenedSupported() {
- return mIsHalfOpenedSupported;
+ return mDeviceStateMapper.mIsHalfOpenedSupported;
}
/**
* Adds the data to the storeFeaturesConsumer when the data is ready.
+ *
* @param storeFeaturesConsumer a consumer to collect the data when it is first available.
*/
@Override
@@ -236,38 +225,123 @@ public final class DeviceStateManagerFoldingFeatureProducer
if (TextUtils.isEmpty(displayFeaturesString)) {
storeFeaturesConsumer.accept(new ArrayList<>());
} else {
- runCallbackWhenValidState(storeFeaturesConsumer, displayFeaturesString);
+ final DeviceState state = getCurrentDeviceState();
+ runCallbackWhenValidState(state, storeFeaturesConsumer, displayFeaturesString);
}
});
}
- private void notifyFoldingFeatureChange(String displayFeaturesString) {
- if (!isCurrentStateValid()) {
+ @GuardedBy("mCurrentDeviceStateLock")
+ private void notifyFoldingFeatureChangeLocked(String displayFeaturesString) {
+ final DeviceState state = mCurrentDeviceState;
+ if (!mDeviceStateMapper.isDeviceStateValid(state)) {
return;
}
if (TextUtils.isEmpty(displayFeaturesString)) {
notifyDataChanged(new ArrayList<>());
} else {
- notifyDataChanged(calculateFoldingFeature(displayFeaturesString));
+ notifyDataChanged(calculateFoldingFeature(state, displayFeaturesString));
}
}
- private List<CommonFoldingFeature> calculateFoldingFeature(String displayFeaturesString) {
- return parseListFromString(displayFeaturesString, currentHingeState());
+ @NonNull
+ private List<CommonFoldingFeature> calculateFoldingFeature(@NonNull DeviceState deviceState,
+ @NonNull String displayFeaturesString) {
+ @CommonFoldingFeature.State
+ final int hingeState = mDeviceStateMapper.getHingeState(deviceState);
+ return parseListFromString(displayFeaturesString, hingeState);
}
- @CommonFoldingFeature.State
- private int currentHingeState() {
- @CommonFoldingFeature.State
- int posture = mDeviceStateToPostureMap.get(mCurrentDeviceState.getIdentifier(),
- COMMON_STATE_UNKNOWN);
+ /**
+ * Internal class to map device states to corresponding postures.
+ *
+ * <p>This class encapsulates the logic for mapping device states to postures. The mapping is
+ * immutable after initialization to ensure thread safety.
+ */
+ private static class DeviceStateMapper {
+ /**
+ * Emulated device state
+ * {@link DeviceStateManager.DeviceStateCallback#onDeviceStateChanged(DeviceState)} to
+ * {@link CommonFoldingFeature.State} map.
+ *
+ * <p>This map must be immutable after initialization to ensure thread safety, as it may be
+ * accessed from multiple threads. Modifications should only occur during object
+ * construction.
+ */
+ private final SparseIntArray mDeviceStateToPostureMap = new SparseIntArray();
+
+ /**
+ * The list of device states that are supported.
+ *
+ * <p>This list must be immutable after initialization to ensure thread safety.
+ */
+ @NonNull
+ private final List<DeviceState> mSupportedStates;
+
+ final boolean mIsHalfOpenedSupported;
+
+ DeviceStateMapper(@NonNull Context context, @NonNull List<DeviceState> supportedStates) {
+ mSupportedStates = supportedStates;
+
+ final String[] deviceStatePosturePairs = context.getResources()
+ .getStringArray(R.array.config_device_state_postures);
+ boolean isHalfOpenedSupported = false;
+ for (String deviceStatePosturePair : deviceStatePosturePairs) {
+ final String[] deviceStatePostureMapping = deviceStatePosturePair.split(":");
+ if (deviceStatePostureMapping.length != 2) {
+ if (DEBUG) {
+ Log.e(TAG, "Malformed device state posture pair: "
+ + deviceStatePosturePair);
+ }
+ continue;
+ }
- if (posture == CommonFoldingFeature.COMMON_STATE_USE_BASE_STATE) {
- posture = mDeviceStateToPostureMap.get(
- DeviceStateUtil.calculateBaseStateIdentifier(mCurrentDeviceState,
- mSupportedStates), COMMON_STATE_UNKNOWN);
+ final int deviceState;
+ final int posture;
+ try {
+ deviceState = Integer.parseInt(deviceStatePostureMapping[0]);
+ posture = Integer.parseInt(deviceStatePostureMapping[1]);
+ } catch (NumberFormatException e) {
+ if (DEBUG) {
+ Log.e(TAG, "Failed to parse device state or posture: "
+ + deviceStatePosturePair,
+ e);
+ }
+ continue;
+ }
+ isHalfOpenedSupported = isHalfOpenedSupported
+ || posture == CommonFoldingFeature.COMMON_STATE_HALF_OPENED;
+ mDeviceStateToPostureMap.put(deviceState, posture);
+ }
+ mIsHalfOpenedSupported = isHalfOpenedSupported;
+ }
+
+ boolean isDeviceStateToPostureMapEmpty() {
+ return mDeviceStateToPostureMap.size() == 0;
+ }
+
+ /**
+ * Validates if the provided deviceState exists in the {@link #mDeviceStateToPostureMap}
+ * which was initialized in the constructor of {@link DeviceStateMapper}.
+ * Returns a boolean value of whether the device state is valid.
+ */
+ boolean isDeviceStateValid(@NonNull DeviceState deviceState) {
+ // If the device state is not found in the map, indexOfKey returns a negative number.
+ return mDeviceStateToPostureMap.indexOfKey(deviceState.getIdentifier()) >= 0;
}
- return posture;
+ @CommonFoldingFeature.State
+ int getHingeState(@NonNull DeviceState deviceState) {
+ @CommonFoldingFeature.State
+ final int posture =
+ mDeviceStateToPostureMap.get(deviceState.getIdentifier(), COMMON_STATE_UNKNOWN);
+ if (posture != CommonFoldingFeature.COMMON_STATE_USE_BASE_STATE) {
+ return posture;
+ }
+
+ final int baseStateIdentifier =
+ DeviceStateUtil.calculateBaseStateIdentifier(deviceState, mSupportedStates);
+ return mDeviceStateToPostureMap.get(baseStateIdentifier, COMMON_STATE_UNKNOWN);
+ }
}
}
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java
index 74cce68f270b..dcc2d93060c9 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java
@@ -377,8 +377,16 @@ class TaskContainer {
@Nullable
TaskFragmentContainer getContainerWithActivity(@NonNull IBinder activityToken) {
- return getContainer(container -> container.hasAppearedActivity(activityToken)
- || container.hasPendingAppearedActivity(activityToken));
+ // When the new activity is launched to the topmost TF because the source activity
+ // was in that TF, and the source activity is finished before resolving the new activity,
+ // we will try to see if the new activity match a rule with the split activities below.
+ // If matched, it can be reparented.
+ final TaskFragmentContainer taskFragmentContainer
+ = getContainer(container -> container.hasPendingAppearedActivity(activityToken));
+ if (taskFragmentContainer != null) {
+ return taskFragmentContainer;
+ }
+ return getContainer(container -> container.hasAppearedActivity(activityToken));
}
@Nullable
diff --git a/libs/WindowManager/Jetpack/tests/unittest/Android.bp b/libs/WindowManager/Jetpack/tests/unittest/Android.bp
index bd430c0e610b..09185ee203b8 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/Android.bp
+++ b/libs/WindowManager/Jetpack/tests/unittest/Android.bp
@@ -29,6 +29,7 @@ android_test {
srcs: [
"**/*.java",
+ "**/*.kt",
],
static_libs: [
@@ -41,6 +42,7 @@ android_test {
"androidx.test.ext.junit",
"flag-junit",
"mockito-target-extended-minus-junit4",
+ "mockito-kotlin-nodeps",
"truth",
"testables",
"platform-test-annotations",
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducerTest.kt b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducerTest.kt
new file mode 100644
index 000000000000..90887a747a6f
--- /dev/null
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/common/DeviceStateManagerFoldingFeatureProducerTest.kt
@@ -0,0 +1,341 @@
+/*
+ * 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 androidx.window.common
+
+import android.content.Context
+import android.content.res.Resources
+import android.hardware.devicestate.DeviceState
+import android.hardware.devicestate.DeviceStateManager
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
+import android.platform.test.flag.junit.SetFlagsRule
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.window.common.layout.CommonFoldingFeature
+import androidx.window.common.layout.CommonFoldingFeature.COMMON_STATE_FLAT
+import androidx.window.common.layout.CommonFoldingFeature.COMMON_STATE_HALF_OPENED
+import androidx.window.common.layout.CommonFoldingFeature.COMMON_STATE_NO_FOLDING_FEATURES
+import androidx.window.common.layout.CommonFoldingFeature.COMMON_STATE_UNKNOWN
+import androidx.window.common.layout.CommonFoldingFeature.COMMON_STATE_USE_BASE_STATE
+import androidx.window.common.layout.DisplayFoldFeatureCommon
+import androidx.window.common.layout.DisplayFoldFeatureCommon.DISPLAY_FOLD_FEATURE_PROPERTY_SUPPORTS_HALF_OPENED
+import androidx.window.common.layout.DisplayFoldFeatureCommon.DISPLAY_FOLD_FEATURE_TYPE_SCREEN_FOLD_IN
+import com.android.internal.R
+import com.android.window.flags.Flags
+import com.google.common.truth.Truth.assertThat
+import java.util.Optional
+import java.util.concurrent.Executor
+import java.util.function.Consumer
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.eq
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.never
+import org.mockito.kotlin.stub
+import org.mockito.kotlin.verify
+
+/**
+ * Test class for [DeviceStateManagerFoldingFeatureProducer].
+ *
+ * Build/Install/Run:
+ * atest WMJetpackUnitTests:DeviceStateManagerFoldingFeatureProducerTest
+ */
+@RunWith(AndroidJUnit4::class)
+class DeviceStateManagerFoldingFeatureProducerTest {
+ @get:Rule
+ val setFlagsRule: SetFlagsRule = SetFlagsRule()
+
+ private val mMockDeviceStateManager = mock<DeviceStateManager>()
+ private val mMockResources = mock<Resources> {
+ on { getStringArray(R.array.config_device_state_postures) } doReturn DEVICE_STATE_POSTURES
+ }
+ private val mMockContext = mock<Context> {
+ on { resources } doReturn mMockResources
+ }
+ private val mRawFoldSupplier = mock<RawFoldingFeatureProducer> {
+ on { currentData } doReturn Optional.of(DISPLAY_FEATURES)
+ on { getData(any<Consumer<String>>()) } doAnswer { invocation ->
+ val callback = invocation.getArgument(0) as Consumer<String>
+ callback.accept(DISPLAY_FEATURES)
+ }
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_WLINFO_ONCREATE)
+ fun testRegisterCallback_whenWlinfoOncreateIsDisabled_usesMainExecutor() {
+ DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ verify(mMockDeviceStateManager).registerCallback(eq(mMockContext.mainExecutor), any())
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_WLINFO_ONCREATE)
+ fun testRegisterCallback_whenWlinfoOncreateIsEnabled_usesRunnableRun() {
+ val executorCaptor = ArgumentCaptor.forClass(Executor::class.java)
+ val runnable = mock<Runnable>()
+
+ DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ verify(mMockDeviceStateManager).registerCallback(executorCaptor.capture(), any())
+ executorCaptor.value.execute(runnable)
+ verify(runnable).run()
+ }
+
+ @Test
+ fun testGetCurrentData_validCurrentState_returnsFoldingFeatureWithState() {
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+ ffp.mDeviceStateCallback.onDeviceStateChanged(DEVICE_STATE_HALF_OPENED)
+
+ val currentData = ffp.getCurrentData()
+
+ assertThat(currentData).isPresent()
+ assertThat(currentData.get()).containsExactlyElementsIn(HALF_OPENED_FOLDING_FEATURES)
+ }
+
+ @Test
+ fun testGetCurrentData_invalidCurrentState_returnsEmptyOptionalFoldingFeature() {
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ val currentData = ffp.getCurrentData()
+
+ assertThat(currentData).isEmpty()
+ }
+
+ @Test
+ fun testGetFoldsWithUnknownState_validFoldingFeature_returnsFoldingFeaturesWithUnknownState() {
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ val result = ffp.getFoldsWithUnknownState()
+
+ assertThat(result).containsExactlyElementsIn(UNKNOWN_STATE_FOLDING_FEATURES)
+ }
+
+ @Test
+ fun testGetFoldsWithUnknownState_emptyFoldingFeature_returnsEmptyList() {
+ mRawFoldSupplier.stub {
+ on { currentData } doReturn Optional.empty()
+ }
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ val result = ffp.getFoldsWithUnknownState()
+
+ assertThat(result).isEmpty()
+ }
+
+ @Test
+ fun testGetDisplayFeatures_validFoldingFeature_returnsDisplayFoldFeatures() {
+ mRawFoldSupplier.stub {
+ on { currentData } doReturn Optional.of(DISPLAY_FEATURES_HALF_OPENED_HINGE)
+ }
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ val result = ffp.displayFeatures
+
+ assertThat(result).containsExactly(
+ DisplayFoldFeatureCommon(
+ DISPLAY_FOLD_FEATURE_TYPE_SCREEN_FOLD_IN,
+ setOf(DISPLAY_FOLD_FEATURE_PROPERTY_SUPPORTS_HALF_OPENED),
+ ),
+ )
+ }
+
+ @Test
+ fun testIsHalfOpenedSupported_withHalfOpenedPostures_returnsTrue() {
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ assertThat(ffp.isHalfOpenedSupported).isTrue()
+ }
+
+ @Test
+ fun testIsHalfOpenedSupported_withEmptyPostures_returnsFalse() {
+ mMockResources.stub {
+ on { getStringArray(R.array.config_device_state_postures) } doReturn emptyArray()
+ }
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ assertThat(ffp.isHalfOpenedSupported).isFalse()
+ }
+
+ @Test
+ fun testGetData_emptyDisplayFeaturesString_callsConsumerWithEmptyList() {
+ mRawFoldSupplier.stub {
+ on { getData(any<Consumer<String>>()) } doAnswer { invocation ->
+ val callback = invocation.getArgument(0) as Consumer<String>
+ callback.accept("")
+ }
+ }
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+ val storeFeaturesConsumer = mock<Consumer<List<CommonFoldingFeature>>>()
+
+ ffp.getData(storeFeaturesConsumer)
+
+ verify(storeFeaturesConsumer).accept(emptyList())
+ }
+
+ @Test
+ fun testGetData_validState_callsConsumerWithFoldingFeatures() {
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+ ffp.mDeviceStateCallback.onDeviceStateChanged(DEVICE_STATE_HALF_OPENED)
+ val storeFeaturesConsumer = mock<Consumer<List<CommonFoldingFeature>>>()
+
+ ffp.getData(storeFeaturesConsumer)
+
+ verify(storeFeaturesConsumer).accept(HALF_OPENED_FOLDING_FEATURES)
+ }
+
+ @Test
+ fun testGetData_invalidState_addsAcceptOnceConsumerToDataChangedCallback() {
+ val ffp = DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+ val storeFeaturesConsumer = mock<Consumer<List<CommonFoldingFeature>>>()
+
+ ffp.getData(storeFeaturesConsumer)
+
+ verify(storeFeaturesConsumer, never()).accept(any())
+ ffp.mDeviceStateCallback.onDeviceStateChanged(DEVICE_STATE_HALF_OPENED)
+ ffp.mDeviceStateCallback.onDeviceStateChanged(DEVICE_STATE_OPENED)
+ verify(storeFeaturesConsumer).accept(HALF_OPENED_FOLDING_FEATURES)
+ }
+
+ @Test
+ fun testDeviceStateMapper_malformedDeviceStatePosturePair_skipsPair() {
+ val malformedDeviceStatePostures = arrayOf(
+ // Missing the posture.
+ "0",
+ // Empty string.
+ "",
+ // Too many elements.
+ "0:1:2",
+ )
+ mMockResources.stub {
+ on { getStringArray(R.array.config_device_state_postures) } doReturn
+ malformedDeviceStatePostures
+ }
+
+ DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ verify(mMockDeviceStateManager, never()).registerCallback(any(), any())
+ }
+
+ @Test
+ fun testDeviceStateMapper_invalidNumberFormat_skipsPair() {
+ val invalidNumberFormatDeviceStatePostures = arrayOf("a:1", "0:b", "a:b", ":1")
+ mMockResources.stub {
+ on { getStringArray(R.array.config_device_state_postures) } doReturn
+ invalidNumberFormatDeviceStatePostures
+ }
+
+ DeviceStateManagerFoldingFeatureProducer(
+ mMockContext,
+ mRawFoldSupplier,
+ mMockDeviceStateManager,
+ )
+
+ verify(mMockDeviceStateManager, never()).registerCallback(any(), any())
+ }
+
+ companion object {
+ // Supported device states configuration.
+ private enum class SupportedDeviceStates {
+ CLOSED, HALF_OPENED, OPENED, REAR_DISPLAY, CONCURRENT;
+
+ override fun toString() = ordinal.toString()
+
+ fun toDeviceState(): DeviceState =
+ DeviceState(DeviceState.Configuration.Builder(ordinal, name).build())
+ }
+
+ // Map of supported device states supplied by DeviceStateManager to WM Jetpack posture.
+ private val DEVICE_STATE_POSTURES =
+ arrayOf(
+ "${SupportedDeviceStates.CLOSED}:$COMMON_STATE_NO_FOLDING_FEATURES",
+ "${SupportedDeviceStates.HALF_OPENED}:$COMMON_STATE_HALF_OPENED",
+ "${SupportedDeviceStates.OPENED}:$COMMON_STATE_FLAT",
+ "${SupportedDeviceStates.REAR_DISPLAY}:$COMMON_STATE_NO_FOLDING_FEATURES",
+ "${SupportedDeviceStates.CONCURRENT}:$COMMON_STATE_USE_BASE_STATE",
+ )
+ private val DEVICE_STATE_HALF_OPENED = SupportedDeviceStates.HALF_OPENED.toDeviceState()
+ private val DEVICE_STATE_OPENED = SupportedDeviceStates.OPENED.toDeviceState()
+
+ // WindowsManager Jetpack display features.
+ private val DISPLAY_FEATURES = "fold-[1104,0,1104,1848]"
+ private val DISPLAY_FEATURES_HALF_OPENED_HINGE = "$DISPLAY_FEATURES-half-opened"
+ private val HALF_OPENED_FOLDING_FEATURES = CommonFoldingFeature.parseListFromString(
+ DISPLAY_FEATURES,
+ COMMON_STATE_HALF_OPENED,
+ )
+ private val UNKNOWN_STATE_FOLDING_FEATURES = CommonFoldingFeature.parseListFromString(
+ DISPLAY_FEATURES,
+ COMMON_STATE_UNKNOWN,
+ )
+ }
+}
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
index 7fab371cb790..bc4916a607a3 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
@@ -535,7 +535,8 @@ public class TaskFragmentContainerTest {
// container1.
container2.setInfo(mTransaction, mInfo);
- assertTrue(container2.hasActivity(mActivity.getActivityToken()));
+ assertTrue(container1.hasActivity(mActivity.getActivityToken()));
+ assertFalse(container2.hasActivity(mActivity.getActivityToken()));
// When the pending appeared record is removed from container1, we respect the appeared
// record in container2.
container1.removePendingAppearedActivity(mActivity.getActivityToken());
diff --git a/libs/WindowManager/Shell/aconfig/multitasking.aconfig b/libs/WindowManager/Shell/aconfig/multitasking.aconfig
index 63a288079401..cf0a975b6c30 100644
--- a/libs/WindowManager/Shell/aconfig/multitasking.aconfig
+++ b/libs/WindowManager/Shell/aconfig/multitasking.aconfig
@@ -156,6 +156,13 @@ flag {
}
flag {
+ name: "enable_flexible_two_app_split"
+ namespace: "multitasking"
+ description: "Enables only 2 app 90:10 split"
+ bug: "349828130"
+}
+
+flag {
name: "enable_flexible_split"
namespace: "multitasking"
description: "Enables flexibile split feature for split screen"
diff --git a/libs/WindowManager/Shell/res/drawable/app_handle_education_tooltip_icon.xml b/libs/WindowManager/Shell/res/drawable/app_handle_education_tooltip_icon.xml
new file mode 100644
index 000000000000..07e5ac1a604b
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/app_handle_education_tooltip_icon.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="?android:attr/textColorTertiary"
+ android:viewportHeight="960"
+ android:viewportWidth="960">
+ <path
+ android:fillColor="@android:color/system_on_tertiary_fixed"
+ android:pathData="M419,880Q391,880 366.5,868Q342,856 325,834L107,557L126,537Q146,516 174,512Q202,508 226,523L300,568L300,240Q300,223 311.5,211.5Q323,200 340,200Q357,200 369,211.5Q381,223 381,240L381,712L284,652L388,785Q394,792 402,796Q410,800 419,800L640,800Q673,800 696.5,776.5Q720,753 720,720L720,560Q720,543 708.5,531.5Q697,520 680,520L461,520L461,440L680,440Q730,440 765,475Q800,510 800,560L800,720Q800,786 753,833Q706,880 640,880L419,880ZM167,340Q154,318 147,292.5Q140,267 140,240Q140,157 198.5,98.5Q257,40 340,40Q423,40 481.5,98.5Q540,157 540,240Q540,267 533,292.5Q526,318 513,340L444,300Q452,286 456,271.5Q460,257 460,240Q460,190 425,155Q390,120 340,120Q290,120 255,155Q220,190 220,240Q220,257 224,271.5Q228,286 236,300L167,340ZM502,620L502,620L502,620L502,620Q502,620 502,620Q502,620 502,620L502,620Q502,620 502,620Q502,620 502,620L502,620Q502,620 502,620Q502,620 502,620L502,620L502,620Z" />
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_background.xml b/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_background.xml
new file mode 100644
index 000000000000..a12a74658953
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_background.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape android:shape="rectangle">
+ <corners android:radius="30dp" />
+ <solid android:color="@android:color/system_tertiary_fixed" />
+ </shape>
+ </item>
+</layer-list>
diff --git a/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_left_arrow.xml b/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_left_arrow.xml
new file mode 100644
index 000000000000..aadffb5a0003
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_left_arrow.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!-- An arrow that points towards left. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="10dp"
+ android:height="12dp"
+ android:viewportWidth="10"
+ android:viewportHeight="12">
+ <path
+ android:pathData="M2.858,4.285C1.564,5.062 1.564,6.938 2.858,7.715L10,12L10,0L2.858,4.285Z"
+ android:fillColor="@android:color/system_tertiary_fixed"/>
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_top_arrow.xml b/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_top_arrow.xml
new file mode 100644
index 000000000000..e3c9a662671e
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/desktop_windowing_education_tooltip_top_arrow.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ 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.
+ -->
+
+<!-- An arrow that points upwards. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="12dp"
+ android:height="9dp"
+ android:viewportWidth="12"
+ android:viewportHeight="9">
+ <path
+ android:pathData="M7.715,1.858C6.938,0.564 5.062,0.564 4.285,1.858L0,9L12,9L7.715,1.858Z"
+ android:fillColor="@android:color/system_tertiary_fixed"/>
+</vector>
diff --git a/libs/WindowManager/Shell/res/layout/desktop_windowing_education_left_arrow_tooltip.xml b/libs/WindowManager/Shell/res/layout/desktop_windowing_education_left_arrow_tooltip.xml
new file mode 100644
index 000000000000..a269b9ee1dd5
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/desktop_windowing_education_left_arrow_tooltip.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:elevation="1dp"
+ android:orientation="horizontal">
+
+ <!-- ImageView for the arrow icon, positioned horizontally at the start of the tooltip
+ container. -->
+ <ImageView
+ android:id="@+id/arrow_icon"
+ android:layout_width="10dp"
+ android:layout_height="12dp"
+ android:layout_gravity="center_vertical"
+ android:src="@drawable/desktop_windowing_education_tooltip_left_arrow" />
+
+ <!-- Layout for the tooltip, excluding the arrow. Separating the tooltip content from the arrow
+ allows scaling of only the tooltip container when the content changes, without affecting the
+ arrow. -->
+ <include layout="@layout/desktop_windowing_education_tooltip_container" />
+</LinearLayout>
diff --git a/libs/WindowManager/Shell/res/layout/desktop_windowing_education_tooltip_container.xml b/libs/WindowManager/Shell/res/layout/desktop_windowing_education_tooltip_container.xml
new file mode 100644
index 000000000000..bdee8836dc2e
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/desktop_windowing_education_tooltip_container.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/tooltip_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/desktop_windowing_education_tooltip_background"
+ android:orientation="horizontal"
+ android:padding="@dimen/desktop_windowing_education_tooltip_padding">
+
+ <ImageView
+ android:id="@+id/tooltip_icon"
+ android:layout_width="32dp"
+ android:layout_height="32dp"
+ android:layout_gravity="center_vertical"
+ android:src="@drawable/app_handle_education_tooltip_icon" />
+
+ <TextView
+ android:id="@+id/tooltip_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginStart="2dp"
+ android:lineHeight="20dp"
+ android:maxWidth="150dp"
+ android:textColor="@android:color/system_on_tertiary_fixed"
+ android:textFontWeight="500"
+ android:textSize="14sp" />
+</LinearLayout> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/layout/desktop_windowing_education_top_arrow_tooltip.xml b/libs/WindowManager/Shell/res/layout/desktop_windowing_education_top_arrow_tooltip.xml
new file mode 100644
index 000000000000..c73c1dad0e18
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/desktop_windowing_education_top_arrow_tooltip.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:elevation="1dp"
+ android:orientation="vertical">
+
+ <!-- ImageView for the arrow icon, positioned vertically above the tooltip container. -->
+ <ImageView
+ android:id="@+id/arrow_icon"
+ android:layout_width="12dp"
+ android:layout_height="9dp"
+ android:layout_gravity="center_horizontal"
+ android:src="@drawable/desktop_windowing_education_tooltip_top_arrow" />
+
+ <!-- Layout for the tooltip, excluding the arrow. Separating the tooltip content from the arrow
+ allows scaling of only the tooltip container when the content changes, without affecting the
+ arrow. -->
+ <include layout="@layout/desktop_windowing_education_tooltip_container" />
+</LinearLayout>
diff --git a/libs/WindowManager/Shell/res/layout/letterbox_restart_dialog_layout.xml b/libs/WindowManager/Shell/res/layout/letterbox_restart_dialog_layout.xml
index 045b975a854e..462a49ccb1eb 100644
--- a/libs/WindowManager/Shell/res/layout/letterbox_restart_dialog_layout.xml
+++ b/libs/WindowManager/Shell/res/layout/letterbox_restart_dialog_layout.xml
@@ -99,11 +99,11 @@
</LinearLayout>
- <FrameLayout
+
+ <LinearLayout
android:minHeight="@dimen/letterbox_restart_dialog_button_height"
- android:layout_width="match_parent"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- style="?android:attr/buttonBarButtonStyle"
android:layout_gravity="end">
<Button
@@ -133,7 +133,7 @@
android:text="@string/letterbox_restart_restart"
android:contentDescription="@string/letterbox_restart_restart"/>
- </FrameLayout>
+ </LinearLayout>
</LinearLayout>
diff --git a/libs/WindowManager/Shell/res/values/dimen.xml b/libs/WindowManager/Shell/res/values/dimen.xml
index 3d8718332199..c7109f5be132 100644
--- a/libs/WindowManager/Shell/res/values/dimen.xml
+++ b/libs/WindowManager/Shell/res/values/dimen.xml
@@ -608,6 +608,9 @@
<!-- The horizontal inset to apply to the close button's ripple drawable -->
<dimen name="desktop_mode_header_close_ripple_inset_horizontal">6dp</dimen>
+ <!-- The padding added to all sides of windowing education tooltip -->
+ <dimen name="desktop_windowing_education_tooltip_padding">8dp</dimen>
+
<!-- The acceptable area ratio of fg icon area/bg icon area, i.e. (72 x 72) / (108 x 108) -->
<item type="dimen" format="float" name="splash_icon_enlarge_foreground_threshold">0.44</item>
<!-- Scaling factor applied to splash icons without provided background i.e. (192 / 160) -->
diff --git a/libs/WindowManager/Shell/res/values/strings.xml b/libs/WindowManager/Shell/res/values/strings.xml
index bda56860d3ba..56f25dae3df2 100644
--- a/libs/WindowManager/Shell/res/values/strings.xml
+++ b/libs/WindowManager/Shell/res/values/strings.xml
@@ -219,6 +219,15 @@
compatibility control. [CHAR LIMIT=NONE] -->
<string name="camera_compat_dismiss_button_description">No camera issues? Tap to dismiss.</string>
+ <!-- App handle education tooltip text for tooltip pointing to app handle -->
+ <string name="windowing_app_handle_education_tooltip">Tap to open the app menu</string>
+
+ <!-- App handle education tooltip text for tooltip pointing to windowing image button -->
+ <string name="windowing_desktop_mode_image_button_education_tooltip">Tap to show multiple apps together</string>
+
+ <!-- App handle education tooltip text for tooltip pointing to app chip -->
+ <string name="windowing_desktop_mode_exit_education_tooltip">Return to fullscreen from the app menu</string>
+
<!-- The title of the letterbox education dialog. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_dialog_title">See and do more</string>
@@ -307,12 +316,11 @@
<!-- Maximize menu snap buttons string. -->
<string name="desktop_mode_maximize_menu_snap_text">Snap Screen</string>
<!-- Snap resizing non-resizable string. -->
- <string name="desktop_mode_non_resizable_snap_text">This app can\'t be resized</string>
+ <string name="desktop_mode_non_resizable_snap_text">App can\'t be moved here</string>
<!-- Accessibility text for the Maximize Menu's maximize button [CHAR LIMIT=NONE] -->
<string name="desktop_mode_maximize_menu_maximize_button_text">Maximize</string>
<!-- Accessibility text for the Maximize Menu's snap left button [CHAR LIMIT=NONE] -->
<string name="desktop_mode_maximize_menu_snap_left_button_text">Snap left</string>
<!-- Accessibility text for the Maximize Menu's snap right button [CHAR LIMIT=NONE] -->
<string name="desktop_mode_maximize_menu_snap_right_button_text">Snap right</string>
-
</resources>
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/FocusTransitionListener.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/FocusTransitionListener.java
new file mode 100644
index 000000000000..26aae2d2aa78
--- /dev/null
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/FocusTransitionListener.java
@@ -0,0 +1,30 @@
+/*
+ * 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.wm.shell.shared;
+
+import com.android.wm.shell.shared.annotations.ExternalThread;
+
+/**
+ * Listener to get focus-related transition callbacks.
+ */
+@ExternalThread
+public interface FocusTransitionListener {
+ /**
+ * Called when a transition changes the top, focused display.
+ */
+ void onFocusedDisplayChanged(int displayId);
+}
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IFocusTransitionListener.aidl b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IFocusTransitionListener.aidl
new file mode 100644
index 000000000000..b91d5b6e2769
--- /dev/null
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IFocusTransitionListener.aidl
@@ -0,0 +1,28 @@
+/*
+ * 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.wm.shell.shared;
+
+/**
+ * Listener interface that to get focus-related transition callbacks.
+ */
+oneway interface IFocusTransitionListener {
+
+ /**
+ * Called when a transition changes the top, focused display.
+ */
+ void onFocusedDisplayChanged(int displayId);
+}
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IShellTransitions.aidl b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IShellTransitions.aidl
index 3256abf09116..02615a96a86c 100644
--- a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IShellTransitions.aidl
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/IShellTransitions.aidl
@@ -20,6 +20,7 @@ import android.view.SurfaceControl;
import android.window.RemoteTransition;
import android.window.TransitionFilter;
+import com.android.wm.shell.shared.IFocusTransitionListener;
import com.android.wm.shell.shared.IHomeTransitionListener;
/**
@@ -59,4 +60,9 @@ interface IShellTransitions {
*/
oneway void registerRemoteForTakeover(in TransitionFilter filter,
in RemoteTransition remoteTransition) = 6;
+
+ /**
+ * Set listener that will receive callbacks about transitions involving focus switch.
+ */
+ oneway void setFocusTransitionListener(in IFocusTransitionListener listener) = 7;
}
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/ShellTransitions.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/ShellTransitions.java
index 6d4ab4c1bd09..2db4311fb771 100644
--- a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/ShellTransitions.java
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/ShellTransitions.java
@@ -22,6 +22,8 @@ import android.window.TransitionFilter;
import com.android.wm.shell.shared.annotations.ExternalThread;
+import java.util.concurrent.Executor;
+
/**
* Interface to manage remote transitions.
*/
@@ -44,4 +46,15 @@ public interface ShellTransitions {
* Unregisters a remote transition for all operations.
*/
default void unregisterRemote(@NonNull RemoteTransition remoteTransition) {}
+
+ /**
+ * Sets listener that will receive callbacks about transitions involving focus switch.
+ */
+ default void setFocusTransitionListener(@NonNull FocusTransitionListener listener,
+ Executor executor) {}
+
+ /**
+ * Unsets listener that will receive callbacks about transitions involving focus switch.
+ */
+ default void unsetFocusTransitionListener(@NonNull FocusTransitionListener listener) {}
}
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/split/OWNERS b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/split/OWNERS
new file mode 100644
index 000000000000..bfb6d4ac5849
--- /dev/null
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/split/OWNERS
@@ -0,0 +1,4 @@
+jeremysim@google.com
+winsonc@google.com
+peanutbutter@google.com
+shuminghao@google.com
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
index bec2ea58e106..4227a6e2903f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
@@ -123,6 +123,7 @@ import com.android.wm.shell.sysui.ShellInterface;
import com.android.wm.shell.taskview.TaskViewFactory;
import com.android.wm.shell.taskview.TaskViewFactoryController;
import com.android.wm.shell.taskview.TaskViewTransitions;
+import com.android.wm.shell.transition.FocusTransitionObserver;
import com.android.wm.shell.transition.HomeTransitionObserver;
import com.android.wm.shell.transition.MixedTransitionHandler;
import com.android.wm.shell.transition.Transitions;
@@ -742,14 +743,15 @@ public abstract class WMShellBaseModule {
@ShellMainThread Handler mainHandler,
@ShellAnimationThread ShellExecutor animExecutor,
RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
- HomeTransitionObserver homeTransitionObserver) {
+ HomeTransitionObserver homeTransitionObserver,
+ FocusTransitionObserver focusTransitionObserver) {
if (!context.getResources().getBoolean(R.bool.config_registerShellTransitionsOnInit)) {
// TODO(b/238217847): Force override shell init if registration is disabled
shellInit = new ShellInit(mainExecutor);
}
return new Transitions(context, shellInit, shellCommandHandler, shellController, organizer,
pool, displayController, mainExecutor, mainHandler, animExecutor,
- rootTaskDisplayAreaOrganizer, homeTransitionObserver);
+ rootTaskDisplayAreaOrganizer, homeTransitionObserver, focusTransitionObserver);
}
@WMSingleton
@@ -761,6 +763,12 @@ public abstract class WMShellBaseModule {
@WMSingleton
@Provides
+ static FocusTransitionObserver provideFocusTransitionObserver() {
+ return new FocusTransitionObserver();
+ }
+
+ @WMSingleton
+ @Provides
static TaskViewTransitions provideTaskViewTransitions(Transitions transitions) {
return new TaskViewTransitions(transitions);
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt
index 759ed035895e..0e8c4e70e05d 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt
@@ -456,6 +456,7 @@ class DesktopModeTaskRepository (
pw.println(
"${innerPrefix}freeformTasksInZOrder=${data.freeformTasksInZOrder.toDumpString()}"
)
+ pw.println("${innerPrefix}minimizedTasks=${data.minimizedTasks.toDumpString()}")
}
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index 968f40c3df5d..afa27f9f1309 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -43,6 +43,7 @@ import android.view.Display.DEFAULT_DISPLAY
import android.view.DragEvent
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
+import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_NONE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_FRONT
@@ -1061,7 +1062,10 @@ class DesktopTasksController(
// Check if freeform task launch during recents should be handled
shouldHandleMidRecentsFreeformLaunch -> handleMidRecentsFreeformTaskLaunch(task)
// Check if the closing task needs to be handled
- TransitionUtil.isClosingType(request.type) -> handleTaskClosing(task)
+ TransitionUtil.isClosingType(request.type) -> handleTaskClosing(
+ task,
+ request.type
+ )
// Check if the top task shouldn't be allowed to enter desktop mode
isIncompatibleTask(task) -> handleIncompatibleTaskLaunch(task)
// Check if fullscreen task should be updated
@@ -1288,7 +1292,10 @@ class DesktopTasksController(
}
/** Handle task closing by removing wallpaper activity if it's the last active task */
- private fun handleTaskClosing(task: RunningTaskInfo): WindowContainerTransaction? {
+ private fun handleTaskClosing(
+ task: RunningTaskInfo,
+ transitionType: Int
+ ): WindowContainerTransaction? {
logV("handleTaskClosing")
if (!isDesktopModeShowing(task.displayId))
return null
@@ -1301,9 +1308,10 @@ class DesktopTasksController(
removeWallpaperActivity(wct)
}
taskRepository.addClosingTask(task.displayId, task.taskId)
- // If a CLOSE or TO_BACK is triggered on a desktop task, remove the task.
+ // If a CLOSE is triggered on a desktop task, remove the task.
if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue() &&
- taskRepository.isVisibleTask(task.taskId)
+ taskRepository.isVisibleTask(task.taskId) &&
+ transitionType == TRANSIT_CLOSE
) {
wct.removeTask(task.token)
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
index 0841628853a3..4796c4d0655a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
@@ -16,16 +16,19 @@
package com.android.wm.shell.desktopmode
+import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.content.Context
import android.os.IBinder
import android.view.SurfaceControl
import android.view.WindowManager
+import android.view.WindowManager.TRANSIT_TO_BACK
import android.window.TransitionInfo
import android.window.WindowContainerTransaction
+import android.window.flags.DesktopModeFlags
+import android.window.flags.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
-import android.window.flags.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
@@ -64,6 +67,30 @@ class DesktopTasksTransitionObserver(
) {
// TODO: b/332682201 Update repository state
updateWallpaperToken(info)
+
+ if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) {
+ handleBackNavigation(info)
+ }
+ }
+
+ private fun handleBackNavigation(info: TransitionInfo) {
+ // When default back navigation happens, transition type is TO_BACK and the change is
+ // TO_BACK. Mark the task going to back as minimized.
+ if (info.type == TRANSIT_TO_BACK) {
+ for (change in info.changes) {
+ val taskInfo = change.taskInfo
+ if (taskInfo == null || taskInfo.taskId == -1) {
+ continue
+ }
+
+ if (desktopModeTaskRepository.getVisibleTaskCount(taskInfo.displayId) > 0 &&
+ change.mode == TRANSIT_TO_BACK &&
+ taskInfo.windowingMode == WINDOWING_MODE_FREEFORM
+ ) {
+ desktopModeTaskRepository.minimizeTask(taskInfo.displayId, taskInfo.taskId)
+ }
+ }
+ }
}
override fun onTransitionStarting(transition: IBinder) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
index 2138acc51eb2..cbb08b804dfe 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
@@ -1344,6 +1344,9 @@ public class PipTransition extends PipTransitionController {
final SurfaceControl leash = pipChange.getLeash();
final Rect destBounds = mPipOrganizer.getCurrentOrAnimatingBounds();
final boolean isInPip = mPipTransitionState.isInPip();
+ ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+ "%s: Update pip for unhandled transition, change=%s, destBounds=%s, isInPip=%b",
+ TAG, pipChange, destBounds, isInPip);
mSurfaceTransactionHelper
.crop(startTransaction, leash, destBounds)
.round(startTransaction, leash, isInPip)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/FocusTransitionObserver.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/FocusTransitionObserver.java
new file mode 100644
index 000000000000..2f5059f3161c
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/FocusTransitionObserver.java
@@ -0,0 +1,142 @@
+/*
+ * 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.wm.shell.transition;
+
+import static android.view.Display.INVALID_DISPLAY;
+import static android.window.TransitionInfo.FLAG_MOVED_TO_TOP;
+
+import static com.android.window.flags.Flags.enableDisplayFocusInShellTransitions;
+import static com.android.wm.shell.transition.Transitions.TransitionObserver;
+
+import android.annotation.NonNull;
+import android.app.ActivityManager.RunningTaskInfo;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Slog;
+import android.view.SurfaceControl;
+import android.window.TransitionInfo;
+
+import com.android.wm.shell.shared.FocusTransitionListener;
+import com.android.wm.shell.shared.IFocusTransitionListener;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executor;
+
+/**
+ * The {@link TransitionObserver} that observes for transitions involving focus switch.
+ * It reports transitions to callers outside of the process via {@link IFocusTransitionListener},
+ * and callers within the process via {@link FocusTransitionListener}.
+ */
+public class FocusTransitionObserver implements TransitionObserver {
+ private static final String TAG = FocusTransitionObserver.class.getSimpleName();
+
+ private IFocusTransitionListener mRemoteListener;
+ private final Map<FocusTransitionListener, Executor> mLocalListeners =
+ new HashMap<>();
+
+ private int mFocusedDisplayId = INVALID_DISPLAY;
+
+ public FocusTransitionObserver() {}
+
+ @Override
+ public void onTransitionReady(@NonNull IBinder transition,
+ @NonNull TransitionInfo info,
+ @NonNull SurfaceControl.Transaction startTransaction,
+ @NonNull SurfaceControl.Transaction finishTransaction) {
+ final List<TransitionInfo.Change> changes = info.getChanges();
+ for (int i = changes.size() - 1; i >= 0; i--) {
+ final TransitionInfo.Change change = changes.get(i);
+ final RunningTaskInfo task = change.getTaskInfo();
+ if (task != null && task.isFocused && change.hasFlags(FLAG_MOVED_TO_TOP)) {
+ if (mFocusedDisplayId != task.displayId) {
+ mFocusedDisplayId = task.displayId;
+ notifyFocusedDisplayChanged();
+ }
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void onTransitionStarting(@NonNull IBinder transition) {}
+
+ @Override
+ public void onTransitionMerged(@NonNull IBinder merged, @NonNull IBinder playing) {}
+
+ @Override
+ public void onTransitionFinished(@NonNull IBinder transition, boolean aborted) {}
+
+ /**
+ * Sets the focus transition listener that receives any transitions resulting in focus switch.
+ * This is for calls from outside the Shell, within the host process.
+ *
+ */
+ public void setLocalFocusTransitionListener(FocusTransitionListener listener,
+ Executor executor) {
+ if (!enableDisplayFocusInShellTransitions()) {
+ return;
+ }
+ mLocalListeners.put(listener, executor);
+ executor.execute(() -> listener.onFocusedDisplayChanged(mFocusedDisplayId));
+ }
+
+ /**
+ * Sets the focus transition listener that receives any transitions resulting in focus switch.
+ * This is for calls from outside the Shell, within the host process.
+ *
+ */
+ public void unsetLocalFocusTransitionListener(FocusTransitionListener listener) {
+ if (!enableDisplayFocusInShellTransitions()) {
+ return;
+ }
+ mLocalListeners.remove(listener);
+ }
+
+ /**
+ * Sets the focus transition listener that receives any transitions resulting in focus switch.
+ * This is for calls from outside the host process.
+ */
+ public void setRemoteFocusTransitionListener(Transitions transitions,
+ IFocusTransitionListener listener) {
+ if (!enableDisplayFocusInShellTransitions()) {
+ return;
+ }
+ mRemoteListener = listener;
+ notifyFocusedDisplayChangedToRemote();
+ }
+
+ /**
+ * Notifies the listener that display focus has changed.
+ */
+ public void notifyFocusedDisplayChanged() {
+ notifyFocusedDisplayChangedToRemote();
+ mLocalListeners.forEach((listener, executor) ->
+ executor.execute(() -> listener.onFocusedDisplayChanged(mFocusedDisplayId)));
+ }
+
+ private void notifyFocusedDisplayChangedToRemote() {
+ if (mRemoteListener != null) {
+ try {
+ mRemoteListener.onFocusedDisplayChanged(mFocusedDisplayId);
+ } catch (RemoteException e) {
+ Slog.w(TAG, "Failed call notifyFocusedDisplayChangedToRemote", e);
+ }
+ }
+ }
+}
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 d03832d3e85e..d280dcd252b4 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
@@ -87,6 +87,8 @@ import com.android.wm.shell.common.RemoteCallable;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.keyguard.KeyguardTransitionHandler;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
+import com.android.wm.shell.shared.FocusTransitionListener;
+import com.android.wm.shell.shared.IFocusTransitionListener;
import com.android.wm.shell.shared.IHomeTransitionListener;
import com.android.wm.shell.shared.IShellTransitions;
import com.android.wm.shell.shared.ShellTransitions;
@@ -103,6 +105,7 @@ import com.android.wm.shell.transition.tracing.TransitionTracer;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.concurrent.Executor;
/**
* Plays transition animations. Within this player, each transition has a lifecycle.
@@ -224,6 +227,7 @@ public class Transitions implements RemoteCallable<Transitions>,
private final ArrayList<TransitionObserver> mObservers = new ArrayList<>();
private HomeTransitionObserver mHomeTransitionObserver;
+ private FocusTransitionObserver mFocusTransitionObserver;
/** List of {@link Runnable} instances to run when the last active transition has finished. */
private final ArrayList<Runnable> mRunWhenIdleQueue = new ArrayList<>();
@@ -309,10 +313,12 @@ public class Transitions implements RemoteCallable<Transitions>,
@NonNull ShellExecutor mainExecutor,
@NonNull Handler mainHandler,
@NonNull ShellExecutor animExecutor,
- @NonNull HomeTransitionObserver observer) {
+ @NonNull HomeTransitionObserver homeTransitionObserver,
+ @NonNull FocusTransitionObserver focusTransitionObserver) {
this(context, shellInit, new ShellCommandHandler(), shellController, organizer, pool,
displayController, mainExecutor, mainHandler, animExecutor,
- new RootTaskDisplayAreaOrganizer(mainExecutor, context, shellInit), observer);
+ new RootTaskDisplayAreaOrganizer(mainExecutor, context, shellInit),
+ homeTransitionObserver, focusTransitionObserver);
}
public Transitions(@NonNull Context context,
@@ -326,7 +332,8 @@ public class Transitions implements RemoteCallable<Transitions>,
@NonNull Handler mainHandler,
@NonNull ShellExecutor animExecutor,
@NonNull RootTaskDisplayAreaOrganizer rootTDAOrganizer,
- @NonNull HomeTransitionObserver observer) {
+ @NonNull HomeTransitionObserver homeTransitionObserver,
+ @NonNull FocusTransitionObserver focusTransitionObserver) {
mOrganizer = organizer;
mContext = context;
mMainExecutor = mainExecutor;
@@ -345,7 +352,8 @@ public class Transitions implements RemoteCallable<Transitions>,
mHandlers.add(mRemoteTransitionHandler);
ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, "addHandler: Remote");
shellInit.addInitCallback(this::onInit, this);
- mHomeTransitionObserver = observer;
+ mHomeTransitionObserver = homeTransitionObserver;
+ mFocusTransitionObserver = focusTransitionObserver;
if (android.tracing.Flags.perfettoTransitionTracing()) {
mTransitionTracer = new PerfettoTransitionTracer();
@@ -384,6 +392,8 @@ public class Transitions implements RemoteCallable<Transitions>,
mShellCommandHandler.addCommandCallback("transitions", this, this);
mShellCommandHandler.addDumpCallback(this::dump, this);
+
+ registerObserver(mFocusTransitionObserver);
}
public boolean isRegistered() {
@@ -1573,6 +1583,21 @@ public class Transitions implements RemoteCallable<Transitions>,
mMainExecutor.execute(
() -> mRemoteTransitionHandler.removeFiltered(remoteTransition));
}
+
+ @Override
+ public void setFocusTransitionListener(FocusTransitionListener listener,
+ Executor executor) {
+ mMainExecutor.execute(() ->
+ mFocusTransitionObserver.setLocalFocusTransitionListener(listener, executor));
+
+ }
+
+ @Override
+ public void unsetFocusTransitionListener(FocusTransitionListener listener) {
+ mMainExecutor.execute(() ->
+ mFocusTransitionObserver.unsetLocalFocusTransitionListener(listener));
+
+ }
}
/**
@@ -1634,6 +1659,15 @@ public class Transitions implements RemoteCallable<Transitions>,
}
@Override
+ public void setFocusTransitionListener(IFocusTransitionListener listener) {
+ executeRemoteCallWithTaskPermission(mTransitions, "setFocusTransitionListener",
+ (transitions) -> {
+ transitions.mFocusTransitionObserver.setRemoteFocusTransitionListener(
+ transitions, listener);
+ });
+ }
+
+ @Override
public SurfaceControl getHomeTaskOverlayContainer() {
SurfaceControl[] result = new SurfaceControl[1];
executeRemoteCallWithTaskPermission(mTransitions, "getHomeTaskOverlayContainer",
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/additionalviewcontainer/AdditionalSystemViewContainer.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/additionalviewcontainer/AdditionalSystemViewContainer.kt
index 226b0fb2e1a1..1be26f080ac8 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/additionalviewcontainer/AdditionalSystemViewContainer.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/additionalviewcontainer/AdditionalSystemViewContainer.kt
@@ -107,4 +107,27 @@ class AdditionalSystemViewContainer(
}
windowManagerWrapper.updateViewLayout(view, lp)
}
+
+ class Factory {
+ fun create(
+ windowManagerWrapper: WindowManagerWrapper,
+ taskId: Int,
+ x: Int,
+ y: Int,
+ width: Int,
+ height: Int,
+ flags: Int,
+ view: View,
+ ): AdditionalSystemViewContainer =
+ AdditionalSystemViewContainer(
+ windowManagerWrapper = windowManagerWrapper,
+ taskId = taskId,
+ x = x,
+ y = y,
+ width = width,
+ height = height,
+ flags = flags,
+ view = view
+ )
+ }
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipController.kt
new file mode 100644
index 000000000000..98413ee96133
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipController.kt
@@ -0,0 +1,249 @@
+/*
+ * 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.wm.shell.windowdecor.education
+
+import android.annotation.DimenRes
+import android.annotation.LayoutRes
+import android.content.Context
+import android.content.res.Resources
+import android.graphics.Point
+import android.util.Size
+import android.view.LayoutInflater
+import android.view.MotionEvent
+import android.view.View
+import android.view.View.MeasureSpec.UNSPECIFIED
+import android.view.WindowManager
+import android.widget.ImageView
+import android.widget.LinearLayout
+import android.widget.TextView
+import androidx.dynamicanimation.animation.DynamicAnimation
+import androidx.dynamicanimation.animation.SpringForce
+import com.android.wm.shell.R
+import com.android.wm.shell.shared.animation.PhysicsAnimator
+import com.android.wm.shell.windowdecor.WindowManagerWrapper
+import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalSystemViewContainer
+
+/**
+ * Controls the lifecycle of an education tooltip, including showing and hiding it. Ensures that
+ * only one tooltip is displayed at a time.
+ */
+class DesktopWindowingEducationTooltipController(
+ private val context: Context,
+ private val additionalSystemViewContainerFactory: AdditionalSystemViewContainer.Factory,
+) {
+ // TODO: b/369384567 - Set tooltip color scheme to match LT/DT of app theme
+ private var tooltipView: View? = null
+ private var animator: PhysicsAnimator<View>? = null
+ private val springConfig by lazy {
+ PhysicsAnimator.SpringConfig(SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_LOW_BOUNCY)
+ }
+ private var popupWindow: AdditionalSystemViewContainer? = null
+
+ /**
+ * Shows education tooltip.
+ *
+ * @param tooltipViewConfig features of tooltip.
+ * @param taskId is used in the title of popup window created for the tooltip view.
+ */
+ fun showEducationTooltip(tooltipViewConfig: EducationViewConfig, taskId: Int) {
+ hideEducationTooltip()
+ tooltipView = createEducationTooltipView(tooltipViewConfig, taskId)
+ animator = createAnimator()
+ animateShowTooltipTransition()
+ }
+
+ /** Hide the current education view if visible */
+ private fun hideEducationTooltip() = animateHideTooltipTransition { cleanUp() }
+
+ /** Create education view by inflating layout provided. */
+ private fun createEducationTooltipView(
+ tooltipViewConfig: EducationViewConfig,
+ taskId: Int,
+ ): View {
+ val tooltipView =
+ LayoutInflater.from(context)
+ .inflate(
+ tooltipViewConfig.tooltipViewLayout, /* root= */ null, /* attachToRoot= */ false)
+ .apply {
+ alpha = 0f
+ scaleX = 0f
+ scaleY = 0f
+
+ requireViewById<TextView>(R.id.tooltip_text).apply {
+ text = tooltipViewConfig.tooltipText
+ }
+
+ setOnTouchListener { _, motionEvent ->
+ if (motionEvent.action == MotionEvent.ACTION_OUTSIDE) {
+ hideEducationTooltip()
+ tooltipViewConfig.onDismissAction()
+ true
+ } else {
+ false
+ }
+ }
+ setOnClickListener {
+ hideEducationTooltip()
+ tooltipViewConfig.onEducationClickAction()
+ }
+ }
+
+ val tooltipDimens = tooltipDimens(tooltipView = tooltipView, tooltipViewConfig.arrowDirection)
+ val tooltipViewGlobalCoordinates =
+ tooltipViewGlobalCoordinates(
+ tooltipViewGlobalCoordinates = tooltipViewConfig.tooltipViewGlobalCoordinates,
+ arrowDirection = tooltipViewConfig.arrowDirection,
+ tooltipDimen = tooltipDimens)
+ createTooltipPopupWindow(
+ taskId, tooltipViewGlobalCoordinates, tooltipDimens, tooltipView = tooltipView)
+
+ return tooltipView
+ }
+
+ /** Create animator for education transitions */
+ private fun createAnimator(): PhysicsAnimator<View>? =
+ tooltipView?.let {
+ PhysicsAnimator.getInstance(it).apply { setDefaultSpringConfig(springConfig) }
+ }
+
+ /** Animate show transition for the education view */
+ private fun animateShowTooltipTransition() {
+ animator
+ ?.spring(DynamicAnimation.ALPHA, 1f)
+ ?.spring(DynamicAnimation.SCALE_X, 1f)
+ ?.spring(DynamicAnimation.SCALE_Y, 1f)
+ ?.start()
+ }
+
+ /** Animate hide transition for the education view */
+ private fun animateHideTooltipTransition(endActions: () -> Unit) {
+ animator
+ ?.spring(DynamicAnimation.ALPHA, 0f)
+ ?.spring(DynamicAnimation.SCALE_X, 0f)
+ ?.spring(DynamicAnimation.SCALE_Y, 0f)
+ ?.start()
+ endActions()
+ }
+
+ /** Remove education tooltip and clean up all relative properties */
+ private fun cleanUp() {
+ tooltipView = null
+ animator = null
+ popupWindow?.releaseView()
+ popupWindow = null
+ }
+
+ private fun createTooltipPopupWindow(
+ taskId: Int,
+ tooltipViewGlobalCoordinates: Point,
+ tooltipDimen: Size,
+ tooltipView: View,
+ ) {
+ popupWindow =
+ additionalSystemViewContainerFactory.create(
+ windowManagerWrapper =
+ WindowManagerWrapper(context.getSystemService(WindowManager::class.java)),
+ taskId = taskId,
+ x = tooltipViewGlobalCoordinates.x,
+ y = tooltipViewGlobalCoordinates.y,
+ width = tooltipDimen.width,
+ height = tooltipDimen.height,
+ flags =
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
+ WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
+ view = tooltipView)
+ }
+
+ private fun tooltipViewGlobalCoordinates(
+ tooltipViewGlobalCoordinates: Point,
+ arrowDirection: TooltipArrowDirection,
+ tooltipDimen: Size,
+ ): Point {
+ var tooltipX = tooltipViewGlobalCoordinates.x
+ var tooltipY = tooltipViewGlobalCoordinates.y
+
+ // Current values of [tooltipX]/[tooltipY] are the coordinates of tip of the arrow.
+ // Parameter x and y passed to [AdditionalSystemViewContainer] is the top left position of
+ // the window to be created. Hence we will need to move the coordinates left/up in order
+ // to position the tooltip correctly.
+ if (arrowDirection == TooltipArrowDirection.UP) {
+ // Arrow is placed at horizontal center on top edge of the tooltip. Hence decrement
+ // half of tooltip width from [tooltipX] to horizontally position the tooltip.
+ tooltipX -= tooltipDimen.width / 2
+ } else {
+ // Arrow is placed at vertical center on the left edge of the tooltip. Hence decrement
+ // half of tooltip height from [tooltipY] to vertically position the tooltip.
+ tooltipY -= tooltipDimen.height / 2
+ }
+ return Point(tooltipX, tooltipY)
+ }
+
+ private fun tooltipDimens(tooltipView: View, arrowDirection: TooltipArrowDirection): Size {
+ val tooltipBackground = tooltipView.requireViewById<LinearLayout>(R.id.tooltip_container)
+ val arrowView = tooltipView.requireViewById<ImageView>(R.id.arrow_icon)
+ tooltipBackground.measure(
+ /* widthMeasureSpec= */ UNSPECIFIED, /* heightMeasureSpec= */ UNSPECIFIED)
+ arrowView.measure(/* widthMeasureSpec= */ UNSPECIFIED, /* heightMeasureSpec= */ UNSPECIFIED)
+
+ var desiredWidth =
+ tooltipBackground.measuredWidth +
+ 2 * loadDimensionPixelSize(R.dimen.desktop_windowing_education_tooltip_padding)
+ var desiredHeight =
+ tooltipBackground.measuredHeight +
+ 2 * loadDimensionPixelSize(R.dimen.desktop_windowing_education_tooltip_padding)
+ if (arrowDirection == TooltipArrowDirection.UP) {
+ // desiredHeight currently does not account for the height of arrow, hence adding it.
+ desiredHeight += arrowView.height
+ } else {
+ // desiredWidth currently does not account for the width of arrow, hence adding it.
+ desiredWidth += arrowView.width
+ }
+
+ return Size(desiredWidth, desiredHeight)
+ }
+
+ private fun loadDimensionPixelSize(@DimenRes resourceId: Int): Int {
+ if (resourceId == Resources.ID_NULL) return 0
+ return context.resources.getDimensionPixelSize(resourceId)
+ }
+
+ /**
+ * The configuration for education view features:
+ *
+ * @property tooltipViewLayout Layout resource ID of the view to be used for education tooltip.
+ * @property tooltipViewGlobalCoordinates Global (screen) coordinates of the tip of the tooltip
+ * arrow.
+ * @property tooltipText Text to be added to the TextView of tooltip.
+ * @property arrowDirection Direction of arrow of the tooltip.
+ * @property onEducationClickAction Lambda to be executed when the tooltip is clicked.
+ * @property onDismissAction Lambda to be executed when the tooltip is dismissed.
+ */
+ data class EducationViewConfig(
+ @LayoutRes val tooltipViewLayout: Int,
+ val tooltipViewGlobalCoordinates: Point,
+ val tooltipText: String,
+ val arrowDirection: TooltipArrowDirection,
+ val onEducationClickAction: () -> Unit,
+ val onDismissAction: () -> Unit,
+ )
+
+ /** Direction of arrow of the tooltip */
+ enum class TooltipArrowDirection {
+ UP,
+ LEFT,
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
index ee545209904f..94e361659090 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
@@ -40,6 +40,7 @@ import android.graphics.Point
import android.graphics.PointF
import android.graphics.Rect
import android.os.Binder
+import android.os.Bundle
import android.os.Handler
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
@@ -2086,16 +2087,13 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
- @EnableFlags(
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION
- )
- fun handleRequest_backTransition_singleTaskNoToken_withWallpaper_withBackNav_removesTask() {
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,)
+ fun handleRequest_backTransition_singleTaskNoToken_withWallpaper_removesTask() {
val task = setUpFreeformTask()
val result = controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_TO_BACK))
- assertNotNull(result, "Should handle request").assertRemoveAt(0, task.token)
+ assertNull(result, "Should not handle request")
}
@Test
@@ -2137,26 +2135,8 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
- @EnableFlags(
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION
- )
- fun handleRequest_backTransition_singleTask_withWallpaper_withBackNav_removesWallpaperAndTask() {
- val task = setUpFreeformTask()
- val wallpaperToken = MockToken().token()
-
- taskRepository.wallpaperActivityToken = wallpaperToken
- val result = controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_TO_BACK))
-
- // Should create remove wallpaper transaction
- assertNotNull(result, "Should handle request").assertRemoveAt(index = 0, wallpaperToken)
- result.assertRemoveAt(index = 1, task.token)
- }
-
- @Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
- fun handleRequest_backTransition_singleTaskWithToken_noBackNav_removesWallpaper() {
+ fun handleRequest_backTransition_singleTaskWithToken_removesWallpaper() {
val task = setUpFreeformTask()
val wallpaperToken = MockToken().token()
@@ -2183,23 +2163,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
- @EnableFlags(
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION
- )
- fun handleRequest_backTransition_multipleTasks_withWallpaper_withBackNav_removesTask() {
- val task1 = setUpFreeformTask()
- setUpFreeformTask()
-
- taskRepository.wallpaperActivityToken = MockToken().token()
- val result = controller.handleRequest(Binder(), createTransition(task1, type = TRANSIT_TO_BACK))
-
- assertNotNull(result, "Should handle request").assertRemoveAt(index = 0, task1.token)
- }
-
- @Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
fun handleRequest_backTransition_multipleTasks_noBackNav_doesNotHandle() {
val task1 = setUpFreeformTask()
setUpFreeformTask()
@@ -2226,29 +2190,11 @@ class DesktopTasksControllerTest : ShellTestCase() {
// Should create remove wallpaper transaction
assertNotNull(result, "Should handle request").assertRemoveAt(index = 0, wallpaperToken)
- result.assertRemoveAt(index = 1, task1.token)
- }
-
- @Test
- @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
- fun handleRequest_backTransition_multipleTasksSingleNonClosing_noBackNav_removesWallpaper() {
- val task1 = setUpFreeformTask(displayId = DEFAULT_DISPLAY)
- val task2 = setUpFreeformTask(displayId = DEFAULT_DISPLAY)
- val wallpaperToken = MockToken().token()
-
- taskRepository.wallpaperActivityToken = wallpaperToken
- taskRepository.addClosingTask(displayId = DEFAULT_DISPLAY, taskId = task2.taskId)
- val result = controller.handleRequest(Binder(), createTransition(task1, type = TRANSIT_TO_BACK))
-
- // Should create remove wallpaper transaction
- assertNotNull(result, "Should handle request").assertRemoveAt(index = 0, wallpaperToken)
}
@Test
@EnableFlags(
Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
- Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION
)
fun handleRequest_backTransition_multipleTasksSingleNonMinimized_removesWallpaperAndTask() {
val task1 = setUpFreeformTask(displayId = DEFAULT_DISPLAY)
@@ -2261,23 +2207,6 @@ class DesktopTasksControllerTest : ShellTestCase() {
// Should create remove wallpaper transaction
assertNotNull(result, "Should handle request").assertRemoveAt(index = 0, wallpaperToken)
- result.assertRemoveAt(index = 1, task1.token)
- }
-
- @Test
- @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
- fun handleRequest_backTransition_multipleTasksSingleNonMinimized_noBackNav_removesWallpaper() {
- val task1 = setUpFreeformTask(displayId = DEFAULT_DISPLAY)
- val task2 = setUpFreeformTask(displayId = DEFAULT_DISPLAY)
- val wallpaperToken = MockToken().token()
-
- taskRepository.wallpaperActivityToken = wallpaperToken
- taskRepository.minimizeTask(displayId = DEFAULT_DISPLAY, taskId = task2.taskId)
- val result = controller.handleRequest(Binder(), createTransition(task1, type = TRANSIT_TO_BACK))
-
- // Should create remove wallpaper transaction
- assertNotNull(result, "Should handle request").assertRemoveAt(index = 0, wallpaperToken)
}
@Test
@@ -2937,6 +2866,108 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
+ fun newWindow_fromFullscreenOpensInSplit() {
+ setUpLandscapeDisplay()
+ val task = setUpFullscreenTask()
+ val optionsCaptor = ArgumentCaptor.forClass(Bundle::class.java)
+ runOpenNewWindow(task)
+ verify(splitScreenController)
+ .startIntent(any(), anyInt(), any(), any(),
+ optionsCaptor.capture(), anyOrNull())
+ assertThat(ActivityOptions.fromBundle(optionsCaptor.value).launchWindowingMode)
+ .isEqualTo(WINDOWING_MODE_MULTI_WINDOW)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
+ fun newWindow_fromSplitOpensInSplit() {
+ setUpLandscapeDisplay()
+ val task = setUpSplitScreenTask()
+ val optionsCaptor = ArgumentCaptor.forClass(Bundle::class.java)
+ runOpenNewWindow(task)
+ verify(splitScreenController)
+ .startIntent(
+ any(), anyInt(), any(), any(),
+ optionsCaptor.capture(), anyOrNull()
+ )
+ assertThat(ActivityOptions.fromBundle(optionsCaptor.value).launchWindowingMode)
+ .isEqualTo(WINDOWING_MODE_MULTI_WINDOW)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
+ fun newWindow_fromFreeformAddsNewWindow() {
+ setUpLandscapeDisplay()
+ val task = setUpFreeformTask()
+ val wctCaptor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ runOpenNewWindow(task)
+ verify(transitions).startTransition(anyInt(), wctCaptor.capture(), anyOrNull())
+ assertThat(ActivityOptions.fromBundle(wctCaptor.value.hierarchyOps[0].launchOptions)
+ .launchWindowingMode).isEqualTo(WINDOWING_MODE_FREEFORM)
+ }
+
+ private fun runOpenNewWindow(task: RunningTaskInfo) {
+ markTaskVisible(task)
+ task.baseActivity = mock(ComponentName::class.java)
+ task.isFocused = true
+ runningTasks.add(task)
+ controller.openNewWindow(task)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
+ fun openInstance_fromFullscreenOpensInSplit() {
+ setUpLandscapeDisplay()
+ val task = setUpFullscreenTask()
+ val taskToRequest = setUpFreeformTask()
+ val optionsCaptor = ArgumentCaptor.forClass(Bundle::class.java)
+ runOpenInstance(task, taskToRequest.taskId)
+ verify(splitScreenController)
+ .startTask(anyInt(), anyInt(), optionsCaptor.capture(), anyOrNull())
+ assertThat(ActivityOptions.fromBundle(optionsCaptor.value).launchWindowingMode)
+ .isEqualTo(WINDOWING_MODE_MULTI_WINDOW)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
+ fun openInstance_fromSplitOpensInSplit() {
+ setUpLandscapeDisplay()
+ val task = setUpSplitScreenTask()
+ val taskToRequest = setUpFreeformTask()
+ val optionsCaptor = ArgumentCaptor.forClass(Bundle::class.java)
+ runOpenInstance(task, taskToRequest.taskId)
+ verify(splitScreenController)
+ .startTask(anyInt(), anyInt(), optionsCaptor.capture(), anyOrNull())
+ assertThat(ActivityOptions.fromBundle(optionsCaptor.value).launchWindowingMode)
+ .isEqualTo(WINDOWING_MODE_MULTI_WINDOW)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
+ fun openInstance_fromFreeformAddsNewWindow() {
+ setUpLandscapeDisplay()
+ val task = setUpFreeformTask()
+ val taskToRequest = setUpFreeformTask()
+ val wctCaptor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ runOpenInstance(task, taskToRequest.taskId)
+ verify(transitions).startTransition(anyInt(), wctCaptor.capture(), anyOrNull())
+ assertThat(ActivityOptions.fromBundle(wctCaptor.value.hierarchyOps[0].launchOptions)
+ .launchWindowingMode).isEqualTo(WINDOWING_MODE_FREEFORM)
+ }
+
+ private fun runOpenInstance(
+ callingTask: RunningTaskInfo,
+ requestedTaskId: Int
+ ) {
+ markTaskVisible(callingTask)
+ callingTask.baseActivity = mock(ComponentName::class.java)
+ callingTask.isFocused = true
+ runningTasks.add(callingTask)
+ controller.openInstance(callingTask, requestedTaskId)
+ }
+
+ @Test
fun toggleBounds_togglesToStableBounds() {
val bounds = Rect(0, 0, 100, 100)
val task = setUpFreeformTask(DEFAULT_DISPLAY, bounds)
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt
new file mode 100644
index 000000000000..c989d1640f80
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt
@@ -0,0 +1,138 @@
+/*
+ * 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.wm.shell.desktopmode
+
+import android.app.ActivityManager.RunningTaskInfo
+import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.platform.test.annotations.EnableFlags
+import android.view.Display.DEFAULT_DISPLAY
+import android.view.WindowManager.TRANSIT_TO_BACK
+import android.window.IWindowContainerToken
+import android.window.TransitionInfo
+import android.window.TransitionInfo.Change
+import android.window.WindowContainerToken
+import com.android.modules.utils.testing.ExtendedMockitoRule
+import com.android.window.flags.Flags
+import com.android.wm.shell.ShellTaskOrganizer
+import com.android.wm.shell.common.ShellExecutor
+import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
+import com.android.wm.shell.sysui.ShellInit
+import com.android.wm.shell.transition.Transitions
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.mockito.Mockito
+import org.mockito.kotlin.any
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.never
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.verify
+import org.mockito.kotlin.whenever
+
+class DesktopTasksTransitionObserverTest {
+
+ @JvmField
+ @Rule
+ val extendedMockitoRule =
+ ExtendedMockitoRule.Builder(this)
+ .mockStatic(DesktopModeStatus::class.java)
+ .build()!!
+
+ private val testExecutor = mock<ShellExecutor>()
+ private val mockShellInit = mock<ShellInit>()
+ private val transitions = mock<Transitions>()
+ private val context = mock<Context>()
+ private val shellTaskOrganizer = mock<ShellTaskOrganizer>()
+ private val taskRepository = mock<DesktopModeTaskRepository>()
+
+ private lateinit var transitionObserver: DesktopTasksTransitionObserver
+ private lateinit var shellInit: ShellInit
+
+ @Before
+ fun setup() {
+ whenever(DesktopModeStatus.canEnterDesktopMode(any())).thenReturn(true)
+ shellInit = spy(ShellInit(testExecutor))
+
+ transitionObserver =
+ DesktopTasksTransitionObserver(
+ context, taskRepository, transitions, shellTaskOrganizer, shellInit
+ )
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
+ fun backNavigation_taskMinimized() {
+ val task = createTaskInfo(1)
+ whenever(taskRepository.getVisibleTaskCount(any())).thenReturn(1)
+
+ transitionObserver.onTransitionReady(
+ transition = mock(),
+ info =
+ createBackNavigationTransition(task),
+ startTransaction = mock(),
+ finishTransaction = mock(),
+ )
+
+ verify(taskRepository).minimizeTask(task.displayId, task.taskId)
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
+ fun backNavigation_nullTaskInfo_taskNotMinimized() {
+ val task = createTaskInfo(1)
+ whenever(taskRepository.getVisibleTaskCount(any())).thenReturn(1)
+
+ transitionObserver.onTransitionReady(
+ transition = mock(),
+ info =
+ createBackNavigationTransition(null),
+ startTransaction = mock(),
+ finishTransaction = mock(),
+ )
+
+ verify(taskRepository, never()).minimizeTask(task.displayId, task.taskId)
+ }
+
+ private fun createBackNavigationTransition(
+ task: RunningTaskInfo?
+ ): TransitionInfo {
+ return TransitionInfo(TRANSIT_TO_BACK, 0 /* flags */).apply {
+ addChange(
+ Change(mock(), mock()).apply {
+ mode = TRANSIT_TO_BACK
+ parent = null
+ taskInfo = task
+ flags = flags
+ }
+ )
+ }
+ }
+
+ private fun createTaskInfo(id: Int) =
+ RunningTaskInfo().apply {
+ taskId = id
+ displayId = DEFAULT_DISPLAY
+ configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM
+ token = WindowContainerToken(Mockito.mock(IWindowContainerToken::class.java))
+ baseIntent = Intent().apply {
+ component = ComponentName("package", "component.name")
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java
index a6c16c43c8cb..67eda8bfecd1 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java
@@ -74,6 +74,7 @@ import com.android.wm.shell.splitscreen.SplitScreen.SplitScreenListener;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.DefaultMixedHandler;
+import com.android.wm.shell.transition.FocusTransitionObserver;
import com.android.wm.shell.transition.HomeTransitionObserver;
import com.android.wm.shell.transition.Transitions;
@@ -429,7 +430,8 @@ public class StageCoordinatorTests extends ShellTestCase {
ShellInit shellInit = new ShellInit(mMainExecutor);
final Transitions t = new Transitions(mContext, shellInit, mock(ShellController.class),
mTaskOrganizer, mTransactionPool, mock(DisplayController.class), mMainExecutor,
- mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class));
+ mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class),
+ mock(FocusTransitionObserver.class));
shellInit.init();
return t;
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/FocusTransitionObserverTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/FocusTransitionObserverTest.java
new file mode 100644
index 000000000000..d37b4cf4b4b3
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/FocusTransitionObserverTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.wm.shell.transition;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.WindowManager.TRANSIT_OPEN;
+import static android.view.WindowManager.TRANSIT_TO_FRONT;
+import static android.window.TransitionInfo.FLAG_MOVED_TO_TOP;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
+
+import static org.mockito.Mockito.clearInvocations;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import android.app.ActivityManager.RunningTaskInfo;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import android.view.SurfaceControl;
+import android.window.TransitionInfo;
+import android.window.TransitionInfo.TransitionMode;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.window.flags.Flags;
+import com.android.wm.shell.ShellTaskOrganizer;
+import com.android.wm.shell.ShellTestCase;
+import com.android.wm.shell.TestShellExecutor;
+import com.android.wm.shell.common.DisplayController;
+import com.android.wm.shell.shared.IFocusTransitionListener;
+import com.android.wm.shell.shared.TransactionPool;
+import com.android.wm.shell.sysui.ShellController;
+import com.android.wm.shell.sysui.ShellInit;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for the focus transition observer.
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+@RequiresFlagsEnabled(Flags.FLAG_ENABLE_DISPLAY_FOCUS_IN_SHELL_TRANSITIONS)
+public class FocusTransitionObserverTest extends ShellTestCase {
+
+ static final int SECONDARY_DISPLAY_ID = 1;
+
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+ private IFocusTransitionListener mListener;
+ private Transitions mTransition;
+ private FocusTransitionObserver mFocusTransitionObserver;
+
+ @Before
+ public void setUp() {
+ mListener = mock(IFocusTransitionListener.class);
+ when(mListener.asBinder()).thenReturn(mock(IBinder.class));
+
+ mFocusTransitionObserver = new FocusTransitionObserver();
+ mTransition =
+ new Transitions(InstrumentationRegistry.getInstrumentation().getTargetContext(),
+ mock(ShellInit.class), mock(ShellController.class),
+ mock(ShellTaskOrganizer.class), mock(TransactionPool.class),
+ mock(DisplayController.class), new TestShellExecutor(),
+ new Handler(Looper.getMainLooper()), new TestShellExecutor(),
+ mock(HomeTransitionObserver.class),
+ mFocusTransitionObserver);
+ mFocusTransitionObserver.setRemoteFocusTransitionListener(mTransition, mListener);
+ }
+
+ @Test
+ public void testTransitionWithMovedToFrontFlagChangesDisplayFocus() throws RemoteException {
+ final IBinder binder = mock(IBinder.class);
+ final SurfaceControl.Transaction tx = mock(SurfaceControl.Transaction.class);
+
+ // Open a task on the default display, which doesn't change display focus because the
+ // default display already has it.
+ TransitionInfo info = mock(TransitionInfo.class);
+ final List<TransitionInfo.Change> changes = new ArrayList<>();
+ setupChange(changes, 123 /* taskId */, TRANSIT_OPEN, DEFAULT_DISPLAY,
+ true /* focused */);
+ when(info.getChanges()).thenReturn(changes);
+ mFocusTransitionObserver.onTransitionReady(binder, info, tx, tx);
+ verify(mListener, never()).onFocusedDisplayChanged(SECONDARY_DISPLAY_ID);
+ clearInvocations(mListener);
+
+ // Open a new task on the secondary display and verify display focus changes to the display.
+ changes.clear();
+ setupChange(changes, 456 /* taskId */, TRANSIT_OPEN, SECONDARY_DISPLAY_ID,
+ true /* focused */);
+ when(info.getChanges()).thenReturn(changes);
+ mFocusTransitionObserver.onTransitionReady(binder, info, tx, tx);
+ verify(mListener, times(1)).onFocusedDisplayChanged(SECONDARY_DISPLAY_ID);
+ clearInvocations(mListener);
+
+ // Open the first task to front and verify display focus goes back to the default display.
+ changes.clear();
+ setupChange(changes, 123 /* taskId */, TRANSIT_TO_FRONT, DEFAULT_DISPLAY,
+ true /* focused */);
+ when(info.getChanges()).thenReturn(changes);
+ mFocusTransitionObserver.onTransitionReady(binder, info, tx, tx);
+ verify(mListener, times(1)).onFocusedDisplayChanged(DEFAULT_DISPLAY);
+ clearInvocations(mListener);
+
+ // Open another task on the default display and verify no display focus switch as it's
+ // already on the default display.
+ changes.clear();
+ setupChange(changes, 789 /* taskId */, TRANSIT_OPEN, DEFAULT_DISPLAY,
+ true /* focused */);
+ when(info.getChanges()).thenReturn(changes);
+ mFocusTransitionObserver.onTransitionReady(binder, info, tx, tx);
+ verify(mListener, never()).onFocusedDisplayChanged(DEFAULT_DISPLAY);
+ }
+
+ private void setupChange(List<TransitionInfo.Change> changes, int taskId,
+ @TransitionMode int mode, int displayId, boolean focused) {
+ TransitionInfo.Change change = mock(TransitionInfo.Change.class);
+ RunningTaskInfo taskInfo = mock(RunningTaskInfo.class);
+ taskInfo.taskId = taskId;
+ taskInfo.isFocused = focused;
+ when(change.hasFlags(FLAG_MOVED_TO_TOP)).thenReturn(focused);
+ taskInfo.displayId = displayId;
+ when(change.getTaskInfo()).thenReturn(taskInfo);
+ when(change.getMode()).thenReturn(mode);
+ changes.add(change);
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/HomeTransitionObserverTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/HomeTransitionObserverTest.java
index 8f49de0a98fb..8dfdfb4dcbcf 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/HomeTransitionObserverTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/HomeTransitionObserverTest.java
@@ -100,7 +100,8 @@ public class HomeTransitionObserverTest extends ShellTestCase {
mHomeTransitionObserver = new HomeTransitionObserver(mContext, mMainExecutor);
mTransition = new Transitions(mContext, mock(ShellInit.class), mock(ShellController.class),
mOrganizer, mTransactionPool, mDisplayController, mMainExecutor,
- mMainHandler, mAnimExecutor, mHomeTransitionObserver);
+ mMainHandler, mAnimExecutor, mHomeTransitionObserver,
+ mock(FocusTransitionObserver.class));
mHomeTransitionObserver.setHomeTransitionListener(mTransition, mListener);
}
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 aea14b900647..6cde0569796d 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
@@ -158,7 +158,8 @@ public class ShellTransitionTests extends ShellTestCase {
ShellInit shellInit = mock(ShellInit.class);
final Transitions t = new Transitions(mContext, shellInit, mock(ShellController.class),
mOrganizer, mTransactionPool, createTestDisplayController(), mMainExecutor,
- mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class));
+ mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class),
+ mock(FocusTransitionObserver.class));
// One from Transitions, one from RootTaskDisplayAreaOrganizer
verify(shellInit).addInitCallback(any(), eq(t));
verify(shellInit).addInitCallback(any(), isA(RootTaskDisplayAreaOrganizer.class));
@@ -170,7 +171,8 @@ public class ShellTransitionTests extends ShellTestCase {
ShellController shellController = mock(ShellController.class);
final Transitions t = new Transitions(mContext, shellInit, shellController,
mOrganizer, mTransactionPool, createTestDisplayController(), mMainExecutor,
- mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class));
+ mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class),
+ mock(FocusTransitionObserver.class));
shellInit.init();
verify(shellController, times(1)).addExternalInterface(
eq(ShellSharedConstants.KEY_EXTRA_SHELL_SHELL_TRANSITIONS), any(), any());
@@ -1238,7 +1240,8 @@ public class ShellTransitionTests extends ShellTestCase {
final Transitions transitions =
new Transitions(mContext, shellInit, mock(ShellController.class), mOrganizer,
mTransactionPool, createTestDisplayController(), mMainExecutor,
- mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class));
+ mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class),
+ mock(FocusTransitionObserver.class));
final RecentsTransitionHandler recentsHandler =
new RecentsTransitionHandler(shellInit, mock(ShellTaskOrganizer.class), transitions,
mock(RecentTasksController.class), mock(HomeTransitionObserver.class));
@@ -1780,7 +1783,8 @@ public class ShellTransitionTests extends ShellTestCase {
ShellInit shellInit = new ShellInit(mMainExecutor);
final Transitions t = new Transitions(mContext, shellInit, mock(ShellController.class),
mOrganizer, mTransactionPool, createTestDisplayController(), mMainExecutor,
- mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class));
+ mMainHandler, mAnimExecutor, mock(HomeTransitionObserver.class),
+ mock(FocusTransitionObserver.class));
shellInit.init();
return t;
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipControllerTest.kt
new file mode 100644
index 000000000000..5594981135b1
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/education/DesktopWindowingEducationTooltipControllerTest.kt
@@ -0,0 +1,237 @@
+/*
+ * 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.wm.shell.windowdecor.education
+
+import android.annotation.LayoutRes
+import android.content.Context
+import android.graphics.Point
+import android.testing.AndroidTestingRunner
+import android.testing.TestableContext
+import android.testing.TestableLooper
+import android.testing.TestableResources
+import android.view.MotionEvent
+import android.view.View
+import android.view.WindowManager
+import android.widget.TextView
+import androidx.test.filters.SmallTest
+import com.android.wm.shell.R
+import com.android.wm.shell.ShellTestCase
+import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalSystemViewContainer
+import com.android.wm.shell.windowdecor.education.DesktopWindowingEducationTooltipController.TooltipArrowDirection
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyInt
+import org.mockito.Mock
+import org.mockito.MockitoAnnotations
+import org.mockito.kotlin.any
+import org.mockito.kotlin.anyOrNull
+import org.mockito.kotlin.argumentCaptor
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.times
+import org.mockito.kotlin.verify
+
+@SmallTest
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@RunWith(AndroidTestingRunner::class)
+class DesktopWindowingEducationTooltipControllerTest : ShellTestCase() {
+ @Mock private lateinit var mockWindowManager: WindowManager
+ @Mock private lateinit var mockViewContainerFactory: AdditionalSystemViewContainer.Factory
+ private lateinit var testableResources: TestableResources
+ private lateinit var testableContext: TestableContext
+ private lateinit var tooltipController: DesktopWindowingEducationTooltipController
+ private val tooltipViewArgumentCaptor = argumentCaptor<View>()
+
+ @Before
+ fun setUp() {
+ MockitoAnnotations.initMocks(this)
+ testableContext = TestableContext(mContext)
+ testableResources =
+ testableContext.orCreateTestableResources.apply {
+ addOverride(R.dimen.desktop_windowing_education_tooltip_padding, 10)
+ }
+ testableContext.addMockSystemService(
+ Context.LAYOUT_INFLATER_SERVICE, context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
+ testableContext.addMockSystemService(WindowManager::class.java, mockWindowManager)
+ tooltipController =
+ DesktopWindowingEducationTooltipController(testableContext, mockViewContainerFactory)
+ }
+
+ @Test
+ fun showEducationTooltip_createsTooltipWithCorrectText() {
+ val tooltipText = "This is a tooltip"
+ val tooltipViewConfig = createTooltipConfig(tooltipText = tooltipText)
+
+ tooltipController.showEducationTooltip(tooltipViewConfig = tooltipViewConfig, taskId = 123)
+
+ verify(mockViewContainerFactory, times(1))
+ .create(
+ windowManagerWrapper = any(),
+ taskId = anyInt(),
+ x = anyInt(),
+ y = anyInt(),
+ width = anyInt(),
+ height = anyInt(),
+ flags = anyInt(),
+ view = tooltipViewArgumentCaptor.capture())
+ val tooltipTextView =
+ tooltipViewArgumentCaptor.lastValue.findViewById<TextView>(R.id.tooltip_text)
+ assertThat(tooltipTextView.text).isEqualTo(tooltipText)
+ }
+
+ @Test
+ fun showEducationTooltip_usesCorrectTaskIdForWindow() {
+ val tooltipViewConfig = createTooltipConfig()
+ val taskIdArgumentCaptor = argumentCaptor<Int>()
+
+ tooltipController.showEducationTooltip(tooltipViewConfig = tooltipViewConfig, taskId = 123)
+
+ verify(mockViewContainerFactory, times(1))
+ .create(
+ windowManagerWrapper = any(),
+ taskId = taskIdArgumentCaptor.capture(),
+ x = anyInt(),
+ y = anyInt(),
+ width = anyInt(),
+ height = anyInt(),
+ flags = anyInt(),
+ view = anyOrNull())
+ assertThat(taskIdArgumentCaptor.lastValue).isEqualTo(123)
+ }
+
+ @Test
+ fun showEducationTooltip_tooltipPointsUpwards_horizontallyPositionTooltip() {
+ val initialTooltipX = 0
+ val initialTooltipY = 0
+ val tooltipViewConfig =
+ createTooltipConfig(
+ arrowDirection = TooltipArrowDirection.UP,
+ tooltipViewGlobalCoordinates = Point(initialTooltipX, initialTooltipY))
+ val tooltipXArgumentCaptor = argumentCaptor<Int>()
+ val tooltipWidthArgumentCaptor = argumentCaptor<Int>()
+
+ tooltipController.showEducationTooltip(tooltipViewConfig = tooltipViewConfig, taskId = 123)
+
+ verify(mockViewContainerFactory, times(1))
+ .create(
+ windowManagerWrapper = any(),
+ taskId = anyInt(),
+ x = tooltipXArgumentCaptor.capture(),
+ y = anyInt(),
+ width = tooltipWidthArgumentCaptor.capture(),
+ height = anyInt(),
+ flags = anyInt(),
+ view = tooltipViewArgumentCaptor.capture())
+ val expectedTooltipX = initialTooltipX - tooltipWidthArgumentCaptor.lastValue / 2
+ assertThat(tooltipXArgumentCaptor.lastValue).isEqualTo(expectedTooltipX)
+ }
+
+ @Test
+ fun showEducationTooltip_tooltipPointsLeft_verticallyPositionTooltip() {
+ val initialTooltipX = 0
+ val initialTooltipY = 0
+ val tooltipViewConfig =
+ createTooltipConfig(
+ arrowDirection = TooltipArrowDirection.LEFT,
+ tooltipViewGlobalCoordinates = Point(initialTooltipX, initialTooltipY))
+ val tooltipYArgumentCaptor = argumentCaptor<Int>()
+ val tooltipHeightArgumentCaptor = argumentCaptor<Int>()
+
+ tooltipController.showEducationTooltip(tooltipViewConfig = tooltipViewConfig, taskId = 123)
+
+ verify(mockViewContainerFactory, times(1))
+ .create(
+ windowManagerWrapper = any(),
+ taskId = anyInt(),
+ x = anyInt(),
+ y = tooltipYArgumentCaptor.capture(),
+ width = anyInt(),
+ height = tooltipHeightArgumentCaptor.capture(),
+ flags = anyInt(),
+ view = tooltipViewArgumentCaptor.capture())
+ val expectedTooltipY = initialTooltipY - tooltipHeightArgumentCaptor.lastValue / 2
+ assertThat(tooltipYArgumentCaptor.lastValue).isEqualTo(expectedTooltipY)
+ }
+
+ @Test
+ fun showEducationTooltip_touchEventActionOutside_dismissActionPerformed() {
+ val mockLambda: () -> Unit = mock()
+ val tooltipViewConfig = createTooltipConfig(onDismissAction = mockLambda)
+
+ tooltipController.showEducationTooltip(tooltipViewConfig = tooltipViewConfig, taskId = 123)
+ verify(mockViewContainerFactory, times(1))
+ .create(
+ windowManagerWrapper = any(),
+ taskId = anyInt(),
+ x = anyInt(),
+ y = anyInt(),
+ width = anyInt(),
+ height = anyInt(),
+ flags = anyInt(),
+ view = tooltipViewArgumentCaptor.capture())
+ val motionEvent =
+ MotionEvent.obtain(
+ /* downTime= */ 0L,
+ /* eventTime= */ 0L,
+ MotionEvent.ACTION_OUTSIDE,
+ /* x= */ 0f,
+ /* y= */ 0f,
+ /* metaState= */ 0)
+ tooltipViewArgumentCaptor.lastValue.dispatchTouchEvent(motionEvent)
+
+ verify(mockLambda).invoke()
+ }
+
+ @Test
+ fun showEducationTooltip_tooltipClicked_onClickActionPerformed() {
+ val mockLambda: () -> Unit = mock()
+ val tooltipViewConfig = createTooltipConfig(onEducationClickAction = mockLambda)
+
+ tooltipController.showEducationTooltip(tooltipViewConfig = tooltipViewConfig, taskId = 123)
+ verify(mockViewContainerFactory, times(1))
+ .create(
+ windowManagerWrapper = any(),
+ taskId = anyInt(),
+ x = anyInt(),
+ y = anyInt(),
+ width = anyInt(),
+ height = anyInt(),
+ flags = anyInt(),
+ view = tooltipViewArgumentCaptor.capture())
+ tooltipViewArgumentCaptor.lastValue.performClick()
+
+ verify(mockLambda).invoke()
+ }
+
+ private fun createTooltipConfig(
+ @LayoutRes tooltipViewLayout: Int = R.layout.desktop_windowing_education_top_arrow_tooltip,
+ tooltipViewGlobalCoordinates: Point = Point(0, 0),
+ tooltipText: String = "This is a tooltip",
+ arrowDirection: TooltipArrowDirection = TooltipArrowDirection.UP,
+ onEducationClickAction: () -> Unit = {},
+ onDismissAction: () -> Unit = {}
+ ) =
+ DesktopWindowingEducationTooltipController.EducationViewConfig(
+ tooltipViewLayout = tooltipViewLayout,
+ tooltipViewGlobalCoordinates = tooltipViewGlobalCoordinates,
+ tooltipText = tooltipText,
+ arrowDirection = arrowDirection,
+ onEducationClickAction = onEducationClickAction,
+ onDismissAction = onDismissAction,
+ )
+}
diff --git a/libs/appfunctions/api/current.txt b/libs/appfunctions/api/current.txt
index 504e3290b0ae..3ed33db2222e 100644
--- a/libs/appfunctions/api/current.txt
+++ b/libs/appfunctions/api/current.txt
@@ -3,13 +3,15 @@ package com.google.android.appfunctions.sidecar {
public final class AppFunctionManager {
ctor public AppFunctionManager(android.content.Context);
- method public void executeAppFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
+ method public void executeAppFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull java.util.concurrent.Executor, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
+ method @Deprecated public void executeAppFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
}
public abstract class AppFunctionService extends android.app.Service {
ctor public AppFunctionService();
method @NonNull public final android.os.IBinder onBind(@Nullable android.content.Intent);
- method @MainThread public abstract void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
+ method @MainThread public void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull android.os.CancellationSignal, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
+ method @Deprecated @MainThread public abstract void onExecuteFunction(@NonNull com.google.android.appfunctions.sidecar.ExecuteAppFunctionRequest, @NonNull java.util.function.Consumer<com.google.android.appfunctions.sidecar.ExecuteAppFunctionResponse>);
field @NonNull public static final String BIND_APP_FUNCTION_SERVICE = "android.permission.BIND_APP_FUNCTION_SERVICE";
field @NonNull public static final String SERVICE_INTERFACE = "android.app.appfunctions.AppFunctionService";
}
diff --git a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionManager.java b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionManager.java
index b1dd4676a35e..815fe05cc3ab 100644
--- a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionManager.java
+++ b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionManager.java
@@ -19,12 +19,12 @@ package com.google.android.appfunctions.sidecar;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.content.Context;
+import android.os.CancellationSignal;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
-
/**
* Provides app functions related functionalities.
*
@@ -45,7 +45,7 @@ public final class AppFunctionManager {
*
* @param context A {@link Context}.
* @throws java.lang.IllegalStateException if the underlying {@link
- * android.app.appfunctions.AppFunctionManager} is not found.
+ * android.app.appfunctions.AppFunctionManager} is not found.
*/
public AppFunctionManager(Context context) {
mContext = Objects.requireNonNull(context);
@@ -66,6 +66,7 @@ public final class AppFunctionManager {
public void executeAppFunction(
@NonNull ExecuteAppFunctionRequest sidecarRequest,
@NonNull @CallbackExecutor Executor executor,
+ @NonNull CancellationSignal cancellationSignal,
@NonNull Consumer<ExecuteAppFunctionResponse> callback) {
Objects.requireNonNull(sidecarRequest);
Objects.requireNonNull(executor);
@@ -74,9 +75,40 @@ public final class AppFunctionManager {
android.app.appfunctions.ExecuteAppFunctionRequest platformRequest =
SidecarConverter.getPlatformExecuteAppFunctionRequest(sidecarRequest);
mManager.executeAppFunction(
- platformRequest, executor, (platformResponse) -> {
- callback.accept(SidecarConverter.getSidecarExecuteAppFunctionResponse(
- platformResponse));
+ platformRequest,
+ executor,
+ cancellationSignal,
+ (platformResponse) -> {
+ callback.accept(
+ SidecarConverter.getSidecarExecuteAppFunctionResponse(
+ platformResponse));
});
}
+
+ /**
+ * Executes the app function.
+ *
+ * <p>Proxies request and response to the underlying {@link
+ * android.app.appfunctions.AppFunctionManager#executeAppFunction}, converting the request and
+ * response in the appropriate type required by the function.
+ *
+ * @deprecated Use {@link #executeAppFunction(ExecuteAppFunctionRequest, Executor,
+ * CancellationSignal, Consumer)} instead. This method will be removed once usage references
+ * are updated.
+ */
+ @Deprecated
+ public void executeAppFunction(
+ @NonNull ExecuteAppFunctionRequest sidecarRequest,
+ @NonNull @CallbackExecutor Executor executor,
+ @NonNull Consumer<ExecuteAppFunctionResponse> callback) {
+ Objects.requireNonNull(sidecarRequest);
+ Objects.requireNonNull(executor);
+ Objects.requireNonNull(callback);
+
+ executeAppFunction(
+ sidecarRequest,
+ executor,
+ new CancellationSignal(),
+ callback);
+ }
}
diff --git a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java
index 65959dfdf561..6023c977bd76 100644
--- a/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java
+++ b/libs/appfunctions/java/com/google/android/appfunctions/sidecar/AppFunctionService.java
@@ -25,6 +25,7 @@ import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
+import android.os.CancellationSignal;
import java.util.function.Consumer;
@@ -69,10 +70,11 @@ public abstract class AppFunctionService extends Service {
private final Binder mBinder =
android.app.appfunctions.AppFunctionService.createBinder(
/* context= */ this,
- /* onExecuteFunction= */ (platformRequest, callback) -> {
+ /* onExecuteFunction= */ (platformRequest, cancellationSignal, callback) -> {
AppFunctionService.this.onExecuteFunction(
SidecarConverter.getSidecarExecuteAppFunctionRequest(
platformRequest),
+ cancellationSignal,
(sidecarResponse) -> {
callback.accept(
SidecarConverter.getPlatformExecuteAppFunctionResponse(
@@ -105,9 +107,42 @@ public abstract class AppFunctionService extends Service {
* result using the callback, no matter if the execution was successful or not.
*
* @param request The function execution request.
+ * @param cancellationSignal A {@link CancellationSignal} to cancel the request.
* @param callback A callback to report back the result.
*/
@MainThread
+ public void onExecuteFunction(
+ @NonNull ExecuteAppFunctionRequest request,
+ @NonNull CancellationSignal cancellationSignal,
+ @NonNull Consumer<ExecuteAppFunctionResponse> callback) {
+ onExecuteFunction(request, callback);
+ }
+
+ /**
+ * Called by the system to execute a specific app function.
+ *
+ * <p>This method is triggered when the system requests your AppFunctionService to handle a
+ * particular function you have registered and made available.
+ *
+ * <p>To ensure proper routing of function requests, assign a unique identifier to each
+ * function. This identifier doesn't need to be globally unique, but it must be unique within
+ * your app. For example, a function to order food could be identified as "orderFood". In most
+ * cases this identifier should come from the ID automatically generated by the AppFunctions
+ * SDK. You can determine the specific function to invoke by calling {@link
+ * ExecuteAppFunctionRequest#getFunctionIdentifier()}.
+ *
+ * <p>This method is always triggered in the main thread. You should run heavy tasks on a worker
+ * thread and dispatch the result with the given callback. You should always report back the
+ * result using the callback, no matter if the execution was successful or not.
+ *
+ * @param request The function execution request.
+ * @param callback A callback to report back the result.
+ *
+ * @deprecated Use {@link #onExecuteFunction(ExecuteAppFunctionRequest, CancellationSignal,
+ * Consumer)} instead. This method will be removed once usage references are updated.
+ */
+ @MainThread
+ @Deprecated
public abstract void onExecuteFunction(
@NonNull ExecuteAppFunctionRequest request,
@NonNull Consumer<ExecuteAppFunctionResponse> callback);
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index b6476c9d466f..ae46a99f09c8 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -50,6 +50,10 @@ constexpr bool skip_eglmanager_telemetry() {
constexpr bool resample_gainmap_regions() {
return false;
}
+
+constexpr bool query_global_priority() {
+ return false;
+}
} // namespace hwui_flags
#endif
@@ -110,6 +114,7 @@ bool Properties::clipSurfaceViews = false;
bool Properties::hdr10bitPlus = false;
bool Properties::skipTelemetry = false;
bool Properties::resampleGainmapRegions = false;
+bool Properties::queryGlobalPriority = false;
int Properties::timeoutMultiplier = 1;
@@ -187,6 +192,7 @@ bool Properties::load() {
hdr10bitPlus = hwui_flags::hdr_10bit_plus();
resampleGainmapRegions = base::GetBoolProperty("debug.hwui.resample_gainmap_regions",
hwui_flags::resample_gainmap_regions());
+ queryGlobalPriority = hwui_flags::query_global_priority();
timeoutMultiplier = android::base::GetIntProperty("ro.hw_timeout_multiplier", 1);
skipTelemetry = base::GetBoolProperty(PROPERTY_SKIP_EGLMANAGER_TELEMETRY,
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index db471527b861..6f84796fb11e 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -346,6 +346,7 @@ public:
static bool hdr10bitPlus;
static bool skipTelemetry;
static bool resampleGainmapRegions;
+ static bool queryGlobalPriority;
static int timeoutMultiplier;
diff --git a/libs/hwui/aconfig/hwui_flags.aconfig b/libs/hwui/aconfig/hwui_flags.aconfig
index ab052b902e02..93df47853769 100644
--- a/libs/hwui/aconfig/hwui_flags.aconfig
+++ b/libs/hwui/aconfig/hwui_flags.aconfig
@@ -129,3 +129,13 @@ flag {
description: "APIs that expose gainmap metadata corresponding to those defined in ISO 21496-1"
bug: "349357636"
}
+
+flag {
+ name: "query_global_priority"
+ namespace: "core_graphics"
+ description: "Attempt to query whether the vulkan driver supports the requested global priority before queue creation."
+ bug: "343986434"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/libs/hwui/jni/PathIterator.cpp b/libs/hwui/jni/PathIterator.cpp
index 3884342d8d37..e9de6555935d 100644
--- a/libs/hwui/jni/PathIterator.cpp
+++ b/libs/hwui/jni/PathIterator.cpp
@@ -20,6 +20,7 @@
#include "GraphicsJNI.h"
#include "SkPath.h"
#include "SkPoint.h"
+#include "graphics_jni_helpers.h"
namespace android {
@@ -36,6 +37,18 @@ public:
return reinterpret_cast<jlong>(new SkPath::RawIter(*path));
}
+ // A variant of 'next' (below) that is compatible with the host JVM.
+ static jint nextHost(JNIEnv* env, jclass clazz, jlong iteratorHandle, jfloatArray pointsArray) {
+ jfloat* points = env->GetFloatArrayElements(pointsArray, 0);
+#ifdef __ANDROID__
+ jint result = next(iteratorHandle, reinterpret_cast<jlong>(points));
+#else
+ jint result = next(env, clazz, iteratorHandle, reinterpret_cast<jlong>(points));
+#endif
+ env->ReleaseFloatArrayElements(pointsArray, points, 0);
+ return result;
+ }
+
// ---------------- @CriticalNative -------------------------
static jint peek(CRITICAL_JNI_PARAMS_COMMA jlong iteratorHandle) {
@@ -72,6 +85,7 @@ static const JNINativeMethod methods[] = {
{"nPeek", "(J)I", (void*)SkPathIteratorGlue::peek},
{"nNext", "(JJ)I", (void*)SkPathIteratorGlue::next},
+ {"nNextHost", "(J[F)I", (void*)SkPathIteratorGlue::nextHost},
};
int register_android_graphics_PathIterator(JNIEnv* env) {
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp
index e3023937964e..6571d92aeafa 100644
--- a/libs/hwui/renderthread/VulkanManager.cpp
+++ b/libs/hwui/renderthread/VulkanManager.cpp
@@ -44,7 +44,7 @@ namespace uirenderer {
namespace renderthread {
// Not all of these are strictly required, but are all enabled if present.
-static std::array<std::string_view, 21> sEnableExtensions{
+static std::array<std::string_view, 23> sEnableExtensions{
VK_KHR_BIND_MEMORY_2_EXTENSION_NAME,
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
@@ -65,6 +65,8 @@ static std::array<std::string_view, 21> sEnableExtensions{
VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME,
VK_KHR_ANDROID_SURFACE_EXTENSION_NAME,
VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME,
+ VK_EXT_GLOBAL_PRIORITY_QUERY_EXTENSION_NAME,
+ VK_KHR_GLOBAL_PRIORITY_EXTENSION_NAME,
VK_EXT_DEVICE_FAULT_EXTENSION_NAME,
};
@@ -206,7 +208,7 @@ void VulkanManager::setupDevice(skgpu::VulkanExtensions& grExtensions,
GET_INST_PROC(GetPhysicalDeviceFeatures2);
GET_INST_PROC(GetPhysicalDeviceImageFormatProperties2);
GET_INST_PROC(GetPhysicalDeviceProperties);
- GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties);
+ GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties2);
uint32_t gpuCount;
LOG_ALWAYS_FATAL_IF(mEnumeratePhysicalDevices(mInstance, &gpuCount, nullptr));
@@ -225,21 +227,30 @@ void VulkanManager::setupDevice(skgpu::VulkanExtensions& grExtensions,
// query to get the initial queue props size
uint32_t queueCount = 0;
- mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr);
+ mGetPhysicalDeviceQueueFamilyProperties2(mPhysicalDevice, &queueCount, nullptr);
LOG_ALWAYS_FATAL_IF(!queueCount);
// now get the actual queue props
- std::unique_ptr<VkQueueFamilyProperties[]> queueProps(new VkQueueFamilyProperties[queueCount]);
- mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, queueProps.get());
+ std::unique_ptr<VkQueueFamilyProperties2[]>
+ queueProps(new VkQueueFamilyProperties2[queueCount]);
+ // query the global priority, this ignored if VK_EXT_global_priority isn't supported
+ std::vector<VkQueueFamilyGlobalPriorityPropertiesEXT> queuePriorityProps(queueCount);
+ for (uint32_t i = 0; i < queueCount; i++) {
+ queuePriorityProps[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_GLOBAL_PRIORITY_PROPERTIES_EXT;
+ queuePriorityProps[i].pNext = nullptr;
+ queueProps[i].pNext = &queuePriorityProps[i];
+ }
+ mGetPhysicalDeviceQueueFamilyProperties2(mPhysicalDevice, &queueCount, queueProps.get());
constexpr auto kRequestedQueueCount = 2;
// iterate to find the graphics queue
mGraphicsQueueIndex = queueCount;
for (uint32_t i = 0; i < queueCount; i++) {
- if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
+ if (queueProps[i].queueFamilyProperties.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
mGraphicsQueueIndex = i;
- LOG_ALWAYS_FATAL_IF(queueProps[i].queueCount < kRequestedQueueCount);
+ LOG_ALWAYS_FATAL_IF(
+ queueProps[i].queueFamilyProperties.queueCount < kRequestedQueueCount);
break;
}
}
@@ -327,6 +338,15 @@ void VulkanManager::setupDevice(skgpu::VulkanExtensions& grExtensions,
tailPNext = &formatFeatures->pNext;
}
+ VkPhysicalDeviceGlobalPriorityQueryFeaturesEXT* globalPriorityQueryFeatures =
+ new VkPhysicalDeviceGlobalPriorityQueryFeaturesEXT;
+ globalPriorityQueryFeatures->sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES_EXT;
+ globalPriorityQueryFeatures->pNext = nullptr;
+ globalPriorityQueryFeatures->globalPriorityQuery = false;
+ *tailPNext = globalPriorityQueryFeatures;
+ tailPNext = &globalPriorityQueryFeatures->pNext;
+
// query to get the physical device features
mGetPhysicalDeviceFeatures2(mPhysicalDevice, &features);
// this looks like it would slow things down,
@@ -341,24 +361,59 @@ void VulkanManager::setupDevice(skgpu::VulkanExtensions& grExtensions,
if (Properties::contextPriority != 0 &&
grExtensions.hasExtension(VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME, 2)) {
- memset(&queuePriorityCreateInfo, 0, sizeof(VkDeviceQueueGlobalPriorityCreateInfoEXT));
- queuePriorityCreateInfo.sType =
- VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT;
- queuePriorityCreateInfo.pNext = nullptr;
+ VkQueueGlobalPriorityEXT globalPriority;
switch (Properties::contextPriority) {
case EGL_CONTEXT_PRIORITY_LOW_IMG:
- queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT;
+ globalPriority = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT;
break;
case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
- queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
+ globalPriority = VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
break;
case EGL_CONTEXT_PRIORITY_HIGH_IMG:
- queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT;
+ globalPriority = VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT;
break;
default:
LOG_ALWAYS_FATAL("Unsupported context priority");
}
- queueNextPtr = &queuePriorityCreateInfo;
+
+ // check if the requested priority is reported by the query
+ bool attachGlobalPriority = false;
+ if (uirenderer::Properties::queryGlobalPriority &&
+ globalPriorityQueryFeatures->globalPriorityQuery) {
+ for (uint32_t i = 0; i < queuePriorityProps[mGraphicsQueueIndex].priorityCount; i++) {
+ if (queuePriorityProps[mGraphicsQueueIndex].priorities[i] == globalPriority) {
+ attachGlobalPriority = true;
+ break;
+ }
+ }
+ } else {
+ // Querying is not supported so attempt queue creation with requested priority anyways
+ // If the priority turns out not to be supported, the driver *may* fail with
+ // VK_ERROR_NOT_PERMITTED_KHR
+ attachGlobalPriority = true;
+ }
+
+ if (attachGlobalPriority) {
+ memset(&queuePriorityCreateInfo, 0, sizeof(VkDeviceQueueGlobalPriorityCreateInfoEXT));
+ queuePriorityCreateInfo.sType =
+ VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT;
+ queuePriorityCreateInfo.pNext = nullptr;
+ queuePriorityCreateInfo.globalPriority = globalPriority;
+ queueNextPtr = &queuePriorityCreateInfo;
+ } else {
+ // If globalPriorityQuery is enabled, attempting queue creation with an unsupported
+ // priority will return VK_ERROR_INITIALIZATION_FAILED.
+ //
+ // SysUI and Launcher will request HIGH when SF has RT but it is a known issue that
+ // upstream drm drivers currently lack a way to grant them the granular privileges
+ // they need for HIGH (but not RT) so they will fail queue creation.
+ // For now, drop the unsupported global priority request so that queue creation
+ // succeeds.
+ //
+ // Once that is fixed, this should probably be a fatal error indicating an improper
+ // request or an app needs to get the correct privileges.
+ ALOGW("Requested context priority is not supported by the queue");
+ }
}
const VkDeviceQueueCreateInfo queueInfo = {
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index f0425719ea89..a593ec6f8351 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -152,7 +152,7 @@ private:
VkPtr<PFN_vkDestroyInstance> mDestroyInstance;
VkPtr<PFN_vkEnumeratePhysicalDevices> mEnumeratePhysicalDevices;
VkPtr<PFN_vkGetPhysicalDeviceProperties> mGetPhysicalDeviceProperties;
- VkPtr<PFN_vkGetPhysicalDeviceQueueFamilyProperties> mGetPhysicalDeviceQueueFamilyProperties;
+ VkPtr<PFN_vkGetPhysicalDeviceQueueFamilyProperties2> mGetPhysicalDeviceQueueFamilyProperties2;
VkPtr<PFN_vkGetPhysicalDeviceFeatures2> mGetPhysicalDeviceFeatures2;
VkPtr<PFN_vkGetPhysicalDeviceImageFormatProperties2> mGetPhysicalDeviceImageFormatProperties2;
VkPtr<PFN_vkCreateDevice> mCreateDevice;
diff --git a/media/java/android/media/tv/flags/media_tv.aconfig b/media/java/android/media/tv/flags/media_tv.aconfig
index c814c95e09d9..10423b9c1f0f 100644
--- a/media/java/android/media/tv/flags/media_tv.aconfig
+++ b/media/java/android/media/tv/flags/media_tv.aconfig
@@ -56,3 +56,11 @@ flag {
description: "Enhance HDMI-CEC power state and activeness transitions"
bug: "332780751"
}
+
+flag {
+ name: "media_quality_fw"
+ is_exported: true
+ namespace: "media_tv"
+ description: "Media Quality V1.0 APIs for Android W"
+ bug: "348412562"
+}
diff --git a/media/jni/android_media_ImageWriter.cpp b/media/jni/android_media_ImageWriter.cpp
index 6776f611559c..33650d91e6a3 100644
--- a/media/jni/android_media_ImageWriter.cpp
+++ b/media/jni/android_media_ImageWriter.cpp
@@ -735,10 +735,15 @@ static void ImageWriter_queueImage(JNIEnv* env, jobject thiz, jlong nativeCtx, j
}
static status_t attachAndQeueuGraphicBuffer(JNIEnv* env, JNIImageWriterContext *ctx,
- sp<Surface> surface, sp<GraphicBuffer> gb, jlong timestampNs, jint dataSpace,
+ sp<GraphicBuffer> gb, jlong timestampNs, jint dataSpace,
jint left, jint top, jint right, jint bottom, jint transform, jint scalingMode) {
status_t res = OK;
// Step 1. Attach Image
+ sp<Surface> surface = ctx->getProducer();
+ if (surface == nullptr) {
+ jniThrowException(env, "java/lang/IllegalStateException",
+ "Producer surface is null, ImageWriter seems already closed");
+ }
res = surface->attachBuffer(gb.get());
if (res != OK) {
ALOGE("Attach image failed: %s (%d)", strerror(-res), res);
@@ -835,7 +840,6 @@ static jint ImageWriter_attachAndQueueImage(JNIEnv* env, jobject thiz, jlong nat
return -1;
}
- sp<Surface> surface = ctx->getProducer();
if (isFormatOpaque(ctx->getBufferFormat()) != isFormatOpaque(nativeHalFormat)) {
jniThrowException(env, "java/lang/IllegalStateException",
"Trying to attach an opaque image into a non-opaque ImageWriter, or vice versa");
@@ -851,7 +855,7 @@ static jint ImageWriter_attachAndQueueImage(JNIEnv* env, jobject thiz, jlong nat
return -1;
}
- return attachAndQeueuGraphicBuffer(env, ctx, surface, buffer->mGraphicBuffer, timestampNs,
+ return attachAndQeueuGraphicBuffer(env, ctx, buffer->mGraphicBuffer, timestampNs,
dataSpace, left, top, right, bottom, transform, scalingMode);
}
@@ -866,7 +870,6 @@ static jint ImageWriter_attachAndQueueGraphicBuffer(JNIEnv* env, jobject thiz, j
return -1;
}
- sp<Surface> surface = ctx->getProducer();
if (isFormatOpaque(ctx->getBufferFormat()) != isFormatOpaque(nativeHalFormat)) {
jniThrowException(env, "java/lang/IllegalStateException",
"Trying to attach an opaque image into a non-opaque ImageWriter, or vice versa");
@@ -880,7 +883,8 @@ static jint ImageWriter_attachAndQueueGraphicBuffer(JNIEnv* env, jobject thiz, j
"Trying to attach an invalid graphic buffer");
return -1;
}
- return attachAndQeueuGraphicBuffer(env, ctx, surface, graphicBuffer, timestampNs,
+
+ return attachAndQeueuGraphicBuffer(env, ctx, graphicBuffer, timestampNs,
dataSpace, left, top, right, bottom, transform, scalingMode);
}
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml b/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml
index fc63c0f9ab93..3e73ebd4880e 100644
--- a/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml
+++ b/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml
@@ -35,11 +35,13 @@
style="@style/SettingsLibActionButton.Expressive"
android:layout_width="@dimen/settingslib_expressive_space_large3"
android:layout_height="@dimen/settingslib_expressive_space_medium5"
- android:layout_gravity="center_horizontal" />
+ android:layout_gravity="center_horizontal"
+ android:importantForAccessibility="no"/>
<TextView
android:id="@+id/text1"
style="@style/SettingsLibActionButton.Expressive.Label"
- android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>
+ android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"
+ android:importantForAccessibility="no"/>
</LinearLayout>
@@ -55,11 +57,13 @@
style="@style/SettingsLibActionButton.Expressive"
android:layout_width="@dimen/settingslib_expressive_space_large3"
android:layout_height="@dimen/settingslib_expressive_space_medium5"
- android:layout_gravity="center_horizontal" />
+ android:layout_gravity="center_horizontal"
+ android:importantForAccessibility="no"/>
<TextView
android:id="@+id/text2"
style="@style/SettingsLibActionButton.Expressive.Label"
- android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>
+ android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"
+ android:importantForAccessibility="no"/>
</LinearLayout>
@@ -75,11 +79,13 @@
style="@style/SettingsLibActionButton.Expressive"
android:layout_width="@dimen/settingslib_expressive_space_large3"
android:layout_height="@dimen/settingslib_expressive_space_medium5"
- android:layout_gravity="center_horizontal" />
+ android:layout_gravity="center_horizontal"
+ android:importantForAccessibility="no"/>
<TextView
android:id="@+id/text3"
style="@style/SettingsLibActionButton.Expressive.Label"
- android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>
+ android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"
+ android:importantForAccessibility="no"/>
</LinearLayout>
@@ -95,10 +101,12 @@
style="@style/SettingsLibActionButton.Expressive"
android:layout_width="@dimen/settingslib_expressive_space_large3"
android:layout_height="@dimen/settingslib_expressive_space_medium5"
- android:layout_gravity="center_horizontal" />
+ android:layout_gravity="center_horizontal"
+ android:importantForAccessibility="no"/>
<TextView
android:id="@+id/text4"
style="@style/SettingsLibActionButton.Expressive.Label"
- android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>
+ android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"
+ android:importantForAccessibility="no"/>
</LinearLayout>
</LinearLayout>
diff --git a/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java b/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java
index f011039517ce..b2861826a103 100644
--- a/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java
+++ b/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java
@@ -548,16 +548,18 @@ public class ActionButtonsPreference extends Preference {
if (mButton instanceof MaterialButton) {
((MaterialButton) mButton).setIcon(mIcon);
}
+ mButton.setEnabled(mIsEnabled);
+ mActionLayout.setOnClickListener(mListener);
+ mActionLayout.setEnabled(mIsEnabled);
+ mActionLayout.setContentDescription(mText);
} else {
mButton.setText(mText);
mButton.setCompoundDrawablesWithIntrinsicBounds(
null /* left */, mIcon /* top */, null /* right */, null /* bottom */);
+ mButton.setOnClickListener(mListener);
+ mButton.setEnabled(mIsEnabled);
}
- mButton.setOnClickListener(mListener);
- mButton.setEnabled(mIsEnabled);
-
-
if (shouldBeVisible()) {
mButton.setVisibility(View.VISIBLE);
if (mIsExpressive) {
diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp
index d4851e1ad698..af07686f064c 100644
--- a/packages/SettingsLib/Android.bp
+++ b/packages/SettingsLib/Android.bp
@@ -33,6 +33,7 @@ android_library {
"SettingsLibBarChartPreference",
"SettingsLibButtonPreference",
"SettingsLibBulletPreference",
+ "SettingsLibCardPreference",
"SettingsLibCollapsingToolbarBaseActivity",
"SettingsLibDeviceStateRotationLock",
"SettingsLibDisplayUtils",
diff --git a/packages/SettingsLib/CardPreference/Android.bp b/packages/SettingsLib/CardPreference/Android.bp
new file mode 100644
index 000000000000..1d871d168ee5
--- /dev/null
+++ b/packages/SettingsLib/CardPreference/Android.bp
@@ -0,0 +1,33 @@
+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_library {
+ name: "SettingsLibCardPreference",
+ use_resource_processor: true,
+ defaults: [
+ "SettingsLintDefaults",
+ ],
+
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
+ resource_dirs: ["res"],
+
+ static_libs: [
+ "androidx.annotation_annotation",
+ "androidx.preference_preference",
+ "SettingsLibSettingsTheme",
+ ],
+ sdk_version: "system_current",
+ min_sdk_version: "21",
+ apex_available: [
+ "//apex_available:platform",
+ ],
+}
diff --git a/packages/SettingsLib/CardPreference/AndroidManifest.xml b/packages/SettingsLib/CardPreference/AndroidManifest.xml
new file mode 100644
index 000000000000..717f66e0296c
--- /dev/null
+++ b/packages/SettingsLib/CardPreference/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.settingslib.widget.preference.card">
+
+ <uses-sdk android:minSdkVersion="21" />
+
+</manifest>
diff --git a/packages/SettingsLib/CardPreference/res/layout/settingslib_expressive_preference_card.xml b/packages/SettingsLib/CardPreference/res/layout/settingslib_expressive_preference_card.xml
new file mode 100644
index 000000000000..716ed412eb5c
--- /dev/null
+++ b/packages/SettingsLib/CardPreference/res/layout/settingslib_expressive_preference_card.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<com.google.android.material.card.MaterialCardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/SettingsLibCardStyle">
+
+ <LinearLayout
+ android:id="@+id/card_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:baselineAligned="false"
+ android:minHeight="@dimen/settingslib_expressive_space_large3"
+ android:paddingStart="@dimen/settingslib_expressive_space_small1"
+ android:paddingEnd="@dimen/settingslib_expressive_space_small1"
+ android:orientation="horizontal"
+ android:gravity="center_vertical">
+
+ <LinearLayout
+ android:id="@+id/icon_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:minWidth="@dimen/settingslib_expressive_space_medium3"
+ android:minHeight="@dimen/settingslib_expressive_space_medium3"
+ android:gravity="center"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@android:id/icon"
+ android:src="@drawable/settingslib_arrow_drop_down"
+ android:layout_width="@dimen/settingslib_expressive_space_medium3"
+ android:layout_height="@dimen/settingslib_expressive_space_medium3"
+ android:scaleType="centerInside"/>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/text_container"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:paddingHorizontal="@dimen/settingslib_expressive_space_small1"
+ android:paddingVertical="@dimen/settingslib_expressive_space_small2"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hyphenationFrequency="normalFast"
+ android:lineBreakWordStyle="phrase"
+ android:textAppearance="@style/TextAppearance.CardTitle.SettingsLib"/>
+
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hyphenationFrequency="normalFast"
+ android:lineBreakWordStyle="phrase"
+ android:textAppearance="@style/TextAppearance.CardSummary.SettingsLib"/>
+
+ </LinearLayout>
+
+ <ImageView
+ android:id="@android:id/closeButton"
+ android:layout_width="@dimen/settingslib_expressive_space_medium4"
+ android:layout_height="@dimen/settingslib_expressive_space_medium4"
+ android:padding="@dimen/settingslib_expressive_space_extrasmall4"
+ android:layout_gravity="center"
+ android:src="@drawable/settingslib_expressive_icon_close"
+ android:background="?android:attr/selectableItemBackground" />
+
+ </LinearLayout>
+
+</com.google.android.material.card.MaterialCardView> \ No newline at end of file
diff --git a/packages/SettingsLib/CardPreference/res/values/styles_expressive.xml b/packages/SettingsLib/CardPreference/res/values/styles_expressive.xml
new file mode 100644
index 000000000000..4cbdea52d439
--- /dev/null
+++ b/packages/SettingsLib/CardPreference/res/values/styles_expressive.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+
+<resources>
+ <style name="TextAppearance.CardTitle.SettingsLib"
+ parent="@style/TextAppearance.PreferenceTitle.SettingsLib">
+ <item name="android:textColor">@color/settingslib_materialColorOnPrimary</item>
+ <item name="android:textSize">20sp</item>
+ </style>
+
+ <style name="TextAppearance.CardSummary.SettingsLib"
+ parent="@style/TextAppearance.PreferenceSummary.SettingsLib">
+ <item name="android:textColor">@color/settingslib_materialColorOnSecondary</item>
+ <item name="android:textSize">14sp</item>
+ </style>
+</resources> \ No newline at end of file
diff --git a/packages/SettingsLib/CardPreference/src/com/android/settingslib/widget/CardPreference.kt b/packages/SettingsLib/CardPreference/src/com/android/settingslib/widget/CardPreference.kt
new file mode 100644
index 000000000000..eb14746a0f22
--- /dev/null
+++ b/packages/SettingsLib/CardPreference/src/com/android/settingslib/widget/CardPreference.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2020 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.settingslib.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import androidx.preference.Preference
+import androidx.preference.PreferenceViewHolder
+import com.android.settingslib.widget.preference.card.R
+
+/**
+ * The CardPreference shows a card like suggestion in homepage, which also support dismiss.
+ */
+class CardPreference @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
+) : Preference(context, attrs, defStyleAttr, defStyleRes) {
+
+ init {
+ layoutResource = R.layout.settingslib_expressive_preference_card
+ }
+ private var dismissible = false
+ set(value) {
+ if (field != value) {
+ field = value
+ notifyChanged()
+ }
+ }
+
+ override fun onBindViewHolder(holder: PreferenceViewHolder) {
+ super.onBindViewHolder(holder)
+ holder.isDividerAllowedBelow = false
+ holder.isDividerAllowedAbove = false
+
+ holder.findViewById(android.R.id.closeButton)?.let { dismissButton ->
+ dismissButton.visibility = if (dismissible) View.VISIBLE else View.GONE
+ dismissButton.setOnClickListener {
+ isVisible = false
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_collapse.xml b/packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_collapse.xml
new file mode 100644
index 000000000000..161ece73f21c
--- /dev/null
+++ b/packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_collapse.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape
+ android:shape="oval">
+ <size android:width="24dp" android:height="24dp"/>
+ <solid android:color="@color/settingslib_materialColorSurfaceDim"/>
+ </shape>
+ </item>
+ <item>
+ <vector
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960">
+ <path
+ android:fillColor="@color/settingslib_materialColorOnSurface"
+ android:pathData="M480,432L296,616L240,560L480,320L720,560L664,616L480,432Z"/>
+ </vector>
+ </item>
+</layer-list> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_expand.xml b/packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_expand.xml
new file mode 100644
index 000000000000..1b5d5182d9b2
--- /dev/null
+++ b/packages/SettingsLib/SettingsTheme/res/drawable-v35/settingslib_expressive_icon_expand.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape
+ android:shape="oval">
+ <size android:width="24dp" android:height="24dp"/>
+ <solid android:color="@color/settingslib_materialColorSurfaceDim"/>
+ </shape>
+ </item>
+ <item>
+ <vector
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960">
+ <path
+ android:fillColor="@color/settingslib_materialColorOnSurface"
+ android:pathData="M480,616L240,376L296,320L480,504L664,320L720,376L480,616Z"/>
+ </vector>
+ </item>
+</layer-list> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/layout-v35/settingslib_expressive_collapsable_textview.xml b/packages/SettingsLib/SettingsTheme/res/layout-v35/settingslib_expressive_collapsable_textview.xml
new file mode 100644
index 000000000000..245d3682636b
--- /dev/null
+++ b/packages/SettingsLib/SettingsTheme/res/layout-v35/settingslib_expressive_collapsable_textview.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="@dimen/settingslib_expressive_space_small1"
+ android:paddingTop="@dimen/settingslib_expressive_space_extrasmall4"
+ android:orientation="vertical"
+ android:animateLayoutChanges="true"
+ android:background="?android:attr/selectableItemBackground"
+ android:clipToPadding="false">
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ android:textAlignment="viewStart"
+ android:clickable="false"
+ android:longClickable="false"
+ android:maxLines="10"
+ android:ellipsize="end"
+ android:textAppearance="@style/TextAppearance.TopIntroText"/>
+
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/collapse_button"
+ app:layout_constraintTop_toBottomOf="@android:id/title"
+ app:layout_constraintStart_toStartOf="parent"
+ android:text="@string/settingslib_expressive_text_expand"
+ app:icon="@drawable/settingslib_expressive_icon_expand"
+ style="@style/SettingslibTextButtonStyle.Expressive"/>
+</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/values-v35/attrs_expressive.xml b/packages/SettingsLib/SettingsTheme/res/values-v35/attrs_expressive.xml
new file mode 100644
index 000000000000..857dd7953234
--- /dev/null
+++ b/packages/SettingsLib/SettingsTheme/res/values-v35/attrs_expressive.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <declare-styleable name="CollapsableTextView">
+ <attr name="android:gravity"/>
+ <!-- The minimum number of lines when the textView collapsed. -->
+ <attr name="android:minLines"/>
+ <!-- Specifies that the textView is collapsable. -->
+ <attr name="isCollapsable" format="boolean"/>
+ </declare-styleable>
+</resources> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/values-v35/strings.xml b/packages/SettingsLib/SettingsTheme/res/values-v35/strings.xml
new file mode 100644
index 000000000000..22734068733a
--- /dev/null
+++ b/packages/SettingsLib/SettingsTheme/res/values-v35/strings.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2021 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 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <!-- text of button to indicate user the textView is expandable [CHAR LIMIT=NONE] -->
+ <string name="settingslib_expressive_text_expand">Expand</string>
+ <!-- text of button to indicate user the textView is collapsable [CHAR LIMIT=NONE] -->
+ <string name="settingslib_expressive_text_collapse">Collapse</string>
+</resources> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml b/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml
index 816433c1a18b..250c27e8b581 100644
--- a/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml
+++ b/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml
@@ -170,6 +170,52 @@
<item name="thumbIcon">@drawable/settingslib_expressive_switch_thumb_icon</item>
</style>
+ <style name="SettingslibMainSwitchStyle.Expressive" parent="SettingslibSwitchStyle.Expressive">
+ <item name="android:layout_gravity">center</item>
+ <item name="trackTint">@color/settingslib_expressive_color_main_switch_track</item>
+ </style>
+
+ <style name="SettingsLibCardStyle" parent="">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_marginHorizontal">?android:attr/listPreferredItemPaddingStart</item>
+ <item name="android:layout_marginVertical">@dimen/settingslib_expressive_space_extrasmall4</item>
+ <item name="cardBackgroundColor">@color/settingslib_materialColorPrimary</item>
+ <item name="cardCornerRadius">@dimen/settingslib_expressive_radius_extralarge3</item>
+ <item name="cardElevation">0dp</item>
+ <item name="rippleColor">?android:attr/colorControlHighlight</item>
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Filled"
+ parent="@style/Widget.Material3.Button">
+ <item name="android:theme">@style/Theme.Material3.DynamicColors.DayNight</item>
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:gravity">center</item>
+ <item name="android:minWidth">@dimen/settingslib_expressive_space_medium4</item>
+ <item name="android:minHeight">@dimen/settingslib_expressive_space_medium4</item>
+ <item name="android:paddingVertical">@dimen/settingslib_expressive_space_extrasmall5</item>
+ <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small1</item>
+ <item name="android:backgroundTint">@color/settingslib_materialColorPrimary</item>
+ <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item>
+ <item name="android:textColor">@color/settingslib_materialColorOnPrimary</item>
+ <item name="android:textSize">14sp</item>
+ <item name="iconGravity">textStart</item>
+ <item name="iconTint">@color/settingslib_materialColorOnPrimary</item>
+ <item name="iconSize">@dimen/settingslib_expressive_space_small4</item>
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Filled.Large">
+ <item name="android:paddingVertical">@dimen/settingslib_expressive_space_small1</item>
+ <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small4</item>
+ <item name="android:textSize">16sp</item>
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Filled.Extra"
+ parent="@style/SettingsLibButtonStyle.Expressive.Filled.Large">
+ <item name="android:layout_width">match_parent</item>
+ </style>
+
<style name="SettingsLibButtonStyle.Expressive.Tonal"
parent="@style/Widget.Material3.Button.TonalButton">
<item name="android:theme">@style/Theme.Material3.DynamicColors.DayNight</item>
@@ -189,8 +235,59 @@
<item name="iconSize">@dimen/settingslib_expressive_space_small4</item>
</style>
- <style name="SettingslibMainSwitchStyle.Expressive" parent="SettingslibSwitchStyle.Expressive">
- <item name="android:layout_gravity">center</item>
- <item name="trackTint">@color/settingslib_expressive_color_main_switch_track</item>
+ <style name="SettingsLibButtonStyle.Expressive.Tonal.Large">
+ <item name="android:paddingVertical">@dimen/settingslib_expressive_space_small1</item>
+ <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small4</item>
+ <item name="android:textSize">16sp</item>
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Tonal.Extra"
+ parent="@style/SettingsLibButtonStyle.Expressive.Tonal.Large">
+ <item name="android:layout_width">match_parent</item>
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Outline"
+ parent="@style/Widget.Material3.Button.OutlinedButton.Icon">
+ <item name="android:theme">@style/Theme.Material3.DynamicColors.DayNight</item>
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:gravity">center</item>
+ <item name="android:minWidth">@dimen/settingslib_expressive_space_medium4</item>
+ <item name="android:minHeight">@dimen/settingslib_expressive_space_medium4</item>
+ <item name="android:paddingVertical">@dimen/settingslib_expressive_space_extrasmall5</item>
+ <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small1</item>
+ <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item>
+ <item name="android:textColor">@color/settingslib_materialColorPrimary</item>
+ <item name="android:textSize">14sp</item>
+ <item name="iconTint">@color/settingslib_materialColorPrimary</item>
+ <item name="iconGravity">textStart</item>
+ <item name="iconSize">@dimen/settingslib_expressive_space_small4</item>
+ <item name="iconPadding">@dimen/settingslib_expressive_space_extrasmall4</item>
+ <item name="strokeColor">@color/settingslib_materialColorOutlineVariant</item>
+
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Outline.Large">
+ <item name="android:paddingVertical">@dimen/settingslib_expressive_space_small1</item>
+ <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small4</item>
+ <item name="android:textSize">16sp</item>
+ </style>
+
+ <style name="SettingsLibButtonStyle.Expressive.Outline.Extra"
+ parent="@style/SettingsLibButtonStyle.Expressive.Outline.Large">
+ <item name="android:layout_width">match_parent</item>
+ </style>
+
+ <style name="SettingslibTextButtonStyle.Expressive"
+ parent="@style/Widget.Material3.Button.TextButton.Icon">
+ <item name="android:theme">@style/Theme.Material3.DynamicColors.DayNight</item>
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item>
+ <item name="android:textSize">16sp</item>
+ <item name="android:textColor">@color/settingslib_materialColorOnSurface</item>
+ <item name="iconTint">@null</item>
+ <item name="iconPadding">@dimen/settingslib_expressive_space_extrasmall4</item>
+ <item name="rippleColor">?android:attr/colorControlHighlight</item>
</style>
</resources> \ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt
new file mode 100644
index 000000000000..127f21a540ab
--- /dev/null
+++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt
@@ -0,0 +1,150 @@
+/*
+ * 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.settingslib.widget
+
+import android.content.Context
+import android.graphics.drawable.Drawable
+import android.util.AttributeSet
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.TextView
+import androidx.constraintlayout.widget.ConstraintLayout
+import com.android.settingslib.widget.theme.R
+import com.google.android.material.button.MaterialButton
+
+class CollapsableTextView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
+) : ConstraintLayout(context, attrs, defStyleAttr) {
+
+ private var isCollapsable: Boolean = false
+ private var isCollapsed: Boolean = false
+ private var minLines: Int = DEFAULT_MIN_LINES
+
+ private val titleTextView: TextView
+ private val collapseButton: MaterialButton
+ private val collapseButtonResources: CollapseButtonResources
+
+ init {
+ LayoutInflater.from(context)
+ .inflate(R.layout.settingslib_expressive_collapsable_textview, this)
+ titleTextView = findViewById(android.R.id.title)
+ collapseButton = findViewById(R.id.collapse_button)
+
+ collapseButtonResources = CollapseButtonResources(
+ context.getDrawable(R.drawable.settingslib_expressive_icon_collapse)!!,
+ context.getDrawable(R.drawable.settingslib_expressive_icon_expand)!!,
+ context.getString(R.string.settingslib_expressive_text_collapse),
+ context.getString(R.string.settingslib_expressive_text_expand)
+ )
+
+ collapseButton.setOnClickListener {
+ isCollapsed = !isCollapsed
+ updateView()
+ }
+
+ initAttributes(context, attrs, defStyleAttr)
+ }
+
+ private fun initAttributes(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
+ context.obtainStyledAttributes(
+ attrs, Attrs, defStyleAttr, 0
+ ).apply {
+ val gravity = getInt(GravityAttr, Gravity.START)
+ when (gravity) {
+ Gravity.CENTER_VERTICAL, Gravity.CENTER, Gravity.CENTER_HORIZONTAL -> {
+ centerHorizontally(titleTextView)
+ centerHorizontally(collapseButton)
+ }
+ }
+ recycle()
+ }
+ }
+
+ private fun centerHorizontally(view: View) {
+ (view.layoutParams as LayoutParams).apply {
+ startToStart = LayoutParams.PARENT_ID
+ endToEnd = LayoutParams.PARENT_ID
+ horizontalBias = 0.5f
+ }
+ }
+
+ /**
+ * Sets the text content of the CollapsableTextView.
+ * @param text The text to display.
+ */
+ fun setText(text: String) {
+ titleTextView.text = text
+ }
+
+ /**
+ * Sets whether the text view is collapsable.
+ * @param collapsable True if the text view should be collapsable, false otherwise.
+ */
+ fun setCollapsable(collapsable: Boolean) {
+ isCollapsable = collapsable
+ updateView()
+ }
+
+ /**
+ * Sets the minimum number of lines to display when collapsed.
+ * @param lines The minimum number of lines.
+ */
+ fun setMinLines(line: Int) {
+ minLines = line.coerceIn(1, DEFAULT_MAX_LINES)
+ updateView()
+ }
+
+ private fun updateView() {
+ when {
+ isCollapsed -> {
+ collapseButton.apply {
+ text = collapseButtonResources.expandText
+ icon = collapseButtonResources.expandIcon
+ }
+ titleTextView.maxLines = minLines
+ }
+
+ else -> {
+ collapseButton.apply {
+ text = collapseButtonResources.collapseText
+ icon = collapseButtonResources.collapseIcon
+ }
+ titleTextView.maxLines = DEFAULT_MAX_LINES
+ }
+ }
+ collapseButton.visibility = if (isCollapsable) VISIBLE else GONE
+ }
+
+ private data class CollapseButtonResources(
+ val collapseIcon: Drawable,
+ val expandIcon: Drawable,
+ val collapseText: String,
+ val expandText: String
+ )
+
+ companion object {
+ private const val DEFAULT_MAX_LINES = 10
+ private const val DEFAULT_MIN_LINES = 2
+
+ private val Attrs = R.styleable.CollapsableTextView
+ private val GravityAttr = R.styleable.CollapsableTextView_android_gravity
+ }
+}
+
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsTypography.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsTypography.kt
index 460bf9993b41..965c97124329 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsTypography.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsTypography.kt
@@ -162,3 +162,6 @@ internal fun rememberSettingsTypography(): Typography {
/** Creates a new [TextStyle] which font weight set to medium. */
internal fun TextStyle.toMediumWeight() =
copy(fontWeight = FontWeight.Medium, letterSpacing = 0.01.em)
+
+internal fun TextStyle.toSemiBoldWeight() =
+ copy(fontWeight = FontWeight.SemiBold, letterSpacing = 0.01.em)
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/button/ActionButtons.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/button/ActionButtons.kt
index 7e1df1694b10..5bb57b8ed1df 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/button/ActionButtons.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/button/ActionButtons.kt
@@ -110,7 +110,7 @@ private fun RowScope.ActionButton(actionButton: ActionButton) {
shape = RectangleShape,
colors = ButtonDefaults.filledTonalButtonColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
- contentColor = MaterialTheme.colorScheme.onPrimary,
+ contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
disabledContainerColor = MaterialTheme.colorScheme.surface,
),
contentPadding = PaddingValues(horizontal = 24.dp, vertical = 16.dp),
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/Actions.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/Actions.kt
index 94d2c210daab..f99d20669183 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/Actions.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/Actions.kt
@@ -41,9 +41,7 @@ import com.android.settingslib.spa.framework.theme.isSpaExpressiveEnabled
internal fun NavigateBack() {
val navController = LocalNavController.current
val contentDescription = stringResource(R.string.abc_action_bar_up_description)
- BackAction(contentDescription) {
- navController.navigateBack()
- }
+ BackAction(contentDescription) { navController.navigateBack() }
}
/** Action that collapses the search bar. */
@@ -55,15 +53,35 @@ internal fun CollapseAction(onClick: () -> Unit) {
@Composable
private fun BackAction(contentDescription: String, onClick: () -> Unit) {
- IconButton(onClick) {
+ IconButton(
+ onClick = onClick,
+ modifier =
+ if (isSpaExpressiveEnabled)
+ Modifier
+ .padding(
+ start = SettingsDimension.paddingLarge,
+ end = SettingsDimension.paddingSmall,
+ top = SettingsDimension.paddingExtraSmall,
+ bottom = SettingsDimension.paddingExtraSmall,
+ )
+ .size(SettingsDimension.actionIconWidth, SettingsDimension.actionIconHeight)
+ .clip(SettingsShape.CornerExtraLarge)
+ else Modifier,
+ ) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.ArrowBack,
contentDescription = contentDescription,
- modifier = if (isSpaExpressiveEnabled) Modifier
- .size(SettingsDimension.actionIconWidth, SettingsDimension.actionIconHeight)
- .clip(SettingsShape.CornerExtraLarge)
- .background(MaterialTheme.colorScheme.surfaceContainerHigh)
- .padding(SettingsDimension.actionIconPadding) else Modifier
+ modifier =
+ if (isSpaExpressiveEnabled)
+ Modifier
+ .size(
+ SettingsDimension.actionIconWidth,
+ SettingsDimension.actionIconHeight,
+ )
+ .clip(SettingsShape.CornerExtraLarge)
+ .background(MaterialTheme.colorScheme.surfaceContainerHighest)
+ .padding(SettingsDimension.actionIconPadding)
+ else Modifier,
)
}
}
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt
index 2ae3b569bc70..2c55779c9a01 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt
@@ -78,7 +78,9 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import com.android.settingslib.spa.framework.theme.SettingsDimension
+import com.android.settingslib.spa.framework.theme.isSpaExpressiveEnabled
import com.android.settingslib.spa.framework.theme.settingsBackground
+import com.android.settingslib.spa.framework.theme.toSemiBoldWeight
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.roundToInt
@@ -116,8 +118,12 @@ internal fun CustomizedLargeTopAppBar(
) {
TwoRowsTopAppBar(
title = { Title(title = title, maxLines = 3) },
- titleTextStyle = MaterialTheme.typography.displaySmall,
- smallTitleTextStyle = MaterialTheme.typography.titleMedium,
+ titleTextStyle =
+ if (isSpaExpressiveEnabled) MaterialTheme.typography.displaySmall.toSemiBoldWeight()
+ else MaterialTheme.typography.displaySmall,
+ smallTitleTextStyle =
+ if (isSpaExpressiveEnabled) MaterialTheme.typography.titleLarge.toSemiBoldWeight()
+ else MaterialTheme.typography.titleLarge,
titleBottomPadding = LargeTitleBottomPadding,
smallTitle = { Title(title = title, maxLines = 1) },
modifier = modifier,
@@ -136,7 +142,9 @@ private fun Title(title: String, maxLines: Int = Int.MAX_VALUE) {
text = title,
modifier =
Modifier.padding(
- start = SettingsDimension.itemPaddingAround,
+ start =
+ if (isSpaExpressiveEnabled) SettingsDimension.paddingExtraSmall
+ else SettingsDimension.itemPaddingAround,
end = SettingsDimension.itemPaddingEnd,
)
.semantics { heading() },
@@ -194,7 +202,7 @@ private class TopAppBarColors(
return lerp(
containerColor,
scrolledContainerColor,
- FastOutLinearInEasing.transform(colorTransitionFraction)
+ FastOutLinearInEasing.transform(colorTransitionFraction),
)
}
@@ -241,7 +249,7 @@ private fun SingleRowTopAppBar(
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
- content = actions
+ content = actions,
)
}
@@ -296,7 +304,7 @@ private fun TwoRowsTopAppBar(
windowInsets: WindowInsets,
colors: TopAppBarColors,
pinnedHeight: Dp,
- scrollBehavior: TopAppBarScrollBehavior?
+ scrollBehavior: TopAppBarScrollBehavior?,
) {
if (MaxHeightWithoutTitle <= pinnedHeight) {
throw IllegalArgumentException(
@@ -333,7 +341,7 @@ private fun TwoRowsTopAppBar(
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
- content = actions
+ content = actions,
)
}
val topTitleAlpha = { TopTitleAlphaEasing.transform(colorTransitionFraction()) }
@@ -356,9 +364,9 @@ private fun TwoRowsTopAppBar(
scrollBehavior.state,
velocity,
scrollBehavior.flingAnimationSpec,
- scrollBehavior.snapAnimationSpec
+ scrollBehavior.snapAnimationSpec,
)
- }
+ },
)
} else {
Modifier
@@ -412,7 +420,8 @@ private fun TwoRowsTopAppBar(
val measuredMaxHeightPx =
density.run {
MaxHeightWithoutTitle.toPx() +
- coordinates.size.height.toFloat()
+ coordinates.size.height.toFloat() +
+ titleBaselineHeight.toPx()
}
// Allow larger max height for multi-line title, but do not reduce
// max height to prevent flaky.
@@ -430,7 +439,7 @@ private fun TwoRowsTopAppBar(
titleBottomPadding = titleBottomPaddingPx,
hideTitleSemantics = hideBottomRowSemantics,
navigationIcon = {},
- actions = {}
+ actions = {},
)
}
}
@@ -485,7 +494,7 @@ private fun TopAppBarLayout(
Box(Modifier.layoutId("navigationIcon").padding(start = TopAppBarHorizontalPadding)) {
CompositionLocalProvider(
LocalContentColor provides navigationIconContentColor,
- content = navigationIcon
+ content = navigationIcon,
)
}
Box(
@@ -504,18 +513,18 @@ private fun TopAppBarLayout(
fontScale = if (titleScaleDisabled) 1f else fontScale,
)
},
- content = title
+ content = title,
)
}
}
Box(Modifier.layoutId("actionIcons").padding(end = TopAppBarHorizontalPadding)) {
CompositionLocalProvider(
LocalContentColor provides actionIconContentColor,
- content = actions
+ content = actions,
)
}
},
- modifier = modifier
+ modifier = modifier,
) { measurables, constraints ->
val navigationIconPlaceable =
measurables
@@ -552,7 +561,7 @@ private fun TopAppBarLayout(
// Navigation icon
navigationIconPlaceable.placeRelative(
x = 0,
- y = (layoutHeight - navigationIconPlaceable.height) / 2
+ y = (layoutHeight - navigationIconPlaceable.height) / 2,
)
// Title
@@ -570,17 +579,17 @@ private fun TopAppBarLayout(
titlePlaceable.height -
max(
0,
- titleBottomPadding - titlePlaceable.height + titleBaseline
+ titleBottomPadding - titlePlaceable.height + titleBaseline,
)
// Arrangement.Top
else -> 0
- }
+ },
)
// Action icons
actionIconsPlaceable.placeRelative(
x = constraints.maxWidth - actionIconsPlaceable.width,
- y = (layoutHeight - actionIconsPlaceable.height) / 2
+ y = (layoutHeight - actionIconsPlaceable.height) / 2,
)
}
}
@@ -595,7 +604,7 @@ private suspend fun settleAppBar(
state: TopAppBarState,
velocity: Float,
flingAnimationSpec: DecayAnimationSpec<Float>?,
- snapAnimationSpec: AnimationSpec<Float>?
+ snapAnimationSpec: AnimationSpec<Float>?,
): Velocity {
// Check if the app bar is completely collapsed/expanded. If so, no need to settle the app bar,
// and just return Zero Velocity.
@@ -609,20 +618,18 @@ private suspend fun settleAppBar(
// continue the motion to expand or collapse the app bar.
if (flingAnimationSpec != null && abs(velocity) > 1f) {
var lastValue = 0f
- AnimationState(
- initialValue = 0f,
- initialVelocity = velocity,
- )
- .animateDecay(flingAnimationSpec) {
- val delta = value - lastValue
- val initialHeightOffset = state.heightOffset
- state.heightOffset = initialHeightOffset + delta
- val consumed = abs(initialHeightOffset - state.heightOffset)
- lastValue = value
- remainingVelocity = this.velocity
- // avoid rounding errors and stop if anything is unconsumed
- if (abs(delta - consumed) > 0.5f) this.cancelAnimation()
- }
+ AnimationState(initialValue = 0f, initialVelocity = velocity).animateDecay(
+ flingAnimationSpec
+ ) {
+ val delta = value - lastValue
+ val initialHeightOffset = state.heightOffset
+ state.heightOffset = initialHeightOffset + delta
+ val consumed = abs(initialHeightOffset - state.heightOffset)
+ lastValue = value
+ remainingVelocity = this.velocity
+ // avoid rounding errors and stop if anything is unconsumed
+ if (abs(delta - consumed) > 0.5f) this.cancelAnimation()
+ }
}
// Snap if animation specs were provided.
if (snapAnimationSpec != null) {
@@ -633,7 +640,7 @@ private suspend fun settleAppBar(
} else {
state.heightOffsetLimit
},
- animationSpec = snapAnimationSpec
+ animationSpec = snapAnimationSpec,
) {
state.heightOffset = value
}
@@ -647,9 +654,10 @@ private suspend fun settleAppBar(
// Medium or Large app bar.
private val TopTitleAlphaEasing = CubicBezierEasing(.8f, 0f, .8f, .15f)
-internal val MaxHeightWithoutTitle = 124.dp
+internal val MaxHeightWithoutTitle = if (isSpaExpressiveEnabled) 84.dp else 124.dp
internal val DefaultTitleHeight = 52.dp
internal val ContainerHeight = 56.dp
+private val titleBaselineHeight = if (isSpaExpressiveEnabled) 8.dp else 0.dp
private val LargeTitleBottomPadding = 28.dp
private val TopAppBarHorizontalPadding = 4.dp
diff --git a/packages/SettingsLib/TopIntroPreference/Android.bp b/packages/SettingsLib/TopIntroPreference/Android.bp
index e70201b0feb7..76e36dc5ff7d 100644
--- a/packages/SettingsLib/TopIntroPreference/Android.bp
+++ b/packages/SettingsLib/TopIntroPreference/Android.bp
@@ -14,7 +14,10 @@ android_library {
"SettingsLintDefaults",
],
- srcs: ["src/**/*.java"],
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
resource_dirs: ["res"],
static_libs: [
diff --git a/packages/SettingsLib/TopIntroPreference/res/layout-v35/settingslib_expressive_top_intro.xml b/packages/SettingsLib/TopIntroPreference/res/layout-v35/settingslib_expressive_top_intro.xml
new file mode 100644
index 000000000000..fb13ef79cc3b
--- /dev/null
+++ b/packages/SettingsLib/TopIntroPreference/res/layout-v35/settingslib_expressive_top_intro.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart">
+
+ <com.android.settingslib.widget.CollapsableTextView
+ android:id="@+id/collapsable_text_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+</LinearLayout> \ No newline at end of file
diff --git a/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java b/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java
deleted file mode 100644
index 1bbd76d86b7f..000000000000
--- a/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2020 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.settingslib.widget;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceViewHolder;
-
-import com.android.settingslib.widget.preference.topintro.R;
-
-/**
- * The TopIntroPreference shows a text which describe a feature. Gernerally, we expect this
- * preference always shows on the top of screen.
- */
-public class TopIntroPreference extends Preference {
-
- public TopIntroPreference(Context context) {
- super(context);
- setLayoutResource(R.layout.top_intro_preference);
- setSelectable(false);
- }
-
- public TopIntroPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- setLayoutResource(R.layout.top_intro_preference);
- setSelectable(false);
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder holder) {
- super.onBindViewHolder(holder);
- holder.setDividerAllowedAbove(false);
- holder.setDividerAllowedBelow(false);
- }
-}
diff --git a/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.kt b/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.kt
new file mode 100644
index 000000000000..afced0c8d638
--- /dev/null
+++ b/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.kt
@@ -0,0 +1,108 @@
+/*
+ * 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.settingslib.widget
+
+import android.content.Context
+import android.os.Build
+import android.util.AttributeSet
+import androidx.annotation.RequiresApi
+import androidx.preference.Preference
+import androidx.preference.PreferenceViewHolder
+import com.android.settingslib.widget.preference.topintro.R
+
+open class TopIntroPreference @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
+) : Preference(context, attrs, defStyleAttr, defStyleRes) {
+
+ private var isCollapsable: Boolean = false
+ private var minLines: Int = 2
+
+ init {
+ if (SettingsThemeHelper.isExpressiveTheme(context)) {
+ layoutResource = R.layout.settingslib_expressive_top_intro
+ initAttributes(context, attrs, defStyleAttr)
+ } else {
+ layoutResource = R.layout.top_intro_preference
+ }
+ isSelectable = false
+ }
+
+ private fun initAttributes(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
+ context.obtainStyledAttributes(
+ attrs,
+ COLLAPSABLE_TEXT_VIEW_ATTRS, defStyleAttr, 0
+ ).apply {
+ isCollapsable = getBoolean(IS_COLLAPSABLE, false)
+ minLines = getInt(
+ MIN_LINES,
+ if (isCollapsable) DEFAULT_MIN_LINES else DEFAULT_MAX_LINES
+ ).coerceIn(1, DEFAULT_MAX_LINES)
+ recycle()
+ }
+ }
+
+ override fun onBindViewHolder(holder: PreferenceViewHolder) {
+ super.onBindViewHolder(holder)
+ holder.isDividerAllowedAbove = false
+ holder.isDividerAllowedBelow = false
+
+ if (!SettingsThemeHelper.isExpressiveTheme(context)) {
+ return
+ }
+
+ (holder.findViewById(R.id.collapsable_text_view) as? CollapsableTextView)?.apply {
+ setCollapsable(isCollapsable)
+ setMinLines(minLines)
+ setText(title.toString())
+ }
+ }
+
+ /**
+ * Sets whether the text view is collapsable.
+ * @param collapsable True if the text view should be collapsable, false otherwise.
+ */
+ @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ fun setCollapsable(collapsable: Boolean) {
+ isCollapsable = collapsable
+ notifyChanged()
+ }
+
+ /**
+ * Sets the minimum number of lines to display when collapsed.
+ * @param lines The minimum number of lines.
+ */
+ @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ fun setMinLines(lines: Int) {
+ minLines = lines.coerceIn(1, DEFAULT_MAX_LINES)
+ notifyChanged()
+ }
+
+ companion object {
+ private const val DEFAULT_MAX_LINES = 10
+ private const val DEFAULT_MIN_LINES = 2
+
+ private val COLLAPSABLE_TEXT_VIEW_ATTRS =
+ com.android.settingslib.widget.theme.R.styleable.CollapsableTextView
+ private val MIN_LINES =
+ com.android.settingslib.widget.theme.R.styleable.CollapsableTextView_android_minLines
+ private val IS_COLLAPSABLE =
+ com.android.settingslib.widget.theme.R.styleable.CollapsableTextView_isCollapsable
+ }
+}
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index 34e33c0df8f5..efc98dbf7102 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -1645,13 +1645,13 @@
<string name="media_transfer_headphone_name">Headphone</string>
<!-- Name of the usb audio device speaker, used in desktop devices. [CHAR LIMIT=50] -->
- <string name="media_transfer_usb_speaker_name">USB speaker</string>
+ <string name="media_transfer_usb_audio_name">USB audio</string>
<!-- Name of the 3.5mm audio device mic. [CHAR LIMIT=50] -->
<string name="media_transfer_wired_device_mic_name">Mic jack</string>
<!-- Name of the usb audio device mic. [CHAR LIMIT=50] -->
- <string name="media_transfer_usb_device_mic_name">USB mic</string>
+ <string name="media_transfer_usb_device_mic_name">USB microphone</string>
<!-- Label for Wifi hotspot switch on. Toggles hotspot on [CHAR LIMIT=30] -->
<string name="wifi_hotspot_switch_on_text">On</string>
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java
index 58dc8c7aad6c..e7c7476d4797 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java
@@ -45,6 +45,7 @@ import java.lang.annotation.RetentionPolicy;
DeviceSettingId.DEVICE_SETTING_ID_KEYBOARD_SETTINGS,
DeviceSettingId.DEVICE_SETTING_ID_DEVICE_DETAILS_FOOTER,
DeviceSettingId.DEVICE_SETTING_ID_ANC,
+ DeviceSettingId.DEVICE_SETTING_ID_GENERAL_BLUETOOTH_DEVICE_HEADER,
},
open = true)
public @interface DeviceSettingId {
@@ -114,6 +115,9 @@ public @interface DeviceSettingId {
/** Device setting ID for "More Settings" page. */
int DEVICE_SETTING_ID_MORE_SETTINGS = 21;
+ /** Device setting ID for general bluetooth device header. */
+ int DEVICE_SETTING_ID_GENERAL_BLUETOOTH_DEVICE_HEADER = 22;
+
/** Device setting ID for ANC. */
int DEVICE_SETTING_ID_ANC = 1001;
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingItem.kt b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingItem.kt
index 38183d5a01fd..da01b3bcaafb 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingItem.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingItem.kt
@@ -32,9 +32,9 @@ import android.os.Parcelable
*/
data class DeviceSettingItem(
@DeviceSettingId val settingId: Int,
- val packageName: String,
- val className: String,
- val intentAction: String,
+ val packageName: String? = null,
+ val className: String? = null,
+ val intentAction: String? = null,
val preferenceKey: String? = null,
val highlighted: Boolean = false,
val extras: Bundle = Bundle.EMPTY,
@@ -62,11 +62,11 @@ data class DeviceSettingItem(
parcel.run {
DeviceSettingItem(
settingId = readInt(),
- packageName = readString() ?: "",
- className = readString() ?: "",
- intentAction = readString() ?: "",
+ packageName = readString(),
+ className = readString(),
+ intentAction = readString(),
highlighted = readBoolean(),
- preferenceKey = readString() ?: "",
+ preferenceKey = readString(),
extras = readBundle((Bundle::class.java.classLoader)) ?: Bundle.EMPTY,
)
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.aidl b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.aidl
new file mode 100644
index 000000000000..d8378067b115
--- /dev/null
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.aidl
@@ -0,0 +1,19 @@
+/*
+ * 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.settingslib.bluetooth.devicesettings;
+
+parcelable DeviceSettingsConfigServiceStatus; \ No newline at end of file
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.kt b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.kt
new file mode 100644
index 000000000000..ae867713c831
--- /dev/null
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatus.kt
@@ -0,0 +1,60 @@
+/*
+ * 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.settingslib.bluetooth.devicesettings
+
+import android.os.Bundle
+import android.os.Parcel
+import android.os.Parcelable
+
+/**
+ * A data class representing a device settings config service status.
+ *
+ * @property success Whether the status is succeed.
+ * @property extras Extra bundle
+ */
+data class DeviceSettingsConfigServiceStatus(
+ val success: Boolean,
+ val extras: Bundle = Bundle.EMPTY,
+) : Parcelable {
+
+ override fun describeContents(): Int = 0
+
+ override fun writeToParcel(parcel: Parcel, flags: Int) {
+ parcel.run {
+ writeBoolean(success)
+ writeBundle(extras)
+ }
+ }
+
+ companion object {
+ @JvmField
+ val CREATOR: Parcelable.Creator<DeviceSettingsConfigServiceStatus> =
+ object : Parcelable.Creator<DeviceSettingsConfigServiceStatus> {
+ override fun createFromParcel(parcel: Parcel) =
+ parcel.run {
+ DeviceSettingsConfigServiceStatus(
+ success = readBoolean(),
+ extras = readBundle((Bundle::class.java.classLoader)) ?: Bundle.EMPTY,
+ )
+ }
+
+ override fun newArray(size: Int): Array<DeviceSettingsConfigServiceStatus?> {
+ return arrayOfNulls(size)
+ }
+ }
+ }
+}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsProviderServiceStatus.kt b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsProviderServiceStatus.kt
index 977849e75556..77d790e7f773 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsProviderServiceStatus.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsProviderServiceStatus.kt
@@ -21,7 +21,7 @@ import android.os.Parcel
import android.os.Parcelable
/**
- * A data class representing a device settings item in bluetooth device details config.
+ * A data class representing a device settings provider service status.
*
* @property enabled Whether the service is enabled.
* @property extras Extra bundle
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IDeviceSettingsConfigProviderService.aidl b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IDeviceSettingsConfigProviderService.aidl
index 647611ed8ef4..9cf49070a62c 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IDeviceSettingsConfigProviderService.aidl
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IDeviceSettingsConfigProviderService.aidl
@@ -17,8 +17,8 @@
package com.android.settingslib.bluetooth.devicesettings;
import com.android.settingslib.bluetooth.devicesettings.DeviceInfo;
-import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfig;
+import com.android.settingslib.bluetooth.devicesettings.IGetDeviceSettingsConfigCallback;
interface IDeviceSettingsConfigProviderService {
- DeviceSettingsConfig getDeviceSettingsConfig(in DeviceInfo device);
+ oneway void getDeviceSettingsConfig(in DeviceInfo device, in IGetDeviceSettingsConfigCallback callback);
} \ No newline at end of file
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IGetDeviceSettingsConfigCallback.aidl b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IGetDeviceSettingsConfigCallback.aidl
new file mode 100644
index 000000000000..403cdd9e4d70
--- /dev/null
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/IGetDeviceSettingsConfigCallback.aidl
@@ -0,0 +1,24 @@
+/*
+ * 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.settingslib.bluetooth.devicesettings;
+
+import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfig;
+import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfigServiceStatus;
+
+interface IGetDeviceSettingsConfigCallback {
+ oneway void onResult(in DeviceSettingsConfigServiceStatus status, in DeviceSettingsConfig config) = 0;
+} \ No newline at end of file
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt
index 3d8ff86c9377..4af0504bd73a 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt
@@ -33,12 +33,15 @@ import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingPreferenceState
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingState
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfig
+import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfigServiceStatus
import com.android.settingslib.bluetooth.devicesettings.IDeviceSettingsConfigProviderService
import com.android.settingslib.bluetooth.devicesettings.IDeviceSettingsListener
import com.android.settingslib.bluetooth.devicesettings.IDeviceSettingsProviderService
+import com.android.settingslib.bluetooth.devicesettings.IGetDeviceSettingsConfigCallback
import com.android.settingslib.bluetooth.devicesettings.data.model.ServiceConnectionStatus
import java.util.concurrent.ConcurrentHashMap
import kotlin.coroutines.CoroutineContext
+import kotlin.coroutines.resume
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -63,6 +66,7 @@ import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
+import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
@OptIn(ExperimentalCoroutinesApi::class)
@@ -74,22 +78,22 @@ class DeviceSettingServiceConnection(
private val backgroundCoroutineContext: CoroutineContext,
) {
data class EndPoint(
- private val packageName: String,
+ private val packageName: String?,
private val className: String?,
- private val intentAction: String,
+ private val intentAction: String?,
) {
- fun toIntent(): Intent =
- Intent().apply {
+ fun toIntent(): Intent? {
+ if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(intentAction)) {
+ return null
+ }
+ return Intent().apply {
if (className.isNullOrBlank()) {
setPackage(packageName)
} else {
- setClassName(packageName, className)
+ setClassName(packageName!!, className)
}
setAction(intentAction)
}
-
- fun isValid(): Boolean {
- return !TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(intentAction)
}
}
@@ -126,8 +130,9 @@ class DeviceSettingServiceConnection(
when (it) {
is ServiceConnectionStatus.Connected ->
flowOf(
- it.service.getDeviceSettingsConfig(
- deviceInfo { setBluetoothAddress(cachedDevice.address) }
+ getDeviceSettingsConfigFromService(
+ deviceInfo { setBluetoothAddress(cachedDevice.address) },
+ it.service,
)
)
ServiceConnectionStatus.Connecting -> flowOf()
@@ -137,6 +142,27 @@ class DeviceSettingServiceConnection(
.first()
}
+ private suspend fun getDeviceSettingsConfigFromService(
+ deviceInfo: DeviceInfo,
+ service: IDeviceSettingsConfigProviderService,
+ ): DeviceSettingsConfig? = suspendCancellableCoroutine { continuation ->
+ service.getDeviceSettingsConfig(
+ deviceInfo,
+ object : IGetDeviceSettingsConfigCallback.Stub() {
+ override fun onResult(
+ status: DeviceSettingsConfigServiceStatus,
+ config: DeviceSettingsConfig?,
+ ) {
+ if (!status.success) {
+ continuation.resume(null)
+ } else {
+ continuation.resume(config)
+ }
+ }
+ },
+ )
+ }
+
private val settingIdToItemMapping =
flow {
if (!isServiceEnabled.await()) {
@@ -160,6 +186,12 @@ class DeviceSettingServiceConnection(
}
.shareIn(scope = coroutineScope, started = SharingStarted.WhileSubscribed(), replay = 1)
+ private val services =
+ ConcurrentHashMap<
+ EndPoint,
+ StateFlow<ServiceConnectionStatus<IDeviceSettingsProviderService>>,
+ >()
+
/** Gets [DeviceSettingsConfig] for the device, return null when failed. */
suspend fun getDeviceSettingsConfig(): DeviceSettingsConfig? {
if (!isServiceEnabled.await()) {
@@ -222,24 +254,23 @@ class DeviceSettingServiceConnection(
)
}
}
- ?.filter { it.isValid() }
?.distinct()
- ?.associateBy(
- { it },
- { endpoint ->
- services.computeIfAbsent(endpoint) {
- getService(
- endpoint.toIntent(),
- IDeviceSettingsProviderService.Stub::asInterface,
- )
- .stateIn(
- coroutineScope.plus(backgroundCoroutineContext),
- SharingStarted.WhileSubscribed(),
- ServiceConnectionStatus.Connecting,
- )
- }
- },
- )
+ ?.mapNotNull { endpoint ->
+ endpoint.toIntent()?.let { intent ->
+ Pair(
+ endpoint,
+ services.computeIfAbsent(endpoint) {
+ getService(intent, IDeviceSettingsProviderService.Stub::asInterface)
+ .stateIn(
+ coroutineScope.plus(backgroundCoroutineContext),
+ SharingStarted.WhileSubscribed(),
+ ServiceConnectionStatus.Connecting,
+ )
+ },
+ )
+ }
+ }
+ ?.toMap()
private fun getDeviceSettingsFromService(
cachedDevice: CachedBluetoothDevice,
@@ -320,11 +351,5 @@ class DeviceSettingServiceConnection(
const val CONFIG_SERVICE_PACKAGE_NAME = "DEVICE_SETTINGS_CONFIG_PACKAGE_NAME"
const val CONFIG_SERVICE_CLASS_NAME = "DEVICE_SETTINGS_CONFIG_CLASS"
const val CONFIG_SERVICE_INTENT_ACTION = "DEVICE_SETTINGS_CONFIG_ACTION"
-
- val services =
- ConcurrentHashMap<
- EndPoint,
- StateFlow<ServiceConnectionStatus<IDeviceSettingsProviderService>>,
- >()
}
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/graph/SignalDrawable.java b/packages/SettingsLib/src/com/android/settingslib/graph/SignalDrawable.java
index ef0f6cbc6ed9..13a06017abbc 100644
--- a/packages/SettingsLib/src/com/android/settingslib/graph/SignalDrawable.java
+++ b/packages/SettingsLib/src/com/android/settingslib/graph/SignalDrawable.java
@@ -42,6 +42,8 @@ import androidx.annotation.Nullable;
import com.android.settingslib.R;
import com.android.settingslib.Utils;
+import java.util.Objects;
+
/**
* Drawable displaying a mobile cell signal indicator.
*/
@@ -90,6 +92,10 @@ public class SignalDrawable extends DrawableWrapper {
private int mCurrentDot;
public SignalDrawable(Context context) {
+ this(context, new Handler());
+ }
+
+ public SignalDrawable(@NonNull Context context, @NonNull Handler handler) {
super(context.getDrawable(ICON_RES));
final String attributionPathString = context.getString(
com.android.internal.R.string.config_signalAttributionPath);
@@ -106,7 +112,7 @@ public class SignalDrawable extends DrawableWrapper {
mIntrinsicSize = context.getResources().getDimensionPixelSize(R.dimen.signal_icon_size);
mTransparentPaint.setColor(context.getColor(android.R.color.transparent));
mTransparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- mHandler = new Handler();
+ mHandler = handler;
setDarkIntensity(0);
}
@@ -304,6 +310,17 @@ public class SignalDrawable extends DrawableWrapper {
| level;
}
+ @Override
+ public boolean equals(@Nullable Object other) {
+ return other instanceof SignalDrawable
+ && ((SignalDrawable) other).getLevel() == this.getLevel();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getLevel());
+ }
+
/** Returns the state representing empty mobile signal with the given number of levels. */
public static int getEmptyState(int numLevels) {
return getState(0, numLevels, true);
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
index 0b8fb22cef3a..feaf7fbc4b64 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
@@ -97,7 +97,7 @@ public class PhoneMediaDevice extends MediaDevice {
case TYPE_USB_ACCESSORY:
name =
inputRoutingEnabledAndIsDesktop()
- ? context.getString(R.string.media_transfer_usb_speaker_name)
+ ? context.getString(R.string.media_transfer_usb_audio_name)
: context.getString(R.string.media_transfer_wired_headphone_name);
break;
case TYPE_DOCK:
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatusTest.kt b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatusTest.kt
new file mode 100644
index 000000000000..3149acf6fc3c
--- /dev/null
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingsConfigServiceStatusTest.kt
@@ -0,0 +1,51 @@
+/*
+ * 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.settingslib.bluetooth.devicesettings
+
+import android.os.Bundle
+import android.os.Parcel
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+
+@RunWith(RobolectricTestRunner::class)
+class DeviceSettingsConfigServiceStatusTest {
+
+ @Test
+ fun parcelOperation() {
+ val item =
+ DeviceSettingsConfigServiceStatus(
+ success = true,
+ extras = Bundle().apply { putString("key1", "value1") },
+ )
+
+ val fromParcel = writeAndRead(item)
+
+ assertThat(fromParcel.success).isEqualTo(item.success)
+ assertThat(fromParcel.extras.getString("key1")).isEqualTo(item.extras.getString("key1"))
+ }
+
+ private fun writeAndRead(
+ item: DeviceSettingsConfigServiceStatus
+ ): DeviceSettingsConfigServiceStatus {
+ val parcel = Parcel.obtain()
+ item.writeToParcel(parcel, 0)
+ parcel.setDataPosition(0)
+ return DeviceSettingsConfigServiceStatus.CREATOR.createFromParcel(parcel)
+ }
+}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt
index 0cb6bc1b1261..4e62fd3b27c5 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt
@@ -33,10 +33,12 @@ import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingItem
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingState
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfig
+import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfigServiceStatus
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsProviderServiceStatus
import com.android.settingslib.bluetooth.devicesettings.IDeviceSettingsConfigProviderService
import com.android.settingslib.bluetooth.devicesettings.IDeviceSettingsListener
import com.android.settingslib.bluetooth.devicesettings.IDeviceSettingsProviderService
+import com.android.settingslib.bluetooth.devicesettings.IGetDeviceSettingsConfigCallback
import com.android.settingslib.bluetooth.devicesettings.MultiTogglePreference
import com.android.settingslib.bluetooth.devicesettings.MultiTogglePreferenceState
import com.android.settingslib.bluetooth.devicesettings.ToggleInfo
@@ -53,7 +55,6 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
-import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -140,15 +141,10 @@ class DeviceSettingRepositoryTest {
)
}
- @After
- fun clean() {
- DeviceSettingServiceConnection.services.clear()
- }
-
@Test
fun getDeviceSettingsConfig_withMetadata_success() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService1.serviceStatus)
.thenReturn(DeviceSettingsProviderServiceStatus(true))
`when`(settingProviderService2.serviceStatus)
@@ -179,7 +175,7 @@ class DeviceSettingRepositoryTest {
)
)
.thenReturn("".toByteArray())
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService1.serviceStatus)
.thenReturn(DeviceSettingsProviderServiceStatus(true))
`when`(settingProviderService2.serviceStatus)
@@ -194,7 +190,7 @@ class DeviceSettingRepositoryTest {
@Test
fun getDeviceSettingsConfig_providerServiceNotEnabled_returnNull() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService1.serviceStatus)
.thenReturn(DeviceSettingsProviderServiceStatus(false))
`when`(settingProviderService2.serviceStatus)
@@ -209,7 +205,7 @@ class DeviceSettingRepositoryTest {
@Test
fun getDeviceSettingsConfig_bindingServiceFail_returnNull() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
doReturn(false).`when`(context).bindService(any(), anyInt(), any(), any())
val config = underTest.getDeviceSettingsConfig(cachedDevice)
@@ -221,7 +217,7 @@ class DeviceSettingRepositoryTest {
@Test
fun getDeviceSetting_actionSwitchPreference_success() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService1.registerDeviceSettingsListener(any(), any())).then {
input ->
input
@@ -247,7 +243,7 @@ class DeviceSettingRepositoryTest {
@Test
fun getDeviceSetting_multiTogglePreference_success() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService2.registerDeviceSettingsListener(any(), any())).then {
input ->
input
@@ -273,7 +269,7 @@ class DeviceSettingRepositoryTest {
@Test
fun getDeviceSetting_helpPreference_success() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService2.registerDeviceSettingsListener(any(), any())).then {
input ->
input
@@ -299,6 +295,7 @@ class DeviceSettingRepositoryTest {
@Test
fun getDeviceSetting_noConfig_returnNull() {
testScope.runTest {
+ setUpConfigService(false, null)
`when`(settingProviderService1.registerDeviceSettingsListener(any(), any())).then {
input ->
input
@@ -320,7 +317,7 @@ class DeviceSettingRepositoryTest {
@Test
fun updateDeviceSettingState_switchState_success() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService1.registerDeviceSettingsListener(any(), any())).then {
input ->
input
@@ -358,7 +355,7 @@ class DeviceSettingRepositoryTest {
@Test
fun updateDeviceSettingState_multiToggleState_success() {
testScope.runTest {
- `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG)
+ setUpConfigService(true, DEVICE_SETTING_CONFIG)
`when`(settingProviderService2.registerDeviceSettingsListener(any(), any())).then {
input ->
input
@@ -459,6 +456,17 @@ class DeviceSettingRepositoryTest {
assertThat(actual.settingId).isEqualTo(serviceResponse.settingId)
}
+ private fun setUpConfigService(success: Boolean, config: DeviceSettingsConfig?) {
+ `when`(configService.getDeviceSettingsConfig(any(), any())).then { input ->
+ input
+ .getArgument<IGetDeviceSettingsConfigCallback>(1)
+ .onResult(
+ DeviceSettingsConfigServiceStatus(success = success),
+ config
+ )
+ }
+ }
+
private companion object {
const val BLUETOOTH_ADDRESS = "12:34:56:78"
const val CONFIG_SERVICE_PACKAGE_NAME = "com.android.fake.configservice"
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/PhoneMediaDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/PhoneMediaDeviceTest.java
index da5f428ce23b..1739c0e5e2bf 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/PhoneMediaDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/PhoneMediaDeviceTest.java
@@ -136,7 +136,7 @@ public class PhoneMediaDeviceTest {
when(mInfo.getType()).thenReturn(TYPE_USB_DEVICE);
assertThat(mPhoneMediaDevice.getName())
- .isEqualTo(mContext.getString(R.string.media_transfer_usb_speaker_name));
+ .isEqualTo(mContext.getString(R.string.media_transfer_usb_audio_name));
when(mInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);
diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
index d7109398b956..5e31da411e49 100644
--- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
+++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
@@ -164,6 +164,7 @@ public class SecureSettings {
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS,
Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS,
+ Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
Settings.Secure.SHOW_NOTIFICATION_SNOOZE,
Settings.Secure.NOTIFICATION_HISTORY_ENABLED,
Settings.Secure.ZEN_DURATION,
diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
index fa16a44f4592..b3f73749f393 100644
--- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
+++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
@@ -243,6 +243,7 @@ public class SecureSettingsValidators {
VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, BOOLEAN_VALIDATOR);
+ VALIDATORS.put(Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.SHOW_NOTIFICATION_SNOOZE, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.NOTIFICATION_HISTORY_ENABLED, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.ZEN_DURATION, ANY_INTEGER_VALIDATOR);
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index f8383d94b1ab..a9d4c89efe98 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -40,16 +40,6 @@ flag {
}
flag {
- name: "notification_minimalism_prototype"
- namespace: "systemui"
- description: "Prototype of notification minimalism; the new 'Intermediate' lockscreen customization proposal."
- bug: "330387368"
- metadata {
- purpose: PURPOSE_BUGFIX
- }
-}
-
-flag {
name: "notification_view_flipper_pausing_v2"
namespace: "systemui"
description: "Pause ViewFlippers inside Notification custom layouts when the shade is closed."
@@ -1128,6 +1118,16 @@ flag {
}
flag {
+ name: "media_controls_umo_inflation_in_background"
+ namespace: "systemui"
+ description: "Inflate UMO in background thread"
+ bug: "368514198"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+flag {
namespace: "systemui"
name: "enable_view_capture_tracing"
description: "Enables view capture tracing in System UI."
@@ -1431,4 +1431,4 @@ flag {
metadata {
purpose: PURPOSE_BUGFIX
}
-} \ No newline at end of file
+}
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java
new file mode 100644
index 000000000000..08db95e5a795
--- /dev/null
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java
@@ -0,0 +1,374 @@
+/*
+ * 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.animation;
+
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.ValueAnimator;
+import android.annotation.Nullable;
+import android.content.Context;
+import android.graphics.Rect;
+import android.hardware.display.DisplayManager;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.SurfaceControl;
+import android.window.IRemoteTransition;
+import android.window.IRemoteTransitionFinishedCallback;
+import android.window.TransitionInfo;
+import android.window.TransitionInfo.Change;
+import android.window.WindowAnimationState;
+
+import com.android.internal.policy.ScreenDecorationsUtils;
+import com.android.wm.shell.shared.TransitionUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An implementation of {@link IRemoteTransition} that accepts a {@link UIComponent} as the origin
+ * and automatically attaches it to the transition leash before the transition starts.
+ */
+public class OriginRemoteTransition extends IRemoteTransition.Stub {
+ private static final String TAG = "OriginRemoteTransition";
+
+ private final Context mContext;
+ private final boolean mIsEntry;
+ private final UIComponent mOrigin;
+ private final TransitionPlayer mPlayer;
+ private final long mDuration;
+ private final Handler mHandler;
+
+ @Nullable private SurfaceControl.Transaction mStartTransaction;
+ @Nullable private IRemoteTransitionFinishedCallback mFinishCallback;
+ @Nullable private UIComponent.Transaction mOriginTransaction;
+ @Nullable private ValueAnimator mAnimator;
+ @Nullable private SurfaceControl mOriginLeash;
+ private boolean mCancelled;
+
+ OriginRemoteTransition(
+ Context context,
+ boolean isEntry,
+ UIComponent origin,
+ TransitionPlayer player,
+ long duration,
+ Handler handler) {
+ mContext = context;
+ mIsEntry = isEntry;
+ mOrigin = origin;
+ mPlayer = player;
+ mDuration = duration;
+ mHandler = handler;
+ }
+
+ @Override
+ public void startAnimation(
+ IBinder token,
+ TransitionInfo info,
+ SurfaceControl.Transaction t,
+ IRemoteTransitionFinishedCallback finishCallback) {
+ logD("startAnimation - " + info);
+ mHandler.post(
+ () -> {
+ mStartTransaction = t;
+ mFinishCallback = finishCallback;
+ startAnimationInternal(info);
+ });
+ }
+
+ @Override
+ public void mergeAnimation(
+ IBinder transition,
+ TransitionInfo info,
+ SurfaceControl.Transaction t,
+ IBinder mergeTarget,
+ IRemoteTransitionFinishedCallback finishCallback) {
+ logD("mergeAnimation - " + info);
+ mHandler.post(this::cancel);
+ }
+
+ @Override
+ public void takeOverAnimation(
+ IBinder transition,
+ TransitionInfo info,
+ SurfaceControl.Transaction t,
+ IRemoteTransitionFinishedCallback finishCallback,
+ WindowAnimationState[] states) {
+ logD("takeOverAnimation - " + info);
+ }
+
+ @Override
+ public void onTransitionConsumed(IBinder transition, boolean aborted) {
+ logD("onTransitionConsumed - aborted: " + aborted);
+ mHandler.post(this::cancel);
+ }
+
+ private void startAnimationInternal(TransitionInfo info) {
+ if (!prepareUIs(info)) {
+ logE("Unable to prepare UI!");
+ finishAnimation(/* finished= */ false);
+ return;
+ }
+ // Notify player that we are starting.
+ mPlayer.onStart(info, mStartTransaction, mOrigin, mOriginTransaction);
+
+ // Start the animator.
+ mAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
+ mAnimator.setDuration(mDuration);
+ mAnimator.addListener(
+ new AnimatorListener() {
+ @Override
+ public void onAnimationStart(Animator a) {}
+
+ @Override
+ public void onAnimationEnd(Animator a) {
+ finishAnimation(/* finished= */ !mCancelled);
+ }
+
+ @Override
+ public void onAnimationCancel(Animator a) {
+ mCancelled = true;
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator a) {}
+ });
+ mAnimator.addUpdateListener(
+ a -> {
+ mPlayer.onProgress((float) a.getAnimatedValue());
+ });
+ mAnimator.start();
+ }
+
+ private boolean prepareUIs(TransitionInfo info) {
+ if (info.getRootCount() == 0) {
+ logE("prepareUIs: no root leash!");
+ return false;
+ }
+ if (info.getRootCount() > 1) {
+ logE("prepareUIs: multi-display transition is not supported yet!");
+ return false;
+ }
+ if (info.getChanges().isEmpty()) {
+ logE("prepareUIs: no changes!");
+ return false;
+ }
+
+ SurfaceControl rootLeash = info.getRoot(0).getLeash();
+ int displayId = info.getChanges().get(0).getEndDisplayId();
+ Rect displayBounds = getDisplayBounds(displayId);
+ float windowRadius = ScreenDecorationsUtils.getWindowCornerRadius(mContext);
+ logD("prepareUIs: windowRadius=" + windowRadius + ", displayBounds=" + displayBounds);
+
+ // Create the origin leash and add to the transition root leash.
+ mOriginLeash =
+ new SurfaceControl.Builder().setName("OriginTransition-origin-leash").build();
+ mStartTransaction
+ .reparent(mOriginLeash, rootLeash)
+ .show(mOriginLeash)
+ .setCornerRadius(mOriginLeash, windowRadius)
+ .setWindowCrop(mOriginLeash, displayBounds.width(), displayBounds.height());
+
+ // Process surfaces
+ List<SurfaceControl> openingSurfaces = new ArrayList<>();
+ List<SurfaceControl> closingSurfaces = new ArrayList<>();
+ for (Change change : info.getChanges()) {
+ int mode = change.getMode();
+ SurfaceControl leash = change.getLeash();
+ // Reparent leash to the transition root.
+ mStartTransaction.reparent(leash, rootLeash);
+ if (TransitionUtil.isOpeningMode(mode)) {
+ openingSurfaces.add(change.getLeash());
+ // For opening surfaces, ending bounds are base bound. Apply corner radius if
+ // it's full screen.
+ Rect bounds = change.getEndAbsBounds();
+ if (displayBounds.equals(bounds)) {
+ mStartTransaction
+ .setCornerRadius(leash, windowRadius)
+ .setWindowCrop(leash, bounds.width(), bounds.height());
+ }
+ } else if (TransitionUtil.isClosingMode(mode)) {
+ closingSurfaces.add(change.getLeash());
+ // For closing surfaces, starting bounds are base bounds. Apply corner radius if
+ // it's full screen.
+ Rect bounds = change.getStartAbsBounds();
+ if (displayBounds.equals(bounds)) {
+ mStartTransaction
+ .setCornerRadius(leash, windowRadius)
+ .setWindowCrop(leash, bounds.width(), bounds.height());
+ }
+ }
+ }
+
+ // Set relative order:
+ // ---- App1 ----
+ // ---- origin ----
+ // ---- App2 ----
+ if (mIsEntry) {
+ mStartTransaction
+ .setRelativeLayer(mOriginLeash, closingSurfaces.get(0), 1)
+ .setRelativeLayer(
+ openingSurfaces.get(openingSurfaces.size() - 1), mOriginLeash, 1);
+ } else {
+ mStartTransaction
+ .setRelativeLayer(mOriginLeash, openingSurfaces.get(0), 1)
+ .setRelativeLayer(
+ closingSurfaces.get(closingSurfaces.size() - 1), mOriginLeash, 1);
+ }
+
+ // Attach origin UIComponent to origin leash.
+ mOriginTransaction = mOrigin.newTransaction();
+ mOriginTransaction
+ .attachToTransitionLeash(
+ mOrigin, mOriginLeash, displayBounds.width(), displayBounds.height())
+ .commit();
+
+ // Apply all surface changes.
+ mStartTransaction.apply();
+ return true;
+ }
+
+ private Rect getDisplayBounds(int displayId) {
+ DisplayManager dm = mContext.getSystemService(DisplayManager.class);
+ DisplayMetrics metrics = new DisplayMetrics();
+ dm.getDisplay(displayId).getMetrics(metrics);
+ return new Rect(0, 0, metrics.widthPixels, metrics.heightPixels);
+ }
+
+ private void finishAnimation(boolean finished) {
+ logD("finishAnimation: finished=" + finished);
+ if (mAnimator == null) {
+ // The transition didn't start. Ensure we apply the start transaction and report
+ // finish afterwards.
+ mStartTransaction
+ .addTransactionCommittedListener(
+ mContext.getMainExecutor(), this::finishInternal)
+ .apply();
+ return;
+ }
+ mAnimator = null;
+ // Notify client that we have ended.
+ mPlayer.onEnd(finished);
+ // Detach the origin from the transition leash and report finish after it's done.
+ mOriginTransaction
+ .detachFromTransitionLeash(
+ mOrigin, mContext.getMainExecutor(), this::finishInternal)
+ .commit();
+ }
+
+ private void finishInternal() {
+ logD("finishInternal");
+ if (mOriginLeash != null) {
+ // Release origin leash.
+ mOriginLeash.release();
+ mOriginLeash = null;
+ }
+ try {
+ mFinishCallback.onTransitionFinished(null, null);
+ } catch (RemoteException e) {
+ logE("Unable to report transition finish!", e);
+ }
+ mStartTransaction = null;
+ mOriginTransaction = null;
+ mFinishCallback = null;
+ }
+
+ private void cancel() {
+ if (mAnimator != null) {
+ mAnimator.cancel();
+ }
+ }
+
+ private static void logD(String msg) {
+ if (OriginTransitionSession.DEBUG) {
+ Log.d(TAG, msg);
+ }
+ }
+
+ private static void logE(String msg) {
+ Log.e(TAG, msg);
+ }
+
+ private static void logE(String msg, Throwable e) {
+ Log.e(TAG, msg, e);
+ }
+
+ private static UIComponent wrapSurfaces(TransitionInfo info, boolean isOpening) {
+ List<SurfaceControl> surfaces = new ArrayList<>();
+ Rect maxBounds = new Rect();
+ for (Change change : info.getChanges()) {
+ int mode = change.getMode();
+ if (TransitionUtil.isOpeningMode(mode) == isOpening) {
+ surfaces.add(change.getLeash());
+ Rect bounds = isOpening ? change.getEndAbsBounds() : change.getStartAbsBounds();
+ maxBounds.union(bounds);
+ }
+ }
+ return new SurfaceUIComponent(
+ surfaces,
+ /* alpha= */ 1.0f,
+ /* visible= */ true,
+ /* bounds= */ maxBounds,
+ /* baseBounds= */ maxBounds);
+ }
+
+ /** An interface that represents an origin transitions. */
+ public interface TransitionPlayer {
+
+ /**
+ * Called when an origin transition starts. This method exposes the raw {@link
+ * TransitionInfo} so that clients can extract more information from it.
+ */
+ default void onStart(
+ TransitionInfo transitionInfo,
+ SurfaceControl.Transaction sfTransaction,
+ UIComponent origin,
+ UIComponent.Transaction uiTransaction) {
+ // Wrap transactions.
+ Transactions transactions =
+ new Transactions()
+ .registerTransactionForClass(origin.getClass(), uiTransaction)
+ .registerTransactionForClass(
+ SurfaceUIComponent.class,
+ new SurfaceUIComponent.Transaction(sfTransaction));
+ // Wrap surfaces and start.
+ onStart(
+ transactions,
+ origin,
+ wrapSurfaces(transitionInfo, /* isOpening= */ false),
+ wrapSurfaces(transitionInfo, /* isOpening= */ true));
+ }
+
+ /**
+ * Called when an origin transition starts. This method exposes the opening and closing
+ * windows as wrapped {@link UIComponent} to provide simplified interface to clients.
+ */
+ void onStart(
+ UIComponent.Transaction transaction,
+ UIComponent origin,
+ UIComponent closingApp,
+ UIComponent openingApp);
+
+ /** Called to update the transition frame. */
+ void onProgress(float progress);
+
+ /** Called when the transition ended. */
+ void onEnd(boolean finished);
+ }
+}
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginTransitionSession.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginTransitionSession.java
index 64bedd347d7a..23693b68a920 100644
--- a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginTransitionSession.java
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginTransitionSession.java
@@ -24,11 +24,14 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
+import android.os.Handler;
+import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.window.IRemoteTransition;
import android.window.RemoteTransition;
+import com.android.systemui.animation.OriginRemoteTransition.TransitionPlayer;
import com.android.systemui.animation.shared.IOriginTransitions;
import java.lang.annotation.Retention;
@@ -182,6 +185,7 @@ public class OriginTransitionSession {
@Nullable private final IOriginTransitions mOriginTransitions;
@Nullable private Supplier<IRemoteTransition> mEntryTransitionSupplier;
@Nullable private Supplier<IRemoteTransition> mExitTransitionSupplier;
+ private Handler mHandler = new Handler(Looper.getMainLooper());
private String mName;
@Nullable private Predicate<RemoteTransition> mIntentStarter;
@@ -259,12 +263,48 @@ public class OriginTransitionSession {
return this;
}
+ /** Add an origin entry transition to the builder. */
+ public Builder withEntryTransition(
+ UIComponent entryOrigin, TransitionPlayer entryPlayer, long entryDuration) {
+ mEntryTransitionSupplier =
+ () ->
+ new OriginRemoteTransition(
+ mContext,
+ /* isEntry= */ true,
+ entryOrigin,
+ entryPlayer,
+ entryDuration,
+ mHandler);
+ return this;
+ }
+
/** Add an exit transition to the builder. */
public Builder withExitTransition(IRemoteTransition transition) {
mExitTransitionSupplier = () -> transition;
return this;
}
+ /** Add an origin exit transition to the builder. */
+ public Builder withExitTransition(
+ UIComponent exitTarget, TransitionPlayer exitPlayer, long exitDuration) {
+ mExitTransitionSupplier =
+ () ->
+ new OriginRemoteTransition(
+ mContext,
+ /* isEntry= */ false,
+ exitTarget,
+ exitPlayer,
+ exitDuration,
+ mHandler);
+ return this;
+ }
+
+ /** Supply a handler where transition callbacks will run. */
+ public Builder withHandler(Handler handler) {
+ mHandler = handler;
+ return this;
+ }
+
/** Build an {@link OriginTransitionSession}. */
public OriginTransitionSession build() {
if (mIntentStarter == null) {
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/SurfaceUIComponent.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/SurfaceUIComponent.java
new file mode 100644
index 000000000000..24387360936b
--- /dev/null
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/SurfaceUIComponent.java
@@ -0,0 +1,169 @@
+/*
+ * 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.animation;
+
+import android.graphics.Matrix;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.view.SurfaceControl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.Executor;
+
+/** A {@link UIComponent} representing a {@link SurfaceControl}. */
+public class SurfaceUIComponent implements UIComponent {
+ private final Collection<SurfaceControl> mSurfaces;
+ private final Rect mBaseBounds;
+ private final float[] mFloat9 = new float[9];
+
+ private float mAlpha;
+ private boolean mVisible;
+ private Rect mBounds;
+
+ public SurfaceUIComponent(
+ SurfaceControl sc, float alpha, boolean visible, Rect bounds, Rect baseBounds) {
+ this(Arrays.asList(sc), alpha, visible, bounds, baseBounds);
+ }
+
+ public SurfaceUIComponent(
+ Collection<SurfaceControl> surfaces,
+ float alpha,
+ boolean visible,
+ Rect bounds,
+ Rect baseBounds) {
+ mSurfaces = surfaces;
+ mAlpha = alpha;
+ mVisible = visible;
+ mBounds = bounds;
+ mBaseBounds = baseBounds;
+ }
+
+ @Override
+ public float getAlpha() {
+ return mAlpha;
+ }
+
+ @Override
+ public boolean isVisible() {
+ return mVisible;
+ }
+
+ @Override
+ public Rect getBounds() {
+ return mBounds;
+ }
+
+ @Override
+ public Transaction newTransaction() {
+ return new Transaction(new SurfaceControl.Transaction());
+ }
+
+ @Override
+ public String toString() {
+ return "SurfaceUIComponent{mSurfaces="
+ + mSurfaces
+ + ", mAlpha="
+ + mAlpha
+ + ", mVisible="
+ + mVisible
+ + ", mBounds="
+ + mBounds
+ + ", mBaseBounds="
+ + mBaseBounds
+ + "}";
+ }
+
+ /** A {@link Transaction} wrapping a {@link SurfaceControl.Transaction}. */
+ public static class Transaction implements UIComponent.Transaction<SurfaceUIComponent> {
+ private final SurfaceControl.Transaction mTransaction;
+ private final ArrayList<Runnable> mChanges = new ArrayList<>();
+
+ public Transaction(SurfaceControl.Transaction transaction) {
+ mTransaction = transaction;
+ }
+
+ @Override
+ public Transaction setAlpha(SurfaceUIComponent ui, float alpha) {
+ mChanges.add(
+ () -> {
+ ui.mAlpha = alpha;
+ ui.mSurfaces.forEach(s -> mTransaction.setAlpha(s, alpha));
+ });
+ return this;
+ }
+
+ @Override
+ public Transaction setVisible(SurfaceUIComponent ui, boolean visible) {
+ mChanges.add(
+ () -> {
+ ui.mVisible = visible;
+ if (visible) {
+ ui.mSurfaces.forEach(s -> mTransaction.show(s));
+ } else {
+ ui.mSurfaces.forEach(s -> mTransaction.hide(s));
+ }
+ });
+ return this;
+ }
+
+ @Override
+ public Transaction setBounds(SurfaceUIComponent ui, Rect bounds) {
+ mChanges.add(
+ () -> {
+ if (ui.mBounds.equals(bounds)) {
+ return;
+ }
+ ui.mBounds = bounds;
+ Matrix matrix = new Matrix();
+ matrix.setRectToRect(
+ new RectF(ui.mBaseBounds),
+ new RectF(ui.mBounds),
+ Matrix.ScaleToFit.FILL);
+ ui.mSurfaces.forEach(s -> mTransaction.setMatrix(s, matrix, ui.mFloat9));
+ });
+ return this;
+ }
+
+ @Override
+ public Transaction attachToTransitionLeash(
+ SurfaceUIComponent ui, SurfaceControl transitionLeash, int w, int h) {
+ mChanges.add(
+ () -> ui.mSurfaces.forEach(s -> mTransaction.reparent(s, transitionLeash)));
+ return this;
+ }
+
+ @Override
+ public Transaction detachFromTransitionLeash(
+ SurfaceUIComponent ui, Executor executor, Runnable onDone) {
+ mChanges.add(
+ () -> {
+ ui.mSurfaces.forEach(s -> mTransaction.reparent(s, null));
+ mTransaction.addTransactionCommittedListener(executor, onDone::run);
+ });
+ return this;
+ }
+
+ @Override
+ public void commit() {
+ mChanges.forEach(Runnable::run);
+ mChanges.clear();
+ mTransaction.apply();
+ }
+ }
+}
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/Transactions.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/Transactions.java
new file mode 100644
index 000000000000..5240d99a9217
--- /dev/null
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/Transactions.java
@@ -0,0 +1,86 @@
+/*
+ * 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.animation;
+
+import android.annotation.FloatRange;
+import android.graphics.Rect;
+import android.util.ArrayMap;
+import android.view.SurfaceControl;
+
+import java.util.Map;
+import java.util.concurrent.Executor;
+
+/**
+ * A composite {@link UIComponent.Transaction} that combines multiple other transactions for each ui
+ * type.
+ */
+public class Transactions implements UIComponent.Transaction<UIComponent> {
+ private final Map<Class, UIComponent.Transaction> mTransactions = new ArrayMap<>();
+
+ /** Register a transaction object for updating a certain {@link UIComponent} type. */
+ public <T extends UIComponent> Transactions registerTransactionForClass(
+ Class<T> clazz, UIComponent.Transaction transaction) {
+ mTransactions.put(clazz, transaction);
+ return this;
+ }
+
+ private UIComponent.Transaction getTransactionFor(UIComponent ui) {
+ UIComponent.Transaction transaction = mTransactions.get(ui.getClass());
+ if (transaction == null) {
+ transaction = ui.newTransaction();
+ mTransactions.put(ui.getClass(), transaction);
+ }
+ return transaction;
+ }
+
+ @Override
+ public Transactions setAlpha(UIComponent ui, @FloatRange(from = 0.0, to = 1.0) float alpha) {
+ getTransactionFor(ui).setAlpha(ui, alpha);
+ return this;
+ }
+
+ @Override
+ public Transactions setVisible(UIComponent ui, boolean visible) {
+ getTransactionFor(ui).setVisible(ui, visible);
+ return this;
+ }
+
+ @Override
+ public Transactions setBounds(UIComponent ui, Rect bounds) {
+ getTransactionFor(ui).setBounds(ui, bounds);
+ return this;
+ }
+
+ @Override
+ public Transactions attachToTransitionLeash(
+ UIComponent ui, SurfaceControl transitionLeash, int w, int h) {
+ getTransactionFor(ui).attachToTransitionLeash(ui, transitionLeash, w, h);
+ return this;
+ }
+
+ @Override
+ public Transactions detachFromTransitionLeash(
+ UIComponent ui, Executor executor, Runnable onDone) {
+ getTransactionFor(ui).detachFromTransitionLeash(ui, executor, onDone);
+ return this;
+ }
+
+ @Override
+ public void commit() {
+ mTransactions.values().forEach(UIComponent.Transaction::commit);
+ }
+}
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/UIComponent.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/UIComponent.java
new file mode 100644
index 000000000000..747e4d1eb278
--- /dev/null
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/UIComponent.java
@@ -0,0 +1,72 @@
+/*
+ * 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.animation;
+
+import android.annotation.FloatRange;
+import android.graphics.Rect;
+import android.view.SurfaceControl;
+
+import java.util.concurrent.Executor;
+
+/** An interface representing an UI component on the display. */
+public interface UIComponent {
+
+ /** Get the current alpha of this UI. */
+ float getAlpha();
+
+ /** Check if this UI is visible. */
+ boolean isVisible();
+
+ /** Get the bounds of this UI in its display. */
+ Rect getBounds();
+
+ /** Create a new {@link Transaction} that can update this UI. */
+ Transaction newTransaction();
+
+ /**
+ * A transaction class for updating {@link UIComponent}.
+ *
+ * @param <T> the subtype of {@link UIComponent} that this {@link Transaction} can handle.
+ */
+ interface Transaction<T extends UIComponent> {
+ /** Update alpha of an UI. Execution will be delayed until {@link #commit()} is called. */
+ Transaction setAlpha(T ui, @FloatRange(from = 0.0, to = 1.0) float alpha);
+
+ /**
+ * Update visibility of an UI. Execution will be delayed until {@link #commit()} is called.
+ */
+ Transaction setVisible(T ui, boolean visible);
+
+ /** Update bounds of an UI. Execution will be delayed until {@link #commit()} is called. */
+ Transaction setBounds(T ui, Rect bounds);
+
+ /**
+ * Attach a ui to the transition leash. Execution will be delayed until {@link #commit()} is
+ * called.
+ */
+ Transaction attachToTransitionLeash(T ui, SurfaceControl transitionLeash, int w, int h);
+
+ /**
+ * Detach a ui from the transition leash. Execution will be delayed until {@link #commit} is
+ * called.
+ */
+ Transaction detachFromTransitionLeash(T ui, Executor executor, Runnable onDone);
+
+ /** Commit any pending changes added to this transaction. */
+ void commit();
+ }
+}
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java
new file mode 100644
index 000000000000..313789c4ca7e
--- /dev/null
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java
@@ -0,0 +1,278 @@
+/*
+ * 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.animation;
+
+import android.annotation.Nullable;
+import android.graphics.Canvas;
+import android.graphics.PorterDuff;
+import android.graphics.Rect;
+import android.os.Build;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver.OnDrawListener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executor;
+
+/**
+ * A {@link UIComponent} wrapping a {@link View}. After being attached to the transition leash, this
+ * class will draw the content of the {@link View} directly into the leash, and the actual View will
+ * be changed to INVISIBLE in its view tree. This allows the {@link View} to transform in the
+ * full-screen size leash without being constrained by the view tree's boundary or inheriting its
+ * parent's alpha and transformation.
+ */
+public class ViewUIComponent implements UIComponent {
+ private static final String TAG = "ViewUIComponent";
+ private static final boolean DEBUG = Build.IS_USERDEBUG || Log.isLoggable(TAG, Log.DEBUG);
+ private final OnDrawListener mOnDrawListener = this::postDraw;
+ private final View mView;
+
+ @Nullable private SurfaceControl mSurfaceControl;
+ @Nullable private Surface mSurface;
+ @Nullable private Rect mViewBoundsOverride;
+ private boolean mVisibleOverride;
+ private boolean mDirty;
+
+ public ViewUIComponent(View view) {
+ mView = view;
+ }
+
+ @Override
+ public float getAlpha() {
+ return mView.getAlpha();
+ }
+
+ @Override
+ public boolean isVisible() {
+ return isAttachedToLeash() ? mVisibleOverride : mView.getVisibility() == View.VISIBLE;
+ }
+
+ @Override
+ public Rect getBounds() {
+ if (isAttachedToLeash() && mViewBoundsOverride != null) {
+ return mViewBoundsOverride;
+ }
+ return getRealBounds();
+ }
+
+ @Override
+ public Transaction newTransaction() {
+ return new Transaction();
+ }
+
+ private void attachToTransitionLeash(SurfaceControl transitionLeash, int w, int h) {
+ logD("attachToTransitionLeash");
+ // Remember current visibility.
+ mVisibleOverride = mView.getVisibility() == View.VISIBLE;
+
+ // Create the surface
+ mSurfaceControl =
+ new SurfaceControl.Builder().setName("ViewUIComponent").setBufferSize(w, h).build();
+ mSurface = new Surface(mSurfaceControl);
+ forceDraw();
+
+ // Attach surface to transition leash
+ SurfaceControl.Transaction t = new SurfaceControl.Transaction();
+ t.reparent(mSurfaceControl, transitionLeash).show(mSurfaceControl);
+
+ // Make sure view draw triggers surface draw.
+ mView.getViewTreeObserver().addOnDrawListener(mOnDrawListener);
+
+ // Make the view invisible AFTER the surface is shown.
+ t.addTransactionCommittedListener(
+ mView.getContext().getMainExecutor(),
+ () -> mView.setVisibility(View.INVISIBLE))
+ .apply();
+ }
+
+ private void detachFromTransitionLeash(Executor executor, Runnable onDone) {
+ logD("detachFromTransitionLeash");
+ Surface s = mSurface;
+ SurfaceControl sc = mSurfaceControl;
+ mSurface = null;
+ mSurfaceControl = null;
+ mView.getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
+ // Restore view visibility
+ mView.setVisibility(mVisibleOverride ? View.VISIBLE : View.INVISIBLE);
+ mView.invalidate();
+ // Clean up surfaces.
+ SurfaceControl.Transaction t = new SurfaceControl.Transaction();
+ t.reparent(sc, null)
+ .addTransactionCommittedListener(
+ mView.getContext().getMainExecutor(),
+ () -> {
+ s.release();
+ sc.release();
+ executor.execute(onDone);
+ });
+ // Apply transaction AFTER the view is drawn.
+ mView.getRootSurfaceControl().applyTransactionOnDraw(t);
+ }
+
+ @Override
+ public String toString() {
+ return "ViewUIComponent{"
+ + "alpha="
+ + getAlpha()
+ + ", visible="
+ + isVisible()
+ + ", bounds="
+ + getBounds()
+ + ", attached="
+ + isAttachedToLeash()
+ + "}";
+ }
+
+ private void draw() {
+ if (!mDirty) {
+ // No need to draw. This is probably a duplicate call.
+ logD("draw: skipped - clean");
+ return;
+ }
+ mDirty = false;
+ if (!isAttachedToLeash()) {
+ // Not attached.
+ logD("draw: skipped - not attached");
+ return;
+ }
+ ViewGroup.LayoutParams params = mView.getLayoutParams();
+ if (params == null || params.width == 0 || params.height == 0) {
+ // layout pass didn't happen.
+ logD("draw: skipped - no layout");
+ return;
+ }
+ Canvas canvas = mSurface.lockHardwareCanvas();
+ // Clear the canvas first.
+ canvas.drawColor(0, PorterDuff.Mode.CLEAR);
+ if (mVisibleOverride) {
+ Rect realBounds = getRealBounds();
+ Rect renderBounds = getBounds();
+ canvas.translate(renderBounds.left, renderBounds.top);
+ canvas.scale(
+ (float) renderBounds.width() / realBounds.width(),
+ (float) renderBounds.height() / realBounds.height());
+ canvas.saveLayerAlpha(null, (int) (255 * mView.getAlpha()));
+ mView.draw(canvas);
+ canvas.restore();
+ }
+ mSurface.unlockCanvasAndPost(canvas);
+ logD("draw: done");
+ }
+
+ private void forceDraw() {
+ mDirty = true;
+ draw();
+ }
+
+ private Rect getRealBounds() {
+ Rect output = new Rect();
+ mView.getBoundsOnScreen(output);
+ return output;
+ }
+
+ private boolean isAttachedToLeash() {
+ return mSurfaceControl != null && mSurface != null;
+ }
+
+ private void logD(String msg) {
+ if (DEBUG) {
+ Log.d(TAG, msg);
+ }
+ }
+
+ private void setVisible(boolean visible) {
+ logD("setVisibility: " + visible);
+ if (isAttachedToLeash()) {
+ mVisibleOverride = visible;
+ postDraw();
+ } else {
+ mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
+ }
+ }
+
+ private void setBounds(Rect bounds) {
+ logD("setBounds: " + bounds);
+ mViewBoundsOverride = bounds;
+ if (isAttachedToLeash()) {
+ postDraw();
+ } else {
+ Log.w(TAG, "setBounds: not attached to leash!");
+ }
+ }
+
+ private void setAlpha(float alpha) {
+ logD("setAlpha: " + alpha);
+ mView.setAlpha(alpha);
+ if (isAttachedToLeash()) {
+ postDraw();
+ }
+ }
+
+ private void postDraw() {
+ if (mDirty) {
+ return;
+ }
+ mDirty = true;
+ mView.post(this::draw);
+ }
+
+ public static class Transaction implements UIComponent.Transaction<ViewUIComponent> {
+ private final List<Runnable> mChanges = new ArrayList<>();
+
+ @Override
+ public Transaction setAlpha(ViewUIComponent ui, float alpha) {
+ mChanges.add(() -> ui.setAlpha(alpha));
+ return this;
+ }
+
+ @Override
+ public Transaction setVisible(ViewUIComponent ui, boolean visible) {
+ mChanges.add(() -> ui.setVisible(visible));
+ return this;
+ }
+
+ @Override
+ public Transaction setBounds(ViewUIComponent ui, Rect bounds) {
+ mChanges.add(() -> ui.setBounds(bounds));
+ return this;
+ }
+
+ @Override
+ public Transaction attachToTransitionLeash(
+ ViewUIComponent ui, SurfaceControl transitionLeash, int w, int h) {
+ mChanges.add(() -> ui.attachToTransitionLeash(transitionLeash, w, h));
+ return this;
+ }
+
+ @Override
+ public Transaction detachFromTransitionLeash(
+ ViewUIComponent ui, Executor executor, Runnable onDone) {
+ mChanges.add(() -> ui.detachFromTransitionLeash(executor, onDone));
+ return this;
+ }
+
+ @Override
+ public void commit() {
+ mChanges.forEach(Runnable::run);
+ mChanges.clear();
+ }
+ }
+}
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt b/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt
index a5f8057b524f..20efea513b3a 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt
@@ -28,11 +28,11 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.IconButtonDefaults
+import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
@Composable
fun PlatformButton(
@@ -100,12 +100,7 @@ fun PlatformIconButton(
@DrawableRes iconResource: Int,
contentDescription: String?,
) {
- IconButton(
- modifier = modifier,
- onClick = onClick,
- enabled = enabled,
- colors = colors,
- ) {
+ IconButton(modifier = modifier, onClick = onClick, enabled = enabled, colors = colors) {
Icon(
painter = painterResource(id = iconResource),
contentDescription = contentDescription,
@@ -118,7 +113,7 @@ private val ButtonPaddings = PaddingValues(horizontal = 16.dp, vertical = 8.dp)
@Composable
private fun filledButtonColors(): ButtonColors {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
return ButtonDefaults.buttonColors(
containerColor = colors.primary,
contentColor = colors.onPrimary,
@@ -127,27 +122,22 @@ private fun filledButtonColors(): ButtonColors {
@Composable
private fun outlineButtonColors(): ButtonColors {
- return ButtonDefaults.outlinedButtonColors(
- contentColor = LocalAndroidColorScheme.current.onSurface,
- )
+ return ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colorScheme.onSurface)
}
@Composable
private fun iconButtonColors(): IconButtonColors {
return IconButtonDefaults.filledIconButtonColors(
- contentColor = LocalAndroidColorScheme.current.onSurface,
+ contentColor = MaterialTheme.colorScheme.onSurface
)
}
@Composable
private fun outlineButtonBorder(): BorderStroke {
- return BorderStroke(
- width = 1.dp,
- color = LocalAndroidColorScheme.current.primary,
- )
+ return BorderStroke(width = 1.dp, color = MaterialTheme.colorScheme.primary)
}
@Composable
private fun textButtonColors(): ButtonColors {
- return ButtonDefaults.textButtonColors(contentColor = LocalAndroidColorScheme.current.primary)
+ return ButtonDefaults.textButtonColors(contentColor = MaterialTheme.colorScheme.primary)
}
diff --git a/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/scene/LockscreenSceneModule.kt b/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/scene/LockscreenSceneModule.kt
index bfeaf928dfe8..0f6e6a7c4383 100644
--- a/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/scene/LockscreenSceneModule.kt
+++ b/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/scene/LockscreenSceneModule.kt
@@ -28,6 +28,7 @@ import com.android.systemui.keyguard.ui.composable.LockscreenSceneBlueprintModul
import com.android.systemui.keyguard.ui.composable.blueprint.ComposableLockscreenSceneBlueprint
import com.android.systemui.keyguard.ui.viewmodel.LockscreenContentViewModel
import com.android.systemui.scene.ui.composable.Scene
+import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationLockscreenScrimViewModel
import dagger.Binds
import dagger.Module
import dagger.Provides
@@ -35,12 +36,7 @@ import dagger.multibindings.IntoSet
import javax.inject.Provider
import kotlinx.coroutines.ExperimentalCoroutinesApi
-@Module(
- includes =
- [
- LockscreenSceneBlueprintModule::class,
- ],
-)
+@Module(includes = [LockscreenSceneBlueprintModule::class])
interface LockscreenSceneModule {
@Binds @IntoSet fun lockscreenScene(scene: LockscreenScene): Scene
@@ -51,9 +47,7 @@ interface LockscreenSceneModule {
@Provides
@SysUISingleton
@KeyguardRootView
- fun viewProvider(
- configurator: Provider<KeyguardViewConfigurator>,
- ): () -> View {
+ fun viewProvider(configurator: Provider<KeyguardViewConfigurator>): () -> View {
return { configurator.get().getKeyguardRootView() }
}
@@ -67,10 +61,16 @@ interface LockscreenSceneModule {
@Provides
fun providesLockscreenContent(
viewModelFactory: LockscreenContentViewModel.Factory,
+ notificationScrimViewModelFactory: NotificationLockscreenScrimViewModel.Factory,
blueprints: Set<@JvmSuppressWildcards ComposableLockscreenSceneBlueprint>,
clockInteractor: KeyguardClockInteractor,
): LockscreenContent {
- return LockscreenContent(viewModelFactory, blueprints, clockInteractor)
+ return LockscreenContent(
+ viewModelFactory,
+ notificationScrimViewModelFactory,
+ blueprints,
+ clockInteractor,
+ )
}
}
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/dialog/ui/composable/AlertDialogContent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/dialog/ui/composable/AlertDialogContent.kt
index 0b9669410b8e..69ca0a5f476c 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/dialog/ui/composable/AlertDialogContent.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/dialog/ui/composable/AlertDialogContent.kt
@@ -38,7 +38,6 @@ import androidx.compose.ui.layout.Placeable
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
import kotlin.math.roundToInt
/**
@@ -69,7 +68,7 @@ fun AlertDialogContent(
Modifier.defaultMinSize(minWidth = defaultSize, minHeight = defaultSize),
propagateMinConstraints = true,
) {
- val iconColor = LocalAndroidColorScheme.current.primary
+ val iconColor = MaterialTheme.colorScheme.primary
CompositionLocalProvider(LocalContentColor provides iconColor) { icon() }
}
@@ -77,7 +76,7 @@ fun AlertDialogContent(
}
// Title.
- val titleColor = LocalAndroidColorScheme.current.onSurface
+ val titleColor = MaterialTheme.colorScheme.onSurface
CompositionLocalProvider(LocalContentColor provides titleColor) {
ProvideTextStyle(
MaterialTheme.typography.headlineSmall.copy(textAlign = TextAlign.Center)
@@ -88,7 +87,7 @@ fun AlertDialogContent(
Spacer(Modifier.height(16.dp))
// Content.
- val contentColor = LocalAndroidColorScheme.current.onSurfaceVariant
+ val contentColor = MaterialTheme.colorScheme.onSurfaceVariant
Box {
CompositionLocalProvider(LocalContentColor provides contentColor) {
ProvideTextStyle(
@@ -169,7 +168,7 @@ private fun AlertDialogButtons(
negative.width -
positive.width -
horizontalSpacing.roundToInt(),
- 0
+ 0,
)
}
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/LockscreenContent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/LockscreenContent.kt
index dbe75382556f..5c5514aec03e 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/LockscreenContent.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/LockscreenContent.kt
@@ -30,6 +30,8 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.ui.composable.blueprint.ComposableLockscreenSceneBlueprint
import com.android.systemui.keyguard.ui.viewmodel.LockscreenContentViewModel
import com.android.systemui.lifecycle.rememberViewModel
+import com.android.systemui.notifications.ui.composable.NotificationLockscreenScrim
+import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationLockscreenScrimViewModel
/**
* Renders the content of the lockscreen.
@@ -39,6 +41,7 @@ import com.android.systemui.lifecycle.rememberViewModel
*/
class LockscreenContent(
private val viewModelFactory: LockscreenContentViewModel.Factory,
+ private val notificationScrimViewModelFactory: NotificationLockscreenScrimViewModel.Factory,
private val blueprints: Set<@JvmSuppressWildcards ComposableLockscreenSceneBlueprint>,
private val clockInteractor: KeyguardClockInteractor,
) {
@@ -47,10 +50,13 @@ class LockscreenContent(
}
@Composable
- fun SceneScope.Content(
- modifier: Modifier = Modifier,
- ) {
- val viewModel = rememberViewModel("LockscreenContent") { viewModelFactory.create() }
+ fun SceneScope.Content(modifier: Modifier = Modifier) {
+ val viewModel =
+ rememberViewModel("LockscreenContent-viewModel") { viewModelFactory.create() }
+ val notificationLockscreenScrimViewModel =
+ rememberViewModel("LockscreenContent-scrimViewModel") {
+ notificationScrimViewModelFactory.create()
+ }
val isContentVisible: Boolean by viewModel.isContentVisible.collectAsStateWithLifecycle()
if (!isContentVisible) {
// If the content isn't supposed to be visible, show a large empty box as it's needed
@@ -71,6 +77,9 @@ class LockscreenContent(
}
val blueprint = blueprintByBlueprintId[blueprintId] ?: return
- with(blueprint) { Content(viewModel, modifier.sysuiResTag("keyguard_root_view")) }
+ with(blueprint) {
+ Content(viewModel, modifier.sysuiResTag("keyguard_root_view"))
+ NotificationLockscreenScrim(notificationLockscreenScrimViewModel)
+ }
}
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/NotificationLockscreenScrim.kt b/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/NotificationLockscreenScrim.kt
new file mode 100644
index 000000000000..4279be3efad0
--- /dev/null
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/NotificationLockscreenScrim.kt
@@ -0,0 +1,119 @@
+/*
+ * 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.notifications.ui.composable
+
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.lifecycle.compose.collectAsStateWithLifecycle
+import com.android.compose.animation.scene.SceneScope
+import com.android.compose.animation.scene.content.state.TransitionState
+import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.shared.model.ShadeMode
+import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationLockscreenScrimViewModel
+import kotlinx.coroutines.launch
+
+/**
+ * A full-screen notifications scrim that is only visible after transitioning from Shade scene to
+ * Lockscreen Scene and ending user input, at which point it fades out, visually completing the
+ * transition.
+ */
+@Composable
+fun SceneScope.NotificationLockscreenScrim(
+ viewModel: NotificationLockscreenScrimViewModel,
+ modifier: Modifier = Modifier,
+) {
+ val coroutineScope = rememberCoroutineScope()
+ val shadeMode = viewModel.shadeMode.collectAsStateWithLifecycle()
+
+ // Important: Make sure that shouldShowScrimFadeOut() is checked the first time the Lockscreen
+ // scene is composed.
+ val useFadeOutOnComposition =
+ remember(shadeMode.value) {
+ layoutState.currentTransition?.let { currentTransition ->
+ shouldShowScrimFadeOut(currentTransition, shadeMode.value)
+ } ?: false
+ }
+
+ val alphaAnimatable = remember { Animatable(1f) }
+
+ LaunchedEffect(
+ alphaAnimatable,
+ layoutState.currentTransition,
+ useFadeOutOnComposition,
+ shadeMode,
+ ) {
+ val currentTransition = layoutState.currentTransition
+ if (
+ useFadeOutOnComposition &&
+ currentTransition != null &&
+ shouldShowScrimFadeOut(currentTransition, shadeMode.value) &&
+ currentTransition.isUserInputOngoing
+ ) {
+ // keep scrim visible until user lifts their finger.
+ viewModel.setAlphaForLockscreenFadeIn(0f)
+ alphaAnimatable.snapTo(1f)
+ } else if (
+ useFadeOutOnComposition &&
+ (currentTransition == null ||
+ (shouldShowScrimFadeOut(currentTransition, shadeMode.value) &&
+ !currentTransition.isUserInputOngoing))
+ ) {
+ // we no longer want to keep the scrim from fading out, so animate the scrim fade-out
+ // and pipe the progress to the view model as well, so NSSL can fade-in the stack in
+ // tandem.
+ viewModel.setAlphaForLockscreenFadeIn(0f)
+ coroutineScope.launch {
+ snapshotFlow { alphaAnimatable.value }
+ .collect { viewModel.setAlphaForLockscreenFadeIn(1 - it) }
+ }
+ alphaAnimatable.animateTo(0f, tween())
+ } else {
+ // disable the scrim fade logic.
+ viewModel.setAlphaForLockscreenFadeIn(1f)
+ alphaAnimatable.snapTo(0f)
+ }
+ }
+
+ Box(
+ modifier
+ .fillMaxSize()
+ .element(Notifications.Elements.NotificationScrim)
+ .graphicsLayer { alpha = alphaAnimatable.value }
+ .background(MaterialTheme.colorScheme.surface)
+ )
+}
+
+private fun shouldShowScrimFadeOut(
+ currentTransition: TransitionState.Transition,
+ shadeMode: ShadeMode,
+): Boolean {
+ return shadeMode == ShadeMode.Single &&
+ currentTransition.isInitiatedByUserInput &&
+ (currentTransition.isTransitioning(from = Scenes.Shade, to = Scenes.Lockscreen) ||
+ currentTransition.isTransitioning(from = Scenes.Bouncer, to = Scenes.Lockscreen))
+}
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 fe4a65b8bbd0..2066c9314bc7 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
@@ -86,6 +86,8 @@ import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.LowestZIndexContentPicker
import com.android.compose.animation.scene.NestedScrollBehavior
import com.android.compose.animation.scene.SceneScope
+import com.android.compose.animation.scene.SceneTransitionLayoutState
+import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.modifiers.thenIf
import com.android.systemui.common.ui.compose.windowinsets.LocalScreenCornerRadius
import com.android.systemui.res.R
@@ -101,7 +103,7 @@ import com.android.systemui.statusbar.notification.stack.ui.viewmodel.Notificati
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationTransitionThresholds.EXPANSION_FOR_MAX_SCRIM_ALPHA
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationsPlaceholderViewModel
import kotlin.math.roundToInt
-import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
object Notifications {
@@ -251,6 +253,7 @@ fun SceneScope.ConstrainedNotificationStack(
NotificationPlaceholder(
stackScrollView = stackScrollView,
viewModel = viewModel,
+ useStackBounds = { shouldUseLockscreenStackBounds(layoutState.transitionState) },
modifier = Modifier.fillMaxSize(),
)
HeadsUpNotificationSpace(
@@ -363,7 +366,6 @@ fun SceneScope.NotificationScrollingStack(
snapshotFlow { syntheticScroll.value }
.collect { delta ->
scrollNotificationStack(
- scope = coroutineScope,
delta = delta,
animate = false,
scrimOffset = scrimOffset,
@@ -383,7 +385,6 @@ fun SceneScope.NotificationScrollingStack(
// composed at least once), and our remote input row overlaps with the ime bounds.
if (isRemoteInputActive && imeTopValue > 0f && remoteInputRowBottom > imeTopValue) {
scrollNotificationStack(
- scope = coroutineScope,
delta = remoteInputRowBottom - imeTopValue,
animate = true,
scrimOffset = scrimOffset,
@@ -450,7 +451,10 @@ fun SceneScope.NotificationScrollingStack(
scrimCornerRadius,
screenCornerRadius,
{ expansionFraction },
- shouldPunchHoleBehindScrim,
+ shouldAnimateScrimCornerRadius(
+ layoutState,
+ shouldPunchHoleBehindScrim,
+ ),
)
.let { scrimRounding.value.toRoundedCornerShape(it) }
clip = true
@@ -514,6 +518,9 @@ fun SceneScope.NotificationScrollingStack(
NotificationPlaceholder(
stackScrollView = stackScrollView,
viewModel = viewModel,
+ useStackBounds = {
+ !shouldUseLockscreenStackBounds(layoutState.transitionState)
+ },
modifier =
Modifier.notificationStackHeight(
view = stackScrollView,
@@ -600,6 +607,7 @@ fun SceneScope.NotificationStackCutoffGuideline(
private fun SceneScope.NotificationPlaceholder(
stackScrollView: NotificationScrollView,
viewModel: NotificationsPlaceholderViewModel,
+ useStackBounds: () -> Boolean,
modifier: Modifier = Modifier,
) {
Box(
@@ -609,21 +617,26 @@ private fun SceneScope.NotificationPlaceholder(
.debugBackground(viewModel, DEBUG_STACK_COLOR)
.onSizeChanged { size -> debugLog(viewModel) { "STACK onSizeChanged: size=$size" } }
.onGloballyPositioned { coordinates: LayoutCoordinates ->
- val positionInWindow = coordinates.positionInWindow()
- debugLog(viewModel) {
- "STACK onGloballyPositioned:" +
- " size=${coordinates.size}" +
- " position=$positionInWindow" +
- " bounds=${coordinates.boundsInWindow()}"
+ // This element is opted out of the shared element system, so there can be
+ // multiple instances of it during a transition. Thus we need to determine which
+ // instance should feed its bounds to NSSL to avoid providing conflicting values
+ val useBounds = useStackBounds()
+ if (useBounds) {
+ // NOTE: positionInWindow.y scrolls off screen, but boundsInWindow.top won't
+ val positionInWindow = coordinates.positionInWindow()
+ debugLog(viewModel) {
+ "STACK onGloballyPositioned:" +
+ " size=${coordinates.size}" +
+ " position=$positionInWindow" +
+ " bounds=${coordinates.boundsInWindow()}"
+ }
+ stackScrollView.setStackTop(positionInWindow.y)
}
- // NOTE: positionInWindow.y scrolls off screen, but boundsInWindow.top will not
- stackScrollView.setStackTop(positionInWindow.y)
}
)
}
private suspend fun scrollNotificationStack(
- scope: CoroutineScope,
delta: Float,
animate: Boolean,
scrimOffset: Animatable<Float, AnimationVector1D>,
@@ -638,7 +651,7 @@ private suspend fun scrollNotificationStack(
if (animate) {
// launch a new coroutine for the remainder animation so that it doesn't suspend the
// scrim animation, allowing both to play simultaneously.
- scope.launch { scrollState.animateScrollTo(remainingDelta) }
+ coroutineScope { launch { scrollState.animateScrollTo(remainingDelta) } }
} else {
scrollState.scrollTo(remainingDelta)
}
@@ -658,6 +671,18 @@ private suspend fun scrollNotificationStack(
}
}
+private fun shouldUseLockscreenStackBounds(state: TransitionState): Boolean {
+ return state is TransitionState.Idle && state.currentScene == Scenes.Lockscreen
+}
+
+private fun shouldAnimateScrimCornerRadius(
+ state: SceneTransitionLayoutState,
+ shouldPunchHoleBehindScrim: Boolean,
+): Boolean {
+ return shouldPunchHoleBehindScrim ||
+ state.isTransitioning(from = Scenes.Shade, to = Scenes.Lockscreen)
+}
+
private fun calculateCornerRadius(
scrimCornerRadius: Dp,
screenCornerRadius: Dp,
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt
index 58fbf430b20c..303a6f0d942a 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt
@@ -82,18 +82,35 @@ val SceneContainerTransitions = transitions {
sharedElement(Notifications.Elements.HeadsUpNotificationPlaceholder, enabled = false)
}
from(Scenes.Shade, to = Scenes.QuickSettings) { shadeToQuickSettingsTransition() }
+ from(Scenes.Shade, to = Scenes.Lockscreen) {
+ reversed { lockscreenToShadeTransition() }
+ sharedElement(Notifications.Elements.NotificationStackPlaceholder, enabled = false)
+ }
// Overlay transitions
to(Overlays.NotificationsShade) { toNotificationsShadeTransition() }
to(Overlays.QuickSettingsShade) { toQuickSettingsShadeTransition() }
- from(Overlays.NotificationsShade, Overlays.QuickSettingsShade) {
+ from(Overlays.NotificationsShade, to = Overlays.QuickSettingsShade) {
notificationsShadeToQuickSettingsShadeTransition()
}
+ from(Scenes.Gone, to = Overlays.NotificationsShade, key = SlightlyFasterShadeCollapse) {
+ toNotificationsShadeTransition(durationScale = 0.9)
+ }
+ from(Scenes.Gone, to = Overlays.QuickSettingsShade, key = SlightlyFasterShadeCollapse) {
+ toQuickSettingsShadeTransition(durationScale = 0.9)
+ }
+ from(Scenes.Lockscreen, to = Overlays.NotificationsShade, key = SlightlyFasterShadeCollapse) {
+ toNotificationsShadeTransition(durationScale = 0.9)
+ }
+ from(Scenes.Lockscreen, to = Overlays.QuickSettingsShade, key = SlightlyFasterShadeCollapse) {
+ toQuickSettingsShadeTransition(durationScale = 0.9)
+ }
// Scene overscroll
overscrollDisabled(Scenes.Gone, Orientation.Vertical)
+ overscrollDisabled(Scenes.Lockscreen, Orientation.Vertical)
overscroll(Scenes.Bouncer, Orientation.Vertical) {
translate(Bouncer.Elements.Content, y = { absoluteDistance })
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/transitions/FromLockscreenToBouncerTransition.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/transitions/FromLockscreenToBouncerTransition.kt
index ac54896c5031..4c0efd2047ff 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/transitions/FromLockscreenToBouncerTransition.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/transitions/FromLockscreenToBouncerTransition.kt
@@ -4,13 +4,19 @@ import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.tween
import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.TransitionBuilder
+import com.android.compose.animation.scene.UserActionDistance
import com.android.systemui.bouncer.ui.composable.Bouncer
const val FROM_LOCK_SCREEN_TO_BOUNCER_FADE_FRACTION = 0.5f
+const val FROM_LOCK_SCREEN_TO_BOUNCER_SWIPE_DISTANCE_FRACTION = 0.5f
fun TransitionBuilder.lockscreenToBouncerTransition() {
spec = tween(durationMillis = 500)
+ distance = UserActionDistance { fromSceneSize, _ ->
+ fromSceneSize.height * FROM_LOCK_SCREEN_TO_BOUNCER_SWIPE_DISTANCE_FRACTION
+ }
+
translate(Bouncer.Elements.Content, y = 300.dp)
fractionRange(end = FROM_LOCK_SCREEN_TO_BOUNCER_FADE_FRACTION) {
fade(Bouncer.Elements.Background)
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt b/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt
index 7f2ee2a8351a..db0fe3e3f79d 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt
@@ -296,7 +296,7 @@ private fun SceneScope.SingleShade(
val shouldPunchHoleBehindScrim =
layoutState.isTransitioningBetween(Scenes.Gone, Scenes.Shade) ||
- layoutState.isTransitioningBetween(Scenes.Lockscreen, Scenes.Shade)
+ layoutState.isTransitioning(from = Scenes.Lockscreen, to = Scenes.Shade)
// Media is visible and we are in landscape on a small height screen
val mediaInRow = isMediaVisible && isLandscape()
val mediaOffset by
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneTransitionInteractorTest.kt
index e25c1a71a5a6..d5020a580d00 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneTransitionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneTransitionInteractorTest.kt
@@ -109,7 +109,9 @@ class CommunalSceneTransitionInteractorTest : SysuiTestCase() {
kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true)
underTest.start()
kosmos.communalSceneRepository.setTransitionState(sceneTransitions)
- testScope.launch { keyguardTransitionRepository.emitInitialStepsFromOff(LOCKSCREEN) }
+ testScope.launch {
+ keyguardTransitionRepository.emitInitialStepsFromOff(LOCKSCREEN, testSetup = true)
+ }
}
/** Transition from blank to glanceable hub. This is the default case. */
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractorTest.kt
index a08fbbf75805..fa304c99ecc9 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractorTest.kt
@@ -198,6 +198,13 @@ class FromDreamingTransitionInteractorTest(flags: FlagsParameterization?) : Sysu
@DisableFlags(Flags.FLAG_SCENE_CONTAINER)
fun testTransitionToGlanceableHubOnWake() =
testScope.runTest {
+ transitionRepository.sendTransitionSteps(
+ from = KeyguardState.LOCKSCREEN,
+ to = KeyguardState.DREAMING,
+ testScope,
+ )
+ reset(transitionRepository)
+
whenever(kosmos.dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
kosmos.setCommunalAvailable(true)
runCurrent()
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorTest.kt
index ba689179c33d..29035ce2aa0a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorTest.kt
@@ -38,7 +38,6 @@ import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.scene.data.repository.Idle
import com.android.systemui.scene.data.repository.Transition
import com.android.systemui.scene.data.repository.setSceneTransition
-import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.testKosmos
@@ -76,7 +75,6 @@ class KeyguardDismissActionInteractorTest : SysuiTestCase() {
transitionInteractor = kosmos.keyguardTransitionInteractor,
dismissInteractor = dismissInteractor,
applicationScope = testScope.backgroundScope,
- sceneInteractor = { kosmos.sceneInteractor },
deviceUnlockedInteractor = { kosmos.deviceUnlockedInteractor },
powerInteractor = kosmos.powerInteractor,
alternateBouncerInteractor = kosmos.alternateBouncerInteractor,
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelTest.kt
index 129752e4f106..aab46d8cb73a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelTest.kt
@@ -22,6 +22,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
+import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
import com.android.systemui.testKosmos
import org.junit.Before
import org.junit.Test
@@ -44,6 +45,7 @@ class KeyguardBlueprintViewModelTest : SysuiTestCase() {
KeyguardBlueprintViewModel(
handler = kosmos.fakeExecutorHandler,
keyguardBlueprintInteractor = keyguardBlueprintInteractor,
+ keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor,
)
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModelTest.kt
index e6ea64f8ee71..d0da2e9671c0 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModelTest.kt
@@ -89,9 +89,12 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
}
@Test
- fun lockscreenFadeOut() =
+ fun lockscreenFadeOut_shadeNotExpanded() =
testScope.runTest {
val values by collectValues(underTest.lockscreenAlpha)
+ shadeExpanded(false)
+ runCurrent()
+
repository.sendTransitionSteps(
steps =
listOf(
@@ -104,10 +107,34 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
),
testScope = testScope,
)
- // Only 5 values should be present, since the dream overlay runs for a small fraction
- // of the overall animation time
assertThat(values.size).isEqualTo(5)
- values.forEach { assertThat(it).isIn(Range.closed(0f, 1f)) }
+ assertThat(values[0]).isEqualTo(1f)
+ assertThat(values[1]).isEqualTo(1f)
+ assertThat(values[2]).isIn(Range.open(0f, 1f))
+ assertThat(values[3]).isIn(Range.open(0f, 1f))
+ assertThat(values[4]).isEqualTo(0f)
+ }
+
+ @Test
+ fun lockscreenFadeOut_shadeExpanded() =
+ testScope.runTest {
+ val values by collectValues(underTest.lockscreenAlpha)
+ shadeExpanded(true)
+ runCurrent()
+
+ repository.sendTransitionSteps(
+ steps =
+ listOf(
+ step(0f, TransitionState.STARTED), // Should start running here...
+ step(0f),
+ step(.1f),
+ step(.4f),
+ step(.7f), // ...up to here
+ step(1f),
+ ),
+ testScope = testScope,
+ )
+ values.forEach { assertThat(it).isEqualTo(0f) }
}
@Test
@@ -115,7 +142,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
testScope.runTest {
configurationRepository.setDimensionPixelSize(
R.dimen.lockscreen_to_occluded_transition_lockscreen_translation_y,
- 100
+ 100,
)
val values by collectValues(underTest.lockscreenTranslationY)
repository.sendTransitionSteps(
@@ -138,7 +165,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
testScope.runTest {
configurationRepository.setDimensionPixelSize(
R.dimen.lockscreen_to_occluded_transition_lockscreen_translation_y,
- 100
+ 100,
)
val values by collectValues(underTest.lockscreenTranslationY)
repository.sendTransitionSteps(
@@ -171,7 +198,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
listOf(
step(0f, TransitionState.STARTED),
step(.5f),
- step(1f, TransitionState.FINISHED)
+ step(1f, TransitionState.FINISHED),
),
testScope = testScope,
)
@@ -228,7 +255,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
to = KeyguardState.OCCLUDED,
value = value,
transitionState = state,
- ownerName = "LockscreenToOccludedTransitionViewModelTest"
+ ownerName = "LockscreenToOccludedTransitionViewModelTest",
)
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelTest.kt
new file mode 100644
index 000000000000..0b7a38eb9ebd
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelTest.kt
@@ -0,0 +1,94 @@
+/*
+ * 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.ui.viewmodel
+
+import android.platform.test.flag.junit.FlagsParameterization
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.flags.andSceneContainer
+import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
+import com.android.systemui.keyguard.shared.model.KeyguardState
+import com.android.systemui.keyguard.shared.model.TransitionState
+import com.android.systemui.keyguard.shared.model.TransitionStep
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.testKosmos
+import com.google.common.collect.Range
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import platform.test.runner.parameterized.ParameterizedAndroidJunit4
+import platform.test.runner.parameterized.Parameters
+
+@ExperimentalCoroutinesApi
+@SmallTest
+@RunWith(ParameterizedAndroidJunit4::class)
+class OffToLockscreenTransitionViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
+ val kosmos = testKosmos()
+ val testScope = kosmos.testScope
+ val repository = kosmos.fakeKeyguardTransitionRepository
+ lateinit var underTest: OffToLockscreenTransitionViewModel
+
+ companion object {
+ @JvmStatic
+ @Parameters(name = "{0}")
+ fun getParams(): List<FlagsParameterization> {
+ return FlagsParameterization.allCombinationsOf().andSceneContainer()
+ }
+ }
+
+ init {
+ mSetFlagsRule.setFlagsParameterization(flags)
+ }
+
+ @Before
+ fun setup() {
+ underTest = kosmos.offToLockscreenTransitionViewModel
+ }
+
+ @Test
+ fun lockscreenAlpha() =
+ testScope.runTest {
+ val alpha by collectLastValue(underTest.lockscreenAlpha)
+
+ repository.sendTransitionStep(step(0f, TransitionState.STARTED))
+ repository.sendTransitionStep(step(0f))
+ assertThat(alpha).isEqualTo(0f)
+
+ repository.sendTransitionStep(step(0.66f))
+ assertThat(alpha).isIn(Range.open(.1f, .9f))
+
+ repository.sendTransitionStep(step(1f))
+ assertThat(alpha).isEqualTo(1f)
+ }
+
+ private fun step(
+ value: Float,
+ state: TransitionState = TransitionState.RUNNING,
+ ): TransitionStep {
+ return TransitionStep(
+ from = KeyguardState.OFF,
+ to = KeyguardState.LOCKSCREEN,
+ value = value,
+ transitionState = state,
+ ownerName = "OffToLockscreenTransitionViewModelTest",
+ )
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModelTest.kt
index 88a1df147489..ada2138d4d52 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModelTest.kt
@@ -16,46 +16,130 @@
package com.android.systemui.notifications.ui.viewmodel
+import android.platform.test.annotations.EnableFlags
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository
+import com.android.systemui.authentication.domain.interactor.AuthenticationResult
+import com.android.systemui.authentication.domain.interactor.authenticationInteractor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.kosmos.testScope
+import com.android.systemui.lifecycle.activateIn
+import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
+import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
+import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.scene.domain.startable.sceneContainerStartable
import com.android.systemui.scene.shared.model.Overlays
+import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.domain.interactor.shadeInteractor
+import com.android.systemui.shade.shared.flag.DualShade
import com.android.systemui.shade.ui.viewmodel.notificationsShadeOverlayContentViewModel
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
@EnableSceneContainer
+@EnableFlags(DualShade.FLAG_NAME)
class NotificationsShadeOverlayContentViewModelTest : SysuiTestCase() {
private val kosmos = testKosmos()
private val testScope = kosmos.testScope
private val sceneInteractor = kosmos.sceneInteractor
- private val underTest = kosmos.notificationsShadeOverlayContentViewModel
+ private val underTest by lazy { kosmos.notificationsShadeOverlayContentViewModel }
+
+ @Before
+ fun setUp() {
+ kosmos.sceneContainerStartable.start()
+ underTest.activateIn(testScope)
+ }
@Test
fun onScrimClicked_hidesShade() =
testScope.runTest {
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
- sceneInteractor.showOverlay(
- overlay = Overlays.NotificationsShade,
- loggingReason = "test",
- )
+ sceneInteractor.showOverlay(Overlays.NotificationsShade, "test")
assertThat(currentOverlays).contains(Overlays.NotificationsShade)
underTest.onScrimClicked()
assertThat(currentOverlays).doesNotContain(Overlays.NotificationsShade)
}
+
+ @Test
+ fun deviceLocked_hidesShade() =
+ testScope.runTest {
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ unlockDevice()
+ sceneInteractor.showOverlay(Overlays.NotificationsShade, "test")
+ assertThat(currentOverlays).contains(Overlays.NotificationsShade)
+
+ lockDevice()
+
+ assertThat(currentOverlays).doesNotContain(Overlays.NotificationsShade)
+ }
+
+ @Test
+ fun bouncerShown_hidesShade() =
+ testScope.runTest {
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ lockDevice()
+ sceneInteractor.showOverlay(Overlays.NotificationsShade, "test")
+ assertThat(currentOverlays).contains(Overlays.NotificationsShade)
+
+ sceneInteractor.changeScene(Scenes.Bouncer, "test")
+ runCurrent()
+
+ assertThat(currentOverlays).doesNotContain(Overlays.NotificationsShade)
+ }
+
+ @Test
+ fun shadeNotTouchable_hidesShade() =
+ testScope.runTest {
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ val isShadeTouchable by collectLastValue(kosmos.shadeInteractor.isShadeTouchable)
+ assertThat(isShadeTouchable).isTrue()
+ sceneInteractor.showOverlay(Overlays.NotificationsShade, "test")
+ assertThat(currentOverlays).contains(Overlays.NotificationsShade)
+
+ lockDevice()
+ assertThat(isShadeTouchable).isFalse()
+ assertThat(currentOverlays).doesNotContain(Overlays.NotificationsShade)
+ }
+
+ private fun TestScope.lockDevice() {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ kosmos.powerInteractor.setAsleepForTest()
+ runCurrent()
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ }
+
+ private suspend fun TestScope.unlockDevice() {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ kosmos.powerInteractor.setAwakeForTest()
+ runCurrent()
+ assertThat(
+ kosmos.authenticationInteractor.authenticate(
+ FakeAuthenticationRepository.DEFAULT_PIN
+ )
+ )
+ .isEqualTo(AuthenticationResult.SUCCEEDED)
+
+ assertThat(currentScene).isEqualTo(Scenes.Gone)
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tileimpl/QSIconViewImplTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tileimpl/QSIconViewImplTest.java
index 2580ac2c8da7..7798f46fdb46 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tileimpl/QSIconViewImplTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tileimpl/QSIconViewImplTest.java
@@ -14,6 +14,8 @@
package com.android.systemui.qs.tileimpl;
+import static com.android.systemui.Flags.FLAG_QS_NEW_TILES;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any;
@@ -21,11 +23,16 @@ import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.content.Context;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.service.quicksettings.Tile;
import android.testing.UiThreadTest;
import android.widget.ImageView;
@@ -47,7 +54,6 @@ import org.mockito.Mockito;
@UiThreadTest
@SmallTest
public class QSIconViewImplTest extends SysuiTestCase {
-
private QSIconViewImpl mIconView;
@Before
@@ -106,6 +112,34 @@ public class QSIconViewImplTest extends SysuiTestCase {
verify(iv).setImageTintList(argThat(stateList -> stateList.getColors()[0] == desiredColor));
}
+
+ @EnableFlags(FLAG_QS_NEW_TILES)
+ @Test
+ public void testIconPreloaded_withFlagOn_immediatelyLoadsAll3TintColors() {
+ Context ctx = spy(mContext);
+
+ QSIconViewImpl iconView = new QSIconViewImpl(ctx);
+
+ verify(ctx, times(3)).obtainStyledAttributes(any());
+
+ iconView.getColor(new State()); // this should not increase the call count
+
+ verify(ctx, times(3)).obtainStyledAttributes(any());
+ }
+
+ @DisableFlags(FLAG_QS_NEW_TILES)
+ @Test
+ public void testIconPreloaded_withFlagOff_loadsOneTintColorAfterIconColorIsRead() {
+ Context ctx = spy(mContext);
+ QSIconViewImpl iconView = new QSIconViewImpl(ctx);
+
+ verify(ctx, never()).obtainStyledAttributes(any()); // none of the colors are preloaded
+
+ iconView.getColor(new State());
+
+ verify(ctx, times(1)).obtainStyledAttributes(any());
+ }
+
@Test
public void testStateSetCorrectly_toString() {
ImageView iv = mock(ImageView.class);
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapperTest.kt
index 620e90dcaa62..d32ba47204c0 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapperTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapperTest.kt
@@ -17,13 +17,17 @@
package com.android.systemui.qs.tiles.impl.internet.domain
import android.graphics.drawable.TestStubDrawable
+import android.os.fakeExecutorHandler
import android.widget.Switch
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
+import com.android.settingslib.graph.SignalDrawable
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.ContentDescription
+import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
+import com.android.systemui.common.shared.model.Text.Companion.loadText
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.qs.tiles.impl.custom.QSTileStateSubject
import com.android.systemui.qs.tiles.impl.internet.domain.model.InternetTileModel
@@ -31,6 +35,9 @@ import com.android.systemui.qs.tiles.impl.internet.qsInternetTileConfig
import com.android.systemui.qs.tiles.viewmodel.QSTileState
import com.android.systemui.res.R
import com.android.systemui.statusbar.connectivity.WifiIcons.WIFI_FULL_ICONS
+import com.android.systemui.statusbar.pipeline.mobile.domain.model.SignalIconModel
+import com.android.systemui.statusbar.pipeline.satellite.ui.model.SatelliteIconModel
+import com.android.systemui.statusbar.pipeline.shared.ui.model.InternetTileIconModel
import org.junit.Test
import org.junit.runner.RunWith
@@ -39,25 +46,93 @@ import org.junit.runner.RunWith
class InternetTileMapperTest : SysuiTestCase() {
private val kosmos = Kosmos()
private val internetTileConfig = kosmos.qsInternetTileConfig
+ private val handler = kosmos.fakeExecutorHandler
private val mapper by lazy {
InternetTileMapper(
context.orCreateTestableResources
.apply {
addOverride(R.drawable.ic_qs_no_internet_unavailable, TestStubDrawable())
+ addOverride(R.drawable.ic_satellite_connected_2, TestStubDrawable())
addOverride(wifiRes, TestStubDrawable())
}
.resources,
context.theme,
- context
+ context,
+ handler,
)
}
@Test
- fun withActiveModel_mappedStateMatchesDataModel() {
+ fun withActiveCellularModel_mappedStateMatchesDataModel() {
val inputModel =
InternetTileModel.Active(
secondaryLabel = Text.Resource(R.string.quick_settings_networks_available),
- iconId = wifiRes,
+ icon = InternetTileIconModel.Cellular(3),
+ stateDescription = null,
+ contentDescription =
+ ContentDescription.Resource(R.string.quick_settings_internet_label),
+ )
+
+ val outputState = mapper.map(internetTileConfig, inputModel)
+
+ val signalDrawable = SignalDrawable(context, handler)
+ signalDrawable.setLevel(3)
+ val expectedState =
+ createInternetTileState(
+ QSTileState.ActivationState.ACTIVE,
+ context.getString(R.string.quick_settings_networks_available),
+ Icon.Loaded(signalDrawable, null),
+ null,
+ context.getString(R.string.quick_settings_internet_label),
+ )
+ QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
+ }
+
+ @Test
+ fun withActiveSatelliteModel_mappedStateMatchesDataModel() {
+ val inputIcon =
+ SignalIconModel.Satellite(
+ 3,
+ Icon.Resource(
+ res = R.drawable.ic_satellite_connected_2,
+ contentDescription =
+ ContentDescription.Resource(
+ R.string.accessibility_status_bar_satellite_good_connection
+ ),
+ ),
+ )
+ val inputModel =
+ InternetTileModel.Active(
+ secondaryLabel = Text.Resource(R.string.quick_settings_networks_available),
+ icon = InternetTileIconModel.Satellite(inputIcon.icon),
+ stateDescription = null,
+ contentDescription =
+ ContentDescription.Resource(
+ R.string.accessibility_status_bar_satellite_good_connection
+ ),
+ )
+
+ val outputState = mapper.map(internetTileConfig, inputModel)
+
+ val expectedSatIcon = SatelliteIconModel.fromSignalStrength(3)
+
+ val expectedState =
+ createInternetTileState(
+ QSTileState.ActivationState.ACTIVE,
+ inputModel.secondaryLabel.loadText(context).toString(),
+ Icon.Loaded(context.getDrawable(expectedSatIcon!!.res)!!, null),
+ expectedSatIcon.res,
+ expectedSatIcon.contentDescription.loadContentDescription(context).toString(),
+ )
+ QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
+ }
+
+ @Test
+ fun withActiveWifiModel_mappedStateMatchesDataModel() {
+ val inputModel =
+ InternetTileModel.Active(
+ secondaryLabel = Text.Resource(R.string.quick_settings_networks_available),
+ icon = InternetTileIconModel.ResourceId(wifiRes),
stateDescription = null,
contentDescription =
ContentDescription.Resource(R.string.quick_settings_internet_label),
@@ -71,7 +146,7 @@ class InternetTileMapperTest : SysuiTestCase() {
context.getString(R.string.quick_settings_networks_available),
Icon.Loaded(context.getDrawable(wifiRes)!!, contentDescription = null),
wifiRes,
- context.getString(R.string.quick_settings_internet_label)
+ context.getString(R.string.quick_settings_internet_label),
)
QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
}
@@ -81,7 +156,7 @@ class InternetTileMapperTest : SysuiTestCase() {
val inputModel =
InternetTileModel.Inactive(
secondaryLabel = Text.Resource(R.string.quick_settings_networks_unavailable),
- iconId = R.drawable.ic_qs_no_internet_unavailable,
+ icon = InternetTileIconModel.ResourceId(R.drawable.ic_qs_no_internet_unavailable),
stateDescription = null,
contentDescription =
ContentDescription.Resource(R.string.quick_settings_networks_unavailable),
@@ -95,10 +170,10 @@ class InternetTileMapperTest : SysuiTestCase() {
context.getString(R.string.quick_settings_networks_unavailable),
Icon.Loaded(
context.getDrawable(R.drawable.ic_qs_no_internet_unavailable)!!,
- contentDescription = null
+ contentDescription = null,
),
R.drawable.ic_qs_no_internet_unavailable,
- context.getString(R.string.quick_settings_networks_unavailable)
+ context.getString(R.string.quick_settings_networks_unavailable),
)
QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState)
}
@@ -107,7 +182,7 @@ class InternetTileMapperTest : SysuiTestCase() {
activationState: QSTileState.ActivationState,
secondaryLabel: String,
icon: Icon,
- iconRes: Int,
+ iconRes: Int? = null,
contentDescription: String,
): QSTileState {
val label = context.getString(R.string.quick_settings_internet_label)
@@ -120,13 +195,13 @@ class InternetTileMapperTest : SysuiTestCase() {
setOf(
QSTileState.UserAction.CLICK,
QSTileState.UserAction.TOGGLE_CLICK,
- QSTileState.UserAction.LONG_CLICK
+ QSTileState.UserAction.LONG_CLICK,
),
contentDescription,
null,
QSTileState.SideViewIcon.Chevron,
QSTileState.EnabledState.ENABLED,
- Switch::class.qualifiedName
+ Switch::class.qualifiedName,
)
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractorTest.kt
index 5a4506086058..5259aa84b193 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractorTest.kt
@@ -18,14 +18,12 @@ package com.android.systemui.qs.tiles.impl.internet.domain.interactor
import android.graphics.drawable.TestStubDrawable
import android.os.UserHandle
-import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.settingslib.AccessibilityContentDescriptions
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
-import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
import com.android.systemui.common.shared.model.Text.Companion.loadText
import com.android.systemui.coroutines.collectLastValue
@@ -49,6 +47,7 @@ import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIc
import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
import com.android.systemui.statusbar.pipeline.shared.data.model.DefaultConnectionModel
import com.android.systemui.statusbar.pipeline.shared.data.repository.FakeConnectivityRepository
+import com.android.systemui.statusbar.pipeline.shared.ui.model.InternetTileIconModel
import com.android.systemui.statusbar.pipeline.wifi.data.repository.FakeWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractorImpl
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel
@@ -60,9 +59,7 @@ import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
-import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
-import org.junit.Assume.assumeFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -144,7 +141,6 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
underTest =
InternetTileDataInteractor(
context,
- testScope.coroutineContext,
testScope.backgroundScope,
airplaneModeRepository,
connectivityRepository,
@@ -164,9 +160,11 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
connectivityRepository.defaultConnections.value = DefaultConnectionModel()
+ val expectedIcon =
+ InternetTileIconModel.ResourceId(R.drawable.ic_qs_no_internet_unavailable)
assertThat(latest?.secondaryLabel)
.isEqualTo(Text.Resource(R.string.quick_settings_networks_unavailable))
- assertThat(latest?.iconId).isEqualTo(R.drawable.ic_qs_no_internet_unavailable)
+ assertThat(latest?.icon).isEqualTo(expectedIcon)
}
@Test
@@ -183,11 +181,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
underTest.tileData(testUser, flowOf(DataUpdateTrigger.InitialRequest))
)
- val networkModel =
- WifiNetworkModel.Active.of(
- level = 4,
- ssid = "test ssid",
- )
+ val networkModel = WifiNetworkModel.Active.of(level = 4, ssid = "test ssid")
+
val wifiIcon =
WifiIcon.fromModel(model = networkModel, context = context, showHotspotInfo = true)
as WifiIcon.Visible
@@ -198,12 +193,9 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
assertThat(latest?.secondaryTitle).isEqualTo("test ssid")
assertThat(latest?.secondaryLabel).isNull()
- val expectedIcon =
- Icon.Loaded(context.getDrawable(WifiIcons.WIFI_NO_INTERNET_ICONS[4])!!, null)
- val actualIcon = latest?.icon
- assertThat(actualIcon).isEqualTo(expectedIcon)
- assertThat(latest?.iconId).isEqualTo(WifiIcons.WIFI_NO_INTERNET_ICONS[4])
+ val expectedIcon = InternetTileIconModel.ResourceId(WifiIcons.WIFI_NO_INTERNET_ICONS[4])
+ assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.contentDescription.loadContentDescription(context))
.isEqualTo("$internet,test ssid")
val expectedSd = wifiIcon.contentDescription
@@ -229,8 +221,7 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
wifiRepository.setIsWifiDefault(true)
wifiRepository.setWifiNetwork(networkModel)
- val expectedIcon =
- Icon.Loaded(context.getDrawable(WifiIcons.WIFI_NO_INTERNET_ICONS[4])!!, null)
+ val expectedIcon = InternetTileIconModel.ResourceId(WifiIcons.WIFI_NO_INTERNET_ICONS[4])
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
.doesNotContain(
@@ -249,9 +240,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.TABLET)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_tablet)!!,
- null
+ InternetTileIconModel.ResourceId(
+ com.android.settingslib.R.drawable.ic_hotspot_tablet
)
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
@@ -271,9 +261,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.LAPTOP)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_laptop)!!,
- null
+ InternetTileIconModel.ResourceId(
+ com.android.settingslib.R.drawable.ic_hotspot_laptop
)
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
@@ -293,10 +282,10 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.WATCH)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_watch)!!,
- null
+ InternetTileIconModel.ResourceId(
+ com.android.settingslib.R.drawable.ic_hotspot_watch
)
+
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
.isEqualTo(
@@ -315,10 +304,7 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.AUTO)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_auto)!!,
- null
- )
+ InternetTileIconModel.ResourceId(com.android.settingslib.R.drawable.ic_hotspot_auto)
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
.isEqualTo(
@@ -336,9 +322,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.PHONE)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_phone)!!,
- null
+ InternetTileIconModel.ResourceId(
+ com.android.settingslib.R.drawable.ic_hotspot_phone
)
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
@@ -358,9 +343,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.UNKNOWN)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_phone)!!,
- null
+ InternetTileIconModel.ResourceId(
+ com.android.settingslib.R.drawable.ic_hotspot_phone
)
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
@@ -380,10 +364,10 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
setWifiNetworkWithHotspot(WifiNetworkModel.HotspotDeviceType.INVALID)
val expectedIcon =
- Icon.Loaded(
- context.getDrawable(com.android.settingslib.R.drawable.ic_hotspot_phone)!!,
- null
+ InternetTileIconModel.ResourceId(
+ com.android.settingslib.R.drawable.ic_hotspot_phone
)
+
assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
.isEqualTo(
@@ -426,8 +410,9 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
assertThat(latest?.secondaryLabel).isNull()
assertThat(latest?.secondaryTitle)
.isEqualTo(context.getString(R.string.quick_settings_networks_available))
- assertThat(latest?.icon).isNull()
- assertThat(latest?.iconId).isEqualTo(R.drawable.ic_qs_no_internet_available)
+ val expectedIcon =
+ InternetTileIconModel.ResourceId(R.drawable.ic_qs_no_internet_available)
+ assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription).isNull()
val expectedCd =
"$internet,${context.getString(R.string.quick_settings_networks_available)}"
@@ -435,54 +420,19 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
.isEqualTo(expectedCd)
}
- /**
- * We expect a RuntimeException because [underTest] instantiates a SignalDrawable on the
- * provided context, and so the SignalDrawable constructor attempts to instantiate a Handler()
- * on the mentioned context. Since that context does not have a looper assigned to it, the
- * handler instantiation will throw a RuntimeException.
- *
- * TODO(b/338068066): Robolectric behavior differs in that it does not throw the exception So
- * either we should make Robolectric behave similar to the device test, or change this test to
- * look for a different signal than the exception, when run by Robolectric. For now we just
- * assume the test is not Robolectric.
- */
- @Test(expected = java.lang.RuntimeException::class)
- fun mobileDefault_usesNetworkNameAndIcon_throwsRunTimeException() =
- testScope.runTest {
- assumeFalse(isRobolectricTest())
-
- collectLastValue(underTest.tileData(testUser, flowOf(DataUpdateTrigger.InitialRequest)))
-
- connectivityRepository.setMobileConnected()
- mobileConnectionsRepository.mobileIsDefault.value = true
- mobileConnectionRepository.apply {
- setAllLevels(3)
- setAllRoaming(false)
- networkName.value = NetworkNameModel.Default("test network")
- }
-
- runCurrent()
- }
-
- /**
- * See [mobileDefault_usesNetworkNameAndIcon_throwsRunTimeException] for description of the
- * problem this test solves. The solution here is to assign a looper to the context via
- * RunWithLooper. In the production code, the solution is to use a Main CoroutineContext for
- * creating the SignalDrawable.
- */
- @TestableLooper.RunWithLooper
@Test
- fun mobileDefault_run_withLooper_usesNetworkNameAndIcon() =
+ fun mobileDefault_usesNetworkNameAndIcon() =
testScope.runTest {
val latest by
collectLastValue(
underTest.tileData(testUser, flowOf(DataUpdateTrigger.InitialRequest))
)
+ val iconLevel = 3
connectivityRepository.setMobileConnected()
mobileConnectionsRepository.mobileIsDefault.value = true
mobileConnectionRepository.apply {
- setAllLevels(3)
+ setAllLevels(iconLevel)
setAllRoaming(false)
networkName.value = NetworkNameModel.Default("test network")
}
@@ -491,8 +441,9 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
assertThat(latest?.secondaryTitle).isNotNull()
assertThat(latest?.secondaryTitle.toString()).contains("test network")
assertThat(latest?.secondaryLabel).isNull()
- assertThat(latest?.icon).isInstanceOf(Icon.Loaded::class.java)
- assertThat(latest?.iconId).isNull()
+ val expectedIcon = InternetTileIconModel.Cellular(iconLevel)
+
+ assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription.loadContentDescription(context))
.isEqualTo(latest?.secondaryTitle.toString())
assertThat(latest?.contentDescription.loadContentDescription(context))
@@ -513,8 +464,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
assertThat(latest?.secondaryLabel.loadText(context))
.isEqualTo(ethernetIcon!!.contentDescription.loadContentDescription(context))
assertThat(latest?.secondaryTitle).isNull()
- assertThat(latest?.iconId).isEqualTo(R.drawable.stat_sys_ethernet_fully)
- assertThat(latest?.icon).isNull()
+ val expectedIcon = InternetTileIconModel.ResourceId(R.drawable.stat_sys_ethernet_fully)
+ assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription).isNull()
assertThat(latest?.contentDescription.loadContentDescription(context))
.isEqualTo(latest?.secondaryLabel.loadText(context))
@@ -534,8 +485,8 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
assertThat(latest?.secondaryLabel.loadText(context))
.isEqualTo(ethernetIcon!!.contentDescription.loadContentDescription(context))
assertThat(latest?.secondaryTitle).isNull()
- assertThat(latest?.iconId).isEqualTo(R.drawable.stat_sys_ethernet)
- assertThat(latest?.icon).isNull()
+ val expectedIcon = InternetTileIconModel.ResourceId(R.drawable.stat_sys_ethernet)
+ assertThat(latest?.icon).isEqualTo(expectedIcon)
assertThat(latest?.stateDescription).isNull()
assertThat(latest?.contentDescription.loadContentDescription(context))
.isEqualTo(latest?.secondaryLabel.loadText(context))
@@ -543,11 +494,7 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
private fun setWifiNetworkWithHotspot(hotspot: WifiNetworkModel.HotspotDeviceType) {
val networkModel =
- WifiNetworkModel.Active.of(
- level = 4,
- ssid = "test ssid",
- hotspotDeviceType = hotspot,
- )
+ WifiNetworkModel.Active.of(level = 4, ssid = "test ssid", hotspotDeviceType = hotspot)
connectivityRepository.setWifiConnected()
wifiRepository.setIsWifiDefault(true)
@@ -560,7 +507,7 @@ class InternetTileDataInteractorTest : SysuiTestCase() {
val NOT_CONNECTED_NETWORKS_UNAVAILABLE =
InternetTileModel.Inactive(
secondaryLabel = Text.Resource(R.string.quick_settings_networks_unavailable),
- iconId = R.drawable.ic_qs_no_internet_unavailable,
+ icon = InternetTileIconModel.ResourceId(R.drawable.ic_qs_no_internet_unavailable),
stateDescription = null,
contentDescription =
ContentDescription.Resource(R.string.quick_settings_networks_unavailable),
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelTest.kt
index abd1e2c7df82..f32894dfd383 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelTest.kt
@@ -16,45 +16,129 @@
package com.android.systemui.qs.ui.viewmodel
+import android.platform.test.annotations.EnableFlags
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository
+import com.android.systemui.authentication.domain.interactor.AuthenticationResult
+import com.android.systemui.authentication.domain.interactor.authenticationInteractor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.kosmos.testScope
+import com.android.systemui.lifecycle.activateIn
+import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
+import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
+import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.scene.domain.startable.sceneContainerStartable
import com.android.systemui.scene.shared.model.Overlays
+import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.domain.interactor.shadeInteractor
+import com.android.systemui.shade.shared.flag.DualShade
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
@EnableSceneContainer
+@EnableFlags(DualShade.FLAG_NAME)
class QuickSettingsShadeOverlayContentViewModelTest : SysuiTestCase() {
private val kosmos = testKosmos()
private val testScope = kosmos.testScope
private val sceneInteractor = kosmos.sceneInteractor
- private val underTest = kosmos.quickSettingsShadeOverlayContentViewModel
+ private val underTest by lazy { kosmos.quickSettingsShadeOverlayContentViewModel }
+
+ @Before
+ fun setUp() {
+ kosmos.sceneContainerStartable.start()
+ underTest.activateIn(testScope)
+ }
@Test
fun onScrimClicked_hidesShade() =
testScope.runTest {
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
- sceneInteractor.showOverlay(
- overlay = Overlays.QuickSettingsShade,
- loggingReason = "test",
- )
+ sceneInteractor.showOverlay(Overlays.QuickSettingsShade, "test")
assertThat(currentOverlays).contains(Overlays.QuickSettingsShade)
underTest.onScrimClicked()
assertThat(currentOverlays).doesNotContain(Overlays.QuickSettingsShade)
}
+
+ @Test
+ fun deviceLocked_hidesShade() =
+ testScope.runTest {
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ unlockDevice()
+ sceneInteractor.showOverlay(Overlays.QuickSettingsShade, "test")
+ assertThat(currentOverlays).contains(Overlays.QuickSettingsShade)
+
+ lockDevice()
+
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ fun bouncerShown_hidesShade() =
+ testScope.runTest {
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ lockDevice()
+ sceneInteractor.showOverlay(Overlays.QuickSettingsShade, "test")
+ assertThat(currentOverlays).contains(Overlays.QuickSettingsShade)
+
+ sceneInteractor.changeScene(Scenes.Bouncer, "test")
+ runCurrent()
+
+ assertThat(currentOverlays).doesNotContain(Overlays.QuickSettingsShade)
+ }
+
+ @Test
+ fun shadeNotTouchable_hidesShade() =
+ testScope.runTest {
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ val isShadeTouchable by collectLastValue(kosmos.shadeInteractor.isShadeTouchable)
+ assertThat(isShadeTouchable).isTrue()
+ sceneInteractor.showOverlay(Overlays.QuickSettingsShade, "test")
+ assertThat(currentOverlays).contains(Overlays.QuickSettingsShade)
+
+ lockDevice()
+ assertThat(isShadeTouchable).isFalse()
+ assertThat(currentOverlays).doesNotContain(Overlays.QuickSettingsShade)
+ }
+
+ private fun TestScope.lockDevice() {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ kosmos.powerInteractor.setAsleepForTest()
+ runCurrent()
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ }
+
+ private suspend fun TestScope.unlockDevice() {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ kosmos.powerInteractor.setAwakeForTest()
+ runCurrent()
+ assertThat(
+ kosmos.authenticationInteractor.authenticate(
+ FakeAuthenticationRepository.DEFAULT_PIN
+ )
+ )
+ .isEqualTo(AuthenticationResult.SUCCEEDED)
+
+ assertThat(currentScene).isEqualTo(Scenes.Gone)
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/recordissue/IssueRecordingServiceCommandHandlerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/recordissue/IssueRecordingServiceSessionTest.kt
index 57cfe1b9e902..3e5dee69c85c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/recordissue/IssueRecordingServiceCommandHandlerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/recordissue/IssueRecordingServiceSessionTest.kt
@@ -47,7 +47,7 @@ import org.mockito.kotlin.verify
@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
-class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
+class IssueRecordingServiceSessionTest : SysuiTestCase() {
private val kosmos = Kosmos().also { it.testCase = this }
private val bgExecutor = kosmos.fakeExecutor
@@ -61,13 +61,13 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
private val notificationManager = mock<NotificationManager>()
private val panelInteractor = mock<PanelInteractor>()
- private lateinit var underTest: IssueRecordingServiceCommandHandler
+ private lateinit var underTest: IssueRecordingServiceSession
@Before
fun setup() {
traceurMessageSender = mock<TraceurMessageSender>()
underTest =
- IssueRecordingServiceCommandHandler(
+ IssueRecordingServiceSession(
bgExecutor,
dialogTransitionAnimator,
panelInteractor,
@@ -75,13 +75,13 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
issueRecordingState,
iActivityManager,
notificationManager,
- userContextProvider
+ userContextProvider,
)
}
@Test
fun startsTracing_afterReceivingActionStartCommand() {
- underTest.handleStartCommand()
+ underTest.start()
bgExecutor.runAllReady()
Truth.assertThat(issueRecordingState.isRecording).isTrue()
@@ -90,7 +90,7 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
@Test
fun stopsTracing_afterReceivingStopTracingCommand() {
- underTest.handleStopCommand(mContext.contentResolver)
+ underTest.stop(mContext.contentResolver)
bgExecutor.runAllReady()
Truth.assertThat(issueRecordingState.isRecording).isFalse()
@@ -99,7 +99,7 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
@Test
fun cancelsNotification_afterReceivingShareCommand() {
- underTest.handleShareCommand(0, null, mContext)
+ underTest.share(0, null, mContext)
bgExecutor.runAllReady()
verify(notificationManager).cancelAsUser(isNull(), anyInt(), any<UserHandle>())
@@ -110,7 +110,7 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
issueRecordingState.takeBugreport = true
val uri = mock<Uri>()
- underTest.handleShareCommand(0, uri, mContext)
+ underTest.share(0, uri, mContext)
bgExecutor.runAllReady()
verify(iActivityManager).requestBugReportWithExtraAttachment(uri)
@@ -121,7 +121,7 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
issueRecordingState.takeBugreport = false
val uri = mock<Uri>()
- underTest.handleShareCommand(0, uri, mContext)
+ underTest.share(0, uri, mContext)
bgExecutor.runAllReady()
verify(traceurMessageSender).shareTraces(mContext, uri)
@@ -131,7 +131,7 @@ class IssueRecordingServiceCommandHandlerTest : SysuiTestCase() {
fun closesShade_afterReceivingShareCommand() {
val uri = mock<Uri>()
- underTest.handleShareCommand(0, uri, mContext)
+ underTest.share(0, uri, mContext)
bgExecutor.runAllReady()
verify(panelInteractor).collapsePanels()
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt
index a0cafcbd5ad1..c9e958dd1cc0 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt
@@ -341,7 +341,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
bouncerActionButton?.onClick?.invoke()
runCurrent()
- // TODO(b/298026988): Assert that an activity was started once we use ActivityStarter.
+ // TODO(b/369765704): Assert that an activity was started once we use ActivityStarter.
}
@Test
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt
index d163abf66b05..19ac0cf40160 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt
@@ -287,7 +287,7 @@ class ShadeInteractorImplTest(flags: FlagsParameterization) : SysuiTestCase() {
@Test
fun anyExpansion_shadeGreater() =
- testScope.runTest() {
+ testScope.runTest {
// WHEN shade is more expanded than QS
shadeTestUtil.setShadeAndQsExpansion(.5f, 0f)
runCurrent()
@@ -298,7 +298,7 @@ class ShadeInteractorImplTest(flags: FlagsParameterization) : SysuiTestCase() {
@Test
fun anyExpansion_qsGreater() =
- testScope.runTest() {
+ testScope.runTest {
// WHEN qs is more expanded than shade
shadeTestUtil.setShadeAndQsExpansion(0f, .5f)
runCurrent()
@@ -308,6 +308,36 @@ class ShadeInteractorImplTest(flags: FlagsParameterization) : SysuiTestCase() {
}
@Test
+ fun isShadeAnyExpanded_shadeCollapsed() =
+ testScope.runTest {
+ val isShadeAnyExpanded by collectLastValue(underTest.isShadeAnyExpanded)
+ shadeTestUtil.setShadeExpansion(0f)
+ runCurrent()
+
+ assertThat(isShadeAnyExpanded).isFalse()
+ }
+
+ @Test
+ fun isShadeAnyExpanded_shadePartiallyExpanded() =
+ testScope.runTest {
+ val isShadeAnyExpanded by collectLastValue(underTest.isShadeAnyExpanded)
+ shadeTestUtil.setShadeExpansion(0.01f)
+ runCurrent()
+
+ assertThat(isShadeAnyExpanded).isTrue()
+ }
+
+ @Test
+ fun isShadeAnyExpanded_shadeFullyExpanded() =
+ testScope.runTest {
+ val isShadeAnyExpanded by collectLastValue(underTest.isShadeAnyExpanded)
+ shadeTestUtil.setShadeExpansion(1f)
+ runCurrent()
+
+ assertThat(isShadeAnyExpanded).isTrue()
+ }
+
+ @Test
fun isShadeTouchable_isFalse_whenDeviceAsleepAndNotPulsing() =
testScope.runTest {
powerRepository.updateWakefulness(
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt
index 109cd05368e6..4592b60e7c2c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt
@@ -35,6 +35,7 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
+import org.junit.Assert.assertThrows
import org.junit.Test
import org.junit.runner.RunWith
@@ -382,4 +383,44 @@ class ShadeInteractorLegacyImplTest : SysuiTestCase() {
// THEN user is not interacting
assertThat(actual).isFalse()
}
+
+ @Test
+ fun expandNotificationsShade_unsupported() =
+ testScope.runTest {
+ assertThrows(UnsupportedOperationException::class.java) {
+ underTest.expandNotificationsShade("reason")
+ }
+ }
+
+ @Test
+ fun expandQuickSettingsShade_unsupported() =
+ testScope.runTest {
+ assertThrows(UnsupportedOperationException::class.java) {
+ underTest.expandQuickSettingsShade("reason")
+ }
+ }
+
+ @Test
+ fun collapseNotificationsShade_unsupported() =
+ testScope.runTest {
+ assertThrows(UnsupportedOperationException::class.java) {
+ underTest.collapseNotificationsShade("reason")
+ }
+ }
+
+ @Test
+ fun collapseQuickSettingsShade_unsupported() =
+ testScope.runTest {
+ assertThrows(UnsupportedOperationException::class.java) {
+ underTest.collapseQuickSettingsShade("reason")
+ }
+ }
+
+ @Test
+ fun collapseEitherShade_unsupported() =
+ testScope.runTest {
+ assertThrows(UnsupportedOperationException::class.java) {
+ underTest.collapseEitherShade("reason")
+ }
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelTest.kt
index f6fe667ff813..eb8ea8ba15cf 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelTest.kt
@@ -1,12 +1,15 @@
package com.android.systemui.shade.ui.viewmodel
import android.content.Intent
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
import android.provider.AlarmClock
import android.provider.Settings
import android.telephony.SubscriptionManager.PROFILE_CLASS_UNSET
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
+import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
@@ -18,7 +21,9 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.plugins.activityStarter
import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.shared.flag.DualShade
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.fakeMobileIconsInteractor
import com.android.systemui.testKosmos
@@ -48,7 +53,7 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
private val sceneInteractor = kosmos.sceneInteractor
private val deviceEntryInteractor = kosmos.deviceEntryInteractor
- private val underTest: ShadeHeaderViewModel = kosmos.shadeHeaderViewModel
+ private val underTest by lazy { kosmos.shadeHeaderViewModel }
@Before
fun setUp() {
@@ -96,6 +101,7 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
}
@Test
+ @DisableFlags(DualShade.FLAG_NAME)
fun onSystemIconContainerClicked_locked_collapsesShadeToLockscreen() =
testScope.runTest {
setDeviceEntered(false)
@@ -108,6 +114,25 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
}
@Test
+ @EnableFlags(DualShade.FLAG_NAME)
+ fun onSystemIconContainerClicked_lockedOnDualShade_collapsesShadeToLockscreen() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ setDeviceEntered(false)
+ setScene(Scenes.Lockscreen)
+ setOverlay(Overlays.NotificationsShade)
+ assertThat(currentOverlays).isNotEmpty()
+
+ underTest.onSystemIconContainerClicked()
+ runCurrent()
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @DisableFlags(DualShade.FLAG_NAME)
fun onSystemIconContainerClicked_unlocked_collapsesShadeToGone() =
testScope.runTest {
setDeviceEntered(true)
@@ -119,6 +144,24 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
assertThat(sceneInteractor.currentScene.value).isEqualTo(Scenes.Gone)
}
+ @Test
+ @EnableFlags(DualShade.FLAG_NAME)
+ fun onSystemIconContainerClicked_unlockedOnDualShade_collapsesShadeToGone() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ setDeviceEntered(true)
+ setScene(Scenes.Gone)
+ setOverlay(Overlays.NotificationsShade)
+ assertThat(currentOverlays).isNotEmpty()
+
+ underTest.onSystemIconContainerClicked()
+ runCurrent()
+
+ assertThat(currentScene).isEqualTo(Scenes.Gone)
+ assertThat(currentOverlays).isEmpty()
+ }
+
companion object {
private val SUB_1 =
SubscriptionModel(
@@ -144,6 +187,17 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
testScope.runCurrent()
}
+ private fun setOverlay(key: OverlayKey) {
+ val currentOverlays = sceneInteractor.currentOverlays.value + key
+ sceneInteractor.showOverlay(key, "test")
+ sceneInteractor.setTransitionState(
+ MutableStateFlow<ObservableTransitionState>(
+ ObservableTransitionState.Idle(sceneInteractor.currentScene.value, currentOverlays)
+ )
+ )
+ testScope.runCurrent()
+ }
+
private fun TestScope.setDeviceEntered(isEntered: Boolean) {
if (isEntered) {
// Unlock the device marking the device has entered.
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorTest.kt
index 7b87aeb60c13..d772e3effbeb 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorTest.kt
@@ -42,7 +42,8 @@ import com.android.systemui.statusbar.notification.collection.modifyEntry
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.domain.interactor.lockScreenNotificationMinimalismSetting
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.stack.data.repository.headsUpNotificationRepository
import com.android.systemui.testKosmos
import com.android.systemui.util.settings.FakeSettings
@@ -66,7 +67,7 @@ import org.mockito.kotlin.whenever
@SmallTest
@RunWith(AndroidJUnit4::class)
-@EnableFlags(NotificationMinimalismPrototype.FLAG_NAME)
+@EnableFlags(NotificationMinimalism.FLAG_NAME)
class LockScreenMinimalismCoordinatorTest : SysuiTestCase() {
private val kosmos =
@@ -76,7 +77,7 @@ class LockScreenMinimalismCoordinatorTest : SysuiTestCase() {
mock<SysuiStatusBarStateController>().also { mock ->
doAnswer { statusBarState.ordinal }.whenever(mock).state
}
- fakeSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, 1)
+ lockScreenNotificationMinimalismSetting = true
}
private val notifPipeline: NotifPipeline = mock()
private var statusBarState: StatusBarState = StatusBarState.KEYGUARD
@@ -193,7 +194,7 @@ class LockScreenMinimalismCoordinatorTest : SysuiTestCase() {
kosmos.activeNotificationListRepository.topUnseenNotificationKey.value = child2.key
assertThat(promoter.shouldPromoteToTopLevel(child1)).isFalse()
assertThat(promoter.shouldPromoteToTopLevel(child2))
- .isEqualTo(NotificationMinimalismPrototype.ungroupTopUnseen)
+ .isEqualTo(NotificationMinimalism.ungroupTopUnseen)
assertThat(promoter.shouldPromoteToTopLevel(child3)).isFalse()
assertThat(promoter.shouldPromoteToTopLevel(parent)).isFalse()
@@ -201,7 +202,7 @@ class LockScreenMinimalismCoordinatorTest : SysuiTestCase() {
kosmos.activeNotificationListRepository.topUnseenNotificationKey.value = child2.key
assertThat(promoter.shouldPromoteToTopLevel(child1)).isTrue()
assertThat(promoter.shouldPromoteToTopLevel(child2))
- .isEqualTo(NotificationMinimalismPrototype.ungroupTopUnseen)
+ .isEqualTo(NotificationMinimalism.ungroupTopUnseen)
assertThat(promoter.shouldPromoteToTopLevel(child3)).isFalse()
assertThat(promoter.shouldPromoteToTopLevel(parent)).isFalse()
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorTest.kt
index 2159b864d2a2..ea2e25e8eb1c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorTest.kt
@@ -21,7 +21,7 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
@@ -57,7 +57,7 @@ class SeenNotificationsInteractorTest : SysuiTestCase() {
}
@Test
- @EnableFlags(NotificationMinimalismPrototype.FLAG_NAME)
+ @EnableFlags(NotificationMinimalism.FLAG_NAME)
fun topOngoingAndUnseenNotification() = runTest {
val entry1 = NotificationEntryBuilder().setTag("entry1").build()
val entry2 = NotificationEntryBuilder().setTag("entry2").build()
@@ -91,4 +91,17 @@ class SeenNotificationsInteractorTest : SysuiTestCase() {
testScheduler.runCurrent()
assertThat(settingEnabled).isTrue()
}
+
+ fun testLockScreenNotificationMinimalismSetting() = runTest {
+ val settingEnabled by
+ collectLastValue(underTest.isLockScreenNotificationMinimalismEnabled())
+
+ kosmos.lockScreenNotificationMinimalismSetting = false
+ testScheduler.runCurrent()
+ assertThat(settingEnabled).isFalse()
+
+ kosmos.lockScreenNotificationMinimalismSetting = true
+ testScheduler.runCurrent()
+ assertThat(settingEnabled).isTrue()
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt
index f9b77697b767..28857a08c2bd 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt
@@ -30,6 +30,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.kosmos.testScope
+import com.android.systemui.shared.settings.data.repository.fakeSecureSettingsRepository
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
@@ -53,6 +54,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
private val testScope = kosmos.testScope
private val zenModeRepository = kosmos.zenModeRepository
private val activeNotificationListRepository = kosmos.activeNotificationListRepository
+ private val fakeSecureSettingsRepository = kosmos.fakeSecureSettingsRepository
private val underTest = kosmos.emptyShadeViewModel
@@ -205,4 +207,84 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
assertThat(footerVisible).isTrue()
}
+
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
+ @Test
+ fun onClick_whenHistoryDisabled_leadsToSettingsPage() =
+ testScope.runTest {
+ val onClick by collectLastValue(underTest.onClick)
+ runCurrent()
+
+ fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0)
+
+ assertThat(onClick?.targetIntent?.action)
+ .isEqualTo(Settings.ACTION_NOTIFICATION_SETTINGS)
+ assertThat(onClick?.backStack).isEmpty()
+ }
+
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
+ @Test
+ fun onClick_whenHistoryEnabled_leadsToHistoryPage() =
+ testScope.runTest {
+ val onClick by collectLastValue(underTest.onClick)
+ runCurrent()
+
+ fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1)
+
+ assertThat(onClick?.targetIntent?.action)
+ .isEqualTo(Settings.ACTION_NOTIFICATION_HISTORY)
+ assertThat(onClick?.backStack?.map { it.action })
+ .containsExactly(Settings.ACTION_NOTIFICATION_SETTINGS)
+ }
+
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
+ @Test
+ fun onClick_whenOneModeHidingNotifications_leadsToModeSettings() =
+ testScope.runTest {
+ val onClick by collectLastValue(underTest.onClick)
+ runCurrent()
+
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setId("ID")
+ .setActive(true)
+ .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
+ .build()
+ )
+ runCurrent()
+
+ assertThat(onClick?.targetIntent?.action)
+ .isEqualTo(Settings.ACTION_AUTOMATIC_ZEN_RULE_SETTINGS)
+ assertThat(
+ onClick?.targetIntent?.extras?.getString(Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID)
+ )
+ .isEqualTo("ID")
+ assertThat(onClick?.backStack?.map { it.action })
+ .containsExactly(Settings.ACTION_ZEN_MODE_SETTINGS)
+ }
+
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
+ @Test
+ fun onClick_whenMultipleModesHidingNotifications_leadsToGeneralModesSettings() =
+ testScope.runTest {
+ val onClick by collectLastValue(underTest.onClick)
+ runCurrent()
+
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setActive(true)
+ .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
+ .build()
+ )
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setActive(true)
+ .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
+ .build()
+ )
+ runCurrent()
+
+ assertThat(onClick?.targetIntent?.action).isEqualTo(Settings.ACTION_ZEN_MODE_SETTINGS)
+ assertThat(onClick?.backStack).isEmpty()
+ }
}
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java
index be44dee0aae6..73626b457dcf 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java
@@ -184,7 +184,10 @@ public interface QSTile {
}
}
- /** Get the text for secondaryLabel. */
+ /**
+ * If the current secondaryLabel value is not empty, ignore the given input and return
+ * the current value. Otherwise return current value.
+ */
public CharSequence getSecondaryLabel(CharSequence stateText) {
// Use a local reference as the value might change from other threads
CharSequence localSecondaryLabel = secondaryLabel;
diff --git a/packages/SystemUI/shared/Android.bp b/packages/SystemUI/shared/Android.bp
index 8f55961af4e9..0f1da509468a 100644
--- a/packages/SystemUI/shared/Android.bp
+++ b/packages/SystemUI/shared/Android.bp
@@ -70,6 +70,7 @@ android_library {
"jsr330",
"//frameworks/libs/systemui:com_android_systemui_shared_flags_lib",
"//frameworks/libs/systemui:msdl",
+ "//frameworks/libs/systemui:view_capture",
],
resource_dirs: [
"res",
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java
index f358ba2d3ccd..4db6ab6ea579 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java
@@ -16,6 +16,9 @@
package com.android.systemui.shared.rotation;
+import static com.android.app.viewcapture.ViewCaptureFactory.getViewCaptureAwareWindowManagerInstance;
+import static com.android.systemui.Flags.enableViewCaptureTracing;
+
import android.annotation.DimenRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
@@ -30,7 +33,6 @@ import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
@@ -38,6 +40,7 @@ import android.widget.FrameLayout;
import androidx.annotation.BoolRes;
import androidx.core.view.OneShotPreDrawListener;
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
import com.android.systemui.shared.rotation.FloatingRotationButtonPositionCalculator.Position;
/**
@@ -47,7 +50,7 @@ public class FloatingRotationButton implements RotationButton {
private static final int MARGIN_ANIMATION_DURATION_MILLIS = 300;
- private final WindowManager mWindowManager;
+ private final ViewCaptureAwareWindowManager mWindowManager;
private final ViewGroup mKeyButtonContainer;
private final FloatingRotationButtonView mKeyButtonView;
@@ -88,7 +91,8 @@ public class FloatingRotationButton implements RotationButton {
@DimenRes int taskbarBottomMargin, @DimenRes int buttonDiameter,
@DimenRes int rippleMaxWidth, @BoolRes int floatingRotationBtnPositionLeftResource) {
mContext = context;
- mWindowManager = mContext.getSystemService(WindowManager.class);
+ mWindowManager = getViewCaptureAwareWindowManagerInstance(mContext,
+ enableViewCaptureTracing());
mKeyButtonContainer = (ViewGroup) LayoutInflater.from(mContext).inflate(layout, null);
mKeyButtonView = mKeyButtonContainer.findViewById(keyButtonId);
mKeyButtonView.setVisibility(View.VISIBLE);
diff --git a/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java b/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java
index 76df9c96c801..fb00d6e16dcc 100644
--- a/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java
+++ b/packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java
@@ -75,6 +75,9 @@ import javax.inject.Named;
* touches are consumed.
*/
public class TouchMonitor {
+ // An incrementing id used to identify the touch monitor instance.
+ private static int sNextInstanceId = 0;
+
private final Logger mLogger;
// This executor is used to protect {@code mActiveTouchSessions} from being modified
// concurrently. Any operation that adds or removes values should use this executor.
@@ -138,7 +141,7 @@ public class TouchMonitor {
completer.set(predecessor);
}
- if (mActiveTouchSessions.isEmpty()) {
+ if (mActiveTouchSessions.isEmpty() && mInitialized) {
if (mStopMonitoringPending) {
stopMonitoring(false);
} else {
@@ -271,7 +274,7 @@ public class TouchMonitor {
@Override
public void onDestroy(LifecycleOwner owner) {
- stopMonitoring(true);
+ destroy();
}
};
@@ -279,6 +282,11 @@ public class TouchMonitor {
* When invoked, instantiates a new {@link InputSession} to monitor touch events.
*/
private void startMonitoring() {
+ if (!mInitialized) {
+ mLogger.w("attempting to startMonitoring when not initialized");
+ return;
+ }
+
mLogger.i("startMonitoring(): monitoring started");
stopMonitoring(true);
@@ -587,7 +595,7 @@ public class TouchMonitor {
mDisplayHelper = displayHelper;
mWindowManagerService = windowManagerService;
mConfigurationInteractor = configurationInteractor;
- mLoggingName = loggingName + ":TouchMonitor";
+ mLoggingName = loggingName + ":TouchMonitor[" + sNextInstanceId++ + "]";
mLogger = new Logger(logBuffer, mLoggingName);
}
@@ -613,7 +621,8 @@ public class TouchMonitor {
*/
public void destroy() {
if (!mInitialized) {
- throw new IllegalStateException("TouchMonitor not initialized");
+ // In the case that we've already been destroyed, this is a no-op
+ return;
}
stopMonitoring(true);
diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerActionButtonInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerActionButtonInteractor.kt
index 8b5a09b3d9fd..2c026c0bb5ce 100644
--- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerActionButtonInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerActionButtonInteractor.kt
@@ -103,7 +103,7 @@ constructor(
prepareToPerformAction()
returnToCall()
},
- onLongClick = null
+ onLongClick = null,
)
}
@@ -115,15 +115,15 @@ constructor(
dozeLogger.logEmergencyCall()
startEmergencyDialerActivity()
},
- // TODO(b/308001302): The long click detector doesn't work properly, investigate.
+ // TODO(b/369767936): The long click detector doesn't work properly, investigate.
onLongClick = {
if (emergencyAffordanceManager.needsEmergencyAffordance()) {
prepareToPerformAction()
- // TODO(b/298026988): Check that !longPressWasDragged before invoking.
+ // TODO(b/369767936): Check that !longPressWasDragged before invoking.
emergencyAffordanceManager.performEmergencyCall()
}
- }
+ },
)
}
@@ -143,7 +143,7 @@ constructor(
applicationContext.startActivityAsUser(
this,
ActivityOptions.makeCustomAnimation(applicationContext, 0, 0).toBundle(),
- UserHandle(selectedUserInteractor.getSelectedUserId())
+ UserHandle(selectedUserInteractor.getSelectedUserId()),
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt b/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt
index cbea87676d3a..8da4d460b7a5 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt
@@ -30,7 +30,7 @@ import com.android.systemui.dreams.AssistantAttentionMonitor
import com.android.systemui.dreams.DreamMonitor
import com.android.systemui.dreams.homecontrols.HomeControlsDreamStartable
import com.android.systemui.globalactions.GlobalActionsComponent
-import com.android.systemui.inputdevice.tutorial.KeyboardTouchpadTutorialCoreStartable
+import com.android.systemui.haptics.msdl.MSDLCoreStartable
import com.android.systemui.keyboard.KeyboardUI
import com.android.systemui.keyboard.PhysicalKeyboardCoreStartable
import com.android.systemui.keyguard.KeyguardViewConfigurator
@@ -323,4 +323,9 @@ abstract class SystemUICoreStartableModule {
@IntoMap
@ClassKey(BatteryControllerStartable::class)
abstract fun bindsBatteryControllerStartable(impl: BatteryControllerStartable): CoreStartable
+
+ @Binds
+ @IntoMap
+ @ClassKey(MSDLCoreStartable::class)
+ abstract fun bindMSDLCoreStartable(impl: MSDLCoreStartable): CoreStartable
}
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java
index 113e0011f5bd..83f86a718029 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java
@@ -65,6 +65,7 @@ import com.android.systemui.dreams.dagger.DreamOverlayComponent;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.navigationbar.gestural.domain.GestureInteractor;
import com.android.systemui.navigationbar.gestural.domain.TaskMatcher;
+import com.android.systemui.scene.shared.flag.SceneContainerFlag;
import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.touch.TouchInsetManager;
import com.android.systemui.util.concurrency.DelayableExecutor;
@@ -499,8 +500,11 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
mDreamOverlayContainerViewController =
dreamOverlayComponent.getDreamOverlayContainerViewController();
- mTouchMonitor = ambientTouchComponent.getTouchMonitor();
- mTouchMonitor.init();
+
+ if (!SceneContainerFlag.isEnabled()) {
+ mTouchMonitor = ambientTouchComponent.getTouchMonitor();
+ mTouchMonitor.init();
+ }
mStateController.setShouldShowComplications(shouldShowComplications());
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FlagDependencies.kt b/packages/SystemUI/src/com/android/systemui/flags/FlagDependencies.kt
index 820c102e81d8..47f0ecfb237a 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FlagDependencies.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/FlagDependencies.kt
@@ -34,12 +34,14 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.MigrateClocksToBlueprint
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.shade.shared.flag.DualShade
+import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
+import com.android.systemui.statusbar.core.StatusBarSimpleFragment
import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag
import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionRefactor
import com.android.systemui.statusbar.notification.shared.NotificationAvalancheSuppression
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.shared.NotificationThrottleHun
import com.android.systemui.statusbar.notification.shared.PriorityPeopleSection
import javax.inject.Inject
@@ -57,7 +59,7 @@ class FlagDependencies @Inject constructor(featureFlags: FeatureFlagsClassic, ha
// Internal notification frontend dependencies
NotificationAvalancheSuppression.token dependsOn VisualInterruptionRefactor.token
PriorityPeopleSection.token dependsOn SortBySectionTimeFlag.token
- NotificationMinimalismPrototype.token dependsOn NotificationThrottleHun.token
+ NotificationMinimalism.token dependsOn NotificationThrottleHun.token
ModesEmptyShadeFix.token dependsOn FooterViewRefactor.token
ModesEmptyShadeFix.token dependsOn modesUi
@@ -73,6 +75,8 @@ class FlagDependencies @Inject constructor(featureFlags: FeatureFlagsClassic, ha
// Status bar chip dependencies
statusBarCallChipNotificationIconToken dependsOn statusBarUseReposForCallChipToken
statusBarCallChipNotificationIconToken dependsOn statusBarScreenSharingChipsToken
+
+ StatusBarConnectedDisplays.token dependsOn StatusBarSimpleFragment.token
}
private inline val politeNotifications
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
index 493afde96aff..aa1873c7ad41 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
@@ -2298,9 +2298,11 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
}
@Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
+ public boolean onScroll(@Nullable MotionEvent e1, MotionEvent e2,
+ float distanceX,
float distanceY) {
if (distanceY < 0 && distanceY > distanceX
+ && e1 != null
&& e1.getY() <= mStatusBarWindowController.getStatusBarHeight()) {
// Downwards scroll from top
openShadeAndDismiss();
@@ -2310,9 +2312,11 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
}
@Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
+ public boolean onFling(@Nullable MotionEvent e1, MotionEvent e2,
+ float velocityX,
float velocityY) {
if (velocityY > 0 && Math.abs(velocityY) > Math.abs(velocityX)
+ && e1 != null
&& e1.getY() <= mStatusBarWindowController.getStatusBarHeight()) {
// Downwards fling from top
openShadeAndDismiss();
diff --git a/packages/SystemUI/src/com/android/systemui/haptics/msdl/MSDLCoreStartable.kt b/packages/SystemUI/src/com/android/systemui/haptics/msdl/MSDLCoreStartable.kt
new file mode 100644
index 000000000000..58736c608af3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/haptics/msdl/MSDLCoreStartable.kt
@@ -0,0 +1,34 @@
+/*
+ * 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.haptics.msdl
+
+import com.android.systemui.CoreStartable
+import com.android.systemui.dagger.SysUISingleton
+import com.google.android.msdl.domain.MSDLPlayer
+import com.google.android.msdl.logging.MSDLHistoryLogger
+import java.io.PrintWriter
+import javax.inject.Inject
+
+@SysUISingleton
+class MSDLCoreStartable @Inject constructor(private val msdlPlayer: MSDLPlayer) : CoreStartable {
+ override fun start() {}
+
+ override fun dump(pw: PrintWriter, args: Array<out String>) {
+ pw.println("MSDLPlayer history of the last ${MSDLHistoryLogger.HISTORY_SIZE} events:")
+ msdlPlayer.getHistory().forEach { event -> pw.println("$event") }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialMetricsLogger.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialMetricsLogger.kt
new file mode 100644
index 000000000000..144c5ead1bb8
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialMetricsLogger.kt
@@ -0,0 +1,55 @@
+/*
+ * 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.inputdevice.tutorial
+
+import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_CONTEXTUAL_EDU
+import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER
+import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEYBOARD
+import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_TOUCHPAD
+import com.android.systemui.shared.system.SysUiStatsLog
+import javax.inject.Inject
+
+class KeyboardTouchpadTutorialMetricsLogger @Inject constructor() {
+
+ fun logPeripheralTutorialLaunched(entryPointExtra: String?, tutorialTypeExtra: String?) {
+ val entryPoint =
+ when (entryPointExtra) {
+ INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER ->
+ SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__SCHEDULED
+ INTENT_TUTORIAL_ENTRY_POINT_CONTEXTUAL_EDU ->
+ SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__CONTEXTUAL_EDU
+ else -> SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__APP
+ }
+
+ val tutorialType =
+ when (tutorialTypeExtra) {
+ INTENT_TUTORIAL_TYPE_KEYBOARD ->
+ SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__KEYBOARD
+ INTENT_TUTORIAL_TYPE_TOUCHPAD ->
+ SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__TOUCHPAD
+ else -> SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__BOTH
+ }
+
+ SysUiStatsLog.write(SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED, entryPoint, tutorialType)
+ }
+
+ fun logPeripheralTutorialLaunchedFromSettings() {
+ val entryPoint = SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__SETTINGS
+ val tutorialType = SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__TOUCHPAD
+ SysUiStatsLog.write(SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED, entryPoint, tutorialType)
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/TutorialNotificationCoordinator.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/TutorialNotificationCoordinator.kt
index 5d9dda3899cd..f2afaee1870b 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/TutorialNotificationCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/TutorialNotificationCoordinator.kt
@@ -31,6 +31,8 @@ import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSched
import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.Companion.TAG
import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.TutorialType
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity
+import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_KEY
+import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_BOTH
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEY
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEYBOARD
@@ -48,7 +50,7 @@ constructor(
@Background private val backgroundScope: CoroutineScope,
@Application private val context: Context,
private val tutorialSchedulerInteractor: TutorialSchedulerInteractor,
- private val notificationManager: NotificationManager
+ private val notificationManager: NotificationManager,
) {
fun start() {
backgroundScope.launch {
@@ -68,7 +70,7 @@ constructor(
val extras = Bundle()
extras.putString(
Notification.EXTRA_SUBSTITUTE_APP_NAME,
- context.getString(com.android.internal.R.string.android_system_label)
+ context.getString(com.android.internal.R.string.android_system_label),
)
val info = getNotificationInfo(tutorialType)!!
@@ -91,7 +93,7 @@ constructor(
NotificationChannel(
CHANNEL_ID,
context.getString(com.android.internal.R.string.android_system_label),
- NotificationManager.IMPORTANCE_DEFAULT
+ NotificationManager.IMPORTANCE_DEFAULT,
)
notificationManager.createNotificationChannel(channel)
}
@@ -100,13 +102,14 @@ constructor(
val intent =
Intent(context, KeyboardTouchpadTutorialActivity::class.java).apply {
putExtra(INTENT_TUTORIAL_TYPE_KEY, tutorialType)
+ putExtra(INTENT_TUTORIAL_ENTRY_POINT_KEY, INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
return PendingIntent.getActivity(
context,
/* requestCode= */ 0,
intent,
- PendingIntent.FLAG_IMMUTABLE
+ PendingIntent.FLAG_IMMUTABLE,
)
}
@@ -118,13 +121,13 @@ constructor(
NotificationInfo(
context.getString(R.string.launch_keyboard_tutorial_notification_title),
context.getString(R.string.launch_keyboard_tutorial_notification_content),
- INTENT_TUTORIAL_TYPE_KEYBOARD
+ INTENT_TUTORIAL_TYPE_KEYBOARD,
)
TutorialType.TOUCHPAD ->
NotificationInfo(
context.getString(R.string.launch_touchpad_tutorial_notification_title),
context.getString(R.string.launch_touchpad_tutorial_notification_content),
- INTENT_TUTORIAL_TYPE_TOUCHPAD
+ INTENT_TUTORIAL_TYPE_TOUCHPAD,
)
TutorialType.BOTH ->
NotificationInfo(
@@ -134,7 +137,7 @@ constructor(
context.getString(
R.string.launch_keyboard_touchpad_tutorial_notification_content
),
- INTENT_TUTORIAL_TYPE_BOTH
+ INTENT_TUTORIAL_TYPE_BOTH,
)
TutorialType.NONE -> null
}
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt
index c130c6c7fe12..29febd32e925 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt
@@ -30,6 +30,7 @@ import androidx.lifecycle.lifecycleScope
import com.android.compose.theme.PlatformTheme
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext
+import com.android.systemui.inputdevice.tutorial.KeyboardTouchpadTutorialMetricsLogger
import com.android.systemui.inputdevice.tutorial.TouchpadTutorialScreensProvider
import com.android.systemui.inputdevice.tutorial.ui.composable.ActionKeyTutorialScreen
import com.android.systemui.inputdevice.tutorial.ui.viewmodel.KeyboardTouchpadTutorialViewModel
@@ -51,6 +52,7 @@ constructor(
private val viewModelFactoryAssistedProvider: ViewModelFactoryAssistedProvider,
private val touchpadTutorialScreensProvider: Optional<TouchpadTutorialScreensProvider>,
private val logger: InputDeviceTutorialLogger,
+ private val metricsLogger: KeyboardTouchpadTutorialMetricsLogger,
) : ComponentActivity() {
companion object {
@@ -58,6 +60,9 @@ constructor(
const val INTENT_TUTORIAL_TYPE_TOUCHPAD = "touchpad"
const val INTENT_TUTORIAL_TYPE_KEYBOARD = "keyboard"
const val INTENT_TUTORIAL_TYPE_BOTH = "both"
+ const val INTENT_TUTORIAL_ENTRY_POINT_KEY = "entry_point"
+ const val INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER = "scheduler"
+ const val INTENT_TUTORIAL_ENTRY_POINT_CONTEXTUAL_EDU = "contextual_edu"
}
private val vm by
@@ -86,6 +91,10 @@ constructor(
PlatformTheme { KeyboardTouchpadTutorialContainer(vm, touchpadTutorialScreensProvider) }
}
if (savedInstanceState == null) {
+ metricsLogger.logPeripheralTutorialLaunched(
+ intent.getStringExtra(INTENT_TUTORIAL_ENTRY_POINT_KEY),
+ intent.getStringExtra(INTENT_TUTORIAL_TYPE_KEY),
+ )
logger.logOpenTutorial(TutorialContext.KEYBOARD_TOUCHPAD_TUTORIAL)
}
}
@@ -109,7 +118,7 @@ fun KeyboardTouchpadTutorialContainer(
ACTION_KEY ->
ActionKeyTutorialScreen(
onDoneButtonClicked = vm::onDoneButtonClicked,
- onBack = vm::onBack
+ onBack = vm::onBack,
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt
index b9a16c402e59..52263ce64a85 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt
@@ -18,6 +18,7 @@ package com.android.systemui.keyboard.shortcut.ui.view
import android.content.ActivityNotFoundException
import android.content.Intent
+import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.res.Configuration
import android.os.Bundle
import android.provider.Settings
@@ -125,7 +126,7 @@ constructor(private val userTracker: UserTracker, private val viewModel: Shortcu
private fun onKeyboardSettingsClicked() {
try {
startActivityAsUser(
- Intent(Settings.ACTION_HARD_KEYBOARD_SETTINGS),
+ Intent(Settings.ACTION_HARD_KEYBOARD_SETTINGS).addFlags(FLAG_ACTIVITY_NEW_TASK),
userTracker.userHandle,
)
} catch (e: ActivityNotFoundException) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
index 68a252b2caba..654c76359505 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
@@ -515,7 +515,13 @@ public class KeyguardSliceProvider extends SliceProvider implements
}
protected void notifyChange() {
- mBgHandler.post(() -> mContentResolver.notifyChange(mSliceUri, null /* observer */));
+ mBgHandler.post(() -> {
+ try {
+ mContentResolver.notifyChange(mSliceUri, null /* observer */);
+ } catch (Exception e) {
+ Log.e(TAG, "Error on mContentResolver.notifyChange()", e);
+ }
+ });
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt
index 416eabae78eb..063adc834f30 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewConfigurator.kt
@@ -63,6 +63,7 @@ import com.android.systemui.shade.NotificationShadeWindowView
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.statusbar.KeyguardIndicationController
import com.android.systemui.statusbar.VibratorHelper
+import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationLockscreenScrimViewModel
import com.android.systemui.statusbar.phone.ScreenOffAnimationController
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator
@@ -102,6 +103,7 @@ constructor(
private val keyguardClockViewModel: KeyguardClockViewModel,
private val smartspaceViewModel: KeyguardSmartspaceViewModel,
private val lockscreenContentViewModelFactory: LockscreenContentViewModel.Factory,
+ private val notificationScrimViewModelFactory: NotificationLockscreenScrimViewModel.Factory,
private val lockscreenSceneBlueprintsLazy: Lazy<Set<LockscreenSceneBlueprint>>,
private val clockInteractor: KeyguardClockInteractor,
private val keyguardViewMediator: KeyguardViewMediator,
@@ -207,6 +209,7 @@ constructor(
private fun createLockscreen(
context: Context,
viewModelFactory: LockscreenContentViewModel.Factory,
+ notificationScrimViewModelFactory: NotificationLockscreenScrimViewModel.Factory,
blueprints: Set<@JvmSuppressWildcards LockscreenSceneBlueprint>,
): View {
val sceneBlueprints =
@@ -222,6 +225,8 @@ constructor(
with(
LockscreenContent(
viewModelFactory = viewModelFactory,
+ notificationScrimViewModelFactory =
+ notificationScrimViewModelFactory,
blueprints = sceneBlueprints,
clockInteractor = clockInteractor,
)
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 0a38ce07a798..9c7cc81c34aa 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -147,6 +147,7 @@ import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.SystemPropertiesHelper;
import com.android.systemui.keyguard.dagger.KeyguardModule;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
+import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionBootInteractor;
import com.android.systemui.keyguard.shared.model.TransitionStep;
import com.android.systemui.log.SessionTracker;
import com.android.systemui.navigationbar.NavigationModeController;
@@ -265,6 +266,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
private static final int SYSTEM_READY = 18;
private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19;
+ private static final int BOOT_INTERACTOR = 20;
/** Enum for reasons behind updating wakeAndUnlock state. */
@Retention(RetentionPolicy.SOURCE)
@@ -1390,6 +1392,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
private final DozeParameters mDozeParameters;
private final SelectedUserInteractor mSelectedUserInteractor;
private final KeyguardInteractor mKeyguardInteractor;
+ private final KeyguardTransitionBootInteractor mTransitionBootInteractor;
@VisibleForTesting
protected FoldGracePeriodProvider mFoldGracePeriodProvider =
new FoldGracePeriodProvider();
@@ -1484,6 +1487,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
Lazy<WindowManagerLockscreenVisibilityManager> wmLockscreenVisibilityManager,
SelectedUserInteractor selectedUserInteractor,
KeyguardInteractor keyguardInteractor,
+ KeyguardTransitionBootInteractor transitionBootInteractor,
WindowManagerOcclusionManager wmOcclusionManager) {
mContext = context;
mUserTracker = userTracker;
@@ -1524,6 +1528,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
mDozeParameters = dozeParameters;
mSelectedUserInteractor = selectedUserInteractor;
mKeyguardInteractor = keyguardInteractor;
+ mTransitionBootInteractor = transitionBootInteractor;
mStatusBarStateController = statusBarStateController;
statusBarStateController.addCallback(this);
@@ -1678,6 +1683,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
adjustStatusBarLocked();
mDreamOverlayStateController.addCallback(mDreamOverlayStateCallback);
+ mHandler.obtainMessage(BOOT_INTERACTOR).sendToTarget();
+
final DreamViewModel dreamViewModel = mDreamViewModel.get();
final CommunalTransitionViewModel communalViewModel =
mCommunalTransitionViewModel.get();
@@ -2705,11 +2712,19 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
message = "SYSTEM_READY";
handleSystemReady();
break;
+ case BOOT_INTERACTOR:
+ message = "BOOT_INTERACTOR";
+ handleBootInteractor();
+ break;
}
Log.d(TAG, "KeyguardViewMediator queue processing message: " + message);
}
};
+ private void handleBootInteractor() {
+ mTransitionBootInteractor.start();
+ }
+
private void tryKeyguardDone() {
if (DEBUG) {
Log.d(TAG, "tryKeyguardDone: pending - " + mKeyguardDonePending + ", animRan - "
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
index 8a3d01707540..d0a40ec3a361 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
@@ -59,6 +59,7 @@ import com.android.systemui.keyguard.data.quickaffordance.KeyguardDataQuickAffor
import com.android.systemui.keyguard.data.repository.DeviceEntryFaceAuthModule;
import com.android.systemui.keyguard.data.repository.KeyguardRepositoryModule;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
+import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionBootInteractor;
import com.android.systemui.keyguard.domain.interactor.StartKeyguardTransitionModule;
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLogger;
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLoggerImpl;
@@ -175,6 +176,7 @@ public interface KeyguardModule {
Lazy<WindowManagerLockscreenVisibilityManager> wmLockscreenVisibilityManager,
SelectedUserInteractor selectedUserInteractor,
KeyguardInteractor keyguardInteractor,
+ KeyguardTransitionBootInteractor transitionBootInteractor,
WindowManagerOcclusionManager windowManagerOcclusionManager) {
return new KeyguardViewMediator(
context,
@@ -225,6 +227,7 @@ public interface KeyguardModule {
wmLockscreenVisibilityManager,
selectedUserInteractor,
keyguardInteractor,
+ transitionBootInteractor,
windowManagerOcclusionManager);
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt
index 797a4ec419a9..690ae71aa56e 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt
@@ -23,6 +23,7 @@ import android.annotation.FloatRange
import android.annotation.SuppressLint
import android.os.Trace
import android.util.Log
+import com.android.app.animation.Interpolators
import com.android.app.tracing.coroutines.withContext
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
@@ -95,7 +96,7 @@ interface KeyguardTransitionRepository {
* Emits STARTED and FINISHED transition steps to the given state. This is used during boot to
* seed the repository with the appropriate initial state.
*/
- suspend fun emitInitialStepsFromOff(to: KeyguardState)
+ suspend fun emitInitialStepsFromOff(to: KeyguardState, testSetup: Boolean = false)
/**
* Allows manual control of a transition. When calling [startTransition], the consumer must pass
@@ -108,16 +109,14 @@ interface KeyguardTransitionRepository {
suspend fun updateTransition(
transitionId: UUID,
@FloatRange(from = 0.0, to = 1.0) value: Float,
- state: TransitionState
+ state: TransitionState,
)
}
@SysUISingleton
class KeyguardTransitionRepositoryImpl
@Inject
-constructor(
- @Main val mainDispatcher: CoroutineDispatcher,
-) : KeyguardTransitionRepository {
+constructor(@Main val mainDispatcher: CoroutineDispatcher) : KeyguardTransitionRepository {
/**
* Each transition between [KeyguardState]s will have an associated Flow. In order to collect
* these events, clients should call [transition].
@@ -140,7 +139,7 @@ constructor(
ownerName = "",
from = KeyguardState.OFF,
to = KeyguardState.OFF,
- animator = null
+ animator = null,
)
)
override var currentTransitionInfoInternal = _currentTransitionInfo.asStateFlow()
@@ -159,12 +158,7 @@ constructor(
// to either GONE or LOCKSCREEN once we're booted up and can determine which state we should
// start in.
emitTransition(
- TransitionStep(
- KeyguardState.OFF,
- KeyguardState.OFF,
- 1f,
- TransitionState.FINISHED,
- )
+ TransitionStep(KeyguardState.OFF, KeyguardState.OFF, 1f, TransitionState.FINISHED)
)
}
@@ -217,7 +211,7 @@ constructor(
TransitionStep(
info,
(animation.animatedValue as Float),
- TransitionState.RUNNING
+ TransitionState.RUNNING,
)
)
}
@@ -266,7 +260,7 @@ constructor(
override suspend fun updateTransition(
transitionId: UUID,
@FloatRange(from = 0.0, to = 1.0) value: Float,
- state: TransitionState
+ state: TransitionState,
) {
// There is no fairness guarantee with 'withContext', which means that transitions could
// be processed out of order. Use a Mutex to guarantee ordering. [startTransition]
@@ -282,7 +276,7 @@ constructor(
private suspend fun updateTransitionInternal(
transitionId: UUID,
@FloatRange(from = 0.0, to = 1.0) value: Float,
- state: TransitionState
+ state: TransitionState,
) {
if (updateTransitionId != transitionId) {
Log.e(TAG, "Attempting to update with old/invalid transitionId: $transitionId")
@@ -303,34 +297,51 @@ constructor(
lastStep = nextStep
}
- override suspend fun emitInitialStepsFromOff(to: KeyguardState) {
- _currentTransitionInfo.value =
- TransitionInfo(
- ownerName = "KeyguardTransitionRepository(boot)",
- from = KeyguardState.OFF,
- to = to,
- animator = null
+ override suspend fun emitInitialStepsFromOff(to: KeyguardState, testSetup: Boolean) {
+ val ownerName = "KeyguardTransitionRepository(boot)"
+ // Tests runs on testDispatcher, which is not the main thread, causing the animator thread
+ // check to fail
+ if (testSetup) {
+ _currentTransitionInfo.value =
+ TransitionInfo(
+ ownerName = ownerName,
+ from = KeyguardState.OFF,
+ to = to,
+ animator = null,
+ )
+ emitTransition(
+ TransitionStep(
+ KeyguardState.OFF,
+ to,
+ 0f,
+ TransitionState.STARTED,
+ ownerName = ownerName,
+ )
)
- emitTransition(
- TransitionStep(
- KeyguardState.OFF,
- to,
- 0f,
- TransitionState.STARTED,
- ownerName = "KeyguardTransitionRepository(boot)",
+ emitTransition(
+ TransitionStep(
+ KeyguardState.OFF,
+ to,
+ 1f,
+ TransitionState.FINISHED,
+ ownerName = ownerName,
+ )
)
- )
-
- emitTransition(
- TransitionStep(
- KeyguardState.OFF,
- to,
- 1f,
- TransitionState.FINISHED,
- ownerName = "KeyguardTransitionRepository(boot)",
- ),
- )
+ } else {
+ startTransition(
+ TransitionInfo(
+ ownerName = ownerName,
+ from = KeyguardState.OFF,
+ to = to,
+ animator =
+ ValueAnimator().apply {
+ interpolator = Interpolators.LINEAR
+ duration = 933L
+ },
+ )
+ )
+ }
}
private fun logAndTrace(step: TransitionStep, isManual: Boolean) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromOccludedTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromOccludedTransitionInteractor.kt
index 0343786bb1fb..840bc0fb5f99 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromOccludedTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromOccludedTransitionInteractor.kt
@@ -106,7 +106,7 @@ constructor(
startTransitionToLockscreenOrHub(
isIdleOnCommunal,
showCommunalFromOccluded,
- dreamFromOccluded
+ dreamFromOccluded,
)
}
}
@@ -127,7 +127,7 @@ constructor(
startTransitionToLockscreenOrHub(
isIdleOnCommunal,
showCommunalFromOccluded,
- dreamFromOccluded
+ dreamFromOccluded,
)
}
}
@@ -147,7 +147,7 @@ constructor(
communalSceneInteractor.changeScene(
newScene = CommunalScenes.Communal,
loggingReason = "occluded to hub",
- transitionKey = CommunalTransitionKeys.SimpleFade
+ transitionKey = CommunalTransitionKeys.SimpleFade,
)
} else {
startTransitionTo(KeyguardState.GLANCEABLE_HUB)
@@ -210,8 +210,9 @@ constructor(
duration =
when (toState) {
- KeyguardState.LOCKSCREEN -> TO_LOCKSCREEN_DURATION
+ KeyguardState.ALTERNATE_BOUNCER -> TO_ALTERNATE_BOUNCER_DURATION
KeyguardState.GLANCEABLE_HUB -> TO_GLANCEABLE_HUB_DURATION
+ KeyguardState.LOCKSCREEN -> TO_LOCKSCREEN_DURATION
else -> DEFAULT_DURATION
}.inWholeMilliseconds
}
@@ -220,9 +221,10 @@ constructor(
companion object {
const val TAG = "FromOccludedTransitionInteractor"
private val DEFAULT_DURATION = 500.milliseconds
- val TO_LOCKSCREEN_DURATION = 933.milliseconds
- val TO_GLANCEABLE_HUB_DURATION = 250.milliseconds
+ val TO_ALTERNATE_BOUNCER_DURATION = DEFAULT_DURATION
val TO_AOD_DURATION = DEFAULT_DURATION
val TO_DOZING_DURATION = DEFAULT_DURATION
+ val TO_GLANCEABLE_HUB_DURATION = 250.milliseconds
+ val TO_LOCKSCREEN_DURATION = 933.milliseconds
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractor.kt
index ea80911335fa..18b14951ee70 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractor.kt
@@ -28,7 +28,6 @@ import com.android.systemui.keyguard.shared.model.KeyguardDone
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
import com.android.systemui.power.domain.interactor.PowerInteractor
-import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.domain.interactor.ShadeInteractor
@@ -60,7 +59,6 @@ constructor(
transitionInteractor: KeyguardTransitionInteractor,
val dismissInteractor: KeyguardDismissInteractor,
@Application private val applicationScope: CoroutineScope,
- sceneInteractor: Lazy<SceneInteractor>,
deviceUnlockedInteractor: Lazy<DeviceUnlockedInteractor>,
powerInteractor: PowerInteractor,
alternateBouncerInteractor: AlternateBouncerInteractor,
@@ -102,20 +100,20 @@ constructor(
private val isOnShadeWhileUnlocked: Flow<Boolean> =
if (SceneContainerFlag.isEnabled) {
combine(
- sceneInteractor.get().currentScene,
+ shadeInteractor.get().isAnyExpanded,
deviceUnlockedInteractor.get().deviceUnlockStatus,
- ) { scene, unlockStatus ->
- unlockStatus.isUnlocked &&
- (scene == Scenes.QuickSettings || scene == Scenes.Shade)
+ ) { isAnyExpanded, unlockStatus ->
+ isAnyExpanded && unlockStatus.isUnlocked
}
.distinctUntilChanged()
} else if (ComposeBouncerFlags.isOnlyComposeBouncerEnabled()) {
combine(
- shadeInteractor.get().isAnyExpanded,
- keyguardInteractor.get().isKeyguardDismissible,
- ) { isAnyExpanded, keyguardDismissible ->
- isAnyExpanded && keyguardDismissible
- }
+ shadeInteractor.get().isAnyExpanded,
+ keyguardInteractor.get().isKeyguardDismissible,
+ ) { isAnyExpanded, keyguardDismissible ->
+ isAnyExpanded && keyguardDismissible
+ }
+ .distinctUntilChanged()
} else {
flow {
error(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionBootInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionBootInteractor.kt
index b2183007c48c..89f636d4a270 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionBootInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionBootInteractor.kt
@@ -17,7 +17,6 @@
package com.android.systemui.keyguard.domain.interactor
import android.util.Log
-import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
@@ -46,7 +45,7 @@ constructor(
val keyguardTransitionInteractor: KeyguardTransitionInteractor,
val internalTransitionInteractor: InternalKeyguardTransitionInteractor,
val repository: KeyguardTransitionRepository,
-) : CoreStartable {
+) {
/**
* Whether the lockscreen should be showing when the device starts up for the first time. If not
@@ -60,14 +59,14 @@ constructor(
}
}
- override fun start() {
+ fun start() {
scope.launch {
if (internalTransitionInteractor.currentTransitionInfoInternal.value.from != OFF) {
Log.e(
"KeyguardTransitionInteractor",
"showLockscreenOnBoot emitted, but we've already " +
"transitioned to a state other than OFF. We'll respect that " +
- "transition, but this should not happen."
+ "transition, but this should not happen.",
)
} else {
if (SceneContainerFlag.isEnabled) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionCoreStartable.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionCoreStartable.kt
index 25b8fd32e82a..b71533389e2d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionCoreStartable.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionCoreStartable.kt
@@ -27,7 +27,6 @@ class KeyguardTransitionCoreStartable
constructor(
private val interactors: Set<TransitionInteractor>,
private val auditLogger: KeyguardTransitionAuditLogger,
- private val bootInteractor: KeyguardTransitionBootInteractor,
private val statusBarDisableFlagsInteractor: StatusBarDisableFlagsInteractor,
private val keyguardStateCallbackInteractor: KeyguardStateCallbackInteractor,
) : CoreStartable {
@@ -54,7 +53,6 @@ constructor(
it.start()
}
auditLogger.start()
- bootInteractor.start()
statusBarDisableFlagsInteractor.start()
keyguardStateCallbackInteractor.start()
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt
index f1b9cba11051..00aa44fe795b 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt
@@ -47,56 +47,53 @@ object KeyguardBlueprintViewBinder {
constraintLayout.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.CREATED) {
launch("$TAG#viewModel.blueprint") {
- viewModel.blueprint
- .pairwise(
- null as KeyguardBlueprint?,
- )
- .collect { (prevBlueprint, blueprint) ->
- val config = Config.DEFAULT
- val transition =
- if (
- !KeyguardBottomAreaRefactor.isEnabled &&
- prevBlueprint != null &&
- prevBlueprint != blueprint
- ) {
- BaseBlueprintTransition(clockViewModel)
- .addTransition(
- IntraBlueprintTransition(
- config,
- clockViewModel,
- smartspaceViewModel
- )
+ viewModel.blueprint.pairwise(null as KeyguardBlueprint?).collect {
+ (prevBlueprint, blueprint) ->
+ val config = Config.DEFAULT
+ val transition =
+ if (
+ !KeyguardBottomAreaRefactor.isEnabled &&
+ prevBlueprint != null &&
+ prevBlueprint != blueprint
+ ) {
+ BaseBlueprintTransition(clockViewModel)
+ .addTransition(
+ IntraBlueprintTransition(
+ config,
+ clockViewModel,
+ smartspaceViewModel,
)
- } else {
- IntraBlueprintTransition(
- config,
- clockViewModel,
- smartspaceViewModel
)
- }
-
- viewModel.runTransition(constraintLayout, transition, config) {
- // Replace sections from the previous blueprint with the new ones
- blueprint.replaceViews(
- constraintLayout,
- prevBlueprint,
- config.rebuildSections
+ } else {
+ IntraBlueprintTransition(
+ config,
+ clockViewModel,
+ smartspaceViewModel,
)
+ }
+
+ viewModel.runTransition(constraintLayout, transition, config) {
+ // Replace sections from the previous blueprint with the new ones
+ blueprint.replaceViews(
+ constraintLayout,
+ prevBlueprint,
+ config.rebuildSections,
+ )
- val cs =
- ConstraintSet().apply {
- clone(constraintLayout)
- val emptyLayout = ConstraintSet.Layout()
- knownIds.forEach {
- getConstraint(it).layout.copyFrom(emptyLayout)
- }
- blueprint.applyConstraints(this)
+ val cs =
+ ConstraintSet().apply {
+ clone(constraintLayout)
+ val emptyLayout = ConstraintSet.Layout()
+ knownIds.forEach {
+ getConstraint(it).layout.copyFrom(emptyLayout)
}
+ blueprint.applyConstraints(this)
+ }
- logAlphaVisibilityScaleOfAppliedConstraintSet(cs, clockViewModel)
- cs.applyTo(constraintLayout)
- }
+ logAlphaVisibilityScaleOfAppliedConstraintSet(cs, clockViewModel)
+ cs.applyTo(constraintLayout)
}
+ }
}
launch("$TAG#viewModel.refreshTransition") {
@@ -105,7 +102,8 @@ object KeyguardBlueprintViewBinder {
viewModel.runTransition(
constraintLayout,
- IntraBlueprintTransition(config, clockViewModel, smartspaceViewModel),
+ clockViewModel,
+ smartspaceViewModel,
config,
) {
blueprint.rebuildViews(constraintLayout, config.rebuildSections)
@@ -126,7 +124,7 @@ object KeyguardBlueprintViewBinder {
private fun logAlphaVisibilityScaleOfAppliedConstraintSet(
cs: ConstraintSet,
- viewModel: KeyguardClockViewModel
+ viewModel: KeyguardClockViewModel,
) {
val currentClock = viewModel.currentClock.value
if (!DEBUG || currentClock == null) return
@@ -137,19 +135,19 @@ object KeyguardBlueprintViewBinder {
TAG,
"applyCsToSmallClock: vis=${cs.getVisibility(smallClockViewId)} " +
"alpha=${cs.getConstraint(smallClockViewId).propertySet.alpha} " +
- "scale=${cs.getConstraint(smallClockViewId).transform.scaleX} "
+ "scale=${cs.getConstraint(smallClockViewId).transform.scaleX} ",
)
Log.i(
TAG,
"applyCsToLargeClock: vis=${cs.getVisibility(largeClockViewId)} " +
"alpha=${cs.getConstraint(largeClockViewId).propertySet.alpha} " +
"scale=${cs.getConstraint(largeClockViewId).transform.scaleX} " +
- "pivotX=${cs.getConstraint(largeClockViewId).transform.transformPivotX} "
+ "pivotX=${cs.getConstraint(largeClockViewId).transform.transformPivotX} ",
)
Log.i(
TAG,
"applyCsToSmartspaceDate: vis=${cs.getVisibility(smartspaceDateId)} " +
- "alpha=${cs.getConstraint(smartspaceDateId).propertySet.alpha}"
+ "alpha=${cs.getConstraint(smartspaceDateId).propertySet.alpha}",
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/transitions/IntraBlueprintTransition.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/transitions/IntraBlueprintTransition.kt
index aa0a9d9cee1f..9a55f7bab33b 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/transitions/IntraBlueprintTransition.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/transitions/IntraBlueprintTransition.kt
@@ -29,18 +29,18 @@ class IntraBlueprintTransition(
smartspaceViewModel: KeyguardSmartspaceViewModel,
) : TransitionSet() {
- enum class Type(
- val priority: Int,
- val animateNotifChanges: Boolean,
- ) {
+ enum class Type(val priority: Int, val animateNotifChanges: Boolean) {
ClockSize(100, true),
ClockCenter(99, false),
DefaultClockStepping(98, false),
- SmartspaceVisibility(2, true),
- DefaultTransition(1, false),
+ SmartspaceVisibility(3, true),
+ DefaultTransition(2, false),
// When transition between blueprint, we don't need any duration or interpolator but we need
// all elements go to correct state
- NoTransition(0, false),
+ NoTransition(1, false),
+ // Similar to NoTransition, except also does not explicitly update any alpha. Used in
+ // OFF->LOCKSCREEN transition
+ Init(0, false),
}
data class Config(
@@ -57,6 +57,7 @@ class IntraBlueprintTransition(
init {
ordering = ORDERING_TOGETHER
when (config.type) {
+ Type.Init -> {}
Type.NoTransition -> {}
Type.DefaultClockStepping ->
addTransition(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt
index ff848264db68..a1c963b3137a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt
@@ -53,14 +53,11 @@ import kotlinx.coroutines.DisposableHandle
internal fun ConstraintSet.setVisibility(views: Iterable<View>, visibility: Int) =
views.forEach { view -> this.setVisibility(view.id, visibility) }
-internal fun ConstraintSet.setAlpha(views: Iterable<View>, alpha: Float) =
- views.forEach { view -> this.setAlpha(view.id, alpha) }
+internal fun ConstraintSet.setScaleX(views: Iterable<View>, scaleX: Float) =
+ views.forEach { view -> this.setScaleX(view.id, scaleX) }
-internal fun ConstraintSet.setScaleX(views: Iterable<View>, alpha: Float) =
- views.forEach { view -> this.setScaleX(view.id, alpha) }
-
-internal fun ConstraintSet.setScaleY(views: Iterable<View>, alpha: Float) =
- views.forEach { view -> this.setScaleY(view.id, alpha) }
+internal fun ConstraintSet.setScaleY(views: Iterable<View>, scaleY: Float) =
+ views.forEach { view -> this.setScaleY(view.id, scaleY) }
@SysUISingleton
class ClockSection
@@ -126,8 +123,6 @@ constructor(
return constraintSet.apply {
setVisibility(getTargetClockFace(clock).views, VISIBLE)
setVisibility(getNonTargetClockFace(clock).views, GONE)
- setAlpha(getTargetClockFace(clock).views, 1F)
- setAlpha(getNonTargetClockFace(clock).views, 0F)
if (!keyguardClockViewModel.isLargeClockVisible.value) {
connect(sharedR.id.bc_smartspace_view, TOP, sharedR.id.date_smartspace_view, BOTTOM)
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerToOccludedTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerToOccludedTransitionViewModel.kt
index 3f2ef29c9570..c49e7833e349 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerToOccludedTransitionViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AlternateBouncerToOccludedTransitionViewModel.kt
@@ -28,22 +28,22 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
/**
- * Breaks down ALTERNATE_BOUNCER->GONE transition into discrete steps for corresponding views to
+ * Breaks down ALTERNATE_BOUNCER->OCCLUDED transition into discrete steps for corresponding views to
* consume.
*/
@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
class AlternateBouncerToOccludedTransitionViewModel
@Inject
-constructor(
- animationFlow: KeyguardTransitionAnimationFlow,
-) : DeviceEntryIconTransition {
+constructor(animationFlow: KeyguardTransitionAnimationFlow) : DeviceEntryIconTransition {
private val transitionAnimation =
animationFlow.setup(
duration = TO_OCCLUDED_DURATION,
edge = Edge.create(from = ALTERNATE_BOUNCER, to = OCCLUDED),
)
+ val lockscreenAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(0f)
+
override val deviceEntryParentViewAlpha: Flow<Float> =
transitionAnimation.immediatelyTransitionTo(0f)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryBackgroundViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryBackgroundViewModel.kt
index a021de446911..ca1a8006c6bb 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryBackgroundViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryBackgroundViewModel.kt
@@ -56,6 +56,7 @@ constructor(
occludedToAodTransitionViewModel: OccludedToAodTransitionViewModel,
occludedToDozingTransitionViewModel: OccludedToDozingTransitionViewModel,
occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel,
+ offToLockscreenTransitionViewModel: OffToLockscreenTransitionViewModel,
primaryBouncerToAodTransitionViewModel: PrimaryBouncerToAodTransitionViewModel,
primaryBouncerToDozingTransitionViewModel: PrimaryBouncerToDozingTransitionViewModel,
primaryBouncerToLockscreenTransitionViewModel: PrimaryBouncerToLockscreenTransitionViewModel,
@@ -67,14 +68,14 @@ constructor(
.map {
Utils.getColorAttrDefaultColor(
context,
- com.android.internal.R.attr.colorSurface
+ com.android.internal.R.attr.colorSurface,
)
}
.onStart {
emit(
Utils.getColorAttrDefaultColor(
context,
- com.android.internal.R.attr.colorSurface
+ com.android.internal.R.attr.colorSurface,
)
)
}
@@ -86,23 +87,23 @@ constructor(
deviceEntryIconViewModel.useBackgroundProtection.flatMapLatest { useBackground ->
if (useBackground) {
setOf(
- lockscreenToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ alternateBouncerToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ alternateBouncerToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
aodToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ dozingToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ dreamingToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ dreamingToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
goneToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
- primaryBouncerToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ goneToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ goneToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ lockscreenToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
occludedToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ occludedToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
occludedToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
- dreamingToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
- alternateBouncerToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
- goneToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
- goneToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ offToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ primaryBouncerToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
primaryBouncerToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
- dozingToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
- alternateBouncerToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
- dreamingToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
- primaryBouncerToLockscreenTransitionViewModel
- .deviceEntryBackgroundViewAlpha,
- occludedToDozingTransitionViewModel.deviceEntryBackgroundViewAlpha,
+ primaryBouncerToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
)
.merge()
.onStart {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModel.kt
index 4cf3c4e7f6d0..1289036c7ae0 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModel.kt
@@ -24,6 +24,9 @@ import android.util.Log
import androidx.constraintlayout.widget.ConstraintLayout
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
+import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
+import com.android.systemui.keyguard.shared.model.KeyguardState
+import com.android.systemui.keyguard.ui.view.layout.blueprints.transitions.IntraBlueprintTransition
import com.android.systemui.keyguard.ui.view.layout.blueprints.transitions.IntraBlueprintTransition.Config
import com.android.systemui.keyguard.ui.view.layout.blueprints.transitions.IntraBlueprintTransition.Type
import javax.inject.Inject
@@ -37,6 +40,7 @@ class KeyguardBlueprintViewModel
constructor(
@Main private val handler: Handler,
private val keyguardBlueprintInteractor: KeyguardBlueprintInteractor,
+ private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
) {
val blueprint = keyguardBlueprintInteractor.blueprint
val blueprintId = keyguardBlueprintInteractor.blueprintId
@@ -49,12 +53,12 @@ constructor(
private val transitionListener =
object : Transition.TransitionListener {
override fun onTransitionCancel(transition: Transition) {
- if (DEBUG) Log.e(TAG, "onTransitionCancel: ${transition::class.simpleName}")
+ if (DEBUG) Log.w(TAG, "onTransitionCancel: ${transition::class.simpleName}")
updateTransitions(null) { remove(transition) }
}
override fun onTransitionEnd(transition: Transition) {
- if (DEBUG) Log.e(TAG, "onTransitionEnd: ${transition::class.simpleName}")
+ if (DEBUG) Log.i(TAG, "onTransitionEnd: ${transition::class.simpleName}")
updateTransitions(null) { remove(transition) }
}
@@ -86,6 +90,28 @@ constructor(
fun runTransition(
constraintLayout: ConstraintLayout,
+ clockViewModel: KeyguardClockViewModel,
+ smartspaceViewModel: KeyguardSmartspaceViewModel,
+ config: Config,
+ apply: () -> Unit,
+ ) {
+ val newConfig =
+ if (keyguardTransitionInteractor.getCurrentState() == KeyguardState.OFF) {
+ config.copy(type = Type.Init)
+ } else {
+ config
+ }
+
+ runTransition(
+ constraintLayout,
+ IntraBlueprintTransition(newConfig, clockViewModel, smartspaceViewModel),
+ config,
+ apply,
+ )
+ }
+
+ fun runTransition(
+ constraintLayout: ConstraintLayout,
transition: Transition,
config: Config,
apply: () -> Unit,
@@ -103,21 +129,29 @@ constructor(
return
}
+ // Don't allow transitions with animations while in OFF state
+ val newConfig =
+ if (keyguardTransitionInteractor.getCurrentState() == KeyguardState.OFF) {
+ config.copy(type = Type.Init)
+ } else {
+ config
+ }
+
if (DEBUG) {
Log.i(
TAG,
"runTransition: running ${transition::class.simpleName}: " +
- "currentPriority=$currentPriority; config=$config",
+ "currentPriority=$currentPriority; config=$newConfig",
)
}
// beginDelayedTransition makes a copy, so we temporarially add the uncopied transition to
// the running set until the copy is started by the handler.
- updateTransitions(TransitionData(config)) { add(transition) }
+ updateTransitions(TransitionData(newConfig)) { add(transition) }
transition.addListener(transitionListener)
handler.post {
- if (config.terminatePrevious) {
+ if (newConfig.terminatePrevious) {
TransitionManager.endTransitions(constraintLayout)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt
index 10a2e5c04b00..3705c2c19110 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt
@@ -20,7 +20,6 @@ package com.android.systemui.keyguard.ui.viewmodel
import android.graphics.Point
import android.util.MathUtils
import android.view.View.VISIBLE
-import com.android.app.tracing.coroutines.launch
import com.android.systemui.common.shared.model.NotificationContainerBounds
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.dagger.SysUISingleton
@@ -35,6 +34,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
+import com.android.systemui.keyguard.shared.model.KeyguardState.OFF
import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
import com.android.systemui.keyguard.shared.model.TransitionState.RUNNING
import com.android.systemui.keyguard.shared.model.TransitionState.STARTED
@@ -88,6 +88,8 @@ constructor(
AlternateBouncerToGoneTransitionViewModel,
private val alternateBouncerToLockscreenTransitionViewModel:
AlternateBouncerToLockscreenTransitionViewModel,
+ private val alternateBouncerToOccludedTransitionViewModel:
+ AlternateBouncerToOccludedTransitionViewModel,
private val aodToGoneTransitionViewModel: AodToGoneTransitionViewModel,
private val aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel,
private val aodToOccludedTransitionViewModel: AodToOccludedTransitionViewModel,
@@ -112,9 +114,12 @@ constructor(
private val lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel,
private val lockscreenToPrimaryBouncerTransitionViewModel:
LockscreenToPrimaryBouncerTransitionViewModel,
+ private val occludedToAlternateBouncerTransitionViewModel:
+ OccludedToAlternateBouncerTransitionViewModel,
private val occludedToAodTransitionViewModel: OccludedToAodTransitionViewModel,
private val occludedToDozingTransitionViewModel: OccludedToDozingTransitionViewModel,
private val occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel,
+ private val offToLockscreenTransitionViewModel: OffToLockscreenTransitionViewModel,
private val primaryBouncerToAodTransitionViewModel: PrimaryBouncerToAodTransitionViewModel,
private val primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel,
private val primaryBouncerToLockscreenTransitionViewModel:
@@ -201,6 +206,10 @@ constructor(
notificationShadeWindowModel.isKeyguardOccluded,
communalInteractor.isIdleOnCommunal,
keyguardTransitionInteractor
+ .transitionValue(OFF)
+ .map { it > 1f - offToLockscreenTransitionViewModel.alphaStartAt }
+ .onStart { emit(false) },
+ keyguardTransitionInteractor
.transitionValue(scene = Scenes.Gone, stateWithoutSceneContainer = GONE)
.map { it == 1f }
.onStart { emit(false) },
@@ -227,6 +236,7 @@ constructor(
alternateBouncerToAodTransitionViewModel.lockscreenAlpha(viewState),
alternateBouncerToGoneTransitionViewModel.lockscreenAlpha(viewState),
alternateBouncerToLockscreenTransitionViewModel.lockscreenAlpha(viewState),
+ alternateBouncerToOccludedTransitionViewModel.lockscreenAlpha,
aodToGoneTransitionViewModel.lockscreenAlpha(viewState),
aodToLockscreenTransitionViewModel.lockscreenAlpha(viewState),
aodToOccludedTransitionViewModel.lockscreenAlpha(viewState),
@@ -249,14 +259,16 @@ constructor(
lockscreenToGoneTransitionViewModel.lockscreenAlpha(viewState),
lockscreenToOccludedTransitionViewModel.lockscreenAlpha,
lockscreenToPrimaryBouncerTransitionViewModel.lockscreenAlpha,
+ occludedToAlternateBouncerTransitionViewModel.lockscreenAlpha,
occludedToAodTransitionViewModel.lockscreenAlpha,
occludedToDozingTransitionViewModel.lockscreenAlpha,
occludedToLockscreenTransitionViewModel.lockscreenAlpha,
+ offToLockscreenTransitionViewModel.lockscreenAlpha,
primaryBouncerToAodTransitionViewModel.lockscreenAlpha,
primaryBouncerToGoneTransitionViewModel.lockscreenAlpha,
primaryBouncerToLockscreenTransitionViewModel.lockscreenAlpha(viewState),
)
- .onStart { emit(1f) },
+ .onStart { emit(0f) },
) { hideKeyguard, alpha ->
if (hideKeyguard) {
0f
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModel.kt
index 8d9ccef95f0d..88e8968501dd 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToOccludedTransitionViewModel.kt
@@ -52,18 +52,26 @@ constructor(
/** Lockscreen views alpha */
val lockscreenAlpha: Flow<Float> =
- transitionAnimation.sharedFlow(
- duration = 250.milliseconds,
- onStep = { 1f - it },
- name = "LOCKSCREEN->OCCLUDED: lockscreenAlpha",
+ shadeDependentFlows.transitionFlow(
+ flowWhenShadeIsNotExpanded =
+ transitionAnimation.sharedFlow(
+ duration = 250.milliseconds,
+ onStep = { 1f - it },
+ name = "LOCKSCREEN->OCCLUDED: lockscreenAlpha",
+ ),
+ flowWhenShadeIsExpanded = transitionAnimation.immediatelyTransitionTo(0f),
)
val shortcutsAlpha: Flow<Float> =
- transitionAnimation.sharedFlow(
- duration = 250.milliseconds,
- onStep = { 1 - it },
- onFinish = { 0f },
- onCancel = { 1f },
+ shadeDependentFlows.transitionFlow(
+ flowWhenShadeIsNotExpanded =
+ transitionAnimation.sharedFlow(
+ duration = 250.milliseconds,
+ onStep = { 1f - it },
+ onFinish = { 0f },
+ onCancel = { 1f },
+ ),
+ flowWhenShadeIsExpanded = transitionAnimation.immediatelyTransitionTo(0f),
)
/** Lockscreen views y-translation */
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModel.kt
new file mode 100644
index 000000000000..5bfcccbaccaa
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModel.kt
@@ -0,0 +1,49 @@
+/*
+ * 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.ui.viewmodel
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.keyguard.domain.interactor.FromOccludedTransitionInteractor.Companion.TO_ALTERNATE_BOUNCER_DURATION
+import com.android.systemui.keyguard.shared.model.Edge
+import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER
+import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
+import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
+import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition
+import javax.inject.Inject
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
+
+/**
+ * Breaks down OCCLUDED->ALTERNATE_BOUNCER transition into discrete steps for corresponding views to
+ * consume.
+ */
+@OptIn(ExperimentalCoroutinesApi::class)
+@SysUISingleton
+class OccludedToAlternateBouncerTransitionViewModel
+@Inject
+constructor(animationFlow: KeyguardTransitionAnimationFlow) : DeviceEntryIconTransition {
+ private val transitionAnimation =
+ animationFlow.setup(
+ duration = TO_ALTERNATE_BOUNCER_DURATION,
+ edge = Edge.create(from = OCCLUDED, to = ALTERNATE_BOUNCER),
+ )
+
+ val lockscreenAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(0f)
+
+ override val deviceEntryParentViewAlpha: Flow<Float> =
+ transitionAnimation.immediatelyTransitionTo(0f)
+}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModel.kt
index 1eecbd5fbda1..b4acce66da4f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModel.kt
@@ -16,6 +16,7 @@
package com.android.systemui.keyguard.ui.viewmodel
+import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
@@ -29,23 +30,29 @@ import kotlinx.coroutines.flow.Flow
@SysUISingleton
class OffToLockscreenTransitionViewModel
@Inject
-constructor(
- animationFlow: KeyguardTransitionAnimationFlow,
-) : DeviceEntryIconTransition {
+constructor(animationFlow: KeyguardTransitionAnimationFlow) : DeviceEntryIconTransition {
+
+ private val startTime = 300.milliseconds
+ private val alphaDuration = 633.milliseconds
+ val alphaStartAt = startTime / (alphaDuration + startTime)
private val transitionAnimation =
animationFlow.setup(
- duration = 250.milliseconds,
+ duration = startTime + alphaDuration,
edge = Edge.create(from = OFF, to = LOCKSCREEN),
)
- val shortcutsAlpha: Flow<Float> =
+ val lockscreenAlpha: Flow<Float> =
transitionAnimation.sharedFlow(
- duration = 250.milliseconds,
+ startTime = startTime,
+ duration = alphaDuration,
+ interpolator = EMPHASIZED_ACCELERATE,
onStep = { it },
- onCancel = { 0f },
)
- override val deviceEntryParentViewAlpha: Flow<Float> =
- transitionAnimation.immediatelyTransitionTo(1f)
+ val shortcutsAlpha: Flow<Float> = lockscreenAlpha
+
+ override val deviceEntryParentViewAlpha: Flow<Float> = lockscreenAlpha
+
+ val deviceEntryBackgroundViewAlpha: Flow<Float> = lockscreenAlpha
}
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListener.kt b/packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListener.kt
index 275f1eecd4db..39cedc36dbec 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListener.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListener.kt
@@ -128,7 +128,7 @@ constructor(
data: MediaData,
immediately: Boolean,
receivedSmartspaceCardLatency: Int,
- isSsReactivated: Boolean
+ isSsReactivated: Boolean,
) {
var reusedListener: PlaybackStateListener? = null
@@ -183,7 +183,7 @@ constructor(
override fun onSmartspaceMediaDataLoaded(
key: String,
data: SmartspaceMediaData,
- shouldPrioritize: Boolean
+ shouldPrioritize: Boolean,
) {
if (!mediaFlags.isPersistentSsCardEnabled()) return
@@ -259,7 +259,9 @@ constructor(
}
override fun onPlaybackStateChanged(state: PlaybackState?) {
- processState(state, dispatchEvents = true, currentResumption = resumption)
+ bgExecutor.execute {
+ processState(state, dispatchEvents = true, currentResumption = resumption)
+ }
}
override fun onSessionDestroyed() {
@@ -276,6 +278,7 @@ constructor(
}
}
+ @WorkerThread
private fun processState(
state: PlaybackState?,
dispatchEvents: Boolean,
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt
index a0fb0bf25c7b..72650ea89dcb 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt
@@ -16,6 +16,7 @@
package com.android.systemui.media.controls.ui.controller
+import android.annotation.WorkerThread
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
@@ -41,6 +42,7 @@ import com.android.internal.logging.InstanceId
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Dumpable
+import com.android.systemui.Flags.mediaControlsUmoInflationInBackground
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
@@ -137,7 +139,7 @@ constructor(
private val activityStarter: ActivityStarter,
private val systemClock: SystemClock,
@Main private val mainDispatcher: CoroutineDispatcher,
- @Main executor: DelayableExecutor,
+ @Main private val uiExecutor: DelayableExecutor,
@Background private val bgExecutor: Executor,
@Background private val backgroundDispatcher: CoroutineDispatcher,
private val mediaManager: MediaDataManager,
@@ -227,7 +229,7 @@ constructor(
private var carouselLocale: Locale? = null
private val animationScaleObserver: ContentObserver =
- object : ContentObserver(executor, 0) {
+ object : ContentObserver(uiExecutor, 0) {
override fun onChange(selfChange: Boolean) {
if (!SceneContainerFlag.isEnabled) {
MediaPlayerData.players().forEach { it.updateAnimatorDurationScale() }
@@ -350,7 +352,7 @@ constructor(
MediaCarouselScrollHandler(
mediaCarousel,
pageIndicator,
- executor,
+ uiExecutor,
this::onSwipeToDismiss,
this::updatePageIndicatorLocation,
this::updateSeekbarListening,
@@ -458,7 +460,17 @@ constructor(
isSsReactivated: Boolean,
) {
debugLogger.logMediaLoaded(key, data.active)
- if (addOrUpdatePlayer(key, oldKey, data, isSsReactivated)) {
+ val onUiExecutionEnd =
+ if (mediaControlsUmoInflationInBackground()) {
+ Runnable {
+ if (immediately) {
+ updateHostVisibility()
+ }
+ }
+ } else {
+ null
+ }
+ if (addOrUpdatePlayer(key, oldKey, data, isSsReactivated, onUiExecutionEnd)) {
// Log card received if a new resumable media card is added
MediaPlayerData.getMediaPlayer(key)?.let {
logSmartspaceCardReported(
@@ -980,6 +992,7 @@ constructor(
oldKey: String?,
data: MediaData,
isSsReactivated: Boolean,
+ onUiExecutionEnd: Runnable? = null,
): Boolean =
traceSection("MediaCarouselController#addOrUpdatePlayer") {
MediaPlayerData.moveIfExists(oldKey, key)
@@ -987,76 +1000,119 @@ constructor(
val curVisibleMediaKey =
MediaPlayerData.visiblePlayerKeys()
.elementAtOrNull(mediaCarouselScrollHandler.visibleMediaIndex)
- if (existingPlayer == null) {
- val newPlayer = mediaControlPanelFactory.get()
- if (SceneContainerFlag.isEnabled) {
- newPlayer.mediaViewController.widthInSceneContainerPx = widthInSceneContainerPx
- newPlayer.mediaViewController.heightInSceneContainerPx =
- heightInSceneContainerPx
- }
- newPlayer.attachPlayer(
- MediaViewHolder.create(LayoutInflater.from(context), mediaContent)
- )
- newPlayer.mediaViewController.sizeChangedListener = this::updateCarouselDimensions
- val lp =
- LinearLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- )
- newPlayer.mediaViewHolder?.player?.setLayoutParams(lp)
- newPlayer.bindPlayer(data, key)
- newPlayer.setListening(
- mediaCarouselScrollHandler.visibleToUser && currentlyExpanded
- )
- MediaPlayerData.addMediaPlayer(
- key,
- data,
- newPlayer,
- systemClock,
- isSsReactivated,
- debugLogger,
- )
- updateViewControllerToState(newPlayer.mediaViewController, noAnimation = true)
- // Media data added from a recommendation card should starts playing.
- if (
- (shouldScrollToKey && data.isPlaying == true) ||
- (!shouldScrollToKey && data.active)
- ) {
- reorderAllPlayers(curVisibleMediaKey, key)
+ if (mediaControlsUmoInflationInBackground()) {
+ if (existingPlayer == null) {
+ bgExecutor.execute {
+ val mediaViewHolder = createMediaViewHolderInBg()
+ // Add the new player in the main thread.
+ uiExecutor.execute {
+ setupNewPlayer(
+ key,
+ data,
+ isSsReactivated,
+ curVisibleMediaKey,
+ mediaViewHolder,
+ )
+ updatePageIndicator()
+ mediaCarouselScrollHandler.onPlayersChanged()
+ mediaFrame.requiresRemeasuring = true
+ onUiExecutionEnd?.run()
+ }
+ }
} else {
- needsReordering = true
+ updatePlayer(key, data, isSsReactivated, curVisibleMediaKey, existingPlayer)
+ updatePageIndicator()
+ mediaCarouselScrollHandler.onPlayersChanged()
+ mediaFrame.requiresRemeasuring = true
+ onUiExecutionEnd?.run()
}
} else {
- existingPlayer.bindPlayer(data, key)
- MediaPlayerData.addMediaPlayer(
- key,
- data,
- existingPlayer,
- systemClock,
- isSsReactivated,
- debugLogger,
- )
- val packageName = MediaPlayerData.smartspaceMediaData?.packageName ?: String()
- // In case of recommendations hits.
- // Check the playing status of media player and the package name.
- // To make sure we scroll to the right app's media player.
- if (
- isReorderingAllowed ||
- shouldScrollToKey &&
- data.isPlaying == true &&
- packageName == data.packageName
- ) {
- reorderAllPlayers(curVisibleMediaKey, key)
+ if (existingPlayer == null) {
+ val mediaViewHolder =
+ MediaViewHolder.create(LayoutInflater.from(context), mediaContent)
+ setupNewPlayer(key, data, isSsReactivated, curVisibleMediaKey, mediaViewHolder)
} else {
- needsReordering = true
+ updatePlayer(key, data, isSsReactivated, curVisibleMediaKey, existingPlayer)
}
+ updatePageIndicator()
+ mediaCarouselScrollHandler.onPlayersChanged()
+ mediaFrame.requiresRemeasuring = true
+ onUiExecutionEnd?.run()
}
- updatePageIndicator()
- mediaCarouselScrollHandler.onPlayersChanged()
- mediaFrame.requiresRemeasuring = true
return existingPlayer == null
}
+ private fun updatePlayer(
+ key: String,
+ data: MediaData,
+ isSsReactivated: Boolean,
+ curVisibleMediaKey: MediaPlayerData.MediaSortKey?,
+ existingPlayer: MediaControlPanel,
+ ) {
+ existingPlayer.bindPlayer(data, key)
+ MediaPlayerData.addMediaPlayer(
+ key,
+ data,
+ existingPlayer,
+ systemClock,
+ isSsReactivated,
+ debugLogger,
+ )
+ val packageName = MediaPlayerData.smartspaceMediaData?.packageName ?: String()
+ // In case of recommendations hits.
+ // Check the playing status of media player and the package name.
+ // To make sure we scroll to the right app's media player.
+ if (
+ isReorderingAllowed ||
+ shouldScrollToKey && data.isPlaying == true && packageName == data.packageName
+ ) {
+ reorderAllPlayers(curVisibleMediaKey, key)
+ } else {
+ needsReordering = true
+ }
+ }
+
+ private fun setupNewPlayer(
+ key: String,
+ data: MediaData,
+ isSsReactivated: Boolean,
+ curVisibleMediaKey: MediaPlayerData.MediaSortKey?,
+ mediaViewHolder: MediaViewHolder,
+ ) {
+ val newPlayer = mediaControlPanelFactory.get()
+ newPlayer.attachPlayer(mediaViewHolder)
+ newPlayer.mediaViewController.sizeChangedListener =
+ this@MediaCarouselController::updateCarouselDimensions
+ val lp =
+ LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ )
+ newPlayer.mediaViewHolder?.player?.setLayoutParams(lp)
+ newPlayer.bindPlayer(data, key)
+ newPlayer.setListening(mediaCarouselScrollHandler.visibleToUser && currentlyExpanded)
+ MediaPlayerData.addMediaPlayer(
+ key,
+ data,
+ newPlayer,
+ systemClock,
+ isSsReactivated,
+ debugLogger,
+ )
+ updateViewControllerToState(newPlayer.mediaViewController, noAnimation = true)
+ // Media data added from a recommendation card should starts playing.
+ if ((shouldScrollToKey && data.isPlaying == true) || (!shouldScrollToKey && data.active)) {
+ reorderAllPlayers(curVisibleMediaKey, key)
+ } else {
+ needsReordering = true
+ }
+ }
+
+ @WorkerThread
+ private fun createMediaViewHolderInBg(): MediaViewHolder {
+ return MediaViewHolder.create(LayoutInflater.from(context), mediaContent)
+ }
+
private fun addSmartspaceMediaRecommendations(
key: String,
data: SmartspaceMediaData,
@@ -1173,8 +1229,16 @@ constructor(
val previousVisibleKey =
MediaPlayerData.visiblePlayerKeys()
.elementAtOrNull(mediaCarouselScrollHandler.visibleMediaIndex)
+ val onUiExecutionEnd = Runnable {
+ if (recreateMedia) {
+ reorderAllPlayers(previousVisibleKey)
+ }
+ }
- MediaPlayerData.mediaData().forEach { (key, data, isSsMediaRec) ->
+ val mediaDataList = MediaPlayerData.mediaData()
+ // Do not loop through the original list of media data because the re-addition of media data
+ // is being executed in background thread.
+ mediaDataList.forEach { (key, data, isSsMediaRec) ->
if (isSsMediaRec) {
val smartspaceMediaData = MediaPlayerData.smartspaceMediaData
removePlayer(key, dismissMediaData = false, dismissRecommendation = false)
@@ -1185,6 +1249,7 @@ constructor(
MediaPlayerData.shouldPrioritizeSs,
)
}
+ onUiExecutionEnd.run()
} else {
val isSsReactivated = MediaPlayerData.isSsReactivated(key)
if (recreateMedia) {
@@ -1195,11 +1260,9 @@ constructor(
oldKey = null,
data = data,
isSsReactivated = isSsReactivated,
+ onUiExecutionEnd = onUiExecutionEnd,
)
}
- if (recreateMedia) {
- reorderAllPlayers(previousVisibleKey)
- }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHostStatesManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHostStatesManager.kt
index 8660d12bcb85..782da4bd6a41 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHostStatesManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHostStatesManager.kt
@@ -17,6 +17,7 @@
package com.android.systemui.media.controls.ui.controller
import com.android.app.tracing.traceSection
+import com.android.systemui.Flags.mediaControlsUmoInflationInBackground
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.media.controls.ui.view.MediaHostState
import com.android.systemui.util.animation.MeasurementOutput
@@ -71,23 +72,34 @@ class MediaHostStatesManager @Inject constructor() {
*/
fun updateCarouselDimensions(
@MediaLocation location: Int,
- hostState: MediaHostState
+ hostState: MediaHostState,
): MeasurementOutput =
traceSection("MediaHostStatesManager#updateCarouselDimensions") {
val result = MeasurementOutput(0, 0)
+ var changed = false
for (controller in controllers) {
val measurement = controller.getMeasurementsForState(hostState)
measurement?.let {
if (it.measuredHeight > result.measuredHeight) {
result.measuredHeight = it.measuredHeight
+ changed = true
}
if (it.measuredWidth > result.measuredWidth) {
result.measuredWidth = it.measuredWidth
+ changed = true
}
}
}
- carouselSizes[location] = result
- return result
+ if (mediaControlsUmoInflationInBackground()) {
+ // Set carousel size if result measurements changed. This avoids setting carousel
+ // size when this method gets called before the addition of media view controllers
+ if (!carouselSizes.contains(location) || changed) {
+ carouselSizes[location] = result
+ }
+ } else {
+ carouselSizes[location] = result
+ }
+ return carouselSizes[location] ?: result
}
/** Add a callback to be called when a MediaState has updated */
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt
index 09a618110f21..5ddc3470da43 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/view/MediaHost.kt
@@ -20,6 +20,7 @@ import android.graphics.Rect
import android.util.ArraySet
import android.view.View
import android.view.View.OnAttachStateChangeListener
+import com.android.systemui.Flags.mediaControlsUmoInflationInBackground
import com.android.systemui.media.controls.domain.pipeline.MediaDataManager
import com.android.systemui.media.controls.shared.model.MediaData
import com.android.systemui.media.controls.shared.model.SmartspaceMediaData
@@ -91,8 +92,10 @@ class MediaHost(
data: MediaData,
immediately: Boolean,
receivedSmartspaceCardLatency: Int,
- isSsReactivated: Boolean
+ isSsReactivated: Boolean,
) {
+ if (mediaControlsUmoInflationInBackground()) return
+
if (immediately) {
updateViewVisibility()
}
@@ -101,7 +104,7 @@ class MediaHost(
override fun onSmartspaceMediaDataLoaded(
key: String,
data: SmartspaceMediaData,
- shouldPrioritize: Boolean
+ shouldPrioritize: Boolean,
) {
updateViewVisibility()
}
@@ -171,7 +174,7 @@ class MediaHost(
input.widthMeasureSpec =
View.MeasureSpec.makeMeasureSpec(
View.MeasureSpec.getSize(input.widthMeasureSpec),
- View.MeasureSpec.EXACTLY
+ View.MeasureSpec.EXACTLY,
)
}
// This will trigger a state change that ensures that we now have a state
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt
index 228b57603bed..d413474fde90 100644
--- a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/MediaProjectionAppSelectorActivity.kt
@@ -54,6 +54,7 @@ import com.android.systemui.mediaprojection.MediaProjectionServiceHelper
import com.android.systemui.mediaprojection.appselector.data.RecentTask
import com.android.systemui.mediaprojection.appselector.view.MediaProjectionRecentsViewController
import com.android.systemui.res.R
+import com.android.systemui.shared.system.ActivityManagerWrapper
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.AsyncActivityLauncher
import java.lang.IllegalArgumentException
@@ -62,9 +63,10 @@ import javax.inject.Inject
class MediaProjectionAppSelectorActivity(
private val componentFactory: MediaProjectionAppSelectorComponent.Factory,
private val activityLauncher: AsyncActivityLauncher,
+ private val activityManager: ActivityManagerWrapper,
/** This is used to override the dependency in a screenshot test */
@VisibleForTesting
- private val listControllerFactory: ((userHandle: UserHandle) -> ResolverListController)?
+ private val listControllerFactory: ((userHandle: UserHandle) -> ResolverListController)?,
) :
ChooserActivity(),
MediaProjectionAppSelectorView,
@@ -74,8 +76,9 @@ class MediaProjectionAppSelectorActivity(
@Inject
constructor(
componentFactory: MediaProjectionAppSelectorComponent.Factory,
- activityLauncher: AsyncActivityLauncher
- ) : this(componentFactory, activityLauncher, listControllerFactory = null)
+ activityLauncher: AsyncActivityLauncher,
+ activityManager: ActivityManagerWrapper,
+ ) : this(componentFactory, activityLauncher, activityManager, listControllerFactory = null)
private val lifecycleRegistry = LifecycleRegistry(this)
override val lifecycle = lifecycleRegistry
@@ -100,7 +103,7 @@ class MediaProjectionAppSelectorActivity(
callingPackage = callingPackage,
view = this,
resultHandler = this,
- isFirstStart = savedInstanceState == null
+ isFirstStart = savedInstanceState == null,
)
component.lifecycleObservers.forEach { lifecycle.addObserver(it) }
@@ -113,7 +116,7 @@ class MediaProjectionAppSelectorActivity(
intent.configureChooserIntent(
resources,
component.hostUserHandle,
- component.personalProfileUserHandle
+ component.personalProfileUserHandle,
)
reviewGrantedConsentRequired =
@@ -180,7 +183,13 @@ class MediaProjectionAppSelectorActivity(
// is created and ready to be captured.
val activityStarted =
activityLauncher.startActivityAsUser(intent, userHandle, activityOptions.toBundle()) {
- returnSelectedApp(launchCookie, taskId = -1)
+ if (targetInfo.resolvedComponentName == callingActivity) {
+ // If attempting to launch the app used to launch the MediaProjection, then
+ // provide the task id since the launch cookie won't match the existing task
+ returnSelectedApp(launchCookie, taskId = activityManager.runningTask.taskId)
+ } else {
+ returnSelectedApp(launchCookie, taskId = -1)
+ }
}
// Rely on the ActivityManager to pop up a dialog regarding app suspension
@@ -213,7 +222,7 @@ class MediaProjectionAppSelectorActivity(
MediaProjectionServiceHelper.setReviewedConsentIfNeeded(
RECORD_CANCEL,
reviewGrantedConsentRequired,
- /* projection= */ null
+ /* projection= */ null,
)
if (isFinishing) {
// Only log dismissed when actually finishing, and not when changing configuration.
@@ -246,7 +255,7 @@ class MediaProjectionAppSelectorActivity(
val resultReceiver =
intent.getParcelableExtra(
EXTRA_CAPTURE_REGION_RESULT_RECEIVER,
- ResultReceiver::class.java
+ ResultReceiver::class.java,
) as ResultReceiver
val captureRegion = MediaProjectionCaptureTarget(launchCookie, taskId)
val data = Bundle().apply { putParcelable(KEY_CAPTURE_TARGET, captureRegion) }
@@ -260,8 +269,8 @@ class MediaProjectionAppSelectorActivity(
val mediaProjectionBinder = intent.getIBinderExtra(EXTRA_MEDIA_PROJECTION)
val projection = IMediaProjection.Stub.asInterface(mediaProjectionBinder)
- projection.setLaunchCookie(launchCookie)
- projection.setTaskId(taskId)
+ projection.launchCookie = launchCookie
+ projection.taskId = taskId
val intent = Intent()
intent.putExtra(EXTRA_MEDIA_PROJECTION, projection.asBinder())
@@ -270,7 +279,7 @@ class MediaProjectionAppSelectorActivity(
MediaProjectionServiceHelper.setReviewedConsentIfNeeded(
RECORD_CONTENT_TASK,
reviewGrantedConsentRequired,
- projection
+ projection,
)
}
@@ -457,7 +466,7 @@ class MediaProjectionAppSelectorActivity(
*/
private class RecyclerViewExpandingAccessibilityDelegate(
rdl: ResolverDrawerLayout,
- view: RecyclerView
+ view: RecyclerView,
) : RecyclerViewAccessibilityDelegate(view) {
private val delegate = AppListAccessibilityDelegate(rdl)
@@ -465,7 +474,7 @@ class MediaProjectionAppSelectorActivity(
override fun onRequestSendAccessibilityEvent(
host: ViewGroup,
child: View,
- event: AccessibilityEvent
+ event: AccessibilityEvent,
): Boolean {
super.onRequestSendAccessibilityEvent(host, child, event)
return delegate.onRequestSendAccessibilityEvent(host, child, event)
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/MediaProjectionPermissionActivity.java b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/MediaProjectionPermissionActivity.java
index 8351597f35de..c3729c0dcdfd 100644
--- a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/MediaProjectionPermissionActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/MediaProjectionPermissionActivity.java
@@ -68,12 +68,12 @@ import com.android.systemui.res.R;
import com.android.systemui.statusbar.phone.AlertDialogWithDelegate;
import com.android.systemui.statusbar.phone.SystemUIDialog;
+import dagger.Lazy;
+
import java.util.function.Consumer;
import javax.inject.Inject;
-import dagger.Lazy;
-
public class MediaProjectionPermissionActivity extends Activity {
private static final String TAG = "MediaProjectionPermissionActivity";
private static final float MAX_APP_NAME_SIZE_PX = 500f;
@@ -132,8 +132,7 @@ public class MediaProjectionPermissionActivity extends Activity {
mPackageName = launchingIntent.getStringExtra(
EXTRA_PACKAGE_REUSING_GRANTED_CONSENT);
} else {
- setResult(RESULT_CANCELED);
- finish(RECORD_CANCEL, /* projection= */ null);
+ finishAsCancelled();
return;
}
}
@@ -145,8 +144,7 @@ public class MediaProjectionPermissionActivity extends Activity {
mUid = aInfo.uid;
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Unable to look up package name", e);
- setResult(RESULT_CANCELED);
- finish(RECORD_CANCEL, /* projection= */ null);
+ finishAsCancelled();
return;
}
@@ -176,15 +174,13 @@ public class MediaProjectionPermissionActivity extends Activity {
}
} catch (RemoteException e) {
Log.e(TAG, "Error checking projection permissions", e);
- setResult(RESULT_CANCELED);
- finish(RECORD_CANCEL, /* projection= */ null);
+ finishAsCancelled();
return;
}
if (mFeatureFlags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING_ENTERPRISE_POLICIES)) {
if (showScreenCaptureDisabledDialogIfNeeded()) {
- setResult(RESULT_CANCELED);
- finish(RECORD_CANCEL, /* projection= */ null);
+ finishAsCancelled();
return;
}
}
@@ -346,6 +342,21 @@ public class MediaProjectionPermissionActivity extends Activity {
private void requestDeviceUnlock() {
mKeyguardManager.requestDismissKeyguard(this,
new KeyguardManager.KeyguardDismissCallback() {
+
+ @Override
+ public void onDismissError() {
+ if (com.android.systemui.Flags.mediaProjectionDialogBehindLockscreen()) {
+ finishAsCancelled();
+ }
+ }
+
+ @Override
+ public void onDismissCancelled() {
+ if (com.android.systemui.Flags.mediaProjectionDialogBehindLockscreen()) {
+ finishAsCancelled();
+ }
+ }
+
@Override
public void onDismissSucceeded() {
mDialog.show();
@@ -386,8 +397,7 @@ public class MediaProjectionPermissionActivity extends Activity {
}
} catch (RemoteException e) {
Log.e(TAG, "Error granting projection permission", e);
- setResult(RESULT_CANCELED);
- finish(RECORD_CANCEL, /* projection= */ null);
+ finishAsCancelled();
} finally {
if (mDialog != null) {
mDialog.dismiss();
@@ -436,6 +446,14 @@ public class MediaProjectionPermissionActivity extends Activity {
}
}
+ /**
+ * Finishes this activity and cancel the projection request.
+ */
+ private void finishAsCancelled() {
+ setResult(RESULT_CANCELED);
+ finish(RECORD_CANCEL, /* projection= */ null);
+ }
+
@Nullable
private MediaProjectionConfig getMediaProjectionConfig() {
Intent intent = getIntent();
diff --git a/packages/SystemUI/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModel.kt b/packages/SystemUI/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModel.kt
index 5be225c718ea..0e5404164ba1 100644
--- a/packages/SystemUI/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/notifications/ui/viewmodel/NotificationsShadeOverlayContentViewModel.kt
@@ -16,12 +16,19 @@
package com.android.systemui.notifications.ui.viewmodel
+import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.scene.domain.interactor.SceneInteractor
-import com.android.systemui.scene.shared.model.Overlays
+import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.ui.viewmodel.ShadeHeaderViewModel
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationsPlaceholderViewModel
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
+import kotlinx.coroutines.awaitCancellation
+import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.launch
/**
* Models UI state used to render the content of the notifications shade overlay.
@@ -34,13 +41,40 @@ class NotificationsShadeOverlayContentViewModel
constructor(
val shadeHeaderViewModelFactory: ShadeHeaderViewModel.Factory,
val notificationsPlaceholderViewModelFactory: NotificationsPlaceholderViewModel.Factory,
- private val sceneInteractor: SceneInteractor,
-) {
+ val sceneInteractor: SceneInteractor,
+ private val shadeInteractor: ShadeInteractor,
+) : ExclusiveActivatable() {
+
+ override suspend fun onActivated(): Nothing {
+ coroutineScope {
+ launch {
+ sceneInteractor.currentScene.collect { currentScene ->
+ when (currentScene) {
+ // TODO(b/369513770): The ShadeSession should be preserved in this scenario.
+ Scenes.Bouncer ->
+ shadeInteractor.collapseNotificationsShade(
+ loggingReason = "bouncer shown while shade is open"
+ )
+ }
+ }
+ }
+
+ launch {
+ shadeInteractor.isShadeTouchable
+ .distinctUntilChanged()
+ .filter { !it }
+ .collect {
+ shadeInteractor.collapseNotificationsShade(
+ loggingReason = "device became non-interactive"
+ )
+ }
+ }
+ }
+ awaitCancellation()
+ }
+
fun onScrimClicked() {
- sceneInteractor.hideOverlay(
- overlay = Overlays.NotificationsShade,
- loggingReason = "Shade scrim clicked",
- )
+ shadeInteractor.collapseNotificationsShade(loggingReason = "shade scrim clicked")
}
@AssistedFactory
diff --git a/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt b/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt
index 278352c6f69b..ead38f3f9b52 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/logging/QSLogger.kt
@@ -33,6 +33,7 @@ import com.android.systemui.log.core.LogLevel.VERBOSE
import com.android.systemui.log.dagger.QSConfigLog
import com.android.systemui.log.dagger.QSLog
import com.android.systemui.plugins.qs.QSTile
+import com.android.systemui.plugins.qs.QSTile.State
import com.android.systemui.statusbar.StatusBarState
import com.google.errorprone.annotations.CompileTimeConstant
import javax.inject.Inject
@@ -57,6 +58,7 @@ constructor(
fun d(@CompileTimeConstant msg: String, arg: Any) {
buffer.log(TAG, DEBUG, { str1 = arg.toString() }, { "$msg: $str1" })
}
+
fun i(@CompileTimeConstant msg: String, arg: Any) {
buffer.log(TAG, INFO, { str1 = arg.toString() }, { "$msg: $str1" })
}
@@ -73,7 +75,19 @@ constructor(
str1 = tileSpec
str2 = reason
},
- { "[$str1] Tile destroyed. Reason: $str2" }
+ { "[$str1] Tile destroyed. Reason: $str2" },
+ )
+ }
+
+ fun logStateChanged(tileSpec: String, state: State) {
+ buffer.log(
+ TAG,
+ DEBUG,
+ {
+ str1 = tileSpec
+ str2 = state.toString()
+ },
+ { "[$str1] Tile state=$str2" },
)
}
@@ -85,7 +99,7 @@ constructor(
bool1 = listening
str1 = tileSpec
},
- { "[$str1] Tile listening=$bool1" }
+ { "[$str1] Tile listening=$bool1" },
)
}
@@ -98,7 +112,7 @@ constructor(
str1 = containerName
str2 = allSpecs
},
- { "Tiles listening=$bool1 in $str1. $str2" }
+ { "Tiles listening=$bool1 in $str1. $str2" },
)
}
@@ -112,7 +126,7 @@ constructor(
str2 = StatusBarState.toString(statusBarState)
str3 = toStateString(state)
},
- { "[$str1][$int1] Tile clicked. StatusBarState=$str2. TileState=$str3" }
+ { "[$str1][$int1] Tile clicked. StatusBarState=$str2. TileState=$str3" },
)
}
@@ -124,7 +138,7 @@ constructor(
str1 = tileSpec
int1 = eventId
},
- { "[$str1][$int1] Tile handling click." }
+ { "[$str1][$int1] Tile handling click." },
)
}
@@ -138,7 +152,7 @@ constructor(
str2 = StatusBarState.toString(statusBarState)
str3 = toStateString(state)
},
- { "[$str1][$int1] Tile secondary clicked. StatusBarState=$str2. TileState=$str3" }
+ { "[$str1][$int1] Tile secondary clicked. StatusBarState=$str2. TileState=$str3" },
)
}
@@ -150,7 +164,7 @@ constructor(
str1 = tileSpec
int1 = eventId
},
- { "[$str1][$int1] Tile handling secondary click." }
+ { "[$str1][$int1] Tile handling secondary click." },
)
}
@@ -164,7 +178,7 @@ constructor(
str2 = StatusBarState.toString(statusBarState)
str3 = toStateString(state)
},
- { "[$str1][$int1] Tile long clicked. StatusBarState=$str2. TileState=$str3" }
+ { "[$str1][$int1] Tile long clicked. StatusBarState=$str2. TileState=$str3" },
)
}
@@ -176,7 +190,7 @@ constructor(
str1 = tileSpec
int1 = eventId
},
- { "[$str1][$int1] Tile handling long click." }
+ { "[$str1][$int1] Tile handling long click." },
)
}
@@ -189,7 +203,7 @@ constructor(
int1 = lastType
str2 = callback
},
- { "[$str1] mLastTileState=$int1, Callback=$str2." }
+ { "[$str1] mLastTileState=$int1, Callback=$str2." },
)
}
@@ -198,7 +212,7 @@ constructor(
tileSpec: String,
state: Int,
disabledByPolicy: Boolean,
- color: Int
+ color: Int,
) {
// This method is added to further debug b/250618218 which has only been observed from the
// InternetTile, so we are only logging the background color change for the InternetTile
@@ -215,7 +229,7 @@ constructor(
bool1 = disabledByPolicy
int2 = color
},
- { "[$str1] state=$int1, disabledByPolicy=$bool1, color=$int2." }
+ { "[$str1] state=$int1, disabledByPolicy=$bool1, color=$int2." },
)
}
@@ -229,7 +243,7 @@ constructor(
str3 = state.icon?.toString()
int1 = state.state
},
- { "[$str1] Tile updated. Label=$str2. State=$int1. Icon=$str3." }
+ { "[$str1] Tile updated. Label=$str2. State=$int1. Icon=$str3." },
)
}
@@ -241,7 +255,7 @@ constructor(
str1 = containerName
bool1 = expanded
},
- { "$str1 expanded=$bool1" }
+ { "$str1 expanded=$bool1" },
)
}
@@ -253,7 +267,7 @@ constructor(
str1 = containerName
int1 = orientation
},
- { "onViewAttached: $str1 orientation $int1" }
+ { "onViewAttached: $str1 orientation $int1" },
)
}
@@ -265,7 +279,7 @@ constructor(
str1 = containerName
int1 = orientation
},
- { "onViewDetached: $str1 orientation $int1" }
+ { "onViewDetached: $str1 orientation $int1" },
)
}
@@ -276,7 +290,7 @@ constructor(
newShouldUseSplitShade: Boolean,
oldScreenLayout: Int,
newScreenLayout: Int,
- containerName: String
+ containerName: String,
) {
configChangedBuffer.log(
TAG,
@@ -297,7 +311,7 @@ constructor(
"screen layout=${toScreenLayoutString(long1.toInt())} " +
"(was ${toScreenLayoutString(long2.toInt())}), " +
"splitShade=$bool2 (was $bool1)"
- }
+ },
)
}
@@ -305,7 +319,7 @@ constructor(
after: Boolean,
before: Boolean,
force: Boolean,
- containerName: String
+ containerName: String,
) {
buffer.log(
TAG,
@@ -316,7 +330,7 @@ constructor(
bool2 = before
bool3 = force
},
- { "change tile layout: $str1 horizontal=$bool1 (was $bool2), force? $bool3" }
+ { "change tile layout: $str1 horizontal=$bool1 (was $bool2), force? $bool3" },
)
}
@@ -328,7 +342,7 @@ constructor(
int1 = tilesPerPageCount
int2 = totalTilesCount
},
- { "Distributing tiles: [tilesPerPageCount=$int1] [totalTilesCount=$int2]" }
+ { "Distributing tiles: [tilesPerPageCount=$int1] [totalTilesCount=$int2]" },
)
}
@@ -340,7 +354,7 @@ constructor(
str1 = tileName
int1 = pageIndex
},
- { "Adding $str1 to page number $int1" }
+ { "Adding $str1 to page number $int1" },
)
}
@@ -361,7 +375,7 @@ constructor(
str1 = viewName
str2 = toVisibilityString(visibility)
},
- { "$str1 visibility: $str2" }
+ { "$str1 visibility: $str2" },
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSIconViewImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSIconViewImpl.java
index 5ea8c2183295..a4f3c7aa2652 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSIconViewImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSIconViewImpl.java
@@ -14,6 +14,7 @@
package com.android.systemui.qs.tileimpl;
+import static com.android.systemui.Flags.qsNewTiles;
import static com.android.systemui.Flags.removeUpdateListenerInQsIconViewImpl;
import android.animation.Animator;
@@ -66,12 +67,22 @@ public class QSIconViewImpl extends QSIconView {
private ValueAnimator mColorAnimator = new ValueAnimator();
+ private int mColorUnavailable;
+ private int mColorInactive;
+ private int mColorActive;
+
public QSIconViewImpl(Context context) {
super(context);
final Resources res = context.getResources();
mIconSizePx = res.getDimensionPixelSize(R.dimen.qs_icon_size);
+ if (qsNewTiles()) { // pre-load icon tint colors
+ mColorUnavailable = Utils.getColorAttrDefaultColor(context, R.attr.outline);
+ mColorInactive = Utils.getColorAttrDefaultColor(context, R.attr.onShadeInactiveVariant);
+ mColorActive = Utils.getColorAttrDefaultColor(context, R.attr.onShadeActive);
+ }
+
mIcon = createIcon();
addView(mIcon);
mColorAnimator.setDuration(QS_ANIM_LENGTH);
@@ -195,7 +206,11 @@ public class QSIconViewImpl extends QSIconView {
}
protected int getColor(QSTile.State state) {
- return getIconColorForState(getContext(), state);
+ if (qsNewTiles()) {
+ return getCachedIconColorForState(state);
+ } else {
+ return getIconColorForState(getContext(), state);
+ }
}
private void animateGrayScale(int fromColor, int toColor, ImageView iv,
@@ -267,6 +282,19 @@ public class QSIconViewImpl extends QSIconView {
}
}
+ private int getCachedIconColorForState(QSTile.State state) {
+ if (state.disabledByPolicy || state.state == Tile.STATE_UNAVAILABLE) {
+ return mColorUnavailable;
+ } else if (state.state == Tile.STATE_INACTIVE) {
+ return mColorInactive;
+ } else if (state.state == Tile.STATE_ACTIVE) {
+ return mColorActive;
+ } else {
+ Log.e("QSIconView", "Invalid state " + state);
+ return 0;
+ }
+ }
+
private static class EndRunnableAnimatorListener extends AnimatorListenerAdapter {
private Runnable mRunnable;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
index 4f3ea8331a17..18b1f071f44e 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
@@ -643,7 +643,6 @@ constructor(
}
// HANDLE STATE CHANGES RELATED METHODS
-
protected open fun handleStateChanged(state: QSTile.State) {
val allowAnimations = animationsEnabled()
isClickable = state.state != Tile.STATE_UNAVAILABLE
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java
index 5ea9e6ae0a70..301ab2bcdd65 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java
@@ -311,10 +311,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
mConfig = MobileMappings.Config.readConfig(mContext);
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId);
mSubIdTelephonyManagerMap.put(mDefaultDataSubId, mTelephonyManager);
- InternetTelephonyCallback telephonyCallback =
- new InternetTelephonyCallback(mDefaultDataSubId);
- mSubIdTelephonyCallbackMap.put(mDefaultDataSubId, telephonyCallback);
- mTelephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback);
+ registerInternetTelephonyCallback(mTelephonyManager, mDefaultDataSubId);
// Listen the connectivity changes
mConnectivityManager.registerDefaultNetworkCallback(mConnectivityManagerNetworkCallback);
mCanConfigWifi = canConfigWifi;
@@ -346,6 +343,23 @@ public class InternetDialogController implements AccessPointController.AccessPoi
mCallback = null;
}
+ /**
+ * This is to generate and register the new callback to Telephony for uncached subscription id,
+ * then cache it. Telephony also cached this callback into
+ * {@link com.android.server.TelephonyRegistry}, so if subscription id and callback were cached
+ * already, it shall do nothing to avoid registering redundant callback to Telephony.
+ */
+ private void registerInternetTelephonyCallback(
+ TelephonyManager telephonyManager, int subId) {
+ if (mSubIdTelephonyCallbackMap.containsKey(subId)) {
+ // Avoid to generate and register unnecessary callback to Telephony.
+ return;
+ }
+ InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId);
+ mSubIdTelephonyCallbackMap.put(subId, telephonyCallback);
+ telephonyManager.registerTelephonyCallback(mExecutor, telephonyCallback);
+ }
+
boolean isAirplaneModeEnabled() {
return mGlobalSettings.getInt(Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
@@ -673,9 +687,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
int subId = subInfo.getSubscriptionId();
if (mSubIdTelephonyManagerMap.get(subId) == null) {
TelephonyManager secondaryTm = mTelephonyManager.createForSubscriptionId(subId);
- InternetTelephonyCallback telephonyCallback = new InternetTelephonyCallback(subId);
- secondaryTm.registerTelephonyCallback(mExecutor, telephonyCallback);
- mSubIdTelephonyCallbackMap.put(subId, telephonyCallback);
+ registerInternetTelephonyCallback(secondaryTm, subId);
mSubIdTelephonyManagerMap.put(subId, secondaryTm);
}
return subId;
@@ -1351,6 +1363,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
if (DEBUG) {
Log.d(TAG, "DDS: defaultDataSubId:" + defaultDataSubId);
}
+
if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) {
// clean up old defaultDataSubId
TelephonyCallback oldCallback = mSubIdTelephonyCallbackMap.get(mDefaultDataSubId);
@@ -1366,9 +1379,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
// create for new defaultDataSubId
mTelephonyManager = mTelephonyManager.createForSubscriptionId(defaultDataSubId);
mSubIdTelephonyManagerMap.put(defaultDataSubId, mTelephonyManager);
- InternetTelephonyCallback newCallback = new InternetTelephonyCallback(defaultDataSubId);
- mSubIdTelephonyCallbackMap.put(defaultDataSubId, newCallback);
- mTelephonyManager.registerTelephonyCallback(mHandler::post, newCallback);
+ registerInternetTelephonyCallback(mTelephonyManager, defaultDataSubId);
mCallback.onSubscriptionsChanged(defaultDataSubId);
}
mDefaultDataSubId = defaultDataSubId;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapper.kt
index 8965ef2bc493..bb0b9b7084fa 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/InternetTileMapper.kt
@@ -18,7 +18,9 @@ package com.android.systemui.qs.tiles.impl.internet.domain
import android.content.Context
import android.content.res.Resources
+import android.os.Handler
import android.widget.Switch
+import com.android.settingslib.graph.SignalDrawable
import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text.Companion.loadText
@@ -28,6 +30,7 @@ import com.android.systemui.qs.tiles.impl.internet.domain.model.InternetTileMode
import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
import com.android.systemui.qs.tiles.viewmodel.QSTileState
import com.android.systemui.res.R
+import com.android.systemui.statusbar.pipeline.shared.ui.model.InternetTileIconModel
import javax.inject.Inject
/** Maps [InternetTileModel] to [QSTileState]. */
@@ -37,6 +40,7 @@ constructor(
@Main private val resources: Resources,
private val theme: Resources.Theme,
private val context: Context,
+ @Main private val handler: Handler,
) : QSTileDataToStateMapper<InternetTileModel> {
override fun map(config: QSTileConfig, data: InternetTileModel): QSTileState =
@@ -44,25 +48,42 @@ constructor(
label = resources.getString(R.string.quick_settings_internet_label)
expandedAccessibilityClass = Switch::class
- if (data.secondaryLabel != null) {
- secondaryLabel = data.secondaryLabel.loadText(context)
- } else {
- secondaryLabel = data.secondaryTitle
- }
+ secondaryLabel =
+ if (data.secondaryLabel != null) {
+ data.secondaryLabel.loadText(context)
+ } else {
+ data.secondaryTitle
+ }
stateDescription = data.stateDescription.loadContentDescription(context)
contentDescription = data.contentDescription.loadContentDescription(context)
- iconRes = data.iconId
- if (data.icon != null) {
- this.icon = { data.icon }
- } else if (data.iconId != null) {
- val loadedIcon =
- Icon.Loaded(
- resources.getDrawable(data.iconId!!, theme),
- contentDescription = null
- )
- this.icon = { loadedIcon }
+ when (val dataIcon = data.icon) {
+ is InternetTileIconModel.ResourceId -> {
+ iconRes = dataIcon.resId
+ icon = {
+ Icon.Loaded(
+ resources.getDrawable(dataIcon.resId, theme),
+ contentDescription = null,
+ )
+ }
+ }
+
+ is InternetTileIconModel.Cellular -> {
+ val signalDrawable = SignalDrawable(context, handler)
+ signalDrawable.setLevel(dataIcon.level)
+ icon = { Icon.Loaded(signalDrawable, contentDescription = null) }
+ }
+
+ is InternetTileIconModel.Satellite -> {
+ iconRes = dataIcon.resourceIcon.res // level is inferred from res
+ icon = {
+ Icon.Loaded(
+ resources.getDrawable(dataIcon.resourceIcon.res, theme),
+ contentDescription = null,
+ )
+ }
+ }
}
sideViewIcon = QSTileState.SideViewIcon.Chevron
@@ -75,7 +96,7 @@ constructor(
setOf(
QSTileState.UserAction.CLICK,
QSTileState.UserAction.TOGGLE_CLICK,
- QSTileState.UserAction.LONG_CLICK
+ QSTileState.UserAction.LONG_CLICK,
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractor.kt
index 204ead3fe29c..6fe3979fa446 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/interactor/InternetTileDataInteractor.kt
@@ -20,13 +20,10 @@ import android.annotation.StringRes
import android.content.Context
import android.os.UserHandle
import android.text.Html
-import com.android.settingslib.graph.SignalDrawable
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
-import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
import com.android.systemui.dagger.qualifiers.Application
-import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger
import com.android.systemui.qs.tiles.base.interactor.QSTileDataInteractor
import com.android.systemui.qs.tiles.impl.internet.domain.model.InternetTileModel
@@ -36,12 +33,12 @@ import com.android.systemui.statusbar.pipeline.ethernet.domain.EthernetInteracto
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor
import com.android.systemui.statusbar.pipeline.mobile.domain.model.SignalIconModel
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
+import com.android.systemui.statusbar.pipeline.shared.ui.model.InternetTileIconModel
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractor
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel
import com.android.systemui.statusbar.pipeline.wifi.ui.model.WifiIcon
import com.android.systemui.utils.coroutines.flow.mapLatestConflated
import javax.inject.Inject
-import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
@@ -51,7 +48,6 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.stateIn
-import kotlinx.coroutines.withContext
@OptIn(ExperimentalCoroutinesApi::class)
/** Observes internet state changes providing the [InternetTileModel]. */
@@ -59,7 +55,6 @@ class InternetTileDataInteractor
@Inject
constructor(
private val context: Context,
- @Main private val mainCoroutineContext: CoroutineContext,
@Application private val scope: CoroutineScope,
airplaneModeRepository: AirplaneModeRepository,
private val connectivityRepository: ConnectivityRepository,
@@ -79,8 +74,7 @@ constructor(
flowOf(
InternetTileModel.Active(
secondaryTitle = secondary,
- iconId = wifiIcon.icon.res,
- icon = Icon.Loaded(context.getDrawable(wifiIcon.icon.res)!!, null),
+ icon = InternetTileIconModel.ResourceId(wifiIcon.icon.res),
stateDescription = wifiIcon.contentDescription,
contentDescription = ContentDescription.Loaded("$internetLabel,$secondary"),
)
@@ -116,11 +110,10 @@ constructor(
if (it == null) {
notConnectedFlow
} else {
- combine(
- it.networkName,
- it.signalLevelIcon,
- mobileDataContentName,
- ) { networkNameModel, signalIcon, dataContentDescription ->
+ combine(it.networkName, it.signalLevelIcon, mobileDataContentName) {
+ networkNameModel,
+ signalIcon,
+ dataContentDescription ->
Triple(networkNameModel, signalIcon, dataContentDescription)
}
.mapLatestConflated { (networkNameModel, signalIcon, dataContentDescription) ->
@@ -129,17 +122,12 @@ constructor(
val secondary =
mobileDataContentConcat(
networkNameModel.name,
- dataContentDescription
+ dataContentDescription,
)
- val drawable =
- withContext(mainCoroutineContext) { SignalDrawable(context) }
- drawable.setLevel(signalIcon.level)
- val loadedIcon = Icon.Loaded(drawable, null)
-
InternetTileModel.Active(
secondaryTitle = secondary,
- icon = loadedIcon,
+ icon = InternetTileIconModel.Cellular(signalIcon.level),
stateDescription =
ContentDescription.Loaded(secondary.toString()),
contentDescription = ContentDescription.Loaded(internetLabel),
@@ -150,9 +138,10 @@ constructor(
signalIcon.icon.contentDescription.loadContentDescription(
context
)
+
InternetTileModel.Active(
secondaryTitle = secondary,
- iconId = signalIcon.icon.res,
+ icon = InternetTileIconModel.Satellite(signalIcon.icon),
stateDescription = ContentDescription.Loaded(secondary),
contentDescription = ContentDescription.Loaded(internetLabel),
)
@@ -164,7 +153,7 @@ constructor(
private fun mobileDataContentConcat(
networkName: String?,
- dataContentDescription: CharSequence?
+ dataContentDescription: CharSequence?,
): CharSequence {
if (dataContentDescription == null) {
return networkName ?: ""
@@ -177,9 +166,9 @@ constructor(
context.getString(
R.string.mobile_carrier_text_format,
networkName,
- dataContentDescription
+ dataContentDescription,
),
- 0
+ 0,
)
}
@@ -199,7 +188,7 @@ constructor(
flowOf(
InternetTileModel.Active(
secondaryLabel = secondary?.toText(),
- iconId = it.res,
+ icon = InternetTileIconModel.ResourceId(it.res),
stateDescription = null,
contentDescription = secondary,
)
@@ -208,16 +197,18 @@ constructor(
}
private val notConnectedFlow: StateFlow<InternetTileModel> =
- combine(
- wifiInteractor.areNetworksAvailable,
- airplaneModeRepository.isAirplaneMode,
- ) { networksAvailable, isAirplaneMode ->
+ combine(wifiInteractor.areNetworksAvailable, airplaneModeRepository.isAirplaneMode) {
+ networksAvailable,
+ isAirplaneMode ->
when {
isAirplaneMode -> {
val secondary = context.getString(R.string.status_bar_airplane)
InternetTileModel.Inactive(
secondaryTitle = secondary,
- iconId = R.drawable.ic_qs_no_internet_unavailable,
+ icon =
+ InternetTileIconModel.ResourceId(
+ R.drawable.ic_qs_no_internet_unavailable
+ ),
stateDescription = null,
contentDescription = ContentDescription.Loaded(secondary),
)
@@ -227,10 +218,13 @@ constructor(
context.getString(R.string.quick_settings_networks_available)
InternetTileModel.Inactive(
secondaryTitle = secondary,
- iconId = R.drawable.ic_qs_no_internet_available,
+ icon =
+ InternetTileIconModel.ResourceId(
+ R.drawable.ic_qs_no_internet_available
+ ),
stateDescription = null,
contentDescription =
- ContentDescription.Loaded("$internetLabel,$secondary")
+ ContentDescription.Loaded("$internetLabel,$secondary"),
)
}
else -> {
@@ -248,7 +242,7 @@ constructor(
*/
override fun tileData(
user: UserHandle,
- triggers: Flow<DataUpdateTrigger>
+ triggers: Flow<DataUpdateTrigger>,
): Flow<InternetTileModel> =
connectivityRepository.defaultConnections.flatMapLatest {
when {
@@ -265,7 +259,7 @@ constructor(
val NOT_CONNECTED_NETWORKS_UNAVAILABLE =
InternetTileModel.Inactive(
secondaryLabel = Text.Resource(R.string.quick_settings_networks_unavailable),
- iconId = R.drawable.ic_qs_no_internet_unavailable,
+ icon = InternetTileIconModel.ResourceId(R.drawable.ic_qs_no_internet_unavailable),
stateDescription = null,
contentDescription =
ContentDescription.Resource(R.string.quick_settings_networks_unavailable),
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/model/InternetTileModel.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/model/InternetTileModel.kt
index ece904611782..15b4e472eec7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/model/InternetTileModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/internet/domain/model/InternetTileModel.kt
@@ -17,23 +17,21 @@
package com.android.systemui.qs.tiles.impl.internet.domain.model
import com.android.systemui.common.shared.model.ContentDescription
-import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
+import com.android.systemui.statusbar.pipeline.shared.ui.model.InternetTileIconModel
/** Model describing the state that the QS Internet tile should be in. */
sealed interface InternetTileModel {
val secondaryTitle: CharSequence?
val secondaryLabel: Text?
- val iconId: Int?
- val icon: Icon?
+ val icon: InternetTileIconModel
val stateDescription: ContentDescription?
val contentDescription: ContentDescription?
data class Active(
override val secondaryTitle: CharSequence? = null,
override val secondaryLabel: Text? = null,
- override val iconId: Int? = null,
- override val icon: Icon? = null,
+ override val icon: InternetTileIconModel = InternetTileIconModel.Cellular(1),
override val stateDescription: ContentDescription? = null,
override val contentDescription: ContentDescription? = null,
) : InternetTileModel
@@ -41,8 +39,7 @@ sealed interface InternetTileModel {
data class Inactive(
override val secondaryTitle: CharSequence? = null,
override val secondaryLabel: Text? = null,
- override val iconId: Int? = null,
- override val icon: Icon? = null,
+ override val icon: InternetTileIconModel = InternetTileIconModel.Cellular(1),
override val stateDescription: ContentDescription? = null,
override val contentDescription: ContentDescription? = null,
) : InternetTileModel
diff --git a/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModel.kt
index 3b97d820e6a8..afb9a788ec24 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModel.kt
@@ -16,11 +16,18 @@
package com.android.systemui.qs.ui.viewmodel
+import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.scene.domain.interactor.SceneInteractor
-import com.android.systemui.scene.shared.model.Overlays
+import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.ui.viewmodel.ShadeHeaderViewModel
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
+import kotlinx.coroutines.awaitCancellation
+import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.launch
/**
* Models UI state used to render the content of the quick settings shade overlay.
@@ -31,15 +38,43 @@ import dagger.assisted.AssistedInject
class QuickSettingsShadeOverlayContentViewModel
@AssistedInject
constructor(
+ val shadeInteractor: ShadeInteractor,
val sceneInteractor: SceneInteractor,
val shadeHeaderViewModelFactory: ShadeHeaderViewModel.Factory,
val quickSettingsContainerViewModel: QuickSettingsContainerViewModel,
-) {
+) : ExclusiveActivatable() {
+
+ override suspend fun onActivated(): Nothing {
+ coroutineScope {
+ launch {
+ sceneInteractor.currentScene.collect { currentScene ->
+ when (currentScene) {
+ // TODO(b/369513770): The ShadeSession should be preserved in this scenario.
+ Scenes.Bouncer ->
+ shadeInteractor.collapseQuickSettingsShade(
+ loggingReason = "bouncer shown while shade is open"
+ )
+ }
+ }
+ }
+
+ launch {
+ shadeInteractor.isShadeTouchable
+ .distinctUntilChanged()
+ .filter { !it }
+ .collect {
+ shadeInteractor.collapseQuickSettingsShade(
+ loggingReason = "device became non-interactive"
+ )
+ }
+ }
+ }
+
+ awaitCancellation()
+ }
+
fun onScrimClicked() {
- sceneInteractor.hideOverlay(
- overlay = Overlays.QuickSettingsShade,
- loggingReason = "Shade scrim clicked",
- )
+ shadeInteractor.collapseQuickSettingsShade(loggingReason = "shade scrim clicked")
}
@AssistedFactory
diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
index ac49e91c777c..559c2637ed4f 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@@ -248,7 +248,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
} else if (action == ACTION_UP) {
// Gesture was too short to be picked up by scene container touch
// handling; programmatically start the transition to the shade.
- mShadeInteractor.get().expandNotificationShade("short launcher swipe");
+ mShadeInteractor.get()
+ .expandNotificationsShade("short launcher swipe", null);
}
}
event.recycle();
@@ -265,7 +266,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
mSceneInteractor.get().onRemoteUserInputStarted(
"trackpad swipe");
} else if (action == ACTION_UP) {
- mShadeInteractor.get().expandNotificationShade("short trackpad swipe");
+ mShadeInteractor.get()
+ .expandNotificationsShade("short trackpad swipe", null);
}
mStatusBarWinController.getWindowRootView().dispatchTouchEvent(event);
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt
index a5f4a8959569..4d2bc91aa52a 100644
--- a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt
+++ b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt
@@ -61,11 +61,11 @@ constructor(
uiEventLogger,
notificationManager,
userContextProvider,
- keyguardDismissUtil
+ keyguardDismissUtil,
) {
- private val commandHandler =
- IssueRecordingServiceCommandHandler(
+ private val session =
+ IssueRecordingServiceSession(
bgExecutor,
dialogTransitionAnimator,
panelInteractor,
@@ -86,7 +86,7 @@ constructor(
Log.d(getTag(), "handling action: ${intent?.action}")
when (intent?.action) {
ACTION_START -> {
- commandHandler.handleStartCommand()
+ session.start()
if (!issueRecordingState.recordScreen) {
// If we don't want to record the screen, the ACTION_SHOW_START_NOTIF action
// will circumvent the RecordingService's screen recording start code.
@@ -94,12 +94,12 @@ constructor(
}
}
ACTION_STOP,
- ACTION_STOP_NOTIF -> commandHandler.handleStopCommand(contentResolver)
+ ACTION_STOP_NOTIF -> session.stop(contentResolver)
ACTION_SHARE -> {
- commandHandler.handleShareCommand(
+ session.share(
intent.getIntExtra(EXTRA_NOTIFICATION_ID, mNotificationId),
intent.getParcelableExtra(EXTRA_PATH, Uri::class.java),
- this
+ this,
)
// Unlike all other actions, action_share has different behavior for the screen
// recording qs tile than it does for the record issue qs tile. Return sticky to
diff --git a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingServiceCommandHandler.kt b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingServiceSession.kt
index 32de0f353502..e4d3e6cae502 100644
--- a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingServiceCommandHandler.kt
+++ b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingServiceSession.kt
@@ -34,9 +34,11 @@ private const val DISABLED = 0
/**
* This class exists to unit test the business logic encapsulated in IssueRecordingService. Android
* specifically calls out that there is no supported way to test IntentServices here:
- * https://developer.android.com/training/testing/other-components/services
+ * https://developer.android.com/training/testing/other-components/services, and mentions that the
+ * best way to add unit tests, is to introduce a separate class containing the business logic of
+ * that service, and test the functionality via that class.
*/
-class IssueRecordingServiceCommandHandler(
+class IssueRecordingServiceSession(
private val bgExecutor: Executor,
private val dialogTransitionAnimator: DialogTransitionAnimator,
private val panelInteractor: PanelInteractor,
@@ -47,12 +49,12 @@ class IssueRecordingServiceCommandHandler(
private val userContextProvider: UserContextProvider,
) {
- fun handleStartCommand() {
+ fun start() {
bgExecutor.execute { traceurMessageSender.startTracing(issueRecordingState.traceConfig) }
issueRecordingState.isRecording = true
}
- fun handleStopCommand(contentResolver: ContentResolver) {
+ fun stop(contentResolver: ContentResolver) {
bgExecutor.execute {
if (issueRecordingState.traceConfig.longTrace) {
Settings.Global.putInt(contentResolver, NOTIFY_SESSION_ENDED_SETTING, DISABLED)
@@ -62,12 +64,12 @@ class IssueRecordingServiceCommandHandler(
issueRecordingState.isRecording = false
}
- fun handleShareCommand(notificationId: Int, screenRecording: Uri?, context: Context) {
+ fun share(notificationId: Int, screenRecording: Uri?, context: Context) {
bgExecutor.execute {
notificationManager.cancelAsUser(
null,
notificationId,
- UserHandle(userContextProvider.userContext.userId)
+ UserHandle(userContextProvider.userContext.userId),
)
if (issueRecordingState.takeBugreport) {
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKeys.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKeys.kt
index b9f57f2f31d5..3c6d858092af 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKeys.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKeys.kt
@@ -32,4 +32,7 @@ object TransitionKeys {
* normal collapse would.
*/
val SlightlyFasterShadeCollapse = TransitionKey("SlightlyFasterShadeCollapse")
+
+ /** Reference to a content transition that should happen instantly, i.e. without animation. */
+ val Instant = TransitionKey("Instant")
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerSceneImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerSceneImpl.kt
index 361226a4df18..6c99282bdcdd 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerSceneImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerSceneImpl.kt
@@ -22,8 +22,8 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.scene.domain.interactor.SceneInteractor
-import com.android.systemui.scene.shared.model.SceneFamilies
import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.scene.shared.model.TransitionKeys.Instant
import com.android.systemui.scene.shared.model.TransitionKeys.SlightlyFasterShadeCollapse
import com.android.systemui.shade.ShadeController.ShadeVisibilityListener
import com.android.systemui.shade.domain.interactor.ShadeInteractor
@@ -80,18 +80,25 @@ constructor(
}
}
+ @Deprecated("Deprecated in Java")
override fun isShadeEnabled() = shadeInteractor.isShadeEnabled.value
+ @Deprecated("Deprecated in Java")
override fun isShadeFullyOpen(): Boolean = shadeInteractor.isAnyFullyExpanded.value
+ @Deprecated("Deprecated in Java")
override fun isExpandingOrCollapsing(): Boolean = shadeInteractor.isUserInteracting.value
+ @Deprecated("Deprecated in Java")
override fun instantExpandShade() {
// Do nothing
}
override fun instantCollapseShade() {
- sceneInteractor.snapToScene(SceneFamilies.Home, "hide shade")
+ shadeInteractor.collapseNotificationsShade(
+ loggingReason = "ShadeControllerSceneImpl.instantCollapseShade",
+ transitionKey = Instant,
+ )
}
override fun animateCollapseShade(
@@ -122,16 +129,17 @@ constructor(
}
}
+ @Deprecated("Deprecated in Java")
override fun collapseWithDuration(animationDuration: Int) {
// TODO(b/300258424) inline this. The only caller uses the default duration.
animateCollapseShade()
}
private fun animateCollapseShadeInternal() {
- sceneInteractor.changeScene(
- SceneFamilies.Home, // TODO(b/336581871): add sceneState?
- "ShadeController.animateCollapseShade",
- SlightlyFasterShadeCollapse,
+ // TODO(b/336581871): add sceneState?
+ shadeInteractor.collapseEitherShade(
+ loggingReason = "ShadeController.animateCollapseShade",
+ transitionKey = SlightlyFasterShadeCollapse,
)
}
@@ -140,6 +148,7 @@ constructor(
animateCollapseShade()
}
+ @Deprecated("Deprecated in Java")
override fun closeShadeIfOpen(): Boolean {
if (shadeInteractor.isAnyExpanded.value) {
commandQueue.animateCollapsePanels(
@@ -155,6 +164,7 @@ constructor(
animateCollapseShadeForcedDelayed()
}
+ @Deprecated("Deprecated in Java")
override fun collapseShade(animate: Boolean) {
if (animate) {
animateCollapseShade()
@@ -163,13 +173,14 @@ constructor(
}
}
+ @Deprecated("Deprecated in Java")
override fun collapseOnMainThread() {
// TODO if this works with delegation alone, we can deprecate and delete
collapseShade()
}
override fun expandToNotifications() {
- shadeInteractor.expandNotificationShade("ShadeController.animateExpandShade")
+ shadeInteractor.expandNotificationsShade("ShadeController.animateExpandShade")
}
override fun expandToQs() {
@@ -193,14 +204,17 @@ constructor(
}
}
+ @Deprecated("Deprecated in Java")
override fun postAnimateCollapseShade() {
animateCollapseShade()
}
+ @Deprecated("Deprecated in Java")
override fun postAnimateForceCollapseShade() {
animateCollapseShadeForced()
}
+ @Deprecated("Deprecated in Java")
override fun postAnimateExpandQs() {
expandToQs()
}
@@ -214,18 +228,23 @@ constructor(
}
}
+ @Deprecated("Deprecated in Java")
override fun makeExpandedInvisible() {
// Do nothing
}
+ @Deprecated("Deprecated in Java")
override fun makeExpandedVisible(force: Boolean) {
// Do nothing
}
+ @Deprecated("Deprecated in Java")
override fun isExpandedVisible(): Boolean {
- return sceneInteractor.currentScene.value != Scenes.Gone
+ return sceneInteractor.currentScene.value != Scenes.Gone ||
+ sceneInteractor.currentOverlays.value.isNotEmpty()
}
+ @Deprecated("Deprecated in Java")
override fun onStatusBarTouch(event: MotionEvent) {
// The only call to this doesn't happen with MigrateClocksToBlueprint.isEnabled enabled
throw UnsupportedOperationException()
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractor.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractor.kt
index b046c50b05d3..a3f2c64f6909 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractor.kt
@@ -17,6 +17,7 @@
package com.android.systemui.shade.domain.interactor
import androidx.annotation.FloatRange
+import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.shade.shared.model.ShadeMode
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@@ -27,19 +28,22 @@ import kotlinx.coroutines.flow.stateIn
/** Business logic for shade interactions. */
interface ShadeInteractor : BaseShadeInteractor {
- /** Emits true if the shade is currently allowed and false otherwise. */
+ /** Emits true if the Notifications shade is currently allowed and false otherwise. */
val isShadeEnabled: StateFlow<Boolean>
- /** Emits true if QS is currently allowed and false otherwise. */
+ /** Emits true if QS shade is currently allowed and false otherwise. */
val isQsEnabled: StateFlow<Boolean>
- /** Whether either the shade or QS is fully expanded. */
+ /** Whether either the Notifications shade or QS shade is fully expanded. */
val isAnyFullyExpanded: StateFlow<Boolean>
- /** Whether the Shade is fully expanded. */
+ /** Whether the Notifications Shade is fully expanded. */
val isShadeFullyExpanded: Flow<Boolean>
- /** Whether the Shade is fully collapsed. */
+ /** Whether Notifications Shade is expanded a non-zero amount. */
+ val isShadeAnyExpanded: StateFlow<Boolean>
+
+ /** Whether the Notifications Shade is fully collapsed. */
val isShadeFullyCollapsed: Flow<Boolean>
/**
@@ -102,7 +106,7 @@ interface BaseShadeInteractor {
*/
val isAnyExpanded: StateFlow<Boolean>
- /** The amount [0-1] that the shade has been opened. */
+ /** The amount [0-1] that the Notifications Shade has been opened. */
val shadeExpansion: StateFlow<Float>
/**
@@ -111,7 +115,7 @@ interface BaseShadeInteractor {
*/
val qsExpansion: StateFlow<Float>
- /** Whether Quick Settings is expanded a non-zero amount. */
+ /** Whether Quick Settings Shade is expanded a non-zero amount. */
val isQsExpanded: StateFlow<Boolean>
/**
@@ -142,16 +146,38 @@ interface BaseShadeInteractor {
val isUserInteractingWithQs: Flow<Boolean>
/**
- * Triggers the expansion (opening) of the notification shade. If the notification shade is
- * already open, this has no effect.
+ * Triggers the expansion (opening) of the notifications shade. If it is already expanded, this
+ * has no effect.
+ */
+ fun expandNotificationsShade(loggingReason: String, transitionKey: TransitionKey? = null)
+
+ /**
+ * Triggers the expansion (opening) of the quick settings shade. If it is already expanded, this
+ * has no effect.
+ */
+ fun expandQuickSettingsShade(loggingReason: String, transitionKey: TransitionKey? = null)
+
+ /**
+ * Triggers the collapse (closing) of the notifications shade. If it is already collapsed, this
+ * has no effect.
+ */
+ fun collapseNotificationsShade(loggingReason: String, transitionKey: TransitionKey? = null)
+
+ /**
+ * Triggers the collapse (closing) of the quick settings shade. If it is already collapsed, this
+ * has no effect.
*/
- fun expandNotificationShade(loggingReason: String)
+ fun collapseQuickSettingsShade(
+ loggingReason: String,
+ transitionKey: TransitionKey? = null,
+ bypassNotificationsShade: Boolean = false,
+ )
/**
- * Triggers the expansion (opening) of the quick settings shade. If the quick settings shade is
- * already open, this has no effect.
+ * Triggers the collapse (closing) of the notifications shade or quick settings shade, whichever
+ * is open. If both are already collapsed, this has no effect.
*/
- fun expandQuickSettingsShade(loggingReason: String)
+ fun collapseEitherShade(loggingReason: String, transitionKey: TransitionKey? = null)
}
fun createAnyExpansionFlow(
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorEmptyImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorEmptyImpl.kt
index fb1482890b87..322fca39a1df 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorEmptyImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorEmptyImpl.kt
@@ -16,6 +16,7 @@
package com.android.systemui.shade.domain.interactor
+import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.shade.shared.model.ShadeMode
import javax.inject.Inject
@@ -31,6 +32,7 @@ class ShadeInteractorEmptyImpl @Inject constructor() : ShadeInteractor {
override val isShadeEnabled: StateFlow<Boolean> = inactiveFlowBoolean
override val isQsEnabled: StateFlow<Boolean> = inactiveFlowBoolean
override val shadeExpansion: StateFlow<Float> = inactiveFlowFloat
+ override val isShadeAnyExpanded: StateFlow<Boolean> = inactiveFlowBoolean
override val qsExpansion: StateFlow<Float> = inactiveFlowFloat
override val isQsExpanded: StateFlow<Boolean> = inactiveFlowBoolean
override val isQsBypassingShade: Flow<Boolean> = inactiveFlowBoolean
@@ -50,7 +52,17 @@ class ShadeInteractorEmptyImpl @Inject constructor() : ShadeInteractor {
override fun getTopEdgeSplitFraction(): Float = 0.5f
- override fun expandNotificationShade(loggingReason: String) {}
+ override fun expandNotificationsShade(loggingReason: String, transitionKey: TransitionKey?) {}
- override fun expandQuickSettingsShade(loggingReason: String) {}
+ override fun expandQuickSettingsShade(loggingReason: String, transitionKey: TransitionKey?) {}
+
+ override fun collapseNotificationsShade(loggingReason: String, transitionKey: TransitionKey?) {}
+
+ override fun collapseQuickSettingsShade(
+ loggingReason: String,
+ transitionKey: TransitionKey?,
+ bypassNotificationsShade: Boolean,
+ ) {}
+
+ override fun collapseEitherShade(loggingReason: String, transitionKey: TransitionKey?) {}
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImpl.kt
index 3eab02ad30d5..949d2aa36bf3 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImpl.kt
@@ -78,12 +78,16 @@ constructor(
override val isShadeFullyExpanded: Flow<Boolean> =
baseShadeInteractor.shadeExpansion.map { it >= 1f }.distinctUntilChanged()
+ override val isShadeAnyExpanded: StateFlow<Boolean> =
+ baseShadeInteractor.shadeExpansion
+ .map { it > 0 }
+ .stateIn(scope, SharingStarted.Eagerly, false)
+
override val isShadeFullyCollapsed: Flow<Boolean> =
baseShadeInteractor.shadeExpansion.map { it <= 0f }.distinctUntilChanged()
override val isUserInteracting: StateFlow<Boolean> =
combine(isUserInteractingWithShade, isUserInteractingWithQs) { shade, qs -> shade || qs }
- .distinctUntilChanged()
.stateIn(scope, SharingStarted.Eagerly, false)
override val isShadeTouchable: Flow<Boolean> =
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImpl.kt
index df094864a71b..0902c3936661 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImpl.kt
@@ -17,6 +17,7 @@
package com.android.systemui.shade.domain.interactor
import com.android.app.tracing.FlowTracing.traceAsCounter
+import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.KeyguardRepository
@@ -111,18 +112,40 @@ constructor(
override val isUserInteractingWithQs: Flow<Boolean> =
userInteractingFlow(repository.legacyQsTracking, repository.qsExpansion)
- override fun expandNotificationShade(loggingReason: String) {
+ override fun expandNotificationsShade(loggingReason: String, transitionKey: TransitionKey?) {
throw UnsupportedOperationException(
"expandNotificationShade() is not supported in legacy shade"
)
}
- override fun expandQuickSettingsShade(loggingReason: String) {
+ override fun expandQuickSettingsShade(loggingReason: String, transitionKey: TransitionKey?) {
throw UnsupportedOperationException(
"expandQuickSettingsShade() is not supported in legacy shade"
)
}
+ override fun collapseNotificationsShade(loggingReason: String, transitionKey: TransitionKey?) {
+ throw UnsupportedOperationException(
+ "collapseNotificationShade() is not supported in legacy shade"
+ )
+ }
+
+ override fun collapseQuickSettingsShade(
+ loggingReason: String,
+ transitionKey: TransitionKey?,
+ bypassNotificationsShade: Boolean,
+ ) {
+ throw UnsupportedOperationException(
+ "collapseQuickSettingsShade() is not supported in legacy shade"
+ )
+ }
+
+ override fun collapseEitherShade(loggingReason: String, transitionKey: TransitionKey?) {
+ throw UnsupportedOperationException(
+ "collapseEitherShade() is not supported in legacy shade"
+ )
+ }
+
/**
* Return a flow for whether a user is interacting with an expandable shade component using
* tracking and expansion flows. NOTE: expansion must be a `StateFlow` to guarantee that
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt
index 81bf712f21e5..765810810bb8 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt
@@ -21,12 +21,16 @@ import com.android.compose.animation.scene.ContentKey
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
+import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Overlays
+import com.android.systemui.scene.shared.model.SceneFamilies
import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.scene.shared.model.TransitionKeys.Instant
+import com.android.systemui.scene.shared.model.TransitionKeys.ToSplitShade
import com.android.systemui.shade.shared.model.ShadeMode
import com.android.systemui.utils.coroutines.flow.flatMapLatestConflated
import javax.inject.Inject
@@ -133,43 +137,120 @@ constructor(
}
}
- override fun expandNotificationShade(loggingReason: String) {
+ override fun expandNotificationsShade(loggingReason: String, transitionKey: TransitionKey?) {
if (shadeModeInteractor.isDualShade) {
if (Overlays.QuickSettingsShade in sceneInteractor.currentOverlays.value) {
sceneInteractor.replaceOverlay(
from = Overlays.QuickSettingsShade,
to = Overlays.NotificationsShade,
loggingReason = loggingReason,
+ transitionKey = transitionKey,
)
} else {
sceneInteractor.showOverlay(
overlay = Overlays.NotificationsShade,
loggingReason = loggingReason,
+ transitionKey = transitionKey,
)
}
} else {
- sceneInteractor.changeScene(toScene = Scenes.Shade, loggingReason = loggingReason)
+ sceneInteractor.changeScene(
+ toScene = Scenes.Shade,
+ loggingReason = loggingReason,
+ transitionKey =
+ transitionKey ?: ToSplitShade.takeIf { shadeModeInteractor.isSplitShade },
+ )
}
}
- override fun expandQuickSettingsShade(loggingReason: String) {
+ override fun expandQuickSettingsShade(loggingReason: String, transitionKey: TransitionKey?) {
if (shadeModeInteractor.isDualShade) {
if (Overlays.NotificationsShade in sceneInteractor.currentOverlays.value) {
sceneInteractor.replaceOverlay(
from = Overlays.NotificationsShade,
to = Overlays.QuickSettingsShade,
loggingReason = loggingReason,
+ transitionKey = transitionKey,
)
} else {
sceneInteractor.showOverlay(
overlay = Overlays.QuickSettingsShade,
loggingReason = loggingReason,
+ transitionKey = transitionKey,
)
}
} else {
+ val isSplitShade = shadeModeInteractor.isSplitShade
+ sceneInteractor.changeScene(
+ toScene = if (isSplitShade) Scenes.Shade else Scenes.QuickSettings,
+ loggingReason = loggingReason,
+ transitionKey = transitionKey ?: ToSplitShade.takeIf { isSplitShade },
+ )
+ }
+ }
+
+ override fun collapseNotificationsShade(loggingReason: String, transitionKey: TransitionKey?) {
+ if (shadeModeInteractor.isDualShade) {
+ // TODO(b/356596436): Hide without animation if transitionKey is Instant.
+ sceneInteractor.hideOverlay(
+ overlay = Overlays.NotificationsShade,
+ loggingReason = loggingReason,
+ transitionKey = transitionKey,
+ )
+ } else if (transitionKey == Instant) {
+ // TODO(b/356596436): Define instant transition instead of snapToScene().
+ sceneInteractor.snapToScene(toScene = SceneFamilies.Home, loggingReason = loggingReason)
+ } else {
sceneInteractor.changeScene(
- toScene = Scenes.QuickSettings,
+ toScene = SceneFamilies.Home,
+ loggingReason = loggingReason,
+ transitionKey =
+ transitionKey ?: ToSplitShade.takeIf { shadeModeInteractor.isSplitShade },
+ )
+ }
+ }
+
+ override fun collapseQuickSettingsShade(
+ loggingReason: String,
+ transitionKey: TransitionKey?,
+ bypassNotificationsShade: Boolean,
+ ) {
+ if (shadeModeInteractor.isDualShade) {
+ // TODO(b/356596436): Hide without animation if transitionKey is Instant.
+ sceneInteractor.hideOverlay(
+ overlay = Overlays.QuickSettingsShade,
+ loggingReason = loggingReason,
+ transitionKey = transitionKey,
+ )
+ return
+ }
+
+ val isSplitShade = shadeModeInteractor.isSplitShade
+ val targetScene =
+ if (bypassNotificationsShade || isSplitShade) SceneFamilies.Home else Scenes.Shade
+ if (transitionKey == Instant) {
+ // TODO(b/356596436): Define instant transition instead of snapToScene().
+ sceneInteractor.snapToScene(toScene = targetScene, loggingReason = loggingReason)
+ } else {
+ sceneInteractor.changeScene(
+ toScene = targetScene,
+ loggingReason = loggingReason,
+ transitionKey = transitionKey ?: ToSplitShade.takeIf { isSplitShade },
+ )
+ }
+ }
+
+ override fun collapseEitherShade(loggingReason: String, transitionKey: TransitionKey?) {
+ // Note: The notifications shade and QS shade may be both partially expanded simultaneously,
+ // so we don't use an 'else' clause here.
+ if (shadeExpansion.value > 0) {
+ collapseNotificationsShade(loggingReason = loggingReason, transitionKey = transitionKey)
+ }
+ if (isQsExpanded.value) {
+ collapseQuickSettingsShade(
loggingReason = loggingReason,
+ transitionKey = transitionKey,
+ bypassNotificationsShade = true,
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeLockscreenInteractorImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeLockscreenInteractorImpl.kt
index 0fb379017be9..ea76ac4b0f83 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeLockscreenInteractorImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeLockscreenInteractorImpl.kt
@@ -21,10 +21,9 @@ import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.scene.domain.interactor.SceneInteractor
-import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.scene.shared.model.TransitionKeys.Instant
import com.android.systemui.shade.data.repository.ShadeRepository
-import com.android.systemui.shade.shared.model.ShadeMode
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
@@ -48,7 +47,7 @@ constructor(
@Deprecated("Use ShadeInteractor instead")
override fun expandToNotifications() {
- shadeInteractor.expandNotificationShade(
+ shadeInteractor.expandNotificationsShade(
loggingReason = "ShadeLockscreenInteractorImpl.expandToNotifications"
)
}
@@ -71,17 +70,11 @@ constructor(
}
override fun resetViews(animate: Boolean) {
- val loggingReason = "ShadeLockscreenInteractorImpl.resetViews"
// The existing comment to the only call to this claims it only calls it to collapse QS
- if (shadeInteractor.shadeMode.value == ShadeMode.Dual) {
- // TODO(b/356596436): Hide without animation if !animate.
- sceneInteractor.hideOverlay(
- overlay = Overlays.QuickSettingsShade,
- loggingReason = loggingReason,
- )
- } else {
- shadeInteractor.expandNotificationShade(loggingReason)
- }
+ shadeInteractor.collapseQuickSettingsShade(
+ loggingReason = "ShadeLockscreenInteractorImpl.resetViews",
+ transitionKey = Instant.takeIf { !animate },
+ )
}
@Deprecated("Not supported by scenes")
@@ -93,7 +86,7 @@ constructor(
backgroundScope.launch {
delay(delay)
withContext(mainDispatcher) {
- shadeInteractor.expandNotificationShade(
+ shadeInteractor.expandNotificationsShade(
"ShadeLockscreenInteractorImpl.transitionToExpandedShade"
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeModeInteractor.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeModeInteractor.kt
index caa45137ed98..c838c378965f 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeModeInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeModeInteractor.kt
@@ -55,6 +55,10 @@ interface ShadeModeInteractor {
val isDualShade: Boolean
get() = shadeMode.value is ShadeMode.Dual
+ /** Convenience shortcut for querying whether the current [shadeMode] is [ShadeMode.Split]. */
+ val isSplitShade: Boolean
+ get() = shadeMode.value is ShadeMode.Split
+
/**
* The fraction between [0..1] (i.e., percentage) of screen width to consider the threshold
* between "top-left" and "top-right" for the purposes of dual-shade invocation.
diff --git a/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModel.kt b/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModel.kt
index a154e91feca1..bd4ed5b45dc7 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModel.kt
@@ -29,9 +29,7 @@ import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.privacy.OngoingPrivacyChip
import com.android.systemui.privacy.PrivacyItem
import com.android.systemui.res.R
-import com.android.systemui.scene.domain.interactor.SceneInteractor
-import com.android.systemui.scene.shared.model.SceneFamilies
-import com.android.systemui.scene.shared.model.TransitionKeys
+import com.android.systemui.scene.shared.model.TransitionKeys.SlightlyFasterShadeCollapse
import com.android.systemui.shade.domain.interactor.PrivacyChipInteractor
import com.android.systemui.shade.domain.interactor.ShadeHeaderClockInteractor
import com.android.systemui.shade.domain.interactor.ShadeInteractor
@@ -55,9 +53,8 @@ import kotlinx.coroutines.launch
class ShadeHeaderViewModel
@AssistedInject
constructor(
- private val context: Context,
+ context: Context,
private val activityStarter: ActivityStarter,
- private val sceneInteractor: SceneInteractor,
private val shadeInteractor: ShadeInteractor,
private val mobileIconsInteractor: MobileIconsInteractor,
val mobileIconsViewModel: MobileIconsViewModel,
@@ -120,7 +117,7 @@ constructor(
map = { intent, _ ->
intent.action == Intent.ACTION_TIMEZONE_CHANGED ||
intent.action == Intent.ACTION_LOCALE_CHANGED
- }
+ },
)
.onEach { invalidateFormats -> updateDateTexts(invalidateFormats) }
.launchIn(this)
@@ -152,10 +149,9 @@ constructor(
/** Notifies that the system icons container was clicked. */
fun onSystemIconContainerClicked() {
- sceneInteractor.changeScene(
- SceneFamilies.Home,
- "ShadeHeaderViewModel.onSystemIconContainerClicked",
- TransitionKeys.SlightlyFasterShadeCollapse,
+ shadeInteractor.collapseEitherShade(
+ loggingReason = "ShadeHeaderViewModel.onSystemIconContainerClicked",
+ transitionKey = SlightlyFasterShadeCollapse,
)
}
@@ -163,7 +159,7 @@ constructor(
fun onShadeCarrierGroupClicked() {
activityStarter.postStartActivityDismissingKeyguard(
Intent(Settings.ACTION_WIRELESS_SETTINGS),
- 0
+ 0,
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/core/StatusBarConntectedDisplays.kt b/packages/SystemUI/src/com/android/systemui/statusbar/core/StatusBarConntectedDisplays.kt
new file mode 100644
index 000000000000..54a18f764406
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/core/StatusBarConntectedDisplays.kt
@@ -0,0 +1,61 @@
+/*
+ * 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.statusbar.core
+
+import com.android.systemui.Flags
+import com.android.systemui.flags.FlagToken
+import com.android.systemui.flags.RefactorFlagUtils
+
+/** Helper for reading or using the status bar connected displays flag state. */
+@Suppress("NOTHING_TO_INLINE")
+object StatusBarConnectedDisplays {
+ /** The aconfig flag name */
+ const val FLAG_NAME = Flags.FLAG_STATUS_BAR_CONNECTED_DISPLAYS
+
+ /** A token used for dependency declaration */
+ val token: FlagToken
+ get() = FlagToken(FLAG_NAME, isEnabled)
+
+ /** Is the refactor enabled */
+ @JvmStatic
+ inline val isEnabled
+ get() = Flags.statusBarConnectedDisplays()
+
+ /**
+ * 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 enabled. This will throw an exception if
+ * the flag is not enabled to ensure that the refactor author catches issues in testing.
+ * Caution!! Using this check incorrectly will cause crashes in nextfood builds!
+ */
+ @JvmStatic
+ inline fun assertInNewMode() = RefactorFlagUtils.assertInNewMode(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/statusbar/notification/NotificationActivityStarter.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.kt
index 0f93b5d1ea12..231a0b0b21cb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.kt
@@ -16,6 +16,11 @@
package com.android.systemui.statusbar.notification
import android.content.Intent
+import android.provider.Settings.ACTION_AUTOMATIC_ZEN_RULE_SETTINGS
+import android.provider.Settings.ACTION_NOTIFICATION_HISTORY
+import android.provider.Settings.ACTION_NOTIFICATION_SETTINGS
+import android.provider.Settings.ACTION_ZEN_MODE_SETTINGS
+import android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID
import android.view.View
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
@@ -25,6 +30,7 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
* (e.g. clicking on a notification, tapping on the settings icon in the notification guts)
*/
interface NotificationActivityStarter {
+
/** Called when the user clicks on the notification bubble icon. */
fun onNotificationBubbleIconClicked(entry: NotificationEntry?)
@@ -35,14 +41,63 @@ interface NotificationActivityStarter {
fun startNotificationGutsIntent(intent: Intent?, appUid: Int, row: ExpandableNotificationRow?)
/**
- * Called when the user clicks "Manage" or "History" in the Shade, or the "No notifications"
- * text.
+ * Called when the user clicks "Manage" or "History" in the Shade. Prefer using
+ * [startSettingsIntent] instead.
*/
fun startHistoryIntent(view: View?, showHistory: Boolean)
+ /**
+ * Called to open a settings intent from a launchable view (such as the "Manage" or "History"
+ * button in the shade, or the "No notifications" text).
+ *
+ * @param view the view to perform the launch animation from (must extend [LaunchableView])
+ * @param intentInfo information about the (settings) intent to be launched
+ */
+ fun startSettingsIntent(view: View, intentInfo: SettingsIntent)
+
/** Called when the user succeed to drop notification to proper target view. */
fun onDragSuccess(entry: NotificationEntry?)
val isCollapsingToShowActivityOverLockscreen: Boolean
get() = false
+
+ /**
+ * Information about a settings intent to be launched.
+ *
+ * If the [targetIntent] is T and [backStack] is [A, B, C], the stack will look like
+ * [A, B, C, T].
+ */
+ data class SettingsIntent(
+ var targetIntent: Intent,
+ var backStack: List<Intent> = emptyList(),
+ var cujType: Int? = null,
+ ) {
+ // Utility factory methods for known intents
+ companion object {
+ fun forNotificationSettings(cujType: Int? = null) =
+ SettingsIntent(
+ targetIntent = Intent(ACTION_NOTIFICATION_SETTINGS),
+ cujType = cujType,
+ )
+
+ fun forNotificationHistory(cujType: Int? = null) =
+ SettingsIntent(
+ targetIntent = Intent(ACTION_NOTIFICATION_HISTORY),
+ backStack = listOf(Intent(ACTION_NOTIFICATION_SETTINGS)),
+ cujType = cujType,
+ )
+
+ fun forModesSettings(cujType: Int? = null) =
+ SettingsIntent(targetIntent = Intent(ACTION_ZEN_MODE_SETTINGS), cujType = cujType)
+
+ fun forModeSettings(modeId: String, cujType: Int? = null) =
+ SettingsIntent(
+ targetIntent =
+ Intent(ACTION_AUTOMATIC_ZEN_RULE_SETTINGS)
+ .putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, modeId),
+ backStack = listOf(Intent(ACTION_ZEN_MODE_SETTINGS)),
+ cujType = cujType,
+ )
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManager.kt
index b342722ebb09..b67092ca9348 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManager.kt
@@ -22,7 +22,7 @@ import com.android.internal.annotations.VisibleForTesting
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.notification.collection.NotificationClassificationFlag
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.shared.PriorityPeopleSection
import com.android.systemui.statusbar.notification.stack.BUCKET_ALERTING
import com.android.systemui.statusbar.notification.stack.BUCKET_FOREGROUND_SERVICE
@@ -54,7 +54,7 @@ constructor(val proxy: DeviceConfigProxy, val context: Context) {
fun getNotificationBuckets(): IntArray {
if (
PriorityPeopleSection.isEnabled ||
- NotificationMinimalismPrototype.isEnabled ||
+ NotificationMinimalism.isEnabled ||
NotificationClassificationFlag.isEnabled
) {
// We don't need this list to be adaptive, it can be the superset of all features.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinator.kt
index a621b2a02c5d..4e63b920a73d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinator.kt
@@ -35,7 +35,7 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.plugga
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
import com.android.systemui.statusbar.notification.domain.interactor.HeadsUpNotificationInteractor
import com.android.systemui.statusbar.notification.domain.interactor.SeenNotificationsInteractor
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.stack.BUCKET_TOP_ONGOING
import com.android.systemui.statusbar.notification.stack.BUCKET_TOP_UNSEEN
import com.android.systemui.util.asIndenting
@@ -77,7 +77,7 @@ constructor(
private var unseenFilterEnabled = false
override fun attach(pipeline: NotifPipeline) {
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) {
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) {
return
}
pipeline.addPromoter(unseenNotifPromoter)
@@ -129,26 +129,25 @@ constructor(
}
}
- private fun unseenFeatureEnabled(): Flow<Boolean> {
- // TODO(b/330387368): create LOCK_SCREEN_NOTIFICATION_MINIMALISM setting to use here?
- // Or should we actually just repurpose using the existing setting?
- if (NotificationMinimalismPrototype.isEnabled) {
- return flowOf(true)
+ private fun minimalismFeatureSettingEnabled(): Flow<Boolean> {
+ if (!NotificationMinimalism.isEnabled) {
+ return flowOf(false)
}
- return seenNotificationsInteractor.isLockScreenShowOnlyUnseenNotificationsEnabled()
+ return seenNotificationsInteractor.isLockScreenNotificationMinimalismEnabled()
}
private suspend fun trackUnseenFilterSettingChanges() {
- unseenFeatureEnabled().collectLatest { isSettingEnabled ->
+ // Only filter the seen notifs when the lock screen minimalism feature settings is on.
+ minimalismFeatureSettingEnabled().collectLatest { isMinimalismSettingEnabled ->
// update local field and invalidate if necessary
- if (isSettingEnabled != unseenFilterEnabled) {
- unseenFilterEnabled = isSettingEnabled
+ if (isMinimalismSettingEnabled != unseenFilterEnabled) {
+ unseenFilterEnabled = isMinimalismSettingEnabled
unseenNotifications.clear()
unseenNotifPromoter.invalidateList("unseen setting changed")
}
// if the setting is enabled, then start tracking and filtering unseen notifications
- logger.logTrackingUnseen(isSettingEnabled)
- if (isSettingEnabled) {
+ logger.logTrackingUnseen(isMinimalismSettingEnabled)
+ if (isMinimalismSettingEnabled) {
trackSeenNotifications()
}
}
@@ -178,7 +177,7 @@ constructor(
}
private fun pickOutTopUnseenNotifs(list: List<ListEntry>) {
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) return
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) return
if (!unseenFilterEnabled) return
// Only ever elevate a top unseen notification on keyguard, not even locked shade
if (statusBarStateController.state != StatusBarState.KEYGUARD) {
@@ -215,9 +214,9 @@ constructor(
object : NotifPromoter(TAG) {
override fun shouldPromoteToTopLevel(child: NotificationEntry): Boolean =
when {
- NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode() -> false
+ NotificationMinimalism.isUnexpectedlyInLegacyMode() -> false
seenNotificationsInteractor.isTopOngoingNotification(child) -> true
- !NotificationMinimalismPrototype.ungroupTopUnseen -> false
+ !NotificationMinimalism.ungroupTopUnseen -> false
else -> seenNotificationsInteractor.isTopUnseenNotification(child)
}
}
@@ -225,7 +224,7 @@ constructor(
val topOngoingSectioner =
object : NotifSectioner("TopOngoing", BUCKET_TOP_ONGOING) {
override fun isInSection(entry: ListEntry): Boolean {
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) return false
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) return false
return entry.anyEntry { notificationEntry ->
seenNotificationsInteractor.isTopOngoingNotification(notificationEntry)
}
@@ -235,7 +234,7 @@ constructor(
val topUnseenSectioner =
object : NotifSectioner("TopUnseen", BUCKET_TOP_UNSEEN) {
override fun isInSection(entry: ListEntry): Boolean {
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) return false
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) return false
return entry.anyEntry { notificationEntry ->
seenNotificationsInteractor.isTopUnseenNotification(notificationEntry)
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorLogger.kt
index e44a77c30999..a4fa72942380 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/LockScreenMinimalismCoordinatorLogger.kt
@@ -34,7 +34,10 @@ constructor(
TAG,
LogLevel.DEBUG,
messageInitializer = { bool1 = trackingUnseen },
- messagePrinter = { "${if (bool1) "Start" else "Stop"} tracking unseen notifications." },
+ messagePrinter = {
+ "${if (bool1) "Start" else "Stop"} " +
+ "tracking unseen notifications because of settings change."
+ },
)
fun logShadeVisible(numUnseen: Int) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt
index 73ce48b2324a..96c260bb0852 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt
@@ -25,7 +25,7 @@ import com.android.systemui.statusbar.notification.collection.SortBySectionTimeF
import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner
import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor
import com.android.systemui.statusbar.notification.shared.PriorityPeopleSection
import javax.inject.Inject
@@ -88,11 +88,10 @@ constructor(
mCoordinators.add(hideLocallyDismissedNotifsCoordinator)
mCoordinators.add(hideNotifsForOtherUsersCoordinator)
mCoordinators.add(keyguardCoordinator)
- if (NotificationMinimalismPrototype.isEnabled) {
+ if (NotificationMinimalism.isEnabled) {
mCoordinators.add(lockScreenMinimalismCoordinator)
- } else {
- mCoordinators.add(unseenKeyguardCoordinator)
}
+ mCoordinators.add(unseenKeyguardCoordinator)
mCoordinators.add(rankingCoordinator)
mCoordinators.add(colorizedFgsCoordinator)
mCoordinators.add(deviceProvisionedCoordinator)
@@ -125,11 +124,11 @@ constructor(
}
// Manually add Ordered Sections
- if (NotificationMinimalismPrototype.isEnabled) {
+ if (NotificationMinimalism.isEnabled) {
mOrderedSections.add(lockScreenMinimalismCoordinator.topOngoingSectioner) // Top Ongoing
}
mOrderedSections.add(headsUpCoordinator.sectioner) // HeadsUp
- if (NotificationMinimalismPrototype.isEnabled) {
+ if (NotificationMinimalism.isEnabled) {
mOrderedSections.add(lockScreenMinimalismCoordinator.topUnseenSectioner) // Top Unseen
}
mOrderedSections.add(colorizedFgsCoordinator.sectioner) // ForegroundService
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/OriginalUnseenKeyguardCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/OriginalUnseenKeyguardCoordinator.kt
index bfea2ba6b839..cf1329c6b564 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/OriginalUnseenKeyguardCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/OriginalUnseenKeyguardCoordinator.kt
@@ -35,7 +35,6 @@ import com.android.systemui.statusbar.notification.collection.coordinator.dagger
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
import com.android.systemui.statusbar.notification.domain.interactor.SeenNotificationsInteractor
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
import com.android.systemui.statusbar.policy.HeadsUpManager
import com.android.systemui.statusbar.policy.headsUpEvents
import com.android.systemui.util.asIndenting
@@ -51,7 +50,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@@ -87,7 +85,6 @@ constructor(
private var unseenFilterEnabled = false
override fun attach(pipeline: NotifPipeline) {
- NotificationMinimalismPrototype.assertInLegacyMode()
pipeline.addFinalizeFilter(unseenNotifFilter)
pipeline.addCollectionListener(collectionListener)
scope.launch { trackUnseenFilterSettingChanges() }
@@ -253,10 +250,6 @@ constructor(
}
private fun unseenFeatureEnabled(): Flow<Boolean> {
- if (NotificationMinimalismPrototype.isEnabled) {
- // TODO(b/330387368): should this really just be turned off? If so, hide the setting.
- return flowOf(false)
- }
return seenNotificationsInteractor.isLockScreenShowOnlyUnseenNotificationsEnabled()
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt
index 5ff5d2d9a7e5..1fe32c9a873a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt
@@ -117,18 +117,12 @@ constructor(
(entry.getSbn().getNotification().flags and
FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY) > 0
) {
+ // If we've received an update from the system and the entry is marked
+ // as lifetime extended, that means system server has received a
+ // cancelation in response to a direct reply, and sent an update to
+ // let system ui know that it should rebuild the notification with
+ // that direct reply.
if (
- mNotificationRemoteInputManager.shouldKeepForRemoteInputHistory(
- entry
- )
- ) {
- val newSbn = mRebuilder.rebuildForRemoteInputReply(entry)
- entry.onRemoteInputInserted()
- mNotifUpdater.onInternalNotificationUpdate(
- newSbn,
- "Extending lifetime of notification with remote input",
- )
- } else if (
mNotificationRemoteInputManager.shouldKeepForSmartReplyHistory(
entry
)
@@ -140,16 +134,11 @@ constructor(
"Extending lifetime of notification with smart reply",
)
} else {
- // The app may have re-cancelled a notification after it had already
- // been lifetime extended.
- // Rebuild the notification with the replies it already had to
- // ensure
- // those replies continue to be displayed.
- val newSbn = mRebuilder.rebuildWithExistingReplies(entry)
+ val newSbn = mRebuilder.rebuildForRemoteInputReply(entry)
+ entry.onRemoteInputInserted()
mNotifUpdater.onInternalNotificationUpdate(
newSbn,
- "Extending lifetime of notification that has already been " +
- "lifetime extended.",
+ "Extending lifetime of notification with remote input",
)
}
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/VisualStabilityCoordinator.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/VisualStabilityCoordinator.java
index 6d0148a24cf8..41419f31eb7a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/VisualStabilityCoordinator.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/VisualStabilityCoordinator.java
@@ -41,7 +41,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifStabilityManager;
import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider;
import com.android.systemui.statusbar.notification.domain.interactor.SeenNotificationsInteractor;
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype;
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.kotlin.BooleanFlowOperators;
@@ -170,7 +170,7 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
if (entry == null) {
return false;
}
- boolean isTopUnseen = NotificationMinimalismPrototype.isEnabled()
+ boolean isTopUnseen = NotificationMinimalism.isEnabled()
&& (mSeenNotificationsInteractor.isTopUnseenNotification(entry)
|| mSeenNotificationsInteractor.isTopOngoingNotification(entry));
if (isTopUnseen || mHeadsUpManager.isHeadsUpEntry(entry.getKey())) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractor.kt
index 29564326481f..1babe47559e5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractor.kt
@@ -23,7 +23,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationListRepository
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.util.printSection
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
@@ -57,25 +57,25 @@ constructor(
/** Set the entry that is identified as the top ongoing notification. */
fun setTopOngoingNotification(entry: NotificationEntry?) {
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) return
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) return
notificationListRepository.topOngoingNotificationKey.value = entry?.key
}
/** Determine if the given notification is the top ongoing notification. */
fun isTopOngoingNotification(entry: NotificationEntry?): Boolean =
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) false
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) false
else
entry != null && notificationListRepository.topOngoingNotificationKey.value == entry.key
/** Set the entry that is identified as the top unseen notification. */
fun setTopUnseenNotification(entry: NotificationEntry?) {
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) return
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) return
notificationListRepository.topUnseenNotificationKey.value = entry?.key
}
/** Determine if the given notification is the top unseen notification. */
fun isTopUnseenNotification(entry: NotificationEntry?): Boolean =
- if (NotificationMinimalismPrototype.isUnexpectedlyInLegacyMode()) false
+ if (NotificationMinimalism.isUnexpectedlyInLegacyMode()) false
else entry != null && notificationListRepository.topUnseenNotificationKey.value == entry.key
fun dump(pw: IndentingPrintWriter) =
@@ -120,4 +120,29 @@ constructor(
// only track the most recent emission, if events are happening faster than they can be
// consumed
.conflate()
+
+ fun isLockScreenNotificationMinimalismEnabled(): Flow<Boolean> =
+ secureSettings
+ // emit whenever the setting has changed
+ .observerFlow(
+ UserHandle.USER_ALL,
+ Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
+ )
+ // perform a query immediately
+ .onStart { emit(Unit) }
+ // for each change, lookup the new value
+ .map {
+ secureSettings.getIntForUser(
+ name = Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
+ default = 1,
+ userHandle = UserHandle.USER_CURRENT,
+ ) == 1
+ }
+ // don't emit anything if nothing has changed
+ .distinctUntilChanged()
+ // perform lookups on the bg thread pool
+ .flowOn(bgDispatcher)
+ // only track the most recent emission, if events are happening faster than they can be
+ // consumed
+ .conflate()
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewbinder/EmptyShadeViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewbinder/EmptyShadeViewBinder.kt
index 102a11c2314c..7f1b04358546 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewbinder/EmptyShadeViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewbinder/EmptyShadeViewBinder.kt
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.emptyshade.ui.viewbinder
import android.view.View
+import com.android.systemui.statusbar.notification.NotificationActivityStarter
import com.android.systemui.statusbar.notification.emptyshade.ui.view.EmptyShadeView
import com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel.EmptyShadeViewModel
import kotlinx.coroutines.coroutineScope
@@ -26,18 +27,16 @@ object EmptyShadeViewBinder {
suspend fun bind(
view: EmptyShadeView,
viewModel: EmptyShadeViewModel,
- launchNotificationSettings: View.OnClickListener,
- launchNotificationHistory: View.OnClickListener,
+ notificationActivityStarter: NotificationActivityStarter,
) = coroutineScope {
launch { viewModel.text.collect { view.setText(it) } }
launch {
- viewModel.tappingShouldLaunchHistory.collect { shouldLaunchHistory ->
- if (shouldLaunchHistory) {
- view.setOnClickListener(launchNotificationHistory)
- } else {
- view.setOnClickListener(launchNotificationSettings)
+ viewModel.onClick.collect { settingsIntent ->
+ val onClickListener = { view: View ->
+ notificationActivityStarter.startSettingsIntent(view, settingsIntent)
}
+ view.setOnClickListener(onClickListener)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt
index d5417e7ae8f6..8c8f200f78b7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt
@@ -22,6 +22,7 @@ import com.android.systemui.dump.DumpManager
import com.android.systemui.modes.shared.ModesUi
import com.android.systemui.res.R
import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
+import com.android.systemui.statusbar.notification.NotificationActivityStarter.SettingsIntent
import com.android.systemui.statusbar.notification.domain.interactor.SeenNotificationsInteractor
import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
@@ -34,6 +35,7 @@ import java.util.Locale
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
@@ -80,8 +82,7 @@ constructor(
if (ModesUi.isEnabled) {
zenModeInteractor.modesHidingNotifications.map { modes ->
// Create a string that is either "No notifications" if no modes are filtering
- // them
- // out, or something like "Notifications paused by SomeMode" otherwise.
+ // them out, or something like "Notifications paused by SomeMode" otherwise.
val msgFormat =
MessageFormat(
context.getString(R.string.modes_suppressing_shade_text),
@@ -116,9 +117,26 @@ constructor(
)
}
- val tappingShouldLaunchHistory by lazy {
+ val onClick: Flow<SettingsIntent> by lazy {
ModesEmptyShadeFix.assertInNewMode()
- notificationSettingsInteractor.isNotificationHistoryEnabled
+ combine(
+ zenModeInteractor.modesHidingNotifications,
+ notificationSettingsInteractor.isNotificationHistoryEnabled,
+ ) { modes, isNotificationHistoryEnabled ->
+ if (modes.isNotEmpty()) {
+ if (modes.size == 1) {
+ SettingsIntent.forModeSettings(modes[0].id)
+ } else {
+ SettingsIntent.forModesSettings()
+ }
+ } else {
+ if (isNotificationHistoryEnabled) {
+ SettingsIntent.forNotificationHistory()
+ } else {
+ SettingsIntent.forNotificationSettings()
+ }
+ }
+ }
}
@AssistedFactory
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewbinder/FooterViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewbinder/FooterViewBinder.kt
index 920541d101cf..22bec5a43230 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewbinder/FooterViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewbinder/FooterViewBinder.kt
@@ -19,6 +19,8 @@ package com.android.systemui.statusbar.notification.footer.ui.viewbinder
import android.view.View
import androidx.lifecycle.lifecycleScope
import com.android.systemui.lifecycle.repeatWhenAttached
+import com.android.systemui.statusbar.notification.NotificationActivityStarter
+import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.ui.view.FooterView
import com.android.systemui.statusbar.notification.footer.ui.viewmodel.FooterViewModel
import com.android.systemui.util.ui.isAnimating
@@ -36,6 +38,7 @@ object FooterViewBinder {
clearAllNotifications: View.OnClickListener,
launchNotificationSettings: View.OnClickListener,
launchNotificationHistory: View.OnClickListener,
+ notificationActivityStarter: NotificationActivityStarter,
): DisposableHandle {
return footer.repeatWhenAttached {
lifecycleScope.launch {
@@ -45,6 +48,7 @@ object FooterViewBinder {
clearAllNotifications,
launchNotificationSettings,
launchNotificationHistory,
+ notificationActivityStarter,
)
}
}
@@ -56,6 +60,7 @@ object FooterViewBinder {
clearAllNotifications: View.OnClickListener,
launchNotificationSettings: View.OnClickListener,
launchNotificationHistory: View.OnClickListener,
+ notificationActivityStarter: NotificationActivityStarter,
) = coroutineScope {
launch { bindClearAllButton(footer, viewModel, clearAllNotifications) }
launch {
@@ -64,6 +69,7 @@ object FooterViewBinder {
viewModel,
launchNotificationSettings,
launchNotificationHistory,
+ notificationActivityStarter,
)
}
launch { bindMessage(footer, viewModel) }
@@ -113,13 +119,23 @@ object FooterViewBinder {
viewModel: FooterViewModel,
launchNotificationSettings: View.OnClickListener,
launchNotificationHistory: View.OnClickListener,
+ notificationActivityStarter: NotificationActivityStarter,
) = coroutineScope {
launch {
- viewModel.manageButtonShouldLaunchHistory.collect { shouldLaunchHistory ->
- if (shouldLaunchHistory) {
- footer.setManageButtonClickListener(launchNotificationHistory)
- } else {
- footer.setManageButtonClickListener(launchNotificationSettings)
+ if (ModesEmptyShadeFix.isEnabled) {
+ viewModel.manageOrHistoryButtonClick.collect { settingsIntent ->
+ val onClickListener = { view: View ->
+ notificationActivityStarter.startSettingsIntent(view, settingsIntent)
+ }
+ footer.setManageButtonClickListener(onClickListener)
+ }
+ } else {
+ viewModel.manageButtonShouldLaunchHistory.collect { shouldLaunchHistory ->
+ if (shouldLaunchHistory) {
+ footer.setManageButtonClickListener(launchNotificationHistory)
+ } else {
+ footer.setManageButtonClickListener(launchNotificationSettings)
+ }
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt
index 90fb7285e939..a3f4cd225130 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt
@@ -16,12 +16,17 @@
package com.android.systemui.statusbar.notification.footer.ui.viewmodel
+import android.content.Intent
+import android.provider.Settings
+import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
+import com.android.systemui.statusbar.notification.NotificationActivityStarter.SettingsIntent
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.domain.interactor.SeenNotificationsInteractor
+import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
import com.android.systemui.statusbar.notification.footer.ui.view.FooterView
import com.android.systemui.util.kotlin.sample
@@ -80,7 +85,7 @@ class FooterViewModel(
combine(
shadeInteractor.isShadeFullyExpanded,
shadeInteractor.isShadeTouchable,
- ::Pair
+ ::Pair,
)
.onStart { emit(Pair(false, false)) }
) { clearAllButtonVisible, (isShadeFullyExpanded, animationsEnabled) ->
@@ -93,8 +98,28 @@ class FooterViewModel(
val manageButtonShouldLaunchHistory =
notificationSettingsInteractor.isNotificationHistoryEnabled
+ // TODO(b/366003631): When inlining the flag, consider adding this to FooterButtonViewModel.
+ val manageOrHistoryButtonClick: Flow<SettingsIntent> by lazy {
+ if (ModesEmptyShadeFix.isUnexpectedlyInLegacyMode()) {
+ flowOf(SettingsIntent(Intent(Settings.ACTION_NOTIFICATION_SETTINGS)))
+ } else {
+ notificationSettingsInteractor.isNotificationHistoryEnabled.map {
+ isNotificationHistoryEnabled ->
+ if (isNotificationHistoryEnabled) {
+ SettingsIntent.forNotificationHistory(
+ cujType = InteractionJankMonitor.CUJ_SHADE_APP_LAUNCH_FROM_HISTORY_BUTTON
+ )
+ } else {
+ SettingsIntent.forNotificationSettings(
+ cujType = InteractionJankMonitor.CUJ_SHADE_APP_LAUNCH_FROM_HISTORY_BUTTON
+ )
+ }
+ }
+ }
+ }
+
private val manageOrHistoryButtonText: Flow<Int> =
- manageButtonShouldLaunchHistory.map { shouldLaunchHistory ->
+ notificationSettingsInteractor.isNotificationHistoryEnabled.map { shouldLaunchHistory ->
if (shouldLaunchHistory) R.string.manage_notifications_history_text
else R.string.manage_notifications_text
}
@@ -128,7 +153,7 @@ object FooterViewModelModule {
activeNotificationsInteractor.get(),
notificationSettingsInteractor.get(),
seenNotificationsInteractor.get(),
- shadeInteractor.get()
+ shadeInteractor.get(),
)
)
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/shared/NotificationMinimalismPrototype.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/shared/NotificationMinimalism.kt
index 06f3db504aaf..70bb2722c678 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/shared/NotificationMinimalismPrototype.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/shared/NotificationMinimalism.kt
@@ -17,23 +17,23 @@
package com.android.systemui.statusbar.notification.shared
import android.os.SystemProperties
-import com.android.systemui.Flags
+import com.android.server.notification.Flags
import com.android.systemui.flags.FlagToken
import com.android.systemui.flags.RefactorFlagUtils
/** Helper for reading or using the minimalism prototype flag state. */
@Suppress("NOTHING_TO_INLINE")
-object NotificationMinimalismPrototype {
- const val FLAG_NAME = Flags.FLAG_NOTIFICATION_MINIMALISM_PROTOTYPE
+object NotificationMinimalism {
+ const val FLAG_NAME = Flags.FLAG_NOTIFICATION_MINIMALISM
/** A token used for dependency declaration */
val token: FlagToken
get() = FlagToken(FLAG_NAME, isEnabled)
- /** Is the heads-up cycling animation enabled */
+ /** Is the notification minimalism enabled */
@JvmStatic
inline val isEnabled
- get() = Flags.notificationMinimalismPrototype()
+ get() = Flags.notificationMinimalism()
/**
* The prototype will (by default) use a promoter to ensure that the top unseen notification is
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
index 1431b28bf794..129d4cee9cdb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
@@ -88,6 +88,8 @@ public class AmbientState implements Dumpable {
private ExpandableView mLastVisibleBackgroundChild;
private float mCurrentScrollVelocity;
private int mStatusBarState;
+ private boolean mShowingStackOnLockscreen;
+ private float mLockscreenStackFadeInProgress;
private float mExpandingVelocity;
private boolean mPanelTracking;
private boolean mExpansionChanging;
@@ -222,6 +224,7 @@ public class AmbientState implements Dumpable {
* @param isSwipingUp Whether we are swiping up.
*/
public void setSwipingUp(boolean isSwipingUp) {
+ SceneContainerFlag.assertInLegacyMode();
if (!isSwipingUp && mIsSwipingUp) {
// Just stopped swiping up.
mIsFlingRequiredAfterLockScreenSwipeUp = true;
@@ -240,6 +243,7 @@ public class AmbientState implements Dumpable {
* @param isFlinging Whether we are flinging the shade open or closed.
*/
public void setFlinging(boolean isFlinging) {
+ SceneContainerFlag.assertInLegacyMode();
if (isOnKeyguard() && !isFlinging && mIsFlinging) {
// Just stopped flinging.
mIsFlingRequiredAfterLockScreenSwipeUp = false;
@@ -624,6 +628,26 @@ public class AmbientState implements Dumpable {
return mStatusBarState == StatusBarState.KEYGUARD;
}
+ public boolean isShowingStackOnLockscreen() {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return false;
+ return mShowingStackOnLockscreen;
+ }
+
+ public void setShowingStackOnLockscreen(boolean showingStackOnLockscreen) {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
+ mShowingStackOnLockscreen = showingStackOnLockscreen;
+ }
+
+ public float getLockscreenStackFadeInProgress() {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0f;
+ return mLockscreenStackFadeInProgress;
+ }
+
+ public void setLockscreenStackFadeInProgress(float lockscreenStackFadeInProgress) {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
+ mLockscreenStackFadeInProgress = lockscreenStackFadeInProgress;
+ }
+
public void setStatusBarState(int statusBarState) {
if (mStatusBarState != StatusBarState.KEYGUARD) {
mIsFlingRequiredAfterLockScreenSwipeUp = false;
@@ -695,6 +719,7 @@ public class AmbientState implements Dumpable {
* @return Whether we need to do a fling down after swiping up on lockscreen.
*/
public boolean isFlingingAfterSwipeUpOnLockscreen() {
+ SceneContainerFlag.assertInLegacyMode();
return mIsFlinging && mIsFlingRequiredAfterLockScreenSwipeUp;
}
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 b2b2c2a790d8..b466bf02387f 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
@@ -568,6 +568,7 @@ public class NotificationStackScrollLayout
private boolean mHasFilteredOutSeenNotifications;
@Nullable private SplitShadeStateController mSplitShadeStateController = null;
private boolean mIsSmallLandscapeLockscreenEnabled = false;
+ private boolean mSuppressHeightUpdates;
/** Pass splitShadeStateController to view and update split shade */
public void passSplitShadeStateController(SplitShadeStateController splitShadeStateController) {
@@ -1458,9 +1459,13 @@ public class NotificationStackScrollLayout
* 2) Swiping up on lockscreen or flinging down after swipe up
*/
private boolean shouldSkipHeightUpdate() {
- return mAmbientState.isOnKeyguard()
- && (mAmbientState.isSwipingUp()
- || mAmbientState.isFlingingAfterSwipeUpOnLockscreen());
+ if (SceneContainerFlag.isEnabled()) {
+ return mSuppressHeightUpdates;
+ } else {
+ return mAmbientState.isOnKeyguard()
+ && (mAmbientState.isSwipingUp()
+ || mAmbientState.isFlingingAfterSwipeUpOnLockscreen());
+ }
}
/**
@@ -5342,6 +5347,19 @@ public class NotificationStackScrollLayout
updateDismissBehavior();
}
+ @Override
+ public void setShowingStackOnLockscreen(boolean showingStackOnLockscreen) {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
+ mAmbientState.setShowingStackOnLockscreen(showingStackOnLockscreen);
+ }
+
+ @Override
+ public void setAlphaForLockscreenFadeIn(float alphaForLockscreenFadeIn) {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
+ mAmbientState.setLockscreenStackFadeInProgress(alphaForLockscreenFadeIn);
+ requestChildrenUpdate();
+ }
+
void setUpcomingStatusBarState(int upcomingStatusBarState) {
FooterViewRefactor.assertInLegacyMode();
mUpcomingStatusBarState = upcomingStatusBarState;
@@ -5386,6 +5404,7 @@ public class NotificationStackScrollLayout
}
public void setPanelFlinging(boolean flinging) {
+ SceneContainerFlag.assertInLegacyMode();
mAmbientState.setFlinging(flinging);
if (!flinging) {
// re-calculate the stack height which was frozen while flinging
@@ -5393,6 +5412,12 @@ public class NotificationStackScrollLayout
}
}
+ @Override
+ public void suppressHeightUpdates(boolean suppress) {
+ if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
+ mSuppressHeightUpdates = suppress;
+ }
+
public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) {
mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java
index dad6894a43ce..7b02d0cebfb3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java
@@ -380,7 +380,7 @@ public class NotificationStackScrollLayoutController implements Dumpable {
new StatusBarStateController.StateListener() {
@Override
public void onStatePreChange(int oldState, int newState) {
- if (oldState == StatusBarState.SHADE_LOCKED
+ if (!SceneContainerFlag.isEnabled() && oldState == StatusBarState.SHADE_LOCKED
&& newState == KEYGUARD) {
mView.requestAnimateEverything();
}
@@ -1439,6 +1439,7 @@ public class NotificationStackScrollLayoutController implements Dumpable {
}
public void setPanelFlinging(boolean flinging) {
+ SceneContainerFlag.assertInLegacyMode();
mView.setPanelFlinging(flinging);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt
index 06222fdb2761..3bc549543ef2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt
@@ -29,7 +29,7 @@ import com.android.systemui.statusbar.StatusBarState.KEYGUARD
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableView
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.policy.SplitShadeStateController
import com.android.systemui.util.Compile
import com.android.systemui.util.children
@@ -74,7 +74,7 @@ constructor(
/** Whether we allow keyguard to show less important notifications above the shelf. */
private val limitLockScreenToOneImportant
- get() = NotificationMinimalismPrototype.isEnabled
+ get() = NotificationMinimalism.isEnabled
/** Minimum space between two notifications, see [calculateGapAndDividerHeight]. */
private var dividerHeight by notNull<Float>()
@@ -406,7 +406,7 @@ constructor(
fun updateResources() {
maxKeyguardNotifications =
infiniteIfNegative(resources.getInteger(R.integer.keyguard_max_notification_count))
- maxNotificationsExcludesMedia = NotificationMinimalismPrototype.isEnabled
+ maxNotificationsExcludesMedia = NotificationMinimalism.isEnabled
dividerHeight =
max(1f, resources.getDimensionPixelSize(R.dimen.notification_divider_height).toFloat())
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
index 9c0fd0e844b4..e0b0ccd9e840 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
@@ -148,12 +148,18 @@ public class StackScrollAlgorithm {
if (isHunGoingToShade) {
// Keep 100% opacity for heads up notification going to shade.
viewState.setAlpha(1f);
- } else if (ambientState.isOnKeyguard()) {
+ } else if ((!SceneContainerFlag.isEnabled() && ambientState.isOnKeyguard())
+ || ambientState.isShowingStackOnLockscreen()) {
// Adjust alpha for wakeup to lockscreen.
if (view.isHeadsUpState()) {
// Pulsing HUN should be visible on AOD and stay visible during
// AOD=>lockscreen transition
viewState.setAlpha(1f - ambientState.getHideAmount());
+ } else if (SceneContainerFlag.isEnabled()) {
+ // Take into account scene container-specific Lockscreen fade-in progress
+ float fadeAlpha = ambientState.getLockscreenStackFadeInProgress();
+ float dozeAlpha = 1f - ambientState.getDozeAmount();
+ viewState.setAlpha(Math.min(dozeAlpha, fadeAlpha));
} else {
// Normal notifications are hidden on AOD and should fade in during
// AOD=>lockscreen transition
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/data/repository/NotificationPlaceholderRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/data/repository/NotificationPlaceholderRepository.kt
index f6722a4ccff0..c0f1a5619140 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/data/repository/NotificationPlaceholderRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/data/repository/NotificationPlaceholderRepository.kt
@@ -31,6 +31,9 @@ class NotificationPlaceholderRepository @Inject constructor() {
/** The alpha of the shade in order to show brightness. */
val alphaForBrightnessMirror = MutableStateFlow(1f)
+ /** The alpha of the Notification Stack for lockscreen fade-in */
+ val alphaForLockscreenFadeIn = MutableStateFlow(0f)
+
/**
* The bounds of the notification shade scrim / container in the current scene.
*
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/NotificationStackAppearanceInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/NotificationStackAppearanceInteractor.kt
index 756cd87970a4..32e092bcdf4d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/NotificationStackAppearanceInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/NotificationStackAppearanceInteractor.kt
@@ -56,10 +56,9 @@ constructor(
/** The rounding of the notification stack. */
val shadeScrimRounding: Flow<ShadeScrimRounding> =
- combine(
- shadeInteractor.shadeMode,
- isExpandingFromHeadsUp,
- ) { shadeMode, isExpandingFromHeadsUp ->
+ combine(shadeInteractor.shadeMode, isExpandingFromHeadsUp) {
+ shadeMode,
+ isExpandingFromHeadsUp ->
ShadeScrimRounding(
isTopRounded = !(shadeMode == ShadeMode.Split && isExpandingFromHeadsUp),
isBottomRounded = shadeMode != ShadeMode.Single,
@@ -71,6 +70,10 @@ constructor(
val alphaForBrightnessMirror: StateFlow<Float> =
placeholderRepository.alphaForBrightnessMirror.asStateFlow()
+ /** The alpha of the Notification Stack for lockscreen fade-in */
+ val alphaForLockscreenFadeIn: StateFlow<Float> =
+ placeholderRepository.alphaForLockscreenFadeIn.asStateFlow()
+
/** The height of the keyguard's available space bounds */
val constrainedAvailableSpace: StateFlow<Int> =
placeholderRepository.constrainedAvailableSpace.asStateFlow()
@@ -99,7 +102,7 @@ constructor(
val shouldCloseGuts: Flow<Boolean> =
combine(
sceneInteractor.isSceneContainerUserInputOngoing,
- viewHeightRepository.isCurrentGestureInGuts
+ viewHeightRepository.isCurrentGestureInGuts,
) { isUserInputOngoing, isCurrentGestureInGuts ->
isUserInputOngoing && !isCurrentGestureInGuts
}
@@ -109,6 +112,11 @@ constructor(
placeholderRepository.alphaForBrightnessMirror.value = alpha
}
+ /** Sets the alpha to apply to the NSSL for fade-in on lockscreen */
+ fun setAlphaForLockscreenFadeIn(alpha: Float) {
+ placeholderRepository.alphaForLockscreenFadeIn.value = alpha
+ }
+
/** Sets the position of the notification stack in the current scene. */
fun setShadeScrimBounds(bounds: ShadeScrimBounds?) {
check(bounds == null || bounds.top <= bounds.bottom) { "Invalid bounds: $bounds" }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/view/NotificationScrollView.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/view/NotificationScrollView.kt
index 41c02934efa6..dbe81c10e2fd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/view/NotificationScrollView.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/view/NotificationScrollView.kt
@@ -89,6 +89,12 @@ interface NotificationScrollView {
/** sets the current QS expand fraction */
fun setQsExpandFraction(expandFraction: Float)
+ /** set whether we are idle on the lockscreen scene */
+ fun setShowingStackOnLockscreen(showingStackOnLockscreen: Boolean)
+
+ /** set the alpha from 0-1f of stack fade-in on lockscreen */
+ fun setAlphaForLockscreenFadeIn(alphaForLockscreenFadeIn: Float)
+
/** Sets whether the view is displayed in doze mode. */
fun setDozing(dozing: Boolean)
@@ -118,4 +124,7 @@ interface NotificationScrollView {
/** @see addHeadsUpHeightChangedListener */
fun removeHeadsUpHeightChangedListener(runnable: Runnable)
+
+ /** Sets whether updates to the stack are are suppressed. */
+ fun suppressHeightUpdates(suppress: Boolean)
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt
index 3dad32662893..ebae235f88d6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt
@@ -187,6 +187,7 @@ constructor(
},
launchNotificationSettings,
launchNotificationHistory,
+ notificationActivityStarter.get(),
)
if (SceneContainerFlag.isEnabled) {
launch {
@@ -266,8 +267,7 @@ constructor(
EmptyShadeViewBinder.bind(
emptyShadeView,
emptyShadeViewModel,
- launchNotificationSettings,
- launchNotificationHistory,
+ notificationActivityStarter.get(),
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationScrollViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationScrollViewBinder.kt
index 2e37dead8787..87d70ba12012 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationScrollViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationScrollViewBinder.kt
@@ -88,6 +88,14 @@ constructor(
viewModel.expandFraction.collect { view.setExpandFraction(it.coerceIn(0f, 1f)) }
}
launch { viewModel.qsExpandFraction.collect { view.setQsExpandFraction(it) } }
+ launch {
+ viewModel.isShowingStackOnLockscreen.collect {
+ view.setShowingStackOnLockscreen(it)
+ }
+ }
+ launch {
+ viewModel.alphaForLockscreenFadeIn.collect { view.setAlphaForLockscreenFadeIn(it) }
+ }
launch { viewModel.isScrollable.collect { view.setScrollingEnabled(it) } }
launch { viewModel.isDozing.collect { isDozing -> view.setDozing(isDozing) } }
launch {
@@ -103,6 +111,7 @@ constructor(
launch {
viewModel.shouldCloseGuts.filter { it }.collect { view.closeGutsOnSceneTouch() }
}
+ launch { viewModel.suppressHeightUpdates.collect { view.suppressHeightUpdates(it) } }
launchAndDispose {
view.setSyntheticScrollConsumer(viewModel.syntheticScrollConsumer)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationLockscreenScrimViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationLockscreenScrimViewModel.kt
new file mode 100644
index 000000000000..84aa997cf0e1
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationLockscreenScrimViewModel.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.statusbar.notification.stack.ui.viewmodel
+
+import com.android.systemui.dump.DumpManager
+import com.android.systemui.lifecycle.ExclusiveActivatable
+import com.android.systemui.shade.domain.interactor.ShadeInteractor
+import com.android.systemui.statusbar.notification.stack.domain.interactor.NotificationStackAppearanceInteractor
+import com.android.systemui.util.kotlin.ActivatableFlowDumper
+import com.android.systemui.util.kotlin.ActivatableFlowDumperImpl
+import dagger.assisted.AssistedFactory
+import dagger.assisted.AssistedInject
+
+class NotificationLockscreenScrimViewModel
+@AssistedInject
+constructor(
+ dumpManager: DumpManager,
+ shadeInteractor: ShadeInteractor,
+ private val stackAppearanceInteractor: NotificationStackAppearanceInteractor,
+) :
+ ActivatableFlowDumper by ActivatableFlowDumperImpl(dumpManager, "NotificationScrollViewModel"),
+ ExclusiveActivatable() {
+
+ val shadeMode = shadeInteractor.shadeMode
+
+ /** Sets the alpha to apply to the NSSL for fade-in on lockscreen */
+ fun setAlphaForLockscreenFadeIn(alpha: Float) {
+ stackAppearanceInteractor.setAlphaForLockscreenFadeIn(alpha)
+ }
+
+ override suspend fun onActivated(): Nothing {
+ activateFlowDumper()
+ }
+
+ @AssistedFactory
+ interface Factory {
+ fun create(): NotificationLockscreenScrimViewModel
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationScrollViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationScrollViewModel.kt
index 5b2e02d446cf..c9eaec7c5b85 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationScrollViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationScrollViewModel.kt
@@ -18,6 +18,7 @@
package com.android.systemui.statusbar.notification.stack.ui.viewmodel
import com.android.compose.animation.scene.ContentKey
+import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.ObservableTransitionState.Idle
import com.android.compose.animation.scene.ObservableTransitionState.Transition
import com.android.compose.animation.scene.ObservableTransitionState.Transition.ChangeScene
@@ -48,6 +49,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
/** ViewModel which represents the state of the NSSL/Controller in the world of flexiglass */
@@ -82,8 +84,13 @@ constructor(
private fun fullyExpandedDuringSceneChange(change: ChangeScene): Boolean {
// The lockscreen stack is visible during all transitions away from the lockscreen, so keep
// the stack expanded until those transitions finish.
- return (expandedInScene(change.fromScene) && expandedInScene(change.toScene)) ||
- change.isBetween({ it == Scenes.Lockscreen }, { true })
+ return if (change.isFrom({ it == Scenes.Lockscreen }, to = { true })) {
+ true
+ } else if (change.isFrom({ it == Scenes.Shade }, to = { it == Scenes.Lockscreen })) {
+ false
+ } else {
+ (expandedInScene(change.fromScene) && expandedInScene(change.toScene))
+ }
}
private fun expandFractionDuringSceneChange(
@@ -93,7 +100,10 @@ constructor(
): Float {
return if (fullyExpandedDuringSceneChange(change)) {
1f
- } else if (change.isBetween({ it == Scenes.Gone }, { it == Scenes.Shade })) {
+ } else if (
+ change.isBetween({ it == Scenes.Gone }, { it == Scenes.Shade }) ||
+ change.isFrom({ it == Scenes.Shade }, to = { it == Scenes.Lockscreen })
+ ) {
shadeExpansion
} else if (change.isBetween({ it == Scenes.Gone }, { it == Scenes.QuickSettings })) {
// during QS expansion, increase fraction at same rate as scrim alpha,
@@ -121,6 +131,14 @@ constructor(
}
}
+ /** Are notification stack height updates suppressed? */
+ val suppressHeightUpdates: Flow<Boolean> =
+ sceneInteractor.transitionState.map { transition: ObservableTransitionState ->
+ transition is Transition &&
+ transition.fromContent == Scenes.Lockscreen &&
+ (transition.toContent == Scenes.Bouncer || transition.toContent == Scenes.Gone)
+ }
+
/**
* The expansion fraction of the notification stack. It should go from 0 to 1 when transitioning
* from Gone to Shade scenes, and remain at 1 when in Lockscreen or Shade scenes and while
@@ -178,6 +196,18 @@ constructor(
.distinctUntilChanged()
.dumpWhileCollecting("shouldResetStackTop")
+ /** Whether the Notification Stack is visibly on the lockscreen scene. */
+ val isShowingStackOnLockscreen: Flow<Boolean> =
+ sceneInteractor.transitionState
+ .mapNotNull { state ->
+ state.isIdle(Scenes.Lockscreen) ||
+ state.isTransitioning(from = Scenes.Lockscreen, to = Scenes.Shade)
+ }
+ .distinctUntilChanged()
+
+ /** The alpha of the Notification Stack for lockscreen fade-in */
+ val alphaForLockscreenFadeIn = stackAppearanceInteractor.alphaForLockscreenFadeIn
+
private operator fun SceneKey.contains(scene: SceneKey) =
sceneInteractor.isSceneInFamily(scene, this)
@@ -298,3 +328,6 @@ constructor(
private fun ChangeScene.isBetween(a: (SceneKey) -> Boolean, b: (SceneKey) -> Boolean): Boolean =
(a(fromScene) && b(toScene)) || (b(fromScene) && a(toScene))
+
+private fun ChangeScene.isFrom(from: (SceneKey) -> Boolean, to: (SceneKey) -> Boolean): Boolean =
+ from(fromScene) && to(toScene)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
index 57be62932e59..0ad22e0b6dc9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
@@ -61,6 +61,7 @@ import com.android.systemui.keyguard.ui.viewmodel.LockscreenToPrimaryBouncerTran
import com.android.systemui.keyguard.ui.viewmodel.OccludedToAodTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.OccludedToGoneTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.OccludedToLockscreenTransitionViewModel
+import com.android.systemui.keyguard.ui.viewmodel.OffToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToGoneTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.ViewStateAccessor
@@ -132,6 +133,7 @@ constructor(
private val occludedToAodTransitionViewModel: OccludedToAodTransitionViewModel,
private val occludedToGoneTransitionViewModel: OccludedToGoneTransitionViewModel,
private val occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel,
+ private val offToLockscreenTransitionViewModel: OffToLockscreenTransitionViewModel,
private val primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel,
private val primaryBouncerToLockscreenTransitionViewModel:
PrimaryBouncerToLockscreenTransitionViewModel,
@@ -444,6 +446,7 @@ constructor(
occludedToAodTransitionViewModel.lockscreenAlpha,
occludedToGoneTransitionViewModel.notificationAlpha(viewState),
occludedToLockscreenTransitionViewModel.lockscreenAlpha,
+ offToLockscreenTransitionViewModel.lockscreenAlpha,
primaryBouncerToLockscreenTransitionViewModel.lockscreenAlpha(viewState),
glanceableHubToLockscreenTransitionViewModel.keyguardAlpha,
lockscreenToGlanceableHubTransitionViewModel.keyguardAlpha,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
index 0a6e7f59e24e..ee961955df39 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
@@ -43,6 +43,7 @@ import android.text.TextUtils;
import android.util.EventLog;
import android.view.View;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor;
@@ -74,6 +75,7 @@ import com.android.systemui.statusbar.notification.NotificationLaunchAnimatorCon
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.provider.LaunchFullScreenIntentProvider;
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
+import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRowDragController;
import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback;
@@ -249,7 +251,7 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
* Called when a notification is clicked.
*
* @param entry notification that was clicked
- * @param row row for that notification
+ * @param row row for that notification
*/
@Override
public void onNotificationClicked(NotificationEntry entry, ExpandableNotificationRow row) {
@@ -547,8 +549,8 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
(adapter) -> TaskStackBuilder.create(mContext)
.addNextIntentWithParentStack(intent)
.startActivities(getActivityOptions(
- mDisplayId,
- adapter),
+ mDisplayId,
+ adapter),
new UserHandle(UserHandle.getUserId(appUid))));
});
return true;
@@ -565,6 +567,7 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
@Override
public void startHistoryIntent(View view, boolean showHistory) {
+ ModesEmptyShadeFix.assertInLegacyMode();
boolean animate = mActivityStarter.shouldAnimateLaunch(true /* isActivityIntent */);
ActivityStarter.OnDismissAction onDismissAction = new ActivityStarter.OnDismissAction() {
@Override
@@ -585,14 +588,14 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
);
ActivityTransitionAnimator.Controller animationController =
viewController == null ? null
- : new StatusBarTransitionAnimatorController(
- viewController,
- mShadeAnimationInteractor,
- mShadeController,
- mNotificationShadeWindowController,
- mCommandQueue,
- mDisplayId,
- true /* isActivityIntent */);
+ : new StatusBarTransitionAnimatorController(
+ viewController,
+ mShadeAnimationInteractor,
+ mShadeController,
+ mNotificationShadeWindowController,
+ mCommandQueue,
+ mDisplayId,
+ true /* isActivityIntent */);
mActivityTransitionAnimator.startIntentWithAnimation(
animationController, animate, intent.getPackage(),
@@ -612,6 +615,51 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
false /* afterKeyguardGone */);
}
+ @Override
+ public void startSettingsIntent(@NonNull View view, @NonNull SettingsIntent intentInfo) {
+ boolean animate = mActivityStarter.shouldAnimateLaunch(true /* isActivityIntent */);
+ ActivityStarter.OnDismissAction onDismissAction = new ActivityStarter.OnDismissAction() {
+ @Override
+ public boolean onDismiss() {
+ AsyncTask.execute(() -> {
+ TaskStackBuilder tsb = TaskStackBuilder.create(mContext);
+ for (Intent intent : intentInfo.getBackStack()) {
+ tsb.addNextIntent(intent);
+ }
+ tsb.addNextIntent(intentInfo.getTargetIntent());
+
+ ActivityTransitionAnimator.Controller viewController =
+ ActivityTransitionAnimator.Controller.fromView(view,
+ intentInfo.getCujType());
+ ActivityTransitionAnimator.Controller animationController =
+ viewController == null ? null
+ : new StatusBarTransitionAnimatorController(
+ viewController,
+ mShadeAnimationInteractor,
+ mShadeController,
+ mNotificationShadeWindowController,
+ mCommandQueue,
+ mDisplayId,
+ true /* isActivityIntent */);
+
+ mActivityTransitionAnimator.startIntentWithAnimation(
+ animationController, animate, intentInfo.getTargetIntent().getPackage(),
+ (adapter) -> tsb.startActivities(
+ getActivityOptions(mDisplayId, adapter),
+ mUserTracker.getUserHandle()));
+ });
+ return true;
+ }
+
+ @Override
+ public boolean willRunAnimationOnKeyguard() {
+ return animate;
+ }
+ };
+ mActivityStarter.dismissKeyguardThenExecute(onDismissAction, null,
+ false /* afterKeyguardGone */);
+ }
+
private void removeHunAfterClick(ExpandableNotificationRow row) {
String key = row.getEntry().getSbn().getKey();
if (mHeadsUpManager != null && mHeadsUpManager.isHeadsUpEntry(key)) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/model/InternetTileIconModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/model/InternetTileIconModel.kt
new file mode 100644
index 000000000000..f8958e0d002f
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/model/InternetTileIconModel.kt
@@ -0,0 +1,27 @@
+/*
+ * 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.statusbar.pipeline.shared.ui.model
+
+import com.android.systemui.common.shared.model.Icon
+
+sealed interface InternetTileIconModel {
+ data class ResourceId(val resId: Int) : InternetTileIconModel
+
+ data class Cellular(val level: Int) : InternetTileIconModel
+
+ data class Satellite(val resourceIcon: Icon.Resource) : InternetTileIconModel
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/ModesDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/ModesDialogDelegate.kt
index e1dcc524c486..78edd3916a88 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/ModesDialogDelegate.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/ModesDialogDelegate.kt
@@ -19,8 +19,10 @@ package com.android.systemui.statusbar.policy.ui.dialog
import android.content.Intent
import android.provider.Settings
import android.util.Log
+import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
@@ -30,6 +32,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.android.compose.PlatformButton
import com.android.compose.PlatformOutlinedButton
+import com.android.compose.theme.PlatformTheme
import com.android.internal.annotations.VisibleForTesting
import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.animation.DialogCuj
@@ -74,7 +77,7 @@ constructor(
currentDialog?.dismiss()
}
- currentDialog = sysuiDialogFactory.create() { ModesDialogContent(it) }
+ currentDialog = sysuiDialogFactory.create { ModesDialogContent(it) }
currentDialog
?.lifecycle
?.addObserver(
@@ -91,28 +94,34 @@ constructor(
@Composable
private fun ModesDialogContent(dialog: SystemUIDialog) {
- AlertDialogContent(
- modifier = Modifier.semantics {
- testTagsAsResourceId = true
- },
- title = {
- Text(
- modifier = Modifier.testTag("modes_title"),
- text = stringResource(R.string.zen_modes_dialog_title)
- )
- },
- content = { ModeTileGrid(viewModel.get()) },
- neutralButton = {
- PlatformOutlinedButton(onClick = { openSettings(dialog) }) {
- Text(stringResource(R.string.zen_modes_dialog_settings))
- }
- },
- positiveButton = {
- PlatformButton(onClick = { dialog.dismiss() }) {
- Text(stringResource(R.string.zen_modes_dialog_done))
- }
- },
- )
+ // TODO(b/369376884): The composable does correctly update when the theme changes
+ // while the dialog is open, but the background (which we don't control here)
+ // doesn't, which causes us to show things like white text on a white background.
+ // as a workaround, we remember the original theme and keep it on recomposition.
+ val isCurrentlyInDarkTheme = isSystemInDarkTheme()
+ val cachedDarkTheme = remember { isCurrentlyInDarkTheme }
+ PlatformTheme(isDarkTheme = cachedDarkTheme) {
+ AlertDialogContent(
+ modifier = Modifier.semantics { testTagsAsResourceId = true },
+ title = {
+ Text(
+ modifier = Modifier.testTag("modes_title"),
+ text = stringResource(R.string.zen_modes_dialog_title),
+ )
+ },
+ content = { ModeTileGrid(viewModel.get()) },
+ neutralButton = {
+ PlatformOutlinedButton(onClick = { openSettings(dialog) }) {
+ Text(stringResource(R.string.zen_modes_dialog_settings))
+ }
+ },
+ positiveButton = {
+ PlatformButton(onClick = { dialog.dismiss() }) {
+ Text(stringResource(R.string.zen_modes_dialog_done))
+ }
+ },
+ )
+ }
}
@VisibleForTesting
@@ -129,7 +138,7 @@ constructor(
activityStarter.startActivity(
ZEN_MODE_SETTINGS_INTENT,
true /* dismissShade */,
- animationController
+ animationController,
)
}
@@ -163,7 +172,7 @@ constructor(
Log.w(
TAG,
"Cannot launch from dialog, the dialog is not present. " +
- "Will launch activity without animating."
+ "Will launch activity without animating.",
)
}
@@ -172,11 +181,7 @@ constructor(
if (animationController == null) {
currentDialog?.dismiss()
}
- activityStarter.startActivity(
- intent,
- true, /* dismissShade */
- animationController,
- )
+ activityStarter.startActivity(intent, true, /* dismissShade */ animationController)
}
companion object {
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt
index d03b2e717398..e1f7bd59005c 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt
@@ -29,6 +29,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.theme.PlatformTheme
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext
+import com.android.systemui.inputdevice.tutorial.KeyboardTouchpadTutorialMetricsLogger
import com.android.systemui.touchpad.tutorial.ui.composable.BackGestureTutorialScreen
import com.android.systemui.touchpad.tutorial.ui.composable.HomeGestureTutorialScreen
import com.android.systemui.touchpad.tutorial.ui.composable.RecentAppsGestureTutorialScreen
@@ -45,6 +46,7 @@ class TouchpadTutorialActivity
constructor(
private val viewModelFactory: TouchpadTutorialViewModel.Factory,
private val logger: InputDeviceTutorialLogger,
+ private val metricsLogger: KeyboardTouchpadTutorialMetricsLogger,
) : ComponentActivity() {
private val vm by viewModels<TouchpadTutorialViewModel>(factoryProducer = { viewModelFactory })
@@ -57,6 +59,7 @@ constructor(
}
// required to handle 3+ fingers on touchpad
window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
+ metricsLogger.logPeripheralTutorialLaunchedFromSettings()
logger.logOpenTutorial(TutorialContext.TOUCHPAD_TUTORIAL)
}
@@ -85,7 +88,7 @@ fun TouchpadTutorialScreen(vm: TouchpadTutorialViewModel, closeTutorial: () -> U
onBackTutorialClicked = { vm.goTo(BACK_GESTURE) },
onHomeTutorialClicked = { vm.goTo(HOME_GESTURE) },
onRecentAppsTutorialClicked = { vm.goTo(RECENT_APPS_GESTURE) },
- onDoneButtonClicked = closeTutorial
+ onDoneButtonClicked = closeTutorial,
)
BACK_GESTURE ->
BackGestureTutorialScreen(
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepositoryTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepositoryTest.java
index 24f3a29e64ee..24f3a29e64ee 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepositoryTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepositoryTest.java
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java b/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java
index aa8c6b7a8a5f..e160ff17a6ed 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.content.res.Configuration;
@@ -643,6 +644,46 @@ public class TouchMonitorTest extends SysuiTestCase {
environment.verifyInputSessionDispose();
}
+ @Test
+ public void testSessionPopAfterDestroy() {
+ final TouchHandler touchHandler = createTouchHandler();
+
+ final Environment environment = new Environment(Stream.of(touchHandler)
+ .collect(Collectors.toCollection(HashSet::new)), mKosmos);
+
+ final InputEvent initialEvent = Mockito.mock(InputEvent.class);
+ environment.publishInputEvent(initialEvent);
+
+ // Ensure session started
+ final InputChannelCompat.InputEventListener eventListener =
+ registerInputEventListener(touchHandler);
+
+ // First event will be missed since we register after the execution loop,
+ final InputEvent event = Mockito.mock(InputEvent.class);
+ environment.publishInputEvent(event);
+ verify(eventListener).onInputEvent(eq(event));
+
+ final ArgumentCaptor<TouchHandler.TouchSession> touchSessionArgumentCaptor =
+ ArgumentCaptor.forClass(TouchHandler.TouchSession.class);
+
+ verify(touchHandler).onSessionStart(touchSessionArgumentCaptor.capture());
+
+ environment.updateLifecycle(Lifecycle.State.DESTROYED);
+
+ // Check to make sure the input session is now disposed.
+ environment.verifyInputSessionDispose();
+
+ clearInvocations(environment.mInputFactory);
+
+ // Pop the session
+ touchSessionArgumentCaptor.getValue().pop();
+
+ environment.executeAll();
+
+ // Ensure no input sessions were created due to the session reset.
+ verifyNoMoreInteractions(environment.mInputFactory);
+ }
+
@Test
public void testPilfering() {
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/authentication/data/repository/AuthenticationRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/authentication/data/repository/AuthenticationRepositoryTest.kt
index 72163e4d7710..72163e4d7710 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/authentication/data/repository/AuthenticationRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/authentication/data/repository/AuthenticationRepositoryTest.kt
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt
index e2a6a5508992..e2a6a5508992 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
index b0810a9edf6b..6608542980b0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
@@ -100,6 +100,7 @@ import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FakeFeatureFlags;
import com.android.systemui.flags.SystemPropertiesHelper;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
+import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionBootInteractor;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.log.SessionTracker;
import com.android.systemui.navigationbar.NavigationModeController;
@@ -199,6 +200,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
private @Mock ShadeWindowLogger mShadeWindowLogger;
private @Mock SelectedUserInteractor mSelectedUserInteractor;
private @Mock KeyguardInteractor mKeyguardInteractor;
+ private @Mock KeyguardTransitionBootInteractor mKeyguardTransitionBootInteractor;
private @Captor ArgumentCaptor<KeyguardStateController.Callback>
mKeyguardStateControllerCallback;
private @Captor ArgumentCaptor<KeyguardUpdateMonitorCallback>
@@ -1294,6 +1296,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
() -> mock(WindowManagerLockscreenVisibilityManager.class),
mSelectedUserInteractor,
mKeyguardInteractor,
+ mKeyguardTransitionBootInteractor,
mock(WindowManagerOcclusionManager.class));
mViewMediator.start();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/scenetransition/LockscreenSceneTransitionInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/scenetransition/LockscreenSceneTransitionInteractorTest.kt
index 8a5af09f52ed..ad5eeabf83d2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/scenetransition/LockscreenSceneTransitionInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/scenetransition/LockscreenSceneTransitionInteractorTest.kt
@@ -65,7 +65,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
private val goneToLs =
@@ -75,7 +75,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
@Before
@@ -84,7 +84,8 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
kosmos.sceneContainerRepository.setTransitionState(sceneTransitions)
testScope.launch {
kosmos.realKeyguardTransitionRepository.emitInitialStepsFromOff(
- KeyguardState.LOCKSCREEN
+ KeyguardState.LOCKSCREEN,
+ testSetup = true,
)
}
}
@@ -105,11 +106,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
sceneTransitions.value = ObservableTransitionState.Idle(Scenes.Gone)
assertTransition(
@@ -142,11 +139,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
sceneTransitions.value = ObservableTransitionState.Idle(Scenes.Lockscreen)
@@ -191,7 +184,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
sceneTransitions.value = lsToGone
@@ -205,11 +198,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
sceneTransitions.value = ObservableTransitionState.Idle(Scenes.Lockscreen)
@@ -257,11 +246,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
sceneTransitions.value = ObservableTransitionState.Idle(Scenes.Lockscreen)
@@ -297,7 +282,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -330,11 +315,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
sceneTransitions.value = ObservableTransitionState.Idle(Scenes.Gone)
val stepM3 = allSteps[allSteps.size - 3]
@@ -393,7 +374,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -466,7 +447,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -523,7 +504,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -577,11 +558,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
kosmos.realKeyguardTransitionRepository.startTransition(
TransitionInfo(
@@ -589,7 +566,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -641,11 +618,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
kosmos.realKeyguardTransitionRepository.startTransition(
TransitionInfo(
@@ -653,7 +626,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -702,11 +675,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
)
progress.value = 0.4f
- assertTransition(
- step = currentStep!!,
- state = TransitionState.RUNNING,
- progress = 0.4f,
- )
+ assertTransition(step = currentStep!!, state = TransitionState.RUNNING, progress = 0.4f)
kosmos.realKeyguardTransitionRepository.startTransition(
TransitionInfo(
@@ -714,7 +683,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -736,7 +705,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -777,7 +746,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -799,7 +768,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
allSteps[allSteps.size - 3]
@@ -858,7 +827,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -880,7 +849,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -959,7 +928,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -977,7 +946,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.AOD,
to = KeyguardState.DOZING,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -995,7 +964,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.DOZING,
to = KeyguardState.OCCLUDED,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -1017,7 +986,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -1077,7 +1046,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.AOD,
animator = null,
- modeOnCanceled = TransitionModeOnCanceled.RESET
+ modeOnCanceled = TransitionModeOnCanceled.RESET,
)
)
@@ -1092,7 +1061,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
kosmos.realKeyguardTransitionRepository.updateTransition(
ktfUuid!!,
1f,
- TransitionState.FINISHED
+ TransitionState.FINISHED,
)
assertTransition(
@@ -1110,7 +1079,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -1171,7 +1140,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -1235,7 +1204,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -1291,7 +1260,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
flowOf(Scenes.Lockscreen),
progress,
false,
- flowOf(false)
+ flowOf(false),
)
assertTransition(
@@ -1308,7 +1277,7 @@ class LockscreenSceneTransitionInteractorTest : SysuiTestCase() {
from: KeyguardState? = null,
to: KeyguardState? = null,
state: TransitionState? = null,
- progress: Float? = null
+ progress: Float? = null,
) {
if (from != null) assertThat(step.from).isEqualTo(from)
if (to != null) assertThat(step.to).isEqualTo(to)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListenerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListenerTest.kt
index 680df1584f89..dcf32a5f574d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListenerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaTimeoutListenerTest.kt
@@ -137,7 +137,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
MediaTestUtils.emptyMediaData.copy(
app = PACKAGE,
packageName = PACKAGE,
- token = session.sessionToken
+ token = session.sessionToken,
)
resumeData = mediaData.copy(token = null, active = false, resumption = true)
@@ -237,7 +237,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
// Assuming we're registered
testOnMediaDataLoaded_registersPlaybackListener()
- mediaCallbackCaptor.value.onPlaybackStateChanged(
+ onPlaybackStateChanged(
PlaybackState.Builder().setState(PlaybackState.STATE_PAUSED, 0L, 0f).build()
)
assertThat(mainExecutor.numPending()).isEqualTo(1)
@@ -249,7 +249,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
// Assuming we have a pending timeout
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()
- mediaCallbackCaptor.value.onPlaybackStateChanged(
+ onPlaybackStateChanged(
PlaybackState.Builder().setState(PlaybackState.STATE_PLAYING, 0L, 0f).build()
)
assertThat(mainExecutor.numPending()).isEqualTo(0)
@@ -261,7 +261,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
// Assuming we have a pending timeout
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()
- mediaCallbackCaptor.value.onPlaybackStateChanged(
+ onPlaybackStateChanged(
PlaybackState.Builder().setState(PlaybackState.STATE_STOPPED, 0L, 0f).build()
)
assertThat(mainExecutor.numPending()).isEqualTo(1)
@@ -435,7 +435,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
// When the playback state changes, and has different actions
val playingState = PlaybackState.Builder().setActions(PlaybackState.ACTION_PLAY).build()
- mediaCallbackCaptor.value.onPlaybackStateChanged(playingState)
+ onPlaybackStateChanged(playingState)
assertThat(uiExecutor.runAllReady()).isEqualTo(1)
// Then the callback is invoked
@@ -448,7 +448,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
PlaybackState.CustomAction.Builder(
"ACTION_1",
"custom action 1",
- android.R.drawable.ic_media_ff
+ android.R.drawable.ic_media_ff,
)
.build()
val pausedState =
@@ -463,7 +463,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
PlaybackState.CustomAction.Builder(
"ACTION_2",
"custom action 2",
- android.R.drawable.ic_media_rew
+ android.R.drawable.ic_media_rew,
)
.build()
val pausedStateTwoActions =
@@ -472,7 +472,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
.addCustomAction(customOne)
.addCustomAction(customTwo)
.build()
- mediaCallbackCaptor.value.onPlaybackStateChanged(pausedStateTwoActions)
+ onPlaybackStateChanged(pausedStateTwoActions)
assertThat(uiExecutor.runAllReady()).isEqualTo(1)
// Then the callback is invoked
@@ -485,7 +485,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
loadMediaDataWithPlaybackState(stateWithActions)
// When the playback state updates with the same actions
- mediaCallbackCaptor.value.onPlaybackStateChanged(stateWithActions)
+ onPlaybackStateChanged(stateWithActions)
// Then the callback is not invoked again
verify(stateCallback, never()).invoke(eq(KEY), any())
@@ -512,7 +512,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
.setActions(PlaybackState.ACTION_PAUSE)
.addCustomAction(customTwo)
.build()
- mediaCallbackCaptor.value.onPlaybackStateChanged(stateTwo)
+ onPlaybackStateChanged(stateTwo)
// Then the callback is not invoked
verify(stateCallback, never()).invoke(eq(KEY), any())
@@ -544,7 +544,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
// When the playback state changes to playing
val playingState =
PlaybackState.Builder().setState(PlaybackState.STATE_PLAYING, 0L, 1f).build()
- mediaCallbackCaptor.value.onPlaybackStateChanged(playingState)
+ onPlaybackStateChanged(playingState)
uiExecutor.runAllReady()
// Then the callback is invoked
@@ -561,7 +561,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
// When the playback state is updated, but still not playing
val playingState =
PlaybackState.Builder().setState(PlaybackState.STATE_STOPPED, 0L, 0f).build()
- mediaCallbackCaptor.value.onPlaybackStateChanged(playingState)
+ onPlaybackStateChanged(playingState)
// Then the callback is not invoked
verify(stateCallback, never()).invoke(eq(KEY), eq(playingState!!))
@@ -571,7 +571,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
fun testTimeoutCallback_dozedPastTimeout_invokedOnWakeup() {
// When paused media is loaded
testOnMediaDataLoaded_registersPlaybackListener()
- mediaCallbackCaptor.value.onPlaybackStateChanged(
+ onPlaybackStateChanged(
PlaybackState.Builder().setState(PlaybackState.STATE_PAUSED, 0L, 0f).build()
)
verify(statusBarStateController).addCallback(capture(dozingCallbackCaptor))
@@ -597,7 +597,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
val time = clock.currentTimeMillis()
clock.setElapsedRealtime(time)
testOnMediaDataLoaded_registersPlaybackListener()
- mediaCallbackCaptor.value.onPlaybackStateChanged(
+ onPlaybackStateChanged(
PlaybackState.Builder().setState(PlaybackState.STATE_PAUSED, 0L, 0f).build()
)
verify(statusBarStateController).addCallback(capture(dozingCallbackCaptor))
@@ -706,4 +706,9 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
bgExecutor.runAllReady()
uiExecutor.runAllReady()
}
+
+ private fun onPlaybackStateChanged(state: PlaybackState) {
+ mediaCallbackCaptor.value.onPlaybackStateChanged(state)
+ bgExecutor.runAllReady()
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt
index 03667cfb8a3b..570c64065c4a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt
@@ -21,19 +21,19 @@ import android.content.res.ColorStateList
import android.content.res.Configuration
import android.database.ContentObserver
import android.os.LocaleList
+import android.platform.test.flag.junit.FlagsParameterization
import android.provider.Settings
import android.testing.TestableLooper
import android.util.MathUtils.abs
import android.view.View
-import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.SceneKey
import com.android.internal.logging.InstanceId
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
+import com.android.systemui.Flags.mediaControlsUmoInflationInBackground
import com.android.systemui.SysuiTestCase
-import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor
import com.android.systemui.dump.DumpManager
import com.android.systemui.flags.DisableSceneContainer
@@ -71,7 +71,6 @@ import com.android.systemui.statusbar.notification.collection.provider.OnReorder
import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.testKosmos
-import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.unconfinedDispatcherFakeSettings
@@ -106,6 +105,8 @@ import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.capture
import org.mockito.kotlin.eq
+import platform.test.runner.parameterized.ParameterizedAndroidJunit4
+import platform.test.runner.parameterized.Parameters
private val DATA = MediaTestUtils.emptyMediaData
@@ -116,8 +117,8 @@ private const val PLAYING_LOCAL = "playing local"
@ExperimentalCoroutinesApi
@SmallTest
@TestableLooper.RunWithLooper(setAsMainLooper = true)
-@RunWith(AndroidJUnit4::class)
-class MediaCarouselControllerTest : SysuiTestCase() {
+@RunWith(ParameterizedAndroidJunit4::class)
+class MediaCarouselControllerTest(flags: FlagsParameterization) : SysuiTestCase() {
private val kosmos = testKosmos()
private val testDispatcher = kosmos.unconfinedTestDispatcher
private val secureSettings = kosmos.unconfinedDispatcherFakeSettings
@@ -129,7 +130,6 @@ class MediaCarouselControllerTest : SysuiTestCase() {
@Mock lateinit var mediaHostStatesManager: MediaHostStatesManager
@Mock lateinit var mediaHostState: MediaHostState
@Mock lateinit var activityStarter: ActivityStarter
- @Mock @Main private lateinit var executor: DelayableExecutor
@Mock lateinit var mediaDataManager: MediaDataManager
@Mock lateinit var configurationController: ConfigurationController
@Mock lateinit var falsingManager: FalsingManager
@@ -153,16 +153,33 @@ class MediaCarouselControllerTest : SysuiTestCase() {
private val clock = FakeSystemClock()
private lateinit var bgExecutor: FakeExecutor
+ private lateinit var uiExecutor: FakeExecutor
private lateinit var mediaCarouselController: MediaCarouselController
private var originalResumeSetting =
Settings.Secure.getInt(context.contentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 1)
+ companion object {
+ @JvmStatic
+ @Parameters(name = "{0}")
+ fun getParams(): List<FlagsParameterization> {
+ return FlagsParameterization.progressionOf(
+ com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_UMO_INFLATION_IN_BACKGROUND
+ )
+ }
+ }
+
+ init {
+ mSetFlagsRule.setFlagsParameterization(flags)
+ }
+
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
context.resources.configuration.setLocales(LocaleList(Locale.US, Locale.UK))
bgExecutor = FakeExecutor(clock)
+ uiExecutor = FakeExecutor(clock)
+
mediaCarouselController =
MediaCarouselController(
applicationScope = kosmos.applicationCoroutineScope,
@@ -173,7 +190,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
activityStarter = activityStarter,
systemClock = clock,
mainDispatcher = kosmos.testDispatcher,
- executor = executor,
+ uiExecutor = uiExecutor,
bgExecutor = bgExecutor,
backgroundDispatcher = testDispatcher,
mediaManager = mediaDataManager,
@@ -201,10 +218,11 @@ class MediaCarouselControllerTest : SysuiTestCase() {
whenever(mediaFlags.isPersistentSsCardEnabled()).thenReturn(false)
MediaPlayerData.clear()
FakeExecutor.exhaustExecutors(bgExecutor)
+ FakeExecutor.exhaustExecutors(uiExecutor)
verify(globalSettings)
.registerContentObserverSync(
eq(Settings.Global.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE)),
- capture(settingsObserverCaptor)
+ capture(settingsObserverCaptor),
)
}
@@ -213,7 +231,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
Settings.Secure.putInt(
context.contentResolver,
Settings.Secure.MEDIA_CONTROLS_RESUME,
- originalResumeSetting
+ originalResumeSetting,
)
}
@@ -227,9 +245,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
+ resumption = false,
),
- 4500L
+ 4500L,
)
val playingCast =
@@ -239,9 +257,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_CAST_LOCAL,
- resumption = false
+ resumption = false,
),
- 5000L
+ 5000L,
)
val pausedLocal =
@@ -251,9 +269,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
+ resumption = false,
),
- 1000L
+ 1000L,
)
val pausedCast =
@@ -263,9 +281,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_CAST_LOCAL,
- resumption = false
+ resumption = false,
),
- 2000L
+ 2000L,
)
val playingRcn =
@@ -275,9 +293,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_CAST_REMOTE,
- resumption = false
+ resumption = false,
),
- 5000L
+ 5000L,
)
val pausedRcn =
@@ -287,9 +305,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_CAST_REMOTE,
- resumption = false
+ resumption = false,
),
- 5000L
+ 5000L,
)
val active =
@@ -299,9 +317,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = true
+ resumption = true,
),
- 250L
+ 250L,
)
val resume1 =
@@ -311,9 +329,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = false,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = true
+ resumption = true,
),
- 500L
+ 500L,
)
val resume2 =
@@ -323,9 +341,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = false,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = true
+ resumption = true,
),
- 1000L
+ 1000L,
)
val activeMoreRecent =
@@ -336,9 +354,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
resumption = true,
- lastActive = 2L
+ lastActive = 2L,
),
- 1000L
+ 1000L,
)
val activeLessRecent =
@@ -349,9 +367,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
resumption = true,
- lastActive = 1L
+ lastActive = 1L,
),
- 1000L
+ 1000L,
)
// Expected ordering for media players:
// Actively playing local sessions
@@ -370,7 +388,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
pausedRcn,
active,
resume2,
- resume1
+ resume1,
)
expected.forEach {
@@ -380,7 +398,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
it.second.copy(notificationKey = it.first),
panel,
clock,
- isSsReactivated = false
+ isSsReactivated = false,
)
}
@@ -403,7 +421,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
EMPTY_SMARTSPACE_MEDIA_DATA.copy(isActive = true),
panel,
true,
- clock
+ clock,
)
// Then it should be shown immediately after any actively playing controls
@@ -421,7 +439,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
listener.value.onSmartspaceMediaDataLoaded(
SMARTSPACE_KEY,
EMPTY_SMARTSPACE_MEDIA_DATA.copy(isActive = true),
- true
+ true,
)
// Then it should be shown immediately after any actively playing controls
@@ -439,7 +457,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
EMPTY_SMARTSPACE_MEDIA_DATA.copy(isActive = true),
panel,
false,
- clock
+ clock,
)
// Then it should be shown at the end of the carousel's active entries
@@ -461,8 +479,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
listener.value.onMediaDataLoaded(
PLAYING_LOCAL,
@@ -471,19 +489,20 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = true
- )
+ resumption = true,
+ ),
)
+ runAllReady()
assertEquals(
MediaPlayerData.getMediaPlayerIndex(PAUSED_LOCAL),
- mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
+ mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex,
)
// paused player order should stays the same in visibleMediaPLayer map.
// paused player order should be first in mediaPlayer map.
assertEquals(
MediaPlayerData.visiblePlayerKeys().elementAt(3),
- MediaPlayerData.playerKeys().elementAt(0)
+ MediaPlayerData.playerKeys().elementAt(0),
)
}
@@ -506,7 +525,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
mediaCarouselController.onDesiredLocationChanged(
LOCATION_QS,
mediaHostState,
- animate = false
+ animate = false,
)
bgExecutor.runAllReady()
verify(logger).logCarouselPosition(LOCATION_QS)
@@ -517,7 +536,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
mediaCarouselController.onDesiredLocationChanged(
MediaHierarchyManager.LOCATION_QQS,
mediaHostState,
- animate = false
+ animate = false,
)
bgExecutor.runAllReady()
verify(logger).logCarouselPosition(MediaHierarchyManager.LOCATION_QQS)
@@ -528,7 +547,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
mediaCarouselController.onDesiredLocationChanged(
MediaHierarchyManager.LOCATION_LOCKSCREEN,
mediaHostState,
- animate = false
+ animate = false,
)
bgExecutor.runAllReady()
verify(logger).logCarouselPosition(MediaHierarchyManager.LOCATION_LOCKSCREEN)
@@ -539,7 +558,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
mediaCarouselController.onDesiredLocationChanged(
MediaHierarchyManager.LOCATION_DREAM_OVERLAY,
mediaHostState,
- animate = false
+ animate = false,
)
bgExecutor.runAllReady()
verify(logger).logCarouselPosition(MediaHierarchyManager.LOCATION_DREAM_OVERLAY)
@@ -570,8 +589,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
listener.value.onMediaDataLoaded(
PAUSED_LOCAL,
@@ -580,14 +599,15 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
+ runAllReady()
// adding a media recommendation card.
listener.value.onSmartspaceMediaDataLoaded(
SMARTSPACE_KEY,
EMPTY_SMARTSPACE_MEDIA_DATA,
- false
+ false,
)
mediaCarouselController.shouldScrollToKey = true
// switching between media players.
@@ -598,8 +618,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = true
- )
+ resumption = true,
+ ),
)
listener.value.onMediaDataLoaded(
PAUSED_LOCAL,
@@ -608,13 +628,14 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
+ runAllReady()
assertEquals(
MediaPlayerData.getMediaPlayerIndex(PAUSED_LOCAL),
- mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
+ mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex,
)
}
@@ -626,7 +647,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
listener.value.onSmartspaceMediaDataLoaded(
SMARTSPACE_KEY,
EMPTY_SMARTSPACE_MEDIA_DATA.copy(packageName = "PACKAGE_NAME", isActive = true),
- false
+ false,
)
listener.value.onMediaDataLoaded(
PLAYING_LOCAL,
@@ -635,14 +656,15 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
+ runAllReady()
var playerIndex = MediaPlayerData.getMediaPlayerIndex(PLAYING_LOCAL)
assertEquals(
playerIndex,
- mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
+ mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex,
)
assertEquals(playerIndex, 0)
@@ -657,9 +679,10 @@ class MediaCarouselControllerTest : SysuiTestCase() {
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
resumption = false,
- packageName = "PACKAGE_NAME"
- )
+ packageName = "PACKAGE_NAME",
+ ),
)
+ runAllReady()
playerIndex = MediaPlayerData.getMediaPlayerIndex(PLAYING_LOCAL)
assertEquals(playerIndex, 0)
}
@@ -704,7 +727,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
player1.second.copy(notificationKey = player1.first),
panel,
clock,
- isSsReactivated = false
+ isSsReactivated = false,
)
assertEquals(mediaCarouselController.getCurrentVisibleMediaContentIntent(), clickIntent1)
@@ -717,7 +740,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
player2.second.copy(notificationKey = player2.first),
panel,
clock,
- isSsReactivated = false
+ isSsReactivated = false,
)
// mediaCarouselScrollHandler.visibleMediaIndex is unchanged (= 0), and the new player is
@@ -732,7 +755,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
player3.second.copy(notificationKey = player3.first),
panel,
clock,
- isSsReactivated = false
+ isSsReactivated = false,
)
// mediaCarouselScrollHandler.visibleMediaIndex is unchanged (= 0), and the new player is
@@ -822,7 +845,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
listener.value.onSmartspaceMediaDataLoaded(
SMARTSPACE_KEY,
EMPTY_SMARTSPACE_MEDIA_DATA.copy(isActive = true),
- true
+ true,
)
// Then the carousel is updated
@@ -841,7 +864,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
listener.value.onSmartspaceMediaDataLoaded(
SMARTSPACE_KEY,
EMPTY_SMARTSPACE_MEDIA_DATA,
- false
+ false,
)
// Then it is added to the carousel with correct state
@@ -886,7 +909,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
transitionRepository.sendTransitionSteps(
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.GONE,
- this
+ this,
)
verify(mediaCarousel).visibility = View.VISIBLE
@@ -932,7 +955,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
transitionRepository.sendTransitionSteps(
from = KeyguardState.GONE,
to = KeyguardState.LOCKSCREEN,
- this
+ this,
)
assertEquals(true, updatedVisibility)
@@ -961,7 +984,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
transitionRepository.sendTransitionSteps(
from = KeyguardState.GONE,
to = KeyguardState.LOCKSCREEN,
- this
+ this,
)
assertEquals(true, updatedVisibility)
@@ -1125,12 +1148,14 @@ class MediaCarouselControllerTest : SysuiTestCase() {
Settings.Secure.putInt(context.contentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 0)
val pausedMedia = DATA.copy(isPlaying = false)
listener.value.onMediaDataLoaded(PAUSED_LOCAL, PAUSED_LOCAL, pausedMedia)
+ runAllReady()
mediaCarouselController.onSwipeToDismiss()
// When it can be removed immediately on update
whenever(visualStabilityProvider.isReorderingAllowed).thenReturn(true)
val inactiveMedia = pausedMedia.copy(active = false)
listener.value.onMediaDataLoaded(PAUSED_LOCAL, PAUSED_LOCAL, inactiveMedia)
+ runAllReady()
// This is processed as a user-initiated dismissal
verify(debugLogger).logMediaRemoved(eq(PAUSED_LOCAL), eq(true))
@@ -1148,12 +1173,14 @@ class MediaCarouselControllerTest : SysuiTestCase() {
val pausedMedia = DATA.copy(isPlaying = false)
listener.value.onMediaDataLoaded(PAUSED_LOCAL, PAUSED_LOCAL, pausedMedia)
+ runAllReady()
mediaCarouselController.onSwipeToDismiss()
// When it can't be removed immediately on update
whenever(visualStabilityProvider.isReorderingAllowed).thenReturn(false)
val inactiveMedia = pausedMedia.copy(active = false)
listener.value.onMediaDataLoaded(PAUSED_LOCAL, PAUSED_LOCAL, inactiveMedia)
+ runAllReady()
visualStabilityCallback.value.onReorderingAllowed()
// This is processed as a user-initiated dismissal
@@ -1175,8 +1202,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
listener.value.onMediaDataLoaded(
PAUSED_LOCAL,
@@ -1185,18 +1212,20 @@ class MediaCarouselControllerTest : SysuiTestCase() {
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
- resumption = false
- )
+ resumption = false,
+ ),
)
+ runAllReady()
val playersSize = MediaPlayerData.players().size
reset(pageIndicator)
function()
+ runAllReady()
assertEquals(playersSize, MediaPlayerData.players().size)
assertEquals(
MediaPlayerData.getMediaPlayerIndex(PLAYING_LOCAL),
- mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
+ mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex,
)
}
@@ -1225,4 +1254,11 @@ class MediaCarouselControllerTest : SysuiTestCase() {
)
runCurrent()
}
+
+ private fun runAllReady() {
+ if (mediaControlsUmoInflationInBackground()) {
+ bgExecutor.runAllReady()
+ uiExecutor.runAllReady()
+ }
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java
index eea02eec7099..2f8f45cb0197 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -887,6 +888,34 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
}
@Test
+ public void getActiveAutoSwitchNonDdsSubId_registerCallbackForExistedSubId_notRegister() {
+ mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true);
+
+ // Adds non DDS subId
+ SubscriptionInfo info = mock(SubscriptionInfo.class);
+ doReturn(SUB_ID2).when(info).getSubscriptionId();
+ doReturn(false).when(info).isOpportunistic();
+ when(mSubscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(info);
+
+ mInternetDialogController.getActiveAutoSwitchNonDdsSubId();
+
+ // 1st time is onStart(), 2nd time is getActiveAutoSwitchNonDdsSubId()
+ verify(mTelephonyManager, times(2)).registerTelephonyCallback(any(), any());
+ assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.size() == 2);
+
+ // Adds non DDS subId again
+ doReturn(SUB_ID2).when(info).getSubscriptionId();
+ doReturn(false).when(info).isOpportunistic();
+ when(mSubscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(info);
+
+ mInternetDialogController.getActiveAutoSwitchNonDdsSubId();
+
+ // Does not add due to cached subInfo in mSubIdTelephonyCallbackMap.
+ verify(mTelephonyManager, times(2)).registerTelephonyCallback(any(), any());
+ assertThat(mInternetDialogController.mSubIdTelephonyCallbackMap.size() == 2);
+ }
+
+ @Test
public void getMobileNetworkSummary() {
mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true);
Resources res1 = mock(Resources.class);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt
index a1750cdd0c84..b1ec740c5564 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt
@@ -21,6 +21,7 @@ import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
+import com.android.compose.animation.scene.OverlayKey
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.coroutines.collectLastValue
@@ -28,6 +29,7 @@ import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.kosmos.testScope
+import com.android.systemui.scene.data.repository.setSceneTransition
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
@@ -38,9 +40,9 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
-import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -55,14 +57,9 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
private val configurationRepository = kosmos.fakeConfigurationRepository
private val keyguardRepository = kosmos.fakeKeyguardRepository
private val sceneInteractor = kosmos.sceneInteractor
- private val shadeTestUtil = kosmos.shadeTestUtil
+ private val shadeTestUtil by lazy { kosmos.shadeTestUtil }
- private lateinit var underTest: ShadeInteractorSceneContainerImpl
-
- @Before
- fun setUp() {
- underTest = kosmos.shadeInteractorSceneContainerImpl
- }
+ private val underTest by lazy { kosmos.shadeInteractorSceneContainerImpl }
@Test
fun qsExpansionWhenInSplitShadeAndQsExpanded() =
@@ -600,14 +597,14 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
@Test
@EnableFlags(DualShade.FLAG_NAME)
- fun expandNotificationShade_dualShadeEnabled_opensOverlay() =
+ fun expandNotificationsShade_dualShade_opensOverlay() =
testScope.runTest {
val currentScene by collectLastValue(sceneInteractor.currentScene)
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).isEmpty()
- underTest.expandNotificationShade("reason")
+ underTest.expandNotificationsShade("reason")
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).containsExactly(Overlays.NotificationsShade)
@@ -615,14 +612,15 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
@Test
@DisableFlags(DualShade.FLAG_NAME)
- fun expandNotificationShade_dualShadeDisabled_switchesToShadeScene() =
+ fun expandNotificationsShade_singleShade_switchesToShadeScene() =
testScope.runTest {
+ shadeTestUtil.setSplitShade(false)
val currentScene by collectLastValue(sceneInteractor.currentScene)
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).isEmpty()
- underTest.expandNotificationShade("reason")
+ underTest.expandNotificationsShade("reason")
assertThat(currentScene).isEqualTo(Scenes.Shade)
assertThat(currentOverlays).isEmpty()
@@ -630,7 +628,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
@Test
@EnableFlags(DualShade.FLAG_NAME)
- fun expandNotificationShade_dualShadeEnabledAndQuickSettingsOpen_replacesOverlay() =
+ fun expandNotificationsShade_dualShadeQuickSettingsOpen_replacesOverlay() =
testScope.runTest {
val currentScene by collectLastValue(sceneInteractor.currentScene)
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
@@ -638,14 +636,14 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).containsExactly(Overlays.QuickSettingsShade)
- underTest.expandNotificationShade("reason")
+ underTest.expandNotificationsShade("reason")
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).containsExactly(Overlays.NotificationsShade)
}
@Test
@EnableFlags(DualShade.FLAG_NAME)
- fun expandQuickSettingsShade_dualShadeEnabled_opensOverlay() =
+ fun expandQuickSettingsShade_dualShade_opensOverlay() =
testScope.runTest {
val currentScene by collectLastValue(sceneInteractor.currentScene)
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
@@ -660,8 +658,9 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
@Test
@DisableFlags(DualShade.FLAG_NAME)
- fun expandQuickSettingsShade_dualShadeDisabled_switchesToQuickSettingsScene() =
+ fun expandQuickSettingsShade_singleShade_switchesToQuickSettingsScene() =
testScope.runTest {
+ shadeTestUtil.setSplitShade(false)
val currentScene by collectLastValue(sceneInteractor.currentScene)
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
@@ -674,12 +673,28 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
}
@Test
+ @DisableFlags(DualShade.FLAG_NAME)
+ fun expandQuickSettingsShade_splitShade_switchesToShadeScene() =
+ testScope.runTest {
+ shadeTestUtil.setSplitShade(true)
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+
+ underTest.expandQuickSettingsShade("reason")
+
+ assertThat(currentScene).isEqualTo(Scenes.Shade)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
@EnableFlags(DualShade.FLAG_NAME)
- fun expandQuickSettingsShade_dualShadeEnabledAndNotificationsOpen_replacesOverlay() =
+ fun expandQuickSettingsShade_dualShadeNotificationsOpen_replacesOverlay() =
testScope.runTest {
val currentScene by collectLastValue(sceneInteractor.currentScene)
val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
- underTest.expandNotificationShade("reason")
+ underTest.expandNotificationsShade("reason")
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).containsExactly(Overlays.NotificationsShade)
@@ -687,4 +702,141 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
assertThat(currentOverlays).containsExactly(Overlays.QuickSettingsShade)
}
+
+ @Test
+ @EnableFlags(DualShade.FLAG_NAME)
+ fun collapseNotificationsShade_dualShade_hidesOverlay() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ openShade(Overlays.NotificationsShade)
+
+ underTest.collapseNotificationsShade("reason")
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @DisableFlags(DualShade.FLAG_NAME)
+ fun collapseNotificationsShade_singleShade_switchesToLockscreen() =
+ testScope.runTest {
+ shadeTestUtil.setSplitShade(false)
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ sceneInteractor.changeScene(Scenes.Shade, "reason")
+ assertThat(currentScene).isEqualTo(Scenes.Shade)
+ assertThat(currentOverlays).isEmpty()
+
+ underTest.collapseNotificationsShade("reason")
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @EnableFlags(DualShade.FLAG_NAME)
+ fun collapseQuickSettingsShade_dualShade_hidesOverlay() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ openShade(Overlays.QuickSettingsShade)
+
+ underTest.collapseQuickSettingsShade("reason")
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @DisableFlags(DualShade.FLAG_NAME)
+ fun collapseQuickSettingsShadeNotBypassingShade_singleShade_switchesToShade() =
+ testScope.runTest {
+ shadeTestUtil.setSplitShade(false)
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ sceneInteractor.changeScene(Scenes.QuickSettings, "reason")
+ assertThat(currentScene).isEqualTo(Scenes.QuickSettings)
+ assertThat(currentOverlays).isEmpty()
+
+ underTest.collapseQuickSettingsShade(
+ loggingReason = "reason",
+ bypassNotificationsShade = false,
+ )
+
+ assertThat(currentScene).isEqualTo(Scenes.Shade)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @DisableFlags(DualShade.FLAG_NAME)
+ fun collapseQuickSettingsShadeNotBypassingShade_splitShade_switchesToLockscreen() =
+ testScope.runTest {
+ shadeTestUtil.setSplitShade(true)
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ sceneInteractor.changeScene(Scenes.QuickSettings, "reason")
+ assertThat(currentScene).isEqualTo(Scenes.QuickSettings)
+ assertThat(currentOverlays).isEmpty()
+
+ underTest.collapseQuickSettingsShade(
+ loggingReason = "reason",
+ bypassNotificationsShade = false,
+ )
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @DisableFlags(DualShade.FLAG_NAME)
+ fun collapseQuickSettingsShadeBypassingShade_singleShade_switchesToLockscreen() =
+ testScope.runTest {
+ shadeTestUtil.setSplitShade(false)
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ sceneInteractor.changeScene(Scenes.QuickSettings, "reason")
+ assertThat(currentScene).isEqualTo(Scenes.QuickSettings)
+ assertThat(currentOverlays).isEmpty()
+
+ underTest.collapseQuickSettingsShade(
+ loggingReason = "reason",
+ bypassNotificationsShade = true,
+ )
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ @Test
+ @EnableFlags(DualShade.FLAG_NAME)
+ fun collapseEitherShade_dualShade_hidesBothOverlays() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ openShade(Overlays.QuickSettingsShade)
+ openShade(Overlays.NotificationsShade)
+ assertThat(currentOverlays)
+ .containsExactly(Overlays.QuickSettingsShade, Overlays.NotificationsShade)
+
+ underTest.collapseEitherShade("reason")
+
+ assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
+ assertThat(currentOverlays).isEmpty()
+ }
+
+ private fun TestScope.openShade(overlay: OverlayKey) {
+ val isAnyExpanded by collectLastValue(underTest.isAnyExpanded)
+ val currentScene by collectLastValue(sceneInteractor.currentScene)
+ val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
+ val initialScene = checkNotNull(currentScene)
+ sceneInteractor.showOverlay(overlay, "reason")
+ kosmos.setSceneTransition(
+ ObservableTransitionState.Idle(initialScene, checkNotNull(currentOverlays))
+ )
+ runCurrent()
+ assertThat(currentScene).isEqualTo(initialScene)
+ assertThat(currentOverlays).contains(overlay)
+ assertThat(isAnyExpanded).isTrue()
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt
index 0407fc14d35a..ac7388281a15 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationSectionsFeatureManagerTest.kt
@@ -24,7 +24,7 @@ import androidx.test.filters.SmallTest
import com.android.dx.mockito.inline.extended.ExtendedMockito
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING
import com.android.systemui.SysuiTestCase
-import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
+import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.shared.PriorityPeopleSection
import com.android.systemui.util.DeviceConfigProxyFake
import com.android.systemui.util.Utils
@@ -42,7 +42,7 @@ import org.mockito.quality.Strictness
@RunWith(AndroidJUnit4::class)
@SmallTest
// this class has no testable logic with either of these flags enabled
-@DisableFlags(PriorityPeopleSection.FLAG_NAME, NotificationMinimalismPrototype.FLAG_NAME)
+@DisableFlags(PriorityPeopleSection.FLAG_NAME, NotificationMinimalism.FLAG_NAME)
class NotificationSectionsFeatureManagerTest : SysuiTestCase() {
lateinit var manager: NotificationSectionsFeatureManager
private val proxyFake = DeviceConfigProxyFake()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt
index deb3fc1224ce..a3f845225a99 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt
@@ -15,8 +15,8 @@
*/
package com.android.systemui.statusbar.notification.collection.coordinator
-import android.app.Flags.lifetimeExtensionRefactor
import android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR
+import android.app.Flags.lifetimeExtensionRefactor
import android.app.Notification
import android.app.RemoteInputHistoryItem
import android.os.Handler
@@ -47,10 +47,10 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
-import org.mockito.Mockito.`when`
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
+import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations.initMocks
@SmallTest
@@ -78,21 +78,20 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
@Before
fun setUp() {
initMocks(this)
- coordinator = RemoteInputCoordinator(
+ coordinator =
+ RemoteInputCoordinator(
dumpManager,
rebuilder,
remoteInputManager,
mainHandler,
- smartReplyController
- )
+ smartReplyController,
+ )
`when`(pipeline.addNotificationLifetimeExtender(any())).thenAnswer {
(it.arguments[0] as NotifLifetimeExtender).setCallback(lifetimeExtensionCallback)
}
`when`(pipeline.getInternalNotifUpdater(any())).thenReturn(notifUpdater)
coordinator.attach(pipeline)
- listener = withArgCaptor {
- verify(remoteInputManager).setRemoteInputListener(capture())
- }
+ listener = withArgCaptor { verify(remoteInputManager).setRemoteInputListener(capture()) }
entry1 = NotificationEntryBuilder().setId(1).build()
entry2 = NotificationEntryBuilder().setId(2).build()
`when`(rebuilder.rebuildForCanceledSmartReplies(any())).thenReturn(sbn)
@@ -101,13 +100,17 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
`when`(rebuilder.rebuildWithExistingReplies(any())).thenReturn(sbn)
}
- val remoteInputActiveExtender get() = coordinator.mRemoteInputActiveExtender
- val remoteInputHistoryExtender get() = coordinator.mRemoteInputHistoryExtender
- val smartReplyHistoryExtender get() = coordinator.mSmartReplyHistoryExtender
+ val remoteInputActiveExtender
+ get() = coordinator.mRemoteInputActiveExtender
- val collectionListeners get() = captureMany {
- verify(pipeline, times(1)).addCollectionListener(capture())
- }
+ val remoteInputHistoryExtender
+ get() = coordinator.mRemoteInputHistoryExtender
+
+ val smartReplyHistoryExtender
+ get() = coordinator.mSmartReplyHistoryExtender
+
+ val collectionListeners
+ get() = captureMany { verify(pipeline, times(1)).addCollectionListener(capture()) }
@Test
fun testRemoteInputActive() {
@@ -179,7 +182,8 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
@EnableFlags(FLAG_LIFETIME_EXTENSION_REFACTOR)
fun testRemoteInputLifetimeExtensionListenerTrigger() {
// Create notification with LIFETIME_EXTENDED_BY_DIRECT_REPLY flag.
- val entry = NotificationEntryBuilder()
+ val entry =
+ NotificationEntryBuilder()
.setId(3)
.setTag("entry")
.setFlag(mContext, Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true)
@@ -187,9 +191,7 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
`when`(remoteInputManager.shouldKeepForRemoteInputHistory(entry)).thenReturn(true)
`when`(remoteInputManager.shouldKeepForSmartReplyHistory(entry)).thenReturn(false)
- collectionListeners.forEach {
- it.onEntryUpdated(entry, true)
- }
+ collectionListeners.forEach { it.onEntryUpdated(entry, true) }
verify(rebuilder, times(1)).rebuildForRemoteInputReply(entry)
}
@@ -198,16 +200,15 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
@EnableFlags(FLAG_LIFETIME_EXTENSION_REFACTOR)
fun testSmartReplyLifetimeExtensionListenerTrigger() {
// Create notification with LIFETIME_EXTENDED_BY_DIRECT_REPLY flag.
- val entry = NotificationEntryBuilder()
+ val entry =
+ NotificationEntryBuilder()
.setId(3)
.setTag("entry")
.setFlag(mContext, Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true)
.build()
`when`(remoteInputManager.shouldKeepForRemoteInputHistory(entry)).thenReturn(false)
`when`(remoteInputManager.shouldKeepForSmartReplyHistory(entry)).thenReturn(true)
- collectionListeners.forEach {
- it.onEntryUpdated(entry, true)
- }
+ collectionListeners.forEach { it.onEntryUpdated(entry, true) }
verify(rebuilder, times(1)).rebuildForCanceledSmartReplies(entry)
verify(smartReplyController, times(1)).stopSending(entry)
@@ -217,25 +218,25 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
@EnableFlags(FLAG_LIFETIME_EXTENSION_REFACTOR)
fun testRepeatedUpdateTriggersRebuild() {
// Create notification with LIFETIME_EXTENDED_BY_DIRECT_REPLY flag.
- val entry = NotificationEntryBuilder()
+ val entry =
+ NotificationEntryBuilder()
.setId(3)
.setTag("entry")
.setFlag(mContext, Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true)
.build()
`when`(remoteInputManager.shouldKeepForRemoteInputHistory(entry)).thenReturn(false)
`when`(remoteInputManager.shouldKeepForSmartReplyHistory(entry)).thenReturn(false)
- collectionListeners.forEach {
- it.onEntryUpdated(entry, true)
- }
+ collectionListeners.forEach { it.onEntryUpdated(entry, true) }
- verify(rebuilder, times(1)).rebuildWithExistingReplies(entry)
+ verify(rebuilder, times(1)).rebuildForRemoteInputReply(entry)
}
@Test
@EnableFlags(FLAG_LIFETIME_EXTENSION_REFACTOR)
fun testLifetimeExtensionListenerClearsRemoteInputs() {
// Create notification with LIFETIME_EXTENDED_BY_DIRECT_REPLY flag.
- val entry = NotificationEntryBuilder()
+ val entry =
+ NotificationEntryBuilder()
.setId(3)
.setTag("entry")
.setFlag(mContext, Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, false)
@@ -245,9 +246,7 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
`when`(remoteInputManager.shouldKeepForRemoteInputHistory(entry)).thenReturn(false)
`when`(remoteInputManager.shouldKeepForSmartReplyHistory(entry)).thenReturn(false)
- collectionListeners.forEach {
- it.onEntryUpdated(entry, true)
- }
+ collectionListeners.forEach { it.onEntryUpdated(entry, true) }
assertThat(entry.remoteInputs).isNull()
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/HeadsUpNotificationInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/HeadsUpNotificationInteractorTest.kt
index cea8857c01bf..7d5278ed1601 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/HeadsUpNotificationInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/HeadsUpNotificationInteractorTest.kt
@@ -332,7 +332,10 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
// WHEN a row is pinned
headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))
// AND the lock screen is shown
- keyguardTransitionRepository.emitInitialStepsFromOff(to = KeyguardState.LOCKSCREEN)
+ keyguardTransitionRepository.emitInitialStepsFromOff(
+ to = KeyguardState.LOCKSCREEN,
+ testSetup = true,
+ )
assertThat(showHeadsUpStatusBar).isFalse()
}
@@ -345,7 +348,10 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
// WHEN a row is pinned
headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))
// AND the lock screen is shown
- keyguardTransitionRepository.emitInitialStepsFromOff(to = KeyguardState.LOCKSCREEN)
+ keyguardTransitionRepository.emitInitialStepsFromOff(
+ to = KeyguardState.LOCKSCREEN,
+ testSetup = true,
+ )
// AND bypass is enabled
faceAuthRepository.isBypassEnabled.value = true
@@ -359,7 +365,10 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
// WHEN no pinned rows
// AND the lock screen is shown
- keyguardTransitionRepository.emitInitialStepsFromOff(to = KeyguardState.LOCKSCREEN)
+ keyguardTransitionRepository.emitInitialStepsFromOff(
+ to = KeyguardState.LOCKSCREEN,
+ testSetup = true,
+ )
// AND bypass is enabled
faceAuthRepository.isBypassEnabled.value = true
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelTest.kt
index 83ad18b6468b..46f3a6b66429 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelTest.kt
@@ -38,6 +38,7 @@ import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.shared.settings.data.repository.fakeSecureSettingsRepository
import com.android.systemui.statusbar.notification.collection.render.NotifStats
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
+import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
import com.android.systemui.testKosmos
import com.android.systemui.util.ui.isAnimating
@@ -254,6 +255,39 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
assertThat(buttonLabel).isEqualTo(R.string.manage_notifications_history_text)
}
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
+ @Test
+ fun manageButtonOnClick_whenHistoryDisabled() =
+ testScope.runTest {
+ val onClick by collectLastValue(underTest.manageOrHistoryButtonClick)
+ runCurrent()
+
+ // WHEN notification history is disabled
+ fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0)
+
+ // THEN onClick leads to settings page
+ assertThat(onClick?.targetIntent?.action)
+ .isEqualTo(Settings.ACTION_NOTIFICATION_SETTINGS)
+ assertThat(onClick?.backStack).isEmpty()
+ }
+
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
+ @Test
+ fun historyButtonOnClick_whenHistoryEnabled() =
+ testScope.runTest {
+ val onClick by collectLastValue(underTest.manageOrHistoryButtonClick)
+ runCurrent()
+
+ // WHEN notification history is enabled
+ fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1)
+
+ // THEN onClick leads to history page
+ assertThat(onClick?.targetIntent?.action)
+ .isEqualTo(Settings.ACTION_NOTIFICATION_HISTORY)
+ assertThat(onClick?.backStack?.map { it.action })
+ .containsExactly(Settings.ACTION_NOTIFICATION_SETTINGS)
+ }
+
@Test
fun manageButtonVisible_whenMessageVisible() =
testScope.runTest {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt
index e396b567ac89..0598b87aec9d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt
@@ -133,7 +133,10 @@ class KeyguardStatusBarViewModelTest(flags: FlagsParameterization) : SysuiTestCa
// WHEN HUN displayed on the bypass lock screen
headsUpRepository.setNotifications(FakeHeadsUpRowRepository("key 0", isPinned = true))
- keyguardTransitionRepository.emitInitialStepsFromOff(KeyguardState.LOCKSCREEN)
+ keyguardTransitionRepository.emitInitialStepsFromOff(
+ KeyguardState.LOCKSCREEN,
+ testSetup = true,
+ )
kosmos.sceneContainerRepository.snapToScene(Scenes.Lockscreen)
faceAuthRepository.isBypassEnabled.value = true
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardTransitionRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardTransitionRepository.kt
index a73c184a1ba8..4d0e603aadd6 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardTransitionRepository.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardTransitionRepository.kt
@@ -48,9 +48,8 @@ import kotlinx.coroutines.test.runCurrent
* with OFF -> GONE. Construct with initInLockscreen = false if your test requires this behavior.
*/
@SysUISingleton
-class FakeKeyguardTransitionRepository(
- private val initInLockscreen: Boolean = true,
-) : KeyguardTransitionRepository {
+class FakeKeyguardTransitionRepository(private val initInLockscreen: Boolean = true) :
+ KeyguardTransitionRepository {
private val _transitions =
MutableSharedFlow<TransitionStep>(replay = 3, onBufferOverflow = BufferOverflow.DROP_OLDEST)
override val transitions: SharedFlow<TransitionStep> = _transitions
@@ -63,7 +62,7 @@ class FakeKeyguardTransitionRepository(
ownerName = "",
from = KeyguardState.OFF,
to = KeyguardState.LOCKSCREEN,
- animator = null
+ animator = null,
)
)
override var currentTransitionInfoInternal = _currentTransitionInfo.asStateFlow()
@@ -71,12 +70,7 @@ class FakeKeyguardTransitionRepository(
init {
// Seed with a FINISHED transition in OFF, same as the real repository.
_transitions.tryEmit(
- TransitionStep(
- KeyguardState.OFF,
- KeyguardState.OFF,
- 1f,
- TransitionState.FINISHED,
- )
+ TransitionStep(KeyguardState.OFF, KeyguardState.OFF, 1f, TransitionState.FINISHED)
)
if (initInLockscreen) {
@@ -173,7 +167,7 @@ class FakeKeyguardTransitionRepository(
transitionState = TransitionState.RUNNING,
from = from,
to = to,
- value = 0.5f
+ value = 0.5f,
)
)
testScheduler.runCurrent()
@@ -184,7 +178,7 @@ class FakeKeyguardTransitionRepository(
transitionState = TransitionState.RUNNING,
from = from,
to = to,
- value = 1f
+ value = 1f,
)
)
testScheduler.runCurrent()
@@ -208,7 +202,7 @@ class FakeKeyguardTransitionRepository(
this.sendTransitionStep(
step = step,
validateStep = validateStep,
- ownerName = step.ownerName
+ ownerName = step.ownerName,
)
}
@@ -240,9 +234,9 @@ class FakeKeyguardTransitionRepository(
to = to,
value = value,
transitionState = transitionState,
- ownerName = ownerName
+ ownerName = ownerName,
),
- validateStep: Boolean = true
+ validateStep: Boolean = true,
) {
if (step.transitionState == TransitionState.STARTED) {
_currentTransitionInfo.value =
@@ -273,7 +267,7 @@ class FakeKeyguardTransitionRepository(
fun sendTransitionStepJava(
coroutineScope: CoroutineScope,
step: TransitionStep,
- validateStep: Boolean = true
+ validateStep: Boolean = true,
): Job {
return coroutineScope.launch {
sendTransitionStep(step = step, validateStep = validateStep)
@@ -283,7 +277,7 @@ class FakeKeyguardTransitionRepository(
suspend fun sendTransitionSteps(
steps: List<TransitionStep>,
testScope: TestScope,
- validateSteps: Boolean = true
+ validateSteps: Boolean = true,
) {
steps.forEach {
sendTransitionStep(step = it, validateStep = validateSteps)
@@ -296,7 +290,7 @@ class FakeKeyguardTransitionRepository(
return if (info.animator == null) UUID.randomUUID() else null
}
- override suspend fun emitInitialStepsFromOff(to: KeyguardState) {
+ override suspend fun emitInitialStepsFromOff(to: KeyguardState, testSetup: Boolean) {
tryEmitInitialStepsFromOff(to)
}
@@ -318,14 +312,14 @@ class FakeKeyguardTransitionRepository(
1f,
TransitionState.FINISHED,
ownerName = "KeyguardTransitionRepository(boot)",
- ),
+ )
)
}
override suspend fun updateTransition(
transitionId: UUID,
@FloatRange(from = 0.0, to = 1.0) value: Float,
- state: TransitionState
+ state: TransitionState,
) = Unit
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorKosmos.kt
index e2b283b06562..38bc758232a2 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardDismissActionInteractorKosmos.kt
@@ -22,7 +22,6 @@ import com.android.systemui.keyguard.data.repository.keyguardRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.domain.interactor.powerInteractor
-import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.shade.domain.interactor.shadeInteractor
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -34,7 +33,6 @@ val Kosmos.keyguardDismissActionInteractor by
transitionInteractor = keyguardTransitionInteractor,
dismissInteractor = keyguardDismissInteractor,
applicationScope = testScope.backgroundScope,
- sceneInteractor = { sceneInteractor },
deviceUnlockedInteractor = { deviceUnlockedInteractor },
powerInteractor = powerInteractor,
alternateBouncerInteractor = alternateBouncerInteractor,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelKosmos.kt
index 0c538ff1d6fe..ab7ccb3bc029 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBlueprintViewModelKosmos.kt
@@ -18,6 +18,7 @@ package com.android.systemui.keyguard.ui.viewmodel
import android.os.fakeExecutorHandler
import com.android.systemui.keyguard.domain.interactor.keyguardBlueprintInteractor
+import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
import com.android.systemui.kosmos.Kosmos
val Kosmos.keyguardBlueprintViewModel by
@@ -25,5 +26,6 @@ val Kosmos.keyguardBlueprintViewModel by
KeyguardBlueprintViewModel(
fakeExecutorHandler,
keyguardBlueprintInteractor,
+ keyguardTransitionInteractor,
)
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt
index 38626a5dbac3..3c87106bf5aa 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt
@@ -47,6 +47,8 @@ val Kosmos.keyguardRootViewModel by Fixture {
alternateBouncerToGoneTransitionViewModel = alternateBouncerToGoneTransitionViewModel,
alternateBouncerToLockscreenTransitionViewModel =
alternateBouncerToLockscreenTransitionViewModel,
+ alternateBouncerToOccludedTransitionViewModel =
+ alternateBouncerToOccludedTransitionViewModel,
aodToGoneTransitionViewModel = aodToGoneTransitionViewModel,
aodToLockscreenTransitionViewModel = aodToLockscreenTransitionViewModel,
aodToOccludedTransitionViewModel = aodToOccludedTransitionViewModel,
@@ -69,9 +71,12 @@ val Kosmos.keyguardRootViewModel by Fixture {
lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel,
lockscreenToPrimaryBouncerTransitionViewModel =
lockscreenToPrimaryBouncerTransitionViewModel,
+ occludedToAlternateBouncerTransitionViewModel =
+ occludedToAlternateBouncerTransitionViewModel,
occludedToAodTransitionViewModel = occludedToAodTransitionViewModel,
occludedToDozingTransitionViewModel = occludedToDozingTransitionViewModel,
occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel,
+ offToLockscreenTransitionViewModel = offToLockscreenTransitionViewModel,
primaryBouncerToAodTransitionViewModel = primaryBouncerToAodTransitionViewModel,
primaryBouncerToGoneTransitionViewModel = primaryBouncerToGoneTransitionViewModel,
primaryBouncerToLockscreenTransitionViewModel =
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModelKosmos.kt
new file mode 100644
index 000000000000..2acd1b40af3e
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAlternateBouncerTransitionViewModelKosmos.kt
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+@file:OptIn(ExperimentalCoroutinesApi::class)
+
+package com.android.systemui.keyguard.ui.viewmodel
+
+import com.android.systemui.keyguard.ui.keyguardTransitionAnimationFlow
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.Kosmos.Fixture
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+
+val Kosmos.occludedToAlternateBouncerTransitionViewModel by Fixture {
+ OccludedToAlternateBouncerTransitionViewModel(animationFlow = keyguardTransitionAnimationFlow)
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelKosmos.kt
new file mode 100644
index 000000000000..5d62a0f4a0cf
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/OffToLockscreenTransitionViewModelKosmos.kt
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+@file:OptIn(ExperimentalCoroutinesApi::class)
+
+package com.android.systemui.keyguard.ui.viewmodel
+
+import com.android.systemui.keyguard.ui.keyguardTransitionAnimationFlow
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.Kosmos.Fixture
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+
+val Kosmos.offToLockscreenTransitionViewModel by Fixture {
+ OffToLockscreenTransitionViewModel(animationFlow = keyguardTransitionAnimationFlow)
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelKosmos.kt
index ff8b478b368b..6540ed6bba45 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsShadeOverlayContentViewModelKosmos.kt
@@ -18,11 +18,13 @@ package com.android.systemui.qs.ui.viewmodel
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.ui.viewmodel.shadeHeaderViewModelFactory
val Kosmos.quickSettingsShadeOverlayContentViewModel: QuickSettingsShadeOverlayContentViewModel by
Kosmos.Fixture {
QuickSettingsShadeOverlayContentViewModel(
+ shadeInteractor = shadeInteractor,
sceneInteractor = sceneInteractor,
shadeHeaderViewModelFactory = shadeHeaderViewModelFactory,
quickSettingsContainerViewModel = quickSettingsContainerViewModel,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt
index 6d488d21301e..60141c60a265 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt
@@ -25,6 +25,7 @@ import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.data.repository.FakeShadeRepository
import com.android.systemui.shade.data.repository.ShadeRepository
+import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.TestScope
@@ -133,7 +134,7 @@ interface ShadeTestUtilDelegate {
class ShadeTestUtilLegacyImpl(
val testScope: TestScope,
val shadeRepository: FakeShadeRepository,
- val context: SysuiTestableContext
+ val context: SysuiTestableContext,
) : ShadeTestUtilDelegate {
override fun setShadeAndQsExpansion(shadeExpansion: Float, qsExpansion: Float) {
shadeRepository.setLegacyShadeExpansion(shadeExpansion)
@@ -191,6 +192,7 @@ class ShadeTestUtilLegacyImpl(
}
/** Sets up shade state for tests when the scene container flag is enabled. */
+@OptIn(ExperimentalCoroutinesApi::class)
class ShadeTestUtilSceneImpl(
val testScope: TestScope,
val sceneInteractor: SceneInteractor,
@@ -269,7 +271,7 @@ class ShadeTestUtilSceneImpl(
from: SceneKey,
to: SceneKey,
progress: Float,
- isInitiatedByUserInput: Boolean = true
+ isInitiatedByUserInput: Boolean = true,
) {
sceneInteractor.changeScene(from, "test")
val transitionState =
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/NotificationsShadeOverlayContentViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/NotificationsShadeOverlayContentViewModelKosmos.kt
index 9cdd51994262..718347fc3490 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/NotificationsShadeOverlayContentViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/NotificationsShadeOverlayContentViewModelKosmos.kt
@@ -20,6 +20,7 @@ import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.notifications.ui.viewmodel.NotificationsShadeOverlayContentViewModel
import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.notificationsPlaceholderViewModelFactory
val Kosmos.notificationsShadeOverlayContentViewModel:
@@ -28,5 +29,6 @@ val Kosmos.notificationsShadeOverlayContentViewModel:
shadeHeaderViewModelFactory = shadeHeaderViewModelFactory,
notificationsPlaceholderViewModelFactory = notificationsPlaceholderViewModelFactory,
sceneInteractor = sceneInteractor,
+ shadeInteractor = shadeInteractor,
)
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelKosmos.kt
index 7eb9f3472482..f5b856df8835 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ui/viewmodel/ShadeHeaderViewModelKosmos.kt
@@ -20,7 +20,6 @@ import android.content.applicationContext
import com.android.systemui.broadcast.broadcastDispatcher
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.plugins.activityStarter
-import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.shade.domain.interactor.privacyChipInteractor
import com.android.systemui.shade.domain.interactor.shadeHeaderClockInteractor
import com.android.systemui.shade.domain.interactor.shadeInteractor
@@ -32,7 +31,6 @@ val Kosmos.shadeHeaderViewModel: ShadeHeaderViewModel by
ShadeHeaderViewModel(
context = applicationContext,
activityStarter = activityStarter,
- sceneInteractor = sceneInteractor,
shadeInteractor = shadeInteractor,
mobileIconsInteractor = mobileIconsInteractor,
mobileIconsViewModel = mobileIconsViewModel,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorKosmos.kt
index b19e221d099c..3d2bd6cf49d4 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/domain/interactor/SeenNotificationsInteractorKosmos.kt
@@ -45,3 +45,17 @@ var Kosmos.lockScreenShowOnlyUnseenNotificationsSetting: Boolean
UserHandle.USER_CURRENT,
)
}
+
+var Kosmos.lockScreenNotificationMinimalismSetting: Boolean
+ get() =
+ fakeSettings.getIntForUser(
+ Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
+ UserHandle.USER_CURRENT,
+ ) == 1
+ set(value) {
+ fakeSettings.putIntForUser(
+ Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
+ if (value) 1 else 0,
+ UserHandle.USER_CURRENT,
+ )
+ }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
index a9e117affefb..237f7e4c4dc8 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
@@ -42,6 +42,7 @@ import com.android.systemui.keyguard.ui.viewmodel.lockscreenToPrimaryBouncerTran
import com.android.systemui.keyguard.ui.viewmodel.occludedToAodTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.occludedToGoneTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.occludedToLockscreenTransitionViewModel
+import com.android.systemui.keyguard.ui.viewmodel.offToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.primaryBouncerToGoneTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.primaryBouncerToLockscreenTransitionViewModel
import com.android.systemui.kosmos.Kosmos
@@ -85,6 +86,7 @@ val Kosmos.sharedNotificationContainerViewModel by Fixture {
occludedToAodTransitionViewModel = occludedToAodTransitionViewModel,
occludedToGoneTransitionViewModel = occludedToGoneTransitionViewModel,
occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel,
+ offToLockscreenTransitionViewModel = offToLockscreenTransitionViewModel,
primaryBouncerToGoneTransitionViewModel = primaryBouncerToGoneTransitionViewModel,
primaryBouncerToLockscreenTransitionViewModel =
primaryBouncerToLockscreenTransitionViewModel,
diff --git a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
index 3224b27d5803..73b7b35ba9a7 100644
--- a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
+++ b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
@@ -165,16 +165,27 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
protected final AccessibilitySecurityPolicy mSecurityPolicy;
protected final AccessibilityTrace mTrace;
- // The attribution tag set by the service that is bound to this instance
+ /** The attribution tag set by the client that is bound to this instance */
protected String mAttributionTag;
protected int mDisplayTypes = DISPLAY_TYPE_DEFAULT;
- // The service that's bound to this instance. Whenever this value is non-null, this
- // object is registered as a death recipient
- IBinder mService;
+ /**
+ * Binder of the {@link #mClient}.
+ *
+ * <p>Whenever this value is non-null, it should be registered as a {@link
+ * IBinder.DeathRecipient}
+ */
+ @Nullable IBinder mClientBinder;
- IAccessibilityServiceClient mServiceInterface;
+ /**
+ * The accessibility client this class represents.
+ *
+ * <p>The client is in the application process, i.e., it's a client of system_server. Depending
+ * on the use case, the client can be an {@link AccessibilityService}, a {@code UiAutomation},
+ * etc.
+ */
+ @Nullable IAccessibilityServiceClient mClient;
int mEventTypes;
@@ -218,10 +229,10 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
int mGenericMotionEventSources;
int mObservedMotionEventSources;
- // the events pending events to be dispatched to this service
+ /** Pending events to be dispatched to the client */
final SparseArray<AccessibilityEvent> mPendingEvents = new SparseArray<>();
- /** Whether this service relies on its {@link AccessibilityCache} being up to date */
+ /** Whether the client relies on its {@link AccessibilityCache} being up to date */
boolean mUsesAccessibilityCache = false;
// Handler only for dispatching accessibility events since we use event
@@ -230,7 +241,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
final SparseArray<IBinder> mOverlayWindowTokens = new SparseArray();
- // All the embedded accessibility overlays that have been added by this service.
+ /** All the embedded accessibility overlays that have been added by the client. */
private List<SurfaceControl> mOverlays = new ArrayList<>();
/** The timestamp of requesting to take screenshot in milliseconds */
@@ -274,7 +285,8 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
/**
* Called back to notify system that the client has changed
- * @param serviceInfoChanged True if the service's AccessibilityServiceInfo changed.
+ *
+ * @param serviceInfoChanged True if the client's AccessibilityServiceInfo changed.
*/
void onClientChangeLocked(boolean serviceInfoChanged);
@@ -360,21 +372,22 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mIPlatformCompat = IPlatformCompat.Stub.asInterface(
ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
- mEventDispatchHandler = new Handler(mainHandler.getLooper()) {
- @Override
- public void handleMessage(Message message) {
- final int eventType = message.what;
- AccessibilityEvent event = (AccessibilityEvent) message.obj;
- boolean serviceWantsEvent = message.arg1 != 0;
- notifyAccessibilityEventInternal(eventType, event, serviceWantsEvent);
- }
- };
+ mEventDispatchHandler =
+ new Handler(mainHandler.getLooper()) {
+ @Override
+ public void handleMessage(Message message) {
+ final int eventType = message.what;
+ AccessibilityEvent event = (AccessibilityEvent) message.obj;
+ boolean clientWantsEvent = message.arg1 != 0;
+ notifyAccessibilityEventInternal(eventType, event, clientWantsEvent);
+ }
+ };
setDynamicallyConfigurableProperties(accessibilityServiceInfo);
}
@Override
public boolean onKeyEvent(KeyEvent keyEvent, int sequenceNumber) {
- if (!mRequestFilterKeyEvents || (mServiceInterface == null)) {
+ if (!mRequestFilterKeyEvents || (mClient == null)) {
return false;
}
if((mAccessibilityServiceInfo.getCapabilities()
@@ -388,7 +401,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
if (svcClientTracingEnabled()) {
logTraceSvcClient("onKeyEvent", keyEvent + ", " + sequenceNumber);
}
- mServiceInterface.onKeyEvent(keyEvent, sequenceNumber);
+ mClient.onKeyEvent(keyEvent, sequenceNumber);
} catch (RemoteException e) {
return false;
}
@@ -470,7 +483,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
}
public boolean canReceiveEventsLocked() {
- return (mEventTypes != 0 && mService != null);
+ return (mEventTypes != 0 && mClientBinder != null);
}
@RequiresNoPermission
@@ -520,7 +533,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
- // If the XML manifest had data to configure the service its info
+ // If the XML manifest had data to configure the AccessibilityService, its info
// should be already set. In such a case update only the dynamically
// configurable properties.
boolean oldRequestIme = mRequestImeApis;
@@ -1733,40 +1746,40 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
try {
// Clear the proxy in the other process so this
// IAccessibilityServiceConnection can be garbage collected.
- if (mServiceInterface != null) {
+ if (mClient != null) {
if (svcClientTracingEnabled()) {
logTraceSvcClient("init", "null, " + mId + ", null");
}
- mServiceInterface.init(null, mId, null);
+ mClient.init(null, mId, null);
}
} catch (RemoteException re) {
/* ignore */
}
- if (mService != null) {
+ if (mClientBinder != null) {
try {
- mService.unlinkToDeath(this, 0);
+ mClientBinder.unlinkToDeath(this, 0);
} catch (NoSuchElementException e) {
Slog.e(LOG_TAG, "Failed unregistering death link");
}
- mService = null;
+ mClientBinder = null;
}
- mServiceInterface = null;
+ mClient = null;
mReceivedAccessibilityButtonCallbackSinceBind = false;
}
public boolean isConnectedLocked() {
- return (mService != null);
+ return (mClientBinder != null);
}
public void notifyAccessibilityEvent(AccessibilityEvent event) {
synchronized (mLock) {
final int eventType = event.getEventType();
- final boolean serviceWantsEvent = wantsEventLocked(event);
+ final boolean clientWantsEvent = clientWantsEventLocked(event);
final boolean requiredForCacheConsistency = mUsesAccessibilityCache
&& ((AccessibilityCache.CACHE_CRITICAL_EVENTS_MASK & eventType) != 0);
- if (!serviceWantsEvent && !requiredForCacheConsistency) {
+ if (!clientWantsEvent && !requiredForCacheConsistency) {
return;
}
@@ -1774,7 +1787,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
return;
}
// Make a copy since during dispatch it is possible the event to
- // be modified to remove its source if the receiving service does
+ // be modified to remove its source if the receiving client does
// not have permission to access the window content.
AccessibilityEvent newEvent = AccessibilityEvent.obtain(event);
Message message;
@@ -1792,22 +1805,20 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
// Send all messages, bypassing mPendingEvents
message = mEventDispatchHandler.obtainMessage(eventType, newEvent);
}
- message.arg1 = serviceWantsEvent ? 1 : 0;
+ message.arg1 = clientWantsEvent ? 1 : 0;
mEventDispatchHandler.sendMessageDelayed(message, mNotificationTimeout);
}
}
/**
- * Determines if given event can be dispatched to a service based on the package of the
- * event source. Specifically, a service is notified if it is interested in events from the
- * package.
+ * Determines if given event can be dispatched to a client based on the package of the event
+ * source. Specifically, a client is notified if it is interested in events from the package.
*
* @param event The event.
- * @return True if the listener should be notified, false otherwise.
+ * @return True if the client should be notified, false otherwise.
*/
- private boolean wantsEventLocked(AccessibilityEvent event) {
-
+ private boolean clientWantsEventLocked(AccessibilityEvent event) {
if (!canReceiveEventsLocked()) {
return false;
}
@@ -1838,22 +1849,20 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
}
/**
- * Notifies an accessibility service client for a scheduled event given the event type.
+ * Notifies a client for a scheduled event given the event type.
*
* @param eventType The type of the event to dispatch.
*/
private void notifyAccessibilityEventInternal(
- int eventType,
- AccessibilityEvent event,
- boolean serviceWantsEvent) {
- IAccessibilityServiceClient listener;
+ int eventType, AccessibilityEvent event, boolean clientWantsEvent) {
+ IAccessibilityServiceClient client;
synchronized (mLock) {
- listener = mServiceInterface;
+ client = mClient;
- // If the service died/was disabled while the message for dispatching
- // the accessibility event was propagating the listener may be null.
- if (listener == null) {
+ // If the client (in the application process) died/was disabled while the message for
+ // dispatching the accessibility event was propagating, "client" may be null.
+ if (client == null) {
return;
}
@@ -1868,7 +1877,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
// 1) A binder thread calls notifyAccessibilityServiceDelayedLocked
// which posts a message for dispatching an event and stores the event
// in mPendingEvents.
- // 2) The message is pulled from the queue by the handler on the service
+ // 2) The message is pulled from the queue by the handler on the client
// thread and this method is just about to acquire the lock.
// 3) Another binder thread acquires the lock in notifyAccessibilityEvent
// 4) notifyAccessibilityEvent recycles the event that this method was about
@@ -1876,7 +1885,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
// 5) This method grabs the new event, processes it, and removes it from
// mPendingEvents
// 6) The second message dispatched in (4) arrives, but the event has been
- // remvoved in (5).
+ // removed in (5).
event = mPendingEvents.get(eventType);
if (event == null) {
return;
@@ -1893,14 +1902,14 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
try {
if (svcClientTracingEnabled()) {
- logTraceSvcClient("onAccessibilityEvent", event + ";" + serviceWantsEvent);
+ logTraceSvcClient("onAccessibilityEvent", event + ";" + clientWantsEvent);
}
- listener.onAccessibilityEvent(event, serviceWantsEvent);
+ client.onAccessibilityEvent(event, clientWantsEvent);
if (DEBUG) {
- Slog.i(LOG_TAG, "Event " + event + " sent to " + listener);
+ Slog.i(LOG_TAG, "Event " + event + " sent to " + client);
}
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error during sending " + event + " to " + listener, re);
+ Slog.e(LOG_TAG, "Error during sending " + event + " to " + client, re);
} finally {
event.recycle();
}
@@ -1978,122 +1987,126 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
return (mGenericMotionEventSources & eventSourceWithoutClass) != 0;
}
-
/**
- * Called by the invocation handler to notify the service that the
- * state of magnification has changed.
+ * Called by the invocation handler to notify the client that the state of magnification has
+ * changed.
*/
- private void notifyMagnificationChangedInternal(int displayId, @NonNull Region region,
- @NonNull MagnificationConfig config) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ private void notifyMagnificationChangedInternal(
+ int displayId, @NonNull Region region, @NonNull MagnificationConfig config) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onMagnificationChanged", displayId + ", " + region + ", "
+ config.toString());
}
- listener.onMagnificationChanged(displayId, region, config);
+ client.onMagnificationChanged(displayId, region, config);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending magnification changes to " + mService, re);
+ Slog.e(LOG_TAG, "Error sending magnification changes to " + mClientBinder, re);
}
}
}
/**
- * Called by the invocation handler to notify the service that the state of the soft
- * keyboard show mode has changed.
+ * Called by the invocation handler to notify the client that the state of the soft keyboard
+ * show mode has changed.
*/
private void notifySoftKeyboardShowModeChangedInternal(int showState) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onSoftKeyboardShowModeChanged", String.valueOf(showState));
}
- listener.onSoftKeyboardShowModeChanged(showState);
+ client.onSoftKeyboardShowModeChanged(showState);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending soft keyboard show mode changes to " + mService,
+ Slog.e(
+ LOG_TAG,
+ "Error sending soft keyboard show mode changes to " + mClientBinder,
re);
}
}
}
private void notifyAccessibilityButtonClickedInternal(int displayId) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onAccessibilityButtonClicked", String.valueOf(displayId));
}
- listener.onAccessibilityButtonClicked(displayId);
+ client.onAccessibilityButtonClicked(displayId);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending accessibility button click to " + mService, re);
+ Slog.e(LOG_TAG, "Error sending accessibility button click to " + mClientBinder, re);
}
}
}
private void notifyAccessibilityButtonAvailabilityChangedInternal(boolean available) {
- // Only notify the service if it's not been notified or the state has changed
+ // Only notify the client if it's not been notified or the state has changed
if (mReceivedAccessibilityButtonCallbackSinceBind
&& (mLastAccessibilityButtonCallbackState == available)) {
return;
}
mReceivedAccessibilityButtonCallbackSinceBind = true;
mLastAccessibilityButtonCallbackState = available;
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onAccessibilityButtonAvailabilityChanged",
String.valueOf(available));
}
- listener.onAccessibilityButtonAvailabilityChanged(available);
+ client.onAccessibilityButtonAvailabilityChanged(available);
} catch (RemoteException re) {
- Slog.e(LOG_TAG,
- "Error sending accessibility button availability change to " + mService,
+ Slog.e(
+ LOG_TAG,
+ "Error sending accessibility button availability change to "
+ + mClientBinder,
re);
}
}
}
private void notifyGestureInternal(AccessibilityGestureEvent gestureInfo) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onGesture", gestureInfo.toString());
}
- listener.onGesture(gestureInfo);
+ client.onGesture(gestureInfo);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error during sending gesture " + gestureInfo
- + " to " + mService, re);
+ Slog.e(
+ LOG_TAG,
+ "Error during sending gesture " + gestureInfo + " to " + mClientBinder,
+ re);
}
}
}
private void notifySystemActionsChangedInternal() {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onSystemActionsChanged", "");
}
- listener.onSystemActionsChanged();
+ client.onSystemActionsChanged();
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending system actions change to " + mService,
- re);
+ Slog.e(LOG_TAG, "Error sending system actions change to " + mClientBinder, re);
}
}
}
private void notifyClearAccessibilityCacheInternal() {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("clearAccessibilityCache", "");
}
- listener.clearAccessibilityCache();
+ client.clearAccessibilityCache();
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error during requesting accessibility info cache"
+ " to be cleared.", re);
@@ -2106,70 +2119,66 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
private void setImeSessionEnabledInternal(IAccessibilityInputMethodSession session,
boolean enabled) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null && session != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null && session != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("createImeSession", "");
}
- listener.setImeSessionEnabled(session, enabled);
+ client.setImeSessionEnabled(session, enabled);
} catch (RemoteException re) {
- Slog.e(LOG_TAG,
- "Error requesting IME session from " + mService, re);
+ Slog.e(LOG_TAG, "Error requesting IME session from " + mClientBinder, re);
}
}
}
private void bindInputInternal() {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("bindInput", "");
}
- listener.bindInput();
+ client.bindInput();
} catch (RemoteException re) {
- Slog.e(LOG_TAG,
- "Error binding input to " + mService, re);
+ Slog.e(LOG_TAG, "Error binding input to " + mClientBinder, re);
}
}
}
private void unbindInputInternal() {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("unbindInput", "");
}
- listener.unbindInput();
+ client.unbindInput();
} catch (RemoteException re) {
- Slog.e(LOG_TAG,
- "Error unbinding input to " + mService, re);
+ Slog.e(LOG_TAG, "Error unbinding input to " + mClientBinder, re);
}
}
}
private void startInputInternal(IRemoteAccessibilityInputConnection connection,
EditorInfo editorInfo, boolean restarting) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("startInput", "editorInfo=" + editorInfo
+ " restarting=" + restarting);
}
- listener.startInput(connection, editorInfo, restarting);
+ client.startInput(connection, editorInfo, restarting);
} catch (RemoteException re) {
- Slog.e(LOG_TAG,
- "Error starting input to " + mService, re);
+ Slog.e(LOG_TAG, "Error starting input to " + mClientBinder, re);
}
}
}
- protected IAccessibilityServiceClient getServiceInterfaceSafely() {
+ protected IAccessibilityServiceClient getClientSafely() {
synchronized (mLock) {
- return mServiceInterface;
+ return mClient;
}
}
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 7580b697b516..d595d02016e0 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -1435,8 +1435,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
interfacesToInterrupt = new ArrayList<>(services.size());
for (int i = 0; i < services.size(); i++) {
AccessibilityServiceConnection service = services.get(i);
- IBinder a11yServiceBinder = service.mService;
- IAccessibilityServiceClient a11yServiceInterface = service.mServiceInterface;
+ IBinder a11yServiceBinder = service.mClientBinder;
+ IAccessibilityServiceClient a11yServiceInterface = service.mClient;
if ((a11yServiceBinder != null) && (a11yServiceInterface != null)) {
interfacesToInterrupt.add(a11yServiceInterface);
}
@@ -4962,9 +4962,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
if (android.permission.flags.Flags.enhancedConfirmationModeApisEnabled()
&& android.security.Flags.extendEcmToAllSettings()) {
try {
- return !mContext.getSystemService(EnhancedConfirmationManager.class)
- .isRestricted(packageName,
- AppOpsManager.OPSTR_BIND_ACCESSIBILITY_SERVICE);
+ final EnhancedConfirmationManager userContextEcm =
+ mContext.createContextAsUser(UserHandle.of(userId), /* flags = */ 0)
+ .getSystemService(EnhancedConfirmationManager.class);
+ if (userContextEcm != null) {
+ return !userContextEcm.isRestricted(packageName,
+ AppOpsManager.OPSTR_BIND_ACCESSIBILITY_SERVICE);
+ }
+ return false;
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG, "Exception when retrieving package:" + packageName, e);
return false;
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java
index 786d167af5de..15999d19ebc0 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java
@@ -166,8 +166,9 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
if (userState.getBindInstantServiceAllowedLocked()) {
flags |= Context.BIND_ALLOW_INSTANT;
}
- if (mService == null && mContext.bindServiceAsUser(
- mIntent, this, flags, new UserHandle(userState.mUserId))) {
+ if (mClientBinder == null
+ && mContext.bindServiceAsUser(
+ mIntent, this, flags, new UserHandle(userState.mUserId))) {
userState.getBindingServicesLocked().add(mComponentName);
}
} finally {
@@ -227,20 +228,20 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
addWindowTokensForAllDisplays();
}
synchronized (mLock) {
- if (mService != service) {
- if (mService != null) {
- mService.unlinkToDeath(this, 0);
+ if (mClientBinder != service) {
+ if (mClientBinder != null) {
+ mClientBinder.unlinkToDeath(this, 0);
}
- mService = service;
+ mClientBinder = service;
try {
- mService.linkToDeath(this, 0);
+ mClientBinder.linkToDeath(this, 0);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Failed registering death link");
binderDied();
return;
}
}
- mServiceInterface = IAccessibilityServiceClient.Stub.asInterface(service);
+ mClient = IAccessibilityServiceClient.Stub.asInterface(service);
if (userState == null) return;
userState.addServiceLocked(this);
mSystemSupport.onClientChangeLocked(false);
@@ -261,7 +262,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
}
private void initializeService() {
- IAccessibilityServiceClient serviceInterface = null;
+ IAccessibilityServiceClient client = null;
synchronized (mLock) {
AccessibilityUserState userState = mUserStateWeakReference.get();
if (userState == null) return;
@@ -272,18 +273,17 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
bindingServices.remove(mComponentName);
crashedServices.remove(mComponentName);
mAccessibilityServiceInfo.crashed = false;
- serviceInterface = mServiceInterface;
+ client = mClient;
}
// There's a chance that service is removed from enabled_accessibility_services setting
// key, but skip unbinding because of it's in binding state. Unbinds it if it's
// not in enabled service list.
- if (serviceInterface != null
- && !userState.getEnabledServicesLocked().contains(mComponentName)) {
+ if (client != null && !userState.getEnabledServicesLocked().contains(mComponentName)) {
mSystemSupport.onClientChangeLocked(false);
return;
}
}
- if (serviceInterface == null) {
+ if (client == null) {
binderDied();
return;
}
@@ -292,10 +292,9 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
logTraceSvcClient("init",
this + "," + mId + "," + mOverlayWindowTokens.get(Display.DEFAULT_DISPLAY));
}
- serviceInterface.init(this, mId, mOverlayWindowTokens.get(Display.DEFAULT_DISPLAY));
+ client.init(this, mId, mOverlayWindowTokens.get(Display.DEFAULT_DISPLAY));
} catch (RemoteException re) {
- Slog.w(LOG_TAG, "Error while setting connection for service: "
- + serviceInterface, re);
+ Slog.w(LOG_TAG, "Error while setting connection for service: " + client, re);
binderDied();
}
}
@@ -496,7 +495,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
@Override
public boolean isCapturingFingerprintGestures() {
- return (mServiceInterface != null)
+ return (mClient != null)
&& mSecurityPolicy.canCaptureFingerprintGestures(this)
&& mCaptureFingerprintGestures;
}
@@ -506,17 +505,17 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
if (!isCapturingFingerprintGestures()) {
return;
}
- IAccessibilityServiceClient serviceInterface;
+ IAccessibilityServiceClient client;
synchronized (mLock) {
- serviceInterface = mServiceInterface;
+ client = mClient;
}
- if (serviceInterface != null) {
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient(
"onFingerprintCapturingGesturesChanged", String.valueOf(active));
}
- mServiceInterface.onFingerprintCapturingGesturesChanged(active);
+ mClient.onFingerprintCapturingGesturesChanged(active);
} catch (RemoteException e) {
}
}
@@ -527,16 +526,16 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
if (!isCapturingFingerprintGestures()) {
return;
}
- IAccessibilityServiceClient serviceInterface;
+ IAccessibilityServiceClient client;
synchronized (mLock) {
- serviceInterface = mServiceInterface;
+ client = mClient;
}
- if (serviceInterface != null) {
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onFingerprintGesture", String.valueOf(gesture));
}
- mServiceInterface.onFingerprintGesture(gesture);
+ mClient.onFingerprintGesture(gesture);
} catch (RemoteException e) {
}
}
@@ -546,7 +545,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
@Override
public void dispatchGesture(int sequence, ParceledListSlice gestureSteps, int displayId) {
synchronized (mLock) {
- if (mServiceInterface != null && mSecurityPolicy.canPerformGestures(this)) {
+ if (mClient != null && mSecurityPolicy.canPerformGestures(this)) {
final long identity = Binder.clearCallingIdentity();
try {
MotionEventInjector motionEventInjector =
@@ -557,16 +556,18 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
if (motionEventInjector != null
&& mWindowManagerService.isTouchOrFaketouchDevice()) {
motionEventInjector.injectEvents(
- gestureSteps.getList(), mServiceInterface, sequence, displayId);
+ gestureSteps.getList(), mClient, sequence, displayId);
} else {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("onPerformGestureResult", sequence + ", false");
}
- mServiceInterface.onPerformGestureResult(sequence, false);
+ mClient.onPerformGestureResult(sequence, false);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending motion event injection failure to "
- + mServiceInterface, re);
+ Slog.e(
+ LOG_TAG,
+ "Error sending motion event injection failure to " + mClient,
+ re);
}
}
} finally {
@@ -631,48 +632,47 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
@Override
protected void createImeSessionInternal() {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (svcClientTracingEnabled()) {
logTraceSvcClient("createImeSession", "");
}
AccessibilityInputMethodSessionCallback
callback = new AccessibilityInputMethodSessionCallback(mUserId);
- listener.createImeSession(callback);
+ client.createImeSession(callback);
} catch (RemoteException re) {
- Slog.e(LOG_TAG,
- "Error requesting IME session from " + mService, re);
+ Slog.e(LOG_TAG, "Error requesting IME session from " + mClientBinder, re);
}
}
}
private void notifyMotionEventInternal(MotionEvent event) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (mTrace.isA11yTracingEnabled()) {
logTraceSvcClient(".onMotionEvent ",
event.toString());
}
- listener.onMotionEvent(event);
+ client.onMotionEvent(event);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending motion event to" + mService, re);
+ Slog.e(LOG_TAG, "Error sending motion event to" + mClientBinder, re);
}
}
}
private void notifyTouchStateInternal(int displayId, int state) {
- final IAccessibilityServiceClient listener = getServiceInterfaceSafely();
- if (listener != null) {
+ final IAccessibilityServiceClient client = getClientSafely();
+ if (client != null) {
try {
if (mTrace.isA11yTracingEnabled()) {
logTraceSvcClient(".onTouchStateChanged ",
TouchInteractionController.stateToString(state));
}
- listener.onTouchStateChanged(displayId, state);
+ client.onTouchStateChanged(displayId, state);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error sending motion event to" + mService, re);
+ Slog.e(LOG_TAG, "Error sending motion event to" + mClientBinder, re);
}
}
}
diff --git a/services/accessibility/java/com/android/server/accessibility/ProxyAccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/ProxyAccessibilityServiceConnection.java
index 4cb3d247edb0..cd97d838e3a0 100644
--- a/services/accessibility/java/com/android/server/accessibility/ProxyAccessibilityServiceConnection.java
+++ b/services/accessibility/java/com/android/server/accessibility/ProxyAccessibilityServiceConnection.java
@@ -109,14 +109,11 @@ public class ProxyAccessibilityServiceConnection extends AccessibilityServiceCon
return mDeviceId;
}
- /**
- * Called when the proxy is registered.
- */
- void initializeServiceInterface(IAccessibilityServiceClient serviceInterface)
- throws RemoteException {
- mServiceInterface = serviceInterface;
- mService = serviceInterface.asBinder();
- mServiceInterface.init(this, mId, this.mOverlayWindowTokens.get(mDisplayId));
+ /** Called when the proxy is registered. */
+ void initializeClient(IAccessibilityServiceClient client) throws RemoteException {
+ mClient = client;
+ mClientBinder = client.asBinder();
+ mClient.init(this, mId, this.mOverlayWindowTokens.get(mDisplayId));
}
/**
diff --git a/services/accessibility/java/com/android/server/accessibility/ProxyManager.java b/services/accessibility/java/com/android/server/accessibility/ProxyManager.java
index b4deeb0a6872..da11a76d5282 100644
--- a/services/accessibility/java/com/android/server/accessibility/ProxyManager.java
+++ b/services/accessibility/java/com/android/server/accessibility/ProxyManager.java
@@ -214,7 +214,7 @@ public class ProxyManager {
mA11yInputFilter.disableFeaturesForDisplayIfInstalled(displayId);
}
});
- connection.initializeServiceInterface(client);
+ connection.initializeClient(client);
}
private void registerVirtualDeviceListener() {
@@ -561,8 +561,8 @@ public class ProxyManager {
final ProxyAccessibilityServiceConnection proxy =
mProxyA11yServiceConnections.valueAt(i);
if (proxy != null && proxy.getDeviceId() == deviceId) {
- final IBinder proxyBinder = proxy.mService;
- final IAccessibilityServiceClient proxyInterface = proxy.mServiceInterface;
+ final IBinder proxyBinder = proxy.mClientBinder;
+ final IAccessibilityServiceClient proxyInterface = proxy.mClient;
if ((proxyBinder != null) && (proxyInterface != null)) {
interfaces.add(proxyInterface);
}
diff --git a/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java b/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java
index f85d786f89c5..ed4eeb534412 100644
--- a/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java
+++ b/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java
@@ -107,8 +107,7 @@ class UiAutomationManager {
Binder.getCallingUserHandle().getIdentifier());
if (mUiAutomationService != null) {
throw new IllegalStateException(
- "UiAutomationService " + mUiAutomationService.mServiceInterface
- + "already registered!");
+ "UiAutomationService " + mUiAutomationService.mClient + "already registered!");
}
try {
@@ -130,10 +129,9 @@ class UiAutomationManager {
mainHandler, mLock, securityPolicy, systemSupport, trace, windowManagerInternal,
systemActionPerformer, awm);
mUiAutomationServiceOwner = owner;
- mUiAutomationService.mServiceInterface = serviceClient;
+ mUiAutomationService.mClient = serviceClient;
try {
- mUiAutomationService.mServiceInterface.asBinder().linkToDeath(mUiAutomationService,
- 0);
+ mUiAutomationService.mClient.asBinder().linkToDeath(mUiAutomationService, 0);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Failed registering death link: " + re);
destroyUiAutomationService();
@@ -149,10 +147,10 @@ class UiAutomationManager {
synchronized (mLock) {
if (useAccessibility()
&& ((mUiAutomationService == null)
- || (serviceClient == null)
- || (mUiAutomationService.mServiceInterface == null)
- || (serviceClient.asBinder()
- != mUiAutomationService.mServiceInterface.asBinder()))) {
+ || (serviceClient == null)
+ || (mUiAutomationService.mClient == null)
+ || (serviceClient.asBinder()
+ != mUiAutomationService.mClient.asBinder()))) {
throw new IllegalStateException("UiAutomationService " + serviceClient
+ " not registered!");
}
@@ -230,8 +228,7 @@ class UiAutomationManager {
private void destroyUiAutomationService() {
synchronized (mLock) {
if (mUiAutomationService != null) {
- mUiAutomationService.mServiceInterface.asBinder().unlinkToDeath(
- mUiAutomationService, 0);
+ mUiAutomationService.mClient.asBinder().unlinkToDeath(mUiAutomationService, 0);
mUiAutomationService.onRemoved();
mUiAutomationService.resetLocked();
mUiAutomationService = null;
@@ -271,40 +268,48 @@ class UiAutomationManager {
void connectServiceUnknownThread() {
// This needs to be done on the main thread
- mMainHandler.post(() -> {
- try {
- final IAccessibilityServiceClient serviceInterface;
- final UiAutomationService uiAutomationService;
- synchronized (mLock) {
- serviceInterface = mServiceInterface;
- uiAutomationService = mUiAutomationService;
- if (serviceInterface == null) {
- mService = null;
- } else {
- mService = mServiceInterface.asBinder();
- mService.linkToDeath(this, 0);
+ mMainHandler.post(
+ () -> {
+ try {
+ final IAccessibilityServiceClient client;
+ final UiAutomationService uiAutomationService;
+ synchronized (mLock) {
+ client = mClient;
+ uiAutomationService = mUiAutomationService;
+ if (client == null) {
+ mClientBinder = null;
+ } else {
+ mClientBinder = mClient.asBinder();
+ mClientBinder.linkToDeath(this, 0);
+ }
+ }
+ // If the client is null, the UiAutomation has been shut down on
+ // another thread.
+ if (client != null && uiAutomationService != null) {
+ uiAutomationService.addWindowTokensForAllDisplays();
+ if (mTrace.isA11yTracingEnabledForTypes(
+ AccessibilityTrace.FLAGS_ACCESSIBILITY_SERVICE_CLIENT)) {
+ mTrace.logTrace(
+ "UiAutomationService.connectServiceUnknownThread",
+ AccessibilityTrace.FLAGS_ACCESSIBILITY_SERVICE_CLIENT,
+ "serviceConnection="
+ + this
+ + ";connectionId="
+ + mId
+ + "windowToken="
+ + mOverlayWindowTokens.get(
+ Display.DEFAULT_DISPLAY));
+ }
+ client.init(
+ this,
+ mId,
+ mOverlayWindowTokens.get(Display.DEFAULT_DISPLAY));
+ }
+ } catch (RemoteException re) {
+ Slog.w(LOG_TAG, "Error initializing connection", re);
+ destroyUiAutomationService();
}
- }
- // If the serviceInterface is null, the UiAutomation has been shut down on
- // another thread.
- if (serviceInterface != null && uiAutomationService != null) {
- uiAutomationService.addWindowTokensForAllDisplays();
- if (mTrace.isA11yTracingEnabledForTypes(
- AccessibilityTrace.FLAGS_ACCESSIBILITY_SERVICE_CLIENT)) {
- mTrace.logTrace("UiAutomationService.connectServiceUnknownThread",
- AccessibilityTrace.FLAGS_ACCESSIBILITY_SERVICE_CLIENT,
- "serviceConnection=" + this + ";connectionId=" + mId
- + "windowToken="
- + mOverlayWindowTokens.get(Display.DEFAULT_DISPLAY));
- }
- serviceInterface.init(this, mId,
- mOverlayWindowTokens.get(Display.DEFAULT_DISPLAY));
- }
- } catch (RemoteException re) {
- Slog.w(LOG_TAG, "Error initializing connection", re);
- destroyUiAutomationService();
- }
- });
+ });
}
@Override
diff --git a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java
index c8f8c2a6b223..082459b8c863 100644
--- a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java
+++ b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java
@@ -21,11 +21,13 @@ import static com.android.server.appfunctions.AppFunctionExecutors.THREAD_POOL_E
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.WorkerThread;
+import android.app.appfunctions.AppFunctionService;
import android.app.appfunctions.AppFunctionStaticMetadataHelper;
import android.app.appfunctions.ExecuteAppFunctionAidlRequest;
import android.app.appfunctions.ExecuteAppFunctionResponse;
import android.app.appfunctions.IAppFunctionManager;
import android.app.appfunctions.IAppFunctionService;
+import android.app.appfunctions.ICancellationCallback;
import android.app.appfunctions.IExecuteAppFunctionCallback;
import android.app.appfunctions.SafeOneTimeExecuteAppFunctionCallback;
import android.app.appsearch.AppSearchManager;
@@ -37,11 +39,15 @@ import android.app.appsearch.observer.SchemaChangeInfo;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
+import android.os.CancellationSignal;
+import android.os.IBinder;
+import android.os.ICancellationSignal;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.infra.AndroidFuture;
import com.android.server.SystemService.TargetUser;
import com.android.server.appfunctions.RemoteServiceCaller.RunServiceCallCallback;
import com.android.server.appfunctions.RemoteServiceCaller.ServiceUsageCompleteListener;
@@ -99,7 +105,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
}
@Override
- public void executeAppFunction(
+ public ICancellationSignal executeAppFunction(
@NonNull ExecuteAppFunctionAidlRequest requestInternal,
@NonNull IExecuteAppFunctionCallback executeAppFunctionCallback) {
Objects.requireNonNull(requestInternal);
@@ -120,11 +126,14 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
ExecuteAppFunctionResponse.RESULT_DENIED,
exception.getMessage(),
/* extras= */ null));
- return;
+ return null;
}
int callingUid = Binder.getCallingUid();
- int callingPid = Binder.getCallingUid();
+ int callingPid = Binder.getCallingPid();
+
+ ICancellationSignal localCancelTransport = CancellationSignal.createTransport();
+
THREAD_POOL_EXECUTOR.execute(
() -> {
try {
@@ -132,12 +141,14 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
requestInternal,
callingUid,
callingPid,
+ localCancelTransport,
safeExecuteAppFunctionCallback);
} catch (Exception e) {
safeExecuteAppFunctionCallback.onResult(
mapExceptionToExecuteAppFunctionResponse(e));
}
});
+ return localCancelTransport;
}
@WorkerThread
@@ -145,6 +156,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
ExecuteAppFunctionAidlRequest requestInternal,
int callingUid,
int callingPid,
+ ICancellationSignal localCancelTransport,
SafeOneTimeExecuteAppFunctionCallback safeExecuteAppFunctionCallback) {
UserHandle targetUser = requestInternal.getUserHandle();
// TODO(b/354956319): Add and honor the new enterprise policies.
@@ -203,6 +215,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
requestInternal,
serviceIntent,
targetUser,
+ localCancelTransport,
safeExecuteAppFunctionCallback,
/* bindFlags= */ Context.BIND_AUTO_CREATE
| Context.BIND_FOREGROUND_SERVICE);
@@ -219,8 +232,19 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
@NonNull ExecuteAppFunctionAidlRequest requestInternal,
@NonNull Intent serviceIntent,
@NonNull UserHandle targetUser,
+ @NonNull ICancellationSignal cancellationSignalTransport,
@NonNull SafeOneTimeExecuteAppFunctionCallback safeExecuteAppFunctionCallback,
int bindFlags) {
+ CancellationSignal cancellationSignal =
+ CancellationSignal.fromTransport(cancellationSignalTransport);
+ ICancellationCallback cancellationCallback =
+ new ICancellationCallback.Stub() {
+ @Override
+ public void sendCancellationTransport(
+ @NonNull ICancellationSignal cancellationTransport) {
+ cancellationSignal.setRemote(cancellationTransport);
+ }
+ };
boolean bindServiceResult =
mRemoteServiceCaller.runServiceCall(
serviceIntent,
@@ -236,6 +260,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
try {
service.executeAppFunction(
requestInternal.getClientRequest(),
+ cancellationCallback,
new IExecuteAppFunctionCallback.Stub() {
@Override
public void onResult(
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index b2c679faed5d..f6ac706c4985 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -1444,7 +1444,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
* in {@link #allocateAppWidgetId}.
*
* @param callingPackage The package that calls this method.
- * @param appWidgetId The id of theapp widget to bind.
+ * @param appWidgetId The id of the widget to bind.
* @param providerProfileId The user/profile id of the provider.
* @param providerComponent The {@link ComponentName} that provides the widget.
* @param options The options to pass to the provider.
@@ -1738,6 +1738,14 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
return false;
}
+ /**
+ * Called by a {@link AppWidgetHost} to remove all records (i.e. {@link Host}
+ * and all {@link Widget} associated with the host) from a specified host.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param hostId id of the {@link Host}.
+ * @see AppWidgetHost#deleteHost()
+ */
@Override
public void deleteHost(String callingPackage, int hostId) {
final int userId = UserHandle.getCallingUserId();
@@ -1771,6 +1779,15 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Called by a host process to remove all records (i.e. {@link Host}
+ * and all {@link Widget} associated with the host) from all hosts associated
+ * with the calling process.
+ *
+ * Typically used in clean up after test execution.
+ *
+ * @see AppWidgetHost#deleteAllHosts()
+ */
@Override
public void deleteAllHosts() {
final int userId = UserHandle.getCallingUserId();
@@ -1805,6 +1822,18 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Returns the {@link AppWidgetProviderInfo} for the specified AppWidget.
+ *
+ * Typically used by launcher during the restore of an AppWidget, the binding
+ * of new AppWidget, and during grid size migration.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetId Id of the widget.
+ * @return The {@link AppWidgetProviderInfo} for the specified widget.
+ *
+ * @see AppWidgetManager#getAppWidgetInfo(int)
+ */
@Override
public AppWidgetProviderInfo getAppWidgetInfo(String callingPackage, int appWidgetId) {
final int userId = UserHandle.getCallingUserId();
@@ -1859,6 +1888,17 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Returns the most recent {@link RemoteViews} of the specified AppWidget.
+ * Typically serves as a cache of the content of the AppWidget.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetId Id of the widget.
+ * @return The {@link RemoteViews} of the specified widget.
+ *
+ * @see AppWidgetHost#updateAppWidgetDeferred(String, int)
+ * @see AppWidgetHost#setListener(int, AppWidgetHostListener)
+ */
@Override
public RemoteViews getAppWidgetViews(String callingPackage, int appWidgetId) {
final int userId = UserHandle.getCallingUserId();
@@ -1886,6 +1926,29 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Update the extras for a given widget instance.
+ * <p>
+ * The extras can be used to embed additional information about this widget to be accessed
+ * by the associated widget's AppWidgetProvider.
+ *
+ * <p>
+ * The new options are merged into existing options using {@link Bundle#putAll} semantics.
+ *
+ * <p>
+ * Typically called by a {@link AppWidgetHost} (e.g. Launcher) to notify
+ * {@link AppWidgetProvider} regarding contextual changes (e.g. sizes) when rendering the
+ * widget.
+ * Calling this method would trigger onAppWidgetOptionsChanged() callback on the provider's
+ * side.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetId Id of the widget.
+ * @param options New options associate with this widget.
+ *
+ * @see AppWidgetManager#getAppWidgetOptions(int, Bundle)
+ * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle)
+ */
@Override
public void updateAppWidgetOptions(String callingPackage, int appWidgetId, Bundle options) {
final int userId = UserHandle.getCallingUserId();
@@ -1919,6 +1982,21 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Get the extras associated with a given widget instance.
+ * <p>
+ * The extras can be used to embed additional information about this widget to be accessed
+ * by the associated widget's AppWidgetProvider.
+ *
+ * Typically called by a host process (e.g. Launcher) to determine if they need to update the
+ * options of the widget.
+ *
+ * @see #updateAppWidgetOptions(String, int, Bundle)
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetId Id of the widget.
+ * @return The options associated with the specified widget instance.
+ */
@Override
public Bundle getAppWidgetOptions(String callingPackage, int appWidgetId) {
final int userId = UserHandle.getCallingUserId();
@@ -1946,6 +2024,28 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Updates the content of the widgets (as specified by appWidgetIds) using the provided
+ * {@link RemoteViews}.
+ *
+ * Typically called by the provider's process. Either in response to the invocation of
+ * {@link AppWidgetProvider#onUpdate} or upon receiving the
+ * {@link AppWidgetManager#ACTION_APPWIDGET_UPDATE} broadcast.
+ *
+ * <p>
+ * Note that the RemoteViews parameter will be cached by the AppWidgetService, and hence should
+ * contain a complete representation of the widget. For performing partial widget updates, see
+ * {@link #partiallyUpdateAppWidgetIds(String, int[], RemoteViews)}.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetIds Ids of the widgets to be updated.
+ * @param views The RemoteViews object containing the update.
+ *
+ * @see AppWidgetProvider#onUpdate(Context, AppWidgetManager, int[])
+ * @see AppWidgetManager#ACTION_APPWIDGET_UPDATE
+ * @see AppWidgetManager#updateAppWidget(int, RemoteViews)
+ * @see AppWidgetManager#updateAppWidget(int[], RemoteViews)
+ */
@Override
public void updateAppWidgetIds(String callingPackage, int[] appWidgetIds,
RemoteViews views) {
@@ -1956,6 +2056,27 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
updateAppWidgetIds(callingPackage, appWidgetIds, views, false);
}
+ /**
+ * Perform an incremental update or command on the widget(s) specified by appWidgetIds.
+ * <p>
+ * This update differs from {@link #updateAppWidgetIds(int[], RemoteViews)} in that the
+ * RemoteViews object which is passed is understood to be an incomplete representation of the
+ * widget, and hence does not replace the cached representation of the widget. As of API
+ * level 17, the new properties set within the views objects will be appended to the cached
+ * representation of the widget, and hence will persist.
+ *
+ * <p>
+ * This method will be ignored if a widget has not received a full update via
+ * {@link #updateAppWidget(int[], RemoteViews)}.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetIds Ids of the widgets to be updated.
+ * @param views The RemoteViews object containing the incremental update / command.
+ *
+ * @see AppWidgetManager#partiallyUpdateAppWidget(int[], RemoteViews)
+ * @see RemoteViews#setDisplayedChild(int, int)
+ * @see RemoteViews#setScrollPosition(int, int)
+ */
@Override
public void partiallyUpdateAppWidgetIds(String callingPackage, int[] appWidgetIds,
RemoteViews views) {
@@ -1966,6 +2087,24 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
updateAppWidgetIds(callingPackage, appWidgetIds, views, true);
}
+ /**
+ * Callback function which marks specified providers as extended from AppWidgetProvider.
+ *
+ * This information is used to determine if the system can combine
+ * {@link AppWidgetManager#ACTION_APPWIDGET_ENABLED} and
+ * {@link AppWidgetManager#ACTION_APPWIDGET_UPDATE} into a single broadcast.
+ *
+ * Note: The system can only combine the two broadcasts if the provider is extended from
+ * AppWidgetProvider. When they do, they are expected to override the
+ * {@link AppWidgetProvider#onUpdate} callback function to provide updates, as opposed to
+ * listening for {@link AppWidgetManager#ACTION_APPWIDGET_UPDATE} broadcasts directly.
+ *
+ * @see AppWidgetManager#ACTION_APPWIDGET_ENABLED
+ * @see AppWidgetManager#ACTION_APPWIDGET_UPDATE
+ * @see AppWidgetManager#ACTION_APPWIDGET_ENABLE_AND_UPDATE
+ * @see AppWidgetProvider#onReceive(Context, Intent)
+ * @see #sendEnableAndUpdateIntentLocked
+ */
@Override
public void notifyProviderInheritance(@Nullable final ComponentName[] componentNames) {
final int userId = UserHandle.getCallingUserId();
@@ -2000,6 +2139,15 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Notifies the specified collection view in all the specified AppWidget instances
+ * to invalidate their data.
+ *
+ * This method is effectively deprecated since
+ * {@link RemoteViews#setRemoteAdapter(int, Intent)} has been deprecated.
+ *
+ * @see AppWidgetManager#notifyAppWidgetViewDataChanged(int[], int)
+ */
@Override
public void notifyAppWidgetViewDataChanged(String callingPackage, int[] appWidgetIds,
int viewId) {
@@ -2035,6 +2183,18 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Updates the content of all widgets associated with given provider (as specified by
+ * componentName) using the provided {@link RemoteViews}.
+ *
+ * Typically called by the provider's process when there's an update that needs to be supplied
+ * to all instances of the widgets.
+ *
+ * @param componentName The component name of the provider.
+ * @param views The RemoteViews object containing the update.
+ *
+ * @see AppWidgetManager#updateAppWidget(ComponentName, RemoteViews)
+ */
@Override
public void updateAppWidgetProvider(ComponentName componentName, RemoteViews views) {
final int userId = UserHandle.getCallingUserId();
@@ -2068,6 +2228,27 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Updates the info for the supplied AppWidget provider. Apps can use this to change the default
+ * behavior of the widget based on the state of the app (e.g., if the user is logged in
+ * or not). Calling this API completely replaces the previous definition.
+ *
+ * <p>
+ * The manifest entry of the provider should contain an additional meta-data tag similar to
+ * {@link AppWidgetManager#META_DATA_APPWIDGET_PROVIDER} which should point to any alternative
+ * definitions for the provider.
+ *
+ * <p>
+ * This is persisted across device reboots and app updates. If this meta-data key is not
+ * present in the manifest entry, the info reverts to default.
+ *
+ * @param provider {@link ComponentName} for the {@link
+ * android.content.BroadcastReceiver BroadcastReceiver} provider for your AppWidget.
+ * @param metaDataKey key for the meta-data tag pointing to the new provider info. Use null
+ * to reset any previously set info.
+ *
+ * @see AppWidgetManager#updateAppWidgetProviderInfo(ComponentName, String)
+ */
@Override
public void updateAppWidgetProviderInfo(ComponentName componentName, String metadataKey) {
final int userId = UserHandle.getCallingUserId();
@@ -2119,6 +2300,11 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Returns true if the default launcher app on the device (the one that currently
+ * holds the android.app.role.HOME role) can support pinning widgets
+ * (typically means adding widgets into home screen).
+ */
@Override
public boolean isRequestPinAppWidgetSupported() {
synchronized (mLock) {
@@ -2133,6 +2319,44 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
LauncherApps.PinItemRequest.REQUEST_TYPE_APPWIDGET);
}
+ /**
+ * Request to pin an app widget on the current launcher. It's up to the launcher to accept this
+ * request (optionally showing a user confirmation). If the request is accepted, the caller will
+ * get a confirmation with extra {@link #EXTRA_APPWIDGET_ID}.
+ *
+ * <p>When a request is denied by the user, the caller app will not get any response.
+ *
+ * <p>Only apps with a foreground activity or a foreground service can call it. Otherwise
+ * it'll throw {@link IllegalStateException}.
+ *
+ * <p>It's up to the launcher how to handle previous pending requests when the same package
+ * calls this API multiple times in a row. It may ignore the previous requests,
+ * for example.
+ *
+ * <p>Launcher will not show the configuration activity associated with the provider in this
+ * case. The app could either show the configuration activity as a response to the callback,
+ * or show if before calling the API (various configurations can be encapsulated in
+ * {@code successCallback} to avoid persisting them before the widgetId is known).
+ *
+ * @param provider The {@link ComponentName} for the {@link
+ * android.content.BroadcastReceiver BroadcastReceiver} provider for your AppWidget.
+ * @param extras If not null, this is passed to the launcher app. For eg {@link
+ * #EXTRA_APPWIDGET_PREVIEW} can be used for a custom preview.
+ * @param successCallback If not null, this intent will be sent when the widget is created.
+ *
+ * @return {@code TRUE} if the launcher supports this feature. Note the API will return without
+ * waiting for the user to respond, so getting {@code TRUE} from this API does *not* mean
+ * the shortcut is pinned. {@code FALSE} if the launcher doesn't support this feature or if
+ * calling app belongs to a user-profile with items restricted on home screen.
+ *
+ * @see android.content.pm.ShortcutManager#isRequestPinShortcutSupported()
+ * @see android.content.pm.ShortcutManager#requestPinShortcut(ShortcutInfo, IntentSender)
+ * @see AppWidgetManager#isRequestPinAppWidgetSupported()
+ * @see AppWidgetManager#requestPinAppWidget(ComponentName, Bundle, PendingIntent)
+ *
+ * @throws IllegalStateException The caller doesn't have a foreground activity or a foreground
+ * service or when the user is locked.
+ */
@Override
public boolean requestPinAppWidget(String callingPackage, ComponentName componentName,
Bundle extras, IntentSender resultSender) {
@@ -2184,6 +2408,24 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
callingPid, callingUid) == PackageManager.PERMISSION_GRANTED;
}
+ /**
+ * Gets the AppWidget providers for the given user profile. User profile can only
+ * be the current user or a profile of the current user. For example, the current
+ * user may have a corporate profile. In this case the parent user profile has a
+ * child profile, the corporate one.
+ *
+ * @param categoryFilter Will only return providers which register as any of the specified
+ * specified categories. See {@link AppWidgetProviderInfo#widgetCategory}.
+ * @param profile A profile of the current user which to be queried. The user
+ * is itself also a profile. If null, the providers only for the current user
+ * are returned.
+ * @param packageName If specified, will only return providers from the given package.
+ * @return The installed providers.
+ *
+ * @see android.os.Process#myUserHandle()
+ * @see android.os.UserManager#getUserProfiles()
+ * @see AppWidgetManager#getInstalledProvidersForProfile(int, UserHandle, String)
+ */
@Override
public ParceledListSlice<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter,
int profileId, String packageName) {
@@ -2244,6 +2486,26 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Updates the content of the widgets (as specified by appWidgetIds) using the provided
+ * {@link RemoteViews}.
+ *
+ * If performing a partial update, the given RemoteViews object is merged into existing
+ * RemoteViews object.
+ *
+ * Fails silently if appWidgetIds is null or empty, or cannot found a widget with the given
+ * appWidgetId.
+ *
+ * @param callingPackage The package that calls this method.
+ * @param appWidgetIds Ids of the widgets to be updated.
+ * @param views The RemoteViews object containing the update.
+ * @param partially Whether it was a partial update.
+ *
+ * @see AppWidgetProvider#onUpdate(Context, AppWidgetManager, int[])
+ * @see AppWidgetManager#ACTION_APPWIDGET_UPDATE
+ * @see AppWidgetManager#updateAppWidget(int, RemoteViews)
+ * @see AppWidgetManager#updateAppWidget(int[], RemoteViews)
+ */
private void updateAppWidgetIds(String callingPackage, int[] appWidgetIds,
RemoteViews views, boolean partially) {
final int userId = UserHandle.getCallingUserId();
@@ -2273,12 +2535,29 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
+ /**
+ * Increment the counter of widget ids and return the new id.
+ *
+ * Typically called by {@link #allocateAppWidgetId} when a instance of widget is created,
+ * either as a result of being pinned by launcher or added during a restore.
+ *
+ * Note: A widget id is a monotonically increasing integer that uniquely identifies the widget
+ * instance.
+ *
+ * TODO: Revisit this method and determine whether we need to alter the widget id during
+ * the restore since widget id mismatch potentially leads to some issues in the past.
+ */
private int incrementAndGetAppWidgetIdLocked(int userId) {
final int appWidgetId = peekNextAppWidgetIdLocked(userId) + 1;
mNextAppWidgetIds.put(userId, appWidgetId);
return appWidgetId;
}
+ /**
+ * Called by {@link #readProfileStateFromFileLocked} when widgets/providers/hosts are loaded
+ * from disk, which ensures mNextAppWidgetIds is larger than any existing widget id for given
+ * user.
+ */
private void setMinAppWidgetIdLocked(int userId, int minWidgetId) {
final int nextAppWidgetId = peekNextAppWidgetIdLocked(userId);
if (nextAppWidgetId < minWidgetId) {
diff --git a/services/core/java/android/os/BatteryStatsInternal.java b/services/core/java/android/os/BatteryStatsInternal.java
index 0713999d4354..60b826b50045 100644
--- a/services/core/java/android/os/BatteryStatsInternal.java
+++ b/services/core/java/android/os/BatteryStatsInternal.java
@@ -41,6 +41,7 @@ public abstract class BatteryStatsInternal {
public static final int CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER = 3;
public static final int CPU_WAKEUP_SUBSYSTEM_SENSOR = 4;
public static final int CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA = 5;
+ public static final int CPU_WAKEUP_SUBSYSTEM_BLUETOOTH = 6;
/** @hide */
@IntDef(prefix = {"CPU_WAKEUP_SUBSYSTEM_"}, value = {
@@ -50,6 +51,7 @@ public abstract class BatteryStatsInternal {
CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER,
CPU_WAKEUP_SUBSYSTEM_SENSOR,
CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA,
+ CPU_WAKEUP_SUBSYSTEM_BLUETOOTH,
})
@Retention(RetentionPolicy.SOURCE)
public @interface CpuWakeupSubsystem {
@@ -99,6 +101,14 @@ public abstract class BatteryStatsInternal {
public abstract void noteCpuWakingNetworkPacket(Network network, long elapsedMillis, int uid);
/**
+ * Informs battery stats of a sysproxy packet that woke up the CPU
+ *
+ * @param uid The uid that received the packet.
+ * @param elapsedMillis The time of the packet's arrival in elapsed timebase.
+ */
+ public abstract void noteCpuWakingBluetoothProxyPacket(int uid, long elapsedMillis);
+
+ /**
* Informs battery stats of binder stats for the given work source UID.
*/
public abstract void noteBinderCallStats(int workSourceUid, long incrementalBinderCallCount,
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index d86bae19f174..e64a4803b14f 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -219,7 +219,7 @@ class StorageManagerService extends IStorageManager.Stub
public static final int FAILED_MOUNT_RESET_TIMEOUT_SECONDS = 10;
/** Extended timeout for the system server watchdog. */
- private static final int SLOW_OPERATION_WATCHDOG_TIMEOUT_MS = 20 * 1000;
+ private static final int SLOW_OPERATION_WATCHDOG_TIMEOUT_MS = 30 * 1000;
/** Extended timeout for the system server watchdog for vold#partition operation. */
private static final int PARTITION_OPERATION_WATCHDOG_TIMEOUT_MS = 3 * 60 * 1000;
@@ -3251,7 +3251,7 @@ class StorageManagerService extends IStorageManager.Stub
if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
throw new SecurityException("no permission to commit checkpoint changes");
}
-
+ extendWatchdogTimeout("vold#commitChanges might be slow");
mVold.commitChanges();
}
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
index 88edb121c0c8..3499a3a5edde 100644
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -1773,8 +1773,7 @@ public class AccountManagerService
// Create a Session for the target user and pass in the bundle
completeCloningAccount(response, result, account, toAccounts, userFrom);
} else {
- // Bundle format is not defined.
- super.onResultSkipSanitization(result);
+ super.onResult(result);
}
}
}.bind();
@@ -1861,8 +1860,7 @@ public class AccountManagerService
// account to avoid retries?
// TODO: what we do with the visibility?
- // Bundle format is not defined.
- super.onResultSkipSanitization(result);
+ super.onResult(result);
}
@Override
@@ -2108,7 +2106,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
IAccountManagerResponse response = getResponseAndClose();
if (response != null) {
try {
@@ -2462,7 +2459,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT)
&& !result.containsKey(AccountManager.KEY_INTENT)) {
final boolean removalAllowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
@@ -2977,7 +2973,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
if (result != null) {
String label = result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL);
Bundle bundle = new Bundle();
@@ -3155,7 +3150,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
if (result != null) {
if (result.containsKey(AccountManager.KEY_AUTH_TOKEN_LABEL)) {
Intent intent = newGrantCredentialsPermissionIntent(
@@ -3627,12 +3621,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- Bundle sessionBundle = null;
- if (result != null) {
- // Session bundle will be removed from result.
- sessionBundle = result.getBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE);
- }
- result = sanitizeBundle(result);
mNumResults++;
Intent intent = null;
if (result != null) {
@@ -3694,6 +3682,7 @@ public class AccountManagerService
// bundle contains data necessary for finishing the session
// later. The session bundle will be encrypted here and
// decrypted later when trying to finish the session.
+ Bundle sessionBundle = result.getBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE);
if (sessionBundle != null) {
String accountType = sessionBundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
if (TextUtils.isEmpty(accountType)
@@ -4081,7 +4070,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
IAccountManagerResponse response = getResponseAndClose();
if (response == null) {
return;
@@ -4395,7 +4383,6 @@ public class AccountManagerService
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
mNumResults++;
if (result == null) {
onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle");
@@ -4952,68 +4939,6 @@ public class AccountManagerService
callback, resultReceiver);
}
-
- // All keys for Strings passed from AbstractAccountAuthenticator using Bundle.
- private static final String[] sStringBundleKeys = new String[] {
- AccountManager.KEY_ACCOUNT_NAME,
- AccountManager.KEY_ACCOUNT_TYPE,
- AccountManager.KEY_AUTHTOKEN,
- AccountManager.KEY_AUTH_TOKEN_LABEL,
- AccountManager.KEY_ERROR_MESSAGE,
- AccountManager.KEY_PASSWORD,
- AccountManager.KEY_ACCOUNT_STATUS_TOKEN};
-
- /**
- * Keep only documented fields in a Bundle received from AbstractAccountAuthenticator.
- */
- protected static Bundle sanitizeBundle(Bundle bundle) {
- if (bundle == null) {
- return null;
- }
- Bundle sanitizedBundle = new Bundle();
- Bundle.setDefusable(sanitizedBundle, true);
- int updatedKeysCount = 0;
- for (String stringKey : sStringBundleKeys) {
- if (bundle.containsKey(stringKey)) {
- String value = bundle.getString(stringKey);
- sanitizedBundle.putString(stringKey, value);
- updatedKeysCount++;
- }
- }
- String key = AbstractAccountAuthenticator.KEY_CUSTOM_TOKEN_EXPIRY;
- if (bundle.containsKey(key)) {
- long expiryMillis = bundle.getLong(key, 0L);
- sanitizedBundle.putLong(key, expiryMillis);
- updatedKeysCount++;
- }
- key = AccountManager.KEY_BOOLEAN_RESULT;
- if (bundle.containsKey(key)) {
- boolean booleanResult = bundle.getBoolean(key, false);
- sanitizedBundle.putBoolean(key, booleanResult);
- updatedKeysCount++;
- }
- key = AccountManager.KEY_ERROR_CODE;
- if (bundle.containsKey(key)) {
- int errorCode = bundle.getInt(key, 0);
- sanitizedBundle.putInt(key, errorCode);
- updatedKeysCount++;
- }
- key = AccountManager.KEY_INTENT;
- if (bundle.containsKey(key)) {
- Intent intent = bundle.getParcelable(key, Intent.class);
- sanitizedBundle.putParcelable(key, intent);
- updatedKeysCount++;
- }
- if (bundle.containsKey(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE)) {
- // The field is not copied in sanitized bundle.
- updatedKeysCount++;
- }
- if (updatedKeysCount != bundle.size()) {
- Log.w(TAG, "Size mismatch after sanitizeBundle call.");
- }
- return sanitizedBundle;
- }
-
private abstract class Session extends IAccountAuthenticatorResponse.Stub
implements IBinder.DeathRecipient, ServiceConnection {
private final Object mSessionLock = new Object();
@@ -5304,15 +5229,10 @@ public class AccountManagerService
}
}
}
+
@Override
public void onResult(Bundle result) {
Bundle.setDefusable(result, true);
- result = sanitizeBundle(result);
- onResultSkipSanitization(result);
- }
-
- public void onResultSkipSanitization(Bundle result) {
- Bundle.setDefusable(result, true);
mNumResults++;
Intent intent = null;
if (result != null) {
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index ad72941595d7..35323d6cb391 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -262,6 +262,7 @@ import android.appwidget.AppWidgetManagerInternal;
import android.content.AttributionSource;
import android.content.AutofillOptions;
import android.content.BroadcastReceiver;
+import android.content.ClipData;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentCaptureOptions;
@@ -419,7 +420,6 @@ import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.MemInfoReader;
import com.android.internal.util.Preconditions;
-import com.android.server.crashrecovery.CrashRecoveryHelper;
import com.android.server.AlarmManagerInternal;
import com.android.server.BootReceiver;
import com.android.server.DeviceIdleInternal;
@@ -439,6 +439,7 @@ import com.android.server.am.LowMemDetector.MemFactor;
import com.android.server.appop.AppOpsService;
import com.android.server.compat.PlatformCompat;
import com.android.server.contentcapture.ContentCaptureManagerInternal;
+import com.android.server.crashrecovery.CrashRecoveryHelper;
import com.android.server.criticalevents.CriticalEventLog;
import com.android.server.firewall.IntentFirewall;
import com.android.server.graphics.fonts.FontManagerInternal;
@@ -483,6 +484,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
@@ -500,6 +502,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@@ -19097,4 +19100,87 @@ public class ActivityManagerService extends IActivityManager.Stub
Freezer getFreezer() {
return mFreezer;
}
+
+ // Set of IntentCreatorToken objects that are currently active.
+ private static final Map<IntentCreatorToken.Key, WeakReference<IntentCreatorToken>>
+ sIntentCreatorTokenCache = new ConcurrentHashMap<>();
+
+ /**
+ * A binder token used to keep track of which app created the intent. This token can be used to
+ * defend against intent redirect attacks. It stores uid of the intent creator and key fields of
+ * the intent to make it impossible for attacker to fake uid with a malicious intent.
+ *
+ * @hide
+ */
+ public static final class IntentCreatorToken extends Binder {
+ @NonNull
+ private final Key mKeyFields;
+
+ public IntentCreatorToken(int creatorUid, Intent intent) {
+ super();
+ this.mKeyFields = new Key(creatorUid, intent);
+ }
+
+ public int getCreatorUid() {
+ return mKeyFields.mCreatorUid;
+ }
+
+ /** {@hide} */
+ public static boolean isValid(@NonNull Intent intent) {
+ IBinder binder = intent.getCreatorToken();
+ IntentCreatorToken token = null;
+ if (binder instanceof IntentCreatorToken) {
+ token = (IntentCreatorToken) binder;
+ }
+ return token != null && token.mKeyFields.equals(
+ new Key(token.mKeyFields.mCreatorUid, intent));
+ }
+
+ private static class Key {
+ private Key(int creatorUid, Intent intent) {
+ this.mCreatorUid = creatorUid;
+ this.mAction = intent.getAction();
+ this.mData = intent.getData();
+ this.mType = intent.getType();
+ this.mPackage = intent.getPackage();
+ this.mComponent = intent.getComponent();
+ this.mFlags = intent.getFlags() & Intent.IMMUTABLE_FLAGS;
+ ClipData clipData = intent.getClipData();
+ if (clipData != null) {
+ this.mClipDataUris = new ArrayList<>(clipData.getItemCount());
+ for (int i = 0; i < clipData.getItemCount(); i++) {
+ this.mClipDataUris.add(clipData.getItemAt(i).getUri());
+ }
+ }
+ }
+
+ private final int mCreatorUid;
+ private final String mAction;
+ private final Uri mData;
+ private final String mType;
+ private final String mPackage;
+ private final ComponentName mComponent;
+ private final int mFlags;
+ private List<Uri> mClipDataUris;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Key key = (Key) o;
+ return mCreatorUid == key.mCreatorUid && mFlags == key.mFlags && Objects.equals(
+ mAction, key.mAction) && Objects.equals(mData, key.mData)
+ && Objects.equals(mType, key.mType) && Objects.equals(mPackage,
+ key.mPackage) && Objects.equals(mComponent, key.mComponent)
+ && Objects.equals(mClipDataUris, key.mClipDataUris);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mCreatorUid, mAction, mData, mType, mPackage, mComponent,
+ mFlags,
+ mClipDataUris);
+ }
+ }
+ }
}
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index 15277cebac6e..ef82c7477558 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -664,6 +664,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
} else if (nc.hasTransport(TRANSPORT_CELLULAR)) {
return CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA;
}
+ // For TRANSPORT_BLUETOOTH, we have a separate channel to catch Bluetooth wakeups.
+ // See noteCpuWakingSysproxyPacket method.
return CPU_WAKEUP_SUBSYSTEM_UNKNOWN;
}
@@ -686,6 +688,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
@Override
+ public void noteCpuWakingBluetoothProxyPacket(int uid, long elapsedMillis) {
+ if (uid < 0) {
+ Slog.e(TAG, "Invalid uid for waking bluetooth proxy packet: " + uid);
+ return;
+ }
+ noteCpuWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH, elapsedMillis, uid);
+ }
+
+ @Override
public void noteBinderCallStats(int workSourceUid, long incrementatCallCount,
Collection<BinderCallsStats.CallStat> callStats) {
synchronized (BatteryStatsService.this.mLock) {
diff --git a/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java b/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
index a13ce654bb95..bae9a670c438 100644
--- a/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
+++ b/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
@@ -40,6 +40,7 @@ import android.aconfigd.Aconfigd.StorageRequestMessages;
import android.aconfigd.Aconfigd.StorageReturnMessage;
import android.aconfigd.Aconfigd.StorageReturnMessages;
import static com.android.aconfig_new_storage.Flags.enableAconfigStorageDaemon;
+import static com.android.aconfig_new_storage.Flags.supportImmediateLocalOverrides;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -491,14 +492,18 @@ public class SettingsToPropertiesMapper {
static void writeFlagOverrideRequest(
ProtoOutputStream proto, String packageName, String flagName, String flagValue,
boolean isLocal) {
+ int localOverrideTag = supportImmediateLocalOverrides()
+ ? StorageRequestMessage.LOCAL_IMMEDIATE
+ : StorageRequestMessage.LOCAL_ON_REBOOT;
+
long msgsToken = proto.start(StorageRequestMessages.MSGS);
long msgToken = proto.start(StorageRequestMessage.FLAG_OVERRIDE_MESSAGE);
proto.write(StorageRequestMessage.FlagOverrideMessage.PACKAGE_NAME, packageName);
proto.write(StorageRequestMessage.FlagOverrideMessage.FLAG_NAME, flagName);
proto.write(StorageRequestMessage.FlagOverrideMessage.FLAG_VALUE, flagValue);
proto.write(StorageRequestMessage.FlagOverrideMessage.OVERRIDE_TYPE, isLocal
- ? StorageRequestMessage.LOCAL_ON_REBOOT
- : StorageRequestMessage.SERVER_ON_REBOOT);
+ ? localOverrideTag
+ : StorageRequestMessage.SERVER_ON_REBOOT);
proto.end(msgToken);
proto.end(msgsToken);
}
diff --git a/services/core/java/com/android/server/am/flags.aconfig b/services/core/java/com/android/server/am/flags.aconfig
index 9b51b6ae4b0f..4f6da3baca12 100644
--- a/services/core/java/com/android/server/am/flags.aconfig
+++ b/services/core/java/com/android/server/am/flags.aconfig
@@ -205,4 +205,12 @@ flag {
metadata {
purpose: PURPOSE_BUGFIX
}
-} \ No newline at end of file
+}
+
+flag {
+ name: "defer_display_events_when_frozen"
+ namespace: "system_performance"
+ is_fixed_read_only: true
+ description: "Defer submitting display events to frozen processes."
+ bug: "326315985"
+}
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index a6389f7f5311..e0cf96fbccd0 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -1031,6 +1031,9 @@ public class AppOpsService extends IAppOpsService.Stub {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
+ if (action == null) {
+ return;
+ }
String pkgName = intent.getData().getEncodedSchemeSpecificPart().intern();
int uid = intent.getIntExtra(Intent.EXTRA_UID, Process.INVALID_UID);
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index ae33b83b49dc..1f9eb082aaf4 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -3377,10 +3377,18 @@ public final class DisplayManagerService extends SystemService {
private void dumpInternal(PrintWriter pw) {
pw.println("DISPLAY MANAGER (dumpsys display)");
BrightnessTracker brightnessTrackerLocal;
+ SparseArray<DisplayPowerController> displayPowerControllersLocal = new SparseArray<>();
+ int displayPowerControllerCount;
synchronized (mSyncRoot) {
brightnessTrackerLocal = mBrightnessTracker;
+ displayPowerControllerCount = mDisplayPowerControllers.size();
+ for (int i = 0; i < displayPowerControllerCount; i++) {
+ displayPowerControllersLocal.put(
+ mDisplayPowerControllers.keyAt(i), mDisplayPowerControllers.valueAt(i));
+ }
+
pw.println(" mSafeMode=" + mSafeMode);
pw.println(" mPendingTraversal=" + mPendingTraversal);
pw.println(" mViewports=" + mViewports);
@@ -3451,13 +3459,6 @@ public final class DisplayManagerService extends SystemService {
+ ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
}
- final int displayPowerControllerCount = mDisplayPowerControllers.size();
- pw.println();
- pw.println("Display Power Controllers: size=" + displayPowerControllerCount);
- for (int i = 0; i < displayPowerControllerCount; i++) {
- mDisplayPowerControllers.valueAt(i).dump(pw);
- }
-
pw.println();
mPersistentDataStore.dump(pw);
@@ -3470,6 +3471,12 @@ public final class DisplayManagerService extends SystemService {
mDisplayWindowPolicyControllers.valueAt(i).second.dump(" ", pw);
}
}
+ pw.println();
+ pw.println("Display Power Controllers: size=" + displayPowerControllerCount);
+ for (int i = 0; i < displayPowerControllerCount; i++) {
+ displayPowerControllersLocal.valueAt(i).dump(pw);
+ }
+
if (brightnessTrackerLocal != null) {
pw.println();
brightnessTrackerLocal.dump(pw);
@@ -5293,6 +5300,17 @@ public final class DisplayManagerService extends SystemService {
}
@Override
+ public IntArray getDisplayIds() {
+ IntArray displayIds = new IntArray();
+ synchronized (mSyncRoot) {
+ mLogicalDisplayMapper.forEachLocked((logicalDisplay -> {
+ displayIds.add(logicalDisplay.getDisplayIdLocked());
+ }), /* includeDisabled= */ false);
+ }
+ return displayIds;
+ }
+
+ @Override
public DisplayManagerInternal.DisplayOffloadSession registerDisplayOffloader(
int displayId, @NonNull DisplayManagerInternal.DisplayOffloader displayOffloader) {
if (!mFlags.isDisplayOffloadEnabled()) {
diff --git a/services/core/java/com/android/server/flags/pinner.aconfig b/services/core/java/com/android/server/flags/pinner.aconfig
index 2f817dbb9a7f..345366882d5a 100644
--- a/services/core/java/com/android/server/flags/pinner.aconfig
+++ b/services/core/java/com/android/server/flags/pinner.aconfig
@@ -9,8 +9,11 @@ flag {
}
flag {
- name: "skip_home_art_pins"
- namespace: "system_performance"
- description: "Ablation study flag that controls if home app odex/vdex files should be pinned in memory."
- bug: "340935152"
-} \ No newline at end of file
+ name: "pin_global_quota"
+ namespace: "system_performance"
+ description: "This flag controls whether pinner will use a global quota or not"
+ bug: "340935152"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/services/core/java/com/android/server/input/InputManagerInternal.java b/services/core/java/com/android/server/input/InputManagerInternal.java
index 92812670057a..99f7f12567b4 100644
--- a/services/core/java/com/android/server/input/InputManagerInternal.java
+++ b/services/core/java/com/android/server/input/InputManagerInternal.java
@@ -23,6 +23,7 @@ import android.graphics.PointF;
import android.hardware.display.DisplayViewport;
import android.hardware.input.KeyGestureEvent;
import android.os.IBinder;
+import android.util.SparseBooleanArray;
import android.view.InputChannel;
import android.view.inputmethod.InputMethodSubtype;
@@ -45,9 +46,11 @@ public abstract class InputManagerInternal {
/**
* Called by the power manager to tell the input manager whether it should start
- * watching for wake events.
+ * watching for wake events on given displays.
+ *
+ * @param displayInteractivities Map of display ids to their current interactive state.
*/
- public abstract void setInteractive(boolean interactive);
+ public abstract void setDisplayInteractivities(SparseBooleanArray displayInteractivities);
/**
* Toggles Caps Lock state for input device with specific id.
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 909c47bc9359..f04557665477 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -96,6 +96,7 @@ import android.os.vibrator.VibrationEffectSegment;
import android.provider.DeviceConfig;
import android.text.TextUtils;
import android.util.ArrayMap;
+import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
@@ -3337,10 +3338,22 @@ public class InputManagerService extends IInputManager.Stub
}
@Override
- public void setInteractive(boolean interactive) {
- mNative.setInteractive(interactive);
- mBatteryController.onInteractiveChanged(interactive);
- mKeyboardBacklightController.onInteractiveChanged(interactive);
+ public void setDisplayInteractivities(SparseBooleanArray displayInteractivities) {
+ boolean globallyInteractive = false;
+ ArraySet<Integer> nonInteractiveDisplays = new ArraySet<>();
+ for (int i = 0; i < displayInteractivities.size(); i++) {
+ final int displayId = displayInteractivities.keyAt(i);
+ final boolean displayInteractive = displayInteractivities.get(displayId);
+ if (displayInteractive) {
+ globallyInteractive = true;
+ } else {
+ nonInteractiveDisplays.add(displayId);
+ }
+ }
+ mNative.setNonInteractiveDisplays(
+ nonInteractiveDisplays.stream().mapToInt(Integer::intValue).toArray());
+ mBatteryController.onInteractiveChanged(globallyInteractive);
+ mKeyboardBacklightController.onInteractiveChanged(globallyInteractive);
}
// TODO(b/358569822): Remove this method from InputManagerInternal after key gesture
diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java
index d17e256e34fc..4404d63e02fc 100644
--- a/services/core/java/com/android/server/input/NativeInputManagerService.java
+++ b/services/core/java/com/android/server/input/NativeInputManagerService.java
@@ -141,7 +141,7 @@ interface NativeInputManagerService {
void setShowTouches(boolean enabled);
- void setInteractive(boolean interactive);
+ void setNonInteractiveDisplays(int[] displayIds);
void reloadCalibration();
@@ -409,7 +409,7 @@ interface NativeInputManagerService {
public native void setShowTouches(boolean enabled);
@Override
- public native void setInteractive(boolean interactive);
+ public native void setNonInteractiveDisplays(int[] displayIds);
@Override
public native void reloadCalibration();
diff --git a/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java b/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java
index 41313fa1fb2c..ef1220fb1786 100644
--- a/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java
+++ b/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java
@@ -33,9 +33,6 @@ final class HardwareKeyboardShortcutController {
@GuardedBy("ImfLock.class")
private final ArrayList<InputMethodSubtypeHandle> mSubtypeHandles = new ArrayList<>();
- HardwareKeyboardShortcutController() {
- }
-
@GuardedBy("ImfLock.class")
void update(@NonNull InputMethodSettings settings) {
mSubtypeHandles.clear();
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java b/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java
index 6cd2493cfdff..fc4c0fc798db 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodDeviceConfigs.java
@@ -40,6 +40,7 @@ final class InputMethodDeviceConfigs {
if (KEY_HIDE_IME_WHEN_NO_EDITOR_FOCUS.equals(name)) {
mHideImeWhenNoEditorFocus = properties.getBoolean(name,
true /* defaultValue */);
+ break;
}
}
};
diff --git a/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java b/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java
index 214aa1d904fa..49d4332d9e2a 100644
--- a/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java
+++ b/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java
@@ -394,6 +394,7 @@ final class ZeroJankProxy implements IInputMethodManagerImpl.Callback {
flags),
this::offload).get();
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
diff --git a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
index 48d24f2e14dd..47f579db604f 100644
--- a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
+++ b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
@@ -195,10 +195,9 @@ public final class MediaProjectionManagerService extends SystemService
== PackageManager.PERMISSION_GRANTED) {
return true;
}
- boolean operationActive = mAppOps.isOperationActive(AppOpsManager.OP_PROJECT_MEDIA,
- mProjectionGrant.uid,
- mProjectionGrant.packageName);
- if (operationActive) {
+ if (AppOpsManager.MODE_ALLOWED == mAppOps.noteOpNoThrow(AppOpsManager.OP_PROJECT_MEDIA,
+ mProjectionGrant.uid, mProjectionGrant.packageName, /* attributionTag= */ null,
+ "recording lockscreen")) {
// Some tools use media projection by granting the OP_PROJECT_MEDIA app
// op via a shell command. Those tools can be granted keyguard capture
return true;
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index c3a714b0eef0..655f2e4596aa 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2579,6 +2579,7 @@ public class NotificationManagerService extends SystemService {
mNotificationChannelLogger,
mAppOps,
mUserProfiles,
+ mUgmInternal,
mShowReviewPermissionsNotification,
Clock.systemUTC());
mRankingHelper = new RankingHelper(getContext(), mRankingHandler, mPreferencesHelper,
@@ -6247,6 +6248,7 @@ public class NotificationManagerService extends SystemService {
int callingUid = Binder.getCallingUid();
@ZenModeConfig.ConfigOrigin int origin = computeZenOrigin(fromUser);
+ boolean isSystemCaller = isCallerSystemOrSystemUiOrShell();
boolean shouldApplyAsImplicitRule = android.app.Flags.modesApi()
&& !canManageGlobalZenPolicy(pkg, callingUid);
@@ -6283,11 +6285,33 @@ public class NotificationManagerService extends SystemService {
policy.priorityCallSenders, policy.priorityMessageSenders,
policy.suppressedVisualEffects, currPolicy.priorityConversationSenders);
}
+
int newVisualEffects = calculateSuppressedVisualEffects(
policy, currPolicy, applicationInfo.targetSdkVersion);
- policy = new Policy(policy.priorityCategories,
- policy.priorityCallSenders, policy.priorityMessageSenders,
- newVisualEffects, policy.priorityConversationSenders);
+
+ if (android.app.Flags.modesUi()) {
+ // 1. Callers should not modify STATE_CHANNELS_BYPASSING_DND, which is
+ // internally calculated and only indicates whether channels that want to bypass
+ // DND _exist_.
+ // 2. Only system callers should modify STATE_PRIORITY_CHANNELS_BLOCKED because
+ // it is @hide.
+ // 3. If the policy has been modified by the targetSdkVersion checks above then
+ // it has lost its state flags and that's fine (STATE_PRIORITY_CHANNELS_BLOCKED
+ // didn't exist until V).
+ int newState = Policy.STATE_UNSET;
+ if (isSystemCaller && policy.state != Policy.STATE_UNSET) {
+ newState = Policy.policyState(
+ currPolicy.hasPriorityChannels(),
+ policy.allowPriorityChannels());
+ }
+ policy = new Policy(policy.priorityCategories,
+ policy.priorityCallSenders, policy.priorityMessageSenders,
+ newVisualEffects, newState, policy.priorityConversationSenders);
+ } else {
+ policy = new Policy(policy.priorityCategories,
+ policy.priorityCallSenders, policy.priorityMessageSenders,
+ newVisualEffects, policy.priorityConversationSenders);
+ }
if (shouldApplyAsImplicitRule) {
mZenModeHelper.applyGlobalPolicyAsImplicitZenRule(pkg, callingUid, policy);
@@ -6672,13 +6696,7 @@ public class NotificationManagerService extends SystemService {
final Uri originalSoundUri =
(originalChannel != null) ? originalChannel.getSound() : null;
if (soundUri != null && !Objects.equals(originalSoundUri, soundUri)) {
- Binder.withCleanCallingIdentity(() -> {
- mUgmInternal.checkGrantUriPermission(sourceUid, null,
- ContentProvider.getUriWithoutUserId(soundUri),
- Intent.FLAG_GRANT_READ_URI_PERMISSION,
- ContentProvider.getUserIdFromUri(soundUri,
- UserHandle.getUserId(sourceUid)));
- });
+ PermissionHelper.grantUriPermission(mUgmInternal, soundUri, sourceUid);
}
}
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
index b9f0968b5864..3ba93845a290 100644
--- a/services/core/java/com/android/server/notification/NotificationRecord.java
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -1493,14 +1493,23 @@ public final class NotificationRecord {
final Notification notification = getNotification();
notification.visitUris((uri) -> {
- visitGrantableUri(uri, false, false);
+ if (com.android.server.notification.Flags.notificationVerifyChannelSoundUri()) {
+ visitGrantableUri(uri, false, false);
+ } else {
+ oldVisitGrantableUri(uri, false, false);
+ }
});
if (notification.getChannelId() != null) {
NotificationChannel channel = getChannel();
if (channel != null) {
- visitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
- & NotificationChannel.USER_LOCKED_SOUND) != 0, true);
+ if (com.android.server.notification.Flags.notificationVerifyChannelSoundUri()) {
+ visitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
+ & NotificationChannel.USER_LOCKED_SOUND) != 0, true);
+ } else {
+ oldVisitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
+ & NotificationChannel.USER_LOCKED_SOUND) != 0, true);
+ }
}
}
} finally {
@@ -1516,7 +1525,7 @@ public final class NotificationRecord {
* {@link #mGrantableUris}. Otherwise, this will either log or throw
* {@link SecurityException} depending on target SDK of enqueuing app.
*/
- private void visitGrantableUri(Uri uri, boolean userOverriddenUri, boolean isSound) {
+ private void oldVisitGrantableUri(Uri uri, boolean userOverriddenUri, boolean isSound) {
if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) return;
if (mGrantableUris != null && mGrantableUris.contains(uri)) {
@@ -1555,6 +1564,45 @@ public final class NotificationRecord {
}
}
+ /**
+ * Note the presence of a {@link Uri} that should have permission granted to
+ * whoever will be rendering it.
+ * <p>
+ * If the enqueuing app has the ability to grant access, it will be added to
+ * {@link #mGrantableUris}. Otherwise, this will either log or throw
+ * {@link SecurityException} depending on target SDK of enqueuing app.
+ */
+ private void visitGrantableUri(Uri uri, boolean userOverriddenUri,
+ boolean isSound) {
+ if (mGrantableUris != null && mGrantableUris.contains(uri)) {
+ return; // already verified this URI
+ }
+
+ final int sourceUid = getSbn().getUid();
+ try {
+ PermissionHelper.grantUriPermission(mUgmInternal, uri, sourceUid);
+
+ if (mGrantableUris == null) {
+ mGrantableUris = new ArraySet<>();
+ }
+ mGrantableUris.add(uri);
+ } catch (SecurityException e) {
+ if (!userOverriddenUri) {
+ if (isSound) {
+ mSound = Settings.System.DEFAULT_NOTIFICATION_URI;
+ Log.w(TAG, "Replacing " + uri + " from " + sourceUid + ": " + e.getMessage());
+ } else {
+ if (mTargetSdkVersion >= Build.VERSION_CODES.P) {
+ throw e;
+ } else {
+ Log.w(TAG,
+ "Ignoring " + uri + " from " + sourceUid + ": " + e.getMessage());
+ }
+ }
+ }
+ }
+ }
+
public LogMaker getLogMaker(long now) {
LogMaker lm = getSbn().getLogMaker()
.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE, mImportance)
diff --git a/services/core/java/com/android/server/notification/PermissionHelper.java b/services/core/java/com/android/server/notification/PermissionHelper.java
index b6f48890c528..1464d481311a 100644
--- a/services/core/java/com/android/server/notification/PermissionHelper.java
+++ b/services/core/java/com/android/server/notification/PermissionHelper.java
@@ -25,19 +25,25 @@ import android.Manifest;
import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.companion.virtual.VirtualDeviceManager;
+import android.content.ContentProvider;
+import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
+import android.net.Uri;
import android.os.Binder;
import android.os.RemoteException;
+import android.os.UserHandle;
import android.permission.IPermissionManager;
import android.util.ArrayMap;
import android.util.Pair;
import android.util.Slog;
import com.android.internal.util.ArrayUtils;
+import com.android.server.uri.UriGrantsManagerInternal;
import java.util.Collections;
import java.util.HashSet;
@@ -58,7 +64,7 @@ public final class PermissionHelper {
private final IPermissionManager mPermManager;
public PermissionHelper(Context context, IPackageManager packageManager,
- IPermissionManager permManager) {
+ IPermissionManager permManager) {
mContext = context;
mPackageManager = packageManager;
mPermManager = permManager;
@@ -298,6 +304,19 @@ public final class PermissionHelper {
return false;
}
+ static void grantUriPermission(final UriGrantsManagerInternal ugmInternal, Uri uri,
+ int sourceUid) {
+ if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) return;
+
+ Binder.withCleanCallingIdentity(() -> {
+ // This will throw a SecurityException if the caller can't grant.
+ ugmInternal.checkGrantUriPermission(sourceUid, null,
+ ContentProvider.getUriWithoutUserId(uri),
+ Intent.FLAG_GRANT_READ_URI_PERMISSION,
+ ContentProvider.getUserIdFromUri(uri, UserHandle.getUserId(sourceUid)));
+ });
+ }
+
public static class PackagePermission {
public final String packageName;
public final @UserIdInt int userId;
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index 85c395781d0a..9e70f815dff9 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -94,6 +94,7 @@ import com.android.internal.util.XmlUtils;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.notification.PermissionHelper.PackagePermission;
+import com.android.server.uri.UriGrantsManagerInternal;
import org.json.JSONArray;
import org.json.JSONException;
@@ -219,6 +220,7 @@ public class PreferencesHelper implements RankingConfig {
private final NotificationChannelLogger mNotificationChannelLogger;
private final AppOpsManager mAppOps;
private final ManagedServices.UserProfiles mUserProfiles;
+ private final UriGrantsManagerInternal mUgmInternal;
private SparseBooleanArray mBadgingEnabled;
private SparseBooleanArray mBubblesEnabled;
@@ -239,6 +241,7 @@ public class PreferencesHelper implements RankingConfig {
ZenModeHelper zenHelper, PermissionHelper permHelper, PermissionManager permManager,
NotificationChannelLogger notificationChannelLogger,
AppOpsManager appOpsManager, ManagedServices.UserProfiles userProfiles,
+ UriGrantsManagerInternal ugmInternal,
boolean showReviewPermissionsNotification, Clock clock) {
mContext = context;
mZenModeHelper = zenHelper;
@@ -249,6 +252,7 @@ public class PreferencesHelper implements RankingConfig {
mNotificationChannelLogger = notificationChannelLogger;
mAppOps = appOpsManager;
mUserProfiles = userProfiles;
+ mUgmInternal = ugmInternal;
mShowReviewPermissionsNotification = showReviewPermissionsNotification;
mIsMediaNotificationFilteringEnabled = context.getResources()
.getBoolean(R.bool.config_quickSettingsShowMediaPlayer);
@@ -1169,6 +1173,13 @@ public class PreferencesHelper implements RankingConfig {
}
clearLockedFieldsLocked(channel);
+ // Verify that the app has permission to read the sound Uri
+ // Only check for new channels, as regular apps can only set sound
+ // before creating. See: {@link NotificationChannel#setSound}
+ if (Flags.notificationVerifyChannelSoundUri()) {
+ PermissionHelper.grantUriPermission(mUgmInternal, channel.getSound(), uid);
+ }
+
channel.setImportanceLockedByCriticalDeviceFunction(
r.defaultAppLockedImportance || r.fixedImportance);
diff --git a/services/core/java/com/android/server/notification/flags.aconfig b/services/core/java/com/android/server/notification/flags.aconfig
index be3adc142fa4..0b34177d7413 100644
--- a/services/core/java/com/android/server/notification/flags.aconfig
+++ b/services/core/java/com/android/server/notification/flags.aconfig
@@ -144,6 +144,13 @@ flag {
}
flag {
+ name: "notification_minimalism"
+ namespace: "systemui"
+ description: "Minimize the notifications to show on the lockscreen."
+ bug: "330387368"
+}
+
+flag {
name: "notification_force_group_singletons"
namespace: "systemui"
description: "This flag enables forced auto-grouping singleton groups"
@@ -163,3 +170,13 @@ flag {
description: "This flag enables sound uri with vibration source"
bug: "358524009"
}
+
+flag {
+ name: "notification_verify_channel_sound_uri"
+ namespace: "systemui"
+ description: "Verify Uri permission for sound when creating a notification channel"
+ bug: "337775777"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/services/core/java/com/android/server/pinner/PinRangeSource.java b/services/core/java/com/android/server/pinner/PinRangeSource.java
new file mode 100644
index 000000000000..5f9641122294
--- /dev/null
+++ b/services/core/java/com/android/server/pinner/PinRangeSource.java
@@ -0,0 +1,27 @@
+/*
+ * 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.server.pinner;
+
+/* package */ abstract class PinRangeSource {
+ /**
+ * Retrieve a range to pin.
+ *
+ * @param outPinRange Receives the pin region
+ * @return True if we filled in outPinRange or false if we're out of pin entries
+ */
+ abstract boolean read(PinnerService.PinRange outPinRange);
+} \ No newline at end of file
diff --git a/services/core/java/com/android/server/pinner/PinRangeSourceStatic.java b/services/core/java/com/android/server/pinner/PinRangeSourceStatic.java
new file mode 100644
index 000000000000..d6fc48790883
--- /dev/null
+++ b/services/core/java/com/android/server/pinner/PinRangeSourceStatic.java
@@ -0,0 +1,37 @@
+/*
+ * 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.server.pinner;
+
+/* package */ class PinRangeSourceStatic extends PinRangeSource {
+ private final int mPinStart;
+ private final int mPinLength;
+ private boolean mDone = false;
+
+ PinRangeSourceStatic(int pinStart, int pinLength) {
+ mPinStart = pinStart;
+ mPinLength = pinLength;
+ }
+
+ @Override
+ boolean read(PinnerService.PinRange outPinRange) {
+ outPinRange.start = mPinStart;
+ outPinRange.length = mPinLength;
+ boolean done = mDone;
+ mDone = true;
+ return !done;
+ }
+} \ No newline at end of file
diff --git a/services/core/java/com/android/server/pinner/PinRangeSourceStream.java b/services/core/java/com/android/server/pinner/PinRangeSourceStream.java
new file mode 100644
index 000000000000..79900b9de463
--- /dev/null
+++ b/services/core/java/com/android/server/pinner/PinRangeSourceStream.java
@@ -0,0 +1,43 @@
+/*
+ * 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.server.pinner;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/* package */ final class PinRangeSourceStream extends PinRangeSource {
+ private final DataInputStream mStream;
+ private boolean mDone = false;
+
+ PinRangeSourceStream(InputStream stream) {
+ mStream = new DataInputStream(stream);
+ }
+
+ @Override
+ boolean read(PinnerService.PinRange outPinRange) {
+ if (!mDone) {
+ try {
+ outPinRange.start = mStream.readInt();
+ outPinRange.length = mStream.readInt();
+ } catch (IOException ex) {
+ mDone = true;
+ }
+ }
+ return !mDone;
+ }
+} \ No newline at end of file
diff --git a/services/core/java/com/android/server/pinner/PinnedFile.java b/services/core/java/com/android/server/pinner/PinnedFile.java
new file mode 100644
index 000000000000..a8de344d10af
--- /dev/null
+++ b/services/core/java/com/android/server/pinner/PinnedFile.java
@@ -0,0 +1,61 @@
+/*
+ * 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.server.pinner;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.util.ArrayList;
+
+@VisibleForTesting
+public final class PinnedFile implements AutoCloseable {
+ private long mAddress;
+ final long mapSize;
+ final String fileName;
+ public final long bytesPinned;
+
+ // Whether this file was pinned using a pinlist
+ boolean used_pinlist;
+
+ // User defined group name for pinner accounting
+ String groupName = "";
+ ArrayList<PinnedFile> pinnedDeps = new ArrayList<>();
+
+ public PinnedFile(long address, long mapSize, String fileName, long bytesPinned) {
+ mAddress = address;
+ this.mapSize = mapSize;
+ this.fileName = fileName;
+ this.bytesPinned = bytesPinned;
+ }
+
+ @Override
+ public void close() {
+ if (mAddress >= 0) {
+ PinnerUtils.safeMunmap(mAddress, mapSize);
+ mAddress = -1;
+ }
+ for (PinnedFile dep : pinnedDeps) {
+ if (dep != null) {
+ dep.close();
+ }
+ }
+ }
+
+ @Override
+ public void finalize() {
+ close();
+ }
+} \ No newline at end of file
diff --git a/services/core/java/com/android/server/PinnerService.java b/services/core/java/com/android/server/pinner/PinnerService.java
index ef03888d6620..d7ac5203ff53 100644
--- a/services/core/java/com/android/server/PinnerService.java
+++ b/services/core/java/com/android/server/pinner/PinnerService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2023 The Android Open Source Project
+ * 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.
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.pinner;
import static android.app.ActivityManager.UID_OBSERVER_ACTIVE;
import static android.app.ActivityManager.UID_OBSERVER_GONE;
import static android.os.Process.SYSTEM_UID;
+import static com.android.server.flags.Flags.pinGlobalQuota;
import static com.android.server.flags.Flags.pinWebview;
-import static com.android.server.flags.Flags.skipHomeArtPins;
import android.annotation.EnforcePermission;
import android.annotation.IntDef;
@@ -49,6 +49,7 @@ import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.Message;
+import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;
@@ -72,13 +73,13 @@ import com.android.internal.app.ResolverActivity;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.function.pooled.PooledLambda;
+import com.android.server.LocalServices;
+import com.android.server.SystemService;
import com.android.server.wm.ActivityTaskManagerInternal;
import dalvik.system.DexFile;
import dalvik.system.VMRuntime;
-import java.io.Closeable;
-import java.io.DataInputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -110,8 +111,7 @@ public final class PinnerService extends SystemService {
private static final String PIN_META_FILENAME = "pinlist.meta";
private static final int PAGE_SIZE = (int) Os.sysconf(OsConstants._SC_PAGESIZE);
private static final int MATCH_FLAGS = PackageManager.MATCH_DEFAULT_ONLY
- | PackageManager.MATCH_DIRECT_BOOT_AWARE
- | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
+ | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
private static final int KEY_CAMERA = 0;
private static final int KEY_HOME = 1;
@@ -126,6 +126,8 @@ public final class PinnerService extends SystemService {
public static final String ANON_REGION_STAT_NAME = "[anon]";
+ private static final String SYSTEM_GROUP_NAME = "system";
+
@IntDef({KEY_CAMERA, KEY_HOME, KEY_ASSISTANT})
@Retention(RetentionPolicy.SOURCE)
public @interface AppKey {}
@@ -139,7 +141,8 @@ public final class PinnerService extends SystemService {
private final UserManager mUserManager;
/** The list of the statically pinned files. */
- @GuardedBy("this") private final ArrayMap<String, PinnedFile> mPinnedFiles = new ArrayMap<>();
+ @GuardedBy("this")
+ private final ArrayMap<String, PinnedFile> mPinnedFiles = new ArrayMap<>();
/** The list of the pinned apps. This is a map from {@link AppKey} to a pinned app. */
@GuardedBy("this")
@@ -159,8 +162,8 @@ public final class PinnerService extends SystemService {
/**
* A set of {@link AppKey} that are configured to be pinned.
*/
- @GuardedBy("this")
- private ArraySet<Integer> mPinKeys;
+ @GuardedBy("this") private
+ ArraySet<Integer> mPinKeys;
// Note that we don't use the `_BOOT` namespace for anonymous pinnings, as we want
// them to be responsive to dynamic flag changes for experimentation.
@@ -180,14 +183,23 @@ public final class PinnerService extends SystemService {
private final boolean mConfiguredToPinAssistant;
private final int mConfiguredWebviewPinBytes;
+ // This is the percentage of total device memory that will be used to set the global quota.
+ private final int mConfiguredMaxPinnedMemoryPercentage;
+
+ // This is the global pinner quota that can be pinned.
+ private long mConfiguredMaxPinnedMemory;
+
+ // This is the currently pinned memory.
+ private long mCurrentPinnedMemory = 0;
+
private BinderService mBinderService;
private PinnerHandler mPinnerHandler = null;
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- // If an app has updated, update pinned files accordingly.
- if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
+ // If an app has updated, update pinned files accordingly.
+ if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
Uri packageUri = intent.getData();
String packageName = packageUri.getSchemeSpecificPart();
ArraySet<String> updatedPackages = new ArraySet<>();
@@ -210,7 +222,7 @@ public final class PinnerService extends SystemService {
/** Utility class for testing. */
@VisibleForTesting
- static class Injector {
+ public static class Injector {
protected DeviceConfigInterface getDeviceConfigInterface() {
return DeviceConfigInterface.REAL;
}
@@ -219,9 +231,9 @@ public final class PinnerService extends SystemService {
service.publishBinderService("pinner", binderService);
}
- protected PinnedFile pinFileInternal(String fileToPin,
- int maxBytesToPin, boolean attemptPinIntrospection) {
- return PinnerService.pinFileInternal(fileToPin, maxBytesToPin, attemptPinIntrospection);
+ protected PinnedFile pinFileInternal(PinnerService service, String fileToPin,
+ long maxBytesToPin, boolean attemptPinIntrospection) {
+ return service.pinFileInternal(fileToPin, maxBytesToPin, attemptPinIntrospection);
}
}
@@ -230,7 +242,7 @@ public final class PinnerService extends SystemService {
}
@VisibleForTesting
- PinnerService(Context context, Injector injector) {
+ public PinnerService(Context context, Injector injector) {
super(context);
mContext = context;
@@ -244,6 +256,9 @@ public final class PinnerService extends SystemService {
com.android.internal.R.bool.config_pinnerAssistantApp);
mConfiguredWebviewPinBytes = context.getResources().getInteger(
com.android.internal.R.integer.config_pinnerWebviewPinBytes);
+ mConfiguredMaxPinnedMemoryPercentage = context.getResources().getInteger(
+ com.android.internal.R.integer.config_pinnerMaxPinnedMemoryPercentage);
+
mPinKeys = createPinKeys();
mPinnerHandler = new PinnerHandler(BackgroundThread.get().getLooper());
@@ -261,10 +276,8 @@ public final class PinnerService extends SystemService {
registerUidListener();
registerUserSetupCompleteListener();
- mDeviceConfigInterface.addOnPropertiesChangedListener(
- DEVICE_CONFIG_NAMESPACE_ANON_SIZE,
- new HandlerExecutor(mPinnerHandler),
- mDeviceConfigAnonSizeListener);
+ mDeviceConfigInterface.addOnPropertiesChangedListener(DEVICE_CONFIG_NAMESPACE_ANON_SIZE,
+ new HandlerExecutor(mPinnerHandler), mDeviceConfigAnonSizeListener);
}
@Override
@@ -272,6 +285,10 @@ public final class PinnerService extends SystemService {
if (DEBUG) {
Slog.i(TAG, "Starting PinnerService");
}
+ mConfiguredMaxPinnedMemory =
+ (Process.getTotalMemory()
+ * Math.clamp(mConfiguredMaxPinnedMemoryPercentage, 0, 100))
+ / 100;
mBinderService = new BinderService();
mInjector.publishBinderService(this, mBinderService);
publishLocalService(PinnerService.class, this);
@@ -348,7 +365,7 @@ public final class PinnerService extends SystemService {
protected PinnedFileStats(int uid, PinnedFile file) {
this.uid = uid;
this.filename = file.fileName.substring(file.fileName.lastIndexOf('/') + 1);
- this.sizeKb = file.bytesPinned / 1024;
+ this.sizeKb = (int) file.bytesPinned / 1024;
}
}
@@ -358,20 +375,11 @@ public final class PinnerService extends SystemService {
private void handlePinOnStart() {
// Files to pin come from the overlay and can be specified per-device config
String[] filesToPin = mContext.getResources().getStringArray(
- com.android.internal.R.array.config_defaultPinnerServiceFiles);
+ com.android.internal.R.array.config_defaultPinnerServiceFiles);
// Continue trying to pin each file even if we fail to pin some of them
for (String fileToPin : filesToPin) {
- PinnedFile pf = mInjector.pinFileInternal(fileToPin, Integer.MAX_VALUE,
- /*attemptPinIntrospection=*/false);
- if (pf == null) {
- Slog.e(TAG, "Failed to pin file = " + fileToPin);
- continue;
- }
- synchronized (this) {
- mPinnedFiles.put(pf.fileName, pf);
- }
- pf.groupName = "system";
- pinOptimizedDexDependencies(pf, Integer.MAX_VALUE, null);
+ pinFile(fileToPin, Integer.MAX_VALUE, /*appInfo=*/null, /*groupName=*/SYSTEM_GROUP_NAME,
+ true);
}
refreshPinAnonConfig();
@@ -383,10 +391,9 @@ public final class PinnerService extends SystemService {
* regular home app.
*/
private void registerUserSetupCompleteListener() {
- Uri userSetupCompleteUri = Settings.Secure.getUriFor(
- Settings.Secure.USER_SETUP_COMPLETE);
- mContext.getContentResolver().registerContentObserver(userSetupCompleteUri,
- false, new ContentObserver(null) {
+ Uri userSetupCompleteUri = Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE);
+ mContext.getContentResolver().registerContentObserver(
+ userSetupCompleteUri, false, new ContentObserver(null) {
@Override
public void onChange(boolean selfChange, Uri uri) {
if (userSetupCompleteUri.equals(uri)) {
@@ -409,7 +416,7 @@ public final class PinnerService extends SystemService {
}
@Override
- public void onUidActive(int uid) {
+ public void onUidActive(int uid) {
mPinnerHandler.sendMessage(PooledLambda.obtainMessage(
PinnerService::handleUidActive, PinnerService.this, uid));
}
@@ -423,7 +430,6 @@ public final class PinnerService extends SystemService {
updateActiveState(uid, false /* active */);
int key;
synchronized (this) {
-
// In case we have a pending repin, repin now. See mPendingRepin for more information.
key = mPendingRepin.getOrDefault(uid, -1);
if (key == -1) {
@@ -491,8 +497,8 @@ public final class PinnerService extends SystemService {
private ApplicationInfo getCameraInfo(int userHandle) {
Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
- ApplicationInfo info = getApplicationInfoForIntent(cameraIntent, userHandle,
- false /* defaultToSystemApp */);
+ ApplicationInfo info = getApplicationInfoForIntent(
+ cameraIntent, userHandle, false /* defaultToSystemApp */);
// If the STILL_IMAGE_CAMERA intent doesn't resolve, try the _SECURE intent.
// We don't use _SECURE first because it will never get set on a device
@@ -501,16 +507,16 @@ public final class PinnerService extends SystemService {
// preference using this intent.
if (info == null) {
cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
- info = getApplicationInfoForIntent(cameraIntent, userHandle,
- false /* defaultToSystemApp */);
+ info = getApplicationInfoForIntent(
+ cameraIntent, userHandle, false /* defaultToSystemApp */);
}
// If the _SECURE intent doesn't resolve, try the original intent but request
// the system app for camera if there was more than one result.
if (info == null) {
cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
- info = getApplicationInfoForIntent(cameraIntent, userHandle,
- true /* defaultToSystemApp */);
+ info = getApplicationInfoForIntent(
+ cameraIntent, userHandle, true /* defaultToSystemApp */);
}
return info;
}
@@ -525,14 +531,14 @@ public final class PinnerService extends SystemService {
return getApplicationInfoForIntent(intent, userHandle, true);
}
- private ApplicationInfo getApplicationInfoForIntent(Intent intent, int userHandle,
- boolean defaultToSystemApp) {
+ private ApplicationInfo getApplicationInfoForIntent(
+ Intent intent, int userHandle, boolean defaultToSystemApp) {
if (intent == null) {
return null;
}
- ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivityAsUser(intent,
- MATCH_FLAGS, userHandle);
+ ResolveInfo resolveInfo =
+ mContext.getPackageManager().resolveActivityAsUser(intent, MATCH_FLAGS, userHandle);
// If this intent can resolve to only one app, choose that one.
// Otherwise, if we've requested to default to the system app, return it;
@@ -547,12 +553,11 @@ public final class PinnerService extends SystemService {
}
if (defaultToSystemApp) {
- List<ResolveInfo> infoList = mContext.getPackageManager()
- .queryIntentActivitiesAsUser(intent, MATCH_FLAGS, userHandle);
+ List<ResolveInfo> infoList = mContext.getPackageManager().queryIntentActivitiesAsUser(
+ intent, MATCH_FLAGS, userHandle);
ApplicationInfo systemAppInfo = null;
for (ResolveInfo info : infoList) {
- if ((info.activityInfo.applicationInfo.flags
- & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ if ((info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
if (systemAppInfo == null) {
systemAppInfo = info.activityInfo.applicationInfo;
} else {
@@ -568,13 +573,13 @@ public final class PinnerService extends SystemService {
}
private void sendPinAppsMessage(int userHandle) {
- mPinnerHandler.sendMessage(PooledLambda.obtainMessage(PinnerService::pinApps, this,
- userHandle));
+ mPinnerHandler.sendMessage(
+ PooledLambda.obtainMessage(PinnerService::pinApps, this, userHandle));
}
private void sendPinAppsWithUpdatedKeysMessage(int userHandle) {
- mPinnerHandler.sendMessage(PooledLambda.obtainMessage(PinnerService::pinAppsWithUpdatedKeys,
- this, userHandle));
+ mPinnerHandler.sendMessage(PooledLambda.obtainMessage(
+ PinnerService::pinAppsWithUpdatedKeys, this, userHandle));
}
private void sendUnpinAppsMessage() {
mPinnerHandler.sendMessage(PooledLambda.obtainMessage(PinnerService::unpinApps, this));
@@ -586,8 +591,7 @@ public final class PinnerService extends SystemService {
// phenotype property is not set.
boolean shouldPinCamera = mConfiguredToPinCamera
&& mDeviceConfigInterface.getBoolean(DeviceConfig.NAMESPACE_RUNTIME_NATIVE_BOOT,
- "pin_camera",
- SystemProperties.getBoolean("pinner.pin_camera", true));
+ "pin_camera", SystemProperties.getBoolean("pinner.pin_camera", true));
if (shouldPinCamera) {
pinKeys.add(KEY_CAMERA);
} else if (DEBUG) {
@@ -626,8 +630,9 @@ public final class PinnerService extends SystemService {
synchronized (this) {
// This code path demands preceding unpinApps() call.
if (!mPinnedApps.isEmpty()) {
- Slog.e(TAG, "Attempted to update a list of apps, "
- + "but apps were already pinned. Skipping.");
+ Slog.e(TAG,
+ "Attempted to update a list of apps, "
+ + "but apps were already pinned. Skipping.");
return;
}
@@ -646,8 +651,8 @@ public final class PinnerService extends SystemService {
* @see #pinApp(int, int, boolean)
*/
private void sendPinAppMessage(int key, int userHandle, boolean force) {
- mPinnerHandler.sendMessage(PooledLambda.obtainMessage(PinnerService::pinApp, this,
- key, userHandle, force));
+ mPinnerHandler.sendMessage(
+ PooledLambda.obtainMessage(PinnerService::pinApp, this, key, userHandle, force));
}
/**
@@ -667,10 +672,10 @@ public final class PinnerService extends SystemService {
}
return;
}
- unpinApp(key);
ApplicationInfo info = getInfoForKey(key, userHandle);
+ unpinApp(key);
if (info != null) {
- pinApp(key, info);
+ pinAppInternal(key, info);
}
}
@@ -682,9 +687,7 @@ public final class PinnerService extends SystemService {
private int getUidForKey(@AppKey int key) {
synchronized (this) {
PinnedApp existing = mPinnedApps.get(key);
- return existing != null && existing.active
- ? existing.uid
- : -1;
+ return existing != null && existing.active ? existing.uid : -1;
}
}
@@ -727,11 +730,8 @@ public final class PinnerService extends SystemService {
* Handle any changes in the anon region pinner config.
*/
private void refreshPinAnonConfig() {
- long newPinAnonSize =
- mDeviceConfigInterface.getLong(
- DEVICE_CONFIG_NAMESPACE_ANON_SIZE,
- DEVICE_CONFIG_KEY_ANON_SIZE,
- DEFAULT_ANON_SIZE);
+ long newPinAnonSize = mDeviceConfigInterface.getLong(
+ DEVICE_CONFIG_NAMESPACE_ANON_SIZE, DEVICE_CONFIG_KEY_ANON_SIZE, DEFAULT_ANON_SIZE);
newPinAnonSize = Math.max(0, Math.min(newPinAnonSize, MAX_ANON_SIZE));
if (newPinAnonSize != mPinAnonSize) {
mPinAnonSize = newPinAnonSize;
@@ -765,10 +765,9 @@ public final class PinnerService extends SystemService {
try {
// Map as SHARED to avoid changing rss.anon for system_server (per /proc/*/status).
// The mapping is visible in other rss metrics, and as private dirty in smaps/meminfo.
- address = Os.mmap(0, alignedPinSize,
- OsConstants.PROT_READ | OsConstants.PROT_WRITE,
- OsConstants.MAP_SHARED | OsConstants.MAP_ANONYMOUS,
- new FileDescriptor(), /*offset=*/0);
+ address = Os.mmap(0, alignedPinSize, OsConstants.PROT_READ | OsConstants.PROT_WRITE,
+ OsConstants.MAP_SHARED | OsConstants.MAP_ANONYMOUS, new FileDescriptor(),
+ /*offset=*/0);
Unsafe tempUnsafe = null;
Class<sun.misc.Unsafe> clazz = sun.misc.Unsafe.class;
@@ -794,14 +793,14 @@ public final class PinnerService extends SystemService {
return;
} finally {
if (address >= 0) {
- safeMunmap(address, alignedPinSize);
+ PinnerUtils.safeMunmap(address, alignedPinSize);
}
}
}
private void unpinAnonRegion() {
if (mPinAnonAddress != 0) {
- safeMunmap(mPinAnonAddress, mCurrentlyPinnedAnonSize);
+ PinnerUtils.safeMunmap(mPinAnonAddress, mCurrentlyPinnedAnonSize);
}
mPinAnonAddress = 0;
mCurrentlyPinnedAnonSize = 0;
@@ -824,12 +823,20 @@ public final class PinnerService extends SystemService {
}
/**
+ * Retrieves remaining quota for pinner service, once it reaches 0 it will no longer
+ * pin any file.
+ */
+ private long getAvailableGlobalQuota() {
+ return mConfiguredMaxPinnedMemory - mCurrentPinnedMemory;
+ }
+
+ /**
* Pins an application.
*
* @param key The key of the app to pin.
* @param appInfo The corresponding app info.
*/
- private void pinApp(@AppKey int key, @Nullable ApplicationInfo appInfo) {
+ private void pinAppInternal(@AppKey int key, @Nullable ApplicationInfo appInfo) {
if (appInfo == null) {
return;
}
@@ -839,7 +846,6 @@ public final class PinnerService extends SystemService {
mPinnedApps.put(key, pinnedApp);
}
-
// pin APK
final int pinSizeLimit = getSizeLimitForKey(key);
List<String> apks = new ArrayList<>();
@@ -851,36 +857,31 @@ public final class PinnerService extends SystemService {
}
}
- int apkPinSizeLimit = pinSizeLimit;
-
- boolean shouldSkipArtPins = key == KEY_HOME && skipHomeArtPins();
+ long apkPinSizeLimit = pinSizeLimit;
- for (String apk: apks) {
+ for (String apk : apks) {
if (apkPinSizeLimit <= 0) {
Slog.w(TAG, "Reached to the pin size limit. Skipping: " + apk);
// Continue instead of break to print all skipped APK names.
continue;
}
- PinnedFile pf = mInjector.pinFileInternal(apk, apkPinSizeLimit, /*attemptPinIntrospection=*/true);
+ String pinGroup = getNameForKey(key);
+ boolean shouldPinDeps = apk.equals(appInfo.sourceDir);
+ PinnedFile pf = pinFile(apk, apkPinSizeLimit, appInfo, pinGroup, shouldPinDeps);
if (pf == null) {
Slog.e(TAG, "Failed to pin " + apk);
continue;
}
- pf.groupName = getNameForKey(key);
if (DEBUG) {
Slog.i(TAG, "Pinned " + pf.fileName);
}
synchronized (this) {
pinnedApp.mFiles.add(pf);
- mPinnedFiles.put(pf.fileName, pf);
}
apkPinSizeLimit -= pf.bytesPinned;
- if (apk.equals(appInfo.sourceDir) && !shouldSkipArtPins) {
- pinOptimizedDexDependencies(pf, Integer.MAX_VALUE, appInfo);
- }
}
}
@@ -892,19 +893,23 @@ public final class PinnerService extends SystemService {
* that related to the file but not within itself.
*
* @param fileToPin File to pin
- * @param maxBytesToPin maximum quota allowed for pinning
- * @return total bytes that were pinned.
+ * @param bytesRequestedToPin maximum bytes requested to pin for {@code fileToPin}.
+ * @param pinOptimizedDeps whether optimized dependencies such as odex,vdex, etc be pinned.
+ * Note: {@code bytesRequestedToPin} limit will not apply to optimized
+ * dependencies pinned, only global quotas will apply instead.
+ * @return pinned file
*/
- public int pinFile(String fileToPin, int maxBytesToPin, @Nullable ApplicationInfo appInfo,
- @Nullable String groupName) {
+ public PinnedFile pinFile(String fileToPin, long bytesRequestedToPin,
+ @Nullable ApplicationInfo appInfo, @Nullable String groupName,
+ boolean pinOptimizedDeps) {
PinnedFile existingPin;
- synchronized(this) {
+ synchronized (this) {
existingPin = mPinnedFiles.get(fileToPin);
}
if (existingPin != null) {
- if (existingPin.bytesPinned == maxBytesToPin) {
+ if (existingPin.bytesPinned == bytesRequestedToPin) {
// Duplicate pin requesting same amount of bytes, lets just bail out.
- return 0;
+ return null;
} else {
// User decided to pin a different amount of bytes than currently pinned
// so this is a valid pin request. Unpin the previous version before repining.
@@ -915,26 +920,38 @@ public final class PinnerService extends SystemService {
}
}
+ long remainingQuota = getAvailableGlobalQuota();
+
+ if (pinGlobalQuota()) {
+ if (remainingQuota <= 0) {
+ Slog.w(TAG, "Reached pin quota, skipping file: " + fileToPin);
+ return null;
+ }
+ bytesRequestedToPin = Math.min(bytesRequestedToPin, remainingQuota);
+ }
+
boolean isApk = fileToPin.endsWith(".apk");
- int bytesPinned = 0;
- PinnedFile pf = mInjector.pinFileInternal(fileToPin, maxBytesToPin,
+
+ PinnedFile pf = mInjector.pinFileInternal(this, fileToPin, bytesRequestedToPin,
/*attemptPinIntrospection=*/isApk);
if (pf == null) {
Slog.e(TAG, "Failed to pin file = " + fileToPin);
- return 0;
+ return null;
}
pf.groupName = groupName != null ? groupName : "";
- bytesPinned += pf.bytesPinned;
- maxBytesToPin -= bytesPinned;
+ mCurrentPinnedMemory += pf.bytesPinned;
synchronized (this) {
mPinnedFiles.put(pf.fileName, pf);
}
- if (maxBytesToPin > 0) {
- pinOptimizedDexDependencies(pf, maxBytesToPin, appInfo);
+
+ if (pinOptimizedDeps) {
+ mCurrentPinnedMemory +=
+ pinOptimizedDexDependencies(pf, getAvailableGlobalQuota(), appInfo);
}
- return bytesPinned;
+
+ return pf;
}
/**
@@ -945,13 +962,13 @@ public final class PinnerService extends SystemService {
* to null it will use the default supported ABI by the device.
* @return total bytes pinned.
*/
- private int pinOptimizedDexDependencies(
- PinnedFile pinnedFile, int maxBytesToPin, @Nullable ApplicationInfo appInfo) {
+ private long pinOptimizedDexDependencies(
+ PinnedFile pinnedFile, long maxBytesToPin, @Nullable ApplicationInfo appInfo) {
if (pinnedFile == null) {
return 0;
}
- int bytesPinned = 0;
+ long bytesPinned = 0;
if (pinnedFile.fileName.endsWith(".jar") | pinnedFile.fileName.endsWith(".apk")) {
String abi = null;
if (appInfo != null) {
@@ -974,7 +991,7 @@ public final class PinnerService extends SystemService {
// Unpin if it was already pinned prior to re-pinning.
unpinFile(file);
- PinnedFile df = mInjector.pinFileInternal(file, maxBytesToPin,
+ PinnedFile df = mInjector.pinFileInternal(this, file, maxBytesToPin,
/*attemptPinIntrospection=*/false);
if (df == null) {
Slog.i(TAG, "Failed to pin ART file = " + file);
@@ -992,7 +1009,8 @@ public final class PinnerService extends SystemService {
return bytesPinned;
}
- /** mlock length bytes of fileToPin in memory
+ /**
+ * mlock length bytes of fileToPin in memory
*
* If attemptPinIntrospection is true, then treat the file to pin as a zip file and
* look for a "pinlist.meta" file in the archive root directory. The structure of this
@@ -1029,8 +1047,8 @@ public final class PinnerService extends SystemService {
* zip in order to extract the
* @return Pinned memory resource owner thing or null on error
*/
- private static PinnedFile pinFileInternal(
- String fileToPin, int maxBytesToPin, boolean attemptPinIntrospection) {
+ private PinnedFile pinFileInternal(
+ String fileToPin, long maxBytesToPin, boolean attemptPinIntrospection) {
if (DEBUG) {
Slog.d(TAG, "pin file: " + fileToPin + " use-pinlist: " + attemptPinIntrospection);
}
@@ -1054,8 +1072,8 @@ public final class PinnerService extends SystemService {
}
return pinnedFile;
} finally {
- safeClose(pinRangeStream);
- safeClose(fileAsZip); // Also closes any streams we've opened
+ PinnerUtils.safeClose(pinRangeStream);
+ PinnerUtils.safeClose(fileAsZip); // Also closes any streams we've opened
}
}
@@ -1068,11 +1086,8 @@ public final class PinnerService extends SystemService {
try {
zip = new ZipFile(fileName);
} catch (IOException ex) {
- Slog.w(TAG,
- String.format(
- "could not open \"%s\" as zip: pinning as blob",
- fileName),
- ex);
+ Slog.w(TAG, String.format("could not open \"%s\" as zip: pinning as blob", fileName),
+ ex);
}
return zip;
}
@@ -1112,9 +1127,9 @@ public final class PinnerService extends SystemService {
pinMetaStream = zipFile.getInputStream(pinMetaEntry);
} catch (IOException ex) {
Slog.w(TAG,
- String.format("error reading pin metadata \"%s\": pinning as blob",
- fileName),
- ex);
+ String.format(
+ "error reading pin metadata \"%s\": pinning as blob", fileName),
+ ex);
}
} else {
Slog.w(TAG,
@@ -1124,57 +1139,6 @@ public final class PinnerService extends SystemService {
return pinMetaStream;
}
- private static abstract class PinRangeSource {
- /** Retrive a range to pin.
- *
- * @param outPinRange Receives the pin region
- * @return True if we filled in outPinRange or false if we're out of pin entries
- */
- abstract boolean read(PinRange outPinRange);
- }
-
- private static final class PinRangeSourceStatic extends PinRangeSource {
- private final int mPinStart;
- private final int mPinLength;
- private boolean mDone = false;
-
- PinRangeSourceStatic(int pinStart, int pinLength) {
- mPinStart = pinStart;
- mPinLength = pinLength;
- }
-
- @Override
- boolean read(PinRange outPinRange) {
- outPinRange.start = mPinStart;
- outPinRange.length = mPinLength;
- boolean done = mDone;
- mDone = true;
- return !done;
- }
- }
-
- private static final class PinRangeSourceStream extends PinRangeSource {
- private final DataInputStream mStream;
- private boolean mDone = false;
-
- PinRangeSourceStream(InputStream stream) {
- mStream = new DataInputStream(stream);
- }
-
- @Override
- boolean read(PinRange outPinRange) {
- if (!mDone) {
- try {
- outPinRange.start = mStream.readInt();
- outPinRange.length = mStream.readInt();
- } catch (IOException ex) {
- mDone = true;
- }
- }
- return !mDone;
- }
- }
-
/**
* Helper for pinFile.
*
@@ -1185,25 +1149,20 @@ public final class PinnerService extends SystemService {
* @return PinnedFile or null on error
*/
private static PinnedFile pinFileRanges(
- String fileToPin,
- int maxBytesToPin,
- PinRangeSource pinRangeSource)
- {
+ String fileToPin, long maxBytesToPin, PinRangeSource pinRangeSource) {
FileDescriptor fd = new FileDescriptor();
long address = -1;
- int mapSize = 0;
+ long mapSize = 0;
try {
int openFlags = (OsConstants.O_RDONLY | OsConstants.O_CLOEXEC);
fd = Os.open(fileToPin, openFlags, 0);
mapSize = (int) Math.min(Os.fstat(fd).st_size, Integer.MAX_VALUE);
- address = Os.mmap(0, mapSize,
- OsConstants.PROT_READ,
- OsConstants.MAP_SHARED,
- fd, /*offset=*/0);
+ address = Os.mmap(
+ 0, mapSize, OsConstants.PROT_READ, OsConstants.MAP_SHARED, fd, /*offset=*/0);
PinRange pinRange = new PinRange();
- int bytesPinned = 0;
+ long bytesPinned = 0;
// We pin at page granularity, so make sure the limit is page-aligned
if (maxBytesToPin % PAGE_SIZE != 0) {
@@ -1211,10 +1170,10 @@ public final class PinnerService extends SystemService {
}
while (bytesPinned < maxBytesToPin && pinRangeSource.read(pinRange)) {
- int pinStart = pinRange.start;
- int pinLength = pinRange.length;
- pinStart = clamp(0, pinStart, mapSize);
- pinLength = clamp(0, pinLength, mapSize - pinStart);
+ long pinStart = pinRange.start;
+ long pinLength = pinRange.length;
+ pinStart = PinnerUtils.clamp(0, pinStart, mapSize);
+ pinLength = PinnerUtils.clamp(0, pinLength, mapSize - pinStart);
pinLength = Math.min(maxBytesToPin - bytesPinned, pinLength);
// mlock doesn't require the region to be page-aligned, but we snap the
@@ -1229,14 +1188,13 @@ public final class PinnerService extends SystemService {
if (pinLength % PAGE_SIZE != 0) {
pinLength += PAGE_SIZE - pinLength % PAGE_SIZE;
}
- pinLength = clamp(0, pinLength, maxBytesToPin - bytesPinned);
+ pinLength = PinnerUtils.clamp(0, pinLength, maxBytesToPin - bytesPinned);
if (pinLength > 0) {
if (DEBUG) {
Slog.d(TAG,
- String.format(
- "pinning at %s %s bytes of %s",
- pinStart, pinLength, fileToPin));
+ String.format("pinning at %s %s bytes of %s", pinStart, pinLength,
+ fileToPin));
}
Os.mlock(address + pinStart, pinLength);
}
@@ -1244,15 +1202,15 @@ public final class PinnerService extends SystemService {
}
PinnedFile pinnedFile = new PinnedFile(address, mapSize, fileToPin, bytesPinned);
- address = -1; // Ownership transferred
+ address = -1; // Ownership transferred
return pinnedFile;
} catch (ErrnoException ex) {
Slog.e(TAG, "Could not pin file " + fileToPin, ex);
return null;
} finally {
- safeClose(fd);
+ PinnerUtils.safeClose(fd);
if (address >= 0) {
- safeMunmap(address, mapSize);
+ PinnerUtils.safeMunmap(address, mapSize);
}
}
}
@@ -1273,81 +1231,50 @@ public final class PinnerService extends SystemService {
}
}
- public void unpinFile(String filename) {
+ /**
+ * Unpin a file and its optimized dependencies.
+ *
+ * @param filename file to unpin.
+ * @return number of bytes unpinned, 0 in case of failure or nothing to unpin.
+ */
+ public long unpinFile(String filename) {
PinnedFile pinnedFile;
synchronized (this) {
pinnedFile = mPinnedFiles.get(filename);
}
if (pinnedFile == null) {
// File not pinned, nothing to do.
- return;
+ return 0;
}
+ long unpinnedBytes = pinnedFile.bytesPinned;
pinnedFile.close();
synchronized (this) {
if (DEBUG) {
Slog.d(TAG, "Unpinned file: " + filename);
}
+ mCurrentPinnedMemory -= pinnedFile.bytesPinned;
+
mPinnedFiles.remove(pinnedFile.fileName);
for (PinnedFile dep : pinnedFile.pinnedDeps) {
if (dep == null) {
continue;
}
+ unpinnedBytes -= dep.bytesPinned;
+ mCurrentPinnedMemory -= dep.bytesPinned;
mPinnedFiles.remove(dep.fileName);
if (DEBUG) {
Slog.d(TAG, "Unpinned dependency: " + dep.fileName);
}
}
}
- }
- private static int clamp(int min, int value, int max) {
- return Math.max(min, Math.min(value, max));
- }
-
- private static void safeMunmap(long address, long mapSize) {
- try {
- Os.munmap(address, mapSize);
- } catch (ErrnoException ex) {
- Slog.w(TAG, "ignoring error in unmap", ex);
- }
- }
-
- /**
- * Close FD, swallowing irrelevant errors.
- */
- private static void safeClose(@Nullable FileDescriptor fd) {
- if (fd != null && fd.valid()) {
- try {
- Os.close(fd);
- } catch (ErrnoException ex) {
- // Swallow the exception: non-EBADF errors in close(2)
- // indicate deferred paging write errors, which we
- // don't care about here. The underlying file
- // descriptor is always closed.
- if (ex.errno == OsConstants.EBADF) {
- throw new AssertionError(ex);
- }
- }
- }
- }
-
- /**
- * Close closeable thing, swallowing errors.
- */
- private static void safeClose(@Nullable Closeable thing) {
- if (thing != null) {
- try {
- thing.close();
- } catch (IOException ex) {
- Slog.w(TAG, "ignoring error closing resource: " + thing, ex);
- }
- }
+ return unpinnedBytes;
}
public List<PinnedFileStat> getPinnerStats() {
ArrayList<PinnedFileStat> stats = new ArrayList<>();
Collection<PinnedFile> pinnedFiles;
- synchronized(this) {
+ synchronized (this) {
pinnedFiles = mPinnedFiles.values();
}
for (PinnedFile pf : pinnedFiles) {
@@ -1355,8 +1282,8 @@ public final class PinnerService extends SystemService {
stats.add(stat);
}
if (mCurrentlyPinnedAnonSize > 0) {
- stats.add(new PinnedFileStat(ANON_REGION_STAT_NAME,
- mCurrentlyPinnedAnonSize, ANON_REGION_STAT_NAME));
+ stats.add(new PinnedFileStat(
+ ANON_REGION_STAT_NAME, mCurrentlyPinnedAnonSize, ANON_REGION_STAT_NAME));
}
return stats;
}
@@ -1364,71 +1291,124 @@ public final class PinnerService extends SystemService {
public final class BinderService extends IPinnerService.Stub {
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
- if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
+ if (!DumpUtils.checkDumpPermission(mContext, TAG, pw))
+ return;
HashSet<PinnedFile> shownPins = new HashSet<>();
- HashSet<String> groups = new HashSet<>();
- final int bytesPerMB = 1024 * 1024;
+ HashSet<String> shownGroups = new HashSet<>();
+ HashSet<String> groupsToPrint = new HashSet<>();
+ final double bytesPerMB = 1024 * 1024;
+ pw.format("Pinner Configs:\n");
+ pw.format(" Total Pinner quota: %d%% of total device memory\n",
+ mConfiguredMaxPinnedMemoryPercentage);
+ pw.format(" Maximum Pinner quota: %d bytes (%.2f MB)\n", mConfiguredMaxPinnedMemory,
+ mConfiguredMaxPinnedMemory / bytesPerMB);
+ pw.format(" Max Home App Pin Bytes (without deps): %d\n", mConfiguredHomePinBytes);
+ pw.format("\nPinned Files:\n");
synchronized (PinnerService.this) {
long totalSize = 0;
+
+ // We print apps separately from regular pins as they contain extra information that
+ // other pins do not.
for (int key : mPinnedApps.keySet()) {
PinnedApp app = mPinnedApps.get(key);
pw.print(getNameForKey(key));
- pw.print(" uid="); pw.print(app.uid);
- pw.print(" active="); pw.print(app.active);
+ pw.print(" uid=");
+ pw.print(app.uid);
+ pw.print(" active=");
+ pw.print(app.active);
+
+ if (!app.mFiles.isEmpty()) {
+ shownGroups.add(app.mFiles.getFirst().groupName);
+ }
pw.println();
+ long bytesPinnedForApp = 0;
+ long bytesPinnedForAppDeps = 0;
for (PinnedFile pf : mPinnedApps.get(key).mFiles) {
pw.print(" ");
- pw.format("%s pinned:%d bytes (%d MB) pinlist:%b\n", pf.fileName,
+ pw.format("%s pinned:%d bytes (%.2f MB) pinlist:%b\n", pf.fileName,
pf.bytesPinned, pf.bytesPinned / bytesPerMB, pf.used_pinlist);
totalSize += pf.bytesPinned;
+ bytesPinnedForApp += pf.bytesPinned;
shownPins.add(pf);
for (PinnedFile dep : pf.pinnedDeps) {
pw.print(" ");
- pw.format("%s pinned:%d bytes (%d MB) pinlist:%b (Dependency)\n", dep.fileName,
- dep.bytesPinned, dep.bytesPinned / bytesPerMB, dep.used_pinlist);
+ pw.format("%s pinned:%d bytes (%.2f MB) pinlist:%b (Dependency)\n",
+ dep.fileName, dep.bytesPinned, dep.bytesPinned / bytesPerMB,
+ dep.used_pinlist);
totalSize += dep.bytesPinned;
+ bytesPinnedForAppDeps += dep.bytesPinned;
shownPins.add(dep);
}
}
+ long bytesPinnedForAppAndDeps = bytesPinnedForApp + bytesPinnedForAppDeps;
+ pw.format("Total Pinned = %d (%.2f MB) [App=%d (%.2f MB), "
+ + "Dependencies=%d (%.2f MB)]\n\n",
+ bytesPinnedForAppAndDeps, bytesPinnedForAppAndDeps / bytesPerMB,
+ bytesPinnedForApp, bytesPinnedForApp / bytesPerMB,
+ bytesPinnedForAppDeps, bytesPinnedForAppDeps / bytesPerMB);
}
pw.println();
for (PinnedFile pinnedFile : mPinnedFiles.values()) {
- if (!groups.contains(pinnedFile.groupName)) {
- groups.add(pinnedFile.groupName);
+ if (!groupsToPrint.contains(pinnedFile.groupName)
+ && !shownGroups.contains(pinnedFile.groupName)) {
+ groupsToPrint.add(pinnedFile.groupName);
}
}
- boolean firstPinInGroup = true;
- for (String group : groups) {
+
+ // Print all the non app groups.
+ for (String group : groupsToPrint) {
List<PinnedFile> groupPins = getAllPinsForGroup(group);
+ pw.print("\nGroup:" + group);
+ long bytesPinnedForGroupNoDeps = 0;
+ long bytesPinnedForGroupDeps = 0;
+ pw.println();
for (PinnedFile pinnedFile : groupPins) {
if (shownPins.contains(pinnedFile)) {
- // Already showed in the dump and accounted for, skip.
+ // Already displayed and accounted for, skip.
continue;
}
- if (firstPinInGroup) {
- firstPinInGroup = false;
- // Ensure we only print when there are pins for groups not yet shown
- // in the pinned app section.
- pw.print("Group:" + group);
- pw.println();
- }
- pw.format(" %s pinned:%d bytes (%d MB) pinlist:%b\n", pinnedFile.fileName,
- pinnedFile.bytesPinned, pinnedFile.bytesPinned / bytesPerMB,
- pinnedFile.used_pinlist);
+ pw.format(" %s pinned: %d bytes (%.2f MB) pinlist:%b\n",
+ pinnedFile.fileName, pinnedFile.bytesPinned,
+ pinnedFile.bytesPinned / bytesPerMB, pinnedFile.used_pinlist);
totalSize += pinnedFile.bytesPinned;
+ bytesPinnedForGroupNoDeps += pinnedFile.bytesPinned;
+ shownPins.add(pinnedFile);
+ for (PinnedFile dep : pinnedFile.pinnedDeps) {
+ if (shownPins.contains(dep)) {
+ // Already displayed and accounted for, skip.
+ continue;
+ }
+ pw.print(" ");
+ pw.format("%s pinned:%d bytes (%.2f MB) pinlist:%b (Dependency)\n",
+ dep.fileName, dep.bytesPinned, dep.bytesPinned / bytesPerMB,
+ dep.used_pinlist);
+ totalSize += dep.bytesPinned;
+ bytesPinnedForGroupDeps += dep.bytesPinned;
+ shownPins.add(dep);
+ }
}
+ long bytesPinnedForGroup = bytesPinnedForGroupNoDeps + bytesPinnedForGroupDeps;
+ pw.format("Total Pinned = %d (%.2f MB) [Main=%d (%.2f MB), "
+ + "Dependencies=%d (%.2f MB)]\n\n",
+ bytesPinnedForGroup, bytesPinnedForGroup / bytesPerMB,
+ bytesPinnedForGroupNoDeps, bytesPinnedForGroupNoDeps / bytesPerMB,
+ bytesPinnedForGroupDeps, bytesPinnedForGroupDeps / bytesPerMB);
}
pw.println();
if (mPinAnonAddress != 0) {
- pw.format("Pinned anon region: %d (%d MB)\n", mCurrentlyPinnedAnonSize, mCurrentlyPinnedAnonSize / bytesPerMB);
+ pw.format("Pinned anon region: %d (%.2f MB)\n", mCurrentlyPinnedAnonSize,
+ mCurrentlyPinnedAnonSize / bytesPerMB);
totalSize += mCurrentlyPinnedAnonSize;
}
- pw.format("Total pinned: %s bytes (%s MB)\n", totalSize, totalSize / bytesPerMB);
+ pw.format("Total pinned: %d bytes (%.2f MB)\n", totalSize, totalSize / bytesPerMB);
+ pw.format("Available Pinner quota: %d bytes (%.2f MB)\n", getAvailableGlobalQuota(),
+ getAvailableGlobalQuota() / bytesPerMB);
pw.println();
if (!mPendingRepin.isEmpty()) {
pw.print("Pending repin: ");
for (int key : mPendingRepin.values()) {
- pw.print(getNameForKey(key)); pw.print(' ');
+ pw.print(getNameForKey(key));
+ pw.print(' ');
}
pw.println();
}
@@ -1462,8 +1442,9 @@ public final class PinnerService extends SystemService {
repin();
break;
default:
- printError(out, String.format(
- "Unknown pinner command: %s. Supported commands: repin", command));
+ printError(out,
+ String.format("Unknown pinner command: %s. Supported commands: repin",
+ command));
resultReceiver.send(-1, null);
return;
}
@@ -1479,46 +1460,6 @@ public final class PinnerService extends SystemService {
}
}
- @VisibleForTesting
- public static final class PinnedFile implements AutoCloseable {
- private long mAddress;
- final int mapSize;
- final String fileName;
- final int bytesPinned;
-
- // Whether this file was pinned using a pinlist
- boolean used_pinlist;
-
- // User defined group name for pinner accounting
- String groupName = "";
- ArrayList<PinnedFile> pinnedDeps = new ArrayList<>();
-
- PinnedFile(long address, int mapSize, String fileName, int bytesPinned) {
- mAddress = address;
- this.mapSize = mapSize;
- this.fileName = fileName;
- this.bytesPinned = bytesPinned;
- }
-
- @Override
- public void close() {
- if (mAddress >= 0) {
- safeMunmap(mAddress, mapSize);
- mAddress = -1;
- }
- for (PinnedFile dep : pinnedDeps) {
- if (dep != null) {
- dep.close();
- }
- }
- }
-
- @Override
- public void finalize() {
- close();
- }
- }
-
final static class PinRange {
int start;
int length;
@@ -1528,7 +1469,6 @@ public final class PinnerService extends SystemService {
* Represents an app that was pinned.
*/
private final class PinnedApp {
-
/**
* The uid of the package being pinned. This stays constant while the package stays
* installed.
@@ -1557,11 +1497,9 @@ public final class PinnerService extends SystemService {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
- case PIN_ONSTART_MSG:
- {
+ case PIN_ONSTART_MSG: {
handlePinOnStart();
- }
- break;
+ } break;
default:
super.handleMessage(msg);
diff --git a/services/core/java/com/android/server/pinner/PinnerUtils.java b/services/core/java/com/android/server/pinner/PinnerUtils.java
new file mode 100644
index 000000000000..a836a83dedab
--- /dev/null
+++ b/services/core/java/com/android/server/pinner/PinnerUtils.java
@@ -0,0 +1,75 @@
+/*
+ * 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.server.pinner;
+
+import android.annotation.Nullable;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.OsConstants;
+import android.util.Slog;
+
+import java.io.Closeable;
+import java.io.FileDescriptor;
+import java.io.IOException;
+
+/* package */ final class PinnerUtils {
+ private static final String TAG = "PinnerUtils";
+
+ public static long clamp(long min, long value, long max) {
+ return Math.max(min, Math.min(value, max));
+ }
+
+ public static void safeMunmap(long address, long mapSize) {
+ try {
+ Os.munmap(address, mapSize);
+ } catch (ErrnoException ex) {
+ Slog.w(TAG, "ignoring error in unmap", ex);
+ }
+ }
+
+ /**
+ * Close FD, swallowing irrelevant errors.
+ */
+ public static void safeClose(@Nullable FileDescriptor fd) {
+ if (fd != null && fd.valid()) {
+ try {
+ Os.close(fd);
+ } catch (ErrnoException ex) {
+ // Swallow the exception: non-EBADF errors in close(2)
+ // indicate deferred paging write errors, which we
+ // don't care about here. The underlying file
+ // descriptor is always closed.
+ if (ex.errno == OsConstants.EBADF) {
+ throw new AssertionError(ex);
+ }
+ }
+ }
+ }
+
+ /**
+ * Close closeable thing, swallowing errors.
+ */
+ public static void safeClose(@Nullable Closeable thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch (IOException ex) {
+ Slog.w(TAG, "ignoring error closing resource: " + thing, ex);
+ }
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/pm/DexOptHelper.java b/services/core/java/com/android/server/pm/DexOptHelper.java
index 9ecc7b9a805d..1569fa0aa8d7 100644
--- a/services/core/java/com/android/server/pm/DexOptHelper.java
+++ b/services/core/java/com/android/server/pm/DexOptHelper.java
@@ -70,13 +70,13 @@ import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.LocalManagerRegistry;
import com.android.server.LocalServices;
-import com.android.server.PinnerService;
import com.android.server.art.ArtManagerLocal;
import com.android.server.art.DexUseManagerLocal;
import com.android.server.art.ReasonMapping;
import com.android.server.art.model.ArtFlags;
import com.android.server.art.model.DexoptParams;
import com.android.server.art.model.DexoptResult;
+import com.android.server.pinner.PinnerService;
import com.android.server.pm.PackageDexOptimizer.DexOptResult;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.DexoptOptions;
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java
index 1316df16027f..b1b1637c890b 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -50,6 +50,7 @@ import android.app.PendingIntent;
import android.app.admin.DevicePolicyEventLogger;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
+import android.app.role.RoleManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
@@ -201,6 +202,9 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
Manifest.permission.USE_FULL_SCREEN_INTENT
);
+ private static final String ROLE_SYSTEM_APP_PROTECTION_SERVICE =
+ "android.app.role.SYSTEM_APP_PROTECTION_SERVICE";
+
final PackageArchiver mPackageArchiver;
private final Context mContext;
@@ -1454,6 +1458,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
.createEvent(DevicePolicyEnums.UNINSTALL_PACKAGE)
.setAdmin(callerPackageName)
.write();
+ } else if (isSystemAppProtectionRoleHolder(snapshot, userId, callingUid)) {
+ // Allow the SYSTEM_APP_PROTECTION_SERVICE role holder to silently uninstall, with a
+ // clean calling identity to get DELETE_PACKAGES permission
+ Binder.withCleanCallingIdentity(() ->
+ mPm.deletePackageVersioned(versionedPackage, adapter.getBinder(), userId, flags)
+ );
} else {
ApplicationInfo appInfo = snapshot.getApplicationInfo(callerPackageName, 0, userId);
if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P) {
@@ -1475,6 +1485,29 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
}
}
+ private Boolean isSystemAppProtectionRoleHolder(
+ @NonNull Computer snapshot, int userId, int callingUid) {
+ if (!Flags.deletePackagesSilentlyBackport()) {
+ return false;
+ }
+ String holderPackageName = Binder.withCleanCallingIdentity(() -> {
+ RoleManager roleManager = mPm.mContext.getSystemService(RoleManager.class);
+ if (roleManager == null) {
+ return null;
+ }
+ List<String> holders = roleManager.getRoleHoldersAsUser(
+ ROLE_SYSTEM_APP_PROTECTION_SERVICE, UserHandle.of(userId));
+ if (holders.isEmpty()) {
+ return null;
+ }
+ return holders.get(0);
+ });
+ if (holderPackageName == null) {
+ return false;
+ }
+ return snapshot.getPackageUid(holderPackageName, /* flags= */ 0, userId) == callingUid;
+ }
+
@Override
public void uninstallExistingPackage(VersionedPackage versionedPackage,
String callerPackageName, IntentSender statusReceiver, int userId) {
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
index df9f7fb3d6e5..5fc3e332b95c 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
@@ -1015,8 +1015,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
permission, attributionSource, message, forDataDelivery, startDataDelivery,
fromDatasource, attributedOp);
// Finish any started op if some step in the attribution chain failed.
- if (startDataDelivery && result != PermissionChecker.PERMISSION_GRANTED
- && result != PermissionChecker.PERMISSION_SOFT_DENIED) {
+ if (startDataDelivery && result != PermissionChecker.PERMISSION_GRANTED) {
if (attributedOp == AppOpsManager.OP_NONE) {
finishDataDelivery(AppOpsManager.permissionToOpCode(permission),
attributionSource.asState(), fromDatasource);
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index 303828f94e8a..0cdf537b3455 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -53,6 +53,7 @@ import android.telephony.TelephonyManager;
import android.util.EventLog;
import android.util.Slog;
import android.util.SparseArray;
+import android.util.SparseBooleanArray;
import android.view.WindowManagerPolicyConstants;
import com.android.internal.annotations.VisibleForTesting;
@@ -512,8 +513,17 @@ public class Notifier {
}
// Start input as soon as we start waking up or going to sleep.
- mInputManagerInternal.setInteractive(interactive);
mInputMethodManagerInternal.setInteractive(interactive);
+ if (!mFlags.isPerDisplayWakeByTouchEnabled()) {
+ // Since wakefulness is a global property in original logic, all displays should
+ // be set to the same interactive state, matching system's global wakefulness
+ SparseBooleanArray displayInteractivities = new SparseBooleanArray();
+ int[] displayIds = mDisplayManagerInternal.getDisplayIds().toArray();
+ for (int displayId : displayIds) {
+ displayInteractivities.put(displayId, interactive);
+ }
+ mInputManagerInternal.setDisplayInteractivities(displayInteractivities);
+ }
// Notify battery stats.
try {
diff --git a/services/core/java/com/android/server/power/feature/PowerManagerFlags.java b/services/core/java/com/android/server/power/feature/PowerManagerFlags.java
index c6ef89dcff69..fd60e06c0762 100644
--- a/services/core/java/com/android/server/power/feature/PowerManagerFlags.java
+++ b/services/core/java/com/android/server/power/feature/PowerManagerFlags.java
@@ -42,6 +42,11 @@ public class PowerManagerFlags {
Flags::improveWakelockLatency
);
+ private final FlagState mPerDisplayWakeByTouch = new FlagState(
+ Flags.FLAG_PER_DISPLAY_WAKE_BY_TOUCH,
+ Flags::perDisplayWakeByTouch
+ );
+
/** Returns whether early-screen-timeout-detector is enabled on not. */
public boolean isEarlyScreenTimeoutDetectorEnabled() {
return mEarlyScreenTimeoutDetectorFlagState.isEnabled();
@@ -55,6 +60,13 @@ public class PowerManagerFlags {
}
/**
+ * @return Whether per-display wake by touch is enabled or not.
+ */
+ public boolean isPerDisplayWakeByTouchEnabled() {
+ return mPerDisplayWakeByTouch.isEnabled();
+ }
+
+ /**
* dumps all flagstates
* @param pw printWriter
*/
@@ -62,6 +74,7 @@ public class PowerManagerFlags {
pw.println("PowerManagerFlags:");
pw.println(" " + mEarlyScreenTimeoutDetectorFlagState);
pw.println(" " + mImproveWakelockLatency);
+ pw.println(" " + mPerDisplayWakeByTouch);
}
private static class FlagState {
diff --git a/services/core/java/com/android/server/power/feature/power_flags.aconfig b/services/core/java/com/android/server/power/feature/power_flags.aconfig
index 3581b2fad1df..9cf3bb6df3db 100644
--- a/services/core/java/com/android/server/power/feature/power_flags.aconfig
+++ b/services/core/java/com/android/server/power/feature/power_flags.aconfig
@@ -17,4 +17,12 @@ flag {
description: "Feature flag for tracking the optimizations to improve the latency of acquiring and releasing a wakelock."
bug: "339590565"
is_fixed_read_only: true
-} \ No newline at end of file
+}
+
+flag {
+ name: "per_display_wake_by_touch"
+ namespace: "power"
+ description: "Feature flag to enable per-display wake by touch"
+ bug: "343295183"
+ is_fixed_read_only: true
+}
diff --git a/services/core/java/com/android/server/power/stats/wakeups/CpuWakeupStats.java b/services/core/java/com/android/server/power/stats/wakeups/CpuWakeupStats.java
index f047f564538d..ab630eef4644 100644
--- a/services/core/java/com/android/server/power/stats/wakeups/CpuWakeupStats.java
+++ b/services/core/java/com/android/server/power/stats/wakeups/CpuWakeupStats.java
@@ -17,6 +17,7 @@
package com.android.server.power.stats.wakeups;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_ALARM;
+import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_BLUETOOTH;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_SENSOR;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER;
@@ -63,6 +64,7 @@ public class CpuWakeupStats {
private static final String SUBSYSTEM_SOUND_TRIGGER_STRING = "Sound_trigger";
private static final String SUBSYSTEM_SENSOR_STRING = "Sensor";
private static final String SUBSYSTEM_CELLULAR_DATA_STRING = "Cellular_data";
+ private static final String SUBSYSTEM_BLUETOOTH_STRING = "Bluetooth";
private static final String TRACE_TRACK_WAKEUP_ATTRIBUTION = "wakeup_attribution";
private static final long WAKEUP_WRITE_DELAY_MS = TimeUnit.SECONDS.toMillis(30);
@@ -512,6 +514,8 @@ public class CpuWakeupStats {
return CPU_WAKEUP_SUBSYSTEM_SENSOR;
case SUBSYSTEM_CELLULAR_DATA_STRING:
return CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA;
+ case SUBSYSTEM_BLUETOOTH_STRING:
+ return CPU_WAKEUP_SUBSYSTEM_BLUETOOTH;
}
return CPU_WAKEUP_SUBSYSTEM_UNKNOWN;
}
@@ -528,6 +532,8 @@ public class CpuWakeupStats {
return SUBSYSTEM_SENSOR_STRING;
case CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA:
return SUBSYSTEM_CELLULAR_DATA_STRING;
+ case CPU_WAKEUP_SUBSYSTEM_BLUETOOTH:
+ return SUBSYSTEM_BLUETOOTH_STRING;
case CPU_WAKEUP_SUBSYSTEM_UNKNOWN:
return "Unknown";
}
diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
index b35a0a772ff2..74c1124e1f16 100644
--- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
@@ -216,13 +216,13 @@ import com.android.role.RoleManagerLocal;
import com.android.server.BinderCallsStatsService;
import com.android.server.LocalManagerRegistry;
import com.android.server.LocalServices;
-import com.android.server.PinnerService;
-import com.android.server.PinnerService.PinnedFileStats;
import com.android.server.SystemService;
import com.android.server.SystemServiceManager;
import com.android.server.am.MemoryStatUtil.MemoryStat;
import com.android.server.health.HealthServiceWrapper;
import com.android.server.notification.NotificationManagerService;
+import com.android.server.pinner.PinnerService;
+import com.android.server.pinner.PinnerService.PinnedFileStats;
import com.android.server.pm.UserManagerInternal;
import com.android.server.power.stats.KernelWakelockReader;
import com.android.server.power.stats.KernelWakelockStats;
diff --git a/services/core/java/com/android/server/vibrator/VibratorController.java b/services/core/java/com/android/server/vibrator/VibratorController.java
index c120fc7d82f5..6aed00e0e32b 100644
--- a/services/core/java/com/android/server/vibrator/VibratorController.java
+++ b/services/core/java/com/android/server/vibrator/VibratorController.java
@@ -57,8 +57,7 @@ final class VibratorController {
// for a snippet of the current known vibrator state/info.
private volatile VibratorInfo mVibratorInfo;
private volatile boolean mVibratorInfoLoadSuccessful;
- private volatile boolean mIsVibrating;
- private volatile boolean mIsUnderExternalControl;
+ private volatile VibratorState mCurrentState;
private volatile float mCurrentAmplitude;
/**
@@ -75,6 +74,11 @@ final class VibratorController {
void onComplete(int vibratorId, long vibrationId);
}
+ /** Representation of the vibrator state based on the interactions through this controller. */
+ private enum VibratorState {
+ IDLE, VIBRATING, UNDER_EXTERNAL_CONTROL
+ }
+
VibratorController(int vibratorId, OnVibrationCompleteListener listener) {
this(vibratorId, listener, new NativeWrapper());
}
@@ -87,6 +91,7 @@ final class VibratorController {
VibratorInfo.Builder vibratorInfoBuilder = new VibratorInfo.Builder(vibratorId);
mVibratorInfoLoadSuccessful = mNativeWrapper.getInfo(vibratorInfoBuilder);
mVibratorInfo = vibratorInfoBuilder.build();
+ mCurrentState = VibratorState.IDLE;
if (!mVibratorInfoLoadSuccessful) {
Slog.e(TAG,
@@ -106,7 +111,7 @@ final class VibratorController {
return false;
}
// Notify its callback after new client registered.
- notifyStateListener(listener, mIsVibrating);
+ notifyStateListener(listener, isVibrating(mCurrentState));
}
return true;
} finally {
@@ -166,7 +171,7 @@ final class VibratorController {
* automatically notified to any registered {@link IVibratorStateListener} on change.
*/
public boolean isVibrating() {
- return mIsVibrating;
+ return isVibrating(mCurrentState);
}
/**
@@ -184,11 +189,6 @@ final class VibratorController {
return mCurrentAmplitude;
}
- /** Return {@code true} if this vibrator is under external control, false otherwise. */
- public boolean isUnderExternalControl() {
- return mIsUnderExternalControl;
- }
-
/**
* Check against this vibrator capabilities.
*
@@ -214,7 +214,7 @@ final class VibratorController {
/**
* Set the vibrator control to be external or not, based on given flag.
*
- * <p>This will affect the state of {@link #isUnderExternalControl()}.
+ * <p>This will affect the state of {@link #isVibrating()}.
*/
public void setExternalControl(boolean externalControl) {
Trace.traceBegin(TRACE_TAG_VIBRATOR,
@@ -224,9 +224,11 @@ final class VibratorController {
if (!mVibratorInfo.hasCapability(IVibrator.CAP_EXTERNAL_CONTROL)) {
return;
}
+ VibratorState newState =
+ externalControl ? VibratorState.UNDER_EXTERNAL_CONTROL : VibratorState.IDLE;
synchronized (mLock) {
- mIsUnderExternalControl = externalControl;
mNativeWrapper.setExternalControl(externalControl);
+ updateStateAndNotifyListenersLocked(newState);
}
} finally {
Trace.traceEnd(TRACE_TAG_VIBRATOR);
@@ -264,7 +266,7 @@ final class VibratorController {
if (mVibratorInfo.hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)) {
mNativeWrapper.setAmplitude(amplitude);
}
- if (mIsVibrating) {
+ if (mCurrentState == VibratorState.VIBRATING) {
mCurrentAmplitude = amplitude;
}
}
@@ -289,7 +291,7 @@ final class VibratorController {
long duration = mNativeWrapper.on(milliseconds, vibrationId);
if (duration > 0) {
mCurrentAmplitude = -1;
- notifyListenerOnVibrating(true);
+ updateStateAndNotifyListenersLocked(VibratorState.VIBRATING);
}
return duration;
}
@@ -319,7 +321,7 @@ final class VibratorController {
vendorEffect.getAdaptiveScale(), vibrationId);
if (duration > 0) {
mCurrentAmplitude = -1;
- notifyListenerOnVibrating(true);
+ updateStateAndNotifyListenersLocked(VibratorState.VIBRATING);
}
return duration;
} finally {
@@ -346,7 +348,7 @@ final class VibratorController {
prebaked.getEffectStrength(), vibrationId);
if (duration > 0) {
mCurrentAmplitude = -1;
- notifyListenerOnVibrating(true);
+ updateStateAndNotifyListenersLocked(VibratorState.VIBRATING);
}
return duration;
}
@@ -374,7 +376,7 @@ final class VibratorController {
long duration = mNativeWrapper.compose(primitives, vibrationId);
if (duration > 0) {
mCurrentAmplitude = -1;
- notifyListenerOnVibrating(true);
+ updateStateAndNotifyListenersLocked(VibratorState.VIBRATING);
}
return duration;
}
@@ -402,7 +404,7 @@ final class VibratorController {
long duration = mNativeWrapper.composePwle(primitives, braking, vibrationId);
if (duration > 0) {
mCurrentAmplitude = -1;
- notifyListenerOnVibrating(true);
+ updateStateAndNotifyListenersLocked(VibratorState.VIBRATING);
}
return duration;
}
@@ -422,7 +424,7 @@ final class VibratorController {
synchronized (mLock) {
mNativeWrapper.off();
mCurrentAmplitude = 0;
- notifyListenerOnVibrating(false);
+ updateStateAndNotifyListenersLocked(VibratorState.IDLE);
}
} finally {
Trace.traceEnd(TRACE_TAG_VIBRATOR);
@@ -443,9 +445,8 @@ final class VibratorController {
return "VibratorController{"
+ "mVibratorInfo=" + mVibratorInfo
+ ", mVibratorInfoLoadSuccessful=" + mVibratorInfoLoadSuccessful
- + ", mIsVibrating=" + mIsVibrating
+ + ", mCurrentState=" + mCurrentState.name()
+ ", mCurrentAmplitude=" + mCurrentAmplitude
- + ", mIsUnderExternalControl=" + mIsUnderExternalControl
+ ", mVibratorStateListeners count="
+ mVibratorStateListeners.getRegisteredCallbackCount()
+ '}';
@@ -454,8 +455,7 @@ final class VibratorController {
void dump(IndentingPrintWriter pw) {
pw.println("Vibrator (id=" + mVibratorInfo.getId() + "):");
pw.increaseIndent();
- pw.println("isVibrating = " + mIsVibrating);
- pw.println("isUnderExternalControl = " + mIsUnderExternalControl);
+ pw.println("currentState = " + mCurrentState.name());
pw.println("currentAmplitude = " + mCurrentAmplitude);
pw.println("vibratorInfoLoadSuccessful = " + mVibratorInfoLoadSuccessful);
pw.println("vibratorStateListener size = "
@@ -464,14 +464,19 @@ final class VibratorController {
pw.decreaseIndent();
}
+ /**
+ * Updates current vibrator state and notify listeners if {@link #isVibrating()} result changed.
+ */
@GuardedBy("mLock")
- private void notifyListenerOnVibrating(boolean isVibrating) {
- if (mIsVibrating != isVibrating) {
- mIsVibrating = isVibrating;
+ private void updateStateAndNotifyListenersLocked(VibratorState state) {
+ boolean previousIsVibrating = isVibrating(mCurrentState);
+ final boolean newIsVibrating = isVibrating(state);
+ mCurrentState = state;
+ if (previousIsVibrating != newIsVibrating) {
// The broadcast method is safe w.r.t. register/unregister listener methods, but lock
// is required here to guarantee delivery order.
mVibratorStateListeners.broadcast(
- listener -> notifyStateListener(listener, isVibrating));
+ listener -> notifyStateListener(listener, newIsVibrating));
}
}
@@ -483,6 +488,11 @@ final class VibratorController {
}
}
+ /** Returns true only if given state is not {@link VibratorState#IDLE}. */
+ private static boolean isVibrating(VibratorState state) {
+ return state != VibratorState.IDLE;
+ }
+
/** Wrapper around the static-native methods of {@link VibratorController} for tests. */
@VisibleForTesting
public static class NativeWrapper {
diff --git a/services/core/java/com/android/server/vibrator/VibratorManagerService.java b/services/core/java/com/android/server/vibrator/VibratorManagerService.java
index 95c648334327..07473d10b217 100644
--- a/services/core/java/com/android/server/vibrator/VibratorManagerService.java
+++ b/services/core/java/com/android/server/vibrator/VibratorManagerService.java
@@ -809,17 +809,9 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
mCurrentExternalVibration.getDebugInfo().dump(proto,
VibratorManagerServiceDumpProto.CURRENT_EXTERNAL_VIBRATION);
}
-
- boolean isVibrating = false;
- boolean isUnderExternalControl = false;
for (int i = 0; i < mVibrators.size(); i++) {
proto.write(VibratorManagerServiceDumpProto.VIBRATOR_IDS, mVibrators.keyAt(i));
- isVibrating |= mVibrators.valueAt(i).isVibrating();
- isUnderExternalControl |= mVibrators.valueAt(i).isUnderExternalControl();
}
- proto.write(VibratorManagerServiceDumpProto.IS_VIBRATING, isVibrating);
- proto.write(VibratorManagerServiceDumpProto.VIBRATOR_UNDER_EXTERNAL_CONTROL,
- isUnderExternalControl);
}
mVibratorManagerRecords.dump(proto);
mVibratorControlService.dump(proto);
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 4754ffb5cf6e..946b61ad5fd9 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -1468,7 +1468,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
|| change == PACKAGE_TEMPORARY_CHANGE) {
changed = true;
if (doit) {
- Slog.w(TAG, "Wallpaper uninstalled, removing: "
+ Slog.e(TAG, "Wallpaper uninstalled, removing: "
+ wallpaper.getComponent());
clearWallpaperLocked(wallpaper.mWhich, wallpaper.userId, false, null);
}
@@ -1491,7 +1491,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
} catch (NameNotFoundException e) {
- Slog.w(TAG, "Wallpaper component gone, removing: "
+ Slog.e(TAG, "Wallpaper component gone, removing: "
+ wallpaper.getComponent());
clearWallpaperLocked(wallpaper.mWhich, wallpaper.userId, false, null);
}
diff --git a/services/core/java/com/android/server/webkit/SystemImpl.java b/services/core/java/com/android/server/webkit/SystemImpl.java
index 67401530763b..ab5316f46d78 100644
--- a/services/core/java/com/android/server/webkit/SystemImpl.java
+++ b/services/core/java/com/android/server/webkit/SystemImpl.java
@@ -41,7 +41,8 @@ import android.webkit.WebViewZygote;
import com.android.internal.util.XmlUtils;
import com.android.server.LocalServices;
-import com.android.server.PinnerService;
+import com.android.server.pinner.PinnedFile;
+import com.android.server.pinner.PinnerService;
import org.xmlpull.v1.XmlPullParserException;
@@ -318,8 +319,9 @@ public class SystemImpl implements SystemInterface {
if (webviewPinQuota <= 0) {
break;
}
- int bytesPinned = pinnerService.pinFile(apk, webviewPinQuota, appInfo, PIN_GROUP);
- webviewPinQuota -= bytesPinned;
+ PinnedFile pf = pinnerService.pinFile(
+ apk, webviewPinQuota, appInfo, PIN_GROUP, /*pinOptimizedDeps=*/true);
+ webviewPinQuota -= pf.bytesPinned;
}
}
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java
index d29ff540e391..4092a0b96c5d 100644
--- a/services/core/java/com/android/server/wm/ActivityStarter.java
+++ b/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -100,6 +100,7 @@ import android.app.ProfilerInfo;
import android.app.WaitResult;
import android.app.WindowConfiguration;
import android.compat.annotation.ChangeId;
+import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledSince;
import android.content.IIntentSender;
import android.content.Intent;
@@ -182,7 +183,7 @@ class ActivityStarter {
* Feature flag for go/activity-security rules
*/
@ChangeId
- @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ @Disabled
static final long ASM_RESTRICTIONS = 230590090L;
private final ActivityTaskManagerService mService;
diff --git a/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java b/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java
index 241390c12818..fbf9478b4fd9 100644
--- a/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java
+++ b/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java
@@ -170,7 +170,7 @@ class AppCompatCameraOverrides {
* </ul>
*/
boolean shouldApplyFreeformTreatmentForCameraCompat() {
- return Flags.cameraCompatForFreeform() && !isChangeEnabled(mActivityRecord,
+ return Flags.enableCameraCompatForDesktopWindowing() && !isChangeEnabled(mActivityRecord,
OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT);
}
diff --git a/services/core/java/com/android/server/wm/AppCompatCameraPolicy.java b/services/core/java/com/android/server/wm/AppCompatCameraPolicy.java
index 67bfd7605128..5338c01666fe 100644
--- a/services/core/java/com/android/server/wm/AppCompatCameraPolicy.java
+++ b/services/core/java/com/android/server/wm/AppCompatCameraPolicy.java
@@ -48,8 +48,9 @@ class AppCompatCameraPolicy {
// without the need to restart the device.
final boolean needsDisplayRotationCompatPolicy =
wmService.mAppCompatConfiguration.isCameraCompatTreatmentEnabledAtBuildTime();
- final boolean needsCameraCompatFreeformPolicy = Flags.cameraCompatForFreeform()
- && DesktopModeHelper.canEnterDesktopMode(wmService.mContext);
+ final boolean needsCameraCompatFreeformPolicy =
+ Flags.enableCameraCompatForDesktopWindowing()
+ && DesktopModeHelper.canEnterDesktopMode(wmService.mContext);
if (needsDisplayRotationCompatPolicy || needsCameraCompatFreeformPolicy) {
mCameraStateMonitor = new CameraStateMonitor(displayContent, wmService.mH);
mActivityRefresher = new ActivityRefresher(wmService, wmService.mH);
diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
index 2259b5a5b08c..515f148ac2ff 100644
--- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
+++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
@@ -1120,7 +1120,9 @@ public class BackgroundActivityStartController {
@Nullable Task targetTask, int launchFlags, int balCode, int callingUid,
int realCallingUid, TaskDisplayArea preferredTaskDisplayArea) {
// BAL Exception allowed in all cases
- if (balCode == BAL_ALLOW_ALLOWLISTED_UID) {
+ if (balCode == BAL_ALLOW_ALLOWLISTED_UID
+ || (android.security.Flags.asmReintroduceGracePeriod()
+ && balCode == BAL_ALLOW_GRACE_PERIOD)) {
return true;
}
@@ -1173,10 +1175,15 @@ public class BackgroundActivityStartController {
ArrayList<Task> visibleTasks = displayArea.getVisibleTasks();
for (int i = 0; i < visibleTasks.size(); i++) {
Task task = visibleTasks.get(i);
- if (visibleTasks.size() == 1 && task.isActivityTypeHomeOrRecents()) {
- bas.optedIn(task.getTopMostActivity());
- } else {
+ if (android.security.Flags.asmReintroduceGracePeriod()) {
bas = checkTopActivityForAsm(task, callingUid, /*sourceRecord*/null, bas);
+ } else {
+ if (visibleTasks.size() == 1 && task.isActivityTypeHomeOrRecents()) {
+ bas.optedIn(task.getTopMostActivity());
+ } else {
+ bas = checkTopActivityForAsm(
+ task, callingUid, /*sourceRecord*/null, bas);
+ }
}
}
}
diff --git a/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java b/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java
index e3232e08749e..d6caa1a248b4 100644
--- a/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java
+++ b/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java
@@ -124,7 +124,7 @@ final class CameraCompatFreeformPolicy implements CameraStateMonitor.CameraCompa
*/
@VisibleForTesting
boolean shouldApplyFreeformTreatmentForCameraCompat(@NonNull ActivityRecord activity) {
- return Flags.cameraCompatForFreeform() && !activity.info.isChangeEnabled(
+ return Flags.enableCameraCompatForDesktopWindowing() && !activity.info.isChangeEnabled(
ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT);
}
diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java
index ddbfd70ea4c4..d7dc4597c508 100644
--- a/services/core/java/com/android/server/wm/InputMonitor.java
+++ b/services/core/java/com/android/server/wm/InputMonitor.java
@@ -222,7 +222,8 @@ final class InputMonitor {
UserHandle clientUser) {
final InputConsumerImpl existingConsumer = getInputConsumer(name);
if (existingConsumer != null && existingConsumer.mClientUser.equals(clientUser)) {
- throw new IllegalStateException("Existing input consumer found with name: " + name
+ destroyInputConsumer(existingConsumer.mToken);
+ Slog.w(TAG_WM, "Replacing existing input consumer found with name: " + name
+ ", display: " + mDisplayId + ", user: " + clientUser);
}
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 86bb75ab3f8c..14f034bb8445 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -66,6 +66,7 @@ import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_LOCKTASK;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_STATES;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_TASKS;
+import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS_MIN;
import static com.android.server.wm.ActivityRecord.State.PAUSED;
import static com.android.server.wm.ActivityRecord.State.PAUSING;
import static com.android.server.wm.ActivityRecord.State.RESUMED;
@@ -6177,6 +6178,8 @@ class Task extends TaskFragment {
void maybeApplyLastRecentsAnimationTransaction() {
if (mLastRecentsAnimationTransaction != null) {
+ ProtoLog.d(WM_DEBUG_WINDOW_TRANSITIONS_MIN,
+ "Applying last recents animation transaction.");
final SurfaceControl.Transaction tx = getPendingTransaction();
if (mLastRecentsAnimationOverlay != null) {
tx.reparent(mLastRecentsAnimationOverlay, mSurfaceControl);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index b8f47cce6005..942634704ff5 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -9007,7 +9007,9 @@ public class WindowManagerService extends IWindowManager.Stub
final boolean isInputTargetNotFocused =
mFocusedInputTarget != t && mFocusedInputTarget != null;
- if (!isInputTargetNotFocused) {
+ final boolean isTouchOnFocusedDisplay = mFocusedInputTarget != null
+ && t.getDisplayId() == mFocusedInputTarget.getDisplayId();
+ if (!(isInputTargetNotFocused && isTouchOnFocusedDisplay)) {
return false;
}
diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java
index 476443aa2050..f35f2b30c5d4 100644
--- a/services/core/java/com/android/server/wm/WindowOrganizerController.java
+++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java
@@ -799,7 +799,12 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
}
} finally {
if (deferTransitionReady) {
- chain.mTransition.continueTransitionReady();
+ if (chain.mTransition.isCollecting()) {
+ chain.mTransition.continueTransitionReady();
+ } else {
+ Slog.wtf(TAG, "Too late, transition : " + chain.mTransition.getSyncId()
+ + " state: " + chain.mTransition.getState() + " is not collecting");
+ }
}
mService.mTaskSupervisor.setDeferRootVisibilityUpdate(false /* deferUpdate */);
if (deferResume) {
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 4c4b4f65edf5..0e3ab63aefb9 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -1969,6 +1969,13 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
boolean isReadyForDisplay() {
final boolean parentAndClientVisible = !isParentWindowHidden()
&& mViewVisibility == View.VISIBLE;
+ // TODO(b/338426357): Remove this once the last target using legacy transitions is moved to
+ // shell transitions
+ if (!mTransitionController.isShellTransitionsEnabled()) {
+ return mHasSurface && isVisibleByPolicy() && !mDestroying
+ && ((parentAndClientVisible && mToken.isVisible())
+ || isAnimating(TRANSITION | PARENTS));
+ }
return mHasSurface && isVisibleByPolicy() && !mDestroying && mToken.isVisible()
&& (parentAndClientVisible || isAnimating(TRANSITION | PARENTS));
}
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 5cd117b512d4..efca90217e83 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -56,6 +56,7 @@
#include <nativehelper/ScopedPrimitiveArray.h>
#include <nativehelper/ScopedUtfChars.h>
#include <server_configurable_flags/get_flags.h>
+#include <ui/LogicalDisplayId.h>
#include <ui/Region.h>
#include <utils/Log.h>
#include <utils/Looper.h>
@@ -64,6 +65,7 @@
#include <atomic>
#include <cinttypes>
+#include <map>
#include <vector>
#include "android_hardware_display_DisplayViewport.h"
@@ -343,7 +345,7 @@ public:
void setTouchpadRightClickZoneEnabled(bool enabled);
void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
void setShowTouches(bool enabled);
- void setInteractive(bool interactive);
+ void setNonInteractiveDisplays(const std::set<ui::LogicalDisplayId>& displayIds);
void reloadCalibration();
void reloadPointerIcons();
void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled);
@@ -508,9 +510,11 @@ private:
// Keycodes to be remapped.
std::map<int32_t /* fromKeyCode */, int32_t /* toKeyCode */> keyRemapping{};
+
+ // Displays which are non-interactive.
+ std::set<ui::LogicalDisplayId> nonInteractiveDisplays;
} mLocked GUARDED_BY(mLock);
- std::atomic<bool> mInteractive;
void updateInactivityTimeoutLocked();
void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
void ensureSpriteControllerLocked();
@@ -524,12 +528,13 @@ private:
void forEachPointerControllerLocked(std::function<void(PointerController&)> apply)
REQUIRES(mLock);
PointerIcon loadPointerIcon(JNIEnv* env, ui::LogicalDisplayId displayId, PointerIconStyle type);
+ bool isDisplayInteractive(ui::LogicalDisplayId displayId);
static inline JNIEnv* jniEnv() { return AndroidRuntime::getJNIEnv(); }
};
NativeInputManager::NativeInputManager(jobject serviceObj, const sp<Looper>& looper)
- : mLooper(looper), mInteractive(true) {
+ : mLooper(looper) {
JNIEnv* env = jniEnv();
mServiceObj = env->NewGlobalRef(serviceObj);
@@ -547,9 +552,13 @@ NativeInputManager::~NativeInputManager() {
void NativeInputManager::dump(std::string& dump) {
dump += "Input Manager State:\n";
- dump += StringPrintf(INDENT "Interactive: %s\n", toString(mInteractive.load()));
{ // acquire lock
std::scoped_lock _l(mLock);
+ auto logicalDisplayIdToString = [](const ui::LogicalDisplayId& displayId) {
+ return std::to_string(displayId.val());
+ };
+ dump += StringPrintf(INDENT "Display not interactive: %s\n",
+ dumpSet(mLocked.nonInteractiveDisplays, streamableToString).c_str());
dump += StringPrintf(INDENT "System UI Lights Out: %s\n",
toString(mLocked.systemUiLightsOut));
dump += StringPrintf(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed);
@@ -1476,8 +1485,10 @@ void NativeInputManager::requestPointerCapture(const sp<IBinder>& windowToken, b
mInputManager->getDispatcher().requestPointerCapture(windowToken, enabled);
}
-void NativeInputManager::setInteractive(bool interactive) {
- mInteractive = interactive;
+void NativeInputManager::setNonInteractiveDisplays(
+ const std::set<ui::LogicalDisplayId>& displayIds) {
+ std::scoped_lock _l(mLock);
+ mLocked.nonInteractiveDisplays = displayIds;
}
void NativeInputManager::reloadCalibration() {
@@ -1606,7 +1617,7 @@ void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent& keyEvent,
// - Ignore untrusted events and pass them along.
// - Ask the window manager what to do with normal events and trusted injected events.
// - For normal events wake and brighten the screen if currently off or dim.
- const bool interactive = mInteractive.load();
+ const bool interactive = isDisplayInteractive(keyEvent.getDisplayId());
if (interactive) {
policyFlags |= POLICY_FLAG_INTERACTIVE;
}
@@ -1644,7 +1655,7 @@ void NativeInputManager::interceptMotionBeforeQueueing(ui::LogicalDisplayId disp
// - No special filtering for injected events required at this time.
// - Filter normal events based on screen state.
// - For normal events brighten (but do not wake) the screen if currently dim.
- const bool interactive = mInteractive.load();
+ const bool interactive = isDisplayInteractive(displayId);
if (interactive) {
policyFlags |= POLICY_FLAG_INTERACTIVE;
}
@@ -1683,6 +1694,24 @@ void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
}
}
+bool NativeInputManager::isDisplayInteractive(ui::LogicalDisplayId displayId) {
+ // If an input event doesn't have an associated id, use the default display id
+ if (displayId == ui::LogicalDisplayId::INVALID) {
+ displayId = ui::LogicalDisplayId::DEFAULT;
+ }
+
+ { // acquire lock
+ std::scoped_lock _l(mLock);
+
+ auto it = mLocked.nonInteractiveDisplays.find(displayId);
+ if (it != mLocked.nonInteractiveDisplays.end()) {
+ return false;
+ }
+ } // release lock
+
+ return true;
+}
+
nsecs_t NativeInputManager::interceptKeyBeforeDispatching(const sp<IBinder>& token,
const KeyEvent& keyEvent,
uint32_t policyFlags) {
@@ -2372,10 +2401,17 @@ static void nativeSetShowTouches(JNIEnv* env, jobject nativeImplObj, jboolean en
im->setShowTouches(enabled);
}
-static void nativeSetInteractive(JNIEnv* env, jobject nativeImplObj, jboolean interactive) {
+static void nativeSetNonInteractiveDisplays(JNIEnv* env, jobject nativeImplObj,
+ jintArray displayIds) {
NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
- im->setInteractive(interactive);
+ const std::vector displayIdsVec = getIntArray(env, displayIds);
+ std::set<ui::LogicalDisplayId> logicalDisplayIds;
+ for (int displayId : displayIdsVec) {
+ logicalDisplayIds.emplace(ui::LogicalDisplayId{displayId});
+ }
+
+ im->setNonInteractiveDisplays(logicalDisplayIds);
}
static void nativeReloadCalibration(JNIEnv* env, jobject nativeImplObj) {
@@ -3021,7 +3057,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
(void*)nativeSetShouldNotifyTouchpadHardwareState},
{"setTouchpadRightClickZoneEnabled", "(Z)V", (void*)nativeSetTouchpadRightClickZoneEnabled},
{"setShowTouches", "(Z)V", (void*)nativeSetShowTouches},
- {"setInteractive", "(Z)V", (void*)nativeSetInteractive},
+ {"setNonInteractiveDisplays", "([I)V", (void*)nativeSetNonInteractiveDisplays},
{"reloadCalibration", "()V", (void*)nativeReloadCalibration},
{"vibrate", "(I[J[III)V", (void*)nativeVibrate},
{"vibrateCombined", "(I[JLandroid/util/SparseArray;II)V", (void*)nativeVibrateCombined},
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index b6a4481902ab..4e89b85305d1 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -4152,8 +4152,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
private void checkAllUsersAreAffiliatedWithDevice() {
- Preconditions.checkCallAuthorization(areAllUsersAffiliatedWithDeviceLocked(),
- "operation not allowed when device has unaffiliated users");
+ synchronized (getLockObject()) {
+ Preconditions.checkCallAuthorization(areAllUsersAffiliatedWithDeviceLocked(),
+ "operation not allowed when device has unaffiliated users");
+ }
}
@Override
@@ -11362,7 +11364,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
if (mOwners.hasDeviceOwner()) {
return false;
}
-
+
final ComponentName profileOwner = getProfileOwnerAsUser(userId);
if (profileOwner == null) {
return false;
@@ -11371,7 +11373,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
if (isManagedProfile(userId)) {
return false;
}
-
+
return true;
}
private void enforceCanQueryLockTaskLocked(ComponentName who, String callerPackageName) {
@@ -18213,6 +18215,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return false;
}
+ @GuardedBy("getLockObject()")
private boolean areAllUsersAffiliatedWithDeviceLocked() {
return mInjector.binderWithCleanCallingIdentity(() -> {
final List<UserInfo> userInfos = mUserManager.getAliveUsers();
@@ -18310,10 +18313,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
final CallerIdentity caller = getCallerIdentity(admin, packageName);
if (isPermissionCheckFlagEnabled()) {
- Preconditions.checkCallAuthorization(isOrganizationOwnedDeviceWithManagedProfile()
- || areAllUsersAffiliatedWithDeviceLocked());
- enforcePermission(MANAGE_DEVICE_POLICY_SECURITY_LOGGING, caller.getPackageName(),
- UserHandle.USER_ALL);
+ synchronized (getLockObject()) {
+ Preconditions.checkCallAuthorization(isOrganizationOwnedDeviceWithManagedProfile()
+ || areAllUsersAffiliatedWithDeviceLocked());
+ enforcePermission(MANAGE_DEVICE_POLICY_SECURITY_LOGGING, caller.getPackageName(),
+ UserHandle.USER_ALL);
+ }
} else {
if (admin != null) {
Preconditions.checkCallAuthorization(
@@ -18325,8 +18330,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
isCallerDelegate(caller, DELEGATION_SECURITY_LOGGING));
}
- Preconditions.checkCallAuthorization(isOrganizationOwnedDeviceWithManagedProfile()
- || areAllUsersAffiliatedWithDeviceLocked());
+ synchronized (getLockObject()) {
+ Preconditions.checkCallAuthorization(isOrganizationOwnedDeviceWithManagedProfile()
+ || areAllUsersAffiliatedWithDeviceLocked());
+ }
}
DevicePolicyEventLogger
@@ -24540,7 +24547,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
});
}
-
+
+ @GuardedBy("getLockObject()")
private void migrateUserControlDisabledPackagesLocked() {
Binder.withCleanCallingIdentity(() -> {
List<UserInfo> users = mUserManager.getUsers();
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 5cf260adece6..ce6f1ecc9463 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -205,6 +205,7 @@ import com.android.server.os.SchedulingPolicyService;
import com.android.server.pdb.PersistentDataBlockService;
import com.android.server.people.PeopleService;
import com.android.server.permission.access.AccessCheckingService;
+import com.android.server.pinner.PinnerService;
import com.android.server.pm.ApexManager;
import com.android.server.pm.ApexSystemServiceInfo;
import com.android.server.pm.BackgroundInstallControlService;
diff --git a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/pkg/PackageStateTest.kt b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/pkg/PackageStateTest.kt
index b21c34905bad..2144785ed8fd 100644
--- a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/pkg/PackageStateTest.kt
+++ b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/pkg/PackageStateTest.kt
@@ -94,6 +94,7 @@ class PackageStateTest {
ParsedService::getIntents,
ParsedService::getProperties,
Intent::getCategories,
+ Intent::getExtraIntentKeys,
PackageUserState::getDisabledComponents,
PackageUserState::getEnabledComponents,
PackageUserState::getSharedLibraryOverlayPaths,
diff --git a/services/tests/RemoteProvisioningServiceTests/Android.bp b/services/tests/RemoteProvisioningServiceTests/Android.bp
index 19c913620760..3a73c3954d52 100644
--- a/services/tests/RemoteProvisioningServiceTests/Android.bp
+++ b/services/tests/RemoteProvisioningServiceTests/Android.bp
@@ -31,7 +31,6 @@ android_test {
"service-rkp.impl",
"services.core",
"truth",
- "truth-java8-extension",
],
test_suites: [
"device-tests",
diff --git a/services/tests/RemoteProvisioningServiceTests/src/com/android/server/security/rkp/RemoteProvisioningShellCommandTest.java b/services/tests/RemoteProvisioningServiceTests/src/com/android/server/security/rkp/RemoteProvisioningShellCommandTest.java
index 007c0db1b731..a1616c676dbd 100644
--- a/services/tests/RemoteProvisioningServiceTests/src/com/android/server/security/rkp/RemoteProvisioningShellCommandTest.java
+++ b/services/tests/RemoteProvisioningServiceTests/src/com/android/server/security/rkp/RemoteProvisioningShellCommandTest.java
@@ -17,7 +17,6 @@
package com.android.server.security.rkp;
import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.Truth8.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
diff --git a/services/tests/appfunctions/src/android/app/appfunctions/GenericDocumentWrapperTest.kt b/services/tests/appfunctions/src/android/app/appfunctions/GenericDocumentWrapperTest.kt
new file mode 100644
index 000000000000..413eb314c41d
--- /dev/null
+++ b/services/tests/appfunctions/src/android/app/appfunctions/GenericDocumentWrapperTest.kt
@@ -0,0 +1,78 @@
+/*
+ * 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 android.app.appfunctions
+
+import android.app.appsearch.GenericDocument
+import android.os.Parcel
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+
+@RunWith(JUnit4::class)
+class GenericDocumentWrapperTest {
+
+ @Test
+ fun parcelUnparcel() {
+ val doc =
+ GenericDocument.Builder<GenericDocument.Builder<*>>("", "", "")
+ .setPropertyLong("test", 42)
+ .build()
+ val wrapper = GenericDocumentWrapper(doc)
+
+ val recovered = parcelUnparcel(wrapper)
+
+ assertThat(recovered.value.getPropertyLong("test")).isEqualTo(42)
+ }
+
+ @Test
+ fun parcelUnparcel_afterGetValue() {
+ val doc =
+ GenericDocument.Builder<GenericDocument.Builder<*>>("", "", "")
+ .setPropertyLong("test", 42)
+ .build()
+ val wrapper = GenericDocumentWrapper(doc)
+ assertThat(wrapper.value.getPropertyLong("test")).isEqualTo(42)
+
+ val recovered = parcelUnparcel(wrapper)
+
+ assertThat(recovered.value.getPropertyLong("test")).isEqualTo(42)
+ }
+
+
+ @Test
+ fun getValue() {
+ val doc =
+ GenericDocument.Builder<GenericDocument.Builder<*>>("", "", "")
+ .setPropertyLong("test", 42)
+ .build()
+ val wrapper = GenericDocumentWrapper(doc)
+
+ assertThat(wrapper.value.getPropertyLong("test")).isEqualTo(42)
+ }
+
+ private fun parcelUnparcel(obj: GenericDocumentWrapper): GenericDocumentWrapper {
+ val parcel = Parcel.obtain()
+ try {
+ obj.writeToParcel(parcel, 0)
+ parcel.setDataPosition(0)
+ return GenericDocumentWrapper.CREATOR.createFromParcel(parcel)
+ } finally {
+ parcel.recycle()
+ }
+ }
+} \ No newline at end of file
diff --git a/services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java b/services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java
index fc4d8d871fd5..07029268661e 100644
--- a/services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java
+++ b/services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java
@@ -16,6 +16,9 @@
package com.android.server.power;
+import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP;
+import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE;
+
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
@@ -31,11 +34,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
+import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.res.Resources;
import android.hardware.SensorManager;
import android.hardware.display.AmbientDisplayConfiguration;
+import android.hardware.display.DisplayManagerInternal;
import android.os.BatteryStats;
import android.os.Handler;
import android.os.IWakeLockCallback;
@@ -48,11 +53,18 @@ import android.os.WorkSource;
import android.os.test.TestLooper;
import android.provider.Settings;
import android.testing.TestableContext;
+import android.util.IntArray;
+import android.util.SparseBooleanArray;
+import android.view.Display;
+import android.view.DisplayAddress;
+import android.view.DisplayInfo;
import androidx.test.InstrumentationRegistry;
import com.android.internal.app.IBatteryStats;
import com.android.server.LocalServices;
+import com.android.server.input.InputManagerInternal;
+import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.power.batterysaver.BatterySaverStateMachine;
import com.android.server.power.feature.PowerManagerFlags;
@@ -71,6 +83,8 @@ import java.util.concurrent.Executor;
public class NotifierTest {
private static final String SYSTEM_PROPERTY_QUIESCENT = "ro.boot.quiescent";
private static final int USER_ID = 0;
+ private static final int DISPLAY_PORT = 0xFF;
+ private static final long DISPLAY_MODEL = 0xEEEEEEEEL;
@Mock private BatterySaverStateMachine mBatterySaverStateMachineMock;
@Mock private PowerManagerService.NativeWrapper mNativeWrapperMock;
@@ -81,10 +95,16 @@ public class NotifierTest {
@Mock private InattentiveSleepWarningController mInattentiveSleepWarningControllerMock;
@Mock private Vibrator mVibrator;
@Mock private StatusBarManagerInternal mStatusBarManagerInternal;
+ @Mock private InputManagerInternal mInputManagerInternal;
+ @Mock private InputMethodManagerInternal mInputMethodManagerInternal;
+ @Mock private DisplayManagerInternal mDisplayManagerInternal;
+ @Mock private ActivityManagerInternal mActivityManagerInternal;
@Mock private WakeLockLog mWakeLockLog;
@Mock private IBatteryStats mBatteryStats;
+ @Mock private WindowManagerPolicy mPolicy;
+
@Mock private PowerManagerFlags mPowerManagerFlags;
@Mock private AppOpsManager mAppOpsManager;
@@ -96,6 +116,8 @@ public class NotifierTest {
private FakeExecutor mTestExecutor = new FakeExecutor();
private Notifier mNotifier;
+ private DisplayInfo mDefaultDisplayInfo = new DisplayInfo();
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -103,11 +125,25 @@ public class NotifierTest {
LocalServices.removeServiceForTest(StatusBarManagerInternal.class);
LocalServices.addService(StatusBarManagerInternal.class, mStatusBarManagerInternal);
+ LocalServices.removeServiceForTest(InputManagerInternal.class);
+ LocalServices.addService(InputManagerInternal.class, mInputManagerInternal);
+ LocalServices.removeServiceForTest(InputMethodManagerInternal.class);
+ LocalServices.addService(InputMethodManagerInternal.class, mInputMethodManagerInternal);
+
+ LocalServices.removeServiceForTest(ActivityManagerInternal.class);
+ LocalServices.addService(ActivityManagerInternal.class, mActivityManagerInternal);
+
+ mDefaultDisplayInfo.address = DisplayAddress.fromPortAndModel(DISPLAY_PORT, DISPLAY_MODEL);
+ LocalServices.removeServiceForTest(DisplayManagerInternal.class);
+ LocalServices.addService(DisplayManagerInternal.class, mDisplayManagerInternal);
+
mContextSpy = spy(new TestableContext(InstrumentationRegistry.getContext()));
mResourcesSpy = spy(mContextSpy.getResources());
when(mContextSpy.getResources()).thenReturn(mResourcesSpy);
when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), anyString())).thenReturn("");
when(mContextSpy.getSystemService(Vibrator.class)).thenReturn(mVibrator);
+ when(mDisplayManagerInternal.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(
+ mDefaultDisplayInfo);
mService = new PowerManagerService(mContextSpy, mInjector);
}
@@ -232,6 +268,32 @@ public class NotifierTest {
}
@Test
+ public void testOnGlobalWakefulnessChangeStarted() throws Exception {
+ createNotifier();
+ // GIVEN system is currently non-interactive
+ when(mPowerManagerFlags.isPerDisplayWakeByTouchEnabled()).thenReturn(false);
+ final int displayId1 = 101;
+ final int displayId2 = 102;
+ final int[] displayIds = new int[]{displayId1, displayId2};
+ when(mDisplayManagerInternal.getDisplayIds()).thenReturn(IntArray.wrap(displayIds));
+ mNotifier.onGlobalWakefulnessChangeStarted(WAKEFULNESS_ASLEEP,
+ PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, /* eventTime= */ 1000);
+ mTestLooper.dispatchAll();
+
+ // WHEN a global wakefulness change to interactive starts
+ mNotifier.onGlobalWakefulnessChangeStarted(WAKEFULNESS_AWAKE,
+ PowerManager.WAKE_REASON_TAP, /* eventTime= */ 2000);
+ mTestLooper.dispatchAll();
+
+ // THEN input is notified of all displays being interactive
+ final SparseBooleanArray expectedDisplayInteractivities = new SparseBooleanArray();
+ expectedDisplayInteractivities.put(displayId1, true);
+ expectedDisplayInteractivities.put(displayId2, true);
+ verify(mInputManagerInternal).setDisplayInteractivities(expectedDisplayInteractivities);
+ verify(mInputMethodManagerInternal).setInteractive(/* interactive= */ true);
+ }
+
+ @Test
public void testOnWakeLockListener_RemoteException_NoRethrow() throws RemoteException {
when(mPowerManagerFlags.improveWakelockLatency()).thenReturn(true);
createNotifier();
@@ -551,7 +613,7 @@ public class NotifierTest {
mContextSpy,
mBatteryStats,
mInjector.createSuspendBlocker(mService, "testBlocker"),
- null,
+ mPolicy,
null,
null,
mTestExecutor, mPowerManagerFlags, injector);
diff --git a/services/tests/powerstatstests/res/xml/irq_device_map_3.xml b/services/tests/powerstatstests/res/xml/irq_device_map_3.xml
index fd55428c48df..c3df0785bd9b 100644
--- a/services/tests/powerstatstests/res/xml/irq_device_map_3.xml
+++ b/services/tests/powerstatstests/res/xml/irq_device_map_3.xml
@@ -32,4 +32,7 @@
<device name="test.sensor.device">
<subsystem>Sensor</subsystem>
</device>
+ <device name="test.bluetooth.device">
+ <subsystem>Bluetooth</subsystem>
+ </device>
</irq-device-map> \ No newline at end of file
diff --git a/services/tests/powerstatstests/src/com/android/server/power/stats/wakeups/CpuWakeupStatsTest.java b/services/tests/powerstatstests/src/com/android/server/power/stats/wakeups/CpuWakeupStatsTest.java
index 0dc836ba0400..fe4d971face5 100644
--- a/services/tests/powerstatstests/src/com/android/server/power/stats/wakeups/CpuWakeupStatsTest.java
+++ b/services/tests/powerstatstests/src/com/android/server/power/stats/wakeups/CpuWakeupStatsTest.java
@@ -17,6 +17,7 @@
package com.android.server.power.stats.wakeups;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_ALARM;
+import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_BLUETOOTH;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_SENSOR;
import static android.os.BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER;
@@ -52,6 +53,7 @@ public class CpuWakeupStatsTest {
private static final String KERNEL_REASON_SOUND_TRIGGER_IRQ = "129 test.sound_trigger.device";
private static final String KERNEL_REASON_SENSOR_IRQ = "15 test.sensor.device";
private static final String KERNEL_REASON_CELLULAR_DATA_IRQ = "18 test.cellular_data.device";
+ private static final String KERNEL_REASON_BLUETOOTH_IRQ = "19 test.bluetooth.device";
private static final String KERNEL_REASON_UNKNOWN_IRQ = "140 test.unknown.device";
private static final String KERNEL_REASON_UNKNOWN_FORMAT = "free-form-reason test.alarm.device";
private static final String KERNEL_REASON_ALARM_ABNORMAL = "-1 test.alarm.device";
@@ -62,12 +64,14 @@ public class CpuWakeupStatsTest {
private static final int TEST_UID_3 = 92261423;
private static final int TEST_UID_4 = 56926423;
private static final int TEST_UID_5 = 76421423;
+ private static final int TEST_UID_6 = 62345353;
private static final int TEST_PROC_STATE_1 = 72331;
private static final int TEST_PROC_STATE_2 = 792351;
private static final int TEST_PROC_STATE_3 = 138831;
private static final int TEST_PROC_STATE_4 = 23231;
private static final int TEST_PROC_STATE_5 = 42;
+ private static final int TEST_PROC_STATE_6 = 129942;
private static final Context sContext = InstrumentationRegistry.getTargetContext();
private final Handler mHandler = Mockito.mock(Handler.class);
@@ -79,6 +83,7 @@ public class CpuWakeupStatsTest {
obj.mUidProcStates.put(TEST_UID_3, TEST_PROC_STATE_3);
obj.mUidProcStates.put(TEST_UID_4, TEST_PROC_STATE_4);
obj.mUidProcStates.put(TEST_UID_5, TEST_PROC_STATE_5);
+ obj.mUidProcStates.put(TEST_UID_6, TEST_PROC_STATE_6);
}
@Test
@@ -118,6 +123,7 @@ public class CpuWakeupStatsTest {
CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER,
CPU_WAKEUP_SUBSYSTEM_SENSOR,
CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA,
+ CPU_WAKEUP_SUBSYSTEM_BLUETOOTH,
};
final String[] kernelReasons = new String[] {
@@ -126,10 +132,11 @@ public class CpuWakeupStatsTest {
KERNEL_REASON_SOUND_TRIGGER_IRQ,
KERNEL_REASON_SENSOR_IRQ,
KERNEL_REASON_CELLULAR_DATA_IRQ,
+ KERNEL_REASON_BLUETOOTH_IRQ,
};
final int[] uids = new int[] {
- TEST_UID_2, TEST_UID_3, TEST_UID_4, TEST_UID_1, TEST_UID_5
+ TEST_UID_2, TEST_UID_3, TEST_UID_4, TEST_UID_1, TEST_UID_5, TEST_UID_6
};
final int[] procStates = new int[] {
@@ -137,7 +144,8 @@ public class CpuWakeupStatsTest {
TEST_PROC_STATE_3,
TEST_PROC_STATE_4,
TEST_PROC_STATE_1,
- TEST_PROC_STATE_5
+ TEST_PROC_STATE_5,
+ TEST_PROC_STATE_6
};
final int total = subsystems.length;
@@ -285,6 +293,40 @@ public class CpuWakeupStatsTest {
}
@Test
+ public void bluetoothIrqAttributionSolo() {
+ final CpuWakeupStats obj = new CpuWakeupStats(sContext, R.xml.irq_device_map_3, mHandler);
+ final long wakeupTime = 1236121;
+
+ populateDefaultProcStates(obj);
+
+ obj.noteWakeupTimeAndReason(wakeupTime, 1, KERNEL_REASON_BLUETOOTH_IRQ);
+
+ // Outside the window, so should be ignored.
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH,
+ wakeupTime - obj.mConfig.WAKEUP_MATCHING_WINDOW_MS - 1, TEST_UID_1);
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH,
+ wakeupTime + obj.mConfig.WAKEUP_MATCHING_WINDOW_MS + 1, TEST_UID_2);
+ // Should be attributed
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH, wakeupTime + 5, TEST_UID_3,
+ TEST_UID_5);
+
+ final SparseArray<SparseIntArray> attribution = obj.mWakeupAttribution.get(wakeupTime);
+ assertThat(attribution).isNotNull();
+ assertThat(attribution.size()).isEqualTo(1);
+ assertThat(attribution.contains(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH)).isTrue();
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).indexOfKey(
+ TEST_UID_1)).isLessThan(0);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).indexOfKey(
+ TEST_UID_2)).isLessThan(0);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).get(TEST_UID_3)).isEqualTo(
+ TEST_PROC_STATE_3);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).indexOfKey(
+ TEST_UID_4)).isLessThan(0);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).get(TEST_UID_5)).isEqualTo(
+ TEST_PROC_STATE_5);
+ }
+
+ @Test
public void alarmAndWifiIrqAttribution() {
final CpuWakeupStats obj = new CpuWakeupStats(sContext, R.xml.irq_device_map_3, mHandler);
final long wakeupTime = 92123210;
@@ -400,6 +442,47 @@ public class CpuWakeupStatsTest {
}
@Test
+ public void unknownAndBluetoothAttribution() {
+ final CpuWakeupStats obj = new CpuWakeupStats(sContext, R.xml.irq_device_map_3, mHandler);
+ final long wakeupTime = 92123520;
+
+ populateDefaultProcStates(obj);
+
+ obj.noteWakeupTimeAndReason(wakeupTime, 24,
+ KERNEL_REASON_UNKNOWN_IRQ + ":" + KERNEL_REASON_BLUETOOTH_IRQ);
+
+ // Bluetooth activity
+ // Outside the window, so should be ignored.
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH,
+ wakeupTime - obj.mConfig.WAKEUP_MATCHING_WINDOW_MS - 1, TEST_UID_4);
+ // Should be attributed
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH, wakeupTime + 2, TEST_UID_1);
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH, wakeupTime - 1, TEST_UID_3,
+ TEST_UID_5);
+
+ // Unrelated, should be ignored.
+ obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime + 5, TEST_UID_3);
+
+ final SparseArray<SparseIntArray> attribution = obj.mWakeupAttribution.get(wakeupTime);
+ assertThat(attribution).isNotNull();
+ assertThat(attribution.size()).isEqualTo(2);
+ assertThat(attribution.contains(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH)).isTrue();
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).get(TEST_UID_1)).isEqualTo(
+ TEST_PROC_STATE_1);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH)
+ .indexOfKey(TEST_UID_2)).isLessThan(0);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).get(TEST_UID_3)).isEqualTo(
+ TEST_PROC_STATE_3);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH)
+ .indexOfKey(TEST_UID_4)).isLessThan(0);
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_BLUETOOTH).get(TEST_UID_5)).isEqualTo(
+ TEST_PROC_STATE_5);
+ assertThat(attribution.contains(CPU_WAKEUP_SUBSYSTEM_UNKNOWN)).isTrue();
+ assertThat(attribution.get(CPU_WAKEUP_SUBSYSTEM_UNKNOWN)).isNull();
+ assertThat(attribution.contains(CPU_WAKEUP_SUBSYSTEM_ALARM)).isFalse();
+ }
+
+ @Test
public void unknownFormatWakeupIgnored() {
final CpuWakeupStats obj = new CpuWakeupStats(sContext, R.xml.irq_device_map_3, mHandler);
final long wakeupTime = 72123210;
diff --git a/services/tests/servicestests/Android.bp b/services/tests/servicestests/Android.bp
index ac1b7c6876f7..cbe6700f4d41 100644
--- a/services/tests/servicestests/Android.bp
+++ b/services/tests/servicestests/Android.bp
@@ -52,6 +52,7 @@ android_test {
"services.credentials",
"services.devicepolicy",
"services.flags",
+ "com.android.server.flags.services-aconfig-java",
"services.net",
"services.people",
"services.supervision",
@@ -81,6 +82,7 @@ android_test {
// TODO: remove once Android migrates to JUnit 4.12,
// which provides assertThrows
"testng",
+ "flag-junit",
"junit",
"junit-params",
"ActivityContext",
diff --git a/services/tests/servicestests/src/com/android/server/PinnerServiceTest.java b/services/tests/servicestests/src/com/android/server/PinnerServiceTest.java
index ec78bcea7539..c18faef2c028 100644
--- a/services/tests/servicestests/src/com/android/server/PinnerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/PinnerServiceTest.java
@@ -31,6 +31,9 @@ import android.content.pm.ResolveInfo;
import android.os.Binder;
import android.os.Handler;
import android.os.Looper;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;
import android.testing.TestableContext;
@@ -43,6 +46,9 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import com.android.server.flags.Flags;
+import com.android.server.pinner.PinnedFile;
+import com.android.server.pinner.PinnerService;
import com.android.server.testutils.FakeDeviceConfigInterface;
import com.android.server.wm.ActivityTaskManagerInternal;
@@ -73,15 +79,18 @@ public class PinnerServiceTest {
private static final long WAIT_FOR_PINNER_TIMEOUT = TimeUnit.SECONDS.toMillis(2);
+ private static final int MEMORY_PERCENTAGE_FOR_QUOTA = 10;
+
@Rule
public TestableContext mContext =
new TestableContext(InstrumentationRegistry.getContext(), null);
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
private final ArraySet<String> mUpdatedPackages = new ArraySet<>();
private ResolveInfo mHomePackageResolveInfo;
private FakeDeviceConfigInterface mFakeDeviceConfigInterface;
private PinnerService.Injector mInjector;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -114,6 +123,8 @@ public class PinnerServiceTest {
resources.addOverride(com.android.internal.R.bool.config_pinnerCameraApp, false);
resources.addOverride(com.android.internal.R.integer.config_pinnerHomePinBytes, 0);
resources.addOverride(com.android.internal.R.bool.config_pinnerAssistantApp, false);
+ resources.addOverride(com.android.internal.R.integer.config_pinnerMaxPinnedMemoryPercentage,
+ MEMORY_PERCENTAGE_FOR_QUOTA);
mFakeDeviceConfigInterface = new FakeDeviceConfigInterface();
setDeviceConfigPinnedAnonSize(0);
@@ -138,10 +149,9 @@ public class PinnerServiceTest {
}
@Override
- protected PinnerService.PinnedFile pinFileInternal(String fileToPin,
- int maxBytesToPin, boolean attemptPinIntrospection) {
- return new PinnerService.PinnedFile(-1,
- maxBytesToPin, fileToPin, maxBytesToPin);
+ protected PinnedFile pinFileInternal(PinnerService service, String fileToPin,
+ long maxBytesToPin, boolean attemptPinIntrospection) {
+ return new PinnedFile(-1, maxBytesToPin, fileToPin, maxBytesToPin);
}
};
}
@@ -167,6 +177,12 @@ public class PinnerServiceTest {
unpinAnonRegionMethod.invoke(pinnerService);
}
+ private long getGlobalPinQuota(PinnerService service) throws Exception {
+ Method getQuotaMethod = PinnerService.class.getDeclaredMethod("getAvailableGlobalQuota");
+ getQuotaMethod.setAccessible(true);
+ return (long) getQuotaMethod.invoke(service);
+ }
+
private void waitForPinnerService(PinnerService pinnerService)
throws NoSuchFieldException, IllegalAccessException {
// There's no notification/callback when pinning finished
@@ -315,15 +331,121 @@ public class PinnerServiceTest {
PinnerService pinnerService = new PinnerService(mContext, mInjector);
pinnerService.onStart();
- pinnerService.pinFile("test_file", 4096, null, "my_group");
+ pinnerService.pinFile("test_file", 4096, null, "my_group", false);
- assertThat(getPinnedSize(pinnerService)).isGreaterThan(0);
- assertThat(getTotalPinnedFiles(pinnerService)).isGreaterThan(0);
+ assertThat(getPinnedSize(pinnerService)).isEqualTo(4096);
+ assertThat(getTotalPinnedFiles(pinnerService)).isEqualTo(1);
+
+ unpinAll(pinnerService);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_PIN_GLOBAL_QUOTA)
+ public void testPinAllQuota() throws Exception {
+ PinnerService pinnerService = new PinnerService(mContext, mInjector);
+ pinnerService.onStart();
+
+ long quota = getGlobalPinQuota(pinnerService);
+
+ pinnerService.pinFile("test_file", Long.MAX_VALUE, null, "my_group", false);
+
+ assertThat(getPinnedSize(pinnerService)).isEqualTo(quota);
unpinAll(pinnerService);
}
@Test
+ @EnableFlags(Flags.FLAG_PIN_GLOBAL_QUOTA)
+ public void testGlobalPinQuotaAsDevicePercentage() throws Exception {
+ PinnerService pinnerService = new PinnerService(mContext, mInjector);
+ pinnerService.onStart();
+ long origQuota = getGlobalPinQuota(pinnerService);
+
+ long totalMem = android.os.Process.getTotalMemory();
+
+ // Verify that pin quota is the set percentage of device total memory
+ assertThat(origQuota).isEqualTo((totalMem * MEMORY_PERCENTAGE_FOR_QUOTA) / 100);
+
+ pinnerService.pinFile("test_file", 4096, null, "my_group", false);
+ assertThat(getGlobalPinQuota(pinnerService)).isEqualTo(origQuota - 4096);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_PIN_GLOBAL_QUOTA)
+ public void testGlobalPinWhenNoQuota() throws Exception {
+ TestableResources resources = mContext.getOrCreateTestableResources();
+ resources.addOverride(
+ com.android.internal.R.integer.config_pinnerMaxPinnedMemoryPercentage, 0);
+
+ PinnerService pinnerService = new PinnerService(mContext, mInjector);
+ pinnerService.onStart();
+
+ // Verify that pin quota is zero
+ assertThat(getGlobalPinQuota(pinnerService)).isEqualTo(0);
+
+ pinnerService.pinFile("test_file", 4096, null, "my_group", false);
+ assertThat(getTotalPinnedFiles(pinnerService)).isEqualTo(0);
+ }
+
+ /**
+ * This test is temporary, it should be cleaned up when removing the pin_global_quota bugfix
+ * flag.
+ */
+ @Test
+ @DisableFlags(Flags.FLAG_PIN_GLOBAL_QUOTA)
+ public void testGlobalQuotaDisabled() throws Exception {
+ TestableResources resources = mContext.getOrCreateTestableResources();
+ resources.addOverride(
+ com.android.internal.R.integer.config_pinnerMaxPinnedMemoryPercentage, 0);
+
+ PinnerService pinnerService = new PinnerService(mContext, mInjector);
+ pinnerService.onStart();
+
+ // The quota parameter exists but it should have no effect on pinning
+ long quota = getGlobalPinQuota(pinnerService);
+
+ pinnerService.pinFile("test_file", quota + 1, null, "my_group", false);
+
+ // Verify that we can pin past the quota as it is disabled
+ assertThat(getPinnedSize(pinnerService)).isEqualTo(quota + 1);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_PIN_GLOBAL_QUOTA)
+ public void testUnpinReleasesQuota() throws Exception {
+ PinnerService pinnerService = new PinnerService(mContext, mInjector);
+ pinnerService.onStart();
+ long origQuota = getGlobalPinQuota(pinnerService);
+
+ // Verify that pin quota exists and is non zero.
+ assertThat(getGlobalPinQuota(pinnerService)).isGreaterThan(0);
+
+ pinnerService.pinFile("test_file", origQuota, null, "my_group", false);
+
+ // Make sure all the quota was consumed
+ assertThat(getPinnedSize(pinnerService)).isEqualTo(origQuota);
+
+ // Unpin the file and verify that the quota has been released.
+ pinnerService.unpinFile("test_file");
+ assertThat(getPinnedSize(pinnerService)).isEqualTo(0);
+ assertThat(getGlobalPinQuota(pinnerService)).isEqualTo(origQuota);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_PIN_GLOBAL_QUOTA)
+ public void testGlobalPinQuotaNegative() throws Exception {
+ TestableResources resources = mContext.getOrCreateTestableResources();
+ resources.addOverride(
+ com.android.internal.R.integer.config_pinnerMaxPinnedMemoryPercentage, -10);
+
+ PinnerService pinnerService = new PinnerService(mContext, mInjector);
+ pinnerService.onStart();
+
+ // Verify that pin quota is zero
+ assertThat(getGlobalPinQuota(pinnerService)).isEqualTo(0);
+ }
+
+ @Test
public void testPinAnonRegion() throws Exception {
setDeviceConfigPinnedAnonSize(32768);
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/AbstractAccessibilityServiceConnectionTest.java b/services/tests/servicestests/src/com/android/server/accessibility/AbstractAccessibilityServiceConnectionTest.java
index 6e6d5a870031..8dfd54fe38bc 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/AbstractAccessibilityServiceConnectionTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/AbstractAccessibilityServiceConnectionTest.java
@@ -174,8 +174,8 @@ public class AbstractAccessibilityServiceConnectionTest {
@Mock private AccessibilityTrace mMockA11yTrace;
@Mock private WindowManagerInternal mMockWindowManagerInternal;
@Mock private SystemActionPerformer mMockSystemActionPerformer;
- @Mock private IBinder mMockService;
- @Mock private IAccessibilityServiceClient mMockServiceInterface;
+ @Mock private IBinder mMockClientBinder;
+ @Mock private IAccessibilityServiceClient mMockClient;
@Mock private KeyEventDispatcher mMockKeyEventDispatcher;
@Mock private IAccessibilityInteractionConnection mMockIA11yInteractionConnection;
@Mock private IAccessibilityInteractionConnectionCallback mMockCallback;
@@ -247,9 +247,9 @@ public class AbstractAccessibilityServiceConnectionTest {
mSpyServiceInfo, SERVICE_ID, mHandler, new Object(), mMockSecurityPolicy,
mMockSystemSupport, mMockA11yTrace, mMockWindowManagerInternal,
mMockSystemActionPerformer, mMockA11yWindowManager);
- // Assume that the service is connected
- mServiceConnection.mService = mMockService;
- mServiceConnection.mServiceInterface = mMockServiceInterface;
+ // Assume that the client is connected
+ mServiceConnection.mClientBinder = mMockClientBinder;
+ mServiceConnection.mClient = mMockClient;
// Update security policy for this service
when(mMockSecurityPolicy.checkAccessibilityAccess(mServiceConnection)).thenReturn(true);
@@ -273,7 +273,7 @@ public class AbstractAccessibilityServiceConnectionTest {
final KeyEvent mockKeyEvent = mock(KeyEvent.class);
mServiceConnection.onKeyEvent(mockKeyEvent, sequenceNumber);
- verify(mMockServiceInterface).onKeyEvent(mockKeyEvent, sequenceNumber);
+ verify(mMockClient).onKeyEvent(mockKeyEvent, sequenceNumber);
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java
index 566feb7e3d80..7481fc8ec46d 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java
@@ -63,8 +63,11 @@ import static org.mockito.Mockito.when;
import android.Manifest;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.IAccessibilityServiceClient;
+import android.annotation.NonNull;
import android.app.PendingIntent;
import android.app.RemoteAction;
+import android.app.admin.DevicePolicyManager;
+import android.app.ecm.EnhancedConfirmationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -212,6 +215,7 @@ public class AccessibilityManagerServiceTest {
@Mock private FullScreenMagnificationController mMockFullScreenMagnificationController;
@Mock private ProxyManager mProxyManager;
@Mock private StatusBarManagerInternal mStatusBarManagerInternal;
+ @Mock private DevicePolicyManager mDevicePolicyManager;
@Spy private IUserInitializationCompleteCallback mUserInitializationCompleteCallback;
@Captor private ArgumentCaptor<Intent> mIntentArgumentCaptor;
private IAccessibilityManager mA11yManagerServiceOnDevice;
@@ -241,6 +245,7 @@ public class AccessibilityManagerServiceTest {
UserManagerInternal.class, mMockUserManagerInternal);
LocalServices.addService(StatusBarManagerInternal.class, mStatusBarManagerInternal);
mInputFilter = mock(FakeInputFilter.class);
+ mTestableContext.addMockSystemService(DevicePolicyManager.class, mDevicePolicyManager);
when(mMockMagnificationController.getMagnificationConnectionManager()).thenReturn(
mMockMagnificationConnectionManager);
@@ -2160,6 +2165,24 @@ public class AccessibilityManagerServiceTest {
.isEqualTo(SOFTWARE);
}
+ @Test
+ @EnableFlags({android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED,
+ android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS})
+ public void isAccessibilityTargetAllowed_nonSystemUserId_useEcmWithNonSystemUserId() {
+ String fakePackageName = "FAKE_PACKAGE_NAME";
+ int uid = 0; // uid is not used in the actual implementation when flags are on
+ int userId = mTestableContext.getUserId() + 1234;
+ when(mDevicePolicyManager.getPermittedAccessibilityServices(userId)).thenReturn(
+ List.of(fakePackageName));
+ Context mockUserContext = mock(Context.class);
+ mTestableContext.addMockUserContext(userId, mockUserContext);
+
+ mA11yms.isAccessibilityTargetAllowed(fakePackageName, uid, userId);
+
+ verify(mockUserContext).getSystemService(EnhancedConfirmationManager.class);
+ }
+
+
private Set<String> readStringsFromSetting(String setting) {
final Set<String> result = new ArraySet<>();
mA11yms.readColonDelimitedSettingToSet(
@@ -2280,6 +2303,7 @@ public class AccessibilityManagerServiceTest {
private final Context mMockContext;
private final Map<String, List<BroadcastReceiver>> mBroadcastReceivers = new ArrayMap<>();
+ private ArrayMap<Integer, Context> mMockUserContexts = new ArrayMap<>();
A11yTestableContext(Context base) {
super(base);
@@ -2317,6 +2341,19 @@ public class AccessibilityManagerServiceTest {
return mMockContext;
}
+ public void addMockUserContext(int userId, Context context) {
+ mMockUserContexts.put(userId, context);
+ }
+
+ @Override
+ @NonNull
+ public Context createContextAsUser(UserHandle user, int flags) {
+ if (mMockUserContexts.containsKey(user.getIdentifier())) {
+ return mMockUserContexts.get(user.getIdentifier());
+ }
+ return super.createContextAsUser(user, flags);
+ }
+
Map<String, List<BroadcastReceiver>> getBroadcastReceivers() {
return mBroadcastReceivers;
}
diff --git a/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
index b9ce8ad0b018..0c92abce7254 100644
--- a/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
@@ -1163,6 +1163,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
verify(mMockAccountManagerResponse).onResult(mBundleCaptor.capture());
Bundle result = mBundleCaptor.getValue();
+ Bundle sessionBundle = result.getBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE);
+ assertNotNull(sessionBundle);
+ // Assert that session bundle is decrypted and hence data is visible.
+ assertEquals(AccountManagerServiceTestFixtures.SESSION_DATA_VALUE_1,
+ sessionBundle.getString(AccountManagerServiceTestFixtures.SESSION_DATA_NAME_1));
+ // Assert finishSessionAsUser added calling uid and pid into the sessionBundle
+ assertTrue(sessionBundle.containsKey(AccountManager.KEY_CALLER_UID));
+ assertTrue(sessionBundle.containsKey(AccountManager.KEY_CALLER_PID));
+ assertEquals(sessionBundle.getString(
+ AccountManager.KEY_ANDROID_PACKAGE_NAME), "APCT.package");
// Verify response data
assertNull(result.getString(AccountManager.KEY_AUTHTOKEN, null));
@@ -2111,6 +2121,12 @@ public class AccountManagerServiceTest extends AndroidTestCase {
result.getString(AccountManager.KEY_ACCOUNT_NAME));
assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1,
result.getString(AccountManager.KEY_ACCOUNT_TYPE));
+
+ Bundle optionBundle = result.getParcelable(
+ AccountManagerServiceTestFixtures.KEY_OPTIONS_BUNDLE);
+ // Assert addAccountAsUser added calling uid and pid into the option bundle
+ assertTrue(optionBundle.containsKey(AccountManager.KEY_CALLER_UID));
+ assertTrue(optionBundle.containsKey(AccountManager.KEY_CALLER_PID));
}
@SmallTest
@@ -3441,52 +3457,6 @@ public class AccountManagerServiceTest extends AndroidTestCase {
+ (readTotalTime.doubleValue() / readerCount / loopSize));
}
- @SmallTest
- public void testSanitizeBundle_expectedFields() throws Exception {
- Bundle bundle = new Bundle();
- bundle.putString(AccountManager.KEY_ACCOUNT_NAME, "name");
- bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, "type");
- bundle.putString(AccountManager.KEY_AUTHTOKEN, "token");
- bundle.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, "label");
- bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error message");
- bundle.putString(AccountManager.KEY_PASSWORD, "password");
- bundle.putString(AccountManager.KEY_ACCOUNT_STATUS_TOKEN, "status");
-
- bundle.putLong(AbstractAccountAuthenticator.KEY_CUSTOM_TOKEN_EXPIRY, 123L);
- bundle.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
- bundle.putInt(AccountManager.KEY_ERROR_CODE, 456);
-
- Bundle sanitizedBundle = AccountManagerService.sanitizeBundle(bundle);
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_NAME), "name");
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_TYPE), "type");
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_AUTHTOKEN), "token");
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_AUTH_TOKEN_LABEL), "label");
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_ERROR_MESSAGE), "error message");
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_PASSWORD), "password");
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_STATUS_TOKEN), "status");
-
- assertEquals(sanitizedBundle.getLong(
- AbstractAccountAuthenticator.KEY_CUSTOM_TOKEN_EXPIRY, 0), 123L);
- assertEquals(sanitizedBundle.getBoolean(AccountManager.KEY_BOOLEAN_RESULT, false), true);
- assertEquals(sanitizedBundle.getInt(AccountManager.KEY_ERROR_CODE, 0), 456);
- }
-
- @SmallTest
- public void testSanitizeBundle_filtersUnexpectedFields() throws Exception {
- Bundle bundle = new Bundle();
- bundle.putString(AccountManager.KEY_ACCOUNT_NAME, "name");
- bundle.putString("unknown_key", "value");
- Bundle sessionBundle = new Bundle();
- bundle.putBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE, sessionBundle);
-
- Bundle sanitizedBundle = AccountManagerService.sanitizeBundle(bundle);
-
- assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_NAME), "name");
- assertFalse(sanitizedBundle.containsKey("unknown_key"));
- // It is a valid response from Authenticator which will be accessed using original Bundle
- assertFalse(sanitizedBundle.containsKey(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE));
- }
-
private void waitForCyclicBarrier(CyclicBarrier cyclicBarrier) {
try {
cyclicBarrier.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS);
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java b/services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java
index d071c159d6f5..ae781dcb834a 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java
@@ -60,6 +60,7 @@ import android.os.RemoteException;
import android.os.ServiceSpecificException;
import android.os.UserManager;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
@@ -130,6 +131,7 @@ public class RebootEscrowManagerTests {
private SecretKey mAesKey;
private MockInjector mMockInjector;
private Handler mHandler;
+ private Network mNetwork;
public interface MockableRebootEscrowInjected {
int getBootCount();
@@ -342,6 +344,7 @@ public class RebootEscrowManagerTests {
when(mCallbacks.isUserSecure(NONSECURE_SECONDARY_USER_ID)).thenReturn(false);
when(mCallbacks.isUserSecure(SECURE_SECONDARY_USER_ID)).thenReturn(true);
mInjected = mock(MockableRebootEscrowInjected.class);
+ mNetwork = mock(Network.class);
mMockInjector =
new MockInjector(
mContext,
@@ -351,6 +354,10 @@ public class RebootEscrowManagerTests {
mKeyStoreManager,
mStorage,
mInjected);
+ mMockInjector.mNetworkConsumer =
+ (callback) -> {
+ callback.onAvailable(mNetwork);
+ };
HandlerThread thread = new HandlerThread("RebootEscrowManagerTest");
thread.start();
mHandler = new Handler(thread.getLooper());
@@ -367,6 +374,10 @@ public class RebootEscrowManagerTests {
mKeyStoreManager,
mStorage,
mInjected);
+ mMockInjector.mNetworkConsumer =
+ (callback) -> {
+ callback.onAvailable(mNetwork);
+ };
mService = new RebootEscrowManager(mMockInjector, mCallbacks, mStorage, mHandler);
}
@@ -621,7 +632,7 @@ public class RebootEscrowManagerTests {
// pretend reboot happens here
when(mInjected.getBootCount()).thenReturn(1);
- mService.loadRebootEscrowDataIfAvailable(null);
+ mService.loadRebootEscrowDataIfAvailable(mHandler);
verify(mServiceConnection, never()).unwrap(any(), anyLong());
verify(mCallbacks, never()).onRebootEscrowRestored(anyByte(), any(), anyInt());
}
@@ -678,7 +689,7 @@ public class RebootEscrowManagerTests {
when(mServiceConnection.unwrap(any(), anyLong()))
.thenAnswer(invocation -> invocation.getArgument(0));
- mService.loadRebootEscrowDataIfAvailable(null);
+ mService.loadRebootEscrowDataIfAvailable(mHandler);
verify(mServiceConnection).unwrap(any(), anyLong());
verify(mCallbacks).onRebootEscrowRestored(anyByte(), any(), eq(PRIMARY_USER_ID));
@@ -734,7 +745,7 @@ public class RebootEscrowManagerTests {
when(mServiceConnection.unwrap(any(), anyLong()))
.thenAnswer(invocation -> invocation.getArgument(0));
- mService.loadRebootEscrowDataIfAvailable(null);
+ mService.loadRebootEscrowDataIfAvailable(mHandler);
verify(mServiceConnection).unwrap(any(), anyLong());
verify(mCallbacks).onRebootEscrowRestored(anyByte(), any(), eq(PRIMARY_USER_ID));
@@ -783,7 +794,7 @@ public class RebootEscrowManagerTests {
when(mServiceConnection.unwrap(any(), anyLong()))
.thenAnswer(invocation -> invocation.getArgument(0));
- mService.loadRebootEscrowDataIfAvailable(null);
+ mService.loadRebootEscrowDataIfAvailable(mHandler);
verify(mServiceConnection).unwrap(any(), anyLong());
assertTrue(metricsSuccessCaptor.getValue());
verify(mKeyStoreManager).clearKeyStoreEncryptionKey();
@@ -827,7 +838,7 @@ public class RebootEscrowManagerTests {
anyInt());
when(mServiceConnection.unwrap(any(), anyLong())).thenThrow(RemoteException.class);
- mService.loadRebootEscrowDataIfAvailable(null);
+ mService.loadRebootEscrowDataIfAvailable(mHandler);
verify(mServiceConnection).unwrap(any(), anyLong());
assertFalse(metricsSuccessCaptor.getValue());
assertEquals(
@@ -836,6 +847,7 @@ public class RebootEscrowManagerTests {
}
@Test
+ @RequiresFlagsDisabled(Flags.FLAG_WAIT_FOR_INTERNET_ROR)
public void loadRebootEscrowDataIfAvailable_ServerBasedIoError_RetryFailure() throws Exception {
setServerBasedRebootEscrowProvider();
@@ -930,114 +942,6 @@ public class RebootEscrowManagerTests {
@Test
@RequiresFlagsEnabled(Flags.FLAG_WAIT_FOR_INTERNET_ROR)
- public void loadRebootEscrowDataIfAvailable_serverBasedWaitForInternet_success()
- throws Exception {
- setServerBasedRebootEscrowProvider();
-
- when(mInjected.getBootCount()).thenReturn(0);
- RebootEscrowListener mockListener = mock(RebootEscrowListener.class);
- mService.setRebootEscrowListener(mockListener);
- mService.prepareRebootEscrow();
-
- clearInvocations(mServiceConnection);
- callToRebootEscrowIfNeededAndWait(PRIMARY_USER_ID);
- verify(mockListener).onPreparedForReboot(eq(true));
- verify(mServiceConnection, never()).wrapBlob(any(), anyLong(), anyLong());
-
- // Use x -> x for both wrap & unwrap functions.
- when(mServiceConnection.wrapBlob(any(), anyLong(), anyLong()))
- .thenAnswer(invocation -> invocation.getArgument(0));
- assertEquals(ARM_REBOOT_ERROR_NONE, mService.armRebootEscrowIfNeeded());
- verify(mServiceConnection).wrapBlob(any(), anyLong(), anyLong());
- assertTrue(mStorage.hasRebootEscrowServerBlob());
-
- // pretend reboot happens here
- when(mInjected.getBootCount()).thenReturn(1);
- ArgumentCaptor<Boolean> metricsSuccessCaptor = ArgumentCaptor.forClass(Boolean.class);
- doNothing()
- .when(mInjected)
- .reportMetric(
- metricsSuccessCaptor.capture(),
- eq(0) /* error code */,
- eq(2) /* Server based */,
- eq(1) /* attempt count */,
- anyInt(),
- eq(0) /* vbmeta status */,
- anyInt());
-
- // load escrow data
- when(mServiceConnection.unwrap(any(), anyLong()))
- .thenAnswer(invocation -> invocation.getArgument(0));
- Network mockNetwork = mock(Network.class);
- mMockInjector.mNetworkConsumer =
- (callback) -> {
- callback.onAvailable(mockNetwork);
- };
-
- mService.loadRebootEscrowDataIfAvailable(mHandler);
- verify(mServiceConnection).unwrap(any(), anyLong());
- assertTrue(metricsSuccessCaptor.getValue());
- verify(mKeyStoreManager).clearKeyStoreEncryptionKey();
- assertNull(mMockInjector.mNetworkCallback);
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_WAIT_FOR_INTERNET_ROR)
- public void loadRebootEscrowDataIfAvailable_serverBasedWaitForInternetRemoteException_Failure()
- throws Exception {
- setServerBasedRebootEscrowProvider();
-
- when(mInjected.getBootCount()).thenReturn(0);
- RebootEscrowListener mockListener = mock(RebootEscrowListener.class);
- mService.setRebootEscrowListener(mockListener);
- mService.prepareRebootEscrow();
-
- clearInvocations(mServiceConnection);
- callToRebootEscrowIfNeededAndWait(PRIMARY_USER_ID);
- verify(mockListener).onPreparedForReboot(eq(true));
- verify(mServiceConnection, never()).wrapBlob(any(), anyLong(), anyLong());
-
- // Use x -> x for both wrap & unwrap functions.
- when(mServiceConnection.wrapBlob(any(), anyLong(), anyLong()))
- .thenAnswer(invocation -> invocation.getArgument(0));
- assertEquals(ARM_REBOOT_ERROR_NONE, mService.armRebootEscrowIfNeeded());
- verify(mServiceConnection).wrapBlob(any(), anyLong(), anyLong());
- assertTrue(mStorage.hasRebootEscrowServerBlob());
-
- // pretend reboot happens here
- when(mInjected.getBootCount()).thenReturn(1);
- ArgumentCaptor<Boolean> metricsSuccessCaptor = ArgumentCaptor.forClass(Boolean.class);
- ArgumentCaptor<Integer> metricsErrorCodeCaptor = ArgumentCaptor.forClass(Integer.class);
- doNothing()
- .when(mInjected)
- .reportMetric(
- metricsSuccessCaptor.capture(),
- metricsErrorCodeCaptor.capture(),
- eq(2) /* Server based */,
- eq(1) /* attempt count */,
- anyInt(),
- eq(0) /* vbmeta status */,
- anyInt());
-
- // load escrow data
- when(mServiceConnection.unwrap(any(), anyLong())).thenThrow(RemoteException.class);
- Network mockNetwork = mock(Network.class);
- mMockInjector.mNetworkConsumer =
- (callback) -> {
- callback.onAvailable(mockNetwork);
- };
-
- mService.loadRebootEscrowDataIfAvailable(mHandler);
- verify(mServiceConnection).unwrap(any(), anyLong());
- assertFalse(metricsSuccessCaptor.getValue());
- assertEquals(
- Integer.valueOf(RebootEscrowManager.ERROR_LOAD_ESCROW_KEY),
- metricsErrorCodeCaptor.getValue());
- assertNull(mMockInjector.mNetworkCallback);
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_WAIT_FOR_INTERNET_ROR)
public void loadRebootEscrowDataIfAvailable_waitForInternet_networkUnavailable()
throws Exception {
setServerBasedRebootEscrowProvider();
diff --git a/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java
index abc9ce3fdc36..ee63d5d32ff1 100644
--- a/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java
@@ -38,6 +38,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -91,6 +92,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
@@ -174,8 +176,8 @@ public class MediaProjectionManagerServiceTest {
private PackageManager mPackageManager;
@Mock
private KeyguardManager mKeyguardManager;
- @Mock
- AppOpsManager mAppOpsManager;
+
+ private AppOpsManager mAppOpsManager;
@Mock
private IMediaProjectionWatcherCallback mWatcherCallback;
@Mock
@@ -193,6 +195,7 @@ public class MediaProjectionManagerServiceTest {
LocalServices.removeServiceForTest(WindowManagerInternal.class);
LocalServices.addService(WindowManagerInternal.class, mWindowManagerInternal);
+ mAppOpsManager = mockAppOpsManager();
mContext.addMockSystemService(AppOpsManager.class, mAppOpsManager);
mContext.addMockSystemService(KeyguardManager.class, mKeyguardManager);
mContext.setMockPackageManager(mPackageManager);
@@ -206,6 +209,17 @@ public class MediaProjectionManagerServiceTest {
mService = new MediaProjectionManagerService(mContext);
}
+ private static AppOpsManager mockAppOpsManager() {
+ return mock(AppOpsManager.class, invocationOnMock -> {
+ if (invocationOnMock.getMethod().getName().startsWith("noteOp")) {
+ // Mockito will return 0 for non-stubbed method which corresponds to MODE_ALLOWED
+ // and is not what we want.
+ return AppOpsManager.MODE_IGNORED;
+ }
+ return Answers.RETURNS_DEFAULTS.answer(invocationOnMock);
+ });
+ }
+
@After
public void tearDown() {
LocalServices.removeServiceForTest(ActivityManagerInternal.class);
@@ -305,8 +319,10 @@ public class MediaProjectionManagerServiceTest {
public void testCreateProjection_keyguardLocked_AppOpMediaProjection()
throws NameNotFoundException {
MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions();
- doReturn(true).when(mAppOpsManager).isOperationActive(eq(AppOpsManager.OP_PROJECT_MEDIA),
- eq(projection.uid), eq(projection.packageName));
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOpNoThrow(eq(AppOpsManager.OP_PROJECT_MEDIA),
+ eq(projection.uid), eq(projection.packageName), nullable(String.class),
+ nullable(String.class));
doReturn(true).when(mKeyguardManager).isKeyguardLocked();
doReturn(PackageManager.PERMISSION_DENIED).when(mPackageManager).checkPermission(
@@ -1159,7 +1175,7 @@ public class MediaProjectionManagerServiceTest {
doReturn(mAppInfo).when(mPackageManager).getApplicationInfoAsUser(anyString(),
any(ApplicationInfoFlags.class), any(UserHandle.class));
return service.createProjectionInternal(UID, PACKAGE_NAME,
- TYPE_MIRRORING, /* isPermanentGrant= */ true, UserHandle.CURRENT);
+ TYPE_MIRRORING, /* isPermanentGrant= */ false, UserHandle.CURRENT);
}
// Set up preconditions for starting a projection, with no foreground service requirements.
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 6c9015d72d5a..bbf2cbdbc145 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -193,6 +193,7 @@ import android.app.Notification.MessagingStyle.Message;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
+import android.app.NotificationManager.Policy;
import android.app.PendingIntent;
import android.app.Person;
import android.app.RemoteInput;
@@ -655,7 +656,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAtm.getTaskToShowPermissionDialogOn(anyString(), anyInt()))
.thenReturn(INVALID_TASK_ID);
mContext.addMockSystemService(AppOpsManager.class, mock(AppOpsManager.class));
- when(mUm.getProfileIds(eq(mUserId), eq(false))).thenReturn(new int[] { mUserId });
+ when(mUm.getProfileIds(eq(mUserId), anyBoolean())).thenReturn(new int[]{mUserId});
+ when(mUmInternal.getProfileIds(eq(mUserId), anyBoolean())).thenReturn(new int[]{mUserId});
when(mAmi.getCurrentUserId()).thenReturn(mUserId);
when(mPackageManagerClient.hasSystemFeature(FEATURE_TELECOM)).thenReturn(true);
@@ -4652,7 +4654,42 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
doThrow(new SecurityException("no access")).when(mUgmInternal)
.checkGrantUriPermission(eq(Process.myUid()), any(), eq(soundUri),
- anyInt(), eq(Process.myUserHandle().getIdentifier()));
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
+
+ mBinderService.updateNotificationChannelFromPrivilegedListener(
+ null, mPkg, Process.myUserHandle(), updatedNotificationChannel);
+
+ verify(mPreferencesHelper, times(1)).updateNotificationChannel(
+ anyString(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean());
+
+ verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
+ eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
+ }
+
+ @Test
+ public void
+ testUpdateNotificationChannelFromPrivilegedListener_oldSoundNoUriPerm_newSoundHasUriPerm()
+ throws Exception {
+ mService.setPreferencesHelper(mPreferencesHelper);
+ when(mCompanionMgr.getAssociations(mPkg, mUserId))
+ .thenReturn(singletonList(mock(AssociationInfo.class)));
+ when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(),
+ eq(mTestNotificationChannel.getId()), anyBoolean()))
+ .thenReturn(mTestNotificationChannel);
+
+ // Missing Uri permissions for the old channel sound
+ final Uri oldSoundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
+ doThrow(new SecurityException("no access")).when(mUgmInternal)
+ .checkGrantUriPermission(eq(Process.myUid()), any(), eq(oldSoundUri),
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
+
+ // Has Uri permissions for the old channel sound
+ final Uri newSoundUri = Uri.parse("content://media/test/sound/uri");
+ final NotificationChannel updatedNotificationChannel = new NotificationChannel(
+ TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT);
+ updatedNotificationChannel.setSound(newSoundUri,
+ updatedNotificationChannel.getAudioAttributes());
mBinderService.updateNotificationChannelFromPrivilegedListener(
null, mPkg, Process.myUserHandle(), updatedNotificationChannel);
@@ -15936,6 +15973,57 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertThat(updatedRule.getValue().isEnabled()).isFalse();
}
+ @Test
+ @EnableFlags({android.app.Flags.FLAG_MODES_API, android.app.Flags.FLAG_MODES_UI})
+ public void setNotificationPolicy_fromSystemApp_appliesPriorityChannelsAllowed()
+ throws Exception {
+ setUpRealZenTest();
+ // Start with hasPriorityChannels=true, allowPriorityChannels=true ("default").
+ mService.mZenModeHelper.setNotificationPolicy(new Policy(0, 0, 0, 0,
+ Policy.policyState(true, true), 0),
+ ZenModeConfig.ORIGIN_SYSTEM, Process.SYSTEM_UID);
+
+ // The caller will supply states with "wrong" hasPriorityChannels.
+ int stateBlockingPriorityChannels = Policy.policyState(false, false);
+ mBinderService.setNotificationPolicy(mPkg,
+ new Policy(1, 0, 0, 0, stateBlockingPriorityChannels, 0), false);
+
+ // hasPriorityChannels is untouched and allowPriorityChannels was updated.
+ assertThat(mBinderService.getNotificationPolicy(mPkg).priorityCategories).isEqualTo(1);
+ assertThat(mBinderService.getNotificationPolicy(mPkg).state).isEqualTo(
+ Policy.policyState(true, false));
+
+ // Same but setting allowPriorityChannels to true.
+ int stateAllowingPriorityChannels = Policy.policyState(false, true);
+ mBinderService.setNotificationPolicy(mPkg,
+ new Policy(2, 0, 0, 0, stateAllowingPriorityChannels, 0), false);
+
+ assertThat(mBinderService.getNotificationPolicy(mPkg).priorityCategories).isEqualTo(2);
+ assertThat(mBinderService.getNotificationPolicy(mPkg).state).isEqualTo(
+ Policy.policyState(true, true));
+ }
+
+ @Test
+ @EnableFlags({android.app.Flags.FLAG_MODES_API, android.app.Flags.FLAG_MODES_UI})
+ @DisableCompatChanges(NotificationManagerService.MANAGE_GLOBAL_ZEN_VIA_IMPLICIT_RULES)
+ public void setNotificationPolicy_fromRegularAppThatCanModifyPolicy_ignoresState()
+ throws Exception {
+ setUpRealZenTest();
+ // Start with hasPriorityChannels=true, allowPriorityChannels=true ("default").
+ mService.mZenModeHelper.setNotificationPolicy(new Policy(0, 0, 0, 0,
+ Policy.policyState(true, true), 0),
+ ZenModeConfig.ORIGIN_SYSTEM, Process.SYSTEM_UID);
+ mService.setCallerIsNormalPackage();
+
+ mBinderService.setNotificationPolicy(mPkg,
+ new Policy(1, 0, 0, 0, Policy.policyState(false, false), 0), false);
+
+ // Policy was updated but the attempt to change state was ignored (it's a @hide API).
+ assertThat(mBinderService.getNotificationPolicy(mPkg).priorityCategories).isEqualTo(1);
+ assertThat(mBinderService.getNotificationPolicy(mPkg).state).isEqualTo(
+ Policy.policyState(true, true));
+ }
+
/** Prepares for a zen-related test that uses the real {@link ZenModeHelper}. */
private void setUpRealZenTest() throws Exception {
when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
index a0c0df8853f9..d64b9e858c64 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
@@ -45,11 +45,13 @@ import static android.app.NotificationManager.IMPORTANCE_MAX;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static android.app.NotificationManager.VISIBILITY_NO_OVERRIDE;
+import static android.content.ContentResolver.SCHEME_ANDROID_RESOURCE;
+import static android.content.ContentResolver.SCHEME_CONTENT;
+import static android.content.ContentResolver.SCHEME_FILE;
import static android.media.AudioAttributes.CONTENT_TYPE_SONIFICATION;
import static android.media.AudioAttributes.USAGE_NOTIFICATION;
import static android.os.UserHandle.USER_ALL;
import static android.os.UserHandle.USER_SYSTEM;
-
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
import static android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION;
import static android.service.notification.Flags.notificationClassification;
@@ -59,6 +61,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_P
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__GRANTED;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED;
import static com.android.server.notification.Flags.FLAG_ALL_NOTIFS_NEED_TTL;
+import static com.android.server.notification.Flags.FLAG_NOTIFICATION_VERIFY_CHANNEL_SOUND_URI;
import static com.android.server.notification.Flags.FLAG_PERSIST_INCOMPLETE_RESTORE_DATA;
import static com.android.server.notification.NotificationChannelLogger.NotificationChannelEvent.NOTIFICATION_CHANNEL_UPDATED_BY_USER;
import static com.android.server.notification.PreferencesHelper.DEFAULT_BUBBLE_PREFERENCE;
@@ -84,6 +87,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
@@ -369,10 +373,10 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- false, mClock);
+ mUgmInternal, false, mClock);
mXmlHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- false, mClock);
+ mUgmInternal, false, mClock);
resetZenModeHelper();
mAudioAttributes = new AudioAttributes.Builder()
@@ -783,7 +787,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testReadXml_oldXml_migrates() throws Exception {
mXmlHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- /* showReviewPermissionsNotification= */ true, mClock);
+ mUgmInternal, /* showReviewPermissionsNotification= */ true, mClock);
String xml = "<ranking version=\"2\">\n"
+ "<package name=\"" + PKG_N_MR1 + "\" uid=\"" + UID_N_MR1
@@ -919,7 +923,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testReadXml_newXml_noMigration_showPermissionNotification() throws Exception {
mXmlHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- /* showReviewPermissionsNotification= */ true, mClock);
+ mUgmInternal, /* showReviewPermissionsNotification= */ true, mClock);
String xml = "<ranking version=\"3\">\n"
+ "<package name=\"" + PKG_N_MR1 + "\" show_badge=\"true\">\n"
@@ -978,7 +982,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testReadXml_newXml_permissionNotificationOff() throws Exception {
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- /* showReviewPermissionsNotification= */ false, mClock);
+ mUgmInternal, /* showReviewPermissionsNotification= */ false, mClock);
String xml = "<ranking version=\"3\">\n"
+ "<package name=\"" + PKG_N_MR1 + "\" show_badge=\"true\">\n"
@@ -1037,7 +1041,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testReadXml_newXml_noMigration_noPermissionNotification() throws Exception {
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- /* showReviewPermissionsNotification= */ true, mClock);
+ mUgmInternal, /* showReviewPermissionsNotification= */ true, mClock);
String xml = "<ranking version=\"4\">\n"
+ "<package name=\"" + PKG_N_MR1 + "\" show_badge=\"true\">\n"
@@ -1709,7 +1713,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
// simulate load after reboot
mXmlHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- false, mClock);
+ mUgmInternal, false, mClock);
loadByteArrayXml(baos.toByteArray(), false, USER_ALL);
// Trigger 2nd restore pass
@@ -1764,7 +1768,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
// simulate load after reboot
mXmlHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- false, mClock);
+ mUgmInternal, false, mClock);
loadByteArrayXml(xml.getBytes(), false, USER_ALL);
// Trigger 2nd restore pass
@@ -1842,10 +1846,10 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper = new PreferencesHelper(mContext, mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- false, mClock);
+ mUgmInternal, false, mClock);
mXmlHelper = new PreferencesHelper(mContext, mPm, mHandler, mMockZenModeHelper,
mPermissionHelper, mPermissionManager, mLogger, mAppOpsManager, mUserProfiles,
- false, mClock);
+ mUgmInternal, false, mClock);
NotificationChannel channel =
new NotificationChannel("id", "name", IMPORTANCE_LOW);
@@ -3049,6 +3053,64 @@ public class PreferencesHelperTest extends UiServiceTestCase {
}
@Test
+ @EnableFlags(FLAG_NOTIFICATION_VERIFY_CHANNEL_SOUND_URI)
+ public void testCreateChannel_noSoundUriPermission_contentSchemeVerified() {
+ final Uri sound = Uri.parse(SCHEME_CONTENT + "://media/test/sound/uri");
+
+ doThrow(new SecurityException("no access")).when(mUgmInternal)
+ .checkGrantUriPermission(eq(UID_N_MR1), any(), eq(sound),
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
+
+ final NotificationChannel channel = new NotificationChannel("id2", "name2",
+ NotificationManager.IMPORTANCE_DEFAULT);
+ channel.setSound(sound, mAudioAttributes);
+
+ assertThrows(SecurityException.class,
+ () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel,
+ true, false, UID_N_MR1, false));
+ assertThat(mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel.getId(), true))
+ .isNull();
+ }
+
+ @Test
+ @EnableFlags(FLAG_NOTIFICATION_VERIFY_CHANNEL_SOUND_URI)
+ public void testCreateChannel_noSoundUriPermission_fileSchemaIgnored() {
+ final Uri sound = Uri.parse(SCHEME_FILE + "://path/sound");
+
+ doThrow(new SecurityException("no access")).when(mUgmInternal)
+ .checkGrantUriPermission(eq(UID_N_MR1), any(), any(),
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
+
+ final NotificationChannel channel = new NotificationChannel("id2", "name2",
+ NotificationManager.IMPORTANCE_DEFAULT);
+ channel.setSound(sound, mAudioAttributes);
+
+ mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true, false, UID_N_MR1,
+ false);
+ assertThat(mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel.getId(), true)
+ .getSound()).isEqualTo(sound);
+ }
+
+ @Test
+ @EnableFlags(FLAG_NOTIFICATION_VERIFY_CHANNEL_SOUND_URI)
+ public void testCreateChannel_noSoundUriPermission_resourceSchemaIgnored() {
+ final Uri sound = Uri.parse(SCHEME_ANDROID_RESOURCE + "://resId/sound");
+
+ doThrow(new SecurityException("no access")).when(mUgmInternal)
+ .checkGrantUriPermission(eq(UID_N_MR1), any(), any(),
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
+
+ final NotificationChannel channel = new NotificationChannel("id2", "name2",
+ NotificationManager.IMPORTANCE_DEFAULT);
+ channel.setSound(sound, mAudioAttributes);
+
+ mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true, false, UID_N_MR1,
+ false);
+ assertThat(mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel.getId(), true)
+ .getSound()).isEqualTo(sound);
+ }
+
+ @Test
public void testPermanentlyDeleteChannels() throws Exception {
NotificationChannel channel1 =
new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH);
diff --git a/services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerTest.java b/services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerTest.java
index 0d13be6d5ab2..e8ca8bf8ec63 100644
--- a/services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerTest.java
+++ b/services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerTest.java
@@ -127,13 +127,13 @@ public class VibratorControllerTest {
public void setExternalControl_withCapability_enablesExternalControl() {
mockVibratorCapabilities(IVibrator.CAP_EXTERNAL_CONTROL);
VibratorController controller = createController();
- assertFalse(controller.isUnderExternalControl());
+ assertFalse(controller.isVibrating());
controller.setExternalControl(true);
- assertTrue(controller.isUnderExternalControl());
+ assertTrue(controller.isVibrating());
controller.setExternalControl(false);
- assertFalse(controller.isUnderExternalControl());
+ assertFalse(controller.isVibrating());
InOrder inOrderVerifier = inOrder(mNativeWrapperMock);
inOrderVerifier.verify(mNativeWrapperMock).setExternalControl(eq(true));
@@ -143,10 +143,10 @@ public class VibratorControllerTest {
@Test
public void setExternalControl_withNoCapability_ignoresExternalControl() {
VibratorController controller = createController();
- assertFalse(controller.isUnderExternalControl());
+ assertFalse(controller.isVibrating());
controller.setExternalControl(true);
- assertFalse(controller.isUnderExternalControl());
+ assertFalse(controller.isVibrating());
verify(mNativeWrapperMock, never()).setExternalControl(anyBoolean());
}
@@ -181,6 +181,38 @@ public class VibratorControllerTest {
}
@Test
+ public void setAmplitude_vibratorIdle_ignoresAmplitude() {
+ VibratorController controller = createController();
+ assertFalse(controller.isVibrating());
+
+ controller.setAmplitude(1);
+ assertEquals(0, controller.getCurrentAmplitude(), /* delta= */ 0);
+ }
+
+ @Test
+ public void setAmplitude_vibratorUnderExternalControl_ignoresAmplitude() {
+ mockVibratorCapabilities(IVibrator.CAP_EXTERNAL_CONTROL);
+ VibratorController controller = createController();
+ controller.setExternalControl(true);
+ assertTrue(controller.isVibrating());
+
+ controller.setAmplitude(1);
+ assertEquals(0, controller.getCurrentAmplitude(), /* delta= */ 0);
+ }
+
+ @Test
+ public void setAmplitude_vibratorVibrating_setsAmplitude() {
+ when(mNativeWrapperMock.on(anyLong(), anyLong())).thenAnswer(args -> args.getArgument(0));
+ VibratorController controller = createController();
+ controller.on(100, /* vibrationId= */ 1);
+ assertTrue(controller.isVibrating());
+ assertEquals(-1, controller.getCurrentAmplitude(), /* delta= */ 0);
+
+ controller.setAmplitude(1);
+ assertEquals(1, controller.getCurrentAmplitude(), /* delta= */ 0);
+ }
+
+ @Test
public void on_withDuration_turnsVibratorOn() {
when(mNativeWrapperMock.on(anyLong(), anyLong())).thenAnswer(args -> args.getArgument(0));
VibratorController controller = createController();
diff --git a/services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java b/services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java
index d99b20c689dd..538c3fc2ddae 100644
--- a/services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java
+++ b/services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java
@@ -266,12 +266,13 @@ public class VibratorManagerServiceTest {
@After
public void tearDown() throws Exception {
if (mService != null) {
- if (!mPendingVibrations.stream().allMatch(HalVibration::hasEnded)) {
- // Cancel any pending vibration from tests.
- cancelVibrate(mService);
- for (HalVibration vibration : mPendingVibrations) {
- vibration.waitForEnd();
- }
+ // Make sure we have permission to cancel test vibrations, even if the test denied them.
+ grantPermission(android.Manifest.permission.VIBRATE);
+ // Cancel any pending vibration from tests, including external vibrations.
+ cancelVibrate(mService);
+ // Wait until pending vibrations end asynchronously.
+ for (HalVibration vibration : mPendingVibrations) {
+ vibration.waitForEnd();
}
// Wait until all vibrators have stopped vibrating, waiting for ramp-down.
// Note: if a test is flaky here something is wrong with the vibration finalization.
@@ -2242,7 +2243,7 @@ public class VibratorManagerServiceTest {
VibratorManagerService service = createSystemReadyService();
VibrationEffect effect = VibrationEffect.createOneShot(10 * TEST_TIMEOUT_MILLIS, 100);
- vibrate(service, effect, HAPTIC_FEEDBACK_ATTRS);
+ HalVibration vibration = vibrate(service, effect, HAPTIC_FEEDBACK_ATTRS);
// VibrationThread will start this vibration async, so wait until vibration is triggered.
assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
@@ -2255,7 +2256,8 @@ public class VibratorManagerServiceTest {
assertNotEquals(ExternalVibrationScale.ScaleLevel.SCALE_MUTE, scale.scaleLevel);
// Vibration is cancelled.
- assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
+ vibration.waitForEnd();
+ assertThat(vibration.getStatus()).isEqualTo(Status.CANCELLED_SUPERSEDED);
assertEquals(Arrays.asList(false, true),
mVibratorProviders.get(1).getExternalControlStates());
}
@@ -2296,7 +2298,7 @@ public class VibratorManagerServiceTest {
VibrationEffect repeatingEffect = VibrationEffect.createWaveform(
new long[]{100, 200, 300}, new int[]{128, 255, 255}, 1);
- vibrate(service, repeatingEffect, ALARM_ATTRS);
+ HalVibration repeatingVibration = vibrate(service, repeatingEffect, ALARM_ATTRS);
// VibrationThread will start this vibration async, so wait until vibration is triggered.
assertTrue(waitUntil(s -> s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
@@ -2308,7 +2310,8 @@ public class VibratorManagerServiceTest {
assertNotEquals(ExternalVibrationScale.ScaleLevel.SCALE_MUTE, scale.scaleLevel);
// Vibration is cancelled.
- assertTrue(waitUntil(s -> !s.isVibrating(1), service, TEST_TIMEOUT_MILLIS));
+ repeatingVibration.waitForEnd();
+ assertThat(repeatingVibration.getStatus()).isEqualTo(Status.CANCELLED_SUPERSEDED);
assertEquals(Arrays.asList(false, true),
mVibratorProviders.get(1).getExternalControlStates());
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
index 639834374c1f..92205f391f32 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
@@ -230,7 +230,7 @@ class AppCompatActivityRobot {
mDisplayContent.setIgnoreOrientationRequest(enabled);
}
- void setTopOrganizedTaskAsTopTask() {
+ void setTopActivityOrganizedTask() {
doReturn(mTaskStack.top()).when(mActivityStack.top()).getOrganizedTask();
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java
index d66c21a77fcd..b91a5b7afe26 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java
@@ -28,7 +28,7 @@ import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_V
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
-import static com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM;
+import static com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING;
import android.compat.testing.PlatformCompatChangeRule;
import android.platform.test.annotations.DisableFlags;
@@ -218,7 +218,7 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase {
}
@Test
- @DisableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testShouldApplyCameraCompatFreeformTreatment_flagIsDisabled_returnsFalse() {
runTestScenario((robot) -> {
robot.activity().createActivityWithComponentInNewTask();
@@ -229,7 +229,7 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase {
@Test
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT})
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testShouldApplyCameraCompatFreeformTreatment_overrideEnabled_returnsFalse() {
runTestScenario((robot) -> {
robot.activity().createActivityWithComponentInNewTask();
@@ -240,7 +240,7 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase {
@Test
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT})
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testShouldApplyCameraCompatFreeformTreatment_disabledByOverride_returnsFalse() {
runTestScenario((robot) -> {
robot.activity().createActivityWithComponentInNewTask();
@@ -250,7 +250,7 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testShouldApplyCameraCompatFreeformTreatment_notDisabledByOverride_returnsTrue() {
runTestScenario((robot) -> {
robot.activity().createActivityWithComponentInNewTask();
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraPolicyTest.java
index d91b38efd40b..41102d6922da 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraPolicyTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraPolicyTest.java
@@ -20,7 +20,7 @@ import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
-import static com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM;
+import static com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -85,7 +85,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraCompatFreeformPolicy_presentWhenEnabledAndDW() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(/* isAllowed= */ true);
@@ -95,7 +95,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraCompatFreeformPolicy_notPresentWhenNoDW() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(/* isAllowed= */ false);
@@ -105,7 +105,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @DisableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraCompatFreeformPolicy_notPresentWhenNoFlag() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(/* isAllowed= */ true);
@@ -115,7 +115,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraCompatFreeformPolicy_notPresentWhenNoFlagAndNoDW() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(/* isAllowed= */ false);
@@ -125,7 +125,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraCompatFreeformPolicy_startedWhenEnabledAndDW() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(/* isAllowed= */ true);
@@ -136,7 +136,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraStateManager_existsWhenCameraCompatFreeformExists() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(true);
@@ -147,7 +147,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraStateManager_startedWhenCameraCompatFreeformExists() {
runTestScenario((robot) -> {
robot.allowEnterDesktopMode(true);
@@ -180,7 +180,7 @@ public class AppCompatCameraPolicyTest extends WindowTestsBase {
}
@Test
- @DisableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testCameraStateManager_doesNotExistWhenNoPolicyExists() {
runTestScenario((robot) -> {
robot.conf().enableCameraCompatTreatmentAtBuildTime(/* enabled= */ false);
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatUtilsTest.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatUtilsTest.java
index 3f34b81487ed..d8373c5dc3d6 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatUtilsTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatUtilsTest.java
@@ -150,7 +150,7 @@ public class AppCompatUtilsTest extends WindowTestsBase {
robot.applyOnActivity((a) -> {
a.createActivityWithComponentInNewTask();
a.setIgnoreOrientationRequest(true);
- a.setTopOrganizedTaskAsTopTask();
+ a.setTopActivityOrganizedTask();
a.setTopActivityInSizeCompatMode(true);
a.setTopActivityVisible(true);
});
diff --git a/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java
index a48813d775d1..dbcef10a6be2 100644
--- a/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java
@@ -35,7 +35,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
-import static com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM;
+import static com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -60,6 +60,7 @@ import android.content.res.Configuration.Orientation;
import android.graphics.Rect;
import android.hardware.camera2.CameraManager;
import android.os.Handler;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.view.DisplayInfo;
import android.view.Surface;
@@ -135,7 +136,6 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
});
mActivityRefresher = new ActivityRefresher(mDisplayContent.mWmService, mMockHandler);
- mSetFlagsRule.enableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM);
CameraStateMonitor cameraStateMonitor =
new CameraStateMonitor(mDisplayContent, mMockHandler);
mCameraCompatFreeformPolicy =
@@ -147,6 +147,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
cameraStateMonitor.startListeningToCameraState();
}
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void testFullscreen_doesNotActivateCameraCompatMode() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT, WINDOWING_MODE_FULLSCREEN);
@@ -157,6 +158,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
assertNotInCameraCompatMode();
}
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void testOrientationUnspecified_doesNotActivateCameraCompatMode() {
configureActivity(SCREEN_ORIENTATION_UNSPECIFIED);
@@ -164,12 +166,14 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
assertNotInCameraCompatMode();
}
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void testNoCameraConnection_doesNotActivateCameraCompatMode() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
assertNotInCameraCompatMode();
}
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void testCameraConnected_deviceInPortrait_portraitCameraCompatMode() throws Exception {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
@@ -210,6 +214,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
assertActivityRefreshRequested(/* refreshRequested */ false);
}
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void testCameraReconnected_cameraCompatModeAndRefresh() throws Exception {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
@@ -235,6 +240,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
}
@Test
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT})
public void testShouldApplyCameraCompatFreeformTreatment_overrideEnabled_returnsFalse() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
@@ -246,6 +252,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
}
@Test
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testShouldApplyCameraCompatFreeformTreatment_notDisabledByOverride_returnsTrue() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
@@ -254,6 +261,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
}
@Test
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testOnActivityConfigurationChanging_refreshDisabledViaFlag_noRefresh()
throws Exception {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
@@ -268,6 +276,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
}
@Test
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testOnActivityConfigurationChanging_cycleThroughStopDisabled() throws Exception {
when(mAppCompatConfiguration.isCameraCompatRefreshCycleThroughStopEnabled())
.thenReturn(false);
@@ -281,6 +290,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
}
@Test
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
public void testOnActivityConfigurationChanging_cycleThroughStopDisabledForApp()
throws Exception {
configureActivity(SCREEN_ORIENTATION_PORTRAIT);
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 85cb1bcc01fb..5c0d424f4f42 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -83,7 +83,7 @@ import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_TOKEN_TRANSFO
import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
-import static com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM;
+import static com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING;
import static com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE;
import static com.google.common.truth.Truth.assertThat;
@@ -2820,7 +2820,7 @@ public class DisplayContentTests extends WindowTestsBase {
verify(mWm.mUmInternal, never()).isUserVisible(userId2, displayId);
}
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void cameraCompatFreeformFlagEnabled_cameraCompatFreeformPolicyNotNull() {
doReturn(true).when(() ->
@@ -2829,7 +2829,7 @@ public class DisplayContentTests extends WindowTestsBase {
assertTrue(createNewDisplay().mAppCompatCameraPolicy.hasCameraCompatFreeformPolicy());
}
- @DisableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@Test
public void cameraCompatFreeformFlagNotEnabled_cameraCompatFreeformPolicyIsNull() {
doReturn(true).when(() ->
@@ -2838,7 +2838,7 @@ public class DisplayContentTests extends WindowTestsBase {
assertFalse(createNewDisplay().mAppCompatCameraPolicy.hasCameraCompatFreeformPolicy());
}
- @EnableFlags(FLAG_CAMERA_COMPAT_FOR_FREEFORM)
+ @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
@DisableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
@Test
public void desktopWindowingFlagNotEnabled_cameraCompatFreeformPolicyIsNull() {
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 6c1e1a428fb8..129494517cd6 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -1027,28 +1027,36 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
boolean enabled = (mCurrentFunctions & UsbManager.FUNCTION_MIDI) != 0;
if (enabled != mMidiEnabled) {
if (enabled) {
+ boolean midiDeviceFound = false;
if (android.hardware.usb.flags.Flags.enableUsbSysfsMidiIdentification()) {
try {
getMidiCardDevice();
+ midiDeviceFound = true;
} catch (FileNotFoundException e) {
- Slog.e(TAG, "could not identify MIDI device", e);
- enabled = false;
+ Slog.w(TAG, "could not identify MIDI device", e);
}
- } else {
+ }
+ // For backward compatibility with older kernels without
+ // https://lore.kernel.org/r/20240307030922.3573161-1-royluo@google.com
+ if (!midiDeviceFound) {
Scanner scanner = null;
try {
scanner = new Scanner(new File(MIDI_ALSA_PATH));
mMidiCard = scanner.nextInt();
mMidiDevice = scanner.nextInt();
+ midiDeviceFound = true;
} catch (FileNotFoundException e) {
Slog.e(TAG, "could not open MIDI file", e);
- enabled = false;
} finally {
if (scanner != null) {
scanner.close();
}
}
}
+ if (!midiDeviceFound) {
+ Slog.e(TAG, "Failed to enable MIDI function");
+ enabled = false;
+ }
}
mMidiEnabled = enabled;
}
diff --git a/telephony/java/android/telephony/data/ApnSetting.java b/telephony/java/android/telephony/data/ApnSetting.java
index 44d3fca6aec6..567314beadd3 100644
--- a/telephony/java/android/telephony/data/ApnSetting.java
+++ b/telephony/java/android/telephony/data/ApnSetting.java
@@ -128,6 +128,12 @@ public class ApnSetting implements Parcelable {
/** APN type for RCS (Rich Communication Services). */
@FlaggedApi(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public static final int TYPE_RCS = ApnTypes.RCS;
+ /** APN type for OEM_PAID networks (Automotive PANS) */
+ @FlaggedApi(Flags.FLAG_OEM_PAID_PRIVATE)
+ public static final int TYPE_OEM_PAID = 1 << 16; // TODO(b/366194627): ApnTypes.OEM_PAID;
+ /** APN type for OEM_PRIVATE networks (Automotive PANS) */
+ @FlaggedApi(Flags.FLAG_OEM_PAID_PRIVATE)
+ public static final int TYPE_OEM_PRIVATE = 1 << 17; // TODO(b/366194627): ApnTypes.OEM_PRIVATE;
/** @hide */
@IntDef(flag = true, prefix = {"TYPE_"}, value = {
@@ -146,7 +152,9 @@ public class ApnSetting implements Parcelable {
TYPE_BIP,
TYPE_VSIM,
TYPE_ENTERPRISE,
- TYPE_RCS
+ TYPE_RCS,
+ TYPE_OEM_PAID,
+ TYPE_OEM_PRIVATE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ApnType {
@@ -375,6 +383,27 @@ public class ApnSetting implements Parcelable {
@SystemApi
public static final String TYPE_RCS_STRING = "rcs";
+ /**
+ * APN type for OEM_PAID networks (Automotive PANS)
+ *
+ * Note: String representations of APN types are intended for system apps to communicate with
+ * modem components or carriers. Non-system apps should use the integer variants instead.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_OEM_PAID_PRIVATE)
+ @SystemApi
+ public static final String TYPE_OEM_PAID_STRING = "oem_paid";
+
+ /**
+ * APN type for OEM_PRIVATE networks (Automotive PANS)
+ *
+ * Note: String representations of APN types are intended for system apps to communicate with
+ * modem components or carriers. Non-system apps should use the integer variants instead.
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_OEM_PAID_PRIVATE)
+ @SystemApi
+ public static final String TYPE_OEM_PRIVATE_STRING = "oem_private";
/** @hide */
@IntDef(prefix = { "AUTH_TYPE_" }, value = {
@@ -489,6 +518,8 @@ public class ApnSetting implements Parcelable {
APN_TYPE_STRING_MAP.put(TYPE_VSIM_STRING, TYPE_VSIM);
APN_TYPE_STRING_MAP.put(TYPE_BIP_STRING, TYPE_BIP);
APN_TYPE_STRING_MAP.put(TYPE_RCS_STRING, TYPE_RCS);
+ APN_TYPE_STRING_MAP.put(TYPE_OEM_PAID_STRING, TYPE_OEM_PAID);
+ APN_TYPE_STRING_MAP.put(TYPE_OEM_PRIVATE_STRING, TYPE_OEM_PRIVATE);
APN_TYPE_INT_MAP = new ArrayMap<>();
APN_TYPE_INT_MAP.put(TYPE_DEFAULT, TYPE_DEFAULT_STRING);
@@ -507,6 +538,8 @@ public class ApnSetting implements Parcelable {
APN_TYPE_INT_MAP.put(TYPE_VSIM, TYPE_VSIM_STRING);
APN_TYPE_INT_MAP.put(TYPE_BIP, TYPE_BIP_STRING);
APN_TYPE_INT_MAP.put(TYPE_RCS, TYPE_RCS_STRING);
+ APN_TYPE_INT_MAP.put(TYPE_OEM_PAID, TYPE_OEM_PAID_STRING);
+ APN_TYPE_INT_MAP.put(TYPE_OEM_PRIVATE, TYPE_OEM_PRIVATE_STRING);
PROTOCOL_STRING_MAP = new ArrayMap<>();
PROTOCOL_STRING_MAP.put("IP", PROTOCOL_IP);
@@ -2383,7 +2416,8 @@ public class ApnSetting implements Parcelable {
public ApnSetting build() {
if ((mApnTypeBitmask & (TYPE_DEFAULT | TYPE_MMS | TYPE_SUPL | TYPE_DUN | TYPE_HIPRI
| TYPE_FOTA | TYPE_IMS | TYPE_CBS | TYPE_IA | TYPE_EMERGENCY | TYPE_MCX
- | TYPE_XCAP | TYPE_VSIM | TYPE_BIP | TYPE_ENTERPRISE | TYPE_RCS)) == 0
+ | TYPE_XCAP | TYPE_VSIM | TYPE_BIP | TYPE_ENTERPRISE | TYPE_RCS | TYPE_OEM_PAID
+ | TYPE_OEM_PRIVATE)) == 0
|| TextUtils.isEmpty(mApnName) || TextUtils.isEmpty(mEntryName)) {
return null;
}
diff --git a/telephony/java/android/telephony/satellite/SatelliteManager.java b/telephony/java/android/telephony/satellite/SatelliteManager.java
index 4eefaaca71f4..bd5c7597ba14 100644
--- a/telephony/java/android/telephony/satellite/SatelliteManager.java
+++ b/telephony/java/android/telephony/satellite/SatelliteManager.java
@@ -1113,6 +1113,12 @@ public final class SatelliteManager {
* @hide
*/
public static final int DATAGRAM_TYPE_SMS = 6;
+ /**
+ * Datagram type indicating that the message to be sent is an SMS checking
+ * for pending incoming SMS.
+ * @hide
+ */
+ public static final int DATAGRAM_TYPE_CHECK_PENDING_INCOMING_SMS = 7;
/** @hide */
@IntDef(prefix = "DATAGRAM_TYPE_", value = {
@@ -1122,7 +1128,8 @@ public final class SatelliteManager {
DATAGRAM_TYPE_KEEP_ALIVE,
DATAGRAM_TYPE_LAST_SOS_MESSAGE_STILL_NEED_HELP,
DATAGRAM_TYPE_LAST_SOS_MESSAGE_NO_HELP_NEEDED,
- DATAGRAM_TYPE_SMS
+ DATAGRAM_TYPE_SMS,
+ DATAGRAM_TYPE_CHECK_PENDING_INCOMING_SMS
})
@Retention(RetentionPolicy.SOURCE)
public @interface DatagramType {}
diff --git a/tests/testables/Android.bp b/tests/testables/Android.bp
index 7596ee722d01..f2111856c666 100644
--- a/tests/testables/Android.bp
+++ b/tests/testables/Android.bp
@@ -25,7 +25,10 @@ package {
java_library {
name: "testables",
- srcs: ["src/**/*.java"],
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
libs: [
"android.test.runner.stubs.system",
"android.test.mock.stubs.system",
diff --git a/tests/testables/src/android/testing/TestWithLooperRule.java b/tests/testables/src/android/testing/TestWithLooperRule.java
index 37b39c314e53..10df17f991d3 100644
--- a/tests/testables/src/android/testing/TestWithLooperRule.java
+++ b/tests/testables/src/android/testing/TestWithLooperRule.java
@@ -34,13 +34,13 @@ import java.util.List;
* Looper for the Statement.
*/
public class TestWithLooperRule implements MethodRule {
-
/*
* This rule requires to be the inner most Rule, so the next statement is RunAfters
* instead of another rule. You can set it by '@Rule(order = Integer.MAX_VALUE)'
*/
@Override
public Statement apply(Statement base, FrameworkMethod method, Object target) {
+
// getting testRunner check, if AndroidTestingRunning then we skip this rule
RunWith runWithAnnotation = target.getClass().getAnnotation(RunWith.class);
if (runWithAnnotation != null) {
@@ -97,6 +97,9 @@ public class TestWithLooperRule implements MethodRule {
case "InvokeParameterizedMethod":
this.wrapFieldMethodFor(next, "frameworkMethod", method, target);
return;
+ case "ExpectException":
+ next = this.getNextStatement(next, "next");
+ break;
default:
throw new Exception(
String.format("Unexpected Statement received: [%s]",
diff --git a/tests/testables/tests/Android.bp b/tests/testables/tests/Android.bp
index 1eb36fa5f908..c23f41a6c3d4 100644
--- a/tests/testables/tests/Android.bp
+++ b/tests/testables/tests/Android.bp
@@ -34,6 +34,7 @@ android_test {
"androidx.core_core-animation",
"androidx.core_core-ktx",
"androidx.test.rules",
+ "androidx.test.ext.junit",
"hamcrest-library",
"mockito-target-inline-minus-junit4",
"testables",
diff --git a/tests/testables/tests/src/android/testing/TestableLooperJUnit4Test.java b/tests/testables/tests/src/android/testing/TestableLooperJUnit4Test.java
new file mode 100644
index 000000000000..b7d5e0e12942
--- /dev/null
+++ b/tests/testables/tests/src/android/testing/TestableLooperJUnit4Test.java
@@ -0,0 +1,42 @@
+/*
+ * 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 android.testing;
+
+import android.testing.TestableLooper.RunWithLooper;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test that TestableLooper now handles expected exceptions in tests
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+@RunWithLooper
+public class TestableLooperJUnit4Test {
+ @Rule
+ public final TestWithLooperRule mTestWithLooperRule = new TestWithLooperRule();
+
+ @Test(expected = Exception.class)
+ public void testException() throws Exception {
+ throw new Exception("this exception is expected");
+ }
+}
+
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp
index df1d51e37660..064b4617b0a2 100644
--- a/tools/aapt2/Debug.cpp
+++ b/tools/aapt2/Debug.cpp
@@ -346,6 +346,21 @@ void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions&
value->value->Accept(&body_printer);
printer->Undent();
}
+ printer->Println("Flag disabled values:");
+ for (const auto& value : entry.flag_disabled_values) {
+ printer->Print("(");
+ printer->Print(value->config.to_string());
+ printer->Print(") ");
+ value->value->Accept(&headline_printer);
+ if (options.show_sources && !value->value->GetSource().path.empty()) {
+ printer->Print(" src=");
+ printer->Print(value->value->GetSource().to_string());
+ }
+ printer->Println();
+ printer->Indent();
+ value->value->Accept(&body_printer);
+ printer->Undent();
+ }
printer->Undent();
}
}
diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h
index a274f047586c..0d261abd728d 100644
--- a/tools/aapt2/Resource.h
+++ b/tools/aapt2/Resource.h
@@ -71,6 +71,17 @@ enum class ResourceType {
enum class FlagStatus { NoFlag = 0, Disabled = 1, Enabled = 2 };
+struct FeatureFlagAttribute {
+ std::string name;
+ bool negated = false;
+
+ std::string ToString() {
+ return (negated ? "!" : "") + name;
+ }
+
+ bool operator==(const FeatureFlagAttribute& o) const = default;
+};
+
android::StringPiece to_string(ResourceType type);
/**
@@ -232,6 +243,12 @@ struct ResourceFile {
// Exported symbols
std::vector<SourcedResourceName> exported_symbols;
+
+ // Flag status
+ FlagStatus flag_status = FlagStatus::NoFlag;
+
+ // Flag
+ std::optional<FeatureFlagAttribute> flag;
};
/**
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index a5aecc855707..fce6aa7c80d9 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -107,9 +107,10 @@ struct ParsedResource {
Visibility::Level visibility_level = Visibility::Level::kUndefined;
bool staged_api = false;
bool allow_new = false;
- FlagStatus flag_status = FlagStatus::NoFlag;
std::optional<OverlayableItem> overlayable_item;
std::optional<StagedId> staged_alias;
+ std::optional<FeatureFlagAttribute> flag;
+ FlagStatus flag_status;
std::string comment;
std::unique_ptr<Value> value;
@@ -151,6 +152,7 @@ static bool AddResourcesToTable(ResourceTable* table, android::IDiagnostics* dia
}
if (res->value != nullptr) {
+ res->value->SetFlag(res->flag);
res->value->SetFlagStatus(res->flag_status);
// Attach the comment, source and config to the value.
res->value->SetComment(std::move(res->comment));
@@ -162,8 +164,6 @@ static bool AddResourcesToTable(ResourceTable* table, android::IDiagnostics* dia
res_builder.SetStagedId(res->staged_alias.value());
}
- res_builder.SetFlagStatus(res->flag_status);
-
bool error = false;
if (!res->name.entry.empty()) {
if (!table->AddResource(res_builder.Build(), diag)) {
@@ -546,12 +546,26 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
{"symbol", std::mem_fn(&ResourceParser::ParseSymbol)},
});
- std::string resource_type = parser->element_name();
- auto flag_status = GetFlagStatus(parser);
- if (!flag_status) {
- return false;
+ std::string_view resource_type = parser->element_name();
+ if (auto flag = ParseFlag(xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag"))) {
+ if (options_.flag) {
+ diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
+ << "Resource flag are not allowed both in the path and in the file");
+ return false;
+ }
+ out_resource->flag = std::move(flag);
+ std::string error;
+ auto flag_status = GetFlagStatus(out_resource->flag, options_.feature_flag_values, &error);
+ if (flag_status) {
+ out_resource->flag_status = flag_status.value();
+ } else {
+ diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) << error);
+ return false;
+ }
+ } else if (options_.flag) {
+ out_resource->flag = options_.flag;
+ out_resource->flag_status = options_.flag_status;
}
- out_resource->flag_status = flag_status.value();
// The value format accepted for this resource.
uint32_t resource_format = 0u;
@@ -567,7 +581,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
// Items have their type encoded in the type attribute.
if (std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
- resource_type = std::string(maybe_type.value());
+ resource_type = maybe_type.value();
} else {
diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
<< "<item> must have a 'type' attribute");
@@ -590,7 +604,7 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
// Bags have their type encoded in the type attribute.
if (std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
- resource_type = std::string(maybe_type.value());
+ resource_type = maybe_type.value();
} else {
diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
<< "<bag> must have a 'type' attribute");
@@ -733,33 +747,6 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
return false;
}
-std::optional<FlagStatus> ResourceParser::GetFlagStatus(xml::XmlPullParser* parser) {
- auto flag_status = FlagStatus::NoFlag;
-
- std::optional<StringPiece> flag = xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag");
- if (flag) {
- auto flag_it = options_.feature_flag_values.find(flag.value());
- if (flag_it == options_.feature_flag_values.end()) {
- diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
- << "Resource flag value undefined");
- return {};
- }
- const auto& flag_properties = flag_it->second;
- if (!flag_properties.read_only) {
- diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
- << "Only read only flags may be used with resources");
- return {};
- }
- if (!flag_properties.enabled.has_value()) {
- diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
- << "Only flags with a value may be used with resources");
- return {};
- }
- flag_status = flag_properties.enabled.value() ? FlagStatus::Enabled : FlagStatus::Disabled;
- }
- return flag_status;
-}
-
bool ResourceParser::ParseItem(xml::XmlPullParser* parser,
ParsedResource* out_resource,
const uint32_t format) {
@@ -1666,21 +1653,25 @@ bool ResourceParser::ParseArrayImpl(xml::XmlPullParser* parser,
const std::string& element_namespace = parser->element_namespace();
const std::string& element_name = parser->element_name();
if (element_namespace.empty() && element_name == "item") {
- auto flag_status = GetFlagStatus(parser);
- if (!flag_status) {
- error = true;
- continue;
- }
+ auto flag = ParseFlag(xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag"));
std::unique_ptr<Item> item = ParseXml(parser, typeMask, kNoRawString);
if (!item) {
diag_->Error(android::DiagMessage(item_source) << "could not parse array item");
error = true;
continue;
}
- item->SetFlagStatus(flag_status.value());
+ item->SetFlag(flag);
+ std::string err;
+ auto status = GetFlagStatus(flag, options_.feature_flag_values, &err);
+ if (status) {
+ item->SetFlagStatus(status.value());
+ } else {
+ diag_->Error(android::DiagMessage(item_source) << err);
+ error = true;
+ continue;
+ }
item->SetSource(item_source);
array->elements.emplace_back(std::move(item));
-
} else if (!ShouldIgnoreElement(element_namespace, element_name)) {
diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
<< "unknown tag <" << element_namespace << ":" << element_name << ">");
diff --git a/tools/aapt2/ResourceParser.h b/tools/aapt2/ResourceParser.h
index 442dea89ef40..90690d522ef2 100644
--- a/tools/aapt2/ResourceParser.h
+++ b/tools/aapt2/ResourceParser.h
@@ -57,6 +57,11 @@ struct ResourceParserOptions {
std::optional<Visibility::Level> visibility;
FeatureFlagValues feature_flag_values;
+
+ // The flag that should be applied to all resources parsed
+ std::optional<FeatureFlagAttribute> flag;
+
+ FlagStatus flag_status = FlagStatus::NoFlag;
};
struct FlattenedXmlSubTree {
@@ -85,8 +90,6 @@ class ResourceParser {
private:
DISALLOW_COPY_AND_ASSIGN(ResourceParser);
- std::optional<FlagStatus> GetFlagStatus(xml::XmlPullParser* parser);
-
std::optional<FlattenedXmlSubTree> CreateFlattenSubTree(xml::XmlPullParser* parser);
// Parses the XML subtree as a StyleString (flattened XML representation for strings with
diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp
index 97514599c0b1..5435cba290fc 100644
--- a/tools/aapt2/ResourceTable.cpp
+++ b/tools/aapt2/ResourceTable.cpp
@@ -101,6 +101,21 @@ struct lt_config_key_ref {
}
};
+struct ConfigFlagKey {
+ const ConfigDescription* config;
+ StringPiece product;
+ const FeatureFlagAttribute& flag;
+};
+
+struct lt_config_flag_key_ref {
+ template <typename T>
+ bool operator()(const T& lhs, const ConfigFlagKey& rhs) const noexcept {
+ return std::tie(lhs->config, lhs->product, lhs->value->GetFlag()->name,
+ lhs->value->GetFlag()->negated) <
+ std::tie(*rhs.config, rhs.product, rhs.flag.name, rhs.flag.negated);
+ }
+};
+
} // namespace
ResourceTable::ResourceTable(ResourceTable::Validation validation) : validation_(validation) {
@@ -213,6 +228,25 @@ std::vector<ResourceConfigValue*> ResourceEntry::FindAllValues(const ConfigDescr
return results;
}
+ResourceConfigValue* ResourceEntry::FindOrCreateFlagDisabledValue(
+ const FeatureFlagAttribute& flag, const android::ConfigDescription& config,
+ android::StringPiece product) {
+ auto iter = std::lower_bound(flag_disabled_values.begin(), flag_disabled_values.end(),
+ ConfigFlagKey{&config, product, flag}, lt_config_flag_key_ref());
+ if (iter != flag_disabled_values.end()) {
+ ResourceConfigValue* value = iter->get();
+ const auto value_flag = value->value->GetFlag().value();
+ if (value_flag.name == flag.name && value_flag.negated == flag.negated &&
+ value->config == config && value->product == product) {
+ return value;
+ }
+ }
+ ResourceConfigValue* newValue =
+ flag_disabled_values.insert(iter, util::make_unique<ResourceConfigValue>(config, product))
+ ->get();
+ return newValue;
+}
+
bool ResourceEntry::HasDefaultValue() const {
// The default config should be at the top of the list, since the list is sorted.
return !values.empty() && values.front()->config == ConfigDescription::DefaultConfig();
@@ -375,13 +409,14 @@ struct EntryViewComparer {
}
};
-void InsertEntryIntoTableView(ResourceTableView& table, const ResourceTablePackage* package,
- const ResourceTableType* type, const std::string& entry_name,
- const std::optional<ResourceId>& id, const Visibility& visibility,
- const std::optional<AllowNew>& allow_new,
- const std::optional<OverlayableItem>& overlayable_item,
- const std::optional<StagedId>& staged_id,
- const std::vector<std::unique_ptr<ResourceConfigValue>>& values) {
+void InsertEntryIntoTableView(
+ ResourceTableView& table, const ResourceTablePackage* package, const ResourceTableType* type,
+ const std::string& entry_name, const std::optional<ResourceId>& id,
+ const Visibility& visibility, const std::optional<AllowNew>& allow_new,
+ const std::optional<OverlayableItem>& overlayable_item,
+ const std::optional<StagedId>& staged_id,
+ const std::vector<std::unique_ptr<ResourceConfigValue>>& values,
+ const std::vector<std::unique_ptr<ResourceConfigValue>>& flag_disabled_values) {
SortedVectorInserter<ResourceTablePackageView, PackageViewComparer> package_inserter;
SortedVectorInserter<ResourceTableTypeView, TypeViewComparer> type_inserter;
SortedVectorInserter<ResourceTableEntryView, EntryViewComparer> entry_inserter;
@@ -408,6 +443,9 @@ void InsertEntryIntoTableView(ResourceTableView& table, const ResourceTablePacka
for (auto& value : values) {
new_entry.values.emplace_back(value.get());
}
+ for (auto& value : flag_disabled_values) {
+ new_entry.flag_disabled_values.emplace_back(value.get());
+ }
entry_inserter.Insert(view_type->entries, std::move(new_entry));
}
@@ -426,6 +464,21 @@ const ResourceConfigValue* ResourceTableEntryView::FindValue(const ConfigDescrip
return nullptr;
}
+const ResourceConfigValue* ResourceTableEntryView::FindFlagDisabledValue(
+ const FeatureFlagAttribute& flag, const ConfigDescription& config,
+ android::StringPiece product) const {
+ auto iter = std::lower_bound(flag_disabled_values.begin(), flag_disabled_values.end(),
+ ConfigFlagKey{&config, product, flag}, lt_config_flag_key_ref());
+ if (iter != values.end()) {
+ const ResourceConfigValue* value = *iter;
+ if (value->value->GetFlag() == flag && value->config == config &&
+ StringPiece(value->product) == product) {
+ return value;
+ }
+ }
+ return nullptr;
+}
+
ResourceTableView ResourceTable::GetPartitionedView(const ResourceTableViewOptions& options) const {
ResourceTableView view;
for (const auto& package : packages) {
@@ -433,13 +486,13 @@ ResourceTableView ResourceTable::GetPartitionedView(const ResourceTableViewOptio
for (const auto& entry : type->entries) {
InsertEntryIntoTableView(view, package.get(), type.get(), entry->name, entry->id,
entry->visibility, entry->allow_new, entry->overlayable_item,
- entry->staged_id, entry->values);
+ entry->staged_id, entry->values, entry->flag_disabled_values);
if (options.create_alias_entries && entry->staged_id) {
auto alias_id = entry->staged_id.value().id;
InsertEntryIntoTableView(view, package.get(), type.get(), entry->name, alias_id,
entry->visibility, entry->allow_new, entry->overlayable_item, {},
- entry->values);
+ entry->values, entry->flag_disabled_values);
}
}
}
@@ -587,6 +640,25 @@ bool ResourceTable::AddResource(NewResource&& res, android::IDiagnostics* diag)
entry->staged_id = res.staged_id.value();
}
+ if (res.value != nullptr && res.value->GetFlagStatus() == FlagStatus::Disabled) {
+ auto disabled_config_value =
+ entry->FindOrCreateFlagDisabledValue(res.value->GetFlag().value(), res.config, res.product);
+ if (!disabled_config_value->value) {
+ // Resource does not exist, add it now.
+ // Must clone the value since it might be in the values vector as well
+ CloningValueTransformer cloner(&string_pool);
+ disabled_config_value->value = res.value->Transform(cloner);
+ } else {
+ diag->Error(android::DiagMessage(source)
+ << "duplicate value for resource '" << res.name << "' " << "with config '"
+ << res.config << "' and flag '"
+ << (res.value->GetFlag().value().negated ? "!" : "")
+ << res.value->GetFlag().value().name << "'");
+ diag->Error(android::DiagMessage(source) << "resource previously defined here");
+ return false;
+ }
+ }
+
if (res.value != nullptr) {
auto config_value = entry->FindOrCreateValue(res.config, res.product);
if (!config_value->value) {
@@ -595,9 +667,9 @@ bool ResourceTable::AddResource(NewResource&& res, android::IDiagnostics* diag)
} else {
// When validation is enabled, ensure that a resource cannot have multiple values defined for
// the same configuration unless protected by flags.
- auto result =
- validate ? ResolveFlagCollision(config_value->value->GetFlagStatus(), res.flag_status)
- : CollisionResult::kKeepBoth;
+ auto result = validate ? ResolveFlagCollision(config_value->value->GetFlagStatus(),
+ res.value->GetFlagStatus())
+ : CollisionResult::kKeepBoth;
if (result == CollisionResult::kConflict) {
result = ResolveValueCollision(config_value->value.get(), res.value.get());
}
@@ -771,11 +843,6 @@ NewResourceBuilder& NewResourceBuilder::SetAllowMangled(bool allow_mangled) {
return *this;
}
-NewResourceBuilder& NewResourceBuilder::SetFlagStatus(FlagStatus flag_status) {
- res_.flag_status = flag_status;
- return *this;
-}
-
NewResource NewResourceBuilder::Build() {
return std::move(res_);
}
diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h
index cba6b70cfbd6..b0e185536d16 100644
--- a/tools/aapt2/ResourceTable.h
+++ b/tools/aapt2/ResourceTable.h
@@ -136,6 +136,9 @@ class ResourceEntry {
// The resource's values for each configuration.
std::vector<std::unique_ptr<ResourceConfigValue>> values;
+ // The resource's values that are behind disabled flags.
+ std::vector<std::unique_ptr<ResourceConfigValue>> flag_disabled_values;
+
explicit ResourceEntry(android::StringPiece name) : name(name) {
}
@@ -148,6 +151,13 @@ class ResourceEntry {
android::StringPiece product);
std::vector<ResourceConfigValue*> FindAllValues(const android::ConfigDescription& config);
+ // Either returns the existing ResourceConfigValue in the disabled list with the given flag,
+ // config, and product or creates a new one and returns that. In either case the returned value
+ // does not have the flag set on the value so it must be set by the caller.
+ ResourceConfigValue* FindOrCreateFlagDisabledValue(const FeatureFlagAttribute& flag,
+ const android::ConfigDescription& config,
+ android::StringPiece product = {});
+
template <typename Func>
std::vector<ResourceConfigValue*> FindValuesIf(Func f) {
std::vector<ResourceConfigValue*> results;
@@ -215,9 +225,14 @@ struct ResourceTableEntryView {
std::optional<OverlayableItem> overlayable_item;
std::optional<StagedId> staged_id;
std::vector<const ResourceConfigValue*> values;
+ std::vector<const ResourceConfigValue*> flag_disabled_values;
const ResourceConfigValue* FindValue(const android::ConfigDescription& config,
android::StringPiece product = {}) const;
+
+ const ResourceConfigValue* FindFlagDisabledValue(const FeatureFlagAttribute& flag,
+ const android::ConfigDescription& config,
+ android::StringPiece product = {}) const;
};
struct ResourceTableTypeView {
@@ -269,7 +284,6 @@ struct NewResource {
std::optional<AllowNew> allow_new;
std::optional<StagedId> staged_id;
bool allow_mangled = false;
- FlagStatus flag_status = FlagStatus::NoFlag;
};
struct NewResourceBuilder {
@@ -283,7 +297,6 @@ struct NewResourceBuilder {
NewResourceBuilder& SetAllowNew(AllowNew allow_new);
NewResourceBuilder& SetStagedId(StagedId id);
NewResourceBuilder& SetAllowMangled(bool allow_mangled);
- NewResourceBuilder& SetFlagStatus(FlagStatus flag_status);
NewResource Build();
private:
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp
index b75e87c90128..723cfc0e035b 100644
--- a/tools/aapt2/ResourceValues.cpp
+++ b/tools/aapt2/ResourceValues.cpp
@@ -1102,6 +1102,7 @@ template <typename T>
std::unique_ptr<T> CopyValueFields(std::unique_ptr<T> new_value, const T* value) {
new_value->SetSource(value->GetSource());
new_value->SetComment(value->GetComment());
+ new_value->SetFlag(value->GetFlag());
new_value->SetFlagStatus(value->GetFlagStatus());
return new_value;
}
diff --git a/tools/aapt2/ResourceValues.h b/tools/aapt2/ResourceValues.h
index a1b1839b19ef..e000c653b87a 100644
--- a/tools/aapt2/ResourceValues.h
+++ b/tools/aapt2/ResourceValues.h
@@ -65,10 +65,21 @@ class Value {
return translatable_;
}
+ void SetFlag(std::optional<FeatureFlagAttribute> val) {
+ flag_ = val;
+ }
+
+ std::optional<FeatureFlagAttribute> GetFlag() const {
+ return flag_;
+ }
+
void SetFlagStatus(FlagStatus val) {
flag_status_ = val;
}
+ // If the value is behind a flag this returns whether that flag was enabled when the value was
+ // parsed by comparing it to the flags passed on the command line to aapt2 (taking into account
+ // negation if necessary). If there was no flag, FlagStatus::NoFlag is returned instead.
FlagStatus GetFlagStatus() const {
return flag_status_;
}
@@ -128,6 +139,7 @@ class Value {
std::string comment_;
bool weak_ = false;
bool translatable_ = true;
+ std::optional<FeatureFlagAttribute> flag_;
FlagStatus flag_status_ = FlagStatus::NoFlag;
private:
diff --git a/tools/aapt2/Resources.proto b/tools/aapt2/Resources.proto
index 5c6408940b34..a0f60b62db3a 100644
--- a/tools/aapt2/Resources.proto
+++ b/tools/aapt2/Resources.proto
@@ -240,6 +240,9 @@ message Entry {
// The staged resource ID of this finalized resource.
StagedId staged_id = 7;
+
+ // The set of values defined for this entry which are behind disabled flags
+ repeated ConfigValue flag_disabled_config_value = 8;
}
// A Configuration/Value pair.
@@ -283,6 +286,8 @@ message Item {
// The status of the flag the value is behind if any
uint32 flag_status = 8;
+ bool flag_negated = 9;
+ string flag_name = 10;
}
// A CompoundValue is an abstract type. It represents a value that is a made of other values.
diff --git a/tools/aapt2/ResourcesInternal.proto b/tools/aapt2/ResourcesInternal.proto
index b0ed3da33368..f4735a2f6ce7 100644
--- a/tools/aapt2/ResourcesInternal.proto
+++ b/tools/aapt2/ResourcesInternal.proto
@@ -49,4 +49,9 @@ message CompiledFile {
// Any symbols this file auto-generates/exports (eg. @+id/foo in an XML file).
repeated Symbol exported_symbol = 5;
+
+ // The status of the flag the file is behind if any
+ uint32 flag_status = 6;
+ bool flag_negated = 7;
+ string flag_name = 8;
}
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 2a978a5153ca..52372fa38525 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -67,6 +67,7 @@ struct ResourcePathData {
std::string resource_dir;
std::string name;
std::string extension;
+ std::string flag_name;
// Original config str. We keep this because when we parse the config, we may add on
// version qualifiers. We want to preserve the original input so the output is easily
@@ -81,6 +82,22 @@ static std::optional<ResourcePathData> ExtractResourcePathData(const std::string
std::string* out_error,
const CompileOptions& options) {
std::vector<std::string> parts = util::Split(path, dir_sep);
+
+ std::string flag_name;
+ // Check for a flag
+ for (auto iter = parts.begin(); iter != parts.end();) {
+ if (iter->starts_with("flag(") && iter->ends_with(")")) {
+ if (!flag_name.empty()) {
+ if (out_error) *out_error = "resource path cannot contain more than one flag directory";
+ return {};
+ }
+ flag_name = iter->substr(5, iter->size() - 6);
+ iter = parts.erase(iter);
+ } else {
+ ++iter;
+ }
+ }
+
if (parts.size() < 2) {
if (out_error) *out_error = "bad resource path";
return {};
@@ -131,6 +148,7 @@ static std::optional<ResourcePathData> ExtractResourcePathData(const std::string
std::string(dir_str),
std::string(name),
std::string(extension),
+ std::move(flag_name),
std::string(config_str),
config};
}
@@ -142,6 +160,9 @@ static std::string BuildIntermediateContainerFilename(const ResourcePathData& da
name << "-" << data.config_str;
}
name << "_" << data.name;
+ if (!data.flag_name.empty()) {
+ name << ".(" << data.flag_name << ")";
+ }
if (!data.extension.empty()) {
name << "." << data.extension;
}
@@ -163,7 +184,6 @@ static bool CompileTable(IAaptContext* context, const CompileOptions& options,
<< "failed to open file: " << fin->GetError());
return false;
}
-
// Parse the values file from XML.
xml::XmlPullParser xml_parser(fin.get());
@@ -176,6 +196,18 @@ static bool CompileTable(IAaptContext* context, const CompileOptions& options,
// If visibility was forced, we need to use it when creating a new resource and also error if
// we try to parse the <public>, <public-group>, <java-symbol> or <symbol> tags.
parser_options.visibility = options.visibility;
+ parser_options.flag = ParseFlag(path_data.flag_name);
+
+ if (parser_options.flag) {
+ std::string error;
+ auto flag_status = GetFlagStatus(parser_options.flag, options.feature_flag_values, &error);
+ if (flag_status) {
+ parser_options.flag_status = std::move(flag_status.value());
+ } else {
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source) << error);
+ return false;
+ }
+ }
ResourceParser res_parser(context->GetDiagnostics(), &table, path_data.source, path_data.config,
parser_options);
@@ -402,6 +434,18 @@ static bool CompileXml(IAaptContext* context, const CompileOptions& options,
xmlres->file.config = path_data.config;
xmlres->file.source = path_data.source;
xmlres->file.type = ResourceFile::Type::kProtoXml;
+ xmlres->file.flag = ParseFlag(path_data.flag_name);
+
+ if (xmlres->file.flag) {
+ std::string error;
+ auto flag_status = GetFlagStatus(xmlres->file.flag, options.feature_flag_values, &error);
+ if (flag_status) {
+ xmlres->file.flag_status = flag_status.value();
+ } else {
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source) << error);
+ return false;
+ }
+ }
// Collect IDs that are defined here.
XmlIdCollector collector;
@@ -491,6 +535,27 @@ static bool CompilePng(IAaptContext* context, const CompileOptions& options,
res_file.source = path_data.source;
res_file.type = ResourceFile::Type::kPng;
+ if (!path_data.flag_name.empty()) {
+ FeatureFlagAttribute flag;
+ auto name = path_data.flag_name;
+ if (name.starts_with('!')) {
+ flag.negated = true;
+ flag.name = name.substr(1);
+ } else {
+ flag.name = name;
+ }
+ res_file.flag = flag;
+
+ std::string error;
+ auto flag_status = GetFlagStatus(flag, options.feature_flag_values, &error);
+ if (flag_status) {
+ res_file.flag_status = flag_status.value();
+ } else {
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source) << error);
+ return false;
+ }
+ }
+
{
auto data = file->OpenAsData();
if (!data) {
diff --git a/tools/aapt2/cmd/Diff.cpp b/tools/aapt2/cmd/Diff.cpp
index 6da3176b2bee..d3750a6100d3 100644
--- a/tools/aapt2/cmd/Diff.cpp
+++ b/tools/aapt2/cmd/Diff.cpp
@@ -138,6 +138,22 @@ static bool EmitResourceEntryDiff(IAaptContext* context, LoadedApk* apk_a,
}
}
+ for (const ResourceConfigValue* config_value_a : entry_a.flag_disabled_values) {
+ auto config_value_b = entry_b.FindFlagDisabledValue(config_value_a->value->GetFlag().value(),
+ config_value_a->config);
+ if (!config_value_b) {
+ std::stringstream str_stream;
+ str_stream << "missing disabled value " << pkg_a.name << ":" << type_a.named_type << "/"
+ << entry_a.name << " config=" << config_value_a->config
+ << " flag=" << config_value_a->value->GetFlag()->ToString();
+ EmitDiffLine(apk_b->GetSource(), str_stream.str());
+ diff = true;
+ } else {
+ diff |= EmitResourceConfigValueDiff(context, apk_a, pkg_a, type_a, entry_a, config_value_a,
+ apk_b, pkg_b, type_b, entry_b, config_value_b);
+ }
+ }
+
// Check for any newly added config values.
for (const ResourceConfigValue* config_value_b : entry_b.values) {
auto config_value_a = entry_a.FindValue(config_value_b->config);
@@ -149,6 +165,18 @@ static bool EmitResourceEntryDiff(IAaptContext* context, LoadedApk* apk_a,
diff = true;
}
}
+ for (const ResourceConfigValue* config_value_b : entry_b.flag_disabled_values) {
+ auto config_value_a = entry_a.FindFlagDisabledValue(config_value_b->value->GetFlag().value(),
+ config_value_b->config);
+ if (!config_value_a) {
+ std::stringstream str_stream;
+ str_stream << "new disabled config " << pkg_b.name << ":" << type_b.named_type << "/"
+ << entry_b.name << " config=" << config_value_b->config
+ << " flag=" << config_value_b->value->GetFlag()->ToString();
+ EmitDiffLine(apk_b->GetSource(), str_stream.str());
+ diff = true;
+ }
+ }
return diff;
}
diff --git a/tools/aapt2/cmd/Util.cpp b/tools/aapt2/cmd/Util.cpp
index 7739171b347f..08f8f0d85807 100644
--- a/tools/aapt2/cmd/Util.cpp
+++ b/tools/aapt2/cmd/Util.cpp
@@ -34,6 +34,44 @@ using ::android::base::StringPrintf;
namespace aapt {
+std::optional<FeatureFlagAttribute> ParseFlag(std::optional<std::string_view> flag_text) {
+ if (!flag_text || flag_text->empty()) {
+ return {};
+ }
+ FeatureFlagAttribute flag;
+ if (flag_text->starts_with('!')) {
+ flag.negated = true;
+ flag.name = flag_text->substr(1);
+ } else {
+ flag.name = flag_text.value();
+ }
+ return flag;
+}
+
+std::optional<FlagStatus> GetFlagStatus(const std::optional<FeatureFlagAttribute>& flag,
+ const FeatureFlagValues& feature_flag_values,
+ std::string* out_err) {
+ if (!flag) {
+ return FlagStatus::NoFlag;
+ }
+ auto flag_it = feature_flag_values.find(flag->name);
+ if (flag_it == feature_flag_values.end()) {
+ *out_err = "Resource flag value undefined: " + flag->name;
+ return {};
+ }
+ const auto& flag_properties = flag_it->second;
+ if (!flag_properties.read_only) {
+ *out_err = "Only read only flags may be used with resources: " + flag->name;
+ return {};
+ }
+ if (!flag_properties.enabled.has_value()) {
+ *out_err = "Only flags with a value may be used with resources: " + flag->name;
+ return {};
+ }
+ return (flag_properties.enabled.value() != flag->negated) ? FlagStatus::Enabled
+ : FlagStatus::Disabled;
+}
+
std::optional<uint16_t> ParseTargetDensityParameter(StringPiece arg, android::IDiagnostics* diag) {
ConfigDescription preferred_density_config;
if (!ConfigDescription::Parse(arg, &preferred_density_config)) {
diff --git a/tools/aapt2/cmd/Util.h b/tools/aapt2/cmd/Util.h
index 6b8813b34082..d32e532b86a8 100644
--- a/tools/aapt2/cmd/Util.h
+++ b/tools/aapt2/cmd/Util.h
@@ -49,6 +49,12 @@ struct FeatureFlagProperties {
using FeatureFlagValues = std::map<std::string, FeatureFlagProperties, std::less<>>;
+std::optional<FeatureFlagAttribute> ParseFlag(std::optional<std::string_view> flag_text);
+
+std::optional<FlagStatus> GetFlagStatus(const std::optional<FeatureFlagAttribute>& flag,
+ const FeatureFlagValues& feature_flag_values,
+ std::string* out_err);
+
// Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc).
// Returns Nothing and logs a human friendly error message if the string was not legal.
std::optional<uint16_t> ParseTargetDensityParameter(android::StringPiece arg,
diff --git a/tools/aapt2/format/proto/ProtoDeserialize.cpp b/tools/aapt2/format/proto/ProtoDeserialize.cpp
index 55f5e5668a16..8583cadff6d2 100644
--- a/tools/aapt2/format/proto/ProtoDeserialize.cpp
+++ b/tools/aapt2/format/proto/ProtoDeserialize.cpp
@@ -536,6 +536,34 @@ static bool DeserializePackageFromPb(const pb::Package& pb_package, const ResStr
config_value->value = DeserializeValueFromPb(pb_config_value.value(), src_pool, config,
&out_table->string_pool, files, out_error);
+
+ if (config_value->value == nullptr) {
+ return false;
+ }
+ }
+
+ // flag disabled
+ for (const pb::ConfigValue& pb_config_value : pb_entry.flag_disabled_config_value()) {
+ const pb::Configuration& pb_config = pb_config_value.config();
+
+ ConfigDescription config;
+ if (!DeserializeConfigFromPb(pb_config, &config, out_error)) {
+ return false;
+ }
+
+ FeatureFlagAttribute flag;
+ flag.name = pb_config_value.value().item().flag_name();
+ flag.negated = pb_config_value.value().item().flag_negated();
+ ResourceConfigValue* config_value =
+ entry->FindOrCreateFlagDisabledValue(std::move(flag), config, pb_config.product());
+ if (config_value->value != nullptr) {
+ *out_error = "duplicate configuration in resource table";
+ return false;
+ }
+
+ config_value->value = DeserializeValueFromPb(pb_config_value.value(), src_pool, config,
+ &out_table->string_pool, files, out_error);
+
if (config_value->value == nullptr) {
return false;
}
@@ -615,6 +643,12 @@ bool DeserializeCompiledFileFromPb(const pb::internal::CompiledFile& pb_file,
out_file->source.path = pb_file.source_path();
out_file->type = DeserializeFileReferenceTypeFromPb(pb_file.type());
+ out_file->flag_status = (FlagStatus)pb_file.flag_status();
+ if (!pb_file.flag_name().empty()) {
+ out_file->flag =
+ FeatureFlagAttribute{.name = pb_file.flag_name(), .negated = pb_file.flag_negated()};
+ }
+
std::string config_error;
if (!DeserializeConfigFromPb(pb_file.config(), &out_file->config, &config_error)) {
std::ostringstream error;
@@ -748,7 +782,6 @@ std::unique_ptr<Value> DeserializeValueFromPb(const pb::Value& pb_value,
if (value == nullptr) {
return {};
}
-
} else if (pb_value.has_compound_value()) {
const pb::CompoundValue& pb_compound_value = pb_value.compound_value();
switch (pb_compound_value.value_case()) {
@@ -1018,6 +1051,12 @@ std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item,
DeserializeItemFromPbInternal(pb_item, src_pool, config, value_pool, files, out_error);
if (item) {
item->SetFlagStatus((FlagStatus)pb_item.flag_status());
+ if (!pb_item.flag_name().empty()) {
+ FeatureFlagAttribute flag;
+ flag.name = pb_item.flag_name();
+ flag.negated = pb_item.flag_negated();
+ item->SetFlag(std::move(flag));
+ }
}
return item;
}
diff --git a/tools/aapt2/format/proto/ProtoSerialize.cpp b/tools/aapt2/format/proto/ProtoSerialize.cpp
index 5772b3b0b3e6..d83fe916ee95 100644
--- a/tools/aapt2/format/proto/ProtoSerialize.cpp
+++ b/tools/aapt2/format/proto/ProtoSerialize.cpp
@@ -427,6 +427,14 @@ void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table
SerializeValueToPb(*config_value->value, pb_config_value->mutable_value(),
source_pool.get());
}
+
+ for (const ResourceConfigValue* config_value : entry.flag_disabled_values) {
+ pb::ConfigValue* pb_config_value = pb_entry->add_flag_disabled_config_value();
+ SerializeConfig(config_value->config, pb_config_value->mutable_config());
+ pb_config_value->mutable_config()->set_product(config_value->product);
+ SerializeValueToPb(*config_value->value, pb_config_value->mutable_value(),
+ source_pool.get());
+ }
}
}
}
@@ -721,6 +729,11 @@ void SerializeValueToPb(const Value& value, pb::Value* out_value, android::Strin
}
if (out_value->has_item()) {
out_value->mutable_item()->set_flag_status((uint32_t)value.GetFlagStatus());
+ if (value.GetFlag()) {
+ const auto& flag = value.GetFlag();
+ out_value->mutable_item()->set_flag_negated(flag->negated);
+ out_value->mutable_item()->set_flag_name(flag->name);
+ }
}
}
@@ -730,6 +743,11 @@ void SerializeItemToPb(const Item& item, pb::Item* out_item) {
item.Accept(&serializer);
out_item->MergeFrom(value.item());
out_item->set_flag_status((uint32_t)item.GetFlagStatus());
+ if (item.GetFlag()) {
+ const auto& flag = item.GetFlag();
+ out_item->set_flag_negated(flag->negated);
+ out_item->set_flag_name(flag->name);
+ }
}
void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledFile* out_file) {
@@ -737,6 +755,11 @@ void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledF
out_file->set_source_path(file.source.path);
out_file->set_type(SerializeFileReferenceTypeToPb(file.type));
SerializeConfig(file.config, out_file->mutable_config());
+ out_file->set_flag_status((uint32_t)file.flag_status);
+ if (file.flag) {
+ out_file->set_flag_negated(file.flag->negated);
+ out_file->set_flag_name(file.flag->name);
+ }
for (const SourcedResourceName& exported : file.exported_symbols) {
pb::internal::CompiledFile_Symbol* pb_symbol = out_file->add_exported_symbol();
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/Android.bp b/tools/aapt2/integration-tests/FlaggedResourcesTest/Android.bp
index c456e5c296d2..7160b35033da 100644
--- a/tools/aapt2/integration-tests/FlaggedResourcesTest/Android.bp
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/Android.bp
@@ -31,13 +31,29 @@ genrule {
"res/values/ints.xml",
"res/values/strings.xml",
"res/layout/layout1.xml",
+ "res/layout/layout3.xml",
+ "res/flag(test.package.falseFlag)/values/bools.xml",
+ "res/flag(test.package.falseFlag)/layout/layout2.xml",
+ "res/flag(test.package.falseFlag)/drawable/removedpng.png",
+ "res/flag(test.package.trueFlag)/layout/layout3.xml",
+ "res/values/flag(test.package.trueFlag)/bools.xml",
+ "res/values/flag(!test.package.trueFlag)/bools.xml",
+ "res/values/flag(!test.package.falseFlag)/bools.xml",
],
out: [
+ "drawable_removedpng.(test.package.falseFlag).png.flat",
"values_bools.arsc.flat",
+ "values_bools.(test.package.falseFlag).arsc.flat",
+ "values_bools.(test.package.trueFlag).arsc.flat",
+ "values_bools.(!test.package.falseFlag).arsc.flat",
+ "values_bools.(!test.package.trueFlag).arsc.flat",
"values_bools2.arsc.flat",
"values_ints.arsc.flat",
"values_strings.arsc.flat",
"layout_layout1.xml.flat",
+ "layout_layout2.(test.package.falseFlag).xml.flat",
+ "layout_layout3.xml.flat",
+ "layout_layout3.(test.package.trueFlag).xml.flat",
],
cmd: "$(location aapt2) compile $(in) -o $(genDir) " +
"--feature-flags test.package.falseFlag:ro=false,test.package.trueFlag:ro=true",
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/drawable/removedpng.png b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/drawable/removedpng.png
new file mode 100644
index 000000000000..8a9e6984be96
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/drawable/removedpng.png
Binary files differ
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/layout/layout2.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/layout/layout2.xml
new file mode 100644
index 000000000000..dec5de72925a
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/layout/layout2.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+</LinearLayout> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/values/bools.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/values/bools.xml
new file mode 100644
index 000000000000..c46c4d4d8546
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.falseFlag)/values/bools.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="bool7">false</bool>
+</resources> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.trueFlag)/layout/layout3.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.trueFlag)/layout/layout3.xml
new file mode 100644
index 000000000000..5aeee0ee1e28
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/flag(test.package.trueFlag)/layout/layout3.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+ <TextView android:id="@+id/text1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="foobar" />
+</LinearLayout> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/layout/layout3.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/layout/layout3.xml
new file mode 100644
index 000000000000..dec5de72925a
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/layout/layout3.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+</LinearLayout> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/bools.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/bools.xml
index 1ed0c8a5f1e6..35975ed1274a 100644
--- a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/bools.xml
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/bools.xml
@@ -9,4 +9,15 @@
<bool name="bool3">false</bool>
<bool name="bool4" android:featureFlag="test.package.falseFlag">true</bool>
+
+ <bool name="bool5">false</bool>
+ <bool name="bool5" android:featureFlag="!test.package.falseFlag">true</bool>
+
+ <bool name="bool6">true</bool>
+ <bool name="bool6" android:featureFlag="!test.package.trueFlag">false</bool>
+
+ <bool name="bool7">true</bool>
+ <bool name="bool8">false</bool>
+ <bool name="bool9">true</bool>
+ <bool name="bool10">false</bool>
</resources> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.falseFlag)/bools.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.falseFlag)/bools.xml
new file mode 100644
index 000000000000..a63749c6ed7e
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.falseFlag)/bools.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="bool10">true</bool>
+</resources> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.trueFlag)/bools.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.trueFlag)/bools.xml
new file mode 100644
index 000000000000..bb5526e69f97
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(!test.package.trueFlag)/bools.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="bool9">false</bool>
+</resources> \ No newline at end of file
diff --git a/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(test.package.trueFlag)/bools.xml b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(test.package.trueFlag)/bools.xml
new file mode 100644
index 000000000000..eba780e88c9a
--- /dev/null
+++ b/tools/aapt2/integration-tests/FlaggedResourcesTest/res/values/flag(test.package.trueFlag)/bools.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="bool8">true</bool>
+</resources> \ No newline at end of file
diff --git a/tools/aapt2/link/FlaggedResources_test.cpp b/tools/aapt2/link/FlaggedResources_test.cpp
index 3db37c2fa6f8..629300838bbe 100644
--- a/tools/aapt2/link/FlaggedResources_test.cpp
+++ b/tools/aapt2/link/FlaggedResources_test.cpp
@@ -17,6 +17,7 @@
#include "LoadedApk.h"
#include "cmd/Dump.h"
#include "io/StringStream.h"
+#include "test/Common.h"
#include "test/Test.h"
#include "text/Printer.h"
@@ -75,6 +76,10 @@ TEST_F(FlaggedResourcesTest, DisabledResourcesRemovedFromTable) {
std::string output;
DumpResourceTableToString(loaded_apk.get(), &output);
+ ASSERT_EQ(output.find("bool4"), std::string::npos);
+ ASSERT_EQ(output.find("str1"), std::string::npos);
+ ASSERT_EQ(output.find("layout2"), std::string::npos);
+ ASSERT_EQ(output.find("removedpng"), std::string::npos);
}
TEST_F(FlaggedResourcesTest, DisabledResourcesRemovedFromTableChunks) {
@@ -86,6 +91,8 @@ TEST_F(FlaggedResourcesTest, DisabledResourcesRemovedFromTableChunks) {
ASSERT_EQ(output.find("bool4"), std::string::npos);
ASSERT_EQ(output.find("str1"), std::string::npos);
+ ASSERT_EQ(output.find("layout2"), std::string::npos);
+ ASSERT_EQ(output.find("removedpng"), std::string::npos);
}
TEST_F(FlaggedResourcesTest, DisabledResourcesInRJava) {
@@ -98,4 +105,47 @@ TEST_F(FlaggedResourcesTest, DisabledResourcesInRJava) {
ASSERT_NE(r_contents.find("public static final int str1"), std::string::npos);
}
+TEST_F(FlaggedResourcesTest, TwoValuesSameDisabledFlag) {
+ test::TestDiagnosticsImpl diag;
+ const std::string compiled_files_dir = GetTestPath("compiled");
+ ASSERT_FALSE(CompileFile(
+ GetTestPath("res/values/values.xml"),
+ R"(<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <bool name="bool1" android:featureFlag="test.package.falseFlag">false</bool>
+ <bool name="bool1" android:featureFlag="test.package.falseFlag">true</bool>
+ </resources>)",
+ compiled_files_dir, &diag,
+ {"--feature-flags", "test.package.falseFlag:ro=false,test.package.trueFlag:ro=true"}));
+ ASSERT_TRUE(diag.GetLog().contains("duplicate value for resource 'bool/bool1'"));
+}
+
+TEST_F(FlaggedResourcesTest, TwoValuesSameDisabledFlagDifferentFiles) {
+ test::TestDiagnosticsImpl diag;
+ const std::string compiled_files_dir = GetTestPath("compiled");
+ ASSERT_TRUE(CompileFile(
+ GetTestPath("res/values/values1.xml"),
+ R"(<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <bool name="bool1" android:featureFlag="test.package.falseFlag">false</bool>
+ </resources>)",
+ compiled_files_dir, &diag,
+ {"--feature-flags", "test.package.falseFlag:ro=false,test.package.trueFlag:ro=true"}));
+ ASSERT_TRUE(CompileFile(
+ GetTestPath("res/values/values2.xml"),
+ R"(<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <bool name="bool1" android:featureFlag="test.package.falseFlag">true</bool>
+ </resources>)",
+ compiled_files_dir, &diag,
+ {"--feature-flags", "test.package.falseFlag:ro=false,test.package.trueFlag:ro=true"}));
+ const std::string out_apk = GetTestPath("out.apk");
+ std::vector<std::string> link_args = {
+ "--manifest",
+ GetDefaultManifest(),
+ "-o",
+ out_apk,
+ };
+
+ ASSERT_FALSE(Link(link_args, compiled_files_dir, &diag));
+ ASSERT_TRUE(diag.GetLog().contains("duplicate value for resource 'bool1'"));
+}
+
} // namespace aapt
diff --git a/tools/aapt2/link/TableMerger.cpp b/tools/aapt2/link/TableMerger.cpp
index 37a039e9528f..1bef5f8b17f6 100644
--- a/tools/aapt2/link/TableMerger.cpp
+++ b/tools/aapt2/link/TableMerger.cpp
@@ -321,6 +321,30 @@ bool TableMerger::DoMerge(const android::Source& src, ResourceTablePackage* src_
}
}
}
+
+ // disabled values
+ for (auto& src_config_value : src_entry->flag_disabled_values) {
+ auto dst_config_value = dst_entry->FindOrCreateFlagDisabledValue(
+ src_config_value->value->GetFlag().value(), src_config_value->config,
+ src_config_value->product);
+ if (!dst_config_value->value) {
+ // Resource does not exist, add it now.
+ // Must clone the value since it might be in the values vector as well
+ CloningValueTransformer cloner(&main_table_->string_pool);
+ dst_config_value->value = src_config_value->value->Transform(cloner);
+ } else {
+ error = true;
+ context_->GetDiagnostics()->Error(
+ android::DiagMessage(src_config_value->value->GetSource())
+ << "duplicate value for resource '" << src_entry->name << "' " << "with config '"
+ << src_config_value->config << "' and flag '"
+ << (src_config_value->value->GetFlag()->negated ? "!" : "")
+ << src_config_value->value->GetFlag()->name << "'");
+ context_->GetDiagnostics()->Note(
+ android::DiagMessage(dst_config_value->value->GetSource())
+ << "resource previously defined here");
+ }
+ }
}
}
return !error;
@@ -353,6 +377,8 @@ bool TableMerger::MergeFile(const ResourceFile& file_desc, bool overlay, io::IFi
file_ref->SetSource(file_desc.source);
file_ref->type = file_desc.type;
file_ref->file = file;
+ file_ref->SetFlagStatus(file_desc.flag_status);
+ file_ref->SetFlag(file_desc.flag);
ResourceTablePackage* pkg = table.FindOrCreatePackage(file_desc.name.package);
pkg->FindOrCreateType(file_desc.name.type)
diff --git a/tools/aapt2/test/Common.cpp b/tools/aapt2/test/Common.cpp
index cdf245341844..c7dd4c90e67f 100644
--- a/tools/aapt2/test/Common.cpp
+++ b/tools/aapt2/test/Common.cpp
@@ -21,23 +21,6 @@ using android::ConfigDescription;
namespace aapt {
namespace test {
-struct TestDiagnosticsImpl : public android::IDiagnostics {
- void Log(Level level, android::DiagMessageActual& actual_msg) override {
- switch (level) {
- case Level::Note:
- return;
-
- case Level::Warn:
- std::cerr << actual_msg.source << ": warn: " << actual_msg.message << "." << std::endl;
- break;
-
- case Level::Error:
- std::cerr << actual_msg.source << ": error: " << actual_msg.message << "." << std::endl;
- break;
- }
- }
-};
-
android::IDiagnostics* GetDiagnostics() {
static TestDiagnosticsImpl diag;
return &diag;
diff --git a/tools/aapt2/test/Common.h b/tools/aapt2/test/Common.h
index 04379804d8ee..b06c4329488e 100644
--- a/tools/aapt2/test/Common.h
+++ b/tools/aapt2/test/Common.h
@@ -37,6 +37,32 @@
namespace aapt {
namespace test {
+struct TestDiagnosticsImpl : public android::IDiagnostics {
+ void Log(Level level, android::DiagMessageActual& actual_msg) override {
+ switch (level) {
+ case Level::Note:
+ return;
+
+ case Level::Warn:
+ std::cerr << actual_msg.source << ": warn: " << actual_msg.message << "." << std::endl;
+ log << actual_msg.source << ": warn: " << actual_msg.message << "." << std::endl;
+ break;
+
+ case Level::Error:
+ std::cerr << actual_msg.source << ": error: " << actual_msg.message << "." << std::endl;
+ log << actual_msg.source << ": error: " << actual_msg.message << "." << std::endl;
+ break;
+ }
+ }
+
+ std::string GetLog() {
+ return log.str();
+ }
+
+ private:
+ std::ostringstream log;
+};
+
android::IDiagnostics* GetDiagnostics();
inline ResourceName ParseNameOrDie(android::StringPiece str) {
diff --git a/tools/aapt2/test/Fixture.cpp b/tools/aapt2/test/Fixture.cpp
index b91abe572306..570bcf16c92c 100644
--- a/tools/aapt2/test/Fixture.cpp
+++ b/tools/aapt2/test/Fixture.cpp
@@ -91,10 +91,13 @@ void TestDirectoryFixture::WriteFile(const std::string& path, const std::string&
}
bool CommandTestFixture::CompileFile(const std::string& path, const std::string& contents,
- android::StringPiece out_dir, android::IDiagnostics* diag) {
+ android::StringPiece out_dir, android::IDiagnostics* diag,
+ const std::vector<android::StringPiece>& additional_args) {
WriteFile(path, contents);
CHECK(file::mkdirs(out_dir.data()));
- return CompileCommand(diag).Execute({path, "-o", out_dir, "-v"}, &std::cerr) == 0;
+ std::vector<android::StringPiece> args = {path, "-o", out_dir, "-v"};
+ args.insert(args.end(), additional_args.begin(), additional_args.end());
+ return CompileCommand(diag).Execute(args, &std::cerr) == 0;
}
bool CommandTestFixture::Link(const std::vector<std::string>& args, android::IDiagnostics* diag) {
diff --git a/tools/aapt2/test/Fixture.h b/tools/aapt2/test/Fixture.h
index 14298d1678f0..178d01156f32 100644
--- a/tools/aapt2/test/Fixture.h
+++ b/tools/aapt2/test/Fixture.h
@@ -73,7 +73,8 @@ class CommandTestFixture : public TestDirectoryFixture {
// Wries the contents of the file to the specified path. The file is compiled and the flattened
// file is written to the out directory.
bool CompileFile(const std::string& path, const std::string& contents,
- android::StringPiece flat_out_dir, android::IDiagnostics* diag);
+ android::StringPiece flat_out_dir, android::IDiagnostics* diag,
+ const std::vector<android::StringPiece>& additional_args = {});
// Executes the link command with the specified arguments.
bool Link(const std::vector<std::string>& args, android::IDiagnostics* diag);