summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.bp3
-rw-r--r--StubLibraries.bp3
-rw-r--r--apex/appsearch/framework/java/android/app/appsearch/AppSearchBatchResult.java42
-rw-r--r--apex/appsearch/framework/java/android/app/appsearch/AppSearchResult.java43
-rw-r--r--apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java230
-rw-r--r--apex/appsearch/framework/java/android/app/appsearch/GlobalSearchSession.java56
-rw-r--r--apex/appsearch/framework/java/android/app/appsearch/SearchResults.java8
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java1
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java118
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java44
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java33
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java292
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResult.java125
-rw-r--r--apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java437
-rw-r--r--apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchMigrationHelperImpl.java14
-rw-r--r--apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SetSchemaResponseToProtoConverter.java (renamed from apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SetSchemaResultToProtoConverter.java)24
-rw-r--r--apex/appsearch/synced_jetpack_changeid.txt2
-rw-r--r--apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java127
-rw-r--r--apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java10
-rw-r--r--apex/appsearch/testing/java/com/android/server/appsearch/testing/external/GlobalSearchSessionShim.java45
-rw-r--r--api/Android.bp62
-rw-r--r--cmds/svc/src/com/android/commands/svc/UsbCommand.java25
-rw-r--r--core/api/current.txt167
-rw-r--r--core/api/module-lib-current.txt7
-rw-r--r--core/api/system-current.txt120
-rw-r--r--core/api/test-current.txt7
-rw-r--r--core/java/android/app/ContextImpl.java32
-rw-r--r--core/java/android/app/IActivityManager.aidl2
-rw-r--r--core/java/android/app/Notification.java11
-rw-r--r--core/java/android/app/NotificationChannel.java42
-rw-r--r--core/java/android/app/SystemServiceRegistry.java2
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java86
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl5
-rw-r--r--core/java/android/app/people/IPeopleManager.aidl3
-rw-r--r--core/java/android/app/people/PeopleManager.java29
-rw-r--r--core/java/android/app/smartspace/SmartspaceAction.java2
-rw-r--r--core/java/android/appwidget/AppWidgetHostView.java105
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java6
-rw-r--r--core/java/android/appwidget/AppWidgetProviderInfo.java54
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java2
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java28
-rw-r--r--core/java/android/content/Context.java95
-rw-r--r--core/java/android/content/ContextWrapper.java20
-rw-r--r--core/java/android/content/pm/LauncherApps.java9
-rw-r--r--core/java/android/content/pm/ShortcutInfo.java10
-rw-r--r--core/java/android/content/pm/dex/DexMetadataHelper.java102
-rw-r--r--core/java/android/content/pm/verify/domain/DomainVerificationManager.java10
-rw-r--r--core/java/android/content/pm/verify/domain/DomainVerificationUserSelection.java28
-rw-r--r--core/java/android/graphics/fonts/FontFamilyUpdateRequest.java264
-rw-r--r--core/java/android/graphics/fonts/FontFileUpdateRequest.java65
-rw-r--r--core/java/android/graphics/fonts/FontManager.java135
-rw-r--r--core/java/android/graphics/fonts/FontUpdateRequest.java24
-rw-r--r--core/java/android/hardware/SystemSensorManager.java50
-rw-r--r--core/java/android/hardware/camera2/params/StreamConfigurationMap.java15
-rw-r--r--core/java/android/hardware/location/ContextHubClient.java14
-rw-r--r--core/java/android/hardware/location/ContextHubClientCallback.java9
-rw-r--r--core/java/android/hardware/location/ContextHubManager.java12
-rw-r--r--core/java/android/hardware/location/ContextHubTransaction.java8
-rw-r--r--core/java/android/hardware/location/IContextHubService.aidl3
-rw-r--r--core/java/android/hardware/usb/IUsbManager.aidl6
-rw-r--r--core/java/android/hardware/usb/UsbManager.java92
-rw-r--r--core/java/android/net/UidRange.java9
-rw-r--r--core/java/android/net/vcn/VcnConfig.java19
-rw-r--r--core/java/android/net/vcn/VcnGatewayConnectionConfig.java62
-rw-r--r--core/java/android/net/vcn/VcnManager.java24
-rw-r--r--core/java/android/os/PowerManager.java8
-rw-r--r--core/java/android/permission/AdminPermissionControlParams.aidl19
-rw-r--r--core/java/android/permission/AdminPermissionControlParams.java132
-rw-r--r--core/java/android/permission/IPermissionController.aidl5
-rw-r--r--core/java/android/permission/PermissionControllerManager.java35
-rw-r--r--core/java/android/permission/PermissionControllerService.java37
-rw-r--r--core/java/android/provider/DeviceConfig.java7
-rw-r--r--core/java/android/provider/Settings.java19
-rw-r--r--core/java/android/provider/SimPhonebookContract.java191
-rw-r--r--core/java/android/speech/tts/ITextToSpeechManager.aidl29
-rw-r--r--core/java/android/speech/tts/ITextToSpeechSession.aidl33
-rw-r--r--core/java/android/speech/tts/ITextToSpeechSessionCallback.aidl32
-rw-r--r--core/java/android/speech/tts/TextToSpeech.java168
-rw-r--r--core/java/android/uwb/RangingSession.java6
-rw-r--r--core/java/android/uwb/UwbManager.java14
-rw-r--r--core/java/android/view/FrameMetrics.java40
-rw-r--r--core/java/android/view/SurfaceControl.java2
-rw-r--r--core/java/android/view/View.java6
-rw-r--r--core/java/android/view/ViewRootImpl.java8
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java13
-rw-r--r--core/java/android/webkit/WebViewFactory.java17
-rw-r--r--core/java/android/widget/EdgeEffect.java90
-rw-r--r--core/java/android/widget/HorizontalScrollView.java45
-rw-r--r--core/java/android/widget/ImageView.java1
-rw-r--r--core/java/android/widget/ImeAwareEditText.java2
-rw-r--r--core/java/android/widget/ProgressBar.java4
-rw-r--r--core/java/android/widget/RemoteViews.java364
-rw-r--r--core/java/android/widget/ScrollView.java44
-rw-r--r--core/java/com/android/internal/graphics/fonts/IFontManager.aidl6
-rw-r--r--core/jni/Android.bp10
-rw-r--r--core/res/AndroidManifest.xml45
-rw-r--r--core/res/res/drawable/btn_borderless_material.xml3
-rw-r--r--core/res/res/drawable/btn_colored_material.xml3
-rw-r--r--core/res/res/drawable/btn_default_material.xml3
-rw-r--r--core/res/res/drawable/btn_toggle_material.xml3
-rw-r--r--core/res/res/values/attrs.xml15
-rw-r--r--core/res/res/values/colors.xml12
-rw-r--r--core/res/res/values/config.xml4
-rw-r--r--core/res/res/values/dimens.xml8
-rw-r--r--core/res/res/values/public.xml14
-rw-r--r--core/res/res/values/strings.xml5
-rw-r--r--core/res/res/values/themes_device_defaults.xml3
-rw-r--r--core/tests/coretests/src/android/provider/SimPhonebookContractTest.java51
-rw-r--r--data/etc/privapp-permissions-platform.xml4
-rw-r--r--data/etc/services.core.protolog.json18
-rw-r--r--graphics/java/android/graphics/HardwareRenderer.java13
-rw-r--r--graphics/java/android/graphics/drawable/RippleAnimationSession.java284
-rw-r--r--graphics/java/android/graphics/drawable/RippleDrawable.java323
-rw-r--r--graphics/java/android/graphics/drawable/RippleShader.java89
-rw-r--r--graphics/java/android/graphics/fonts/FontVariationAxis.java12
-rw-r--r--keystore/java/android/security/keystore/KeyGenParameterSpec.java41
-rw-r--r--keystore/java/android/security/keystore/KeyProperties.java9
-rw-r--r--libs/WindowManager/Shell/Android.bp24
-rw-r--r--libs/WindowManager/Shell/res/raw/wm_shell_protolog.json286
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/FullscreenTaskListener.java5
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java3
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/TaskView.java8
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/apppairs/AppPair.java13
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java8
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java7
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java25
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java18
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java13
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java10
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java28
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java4
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java9
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java11
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java5
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java62
-rw-r--r--libs/hwui/Android.bp8
-rw-r--r--libs/hwui/Animator.cpp8
-rw-r--r--libs/hwui/FrameInfo.cpp2
-rw-r--r--libs/hwui/FrameInfo.h5
-rw-r--r--libs/hwui/FrameMetricsReporter.h30
-rw-r--r--libs/hwui/JankTracker.cpp15
-rw-r--r--libs/hwui/JankTracker.h7
-rw-r--r--libs/hwui/ProfileDataContainer.cpp7
-rw-r--r--libs/hwui/ProfileDataContainer.h11
-rw-r--r--libs/hwui/SkiaCanvas.cpp24
-rw-r--r--libs/hwui/SkiaCanvas.h24
-rw-r--r--libs/hwui/hwui/BlurDrawLooper.cpp45
-rw-r--r--libs/hwui/hwui/BlurDrawLooper.h53
-rw-r--r--libs/hwui/hwui/Paint.h8
-rw-r--r--libs/hwui/jni/Paint.cpp6
-rw-r--r--libs/hwui/jni/android_graphics_HardwareRenderer.cpp9
-rw-r--r--libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp24
-rw-r--r--libs/hwui/renderthread/CanvasContext.cpp104
-rw-r--r--libs/hwui/renderthread/CanvasContext.h20
-rw-r--r--libs/hwui/renderthread/RenderProxy.cpp15
-rw-r--r--libs/hwui/renderthread/RenderProxy.h2
-rw-r--r--libs/hwui/renderthread/RenderThread.cpp35
-rw-r--r--libs/hwui/renderthread/RenderThread.h30
-rw-r--r--libs/hwui/tests/unit/SkiaBehaviorTests.cpp13
-rw-r--r--libs/hwui/tests/unit/SkiaCanvasTests.cpp3
-rw-r--r--libs/hwui/utils/PaintUtils.h1
-rw-r--r--location/java/android/location/Location.java7
-rw-r--r--media/java/android/media/AudioManager.java19
-rw-r--r--media/java/android/media/AudioPlaybackConfiguration.java15
-rw-r--r--media/java/android/media/AudioTrack.java4
-rw-r--r--media/java/android/media/ImageWriter.java20
-rw-r--r--media/java/android/media/MediaDrm.java77
-rw-r--r--media/java/android/media/MediaPlayer.java20
-rw-r--r--media/java/android/media/metrics/Event.java44
-rw-r--r--media/java/android/media/metrics/MediaMetricsManager.java3
-rw-r--r--media/java/android/media/metrics/PlaybackErrorEvent.java74
-rw-r--r--media/java/android/media/metrics/PlaybackSession.java6
-rw-r--r--media/java/android/media/metrics/PlaybackStateEvent.java128
-rw-r--r--media/java/android/media/session/MediaSessionManager.java5
-rw-r--r--media/jni/Android.bp1
-rw-r--r--media/jni/android_media_MediaDrm.cpp43
-rw-r--r--native/android/Android.bp2
-rw-r--r--native/android/libandroid.map.txt10
-rw-r--r--native/android/surface_control.cpp48
-rw-r--r--packages/Connectivity/framework/src/android/net/ConnectivityManager.java14
-rw-r--r--packages/Connectivity/framework/src/android/net/TestNetworkManager.java1
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java22
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/connectivity/ConnectivitySubsystemsRecoveryManager.java2
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java13
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/development/EnableAdbPreferenceControllerTest.java28
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java20
-rw-r--r--packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java1
-rw-r--r--packages/Shell/AndroidManifest.xml10
-rw-r--r--packages/SystemUI/Android.bp1
-rw-r--r--packages/SystemUI/AndroidManifest.xml8
-rw-r--r--packages/SystemUI/README.md4
-rw-r--r--packages/SystemUI/res-keyguard/drawable/ripple_drawable_pin.xml20
-rw-r--r--packages/SystemUI/res/drawable/circle_green_10dp.xml22
-rw-r--r--packages/SystemUI/res/drawable/people_space_content_background.xml2
-rw-r--r--packages/SystemUI/res/drawable/people_space_new_story_outline.xml (renamed from packages/SystemUI/res/drawable/people_space_round_tile_view_card.xml)5
-rw-r--r--packages/SystemUI/res/layout/people_space_large_avatar_tile.xml70
-rw-r--r--packages/SystemUI/res/layout/people_space_notification_content_tile.xml154
-rw-r--r--packages/SystemUI/res/layout/people_space_small_avatar_tile.xml271
-rw-r--r--packages/SystemUI/res/layout/punctuation_layout.xml100
-rw-r--r--packages/SystemUI/res/layout/status_bar_expanded.xml7
-rw-r--r--packages/SystemUI/res/values/config.xml1
-rw-r--r--packages/SystemUI/res/values/dimens.xml4
-rw-r--r--packages/SystemUI/res/values/flags.xml3
-rw-r--r--packages/SystemUI/res/values/strings.xml29
-rw-r--r--packages/SystemUI/res/xml/people_space_widget_info.xml6
-rw-r--r--packages/SystemUI/shared/src/com/android/systemui/shared/system/PeopleProviderUtils.java76
-rw-r--r--packages/SystemUI/src/com/android/keyguard/CarrierText.java65
-rw-r--r--packages/SystemUI/src/com/android/keyguard/CarrierTextController.java691
-rw-r--r--packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java720
-rw-r--r--packages/SystemUI/src/com/android/keyguard/EmergencyButton.java140
-rw-r--r--packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java196
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java14
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java8
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java45
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java3
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java18
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java14
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java3
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java6
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java14
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java13
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java6
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java10
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java35
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSliceViewController.java4
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java19
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java18
-rw-r--r--packages/SystemUI/src/com/android/keyguard/NumPadButton.java48
-rw-r--r--packages/SystemUI/src/com/android/keyguard/NumPadKey.java30
-rw-r--r--packages/SystemUI/src/com/android/keyguard/clock/ClockModule.java33
-rw-r--r--packages/SystemUI/src/com/android/keyguard/clock/ClockOptionsProvider.java20
-rw-r--r--packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewComponent.java42
-rw-r--r--packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewModule.java34
-rw-r--r--packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewScope.java32
-rw-r--r--packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/SystemUIApplication.java19
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt76
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java6
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java34
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndication.java11
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java157
-rw-r--r--packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java24
-rw-r--r--packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java261
-rw-r--r--packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetEnabler.java61
-rw-r--r--packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java31
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java34
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java29
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/CropView.java89
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureClient.java11
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt31
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/FeatureFlags.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java9
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java64
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java48
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java62
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java13
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java (renamed from packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java)136
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardDisplayManagerTest.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt5
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt111
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java26
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java11
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java23
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java156
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java40
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java178
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java13
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java54
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt34
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java40
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java72
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java5
-rw-r--r--services/Android.bp2
-rw-r--r--services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java14
-rw-r--r--services/core/Android.bp4
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java318
-rw-r--r--services/core/java/com/android/server/SensorPrivacyService.java16
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java18
-rw-r--r--services/core/java/com/android/server/app/GameManagerService.java13
-rw-r--r--services/core/java/com/android/server/app/GameManagerSettings.java (renamed from services/core/java/com/android/server/app/Settings.java)5
-rw-r--r--services/core/java/com/android/server/audio/PlaybackActivityMonitor.java4
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceAuthenticationClient.java2
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceEnrollClient.java15
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGenerateChallengeClient.java3
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGetFeatureClient.java2
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalCleanupClient.java3
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalEnumerateClient.java3
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRemovalClient.java2
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceResetLockoutClient.java2
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRevokeChallengeClient.java2
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceSetFeatureClient.java2
-rw-r--r--services/core/java/com/android/server/biometrics/sensors/face/hidl/TestHal.java13
-rw-r--r--services/core/java/com/android/server/connectivity/PermissionMonitor.java33
-rw-r--r--services/core/java/com/android/server/graphics/fonts/FontManagerService.java19
-rw-r--r--services/core/java/com/android/server/graphics/fonts/TEST_MAPPING7
-rw-r--r--services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java27
-rw-r--r--services/core/java/com/android/server/hdmi/HdmiCecController.java265
-rw-r--r--services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java8
-rw-r--r--services/core/java/com/android/server/infra/AbstractMasterSystemService.java14
-rw-r--r--services/core/java/com/android/server/location/LocationManagerService.java32
-rw-r--r--services/core/java/com/android/server/location/contexthub/AuthStateDenialTimer.java105
-rw-r--r--services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java421
-rw-r--r--services/core/java/com/android/server/location/contexthub/ContextHubClientManager.java55
-rw-r--r--services/core/java/com/android/server/location/contexthub/ContextHubService.java73
-rw-r--r--services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java27
-rw-r--r--services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java82
-rw-r--r--services/core/java/com/android/server/location/contexthub/NanoAppStateManager.java6
-rw-r--r--services/core/java/com/android/server/location/eventlog/LocationEventLog.java28
-rw-r--r--services/core/java/com/android/server/location/injector/DeviceIdleHelper.java76
-rw-r--r--services/core/java/com/android/server/location/injector/DeviceStationaryHelper.java36
-rw-r--r--services/core/java/com/android/server/location/injector/Injector.java6
-rw-r--r--services/core/java/com/android/server/location/injector/SystemDeviceIdleHelper.java70
-rw-r--r--services/core/java/com/android/server/location/injector/SystemDeviceStationaryHelper.java44
-rw-r--r--services/core/java/com/android/server/location/provider/AbstractLocationProvider.java6
-rw-r--r--services/core/java/com/android/server/location/provider/DelegateLocationProvider.java119
-rw-r--r--services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java294
-rw-r--r--services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java2
-rw-r--r--services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java11
-rw-r--r--services/core/java/com/android/server/om/OverlayManagerService.java4
-rw-r--r--services/core/java/com/android/server/om/OverlayManagerServiceImpl.java8
-rw-r--r--services/core/java/com/android/server/pm/LauncherAppsService.java3
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java107
-rw-r--r--services/core/java/com/android/server/pm/PackageSettingBase.java4
-rw-r--r--services/core/java/com/android/server/pm/Settings.java8
-rw-r--r--services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java4
-rw-r--r--services/core/java/com/android/server/pm/verify/domain/DomainVerificationDebug.java5
-rw-r--r--services/core/java/com/android/server/pm/verify/domain/DomainVerificationManagerInternal.java108
-rw-r--r--services/core/java/com/android/server/pm/verify/domain/DomainVerificationPersistence.java10
-rw-r--r--services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java408
-rw-r--r--services/core/java/com/android/server/pm/verify/domain/DomainVerificationSettings.java7
-rw-r--r--services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationUserState.java48
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java9
-rw-r--r--services/core/java/com/android/server/stats/pull/StatsPullAtomService.java2
-rw-r--r--services/core/java/com/android/server/vcn/VcnGatewayConnection.java120
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java1
-rw-r--r--services/core/java/com/android/server/wm/DisplayContent.java30
-rw-r--r--services/core/java/com/android/server/wm/RootWindowContainer.java2
-rw-r--r--services/core/java/com/android/server/wm/Task.java14
-rw-r--r--services/core/java/com/android/server/wm/TaskOrganizerController.java2
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java13
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java110
-rw-r--r--services/java/com/android/server/SystemServer.java25
-rw-r--r--services/people/java/com/android/server/people/PeopleService.java16
-rw-r--r--services/people/java/com/android/server/people/data/DataManager.java9
-rw-r--r--services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationEnforcerTest.kt1
-rw-r--r--services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt18
-rw-r--r--services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationSettingsMutationTest.kt1
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceIdleHelper.java38
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceStationaryHelper.java52
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/location/injector/TestInjector.java14
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java186
-rw-r--r--services/tests/servicestests/res/values/values.xml (renamed from services/tests/servicestests/res/values/strings.xml)8
-rw-r--r--services/tests/servicestests/res/xml/dummy_appwidget_info.xml12
-rw-r--r--services/tests/servicestests/src/com/android/server/app/GameManagerServiceSettingsTests.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java166
-rw-r--r--services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java28
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java77
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java3
-rw-r--r--services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java11
-rw-r--r--services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java36
-rw-r--r--services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java28
-rw-r--r--services/tests/servicestests/src/com/android/server/job/WorkCountTrackerTest.java8
-rw-r--r--services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java16
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java36
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/dex/DexMetadataHelperTest.java204
-rw-r--r--services/tests/servicestests/src/com/android/server/rotationresolver/OWNERS1
-rw-r--r--services/tests/servicestests/src/com/android/server/rotationresolver/RotationResolverManagerPerUserServiceTest.java58
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java53
-rw-r--r--services/texttospeech/Android.bp13
-rw-r--r--services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java184
-rw-r--r--services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerService.java77
-rw-r--r--services/usb/Android.bp1
-rw-r--r--services/usb/java/com/android/server/usb/UsbPortManager.java71
-rw-r--r--services/usb/java/com/android/server/usb/UsbService.java32
-rw-r--r--telecomm/java/android/telecom/CallScreeningService.aidl22
-rw-r--r--telecomm/java/android/telecom/CallScreeningService.java273
-rw-r--r--telecomm/java/android/telecom/Connection.java11
-rwxr-xr-xtelecomm/java/android/telecom/ConnectionService.java25
-rw-r--r--telecomm/java/android/telecom/RemoteConnection.java12
-rw-r--r--telecomm/java/com/android/internal/telecom/ICallScreeningAdapter.aidl15
-rw-r--r--telecomm/java/com/android/internal/telecom/IConnectionService.aidl4
-rw-r--r--telephony/java/com/android/internal/telephony/uicc/IccUtils.java45
-rw-r--r--tests/UpdatableSystemFontTest/TEST_MAPPING2
-rw-r--r--tests/net/java/com/android/server/ConnectivityServiceTest.java267
-rw-r--r--tests/net/java/com/android/server/connectivity/PermissionMonitorTest.java64
-rw-r--r--tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java43
-rw-r--r--tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectingStateTest.java5
-rw-r--r--tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java5
-rw-r--r--tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectingStateTest.java5
-rw-r--r--tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionRetryTimeoutStateTest.java5
-rw-r--r--tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java25
404 files changed, 14319 insertions, 4025 deletions
diff --git a/Android.bp b/Android.bp
index 0a3ca3b808ea..240d803ef337 100644
--- a/Android.bp
+++ b/Android.bp
@@ -403,6 +403,7 @@ filegroup {
":framework-mediaprovider-sources",
":framework-permission-sources",
":framework-permission-s-sources",
+ ":framework-scheduling-sources",
":framework-sdkextensions-sources",
":framework-statsd-sources",
":framework-tethering-srcs",
@@ -423,6 +424,7 @@ java_library {
"framework-mediaprovider.stubs.module_lib",
"framework-permission.stubs.module_lib",
"framework-permission-s.stubs.module_lib",
+ "framework-scheduling.stubs.module_lib",
"framework-sdkextensions.stubs.module_lib",
"framework-statsd.stubs.module_lib",
"framework-tethering.stubs.module_lib",
@@ -443,6 +445,7 @@ java_library {
"framework-mediaprovider.impl",
"framework-permission.impl",
"framework-permission-s.impl",
+ "framework-scheduling.impl",
"framework-sdkextensions.impl",
"framework-statsd.impl",
"framework-tethering.impl",
diff --git a/StubLibraries.bp b/StubLibraries.bp
index 3f2e89889912..4bd524f229ca 100644
--- a/StubLibraries.bp
+++ b/StubLibraries.bp
@@ -315,6 +315,7 @@ java_library_static {
"framework-mediaprovider.stubs",
"framework-permission.stubs",
"framework-permission-s.stubs",
+ "framework-scheduling.stubs",
"framework-sdkextensions.stubs",
"framework-statsd.stubs",
"framework-tethering.stubs",
@@ -338,6 +339,7 @@ java_library_static {
"framework-mediaprovider.stubs.system",
"framework-permission.stubs.system",
"framework-permission-s.stubs.system",
+ "framework-scheduling.stubs.system",
"framework-sdkextensions.stubs.system",
"framework-statsd.stubs.system",
"framework-tethering.stubs.system",
@@ -377,6 +379,7 @@ java_library_static {
"framework-mediaprovider.stubs.system",
"framework-permission.stubs.system",
"framework-permission-s.stubs.system",
+ "framework-scheduling.stubs.system",
"framework-sdkextensions.stubs.system",
"framework-statsd.stubs.system",
"framework-tethering.stubs.system",
diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchBatchResult.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchBatchResult.java
index 97cfe36fca80..cd75b1456ba8 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchBatchResult.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchBatchResult.java
@@ -37,24 +37,36 @@ import java.util.Map;
public final class AppSearchBatchResult<KeyType, ValueType> implements Parcelable {
@NonNull private final Map<KeyType, ValueType> mSuccesses;
@NonNull private final Map<KeyType, AppSearchResult<ValueType>> mFailures;
+ @NonNull private final Map<KeyType, AppSearchResult<ValueType>> mAll;
AppSearchBatchResult(
@NonNull Map<KeyType, ValueType> successes,
- @NonNull Map<KeyType, AppSearchResult<ValueType>> failures) {
+ @NonNull Map<KeyType, AppSearchResult<ValueType>> failures,
+ @NonNull Map<KeyType, AppSearchResult<ValueType>> all) {
mSuccesses = successes;
mFailures = failures;
+ mAll = all;
}
private AppSearchBatchResult(@NonNull Parcel in) {
- mSuccesses = Collections.unmodifiableMap(in.readHashMap(/*loader=*/ null));
- mFailures = Collections.unmodifiableMap(in.readHashMap(/*loader=*/ null));
+ mAll = Collections.unmodifiableMap(in.readHashMap(/*loader=*/ null));
+ Map<KeyType, ValueType> successes = new ArrayMap<>();
+ Map<KeyType, AppSearchResult<ValueType>> failures = new ArrayMap<>();
+ for (Map.Entry<KeyType, AppSearchResult<ValueType>> entry : mAll.entrySet()) {
+ if (entry.getValue().isSuccess()) {
+ successes.put(entry.getKey(), entry.getValue().getResultValue());
+ } else {
+ failures.put(entry.getKey(), entry.getValue());
+ }
+ }
+ mSuccesses = Collections.unmodifiableMap(successes);
+ mFailures = Collections.unmodifiableMap(failures);
}
/** @hide */
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeMap(mSuccesses);
- dest.writeMap(mFailures);
+ dest.writeMap(mAll);
}
/** Returns {@code true} if this {@link AppSearchBatchResult} has no failures. */
@@ -63,8 +75,8 @@ public final class AppSearchBatchResult<KeyType, ValueType> implements Parcelabl
}
/**
- * Returns a {@link Map} of all successful keys mapped to the successful
- * {@link AppSearchResult}s they produced.
+ * Returns a {@link Map} of all successful keys mapped to the successful {@link
+ * AppSearchResult}s they produced.
*
* <p>The values of the {@link Map} will not be {@code null}.
*/
@@ -85,7 +97,19 @@ public final class AppSearchBatchResult<KeyType, ValueType> implements Parcelabl
}
/**
+ * Returns a {@link Map} of all keys mapped to the {@link AppSearchResult}s they produced.
+ *
+ * <p>The values of the {@link Map} will not be {@code null}.
+ * @hide
+ */
+ @NonNull
+ public Map<KeyType, AppSearchResult<ValueType>> getAll() {
+ return mAll;
+ }
+
+ /**
* Asserts that this {@link AppSearchBatchResult} has no failures.
+ *
* @hide
*/
public void checkSuccess() {
@@ -133,6 +157,7 @@ public final class AppSearchBatchResult<KeyType, ValueType> implements Parcelabl
public static final class Builder<KeyType, ValueType> {
private final Map<KeyType, ValueType> mSuccesses = new ArrayMap<>();
private final Map<KeyType, AppSearchResult<ValueType>> mFailures = new ArrayMap<>();
+ private final Map<KeyType, AppSearchResult<ValueType>> mAll = new ArrayMap<>();
private boolean mBuilt = false;
/**
@@ -181,6 +206,7 @@ public final class AppSearchBatchResult<KeyType, ValueType> implements Parcelabl
mFailures.put(key, result);
mSuccesses.remove(key);
}
+ mAll.put(key, result);
return this;
}
@@ -189,7 +215,7 @@ public final class AppSearchBatchResult<KeyType, ValueType> implements Parcelabl
public AppSearchBatchResult<KeyType, ValueType> build() {
Preconditions.checkState(!mBuilt, "Builder has already been used");
mBuilt = true;
- return new AppSearchBatchResult<>(mSuccesses, mFailures);
+ return new AppSearchBatchResult<>(mSuccesses, mFailures, mAll);
}
}
}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchResult.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchResult.java
index 76225e40c56e..440f63341151 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchResult.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchResult.java
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.app.appsearch.exceptions.AppSearchException;
import android.os.Parcel;
import android.os.Parcelable;
+import android.util.Log;
import java.io.IOException;
import java.lang.annotation.Retention;
@@ -35,19 +36,21 @@ import java.util.Objects;
*/
public final class AppSearchResult<ValueType> implements Parcelable {
/**
- * Result codes from {@link AppSearchManager} methods.
+ * Result codes from {@link AppSearchSession} methods.
+ *
* @hide
*/
- @IntDef(value = {
- RESULT_OK,
- RESULT_UNKNOWN_ERROR,
- RESULT_INTERNAL_ERROR,
- RESULT_INVALID_ARGUMENT,
- RESULT_IO_ERROR,
- RESULT_OUT_OF_SPACE,
- RESULT_NOT_FOUND,
- RESULT_INVALID_SCHEMA,
- })
+ @IntDef(
+ value = {
+ RESULT_OK,
+ RESULT_UNKNOWN_ERROR,
+ RESULT_INTERNAL_ERROR,
+ RESULT_INVALID_ARGUMENT,
+ RESULT_IO_ERROR,
+ RESULT_OUT_OF_SPACE,
+ RESULT_NOT_FOUND,
+ RESULT_INVALID_SCHEMA,
+ })
@Retention(RetentionPolicy.SOURCE)
public @interface ResultCode {}
@@ -60,21 +63,21 @@ public final class AppSearchResult<ValueType> implements Parcelable {
/**
* An internal error occurred within AppSearch, which the caller cannot address.
*
- * This error may be considered similar to {@link IllegalStateException}
+ * <p>This error may be considered similar to {@link IllegalStateException}
*/
public static final int RESULT_INTERNAL_ERROR = 2;
/**
* The caller supplied invalid arguments to the call.
*
- * This error may be considered similar to {@link IllegalArgumentException}.
+ * <p>This error may be considered similar to {@link IllegalArgumentException}.
*/
public static final int RESULT_INVALID_ARGUMENT = 3;
/**
* An issue occurred reading or writing to storage. The call might succeed if repeated.
*
- * This error may be considered similar to {@link java.io.IOException}.
+ * <p>This error may be considered similar to {@link java.io.IOException}.
*/
public static final int RESULT_IO_ERROR = 4;
@@ -127,7 +130,7 @@ public final class AppSearchResult<ValueType> implements Parcelable {
/**
* Returns the result value associated with this result, if it was successful.
*
- * <p>See the documentation of the particular {@link AppSearchManager} call producing this
+ * <p>See the documentation of the particular {@link AppSearchSession} call producing this
* {@link AppSearchResult} for what is placed in the result value by that call.
*
* @throws IllegalStateException if this {@link AppSearchResult} is not successful.
@@ -145,8 +148,8 @@ public final class AppSearchResult<ValueType> implements Parcelable {
*
* <p>If {@link #isSuccess} is {@code true}, the error message is always {@code null}. The error
* message may be {@code null} even if {@link #isSuccess} is {@code false}. See the
- * documentation of the particular {@link AppSearchManager} call producing this
- * {@link AppSearchResult} for what is returned by {@link #getErrorMessage}.
+ * documentation of the particular {@link AppSearchSession} call producing this {@link
+ * AppSearchResult} for what is returned by {@link #getErrorMessage}.
*/
@Nullable
public String getErrorMessage() {
@@ -205,6 +208,7 @@ public final class AppSearchResult<ValueType> implements Parcelable {
/**
* Creates a new successful {@link AppSearchResult}.
+ *
* @hide
*/
@NonNull
@@ -215,6 +219,7 @@ public final class AppSearchResult<ValueType> implements Parcelable {
/**
* Creates a new failed {@link AppSearchResult}.
+ *
* @hide
*/
@NonNull
@@ -227,6 +232,8 @@ public final class AppSearchResult<ValueType> implements Parcelable {
@NonNull
public static <ValueType> AppSearchResult<ValueType> throwableToFailedResult(
@NonNull Throwable t) {
+ Log.d("AppSearchResult", "Converting throwable to failed result.", t);
+
if (t instanceof AppSearchException) {
return ((AppSearchException) t).toAppSearchResult();
}
@@ -241,6 +248,6 @@ public final class AppSearchResult<ValueType> implements Parcelable {
} else {
resultCode = AppSearchResult.RESULT_UNKNOWN_ERROR;
}
- return AppSearchResult.newFailedResult(resultCode, t.toString());
+ return AppSearchResult.newFailedResult(resultCode, t.getMessage());
}
}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java
index 8fcd2f9bffb2..73ca0ccab46d 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java
@@ -108,54 +108,85 @@ public final class AppSearchSession implements Closeable {
* to {@link #setSchema}, if any, to determine how to treat existing documents. The following
* types of schema modifications are always safe and are made without deleting any existing
* documents:
+ *
* <ul>
- * <li>Addition of new types
- * <li>Addition of new
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_OPTIONAL OPTIONAL} or
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_REPEATED REPEATED} properties to a
- * type
- * <li>Changing the cardinality of a data type to be less restrictive (e.g. changing an
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_OPTIONAL OPTIONAL} property into a
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_REPEATED REPEATED} property.
+ * <li>Addition of new types
+ * <li>Addition of new {@link AppSearchSchema.PropertyConfig#CARDINALITY_OPTIONAL OPTIONAL} or
+ * {@link AppSearchSchema.PropertyConfig#CARDINALITY_REPEATED REPEATED} properties to a
+ * type
+ * <li>Changing the cardinality of a data type to be less restrictive (e.g. changing an {@link
+ * AppSearchSchema.PropertyConfig#CARDINALITY_OPTIONAL OPTIONAL} property into a {@link
+ * AppSearchSchema.PropertyConfig#CARDINALITY_REPEATED REPEATED} property.
* </ul>
*
* <p>The following types of schema changes are not backwards-compatible:
+ *
* <ul>
- * <li>Removal of an existing type
- * <li>Removal of a property from a type
- * <li>Changing the data type ({@code boolean}, {@code long}, etc.) of an existing property
- * <li>For properties of {@code Document} type, changing the schema type of
- * {@code Document}s of that property
- * <li>Changing the cardinality of a data type to be more restrictive (e.g. changing an
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_OPTIONAL OPTIONAL} property into a
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_REQUIRED REQUIRED} property).
- * <li>Adding a
- * {@link AppSearchSchema.PropertyConfig#CARDINALITY_REQUIRED REQUIRED} property.
+ * <li>Removal of an existing type
+ * <li>Removal of a property from a type
+ * <li>Changing the data type ({@code boolean}, {@code long}, etc.) of an existing property
+ * <li>For properties of {@code Document} type, changing the schema type of {@code Document}s
+ * of that property
+ * <li>Changing the cardinality of a data type to be more restrictive (e.g. changing an {@link
+ * AppSearchSchema.PropertyConfig#CARDINALITY_OPTIONAL OPTIONAL} property into a {@link
+ * AppSearchSchema.PropertyConfig#CARDINALITY_REQUIRED REQUIRED} property).
+ * <li>Adding a {@link AppSearchSchema.PropertyConfig#CARDINALITY_REQUIRED REQUIRED} property.
* </ul>
- * <p>Supplying a schema with such changes will, by default, result in this call returning an
- * {@link AppSearchResult} with a code of {@link AppSearchResult#RESULT_INVALID_SCHEMA} and an
- * error message describing the incompatibility. In this case the previously set schema will
- * remain active.
*
- * <p>If you need to make non-backwards-compatible changes as described above, you can set the
- * {@link SetSchemaRequest.Builder#setForceOverride} method to {@code true}. In this case,
- * instead of returning an {@link AppSearchResult} with the
- * {@link AppSearchResult#RESULT_INVALID_SCHEMA} error code, all documents which are not
- * compatible with the new schema will be deleted and the incompatible schema will be applied.
+ * <p>Supplying a schema with such changes will, by default, result in this call completing its
+ * future with an {@link android.app.appsearch.exceptions.AppSearchException} with a code of
+ * {@link AppSearchResult#RESULT_INVALID_SCHEMA} and a message describing the incompatibility.
+ * In this case the previously set schema will remain active.
+ *
+ * <p>If you need to make non-backwards-compatible changes as described above, you can either:
+ *
+ * <ul>
+ * <li>Set the {@link SetSchemaRequest.Builder#setForceOverride} method to {@code true}. In
+ * this case, instead of completing its future with an {@link
+ * android.app.appsearch.exceptions.AppSearchException} with the {@link
+ * AppSearchResult#RESULT_INVALID_SCHEMA} error code, all documents which are not
+ * compatible with the new schema will be deleted and the incompatible schema will be
+ * applied. Incompatible types and deleted types will be set into {@link
+ * SetSchemaResponse#getIncompatibleTypes()} and {@link
+ * SetSchemaResponse#getDeletedTypes()}, respectively.
+ * <li>Add a {@link android.app.appsearch.AppSearchSchema.Migrator} for each incompatible type
+ * and make no deletion. The migrator will migrate documents from it's old schema version
+ * to the new version. Migrated types will be set into both {@link
+ * SetSchemaResponse#getIncompatibleTypes()} and {@link
+ * SetSchemaResponse#getMigratedTypes()}. See the migration section below.
+ * </ul>
*
* <p>It is a no-op to set the same schema as has been previously set; this is handled
* efficiently.
*
- * <p>By default, documents are visible on platform surfaces. To opt out, call
- * {@link SetSchemaRequest.Builder#setSchemaTypeVisibilityForSystemUi} with {@code visible} as
- * false. Any visibility settings apply only to the schemas that are included in the
- * {@code request}. Visibility settings for a schema type do not persist across
- * {@link #setSchema} calls.
+ * <p>By default, documents are visible on platform surfaces. To opt out, call {@code
+ * SetSchemaRequest.Builder#setPlatformSurfaceable} with {@code surfaceable} as false. Any
+ * visibility settings apply only to the schemas that are included in the {@code request}.
+ * Visibility settings for a schema type do not apply or persist across {@link
+ * SetSchemaRequest}s.
+ *
+ * <p>Migration: make non-backwards-compatible changes will delete all stored documents in old
+ * schema. You can save your documents by setting {@link
+ * android.app.appsearch.AppSearchSchema.Migrator} via the {@link
+ * SetSchemaRequest.Builder#setMigrator} for each type you want to save.
+ *
+ * <p>{@link android.app.appsearch.AppSearchSchema.Migrator#onDowngrade} or {@link
+ * android.app.appsearch.AppSearchSchema.Migrator#onUpgrade} will be triggered if the version
+ * number of the schema stored in AppSearch is different with the version in the request.
+ *
+ * <p>If any error or Exception occurred in the {@link
+ * android.app.appsearch.AppSearchSchema.Migrator#onDowngrade}, {@link
+ * android.app.appsearch.AppSearchSchema.Migrator#onUpgrade} or {@link
+ * android.app.appsearch.AppSearchMigrationHelper.Transformer#transform}, the migration will be
+ * terminated, the setSchema request will be rejected unless the schema changes are
+ * backwards-compatible, and stored documents won't have any observable changes.
*
- * @param request The schema update request.
+ * @param request The schema update request.
* @param executor Executor on which to invoke the callback.
* @param callback Callback to receive errors resulting from setting the schema. If the
* operation succeeds, the callback will be invoked with {@code null}.
+ * @see android.app.appsearch.AppSearchSchema.Migrator
+ * @see android.app.appsearch.AppSearchMigrationHelper.Transformer
*/
public void setSchema(
@NonNull SetSchemaRequest request,
@@ -193,11 +224,9 @@ public final class AppSearchSession implements Closeable {
executor.execute(() -> {
if (result.isSuccess()) {
callback.accept(
- // TODO(b/151178558) implement Migration in platform.
+ // TODO(b/177266929) implement Migration in platform.
AppSearchResult.newSuccessfulResult(
- new SetSchemaResponse.Builder().setResultCode(
- result.getResultCode())
- .build()));
+ new SetSchemaResponse.Builder().build()));
} else {
callback.accept(result);
}
@@ -256,7 +285,7 @@ public final class AppSearchSession implements Closeable {
* <p>Each {@link GenericDocument}'s {@code schemaType} field must be set to the name of a
* schema type previously registered via the {@link #setSchema} method.
*
- * @param request {@link PutDocumentsRequest} containing documents to be indexed
+ * @param request {@link PutDocumentsRequest} containing documents to be indexed
* @param executor Executor on which to invoke the callback.
* @param callback Callback to receive pending result of performing this operation. The keys
* of the returned {@link AppSearchBatchResult} are the URIs of the input
@@ -297,9 +326,10 @@ public final class AppSearchSession implements Closeable {
}
/**
- * Retrieves {@link GenericDocument}s by URI.
+ * Gets {@link GenericDocument} objects by URIs and namespace from the {@link AppSearchSession}
+ * database.
*
- * @param request {@link GetByUriRequest} containing URIs to be retrieved.
+ * @param request a request containing URIs and namespace to get documents for.
* @param executor Executor on which to invoke the callback.
* @param callback Callback to receive the pending result of performing this operation. The keys
* of the returned {@link AppSearchBatchResult} are the input URIs. The values
@@ -377,48 +407,65 @@ public final class AppSearchSession implements Closeable {
}
/**
- * Searches a document based on a given query string.
+ * Retrieves documents from the open {@link AppSearchSession} that match a given query string
+ * and type of search provided.
+ *
+ * <p>Query strings can be empty, contain one term with no operators, or contain multiple terms
+ * and operators.
+ *
+ * <p>For query strings that are empty, all documents that match the {@link SearchSpec} will be
+ * returned.
+ *
+ * <p>For query strings with a single term and no operators, documents that match the provided
+ * query string and {@link SearchSpec} will be returned.
+ *
+ * <p>The following operators are supported:
*
- * <p>Currently we support following features in the raw query format:
* <ul>
- * <li>AND
- * <p>AND joins (e.g. “match documents that have both the terms ‘dog’ and
- * ‘cat’”).
- * Example: hello world matches documents that have both ‘hello’ and ‘world’
- * <li>OR
- * <p>OR joins (e.g. “match documents that have either the term ‘dog’ or
- * ‘cat’”).
- * Example: dog OR puppy
- * <li>Exclusion
- * <p>Exclude a term (e.g. “match documents that do
- * not have the term ‘dog’”).
- * Example: -dog excludes the term ‘dog’
- * <li>Grouping terms
- * <p>Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
- * “match documents that have either ‘dog’ or ‘puppy’, and either ‘cat’ or ‘kitten’”).
- * Example: (dog puppy) (cat kitten) two one group containing two terms.
- * <li>Property restricts
- * <p> Specifies which properties of a document to specifically match terms in (e.g.
- * “match documents where the ‘subject’ property contains ‘important’”).
- * Example: subject:important matches documents with the term ‘important’ in the
- * ‘subject’ property
- * <li>Schema type restricts
- * <p>This is similar to property restricts, but allows for restricts on top-level document
- * fields, such as schema_type. Clients should be able to limit their query to documents of
- * a certain schema_type (e.g. “match documents that are of the ‘Email’ schema_type”).
- * Example: { schema_type_filters: “Email”, “Video”,query: “dog” } will match documents
- * that contain the query term ‘dog’ and are of either the ‘Email’ schema type or the
- * ‘Video’ schema type.
+ * <li>AND (implicit)
+ * <p>AND is an operator that matches documents that contain <i>all</i> provided terms.
+ * <p><b>NOTE:</b> A space between terms is treated as an "AND" operator. Explicitly
+ * including "AND" in a query string will treat "AND" as a term, returning documents that
+ * also contain "AND".
+ * <p>Example: "apple AND banana" matches documents that contain the terms "apple", "and",
+ * "banana".
+ * <p>Example: "apple banana" matches documents that contain both "apple" and "banana".
+ * <p>Example: "apple banana cherry" matches documents that contain "apple", "banana", and
+ * "cherry".
+ * <li>OR
+ * <p>OR is an operator that matches documents that contain <i>any</i> provided term.
+ * <p>Example: "apple OR banana" matches documents that contain either "apple" or
+ * "banana".
+ * <p>Example: "apple OR banana OR cherry" matches documents that contain any of "apple",
+ * "banana", or "cherry".
+ * <li>Exclusion (-)
+ * <p>Exclusion (-) is an operator that matches documents that <i>do not</i> contain the
+ * provided term.
+ * <p>Example: "-apple" matches documents that do not contain "apple".
+ * <li>Grouped Terms
+ * <p>For queries that require multiple operators and terms, terms can be grouped into
+ * subqueries. Subqueries are contained within an open "(" and close ")" parenthesis.
+ * <p>Example: "(donut OR bagel) (coffee OR tea)" matches documents that contain either
+ * "donut" or "bagel" and either "coffee" or "tea".
+ * <li>Property Restricts
+ * <p>For queries that require a term to match a specific {@link AppSearchSchema} property
+ * of a document, a ":" must be included between the property name and the term.
+ * <p>Example: "subject:important" matches documents that contain the term "important" in
+ * the "subject" property.
* </ul>
*
- * <p> This method is lightweight. The heavy work will be done in
- * {@link SearchResults#getNextPage}.
+ * <p>Additional search specifications, such as filtering by {@link AppSearchSchema} type or
+ * adding projection, can be set by calling the corresponding {@link SearchSpec.Builder} setter.
*
- * @param queryExpression Query String to search.
- * @param searchSpec Spec for setting filters, raw query etc.
+ * <p>This method is lightweight. The heavy work will be done in {@link
+ * SearchResults#getNextPage}.
+ *
+ * @param queryExpression query string to search.
+ * @param searchSpec spec for setting document filters, adding projection, setting term match
+ * type, etc.
* @param executor Executor on which to invoke the callback of the following request
* {@link SearchResults#getNextPage}.
- * @return The search result of performing this operation.
+ * @return a {@link SearchResults} object for retrieved matched documents.
*/
@NonNull
public SearchResults search(
@@ -440,8 +487,8 @@ public final class AppSearchSession implements Closeable {
*
* <p>For each call to {@link #reportUsage}, AppSearch updates usage count and usage recency
* metrics for that particular document. These metrics are used for ordering {@link #search}
- * results by the {@link SearchSpec#RANKING_STRATEGY_USAGE_COUNT} and
- * {@link SearchSpec#RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP} ranking strategies.
+ * results by the {@link SearchSpec#RANKING_STRATEGY_USAGE_COUNT} and {@link
+ * SearchSpec#RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP} ranking strategies.
*
* <p>Reporting usage of a document is optional.
*
@@ -479,9 +526,17 @@ public final class AppSearchSession implements Closeable {
}
/**
- * Removes {@link GenericDocument}s from the index by URI.
+ * Removes {@link GenericDocument} objects by URIs and namespace from the {@link
+ * AppSearchSession} database.
+ *
+ * <p>Removed documents will no longer be surfaced by {@link #search} or {@link #getByUri}
+ * calls.
+ *
+ * <p><b>NOTE:</b>By default, documents are removed via a soft delete operation. Once the
+ * document crosses the count threshold or byte usage threshold, the documents will be removed
+ * from disk.
*
- * @param request Request containing URIs to be removed.
+ * @param request {@link RemoveByUriRequest} with URIs and namespace to remove from the index.
* @param executor Executor on which to invoke the callback.
* @param callback Callback to receive the pending result of performing this operation. The keys
* of the returned {@link AppSearchBatchResult} are the input URIs. The values
@@ -520,19 +575,18 @@ public final class AppSearchSession implements Closeable {
/**
* Removes {@link GenericDocument}s from the index by Query. Documents will be removed if they
- * match the {@code queryExpression} in given namespaces and schemaTypes which is set via
- * {@link SearchSpec.Builder#addFilterNamespaces} and
- * {@link SearchSpec.Builder#addFilterSchemas}.
+ * match the {@code queryExpression} in given namespaces and schemaTypes which is set via {@link
+ * SearchSpec.Builder#addFilterNamespaces} and {@link SearchSpec.Builder#addFilterSchemas}.
*
- * <p> An empty {@code queryExpression} matches all documents.
+ * <p>An empty {@code queryExpression} matches all documents.
*
- * <p> An empty set of namespaces or schemaTypes matches all namespaces or schemaTypes in
- * the current database.
+ * <p>An empty set of namespaces or schemaTypes matches all namespaces or schemaTypes in the
+ * current database.
*
* @param queryExpression Query String to search.
- * @param searchSpec Spec containing schemaTypes, namespaces and query expression indicates
- * how document will be removed. All specific about how to scoring,
- * ordering, snippeting and resulting will be ignored.
+ * @param searchSpec Spec containing schemaTypes, namespaces and query expression indicates how
+ * document will be removed. All specific about how to scoring, ordering, snippeting and
+ * resulting will be ignored.
* @param executor Executor on which to invoke the callback.
* @param callback Callback to receive errors resulting from removing the documents. If
* the operation succeeds, the callback will be invoked with
diff --git a/apex/appsearch/framework/java/android/app/appsearch/GlobalSearchSession.java b/apex/appsearch/framework/java/android/app/appsearch/GlobalSearchSession.java
index 86518347d770..09bca4fb3b9d 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/GlobalSearchSession.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/GlobalSearchSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Android Open Source Project
+ * Copyright 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.
@@ -32,7 +32,7 @@ import java.util.function.Consumer;
/**
* This class provides global access to the centralized AppSearch index maintained by the system.
*
- * <p>Apps can retrieve indexed documents through the query API.
+ * <p>Apps can retrieve indexed documents through the {@link #search} API.
*/
public class GlobalSearchSession implements Closeable {
@@ -90,48 +90,26 @@ public class GlobalSearchSession implements Closeable {
}
/**
- * Searches across all documents in the storage based on a given query string.
+ * Retrieves documents from all AppSearch databases that the querying application has access to.
*
- * <p>Currently we support following features in the raw query format:
- * <ul>
- * <li>AND
- * <p>AND joins (e.g. “match documents that have both the terms ‘dog’ and
- * ‘cat’”).
- * Example: hello world matches documents that have both ‘hello’ and ‘world’
- * <li>OR
- * <p>OR joins (e.g. “match documents that have either the term ‘dog’ or
- * ‘cat’”).
- * Example: dog OR puppy
- * <li>Exclusion
- * <p>Exclude a term (e.g. “match documents that do
- * not have the term ‘dog’”).
- * Example: -dog excludes the term ‘dog’
- * <li>Grouping terms
- * <p>Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
- * “match documents that have either ‘dog’ or ‘puppy’, and either ‘cat’ or ‘kitten’”).
- * Example: (dog puppy) (cat kitten) two one group containing two terms.
- * <li>Property restricts
- * <p> Specifies which properties of a document to specifically match terms in (e.g.
- * “match documents where the ‘subject’ property contains ‘important’”).
- * Example: subject:important matches documents with the term ‘important’ in the
- * ‘subject’ property
- * <li>Schema type restricts
- * <p>This is similar to property restricts, but allows for restricts on top-level document
- * fields, such as schema_type. Clients should be able to limit their query to documents of
- * a certain schema_type (e.g. “match documents that are of the ‘Email’ schema_type”).
- * Example: { schema_type_filters: “Email”, “Video”,query: “dog” } will match documents
- * that contain the query term ‘dog’ and are of either the ‘Email’ schema type or the
- * ‘Video’ schema type.
- * </ul>
+ * <p>Applications can be granted access to documents by specifying {@link
+ * SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage} when building a schema.
*
- * <p> This method is lightweight. The heavy work will be done in
- * {@link SearchResults#getNextPage}.
+ * <p>Document access can also be granted to system UIs by specifying {@link
+ * SetSchemaRequest.Builder#setSchemaTypeVisibilityForSystemUi} when building a schema.
*
- * @param queryExpression Query String to search.
- * @param searchSpec Spec for setting filters, raw query etc.
+ * <p>See {@link AppSearchSession#search} for a detailed explanation on
+ * forming a query string.
+ *
+ * <p>This method is lightweight. The heavy work will be done in {@link
+ * SearchResults#getNextPage}.
+ *
+ * @param queryExpression query string to search.
+ * @param searchSpec spec for setting document filters, adding projection, setting term match
+ * type, etc.
* @param executor Executor on which to invoke the callback of the following request
* {@link SearchResults#getNextPage}.
- * @return The search result of performing this operation.
+ * @return a {@link SearchResults} object for retrieved matched documents.
*/
@NonNull
public SearchResults search(
diff --git a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
index 704509bce2a1..a63e01555f6c 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
@@ -35,8 +35,8 @@ import java.util.function.Consumer;
/**
* SearchResults are a returned object from a query API.
*
- * <p>Each {@link SearchResult} contains a document and may contain other fields like snippets
- * based on request.
+ * <p>Each {@link SearchResult} contains a document and may contain other fields like snippets based
+ * on request.
*
* <p>Should close this object after finish fetching results.
*
@@ -89,8 +89,8 @@ public class SearchResults implements Closeable {
/**
* Gets a whole page of {@link SearchResult}s.
*
- * <p>Re-call this method to get next page of {@link SearchResult}, until it returns an
- * empty list.
+ * <p>Re-call this method to get next page of {@link SearchResult}, until it returns an empty
+ * list.
*
* <p>The page size is set by {@link SearchSpec.Builder#setResultCountPerPage}.
*
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java b/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java
index e94b3b269041..8bf438d43cd1 100644
--- a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java
+++ b/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchSchema.java
@@ -90,6 +90,7 @@ public final class AppSearchSchema {
* <p>This method creates a new list when called.
*/
@NonNull
+ @SuppressWarnings("MixedMutabilityReturnType")
public List<PropertyConfig> getProperties() {
ArrayList<Bundle> propertyBundles =
mBundle.getParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD);
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java
index 4c11514cf403..138eb23148af 100644
--- a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java
+++ b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java
@@ -36,7 +36,8 @@ import java.util.Set;
/**
* Represents a document unit.
*
- * <p>Documents are constructed via {@link GenericDocument.Builder}.
+ * <p>Documents contain structured data conforming to their {@link AppSearchSchema} type. Each
+ * document is uniquely identified by a URI and namespace.
*
* @see AppSearchSession#put
* @see AppSearchSession#getByUri
@@ -48,16 +49,10 @@ public class GenericDocument {
/** The default empty namespace. */
public static final String DEFAULT_NAMESPACE = "";
- /**
- * The maximum number of elements in a repeatable field. Will reject the request if exceed this
- * limit.
- */
+ /** The maximum number of elements in a repeatable field. */
private static final int MAX_REPEATED_PROPERTY_LENGTH = 100;
- /**
- * The maximum {@link String#length} of a {@link String} field. Will reject the request if
- * {@link String}s longer than this.
- */
+ /** The maximum {@link String#length} of a {@link String} field. */
private static final int MAX_STRING_LENGTH = 20_000;
/** The maximum number of indexed properties a document can have. */
@@ -149,7 +144,7 @@ public class GenericDocument {
return mBundle.getString(NAMESPACE_FIELD, DEFAULT_NAMESPACE);
}
- /** Returns the schema type of the {@link GenericDocument}. */
+ /** Returns the {@link AppSearchSchema} type of the {@link GenericDocument}. */
@NonNull
public String getSchemaType() {
return mSchemaType;
@@ -165,14 +160,14 @@ public class GenericDocument {
}
/**
- * Returns the TTL (Time To Live) of the {@link GenericDocument}, in milliseconds.
+ * Returns the TTL (time-to-live) of the {@link GenericDocument}, in milliseconds.
*
* <p>The TTL is measured against {@link #getCreationTimestampMillis}. At the timestamp of
* {@code creationTimestampMillis + ttlMillis}, measured in the {@link System#currentTimeMillis}
* time base, the document will be auto-deleted.
*
* <p>The default value is 0, which means the document is permanent and won't be auto-deleted
- * until the app is uninstalled.
+ * until the app is uninstalled or {@link AppSearchSession#remove} is called.
*/
public long getTtlMillis() {
return mBundle.getLong(TTL_MILLIS_FIELD, DEFAULT_TTL_MILLIS);
@@ -182,12 +177,12 @@ public class GenericDocument {
* Returns the score of the {@link GenericDocument}.
*
* <p>The score is a query-independent measure of the document's quality, relative to other
- * {@link GenericDocument}s of the same type.
+ * {@link GenericDocument} objects of the same {@link AppSearchSchema} type.
*
* <p>Results may be sorted by score using {@link SearchSpec.Builder#setRankingStrategy}.
* Documents with higher scores are considered better than documents with lower scores.
*
- * <p>Any nonnegative integer can be used a score.
+ * <p>Any non-negative integer can be used a score.
*/
public int getScore() {
return mBundle.getInt(SCORE_FIELD, DEFAULT_SCORE);
@@ -355,7 +350,7 @@ public class GenericDocument {
}
/**
- * Retrieves a repeated {@link String} property by key.
+ * Retrieves a repeated {@code long[]} property by key.
*
* @param key The key to look for.
* @return The {@code long[]} associated with the given key, or {@code null} if no value is set
@@ -580,14 +575,17 @@ public class GenericDocument {
private boolean mBuilt = false;
/**
- * Create a new {@link GenericDocument.Builder}.
+ * Creates a new {@link GenericDocument.Builder}.
+ *
+ * <p>Once {@link #build} is called, the instance can no longer be used.
*
- * @param uri The uri of {@link GenericDocument}.
- * @param schemaType The schema type of the {@link GenericDocument}. The passed-in {@code
- * schemaType} must be defined using {@link AppSearchSession#setSchema} prior to
- * inserting a document of this {@code schemaType} into the AppSearch index using {@link
- * AppSearchSession#put}. Otherwise, the document will be rejected by {@link
- * AppSearchSession#put}.
+ * @param uri the URI to set for the {@link GenericDocument}.
+ * @param schemaType the {@link AppSearchSchema} type of the {@link GenericDocument}. The
+ * provided {@code schemaType} must be defined using {@link AppSearchSession#setSchema}
+ * prior to inserting a document of this {@code schemaType} into the AppSearch index
+ * using {@link AppSearchSession#put}. Otherwise, the document will
+ * be rejected by {@link AppSearchSession#put} with result code
+ * {@link AppSearchResult#RESULT_NOT_FOUND}.
*/
@SuppressWarnings("unchecked")
public Builder(@NonNull String uri, @NonNull String schemaType) {
@@ -606,15 +604,18 @@ public class GenericDocument {
}
/**
- * Sets the app-defined namespace this Document resides in. No special values are reserved
+ * Sets the app-defined namespace this document resides in. No special values are reserved
* or understood by the infrastructure.
*
* <p>URIs are unique within a namespace.
*
* <p>The number of namespaces per app should be kept small for efficiency reasons.
+ *
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setNamespace(@NonNull String namespace) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
mBundle.putString(GenericDocument.NAMESPACE_FIELD, namespace);
return mBuilderTypeInstance;
}
@@ -623,14 +624,15 @@ public class GenericDocument {
* Sets the score of the {@link GenericDocument}.
*
* <p>The score is a query-independent measure of the document's quality, relative to other
- * {@link GenericDocument}s of the same type.
+ * {@link GenericDocument} objects of the same {@link AppSearchSchema} type.
*
* <p>Results may be sorted by score using {@link SearchSpec.Builder#setRankingStrategy}.
* Documents with higher scores are considered better than documents with lower scores.
*
- * <p>Any nonnegative integer can be used a score.
+ * <p>Any non-negative integer can be used a score. By default, scores are set to 0.
*
- * @throws IllegalArgumentException If the provided value is negative.
+ * @param score any non-negative {@code int} representing the document's score.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setScore(@IntRange(from = 0, to = Integer.MAX_VALUE) int score) {
@@ -645,8 +647,11 @@ public class GenericDocument {
/**
* Sets the creation timestamp of the {@link GenericDocument}, in milliseconds.
*
- * <p>Should be set using a value obtained from the {@link System#currentTimeMillis} time
- * base.
+ * <p>This should be set using a value obtained from the {@link System#currentTimeMillis}
+ * time base.
+ *
+ * @param creationTimestampMillis a creation timestamp in milliseconds.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setCreationTimestampMillis(long creationTimestampMillis) {
@@ -657,17 +662,17 @@ public class GenericDocument {
}
/**
- * Sets the TTL (Time To Live) of the {@link GenericDocument}, in milliseconds.
+ * Sets the TTL (time-to-live) of the {@link GenericDocument}, in milliseconds.
*
* <p>The TTL is measured against {@link #getCreationTimestampMillis}. At the timestamp of
* {@code creationTimestampMillis + ttlMillis}, measured in the {@link
* System#currentTimeMillis} time base, the document will be auto-deleted.
*
* <p>The default value is 0, which means the document is permanent and won't be
- * auto-deleted until the app is uninstalled.
+ * auto-deleted until the app is uninstalled or {@link AppSearchSession#remove} is called.
*
- * @param ttlMillis A non-negative duration in milliseconds.
- * @throws IllegalArgumentException If the provided value is negative.
+ * @param ttlMillis a non-negative duration in milliseconds.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setTtlMillis(long ttlMillis) {
@@ -682,8 +687,11 @@ public class GenericDocument {
/**
* Sets one or multiple {@code String} values for a property, replacing its previous values.
*
- * @param key The key associated with the {@code values}.
- * @param values The {@code String} values of the property.
+ * @param key the key associated with the {@code values}.
+ * @param values the {@code String} values of the property.
+ * @throws IllegalArgumentException if no values are provided, if provided values exceed
+ * maximum repeated property length, or if a passed in {@code String} is {@code null}.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setPropertyString(@NonNull String key, @NonNull String... values) {
@@ -698,8 +706,11 @@ public class GenericDocument {
* Sets one or multiple {@code boolean} values for a property, replacing its previous
* values.
*
- * @param key The key associated with the {@code values}.
- * @param values The {@code boolean} values of the property.
+ * @param key the key associated with the {@code values}.
+ * @param values the {@code boolean} values of the property.
+ * @throws IllegalArgumentException if no values are provided or if values exceed maximum
+ * repeated property length.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setPropertyBoolean(@NonNull String key, @NonNull boolean... values) {
@@ -713,8 +724,11 @@ public class GenericDocument {
/**
* Sets one or multiple {@code long} values for a property, replacing its previous values.
*
- * @param key The key associated with the {@code values}.
- * @param values The {@code long} values of the property.
+ * @param key the key associated with the {@code values}.
+ * @param values the {@code long} values of the property.
+ * @throws IllegalArgumentException if no values are provided or if values exceed maximum
+ * repeated property length.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setPropertyLong(@NonNull String key, @NonNull long... values) {
@@ -728,8 +742,11 @@ public class GenericDocument {
/**
* Sets one or multiple {@code double} values for a property, replacing its previous values.
*
- * @param key The key associated with the {@code values}.
- * @param values The {@code double} values of the property.
+ * @param key the key associated with the {@code values}.
+ * @param values the {@code double} values of the property.
+ * @throws IllegalArgumentException if no values are provided or if values exceed maximum
+ * repeated property length.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setPropertyDouble(@NonNull String key, @NonNull double... values) {
@@ -743,8 +760,11 @@ public class GenericDocument {
/**
* Sets one or multiple {@code byte[]} for a property, replacing its previous values.
*
- * @param key The key associated with the {@code values}.
- * @param values The {@code byte[]} of the property.
+ * @param key the key associated with the {@code values}.
+ * @param values the {@code byte[]} of the property.
+ * @throws IllegalArgumentException if no values are provided, if provided values exceed
+ * maximum repeated property length, or if a passed in {@code byte[]} is {@code null}.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setPropertyBytes(@NonNull String key, @NonNull byte[]... values) {
@@ -759,8 +779,12 @@ public class GenericDocument {
* Sets one or multiple {@link GenericDocument} values for a property, replacing its
* previous values.
*
- * @param key The key associated with the {@code values}.
- * @param values The {@link GenericDocument} values of the property.
+ * @param key the key associated with the {@code values}.
+ * @param values the {@link GenericDocument} values of the property.
+ * @throws IllegalArgumentException if no values are provided, if provided values exceed if
+ * provided values exceed maximum repeated property length, or if a passed in {@link
+ * GenericDocument} is {@code null}.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public BuilderType setPropertyDocument(
@@ -853,7 +877,11 @@ public class GenericDocument {
}
}
- /** Builds the {@link GenericDocument} object. */
+ /**
+ * Builds the {@link GenericDocument} object.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public GenericDocument build() {
Preconditions.checkState(!mBuilt, "Builder has already been used");
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java
index 656608d82ad4..c927e3412cbc 100644
--- a/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java
+++ b/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java
@@ -31,7 +31,8 @@ import java.util.Map;
import java.util.Set;
/**
- * Encapsulates a request to retrieve documents by namespace and URI.
+ * Encapsulates a request to retrieve documents by namespace and URIs from the {@link
+ * AppSearchSession} database.
*
* @see AppSearchSession#getByUri
*/
@@ -56,13 +57,13 @@ public final class GetByUriRequest {
mTypePropertyPathsMap = Preconditions.checkNotNull(typePropertyPathsMap);
}
- /** Returns the namespace to get documents from. */
+ /** Returns the namespace attached to the request. */
@NonNull
public String getNamespace() {
return mNamespace;
}
- /** Returns the URIs to get from the namespace. */
+ /** Returns the set of URIs attached to the request. */
@NonNull
public Set<String> getUris() {
return Collections.unmodifiableSet(mUris);
@@ -100,7 +101,11 @@ public final class GetByUriRequest {
return mTypePropertyPathsMap;
}
- /** Builder for {@link GetByUriRequest} objects. */
+ /**
+ * Builder for {@link GetByUriRequest} objects.
+ *
+ * <p>Once {@link #build} is called, the instance can no longer be used.
+ */
public static final class Builder {
private String mNamespace = GenericDocument.DEFAULT_NAMESPACE;
private final Set<String> mUris = new ArraySet<>();
@@ -108,9 +113,12 @@ public final class GetByUriRequest {
private boolean mBuilt = false;
/**
- * Sets which namespace these documents will be retrieved from.
+ * Sets the namespace to retrieve documents for.
+ *
+ * <p>If this is not called, the namespace defaults to {@link
+ * GenericDocument#DEFAULT_NAMESPACE}.
*
- * <p>If this is not set, it defaults to {@link GenericDocument#DEFAULT_NAMESPACE}.
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public Builder setNamespace(@NonNull String namespace) {
@@ -120,14 +128,22 @@ public final class GetByUriRequest {
return this;
}
- /** Adds one or more URIs to the request. */
+ /**
+ * Adds one or more URIs to the request.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public Builder addUris(@NonNull String... uris) {
Preconditions.checkNotNull(uris);
return addUris(Arrays.asList(uris));
}
- /** Adds one or more URIs to the request. */
+ /**
+ * Adds a collection of URIs to the request.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public Builder addUris(@NonNull Collection<String> uris) {
Preconditions.checkState(!mBuilt, "Builder has already been used");
@@ -149,7 +165,8 @@ public final class GetByUriRequest {
* GetByUriRequest#PROJECTION_SCHEMA_TYPE_WILDCARD}, then those property paths will apply to
* all results, excepting any types that have their own, specific property paths set.
*
- * <p>{@see SearchSpec.Builder#addProjection(String, String...)}
+ * @throws IllegalStateException if the builder has already been used.
+ * <p>{@see SearchSpec.Builder#addProjection(String, String...)}
*/
@NonNull
public Builder addProjection(@NonNull String schemaType, @NonNull String... propertyPaths) {
@@ -170,7 +187,8 @@ public final class GetByUriRequest {
* GetByUriRequest#PROJECTION_SCHEMA_TYPE_WILDCARD}, then those property paths will apply to
* all results, excepting any types that have their own, specific property paths set.
*
- * <p>{@see SearchSpec.Builder#addProjection(String, String...)}
+ * @throws IllegalStateException if the builder has already been used.
+ * <p>{@see SearchSpec.Builder#addProjection(String, String...)}
*/
@NonNull
public Builder addProjection(
@@ -187,7 +205,11 @@ public final class GetByUriRequest {
return this;
}
- /** Builds a new {@link GetByUriRequest}. */
+ /**
+ * Builds a new {@link GetByUriRequest}.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public GetByUriRequest build() {
Preconditions.checkState(!mBuilt, "Builder has already been used");
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java
index 198eee85be53..39b53b604abb 100644
--- a/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java
+++ b/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java
@@ -27,7 +27,8 @@ import java.util.Collections;
import java.util.Set;
/**
- * Encapsulates a request to remove documents by namespace and URI.
+ * Encapsulates a request to remove documents by namespace and URIs from the {@link
+ * AppSearchSession} database.
*
* @see AppSearchSession#remove
*/
@@ -46,22 +47,28 @@ public final class RemoveByUriRequest {
return mNamespace;
}
- /** Returns the URIs of documents to remove from the namespace. */
+ /** Returns the set of URIs attached to the request. */
@NonNull
public Set<String> getUris() {
return Collections.unmodifiableSet(mUris);
}
- /** Builder for {@link RemoveByUriRequest} objects. */
+ /**
+ * Builder for {@link RemoveByUriRequest} objects.
+ *
+ * <p>Once {@link #build} is called, the instance can no longer be used.
+ */
public static final class Builder {
private String mNamespace = GenericDocument.DEFAULT_NAMESPACE;
private final Set<String> mUris = new ArraySet<>();
private boolean mBuilt = false;
/**
- * Sets which namespace these documents will be removed from.
+ * Sets the namespace to remove documents for.
*
* <p>If this is not set, it defaults to {@link GenericDocument#DEFAULT_NAMESPACE}.
+ *
+ * @throws IllegalStateException if the builder has already been used.
*/
@NonNull
public Builder setNamespace(@NonNull String namespace) {
@@ -71,14 +78,22 @@ public final class RemoveByUriRequest {
return this;
}
- /** Adds one or more URIs to the request. */
+ /**
+ * Adds one or more URIs to the request.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public Builder addUris(@NonNull String... uris) {
Preconditions.checkNotNull(uris);
return addUris(Arrays.asList(uris));
}
- /** Adds one or more URIs to the request. */
+ /**
+ * Adds a collection of URIs to the request.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public Builder addUris(@NonNull Collection<String> uris) {
Preconditions.checkState(!mBuilt, "Builder has already been used");
@@ -87,7 +102,11 @@ public final class RemoveByUriRequest {
return this;
}
- /** Builds a new {@link RemoveByUriRequest}. */
+ /**
+ * Builds a new {@link RemoveByUriRequest}.
+ *
+ * @throws IllegalStateException if the builder has already been used.
+ */
@NonNull
public RemoveByUriRequest build() {
Preconditions.checkState(!mBuilt, "Builder has already been used");
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java b/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java
index 4869aa38b5fd..bc99d4f67d86 100644
--- a/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java
+++ b/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java
@@ -16,10 +16,9 @@
package android.app.appsearch;
-import static android.app.appsearch.AppSearchResult.RESULT_OK;
-
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.os.Bundle;
import android.util.ArraySet;
import com.android.internal.util.Preconditions;
@@ -32,23 +31,58 @@ import java.util.Set;
/** The response class of {@link AppSearchSession#setSchema} */
public class SetSchemaResponse {
+
+ private static final String DELETED_TYPES_FIELD = "deletedTypes";
+ private static final String INCOMPATIBLE_TYPES_FIELD = "incompatibleTypes";
+ private static final String MIGRATED_TYPES_FIELD = "migratedTypes";
+
+ private final Bundle mBundle;
+ /**
+ * The migrationFailures won't be saved in the bundle. Since:
+ *
+ * <ul>
+ * <li>{@link MigrationFailure} is generated in {@link AppSearchSession} which will be the SDK
+ * side in platform. We don't need to pass it from service side via binder.
+ * <li>Translate multiple {@link MigrationFailure}s to bundles in {@link Builder} and then
+ * back in constructor will be a huge waste.
+ * </ul>
+ */
private final List<MigrationFailure> mMigrationFailures;
- private final Set<String> mDeletedTypes;
- private final Set<String> mMigratedTypes;
- private final Set<String> mIncompatibleTypes;
- private final @AppSearchResult.ResultCode int mResultCode;
-
- SetSchemaResponse(
- @NonNull List<MigrationFailure> migrationFailures,
- @NonNull Set<String> deletedTypes,
- @NonNull Set<String> migratedTypes,
- @NonNull Set<String> incompatibleTypes,
- @AppSearchResult.ResultCode int resultCode) {
+
+ /** Cache of the inflated deleted schema types. Comes from inflating mBundles at first use. */
+ @Nullable private Set<String> mDeletedTypes;
+
+ /** Cache of the inflated migrated schema types. Comes from inflating mBundles at first use. */
+ @Nullable private Set<String> mMigratedTypes;
+
+ /**
+ * Cache of the inflated incompatible schema types. Comes from inflating mBundles at first use.
+ */
+ @Nullable private Set<String> mIncompatibleTypes;
+
+ SetSchemaResponse(@NonNull Bundle bundle, @NonNull List<MigrationFailure> migrationFailures) {
+ mBundle = Preconditions.checkNotNull(bundle);
mMigrationFailures = Preconditions.checkNotNull(migrationFailures);
- mDeletedTypes = Preconditions.checkNotNull(deletedTypes);
- mMigratedTypes = Preconditions.checkNotNull(migratedTypes);
- mIncompatibleTypes = Preconditions.checkNotNull(incompatibleTypes);
- mResultCode = resultCode;
+ }
+
+ SetSchemaResponse(@NonNull Bundle bundle) {
+ this(bundle, /*migrationFailures=*/ Collections.emptyList());
+ }
+
+ /**
+ * Returns the {@link Bundle} populated by this builder.
+ *
+ * @hide
+ */
+ @NonNull
+ public Bundle getBundle() {
+ return mBundle;
+ }
+
+ /** TODO(b/177266929): Remove this deprecated method */
+ //@Deprecated
+ public boolean isSuccess() {
+ return true;
}
/**
@@ -72,6 +106,12 @@ public class SetSchemaResponse {
*/
@NonNull
public Set<String> getDeletedTypes() {
+ if (mDeletedTypes == null) {
+ mDeletedTypes =
+ new ArraySet<>(
+ Preconditions.checkNotNull(
+ mBundle.getStringArrayList(DELETED_TYPES_FIELD)));
+ }
return Collections.unmodifiableSet(mDeletedTypes);
}
@@ -81,6 +121,12 @@ public class SetSchemaResponse {
*/
@NonNull
public Set<String> getMigratedTypes() {
+ if (mMigratedTypes == null) {
+ mMigratedTypes =
+ new ArraySet<>(
+ Preconditions.checkNotNull(
+ mBundle.getStringArrayList(MIGRATED_TYPES_FIELD)));
+ }
return Collections.unmodifiableSet(mMigratedTypes);
}
@@ -96,22 +142,28 @@ public class SetSchemaResponse {
*/
@NonNull
public Set<String> getIncompatibleTypes() {
+ if (mIncompatibleTypes == null) {
+ mIncompatibleTypes =
+ new ArraySet<>(
+ Preconditions.checkNotNull(
+ mBundle.getStringArrayList(INCOMPATIBLE_TYPES_FIELD)));
+ }
return Collections.unmodifiableSet(mIncompatibleTypes);
}
- /** Returns {@code true} if all {@link AppSearchSchema}s are successful set to the system. */
- public boolean isSuccess() {
- return mResultCode == RESULT_OK;
- }
-
- @Override
+ /**
+ * Translates the {@link SetSchemaResponse}'s bundle to {@link Builder}.
+ *
+ * @hide
+ */
@NonNull
- public String toString() {
- return "{\n Does setSchema success? : "
- + isSuccess()
- + "\n failures: "
- + mMigrationFailures
- + "\n}";
+ // TODO(b/179302942) change to Builder(mBundle) powered by mBundle.deepCopy
+ public Builder toBuilder() {
+ return new Builder()
+ .addDeletedTypes(getDeletedTypes())
+ .addIncompatibleTypes(getIncompatibleTypes())
+ .addMigratedTypes(getMigratedTypes())
+ .addMigrationFailures(mMigrationFailures);
}
/**
@@ -120,44 +172,26 @@ public class SetSchemaResponse {
* @hide
*/
public static class Builder {
- private final List<MigrationFailure> mMigrationFailures = new ArrayList<>();
- private final Set<String> mDeletedTypes = new ArraySet<>();
- private final Set<String> mMigratedTypes = new ArraySet<>();
- private final Set<String> mIncompatibleTypes = new ArraySet<>();
- private @AppSearchResult.ResultCode int mResultCode = RESULT_OK;
+ private final ArrayList<MigrationFailure> mMigrationFailures = new ArrayList<>();
+ private final ArrayList<String> mDeletedTypes = new ArrayList<>();
+ private final ArrayList<String> mMigratedTypes = new ArrayList<>();
+ private final ArrayList<String> mIncompatibleTypes = new ArrayList<>();
private boolean mBuilt = false;
- /** Adds a {@link MigrationFailure}. */
+ /** Adds {@link MigrationFailure}s to the list of migration failures. */
@NonNull
- public Builder setFailure(
- @NonNull String schemaType,
- @NonNull String namespace,
- @NonNull String uri,
- @NonNull AppSearchResult<Void> failureResult) {
+ public Builder addMigrationFailures(
+ @NonNull Collection<MigrationFailure> migrationFailures) {
Preconditions.checkState(!mBuilt, "Builder has already been used");
- Preconditions.checkNotNull(schemaType);
- Preconditions.checkNotNull(namespace);
- Preconditions.checkNotNull(uri);
- Preconditions.checkNotNull(failureResult);
- Preconditions.checkState(!failureResult.isSuccess());
- mMigrationFailures.add(new MigrationFailure(schemaType, namespace, uri, failureResult));
+ mMigrationFailures.addAll(Preconditions.checkNotNull(migrationFailures));
return this;
}
- /** Adds a {@link MigrationFailure}. */
+ /** Adds a {@link MigrationFailure} to the list of migration failures. */
@NonNull
- public Builder setFailure(
- @NonNull String schemaType,
- @NonNull String namespace,
- @NonNull String uri,
- @AppSearchResult.ResultCode int resultCode,
- @Nullable String errorMessage) {
- mMigrationFailures.add(
- new MigrationFailure(
- schemaType,
- namespace,
- uri,
- AppSearchResult.newFailedResult(resultCode, errorMessage)));
+ public Builder addMigrationFailure(@NonNull MigrationFailure migrationFailure) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mMigrationFailures.add(Preconditions.checkNotNull(migrationFailure));
return this;
}
@@ -169,6 +203,14 @@ public class SetSchemaResponse {
return this;
}
+ /** Adds one deletedType to the list of deleted schema types. */
+ @NonNull
+ public Builder addDeletedType(@NonNull String deletedType) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mDeletedTypes.add(Preconditions.checkNotNull(deletedType));
+ return this;
+ }
+
/** Adds incompatibleTypes to the list of incompatible schema types. */
@NonNull
public Builder addIncompatibleTypes(@NonNull Collection<String> incompatibleTypes) {
@@ -177,6 +219,14 @@ public class SetSchemaResponse {
return this;
}
+ /** Adds one incompatibleType to the list of incompatible schema types. */
+ @NonNull
+ public Builder addIncompatibleType(@NonNull String incompatibleType) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mIncompatibleTypes.add(Preconditions.checkNotNull(incompatibleType));
+ return this;
+ }
+
/** Adds migratedTypes to the list of migrated schema types. */
@NonNull
public Builder addMigratedTypes(@NonNull Collection<String> migratedTypes) {
@@ -185,11 +235,11 @@ public class SetSchemaResponse {
return this;
}
- /** Sets the {@link AppSearchResult.ResultCode} of the response. */
+ /** Adds one migratedType to the list of migrated schema types. */
@NonNull
- public Builder setResultCode(@AppSearchResult.ResultCode int resultCode) {
+ public Builder addMigratedType(@NonNull String migratedType) {
Preconditions.checkState(!mBuilt, "Builder has already been used");
- mResultCode = resultCode;
+ mMigratedTypes.add(Preconditions.checkNotNull(migratedType));
return this;
}
@@ -197,13 +247,15 @@ public class SetSchemaResponse {
@NonNull
public SetSchemaResponse build() {
Preconditions.checkState(!mBuilt, "Builder has already been used");
+ Bundle bundle = new Bundle();
+ bundle.putStringArrayList(INCOMPATIBLE_TYPES_FIELD, mIncompatibleTypes);
+ bundle.putStringArrayList(DELETED_TYPES_FIELD, mDeletedTypes);
+ bundle.putStringArrayList(MIGRATED_TYPES_FIELD, mMigratedTypes);
mBuilt = true;
- return new SetSchemaResponse(
- mMigrationFailures,
- mDeletedTypes,
- mMigratedTypes,
- mIncompatibleTypes,
- mResultCode);
+ // Avoid converting the potential thousands of MigrationFailures to Pracelable and
+ // back just for put in bundle. In platform, we should set MigrationFailures in
+ // AppSearchSession after we pass SetSchemaResponse via binder.
+ return new SetSchemaResponse(bundle, mMigrationFailures);
}
}
@@ -212,38 +264,44 @@ public class SetSchemaResponse {
* {@link AppSearchSession#setSchema}.
*/
public static class MigrationFailure {
- private final String mSchemaType;
- private final String mNamespace;
- private final String mUri;
- AppSearchResult<Void> mFailureResult;
-
- MigrationFailure(
- @NonNull String schemaType,
- @NonNull String namespace,
- @NonNull String uri,
- @NonNull AppSearchResult<Void> result) {
- mSchemaType = schemaType;
- mNamespace = namespace;
- mUri = uri;
- mFailureResult = result;
+ private static final String SCHEMA_TYPE_FIELD = "schemaType";
+ private static final String NAMESPACE_FIELD = "namespace";
+ private static final String URI_FIELD = "uri";
+ private static final String ERROR_MESSAGE_FIELD = "errorMessage";
+ private static final String RESULT_CODE_FIELD = "resultCode";
+
+ private final Bundle mBundle;
+
+ MigrationFailure(@NonNull Bundle bundle) {
+ mBundle = bundle;
+ }
+
+ /**
+ * Returns the Bundle of the {@link MigrationFailure}.
+ *
+ * @hide
+ */
+ @NonNull
+ public Bundle getBundle() {
+ return mBundle;
}
/** Returns the schema type of the {@link GenericDocument} that fails to be migrated. */
@NonNull
public String getSchemaType() {
- return mSchemaType;
+ return mBundle.getString(SCHEMA_TYPE_FIELD, /*defaultValue=*/ "");
}
/** Returns the namespace of the {@link GenericDocument} that fails to be migrated. */
@NonNull
public String getNamespace() {
- return mNamespace;
+ return mBundle.getString(NAMESPACE_FIELD, /*defaultValue=*/ "");
}
/** Returns the uri of the {@link GenericDocument} that fails to be migrated. */
@NonNull
public String getUri() {
- return mUri;
+ return mBundle.getString(URI_FIELD, /*defaultValue=*/ "");
}
/**
@@ -252,7 +310,69 @@ public class SetSchemaResponse {
*/
@NonNull
public AppSearchResult<Void> getAppSearchResult() {
- return mFailureResult;
+ return AppSearchResult.newFailedResult(
+ mBundle.getInt(RESULT_CODE_FIELD),
+ mBundle.getString(ERROR_MESSAGE_FIELD, /*defaultValue=*/ ""));
+ }
+
+ /**
+ * Builder for {@link MigrationFailure} objects.
+ *
+ * @hide
+ */
+ public static class Builder {
+ private String mSchemaType;
+ private String mNamespace;
+ private String mUri;
+ private final Bundle mBundle = new Bundle();
+ private AppSearchResult<Void> mFailureResult;
+ private boolean mBuilt = false;
+
+ /** Sets the schema type for the {@link MigrationFailure}. */
+ @NonNull
+ public Builder setSchemaType(@NonNull String schemaType) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mSchemaType = Preconditions.checkNotNull(schemaType);
+ return this;
+ }
+
+ /** Sets the namespace for the {@link MigrationFailure}. */
+ @NonNull
+ public Builder setNamespace(@NonNull String namespace) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mNamespace = Preconditions.checkNotNull(namespace);
+ return this;
+ }
+
+ /** Sets the uri for the {@link MigrationFailure}. */
+ @NonNull
+ public Builder setUri(@NonNull String uri) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mUri = Preconditions.checkNotNull(uri);
+ return this;
+ }
+
+ /** Sets the failure {@link AppSearchResult} for the {@link MigrationFailure}. */
+ @NonNull
+ public Builder setAppSearchResult(@NonNull AppSearchResult<Void> appSearchResult) {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ Preconditions.checkState(!appSearchResult.isSuccess(), "Input a success result");
+ mFailureResult = Preconditions.checkNotNull(appSearchResult);
+ return this;
+ }
+
+ /** Builds a {@link MigrationFailure} object. */
+ @NonNull
+ public MigrationFailure build() {
+ Preconditions.checkState(!mBuilt, "Builder has already been used");
+ mBundle.putString(SCHEMA_TYPE_FIELD, mSchemaType);
+ mBundle.putString(NAMESPACE_FIELD, mNamespace);
+ mBundle.putString(URI_FIELD, mUri);
+ mBundle.putString(ERROR_MESSAGE_FIELD, mFailureResult.getErrorMessage());
+ mBundle.putInt(RESULT_CODE_FIELD, mFailureResult.getResultCode());
+ mBuilt = true;
+ return new MigrationFailure(mBundle);
+ }
}
}
}
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResult.java b/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResult.java
deleted file mode 100644
index f04ace684839..000000000000
--- a/apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResult.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 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.
- */
-
-package android.app.appsearch;
-
-import android.annotation.NonNull;
-import android.os.Bundle;
-
-import com.android.internal.util.Preconditions;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * This class represents the results of setSchema().
- *
- * @hide
- */
-public class SetSchemaResult {
-
- public static final String DELETED_SCHEMA_TYPES_FIELD = "deletedSchemaTypes";
- public static final String INCOMPATIBLE_SCHEMA_TYPES_FIELD = "incompatibleSchemaTypes";
- public static final String RESULT_CODE_FIELD = "resultCode";
- private final List<String> mDeletedSchemaTypes;
- private final List<String> mIncompatibleSchemaTypes;
- private final Bundle mBundle;
-
- SetSchemaResult(@NonNull Bundle bundle) {
- mBundle = Preconditions.checkNotNull(bundle);
- mDeletedSchemaTypes =
- Preconditions.checkNotNull(mBundle.getStringArrayList(DELETED_SCHEMA_TYPES_FIELD));
- mIncompatibleSchemaTypes =
- Preconditions.checkNotNull(
- mBundle.getStringArrayList(INCOMPATIBLE_SCHEMA_TYPES_FIELD));
- }
-
- /** Returns the {@link Bundle} of this class. */
- @NonNull
- public Bundle getBundle() {
- return mBundle;
- }
-
- /** returns all deleted schema types in this setSchema call. */
- @NonNull
- public List<String> getDeletedSchemaTypes() {
- return Collections.unmodifiableList(mDeletedSchemaTypes);
- }
-
- /** returns all incompatible schema types in this setSchema call. */
- @NonNull
- public List<String> getIncompatibleSchemaTypes() {
- return Collections.unmodifiableList(mIncompatibleSchemaTypes);
- }
-
- /**
- * returns the {@link android.app.appsearch.AppSearchResult.ResultCode} of the {@link
- * AppSearchSession#setSchema} call.
- */
- public int getResultCode() {
- return mBundle.getInt(RESULT_CODE_FIELD);
- }
-
- /** Builder for {@link SetSchemaResult} objects. */
- public static final class Builder {
- private final ArrayList<String> mDeletedSchemaTypes = new ArrayList<>();
- private final ArrayList<String> mIncompatibleSchemaTypes = new ArrayList<>();
- @AppSearchResult.ResultCode private int mResultCode;
- private boolean mBuilt = false;
-
- /** Adds a deletedSchemaTypes to the {@link SetSchemaResult}. */
- @NonNull
- public Builder addDeletedSchemaType(@NonNull String deletedSchemaType) {
- Preconditions.checkState(!mBuilt, "Builder has already been used");
- mDeletedSchemaTypes.add(Preconditions.checkNotNull(deletedSchemaType));
- return this;
- }
-
- /** Adds a incompatible SchemaTypes to the {@link SetSchemaResult}. */
- @NonNull
- public Builder addIncompatibleSchemaType(@NonNull String incompatibleSchemaTypes) {
- Preconditions.checkState(!mBuilt, "Builder has already been used");
- mIncompatibleSchemaTypes.add(Preconditions.checkNotNull(incompatibleSchemaTypes));
- return this;
- }
-
- /**
- * Sets the {@link android.app.appsearch.AppSearchResult.ResultCode} of the {@link
- * AppSearchSession#setSchema} call to the {@link SetSchemaResult}
- */
- @NonNull
- public Builder setResultCode(@AppSearchResult.ResultCode int resultCode) {
- Preconditions.checkState(!mBuilt, "Builder has already been used");
- mResultCode = resultCode;
- return this;
- }
-
- /** Builds a {@link SetSchemaResult}. */
- @NonNull
- public SetSchemaResult build() {
- Preconditions.checkState(!mBuilt, "Builder has already been used");
- Bundle bundle = new Bundle();
- bundle.putStringArrayList(
- SetSchemaResult.DELETED_SCHEMA_TYPES_FIELD, mDeletedSchemaTypes);
- bundle.putStringArrayList(
- SetSchemaResult.INCOMPATIBLE_SCHEMA_TYPES_FIELD, mIncompatibleSchemaTypes);
- bundle.putInt(RESULT_CODE_FIELD, mResultCode);
- mBuilt = true;
- return new SetSchemaResult(bundle);
- }
- }
-}
diff --git a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
index 2f1817ec82a7..6c2e30e98877 100644
--- a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
+++ b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
@@ -25,7 +25,7 @@ import android.app.appsearch.GetByUriRequest;
import android.app.appsearch.PackageIdentifier;
import android.app.appsearch.SearchResultPage;
import android.app.appsearch.SearchSpec;
-import android.app.appsearch.SetSchemaResult;
+import android.app.appsearch.SetSchemaResponse;
import android.app.appsearch.exceptions.AppSearchException;
import android.content.Context;
import android.os.Bundle;
@@ -41,7 +41,7 @@ import com.android.server.appsearch.external.localstorage.converter.ResultCodeTo
import com.android.server.appsearch.external.localstorage.converter.SchemaToProtoConverter;
import com.android.server.appsearch.external.localstorage.converter.SearchResultToProtoConverter;
import com.android.server.appsearch.external.localstorage.converter.SearchSpecToProtoConverter;
-import com.android.server.appsearch.external.localstorage.converter.SetSchemaResultToProtoConverter;
+import com.android.server.appsearch.external.localstorage.converter.SetSchemaResponseToProtoConverter;
import com.android.server.appsearch.external.localstorage.converter.TypePropertyPathToProtoConverter;
import com.google.android.icing.IcingSearchEngine;
@@ -73,6 +73,7 @@ import com.google.android.icing.proto.StatusProto;
import com.google.android.icing.proto.TypePropertyMask;
import com.google.android.icing.proto.UsageReport;
+import java.io.Closeable;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -119,7 +120,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* @hide
*/
@WorkerThread
-public final class AppSearchImpl {
+public final class AppSearchImpl implements Closeable {
private static final String TAG = "AppSearchImpl";
@VisibleForTesting static final char DATABASE_DELIMITER = '/';
@@ -151,12 +152,16 @@ public final class AppSearchImpl {
private final Map<String, Set<String>> mNamespaceMapLocked = new HashMap<>();
/**
- * The counter to check when to call {@link #checkForOptimizeLocked(boolean)}. The interval is
- * {@link #CHECK_OPTIMIZE_INTERVAL}.
+ * The counter to check when to call {@link #checkForOptimize}. The interval is {@link
+ * #CHECK_OPTIMIZE_INTERVAL}.
*/
@GuardedBy("mReadWriteLock")
private int mOptimizeIntervalCountLocked = 0;
+ /** Whether this instance has been closed, and therefore unusable. */
+ @GuardedBy("mReadWriteLock")
+ private boolean mClosedLocked = false;
+
/**
* Creates and initializes an instance of {@link AppSearchImpl} which writes data to the given
* folder.
@@ -208,7 +213,7 @@ public final class AppSearchImpl {
} catch (AppSearchException e) {
Log.w(TAG, "Error initializing, resetting IcingSearchEngine.", e);
// Some error. Reset and see if it fixes it.
- reset();
+ resetLocked();
return;
}
@@ -222,11 +227,6 @@ public final class AppSearchImpl {
for (String prefixedNamespace : getAllNamespacesResultProto.getNamespacesList()) {
addToMap(mNamespaceMapLocked, getPrefix(prefixedNamespace), prefixedNamespace);
}
-
- // TODO(b/155939114): It's possible to optimize after init, which would reduce the time
- // to when we're able to serve queries. Consider moving this optimize call out.
- checkForOptimizeLocked(/* force= */ true);
-
} finally {
mReadWriteLock.writeLock().unlock();
}
@@ -240,12 +240,45 @@ public final class AppSearchImpl {
void initializeVisibilityStore() throws AppSearchException {
mReadWriteLock.writeLock().lock();
try {
+ throwIfClosedLocked();
+
mVisibilityStoreLocked.initialize();
} finally {
mReadWriteLock.writeLock().unlock();
}
}
+ @GuardedBy("mReadWriteLock")
+ private void throwIfClosedLocked() {
+ if (mClosedLocked) {
+ throw new IllegalStateException("Trying to use a closed AppSearchImpl instance.");
+ }
+ }
+
+ /**
+ * Persists data to disk and closes the instance.
+ *
+ * <p>This instance is no longer usable after it's been closed. Call {@link #create} to create a
+ * new, usable instance.
+ */
+ @Override
+ public void close() {
+ mReadWriteLock.writeLock().lock();
+ try {
+ if (mClosedLocked) {
+ return;
+ }
+
+ persistToDisk();
+ mIcingSearchEngineLocked.close();
+ mClosedLocked = true;
+ } catch (AppSearchException e) {
+ Log.w(TAG, "Error when closing AppSearchImpl.", e);
+ } finally {
+ mReadWriteLock.writeLock().unlock();
+ }
+ }
+
/**
* Updates the AppSearch schema for this app.
*
@@ -259,10 +292,14 @@ public final class AppSearchImpl {
* @param schemasPackageAccessible Schema types that are visible to the specified packages.
* @param forceOverride Whether to force-apply the schema even if it is incompatible. Documents
* which do not comply with the new schema will be deleted.
- * @throws AppSearchException on IcingSearchEngine error.
+ * @throws AppSearchException On IcingSearchEngine error. If the status code is
+ * FAILED_PRECONDITION for the incompatible change, the exception will be converted to the
+ * SetSchemaResponse.
+ * @return The response contains deleted schema types and incompatible schema types of this
+ * call.
*/
@NonNull
- public SetSchemaResult setSchema(
+ public SetSchemaResponse setSchema(
@NonNull String packageName,
@NonNull String databaseName,
@NonNull List<AppSearchSchema> schemas,
@@ -272,6 +309,8 @@ public final class AppSearchImpl {
throws AppSearchException {
mReadWriteLock.writeLock().lock();
try {
+ throwIfClosedLocked();
+
SchemaProto.Builder existingSchemaBuilder = getSchemaProtoLocked().toBuilder();
SchemaProto.Builder newSchemaBuilder = SchemaProto.newBuilder();
@@ -297,9 +336,16 @@ public final class AppSearchImpl {
try {
checkSuccess(setSchemaResultProto.getStatus());
} catch (AppSearchException e) {
- if (setSchemaResultProto.getDeletedSchemaTypesCount() > 0
- || setSchemaResultProto.getIncompatibleSchemaTypesCount() > 0) {
- return SetSchemaResultToProtoConverter.toSetSchemaResult(
+ // Swallow the exception for the incompatible change case. We will propagate
+ // those deleted schemas and incompatible types to the SetSchemaResponse.
+ boolean isFailedPrecondition =
+ setSchemaResultProto.getStatus().getCode()
+ == StatusProto.Code.FAILED_PRECONDITION;
+ boolean isIncompatible =
+ setSchemaResultProto.getDeletedSchemaTypesCount() > 0
+ || setSchemaResultProto.getIncompatibleSchemaTypesCount() > 0;
+ if (isFailedPrecondition && isIncompatible) {
+ return SetSchemaResponseToProtoConverter.toSetSchemaResponse(
setSchemaResultProto, prefix);
} else {
throw e;
@@ -328,16 +374,8 @@ public final class AppSearchImpl {
prefixedSchemasNotPlatformSurfaceable,
prefixedSchemasPackageAccessible);
- // Determine whether to schedule an immediate optimize.
- if (setSchemaResultProto.getDeletedSchemaTypesCount() > 0
- || (setSchemaResultProto.getIncompatibleSchemaTypesCount() > 0
- && forceOverride)) {
- // Any existing schemas which is not in 'schemas' will be deleted, and all
- // documents of these types were also deleted. And so well if we force override
- // incompatible schemas.
- checkForOptimizeLocked(/* force= */ true);
- }
- return SetSchemaResultToProtoConverter.toSetSchemaResult(setSchemaResultProto, prefix);
+ return SetSchemaResponseToProtoConverter.toSetSchemaResponse(
+ setSchemaResultProto, prefix);
} finally {
mReadWriteLock.writeLock().unlock();
}
@@ -355,44 +393,47 @@ public final class AppSearchImpl {
@NonNull
public List<AppSearchSchema> getSchema(
@NonNull String packageName, @NonNull String databaseName) throws AppSearchException {
- SchemaProto fullSchema;
mReadWriteLock.readLock().lock();
try {
- fullSchema = getSchemaProtoLocked();
- } finally {
- mReadWriteLock.readLock().unlock();
- }
+ throwIfClosedLocked();
- String prefix = createPrefix(packageName, databaseName);
- List<AppSearchSchema> result = new ArrayList<>();
- for (int i = 0; i < fullSchema.getTypesCount(); i++) {
- String typePrefix = getPrefix(fullSchema.getTypes(i).getSchemaType());
- if (!prefix.equals(typePrefix)) {
- continue;
- }
- // Rewrite SchemaProto.types.schema_type
- SchemaTypeConfigProto.Builder typeConfigBuilder = fullSchema.getTypes(i).toBuilder();
- String newSchemaType = typeConfigBuilder.getSchemaType().substring(prefix.length());
- typeConfigBuilder.setSchemaType(newSchemaType);
+ SchemaProto fullSchema = getSchemaProtoLocked();
- // Rewrite SchemaProto.types.properties.schema_type
- for (int propertyIdx = 0;
- propertyIdx < typeConfigBuilder.getPropertiesCount();
- propertyIdx++) {
- PropertyConfigProto.Builder propertyConfigBuilder =
- typeConfigBuilder.getProperties(propertyIdx).toBuilder();
- if (!propertyConfigBuilder.getSchemaType().isEmpty()) {
- String newPropertySchemaType =
- propertyConfigBuilder.getSchemaType().substring(prefix.length());
- propertyConfigBuilder.setSchemaType(newPropertySchemaType);
- typeConfigBuilder.setProperties(propertyIdx, propertyConfigBuilder);
+ String prefix = createPrefix(packageName, databaseName);
+ List<AppSearchSchema> result = new ArrayList<>();
+ for (int i = 0; i < fullSchema.getTypesCount(); i++) {
+ String typePrefix = getPrefix(fullSchema.getTypes(i).getSchemaType());
+ if (!prefix.equals(typePrefix)) {
+ continue;
+ }
+ // Rewrite SchemaProto.types.schema_type
+ SchemaTypeConfigProto.Builder typeConfigBuilder =
+ fullSchema.getTypes(i).toBuilder();
+ String newSchemaType = typeConfigBuilder.getSchemaType().substring(prefix.length());
+ typeConfigBuilder.setSchemaType(newSchemaType);
+
+ // Rewrite SchemaProto.types.properties.schema_type
+ for (int propertyIdx = 0;
+ propertyIdx < typeConfigBuilder.getPropertiesCount();
+ propertyIdx++) {
+ PropertyConfigProto.Builder propertyConfigBuilder =
+ typeConfigBuilder.getProperties(propertyIdx).toBuilder();
+ if (!propertyConfigBuilder.getSchemaType().isEmpty()) {
+ String newPropertySchemaType =
+ propertyConfigBuilder.getSchemaType().substring(prefix.length());
+ propertyConfigBuilder.setSchemaType(newPropertySchemaType);
+ typeConfigBuilder.setProperties(propertyIdx, propertyConfigBuilder);
+ }
}
- }
- AppSearchSchema schema = SchemaToProtoConverter.toAppSearchSchema(typeConfigBuilder);
- result.add(schema);
+ AppSearchSchema schema =
+ SchemaToProtoConverter.toAppSearchSchema(typeConfigBuilder);
+ result.add(schema);
+ }
+ return result;
+ } finally {
+ mReadWriteLock.readLock().unlock();
}
- return result;
}
/**
@@ -410,23 +451,22 @@ public final class AppSearchImpl {
@NonNull String databaseName,
@NonNull GenericDocument document)
throws AppSearchException {
- DocumentProto.Builder documentBuilder =
- GenericDocumentToProtoConverter.toDocumentProto(document).toBuilder();
- String prefix = createPrefix(packageName, databaseName);
- addPrefixToDocument(documentBuilder, prefix);
-
- PutResultProto putResultProto;
mReadWriteLock.writeLock().lock();
try {
- putResultProto = mIcingSearchEngineLocked.put(documentBuilder.build());
+ throwIfClosedLocked();
+
+ DocumentProto.Builder documentBuilder =
+ GenericDocumentToProtoConverter.toDocumentProto(document).toBuilder();
+ String prefix = createPrefix(packageName, databaseName);
+ addPrefixToDocument(documentBuilder, prefix);
+
+ PutResultProto putResultProto = mIcingSearchEngineLocked.put(documentBuilder.build());
addToMap(mNamespaceMapLocked, prefix, documentBuilder.getNamespace());
- // The existing documents with same URI will be deleted, so there maybe some resources
- // could be released after optimize().
- checkForOptimizeLocked(/* force= */ false);
+
+ checkSuccess(putResultProto.getStatus());
} finally {
mReadWriteLock.writeLock().unlock();
}
- checkSuccess(putResultProto.getStatus());
}
/**
@@ -451,40 +491,42 @@ public final class AppSearchImpl {
@NonNull String uri,
@NonNull Map<String, List<String>> typePropertyPaths)
throws AppSearchException {
- GetResultProto getResultProto;
- List<TypePropertyMask> nonPrefixedPropertyMasks =
- TypePropertyPathToProtoConverter.toTypePropertyMaskList(typePropertyPaths);
- List<TypePropertyMask> prefixedPropertyMasks =
- new ArrayList<>(nonPrefixedPropertyMasks.size());
- for (int i = 0; i < nonPrefixedPropertyMasks.size(); ++i) {
- TypePropertyMask typePropertyMask = nonPrefixedPropertyMasks.get(i);
- String nonPrefixedType = typePropertyMask.getSchemaType();
- String prefixedType =
- nonPrefixedType.equals(GetByUriRequest.PROJECTION_SCHEMA_TYPE_WILDCARD)
- ? nonPrefixedType
- : createPrefix(packageName, databaseName) + nonPrefixedType;
- prefixedPropertyMasks.add(
- typePropertyMask.toBuilder().setSchemaType(prefixedType).build());
- }
- GetResultSpecProto getResultSpec =
- GetResultSpecProto.newBuilder()
- .addAllTypePropertyMasks(prefixedPropertyMasks)
- .build();
mReadWriteLock.readLock().lock();
try {
- getResultProto =
+ throwIfClosedLocked();
+
+ List<TypePropertyMask> nonPrefixedPropertyMasks =
+ TypePropertyPathToProtoConverter.toTypePropertyMaskList(typePropertyPaths);
+ List<TypePropertyMask> prefixedPropertyMasks =
+ new ArrayList<>(nonPrefixedPropertyMasks.size());
+ for (int i = 0; i < nonPrefixedPropertyMasks.size(); ++i) {
+ TypePropertyMask typePropertyMask = nonPrefixedPropertyMasks.get(i);
+ String nonPrefixedType = typePropertyMask.getSchemaType();
+ String prefixedType =
+ nonPrefixedType.equals(GetByUriRequest.PROJECTION_SCHEMA_TYPE_WILDCARD)
+ ? nonPrefixedType
+ : createPrefix(packageName, databaseName) + nonPrefixedType;
+ prefixedPropertyMasks.add(
+ typePropertyMask.toBuilder().setSchemaType(prefixedType).build());
+ }
+ GetResultSpecProto getResultSpec =
+ GetResultSpecProto.newBuilder()
+ .addAllTypePropertyMasks(prefixedPropertyMasks)
+ .build();
+
+ GetResultProto getResultProto =
mIcingSearchEngineLocked.get(
createPrefix(packageName, databaseName) + namespace,
uri,
getResultSpec);
+ checkSuccess(getResultProto.getStatus());
+
+ DocumentProto.Builder documentBuilder = getResultProto.getDocument().toBuilder();
+ removePrefixesFromDocument(documentBuilder);
+ return GenericDocumentToProtoConverter.toGenericDocument(documentBuilder.build());
} finally {
mReadWriteLock.readLock().unlock();
}
- checkSuccess(getResultProto.getStatus());
-
- DocumentProto.Builder documentBuilder = getResultProto.getDocument().toBuilder();
- removePrefixesFromDocument(documentBuilder);
- return GenericDocumentToProtoConverter.toGenericDocument(documentBuilder.build());
}
/**
@@ -507,17 +549,19 @@ public final class AppSearchImpl {
@NonNull String queryExpression,
@NonNull SearchSpec searchSpec)
throws AppSearchException {
- List<String> filterPackageNames = searchSpec.getFilterPackageNames();
- if (!filterPackageNames.isEmpty() && !filterPackageNames.contains(packageName)) {
- // Client wanted to query over some packages that weren't its own. This isn't
- // allowed through local query so we can return early with no results.
- return new SearchResultPage(Bundle.EMPTY);
- }
-
mReadWriteLock.readLock().lock();
try {
+ throwIfClosedLocked();
+
+ List<String> filterPackageNames = searchSpec.getFilterPackageNames();
+ if (!filterPackageNames.isEmpty() && !filterPackageNames.contains(packageName)) {
+ // Client wanted to query over some packages that weren't its own. This isn't
+ // allowed through local query so we can return early with no results.
+ return new SearchResultPage(Bundle.EMPTY);
+ }
+
String prefix = createPrefix(packageName, databaseName);
- Set<String> allowedPrefixedSchemas = getAllowedPrefixSchemas(prefix, searchSpec);
+ Set<String> allowedPrefixedSchemas = getAllowedPrefixSchemasLocked(prefix, searchSpec);
return doQueryLocked(
Collections.singleton(createPrefix(packageName, databaseName)),
@@ -552,6 +596,8 @@ public final class AppSearchImpl {
throws AppSearchException {
mReadWriteLock.readLock().lock();
try {
+ throwIfClosedLocked();
+
Set<String> packageFilters = new ArraySet<>(searchSpec.getFilterPackageNames());
Set<String> prefixFilters = new ArraySet<>();
Set<String> allPrefixes = mNamespaceMapLocked.keySet();
@@ -654,6 +700,8 @@ public final class AppSearchImpl {
public SearchResultPage getNextPage(long nextPageToken) throws AppSearchException {
mReadWriteLock.readLock().lock();
try {
+ throwIfClosedLocked();
+
SearchResultProto searchResultProto =
mIcingSearchEngineLocked.getNextPage(nextPageToken);
checkSuccess(searchResultProto.getStatus());
@@ -674,6 +722,8 @@ public final class AppSearchImpl {
public void invalidateNextPageToken(long nextPageToken) {
mReadWriteLock.readLock().lock();
try {
+ throwIfClosedLocked();
+
mIcingSearchEngineLocked.invalidateNextPageToken(nextPageToken);
} finally {
mReadWriteLock.readLock().unlock();
@@ -688,16 +738,19 @@ public final class AppSearchImpl {
@NonNull String uri,
long usageTimestampMillis)
throws AppSearchException {
- String prefixedNamespace = createPrefix(packageName, databaseName) + namespace;
- UsageReport report =
- UsageReport.newBuilder()
- .setDocumentNamespace(prefixedNamespace)
- .setDocumentUri(uri)
- .setUsageTimestampMs(usageTimestampMillis)
- .setUsageType(UsageReport.UsageType.USAGE_TYPE1)
- .build();
mReadWriteLock.writeLock().lock();
try {
+ throwIfClosedLocked();
+
+ String prefixedNamespace = createPrefix(packageName, databaseName) + namespace;
+ UsageReport report =
+ UsageReport.newBuilder()
+ .setDocumentNamespace(prefixedNamespace)
+ .setDocumentUri(uri)
+ .setUsageTimestampMs(usageTimestampMillis)
+ .setUsageType(UsageReport.UsageType.USAGE_TYPE1)
+ .build();
+
ReportUsageResultProto result = mIcingSearchEngineLocked.reportUsage(report);
checkSuccess(result.getStatus());
} finally {
@@ -722,16 +775,18 @@ public final class AppSearchImpl {
@NonNull String namespace,
@NonNull String uri)
throws AppSearchException {
- String prefixedNamespace = createPrefix(packageName, databaseName) + namespace;
- DeleteResultProto deleteResultProto;
mReadWriteLock.writeLock().lock();
try {
- deleteResultProto = mIcingSearchEngineLocked.delete(prefixedNamespace, uri);
- checkForOptimizeLocked(/* force= */ false);
+ throwIfClosedLocked();
+
+ String prefixedNamespace = createPrefix(packageName, databaseName) + namespace;
+ DeleteResultProto deleteResultProto =
+ mIcingSearchEngineLocked.delete(prefixedNamespace, uri);
+
+ checkSuccess(deleteResultProto.getStatus());
} finally {
mReadWriteLock.writeLock().unlock();
}
- checkSuccess(deleteResultProto.getStatus());
}
/**
@@ -751,22 +806,25 @@ public final class AppSearchImpl {
@NonNull String queryExpression,
@NonNull SearchSpec searchSpec)
throws AppSearchException {
- List<String> filterPackageNames = searchSpec.getFilterPackageNames();
- if (!filterPackageNames.isEmpty() && !filterPackageNames.contains(packageName)) {
- // We're only removing documents within the parameter `packageName`. If we're not
- // restricting our remove-query to this package name, then there's nothing for us to
- // remove.
- return;
- }
-
- SearchSpecProto searchSpecProto = SearchSpecToProtoConverter.toSearchSpecProto(searchSpec);
- SearchSpecProto.Builder searchSpecBuilder =
- searchSpecProto.toBuilder().setQuery(queryExpression);
- DeleteByQueryResultProto deleteResultProto;
mReadWriteLock.writeLock().lock();
try {
+ throwIfClosedLocked();
+
+ List<String> filterPackageNames = searchSpec.getFilterPackageNames();
+ if (!filterPackageNames.isEmpty() && !filterPackageNames.contains(packageName)) {
+ // We're only removing documents within the parameter `packageName`. If we're not
+ // restricting our remove-query to this package name, then there's nothing for us to
+ // remove.
+ return;
+ }
+
+ SearchSpecProto searchSpecProto =
+ SearchSpecToProtoConverter.toSearchSpecProto(searchSpec);
+ SearchSpecProto.Builder searchSpecBuilder =
+ searchSpecProto.toBuilder().setQuery(queryExpression);
+
String prefix = createPrefix(packageName, databaseName);
- Set<String> allowedPrefixedSchemas = getAllowedPrefixSchemas(prefix, searchSpec);
+ Set<String> allowedPrefixedSchemas = getAllowedPrefixSchemasLocked(prefix, searchSpec);
// rewriteSearchSpecForPrefixesLocked will return false if there is nothing to search
// over given their search filters, so we can return early and skip sending request
@@ -775,15 +833,16 @@ public final class AppSearchImpl {
searchSpecBuilder, Collections.singleton(prefix), allowedPrefixedSchemas)) {
return;
}
- deleteResultProto = mIcingSearchEngineLocked.deleteByQuery(searchSpecBuilder.build());
- checkForOptimizeLocked(/* force= */ true);
+ DeleteByQueryResultProto deleteResultProto =
+ mIcingSearchEngineLocked.deleteByQuery(searchSpecBuilder.build());
+
+ // It seems that the caller wants to get success if the data matching the query is
+ // not in the DB because it was not there or was successfully deleted.
+ checkCodeOneOf(
+ deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND);
} finally {
mReadWriteLock.writeLock().unlock();
}
- // It seems that the caller wants to get success if the data matching the query is not in
- // the DB because it was not there or was successfully deleted.
- checkCodeOneOf(
- deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND);
}
/**
@@ -799,9 +858,16 @@ public final class AppSearchImpl {
* @throws AppSearchException on any error that AppSearch persist data to disk.
*/
public void persistToDisk() throws AppSearchException {
- PersistToDiskResultProto persistToDiskResultProto =
- mIcingSearchEngineLocked.persistToDisk();
- checkSuccess(persistToDiskResultProto.getStatus());
+ mReadWriteLock.writeLock().lock();
+ try {
+ throwIfClosedLocked();
+
+ PersistToDiskResultProto persistToDiskResultProto =
+ mIcingSearchEngineLocked.persistToDisk();
+ checkSuccess(persistToDiskResultProto.getStatus());
+ } finally {
+ mReadWriteLock.writeLock().unlock();
+ }
}
/**
@@ -814,21 +880,16 @@ public final class AppSearchImpl {
*
* @throws AppSearchException on IcingSearchEngine error.
*/
- private void reset() throws AppSearchException {
- ResetResultProto resetResultProto;
- mReadWriteLock.writeLock().lock();
- try {
- resetResultProto = mIcingSearchEngineLocked.reset();
- mOptimizeIntervalCountLocked = 0;
- mSchemaMapLocked.clear();
- mNamespaceMapLocked.clear();
-
- // Must be called after everything else since VisibilityStore may repopulate
- // IcingSearchEngine with an initial schema.
- mVisibilityStoreLocked.handleReset();
- } finally {
- mReadWriteLock.writeLock().unlock();
- }
+ @GuardedBy("mReadWriteLock")
+ private void resetLocked() throws AppSearchException {
+ ResetResultProto resetResultProto = mIcingSearchEngineLocked.reset();
+ mOptimizeIntervalCountLocked = 0;
+ mSchemaMapLocked.clear();
+ mNamespaceMapLocked.clear();
+
+ // Must be called after everything else since VisibilityStore may repopulate
+ // IcingSearchEngine with an initial schema.
+ mVisibilityStoreLocked.handleReset();
checkSuccess(resetResultProto.getStatus());
}
@@ -1079,7 +1140,8 @@ public final class AppSearchImpl {
* <p>This only checks intersection of schema filters on the search spec with those that the
* prefix owns itself. This does not check global query permissions.
*/
- private Set<String> getAllowedPrefixSchemas(
+ @GuardedBy("mReadWriteLock")
+ private Set<String> getAllowedPrefixSchemasLocked(
@NonNull String prefix, @NonNull SearchSpec searchSpec) {
Set<String> allowedPrefixedSchemas = new ArraySet<>();
@@ -1295,35 +1357,72 @@ public final class AppSearchImpl {
/**
* Checks whether {@link IcingSearchEngine#optimize()} should be called to release resources.
*
- * <p>This method should be only called in mutate methods and get the WRITE lock to keep thread
- * safety.
+ * <p>This method should be only called after a mutation to local storage backend which deletes
+ * a mass of data and could release lots resources after {@link IcingSearchEngine#optimize()}.
+ *
+ * <p>This method will trigger {@link IcingSearchEngine#getOptimizeInfo()} to check resources
+ * that could be released for every {@link #CHECK_OPTIMIZE_INTERVAL} mutations.
*
* <p>{@link IcingSearchEngine#optimize()} should be called only if {@link
* GetOptimizeInfoResultProto} shows there is enough resources could be released.
*
- * <p>{@link IcingSearchEngine#getOptimizeInfo()} should be called once per {@link
- * #CHECK_OPTIMIZE_INTERVAL} of remove executions.
+ * @param mutationSize The number of how many mutations have been executed for current request.
+ * An inside counter will accumulates it. Once the counter reaches {@link
+ * #CHECK_OPTIMIZE_INTERVAL}, {@link IcingSearchEngine#getOptimizeInfo()} will be triggered
+ * and the counter will be reset.
+ */
+ public void checkForOptimize(int mutationSize) throws AppSearchException {
+ mReadWriteLock.writeLock().lock();
+ try {
+ mOptimizeIntervalCountLocked += mutationSize;
+ if (mOptimizeIntervalCountLocked >= CHECK_OPTIMIZE_INTERVAL) {
+ checkForOptimize();
+ }
+ } finally {
+ mReadWriteLock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * Checks whether {@link IcingSearchEngine#optimize()} should be called to release resources.
+ *
+ * <p>This method will directly trigger {@link IcingSearchEngine#getOptimizeInfo()} to check
+ * resources that could be released.
*
- * @param force whether we should directly call {@link IcingSearchEngine#getOptimizeInfo()}.
+ * <p>{@link IcingSearchEngine#optimize()} should be called only if {@link
+ * GetOptimizeInfoResultProto} shows there is enough resources could be released.
*/
- @GuardedBy("mReadWriteLock")
- private void checkForOptimizeLocked(boolean force) throws AppSearchException {
- ++mOptimizeIntervalCountLocked;
- if (force || mOptimizeIntervalCountLocked >= CHECK_OPTIMIZE_INTERVAL) {
- mOptimizeIntervalCountLocked = 0;
+ public void checkForOptimize() throws AppSearchException {
+ mReadWriteLock.writeLock().lock();
+ try {
GetOptimizeInfoResultProto optimizeInfo = getOptimizeInfoResultLocked();
checkSuccess(optimizeInfo.getStatus());
+ mOptimizeIntervalCountLocked = 0;
// Second threshold, decide when to call optimize().
if (optimizeInfo.getOptimizableDocs() >= OPTIMIZE_THRESHOLD_DOC_COUNT
|| optimizeInfo.getEstimatedOptimizableBytes() >= OPTIMIZE_THRESHOLD_BYTES) {
- // TODO(b/155939114): call optimize in the same thread will slow down api calls
- // significantly. Move this call to background.
- OptimizeResultProto optimizeResultProto = mIcingSearchEngineLocked.optimize();
- checkSuccess(optimizeResultProto.getStatus());
+ optimize();
}
- // TODO(b/147699081): Return OptimizeResultProto & log lost data detail once we add
- // a field to indicate lost_schema and lost_documents in OptimizeResultProto.
- // go/icing-library-apis.
+ } finally {
+ mReadWriteLock.writeLock().unlock();
+ }
+ // TODO(b/147699081): Return OptimizeResultProto & log lost data detail once we add
+ // a field to indicate lost_schema and lost_documents in OptimizeResultProto.
+ // go/icing-library-apis.
+ }
+
+ /**
+ * Triggers {@link IcingSearchEngine#optimize()} directly.
+ *
+ * <p>This method should be only called as a scheduled task in AppSearch Platform backend.
+ */
+ public void optimize() throws AppSearchException {
+ mReadWriteLock.writeLock().lock();
+ try {
+ OptimizeResultProto optimizeResultProto = mIcingSearchEngineLocked.optimize();
+ checkSuccess(optimizeResultProto.getStatus());
+ } finally {
+ mReadWriteLock.writeLock().unlock();
}
}
diff --git a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchMigrationHelperImpl.java b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchMigrationHelperImpl.java
index b3f8264dc18a..a501e99db1ef 100644
--- a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchMigrationHelperImpl.java
+++ b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchMigrationHelperImpl.java
@@ -76,7 +76,7 @@ class AppSearchMigrationHelperImpl implements AppSearchMigrationHelper {
int currentVersion = mCurrentVersionMap.get(schemaType);
int finalVersion = mFinalVersionMap.get(schemaType);
try (FileOutputStream outputStream = new FileOutputStream(mFile)) {
- // TODO(b/151178558) change the output stream so that we can use it in platform
+ // TODO(b/177266929) change the output stream so that we can use it in platform
CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(outputStream);
SearchResultPage searchResultPage =
mAppSearchImpl.query(
@@ -126,11 +126,13 @@ class AppSearchMigrationHelperImpl implements AppSearchMigrationHelper {
try {
mAppSearchImpl.putDocument(mPackageName, mDatabaseName, document);
} catch (Throwable t) {
- responseBuilder.setFailure(
- document.getSchemaType(),
- document.getNamespace(),
- document.getUri(),
- throwableToFailedResult(t));
+ responseBuilder.addMigrationFailure(
+ new SetSchemaResponse.MigrationFailure.Builder()
+ .setNamespace(document.getNamespace())
+ .setSchemaType(document.getSchemaType())
+ .setUri(document.getUri())
+ .setAppSearchResult(throwableToFailedResult(t))
+ .build());
}
}
mAppSearchImpl.persistToDisk();
diff --git a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SetSchemaResultToProtoConverter.java b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SetSchemaResponseToProtoConverter.java
index e1e7d46d77ea..a0f39ecd68fb 100644
--- a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SetSchemaResultToProtoConverter.java
+++ b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SetSchemaResponseToProtoConverter.java
@@ -17,45 +17,41 @@
package com.android.server.appsearch.external.localstorage.converter;
import android.annotation.NonNull;
-import android.app.appsearch.SetSchemaResult;
+import android.app.appsearch.SetSchemaResponse;
import com.android.internal.util.Preconditions;
import com.google.android.icing.proto.SetSchemaResultProto;
/**
- * Translates a {@link SetSchemaResultProto} into {@link SetSchemaResult}.
+ * Translates a {@link SetSchemaResultProto} into {@link SetSchemaResponse}.
*
* @hide
*/
-public class SetSchemaResultToProtoConverter {
+public class SetSchemaResponseToProtoConverter {
- private SetSchemaResultToProtoConverter() {}
+ private SetSchemaResponseToProtoConverter() {}
/**
- * Translate a {@link SetSchemaResultProto} into {@link SetSchemaResult}.
+ * Translate a {@link SetSchemaResultProto} into {@link SetSchemaResponse}.
*
* @param proto The {@link SetSchemaResultProto} containing results.
* @param prefix The prefix need to removed from schemaTypes
- * @return {@link SetSchemaResult} of results.
+ * @return The {@link SetSchemaResponse} object.
*/
@NonNull
- public static SetSchemaResult toSetSchemaResult(
+ public static SetSchemaResponse toSetSchemaResponse(
@NonNull SetSchemaResultProto proto, @NonNull String prefix) {
Preconditions.checkNotNull(proto);
Preconditions.checkNotNull(prefix);
- SetSchemaResult.Builder builder =
- new SetSchemaResult.Builder()
- .setResultCode(
- ResultCodeToProtoConverter.toResultCode(
- proto.getStatus().getCode()));
+ SetSchemaResponse.Builder builder = new SetSchemaResponse.Builder();
for (int i = 0; i < proto.getDeletedSchemaTypesCount(); i++) {
- builder.addDeletedSchemaType(proto.getDeletedSchemaTypes(i).substring(prefix.length()));
+ builder.addDeletedType(proto.getDeletedSchemaTypes(i).substring(prefix.length()));
}
for (int i = 0; i < proto.getIncompatibleSchemaTypesCount(); i++) {
- builder.addIncompatibleSchemaType(
+ builder.addIncompatibleType(
proto.getIncompatibleSchemaTypes(i).substring(prefix.length()));
}
diff --git a/apex/appsearch/synced_jetpack_changeid.txt b/apex/appsearch/synced_jetpack_changeid.txt
index 6ba557224582..d076db3b8f82 100644
--- a/apex/appsearch/synced_jetpack_changeid.txt
+++ b/apex/appsearch/synced_jetpack_changeid.txt
@@ -1 +1 @@
-I2bf8bd9db1b71b7da4ab50dd7480e4529678413a
+Ia9a8daef1a6d7d9432f7808d440abd64f4797701
diff --git a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java
index b2ffd5b4b60c..ea21e19b2bea 100644
--- a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java
+++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java
@@ -77,10 +77,14 @@ public interface AppSearchSessionShim extends Closeable {
* android.app.appsearch.exceptions.AppSearchException} with the {@link
* AppSearchResult#RESULT_INVALID_SCHEMA} error code, all documents which are not
* compatible with the new schema will be deleted and the incompatible schema will be
- * applied.
+ * applied. Incompatible types and deleted types will be set into {@link
+ * SetSchemaResponse#getIncompatibleTypes()} and {@link
+ * SetSchemaResponse#getDeletedTypes()}, respectively.
* <li>Add a {@link android.app.appsearch.AppSearchSchema.Migrator} for each incompatible type
* and make no deletion. The migrator will migrate documents from it's old schema version
- * to the new version. See the migration section below.
+ * to the new version. Migrated types will be set into both {@link
+ * SetSchemaResponse#getIncompatibleTypes()} and {@link
+ * SetSchemaResponse#getMigratedTypes()}. See the migration section below.
* </ul>
*
* <p>It is a no-op to set the same schema as has been previously set; this is handled
@@ -109,10 +113,8 @@ public interface AppSearchSessionShim extends Closeable {
* backwards-compatible, and stored documents won't have any observable changes.
*
* @param request The schema update request.
- * @return The pending {@link SetSchemaResponse} of performing this operation. Success if the
- * the schema has been set and any migrations has been done. Otherwise, the failure {@link
- * android.app.appsearch.SetSchemaResponse.MigrationFailure} indicates which document is
- * fail to be migrated.
+ * @return A {@link ListenableFuture} with exception if we hit any error. Or the pending {@link
+ * SetSchemaResponse} of performing this operation, if the schema has been successfully set.
* @see android.app.appsearch.AppSearchSchema.Migrator
* @see android.app.appsearch.AppSearchMigrationHelper.Transformer
*/
@@ -144,57 +146,79 @@ public interface AppSearchSessionShim extends Closeable {
ListenableFuture<AppSearchBatchResult<String, Void>> put(@NonNull PutDocumentsRequest request);
/**
- * Retrieves {@link GenericDocument}s by URI.
+ * Gets {@link GenericDocument} objects by URIs and namespace from the {@link
+ * AppSearchSessionShim} database.
*
- * @param request {@link GetByUriRequest} containing URIs to be retrieved.
- * @return The pending result of performing this operation. The keys of the returned {@link
- * AppSearchBatchResult} are the input URIs. The values are the returned {@link
- * GenericDocument}s on success, or a failed {@link AppSearchResult} otherwise. URIs that
- * are not found will return a failed {@link AppSearchResult} with a result code of {@link
- * AppSearchResult#RESULT_NOT_FOUND}.
+ * @param request a request containing URIs and namespace to get documents for.
+ * @return A {@link ListenableFuture} which resolves to an {@link AppSearchBatchResult}. The
+ * keys of the {@link AppSearchBatchResult} represent the input URIs from the {@link
+ * GetByUriRequest} object. The values are either the corresponding {@link GenericDocument}
+ * object for the URI on success, or an {@link AppSearchResult} object on failure. For
+ * example, if a URI is not found, the value for that URI will be set to an {@link
+ * AppSearchResult} object with result code: {@link AppSearchResult#RESULT_NOT_FOUND}.
*/
@NonNull
ListenableFuture<AppSearchBatchResult<String, GenericDocument>> getByUri(
@NonNull GetByUriRequest request);
/**
- * Searches for documents based on a given query string.
+ * Retrieves documents from the open {@link AppSearchSessionShim} that match a given query
+ * string and type of search provided.
+ *
+ * <p>Query strings can be empty, contain one term with no operators, or contain multiple terms
+ * and operators.
+ *
+ * <p>For query strings that are empty, all documents that match the {@link SearchSpec} will be
+ * returned.
*
- * <p>Currently we support following features in the raw query format:
+ * <p>For query strings with a single term and no operators, documents that match the provided
+ * query string and {@link SearchSpec} will be returned.
+ *
+ * <p>The following operators are supported:
*
* <ul>
- * <li>AND
- * <p>AND joins (e.g. “match documents that have both the terms ‘dog’ and ‘cat’”).
- * Example: hello world matches documents that have both ‘hello’ and ‘world’
+ * <li>AND (implicit)
+ * <p>AND is an operator that matches documents that contain <i>all</i> provided terms.
+ * <p><b>NOTE:</b> A space between terms is treated as an "AND" operator. Explicitly
+ * including "AND" in a query string will treat "AND" as a term, returning documents that
+ * also contain "AND".
+ * <p>Example: "apple AND banana" matches documents that contain the terms "apple", "and",
+ * "banana".
+ * <p>Example: "apple banana" matches documents that contain both "apple" and "banana".
+ * <p>Example: "apple banana cherry" matches documents that contain "apple", "banana", and
+ * "cherry".
* <li>OR
- * <p>OR joins (e.g. “match documents that have either the term ‘dog’ or ‘cat’”). Example:
- * dog OR puppy
- * <li>Exclusion
- * <p>Exclude a term (e.g. “match documents that do not have the term ‘dog’”). Example:
- * -dog excludes the term ‘dog’
- * <li>Grouping terms
- * <p>Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
- * “match documents that have either ‘dog’ or ‘puppy’, and either ‘cat’ or ‘kitten’”).
- * Example: (dog puppy) (cat kitten) two one group containing two terms.
- * <li>Property restricts
- * <p>Specifies which properties of a document to specifically match terms in (e.g. “match
- * documents where the ‘subject’ property contains ‘important’”). Example:
- * subject:important matches documents with the term ‘important’ in the ‘subject’ property
- * <li>Schema type restricts
- * <p>This is similar to property restricts, but allows for restricts on top-level
- * document fields, such as schema_type. Clients should be able to limit their query to
- * documents of a certain schema_type (e.g. “match documents that are of the ‘Email’
- * schema_type”). Example: { schema_type_filters: “Email”, “Video”,query: “dog” } will
- * match documents that contain the query term ‘dog’ and are of either the ‘Email’ schema
- * type or the ‘Video’ schema type.
+ * <p>OR is an operator that matches documents that contain <i>any</i> provided term.
+ * <p>Example: "apple OR banana" matches documents that contain either "apple" or
+ * "banana".
+ * <p>Example: "apple OR banana OR cherry" matches documents that contain any of "apple",
+ * "banana", or "cherry".
+ * <li>Exclusion (-)
+ * <p>Exclusion (-) is an operator that matches documents that <i>do not</i> contain the
+ * provided term.
+ * <p>Example: "-apple" matches documents that do not contain "apple".
+ * <li>Grouped Terms
+ * <p>For queries that require multiple operators and terms, terms can be grouped into
+ * subqueries. Subqueries are contained within an open "(" and close ")" parenthesis.
+ * <p>Example: "(donut OR bagel) (coffee OR tea)" matches documents that contain either
+ * "donut" or "bagel" and either "coffee" or "tea".
+ * <li>Property Restricts
+ * <p>For queries that require a term to match a specific {@link AppSearchSchema} property
+ * of a document, a ":" must be included between the property name and the term.
+ * <p>Example: "subject:important" matches documents that contain the term "important" in
+ * the "subject" property.
* </ul>
*
+ * <p>Additional search specifications, such as filtering by {@link AppSearchSchema} type or
+ * adding projection, can be set by calling the corresponding {@link SearchSpec.Builder} setter.
+ *
* <p>This method is lightweight. The heavy work will be done in {@link
* SearchResultsShim#getNextPage()}.
*
- * @param queryExpression Query String to search.
- * @param searchSpec Spec for setting filters, raw query etc.
- * @return The search result of performing this operation.
+ * @param queryExpression query string to search.
+ * @param searchSpec spec for setting document filters, adding projection, setting term match
+ * type, etc.
+ * @return a {@link SearchResultsShim} object for retrieved matched documents.
*/
@NonNull
SearchResultsShim search(@NonNull String queryExpression, @NonNull SearchSpec searchSpec);
@@ -219,13 +243,22 @@ public interface AppSearchSessionShim extends Closeable {
ListenableFuture<Void> reportUsage(@NonNull ReportUsageRequest request);
/**
- * Removes {@link GenericDocument}s from the index by URI.
+ * Removes {@link GenericDocument} objects by URIs and namespace from the {@link
+ * AppSearchSessionShim} database.
*
- * @param request Request containing URIs to be removed.
- * @return The pending result of performing this operation. The keys of the returned {@link
- * AppSearchBatchResult} are the input URIs. The values are {@code null} on success, or a
- * failed {@link AppSearchResult} otherwise. URIs that are not found will return a failed
- * {@link AppSearchResult} with a result code of {@link AppSearchResult#RESULT_NOT_FOUND}.
+ * <p>Removed documents will no longer be surfaced by {@link #search} or {@link #getByUri}
+ * calls.
+ *
+ * <p><b>NOTE:</b>By default, documents are removed via a soft delete operation. Once the
+ * document crosses the count threshold or byte usage threshold, the documents will be removed
+ * from disk.
+ *
+ * @param request {@link RemoveByUriRequest} with URIs and namespace to remove from the index.
+ * @return a {@link ListenableFuture} which resolves to an {@link AppSearchBatchResult}. The
+ * keys of the {@link AppSearchBatchResult} represent the input URIs from the {@link
+ * RemoveByUriRequest} object. The values are either {@code null} on success, or a failed
+ * {@link AppSearchResult} otherwise. URIs that are not found will return a failed {@link
+ * AppSearchResult} with a result code of {@link AppSearchResult#RESULT_NOT_FOUND}.
*/
@NonNull
ListenableFuture<AppSearchBatchResult<String, Void>> remove(
diff --git a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java
index 44d5180c3a36..37717d6837b9 100644
--- a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java
+++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java
@@ -25,7 +25,6 @@ import android.app.appsearch.GenericDocument;
import android.app.appsearch.GetByUriRequest;
import android.app.appsearch.SearchResult;
import android.app.appsearch.SearchResultsShim;
-import android.app.appsearch.SetSchemaResponse;
import java.util.ArrayList;
import java.util.List;
@@ -43,15 +42,6 @@ public class AppSearchTestUtils {
return result;
}
- // TODO(b/151178558) check setSchemaResponse.xxxtypes for the test need to verify.
- public static void checkIsSetSchemaResponseSuccess(Future<SetSchemaResponse> future)
- throws Exception {
- SetSchemaResponse setSchemaResponse = future.get();
- assertWithMessage("SetSchemaResponse not successful.")
- .that(setSchemaResponse.isSuccess())
- .isTrue();
- }
-
public static List<GenericDocument> doGet(
AppSearchSessionShim session, String namespace, String... uris) throws Exception {
AppSearchBatchResult<String, GenericDocument> result =
diff --git a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/GlobalSearchSessionShim.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/GlobalSearchSessionShim.java
index b96f99e7cd37..31c934f8bb27 100644
--- a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/GlobalSearchSessionShim.java
+++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/GlobalSearchSessionShim.java
@@ -27,43 +27,26 @@ import java.io.Closeable;
*/
public interface GlobalSearchSessionShim extends Closeable {
/**
- * Searches across all documents in the storage based on a given query string.
+ * Retrieves documents from all AppSearch databases that the querying application has access to.
*
- * <p>Currently we support following features in the raw query format:
+ * <p>Applications can be granted access to documents by specifying {@link
+ * SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage}, or {@link
+ * SetSchemaRequest.Builder#setDocumentClassVisibilityForPackage} when building a schema.
*
- * <ul>
- * <li>AND
- * <p>AND joins (e.g. “match documents that have both the terms ‘dog’ and ‘cat’”).
- * Example: hello world matches documents that have both ‘hello’ and ‘world’
- * <li>OR
- * <p>OR joins (e.g. “match documents that have either the term ‘dog’ or ‘cat’”). Example:
- * dog OR puppy
- * <li>Exclusion
- * <p>Exclude a term (e.g. “match documents that do not have the term ‘dog’”). Example:
- * -dog excludes the term ‘dog’
- * <li>Grouping terms
- * <p>Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
- * “match documents that have either ‘dog’ or ‘puppy’, and either ‘cat’ or ‘kitten’”).
- * Example: (dog puppy) (cat kitten) two one group containing two terms.
- * <li>Property restricts
- * <p>Specifies which properties of a document to specifically match terms in (e.g. “match
- * documents where the ‘subject’ property contains ‘important’”). Example:
- * subject:important matches documents with the term ‘important’ in the ‘subject’ property
- * <li>Schema type restricts
- * <p>This is similar to property restricts, but allows for restricts on top-level
- * document fields, such as schema_type. Clients should be able to limit their query to
- * documents of a certain schema_type (e.g. “match documents that are of the ‘Email’
- * schema_type”). Example: { schema_type_filters: “Email”, “Video”,query: “dog” } will
- * match documents that contain the query term ‘dog’ and are of either the ‘Email’ schema
- * type or the ‘Video’ schema type.
- * </ul>
+ * <p>Document access can also be granted to system UIs by specifying {@link
+ * SetSchemaRequest.Builder#setSchemaTypeVisibilityForSystemUi}, or {@link
+ * SetSchemaRequest.Builder#setDocumentClassVisibilityForSystemUi} when building a schema.
+ *
+ * <p>See {@link AppSearchSessionShim#search(String, SearchSpec)} for a detailed explanation on
+ * forming a query string.
*
* <p>This method is lightweight. The heavy work will be done in {@link
* SearchResultsShim#getNextPage()}.
*
- * @param queryExpression Query String to search.
- * @param searchSpec Spec for setting filters, raw query etc.
- * @return The search result of performing this operation.
+ * @param queryExpression query string to search.
+ * @param searchSpec spec for setting document filters, adding projection, setting term match
+ * type, etc.
+ * @return a {@link SearchResultsShim} object for retrieved matched documents.
*/
@NonNull
SearchResultsShim search(@NonNull String queryExpression, @NonNull SearchSpec searchSpec);
diff --git a/api/Android.bp b/api/Android.bp
index d5c6bf6d024e..5466bd2833a9 100644
--- a/api/Android.bp
+++ b/api/Android.bp
@@ -37,6 +37,7 @@ genrule {
":framework-mediaprovider{.public.api.txt}",
":framework-permission{.public.api.txt}",
":framework-permission-s{.public.api.txt}",
+ ":framework-scheduling{.public.api.txt}",
":framework-sdkextensions{.public.api.txt}",
":framework-statsd{.public.api.txt}",
":framework-tethering{.public.api.txt}",
@@ -63,6 +64,22 @@ genrule {
}
genrule {
+ name: "frameworks-base-api-current-compat",
+ srcs: [
+ ":android.api.public.latest",
+ ":android-incompatibilities.api.public.latest",
+ ":frameworks-base-api-current.txt",
+ ],
+ out: ["stdout.txt"],
+ tools: ["metalava"],
+ cmd: "$(location metalava) --no-banner --format=v2 " +
+ "--check-compatibility:api:released $(location :android.api.public.latest) " +
+ "--baseline:compatibility:released $(location :android-incompatibilities.api.public.latest) " +
+ "$(location :frameworks-base-api-current.txt) " +
+ "> $(genDir)/stdout.txt",
+}
+
+genrule {
name: "frameworks-base-api-current.srcjar",
srcs: [
":android.net.ipsec.ike{.public.stubs.source}",
@@ -75,6 +92,7 @@ genrule {
":framework-mediaprovider{.public.stubs.source}",
":framework-permission{.public.stubs.source}",
":framework-permission-s{.public.stubs.source}",
+ ":framework-scheduling{.public.stubs.source}",
":framework-sdkextensions{.public.stubs.source}",
":framework-statsd{.public.stubs.source}",
":framework-tethering{.public.stubs.source}",
@@ -99,6 +117,7 @@ genrule {
":framework-mediaprovider{.public.removed-api.txt}",
":framework-permission{.public.removed-api.txt}",
":framework-permission-s{.public.removed-api.txt}",
+ ":framework-scheduling{.public.removed-api.txt}",
":framework-sdkextensions{.public.removed-api.txt}",
":framework-statsd{.public.removed-api.txt}",
":framework-tethering{.public.removed-api.txt}",
@@ -133,6 +152,7 @@ genrule {
":framework-mediaprovider{.system.api.txt}",
":framework-permission{.system.api.txt}",
":framework-permission-s{.system.api.txt}",
+ ":framework-scheduling{.system.api.txt}",
":framework-sdkextensions{.system.api.txt}",
":framework-statsd{.system.api.txt}",
":framework-tethering{.system.api.txt}",
@@ -158,6 +178,24 @@ genrule {
}
genrule {
+ name: "frameworks-base-api-system-current-compat",
+ srcs: [
+ ":android.api.system.latest",
+ ":android-incompatibilities.api.system.latest",
+ ":frameworks-base-api-current.txt",
+ ":frameworks-base-api-system-current.txt",
+ ],
+ out: ["stdout.txt"],
+ tools: ["metalava"],
+ cmd: "$(location metalava) --no-banner --format=v2 " +
+ "--check-compatibility:api:released $(location :android.api.system.latest) " +
+ "--check-compatibility:base $(location :frameworks-base-api-current.txt) " +
+ "--baseline:compatibility:released $(location :android-incompatibilities.api.system.latest) " +
+ "$(location :frameworks-base-api-system-current.txt) " +
+ "> $(genDir)/stdout.txt",
+}
+
+genrule {
name: "frameworks-base-api-system-removed.txt",
srcs: [
":android.net.ipsec.ike{.system.removed-api.txt}",
@@ -167,6 +205,7 @@ genrule {
":framework-mediaprovider{.system.removed-api.txt}",
":framework-permission{.system.removed-api.txt}",
":framework-permission-s{.system.removed-api.txt}",
+ ":framework-scheduling{.system.removed-api.txt}",
":framework-sdkextensions{.system.removed-api.txt}",
":framework-statsd{.system.removed-api.txt}",
":framework-tethering{.system.removed-api.txt}",
@@ -201,6 +240,7 @@ genrule {
":framework-mediaprovider{.module-lib.api.txt}",
":framework-permission{.module-lib.api.txt}",
":framework-permission-s{.module-lib.api.txt}",
+ ":framework-scheduling{.module-lib.api.txt}",
":framework-sdkextensions{.module-lib.api.txt}",
":framework-statsd{.module-lib.api.txt}",
":framework-tethering{.module-lib.api.txt}",
@@ -225,6 +265,27 @@ genrule {
}
genrule {
+ name: "frameworks-base-api-module-lib-current-compat",
+ srcs: [
+ ":android.api.module-lib.latest",
+ ":android-incompatibilities.api.module-lib.latest",
+ ":frameworks-base-api-current.txt",
+ ":frameworks-base-api-module-lib-current.txt",
+ ],
+ out: ["stdout.txt"],
+ tools: ["metalava"],
+ cmd: "$(location metalava) --no-banner --format=v2 " +
+ "--check-compatibility:api:released $(location :android.api.module-lib.latest) " +
+ // Note: having "public" be the base of module-lib is not perfect -- it should
+ // ideally be a merged public+system), but this will help when migrating from
+ // MODULE_LIBS -> public.
+ "--check-compatibility:base $(location :frameworks-base-api-current.txt) " +
+ "--baseline:compatibility:released $(location :android-incompatibilities.api.module-lib.latest) " +
+ "$(location :frameworks-base-api-module-lib-current.txt) " +
+ "> $(genDir)/stdout.txt",
+}
+
+genrule {
name: "frameworks-base-api-module-lib-removed.txt",
srcs: [
":android.net.ipsec.ike{.module-lib.removed-api.txt}",
@@ -234,6 +295,7 @@ genrule {
":framework-mediaprovider{.module-lib.removed-api.txt}",
":framework-permission{.module-lib.removed-api.txt}",
":framework-permission-s{.module-lib.removed-api.txt}",
+ ":framework-scheduling{.module-lib.removed-api.txt}",
":framework-sdkextensions{.module-lib.removed-api.txt}",
":framework-statsd{.module-lib.removed-api.txt}",
":framework-tethering{.module-lib.removed-api.txt}",
diff --git a/cmds/svc/src/com/android/commands/svc/UsbCommand.java b/cmds/svc/src/com/android/commands/svc/UsbCommand.java
index 227b9e24f173..115c1f23c521 100644
--- a/cmds/svc/src/com/android/commands/svc/UsbCommand.java
+++ b/cmds/svc/src/com/android/commands/svc/UsbCommand.java
@@ -55,7 +55,11 @@ public class UsbCommand extends Svc.Command {
+ " svc usb getGadgetHalVersion\n"
+ " Gets current Gadget Hal Version\n"
+ " possible values of Hal version are any of 'unknown', 'V1_0', 'V1_1',\n"
- + " 'V1_2'\n";
+ + " 'V1_2'\n"
+ + " svc usb getUsbHalVersion\n"
+ + " Gets current USB Hal Version\n"
+ + " possible values of Hal version are any of 'unknown', 'V1_0', 'V1_1',\n"
+ + " 'V1_2', 'V1_3'\n";
}
@Override
@@ -111,6 +115,25 @@ public class UsbCommand extends Svc.Command {
System.err.println("Error communicating with UsbManager: " + e);
}
return;
+ } else if ("getUsbHalVersion".equals(args[1])) {
+ try {
+ int version = usbMgr.getUsbHalVersion();
+
+ if (version == 13) {
+ System.err.println("V1_3");
+ } else if (version == 12) {
+ System.err.println("V1_2");
+ } else if (version == 11) {
+ System.err.println("V1_1");
+ } else if (version == 10) {
+ System.err.println("V1_0");
+ } else {
+ System.err.println("unknown");
+ }
+ } catch (RemoteException e) {
+ System.err.println("Error communicating with UsbManager: " + e);
+ }
+ return;
}
}
System.err.println(longHelp());
diff --git a/core/api/current.txt b/core/api/current.txt
index 9ef3eb462552..508d916d2784 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -88,6 +88,7 @@ package android {
field @Deprecated public static final String GET_TASKS = "android.permission.GET_TASKS";
field public static final String GLOBAL_SEARCH = "android.permission.GLOBAL_SEARCH";
field public static final String HIDE_OVERLAY_WINDOWS = "android.permission.HIDE_OVERLAY_WINDOWS";
+ field public static final String HIGH_SAMPLING_RATE_SENSORS = "android.permission.HIGH_SAMPLING_RATE_SENSORS";
field public static final String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER";
field public static final String INSTALL_PACKAGES = "android.permission.INSTALL_PACKAGES";
field public static final String INSTALL_SHORTCUT = "com.android.launcher.permission.INSTALL_SHORTCUT";
@@ -959,6 +960,8 @@ package android {
field public static final int maxLines = 16843091; // 0x1010153
field public static final int maxLongVersionCode = 16844163; // 0x1010583
field public static final int maxRecents = 16843846; // 0x1010446
+ field public static final int maxResizeHeight = 16844339; // 0x1010633
+ field public static final int maxResizeWidth = 16844338; // 0x1010632
field public static final int maxRows = 16843059; // 0x1010133
field public static final int maxSdkVersion = 16843377; // 0x1010271
field public static final int maxWidth = 16843039; // 0x101011f
@@ -1185,6 +1188,7 @@ package android {
field public static final int right = 16843183; // 0x10101af
field public static final int ringtonePreferenceStyle = 16842899; // 0x1010093
field public static final int ringtoneType = 16843257; // 0x10101f9
+ field public static final int rippleStyle = 16844337; // 0x1010631
field public static final int rollbackDataPolicy = 16844311; // 0x1010617
field public static final int rotation = 16843558; // 0x1010326
field public static final int rotationAnimation = 16844090; // 0x101053a
@@ -1392,6 +1396,8 @@ package android {
field public static final int tabWidgetStyle = 16842883; // 0x1010083
field public static final int tag = 16842961; // 0x10100d1
field public static final int targetActivity = 16843266; // 0x1010202
+ field public static final int targetCellHeight = 16844341; // 0x1010635
+ field public static final int targetCellWidth = 16844340; // 0x1010634
field public static final int targetClass = 16842799; // 0x101002f
field @Deprecated public static final int targetDescriptions = 16843680; // 0x10103a0
field public static final int targetId = 16843740; // 0x10103dc
@@ -1746,6 +1752,9 @@ package android {
field public static final int dialog_min_width_minor = 17104900; // 0x1050004
field public static final int notification_large_icon_height = 17104902; // 0x1050006
field public static final int notification_large_icon_width = 17104901; // 0x1050005
+ field public static final int system_app_widget_background_radius = 17104904; // 0x1050008
+ field public static final int system_app_widget_inner_radius = 17104905; // 0x1050009
+ field public static final int system_app_widget_internal_padding = 17104906; // 0x105000a
field public static final int thumbnail_height = 17104897; // 0x1050001
field public static final int thumbnail_width = 17104898; // 0x1050002
}
@@ -6069,6 +6078,13 @@ package android.app {
method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.NotificationChannel> CREATOR;
field public static final String DEFAULT_CHANNEL_ID = "miscellaneous";
+ field public static final String EDIT_CONVERSATION = "convo";
+ field public static final String EDIT_IMPORTANCE = "importance";
+ field public static final String EDIT_LAUNCHER = "launcher";
+ field public static final String EDIT_LOCKED_DEVICE = "locked";
+ field public static final String EDIT_SOUND = "sound";
+ field public static final String EDIT_VIBRATION = "vibration";
+ field public static final String EDIT_ZEN = "dnd";
}
public final class NotificationChannelGroup implements android.os.Parcelable {
@@ -6958,6 +6974,7 @@ package android.app.admin {
method public void addUserRestriction(@NonNull android.content.ComponentName, String);
method public boolean bindDeviceAdminServiceAsUser(@NonNull android.content.ComponentName, android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull android.os.UserHandle);
method public boolean canAdminGrantSensorsPermissions();
+ method public boolean canUsbDataSignalingBeDisabled();
method public void clearApplicationUserData(@NonNull android.content.ComponentName, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.app.admin.DevicePolicyManager.OnClearApplicationUserDataListener);
method public void clearCrossProfileIntentFilters(@NonNull android.content.ComponentName);
method @Deprecated public void clearDeviceOwnerApp(String);
@@ -7085,6 +7102,7 @@ package android.app.admin {
method public boolean isSecurityLoggingEnabled(@Nullable android.content.ComponentName);
method public boolean isUninstallBlocked(@Nullable android.content.ComponentName, String);
method public boolean isUniqueDeviceAttestationSupported();
+ method public boolean isUsbDataSignalingEnabled();
method public boolean isUsingUnifiedPassword(@NonNull android.content.ComponentName);
method public void lockNow();
method public void lockNow(int);
@@ -7186,6 +7204,7 @@ package android.app.admin {
method public boolean setTimeZone(@NonNull android.content.ComponentName, String);
method public void setTrustAgentConfiguration(@NonNull android.content.ComponentName, @NonNull android.content.ComponentName, android.os.PersistableBundle);
method public void setUninstallBlocked(@Nullable android.content.ComponentName, String, boolean);
+ method public void setUsbDataSignalingEnabled(boolean);
method public void setUserControlDisabledPackages(@NonNull android.content.ComponentName, @NonNull java.util.List<java.lang.String>);
method public void setUserIcon(@NonNull android.content.ComponentName, android.graphics.Bitmap);
method public int startUserInBackground(@NonNull android.content.ComponentName, @NonNull android.os.UserHandle);
@@ -8302,6 +8321,7 @@ package android.appwidget {
public class AppWidgetHostView extends android.widget.FrameLayout {
ctor public AppWidgetHostView(android.content.Context);
ctor public AppWidgetHostView(android.content.Context, int, int);
+ method public void clearCurrentSize();
method public int getAppWidgetId();
method public android.appwidget.AppWidgetProviderInfo getAppWidgetInfo();
method public static android.graphics.Rect getDefaultPaddingForWidget(android.content.Context, android.content.ComponentName, android.graphics.Rect);
@@ -8309,11 +8329,13 @@ package android.appwidget {
method protected android.view.View getErrorView();
method protected void prepareView(android.view.View);
method public void setAppWidget(int, android.appwidget.AppWidgetProviderInfo);
+ method public void setCurrentSize(@NonNull android.graphics.PointF);
method public void setExecutor(java.util.concurrent.Executor);
method public void setOnLightBackground(boolean);
method public void updateAppWidget(android.widget.RemoteViews);
method public void updateAppWidgetOptions(android.os.Bundle);
- method public void updateAppWidgetSize(android.os.Bundle, int, int, int, int);
+ method @Deprecated public void updateAppWidgetSize(android.os.Bundle, int, int, int, int);
+ method public void updateAppWidgetSize(@NonNull android.os.Bundle, @NonNull java.util.List<android.graphics.PointF>);
}
public class AppWidgetManager {
@@ -8366,6 +8388,7 @@ package android.appwidget {
field public static final String OPTION_APPWIDGET_MIN_HEIGHT = "appWidgetMinHeight";
field public static final String OPTION_APPWIDGET_MIN_WIDTH = "appWidgetMinWidth";
field public static final String OPTION_APPWIDGET_RESTORE_COMPLETED = "appWidgetRestoreCompleted";
+ field public static final String OPTION_APPWIDGET_SIZES = "appWidgetSizes";
}
public class AppWidgetProvider extends android.content.BroadcastReceiver {
@@ -8409,6 +8432,8 @@ package android.appwidget {
field public int initialKeyguardLayout;
field public int initialLayout;
field @Deprecated public String label;
+ field public int maxResizeHeight;
+ field public int maxResizeWidth;
field public int minHeight;
field public int minResizeHeight;
field public int minResizeWidth;
@@ -8417,6 +8442,8 @@ package android.appwidget {
field @IdRes public int previewLayout;
field public android.content.ComponentName provider;
field public int resizeMode;
+ field public int targetCellHeight;
+ field public int targetCellWidth;
field public int updatePeriodMillis;
field public int widgetCategory;
field public int widgetFeatures;
@@ -10234,12 +10261,15 @@ package android.content {
method @RequiresPermission(anyOf={"android.permission.INTERACT_ACROSS_USERS", android.Manifest.permission.INTERACT_ACROSS_PROFILES}) public boolean bindServiceAsUser(@NonNull @RequiresPermission android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull android.os.UserHandle);
method @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)") public abstract int checkCallingOrSelfPermission(@NonNull String);
method @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)") public abstract int checkCallingOrSelfUriPermission(android.net.Uri, int);
+ method @NonNull public int[] checkCallingOrSelfUriPermissions(@NonNull java.util.List<android.net.Uri>, int);
method @CheckResult(suggest="#enforceCallingPermission(String,String)") public abstract int checkCallingPermission(@NonNull String);
method @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)") public abstract int checkCallingUriPermission(android.net.Uri, int);
+ method @NonNull public int[] checkCallingUriPermissions(@NonNull java.util.List<android.net.Uri>, int);
method @CheckResult(suggest="#enforcePermission(String,int,int,String)") public abstract int checkPermission(@NonNull String, int, int);
method public abstract int checkSelfPermission(@NonNull String);
method @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)") public abstract int checkUriPermission(android.net.Uri, int, int, int);
method @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)") public abstract int checkUriPermission(@Nullable android.net.Uri, @Nullable String, @Nullable String, int, int, int);
+ method @NonNull public int[] checkUriPermissions(@NonNull java.util.List<android.net.Uri>, int, int, int);
method @Deprecated public abstract void clearWallpaper() throws java.io.IOException;
method @NonNull public android.content.Context createAttributionContext(@Nullable String);
method public abstract android.content.Context createConfigurationContext(@NonNull android.content.res.Configuration);
@@ -16524,9 +16554,13 @@ package android.graphics.drawable {
public class RippleDrawable extends android.graphics.drawable.LayerDrawable {
ctor public RippleDrawable(@NonNull android.content.res.ColorStateList, @Nullable android.graphics.drawable.Drawable, @Nullable android.graphics.drawable.Drawable);
method public int getRadius();
+ method public int getRippleStyle();
method public void setColor(android.content.res.ColorStateList);
method public void setRadius(int);
+ method public void setRippleStyle(int) throws java.lang.IllegalArgumentException;
field public static final int RADIUS_AUTO = -1; // 0xffffffff
+ field public static final int STYLE_PATTERNED = 1; // 0x1
+ field public static final int STYLE_SOLID = 0; // 0x0
}
public class RotateDrawable extends android.graphics.drawable.DrawableWrapper {
@@ -21600,6 +21634,7 @@ package android.media {
method @android.media.MediaDrm.HdcpLevel public int getConnectedHdcpLevel();
method public android.media.MediaDrm.CryptoSession getCryptoSession(@NonNull byte[], @NonNull String, @NonNull String);
method @NonNull public android.media.MediaDrm.KeyRequest getKeyRequest(@NonNull byte[], @Nullable byte[], @Nullable String, int, @Nullable java.util.HashMap<java.lang.String,java.lang.String>) throws android.media.NotProvisionedException;
+ method @NonNull public java.util.List<android.media.MediaDrm.LogMessage> getLogMessages();
method @android.media.MediaDrm.HdcpLevel public int getMaxHdcpLevel();
method public static int getMaxSecurityLevel();
method public int getMaxSessionCount();
@@ -21708,6 +21743,12 @@ package android.media {
field public static final int STATUS_USABLE_IN_FUTURE = 5; // 0x5
}
+ public static class MediaDrm.LogMessage {
+ field @NonNull public final String message;
+ field public final int priority;
+ field public final long timestampMillis;
+ }
+
public static final class MediaDrm.MediaDrmStateException extends java.lang.IllegalStateException {
method @NonNull public String getDiagnosticInfo();
}
@@ -24056,13 +24097,70 @@ package android.media.effect {
package android.media.metrics {
+ public abstract class Event {
+ ctor protected Event(long);
+ method @IntRange(from=0xffffffff) public long getTimeSinceCreatedMillis();
+ }
+
public class MediaMetricsManager {
method @NonNull public android.media.metrics.PlaybackSession createPlaybackSession();
+ field public static final long INVALID_TIMESTAMP = -1L; // 0xffffffffffffffffL
+ }
+
+ public final class PlaybackErrorEvent extends android.media.metrics.Event implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getErrorCode();
+ method @IntRange(from=java.lang.Integer.MIN_VALUE, to=java.lang.Integer.MAX_VALUE) public int getSubErrorCode();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.media.metrics.PlaybackErrorEvent> CREATOR;
+ field public static final int ERROR_CODE_OTHER = 1; // 0x1
+ field public static final int ERROR_CODE_RUNTIME = 2; // 0x2
+ field public static final int ERROR_CODE_UNKNOWN = 0; // 0x0
+ }
+
+ public static final class PlaybackErrorEvent.Builder {
+ ctor public PlaybackErrorEvent.Builder();
+ method @NonNull public android.media.metrics.PlaybackErrorEvent build();
+ method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setErrorCode(int);
+ method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setException(@NonNull Exception);
+ method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setSubErrorCode(@IntRange(from=java.lang.Integer.MIN_VALUE, to=java.lang.Integer.MAX_VALUE) int);
+ method @NonNull public android.media.metrics.PlaybackErrorEvent.Builder setTimeSinceCreatedMillis(@IntRange(from=0xffffffff) long);
}
public final class PlaybackSession implements java.lang.AutoCloseable {
method public void close();
method @NonNull public String getId();
+ method public void reportPlaybackErrorEvent(@NonNull android.media.metrics.PlaybackErrorEvent);
+ method public void reportPlaybackStateEvent(@NonNull android.media.metrics.PlaybackStateEvent);
+ }
+
+ public final class PlaybackStateEvent extends android.media.metrics.Event implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getState();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.media.metrics.PlaybackStateEvent> CREATOR;
+ field public static final int STATE_ABANDONED = 15; // 0xf
+ field public static final int STATE_BUFFERING = 6; // 0x6
+ field public static final int STATE_ENDED = 11; // 0xb
+ field public static final int STATE_FAILED = 13; // 0xd
+ field public static final int STATE_INTERRUPTED_BY_AD = 14; // 0xe
+ field public static final int STATE_JOINING_BACKGROUND = 1; // 0x1
+ field public static final int STATE_JOINING_FOREGROUND = 2; // 0x2
+ field public static final int STATE_NOT_STARTED = 0; // 0x0
+ field public static final int STATE_PAUSED = 4; // 0x4
+ field public static final int STATE_PAUSED_BUFFERING = 7; // 0x7
+ field public static final int STATE_PLAYING = 3; // 0x3
+ field public static final int STATE_SEEKING = 5; // 0x5
+ field public static final int STATE_STOPPED = 12; // 0xc
+ field public static final int STATE_SUPPRESSED = 9; // 0x9
+ field public static final int STATE_SUPPRESSED_BUFFERING = 10; // 0xa
+ }
+
+ public static final class PlaybackStateEvent.Builder {
+ ctor public PlaybackStateEvent.Builder();
+ method @NonNull public android.media.metrics.PlaybackStateEvent build();
+ method @NonNull public android.media.metrics.PlaybackStateEvent.Builder setState(int);
+ method @NonNull public android.media.metrics.PlaybackStateEvent.Builder setTimeSinceCreatedMillis(@IntRange(from=0xffffffff) long);
}
}
@@ -26703,6 +26801,46 @@ package android.net.sip {
}
+package android.net.vcn {
+
+ public final class VcnConfig implements android.os.Parcelable {
+ method public int describeContents();
+ method @NonNull public java.util.Set<android.net.vcn.VcnGatewayConnectionConfig> getGatewayConnectionConfigs();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.net.vcn.VcnConfig> CREATOR;
+ }
+
+ public static final class VcnConfig.Builder {
+ ctor public VcnConfig.Builder(@NonNull android.content.Context);
+ method @NonNull public android.net.vcn.VcnConfig.Builder addGatewayConnectionConfig(@NonNull android.net.vcn.VcnGatewayConnectionConfig);
+ method @NonNull public android.net.vcn.VcnConfig build();
+ }
+
+ public final class VcnGatewayConnectionConfig {
+ method @NonNull public int[] getExposedCapabilities();
+ method @IntRange(from=android.net.vcn.VcnGatewayConnectionConfig.MIN_MTU_V6) public int getMaxMtu();
+ method @NonNull public int[] getRequiredUnderlyingCapabilities();
+ method @NonNull public long[] getRetryInterval();
+ }
+
+ public static final class VcnGatewayConnectionConfig.Builder {
+ ctor public VcnGatewayConnectionConfig.Builder();
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addExposedCapability(int);
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addRequiredUnderlyingCapability(int);
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig build();
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int);
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeRequiredUnderlyingCapability(int);
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setMaxMtu(@IntRange(from=android.net.vcn.VcnGatewayConnectionConfig.MIN_MTU_V6) int);
+ method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setRetryInterval(@NonNull long[]);
+ }
+
+ public class VcnManager {
+ method @RequiresPermission("carrier privileges") public void clearVcnConfig(@NonNull android.os.ParcelUuid) throws java.io.IOException;
+ method @RequiresPermission("carrier privileges") public void setVcnConfig(@NonNull android.os.ParcelUuid, @NonNull android.net.vcn.VcnConfig) throws java.io.IOException;
+ }
+
+}
+
package android.nfc {
public class FormatException extends java.lang.Exception {
@@ -34710,6 +34848,7 @@ package android.provider {
field public static final String EXTRA_AUTHORITIES = "authorities";
field public static final String EXTRA_BATTERY_SAVER_MODE_ENABLED = "android.settings.extra.battery_saver_mode_enabled";
field public static final String EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED = "android.provider.extra.BIOMETRIC_AUTHENTICATORS_ALLOWED";
+ field public static final String EXTRA_CHANNEL_FILTER_LIST = "android.provider.extra.CHANNEL_FILTER_LIST";
field public static final String EXTRA_CHANNEL_ID = "android.provider.extra.CHANNEL_ID";
field public static final String EXTRA_CONVERSATION_ID = "android.provider.extra.CONVERSATION_ID";
field public static final String EXTRA_DO_NOT_DISTURB_MODE_ENABLED = "android.settings.extra.do_not_disturb_mode_enabled";
@@ -35050,30 +35189,18 @@ package android.provider {
public static final class SimPhonebookContract.SimRecords {
method @NonNull public static android.net.Uri getContentUri(int, int);
+ method @WorkerThread public static int getEncodedNameLength(@NonNull android.content.ContentResolver, @NonNull String);
method @NonNull public static android.net.Uri getItemUri(int, int, int);
- method @NonNull @WorkerThread public static android.provider.SimPhonebookContract.SimRecords.NameValidationResult validateName(@NonNull android.content.ContentResolver, int, int, @NonNull String);
field public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sim-contact_v2";
field public static final String CONTENT_TYPE = "vnd.android.cursor.dir/sim-contact_v2";
field public static final String ELEMENTARY_FILE_TYPE = "elementary_file_type";
+ field public static final int ERROR_NAME_UNSUPPORTED = -1; // 0xffffffff
field public static final String NAME = "name";
field public static final String PHONE_NUMBER = "phone_number";
field public static final String RECORD_NUMBER = "record_number";
field public static final String SUBSCRIPTION_ID = "subscription_id";
}
- public static final class SimPhonebookContract.SimRecords.NameValidationResult implements android.os.Parcelable {
- ctor public SimPhonebookContract.SimRecords.NameValidationResult(@NonNull String, @NonNull String, int, int);
- method public int describeContents();
- method public int getEncodedLength();
- method public int getMaxEncodedLength();
- method @NonNull public String getName();
- method @NonNull public String getSanitizedName();
- method public boolean isSupportedCharacter(int);
- method public boolean isValid();
- method public void writeToParcel(@NonNull android.os.Parcel, int);
- field @NonNull public static final android.os.Parcelable.Creator<android.provider.SimPhonebookContract.SimRecords.NameValidationResult> CREATOR;
- }
-
public class SyncStateContract {
ctor public SyncStateContract();
}
@@ -39127,16 +39254,22 @@ package android.telecom {
}
public static class CallScreeningService.CallResponse {
+ method public int getCallComposerAttachmentsToShow();
method public boolean getDisallowCall();
method public boolean getRejectCall();
method public boolean getSilenceCall();
method public boolean getSkipCallLog();
method public boolean getSkipNotification();
+ field public static final int CALL_COMPOSER_ATTACHMENT_LOCATION = 2; // 0x2
+ field public static final int CALL_COMPOSER_ATTACHMENT_PICTURE = 1; // 0x1
+ field public static final int CALL_COMPOSER_ATTACHMENT_PRIORITY = 8; // 0x8
+ field public static final int CALL_COMPOSER_ATTACHMENT_SUBJECT = 4; // 0x4
}
public static class CallScreeningService.CallResponse.Builder {
ctor public CallScreeningService.CallResponse.Builder();
method public android.telecom.CallScreeningService.CallResponse build();
+ method @NonNull public android.telecom.CallScreeningService.CallResponse.Builder setCallComposerAttachmentsToShow(int);
method public android.telecom.CallScreeningService.CallResponse.Builder setDisallowCall(boolean);
method public android.telecom.CallScreeningService.CallResponse.Builder setRejectCall(boolean);
method @NonNull public android.telecom.CallScreeningService.CallResponse.Builder setSilenceCall(boolean);
@@ -46380,8 +46513,10 @@ package android.view {
method public long getMetric(int);
field public static final int ANIMATION_DURATION = 2; // 0x2
field public static final int COMMAND_ISSUE_DURATION = 6; // 0x6
+ field public static final int DEADLINE = 13; // 0xd
field public static final int DRAW_DURATION = 4; // 0x4
field public static final int FIRST_DRAW_FRAME = 9; // 0x9
+ field public static final int GPU_DURATION = 12; // 0xc
field public static final int INPUT_HANDLING_DURATION = 1; // 0x1
field public static final int INTENDED_VSYNC_TIMESTAMP = 10; // 0xa
field public static final int LAYOUT_MEASURE_DURATION = 3; // 0x3
@@ -54635,6 +54770,7 @@ package android.widget {
public class RemoteViews implements android.view.LayoutInflater.Filter android.os.Parcelable {
ctor public RemoteViews(String, int);
ctor public RemoteViews(android.widget.RemoteViews, android.widget.RemoteViews);
+ ctor public RemoteViews(@NonNull java.util.Map<android.graphics.PointF,android.widget.RemoteViews>);
ctor public RemoteViews(android.widget.RemoteViews);
ctor public RemoteViews(android.os.Parcel);
method public void addView(@IdRes int, android.widget.RemoteViews);
@@ -54649,6 +54785,7 @@ package android.widget {
method public void setAccessibilityTraversalAfter(@IdRes int, @IdRes int);
method public void setAccessibilityTraversalBefore(@IdRes int, @IdRes int);
method public void setBitmap(@IdRes int, String, android.graphics.Bitmap);
+ method public void setBlendMode(@IdRes int, @NonNull String, @Nullable android.graphics.BlendMode);
method public void setBoolean(@IdRes int, String, boolean);
method public void setBundle(@IdRes int, String, android.os.Bundle);
method public void setByte(@IdRes int, String, byte);
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt
index 51d513966140..de02d0bb7e98 100644
--- a/core/api/module-lib-current.txt
+++ b/core/api/module-lib-current.txt
@@ -73,6 +73,7 @@ package android.hardware.usb {
public class UsbManager {
method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int getGadgetHalVersion();
method public int getUsbBandwidth();
+ method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int getUsbHalVersion();
field public static final int GADGET_HAL_NOT_SUPPORTED = -1; // 0xffffffff
field public static final int GADGET_HAL_V1_0 = 10; // 0xa
field public static final int GADGET_HAL_V1_1 = 11; // 0xb
@@ -85,6 +86,11 @@ package android.hardware.usb {
field public static final int USB_DATA_TRANSFER_RATE_HIGH_SPEED = 480; // 0x1e0
field public static final int USB_DATA_TRANSFER_RATE_LOW_SPEED = 2; // 0x2
field public static final int USB_DATA_TRANSFER_RATE_UNKNOWN = -1; // 0xffffffff
+ field public static final int USB_HAL_NOT_SUPPORTED = -1; // 0xffffffff
+ field public static final int USB_HAL_V1_0 = 10; // 0xa
+ field public static final int USB_HAL_V1_1 = 11; // 0xb
+ field public static final int USB_HAL_V1_2 = 12; // 0xc
+ field public static final int USB_HAL_V1_3 = 13; // 0xd
}
}
@@ -211,6 +217,7 @@ package android.net {
method @NonNull public android.net.TestNetworkInterface createTunInterface(@NonNull java.util.Collection<android.net.LinkAddress>);
method public void setupTestNetwork(@NonNull String, @NonNull android.os.IBinder);
method public void teardownTestNetwork(@NonNull android.net.Network);
+ field public static final String TEST_TAP_PREFIX = "testtap";
}
public final class UnderlyingNetworkInfo implements android.os.Parcelable {
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index f5a22543f940..b53ea2ee8451 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -14,6 +14,7 @@ package android {
field public static final String ACCESS_MTP = "android.permission.ACCESS_MTP";
field public static final String ACCESS_NETWORK_CONDITIONS = "android.permission.ACCESS_NETWORK_CONDITIONS";
field public static final String ACCESS_NOTIFICATIONS = "android.permission.ACCESS_NOTIFICATIONS";
+ field public static final String ACCESS_RCS_USER_CAPABILITY_EXCHANGE = "android.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE";
field public static final String ACCESS_SHARED_LIBRARIES = "android.permission.ACCESS_SHARED_LIBRARIES";
field public static final String ACCESS_SHORTCUTS = "android.permission.ACCESS_SHORTCUTS";
field public static final String ACCESS_SURFACE_FLINGER = "android.permission.ACCESS_SURFACE_FLINGER";
@@ -27,6 +28,7 @@ package android {
field public static final String AMBIENT_WALLPAPER = "android.permission.AMBIENT_WALLPAPER";
field public static final String APPROVE_INCIDENT_REPORTS = "android.permission.APPROVE_INCIDENT_REPORTS";
field public static final String BACKUP = "android.permission.BACKUP";
+ field public static final String BATTERY_PREDICTION = "android.permission.BATTERY_PREDICTION";
field public static final String BIND_ATTENTION_SERVICE = "android.permission.BIND_ATTENTION_SERVICE";
field public static final String BIND_AUGMENTED_AUTOFILL_SERVICE = "android.permission.BIND_AUGMENTED_AUTOFILL_SERVICE";
field public static final String BIND_CELL_BROADCAST_SERVICE = "android.permission.BIND_CELL_BROADCAST_SERVICE";
@@ -196,6 +198,7 @@ package android {
field public static final String READ_INSTALL_SESSIONS = "android.permission.READ_INSTALL_SESSIONS";
field public static final String READ_NETWORK_USAGE_HISTORY = "android.permission.READ_NETWORK_USAGE_HISTORY";
field public static final String READ_OEM_UNLOCK_STATE = "android.permission.READ_OEM_UNLOCK_STATE";
+ field public static final String READ_PEOPLE_DATA = "android.permission.READ_PEOPLE_DATA";
field public static final String READ_PRINT_SERVICES = "android.permission.READ_PRINT_SERVICES";
field public static final String READ_PRINT_SERVICE_RECOMMENDATIONS = "android.permission.READ_PRINT_SERVICE_RECOMMENDATIONS";
field public static final String READ_PRIVILEGED_PHONE_STATE = "android.permission.READ_PRIVILEGED_PHONE_STATE";
@@ -270,6 +273,7 @@ package android {
field public static final String UPGRADE_RUNTIME_PERMISSIONS = "android.permission.UPGRADE_RUNTIME_PERMISSIONS";
field public static final String USER_ACTIVITY = "android.permission.USER_ACTIVITY";
field public static final String USE_RESERVED_DISK = "android.permission.USE_RESERVED_DISK";
+ field public static final String UWB_PRIVILEGED = "android.permission.UWB_PRIVILEGED";
field public static final String WHITELIST_AUTO_REVOKE_PERMISSIONS = "android.permission.WHITELIST_AUTO_REVOKE_PERMISSIONS";
field public static final String WHITELIST_RESTRICTED_PERMISSIONS = "android.permission.WHITELIST_RESTRICTED_PERMISSIONS";
field public static final String WIFI_ACCESS_COEX_UNSAFE_CHANNELS = "android.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS";
@@ -342,7 +346,9 @@ package android {
field public static final int config_helpPackageNameValue = 17039388; // 0x104001c
field public static final int config_systemAutomotiveCluster = 17039400; // 0x1040028
field public static final int config_systemAutomotiveProjection = 17039401; // 0x1040029
+ field public static final int config_systemContacts = 17039403; // 0x104002b
field public static final int config_systemGallery = 17039399; // 0x1040027
+ field public static final int config_systemShell = 17039402; // 0x104002a
}
public static final class R.style {
@@ -680,6 +686,7 @@ package android.app {
}
public static class Notification.Action implements android.os.Parcelable {
+ field public static final int SEMANTIC_ACTION_CONVERSATION_IS_PHISHING = 12; // 0xc
field public static final int SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY = 11; // 0xb
}
@@ -1272,6 +1279,14 @@ package android.app.job {
}
+package android.app.people {
+
+ public final class PeopleManager {
+ method @RequiresPermission(android.Manifest.permission.READ_PEOPLE_DATA) public boolean isConversation(@NonNull String, @NonNull String);
+ }
+
+}
+
package android.app.prediction {
public final class AppPredictionContext implements android.os.Parcelable {
@@ -1851,6 +1866,7 @@ package android.bluetooth {
}
public final class BluetoothDevice implements android.os.Parcelable {
+ method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean canBondWithoutDialog();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean cancelBondProcess();
method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getSimAccessPermission();
@@ -2119,6 +2135,7 @@ package android.content {
field public static final String OEM_LOCK_SERVICE = "oem_lock";
field public static final String PERMISSION_SERVICE = "permission";
field public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
+ field public static final String REBOOT_READINESS_SERVICE = "reboot_readiness";
field public static final String ROLLBACK_SERVICE = "rollback";
field public static final String SEARCH_UI_SERVICE = "search_ui";
field public static final String SECURE_ELEMENT_SERVICE = "secure_element";
@@ -2814,16 +2831,49 @@ package android.debug {
package android.graphics.fonts {
+ public final class FontFamilyUpdateRequest {
+ method @NonNull public java.util.List<android.graphics.fonts.FontFamilyUpdateRequest.FontFamily> getFontFamilies();
+ method @NonNull public java.util.List<android.graphics.fonts.FontFileUpdateRequest> getFontFileUpdateRequests();
+ }
+
+ public static final class FontFamilyUpdateRequest.Builder {
+ ctor public FontFamilyUpdateRequest.Builder();
+ method @NonNull public android.graphics.fonts.FontFamilyUpdateRequest.Builder addFontFamily(@NonNull android.graphics.fonts.FontFamilyUpdateRequest.FontFamily);
+ method @NonNull public android.graphics.fonts.FontFamilyUpdateRequest.Builder addFontFileUpdateRequest(@NonNull android.graphics.fonts.FontFileUpdateRequest);
+ method @NonNull public android.graphics.fonts.FontFamilyUpdateRequest build();
+ }
+
+ public static final class FontFamilyUpdateRequest.Font {
+ ctor public FontFamilyUpdateRequest.Font(@NonNull String, @NonNull android.graphics.fonts.FontStyle, @NonNull java.util.List<android.graphics.fonts.FontVariationAxis>);
+ method @NonNull public java.util.List<android.graphics.fonts.FontVariationAxis> getAxes();
+ method @NonNull public String getPostScriptName();
+ method @NonNull public android.graphics.fonts.FontStyle getStyle();
+ }
+
+ public static final class FontFamilyUpdateRequest.FontFamily {
+ ctor public FontFamilyUpdateRequest.FontFamily(@NonNull String, @NonNull java.util.List<android.graphics.fonts.FontFamilyUpdateRequest.Font>);
+ method @NonNull public java.util.List<android.graphics.fonts.FontFamilyUpdateRequest.Font> getFonts();
+ method @NonNull public String getName();
+ }
+
+ public final class FontFileUpdateRequest {
+ ctor public FontFileUpdateRequest(@NonNull android.os.ParcelFileDescriptor, @NonNull byte[]);
+ method @NonNull public android.os.ParcelFileDescriptor getParcelFileDescriptor();
+ method @NonNull public byte[] getSignature();
+ }
+
public class FontManager {
method @Nullable public android.text.FontConfig getFontConfig();
- method @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFile(@NonNull android.os.ParcelFileDescriptor, @NonNull byte[], @IntRange(from=0) int);
+ method @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFamily(@NonNull android.graphics.fonts.FontFamilyUpdateRequest, @IntRange(from=0) int);
+ method @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFile(@NonNull android.graphics.fonts.FontFileUpdateRequest, @IntRange(from=0) int);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFile(@NonNull android.os.ParcelFileDescriptor, @NonNull byte[], @IntRange(from=0) int);
field public static final int RESULT_ERROR_DOWNGRADING = -5; // 0xfffffffb
field public static final int RESULT_ERROR_FAILED_TO_WRITE_FONT_FILE = -1; // 0xffffffff
field public static final int RESULT_ERROR_FAILED_UPDATE_CONFIG = -6; // 0xfffffffa
+ field public static final int RESULT_ERROR_FONT_NOT_FOUND = -9; // 0xfffffff7
field public static final int RESULT_ERROR_FONT_UPDATER_DISABLED = -7; // 0xfffffff9
field public static final int RESULT_ERROR_INVALID_FONT_FILE = -3; // 0xfffffffd
field public static final int RESULT_ERROR_INVALID_FONT_NAME = -4; // 0xfffffffc
- field public static final int RESULT_ERROR_REMOTE_EXCEPTION = -9; // 0xfffffff7
field public static final int RESULT_ERROR_VERIFICATION_FAILURE = -2; // 0xfffffffe
field public static final int RESULT_ERROR_VERSION_MISMATCH = -8; // 0xfffffff8
field public static final int RESULT_SUCCESS = 0; // 0x0
@@ -3506,6 +3556,7 @@ package android.hardware.location {
field public static final int RESULT_FAILED_BAD_PARAMS = 2; // 0x2
field public static final int RESULT_FAILED_BUSY = 4; // 0x4
field public static final int RESULT_FAILED_HAL_UNAVAILABLE = 8; // 0x8
+ field public static final int RESULT_FAILED_PERMISSION_DENIED = 9; // 0x9
field public static final int RESULT_FAILED_SERVICE_INTERNAL_FAILURE = 7; // 0x7
field public static final int RESULT_FAILED_TIMEOUT = 6; // 0x6
field public static final int RESULT_FAILED_UNINITIALIZED = 3; // 0x3
@@ -8529,7 +8580,7 @@ package android.os {
method @RequiresPermission(android.Manifest.permission.READ_DREAM_STATE) public boolean isAmbientDisplaySuppressedForToken(@NonNull String);
method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setAdaptivePowerSaveEnabled(boolean);
method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setAdaptivePowerSavePolicy(@NonNull android.os.BatterySaverPolicyConfig);
- method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public void setBatteryDischargePrediction(@NonNull java.time.Duration, boolean);
+ method @RequiresPermission(anyOf={android.Manifest.permission.BATTERY_PREDICTION, android.Manifest.permission.DEVICE_POWER}) public void setBatteryDischargePrediction(@NonNull java.time.Duration, boolean);
method @RequiresPermission(android.Manifest.permission.POWER_SAVER) public boolean setDynamicPowerSaveHint(boolean, int);
method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setFullPowerSavePolicy(@NonNull android.os.BatterySaverPolicyConfig);
method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setPowerSaveModeEnabled(boolean);
@@ -8910,6 +8961,16 @@ package android.os.storage {
package android.permission {
+ public final class AdminPermissionControlParams implements android.os.Parcelable {
+ method public boolean canAdminGrantSensorsPermissions();
+ method public int describeContents();
+ method public int getGrantState();
+ method @NonNull public String getGranteePackageName();
+ method @NonNull public String getPermission();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.permission.AdminPermissionControlParams> CREATOR;
+ }
+
public final class PermissionControllerManager {
method @RequiresPermission(anyOf={android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS, android.Manifest.permission.RESTORE_RUNTIME_PERMISSIONS}) public void applyStagedRuntimePermissionBackup(@NonNull String, @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
method @RequiresPermission(android.Manifest.permission.GET_RUNTIME_PERMISSIONS) public void getRuntimePermissionBackup(@NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<byte[]>);
@@ -8941,7 +9002,8 @@ package android.permission {
method @Deprecated @BinderThread public void onRestoreRuntimePermissionsBackup(@NonNull android.os.UserHandle, @NonNull java.io.InputStream, @NonNull Runnable);
method @BinderThread public abstract void onRevokeRuntimePermission(@NonNull String, @NonNull String, @NonNull Runnable);
method @BinderThread public abstract void onRevokeRuntimePermissions(@NonNull java.util.Map<java.lang.String,java.util.List<java.lang.String>>, boolean, int, @NonNull String, @NonNull java.util.function.Consumer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>);
- method @BinderThread public abstract void onSetRuntimePermissionGrantStateByDeviceAdmin(@NonNull String, @NonNull String, @NonNull String, int, @NonNull java.util.function.Consumer<java.lang.Boolean>);
+ method @Deprecated @BinderThread public abstract void onSetRuntimePermissionGrantStateByDeviceAdmin(@NonNull String, @NonNull String, @NonNull String, int, @NonNull java.util.function.Consumer<java.lang.Boolean>);
+ method @BinderThread public void onSetRuntimePermissionGrantStateByDeviceAdmin(@NonNull String, @NonNull android.permission.AdminPermissionControlParams, @NonNull java.util.function.Consumer<java.lang.Boolean>);
method @BinderThread public void onStageAndApplyRuntimePermissionsBackup(@NonNull android.os.UserHandle, @NonNull java.io.InputStream, @NonNull Runnable);
method @BinderThread public void onUpdateUserSensitivePermissionFlags(int, @NonNull java.util.concurrent.Executor, @NonNull Runnable);
method @BinderThread public void onUpdateUserSensitivePermissionFlags(int, @NonNull Runnable);
@@ -9412,22 +9474,8 @@ package android.provider {
method @RequiresPermission(android.Manifest.permission.MODIFY_SETTINGS_OVERRIDEABLE_BY_RESTORE) public static boolean putString(@NonNull android.content.ContentResolver, @NonNull String, @Nullable String, boolean);
}
- public final class SimPhonebookContract {
- method @NonNull public static String getEfUriPath(int);
- field public static final String SUBSCRIPTION_ID_PATH_SEGMENT = "subid";
- }
-
- public static final class SimPhonebookContract.ElementaryFiles {
- field public static final String EF_ADN_PATH_SEGMENT = "adn";
- field public static final String EF_FDN_PATH_SEGMENT = "fdn";
- field public static final String EF_SDN_PATH_SEGMENT = "sdn";
- field public static final String ELEMENTARY_FILES_PATH_SEGMENT = "elementary_files";
- }
-
public static final class SimPhonebookContract.SimRecords {
- field public static final String EXTRA_NAME_VALIDATION_RESULT = "android.provider.extra.NAME_VALIDATION_RESULT";
field public static final String QUERY_ARG_PIN2 = "android:query-arg-pin2";
- field public static final String VALIDATE_NAME_PATH_SEGMENT = "validate_name";
}
public static final class Telephony.Carriers implements android.provider.BaseColumns {
@@ -10721,7 +10769,7 @@ package android.telecom {
method @Nullable public android.telecom.PhoneAccountHandle getPhoneAccountHandle();
method @Nullable public final String getTelecomCallId();
method @Deprecated public void onAudioStateChanged(android.telecom.AudioState);
- method @RequiresPermission(android.Manifest.permission.READ_CONTACTS) public void onCallFilteringCompleted(boolean, boolean);
+ method @RequiresPermission(android.Manifest.permission.READ_CONTACTS) public void onCallFilteringCompleted(boolean, boolean, @Nullable android.telecom.CallScreeningService.CallResponse, boolean);
method public final void resetConnectionTime();
method public void setCallDirection(int);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public final void setConnectTimeMillis(@IntRange(from=0) long);
@@ -10898,7 +10946,7 @@ package android.telecom {
}
public final class RemoteConnection {
- method @RequiresPermission(android.Manifest.permission.READ_CONTACTS) public void onCallFilteringCompleted(boolean, boolean);
+ method @RequiresPermission(android.Manifest.permission.READ_CONTACTS) public void onCallFilteringCompleted(boolean, boolean, @Nullable android.telecom.CallScreeningService.CallResponse, boolean);
method @Deprecated public void setAudioState(android.telecom.AudioState);
}
@@ -14178,10 +14226,10 @@ package android.uwb {
}
public final class RangingSession implements java.lang.AutoCloseable {
- method public void close();
- method public void reconfigure(@NonNull android.os.PersistableBundle);
- method public void start(@NonNull android.os.PersistableBundle);
- method public void stop();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void close();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void reconfigure(@NonNull android.os.PersistableBundle);
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void start(@NonNull android.os.PersistableBundle);
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void stop();
}
public static interface RangingSession.Callback {
@@ -14217,18 +14265,18 @@ package android.uwb {
}
public final class UwbManager {
- method public long elapsedRealtimeResolutionNanos();
- method public int getAngleOfArrivalSupport();
- method public int getMaxRemoteDevicesPerInitiatorSession();
- method public int getMaxRemoteDevicesPerResponderSession();
- method public int getMaxSimultaneousSessions();
- method @NonNull public android.os.PersistableBundle getSpecificationInfo();
- method @NonNull public java.util.List<java.lang.Integer> getSupportedChannelNumbers();
- method @NonNull public java.util.Set<java.lang.Integer> getSupportedPreambleCodeIndices();
- method public boolean isRangingSupported();
- method @NonNull public AutoCloseable openRangingSession(@NonNull android.os.PersistableBundle, @NonNull java.util.concurrent.Executor, @NonNull android.uwb.RangingSession.Callback);
- method public void registerAdapterStateCallback(@NonNull java.util.concurrent.Executor, @NonNull android.uwb.UwbManager.AdapterStateCallback);
- method public void unregisterAdapterStateCallback(@NonNull android.uwb.UwbManager.AdapterStateCallback);
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public long elapsedRealtimeResolutionNanos();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public int getAngleOfArrivalSupport();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public int getMaxRemoteDevicesPerInitiatorSession();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public int getMaxRemoteDevicesPerResponderSession();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public int getMaxSimultaneousSessions();
+ method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public android.os.PersistableBundle getSpecificationInfo();
+ method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public java.util.List<java.lang.Integer> getSupportedChannelNumbers();
+ method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public java.util.Set<java.lang.Integer> getSupportedPreambleCodeIndices();
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public boolean isRangingSupported();
+ method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public AutoCloseable openRangingSession(@NonNull android.os.PersistableBundle, @NonNull java.util.concurrent.Executor, @NonNull android.uwb.RangingSession.Callback);
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void registerAdapterStateCallback(@NonNull java.util.concurrent.Executor, @NonNull android.uwb.UwbManager.AdapterStateCallback);
+ method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void unregisterAdapterStateCallback(@NonNull android.uwb.UwbManager.AdapterStateCallback);
field public static final int ANGLE_OF_ARRIVAL_SUPPORT_TYPE_2D = 2; // 0x2
field public static final int ANGLE_OF_ARRIVAL_SUPPORT_TYPE_3D_HEMISPHERICAL = 3; // 0x3
field public static final int ANGLE_OF_ARRIVAL_SUPPORT_TYPE_3D_SPHERICAL = 4; // 0x4
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 29be5c6e4681..c03f660c21b8 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -837,14 +837,16 @@ package android.graphics.fonts {
public class FontManager {
method @Nullable public android.text.FontConfig getFontConfig();
- method @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFile(@NonNull android.os.ParcelFileDescriptor, @NonNull byte[], @IntRange(from=0) int);
+ method @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFamily(@NonNull android.graphics.fonts.FontFamilyUpdateRequest, @IntRange(from=0) int);
+ method @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFile(@NonNull android.graphics.fonts.FontFileUpdateRequest, @IntRange(from=0) int);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.UPDATE_FONTS) public int updateFontFile(@NonNull android.os.ParcelFileDescriptor, @NonNull byte[], @IntRange(from=0) int);
field public static final int RESULT_ERROR_DOWNGRADING = -5; // 0xfffffffb
field public static final int RESULT_ERROR_FAILED_TO_WRITE_FONT_FILE = -1; // 0xffffffff
field public static final int RESULT_ERROR_FAILED_UPDATE_CONFIG = -6; // 0xfffffffa
+ field public static final int RESULT_ERROR_FONT_NOT_FOUND = -9; // 0xfffffff7
field public static final int RESULT_ERROR_FONT_UPDATER_DISABLED = -7; // 0xfffffff9
field public static final int RESULT_ERROR_INVALID_FONT_FILE = -3; // 0xfffffffd
field public static final int RESULT_ERROR_INVALID_FONT_NAME = -4; // 0xfffffffc
- field public static final int RESULT_ERROR_REMOTE_EXCEPTION = -9; // 0xfffffff7
field public static final int RESULT_ERROR_VERIFICATION_FAILURE = -2; // 0xfffffffe
field public static final int RESULT_ERROR_VERSION_MISMATCH = -8; // 0xfffffff8
field public static final int RESULT_SUCCESS = 0; // 0x0
@@ -2568,6 +2570,7 @@ package android.view.inputmethod {
public final class InputMethodManager {
method public int getDisplayId();
+ method public boolean hasActiveInputConnection(@Nullable android.view.View);
method public boolean isInputMethodPickerShown();
}
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 9a20e0fefd33..85fb543a3967 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -16,6 +16,7 @@
package android.app;
+import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.StrictMode.vmIncorrectContextUseEnabled;
@@ -105,6 +106,7 @@ import java.lang.annotation.RetentionPolicy;
import java.nio.ByteOrder;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
@@ -2181,6 +2183,18 @@ class ContextImpl extends Context {
}
}
+ @NonNull
+ @Override
+ public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid,
+ int modeFlags) {
+ try {
+ return ActivityManager.getService().checkUriPermissions(uris, pid, uid, modeFlags,
+ null);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
/** @hide */
@Override
public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags, IBinder callerToken) {
@@ -2207,12 +2221,30 @@ class ContextImpl extends Context {
return PackageManager.PERMISSION_DENIED;
}
+ @NonNull
+ @Override
+ public int[] checkCallingUriPermissions(@NonNull List<Uri> uris, int modeFlags) {
+ int pid = Binder.getCallingPid();
+ if (pid != Process.myPid()) {
+ return checkUriPermissions(uris, pid, Binder.getCallingUid(), modeFlags);
+ }
+ int[] res = new int[uris.size()];
+ Arrays.fill(res, PERMISSION_DENIED);
+ return res;
+ }
+
@Override
public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
return checkUriPermission(uri, Binder.getCallingPid(),
Binder.getCallingUid(), modeFlags);
}
+ @NonNull
+ @Override
+ public int[] checkCallingOrSelfUriPermissions(@NonNull List<Uri> uris, int modeFlags) {
+ return checkUriPermissions(uris, Binder.getCallingPid(), Binder.getCallingUid(), modeFlags);
+ }
+
@Override
public int checkUriPermission(Uri uri, String readPermission,
String writePermission, int pid, int uid, int modeFlags) {
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index e73636fe7fd0..4ad13e1932dd 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -220,6 +220,8 @@ interface IActivityManager {
int getProcessLimit();
int checkUriPermission(in Uri uri, int pid, int uid, int mode, int userId,
in IBinder callerToken);
+ int[] checkUriPermissions(in List<Uri> uris, int pid, int uid, int mode,
+ in IBinder callerToken);
void grantUriPermission(in IApplicationThread caller, in String targetPkg, in Uri uri,
int mode, int userId);
void revokeUriPermission(in IApplicationThread caller, in String targetPkg, in Uri uri,
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index b6fc47f27b05..77daf8ddf08f 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -1604,6 +1604,14 @@ public class Notification implements Parcelable
@SystemApi
public static final int SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY = 11;
+ /**
+ * {@code SemanticAction}: Mark content as a potential phishing attempt.
+ * Note that this is only for use by the notification assistant services.
+ * @hide
+ */
+ @SystemApi
+ public static final int SEMANTIC_ACTION_CONVERSATION_IS_PHISHING = 12;
+
private final Bundle mExtras;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private Icon mIcon;
@@ -2315,7 +2323,8 @@ public class Notification implements Parcelable
SEMANTIC_ACTION_THUMBS_UP,
SEMANTIC_ACTION_THUMBS_DOWN,
SEMANTIC_ACTION_CALL,
- SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY
+ SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY,
+ SEMANTIC_ACTION_CONVERSATION_IS_PHISHING
})
@Retention(RetentionPolicy.SOURCE)
public @interface SemanticAction {}
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java
index 323af8211d76..685c222539c6 100644
--- a/core/java/android/app/NotificationChannel.java
+++ b/core/java/android/app/NotificationChannel.java
@@ -80,6 +80,48 @@ public final class NotificationChannel implements Parcelable {
public static final String PLACEHOLDER_CONVERSATION_ID = ":placeholder_id";
/**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing sound, like a tone picker
+ * ({@link #setSound(Uri, AudioAttributes)}).
+ */
+ public static final String EDIT_SOUND = "sound";
+ /**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing vibration ({@link #enableVibration(boolean)},
+ * {@link #setVibrationPattern(long[])}).
+ */
+ public static final String EDIT_VIBRATION = "vibration";
+ /**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing importance ({@link #setImportance(int)}) and/or conversation
+ * priority.
+ */
+ public static final String EDIT_IMPORTANCE = "importance";
+ /**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing behavior on devices that are locked or have a turned off
+ * display ({@link #setLockscreenVisibility(int)}, {@link #enableLights(boolean)},
+ * {@link #setLightColor(int)}).
+ */
+ public static final String EDIT_LOCKED_DEVICE = "locked";
+ /**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing do not disturb bypass {(@link #setBypassDnd(boolean)}) .
+ */
+ public static final String EDIT_ZEN = "dnd";
+ /**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing conversation settings (demoting or restoring a channel to
+ * be a Conversation, changing bubble behavior, or setting the priority of a conversation).
+ */
+ public static final String EDIT_CONVERSATION = "convo";
+ /**
+ * Extra value for {@link Settings#EXTRA_CHANNEL_FILTER_LIST}. Include to show fields
+ * that have to do with editing launcher behavior (showing badges)}.
+ */
+ public static final String EDIT_LAUNCHER = "launcher";
+
+ /**
* The maximum length for text fields in a NotificationChannel. Fields will be truncated at this
* limit.
*/
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index c047fc21413d..c47b546653b9 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -185,6 +185,7 @@ import android.permission.PermissionControllerManager;
import android.permission.PermissionManager;
import android.print.IPrintManager;
import android.print.PrintManager;
+import android.scheduling.SchedulingFrameworkInitializer;
import android.security.FileIntegrityManager;
import android.security.IFileIntegrityService;
import android.service.oemlock.IOemLockService;
@@ -1440,6 +1441,7 @@ public final class SystemServiceRegistry {
MediaFrameworkPlatformInitializer.registerServiceWrappers();
MediaFrameworkInitializer.registerServiceWrappers();
RoleFrameworkInitializer.registerServiceWrappers();
+ SchedulingFrameworkInitializer.registerServiceWrappers();
} finally {
// If any of the above code throws, we're in a pretty bad shape and the process
// will likely crash, but we'll reset it just in case there's an exception handler...
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 3b80f83aab0d..28242b08ca65 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -1869,13 +1869,13 @@ public class DevicePolicyManager {
/**
* Grants access to {@link #setNetworkLoggingEnabled}, {@link #isNetworkLoggingEnabled} and
* {@link #retrieveNetworkLogs}. Once granted the delegated app will start receiving
- * DelegatedAdminReceiver.onNetworkLogsAvailable() callback, and Device owner will no longer
- * receive the DeviceAdminReceiver.onNetworkLogsAvailable() callback.
+ * DelegatedAdminReceiver.onNetworkLogsAvailable() callback, and Device owner or Profile Owner
+ * will no longer receive the DeviceAdminReceiver.onNetworkLogsAvailable() callback.
* There can be at most one app that has this delegation.
* If another app already had delegated network logging access,
* it will lose the delegation when a new app is delegated.
*
- * <p> Can only be granted by Device Owner.
+ * <p> Can only be granted by Device Owner or Profile Owner of a managed profile.
*/
public static final String DELEGATION_NETWORK_LOGGING = "delegation-network-logging";
@@ -13379,4 +13379,84 @@ public class DevicePolicyManager {
throw re.rethrowFromSystemServer();
}
}
+
+ /**
+ * Called by device owner or profile owner of an organization-owned managed profile to
+ * enable or disable USB data signaling for the device. When disabled, USB data connections
+ * (except from charging functions) are prohibited.
+ *
+ * <p> This API is not supported on all devices, the caller should call
+ * {@link #canUsbDataSignalingBeDisabled()} to check whether enabling or disabling USB data
+ * signaling is supported on the device.
+ *
+ * @param enabled whether USB data signaling should be enabled or not.
+ * @throws SecurityException if the caller is not a device owner or a profile owner on
+ * an organization-owned managed profile.
+ * @throws IllegalStateException if disabling USB data signaling is not supported or
+ * if USB data signaling fails to be enabled/disabled.
+ */
+ public void setUsbDataSignalingEnabled(boolean enabled) {
+ throwIfParentInstance("setUsbDataSignalingEnabled");
+ if (mService != null) {
+ try {
+ mService.setUsbDataSignalingEnabled(mContext.getPackageName(), enabled);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ }
+
+ /**
+ * Called by device owner or profile owner of an organization-owned managed profile to return
+ * whether USB data signaling is currently enabled by the admin.
+ *
+ * @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
+ */
+ public boolean isUsbDataSignalingEnabled() {
+ throwIfParentInstance("isUsbDataSignalingEnabled");
+ if (mService != null) {
+ try {
+ return mService.isUsbDataSignalingEnabled(mContext.getPackageName());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Called by the system to check whether USB data signaling is currently enabled for this user.
+ *
+ * @param userId which user to check for.
+ * @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
+ * @hide
+ */
+ public boolean isUsbDataSignalingEnabledForUser(@UserIdInt int userId) {
+ throwIfParentInstance("isUsbDataSignalingEnabledForUser");
+ if (mService != null) {
+ try {
+ return mService.isUsbDataSignalingEnabledForUser(userId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns whether enabling or disabling USB data signaling is supported on the device.
+ *
+ * @return {@code true} if the device supports enabling and disabling USB data signaling.
+ */
+ public boolean canUsbDataSignalingBeDisabled() {
+ throwIfParentInstance("canUsbDataSignalingBeDisabled");
+ if (mService != null) {
+ try {
+ return mService.canUsbDataSignalingBeDisabled();
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
+ return false;
+ }
}
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 032cf2483cd3..94388cfd41b9 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -502,4 +502,9 @@ interface IDevicePolicyManager {
void resetDefaultCrossProfileIntentFilters(int userId);
boolean canAdminGrantSensorsPermissionsForUser(int userId);
+
+ void setUsbDataSignalingEnabled(String callerPackage, boolean enabled);
+ boolean isUsbDataSignalingEnabled(String callerPackage);
+ boolean isUsbDataSignalingEnabledForUser(int userId);
+ boolean canUsbDataSignalingBeDisabled();
}
diff --git a/core/java/android/app/people/IPeopleManager.aidl b/core/java/android/app/people/IPeopleManager.aidl
index ebe9f60dc150..d000f3b0b01d 100644
--- a/core/java/android/app/people/IPeopleManager.aidl
+++ b/core/java/android/app/people/IPeopleManager.aidl
@@ -49,6 +49,9 @@ interface IPeopleManager {
/** Removes all the recent conversations and uncaches their cached shortcuts. */
void removeAllRecentConversations();
+ /** Returns whether the shortcutId is backed by a Conversation in People Service. */
+ boolean isConversation(in String packageName, int userId, in String shortcutId);
+
/**
* Returns the last interaction with the specified conversation. If the
* conversation can't be found or no interactions have been recorded, returns 0L.
diff --git a/core/java/android/app/people/PeopleManager.java b/core/java/android/app/people/PeopleManager.java
index de7ba622ae88..d348edb6dfbf 100644
--- a/core/java/android/app/people/PeopleManager.java
+++ b/core/java/android/app/people/PeopleManager.java
@@ -17,6 +17,8 @@
package android.app.people;
import android.annotation.NonNull;
+import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.content.Context;
import android.content.pm.ParceledListSlice;
@@ -53,6 +55,33 @@ public final class PeopleManager {
Context.PEOPLE_SERVICE));
}
+ /**
+ * Returns whether a shortcut has a conversation associated.
+ *
+ * <p>Requires android.permission.READ_PEOPLE_DATA permission.
+ *
+ * <p>This method may return different results for the same shortcut over time, as an app adopts
+ * conversation features or if a user hasn't communicated with the conversation associated to
+ * the shortcut in a while, so the result should not be stored and relied on indefinitely by
+ * clients.
+ *
+ * @param packageName name of the package the conversation is part of
+ * @param shortcutId the shortcut id backing the conversation
+ * @return whether the {@shortcutId} is backed by a Conversation.
+ *
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(android.Manifest.permission.READ_PEOPLE_DATA)
+ public boolean isConversation(@NonNull String packageName, @NonNull String shortcutId) {
+ Preconditions.checkStringNotEmpty(packageName);
+ Preconditions.checkStringNotEmpty(shortcutId);
+ try {
+ return mService.isConversation(packageName, mContext.getUserId(), shortcutId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
/**
* Sets or updates a {@link ConversationStatus} for a conversation.
diff --git a/core/java/android/app/smartspace/SmartspaceAction.java b/core/java/android/app/smartspace/SmartspaceAction.java
index 439d851acea6..f17b044f7996 100644
--- a/core/java/android/app/smartspace/SmartspaceAction.java
+++ b/core/java/android/app/smartspace/SmartspaceAction.java
@@ -89,7 +89,7 @@ public final class SmartspaceAction implements Parcelable {
mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
mIntent = in.readTypedObject(Intent.CREATOR);
mUserHandle = in.readTypedObject(UserHandle.CREATOR);
- mExtras = in.readTypedObject(Bundle.CREATOR);
+ mExtras = in.readBundle();
}
private SmartspaceAction(
diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java
index a3c3a0e106a3..42d90a794e74 100644
--- a/core/java/android/appwidget/AppWidgetHostView.java
+++ b/core/java/android/appwidget/AppWidgetHostView.java
@@ -16,6 +16,7 @@
package android.appwidget;
+import android.annotation.NonNull;
import android.app.Activity;
import android.app.ActivityOptions;
import android.compat.annotation.UnsupportedAppUsage;
@@ -29,6 +30,7 @@ import android.content.pm.LauncherApps;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Color;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
@@ -53,6 +55,7 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.Executor;
/**
@@ -89,6 +92,7 @@ public class AppWidgetHostView extends FrameLayout {
int mLayoutId = -1;
private OnClickHandler mOnClickHandler;
private boolean mOnLightBackground;
+ PointF mCurrentSize = null;
private Executor mAsyncExecutor;
private CancellationSignal mLastExecutionSignal;
@@ -268,7 +272,8 @@ public class AppWidgetHostView extends FrameLayout {
* Provide guidance about the size of this widget to the AppWidgetManager. The widths and
* heights should correspond to the full area the AppWidgetHostView is given. Padding added by
* the framework will be accounted for automatically. This information gets embedded into the
- * AppWidget options and causes a callback to the AppWidgetProvider.
+ * AppWidget options and causes a callback to the AppWidgetProvider. In addition, the list of
+ * sizes is explicitly set to an empty list.
* @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle)
*
* @param newOptions The bundle of options, in addition to the size information,
@@ -277,14 +282,97 @@ public class AppWidgetHostView extends FrameLayout {
* @param minHeight The maximum height in dips that the widget will be displayed at.
* @param maxWidth The maximum width in dips that the widget will be displayed at.
* @param maxHeight The maximum height in dips that the widget will be displayed at.
- *
+ * @deprecated use {@link AppWidgetHostView#updateAppWidgetSize(Bundle, List)} instead.
*/
+ @Deprecated
public void updateAppWidgetSize(Bundle newOptions, int minWidth, int minHeight, int maxWidth,
int maxHeight) {
updateAppWidgetSize(newOptions, minWidth, minHeight, maxWidth, maxHeight, false);
}
/**
+ * Provide guidance about the size of this widget to the AppWidgetManager. The sizes should
+ * correspond to the full area the AppWidgetHostView is given. Padding added by the framework
+ * will be accounted for automatically.
+ *
+ * This method will update the option bundle with the list of sizes and the min/max bounds for
+ * width and height.
+ *
+ * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle)
+ *
+ * @param newOptions The bundle of options, in addition to the size information.
+ * @param sizes Sizes, in dips, the widget may be displayed at without calling the provider
+ * again. Typically, this will be size of the widget in landscape and portrait.
+ * On some foldables, this might include the size on the outer and inner screens.
+ */
+ public void updateAppWidgetSize(@NonNull Bundle newOptions, @NonNull List<PointF> sizes) {
+ AppWidgetManager widgetManager = AppWidgetManager.getInstance(mContext);
+
+ Rect padding = getDefaultPadding();
+ float density = getResources().getDisplayMetrics().density;
+
+ float xPaddingDips = (padding.left + padding.right) / density;
+ float yPaddingDips = (padding.top + padding.bottom) / density;
+
+ ArrayList<PointF> paddedSizes = new ArrayList<>(sizes.size());
+ float minWidth = Float.MAX_VALUE;
+ float maxWidth = 0;
+ float minHeight = Float.MAX_VALUE;
+ float maxHeight = 0;
+ for (int i = 0; i < sizes.size(); i++) {
+ PointF size = sizes.get(i);
+ PointF paddedPoint = new PointF(Math.max(0.f, size.x - xPaddingDips),
+ Math.max(0.f, size.y - yPaddingDips));
+ paddedSizes.add(paddedPoint);
+ minWidth = Math.min(minWidth, paddedPoint.x);
+ maxWidth = Math.max(maxWidth, paddedPoint.x);
+ minHeight = Math.min(minHeight, paddedPoint.y);
+ maxHeight = Math.max(maxHeight, paddedPoint.y);
+ }
+ if (paddedSizes.equals(
+ widgetManager.getAppWidgetOptions(mAppWidgetId).<PointF>getParcelableArrayList(
+ AppWidgetManager.OPTION_APPWIDGET_SIZES))) {
+ return;
+ }
+ Bundle options = newOptions.deepCopy();
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, (int) minWidth);
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, (int) minHeight);
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, (int) maxWidth);
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, (int) maxHeight);
+ options.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, paddedSizes);
+ updateAppWidgetOptions(options);
+ }
+
+ /**
+ * Set the current size of the widget. This should be the full area the AppWidgetHostView is
+ * given. Padding added by the framework will be accounted for automatically.
+ *
+ * This size will be used to choose the appropriate layout the next time the {@link RemoteViews}
+ * is re-inflated, if it was created with {@link RemoteViews#RemoteViews(Map)} .
+ */
+ public void setCurrentSize(@NonNull PointF size) {
+ Rect padding = getDefaultPadding();
+ float density = getResources().getDisplayMetrics().density;
+ float xPaddingDips = (padding.left + padding.right) / density;
+ float yPaddingDips = (padding.top + padding.bottom) / density;
+ PointF newSize = new PointF(size.x - xPaddingDips, size.y - yPaddingDips);
+ if (!newSize.equals(mCurrentSize)) {
+ mCurrentSize = newSize;
+ mLayoutId = -1; // Prevents recycling the view.
+ }
+ }
+
+ /**
+ * Clear the current size, indicating it is not currently known.
+ */
+ public void clearCurrentSize() {
+ if (mCurrentSize != null) {
+ mCurrentSize = null;
+ mLayoutId = -1;
+ }
+ }
+
+ /**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@@ -322,6 +410,8 @@ public class AppWidgetHostView extends FrameLayout {
newOptions.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, newMinHeight);
newOptions.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, newMaxWidth);
newOptions.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, newMaxHeight);
+ newOptions.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES,
+ new ArrayList<PointF>());
updateAppWidgetOptions(newOptions);
}
}
@@ -440,7 +530,7 @@ public class AppWidgetHostView extends FrameLayout {
// Try normal RemoteView inflation
if (content == null) {
try {
- content = remoteViews.apply(mContext, this, mOnClickHandler);
+ content = remoteViews.apply(mContext, this, mOnClickHandler, mCurrentSize);
if (LOGD) Log.d(TAG, "had to inflate new layout");
} catch (RuntimeException e) {
exception = e;
@@ -492,7 +582,8 @@ public class AppWidgetHostView extends FrameLayout {
mView,
mAsyncExecutor,
new ViewApplyListener(remoteViews, layoutId, true),
- mOnClickHandler);
+ mOnClickHandler,
+ mCurrentSize);
} catch (Exception e) {
// Reapply failed. Try apply
}
@@ -502,7 +593,8 @@ public class AppWidgetHostView extends FrameLayout {
this,
mAsyncExecutor,
new ViewApplyListener(remoteViews, layoutId, false),
- mOnClickHandler);
+ mOnClickHandler,
+ mCurrentSize);
}
}
@@ -533,7 +625,8 @@ public class AppWidgetHostView extends FrameLayout {
AppWidgetHostView.this,
mAsyncExecutor,
new ViewApplyListener(mViews, mLayoutId, false),
- mOnClickHandler);
+ mOnClickHandler,
+ mCurrentSize);
} else {
applyContent(null, false, e);
}
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index 37093a10b2f0..aac8710e8691 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -217,6 +217,12 @@ public class AppWidgetManager {
public static final String OPTION_APPWIDGET_MAX_HEIGHT = "appWidgetMaxHeight";
/**
+ * A bundle extra ({@code List<PointF>}) that contains the list of possible sizes, in dips, a
+ * widget instance can take.
+ */
+ public static final String OPTION_APPWIDGET_SIZES = "appWidgetSizes";
+
+ /**
* A bundle extra that hints to the AppWidgetProvider the category of host that owns this
* this widget. Can have the value {@link
* AppWidgetProviderInfo#WIDGET_CATEGORY_HOME_SCREEN} or {@link
diff --git a/core/java/android/appwidget/AppWidgetProviderInfo.java b/core/java/android/appwidget/AppWidgetProviderInfo.java
index 42214d047740..d893a5e49aa9 100644
--- a/core/java/android/appwidget/AppWidgetProviderInfo.java
+++ b/core/java/android/appwidget/AppWidgetProviderInfo.java
@@ -179,6 +179,44 @@ public class AppWidgetProviderInfo implements Parcelable {
public int minResizeHeight;
/**
+ * Maximum width (in dp) which the widget can be resized to. This field has no effect if it is
+ * smaller than minWidth or if horizontal resizing isn't enabled (see {@link #resizeMode}).
+ *
+ * <p>This field corresponds to the <code>android:maxResizeWidth</code> attribute in the
+ * AppWidget meta-data file.
+ */
+ @SuppressLint("MutableBareField")
+ public int maxResizeWidth;
+
+ /**
+ * Maximum height (in dp) which the widget can be resized to. This field has no effect if it is
+ * smaller than minHeight or if vertical resizing isn't enabled (see {@link #resizeMode}).
+ *
+ * <p>This field corresponds to the <code>android:maxResizeHeight</code> attribute in the
+ * AppWidget meta-data file.
+ */
+ @SuppressLint("MutableBareField")
+ public int maxResizeHeight;
+
+ /**
+ * The default width of a widget when added to a host, in units of launcher grid cells.
+ *
+ * <p>This field corresponds to the <code>android:targetCellWidth</code> attribute in the
+ * AppWidget meta-data file.
+ */
+ @SuppressLint("MutableBareField")
+ public int targetCellWidth;
+
+ /**
+ * The default height of a widget when added to a host, in units of launcher grid cells.
+ *
+ * <p>This field corresponds to the <code>android:targetCellHeight</code> attribute in the
+ * AppWidget meta-data file.
+ */
+ @SuppressLint("MutableBareField")
+ public int targetCellHeight;
+
+ /**
* How often, in milliseconds, that this AppWidget wants to be updated.
* The AppWidget manager may place a limit on how often a AppWidget is updated.
*
@@ -330,6 +368,10 @@ public class AppWidgetProviderInfo implements Parcelable {
this.minHeight = in.readInt();
this.minResizeWidth = in.readInt();
this.minResizeHeight = in.readInt();
+ this.maxResizeWidth = in.readInt();
+ this.maxResizeHeight = in.readInt();
+ this.targetCellWidth = in.readInt();
+ this.targetCellHeight = in.readInt();
this.updatePeriodMillis = in.readInt();
this.initialLayout = in.readInt();
this.initialKeyguardLayout = in.readInt();
@@ -440,6 +482,10 @@ public class AppWidgetProviderInfo implements Parcelable {
out.writeInt(this.minHeight);
out.writeInt(this.minResizeWidth);
out.writeInt(this.minResizeHeight);
+ out.writeInt(this.maxResizeWidth);
+ out.writeInt(this.maxResizeHeight);
+ out.writeInt(this.targetCellWidth);
+ out.writeInt(this.targetCellHeight);
out.writeInt(this.updatePeriodMillis);
out.writeInt(this.initialLayout);
out.writeInt(this.initialKeyguardLayout);
@@ -463,8 +509,12 @@ public class AppWidgetProviderInfo implements Parcelable {
that.provider = this.provider == null ? null : this.provider.clone();
that.minWidth = this.minWidth;
that.minHeight = this.minHeight;
- that.minResizeWidth = this.minResizeHeight;
+ that.minResizeWidth = this.minResizeWidth;
that.minResizeHeight = this.minResizeHeight;
+ that.maxResizeWidth = this.maxResizeWidth;
+ that.maxResizeHeight = this.maxResizeHeight;
+ that.targetCellWidth = this.targetCellWidth;
+ that.targetCellHeight = this.targetCellHeight;
that.updatePeriodMillis = this.updatePeriodMillis;
that.initialLayout = this.initialLayout;
that.initialKeyguardLayout = this.initialKeyguardLayout;
@@ -512,6 +562,8 @@ public class AppWidgetProviderInfo implements Parcelable {
minHeight = TypedValue.complexToDimensionPixelSize(minHeight, displayMetrics);
minResizeWidth = TypedValue.complexToDimensionPixelSize(minResizeWidth, displayMetrics);
minResizeHeight = TypedValue.complexToDimensionPixelSize(minResizeHeight, displayMetrics);
+ maxResizeWidth = TypedValue.complexToDimensionPixelSize(maxResizeWidth, displayMetrics);
+ maxResizeHeight = TypedValue.complexToDimensionPixelSize(maxResizeHeight, displayMetrics);
}
/**
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index ea7e5ea7c802..ec46da0dcf0e 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -1654,7 +1654,7 @@ public final class BluetoothAdapter {
mContext = context;
}
- private String getOpPackageName() {
+ String getOpPackageName() {
// Workaround for legacy API for getting a BluetoothAdapter not
// passing a context
if (mContext != null) {
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 3b8dec7bf955..e7661dbad749 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -1236,7 +1236,8 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.createBond(this, transport, oobData);
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ return service.createBond(this, transport, oobData, adapter.getOpPackageName());
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1394,6 +1395,31 @@ public final class BluetoothDevice implements Parcelable {
}
/**
+ * Checks whether this bluetooth device is associated with CDM and meets the criteria to skip
+ * the bluetooth pairing dialog because it has been already consented by the CDM prompt.
+ *
+ * @return true if we can bond without the dialog, false otherwise
+ *
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
+ public boolean canBondWithoutDialog() {
+ final IBluetooth service = sService;
+ if (service == null) {
+ Log.e(TAG, "BT not enabled. Cannot check if we can skip pairing dialog");
+ return false;
+ }
+ try {
+ if (DBG) Log.d(TAG, "canBondWithoutDialog, device: " + this);
+ return service.canBondWithoutDialog(this);
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
+ return false;
+ }
+
+ /**
* Returns whether there is an open connection to this device.
*
* @return True if there is at least one open connection to this device.
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 025d777f2053..10b00f245d79 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -93,6 +93,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.List;
import java.util.concurrent.Executor;
/**
@@ -3520,6 +3521,7 @@ public abstract class Context {
APPWIDGET_SERVICE,
//@hide: VOICE_INTERACTION_MANAGER_SERVICE,
//@hide: BACKUP_SERVICE,
+ REBOOT_READINESS_SERVICE,
ROLLBACK_SERVICE,
DROPBOX_SERVICE,
//@hide: DEVICE_IDLE_CONTROLLER,
@@ -4581,6 +4583,14 @@ public abstract class Context {
public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
/**
+ * Official published name of the (internal) text to speech manager service.
+ *
+ * @hide
+ * @see #getSystemService(String)
+ */
+ public static final String TEXT_TO_SPEECH_MANAGER_SERVICE = "texttospeech";
+
+ /**
* Official published name of the content capture service.
*
* @hide
@@ -4742,6 +4752,17 @@ public abstract class Context {
public static final String ROLLBACK_SERVICE = "rollback";
/**
+ * Use with {@link #getSystemService(String)} to retrieve an
+ * {@link android.app.scheduling.RebootReadinessManagerService} for communicating
+ * with the reboot readiness detector.
+ *
+ * @see #getSystemService(String)
+ * @hide
+ */
+ @SystemApi
+ public static final String REBOOT_READINESS_SERVICE = "reboot_readiness";
+
+ /**
* Use with {@link #getSystemService(String)} to retrieve a
* {@link android.os.DropBoxManager} instance for recording
* diagnostic logs.
@@ -5725,6 +5746,32 @@ public abstract class Context {
public abstract int checkUriPermission(Uri uri, int pid, int uid,
@Intent.AccessUriMode int modeFlags);
+ /**
+ * Determine whether a particular process and user ID has been granted
+ * permission to access a list of URIs. This only checks for permissions
+ * that have been explicitly granted -- if the given process/uid has
+ * more general access to the URI's content provider then this check will
+ * always fail.
+ *
+ * @param uris The list of URIs that is being checked.
+ * @param pid The process ID being checked against. Must be &gt; 0.
+ * @param uid The user ID being checked against. A uid of 0 is the root
+ * user, which will pass every permission check.
+ * @param modeFlags The access modes to check for the list of uris
+ *
+ * @return Array of permission grants corresponding to each entry in the list of uris.
+ * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
+ * or {@link PackageManager#PERMISSION_DENIED} if it is not.
+ *
+ * @see #checkCallingUriPermission
+ */
+ @NonNull
+ @PackageManager.PermissionResult
+ public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid,
+ @Intent.AccessUriMode int modeFlags) {
+ throw new RuntimeException("Not implemented. Must override in a subclass.");
+ }
+
/** @hide */
@SuppressWarnings("HiddenAbstractMethod")
@PackageManager.PermissionResult
@@ -5755,6 +5802,32 @@ public abstract class Context {
public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
/**
+ * Determine whether the calling process and user ID has been
+ * granted permission to access a list of URIs. This is basically
+ * the same as calling {@link #checkUriPermissions(List, int, int, int)}
+ * with the pid and uid returned by {@link
+ * android.os.Binder#getCallingPid} and {@link
+ * android.os.Binder#getCallingUid}. One important difference is
+ * that if you are not currently processing an IPC, this function
+ * will always fail.
+ *
+ * @param uris The list of URIs that is being checked.
+ * @param modeFlags The access modes to check.
+ *
+ * @return Array of permission grants corresponding to each entry in the list of uris.
+ * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
+ * or {@link PackageManager#PERMISSION_DENIED} if it is not.
+ *
+ * @see #checkUriPermission(Uri, int, int, int)
+ */
+ @NonNull
+ @PackageManager.PermissionResult
+ public int[] checkCallingUriPermissions(@NonNull List<Uri> uris,
+ @Intent.AccessUriMode int modeFlags) {
+ throw new RuntimeException("Not implemented. Must override in a subclass.");
+ }
+
+ /**
* Determine whether the calling process of an IPC <em>or you</em> has been granted
* permission to access a specific URI. This is the same as
* {@link #checkCallingUriPermission}, except it grants your own permissions
@@ -5775,6 +5848,28 @@ public abstract class Context {
@Intent.AccessUriMode int modeFlags);
/**
+ * Determine whether the calling process of an IPC <em>or you</em> has been granted
+ * permission to access a list of URIs. This is the same as
+ * {@link #checkCallingUriPermission}, except it grants your own permissions
+ * if you are not currently processing an IPC. Use with care!
+ *
+ * @param uris The list of URIs that is being checked.
+ * @param modeFlags The access modes to check.
+ *
+ * @return Array of permission grants corresponding to each entry in the list of uris.
+ * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
+ * or {@link PackageManager#PERMISSION_DENIED} if it is not.
+ *
+ * @see #checkCallingUriPermission
+ */
+ @NonNull
+ @PackageManager.PermissionResult
+ public int[] checkCallingOrSelfUriPermissions(@NonNull List<Uri> uris,
+ @Intent.AccessUriMode int modeFlags) {
+ throw new RuntimeException("Not implemented. Must override in a subclass.");
+ }
+
+ /**
* Check both a Uri and normal permission. This allows you to perform
* both {@link #checkPermission} and {@link #checkUriPermission} in one
* call.
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index c1c213eee81b..b71fb2712c24 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -53,6 +53,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.List;
import java.util.concurrent.Executor;
/**
@@ -905,6 +906,13 @@ public class ContextWrapper extends Context {
return mBase.checkUriPermission(uri, pid, uid, modeFlags);
}
+ @NonNull
+ @Override
+ public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid,
+ int modeFlags) {
+ return mBase.checkUriPermissions(uris, pid, uid, modeFlags);
+ }
+
/** @hide */
@Override
public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags, IBinder callerToken) {
@@ -916,11 +924,23 @@ public class ContextWrapper extends Context {
return mBase.checkCallingUriPermission(uri, modeFlags);
}
+ @NonNull
+ @Override
+ public int[] checkCallingUriPermissions(@NonNull List<Uri> uris, int modeFlags) {
+ return mBase.checkCallingUriPermissions(uris, modeFlags);
+ }
+
@Override
public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
return mBase.checkCallingOrSelfUriPermission(uri, modeFlags);
}
+ @NonNull
+ @Override
+ public int[] checkCallingOrSelfUriPermissions(@NonNull List<Uri> uris, int modeFlags) {
+ return mBase.checkCallingOrSelfUriPermissions(uris, modeFlags);
+ }
+
@Override
public int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
@Nullable String writePermission, int pid, int uid, int modeFlags) {
diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java
index 0c0e4020d04a..80fecc1a3195 100644
--- a/core/java/android/content/pm/LauncherApps.java
+++ b/core/java/android/content/pm/LauncherApps.java
@@ -167,10 +167,17 @@ public class LauncherApps {
*/
public static final int FLAG_CACHE_BUBBLE_SHORTCUTS = 1;
+ /**
+ * Cache shortcuts which are used in People Tile.
+ * @hide
+ */
+ public static final int FLAG_CACHE_PEOPLE_TILE_SHORTCUTS = 2;
+
/** @hide */
@IntDef(flag = false, prefix = { "FLAG_CACHE_" }, value = {
FLAG_CACHE_NOTIFICATION_SHORTCUTS,
FLAG_CACHE_BUBBLE_SHORTCUTS,
+ FLAG_CACHE_PEOPLE_TILE_SHORTCUTS
})
@Retention(RetentionPolicy.SOURCE)
public @interface ShortcutCacheFlags {}
@@ -1179,6 +1186,7 @@ public class LauncherApps {
* <ul>
* <li>{@link #FLAG_CACHE_NOTIFICATION_SHORTCUTS}
* <li>{@link #FLAG_CACHE_BUBBLE_SHORTCUTS}
+ * <li>{@link #FLAG_CACHE_PEOPLE_TILE_SHORTCUTS}
* </ul>
* @throws IllegalStateException when the user is locked, or when the {@code user} user
* is locked or not running.
@@ -1209,6 +1217,7 @@ public class LauncherApps {
* <ul>
* <li>{@link #FLAG_CACHE_NOTIFICATION_SHORTCUTS}
* <li>{@link #FLAG_CACHE_BUBBLE_SHORTCUTS}
+ * <li>{@link #FLAG_CACHE_PEOPLE_TILE_SHORTCUTS}
* </ul>
* @throws IllegalStateException when the user is locked, or when the {@code user} user
* is locked or not running.
diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java
index ce0547f5d0f4..5f80ba110773 100644
--- a/core/java/android/content/pm/ShortcutInfo.java
+++ b/core/java/android/content/pm/ShortcutInfo.java
@@ -129,6 +129,12 @@ public final class ShortcutInfo implements Parcelable {
/** @hide */
public static final int FLAG_HAS_ICON_URI = 1 << 15;
+ /**
+ * TODO(b/155135057): This is a quick and temporary fix for b/155135890. ShortcutService doesn't
+ * need to be aware of the outside world. Replace this with a more extensible solution.
+ * @hide
+ */
+ public static final int FLAG_CACHED_PEOPLE_TILE = 1 << 29;
/**
* TODO(b/155135057): This is a quick and temporary fix for b/155135890. ShortcutService doesn't
@@ -138,7 +144,8 @@ public final class ShortcutInfo implements Parcelable {
public static final int FLAG_CACHED_BUBBLES = 1 << 30;
/** @hide */
- public static final int FLAG_CACHED_ALL = FLAG_CACHED_NOTIFICATIONS | FLAG_CACHED_BUBBLES;
+ public static final int FLAG_CACHED_ALL =
+ FLAG_CACHED_NOTIFICATIONS | FLAG_CACHED_BUBBLES | FLAG_CACHED_PEOPLE_TILE;
/** @hide */
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
@@ -159,6 +166,7 @@ public final class ShortcutInfo implements Parcelable {
FLAG_HAS_ICON_URI,
FLAG_CACHED_NOTIFICATIONS,
FLAG_CACHED_BUBBLES,
+ FLAG_CACHED_PEOPLE_TILE
})
@Retention(RetentionPolicy.SOURCE)
public @interface ShortcutFlags {}
diff --git a/core/java/android/content/pm/dex/DexMetadataHelper.java b/core/java/android/content/pm/dex/DexMetadataHelper.java
index bf35c4d92d3a..bc5d14a533e2 100644
--- a/core/java/android/content/pm/dex/DexMetadataHelper.java
+++ b/core/java/android/content/pm/dex/DexMetadataHelper.java
@@ -22,17 +22,26 @@ import static android.content.pm.parsing.ApkLiteParseUtils.APK_FILE_EXTENSION;
import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.parsing.ApkLiteParseUtils;
import android.content.pm.parsing.PackageLite;
+import android.os.SystemProperties;
import android.util.ArrayMap;
import android.util.jar.StrictJarFile;
+import android.util.JsonReader;
+import android.util.Log;
+
+import com.android.internal.annotations.VisibleForTesting;
import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.zip.ZipEntry;
/**
* Helper class used to compute and validate the location of dex metadata files.
@@ -40,6 +49,12 @@ import java.util.Map;
* @hide
*/
public class DexMetadataHelper {
+ public static final String TAG = "DexMetadataHelper";
+ /** $> adb shell 'setprop log.tag.DexMetadataHelper VERBOSE' */
+ public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ /** $> adb shell 'setprop pm.dexopt.dm.require_manifest true' */
+ private static String PROPERTY_DM_JSON_MANIFEST_REQUIRED = "pm.dexopt.dm.require_manifest";
+
private static final String DEX_METADATA_FILE_EXTENSION = ".dm";
private DexMetadataHelper() {}
@@ -147,14 +162,31 @@ public class DexMetadataHelper {
/**
* Validate that the given file is a dex metadata archive.
- * This is just a validation that the file is a zip archive.
+ * This is just a validation that the file is a zip archive that contains a manifest.json
+ * with the package name and version code.
*
* @throws PackageParserException if the file is not a .dm file.
*/
- public static void validateDexMetadataFile(String dmaPath) throws PackageParserException {
+ public static void validateDexMetadataFile(String dmaPath, String packageName, long versionCode)
+ throws PackageParserException {
+ validateDexMetadataFile(dmaPath, packageName, versionCode,
+ SystemProperties.getBoolean(PROPERTY_DM_JSON_MANIFEST_REQUIRED, false));
+ }
+
+ @VisibleForTesting
+ public static void validateDexMetadataFile(String dmaPath, String packageName, long versionCode,
+ boolean requireManifest) throws PackageParserException {
StrictJarFile jarFile = null;
+
+ if (DEBUG) {
+ Log.v(TAG, "validateDexMetadataFile: " + dmaPath + ", " + packageName +
+ ", " + versionCode);
+ }
+
try {
jarFile = new StrictJarFile(dmaPath, false, false);
+ validateDexMetadataManifest(dmaPath, jarFile, packageName, versionCode,
+ requireManifest);
} catch (IOException e) {
throw new PackageParserException(INSTALL_FAILED_BAD_DEX_METADATA,
"Error opening " + dmaPath, e);
@@ -168,6 +200,72 @@ public class DexMetadataHelper {
}
}
+ /** Ensure that packageName and versionCode match the manifest.json in the .dm file */
+ private static void validateDexMetadataManifest(String dmaPath, StrictJarFile jarFile,
+ String packageName, long versionCode, boolean requireManifest)
+ throws IOException, PackageParserException {
+ if (!requireManifest) {
+ if (DEBUG) {
+ Log.v(TAG, "validateDexMetadataManifest: " + dmaPath
+ + " manifest.json check skipped");
+ }
+ return;
+ }
+
+ ZipEntry zipEntry = jarFile.findEntry("manifest.json");
+ if (zipEntry == null) {
+ throw new PackageParserException(INSTALL_FAILED_BAD_DEX_METADATA,
+ "Missing manifest.json in " + dmaPath);
+ }
+ InputStream inputStream = jarFile.getInputStream(zipEntry);
+
+ JsonReader reader;
+ try {
+ reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new PackageParserException(INSTALL_FAILED_BAD_DEX_METADATA,
+ "Error opening manifest.json in " + dmaPath, e);
+ }
+ String jsonPackageName = null;
+ long jsonVersionCode = -1;
+
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+ if (name.equals("packageName")) {
+ jsonPackageName = reader.nextString();
+ } else if (name.equals("versionCode")) {
+ jsonVersionCode = reader.nextLong();
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+
+ if (jsonPackageName == null || jsonVersionCode == -1) {
+ throw new PackageParserException(INSTALL_FAILED_BAD_DEX_METADATA,
+ "manifest.json in " + dmaPath
+ + " is missing 'packageName' and/or 'versionCode'");
+ }
+
+ if (!jsonPackageName.equals(packageName)) {
+ throw new PackageParserException(INSTALL_FAILED_BAD_DEX_METADATA,
+ "manifest.json in " + dmaPath + " has invalid packageName: " + jsonPackageName
+ + ", expected: " + packageName);
+ }
+
+ if (versionCode != jsonVersionCode) {
+ throw new PackageParserException(INSTALL_FAILED_BAD_DEX_METADATA,
+ "manifest.json in " + dmaPath + " has invalid versionCode: " + jsonVersionCode
+ + ", expected: " + versionCode);
+ }
+
+ if (DEBUG) {
+ Log.v(TAG, "validateDexMetadataManifest: " + dmaPath + ", " + packageName +
+ ", " + versionCode + ": successful");
+ }
+ }
+
/**
* Validates that all dex metadata paths in the given list have a matching apk.
* (for any foo.dm there should be either a 'foo' of a 'foo.apk' file).
diff --git a/core/java/android/content/pm/verify/domain/DomainVerificationManager.java b/core/java/android/content/pm/verify/domain/DomainVerificationManager.java
index af12536fff99..cbb3baaa6700 100644
--- a/core/java/android/content/pm/verify/domain/DomainVerificationManager.java
+++ b/core/java/android/content/pm/verify/domain/DomainVerificationManager.java
@@ -238,8 +238,8 @@ public interface DomainVerificationManager {
* permissions must be acquired and
* {@link Context#createPackageContextAsUser(String, int, UserHandle)} should be used.
*
- * This will be combined with the verification status and other system state to determine which
- * application is launched to handle an app link.
+ * Enabling an unverified domain will allow an application to open it, but this can only occur
+ * if no other app on the device is approved for the domain.
*
* @param domainSetId See {@link DomainVerificationInfo#getIdentifier()}.
* @param domains The domains to toggle the state of.
@@ -290,13 +290,15 @@ public interface DomainVerificationManager {
public static final int REASON_ID_INVALID = 2;
public static final int REASON_SET_NULL_OR_EMPTY = 3;
public static final int REASON_UNKNOWN_DOMAIN = 4;
+ public static final int REASON_UNABLE_TO_APPROVE = 5;
/** @hide */
@IntDef({
REASON_ID_NULL,
REASON_ID_INVALID,
REASON_SET_NULL_OR_EMPTY,
- REASON_UNKNOWN_DOMAIN
+ REASON_UNKNOWN_DOMAIN,
+ REASON_UNABLE_TO_APPROVE
})
public @interface Reason {
}
@@ -313,6 +315,8 @@ public interface DomainVerificationManager {
case REASON_UNKNOWN_DOMAIN:
return "Domain set contains value that was not declared by the target package "
+ packageName;
+ case REASON_UNABLE_TO_APPROVE:
+ return "Domain set contains value that was owned by another package";
default:
return "Unknown failure";
}
diff --git a/core/java/android/content/pm/verify/domain/DomainVerificationUserSelection.java b/core/java/android/content/pm/verify/domain/DomainVerificationUserSelection.java
index 8d16f75bf1b4..73346ef0273b 100644
--- a/core/java/android/content/pm/verify/domain/DomainVerificationUserSelection.java
+++ b/core/java/android/content/pm/verify/domain/DomainVerificationUserSelection.java
@@ -17,6 +17,7 @@
package android.content.pm.verify.domain;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.os.Parcelable;
@@ -30,18 +31,18 @@ import java.util.Set;
import java.util.UUID;
/**
- * Contains the user selection state for a package. This means all web HTTP(S) domains
- * declared by a package in its manifest, whether or not they were marked for auto
- * verification.
+ * Contains the user selection state for a package. This means all web HTTP(S) domains declared by a
+ * package in its manifest, whether or not they were marked for auto verification.
* <p>
* By default, all apps are allowed to automatically open links with domains that they've
- * successfully verified against. This is reflected by {@link #isLinkHandlingAllowed()}.
- * The user can decide to disable this, disallowing the application from opening these
- * links.
+ * successfully verified against. This is reflected by {@link #isLinkHandlingAllowed()}. The user
+ * can decide to disable this, disallowing the application from opening all links. Note that the
+ * toggle affects <b>all</b> links and is not based on the verification state of the domains.
* <p>
- * Separately, independent of this toggle, the user can choose specific domains to allow
- * an app to open, which is reflected as part of {@link #getHostToUserSelectionMap()},
- * which maps the domain name to the true/false state of whether it was enabled by the user.
+ * Assuming the toggle is enabled, the user can also select additional unverified domains to grant
+ * to the application to open, which is reflected in {@link #getHostToUserSelectionMap()}. But only
+ * a single application can be approved for a domain unless the applications are both approved. If
+ * another application is approved, the user will not be allowed to enable the domain.
* <p>
* These values can be changed through the
* {@link DomainVerificationManager#setDomainVerificationLinkHandlingAllowed(String,
@@ -105,7 +106,8 @@ public final class DomainVerificationUserSelection implements Parcelable {
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
- // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/domain/verify/DomainVerificationUserSelection.java
+ // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/verify/domain
+ // /DomainVerificationUserSelection.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
@@ -216,7 +218,7 @@ public final class DomainVerificationUserSelection implements Parcelable {
@Override
@DataClass.Generated.Member
- public boolean equals(@android.annotation.Nullable Object o) {
+ public boolean equals(@Nullable Object o) {
// You can override field equality logic by defining either of the methods like:
// boolean fieldNameEquals(DomainVerificationUserSelection other) { ... }
// boolean fieldNameEquals(FieldType otherValue) { ... }
@@ -328,9 +330,9 @@ public final class DomainVerificationUserSelection implements Parcelable {
};
@DataClass.Generated(
- time = 1611799495498L,
+ time = 1612829797220L,
codegenVersion = "1.0.22",
- sourceFile = "frameworks/base/core/java/android/content/pm/domain/verify/DomainVerificationUserSelection.java",
+ sourceFile = "frameworks/base/core/java/android/content/pm/verify/domain/DomainVerificationUserSelection.java",
inputSignatures = "private final @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForUUID.class) java.util.UUID mIdentifier\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull android.os.UserHandle mUser\nprivate final @android.annotation.NonNull boolean mLinkHandlingAllowed\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.Boolean> mHostToUserSelectionMap\nclass DomainVerificationUserSelection extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=true, genHiddenConstructor=true, genParcelable=true, genToString=true, genEqualsHashCode=true)")
@Deprecated
private void __metadata() {}
diff --git a/core/java/android/graphics/fonts/FontFamilyUpdateRequest.java b/core/java/android/graphics/fonts/FontFamilyUpdateRequest.java
new file mode 100644
index 000000000000..25758e9d9a61
--- /dev/null
+++ b/core/java/android/graphics/fonts/FontFamilyUpdateRequest.java
@@ -0,0 +1,264 @@
+/*
+ * 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.
+ */
+
+package android.graphics.fonts;
+
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Request for updating or adding a font family on the system.
+ *
+ * <p>You can update or add a font family with custom style parameters. The following example
+ * defines a font family called "roboto" using "Roboto-Regular" font file that is already available
+ * on the system by preloading or {@link FontManager#updateFontFile}.
+ * <pre>
+ * FontManager fm = getContext().getSystemService(FontManager.class);
+ * fm.updateFontFamily(new FontFamilyUpdateRequest.Builder()
+ * .addFontFamily(new FontFamilyUpdateRequest.FontFamily("roboto", Arrays.asList(
+ * new FontFamilyUpdateRequest.Font(
+ * "Roboto-Regular",
+ * new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_UPRIGHT),
+ * Collections.emptyList()),
+ * new FontFamilyUpdateRequest.Font(
+ * "Roboto-Regular",
+ * new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_ITALIC),
+ * Collections.emptyList()))))
+ * .build(), fm.getFontConfig().getConfigVersion());
+ * </pre>
+ *
+ * <p>You can update or add font files in the same request by calling
+ * {@link FontFamilyUpdateRequest.Builder#addFontFileUpdateRequest(FontFileUpdateRequest)}.
+ * The following example adds "YourFont" font file and defines "your-font" font family in the same
+ * request. In this case, the font file represented by {@code yourFontFd} should be an OpenType
+ * compliant font file and have "YourFont" as PostScript name (ID=6) in 'name' table.
+ * <pre>
+ * FontManager fm = getContext().getSystemService(FontManager.class);
+ * fm.updateFontFamily(new FontFamilyUpdateRequest.Builder()
+ * .addFontFileUpdateRequest(new FontFileUpdateRequest(yourFontFd, signature))
+ * .addFontFamily(new FontFamilyUpdateRequest.FontFamily("your-font", Arrays.asList(
+ * new FontFamilyUpdateRequest.Font(
+ * "YourFont",
+ * new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_UPRIGHT),
+ * Collections.emptyList()))))
+ * .build(), fm.getFontConfig().getConfigVersion());
+ * </pre>
+ *
+ * @hide
+ */
+@SystemApi
+public final class FontFamilyUpdateRequest {
+
+ /**
+ * A font family definition.
+ */
+ public static final class FontFamily {
+ @NonNull
+ private final String mName;
+ @NonNull
+ private final List<Font> mFonts;
+
+ /**
+ * Constructs a FontFamily.
+ *
+ * <p>A font family has a name to identify the font family. Apps can use
+ * {@link android.graphics.Typeface#create(String, int)} or XML resources to use a specific
+ * font family.
+ *
+ * <p>A font family consists of multiple fonts with different styles. The style information
+ * can be specified by {@link Font}.
+ *
+ * @see android.graphics.Typeface#create(String, int)
+ * @see Font
+ */
+ public FontFamily(@NonNull String name, @NonNull List<Font> fonts) {
+ Objects.requireNonNull(name);
+ Preconditions.checkStringNotEmpty(name);
+ Objects.requireNonNull(fonts);
+ Preconditions.checkCollectionElementsNotNull(fonts, "fonts");
+ Preconditions.checkCollectionNotEmpty(fonts, "fonts");
+ mName = name;
+ mFonts = fonts;
+ }
+
+ /**
+ * Returns the name of this family.
+ */
+ @NonNull
+ public String getName() {
+ return mName;
+ }
+
+ /**
+ * Returns the fonts in this family.
+ */
+ @NonNull
+ public List<Font> getFonts() {
+ return mFonts;
+ }
+ }
+
+ /**
+ * A single entry in a font family representing a font.
+ */
+ public static final class Font {
+
+ @NonNull
+ private final String mPostScriptName;
+ @NonNull
+ private final FontStyle mStyle;
+ @NonNull
+ private final List<FontVariationAxis> mAxes;
+
+ /**
+ * Constructs a FontStyleVariation.
+ *
+ * <p>A font has a PostScript name to identify the font file to use, a {@link FontStyle}
+ * to specify the style, and a list of {@link FontVariationAxis} to specify axis tags and
+ * values for variable fonts. If the font file identified by {@code postScriptName} is not a
+ * variable font, {@code axes} must be empty.
+ *
+ * @param postScriptName The PostScript name of the font file to use. PostScript name is in
+ * Name ID 6 field in 'name' table, as specified by OpenType
+ * specification.
+ * @param style The style for this font.
+ * @param axes A list of {@link FontVariationAxis} to specify axis tags and values
+ * for variable fonts.
+ */
+ public Font(@NonNull String postScriptName, @NonNull FontStyle style,
+ @NonNull List<FontVariationAxis> axes) {
+ Objects.requireNonNull(postScriptName);
+ Preconditions.checkStringNotEmpty(postScriptName);
+ Objects.requireNonNull(style);
+ Objects.requireNonNull(axes);
+ Preconditions.checkCollectionElementsNotNull(axes, "axes");
+ mPostScriptName = postScriptName;
+ mStyle = style;
+ mAxes = axes;
+ }
+
+ /**
+ * Returns PostScript name of the font file to use.
+ */
+ @NonNull
+ public String getPostScriptName() {
+ return mPostScriptName;
+ }
+
+ /**
+ * Returns the style.
+ */
+ @NonNull
+ public FontStyle getStyle() {
+ return mStyle;
+ }
+
+ /**
+ * Returns the list of {@link FontVariationAxis}.
+ */
+ @NonNull
+ public List<FontVariationAxis> getAxes() {
+ return mAxes;
+ }
+ }
+
+ /**
+ * Builds a {@link FontFamilyUpdateRequest}.
+ */
+ public static final class Builder {
+ @NonNull
+ private final List<FontFileUpdateRequest> mFontFileUpdateRequests = new ArrayList<>();
+ @NonNull
+ private final List<FontFamily> mFontFamilies = new ArrayList<>();
+
+ /**
+ * Constructs a FontFamilyUpdateRequest.Builder.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Adds a {@link FontFileUpdateRequest} to execute as a part of the constructed
+ * {@link FontFamilyUpdateRequest}.
+ *
+ * @param request A font file update request.
+ * @return This builder object.
+ */
+ @NonNull
+ public Builder addFontFileUpdateRequest(@NonNull FontFileUpdateRequest request) {
+ Objects.requireNonNull(request);
+ mFontFileUpdateRequests.add(request);
+ return this;
+ }
+
+ /**
+ * Adds a font family to update an existing font family in the system font config or
+ * add as a new font family to the system font config.
+ *
+ * @param fontFamily An font family definition to add or update.
+ * @return This builder object.
+ */
+ @NonNull
+ public Builder addFontFamily(@NonNull FontFamily fontFamily) {
+ Objects.requireNonNull(fontFamily);
+ mFontFamilies.add(fontFamily);
+ return this;
+ }
+
+ /**
+ * Builds a {@link FontFamilyUpdateRequest}.
+ */
+ @NonNull
+ public FontFamilyUpdateRequest build() {
+ return new FontFamilyUpdateRequest(mFontFileUpdateRequests, mFontFamilies);
+ }
+ }
+
+ @NonNull
+ private final List<FontFileUpdateRequest> mFontFiles;
+
+ @NonNull
+ private final List<FontFamily> mFontFamilies;
+
+ private FontFamilyUpdateRequest(@NonNull List<FontFileUpdateRequest> fontFiles,
+ @NonNull List<FontFamily> fontFamilies) {
+ mFontFiles = fontFiles;
+ mFontFamilies = fontFamilies;
+ }
+
+ /**
+ * Returns the list of {@link FontFileUpdateRequest} that will be executed as a part of this
+ * request.
+ */
+ @NonNull
+ public List<FontFileUpdateRequest> getFontFileUpdateRequests() {
+ return mFontFiles;
+ }
+
+ /**
+ * Returns the list of {@link FontFamily} that will be updated in this request.
+ */
+ @NonNull
+ public List<FontFamily> getFontFamilies() {
+ return mFontFamilies;
+ }
+}
diff --git a/core/java/android/graphics/fonts/FontFileUpdateRequest.java b/core/java/android/graphics/fonts/FontFileUpdateRequest.java
new file mode 100644
index 000000000000..cf1dca965216
--- /dev/null
+++ b/core/java/android/graphics/fonts/FontFileUpdateRequest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package android.graphics.fonts;
+
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+import android.os.ParcelFileDescriptor;
+
+import java.util.Objects;
+
+/**
+ * Request for updating a font file on the system.
+ *
+ * @hide
+ */
+@SystemApi
+public final class FontFileUpdateRequest {
+
+ private final ParcelFileDescriptor mParcelFileDescriptor;
+ private final byte[] mSignature;
+
+ /**
+ * Creates a FontFileUpdateRequest with the given file and signature.
+ *
+ * @param parcelFileDescriptor A file descriptor of the font file.
+ * @param signature A PKCS#7 detached signature for verifying the font file.
+ */
+ public FontFileUpdateRequest(@NonNull ParcelFileDescriptor parcelFileDescriptor,
+ @NonNull byte[] signature) {
+ Objects.requireNonNull(parcelFileDescriptor);
+ Objects.requireNonNull(signature);
+ mParcelFileDescriptor = parcelFileDescriptor;
+ mSignature = signature;
+ }
+
+ /**
+ * Returns the file descriptor of the font file.
+ */
+ @NonNull
+ public ParcelFileDescriptor getParcelFileDescriptor() {
+ return mParcelFileDescriptor;
+ }
+
+ /**
+ * Returns the PKCS#7 detached signature for verifying the font file.
+ */
+ @NonNull
+ public byte[] getSignature() {
+ return mSignature;
+ }
+}
diff --git a/core/java/android/graphics/fonts/FontManager.java b/core/java/android/graphics/fonts/FontManager.java
index abb4f9fa7eef..e512cf1bbb1f 100644
--- a/core/java/android/graphics/fonts/FontManager.java
+++ b/core/java/android/graphics/fonts/FontManager.java
@@ -35,6 +35,8 @@ import com.android.internal.graphics.fonts.IFontManager;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
/**
@@ -58,7 +60,7 @@ public class FontManager {
RESULT_ERROR_VERIFICATION_FAILURE, RESULT_ERROR_VERSION_MISMATCH,
RESULT_ERROR_INVALID_FONT_FILE, RESULT_ERROR_INVALID_FONT_NAME,
RESULT_ERROR_DOWNGRADING, RESULT_ERROR_FAILED_UPDATE_CONFIG,
- RESULT_ERROR_FONT_UPDATER_DISABLED, RESULT_ERROR_REMOTE_EXCEPTION })
+ RESULT_ERROR_FONT_UPDATER_DISABLED, RESULT_ERROR_FONT_NOT_FOUND })
@Retention(RetentionPolicy.SOURCE)
public @interface ResultCode {}
@@ -131,9 +133,10 @@ public class FontManager {
public static final int RESULT_ERROR_VERSION_MISMATCH = -8;
/**
- * Indicates a failure due to IPC communication.
+ * Indicates a failure occurred because a font with the specified PostScript name could not be
+ * found.
*/
- public static final int RESULT_ERROR_REMOTE_EXCEPTION = -9;
+ public static final int RESULT_ERROR_FONT_NOT_FOUND = -9;
/**
* Indicates a failure of opening font file.
@@ -205,42 +208,40 @@ public class FontManager {
}
/**
- * Update system installed font file.
+ * Update a system installed font file.
*
* <p>
- * To protect devices, system font updater relies on the Linux Kernel feature called fs-verity.
- * If the device is not ready for fs-verity, {@link #RESULT_ERROR_FONT_UPDATER_DISABLED} will be
+ * To protect devices, system font updater relies on a Linux Kernel feature called fs-verity.
+ * If the device does not support fs-verity, {@link #RESULT_ERROR_FONT_UPDATER_DISABLED} will be
* returned.
*
- * Android only accepts OpenType compliant font files. If other font files are provided,
+ * <p>Android only accepts OpenType compliant font files. If other font files are provided,
* {@link #RESULT_ERROR_INVALID_FONT_FILE} will be returned.
*
- * The font file to be updated is identified by PostScript name stored in name table. If the
- * font file doesn't have PostScript name entry, {@link #RESULT_ERROR_INVALID_FONT_NAME} will be
- * returned.
+ * <p>The font file to be updated is identified by PostScript name stored in the name table. If
+ * the font file doesn't have PostScript name entry, {@link #RESULT_ERROR_INVALID_FONT_NAME}
+ * will be returned.
*
- * The entire font file is verified with the given signature for the system installed
- * certificate. If the system cannot verify the font contents,
+ * <p>The entire font file is verified with the given signature using system installed
+ * certificates. If the system cannot verify the font file contents,
* {@link #RESULT_ERROR_VERIFICATION_FAILURE} will be returned.
*
- * The font file must have newer or equal revision number in the head table. In other words, the
- * downgrading font file is not allowed. If the older font file is provided,
+ * <p>The font file must have a newer revision number in the head table. In other words, it is
+ * not allowed to downgrade a font file. If an older font file is provided,
* {@link #RESULT_ERROR_DOWNGRADING} will be returned.
*
- * The caller must specify the base config version for keeping consist system configuration. If
- * the system configuration is updated for some reason between you get config with
- * {@link #getFontConfig()} and calling this method, {@link #RESULT_ERROR_VERSION_MISMATCH} will
- * be returned. Get the latest font configuration by calling {@link #getFontConfig()} again and
- * try with the latest config version again.
- *
- * @param pfd A file descriptor of the font file.
- * @param signature A PKCS#7 detached signature for verifying entire font files.
- * @param baseVersion A base config version to be updated. You can get latest config version by
- * {@link FontConfig#getConfigVersion()} via {@link #getFontConfig()}. If the
- * system has newer config version, the update will fail with
- * {@link #RESULT_ERROR_VERSION_MISMATCH}. Try to get the latest config and
- * try update again.
- * @return result code.
+ * <p>The caller must specify the base config version for keeping the font configuration
+ * consistent. If the font configuration is updated for some reason between the time you get
+ * a configuration with {@link #getFontConfig()} and the time when you call this method,
+ * {@link #RESULT_ERROR_VERSION_MISMATCH} will be returned. Get the latest font configuration by
+ * calling {@link #getFontConfig()} and call this method again with the latest config version.
+ *
+ * @param request A {@link FontFileUpdateRequest} to execute.
+ * @param baseVersion A base config version to be updated. You can get the latest config version
+ * by {@link FontConfig#getConfigVersion()} via {@link #getFontConfig()}. If
+ * the system has a newer config version, the update will fail with
+ * {@link #RESULT_ERROR_VERSION_MISMATCH}.
+ * @return A result code.
*
* @see FontConfig#getConfigVersion()
* @see #getFontConfig()
@@ -253,18 +254,88 @@ public class FontManager {
* @see #RESULT_ERROR_DOWNGRADING
* @see #RESULT_ERROR_FAILED_UPDATE_CONFIG
* @see #RESULT_ERROR_FONT_UPDATER_DISABLED
- * @see #RESULT_ERROR_REMOTE_EXCEPTION
*/
@RequiresPermission(Manifest.permission.UPDATE_FONTS) public @ResultCode int updateFontFile(
+ @NonNull FontFileUpdateRequest request, @IntRange(from = 0) int baseVersion) {
+ try {
+ return mIFontManager.updateFontFile(new FontUpdateRequest(
+ request.getParcelFileDescriptor(), request.getSignature()), baseVersion);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * @deprecated Use {@link #updateFontFile(FontFileUpdateRequest, int)}
+ */
+ // TODO: Remove this API before Developer Preview 3.
+ @Deprecated
+ @RequiresPermission(Manifest.permission.UPDATE_FONTS) public @ResultCode int updateFontFile(
@NonNull ParcelFileDescriptor pfd,
@NonNull byte[] signature,
@IntRange(from = 0) int baseVersion
) {
+ return updateFontFile(new FontFileUpdateRequest(pfd, signature), baseVersion);
+ }
+
+
+ /**
+ * Update or add system wide font families.
+ *
+ * <p>This method will update existing font families or add new font families. The updated
+ * font family definitions will be used when creating {@link android.graphics.Typeface} objects
+ * with using {@link android.graphics.Typeface#create(String, int)} specifying the family name,
+ * or through XML resources. Note that system fallback fonts cannot be modified by this method.
+ * Apps must use {@link android.graphics.Typeface.CustomFallbackBuilder} to use custom fallback
+ * fonts.
+ *
+ * <p>Font files can be updated by including {@link FontFileUpdateRequest} to {@code request}
+ * via {@link FontFamilyUpdateRequest.Builder#addFontFileUpdateRequest(FontFileUpdateRequest)}.
+ * The same constraints as {@link #updateFontFile} will apply when updating font files.
+ *
+ * <p>The caller must specify the base config version for keeping the font configuration
+ * consistent. If the font configuration is updated for some reason between the time you get
+ * a configuration with {@link #getFontConfig()} and the time when you call this method,
+ * {@link #RESULT_ERROR_VERSION_MISMATCH} will be returned. Get the latest font configuration by
+ * calling {@link #getFontConfig()} and call this method again with the latest config version.
+ *
+ * @param request A {@link FontFamilyUpdateRequest} to execute.
+ * @param baseVersion A base config version to be updated. You can get the latest config version
+ * by {@link FontConfig#getConfigVersion()} via {@link #getFontConfig()}. If
+ * the system has a newer config version, the update will fail with
+ * {@link #RESULT_ERROR_VERSION_MISMATCH}.
+ * @return A result code.
+ * @see FontConfig#getConfigVersion()
+ * @see #getFontConfig()
+ * @see #RESULT_SUCCESS
+ * @see #RESULT_ERROR_FAILED_TO_WRITE_FONT_FILE
+ * @see #RESULT_ERROR_VERIFICATION_FAILURE
+ * @see #RESULT_ERROR_VERSION_MISMATCH
+ * @see #RESULT_ERROR_INVALID_FONT_FILE
+ * @see #RESULT_ERROR_INVALID_FONT_NAME
+ * @see #RESULT_ERROR_DOWNGRADING
+ * @see #RESULT_ERROR_FAILED_UPDATE_CONFIG
+ * @see #RESULT_ERROR_FONT_UPDATER_DISABLED
+ * @see #RESULT_ERROR_FONT_NOT_FOUND
+ */
+ @RequiresPermission(Manifest.permission.UPDATE_FONTS) public @ResultCode int updateFontFamily(
+ @NonNull FontFamilyUpdateRequest request, @IntRange(from = 0) int baseVersion) {
+ List<FontUpdateRequest> requests = new ArrayList<>();
+ List<FontFileUpdateRequest> fontFileUpdateRequests = request.getFontFileUpdateRequests();
+ for (int i = 0; i < fontFileUpdateRequests.size(); i++) {
+ FontFileUpdateRequest fontFile = fontFileUpdateRequests.get(i);
+ requests.add(new FontUpdateRequest(fontFile.getParcelFileDescriptor(),
+ fontFile.getSignature()));
+ }
+ List<FontFamilyUpdateRequest.FontFamily> fontFamilies = request.getFontFamilies();
+ for (int i = 0; i < fontFamilies.size(); i++) {
+ FontFamilyUpdateRequest.FontFamily fontFamily = fontFamilies.get(i);
+ requests.add(new FontUpdateRequest(fontFamily.getName(), fontFamily.getFonts()));
+ }
try {
- return mIFontManager.updateFont(baseVersion, new FontUpdateRequest(pfd, signature));
+ return mIFontManager.updateFontFamily(requests, baseVersion);
} catch (RemoteException e) {
- Log.e(TAG, "Failed to call updateFont API", e);
- return RESULT_ERROR_REMOTE_EXCEPTION;
+ throw e.rethrowFromSystemServer();
}
}
diff --git a/core/java/android/graphics/fonts/FontUpdateRequest.java b/core/java/android/graphics/fonts/FontUpdateRequest.java
index f551d6a175da..b79c8f62d492 100644
--- a/core/java/android/graphics/fonts/FontUpdateRequest.java
+++ b/core/java/android/graphics/fonts/FontUpdateRequest.java
@@ -19,13 +19,17 @@ package android.graphics.fonts;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.os.LocaleList;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.text.FontConfig;
+import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.List;
/**
* Represents a font update request. Currently only font install request is supported.
@@ -80,6 +84,26 @@ public final class FontUpdateRequest implements Parcelable {
mFontFamily = fontFamily;
}
+ public FontUpdateRequest(@NonNull String postScriptName,
+ @NonNull List<FontFamilyUpdateRequest.Font> variations) {
+ // TODO: Serialize the request directly instead of reusing FontConfig.FontFamily.
+ this(createFontFamily(postScriptName, variations));
+ }
+
+ private static FontConfig.FontFamily createFontFamily(@NonNull String postScriptName,
+ @NonNull List<FontFamilyUpdateRequest.Font> fonts) {
+ List<FontConfig.Font> configFonts = new ArrayList<>(fonts.size());
+ for (FontFamilyUpdateRequest.Font font : fonts) {
+ // TODO: Support .otf.
+ configFonts.add(new FontConfig.Font(new File(font.getPostScriptName() + ".ttf"), null,
+ font.getStyle(), 0 /* index */,
+ FontVariationAxis.toFontVariationSettings(font.getAxes()),
+ null /* fontFamilyName */));
+ }
+ return new FontConfig.FontFamily(configFonts, postScriptName,
+ LocaleList.getEmptyLocaleList(), FontConfig.FontFamily.VARIANT_DEFAULT);
+ }
+
protected FontUpdateRequest(Parcel in) {
mType = in.readInt();
mFd = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java
index 376503e79cfc..1ffd18fc1ac8 100644
--- a/core/java/android/hardware/SystemSensorManager.java
+++ b/core/java/android/hardware/SystemSensorManager.java
@@ -16,11 +16,18 @@
package android.hardware;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+
+import android.compat.Compatibility;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
@@ -54,6 +61,19 @@ public class SystemSensorManager extends SensorManager {
private static final boolean DEBUG_DYNAMIC_SENSOR = true;
private static final int MIN_DIRECT_CHANNEL_BUFFER_SIZE = 104;
private static final int MAX_LISTENER_COUNT = 128;
+ private static final int CAPPED_SAMPLING_PERIOD_US = 5000;
+ private static final int CAPPED_SAMPLING_RATE_LEVEL = SensorDirectChannel.RATE_NORMAL;
+
+ private static final String HIGH_SAMPLING_RATE_SENSORS_PERMISSION =
+ "android.permisison.HIGH_SAMPLING_RATE_SENSORS";
+ /**
+ * For apps targeting S and above, a SecurityException is thrown when they do not have
+ * HIGH_SAMPLING_RATE_SENSORS permission, run in debug mode, and request sampling rates that
+ * are faster than 200 Hz.
+ */
+ @ChangeId
+ @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
+ static final long CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION = 136069189L;
private static native void nativeClassInit();
private static native long nativeCreate(String opPackageName);
@@ -98,6 +118,8 @@ public class SystemSensorManager extends SensorManager {
// Looper associated with the context in which this instance was created.
private final Looper mMainLooper;
private final int mTargetSdkLevel;
+ private final boolean mIsPackageDebuggable;
+ private final boolean mHasHighSamplingRateSensorsPermission;
private final Context mContext;
private final long mNativeInstance;
@@ -111,9 +133,16 @@ public class SystemSensorManager extends SensorManager {
}
mMainLooper = mainLooper;
- mTargetSdkLevel = context.getApplicationInfo().targetSdkVersion;
+ ApplicationInfo appInfo = context.getApplicationInfo();
+ mTargetSdkLevel = appInfo.targetSdkVersion;
mContext = context;
mNativeInstance = nativeCreate(context.getOpPackageName());
+ mIsPackageDebuggable = (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
+ PackageManager packageManager = context.getPackageManager();
+ mHasHighSamplingRateSensorsPermission =
+ (PERMISSION_GRANTED == packageManager.checkPermission(
+ HIGH_SAMPLING_RATE_SENSORS_PERMISSION,
+ appInfo.packageName));
// initialize the sensor list
for (int index = 0;; ++index) {
@@ -542,10 +571,18 @@ public class SystemSensorManager extends SensorManager {
}
int sensorHandle = (sensor == null) ? -1 : sensor.getHandle();
+ if (Compatibility.isChangeEnabled(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION)
+ && rate > CAPPED_SAMPLING_RATE_LEVEL
+ && mIsPackageDebuggable
+ && !mHasHighSamplingRateSensorsPermission) {
+ Compatibility.reportChange(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION);
+ throw new SecurityException("To use the sampling rate level " + rate
+ + ", app needs to declare the normal permission"
+ + " HIGH_SAMPLING_RATE_SENSORS.");
+ }
int ret = nativeConfigDirectChannel(
mNativeInstance, channel.getNativeHandle(), sensorHandle, rate);
-
if (rate == SensorDirectChannel.RATE_STOP) {
return (ret == 0) ? 1 : 0;
} else {
@@ -745,6 +782,15 @@ public class SystemSensorManager extends SensorManager {
Sensor sensor, int rateUs, int maxBatchReportLatencyUs) {
if (mNativeSensorEventQueue == 0) throw new NullPointerException();
if (sensor == null) throw new NullPointerException();
+ if (Compatibility.isChangeEnabled(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION)
+ && rateUs < CAPPED_SAMPLING_PERIOD_US
+ && mManager.mIsPackageDebuggable
+ && !mManager.mHasHighSamplingRateSensorsPermission) {
+ Compatibility.reportChange(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION);
+ throw new SecurityException("To use the sampling rate of " + rateUs
+ + " microseconds, app needs to declare the normal permission"
+ + " HIGH_SAMPLING_RATE_SENSORS.");
+ }
return nativeEnableSensor(mNativeSensorEventQueue, sensor.getHandle(), rateUs,
maxBatchReportLatencyUs);
}
diff --git a/core/java/android/hardware/camera2/params/StreamConfigurationMap.java b/core/java/android/hardware/camera2/params/StreamConfigurationMap.java
index 8bb0b184ce02..10a814acd70b 100644
--- a/core/java/android/hardware/camera2/params/StreamConfigurationMap.java
+++ b/core/java/android/hardware/camera2/params/StreamConfigurationMap.java
@@ -1917,9 +1917,18 @@ public final class StreamConfigurationMap {
(3 << HAL_DATASPACE_TRANSFER_SHIFT) |
(1 << HAL_DATASPACE_RANGE_SHIFT);
- private static final int HAL_DATASPACE_DEPTH = 0x1000;
- private static final int HAL_DATASPACE_DYNAMIC_DEPTH = 0x1002;
- private static final int HAL_DATASPACE_HEIF = 0x1003;
+ /**
+ * @hide
+ */
+ public static final int HAL_DATASPACE_DEPTH = 0x1000;
+ /**
+ * @hide
+ */
+ public static final int HAL_DATASPACE_DYNAMIC_DEPTH = 0x1002;
+ /**
+ * @hide
+ */
+ public static final int HAL_DATASPACE_HEIF = 0x1003;
private static final long DURATION_20FPS_NS = 50000000L;
/**
* @see #getDurations(int, int)
diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java
index 43480ab9cc44..49beeb3a2e96 100644
--- a/core/java/android/hardware/location/ContextHubClient.java
+++ b/core/java/android/hardware/location/ContextHubClient.java
@@ -127,6 +127,20 @@ public class ContextHubClient implements Closeable {
* This function returns RESULT_SUCCESS if the message has reached the HAL, but
* does not guarantee delivery of the message to the target nanoapp.
*
+ * Before sending the first message to your nanoapp, it's recommended that the following
+ * operations should be performed:
+ * 1) Invoke {@link ContextHubManager#queryNanoApps(ContextHubInfo)} to verify the nanoapp is
+ * present.
+ * 2) Validate that you have the permissions to communicate with the nanoapp by looking at
+ * {@link NanoAppState#getNanoAppPermissions}.
+ * 3) If you don't have permissions, send an idempotent message to the nanoapp ensuring any
+ * work your app previously may have asked it to do is stopped. This is useful if your app
+ * restarts due to permission changes and no longer has the permissions when it is started
+ * again.
+ * 4) If you have valid permissions, send a message to your nanoapp to resubscribe so that it's
+ * aware you have restarted or so you can initially subscribe if this is the first time you
+ * have sent it a message.
+ *
* @param message the message object to send
*
* @return the result of sending the message defined as in ContextHubTransaction.Result
diff --git a/core/java/android/hardware/location/ContextHubClientCallback.java b/core/java/android/hardware/location/ContextHubClientCallback.java
index b31b85fdabf6..7e484dda283c 100644
--- a/core/java/android/hardware/location/ContextHubClientCallback.java
+++ b/core/java/android/hardware/location/ContextHubClientCallback.java
@@ -117,10 +117,11 @@ public class ContextHubClientCallback {
* 4) {@link ContextHubClient} performs any cleanup required with the nanoapp
* 5) Callback invoked with the nanoapp ID and {@link ContextHubManager#AUTHORIZATION_DENIED}.
* At this point, any further attempts of communication between the nanoapp and the
- * {@link ContextHubClient} will be dropped by the contexthub along with
- * {@link ContextHubManager#AUTHORIZATION_DENIED} being sent. The {@link ContextHubClient}
- * should assume no communciation can happen again until
- * {@link ContextHubManager#AUTHORIZATION_GRANTED} is received.
+ * {@link ContextHubClient} will be dropped by the contexthub and a return value of
+ * {@link ContextHubTransaction#RESULT_FAILED_PERMISSION_DENIED} will be used when calling
+ * {@link ContextHubClient#sendMessageToNanoApp}. The {@link ContextHubClient} should assume
+ * no communciation can happen again until {@link ContextHubManager#AUTHORIZATION_GRANTED} is
+ * received.
*
* @param client the client that is associated with this callback
* @param nanoAppId the ID of the nanoapp associated with the new
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index ebb3021bf083..a65f36b14f13 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -24,6 +24,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
+import android.app.ActivityThread;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -849,9 +850,18 @@ public final class ContextHubManager {
attributionTag = context.getAttributionTag();
}
+ // Workaround for old APIs not providing a context
+ String packageName;
+ if (context != null) {
+ packageName = context.getPackageName();
+ } else {
+ packageName = ActivityThread.currentPackageName();
+ }
+
IContextHubClient clientProxy;
try {
- clientProxy = mService.createClient(hubInfo.getId(), clientInterface, attributionTag);
+ clientProxy = mService.createClient(
+ hubInfo.getId(), clientInterface, attributionTag, packageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/hardware/location/ContextHubTransaction.java b/core/java/android/hardware/location/ContextHubTransaction.java
index d11e0a9b6081..86f77c0bf138 100644
--- a/core/java/android/hardware/location/ContextHubTransaction.java
+++ b/core/java/android/hardware/location/ContextHubTransaction.java
@@ -81,7 +81,8 @@ public class ContextHubTransaction<T> {
RESULT_FAILED_AT_HUB,
RESULT_FAILED_TIMEOUT,
RESULT_FAILED_SERVICE_INTERNAL_FAILURE,
- RESULT_FAILED_HAL_UNAVAILABLE
+ RESULT_FAILED_HAL_UNAVAILABLE,
+ RESULT_FAILED_PERMISSION_DENIED
})
public @interface Result {}
public static final int RESULT_SUCCESS = 0;
@@ -117,6 +118,11 @@ public class ContextHubTransaction<T> {
* Failure mode when the Context Hub HAL was not available.
*/
public static final int RESULT_FAILED_HAL_UNAVAILABLE = 8;
+ /**
+ * Failure mode when the user of the API doesn't have the required permissions to perform the
+ * operation.
+ */
+ public static final int RESULT_FAILED_PERMISSION_DENIED = 9;
/**
* A class describing the response for a ContextHubTransaction.
diff --git a/core/java/android/hardware/location/IContextHubService.aidl b/core/java/android/hardware/location/IContextHubService.aidl
index 4961195a3017..92882c4f93bb 100644
--- a/core/java/android/hardware/location/IContextHubService.aidl
+++ b/core/java/android/hardware/location/IContextHubService.aidl
@@ -60,7 +60,8 @@ interface IContextHubService {
// Creates a client to send and receive messages
IContextHubClient createClient(
- int contextHubId, in IContextHubClientCallback client, in String attributionTag);
+ int contextHubId, in IContextHubClientCallback client, in String attributionTag,
+ in String packageName);
// Creates a PendingIntent-based client to send and receive messages
IContextHubClient createPendingIntentClient(
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl
index ca79901c2bbe..7f07af79ab69 100644
--- a/core/java/android/hardware/usb/IUsbManager.aidl
+++ b/core/java/android/hardware/usb/IUsbManager.aidl
@@ -135,6 +135,12 @@ interface IUsbManager
/* Resets the USB gadget. */
void resetUsbGadget();
+ /* Set USB data on or off */
+ boolean enableUsbDataSignal(boolean enable);
+
+ /* Gets the USB Hal Version. */
+ int getUsbHalVersion();
+
/* Get the functionfs control handle for the given function. Usb
* descriptors will already be written, and the handle will be
* ready to use.
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index 5bac481fb23e..841fd2f49967 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -516,6 +516,46 @@ public class UsbManager {
public static final int USB_DATA_TRANSFER_RATE_40G = 40 * 1024;
/**
+ * The Value for USB hal is not presented.
+ *
+ * {@hide}
+ */
+ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ public static final int USB_HAL_NOT_SUPPORTED = -1;
+
+ /**
+ * Value for USB Hal Version v1.0.
+ *
+ * {@hide}
+ */
+ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ public static final int USB_HAL_V1_0 = 10;
+
+ /**
+ * Value for USB Hal Version v1.1.
+ *
+ * {@hide}
+ */
+ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ public static final int USB_HAL_V1_1 = 11;
+
+ /**
+ * Value for USB Hal Version v1.2.
+ *
+ * {@hide}
+ */
+ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ public static final int USB_HAL_V1_2 = 12;
+
+ /**
+ * Value for USB Hal Version v1.3.
+ *
+ * {@hide}
+ */
+ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ public static final int USB_HAL_V1_3 = 13;
+
+ /**
* Code for the charging usb function. Passed into {@link #setCurrentFunctions(long)}
* {@hide}
*/
@@ -617,6 +657,16 @@ public class UsbManager {
})
public @interface UsbGadgetHalVersion {}
+ /** @hide */
+ @IntDef(prefix = { "USB_HAL_" }, value = {
+ USB_HAL_NOT_SUPPORTED,
+ USB_HAL_V1_0,
+ USB_HAL_V1_1,
+ USB_HAL_V1_2,
+ USB_HAL_V1_3,
+ })
+ public @interface UsbHalVersion {}
+
private final Context mContext;
private final IUsbManager mService;
@@ -1076,6 +1126,26 @@ public class UsbManager {
}
/**
+ * Get the Current USB Hal Version.
+ * <p>
+ * This function returns the current USB Hal Version.
+ * </p>
+ *
+ * @return a integer {@code USB_HAL_*} represent hal version.
+ *
+ * {@hide}
+ */
+ @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ @RequiresPermission(Manifest.permission.MANAGE_USB)
+ public @UsbHalVersion int getUsbHalVersion() {
+ try {
+ return mService.getUsbHalVersion();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Resets the USB Gadget.
* <p>
* Performs USB data stack reset through USB Gadget HAL.
@@ -1095,6 +1165,28 @@ public class UsbManager {
}
/**
+ * Enable/Disable the USB data signaling.
+ * <p>
+ * Enables/Disables USB data path in all the USB ports.
+ * It will force to stop or restore USB data signaling.
+ * </p>
+ *
+ * @param enable enable or disable USB data signaling
+ * @return true enable or disable USB data successfully
+ * false if something wrong
+ *
+ * @hide
+ */
+ @RequiresPermission(Manifest.permission.MANAGE_USB)
+ public boolean enableUsbDataSignal(boolean enable) {
+ try {
+ return mService.enableUsbDataSignal(enable);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Returns a list of physical USB ports on the device.
* <p>
* This list is guaranteed to contain all dual-role USB Type C ports but it might
diff --git a/core/java/android/net/UidRange.java b/core/java/android/net/UidRange.java
index 3bc0f9ca4e6a..b172ccc4e370 100644
--- a/core/java/android/net/UidRange.java
+++ b/core/java/android/net/UidRange.java
@@ -21,6 +21,7 @@ import static android.os.UserHandle.PER_USER_RANGE;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
+import android.os.UserHandle;
import java.util.Collection;
@@ -45,6 +46,14 @@ public final class UidRange implements Parcelable {
return new UidRange(userId * PER_USER_RANGE, (userId + 1) * PER_USER_RANGE - 1);
}
+ /** Creates a UidRange for the specified user. */
+ public static UidRange createForUser(UserHandle user) {
+ final UserHandle nextUser = UserHandle.of(user.getIdentifier() + 1);
+ final int start = UserHandle.getUid(user, 0 /* appId */);
+ final int end = UserHandle.getUid(nextUser, 0) - 1;
+ return new UidRange(start, end);
+ }
+
/** Returns the smallest user Id which is contained in this UidRange */
public int getStartUser() {
return start / PER_USER_RANGE;
diff --git a/core/java/android/net/vcn/VcnConfig.java b/core/java/android/net/vcn/VcnConfig.java
index 5eb4ba6a2f8e..52cc2182b094 100644
--- a/core/java/android/net/vcn/VcnConfig.java
+++ b/core/java/android/net/vcn/VcnConfig.java
@@ -20,6 +20,7 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
+import android.net.NetworkRequest;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
@@ -41,7 +42,6 @@ import java.util.Set;
* brought up on demand based on active {@link NetworkRequest}(s).
*
* @see VcnManager for more information on the Virtual Carrier Network feature
- * @hide
*/
public final class VcnConfig implements Parcelable {
@NonNull private static final String TAG = VcnConfig.class.getSimpleName();
@@ -56,7 +56,8 @@ public final class VcnConfig implements Parcelable {
@NonNull String packageName,
@NonNull Set<VcnGatewayConnectionConfig> gatewayConnectionConfigs) {
mPackageName = packageName;
- mGatewayConnectionConfigs = Collections.unmodifiableSet(gatewayConnectionConfigs);
+ mGatewayConnectionConfigs =
+ Collections.unmodifiableSet(new ArraySet<>(gatewayConnectionConfigs));
validate();
}
@@ -96,11 +97,7 @@ public final class VcnConfig implements Parcelable {
return mPackageName;
}
- /**
- * Retrieves the set of configured tunnels.
- *
- * @hide
- */
+ /** Retrieves the set of configured GatewayConnection(s). */
@NonNull
public Set<VcnGatewayConnectionConfig> getGatewayConnectionConfigs() {
return Collections.unmodifiableSet(mGatewayConnectionConfigs);
@@ -168,11 +165,7 @@ public final class VcnConfig implements Parcelable {
}
};
- /**
- * This class is used to incrementally build {@link VcnConfig} objects.
- *
- * @hide
- */
+ /** This class is used to incrementally build {@link VcnConfig} objects. */
public static final class Builder {
@NonNull private final String mPackageName;
@@ -190,7 +183,6 @@ public final class VcnConfig implements Parcelable {
*
* @param gatewayConnectionConfig the configuration for an individual gateway connection
* @return this {@link Builder} instance, for chaining
- * @hide
*/
@NonNull
public Builder addGatewayConnectionConfig(
@@ -205,7 +197,6 @@ public final class VcnConfig implements Parcelable {
* Builds and validates the VcnConfig.
*
* @return an immutable VcnConfig instance
- * @hide
*/
@NonNull
public VcnConfig build() {
diff --git a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
index cead2f1caad1..40aa518c7b2f 100644
--- a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
+++ b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
@@ -21,6 +21,8 @@ import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SuppressLint;
+import android.net.Network;
import android.net.NetworkCapabilities;
import android.os.PersistableBundle;
import android.util.ArraySet;
@@ -55,28 +57,23 @@ import java.util.concurrent.TimeUnit;
* subscription group under which this configuration is registered (see {@link
* VcnManager#setVcnConfig}).
*
- * <p>Services that can be provided by a VCN network, or required for underlying networks are
- * limited to services provided by cellular networks:
+ * <p>As an abstraction of a cellular network, services that can be provided by a VCN network, or
+ * required for underlying networks are limited to services provided by cellular networks:
*
* <ul>
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_MMS}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_SUPL}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_DUN}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_FOTA}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_IMS}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_CBS}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_IA}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_RCS}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_XCAP}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_EIMS}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET}
- * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_MCX}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_MMS}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_SUPL}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_DUN}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_FOTA}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_IMS}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_CBS}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_IA}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_RCS}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_XCAP}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_EIMS}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_INTERNET}
+ * <li>{@link NetworkCapabilities#NET_CAPABILITY_MCX}
* </ul>
- *
- * <p>The meteredness and roaming of the VCN {@link Network} will be determined by that of the
- * underlying Network(s).
- *
- * @hide
*/
public final class VcnGatewayConnectionConfig {
// TODO: Use MIN_MTU_V6 once it is public, @hide
@@ -249,8 +246,7 @@ public final class VcnGatewayConnectionConfig {
* ascending numerical order.
*
* @see Builder#addExposedCapability(int)
- * @see Builder#clearExposedCapability(int)
- * @hide
+ * @see Builder#removeExposedCapability(int)
*/
@NonNull
public int[] getExposedCapabilities() {
@@ -278,8 +274,7 @@ public final class VcnGatewayConnectionConfig {
* <p>The returned integer-value capabilities will be sorted in ascending numerical order.
*
* @see Builder#addRequiredUnderlyingCapability(int)
- * @see Builder#clearRequiredUnderlyingCapability(int)
- * @hide
+ * @see Builder#removeRequiredUnderlyingCapability(int)
*/
@NonNull
public int[] getRequiredUnderlyingCapabilities() {
@@ -305,7 +300,6 @@ public final class VcnGatewayConnectionConfig {
* Retrieves the configured retry intervals.
*
* @see Builder#setRetryInterval(long[])
- * @hide
*/
@NonNull
public long[] getRetryInterval() {
@@ -317,7 +311,7 @@ public final class VcnGatewayConnectionConfig {
*
* <p>Left to prevent the need to make major changes while changes are actively in flight.
*
- * @deprecated use getRequiredUnderlyingCapabilities() instead
+ * @deprecated use getRetryInterval() instead
* @hide
*/
@Deprecated
@@ -329,8 +323,7 @@ public final class VcnGatewayConnectionConfig {
/**
* Retrieves the maximum MTU allowed for this Gateway Connection.
*
- * @see Builder.setMaxMtu(int)
- * @hide
+ * @see Builder#setMaxMtu(int)
*/
@IntRange(from = MIN_MTU_V6)
public int getMaxMtu() {
@@ -388,8 +381,6 @@ public final class VcnGatewayConnectionConfig {
/**
* This class is used to incrementally build {@link VcnGatewayConnectionConfig} objects.
- *
- * @hide
*/
public static final class Builder {
@NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
@@ -409,7 +400,6 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be exposed by a Gateway
* Connection
- * @hide
*/
@NonNull
public Builder addExposedCapability(@VcnSupportedCapability int exposedCapability) {
@@ -427,10 +417,10 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be exposed by a Gateway
* Connection
- * @hide
*/
@NonNull
- public Builder clearExposedCapability(@VcnSupportedCapability int exposedCapability) {
+ @SuppressLint("BuilderSetStyle") // For consistency with NetCaps.Builder add/removeCap
+ public Builder removeExposedCapability(@VcnSupportedCapability int exposedCapability) {
checkValidCapability(exposedCapability);
mExposedCapabilities.remove(exposedCapability);
@@ -445,7 +435,6 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be required of underlying
* networks
- * @hide
*/
@NonNull
public Builder addRequiredUnderlyingCapability(
@@ -468,10 +457,10 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be required of underlying
* networks
- * @hide
*/
@NonNull
- public Builder clearRequiredUnderlyingCapability(
+ @SuppressLint("BuilderSetStyle") // For consistency with NetCaps.Builder add/removeCap
+ public Builder removeRequiredUnderlyingCapability(
@VcnSupportedCapability int underlyingCapability) {
checkValidCapability(underlyingCapability);
@@ -501,7 +490,6 @@ public final class VcnGatewayConnectionConfig {
* 15m]}
* @return this {@link Builder} instance, for chaining
* @see VcnManager for additional discussion on fail-safe mode
- * @hide
*/
@NonNull
public Builder setRetryInterval(@NonNull long[] retryIntervalsMs) {
@@ -523,7 +511,6 @@ public final class VcnGatewayConnectionConfig {
* @param maxMtu the maximum MTU allowed for this Gateway Connection. Must be greater than
* the IPv6 minimum MTU of 1280. Defaults to 1500.
* @return this {@link Builder} instance, for chaining
- * @hide
*/
@NonNull
public Builder setMaxMtu(@IntRange(from = MIN_MTU_V6) int maxMtu) {
@@ -538,7 +525,6 @@ public final class VcnGatewayConnectionConfig {
* Builds and validates the VcnGatewayConnectionConfig.
*
* @return an immutable VcnGatewayConnectionConfig instance
- * @hide
*/
@NonNull
public VcnGatewayConnectionConfig build() {
diff --git a/core/java/android/net/vcn/VcnManager.java b/core/java/android/net/vcn/VcnManager.java
index 1a38338c26aa..467043665da3 100644
--- a/core/java/android/net/vcn/VcnManager.java
+++ b/core/java/android/net/vcn/VcnManager.java
@@ -39,12 +39,12 @@ import java.util.concurrent.Executor;
/**
* VcnManager publishes APIs for applications to configure and manage Virtual Carrier Networks.
*
- * <p>A VCN creates a virtualization layer to allow MVNOs to aggregate heterogeneous physical
+ * <p>A VCN creates a virtualization layer to allow carriers to aggregate heterogeneous physical
* networks, unifying them as a single carrier network. This enables infrastructure flexibility on
- * the part of MVNOs without impacting user connectivity, abstracting the physical network
+ * the part of carriers without impacting user connectivity, abstracting the physical network
* technologies as an implementation detail of their public network.
*
- * <p>Each VCN virtualizes an Carrier's network by building tunnels to a carrier's core network over
+ * <p>Each VCN virtualizes a carrier's network by building tunnels to a carrier's core network over
* carrier-managed physical links and supports a IP mobility layer to ensure seamless transitions
* between the underlying networks. Each VCN is configured based on a Subscription Group (see {@link
* android.telephony.SubscriptionManager}) and aggregates all networks that are brought up based on
@@ -62,8 +62,6 @@ import java.util.concurrent.Executor;
* tasks. In Safe Mode, the system will allow underlying cellular networks to be used as default.
* Additionally, during Safe Mode, the VCN will continue to retry the connections, and will
* automatically exit Safe Mode if all active tunnels connect successfully.
- *
- * @hide
*/
@SystemService(Context.VCN_MANAGEMENT_SERVICE)
public class VcnManager {
@@ -101,7 +99,6 @@ public class VcnManager {
return Collections.unmodifiableMap(REGISTERED_POLICY_LISTENERS);
}
- // TODO: Make setVcnConfig(), clearVcnConfig() Public API
/**
* Sets the VCN configuration for a given subscription group.
*
@@ -113,11 +110,10 @@ public class VcnManager {
*
* @param subscriptionGroup the subscription group that the configuration should be applied to
* @param config the configuration parameters for the VCN
- * @throws SecurityException if the caller does not have carrier privileges, or is not running
- * as the primary user
- * @throws IOException if the configuration failed to be persisted. A caller encountering this
- * exception should attempt to retry (possibly after a delay).
- * @hide
+ * @throws SecurityException if the caller does not have carrier privileges for the provided
+ * subscriptionGroup, or is not running as the primary user
+ * @throws IOException if the configuration failed to be saved and persisted to disk. This may
+ * occur due to temporary disk errors, or more permanent conditions such as a full disk.
*/
@RequiresPermission("carrier privileges") // TODO (b/72967236): Define a system-wide constant
public void setVcnConfig(@NonNull ParcelUuid subscriptionGroup, @NonNull VcnConfig config)
@@ -134,7 +130,6 @@ public class VcnManager {
}
}
- // TODO: Make setVcnConfig(), clearVcnConfig() Public API
/**
* Clears the VCN configuration for a given subscription group.
*
@@ -145,9 +140,8 @@ public class VcnManager {
* @param subscriptionGroup the subscription group that the configuration should be applied to
* @throws SecurityException if the caller does not have carrier privileges, or is not running
* as the primary user
- * @throws IOException if the configuration failed to be cleared. A caller encountering this
- * exception should attempt to retry (possibly after a delay).
- * @hide
+ * @throws IOException if the configuration failed to be cleared from disk. This may occur due
+ * to temporary disk errors, or more permanent conditions such as a full disk.
*/
@RequiresPermission("carrier privileges") // TODO (b/72967236): Define a system-wide constant
public void clearVcnConfig(@NonNull ParcelUuid subscriptionGroup) throws IOException {
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 059e932a9da9..3774fb595680 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -1898,7 +1898,8 @@ public final class PowerManager {
* These estimates will be displayed on system UI surfaces in place of the system computed
* value.
*
- * Calling this requires the {@link android.Manifest.permission#DEVICE_POWER} permission.
+ * Calling this requires either the {@link android.Manifest.permission#DEVICE_POWER} or the
+ * {@link android.Manifest.permission#BATTERY_PREDICTION} permissions.
*
* @param timeRemaining The time remaining as a {@link Duration}.
* @param isPersonalized true if personalized based on device usage history, false otherwise.
@@ -1906,7 +1907,10 @@ public final class PowerManager {
* @hide
*/
@SystemApi
- @RequiresPermission(android.Manifest.permission.DEVICE_POWER)
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.BATTERY_PREDICTION,
+ android.Manifest.permission.DEVICE_POWER
+ })
public void setBatteryDischargePrediction(@NonNull Duration timeRemaining,
boolean isPersonalized) {
if (timeRemaining == null) {
diff --git a/core/java/android/permission/AdminPermissionControlParams.aidl b/core/java/android/permission/AdminPermissionControlParams.aidl
new file mode 100644
index 000000000000..35e63d4851fc
--- /dev/null
+++ b/core/java/android/permission/AdminPermissionControlParams.aidl
@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+package android.permission;
+
+parcelable AdminPermissionControlParams;
diff --git a/core/java/android/permission/AdminPermissionControlParams.java b/core/java/android/permission/AdminPermissionControlParams.java
new file mode 100644
index 000000000000..49507220e7b0
--- /dev/null
+++ b/core/java/android/permission/AdminPermissionControlParams.java
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+package android.permission;
+
+import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT;
+import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED;
+import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED;
+
+import static com.android.internal.util.Preconditions.checkArgument;
+
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+import android.app.admin.DevicePolicyManager;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.Preconditions;
+
+/**
+ * A data object representing an admin's request to control a certain permission
+ * for a certain app.
+ * This class is processed by the Permission Controller's
+ * setRuntimePermissionGrantStateByDeviceAdmin method.
+ *
+ * @hide
+ */
+@SystemApi
+public final class AdminPermissionControlParams implements Parcelable {
+ // The package to grant/deny the permission to.
+ private final @NonNull String mGranteePackageName;
+ // The permission to grant/deny.
+ private final @NonNull String mPermission;
+ // The grant state (granted/denied/default).
+ private final @DevicePolicyManager.PermissionGrantState int mGrantState;
+ // Whether the admin can grant sensors-related permissions.
+ private final boolean mCanAdminGrantSensorsPermissions;
+
+ /**
+ * @hide
+ * A new instance is only created by the framework, so the constructor need not be visible
+ * as system API.
+ */
+ public AdminPermissionControlParams(@NonNull String granteePackageName,
+ @NonNull String permission,
+ int grantState, boolean canAdminGrantSensorsPermissions) {
+ Preconditions.checkStringNotEmpty(granteePackageName, "Package name must not be empty.");
+ Preconditions.checkStringNotEmpty(permission, "Permission must not be empty.");
+ checkArgument(grantState == PERMISSION_GRANT_STATE_GRANTED
+ || grantState == PERMISSION_GRANT_STATE_DENIED
+ || grantState == PERMISSION_GRANT_STATE_DEFAULT);
+
+ mGranteePackageName = granteePackageName;
+ mPermission = permission;
+ mGrantState = grantState;
+ mCanAdminGrantSensorsPermissions = canAdminGrantSensorsPermissions;
+ }
+
+ public static final @NonNull Creator<AdminPermissionControlParams> CREATOR =
+ new Creator<AdminPermissionControlParams>() {
+ @Override
+ public AdminPermissionControlParams createFromParcel(Parcel in) {
+ String granteePackageName = in.readString();
+ String permission = in.readString();
+ int grantState = in.readInt();
+ boolean mayAdminGrantSensorPermissions = in.readBoolean();
+
+ return new AdminPermissionControlParams(granteePackageName, permission,
+ grantState, mayAdminGrantSensorPermissions);
+ }
+
+ @Override
+ public AdminPermissionControlParams[] newArray(int size) {
+ return new AdminPermissionControlParams[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeString(mGranteePackageName);
+ dest.writeString(mPermission);
+ dest.writeInt(mGrantState);
+ dest.writeBoolean(mCanAdminGrantSensorsPermissions);
+ }
+
+ /** Returns the name of the package the permission applies to */
+ public @NonNull String getGranteePackageName() {
+ return mGranteePackageName;
+ }
+
+ /** Returns the permission name */
+ public @NonNull String getPermission() {
+ return mPermission;
+ }
+
+ /** Returns the grant state */
+ public int getGrantState() {
+ return mGrantState;
+ }
+
+ /**
+ * return true if the admin may control grants of permissions related to sensors.
+ */
+ public boolean canAdminGrantSensorsPermissions() {
+ return mCanAdminGrantSensorsPermissions;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "Grantee %s Permission %s state: %d admin grant of sensors permissions: %b",
+ mGranteePackageName, mPermission, mGrantState, mCanAdminGrantSensorsPermissions);
+ }
+}
diff --git a/core/java/android/permission/IPermissionController.aidl b/core/java/android/permission/IPermissionController.aidl
index 084cc2ff4aa4..6d677f35b563 100644
--- a/core/java/android/permission/IPermissionController.aidl
+++ b/core/java/android/permission/IPermissionController.aidl
@@ -20,6 +20,7 @@ import android.os.RemoteCallback;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
+import android.permission.AdminPermissionControlParams;
import com.android.internal.infra.AndroidFuture;
/**
@@ -39,8 +40,8 @@ oneway interface IPermissionController {
void countPermissionApps(in List<String> permissionNames, int flags,
in AndroidFuture callback);
void getPermissionUsages(boolean countSystem, long numMillis, in AndroidFuture callback);
- void setRuntimePermissionGrantStateByDeviceAdmin(String callerPackageName, String packageName,
- String permission, int grantState, in AndroidFuture callback);
+ void setRuntimePermissionGrantStateByDeviceAdminFromParams(String callerPackageName,
+ in AdminPermissionControlParams params, in AndroidFuture callback);
void grantOrUpgradeDefaultRuntimePermissions(in AndroidFuture callback);
void notifyOneTimePermissionSessionTimeout(String packageName);
void updateUserSensitiveForApp(int uid, in AndroidFuture callback);
diff --git a/core/java/android/permission/PermissionControllerManager.java b/core/java/android/permission/PermissionControllerManager.java
index f306805ac3a4..084b18eb2999 100644
--- a/core/java/android/permission/PermissionControllerManager.java
+++ b/core/java/android/permission/PermissionControllerManager.java
@@ -16,13 +16,9 @@
package android.permission;
-import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT;
-import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED;
-import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED;
import static android.permission.PermissionControllerService.SERVICE_INTERFACE;
import static com.android.internal.util.FunctionalUtils.uncheckExceptions;
-import static com.android.internal.util.Preconditions.checkArgument;
import static com.android.internal.util.Preconditions.checkArgumentNonnegative;
import static com.android.internal.util.Preconditions.checkCollectionElementsNotNull;
import static com.android.internal.util.Preconditions.checkFlagsArgument;
@@ -39,7 +35,6 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.ActivityThread;
-import android.app.admin.DevicePolicyManager.PermissionGrantState;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -70,6 +65,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -323,11 +319,11 @@ public final class PermissionControllerManager {
/**
* Set the runtime permission state from a device admin.
+ * This variant takes into account whether the admin may or may not grant sensors-related
+ * permissions.
*
* @param callerPackageName The package name of the admin requesting the change
- * @param packageName Package the permission belongs to
- * @param permission Permission to change
- * @param grantState State to set the permission into
+ * @param params Information about the permission being granted.
* @param executor Executor to run the {@code callback} on
* @param callback The callback
*
@@ -338,30 +334,27 @@ public final class PermissionControllerManager {
Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY},
conditional = true)
public void setRuntimePermissionGrantStateByDeviceAdmin(@NonNull String callerPackageName,
- @NonNull String packageName, @NonNull String permission,
- @PermissionGrantState int grantState, @NonNull @CallbackExecutor Executor executor,
+ @NonNull AdminPermissionControlParams params,
+ @NonNull @CallbackExecutor Executor executor,
@NonNull Consumer<Boolean> callback) {
checkStringNotEmpty(callerPackageName);
- checkStringNotEmpty(packageName);
- checkStringNotEmpty(permission);
- checkArgument(grantState == PERMISSION_GRANT_STATE_GRANTED
- || grantState == PERMISSION_GRANT_STATE_DENIED
- || grantState == PERMISSION_GRANT_STATE_DEFAULT);
- checkNotNull(executor);
- checkNotNull(callback);
+ Objects.requireNonNull(executor);
+ Objects.requireNonNull(callback);
+ Objects.requireNonNull(params, "Admin control params must not be null.");
mRemoteService.postAsync(service -> {
AndroidFuture<Boolean> setRuntimePermissionGrantStateResult = new AndroidFuture<>();
- service.setRuntimePermissionGrantStateByDeviceAdmin(
- callerPackageName, packageName, permission, grantState,
+ service.setRuntimePermissionGrantStateByDeviceAdminFromParams(
+ callerPackageName, params,
setRuntimePermissionGrantStateResult);
return setRuntimePermissionGrantStateResult;
}).whenCompleteAsync((setRuntimePermissionGrantStateResult, err) -> {
final long token = Binder.clearCallingIdentity();
try {
if (err != null) {
- Log.e(TAG, "Error setting permissions state for device admin " + packageName,
- err);
+ Log.e(TAG,
+ "Error setting permissions state for device admin "
+ + callerPackageName, err);
callback.accept(false);
} else {
callback.accept(Boolean.TRUE.equals(setRuntimePermissionGrantStateResult));
diff --git a/core/java/android/permission/PermissionControllerService.java b/core/java/android/permission/PermissionControllerService.java
index 8105b6517015..ad9e8b3d6dd4 100644
--- a/core/java/android/permission/PermissionControllerService.java
+++ b/core/java/android/permission/PermissionControllerService.java
@@ -16,9 +16,7 @@
package android.permission;
-import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT;
import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED;
-import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED;
import static android.permission.PermissionControllerManager.COUNT_ONLY_WHEN_GRANTED;
import static android.permission.PermissionControllerManager.COUNT_WHEN_SYSTEM;
@@ -259,6 +257,8 @@ public abstract class PermissionControllerService extends Service {
}
/**
+ * @deprecated See {@link #onSetRuntimePermissionGrantStateByDeviceAdmin(String,
+ * AdminPermissionControlParams, Consumer)}.
* Set the runtime permission state from a device admin.
*
* @param callerPackageName The package name of the admin requesting the change
@@ -267,6 +267,7 @@ public abstract class PermissionControllerService extends Service {
* @param grantState State to set the permission into
* @param callback Callback waiting for whether the state could be set or not
*/
+ @Deprecated
@BinderThread
public abstract void onSetRuntimePermissionGrantStateByDeviceAdmin(
@NonNull String callerPackageName, @NonNull String packageName,
@@ -274,6 +275,20 @@ public abstract class PermissionControllerService extends Service {
@NonNull Consumer<Boolean> callback);
/**
+ * Set the runtime permission state from a device admin.
+ *
+ * @param callerPackageName The package name of the admin requesting the change
+ * @param params Parameters of admin request.
+ * @param callback Callback waiting for whether the state could be set or not
+ */
+ @BinderThread
+ public void onSetRuntimePermissionGrantStateByDeviceAdmin(
+ @NonNull String callerPackageName, @NonNull AdminPermissionControlParams params,
+ @NonNull Consumer<Boolean> callback) {
+ throw new AbstractMethodError("Must be overridden in implementing class");
+ }
+
+ /**
* Called when a package is considered inactive based on the criteria given by
* {@link PermissionManager#startOneTimePermissionSession(String, long, int, int)}.
* This method is called at the end of a one-time permission session
@@ -468,32 +483,26 @@ public abstract class PermissionControllerService extends Service {
}
@Override
- public void setRuntimePermissionGrantStateByDeviceAdmin(String callerPackageName,
- String packageName, String permission, int grantState,
+ public void setRuntimePermissionGrantStateByDeviceAdminFromParams(
+ String callerPackageName, AdminPermissionControlParams params,
AndroidFuture callback) {
checkStringNotEmpty(callerPackageName);
- checkStringNotEmpty(packageName);
- checkStringNotEmpty(permission);
- checkArgument(grantState == PERMISSION_GRANT_STATE_GRANTED
- || grantState == PERMISSION_GRANT_STATE_DENIED
- || grantState == PERMISSION_GRANT_STATE_DEFAULT);
- checkNotNull(callback);
-
- if (grantState == PERMISSION_GRANT_STATE_DENIED) {
+ if (params.getGrantState() == PERMISSION_GRANT_STATE_DENIED) {
enforceSomePermissionsGrantedToCaller(
Manifest.permission.GRANT_RUNTIME_PERMISSIONS);
}
- if (grantState == PERMISSION_GRANT_STATE_DENIED) {
+ if (params.getGrantState() == PERMISSION_GRANT_STATE_DENIED) {
enforceSomePermissionsGrantedToCaller(
Manifest.permission.REVOKE_RUNTIME_PERMISSIONS);
}
enforceSomePermissionsGrantedToCaller(
Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY);
+ checkNotNull(callback);
onSetRuntimePermissionGrantStateByDeviceAdmin(callerPackageName,
- packageName, permission, grantState, callback::complete);
+ params, callback::complete);
}
@Override
diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java
index 91e091c50532..e134c29520b2 100644
--- a/core/java/android/provider/DeviceConfig.java
+++ b/core/java/android/provider/DeviceConfig.java
@@ -525,6 +525,13 @@ public final class DeviceConfig {
*/
public static final String NAMESPACE_INTERACTION_JANK_MONITOR = "interaction_jank_monitor";
+ /**
+ * Namespace for game overlay related features.
+ *
+ * @hide
+ */
+ public static final String NAMESPACE_GAME_OVERLAY = "game_overlay";
+
private static final Object sLock = new Object();
@GuardedBy("sLock")
private static ArrayMap<OnPropertiesChangedListener, Pair<String, Executor>> sListeners =
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index ef81ed768e56..e979e13d89c5 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1902,6 +1902,18 @@ public final class Settings {
public static final String EXTRA_CONVERSATION_ID = "android.provider.extra.CONVERSATION_ID";
/**
+ * Activity Extra: An {@code Arraylist<String>} of {@link NotificationChannel} field names to
+ * show on the Settings UI.
+ *
+ * <p>
+ * This is an optional extra field to the {@link #ACTION_CHANNEL_NOTIFICATION_SETTINGS}. If
+ * included the system will filter out any Settings that doesn't appear in this list that
+ * otherwise would display.
+ */
+ public static final String EXTRA_CHANNEL_FILTER_LIST
+ = "android.provider.extra.CHANNEL_FILTER_LIST";
+
+ /**
* Activity Action: Show notification redaction settings.
*
* @hide
@@ -10780,6 +10792,13 @@ public final class Settings {
"location_ignore_settings_package_whitelist";
/**
+ * Whether to throttle location when the device is in doze and still.
+ * @hide
+ */
+ public static final String LOCATION_ENABLE_STATIONARY_THROTTLE =
+ "location_enable_stationary_throttle";
+
+ /**
* Whether TV will switch to MHL port when a mobile device is plugged in.
* (0 = false, 1 = true)
* @hide
diff --git a/core/java/android/provider/SimPhonebookContract.java b/core/java/android/provider/SimPhonebookContract.java
index 2efc21229422..074d5f167ec3 100644
--- a/core/java/android/provider/SimPhonebookContract.java
+++ b/core/java/android/provider/SimPhonebookContract.java
@@ -29,11 +29,8 @@ import android.annotation.SystemApi;
import android.annotation.WorkerThread;
import android.content.ContentResolver;
import android.content.ContentValues;
-import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Parcel;
-import android.os.Parcelable;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
@@ -63,7 +60,6 @@ public final class SimPhonebookContract {
*
* @hide
*/
- @SystemApi
public static final String SUBSCRIPTION_ID_PATH_SEGMENT = "subid";
private SimPhonebookContract() {
@@ -76,7 +72,6 @@ public final class SimPhonebookContract {
* @hide
*/
@NonNull
- @SystemApi
public static String getEfUriPath(@ElementaryFiles.EfType int efType) {
switch (efType) {
case EF_ADN:
@@ -122,12 +117,12 @@ public final class SimPhonebookContract {
* The name for this record.
*
* <p>An {@link IllegalArgumentException} will be thrown by insert and update if this
- * exceeds the maximum supported length or contains unsupported characters.
- * {@link #validateName(ContentResolver, int, int, String)} )} can be used to
- * check whether the name is supported.
+ * exceeds the maximum supported length. Use
+ * {@link #getEncodedNameLength(ContentResolver, String)} to check how long the name
+ * will be after encoding.
*
* @see ElementaryFiles#NAME_MAX_LENGTH
- * @see #validateName(ContentResolver, int, int, String) )
+ * @see #getEncodedNameLength(ContentResolver, String)
*/
public static final String NAME = "name";
/**
@@ -149,24 +144,31 @@ public final class SimPhonebookContract {
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/sim-contact_v2";
/**
- * The path segment that is appended to {@link #getContentUri(int, int)} which indicates
- * that the following path segment contains a name to be validated.
+ * Value returned from {@link #getEncodedNameLength(ContentResolver, String)} when the name
+ * length could not be determined because the name could not be encoded.
+ */
+ public static final int ERROR_NAME_UNSUPPORTED = -1;
+
+ /**
+ * The method name used to get the encoded length of a value for {@link SimRecords#NAME}
+ * column.
*
* @hide
- * @see #validateName(ContentResolver, int, int, String)
+ * @see #getEncodedNameLength(ContentResolver, String)
+ * @see ContentResolver#call(String, String, String, Bundle)
*/
- @SystemApi
- public static final String VALIDATE_NAME_PATH_SEGMENT = "validate_name";
+ public static final String GET_ENCODED_NAME_LENGTH_METHOD_NAME = "get_encoded_name_length";
/**
- * The key for a cursor extra that contains the result of a validate name query.
+ * Extra key used for an integer value that contains the length in bytes of an encoded
+ * name.
*
* @hide
- * @see #validateName(ContentResolver, int, int, String)
+ * @see #getEncodedNameLength(ContentResolver, String)
+ * @see #GET_ENCODED_NAME_LENGTH_METHOD_NAME
*/
- @SystemApi
- public static final String EXTRA_NAME_VALIDATION_RESULT =
- "android.provider.extra.NAME_VALIDATION_RESULT";
+ public static final String EXTRA_ENCODED_NAME_LENGTH =
+ "android.provider.extra.ENCODED_NAME_LENGTH";
/**
@@ -244,32 +246,34 @@ public final class SimPhonebookContract {
}
/**
- * Validates a value that is being provided for the {@link #NAME} column.
+ * Returns the number of bytes required to encode the specified name when it is stored
+ * on the SIM.
*
- * <p>The return value can be used to check if the name is valid. If it is not valid then
- * inserts and updates to the specified elementary file that use the provided name value
- * will throw an {@link IllegalArgumentException}.
+ * <p>{@link ElementaryFiles#NAME_MAX_LENGTH} is specified in bytes but the encoded name
+ * may require more than 1 byte per character depending on the characters it contains. So
+ * this method can be used to check whether a name exceeds the max length.
*
- * <p>If the specified SIM or elementary file don't exist then
- * {@link NameValidationResult#getMaxEncodedLength()} will be zero and
- * {@link NameValidationResult#isValid()} will return false.
+ * @return the number of bytes required by the encoded name or
+ * {@link #ERROR_NAME_UNSUPPORTED} if the name could not be encoded.
+ * @throws IllegalStateException if the provider fails to return the length.
+ * @see SimRecords#NAME
+ * @see ElementaryFiles#NAME_MAX_LENGTH
*/
- @NonNull
@WorkerThread
- public static NameValidationResult validateName(
- @NonNull ContentResolver resolver, int subscriptionId,
- @ElementaryFiles.EfType int efType,
- @NonNull String name) {
- Bundle queryArgs = new Bundle();
- queryArgs.putString(SimRecords.NAME, name);
- try (Cursor cursor =
- resolver.query(buildContentUri(subscriptionId, efType)
- .appendPath(VALIDATE_NAME_PATH_SEGMENT)
- .build(), null, queryArgs, null)) {
- NameValidationResult result = cursor.getExtras()
- .getParcelable(EXTRA_NAME_VALIDATION_RESULT);
- return result != null ? result : new NameValidationResult(name, "", 0, 0);
+ public static int getEncodedNameLength(
+ @NonNull ContentResolver resolver, @NonNull String name) {
+ Objects.requireNonNull(name);
+ Bundle result = resolver.call(AUTHORITY, GET_ENCODED_NAME_LENGTH_METHOD_NAME, name,
+ null);
+ if (result == null || !result.containsKey(EXTRA_ENCODED_NAME_LENGTH)) {
+ throw new IllegalStateException("Provider malfunction: no length was returned.");
}
+ int length = result.getInt(EXTRA_ENCODED_NAME_LENGTH, ERROR_NAME_UNSUPPORTED);
+ if (length < 0 && length != ERROR_NAME_UNSUPPORTED) {
+ throw new IllegalStateException(
+ "Provider malfunction: invalid length was returned.");
+ }
+ return length;
}
private static Uri.Builder buildContentUri(
@@ -281,106 +285,6 @@ public final class SimPhonebookContract {
.appendPath(getEfUriPath(efType));
}
- /** Contains details about the validity of a value provided for the {@link #NAME} column. */
- public static final class NameValidationResult implements Parcelable {
-
- @NonNull
- public static final Creator<NameValidationResult> CREATOR =
- new Creator<NameValidationResult>() {
-
- @Override
- public NameValidationResult createFromParcel(@NonNull Parcel in) {
- return new NameValidationResult(in);
- }
-
- @NonNull
- @Override
- public NameValidationResult[] newArray(int size) {
- return new NameValidationResult[size];
- }
- };
-
- private final String mName;
- private final String mSanitizedName;
- private final int mEncodedLength;
- private final int mMaxEncodedLength;
-
- /** Creates a new instance from the provided values. */
- public NameValidationResult(@NonNull String name, @NonNull String sanitizedName,
- int encodedLength, int maxEncodedLength) {
- this.mName = Objects.requireNonNull(name);
- this.mSanitizedName = Objects.requireNonNull(sanitizedName);
- this.mEncodedLength = encodedLength;
- this.mMaxEncodedLength = maxEncodedLength;
- }
-
- private NameValidationResult(Parcel in) {
- this(in.readString(), in.readString(), in.readInt(), in.readInt());
- }
-
- /** Returns the original name that is being validated. */
- @NonNull
- public String getName() {
- return mName;
- }
-
- /**
- * Returns a sanitized copy of the original name with all unsupported characters
- * replaced with spaces.
- */
- @NonNull
- public String getSanitizedName() {
- return mSanitizedName;
- }
-
- /**
- * Returns whether the original name isValid.
- *
- * <p>If this returns false then inserts and updates using the name will throw an
- * {@link IllegalArgumentException}
- */
- public boolean isValid() {
- return mMaxEncodedLength > 0 && mEncodedLength <= mMaxEncodedLength
- && Objects.equals(
- mName, mSanitizedName);
- }
-
- /** Returns whether the character at the specified position is supported by the SIM. */
- public boolean isSupportedCharacter(int position) {
- return mName.charAt(position) == mSanitizedName.charAt(position);
- }
-
- /**
- * Returns the number of bytes required to save the name.
- *
- * <p>This may be more than the number of characters in the name.
- */
- public int getEncodedLength() {
- return mEncodedLength;
- }
-
- /**
- * Returns the maximum number of bytes that are supported for the name.
- *
- * @see ElementaryFiles#NAME_MAX_LENGTH
- */
- public int getMaxEncodedLength() {
- return mMaxEncodedLength;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeString(mName);
- dest.writeString(mSanitizedName);
- dest.writeInt(mEncodedLength);
- dest.writeInt(mMaxEncodedLength);
- }
- }
}
/** Constants for metadata about the elementary files of the SIM cards in the phone. */
@@ -446,13 +350,10 @@ public final class SimPhonebookContract {
*/
public static final int EF_SDN = 3;
/** @hide */
- @SystemApi
public static final String EF_ADN_PATH_SEGMENT = "adn";
/** @hide */
- @SystemApi
public static final String EF_FDN_PATH_SEGMENT = "fdn";
/** @hide */
- @SystemApi
public static final String EF_SDN_PATH_SEGMENT = "sdn";
/** The MIME type of CONTENT_URI providing a directory of ADN-like elementary files. */
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/sim-elementary-file";
@@ -464,7 +365,6 @@ public final class SimPhonebookContract {
*
* @hide
*/
- @SystemApi
public static final String ELEMENTARY_FILES_PATH_SEGMENT = "elementary_files";
/** Content URI for the ADN-like elementary files available on the device. */
@@ -480,8 +380,7 @@ public final class SimPhonebookContract {
* Returns a content uri for a specific elementary file.
*
* <p>If a SIM with the specified subscriptionId is not present an exception will be thrown.
- * If the SIM doesn't support the specified elementary file it will have a zero value for
- * {@link #MAX_RECORDS}.
+ * If the SIM doesn't support the specified elementary file it will return an empty cursor.
*/
@NonNull
public static Uri getItemUri(int subscriptionId, @EfType int efType) {
diff --git a/core/java/android/speech/tts/ITextToSpeechManager.aidl b/core/java/android/speech/tts/ITextToSpeechManager.aidl
new file mode 100644
index 000000000000..e6b63dff1553
--- /dev/null
+++ b/core/java/android/speech/tts/ITextToSpeechManager.aidl
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package android.speech.tts;
+
+import android.speech.tts.ITextToSpeechSessionCallback;
+
+/**
+ * TextToSpeechManagerService interface. Allows opening {@link TextToSpeech} session with the
+ * specified provider proxied by the system service.
+ *
+ * @hide
+ */
+oneway interface ITextToSpeechManager {
+ void createSession(in String engine, in ITextToSpeechSessionCallback managerCallback);
+}
diff --git a/core/java/android/speech/tts/ITextToSpeechSession.aidl b/core/java/android/speech/tts/ITextToSpeechSession.aidl
new file mode 100644
index 000000000000..b2afeb0d1ba8
--- /dev/null
+++ b/core/java/android/speech/tts/ITextToSpeechSession.aidl
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package android.speech.tts;
+
+/**
+ * TextToSpeech session interface. Allows to control remote TTS service session once connected.
+ *
+ * @see ITextToSpeechManager
+ * @see ITextToSpeechSessionCallback
+ *
+ * {@hide}
+ */
+oneway interface ITextToSpeechSession {
+
+ /**
+ * Disconnects the client from the TTS provider.
+ */
+ void disconnect();
+} \ No newline at end of file
diff --git a/core/java/android/speech/tts/ITextToSpeechSessionCallback.aidl b/core/java/android/speech/tts/ITextToSpeechSessionCallback.aidl
new file mode 100644
index 000000000000..545622a007f3
--- /dev/null
+++ b/core/java/android/speech/tts/ITextToSpeechSessionCallback.aidl
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package android.speech.tts;
+import android.speech.tts.ITextToSpeechSession;
+
+/**
+ * Callback interface for a session created by {@link ITextToSpeechManager} API.
+ *
+ * @hide
+ */
+oneway interface ITextToSpeechSessionCallback {
+
+ void onConnected(in ITextToSpeechSession session, in IBinder serviceBinder);
+
+ void onDisconnected();
+
+ void onError(in String errorInfo);
+} \ No newline at end of file
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index 7a185382a631..5d66dc7f29eb 100644
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -35,6 +35,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.text.TextUtils;
import android.util.Log;
@@ -51,6 +52,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Set;
+import java.util.concurrent.Executor;
/**
*
@@ -695,6 +697,8 @@ public class TextToSpeech {
public static final String KEY_FEATURE_NETWORK_RETRIES_COUNT = "networkRetriesCount";
}
+ private static final boolean DEBUG = false;
+
private final Context mContext;
@UnsupportedAppUsage
private Connection mConnectingServiceConnection;
@@ -716,6 +720,9 @@ public class TextToSpeech {
private final Map<CharSequence, Uri> mUtterances;
private final Bundle mParams = new Bundle();
private final TtsEngines mEnginesHelper;
+ private final boolean mIsSystem;
+ @Nullable private final Executor mInitExecutor;
+
@UnsupportedAppUsage
private volatile String mCurrentEngine = null;
@@ -758,8 +765,21 @@ public class TextToSpeech {
*/
public TextToSpeech(Context context, OnInitListener listener, String engine,
String packageName, boolean useFallback) {
+ this(context, /* initExecutor= */ null, listener, engine, packageName,
+ useFallback, /* isSystem= */ true);
+ }
+
+ /**
+ * Used internally to instantiate TextToSpeech objects.
+ *
+ * @hide
+ */
+ private TextToSpeech(Context context, @Nullable Executor initExecutor,
+ OnInitListener initListener, String engine, String packageName, boolean useFallback,
+ boolean isSystem) {
mContext = context;
- mInitListener = listener;
+ mInitExecutor = initExecutor;
+ mInitListener = initListener;
mRequestedEngine = engine;
mUseFallback = useFallback;
@@ -768,6 +788,9 @@ public class TextToSpeech {
mUtteranceProgressListener = null;
mEnginesHelper = new TtsEngines(mContext);
+
+ mIsSystem = isSystem;
+
initTts();
}
@@ -842,10 +865,14 @@ public class TextToSpeech {
}
private boolean connectToEngine(String engine) {
- Connection connection = new Connection();
- Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
- intent.setPackage(engine);
- boolean bound = mContext.bindService(intent, connection, Context.BIND_AUTO_CREATE);
+ Connection connection;
+ if (mIsSystem) {
+ connection = new SystemConnection();
+ } else {
+ connection = new DirectConnection();
+ }
+
+ boolean bound = connection.connect(engine);
if (!bound) {
Log.e(TAG, "Failed to bind to " + engine);
return false;
@@ -857,11 +884,19 @@ public class TextToSpeech {
}
private void dispatchOnInit(int result) {
- synchronized (mStartLock) {
- if (mInitListener != null) {
- mInitListener.onInit(result);
- mInitListener = null;
+ Runnable onInitCommand = () -> {
+ synchronized (mStartLock) {
+ if (mInitListener != null) {
+ mInitListener.onInit(result);
+ mInitListener = null;
+ }
}
+ };
+
+ if (mInitExecutor != null) {
+ mInitExecutor.execute(onInitCommand);
+ } else {
+ onInitCommand.run();
}
}
@@ -2127,13 +2162,17 @@ public class TextToSpeech {
return mEnginesHelper.getEngines();
}
- private class Connection implements ServiceConnection {
+ private abstract class Connection implements ServiceConnection {
private ITextToSpeechService mService;
private SetupConnectionAsyncTask mOnSetupConnectionAsyncTask;
private boolean mEstablished;
+ abstract boolean connect(String engine);
+
+ abstract void disconnect();
+
private final ITextToSpeechCallback.Stub mCallback =
new ITextToSpeechCallback.Stub() {
public void onStop(String utteranceId, boolean isStarted)
@@ -2199,11 +2238,6 @@ public class TextToSpeech {
};
private class SetupConnectionAsyncTask extends AsyncTask<Void, Void, Integer> {
- private final ComponentName mName;
-
- public SetupConnectionAsyncTask(ComponentName name) {
- mName = name;
- }
@Override
protected Integer doInBackground(Void... params) {
@@ -2227,7 +2261,7 @@ public class TextToSpeech {
mParams.putString(Engine.KEY_PARAM_VOICE_NAME, defaultVoiceName);
}
- Log.i(TAG, "Set up connection to " + mName);
+ Log.i(TAG, "Setting up the connection to TTS engine...");
return SUCCESS;
} catch (RemoteException re) {
Log.e(TAG, "Error connecting to service, setCallback() failed");
@@ -2249,11 +2283,11 @@ public class TextToSpeech {
}
@Override
- public void onServiceConnected(ComponentName name, IBinder service) {
+ public void onServiceConnected(ComponentName componentName, IBinder service) {
synchronized(mStartLock) {
mConnectingServiceConnection = null;
- Log.i(TAG, "Connected to " + name);
+ Log.i(TAG, "Connected to TTS engine");
if (mOnSetupConnectionAsyncTask != null) {
mOnSetupConnectionAsyncTask.cancel(false);
@@ -2263,7 +2297,7 @@ public class TextToSpeech {
mServiceConnection = Connection.this;
mEstablished = false;
- mOnSetupConnectionAsyncTask = new SetupConnectionAsyncTask(name);
+ mOnSetupConnectionAsyncTask = new SetupConnectionAsyncTask();
mOnSetupConnectionAsyncTask.execute();
}
}
@@ -2277,7 +2311,7 @@ public class TextToSpeech {
*
* @return true if we cancel mOnSetupConnectionAsyncTask in progress.
*/
- private boolean clearServiceConnection() {
+ protected boolean clearServiceConnection() {
synchronized(mStartLock) {
boolean result = false;
if (mOnSetupConnectionAsyncTask != null) {
@@ -2295,8 +2329,8 @@ public class TextToSpeech {
}
@Override
- public void onServiceDisconnected(ComponentName name) {
- Log.i(TAG, "Asked to disconnect from " + name);
+ public void onServiceDisconnected(ComponentName componentName) {
+ Log.i(TAG, "Disconnected from TTS engine");
if (clearServiceConnection()) {
/* We need to protect against a rare case where engine
* dies just after successful connection - and we process onServiceDisconnected
@@ -2308,11 +2342,6 @@ public class TextToSpeech {
}
}
- public void disconnect() {
- mContext.unbindService(this);
- clearServiceConnection();
- }
-
public boolean isEstablished() {
return mService != null && mEstablished;
}
@@ -2342,6 +2371,91 @@ public class TextToSpeech {
}
}
+ // Currently all the clients are routed through the System connection. Direct connection
+ // is left for debugging, testing and benchmarking purposes.
+ // TODO(b/179599071): Remove direct connection once system one is fully tested.
+ private class DirectConnection extends Connection {
+ @Override
+ boolean connect(String engine) {
+ Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
+ intent.setPackage(engine);
+ return mContext.bindService(intent, this, Context.BIND_AUTO_CREATE);
+ }
+
+ @Override
+ void disconnect() {
+ mContext.unbindService(this);
+ clearServiceConnection();
+ }
+ }
+
+ private class SystemConnection extends Connection {
+
+ @Nullable
+ private volatile ITextToSpeechSession mSession;
+
+ @Override
+ boolean connect(String engine) {
+ IBinder binder = ServiceManager.getService(Context.TEXT_TO_SPEECH_MANAGER_SERVICE);
+
+ ITextToSpeechManager manager = ITextToSpeechManager.Stub.asInterface(binder);
+
+ if (manager == null) {
+ Log.e(TAG, "System service is not available!");
+ return false;
+ }
+
+ if (DEBUG) {
+ Log.d(TAG, "Connecting to engine: " + engine);
+ }
+
+ try {
+ manager.createSession(engine, new ITextToSpeechSessionCallback.Stub() {
+ @Override
+ public void onConnected(ITextToSpeechSession session, IBinder serviceBinder) {
+ mSession = session;
+ onServiceConnected(
+ /* componentName= */ null,
+ serviceBinder);
+ }
+
+ @Override
+ public void onDisconnected() {
+ onServiceDisconnected(/* componentName= */ null);
+ }
+
+ @Override
+ public void onError(String errorInfo) {
+ Log.w(TAG, "System TTS connection error: " + errorInfo);
+ // The connection was not established successfully - handle as
+ // disconnection: clear the state and notify the user.
+ onServiceDisconnected(/* componentName= */ null);
+ }
+ });
+
+ return true;
+ } catch (RemoteException ex) {
+ Log.e(TAG, "Error communicating with the System Server: ", ex);
+ throw ex.rethrowFromSystemServer();
+ }
+ }
+
+ @Override
+ void disconnect() {
+ ITextToSpeechSession session = mSession;
+
+ if (session != null) {
+ try {
+ session.disconnect();
+ } catch (RemoteException ex) {
+ Log.w(TAG, "Error disconnecting session", ex);
+ }
+
+ clearServiceConnection();
+ }
+ }
+ }
+
private interface Action<R> {
R run(ITextToSpeechService service) throws RemoteException;
}
diff --git a/core/java/android/uwb/RangingSession.java b/core/java/android/uwb/RangingSession.java
index bfa8bf21ec6a..52ec5bde0dac 100644
--- a/core/java/android/uwb/RangingSession.java
+++ b/core/java/android/uwb/RangingSession.java
@@ -16,8 +16,10 @@
package android.uwb;
+import android.Manifest;
import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.os.Binder;
import android.os.PersistableBundle;
@@ -247,6 +249,7 @@ public final class RangingSession implements AutoCloseable {
*
* @param params configuration parameters for starting the session
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public void start(@NonNull PersistableBundle params) {
if (mState != State.IDLE) {
throw new IllegalStateException();
@@ -271,6 +274,7 @@ public final class RangingSession implements AutoCloseable {
*
* @param params the parameters to reconfigure and their new values
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public void reconfigure(@NonNull PersistableBundle params) {
if (mState != State.ACTIVE && mState != State.IDLE) {
throw new IllegalStateException();
@@ -302,6 +306,7 @@ public final class RangingSession implements AutoCloseable {
* <p>On failure to stop the session,
* {@link RangingSession.Callback#onStopFailed(int, PersistableBundle)} is invoked.
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public void stop() {
if (mState != State.ACTIVE) {
throw new IllegalStateException();
@@ -333,6 +338,7 @@ public final class RangingSession implements AutoCloseable {
* {@link #close()}, even if the {@link RangingSession} is already closed.
*/
@Override
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public void close() {
if (mState == State.CLOSED) {
mExecutor.execute(() -> mCallback.onClosed(
diff --git a/core/java/android/uwb/UwbManager.java b/core/java/android/uwb/UwbManager.java
index 8adfe0601b14..2dc0ba0b9b80 100644
--- a/core/java/android/uwb/UwbManager.java
+++ b/core/java/android/uwb/UwbManager.java
@@ -16,9 +16,11 @@
package android.uwb;
+import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
@@ -154,6 +156,7 @@ public final class UwbManager {
* @param executor an {@link Executor} to execute given callback
* @param callback user implementation of the {@link AdapterStateCallback}
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public void registerAdapterStateCallback(@NonNull @CallbackExecutor Executor executor,
@NonNull AdapterStateCallback callback) {
mAdapterStateListener.register(executor, callback);
@@ -168,6 +171,7 @@ public final class UwbManager {
*
* @param callback user implementation of the {@link AdapterStateCallback}
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public void unregisterAdapterStateCallback(@NonNull AdapterStateCallback callback) {
mAdapterStateListener.unregister(callback);
}
@@ -181,6 +185,7 @@ public final class UwbManager {
* @return {@link PersistableBundle} of the device's supported UWB protocols and parameters
*/
@NonNull
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public PersistableBundle getSpecificationInfo() {
try {
return mUwbAdapter.getSpecificationInfo();
@@ -194,6 +199,7 @@ public final class UwbManager {
*
* @return true if ranging is supported
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public boolean isRangingSupported() {
try {
return mUwbAdapter.isRangingSupported();
@@ -250,6 +256,7 @@ public final class UwbManager {
* @return angle of arrival type supported
*/
@AngleOfArrivalSupportType
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public int getAngleOfArrivalSupport() {
try {
switch (mUwbAdapter.getAngleOfArrivalSupport()) {
@@ -281,6 +288,7 @@ public final class UwbManager {
* @return {@link List} of supported channel numbers ordered by preference
*/
@NonNull
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public List<Integer> getSupportedChannelNumbers() {
List<Integer> channels = new ArrayList<>();
try {
@@ -300,6 +308,7 @@ public final class UwbManager {
* @return {@link List} of supported preamble code indices
*/
@NonNull
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public Set<Integer> getSupportedPreambleCodeIndices() {
Set<Integer> preambles = new HashSet<>();
try {
@@ -320,6 +329,7 @@ public final class UwbManager {
* @return the timestamp resolution in nanoseconds
*/
@SuppressLint("MethodNameUnits")
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public long elapsedRealtimeResolutionNanos() {
try {
return mUwbAdapter.getTimestampResolutionNanos();
@@ -333,6 +343,7 @@ public final class UwbManager {
*
* @return the maximum allowed number of simultaneously open {@link RangingSession} instances.
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public int getMaxSimultaneousSessions() {
try {
return mUwbAdapter.getMaxSimultaneousSessions();
@@ -347,6 +358,7 @@ public final class UwbManager {
*
* @return the maximum number of remote devices per {@link RangingSession}
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public int getMaxRemoteDevicesPerInitiatorSession() {
try {
return mUwbAdapter.getMaxRemoteDevicesPerInitiatorSession();
@@ -361,6 +373,7 @@ public final class UwbManager {
*
* @return the maximum number of remote devices per {@link RangingSession}
*/
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public int getMaxRemoteDevicesPerResponderSession() {
try {
return mUwbAdapter.getMaxRemoteDevicesPerResponderSession();
@@ -396,6 +409,7 @@ public final class UwbManager {
* {@link RangingSession.Callback#onOpened(RangingSession)}.
*/
@NonNull
+ @RequiresPermission(Manifest.permission.UWB_PRIVILEGED)
public AutoCloseable openRangingSession(@NonNull PersistableBundle parameters,
@NonNull @CallbackExecutor Executor executor,
@NonNull RangingSession.Callback callbacks) {
diff --git a/core/java/android/view/FrameMetrics.java b/core/java/android/view/FrameMetrics.java
index 5937499744b8..6543de15f969 100644
--- a/core/java/android/view/FrameMetrics.java
+++ b/core/java/android/view/FrameMetrics.java
@@ -154,6 +154,24 @@ public final class FrameMetrics {
*/
public static final int VSYNC_TIMESTAMP = 11;
+ /**
+ * Metric identifier for GPU duration.
+ * <p>
+ * Represents the total time in nanoseconds this frame took to complete on the GPU.
+ * </p>
+ **/
+ public static final int GPU_DURATION = 12;
+
+ /**
+ * Metric identifier for the total duration that was available to the app to produce a frame.
+ * <p>
+ * Represents the total time in nanoseconds the system allocated for the app to produce its
+ * frame. If FrameMetrics.TOTAL_DURATION < FrameMetrics.DEADLINE, the app hit its intended
+ * deadline and there was no jank visible to the user.
+ * </p>
+ **/
+ public static final int DEADLINE = 13;
+
private static final int FRAME_INFO_FLAG_FIRST_DRAW = 1 << 0;
/**
@@ -175,6 +193,8 @@ public final class FrameMetrics {
FIRST_DRAW_FRAME,
INTENDED_VSYNC_TIMESTAMP,
VSYNC_TIMESTAMP,
+ GPU_DURATION,
+ DEADLINE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface Metric {}
@@ -205,6 +225,8 @@ public final class FrameMetrics {
Index.ISSUE_DRAW_COMMANDS_START,
Index.SWAP_BUFFERS,
Index.FRAME_COMPLETED,
+ Index.GPU_COMPLETED,
+ Index.SWAP_BUFFERS_COMPLETED
})
@Retention(RetentionPolicy.SOURCE)
public @interface Index {
@@ -224,8 +246,10 @@ public final class FrameMetrics {
int ISSUE_DRAW_COMMANDS_START = 13;
int SWAP_BUFFERS = 14;
int FRAME_COMPLETED = 15;
+ int GPU_COMPLETED = 18;
+ int SWAP_BUFFERS_COMPLETED = 19;
- int FRAME_STATS_COUNT = 19; // must always be last and in sync with
+ int FRAME_STATS_COUNT = 20; // must always be last and in sync with
// FrameInfoIndex::NumIndexes in libs/hwui/FrameInfo.h
}
@@ -251,9 +275,19 @@ public final class FrameMetrics {
// COMMAND_ISSUE
Index.ISSUE_DRAW_COMMANDS_START, Index.SWAP_BUFFERS,
// SWAP_BUFFERS
- Index.SWAP_BUFFERS, Index.FRAME_COMPLETED,
+ Index.SWAP_BUFFERS, Index.SWAP_BUFFERS_COMPLETED,
// TOTAL_DURATION
Index.INTENDED_VSYNC, Index.FRAME_COMPLETED,
+ // RESERVED for FIRST_DRAW_FRAME
+ 0, 0,
+ // RESERVED forINTENDED_VSYNC_TIMESTAMP
+ 0, 0,
+ // RESERVED VSYNC_TIMESTAMP
+ 0, 0,
+ // GPU_DURATION
+ Index.SWAP_BUFFERS, Index.GPU_COMPLETED,
+ // DEADLINE
+ Index.INTENDED_VSYNC, Index.FRAME_DEADLINE,
};
/**
@@ -294,7 +328,7 @@ public final class FrameMetrics {
* @return the value of the metric or -1 if it is not available.
*/
public long getMetric(@Metric int id) {
- if (id < UNKNOWN_DELAY_DURATION || id > VSYNC_TIMESTAMP) {
+ if (id < UNKNOWN_DELAY_DURATION || id > DEADLINE) {
return -1;
}
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 6a629ca4e462..66b9617714a6 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -2404,7 +2404,7 @@ public final class SurfaceControl implements Parcelable {
if (Float.isNaN(brightness) || brightness > 1.0f
|| (brightness < 0.0f && brightness != -1.0f)) {
throw new IllegalArgumentException("brightness must be a number between 0.0f and 1.0f,"
- + " or -1 to turn the backlight off.");
+ + " or -1 to turn the backlight off: " + brightness);
}
return nativeSetDisplayBrightness(displayToken, brightness);
}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 1273b491d0e1..44d4d6b24f58 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -22164,6 +22164,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* and hardware acceleration.
*/
boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
+ // Clear the overscroll effect:
+ // TODO: Use internal API instead of overriding the existing RenderEffect
+ setRenderEffect(null);
+
final boolean hardwareAcceleratedCanvas = canvas.isHardwareAccelerated();
/* If an attached view draws to a HW canvas, it may use its RenderNode + DisplayList.
*
@@ -24028,6 +24032,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #getBackgroundTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setBackgroundTintBlendMode(@Nullable BlendMode blendMode) {
if (mBackgroundTint == null) {
mBackgroundTint = new TintInfo();
@@ -24290,6 +24295,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #getForegroundTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setForegroundTintBlendMode(@Nullable BlendMode blendMode) {
if (mForegroundInfo == null) {
mForegroundInfo = new ForegroundInfo();
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 228ee3c76b14..f1f6786aa43e 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -1375,6 +1375,7 @@ public final class ViewRootImpl implements ViewParent,
final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets;
mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent,
attrs.getTitle().toString());
+ mAttachInfo.mThreadedRenderer.setSurfaceControl(mSurfaceControl);
updateColorModeIfNeeded(attrs.getColorMode());
updateForceDarkMode();
if (mAttachInfo.mThreadedRenderer != null) {
@@ -1941,6 +1942,10 @@ public final class ViewRootImpl implements ViewParent,
mBlastBufferQueue.destroy();
mBlastBufferQueue = null;
}
+
+ if (mAttachInfo.mThreadedRenderer != null) {
+ mAttachInfo.mThreadedRenderer.setSurfaceControl(null);
+ }
}
/**
@@ -7651,6 +7656,9 @@ public final class ViewRootImpl implements ViewParent,
mSurface.transferFrom(blastSurface);
}
}
+ if (mAttachInfo.mThreadedRenderer != null) {
+ mAttachInfo.mThreadedRenderer.setSurfaceControl(mSurfaceControl);
+ }
} else {
destroySurface();
}
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 7b2bb73ff562..a8fff8bb6a43 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -749,7 +749,7 @@ public final class InputMethodManager {
@Override
public boolean hasActiveConnection(View view) {
synchronized (mH) {
- if (!hasServedByInputMethodLocked(view)) {
+ if (!hasServedByInputMethodLocked(view) || mCurMethod == null) {
return false;
}
@@ -765,6 +765,17 @@ public final class InputMethodManager {
return mDelegate;
}
+ /**
+ * Checks whether the active input connection (if any) is for the given view.
+ *
+ * @hide
+ * @see ImeFocusController#getImmDelegate()#hasActiveInputConnection(View)
+ */
+ @TestApi
+ public boolean hasActiveInputConnection(@Nullable View view) {
+ return mDelegate.hasActiveConnection(view);
+ }
+
private View getServedViewLocked() {
return mCurRootView != null ? mCurRootView.getImeFocusController().getServedView() : null;
}
diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java
index 2e75834f4ec5..bc2b221d134a 100644
--- a/core/java/android/webkit/WebViewFactory.java
+++ b/core/java/android/webkit/WebViewFactory.java
@@ -31,6 +31,7 @@ import android.content.pm.Signature;
import android.os.Build;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.SystemClock;
import android.os.Trace;
import android.util.AndroidRuntimeException;
import android.util.ArraySet;
@@ -261,7 +262,7 @@ public final class WebViewFactory {
// us honest and minimize usage of WebView internals when binding the proxy.
if (sProviderInstance != null) return sProviderInstance;
- sTimestamps[WEBVIEW_LOAD_START] = System.currentTimeMillis();
+ sTimestamps[WEBVIEW_LOAD_START] = SystemClock.elapsedRealtime();
final int uid = android.os.Process.myUid();
if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID
|| uid == android.os.Process.PHONE_UID || uid == android.os.Process.NFC_UID
@@ -401,7 +402,7 @@ public final class WebViewFactory {
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW,
"initialApplication.createApplicationContext");
- sTimestamps[CREATE_CONTEXT_START] = System.currentTimeMillis();
+ sTimestamps[CREATE_CONTEXT_START] = SystemClock.elapsedRealtime();
try {
// Construct an app context to load the Java code into the current app.
Context webViewContext = initialApplication.createApplicationContext(
@@ -410,7 +411,7 @@ public final class WebViewFactory {
sPackageInfo = newPackageInfo;
return webViewContext;
} finally {
- sTimestamps[CREATE_CONTEXT_END] = System.currentTimeMillis();
+ sTimestamps[CREATE_CONTEXT_END] = SystemClock.elapsedRealtime();
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (RemoteException | PackageManager.NameNotFoundException e) {
@@ -436,26 +437,26 @@ public final class WebViewFactory {
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getChromiumProviderClass()");
try {
- sTimestamps[ADD_ASSETS_START] = System.currentTimeMillis();
+ sTimestamps[ADD_ASSETS_START] = SystemClock.elapsedRealtime();
for (String newAssetPath : webViewContext.getApplicationInfo().getAllApkPaths()) {
initialApplication.getAssets().addAssetPathAsSharedLibrary(newAssetPath);
}
sTimestamps[ADD_ASSETS_END] = sTimestamps[GET_CLASS_LOADER_START] =
- System.currentTimeMillis();
+ SystemClock.elapsedRealtime();
ClassLoader clazzLoader = webViewContext.getClassLoader();
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
sTimestamps[GET_CLASS_LOADER_END] = sTimestamps[NATIVE_LOAD_START] =
- System.currentTimeMillis();
+ SystemClock.elapsedRealtime();
WebViewLibraryLoader.loadNativeLibrary(clazzLoader,
getWebViewLibrary(sPackageInfo.applicationInfo));
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
sTimestamps[NATIVE_LOAD_END] = sTimestamps[PROVIDER_CLASS_FOR_NAME_START] =
- System.currentTimeMillis();
+ SystemClock.elapsedRealtime();
try {
return getWebViewProviderClass(clazzLoader);
} finally {
- sTimestamps[PROVIDER_CLASS_FOR_NAME_END] = System.currentTimeMillis();
+ sTimestamps[PROVIDER_CLASS_FOR_NAME_END] = SystemClock.elapsedRealtime();
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (ClassNotFoundException e) {
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java
index 681fd147a51f..1b62266c12e2 100644
--- a/core/java/android/widget/EdgeEffect.java
+++ b/core/java/android/widget/EdgeEffect.java
@@ -25,8 +25,12 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.BlendMode;
import android.graphics.Canvas;
+import android.graphics.Matrix;
import android.graphics.Paint;
+import android.graphics.RecordingCanvas;
import android.graphics.Rect;
+import android.graphics.RenderEffect;
+import android.graphics.RenderNode;
import android.os.Build;
import android.util.AttributeSet;
import android.view.animation.AnimationUtils;
@@ -149,6 +153,8 @@ public class EdgeEffect {
private float mDisplacement = 0.5f;
private float mTargetDisplacement = 0.5f;
private @EdgeEffectType int mEdgeEffectType = TYPE_GLOW;
+ private Matrix mTmpMatrix = null;
+ private float[] mTmpPoints = null;
/**
* Construct a new EdgeEffect with a theme appropriate for the provided context.
@@ -250,11 +256,18 @@ public class EdgeEffect {
public void onPull(float deltaDistance, float displacement) {
final long now = AnimationUtils.currentAnimationTimeMillis();
mTargetDisplacement = displacement;
- if (mState == STATE_PULL_DECAY && now - mStartTime < mDuration) {
+ if (mState == STATE_PULL_DECAY && now - mStartTime < mDuration
+ && mEdgeEffectType == TYPE_GLOW) {
return;
}
if (mState != STATE_PULL) {
- mGlowScaleY = Math.max(PULL_GLOW_BEGIN, mGlowScaleY);
+ if (mEdgeEffectType == TYPE_STRETCH) {
+ // Restore the mPullDistance to the fraction it is currently showing -- we want
+ // to "catch" the current stretch value.
+ mPullDistance = mDistance;
+ } else {
+ mGlowScaleY = Math.max(PULL_GLOW_BEGIN, mGlowScaleY);
+ }
}
mState = STATE_PULL;
@@ -313,6 +326,15 @@ public class EdgeEffect {
public float onPullDistance(float deltaDistance, float displacement) {
float finalDistance = Math.max(0f, deltaDistance + mDistance);
float delta = finalDistance - mDistance;
+ if (delta == 0f && mDistance == 0f) {
+ return 0f; // No pull, don't do anything.
+ }
+
+ if (mState != STATE_PULL && mState != STATE_PULL_DECAY && mEdgeEffectType == TYPE_GLOW) {
+ // Catch the edge glow in the middle of an animation.
+ mPullDistance = mDistance;
+ mState = STATE_PULL;
+ }
onPull(delta, displacement);
return delta;
}
@@ -466,33 +488,59 @@ public class EdgeEffect {
* Draw into the provided canvas. Assumes that the canvas has been rotated
* accordingly and the size has been set. The effect will be drawn the full
* width of X=0 to X=width, beginning from Y=0 and extending to some factor <
- * 1.f of height.
+ * 1.f of height. The {@link #TYPE_STRETCH} effect will only be visible on a
+ * hardware canvas, e.g. {@link RenderNode#beginRecording()}.
*
* @param canvas Canvas to draw into
* @return true if drawing should continue beyond this frame to continue the
* animation
*/
public boolean draw(Canvas canvas) {
- update();
-
- final int count = canvas.save();
-
- final float centerX = mBounds.centerX();
- final float centerY = mBounds.height() - mRadius;
-
- canvas.scale(1.f, Math.min(mGlowScaleY, 1.f) * mBaseGlowScale, centerX, 0);
-
- final float displacement = Math.max(0, Math.min(mDisplacement, 1.f)) - 0.5f;
- float translateX = mBounds.width() * displacement / 2;
-
- canvas.clipRect(mBounds);
- canvas.translate(translateX, 0);
- mPaint.setAlpha((int) (0xff * mGlowAlpha));
- canvas.drawCircle(centerX, centerY, mRadius, mPaint);
- canvas.restoreToCount(count);
+ if (mEdgeEffectType == TYPE_GLOW) {
+ update();
+ final int count = canvas.save();
+
+ final float centerX = mBounds.centerX();
+ final float centerY = mBounds.height() - mRadius;
+
+ canvas.scale(1.f, Math.min(mGlowScaleY, 1.f) * mBaseGlowScale, centerX, 0);
+
+ final float displacement = Math.max(0, Math.min(mDisplacement, 1.f)) - 0.5f;
+ float translateX = mBounds.width() * displacement / 2;
+
+ canvas.clipRect(mBounds);
+ canvas.translate(translateX, 0);
+ mPaint.setAlpha((int) (0xff * mGlowAlpha));
+ canvas.drawCircle(centerX, centerY, mRadius, mPaint);
+ canvas.restoreToCount(count);
+ } else if (canvas instanceof RecordingCanvas) {
+ if (mState != STATE_PULL) {
+ update();
+ }
+ RecordingCanvas recordingCanvas = (RecordingCanvas) canvas;
+ if (mTmpMatrix == null) {
+ mTmpMatrix = new Matrix();
+ mTmpPoints = new float[4];
+ }
+ //noinspection deprecation
+ recordingCanvas.getMatrix(mTmpMatrix);
+ mTmpPoints[0] = mBounds.width() * mDisplacement;
+ mTmpPoints[1] = mDistance * mBounds.height();
+ mTmpPoints[2] = mTmpPoints[0];
+ mTmpPoints[3] = 0;
+ mTmpMatrix.mapPoints(mTmpPoints);
+ float x = mTmpPoints[0] - mTmpPoints[2];
+ float y = mTmpPoints[1] - mTmpPoints[3];
+
+ RenderNode renderNode = recordingCanvas.mNode;
+
+ // TODO: use stretchy RenderEffect and use internal API when it is ready
+ // TODO: wrap existing RenderEffect
+ renderNode.setRenderEffect(RenderEffect.createOffsetEffect(x, y));
+ }
boolean oneLastFrame = false;
- if (mState == STATE_RECEDE && mGlowScaleY == 0) {
+ if (mState == STATE_RECEDE && mDistance == 0) {
mState = STATE_IDLE;
oneLastFrame = true;
}
diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java
index 97dbb1542717..6dedd12a2730 100644
--- a/core/java/android/widget/HorizontalScrollView.java
+++ b/core/java/android/widget/HorizontalScrollView.java
@@ -89,7 +89,7 @@ public class HorizontalScrollView extends FrameLayout {
*/
@NonNull
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 124053130)
- private EdgeEffect mEdgeGlowLeft = new EdgeEffect(getContext());
+ private EdgeEffect mEdgeGlowLeft;
/**
* Tracks the state of the bottom edge glow.
@@ -98,7 +98,7 @@ public class HorizontalScrollView extends FrameLayout {
* setting it via reflection and they need to keep working until they target Q.
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 124052619)
- private EdgeEffect mEdgeGlowRight = new EdgeEffect(getContext());
+ private EdgeEffect mEdgeGlowRight;
/**
* Position of the last motion event.
@@ -186,6 +186,8 @@ public class HorizontalScrollView extends FrameLayout {
public HorizontalScrollView(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
+ mEdgeGlowLeft = new EdgeEffect(context, attrs);
+ mEdgeGlowRight = new EdgeEffect(context, attrs);
initScrollView();
final TypedArray a = context.obtainStyledAttributes(
@@ -631,7 +633,15 @@ public class HorizontalScrollView extends FrameLayout {
* otherwise don't. mScroller.isFinished should be false when
* being flinged.
*/
- mIsBeingDragged = !mScroller.isFinished();
+ mIsBeingDragged = !mScroller.isFinished() || !mEdgeGlowLeft.isFinished()
+ || !mEdgeGlowRight.isFinished();
+ // Catch the edge effect if it is active.
+ if (!mEdgeGlowLeft.isFinished()) {
+ mEdgeGlowLeft.onPullDistance(0f, 1f - ev.getY() / getHeight());
+ }
+ if (!mEdgeGlowRight.isFinished()) {
+ mEdgeGlowRight.onPullDistance(0f, ev.getY() / getHeight());
+ }
break;
}
@@ -675,7 +685,8 @@ public class HorizontalScrollView extends FrameLayout {
if (getChildCount() == 0) {
return false;
}
- if ((mIsBeingDragged = !mScroller.isFinished())) {
+ if ((mIsBeingDragged = !mScroller.isFinished() || !mEdgeGlowRight.isFinished()
+ || !mEdgeGlowLeft.isFinished())) {
final ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
@@ -721,12 +732,26 @@ public class HorizontalScrollView extends FrameLayout {
mLastMotionX = x;
final int oldX = mScrollX;
- final int oldY = mScrollY;
final int range = getScrollRange();
final int overscrollMode = getOverScrollMode();
final boolean canOverscroll = overscrollMode == OVER_SCROLL_ALWAYS ||
(overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);
+ final float displacement = ev.getY(activePointerIndex) / getHeight();
+ if (canOverscroll) {
+ int consumed = 0;
+ if (deltaX < 0 && mEdgeGlowRight.getDistance() != 0f) {
+ consumed = Math.round(getHeight()
+ * mEdgeGlowRight.onPullDistance((float) deltaX / getWidth(),
+ displacement));
+ } else if (deltaX > 0 && mEdgeGlowLeft.getDistance() != 0f) {
+ consumed = Math.round(-getHeight()
+ * mEdgeGlowLeft.onPullDistance((float) -deltaX / getWidth(),
+ 1 - displacement));
+ }
+ deltaX -= consumed;
+ }
+
// Calling overScrollBy will call onOverScrolled, which
// calls onScrollChanged if applicable.
if (overScrollBy(deltaX, 0, mScrollX, 0, range, 0,
@@ -735,17 +760,17 @@ public class HorizontalScrollView extends FrameLayout {
mVelocityTracker.clear();
}
- if (canOverscroll) {
+ if (canOverscroll && deltaX != 0f) {
final int pulledToX = oldX + deltaX;
if (pulledToX < 0) {
- mEdgeGlowLeft.onPull((float) deltaX / getWidth(),
- 1.f - ev.getY(activePointerIndex) / getHeight());
+ mEdgeGlowLeft.onPullDistance((float) -deltaX / getWidth(),
+ 1.f - displacement);
if (!mEdgeGlowRight.isFinished()) {
mEdgeGlowRight.onRelease();
}
} else if (pulledToX > range) {
- mEdgeGlowRight.onPull((float) deltaX / getWidth(),
- ev.getY(activePointerIndex) / getHeight());
+ mEdgeGlowRight.onPullDistance((float) deltaX / getWidth(),
+ displacement);
if (!mEdgeGlowLeft.isFinished()) {
mEdgeGlowLeft.onRelease();
}
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index ed20d26a8b47..0a08ccd34f02 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -695,6 +695,7 @@ public class ImageView extends View {
* @see #getImageTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setImageTintBlendMode(@Nullable BlendMode blendMode) {
mDrawableBlendMode = blendMode;
mHasDrawableBlendMode = true;
diff --git a/core/java/android/widget/ImeAwareEditText.java b/core/java/android/widget/ImeAwareEditText.java
index 9cd458558de3..0d9808507fd7 100644
--- a/core/java/android/widget/ImeAwareEditText.java
+++ b/core/java/android/widget/ImeAwareEditText.java
@@ -80,7 +80,7 @@ public class ImeAwareEditText extends EditText {
public void scheduleShowSoftInput() {
final InputMethodManager imm = getContext().getSystemService(InputMethodManager.class);
- if (imm.isActive(this)) {
+ if (imm.hasActiveInputConnection(this)) {
// This means that ImeAwareEditText is already connected to the IME.
// InputMethodManager#showSoftInput() is guaranteed to pass client-side focus check.
mHasPendingShowSoftInputRequest = false;
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index 67216f5955f7..a44808eb3120 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -823,6 +823,7 @@ public class ProgressBar extends View {
* @see #setIndeterminateTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setIndeterminateTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
@@ -1132,6 +1133,7 @@ public class ProgressBar extends View {
* @see #getProgressTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setProgressTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
@@ -1248,6 +1250,7 @@ public class ProgressBar extends View {
* @see #setProgressBackgroundTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setProgressBackgroundTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
@@ -1360,6 +1363,7 @@ public class ProgressBar extends View {
* @see #setSecondaryProgressTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
+ @RemotableViewMethod
public void setSecondaryProgressTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 6cb4b81827b9..81572b5bbb45 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -47,7 +47,9 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
+import android.graphics.BlendMode;
import android.graphics.Outline;
+import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
@@ -99,6 +101,8 @@ import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Stack;
@@ -171,6 +175,11 @@ public class RemoteViews implements Parcelable, Filter {
*/
private static final int MAX_NESTED_VIEWS = 10;
+ /**
+ * Maximum number of RemoteViews that can be specified in constructor.
+ */
+ private static final int MAX_INIT_VIEW_COUNT = 16;
+
// The unique identifiers for each custom {@link Action}.
private static final int SET_ON_CLICK_RESPONSE_TAG = 1;
private static final int REFLECTION_ACTION_TAG = 2;
@@ -290,7 +299,7 @@ public class RemoteViews implements Parcelable, Filter {
* The resource ID of the layout file. (Added to the parcel)
*/
@UnsupportedAppUsage
- private final int mLayoutId;
+ private int mLayoutId;
/**
* The resource ID of the layout file in dark text mode. (Added to the parcel)
@@ -322,6 +331,7 @@ public class RemoteViews implements Parcelable, Filter {
*/
private static final int MODE_NORMAL = 0;
private static final int MODE_HAS_LANDSCAPE_AND_PORTRAIT = 1;
+ private static final int MODE_HAS_SIZED_REMOTEVIEWS = 2;
/**
* Used in conjunction with the special constructor
@@ -331,12 +341,26 @@ public class RemoteViews implements Parcelable, Filter {
private RemoteViews mLandscape = null;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private RemoteViews mPortrait = null;
+ /**
+ * List of RemoteViews with their ideal size. There must be at least two if the map is not null.
+ *
+ * The smallest remote view is always the last element in the list.
+ */
+ private List<RemoteViews> mSizedRemoteViews = null;
+
+ /**
+ * Ideal size for this RemoteViews.
+ *
+ * Only to be used on children views used in a {@link RemoteViews} with
+ * {@link RemoteViews#hasSizedRemoteViews()}.
+ */
+ private PointF mIdealSize = null;
@ApplyFlags
private int mApplyFlags = 0;
/** Class cookies of the Parcel this instance was read from. */
- private final Map<Class, Object> mClassCookies;
+ private Map<Class, Object> mClassCookies;
private static final OnClickHandler DEFAULT_ON_CLICK_HANDLER = (view, pendingIntent, response)
-> startPendingIntent(view, pendingIntent, response.getLaunchOptions(view));
@@ -1031,6 +1055,8 @@ public class RemoteViews implements Parcelable, Filter {
return ColorStateList.class;
case BaseReflectionAction.ICON:
return Icon.class;
+ case BaseReflectionAction.BLEND_MODE:
+ return BlendMode.class;
default:
return null;
}
@@ -1377,6 +1403,7 @@ public class RemoteViews implements Parcelable, Filter {
static final int INTENT = 14;
static final int COLOR_STATE_LIST = 15;
static final int ICON = 16;
+ static final int BLEND_MODE = 17;
@UnsupportedAppUsage
String methodName;
@@ -1566,6 +1593,10 @@ public class RemoteViews implements Parcelable, Filter {
break;
case ICON:
this.value = in.readTypedObject(Icon.CREATOR);
+ break;
+ case BLEND_MODE:
+ this.value = BlendMode.fromValue(in.readInt());
+ break;
default:
break;
}
@@ -1609,6 +1640,9 @@ public class RemoteViews implements Parcelable, Filter {
case BUNDLE:
out.writeBundle((Bundle) this.value);
break;
+ case BLEND_MODE:
+ out.writeInt(BlendMode.toValue((BlendMode) this.value));
+ break;
case URI:
case BITMAP:
case INTENT:
@@ -2768,23 +2802,50 @@ public class RemoteViews implements Parcelable, Filter {
mClassCookies = null;
}
+ private boolean hasMultipleLayouts() {
+ return hasLandscapeAndPortraitLayouts() || hasSizedRemoteViews();
+ }
+
private boolean hasLandscapeAndPortraitLayouts() {
return (mLandscape != null) && (mPortrait != null);
}
+ private boolean hasSizedRemoteViews() {
+ return mSizedRemoteViews != null;
+ }
+
+ private @Nullable PointF getIdealSize() {
+ return mIdealSize;
+ }
+
+ private void setIdealSize(@Nullable PointF size) {
+ mIdealSize = size;
+ }
+
+ /**
+ * Finds the smallest view in {@code mSizedRemoteViews}.
+ * This method must not be called if {@code mSizedRemoteViews} is null.
+ */
+ private RemoteViews findSmallestRemoteView() {
+ return mSizedRemoteViews.get(mSizedRemoteViews.size() - 1);
+ }
+
/**
* Create a new RemoteViews object that will inflate as the specified
* landspace or portrait RemoteViews, depending on the current configuration.
*
* @param landscape The RemoteViews to inflate in landscape configuration
* @param portrait The RemoteViews to inflate in portrait configuration
+ * @throws IllegalArgumentException if either landscape or portrait are null or if they are
+ * not from the same application
*/
public RemoteViews(RemoteViews landscape, RemoteViews portrait) {
if (landscape == null || portrait == null) {
- throw new RuntimeException("Both RemoteViews must be non-null");
+ throw new IllegalArgumentException("Both RemoteViews must be non-null");
}
if (!landscape.hasSameAppInfo(portrait.mApplication)) {
- throw new RuntimeException("Both RemoteViews must share the same package and user");
+ throw new IllegalArgumentException(
+ "Both RemoteViews must share the same package and user");
}
mApplication = portrait.mApplication;
mLayoutId = portrait.mLayoutId;
@@ -2802,9 +2863,84 @@ public class RemoteViews implements Parcelable, Filter {
}
/**
+ * Create a new RemoteViews object that will inflate the layout with the closest size
+ * specification.
+ *
+ * The default remote views in that case is always the smallest one provided.
+ *
+ * @param remoteViews Mapping of size to layout.
+ * @throws IllegalArgumentException if the map is empty, there are more than
+ * MAX_INIT_VIEW_COUNT layouts or the remote views are not all from the same application.
+ */
+ public RemoteViews(@NonNull Map<PointF, RemoteViews> remoteViews) {
+ if (remoteViews.isEmpty()) {
+ throw new IllegalArgumentException("The set of RemoteViews cannot be empty");
+ }
+ if (remoteViews.size() > MAX_INIT_VIEW_COUNT) {
+ throw new IllegalArgumentException("Too many RemoteViews in constructor");
+ }
+ if (remoteViews.size() == 1) {
+ initializeFrom(remoteViews.values().iterator().next());
+ return;
+ }
+ mBitmapCache = new BitmapCache();
+ mClassCookies = initializeSizedRemoteViews(
+ remoteViews.entrySet().stream().map(
+ entry -> {
+ entry.getValue().setIdealSize(entry.getKey());
+ return entry.getValue();
+ }
+ ).iterator()
+ );
+
+ RemoteViews smallestView = findSmallestRemoteView();
+ mApplication = smallestView.mApplication;
+ mLayoutId = smallestView.mLayoutId;
+ mLightBackgroundLayoutId = smallestView.mLightBackgroundLayoutId;
+ }
+
+ // Initialize mSizedRemoteViews and return the class cookies.
+ private Map<Class, Object> initializeSizedRemoteViews(Iterator<RemoteViews> remoteViews) {
+ List<RemoteViews> sizedRemoteViews = new ArrayList<>();
+ Map<Class, Object> classCookies = null;
+ float viewArea = Float.MAX_VALUE;
+ RemoteViews smallestView = null;
+ while (remoteViews.hasNext()) {
+ RemoteViews view = remoteViews.next();
+ PointF size = view.getIdealSize();
+ float newViewArea = size.x * size.y;
+ if (smallestView != null && !view.hasSameAppInfo(smallestView.mApplication)) {
+ throw new IllegalArgumentException(
+ "All RemoteViews must share the same package and user");
+ }
+ if (smallestView == null || newViewArea < viewArea) {
+ if (smallestView != null) {
+ sizedRemoteViews.add(smallestView);
+ }
+ viewArea = newViewArea;
+ smallestView = view;
+ } else {
+ sizedRemoteViews.add(view);
+ }
+ configureRemoteViewsAsChild(view);
+ view.setIdealSize(size);
+ if (classCookies == null) {
+ classCookies = view.mClassCookies;
+ }
+ }
+ sizedRemoteViews.add(smallestView);
+ mSizedRemoteViews = sizedRemoteViews;
+ return classCookies;
+ }
+
+ /**
* Creates a copy of another RemoteViews.
*/
public RemoteViews(RemoteViews src) {
+ initializeFrom(src);
+ }
+
+ private void initializeFrom(RemoteViews src) {
mBitmapCache = src.mBitmapCache;
mApplication = src.mApplication;
mIsRoot = src.mIsRoot;
@@ -2812,12 +2948,20 @@ public class RemoteViews implements Parcelable, Filter {
mLightBackgroundLayoutId = src.mLightBackgroundLayoutId;
mApplyFlags = src.mApplyFlags;
mClassCookies = src.mClassCookies;
+ mIdealSize = src.mIdealSize;
if (src.hasLandscapeAndPortraitLayouts()) {
mLandscape = new RemoteViews(src.mLandscape);
mPortrait = new RemoteViews(src.mPortrait);
}
+ if (src.hasSizedRemoteViews()) {
+ mSizedRemoteViews = new ArrayList<>(src.mSizedRemoteViews.size());
+ for (RemoteViews srcView : src.mSizedRemoteViews) {
+ mSizedRemoteViews.add(new RemoteViews(srcView));
+ }
+ }
+
if (src.mActions != null) {
Parcel p = Parcel.obtain();
p.putClassCookies(mClassCookies);
@@ -2867,10 +3011,29 @@ public class RemoteViews implements Parcelable, Filter {
if (mode == MODE_NORMAL) {
mApplication = parcel.readInt() == 0 ? info :
ApplicationInfo.CREATOR.createFromParcel(parcel);
+ mIdealSize = parcel.readInt() == 0 ? null : PointF.CREATOR.createFromParcel(parcel);
mLayoutId = parcel.readInt();
mLightBackgroundLayoutId = parcel.readInt();
readActionsFromParcel(parcel, depth);
+ } else if (mode == MODE_HAS_SIZED_REMOTEVIEWS) {
+ int numViews = parcel.readInt();
+ if (numViews > MAX_INIT_VIEW_COUNT) {
+ throw new IllegalArgumentException(
+ "Too many views in mapping from size to RemoteViews.");
+ }
+ List<RemoteViews> remoteViews = new ArrayList<>(numViews);
+ for (int i = 0; i < numViews; i++) {
+ RemoteViews view = new RemoteViews(parcel, mBitmapCache, info, depth,
+ mClassCookies);
+ info = view.mApplication;
+ remoteViews.add(view);
+ }
+ initializeSizedRemoteViews(remoteViews.iterator());
+ RemoteViews smallestView = findSmallestRemoteView();
+ mApplication = smallestView.mApplication;
+ mLayoutId = smallestView.mLayoutId;
+ mLightBackgroundLayoutId = smallestView.mLightBackgroundLayoutId;
} else {
// MODE_HAS_LANDSCAPE_AND_PORTRAIT
mLandscape = new RemoteViews(parcel, mBitmapCache, info, depth, mClassCookies);
@@ -2990,16 +3153,20 @@ public class RemoteViews implements Parcelable, Filter {
*/
private void setBitmapCache(BitmapCache bitmapCache) {
mBitmapCache = bitmapCache;
- if (!hasLandscapeAndPortraitLayouts()) {
+ if (hasSizedRemoteViews()) {
+ for (RemoteViews remoteView : mSizedRemoteViews) {
+ remoteView.setBitmapCache(bitmapCache);
+ }
+ } else if (hasLandscapeAndPortraitLayouts()) {
+ mLandscape.setBitmapCache(bitmapCache);
+ mPortrait.setBitmapCache(bitmapCache);
+ } else {
if (mActions != null) {
final int count = mActions.size();
- for (int i= 0; i < count; ++i) {
+ for (int i = 0; i < count; ++i) {
mActions.get(i).setBitmapCache(bitmapCache);
}
}
- } else {
- mLandscape.setBitmapCache(bitmapCache);
- mPortrait.setBitmapCache(bitmapCache);
}
}
@@ -3018,10 +3185,10 @@ public class RemoteViews implements Parcelable, Filter {
* @param a The action to add
*/
private void addAction(Action a) {
- if (hasLandscapeAndPortraitLayouts()) {
- throw new RuntimeException("RemoteViews specifying separate landscape and portrait" +
- " layouts cannot be modified. Instead, fully configure the landscape and" +
- " portrait layouts individually before constructing the combined layout.");
+ if (hasMultipleLayouts()) {
+ throw new RuntimeException("RemoteViews specifying separate layouts for orientation"
+ + " or size cannot be modified. Instead, fully configure each layouts"
+ + " individually before constructing the combined layout.");
}
if (mActions == null) {
mActions = new ArrayList<>();
@@ -3976,6 +4143,18 @@ public class RemoteViews implements Parcelable, Filter {
}
/**
+ * Call a method taking one BlendMode on a view in the layout for this RemoteViews.
+ *
+ * @param viewId The id of the view on which to call the method.
+ * @param methodName The name of the method to call.
+ * @param value The value to pass to the method.
+ */
+ public void setBlendMode(@IdRes int viewId, @NonNull String methodName,
+ @Nullable BlendMode value) {
+ addAction(new ReflectionAction(viewId, methodName, BaseReflectionAction.BLEND_MODE, value));
+ }
+
+ /**
* Call a method taking one Bundle on a view in the layout for this RemoteViews.
*
* @param viewId The id of the view on which to call the method.
@@ -4100,14 +4279,79 @@ public class RemoteViews implements Parcelable, Filter {
int orientation = context.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
return mLandscape;
- } else {
- return mPortrait;
}
+ return mPortrait;
+ }
+ if (hasSizedRemoteViews()) {
+ return findSmallestRemoteView();
}
return this;
}
/**
+ * Returns the square distance between two points.
+ *
+ * This is particularly useful when we only care about the ordering of the distances.
+ */
+ private static float squareDistance(PointF p1, PointF p2) {
+ float dx = p1.x - p2.x;
+ float dy = p1.y - p2.y;
+ return dx * dx + dy * dy;
+ }
+
+ /**
+ * Returns whether the layout fits in the space available to the widget.
+ *
+ * A layout fits on a widget if the widget size is known (i.e. not null) and both dimensions
+ * are smaller than the ones of the widget, adding some padding to account for rounding errors.
+ */
+ private static boolean fitsIn(PointF sizeLayout, @Nullable PointF sizeWidget) {
+ return sizeWidget != null && (Math.ceil(sizeWidget.x) + 1 > sizeLayout.x)
+ && (Math.ceil(sizeWidget.y) + 1 > sizeLayout.y);
+ }
+
+ /**
+ * Returns the most appropriate {@link RemoteViews} given the context and, if not null, the
+ * size of the widget.
+ *
+ * If {@link RemoteViews#hasSizedRemoteViews()} returns true, the most appropriate view is
+ * the one that fits in the widget (according to {@link RemoteViews#fitsIn}) and has the
+ * diagonal the most similar to the widget. If no layout fits or the size of the widget is
+ * not specified, the one with the smallest area will be chosen.
+ */
+ private RemoteViews getRemoteViewsToApply(@NonNull Context context,
+ @Nullable PointF widgetSize) {
+ if (!hasSizedRemoteViews()) {
+ // If there isn't multiple remote views, fall back on the previous methods.
+ return getRemoteViewsToApply(context);
+ }
+ // Find the better remote view
+ RemoteViews bestFit = null;
+ float bestSqDist = Float.MAX_VALUE;
+ for (RemoteViews layout : mSizedRemoteViews) {
+ PointF layoutSize = layout.getIdealSize();
+ if (fitsIn(layoutSize, widgetSize)) {
+ if (bestFit == null) {
+ bestFit = layout;
+ bestSqDist = squareDistance(layoutSize, widgetSize);
+ } else {
+ float newSqDist = squareDistance(layoutSize, widgetSize);
+ if (newSqDist < bestSqDist) {
+ bestFit = layout;
+ bestSqDist = newSqDist;
+ }
+ }
+ }
+ }
+ if (bestFit == null) {
+ Log.w(LOG_TAG, "Could not find a RemoteViews fitting the current size: " + widgetSize);
+ return findSmallestRemoteView();
+ }
+ return bestFit;
+ }
+
+
+ /**
* Inflates the view hierarchy represented by this object and applies
* all of the actions.
*
@@ -4124,7 +4368,13 @@ public class RemoteViews implements Parcelable, Filter {
/** @hide */
public View apply(Context context, ViewGroup parent, OnClickHandler handler) {
- RemoteViews rvToApply = getRemoteViewsToApply(context);
+ return apply(context, parent, handler, null);
+ }
+
+ /** @hide */
+ public View apply(@NonNull Context context, @NonNull ViewGroup parent,
+ @Nullable OnClickHandler handler, @Nullable PointF size) {
+ RemoteViews rvToApply = getRemoteViewsToApply(context, size);
View result = inflateView(context, rvToApply, parent);
rvToApply.performApply(result, parent, handler);
@@ -4132,9 +4382,17 @@ public class RemoteViews implements Parcelable, Filter {
}
/** @hide */
- public View applyWithTheme(Context context, ViewGroup parent, OnClickHandler handler,
+ public View applyWithTheme(@NonNull Context context, @NonNull ViewGroup parent,
+ @Nullable OnClickHandler handler,
@StyleRes int applyThemeResId) {
- RemoteViews rvToApply = getRemoteViewsToApply(context);
+ return applyWithTheme(context, parent, handler, applyThemeResId, null);
+ }
+
+ /** @hide */
+ public View applyWithTheme(@NonNull Context context, @NonNull ViewGroup parent,
+ @Nullable OnClickHandler handler,
+ @StyleRes int applyThemeResId, @Nullable PointF size) {
+ RemoteViews rvToApply = getRemoteViewsToApply(context, size);
View result = inflateView(context, rvToApply, parent, applyThemeResId);
rvToApply.performApply(result, parent, handler);
@@ -4219,12 +4477,26 @@ public class RemoteViews implements Parcelable, Filter {
/** @hide */
public CancellationSignal applyAsync(Context context, ViewGroup parent,
Executor executor, OnViewAppliedListener listener, OnClickHandler handler) {
- return getAsyncApplyTask(context, parent, listener, handler).startTaskOnExecutor(executor);
+ return applyAsync(context, parent, executor, listener, handler, null);
+ }
+
+ /** @hide */
+ public CancellationSignal applyAsync(Context context, ViewGroup parent,
+ Executor executor, OnViewAppliedListener listener, OnClickHandler handler,
+ PointF size) {
+ return getAsyncApplyTask(context, parent, listener, handler, size).startTaskOnExecutor(
+ executor);
}
private AsyncApplyTask getAsyncApplyTask(Context context, ViewGroup parent,
OnViewAppliedListener listener, OnClickHandler handler) {
- return new AsyncApplyTask(getRemoteViewsToApply(context), parent, context, listener,
+ return getAsyncApplyTask(context, parent, listener, handler, null);
+ }
+
+ private AsyncApplyTask getAsyncApplyTask(Context context, ViewGroup parent,
+ OnViewAppliedListener listener, OnClickHandler handler, PointF size) {
+ return new AsyncApplyTask(getRemoteViewsToApply(context, size), parent, context,
+ listener,
handler, null);
}
@@ -4341,12 +4613,18 @@ public class RemoteViews implements Parcelable, Filter {
/** @hide */
public void reapply(Context context, View v, OnClickHandler handler) {
- RemoteViews rvToApply = getRemoteViewsToApply(context);
+ reapply(context, v, handler, null);
+ }
- // In the case that a view has this RemoteViews applied in one orientation, is persisted
- // across orientation change, and has the RemoteViews re-applied in the new orientation,
- // we throw an exception, since the layouts may be completely unrelated.
- if (hasLandscapeAndPortraitLayouts()) {
+ /** @hide */
+ public void reapply(Context context, View v, OnClickHandler handler, PointF size) {
+ RemoteViews rvToApply = getRemoteViewsToApply(context, size);
+
+ // In the case that a view has this RemoteViews applied in one orientation or size, is
+ // persisted across change, and has the RemoteViews re-applied in a different situation
+ // (orientation or size), we throw an exception, since the layouts may be completely
+ // unrelated.
+ if (hasMultipleLayouts()) {
if ((Integer) v.getTag(R.id.widget_frame) != rvToApply.getLayoutId()) {
throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" +
" that does not share the same root layout id.");
@@ -4377,12 +4655,18 @@ public class RemoteViews implements Parcelable, Filter {
/** @hide */
public CancellationSignal reapplyAsync(Context context, View v, Executor executor,
OnViewAppliedListener listener, OnClickHandler handler) {
- RemoteViews rvToApply = getRemoteViewsToApply(context);
+ return reapplyAsync(context, v, executor, listener, handler, null);
+ }
+
+ /** @hide */
+ public CancellationSignal reapplyAsync(Context context, View v, Executor executor,
+ OnViewAppliedListener listener, OnClickHandler handler, PointF size) {
+ RemoteViews rvToApply = getRemoteViewsToApply(context, size);
// In the case that a view has this RemoteViews applied in one orientation, is persisted
// across orientation change, and has the RemoteViews re-applied in the new orientation,
// we throw an exception, since the layouts may be completely unrelated.
- if (hasLandscapeAndPortraitLayouts()) {
+ if (hasMultipleLayouts()) {
if ((Integer) v.getTag(R.id.widget_frame) != rvToApply.getLayoutId()) {
throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" +
" that does not share the same root layout id.");
@@ -4466,7 +4750,7 @@ public class RemoteViews implements Parcelable, Filter {
}
public void writeToParcel(Parcel dest, int flags) {
- if (!hasLandscapeAndPortraitLayouts()) {
+ if (!hasMultipleLayouts()) {
dest.writeInt(MODE_NORMAL);
// We only write the bitmap cache if we are the root RemoteViews, as this cache
// is shared by all children.
@@ -4479,9 +4763,26 @@ public class RemoteViews implements Parcelable, Filter {
dest.writeInt(1);
mApplication.writeToParcel(dest, flags);
}
+ if (mIsRoot || mIdealSize == null) {
+ dest.writeInt(0);
+ } else {
+ dest.writeInt(1);
+ mIdealSize.writeToParcel(dest, flags);
+ }
dest.writeInt(mLayoutId);
dest.writeInt(mLightBackgroundLayoutId);
writeActionsToParcel(dest);
+ } else if (hasSizedRemoteViews()) {
+ dest.writeInt(MODE_HAS_SIZED_REMOTEVIEWS);
+ if (mIsRoot) {
+ mBitmapCache.writeBitmapsToParcel(dest, flags);
+ }
+ int childFlags = flags;
+ dest.writeInt(mSizedRemoteViews.size());
+ for (RemoteViews view : mSizedRemoteViews) {
+ view.writeToParcel(dest, childFlags);
+ childFlags |= PARCELABLE_ELIDE_DUPLICATES;
+ }
} else {
dest.writeInt(MODE_HAS_LANDSCAPE_AND_PORTRAIT);
// We only write the bitmap cache if we are the root RemoteViews, as this cache
@@ -4735,11 +5036,9 @@ public class RemoteViews implements Parcelable, Filter {
* before starting the intent.
*
* @param fillIntent The intent which will be combined with the parent's PendingIntent in
- * order to determine the behavior of the response
- *
+ * order to determine the behavior of the response
* @see RemoteViews#setPendingIntentTemplate(int, PendingIntent)
* @see RemoteViews#setOnClickFillInIntent(int, Intent)
- * @return
*/
@NonNull
public static RemoteResponse fromFillInIntent(@NonNull Intent fillIntent) {
@@ -4754,9 +5053,8 @@ public class RemoteViews implements Parcelable, Filter {
* the epicenter for the exit Transition. The position of the associated shared element in
* the launched Activity will be the epicenter of its entering Transition.
*
- * @param viewId The id of the view to be shared as part of the transition
+ * @param viewId The id of the view to be shared as part of the transition
* @param sharedElementName The shared element name for this view
- *
* @see ActivityOptions#makeSceneTransitionAnimation(Activity, Pair[])
*/
@NonNull
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index f3de9828c4aa..64d09de49f2d 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -98,7 +98,7 @@ public class ScrollView extends FrameLayout {
*/
@NonNull
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768600)
- private EdgeEffect mEdgeGlowTop = new EdgeEffect(getContext());
+ private EdgeEffect mEdgeGlowTop;
/**
* Tracks the state of the bottom edge glow.
@@ -108,7 +108,7 @@ public class ScrollView extends FrameLayout {
*/
@NonNull
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769386)
- private EdgeEffect mEdgeGlowBottom = new EdgeEffect(getContext());
+ private EdgeEffect mEdgeGlowBottom;
/**
* Position of the last motion event.
@@ -213,6 +213,8 @@ public class ScrollView extends FrameLayout {
public ScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
+ mEdgeGlowTop = new EdgeEffect(context, attrs);
+ mEdgeGlowBottom = new EdgeEffect(context, attrs);
initScrollView();
final TypedArray a = context.obtainStyledAttributes(
@@ -679,7 +681,15 @@ public class ScrollView extends FrameLayout {
* isFinished() is correct.
*/
mScroller.computeScrollOffset();
- mIsBeingDragged = !mScroller.isFinished();
+ mIsBeingDragged = !mScroller.isFinished() || !mEdgeGlowBottom.isFinished()
+ || !mEdgeGlowTop.isFinished();
+ // Catch the edge effect if it is active.
+ if (!mEdgeGlowTop.isFinished()) {
+ mEdgeGlowTop.onPullDistance(0f, ev.getX() / getWidth());
+ }
+ if (!mEdgeGlowBottom.isFinished()) {
+ mEdgeGlowBottom.onPullDistance(0f, 1f - ev.getX() / getWidth());
+ }
if (mIsBeingDragged && mScrollStrictSpan == null) {
mScrollStrictSpan = StrictMode.enterCriticalSpan("ScrollView-scroll");
}
@@ -732,7 +742,8 @@ public class ScrollView extends FrameLayout {
if (getChildCount() == 0) {
return false;
}
- if ((mIsBeingDragged = !mScroller.isFinished())) {
+ if ((mIsBeingDragged = !mScroller.isFinished() || !mEdgeGlowTop.isFinished()
+ || !mEdgeGlowBottom.isFinished())) {
final ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
@@ -793,6 +804,21 @@ public class ScrollView extends FrameLayout {
boolean canOverscroll = overscrollMode == OVER_SCROLL_ALWAYS ||
(overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);
+ final float displacement = ev.getX(activePointerIndex) / getWidth();
+ if (canOverscroll) {
+ int consumed = 0;
+ if (deltaY < 0 && mEdgeGlowBottom.getDistance() != 0f) {
+ consumed = Math.round(getHeight()
+ * mEdgeGlowBottom.onPullDistance((float) deltaY / getHeight(),
+ 1 - displacement));
+ } else if (deltaY > 0 && mEdgeGlowTop.getDistance() != 0f) {
+ consumed = Math.round(-getHeight()
+ * mEdgeGlowTop.onPullDistance((float) -deltaY / getHeight(),
+ displacement));
+ }
+ deltaY -= consumed;
+ }
+
// Calling overScrollBy will call onOverScrolled, which
// calls onScrollChanged if applicable.
if (overScrollBy(0, deltaY, 0, mScrollY, 0, range, 0, mOverscrollDistance, true)
@@ -807,17 +833,17 @@ public class ScrollView extends FrameLayout {
mLastMotionY -= mScrollOffset[1];
vtev.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
- } else if (canOverscroll) {
+ } else if (canOverscroll && deltaY != 0f) {
final int pulledToY = oldY + deltaY;
if (pulledToY < 0) {
- mEdgeGlowTop.onPull((float) deltaY / getHeight(),
- ev.getX(activePointerIndex) / getWidth());
+ mEdgeGlowTop.onPullDistance((float) -deltaY / getHeight(),
+ displacement);
if (!mEdgeGlowBottom.isFinished()) {
mEdgeGlowBottom.onRelease();
}
} else if (pulledToY > range) {
- mEdgeGlowBottom.onPull((float) deltaY / getHeight(),
- 1.f - ev.getX(activePointerIndex) / getWidth());
+ mEdgeGlowBottom.onPullDistance((float) deltaY / getHeight(),
+ 1.f - displacement);
if (!mEdgeGlowTop.isFinished()) {
mEdgeGlowTop.onRelease();
}
diff --git a/core/java/com/android/internal/graphics/fonts/IFontManager.aidl b/core/java/com/android/internal/graphics/fonts/IFontManager.aidl
index dfcc91421b9e..1c7eca8b6c8e 100644
--- a/core/java/com/android/internal/graphics/fonts/IFontManager.aidl
+++ b/core/java/com/android/internal/graphics/fonts/IFontManager.aidl
@@ -20,6 +20,8 @@ import android.os.ParcelFileDescriptor;
import android.graphics.fonts.FontUpdateRequest;
import android.text.FontConfig;
+import java.util.List;
+
/**
* System private interface for talking with
* {@link com.android.server.graphics.fonts.FontManagerService}.
@@ -28,5 +30,7 @@ import android.text.FontConfig;
interface IFontManager {
FontConfig getFontConfig();
- int updateFont(int baseVersion, in FontUpdateRequest request);
+ int updateFontFile(in FontUpdateRequest request, int baseVersion);
+
+ int updateFontFamily(in List<FontUpdateRequest> request, int baseVersion);
}
diff --git a/core/jni/Android.bp b/core/jni/Android.bp
index 6983d35c5a3f..d72a0ec8641f 100644
--- a/core/jni/Android.bp
+++ b/core/jni/Android.bp
@@ -49,11 +49,12 @@ cc_library_shared {
"libhwui",
"liblog",
"libminikin",
- "libnativehelper",
"libz",
"libziparchive",
],
+ static_libs: ["libnativehelper_lazy"],
+
export_include_dirs: [
".",
"include",
@@ -272,12 +273,13 @@ cc_library_shared {
"libstatspull",
],
export_shared_lib_headers: [
- // AndroidRuntime.h depends on nativehelper/jni.h
- "libnativehelper",
-
// our headers include libnativewindow's public headers
"libnativewindow",
],
+ export_static_lib_headers: [
+ // AndroidRuntime.h depends on nativehelper/jni.h
+ "libnativehelper_lazy",
+ ],
header_libs: [
"bionic_libc_platform_headers",
"dnsproxyd_protocol_headers",
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index ba43ee79e6f3..62e077fae256 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1313,11 +1313,13 @@
android:protectionLevel="dangerous|instant" />
<!-- ====================================================================== -->
- <!-- Permissions for accessing the UCE Service -->
+ <!-- Permissions for accessing the vendor UCE Service -->
<!-- ====================================================================== -->
<!-- @hide Allows an application to Access UCE-Presence.
<p>Protection level: signature|privileged
+ @deprecated Framework should no longer use this permission to access the vendor UCE service
+ using AIDL, it is instead implemented by RcsCapabilityExchangeImplBase
-->
<permission android:name="android.permission.ACCESS_UCE_PRESENCE_SERVICE"
android:permissionGroup="android.permission-group.PHONE"
@@ -1325,6 +1327,8 @@
<!-- @hide Allows an application to Access UCE-OPTIONS.
<p>Protection level: signature|privileged
+ @deprecated Framework should no longer use this permission to access the vendor UCE service
+ using AIDL, it is instead implemented by RcsCapabilityExchangeImplBase
-->
<permission android:name="android.permission.ACCESS_UCE_OPTIONS_SERVICE"
android:permissionGroup="android.permission-group.PHONE"
@@ -1403,6 +1407,15 @@
android:description="@string/permgroupdesc_sensors"
android:priority="800" />
+ <!-- Allows an app to access sensor data with a sampling rate greater than 200 Hz.
+ <p>Protection level: normal
+ -->
+ <permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS"
+ android:permissionGroup="android.permission-group.SENSORS"
+ android:label="@string/permlab_highSamplingRateSensors"
+ android:description="@string/permdesc_highSamplingRateSensors"
+ android:protectionLevel="normal" />
+
<!-- Allows an application to access data from sensors that the user uses to
measure what is happening inside their body, such as heart rate.
<p>Protection level: dangerous -->
@@ -2002,6 +2015,12 @@
<permission android:name="android.permission.ENABLE_TEST_HARNESS_MODE"
android:protectionLevel="signature" />
+ <!-- @SystemApi Allows access to ultra wideband device.
+ <p>Not for use by third-party applications.
+ @hide -->
+ <permission android:name="android.permission.UWB_PRIVILEGED"
+ android:protectionLevel="signature|privileged" />
+
<!-- ================================== -->
<!-- Permissions for accessing accounts -->
<!-- ================================== -->
@@ -2448,6 +2467,15 @@
<permission android:name="android.permission.BIND_GBA_SERVICE"
android:protectionLevel="signature" />
+ <!-- Required for an Application to access APIs related to RCS User Capability Exchange.
+ <p> This permission is only granted to system applications fulfilling the SMS, Dialer, and
+ Contacts app roles.
+ <p>Protection level: internal|role
+ @SystemApi
+ @hide -->
+ <permission android:name="android.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE"
+ android:protectionLevel="internal|role" />
+
<!-- ================================== -->
<!-- Permissions for sdcard interaction -->
<!-- ================================== -->
@@ -4372,6 +4400,12 @@
<permission android:name="android.permission.POWER_SAVER"
android:protectionLevel="signature|privileged" />
+ <!-- Allows providing the system with battery predictions.
+ Superseded by DEVICE_POWER permission. @hide @SystemApi
+ -->
+ <permission android:name="android.permission.BATTERY_PREDICTION"
+ android:protectionLevel="signature|privileged" />
+
<!-- Allows access to the PowerManager.userActivity function.
<p>Not for use by third-party applications. @hide @SystemApi -->
<permission android:name="android.permission.USER_ACTIVITY"
@@ -5477,6 +5511,15 @@
<permission android:name="android.permission.SIGNAL_REBOOT_READINESS"
android:protectionLevel="signature|privileged" />
+ <!-- @hide Allows an application to get a People Tile preview for a given shortcut. -->
+ <permission android:name="android.permission.GET_PEOPLE_TILE_PREVIEW"
+ android:protectionLevel="signature|recents" />
+
+ <!-- @hide @SystemApi Allows an application to retrieve whether shortcut is backed by a
+ Conversation.
+ TODO(b/180412052): STOPSHIP: Define a role so it can be granted to Shell and AiAi. -->
+ <permission android:name="android.permission.READ_PEOPLE_DATA"
+ android:protectionLevel="signature|appPredictor|recents"/>
<!-- Attribution for Geofencing service. -->
<attribution android:tag="GeofencingService" android:label="@string/geofencing_service"/>
diff --git a/core/res/res/drawable/btn_borderless_material.xml b/core/res/res/drawable/btn_borderless_material.xml
index 08e1060ebad3..1a0912ee47dc 100644
--- a/core/res/res/drawable/btn_borderless_material.xml
+++ b/core/res/res/drawable/btn_borderless_material.xml
@@ -15,7 +15,8 @@
-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
- android:color="?attr/colorControlHighlight">
+ android:color="?attr/colorControlHighlight"
+ android:rippleStyle="?attr/rippleStyle">
<item android:id="@id/mask"
android:drawable="@drawable/btn_default_mtrl_shape" />
</ripple>
diff --git a/core/res/res/drawable/btn_colored_material.xml b/core/res/res/drawable/btn_colored_material.xml
index 7ba21e840a59..5274ef2f6dce 100644
--- a/core/res/res/drawable/btn_colored_material.xml
+++ b/core/res/res/drawable/btn_colored_material.xml
@@ -19,7 +19,8 @@
android:insetTop="@dimen/button_inset_vertical_material"
android:insetRight="@dimen/button_inset_horizontal_material"
android:insetBottom="@dimen/button_inset_vertical_material">
- <ripple android:color="?attr/colorControlHighlight">
+ <ripple android:color="?attr/colorControlHighlight"
+ android:rippleStyle="?attr/rippleStyle">
<item>
<shape android:shape="rectangle"
android:tint="@color/btn_colored_background_material">
diff --git a/core/res/res/drawable/btn_default_material.xml b/core/res/res/drawable/btn_default_material.xml
index ed2b5aacb236..6a9e62110ba4 100644
--- a/core/res/res/drawable/btn_default_material.xml
+++ b/core/res/res/drawable/btn_default_material.xml
@@ -15,6 +15,7 @@
-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
- android:color="?attr/colorControlHighlight">
+ android:color="?attr/colorControlHighlight"
+ android:rippleStyle="?attr/rippleStyle">
<item android:drawable="@drawable/btn_default_mtrl_shape" />
</ripple>
diff --git a/core/res/res/drawable/btn_toggle_material.xml b/core/res/res/drawable/btn_toggle_material.xml
index 8b19e4ae3561..7cee3820172b 100644
--- a/core/res/res/drawable/btn_toggle_material.xml
+++ b/core/res/res/drawable/btn_toggle_material.xml
@@ -21,7 +21,8 @@
android:insetBottom="@dimen/button_inset_vertical_material">
<layer-list android:paddingMode="stack">
<item>
- <ripple android:color="?attr/colorControlHighlight">
+ <ripple android:color="?attr/colorControlHighlight"
+ android:rippleStyle="?attr/rippleStyle">
<item>
<shape android:shape="rectangle"
android:tint="?attr/colorButtonNormal">
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 927a8b49c17e..69bb20cf9c1e 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -6389,6 +6389,13 @@
<!-- The radius of the ripple when fully expanded. By default, the
radius is computed based on the size of the ripple's container. -->
<attr name="radius" />
+ <!-- The style of the ripple drawable is solid by default -->
+ <attr name="rippleStyle">
+ <!-- Solid is the default style -->
+ <enum name="solid" value="0" />
+ <!-- Patterned style-->
+ <enum name="patterned" value="1" />
+ </attr>
</declare-styleable>
<declare-styleable name="ScaleDrawable">
@@ -8003,6 +8010,14 @@
<attr name="minResizeWidth" format="dimension"/>
<!-- Minimum height that the AppWidget can be resized to. -->
<attr name="minResizeHeight" format="dimension"/>
+ <!-- Maximum width that the AppWidget can be resized to. -->
+ <attr name="maxResizeWidth" format="dimension"/>
+ <!-- Maximum height that the AppWidget can be resized to. -->
+ <attr name="maxResizeHeight" format="dimension"/>
+ <!-- Default width of the AppWidget in units of launcher grid cells. -->
+ <attr name="targetCellWidth" format="integer"/>
+ <!-- Default height of the AppWidget in units of launcher grid cells. -->
+ <attr name="targetCellHeight" format="integer"/>
<!-- Update period in milliseconds, or 0 if the AppWidget will update itself. -->
<attr name="updatePeriodMillis" format="integer" />
<!-- A resource id of a layout. -->
diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml
index 5546621b6ee8..e7c4947bed5f 100644
--- a/core/res/res/values/colors.xml
+++ b/core/res/res/values/colors.xml
@@ -245,19 +245,19 @@
<color name="system_main_0">#ffffff</color>
<!-- Shade of the main system color at 95% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
- <color name="system_main_50">#f0f0f0</color>
+ <color name="system_main_50">#f2f2f2</color>
<!-- Shade of the main system color at 90% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
- <color name="system_main_100">#e2e2e2</color>
+ <color name="system_main_100">#e3e3e3</color>
<!-- Shade of the main system color at 80% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
- <color name="system_main_200">#c6c6c6</color>
+ <color name="system_main_200">#c7c7c7</color>
<!-- Shade of the main system color at 70% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
<color name="system_main_300">#ababab</color>
<!-- Shade of the main system color at 60% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
- <color name="system_main_400">#909090</color>
+ <color name="system_main_400">#8f8f8f</color>
<!-- Shade of the main system color at 50% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
<color name="system_main_500">#757575</color>
@@ -266,13 +266,13 @@
<color name="system_main_600">#5e5e5e</color>
<!-- Shade of the main system color at 30% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
- <color name="system_main_700">#464646</color>
+ <color name="system_main_700">#474747</color>
<!-- Shade of the main system color at 20% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
<color name="system_main_800">#303030</color>
<!-- Shade of the main system color at 10% lightness.
This value can be overlaid at runtime by OverlayManager RROs. -->
- <color name="system_main_900">#1b1b1b</color>
+ <color name="system_main_900">#1f1f1f</color>
<!-- Darkest shade of the main color used by the system. Black.
This value can be overlaid at runtime by OverlayManager RROs. -->
<color name="system_main_1000">#000000</color>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index b7c755ef7f6b..cc23f77a7929 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1946,6 +1946,10 @@
<string name="config_systemAutomotiveProjection" translatable="false"></string>
<!-- The name of the package that will hold the system cluster service role. -->
<string name="config_systemAutomotiveCluster" translatable="false"></string>
+ <!-- The name of the package that will hold the system shell role. -->
+ <string name="config_systemShell" translatable="false">com.android.shell</string>
+ <!-- The name of the package that will hold the system contacts role. -->
+ <string name="config_systemContacts" translatable="false">com.android.contacts</string>
<!-- The name of the package that will be allowed to change its components' label/icon. -->
<string name="config_overrideComponentUiPackage" translatable="false"></string>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index debdab0b37ba..706641985e20 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -926,4 +926,12 @@
<dimen name="controls_thumbnail_image_max_height">140dp</dimen>
<!-- The maximum width of a thumbnail in a ThumbnailTemplate. The image will be reduced to that width in case they are bigger.-->
<dimen name="controls_thumbnail_image_max_width">280dp</dimen>
+
+ <!-- System-provided radius for the background view of app widgets. The resolved value of this resource may change at runtime. -->
+ <dimen name="system_app_widget_background_radius">16dp</dimen>
+ <!-- System-provided radius for inner views on app widgets. The resolved value of this resource may change at runtime. -->
+ <dimen name="system_app_widget_inner_radius">8dp</dimen>
+ <!-- System-provided padding for inner views on app widgets. The resolved value of this resource may change at runtime. -->
+ <dimen name="system_app_widget_internal_padding">16dp</dimen>
+
</resources>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 278708a26d44..e43aa3dffc4d 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -3071,6 +3071,11 @@
<public name="windowSplashScreenAnimationDuration"/>
<public name="windowSplashScreenBrandingImage"/>
<public name="splashScreenTheme" />
+ <public name="rippleStyle" />
+ <public name="maxResizeWidth" />
+ <public name="maxResizeHeight" />
+ <public name="targetCellWidth" />
+ <public name="targetCellHeight" />
</public-group>
<public-group type="drawable" first-id="0x010800b5">
@@ -3111,6 +3116,11 @@
<public-group type="dimen" first-id="0x01050008">
<!-- dimension definitions go here -->
+
+ <!-- System-provided dimensions for app widgets. -->
+ <public name="system_app_widget_background_radius" />
+ <public name="system_app_widget_inner_radius" />
+ <public name="system_app_widget_internal_padding" />
</public-group>
<public-group type="bool" first-id="0x01110007">
@@ -3126,6 +3136,10 @@
<public name="config_systemAutomotiveCluster" />
<!-- @hide @SystemApi @TestApi -->
<public name="config_systemAutomotiveProjection" />
+ <!-- @hide @SystemApi -->
+ <public name="config_systemShell" />
+ <!-- @hide @SystemApi -->
+ <public name="config_systemContacts" />
</public-group>
<public-group type="id" first-id="0x01020055">
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index af5e406979ad..9ebe23af2c59 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1830,6 +1830,11 @@
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permdesc_startViewPermissionUsage">Allows the holder to start the permission usage for an app. Should never be needed for normal apps.</string>
+ <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR_LIMIT=NONE] -->
+ <string name="permlab_highSamplingRateSensors">access sensor data at a high sampling rate</string>
+ <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this.[CHAR_LIMIT=NONE] -->
+ <string name="permdesc_highSamplingRateSensors">Allows the app to sample sensor data at a rate greater than 200 Hz</string>
+
<!-- Policy administration -->
<!-- Title of policy access to limiting the user's password choices -->
diff --git a/core/res/res/values/themes_device_defaults.xml b/core/res/res/values/themes_device_defaults.xml
index ce4ee87e52a0..e7e049da18c9 100644
--- a/core/res/res/values/themes_device_defaults.xml
+++ b/core/res/res/values/themes_device_defaults.xml
@@ -224,6 +224,9 @@ easier.
<item name="textColorTertiary">@color/text_color_tertiary_device_default_dark</item>
<item name="colorForeground">@color/foreground_device_default_dark</item>
<item name="colorForegroundInverse">@color/foreground_device_default_light</item>
+
+ <!-- Ripple style-->
+ <item name="rippleStyle">solid</item>
</style>
<style name="Theme.DeviceDefault" parent="Theme.DeviceDefaultBase" />
diff --git a/core/tests/coretests/src/android/provider/SimPhonebookContractTest.java b/core/tests/coretests/src/android/provider/SimPhonebookContractTest.java
index be3826007aa3..bc7be1b08626 100644
--- a/core/tests/coretests/src/android/provider/SimPhonebookContractTest.java
+++ b/core/tests/coretests/src/android/provider/SimPhonebookContractTest.java
@@ -16,14 +16,8 @@
package android.provider;
-import static com.google.common.truth.Truth.assertThat;
-
import static org.testng.Assert.assertThrows;
-import android.content.ContentValues;
-import android.os.Parcel;
-import android.provider.SimPhonebookContract.SimRecords.NameValidationResult;
-
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
@@ -71,50 +65,5 @@ public class SimPhonebookContractTest {
SimPhonebookContract.ElementaryFiles.EF_ADN, -1)
);
}
-
- @Test
- public void nameValidationResult_isValid_validNames() {
- assertThat(new NameValidationResult("", "", 0, 1).isValid()).isTrue();
- assertThat(new NameValidationResult("a", "a", 1, 1).isValid()).isTrue();
- assertThat(new NameValidationResult("First Last", "First Last", 10, 10).isValid()).isTrue();
- assertThat(
- new NameValidationResult("First Last", "First Last", 10, 100).isValid()).isTrue();
- }
-
- @Test
- public void nameValidationResult_isValid_invalidNames() {
- assertThat(new NameValidationResult("", "", 0, 0).isValid()).isFalse();
- assertThat(new NameValidationResult("ab", "ab", 2, 1).isValid()).isFalse();
- NameValidationResult unsupportedCharactersResult = new NameValidationResult("A_b_c",
- "A b c", 5, 5);
- assertThat(unsupportedCharactersResult.isValid()).isFalse();
- assertThat(unsupportedCharactersResult.isSupportedCharacter(0)).isTrue();
- assertThat(unsupportedCharactersResult.isSupportedCharacter(1)).isFalse();
- assertThat(unsupportedCharactersResult.isSupportedCharacter(2)).isTrue();
- assertThat(unsupportedCharactersResult.isSupportedCharacter(3)).isFalse();
- assertThat(unsupportedCharactersResult.isSupportedCharacter(4)).isTrue();
- }
-
- @Test
- public void nameValidationResult_parcel() {
- ContentValues values = new ContentValues();
- values.put("name", "Name");
- values.put("phone_number", "123");
-
- NameValidationResult result;
- Parcel parcel = Parcel.obtain();
- try {
- parcel.writeParcelable(new NameValidationResult("name", "sanitized name", 1, 2), 0);
- parcel.setDataPosition(0);
- result = parcel.readParcelable(NameValidationResult.class.getClassLoader());
- } finally {
- parcel.recycle();
- }
-
- assertThat(result.getName()).isEqualTo("name");
- assertThat(result.getSanitizedName()).isEqualTo("sanitized name");
- assertThat(result.getEncodedLength()).isEqualTo(1);
- assertThat(result.getMaxEncodedLength()).isEqualTo(2);
- }
}
diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml
index 403dc65abbf5..8fd5d804adc0 100644
--- a/data/etc/privapp-permissions-platform.xml
+++ b/data/etc/privapp-permissions-platform.xml
@@ -316,6 +316,8 @@ applications that come with the platform
<permission name="android.permission.MODIFY_DAY_NIGHT_MODE"/>
<permission name="android.permission.ACCESS_LOWPAN_STATE"/>
<permission name="android.permission.BACKUP"/>
+ <!-- Needed for test only -->
+ <permission name="android.permission.BATTERY_PREDICTION"/>
<permission name="android.permission.BATTERY_STATS"/>
<permission name="android.permission.BIND_APPWIDGET"/>
<permission name="android.permission.CHANGE_APP_IDLE_STATE"/>
@@ -476,6 +478,8 @@ applications that come with the platform
<permission name="android.permission.CAPTURE_AUDIO_HOTWORD" />
<!-- Permission required for CTS test - CtsRebootReadinessTestCases -->
<permission name="android.permission.SIGNAL_REBOOT_READINESS" />
+ <!-- Permission required for CTS test - PeopleManagerTest -->
+ <permission name="android.permission.READ_PEOPLE_DATA" />
</privapp-permissions>
<privapp-permissions package="com.android.statementservice">
diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json
index ded4a276880f..84da930aac54 100644
--- a/data/etc/services.core.protolog.json
+++ b/data/etc/services.core.protolog.json
@@ -1075,12 +1075,6 @@
"group": "WM_DEBUG_IME",
"at": "com\/android\/server\/wm\/ImeInsetsSourceProvider.java"
},
- "-856025122": {
- "message": "SURFACE transparentRegionHint=%s: %s",
- "level": "INFO",
- "group": "WM_SHOW_TRANSACTIONS",
- "at": "com\/android\/server\/wm\/WindowManagerService.java"
- },
"-855366859": {
"message": " merging children in from %s: %s",
"level": "VERBOSE",
@@ -2821,12 +2815,6 @@
"group": "WM_ERROR",
"at": "com\/android\/server\/wm\/WindowManagerService.java"
},
- "1217926207": {
- "message": "Activity not running, resuming next.",
- "level": "VERBOSE",
- "group": "WM_DEBUG_STATES",
- "at": "com\/android\/server\/wm\/Task.java"
- },
"1219600119": {
"message": "addWindow: win=%s Callers=%s",
"level": "DEBUG",
@@ -3331,6 +3319,12 @@
"group": "WM_DEBUG_STATES",
"at": "com\/android\/server\/wm\/Task.java"
},
+ "1847414670": {
+ "message": "Activity not running or entered PiP, resuming next.",
+ "level": "VERBOSE",
+ "group": "WM_DEBUG_STATES",
+ "at": "com\/android\/server\/wm\/Task.java"
+ },
"1853793312": {
"message": "Notify removed startingWindow %s",
"level": "VERBOSE",
diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java
index b70fa0e693c2..88cf96a9eb4e 100644
--- a/graphics/java/android/graphics/HardwareRenderer.java
+++ b/graphics/java/android/graphics/HardwareRenderer.java
@@ -39,6 +39,7 @@ import android.view.IGraphicsStatsCallback;
import android.view.NativeVectorDrawableAnimator;
import android.view.PixelCopy;
import android.view.Surface;
+import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.animation.AnimationUtils;
@@ -314,6 +315,16 @@ public class HardwareRenderer {
}
/**
+ * Sets the SurfaceControl to be used internally inside render thread
+ * @hide
+ * @param surfaceControl The surface control to pass to render thread in hwui.
+ * If null, any previous references held in render thread will be discarded.
+ */
+ public void setSurfaceControl(@Nullable SurfaceControl surfaceControl) {
+ nSetSurfaceControl(mNativeProxy, surfaceControl != null ? surfaceControl.mNativeObject : 0);
+ }
+
+ /**
* Sets the parameters that can be used to control a render request for a
* {@link HardwareRenderer}. This is not thread-safe and must not be held on to for longer
* than a single frame request.
@@ -1216,6 +1227,8 @@ public class HardwareRenderer {
private static native void nSetSurface(long nativeProxy, Surface window, boolean discardBuffer);
+ private static native void nSetSurfaceControl(long nativeProxy, long nativeSurfaceControl);
+
private static native boolean nPause(long nativeProxy);
private static native void nSetStopped(long nativeProxy, boolean stopped);
diff --git a/graphics/java/android/graphics/drawable/RippleAnimationSession.java b/graphics/java/android/graphics/drawable/RippleAnimationSession.java
new file mode 100644
index 000000000000..80f65f919fa6
--- /dev/null
+++ b/graphics/java/android/graphics/drawable/RippleAnimationSession.java
@@ -0,0 +1,284 @@
+/*
+ * 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 android.graphics.drawable;
+
+import android.animation.Animator;
+import android.animation.TimeInterpolator;
+import android.animation.ValueAnimator;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.graphics.Canvas;
+import android.graphics.CanvasProperty;
+import android.graphics.Paint;
+import android.graphics.RecordingCanvas;
+import android.graphics.animation.RenderNodeAnimator;
+import android.util.ArraySet;
+import android.view.animation.DecelerateInterpolator;
+import android.view.animation.LinearInterpolator;
+
+import java.util.function.Consumer;
+
+/**
+ * @hide
+ */
+public final class RippleAnimationSession {
+ private static final int ENTER_ANIM_DURATION = 350;
+ private static final int EXIT_ANIM_OFFSET = ENTER_ANIM_DURATION;
+ private static final int EXIT_ANIM_DURATION = 350;
+ private static final TimeInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
+ // Matches R.interpolator.fast_out_slow_in but as we have no context we can't just import that
+ private static final TimeInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();
+
+ private Consumer<RippleAnimationSession> mOnSessionEnd;
+ private AnimationProperties<Float, Paint> mProperties;
+ private AnimationProperties<CanvasProperty<Float>, CanvasProperty<Paint>> mCanvasProperties;
+ private Runnable mOnUpdate;
+ private long mStartTime;
+ private boolean mForceSoftware;
+ private ArraySet<Animator> mActiveAnimations = new ArraySet(3);
+
+ RippleAnimationSession(@NonNull AnimationProperties<Float, Paint> properties,
+ boolean forceSoftware) {
+ mProperties = properties;
+ mForceSoftware = forceSoftware;
+ }
+
+ void end() {
+ for (Animator anim: mActiveAnimations) {
+ if (anim != null) anim.end();
+ }
+ mActiveAnimations.clear();
+ }
+
+ @NonNull RippleAnimationSession enter(Canvas canvas) {
+ if (isHwAccelerated(canvas)) {
+ enterHardware((RecordingCanvas) canvas);
+ } else {
+ enterSoftware();
+ }
+ mStartTime = System.nanoTime();
+ return this;
+ }
+
+ @NonNull RippleAnimationSession exit(Canvas canvas) {
+ if (isHwAccelerated(canvas)) exitHardware((RecordingCanvas) canvas);
+ else exitSoftware();
+ return this;
+ }
+
+ private void onAnimationEnd(Animator anim) {
+ mActiveAnimations.remove(anim);
+ }
+
+ @NonNull RippleAnimationSession setOnSessionEnd(
+ @Nullable Consumer<RippleAnimationSession> onSessionEnd) {
+ mOnSessionEnd = onSessionEnd;
+ return this;
+ }
+
+ RippleAnimationSession setOnAnimationUpdated(@Nullable Runnable run) {
+ mOnUpdate = run;
+ mProperties.setOnChange(mOnUpdate);
+ return this;
+ }
+
+ private boolean isHwAccelerated(Canvas canvas) {
+ return canvas.isHardwareAccelerated() && !mForceSoftware;
+ }
+
+ private void exitSoftware() {
+ ValueAnimator expand = ValueAnimator.ofFloat(.5f, 1f);
+ expand.setDuration(EXIT_ANIM_DURATION);
+ expand.setStartDelay(computeDelay());
+ expand.addUpdateListener(updatedAnimation -> {
+ notifyUpdate();
+ mProperties.getShader().setProgress((Float) expand.getAnimatedValue());
+ });
+ expand.addListener(new AnimatorListener(this) {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ Consumer<RippleAnimationSession> onEnd = mOnSessionEnd;
+ if (onEnd != null) onEnd.accept(RippleAnimationSession.this);
+ }
+ });
+ expand.setInterpolator(LINEAR_INTERPOLATOR);
+ expand.start();
+ mActiveAnimations.add(expand);
+ }
+
+ private long computeDelay() {
+ long currentTime = System.nanoTime();
+ long timePassed = (currentTime - mStartTime) / 1_000_000;
+ long difference = EXIT_ANIM_OFFSET;
+ return Math.max(difference - timePassed, 0);
+ }
+ private void notifyUpdate() {
+ Runnable onUpdate = mOnUpdate;
+ if (onUpdate != null) onUpdate.run();
+ }
+
+ RippleAnimationSession setForceSoftwareAnimation(boolean forceSw) {
+ mForceSoftware = forceSw;
+ return this;
+ }
+
+
+ private void exitHardware(RecordingCanvas canvas) {
+ AnimationProperties<CanvasProperty<Float>, CanvasProperty<Paint>>
+ props = getCanvasProperties();
+ RenderNodeAnimator exit =
+ new RenderNodeAnimator(props.getProgress(), 1f);
+ exit.setDuration(EXIT_ANIM_DURATION);
+ exit.addListener(new AnimatorListener(this) {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ Consumer<RippleAnimationSession> onEnd = mOnSessionEnd;
+ if (onEnd != null) onEnd.accept(RippleAnimationSession.this);
+ }
+ });
+ exit.setTarget(canvas);
+ exit.setInterpolator(DECELERATE_INTERPOLATOR);
+
+ long delay = computeDelay();
+ exit.setStartDelay(delay);
+ exit.start();
+ mActiveAnimations.add(exit);
+ }
+
+ private void enterHardware(RecordingCanvas can) {
+ AnimationProperties<CanvasProperty<Float>, CanvasProperty<Paint>>
+ props = getCanvasProperties();
+ RenderNodeAnimator expand =
+ new RenderNodeAnimator(props.getProgress(), .5f);
+ expand.setTarget(can);
+ expand.setDuration(ENTER_ANIM_DURATION);
+ expand.addListener(new AnimatorListener(this));
+ expand.setInterpolator(LINEAR_INTERPOLATOR);
+ expand.start();
+ mActiveAnimations.add(expand);
+ }
+
+ private void enterSoftware() {
+ ValueAnimator expand = ValueAnimator.ofFloat(0f, 0.5f);
+ expand.addUpdateListener(updatedAnimation -> {
+ notifyUpdate();
+ mProperties.getShader().setProgress((Float) expand.getAnimatedValue());
+ });
+ expand.addListener(new AnimatorListener(this));
+ expand.setInterpolator(LINEAR_INTERPOLATOR);
+ expand.start();
+ mActiveAnimations.add(expand);
+ }
+
+ @NonNull AnimationProperties<Float, Paint> getProperties() {
+ return mProperties;
+ }
+
+ @NonNull AnimationProperties getCanvasProperties() {
+ if (mCanvasProperties == null) {
+ mCanvasProperties = new AnimationProperties<>(
+ CanvasProperty.createFloat(mProperties.getX()),
+ CanvasProperty.createFloat(mProperties.getY()),
+ CanvasProperty.createFloat(mProperties.getMaxRadius()),
+ CanvasProperty.createPaint(mProperties.getPaint()),
+ CanvasProperty.createFloat(mProperties.getProgress()),
+ mProperties.getShader());
+ }
+ return mCanvasProperties;
+ }
+
+ private static class AnimatorListener implements Animator.AnimatorListener {
+ private final RippleAnimationSession mSession;
+
+ AnimatorListener(RippleAnimationSession session) {
+ mSession = session;
+ }
+ @Override
+ public void onAnimationStart(Animator animation) {
+
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mSession.onAnimationEnd(animation);
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animation) {
+
+ }
+ }
+
+ static class AnimationProperties<FloatType, PaintType> {
+ private final FloatType mY;
+ private FloatType mProgress;
+ private FloatType mMaxRadius;
+ private final PaintType mPaint;
+ private final FloatType mX;
+ private final RippleShader mShader;
+ private Runnable mOnChange;
+
+ private void onChange() {
+ if (mOnChange != null) mOnChange.run();
+ }
+
+ private void setOnChange(Runnable onChange) {
+ mOnChange = onChange;
+ }
+
+ AnimationProperties(FloatType x, FloatType y, FloatType maxRadius,
+ PaintType paint, FloatType progress, RippleShader shader) {
+ mY = y;
+ mX = x;
+ mMaxRadius = maxRadius;
+ mPaint = paint;
+ mShader = shader;
+ mProgress = progress;
+ }
+
+ FloatType getProgress() {
+ return mProgress;
+ }
+
+ FloatType getX() {
+ return mX;
+ }
+
+ FloatType getY() {
+ return mY;
+ }
+
+ FloatType getMaxRadius() {
+ return mMaxRadius;
+ }
+
+ PaintType getPaint() {
+ return mPaint;
+ }
+
+ RippleShader getShader() {
+ return mShader;
+ }
+ }
+}
diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java
index bab80cee2b26..5024875aab3c 100644
--- a/graphics/java/android/graphics/drawable/RippleDrawable.java
+++ b/graphics/java/android/graphics/drawable/RippleDrawable.java
@@ -16,6 +16,14 @@
package android.graphics.drawable;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.animation.ValueAnimator;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
@@ -27,17 +35,21 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
+import android.graphics.CanvasProperty;
import android.graphics.Color;
+import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
+import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.Shader;
import android.os.Build;
import android.util.AttributeSet;
+import android.view.animation.LinearInterpolator;
import com.android.internal.R;
@@ -45,6 +57,9 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
import java.util.Arrays;
/**
@@ -94,6 +109,17 @@ import java.util.Arrays;
* </pre>
*
* @attr ref android.R.styleable#RippleDrawable_color
+ *
+ * To change the ripple style, assign the value of "solid" or "patterned" to the android:rippleStyle
+ * attribute.
+ *
+ * <pre>
+ * <code>&lt;!-- A red ripple masked against an opaque rectangle. --/>
+ * &lt;ripple android:rippleStyle="patterned">
+ * &lt;/ripple></code>
+ * </pre>
+ *
+ * @attr ref android.R.styleable#RippleDrawable_rippleStyle
*/
public class RippleDrawable extends LayerDrawable {
/**
@@ -102,6 +128,29 @@ public class RippleDrawable extends LayerDrawable {
*/
public static final int RADIUS_AUTO = -1;
+ /**
+ * Ripple style where a solid circle is drawn. This is also the default style
+ * @see #setRippleStyle(int)
+ */
+ public static final int STYLE_SOLID = 0;
+ /**
+ * Ripple style where a circle shape with a patterned,
+ * noisy interior expands from the hotspot to the bounds".
+ * @see #setRippleStyle(int)
+ */
+ public static final int STYLE_PATTERNED = 1;
+
+ /**
+ * Ripple drawing style
+ * @hide
+ */
+ @Retention(SOURCE)
+ @Target({PARAMETER, METHOD, LOCAL_VARIABLE, FIELD})
+ @IntDef({STYLE_SOLID, STYLE_PATTERNED})
+ public @interface RippleStyle {
+ }
+
+ private static final int BACKGROUND_OPACITY_DURATION = 80;
private static final int MASK_UNKNOWN = -1;
private static final int MASK_NONE = 0;
private static final int MASK_CONTENT = 1;
@@ -109,6 +158,7 @@ public class RippleDrawable extends LayerDrawable {
/** The maximum number of ripples supported. */
private static final int MAX_RIPPLES = 10;
+ private static final LinearInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
private final Rect mTempRect = new Rect();
@@ -172,6 +222,14 @@ public class RippleDrawable extends LayerDrawable {
*/
private boolean mForceSoftware;
+ // Patterned
+ private float mTargetBackgroundOpacity;
+ private ValueAnimator mBackgroundAnimation;
+ private float mBackgroundOpacity;
+ private boolean mRunBackgroundAnimation;
+ private boolean mExitingAnimation;
+ private ArrayList<RippleAnimationSession> mRunningAnimations = new ArrayList<>();
+
/**
* Constructor used for drawable inflation.
*/
@@ -235,7 +293,7 @@ public class RippleDrawable extends LayerDrawable {
Arrays.fill(ripples, 0, count, null);
}
mExitingRipplesCount = 0;
-
+ mExitingAnimation = true;
// Always draw an additional "clean" frame after canceling animations.
invalidateSelf(false);
}
@@ -276,21 +334,37 @@ public class RippleDrawable extends LayerDrawable {
private void setRippleActive(boolean active) {
if (mRippleActive != active) {
mRippleActive = active;
+ }
+ if (mState.mRippleStyle == STYLE_SOLID) {
if (active) {
tryRippleEnter();
} else {
tryRippleExit();
}
+ } else {
+ if (active) {
+ startPatternedAnimation();
+ } else {
+ exitPatternedAnimation();
+ }
}
}
private void setBackgroundActive(boolean hovered, boolean focused, boolean pressed) {
- if (mBackground == null && (hovered || focused)) {
- mBackground = new RippleBackground(this, mHotspotBounds, isBounded());
- mBackground.setup(mState.mMaxRadius, mDensity);
- }
- if (mBackground != null) {
- mBackground.setState(focused, hovered, pressed);
+ if (mState.mRippleStyle == STYLE_SOLID) {
+ if (mBackground == null && (hovered || focused)) {
+ mBackground = new RippleBackground(this, mHotspotBounds, isBounded());
+ mBackground.setup(mState.mMaxRadius, mDensity);
+ }
+ if (mBackground != null) {
+ mBackground.setState(focused, hovered, pressed);
+ }
+ } else {
+ if (focused || hovered) {
+ enterPatternedBackgroundAnimation(focused, hovered);
+ } else {
+ exitPatternedBackgroundAnimation();
+ }
}
}
@@ -317,6 +391,9 @@ public class RippleDrawable extends LayerDrawable {
mRipple.onBoundsChange();
}
+ mState.mMaxRadius = mState.mMaxRadius <= 0 && mState.mRippleStyle != STYLE_SOLID
+ ? (int) computeRadius()
+ : mState.mMaxRadius;
invalidateSelf();
}
@@ -330,7 +407,11 @@ public class RippleDrawable extends LayerDrawable {
// If we just became visible, ensure the background and ripple
// visibilities are consistent with their internal states.
if (mRippleActive) {
- tryRippleEnter();
+ if (mState.mRippleStyle == STYLE_SOLID) {
+ tryRippleEnter();
+ } else {
+ invalidateSelf();
+ }
}
// Skip animations, just show the correct final states.
@@ -489,6 +570,8 @@ public class RippleDrawable extends LayerDrawable {
mState.mMaxRadius = a.getDimensionPixelSize(
R.styleable.RippleDrawable_radius, mState.mMaxRadius);
+
+ mState.mRippleStyle = a.getInteger(R.styleable.RippleDrawable_rippleStyle, STYLE_SOLID);
}
private void verifyRequiredAttributes(@NonNull TypedArray a) throws XmlPullParserException {
@@ -535,9 +618,9 @@ public class RippleDrawable extends LayerDrawable {
@Override
public void setHotspot(float x, float y) {
+ mPendingX = x;
+ mPendingY = y;
if (mRipple == null || mBackground == null) {
- mPendingX = x;
- mPendingY = y;
mHasPending = true;
}
@@ -665,6 +748,14 @@ public class RippleDrawable extends LayerDrawable {
*/
@Override
public void draw(@NonNull Canvas canvas) {
+ if (mState.mRippleStyle == STYLE_SOLID) {
+ drawSolid(canvas);
+ } else {
+ drawPatterned(canvas);
+ }
+ }
+
+ private void drawSolid(Canvas canvas) {
pruneRipples();
// Clip to the dirty bounds, which will be the drawable bounds if we
@@ -681,6 +772,178 @@ public class RippleDrawable extends LayerDrawable {
canvas.restoreToCount(saveCount);
}
+ private void exitPatternedBackgroundAnimation() {
+ mTargetBackgroundOpacity = 0;
+ if (mBackgroundAnimation != null) mBackgroundAnimation.cancel();
+ // after cancel
+ mRunBackgroundAnimation = true;
+ invalidateSelf(false);
+ }
+
+ private void startPatternedAnimation() {
+ mRippleActive = true;
+ invalidateSelf(false);
+ }
+
+ private void exitPatternedAnimation() {
+ mExitingAnimation = true;
+ invalidateSelf(false);
+ }
+
+ private void enterPatternedBackgroundAnimation(boolean focused, boolean hovered) {
+ mBackgroundOpacity = 0;
+ mTargetBackgroundOpacity = focused ? .6f : hovered ? .2f : 0f;
+ if (mBackgroundAnimation != null) mBackgroundAnimation.cancel();
+ // after cancel
+ mRunBackgroundAnimation = true;
+ invalidateSelf(false);
+ }
+
+ private void startBackgroundAnimation() {
+ mRunBackgroundAnimation = false;
+ mBackgroundAnimation = ValueAnimator.ofFloat(mBackgroundOpacity, mTargetBackgroundOpacity);
+ mBackgroundAnimation.setInterpolator(LINEAR_INTERPOLATOR);
+ mBackgroundAnimation.setDuration(BACKGROUND_OPACITY_DURATION);
+ mBackgroundAnimation.addUpdateListener(update -> {
+ mBackgroundOpacity = (float) update.getAnimatedValue();
+ invalidateSelf(false);
+ });
+ mBackgroundAnimation.start();
+ }
+
+ private void drawPatterned(@NonNull Canvas canvas) {
+ final Rect bounds = getBounds();
+ final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
+ boolean useCanvasProps = shouldUseCanvasProps(canvas);
+ boolean changedHotspotBounds = !bounds.equals(mHotspotBounds);
+ if (isBounded()) {
+ canvas.clipRect(mHotspotBounds);
+ }
+ float x, y;
+ if (changedHotspotBounds) {
+ x = mHotspotBounds.exactCenterX();
+ y = mHotspotBounds.exactCenterY();
+ useCanvasProps = false;
+ } else {
+ x = mPendingX;
+ y = mPendingY;
+ }
+ boolean shouldAnimate = mRippleActive;
+ boolean shouldExit = mExitingAnimation;
+ mRippleActive = false;
+ mExitingAnimation = false;
+ getRipplePaint();
+ drawContent(canvas);
+ drawPatternedBackground(canvas);
+ if (shouldAnimate && mRunningAnimations.size() <= MAX_RIPPLES) {
+ RippleAnimationSession.AnimationProperties<Float, Paint> properties =
+ createAnimationProperties(x, y);
+ mRunningAnimations.add(new RippleAnimationSession(properties, !useCanvasProps)
+ .setOnAnimationUpdated(useCanvasProps ? null : () -> invalidateSelf(false))
+ .setOnSessionEnd(session -> {
+ mRunningAnimations.remove(session);
+ })
+ .setForceSoftwareAnimation(!useCanvasProps)
+ .enter(canvas));
+ }
+ if (shouldExit) {
+ for (int i = 0; i < mRunningAnimations.size(); i++) {
+ RippleAnimationSession s = mRunningAnimations.get(i);
+ s.exit(canvas);
+ }
+ }
+ for (int i = 0; i < mRunningAnimations.size(); i++) {
+ RippleAnimationSession s = mRunningAnimations.get(i);
+ if (useCanvasProps) {
+ RippleAnimationSession.AnimationProperties<CanvasProperty<Float>,
+ CanvasProperty<Paint>>
+ p = s.getCanvasProperties();
+ RecordingCanvas can = (RecordingCanvas) canvas;
+ can.drawRipple(p.getX(), p.getY(), p.getMaxRadius(), p.getPaint(),
+ p.getProgress(), p.getShader());
+ } else {
+ RippleAnimationSession.AnimationProperties<Float, Paint> p =
+ s.getProperties();
+ float posX, posY;
+ if (changedHotspotBounds) {
+ posX = x;
+ posY = y;
+ if (p.getPaint().getShader() instanceof RippleShader) {
+ RippleShader shader = (RippleShader) p.getPaint().getShader();
+ shader.setOrigin(posX, posY);
+ }
+ } else {
+ posX = p.getX();
+ posY = p.getY();
+ }
+ float radius = p.getMaxRadius();
+ canvas.drawCircle(posX, posY, radius, p.getPaint());
+ }
+ }
+ canvas.restoreToCount(saveCount);
+ }
+
+ private void drawPatternedBackground(Canvas c) {
+ if (mRunBackgroundAnimation) {
+ startBackgroundAnimation();
+ }
+ if (mBackgroundOpacity == 0) return;
+ Paint p = mRipplePaint;
+ float newOpacity = mBackgroundOpacity;
+ final int origAlpha = p.getAlpha();
+ final int alpha = Math.min((int) (origAlpha * newOpacity + 0.5f), 255);
+ if (alpha > 0) {
+ ColorFilter origFilter = p.getColorFilter();
+ p.setColorFilter(mMaskColorFilter);
+ p.setAlpha(alpha);
+ Rect b = mHotspotBounds;
+ c.drawCircle(b.centerX(), b.centerY(), mState.mMaxRadius, p);
+ p.setAlpha(origAlpha);
+ p.setColorFilter(origFilter);
+ }
+ }
+
+ private float computeRadius() {
+ Rect b = getDirtyBounds();
+ float gap = 0;
+ float radius = (float) Math.sqrt(b.width() * b.width() + b.height() * b.height()) / 2 + gap;
+ return radius;
+ }
+
+ @NonNull
+ private RippleAnimationSession.AnimationProperties<Float, Paint> createAnimationProperties(
+ float x, float y) {
+ Paint p = new Paint(mRipplePaint);
+ float radius = mState.mMaxRadius;
+ RippleAnimationSession.AnimationProperties<Float, Paint> properties;
+ RippleShader shader = new RippleShader();
+ int color = mMaskColorFilter == null
+ ? mState.mColor.getColorForState(getState(), Color.BLACK)
+ : mMaskColorFilter.getColor();
+ color = color | 0xFF000000;
+ shader.setColor(color);
+ shader.setOrigin(x, y);
+ shader.setRadius(radius);
+ shader.setProgress(.0f);
+ properties = new RippleAnimationSession.AnimationProperties<>(
+ x, y, radius, p, 0f,
+ shader);
+ if (mMaskShader == null) {
+ shader.setHasMask(false);
+ } else {
+ shader.setShader(mMaskShader);
+ shader.setHasMask(true);
+ }
+ p.setShader(shader);
+ p.setColorFilter(null);
+ p.setColor(color);
+ return properties;
+ }
+
+ private boolean shouldUseCanvasProps(Canvas c) {
+ return !mForceSoftware && c.isHardwareAccelerated();
+ }
+
@Override
public void invalidateSelf() {
invalidateSelf(true);
@@ -774,18 +1037,23 @@ public class RippleDrawable extends LayerDrawable {
// Draw the appropriate mask anchored to (0,0).
final int left = bounds.left;
final int top = bounds.top;
- mMaskCanvas.translate(-left, -top);
+ if (mState.mRippleStyle == STYLE_SOLID) {
+ mMaskCanvas.translate(-left, -top);
+ }
if (maskType == MASK_EXPLICIT) {
drawMask(mMaskCanvas);
} else if (maskType == MASK_CONTENT) {
drawContent(mMaskCanvas);
}
- mMaskCanvas.translate(left, top);
+ if (mState.mRippleStyle == STYLE_SOLID) {
+ mMaskCanvas.translate(left, top);
+ }
}
private int getMaskType() {
if (mRipple == null && mExitingRipplesCount <= 0
- && (mBackground == null || !mBackground.isVisible())) {
+ && (mBackground == null || !mBackground.isVisible())
+ && mState.mRippleStyle == STYLE_SOLID) {
// We might need a mask later.
return MASK_UNKNOWN;
}
@@ -874,7 +1142,7 @@ public class RippleDrawable extends LayerDrawable {
updateMaskShaderIfNeeded();
// Position the shader to account for canvas translation.
- if (mMaskShader != null) {
+ if (mMaskShader != null && mState.mRippleStyle == STYLE_SOLID) {
final Rect bounds = getBounds();
mMaskMatrix.setTranslate(bounds.left - x, bounds.top - y);
mMaskShader.setLocalMatrix(mMaskMatrix);
@@ -973,6 +1241,31 @@ public class RippleDrawable extends LayerDrawable {
return this;
}
+ /**
+ * Sets the visual style of the ripple.
+ *
+ * @see #STYLE_SOLID
+ * @see #STYLE_PATTERNED
+ *
+ * @param style The style of the ripple
+ */
+ public void setRippleStyle(@RippleStyle int style) throws IllegalArgumentException {
+ if (style == STYLE_SOLID || style == STYLE_PATTERNED) {
+ mState.mRippleStyle = style;
+ } else {
+ throw new IllegalArgumentException("Invalid style value " + style);
+ }
+ }
+
+ /**
+ * Get the current ripple style
+ * @return Ripple style
+ */
+ public @RippleStyle int getRippleStyle() {
+ return mState.mRippleStyle;
+ }
+
+
@Override
RippleState createConstantState(LayerState state, Resources res) {
return new RippleState(state, this, res);
@@ -983,6 +1276,7 @@ public class RippleDrawable extends LayerDrawable {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
ColorStateList mColor = ColorStateList.valueOf(Color.MAGENTA);
int mMaxRadius = RADIUS_AUTO;
+ int mRippleStyle = STYLE_SOLID;
public RippleState(LayerState orig, RippleDrawable owner, Resources res) {
super(orig, owner, res);
@@ -992,6 +1286,7 @@ public class RippleDrawable extends LayerDrawable {
mTouchThemeAttrs = origs.mTouchThemeAttrs;
mColor = origs.mColor;
mMaxRadius = origs.mMaxRadius;
+ mRippleStyle = origs.mRippleStyle;
if (origs.mDensity != mDensity) {
applyDensityScaling(orig.mDensity, mDensity);
diff --git a/graphics/java/android/graphics/drawable/RippleShader.java b/graphics/java/android/graphics/drawable/RippleShader.java
new file mode 100644
index 000000000000..500efdd84854
--- /dev/null
+++ b/graphics/java/android/graphics/drawable/RippleShader.java
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package android.graphics.drawable;
+
+import android.annotation.ColorInt;
+import android.annotation.NonNull;
+import android.graphics.Color;
+import android.graphics.RuntimeShader;
+import android.graphics.Shader;
+
+final class RippleShader extends RuntimeShader {
+ private static final String SHADER = "uniform float2 in_origin;\n"
+ + "uniform float in_maxRadius;\n"
+ + "uniform float in_progress;\n"
+ + "uniform float in_hasMask;\n"
+ + "uniform float4 in_color;\n"
+ + "uniform shader in_shader;\n"
+ + "float dist2(float2 p0, float2 pf) { return sqrt((pf.x - p0.x) * (pf.x - p0.x) + "
+ + "(pf.y - p0.y) * (pf.y - p0.y)); }\n"
+ + "float mod2(float a, float b) { return a - (b * floor(a / b)); }\n"
+ + "float rand(float2 src) { return fract(sin(dot(src.xy, float2(12.9898, 78.233))) * "
+ + "43758.5453123); }\n"
+ + "float4 main(float2 p)\n"
+ + "{\n"
+ + " float fraction = in_progress;\n"
+ + " float2 fragCoord = p;//sk_FragCoord.xy;\n"
+ + " float maxDist = in_maxRadius;\n"
+ + " float fragDist = dist2(in_origin, fragCoord.xy);\n"
+ + " float circleRadius = maxDist * fraction;\n"
+ + " float colorVal = (fragDist - circleRadius) / maxDist;\n"
+ + " float d = fragDist < circleRadius \n"
+ + " ? 1. - abs(colorVal * 3. * smoothstep(0., 1., fraction)) \n"
+ + " : 1. - abs(colorVal * 5.);\n"
+ + " d = smoothstep(0., 1., d);\n"
+ + " float divider = 2.;\n"
+ + " float x = floor(fragCoord.x / divider);\n"
+ + " float y = floor(fragCoord.y / divider);\n"
+ + " float density = .95;\n"
+ + " d = rand(float2(x, y)) > density ? d : d * .2;\n"
+ + " d = d * rand(float2(fraction, x * y));\n"
+ + " float alpha = 1. - pow(fraction, 2.);\n"
+ + " if (in_hasMask != 0.) {return sample(in_shader).a * in_color * d * alpha;}\n"
+ + " return in_color * d * alpha;\n"
+ + "}\n";
+
+ RippleShader() {
+ super(SHADER, false);
+ }
+
+ public void setShader(@NonNull Shader s) {
+ setInputShader("in_shader", s);
+ }
+
+ public void setRadius(float radius) {
+ setUniform("in_maxRadius", radius);
+ }
+
+ public void setOrigin(float x, float y) {
+ setUniform("in_origin", new float[] {x, y});
+ }
+
+ public void setProgress(float progress) {
+ setUniform("in_progress", progress);
+ }
+
+ public void setHasMask(boolean hasMask) {
+ setUniform("in_hasMask", hasMask ? 1 : 0);
+ }
+
+ public void setColor(@ColorInt int colorIn) {
+ Color color = Color.valueOf(colorIn);
+ this.setUniform("in_color", new float[] {color.red(),
+ color.green(), color.blue(), color.alpha()});
+ }
+}
diff --git a/graphics/java/android/graphics/fonts/FontVariationAxis.java b/graphics/java/android/graphics/fonts/FontVariationAxis.java
index 7bd581723d18..d1fe2cdbcd77 100644
--- a/graphics/java/android/graphics/fonts/FontVariationAxis.java
+++ b/graphics/java/android/graphics/fonts/FontVariationAxis.java
@@ -23,6 +23,7 @@ import android.os.Build;
import android.text.TextUtils;
import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
@@ -189,6 +190,17 @@ public final class FontVariationAxis {
return TextUtils.join(",", axes);
}
+ /**
+ * Stringify the array of FontVariationAxis.
+ * @hide
+ */
+ public static @NonNull String toFontVariationSettings(@Nullable List<FontVariationAxis> axes) {
+ if (axes == null) {
+ return "";
+ }
+ return TextUtils.join(",", axes);
+ }
+
@Override
public boolean equals(@Nullable Object o) {
if (o == this) {
diff --git a/keystore/java/android/security/keystore/KeyGenParameterSpec.java b/keystore/java/android/security/keystore/KeyGenParameterSpec.java
index e92eaca2b6e9..2b0d7e53b749 100644
--- a/keystore/java/android/security/keystore/KeyGenParameterSpec.java
+++ b/keystore/java/android/security/keystore/KeyGenParameterSpec.java
@@ -236,6 +236,47 @@ import javax.security.auth.x500.X500Principal;
* keyStore.load(null);
* key = (SecretKey) keyStore.getKey("key2", null);
* }</pre>
+ *
+ * <p><h3 id="example:ecdh">Example: EC key for ECDH key agreement</h3>
+ * This example illustrates how to generate an elliptic curve key pair, used to establish a shared
+ * secret with another party using ECDH key agreement.
+ * <pre> {@code
+ * KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
+ * KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
+ * keyPairGenerator.initialize(
+ * new KeyGenParameterSpec.Builder(
+ * "eckeypair",
+ * KeyProperties.PURPOSE_AGREE_KEY)
+ * .setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1"))
+ * .build());
+ * KeyPair myKeyPair = keyPairGenerator.generateKeyPair();
+ *
+ * // Exchange public keys with server. A new ephemeral key MUST be used for every message.
+ * PublicKey serverEphemeralPublicKey; // Ephemeral key received from server.
+ *
+ * // Create a shared secret based on our private key and the other party's public key.
+ * KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH", "AndroidKeyStore");
+ * keyAgreement.init(myKeyPair.getPrivate());
+ * keyAgreement.doPhase(serverEphemeralPublicKey, true);
+ * byte[] sharedSecret = keyAgreement.generateSecret();
+ *
+ * // sharedSecret cannot safely be used as a key yet. We must run it through a key derivation
+ * // function with some other data: "salt" and "info". Salt is an optional random value,
+ * // omitted in this example. It's good practice to include both public keys and any other
+ * // key negotiation data in info. Here we use the public keys and a label that indicates
+ * // messages encrypted with this key are coming from the server.
+ * byte[] salt = {};
+ * ByteArrayOutputStream info = new ByteArrayOutputStream();
+ * info.write("ECDH secp256r1 AES-256-GCM-SIV\0".getBytes(StandardCharsets.UTF_8));
+ * info.write(myKeyPair.getPublic().getEncoded());
+ * info.write(serverEphemeralPublicKey.getEncoded());
+ *
+ * // This example uses the Tink library and the HKDF key derivation function.
+ * AesGcmSiv key = new AesGcmSiv(Hkdf.computeHkdf(
+ * "HMACSHA256", sharedSecret, salt, info.toByteArray(), 32));
+ * byte[] associatedData = {};
+ * return key.decrypt(ciphertext, associatedData);
+ * }
*/
public final class KeyGenParameterSpec implements AlgorithmParameterSpec, UserAuthArgs {
diff --git a/keystore/java/android/security/keystore/KeyProperties.java b/keystore/java/android/security/keystore/KeyProperties.java
index 3ebca6ad302d..293ab05e0b10 100644
--- a/keystore/java/android/security/keystore/KeyProperties.java
+++ b/keystore/java/android/security/keystore/KeyProperties.java
@@ -100,6 +100,15 @@ public abstract class KeyProperties {
/**
* Purpose of key: creating a shared ECDH secret through key agreement.
+ *
+ * <p>A key having this purpose can be combined with the elliptic curve public key of another
+ * party to establish a shared secret over an insecure channel. It should be used as a
+ * parameter to {@link javax.crypto.KeyAgreement#init(java.security.Key)} (a complete example is
+ * available <a
+ * href="{@docRoot}reference/android/security/keystore/KeyGenParameterSpec#example:ecdh"
+ * >here</a>).
+ * See <a href="https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman">this
+ * article</a> for a more detailed explanation.
*/
public static final int PURPOSE_AGREE_KEY = 1 << 6;
diff --git a/libs/WindowManager/Shell/Android.bp b/libs/WindowManager/Shell/Android.bp
index 96e0559b0df6..0540aee1d6d9 100644
--- a/libs/WindowManager/Shell/Android.bp
+++ b/libs/WindowManager/Shell/Android.bp
@@ -71,27 +71,6 @@ genrule {
"$(locations :wm_shell-sources)",
out: ["wm_shell_protolog.json"],
}
-
-filegroup {
- name: "wm_shell_protolog.json",
- srcs: ["res/raw/wm_shell_protolog.json"],
-}
-
-genrule {
- name: "checked-wm_shell_protolog.json",
- srcs: [
- ":generate-wm_shell_protolog.json",
- ":wm_shell_protolog.json",
- ],
- cmd: "cp $(location :generate-wm_shell_protolog.json) $(out) && " +
- "{ ! (diff $(out) $(location :wm_shell_protolog.json) | grep -q '^<') || " +
- "{ echo -e '\\n\\n################################################################\\n#\\n" +
- "# ERROR: ProtoLog viewer config is stale. To update it, run:\\n#\\n" +
- "# cp $(location :generate-wm_shell_protolog.json) " +
- "$(location :wm_shell_protolog.json)\\n#\\n" +
- "################################################################\\n\\n' >&2 && false; } }",
- out: ["wm_shell_protolog.json"],
-}
// End ProtoLog
java_library {
@@ -115,6 +94,9 @@ android_library {
resource_dirs: [
"res",
],
+ java_resources: [
+ ":generate-wm_shell_protolog.json"
+ ],
static_libs: [
"androidx.appcompat_appcompat",
"androidx.arch.core_core-runtime",
diff --git a/libs/WindowManager/Shell/res/raw/wm_shell_protolog.json b/libs/WindowManager/Shell/res/raw/wm_shell_protolog.json
deleted file mode 100644
index 9c3d84e72f8c..000000000000
--- a/libs/WindowManager/Shell/res/raw/wm_shell_protolog.json
+++ /dev/null
@@ -1,286 +0,0 @@
-{
- "version": "1.0.0",
- "messages": {
- "-2076257741": {
- "message": "Transition requested: %s %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "-1683614271": {
- "message": "Existing task: id=%d component=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "-1671119352": {
- "message": " Delegate animation for %s to %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/RemoteTransitionHandler.java"
- },
- "-1501874464": {
- "message": "Fullscreen Task Appeared: #%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/FullscreenTaskListener.java"
- },
- "-1382704050": {
- "message": "Display removed: %d",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragAndDropController.java"
- },
- "-1362429294": {
- "message": "%s onTaskAppeared Primary taskId=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/legacysplitscreen\/LegacySplitScreenTaskListener.java"
- },
- "-1340279385": {
- "message": "Remove listener=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "-1325223370": {
- "message": "Task appeared taskId=%d listener=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "-1312360667": {
- "message": "createRootTask() displayId=%d winMode=%d listener=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "-1308483871": {
- "message": " try handler %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "-1297259344": {
- "message": " animated by %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "-1269886472": {
- "message": "Transition %s doesn't have explicit remote, search filters for match for %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/RemoteTransitionHandler.java"
- },
- "-1006733970": {
- "message": "Display added: %d",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragAndDropController.java"
- },
- "-1000962629": {
- "message": "Animate bounds: from=%s to=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DropOutlineDrawable.java"
- },
- "-880817403": {
- "message": "Task vanished taskId=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "-742394458": {
- "message": "pair task1=%d task2=%d in AppPair=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPair.java"
- },
- "-710770147": {
- "message": "Add target: %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragLayout.java"
- },
- "-298656957": {
- "message": "%s onTaskAppeared unknown taskId=%d winMode=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/legacysplitscreen\/LegacySplitScreenTaskListener.java"
- },
- "-234284913": {
- "message": "unpair taskId=%d pair=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPairsController.java"
- },
- "138343607": {
- "message": " try firstHandler %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "157713005": {
- "message": "Task info changed taskId=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "214412327": {
- "message": "RemoteTransition directly requested for %s: %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/RemoteTransitionHandler.java"
- },
- "274140888": {
- "message": "Animate alpha: from=%d to=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DropOutlineDrawable.java"
- },
- "325110414": {
- "message": "Transition animations finished, notifying core %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "375908576": {
- "message": "Clip description: handlingDrag=%b itemCount=%d mimeTypes=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragAndDropController.java"
- },
- "410592459": {
- "message": "Invalid root leash (%s): %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "473543554": {
- "message": "%s onTaskAppeared Supported",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/legacysplitscreen\/LegacySplitScreenTaskListener.java"
- },
- "481673835": {
- "message": "addListenerForTaskId taskId=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "564235578": {
- "message": "Fullscreen Task Vanished: #%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/FullscreenTaskListener.java"
- },
- "580605218": {
- "message": "Registering organizer",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "707170340": {
- "message": " animated by firstHandler",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "900599280": {
- "message": "Can't pair unresizeable tasks task1.isResizeable=%b task1.isResizeable=%b",
- "level": "ERROR",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPair.java"
- },
- "950299522": {
- "message": "taskId %d isn't isn't in an app-pair.",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPairsController.java"
- },
- "980952660": {
- "message": "Task root back pressed taskId=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "982027396": {
- "message": "%s onTaskAppeared Secondary taskId=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/legacysplitscreen\/LegacySplitScreenTaskListener.java"
- },
- "990371881": {
- "message": " Checking filter %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/RemoteTransitionHandler.java"
- },
- "1070270131": {
- "message": "onTransitionReady %s: %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TRANSITIONS",
- "at": "com\/android\/wm\/shell\/transition\/Transitions.java"
- },
- "1079041527": {
- "message": "incrementPool size=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPairsPool.java"
- },
- "1184615936": {
- "message": "Set drop target window visibility: displayId=%d visibility=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragAndDropController.java"
- },
- "1481772149": {
- "message": "Current target: %s",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragLayout.java"
- },
- "1862198614": {
- "message": "Drag event: action=%s x=%f y=%f xOffset=%f yOffset=%f",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragAndDropController.java"
- },
- "1891981945": {
- "message": "release entry.taskId=%s listener=%s size=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPairsPool.java"
- },
- "1990759023": {
- "message": "addListenerForType types=%s listener=%s",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
- },
- "2006473416": {
- "message": "acquire entry.taskId=%s listener=%s size=%d",
- "level": "VERBOSE",
- "group": "WM_SHELL_TASK_ORG",
- "at": "com\/android\/wm\/shell\/apppairs\/AppPairsPool.java"
- },
- "2057038970": {
- "message": "Display changed: %d",
- "level": "VERBOSE",
- "group": "WM_SHELL_DRAG_AND_DROP",
- "at": "com\/android\/wm\/shell\/draganddrop\/DragAndDropController.java"
- }
- },
- "groups": {
- "WM_SHELL_DRAG_AND_DROP": {
- "tag": "WindowManagerShell"
- },
- "WM_SHELL_TASK_ORG": {
- "tag": "WindowManagerShell"
- },
- "WM_SHELL_TRANSITIONS": {
- "tag": "WindowManagerShell"
- }
- }
-}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/FullscreenTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/FullscreenTaskListener.java
index 59fa9948bc2d..6984ea458ccf 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/FullscreenTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/FullscreenTaskListener.java
@@ -95,11 +95,6 @@ public class FullscreenTaskListener implements ShellTaskOrganizer.TaskListener {
}
@Override
- public boolean supportSizeCompatUI() {
- return true;
- }
-
- @Override
public void attachChildSurfaceToTask(int taskId, SurfaceControl.Builder b) {
if (!mLeashByTaskId.contains(taskId)) {
throw new IllegalArgumentException("There is no surface for taskId=" + taskId);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java
index 34a7157dbb3c..efc55c4fbe31 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java
@@ -84,7 +84,8 @@ public class ShellTaskOrganizer extends TaskOrganizer {
default void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {}
/** Whether this task listener supports size compat UI. */
default boolean supportSizeCompatUI() {
- return false;
+ // All TaskListeners should support size compat except PIP.
+ return true;
}
/** Attaches the a child window surface to the task surface. */
default void attachChildSurfaceToTask(int taskId, SurfaceControl.Builder b) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/TaskView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/TaskView.java
index bb8a97344664..5992447bd6da 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/TaskView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/TaskView.java
@@ -301,6 +301,14 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
}
@Override
+ public void attachChildSurfaceToTask(int taskId, SurfaceControl.Builder b) {
+ if (mTaskInfo.taskId != taskId) {
+ throw new IllegalArgumentException("There is no surface for taskId=" + taskId);
+ }
+ b.setParent(mTaskLeash);
+ }
+
+ @Override
public void dump(@androidx.annotation.NonNull PrintWriter pw, String prefix) {
final String innerPrefix = prefix + " ";
final String childPrefix = innerPrefix + " ";
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apppairs/AppPair.java b/libs/WindowManager/Shell/src/com/android/wm/shell/apppairs/AppPair.java
index bab5140e2f52..79f9dcd8a1fb 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apppairs/AppPair.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apppairs/AppPair.java
@@ -214,6 +214,19 @@ class AppPair implements ShellTaskOrganizer.TaskListener, SplitLayout.LayoutChan
}
@Override
+ public void attachChildSurfaceToTask(int taskId, SurfaceControl.Builder b) {
+ if (getRootTaskId() == taskId) {
+ b.setParent(mRootTaskLeash);
+ } else if (getTaskId1() == taskId) {
+ b.setParent(mTaskLeash1);
+ } else if (getTaskId2() == taskId) {
+ b.setParent(mTaskLeash2);
+ } else {
+ throw new IllegalArgumentException("There is no surface for taskId=" + taskId);
+ }
+ }
+
+ @Override
public void dump(@NonNull PrintWriter pw, String prefix) {
final String innerPrefix = prefix + " ";
final String childPrefix = innerPrefix + " ";
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java
index 5a493c234ce3..05526018d73f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java
@@ -323,6 +323,14 @@ class LegacySplitScreenTaskListener implements ShellTaskOrganizer.TaskListener {
}
@Override
+ public void attachChildSurfaceToTask(int taskId, SurfaceControl.Builder b) {
+ if (!mLeashByTaskId.contains(taskId)) {
+ throw new IllegalArgumentException("There is no surface for taskId=" + taskId);
+ }
+ b.setParent(mLeashByTaskId.get(taskId));
+ }
+
+ @Override
public void dump(@NonNull PrintWriter pw, String prefix) {
final String innerPrefix = prefix + " ";
final String childPrefix = innerPrefix + " ";
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java
index 3064af6f5170..71331dfcef44 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java
@@ -66,7 +66,6 @@ import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.annotations.ShellMainThread;
-import com.android.wm.shell.legacysplitscreen.LegacySplitScreen;
import com.android.wm.shell.legacysplitscreen.LegacySplitScreenController;
import com.android.wm.shell.pip.phone.PipMotionHelper;
import com.android.wm.shell.transition.Transitions;
@@ -585,6 +584,12 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
}
@Override
+ public boolean supportSizeCompatUI() {
+ // PIP doesn't support size compat.
+ return false;
+ }
+
+ @Override
public void onFixedRotationStarted(int displayId, int newRotation) {
mNextRotation = newRotation;
mWaitForFixedRotation = true;
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java
index ae5300502993..725f87d93e4e 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java
@@ -375,17 +375,29 @@ public class PhonePipMenuController implements PipMenuController {
}
/**
- * Hides the menu activity.
+ * Hides the menu view.
*/
public void hideMenu() {
+ hideMenu(true /* animate */, true /* resize */);
+ }
+
+ /**
+ * Hides the menu view.
+ *
+ * @param animate whether to animate the menu fadeout
+ * @param resize whether or not to resize the PiP with the state change
+ */
+ public void hideMenu(boolean animate, boolean resize) {
final boolean isMenuVisible = isMenuVisible();
if (DEBUG) {
Log.d(TAG, "hideMenu() state=" + mMenuState
+ " isMenuVisible=" + isMenuVisible
+ + " animate=" + animate
+ + " resize=" + resize
+ " callers=\n" + Debug.getCallers(5, " "));
}
if (isMenuVisible) {
- mPipMenuView.hideMenu();
+ mPipMenuView.hideMenu(animate, resize);
}
}
@@ -404,15 +416,6 @@ public class PhonePipMenuController implements PipMenuController {
}
/**
- * Preemptively mark the menu as invisible, used when we are directly manipulating the pinned
- * stack and don't want to trigger a resize which can animate the stack in a conflicting way
- * (ie. when manually expanding or dismissing).
- */
- public void hideMenuWithoutResize() {
- onMenuStateChanged(MENU_STATE_NONE, false /* resize */, null /* callback */);
- }
-
- /**
* Sets the menu actions to the actions provided by the current PiP menu.
*/
@Override
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java
index 962c4672644a..1cf3a48e9575 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java
@@ -89,7 +89,6 @@ public class PipMenuView extends FrameLayout {
private static final boolean ENABLE_RESIZE_HANDLE = false;
private int mMenuState;
- private boolean mResize = true;
private boolean mAllowMenuTimeout = true;
private boolean mAllowTouches = true;
@@ -329,16 +328,21 @@ public class PipMenuView extends FrameLayout {
hideMenu(null);
}
+ void hideMenu(boolean animate, boolean resize) {
+ hideMenu(null, true /* notifyMenuVisibility */, animate, resize);
+ }
+
void hideMenu(Runnable animationEndCallback) {
- hideMenu(animationEndCallback, true /* notifyMenuVisibility */, true /* animate */);
+ hideMenu(animationEndCallback, true /* notifyMenuVisibility */, true /* animate */,
+ true /* resize */);
}
private void hideMenu(final Runnable animationFinishedRunnable, boolean notifyMenuVisibility,
- boolean animate) {
+ boolean animate, boolean resize) {
if (mMenuState != MENU_STATE_NONE) {
cancelDelayedHide();
if (notifyMenuVisibility) {
- notifyMenuStateChange(MENU_STATE_NONE, mResize, null);
+ notifyMenuStateChange(MENU_STATE_NONE, resize, null);
}
mMenuContainerAnimator = new AnimatorSet();
ObjectAnimator menuAnim = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
@@ -469,7 +473,8 @@ public class PipMenuView extends FrameLayout {
private void expandPip() {
// Do not notify menu visibility when hiding the menu, the controller will do this when it
// handles the message
- hideMenu(mController::onPipExpand, false /* notifyMenuVisibility */, true /* animate */);
+ hideMenu(mController::onPipExpand, false /* notifyMenuVisibility */, true /* animate */,
+ true /* resize */);
}
private void dismissPip() {
@@ -479,7 +484,8 @@ public class PipMenuView extends FrameLayout {
final boolean animate = mMenuState != MENU_STATE_CLOSE;
// Do not notify menu visibility when hiding the menu, the controller will do this when it
// handles the message
- hideMenu(mController::onPipDismiss, false /* notifyMenuVisibility */, animate);
+ hideMenu(mController::onPipDismiss, false /* notifyMenuVisibility */, animate,
+ true /* resize */);
}
private void showSettings() {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java
index b19dcae2def8..eae8945ce6be 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java
@@ -17,8 +17,7 @@
package com.android.wm.shell.pip.phone;
import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_EXPAND_OR_UNEXPAND;
-import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT;
-import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT;
+import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -325,7 +324,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
+ " callers=\n" + Debug.getCallers(5, " "));
}
cancelPhysicsAnimation();
- mMenuController.hideMenuWithoutResize();
+ mMenuController.hideMenu(false /* animate */, false /* resize */);
mPipTaskOrganizer.exitPip(skipAnimation ? 0 : LEAVE_PIP_DURATION);
}
@@ -338,7 +337,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
Log.d(TAG, "removePip: callers=\n" + Debug.getCallers(5, " "));
}
cancelPhysicsAnimation();
- mMenuController.hideMenuWithoutResize();
+ mMenuController.hideMenu(true /* animate*/, false /* resize */);
mPipTaskOrganizer.removePip();
}
@@ -371,9 +370,9 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
/**
* Stash PiP to the closest edge. We set velocityY to 0 to limit pure horizontal motion.
*/
- void stashToEdge(float velocityX, @Nullable Runnable postBoundsUpdateCallback) {
- mPipBoundsState.setStashed(velocityX < 0 ? STASH_TYPE_LEFT : STASH_TYPE_RIGHT);
- movetoTarget(velocityX, 0 /* velocityY */, postBoundsUpdateCallback, true /* isStash */);
+ void stashToEdge(float velX, float velY, @Nullable Runnable postBoundsUpdateCallback) {
+ velY = mPipBoundsState.getStashedState() == STASH_TYPE_NONE ? 0 : velY;
+ movetoTarget(velX, velY, postBoundsUpdateCallback, true /* isStash */);
}
private void movetoTarget(
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java
index 1ef9ffa494f4..78ee1868eee7 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java
@@ -106,7 +106,7 @@ public class PipResizeGestureHandler {
// For pinch-resize
private boolean mThresholdCrossed0;
private boolean mThresholdCrossed1;
- private boolean mUsingPinchToZoom = false;
+ private boolean mUsingPinchToZoom = true;
private float mAngle = 0;
int mFirstIndex = -1;
int mSecondIndex = -1;
@@ -139,7 +139,7 @@ public class PipResizeGestureHandler {
mEnablePinchResize = DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_SYSTEMUI,
PIP_PINCH_RESIZE,
- /* defaultValue = */ false);
+ /* defaultValue = */ true);
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
mMainExecutor,
new DeviceConfig.OnPropertiesChangedListener() {
@@ -147,7 +147,7 @@ public class PipResizeGestureHandler {
public void onPropertiesChanged(DeviceConfig.Properties properties) {
if (properties.getKeyset().contains(PIP_PINCH_RESIZE)) {
mEnablePinchResize = properties.getBoolean(
- PIP_PINCH_RESIZE, /* defaultValue = */ false);
+ PIP_PINCH_RESIZE, /* defaultValue = */ true);
}
}
});
@@ -516,8 +516,8 @@ public class PipResizeGestureHandler {
}
if (mThresholdCrossed) {
if (mPhonePipMenuController.isMenuVisible()) {
- mPhonePipMenuController.hideMenuWithoutResize();
- mPhonePipMenuController.hideMenu();
+ mPhonePipMenuController.hideMenu(false /* animate */,
+ false /* resize */);
}
final Rect currentPipBounds = mPipBoundsState.getBounds();
mLastResizeBounds.set(TaskResizingAlgorithm.resizeDrag(x, y,
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java
index e69c6f2f47bc..afc7b5294a2f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java
@@ -19,7 +19,9 @@ package com.android.wm.shell.pip.phone;
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.PIP_STASHING;
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.PIP_STASH_MINIMUM_VELOCITY_THRESHOLD;
import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_TO_PIP;
+import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT;
import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE;
+import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT;
import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_CLOSE;
import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_FULL;
import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_NONE;
@@ -63,8 +65,9 @@ import java.util.function.Consumer;
* the PIP.
*/
public class PipTouchHandler {
+ @VisibleForTesting static final float MINIMUM_SIZE_PERCENT = 0.4f;
+
private static final String TAG = "PipTouchHandler";
- private static final float MINIMUM_SIZE_PERCENT = 0.4f;
private static final float DEFAULT_STASH_VELOCITY_THRESHOLD = 18000.f;
// Allow PIP to resize to a slightly bigger state upon touch
@@ -809,7 +812,6 @@ public class PipTouchHandler {
}
if (touchState.startedDragging()) {
- mPipBoundsState.setStashed(STASH_TYPE_NONE);
mSavedSnapFraction = -1f;
mPipDismissTargetHandler.showDismissTargetMaybe();
}
@@ -862,10 +864,10 @@ public class PipTouchHandler {
// Reset the touch state on up before the fling settles
mTouchState.reset();
- if (mEnableStash && !mPipBoundsState.isStashed()
- && shouldStash(vel, getPossiblyMotionBounds())) {
- mMotionHelper.stashToEdge(vel.x, this::stashEndAction /* endAction */);
+ if (mEnableStash && shouldStash(vel, getPossiblyMotionBounds())) {
+ mMotionHelper.stashToEdge(vel.x, vel.y, this::stashEndAction /* endAction */);
} else {
+ mPipBoundsState.setStashed(STASH_TYPE_NONE);
mMotionHelper.flingToSnapTarget(vel.x, vel.y,
this::flingEndAction /* endAction */);
}
@@ -876,6 +878,9 @@ public class PipTouchHandler {
< mPipBoundsState.getMaxSize().x
&& mPipBoundsState.getBounds().height()
< mPipBoundsState.getMaxSize().y;
+ if (mMenuController.isMenuVisible()) {
+ mMenuController.hideMenu(false /* animate */, false /* resize */);
+ }
if (toExpand) {
mPipResizeGestureHandler.setUserResizeBounds(mPipBoundsState.getBounds());
animateToMaximizedState(null);
@@ -916,6 +921,11 @@ public class PipTouchHandler {
&& mPipExclusionBoundsChangeListener.get() != null) {
mPipExclusionBoundsChangeListener.get().accept(mPipBoundsState.getBounds());
}
+ if (mPipBoundsState.getBounds().left < 0) {
+ mPipBoundsState.setStashed(STASH_TYPE_LEFT);
+ } else {
+ mPipBoundsState.setStashed(STASH_TYPE_RIGHT);
+ }
}
private void flingEndAction() {
@@ -933,12 +943,12 @@ public class PipTouchHandler {
private boolean shouldStash(PointF vel, Rect motionBounds) {
// If user flings the PIP window above the minimum velocity, stash PIP.
- // Only allow stashing to the edge if the user starts dragging the PIP from the
- // opposite edge.
+ // Only allow stashing to the edge if PIP wasn't previously stashed on the opposite
+ // edge.
final boolean stashFromFlingToEdge = ((vel.x < -mStashVelocityThreshold
- && mDownSavedFraction > 1f && mDownSavedFraction < 2f)
+ && mPipBoundsState.getStashedState() != STASH_TYPE_RIGHT)
|| (vel.x > mStashVelocityThreshold
- && mDownSavedFraction > 3f && mDownSavedFraction < 4f));
+ && mPipBoundsState.getStashedState() != STASH_TYPE_LEFT));
// If User releases the PIP window while it's out of the display bounds, put
// PIP into stashed mode.
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java
index 4f4e7dafe5c0..2b0a0cd3de20 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java
@@ -26,9 +26,9 @@ import com.android.internal.protolog.common.IProtoLogGroup;
public enum ShellProtoLogGroup implements IProtoLogGroup {
// NOTE: Since we enable these from the same WM ShellCommand, these names should not conflict
// with those in the framework ProtoLogGroup
- WM_SHELL_TASK_ORG(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
+ WM_SHELL_TASK_ORG(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
Consts.TAG_WM_SHELL),
- WM_SHELL_TRANSITIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
+ WM_SHELL_TRANSITIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
Consts.TAG_WM_SHELL),
WM_SHELL_DRAG_AND_DROP(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
Consts.TAG_WM_SHELL),
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java
index 66ecf453c362..552ebde05274 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java
@@ -28,6 +28,7 @@ import com.android.wm.shell.R;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
import org.json.JSONException;
@@ -109,10 +110,10 @@ public class ShellProtoLogImpl extends BaseProtoLogImpl {
return sServiceInstance;
}
- public int startTextLogging(Context context, String[] groups, PrintWriter pw) {
- try {
- mViewerConfig.loadViewerConfig(
- context.getResources().openRawResource(R.raw.wm_shell_protolog));
+ public int startTextLogging(String[] groups, PrintWriter pw) {
+ try (InputStream is =
+ getClass().getClassLoader().getResourceAsStream("wm_shell_protolog.json")){
+ mViewerConfig.loadViewerConfig(is);
return setLogging(true /* setTextLogging */, true, pw, groups);
} catch (IOException e) {
Log.i(TAG, "Unable to load log definitions: IOException while reading "
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java
index 653299326cd0..10c742b69578 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java
@@ -130,6 +130,17 @@ class StageTaskListener implements ShellTaskOrganizer.TaskListener {
}
}
+ @Override
+ public void attachChildSurfaceToTask(int taskId, SurfaceControl.Builder b) {
+ if (mRootTaskInfo.taskId == taskId) {
+ b.setParent(mRootLeash);
+ } else if (mChildrenLeashes.contains(taskId)) {
+ b.setParent(mChildrenLeashes.get(taskId));
+ } else {
+ throw new IllegalArgumentException("There is no surface for taskId=" + taskId);
+ }
+ }
+
void setBounds(Rect bounds, WindowContainerTransaction wct) {
wct.setBounds(mRootTaskInfo.token, bounds);
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java
index 733e4845dd62..a0e9f43218f2 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java
@@ -106,11 +106,6 @@ public class ShellTaskOrganizerTests {
public void onTaskVanished(RunningTaskInfo taskInfo) {
vanished.add(taskInfo);
}
-
- @Override
- public boolean supportSizeCompatUI() {
- return true;
- }
}
@Before
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java
index 449ad88f6532..19930485047c 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java
@@ -22,16 +22,14 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import android.graphics.Point;
import android.graphics.Rect;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
-import android.util.Size;
import androidx.test.filters.SmallTest;
-import com.android.wm.shell.R;
import com.android.wm.shell.ShellTestCase;
+import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.pip.PipBoundsAlgorithm;
@@ -59,6 +57,9 @@ import org.mockito.MockitoAnnotations;
@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class PipTouchHandlerTest extends ShellTestCase {
+ private static final int INSET = 10;
+ private static final int PIP_LENGTH = 100;
+
private PipTouchHandler mPipTouchHandler;
@Mock
@@ -85,8 +86,9 @@ public class PipTouchHandlerTest extends ShellTestCase {
private PipMotionHelper mMotionHelper;
private PipResizeGestureHandler mPipResizeGestureHandler;
+ private DisplayLayout mDisplayLayout;
private Rect mInsetBounds;
- private Rect mMinBounds;
+ private Rect mPipBounds;
private Rect mCurBounds;
private boolean mFromImeAdjustment;
private boolean mFromShelfAdjustment;
@@ -109,12 +111,18 @@ public class PipTouchHandlerTest extends ShellTestCase {
mPipTouchHandler.setPipMotionHelper(mMotionHelper);
mPipTouchHandler.setPipResizeGestureHandler(mPipResizeGestureHandler);
- // Assume a display of 1000 x 1000
- // inset of 10
- mInsetBounds = new Rect(10, 10, 990, 990);
+ mDisplayLayout = new DisplayLayout(mContext, mContext.getDisplay());
+ mPipBoundsState.setDisplayLayout(mDisplayLayout);
+ mInsetBounds = new Rect(mPipBoundsState.getDisplayBounds().left + INSET,
+ mPipBoundsState.getDisplayBounds().top + INSET,
+ mPipBoundsState.getDisplayBounds().right - INSET,
+ mPipBoundsState.getDisplayBounds().bottom - INSET);
// minBounds of 100x100 bottom right corner
- mMinBounds = new Rect(890, 890, 990, 990);
- mCurBounds = new Rect(mMinBounds);
+ mPipBounds = new Rect(mPipBoundsState.getDisplayBounds().right - INSET - PIP_LENGTH,
+ mPipBoundsState.getDisplayBounds().bottom - INSET - PIP_LENGTH,
+ mPipBoundsState.getDisplayBounds().right - INSET,
+ mPipBoundsState.getDisplayBounds().bottom - INSET);
+ mCurBounds = new Rect(mPipBounds);
mFromImeAdjustment = false;
mFromShelfAdjustment = false;
mDisplayRotation = 0;
@@ -122,37 +130,23 @@ public class PipTouchHandlerTest extends ShellTestCase {
}
@Test
- public void updateMovementBounds_minBounds() {
- Rect expectedMinMovementBounds = new Rect();
- mPipBoundsAlgorithm.getMovementBounds(mMinBounds, mInsetBounds, expectedMinMovementBounds,
+ public void updateMovementBounds_minMaxBounds() {
+ final int shorterLength = Math.min(mPipBoundsState.getDisplayBounds().width(),
+ mPipBoundsState.getDisplayBounds().height());
+ Rect expectedMovementBounds = new Rect();
+ mPipBoundsAlgorithm.getMovementBounds(mPipBounds, mInsetBounds, expectedMovementBounds,
0);
- mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
+ mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mPipBounds, mCurBounds,
mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);
- assertEquals(expectedMinMovementBounds, mPipBoundsState.getNormalMovementBounds());
+ assertEquals(expectedMovementBounds, mPipBoundsState.getNormalMovementBounds());
verify(mPipResizeGestureHandler, times(1))
- .updateMinSize(mMinBounds.width(), mMinBounds.height());
- }
-
- @Test
- public void updateMovementBounds_maxBounds() {
- Point displaySize = new Point();
- mContext.getDisplay().getRealSize(displaySize);
- Size maxSize = mPipBoundsAlgorithm.getSizeForAspectRatio(1,
- mContext.getResources().getDimensionPixelSize(
- R.dimen.pip_expanded_shortest_edge_size), displaySize.x, displaySize.y);
- Rect maxBounds = new Rect(0, 0, maxSize.getWidth(), maxSize.getHeight());
- Rect expectedMaxMovementBounds = new Rect();
- mPipBoundsAlgorithm.getMovementBounds(maxBounds, mInsetBounds, expectedMaxMovementBounds,
- 0);
-
- mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
- mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);
+ .updateMinSize(mPipBounds.width(), mPipBounds.height());
- assertEquals(expectedMaxMovementBounds, mPipBoundsState.getExpandedMovementBounds());
verify(mPipResizeGestureHandler, times(1))
- .updateMaxSize(maxBounds.width(), maxBounds.height());
+ .updateMaxSize(shorterLength - 2 * mInsetBounds.left,
+ shorterLength - 2 * mInsetBounds.left);
}
@Test
@@ -160,7 +154,7 @@ public class PipTouchHandlerTest extends ShellTestCase {
mFromImeAdjustment = true;
mPipTouchHandler.onImeVisibilityChanged(true /* imeVisible */, mImeHeight);
- mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
+ mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mPipBounds, mCurBounds,
mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);
verify(mMotionHelper, times(1)).animateToOffset(any(), anyInt());
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index f48122858267..678b0ad3924d 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -357,12 +357,13 @@ cc_defaults {
"libharfbuzz_ng",
"liblog",
"libminikin",
- "libnativehelper",
"libz",
"libziparchive",
"libjpeg",
],
+ static_libs: ["libnativehelper_lazy"],
+
target: {
android: {
srcs: [ // sources that depend on android only libraries
@@ -444,6 +445,7 @@ cc_defaults {
"renderthread/TimeLord.cpp",
"hwui/AnimatedImageDrawable.cpp",
"hwui/Bitmap.cpp",
+ "hwui/BlurDrawLooper.cpp",
"hwui/Canvas.cpp",
"hwui/ImageDecoder.cpp",
"hwui/MinikinSkia.cpp",
@@ -480,6 +482,8 @@ cc_defaults {
target: {
android: {
+ header_libs: ["libandroid_headers_private" ],
+
srcs: [
"hwui/AnimatedImageThread.cpp",
"pipeline/skia/ATraceMemoryDump.cpp",
@@ -567,6 +571,7 @@ cc_defaults {
name: "hwui_test_defaults",
defaults: ["hwui_defaults"],
test_suites: ["device-tests"],
+ header_libs: ["libandroid_headers_private"],
target: {
android: {
shared_libs: [
@@ -604,7 +609,6 @@ cc_test {
shared_libs: [
"libmemunreachable",
],
-
srcs: [
"tests/unit/main.cpp",
"tests/unit/ABitmapTests.cpp",
diff --git a/libs/hwui/Animator.cpp b/libs/hwui/Animator.cpp
index 74cf1fda1b75..20a8a8c71a0f 100644
--- a/libs/hwui/Animator.cpp
+++ b/libs/hwui/Animator.cpp
@@ -160,10 +160,6 @@ void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) {
}
}
- if (!mHasStartValue) {
- doSetStartValue(getValue(mTarget));
- }
-
if (!mStagingRequests.empty()) {
// No interpolator was set, use the default
if (mPlayState == PlayState::NotStarted && !mInterpolator) {
@@ -270,9 +266,11 @@ bool BaseRenderNodeAnimator::updatePlayTime(nsecs_t playTime) {
// to call setValue even if the animation isn't yet running or is still
// being delayed as we need to override the staging value
if (playTime < 0) {
- setValue(mTarget, mFromValue);
return false;
}
+ if (!this->mHasStartValue) {
+ doSetStartValue(getValue(mTarget));
+ }
float fraction = 1.0f;
if ((mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) && mDuration > 0) {
diff --git a/libs/hwui/FrameInfo.cpp b/libs/hwui/FrameInfo.cpp
index 8b20492543f7..ce9b2889cd9e 100644
--- a/libs/hwui/FrameInfo.cpp
+++ b/libs/hwui/FrameInfo.cpp
@@ -42,7 +42,7 @@ const std::array<std::string, static_cast<int>(FrameInfoIndex::NumIndexes)> Fram
"GpuCompleted",
};
-static_assert(static_cast<int>(FrameInfoIndex::NumIndexes) == 19,
+static_assert(static_cast<int>(FrameInfoIndex::NumIndexes) == 20,
"Must update value in FrameMetrics.java#FRAME_STATS_COUNT (and here)");
void FrameInfo::importUiThreadInfo(int64_t* info) {
diff --git a/libs/hwui/FrameInfo.h b/libs/hwui/FrameInfo.h
index ee7d15a2fbce..45a367f525da 100644
--- a/libs/hwui/FrameInfo.h
+++ b/libs/hwui/FrameInfo.h
@@ -55,6 +55,7 @@ enum class FrameInfoIndex {
QueueBufferDuration,
GpuCompleted,
+ SwapBuffersCompleted,
// Must be the last value!
// Also must be kept in sync with FrameMetrics.java#FRAME_STATS_COUNT
@@ -120,6 +121,10 @@ public:
void markSwapBuffers() { set(FrameInfoIndex::SwapBuffers) = systemTime(SYSTEM_TIME_MONOTONIC); }
+ void markSwapBuffersCompleted() {
+ set(FrameInfoIndex::SwapBuffersCompleted) = systemTime(SYSTEM_TIME_MONOTONIC);
+ }
+
void markFrameCompleted() { set(FrameInfoIndex::FrameCompleted) = systemTime(SYSTEM_TIME_MONOTONIC); }
void addFlag(int frameInfoFlag) {
diff --git a/libs/hwui/FrameMetricsReporter.h b/libs/hwui/FrameMetricsReporter.h
index 75b8038c5040..0643e790d00b 100644
--- a/libs/hwui/FrameMetricsReporter.h
+++ b/libs/hwui/FrameMetricsReporter.h
@@ -16,14 +16,16 @@
#pragma once
+#include <utils/Mutex.h>
#include <utils/Log.h>
#include <utils/RefBase.h>
+#include <ui/FatVector.h>
+
#include "FrameInfo.h"
#include "FrameMetricsObserver.h"
#include <string.h>
-#include <vector>
namespace android {
namespace uirenderer {
@@ -32,9 +34,13 @@ class FrameMetricsReporter {
public:
FrameMetricsReporter() {}
- void addObserver(FrameMetricsObserver* observer) { mObservers.push_back(observer); }
+ void addObserver(FrameMetricsObserver* observer) {
+ std::lock_guard lock(mObserversLock);
+ mObservers.push_back(observer);
+ }
bool removeObserver(FrameMetricsObserver* observer) {
+ std::lock_guard lock(mObserversLock);
for (size_t i = 0; i < mObservers.size(); i++) {
if (mObservers[i].get() == observer) {
mObservers.erase(mObservers.begin() + i);
@@ -44,16 +50,28 @@ public:
return false;
}
- bool hasObservers() { return mObservers.size() > 0; }
+ bool hasObservers() {
+ std::lock_guard lock(mObserversLock);
+ return mObservers.size() > 0;
+ }
void reportFrameMetrics(const int64_t* stats) {
- for (size_t i = 0; i < mObservers.size(); i++) {
- mObservers[i]->notify(stats);
+ FatVector<sp<FrameMetricsObserver>, 10> copy;
+ {
+ std::lock_guard lock(mObserversLock);
+ copy.reserve(mObservers.size());
+ for (size_t i = 0; i < mObservers.size(); i++) {
+ copy.push_back(mObservers[i]);
+ }
+ }
+ for (size_t i = 0; i < copy.size(); i++) {
+ copy[i]->notify(stats);
}
}
private:
- std::vector<sp<FrameMetricsObserver> > mObservers;
+ FatVector<sp<FrameMetricsObserver>, 10> mObservers GUARDED_BY(mObserversLock);
+ std::mutex mObserversLock;
};
} // namespace uirenderer
diff --git a/libs/hwui/JankTracker.cpp b/libs/hwui/JankTracker.cpp
index ccce403ecfac..4a2e30dd38f2 100644
--- a/libs/hwui/JankTracker.cpp
+++ b/libs/hwui/JankTracker.cpp
@@ -79,7 +79,9 @@ static const int64_t EXEMPT_FRAMES_FLAGS = FrameInfoFlags::SurfaceCanvas;
// and filter it out of the frame profile data
static FrameInfoIndex sFrameStart = FrameInfoIndex::IntendedVsync;
-JankTracker::JankTracker(ProfileDataContainer* globalData) {
+JankTracker::JankTracker(ProfileDataContainer* globalData)
+ : mData(globalData->getDataMutex())
+ , mDataMutex(globalData->getDataMutex()) {
mGlobalData = globalData;
nsecs_t frameIntervalNanos = DeviceInfo::getVsyncPeriod();
nsecs_t sfOffset = DeviceInfo::getCompositorOffset();
@@ -107,6 +109,8 @@ void JankTracker::setFrameInterval(nsecs_t frameInterval) {
}
void JankTracker::finishFrame(const FrameInfo& frame) {
+ std::lock_guard lock(mDataMutex);
+
// Fast-path for jank-free frames
int64_t totalDuration = frame.duration(sFrameStart, FrameInfoIndex::FrameCompleted);
if (mDequeueTimeForgiveness && frame[FrameInfoIndex::DequeueBufferDuration] > 500_us) {
@@ -125,7 +129,11 @@ void JankTracker::finishFrame(const FrameInfo& frame) {
}
}
- LOG_ALWAYS_FATAL_IF(totalDuration <= 0, "Impossible totalDuration %" PRId64, totalDuration);
+ LOG_ALWAYS_FATAL_IF(totalDuration <= 0, "Impossible totalDuration %" PRId64 " start=%" PRIi64
+ " gpuComplete=%" PRIi64, totalDuration,
+ frame[FrameInfoIndex::IntendedVsync],
+ frame[FrameInfoIndex::GpuCompleted]);
+
mData->reportFrame(totalDuration);
(*mGlobalData)->reportFrame(totalDuration);
@@ -188,6 +196,7 @@ void JankTracker::finishFrame(const FrameInfo& frame) {
void JankTracker::dumpData(int fd, const ProfileDataDescription* description,
const ProfileData* data) {
+
if (description) {
switch (description->type) {
case JankTrackerType::Generic:
@@ -227,6 +236,7 @@ void JankTracker::dumpFrames(int fd) {
}
void JankTracker::reset() {
+ std::lock_guard lock(mDataMutex);
mFrames.clear();
mData->reset();
(*mGlobalData)->reset();
@@ -235,6 +245,7 @@ void JankTracker::reset() {
}
void JankTracker::finishGpuDraw(const FrameInfo& frame) {
+ std::lock_guard lock(mDataMutex);
int64_t totalGPUDrawTime = frame.gpuDrawTime();
if (totalGPUDrawTime >= 0) {
mData->reportGPUFrame(totalGPUDrawTime);
diff --git a/libs/hwui/JankTracker.h b/libs/hwui/JankTracker.h
index b3fbbfe98669..096455372923 100644
--- a/libs/hwui/JankTracker.h
+++ b/libs/hwui/JankTracker.h
@@ -84,12 +84,15 @@ private:
// This is only used if we are in pipelined mode and are using HWC2,
// otherwise it's 0.
nsecs_t mDequeueTimeForgiveness = 0;
- ProfileDataContainer mData;
- ProfileDataContainer* mGlobalData;
+ ProfileDataContainer mData GUARDED_BY(mDataMutex);
+ ProfileDataContainer* mGlobalData GUARDED_BY(mDataMutex);
ProfileDataDescription mDescription;
// Ring buffer large enough for 2 seconds worth of frames
RingBuffer<FrameInfo, 120> mFrames;
+
+ // Mutex to protect acccess to mData and mGlobalData obtained from mGlobalData->getDataMutex
+ std::mutex& mDataMutex;
};
} /* namespace uirenderer */
diff --git a/libs/hwui/ProfileDataContainer.cpp b/libs/hwui/ProfileDataContainer.cpp
index 38e0f0aa8d83..41afc0e04c8b 100644
--- a/libs/hwui/ProfileDataContainer.cpp
+++ b/libs/hwui/ProfileDataContainer.cpp
@@ -38,6 +38,8 @@ void ProfileDataContainer::freeData() {
}
void ProfileDataContainer::rotateStorage() {
+ std::lock_guard lock(mJankDataMutex);
+
// If we are mapped we want to stop using the ashmem backend and switch to malloc
// We are expecting a switchStorageToAshmem call to follow this, but it's not guaranteed
// If we aren't sitting on top of ashmem then just do a reset() as it's functionally
@@ -50,6 +52,7 @@ void ProfileDataContainer::rotateStorage() {
}
void ProfileDataContainer::switchStorageToAshmem(int ashmemfd) {
+ std::lock_guard lock(mJankDataMutex);
int regionSize = ashmem_get_size_region(ashmemfd);
if (regionSize < 0) {
int err = errno;
@@ -70,7 +73,9 @@ void ProfileDataContainer::switchStorageToAshmem(int ashmemfd) {
return;
}
- newData->mergeWith(*mData);
+ if (mData != nullptr) {
+ newData->mergeWith(*mData);
+ }
freeData();
mData = newData;
mIsMapped = true;
diff --git a/libs/hwui/ProfileDataContainer.h b/libs/hwui/ProfileDataContainer.h
index a39869491ede..a61b8dcf390e 100644
--- a/libs/hwui/ProfileDataContainer.h
+++ b/libs/hwui/ProfileDataContainer.h
@@ -19,6 +19,9 @@
#include "ProfileData.h"
#include "utils/Macros.h"
+#include <mutex>
+#include <utils/Mutex.h>
+
namespace android {
namespace uirenderer {
@@ -26,7 +29,8 @@ class ProfileDataContainer {
PREVENT_COPY_AND_ASSIGN(ProfileDataContainer);
public:
- explicit ProfileDataContainer() {}
+ explicit ProfileDataContainer(std::mutex& jankDataMutex)
+ : mData(new ProfileData()), mJankDataMutex(jankDataMutex) {}
~ProfileDataContainer() { freeData(); }
@@ -36,13 +40,16 @@ public:
ProfileData* get() { return mData; }
ProfileData* operator->() { return mData; }
+ std::mutex& getDataMutex() { return mJankDataMutex; }
+
private:
void freeData();
// By default this will use malloc memory. It may be moved later to ashmem
// if there is shared space for it and a request comes in to do that.
- ProfileData* mData = new ProfileData;
+ ProfileData* mData GUARDED_BY(mJankDataMutex);
bool mIsMapped = false;
+ std::mutex& mJankDataMutex;
};
} /* namespace uirenderer */
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index 8fddf713f1fa..1fddac4cd05d 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -463,9 +463,7 @@ void SkiaCanvas::drawPoints(const float* points, int count, const Paint& paint,
}
void SkiaCanvas::drawPoint(float x, float y, const Paint& paint) {
- apply_looper(&paint, [&](const SkPaint& p) {
- mCanvas->drawPoint(x, y, p);
- });
+ apply_looper(&paint, [&](const SkPaint& p) { mCanvas->drawPoint(x, y, p); });
}
void SkiaCanvas::drawPoints(const float* points, int count, const Paint& paint) {
@@ -493,9 +491,7 @@ void SkiaCanvas::drawRect(float left, float top, float right, float bottom, cons
void SkiaCanvas::drawRegion(const SkRegion& region, const Paint& paint) {
if (CC_UNLIKELY(paint.nothingToDraw())) return;
- apply_looper(&paint, [&](const SkPaint& p) {
- mCanvas->drawRegion(region, p);
- });
+ apply_looper(&paint, [&](const SkPaint& p) { mCanvas->drawRegion(region, p); });
}
void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
@@ -509,24 +505,18 @@ void SkiaCanvas::drawRoundRect(float left, float top, float right, float bottom,
void SkiaCanvas::drawDoubleRoundRect(const SkRRect& outer, const SkRRect& inner,
const Paint& paint) {
- apply_looper(&paint, [&](const SkPaint& p) {
- mCanvas->drawDRRect(outer, inner, p);
- });
+ apply_looper(&paint, [&](const SkPaint& p) { mCanvas->drawDRRect(outer, inner, p); });
}
void SkiaCanvas::drawCircle(float x, float y, float radius, const Paint& paint) {
if (CC_UNLIKELY(radius <= 0 || paint.nothingToDraw())) return;
- apply_looper(&paint, [&](const SkPaint& p) {
- mCanvas->drawCircle(x, y, radius, p);
- });
+ apply_looper(&paint, [&](const SkPaint& p) { mCanvas->drawCircle(x, y, radius, p); });
}
void SkiaCanvas::drawOval(float left, float top, float right, float bottom, const Paint& paint) {
if (CC_UNLIKELY(paint.nothingToDraw())) return;
SkRect oval = SkRect::MakeLTRB(left, top, right, bottom);
- apply_looper(&paint, [&](const SkPaint& p) {
- mCanvas->drawOval(oval, p);
- });
+ apply_looper(&paint, [&](const SkPaint& p) { mCanvas->drawOval(oval, p); });
}
void SkiaCanvas::drawArc(float left, float top, float right, float bottom, float startAngle,
@@ -547,9 +537,7 @@ void SkiaCanvas::drawPath(const SkPath& path, const Paint& paint) {
if (CC_UNLIKELY(path.isEmpty() && (!path.isInverseFillType()))) {
return;
}
- apply_looper(&paint, [&](const SkPaint& p) {
- mCanvas->drawPath(path, p);
- });
+ apply_looper(&paint, [&](const SkPaint& p) { mCanvas->drawPath(path, p); });
}
void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const Paint& paint) {
diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h
index 155f6df7b703..eac3f2217bd8 100644
--- a/libs/hwui/SkiaCanvas.h
+++ b/libs/hwui/SkiaCanvas.h
@@ -208,29 +208,21 @@ protected:
*/
PaintCoW&& filterPaint(PaintCoW&& paint) const;
+ // proc(const SkPaint& modifiedPaint)
template <typename Proc> void apply_looper(const Paint* paint, Proc proc) {
SkPaint skp;
- SkDrawLooper* looper = nullptr;
+ BlurDrawLooper* looper = nullptr;
if (paint) {
skp = *filterPaint(paint);
looper = paint->getLooper();
}
if (looper) {
- SkSTArenaAlloc<256> alloc;
- SkDrawLooper::Context* ctx = looper->makeContext(&alloc);
- if (ctx) {
- SkDrawLooper::Context::Info info;
- for (;;) {
- SkPaint p = skp;
- if (!ctx->next(&info, &p)) {
- break;
- }
- mCanvas->save();
- mCanvas->translate(info.fTranslate.fX, info.fTranslate.fY);
- proc(p);
- mCanvas->restore();
- }
- }
+ looper->apply(skp, [&](SkPoint offset, const SkPaint& modifiedPaint) {
+ mCanvas->save();
+ mCanvas->translate(offset.fX, offset.fY);
+ proc(modifiedPaint);
+ mCanvas->restore();
+ });
} else {
proc(skp);
}
diff --git a/libs/hwui/hwui/BlurDrawLooper.cpp b/libs/hwui/hwui/BlurDrawLooper.cpp
new file mode 100644
index 000000000000..27a038d4598e
--- /dev/null
+++ b/libs/hwui/hwui/BlurDrawLooper.cpp
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+#include "BlurDrawLooper.h"
+#include <SkMaskFilter.h>
+
+namespace android {
+
+BlurDrawLooper::BlurDrawLooper(SkColor4f color, float blurSigma, SkPoint offset)
+ : mColor(color), mBlurSigma(blurSigma), mOffset(offset) {}
+
+BlurDrawLooper::~BlurDrawLooper() = default;
+
+SkPoint BlurDrawLooper::apply(SkPaint* paint) const {
+ paint->setColor(mColor);
+ if (mBlurSigma > 0) {
+ paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, mBlurSigma, true));
+ }
+ return mOffset;
+}
+
+sk_sp<BlurDrawLooper> BlurDrawLooper::Make(SkColor4f color, SkColorSpace* cs, float blurSigma,
+ SkPoint offset) {
+ if (cs) {
+ SkPaint tmp;
+ tmp.setColor(color, cs); // converts color to sRGB
+ color = tmp.getColor4f();
+ }
+ return sk_sp<BlurDrawLooper>(new BlurDrawLooper(color, blurSigma, offset));
+}
+
+} // namespace android
diff --git a/libs/hwui/hwui/BlurDrawLooper.h b/libs/hwui/hwui/BlurDrawLooper.h
new file mode 100644
index 000000000000..7e6786f7dfbc
--- /dev/null
+++ b/libs/hwui/hwui/BlurDrawLooper.h
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+#ifndef ANDROID_GRAPHICS_BLURDRAWLOOPER_H_
+#define ANDROID_GRAPHICS_BLURDRAWLOOPER_H_
+
+#include <SkPaint.h>
+#include <SkRefCnt.h>
+
+class SkColorSpace;
+
+namespace android {
+
+class BlurDrawLooper : public SkRefCnt {
+public:
+ static sk_sp<BlurDrawLooper> Make(SkColor4f, SkColorSpace*, float blurSigma, SkPoint offset);
+
+ ~BlurDrawLooper() override;
+
+ // proc(SkPoint offset, const SkPaint& modifiedPaint)
+ template <typename DrawProc>
+ void apply(const SkPaint& paint, DrawProc proc) const {
+ SkPaint p(paint);
+ proc(this->apply(&p), p); // draw the shadow
+ proc({0, 0}, paint); // draw the original (on top)
+ }
+
+private:
+ const SkColor4f mColor;
+ const float mBlurSigma;
+ const SkPoint mOffset;
+
+ SkPoint apply(SkPaint* paint) const;
+
+ BlurDrawLooper(SkColor4f, float, SkPoint);
+};
+
+} // namespace android
+
+#endif // ANDROID_GRAPHICS_BLURDRAWLOOPER_H_
diff --git a/libs/hwui/hwui/Paint.h b/libs/hwui/hwui/Paint.h
index 05bae5c9f778..d9c9eeed03e9 100644
--- a/libs/hwui/hwui/Paint.h
+++ b/libs/hwui/hwui/Paint.h
@@ -17,11 +17,11 @@
#ifndef ANDROID_GRAPHICS_PAINT_H_
#define ANDROID_GRAPHICS_PAINT_H_
+#include "BlurDrawLooper.h"
#include "Typeface.h"
#include <cutils/compiler.h>
-#include <SkDrawLooper.h>
#include <SkFont.h>
#include <SkPaint.h>
#include <string>
@@ -59,8 +59,8 @@ public:
SkFont& getSkFont() { return mFont; }
const SkFont& getSkFont() const { return mFont; }
- SkDrawLooper* getLooper() const { return mLooper.get(); }
- void setLooper(sk_sp<SkDrawLooper> looper) { mLooper = std::move(looper); }
+ BlurDrawLooper* getLooper() const { return mLooper.get(); }
+ void setLooper(sk_sp<BlurDrawLooper> looper) { mLooper = std::move(looper); }
// These shadow the methods on SkPaint, but we need to so we can keep related
// attributes in-sync.
@@ -155,7 +155,7 @@ public:
private:
SkFont mFont;
- sk_sp<SkDrawLooper> mLooper;
+ sk_sp<BlurDrawLooper> mLooper;
float mLetterSpacing = 0;
float mWordSpacing = 0;
diff --git a/libs/hwui/jni/Paint.cpp b/libs/hwui/jni/Paint.cpp
index 3c86b28262b0..bcec0fa8a1cc 100644
--- a/libs/hwui/jni/Paint.cpp
+++ b/libs/hwui/jni/Paint.cpp
@@ -25,7 +25,6 @@
#include <nativehelper/ScopedUtfChars.h>
#include <nativehelper/ScopedPrimitiveArray.h>
-#include "SkBlurDrawLooper.h"
#include "SkColorFilter.h"
#include "SkFont.h"
#include "SkFontMetrics.h"
@@ -39,6 +38,7 @@
#include "unicode/ushape.h"
#include "utils/Blur.h"
+#include <hwui/BlurDrawLooper.h>
#include <hwui/MinikinSkia.h>
#include <hwui/MinikinUtils.h>
#include <hwui/Paint.h>
@@ -964,13 +964,13 @@ namespace PaintGlue {
}
else {
SkScalar sigma = android::uirenderer::Blur::convertRadiusToSigma(radius);
- paint->setLooper(SkBlurDrawLooper::Make(color, cs.get(), sigma, dx, dy));
+ paint->setLooper(BlurDrawLooper::Make(color, cs.get(), sigma, {dx, dy}));
}
}
static jboolean hasShadowLayer(CRITICAL_JNI_PARAMS_COMMA jlong paintHandle) {
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- return paint->getLooper() && paint->getLooper()->asABlurShadow(nullptr);
+ return paint->getLooper() != nullptr;
}
static jboolean equalsForTextMeasurement(CRITICAL_JNI_PARAMS_COMMA jlong lPaint, jlong rPaint) {
diff --git a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
index 4966bfa1c1e9..df66981853bb 100644
--- a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
+++ b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
@@ -189,6 +189,13 @@ static void android_view_ThreadedRenderer_setSurface(JNIEnv* env, jobject clazz,
}
}
+static void android_view_ThreadedRenderer_setSurfaceControl(JNIEnv* env, jobject clazz,
+ jlong proxyPtr, jlong surfaceControlPtr) {
+ RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
+ ASurfaceControl* surfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControlPtr);
+ proxy->setSurfaceControl(surfaceControl);
+}
+
static jboolean android_view_ThreadedRenderer_pause(JNIEnv* env, jobject clazz,
jlong proxyPtr) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
@@ -671,6 +678,8 @@ static const JNINativeMethod gMethods[] = {
{"nSetName", "(JLjava/lang/String;)V", (void*)android_view_ThreadedRenderer_setName},
{"nSetSurface", "(JLandroid/view/Surface;Z)V",
(void*)android_view_ThreadedRenderer_setSurface},
+ {"nSetSurfaceControl", "(JJ)V",
+ (void*)android_view_ThreadedRenderer_setSurfaceControl},
{"nPause", "(J)Z", (void*)android_view_ThreadedRenderer_pause},
{"nSetStopped", "(JZ)V", (void*)android_view_ThreadedRenderer_setStopped},
{"nSetLightAlpha", "(JFF)V", (void*)android_view_ThreadedRenderer_setLightAlpha},
diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
index ee7c4d8bb54a..b2884023a83d 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
@@ -194,28 +194,20 @@ SkiaCanvas::PaintCoW&& SkiaRecordingCanvas::filterBitmap(PaintCoW&& paint) {
return filterPaint(std::move(paint));
}
-static SkDrawLooper* get_looper(const Paint* paint) {
+static BlurDrawLooper* get_looper(const Paint* paint) {
return paint ? paint->getLooper() : nullptr;
}
template <typename Proc>
-void applyLooper(SkDrawLooper* looper, const SkPaint* paint, Proc proc) {
+void applyLooper(BlurDrawLooper* looper, const SkPaint* paint, Proc proc) {
if (looper) {
- SkSTArenaAlloc<256> alloc;
- SkDrawLooper::Context* ctx = looper->makeContext(&alloc);
- if (ctx) {
- SkDrawLooper::Context::Info info;
- for (;;) {
- SkPaint p;
- if (paint) {
- p = *paint;
- }
- if (!ctx->next(&info, &p)) {
- break;
- }
- proc(info.fTranslate.fX, info.fTranslate.fY, &p);
- }
+ SkPaint p;
+ if (paint) {
+ p = *paint;
}
+ looper->apply(p, [&](SkPoint offset, const SkPaint& modifiedPaint) {
+ proc(offset.fX, offset.fY, &modifiedPaint);
+ });
} else {
proc(0, 0, paint);
}
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 65afcc3a2558..b760db287bcb 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -133,6 +133,7 @@ void CanvasContext::removeRenderNode(RenderNode* node) {
void CanvasContext::destroy() {
stopDrawing();
setSurface(nullptr);
+ setSurfaceControl(nullptr);
freePrefetchedLayers();
destroyHardwareResources();
mAnimationContext->destroy();
@@ -173,6 +174,23 @@ void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) {
setupPipelineSurface();
}
+void CanvasContext::setSurfaceControl(ASurfaceControl* surfaceControl) {
+ if (surfaceControl == mSurfaceControl) return;
+
+ auto funcs = mRenderThread.getASurfaceControlFunctions();
+
+ if (mSurfaceControl != nullptr) {
+ funcs.unregisterListenerFunc(this, &onSurfaceStatsAvailable);
+ funcs.releaseFunc(mSurfaceControl);
+ }
+ mSurfaceControl = surfaceControl;
+ mExpectSurfaceStats = surfaceControl != nullptr;
+ if (mSurfaceControl != nullptr) {
+ funcs.acquireFunc(mSurfaceControl);
+ funcs.registerListenerFunc(surfaceControl, this, &onSurfaceStatsAvailable);
+ }
+}
+
void CanvasContext::setupPipelineSurface() {
bool hasSurface = mRenderPipeline->setSurface(
mNativeSurface ? mNativeSurface->getNativeWindow() : nullptr, mSwapBehavior);
@@ -318,8 +336,8 @@ void CanvasContext::prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t sy
// just keep using the previous frame's structure instead
if (!wasSkipped(mCurrentFrameInfo)) {
mCurrentFrameInfo = mJankTracker.startFrame();
- mLast4FrameInfos.next().first = mCurrentFrameInfo;
}
+
mCurrentFrameInfo->importUiThreadInfo(uiFrameInfo);
mCurrentFrameInfo->set(FrameInfoIndex::SyncQueued) = syncQueued;
mCurrentFrameInfo->markSyncStart();
@@ -524,17 +542,14 @@ void CanvasContext::draw() {
}
mCurrentFrameInfo->set(FrameInfoIndex::DequeueBufferDuration) = swap.dequeueDuration;
mCurrentFrameInfo->set(FrameInfoIndex::QueueBufferDuration) = swap.queueDuration;
- mLast4FrameInfos[-1].second = frameCompleteNr;
mHaveNewSurface = false;
mFrameNumber = -1;
} else {
mCurrentFrameInfo->set(FrameInfoIndex::DequeueBufferDuration) = 0;
mCurrentFrameInfo->set(FrameInfoIndex::QueueBufferDuration) = 0;
- mLast4FrameInfos[-1].second = -1;
}
- // TODO: Use a fence for real completion?
- mCurrentFrameInfo->markFrameCompleted();
+ mCurrentFrameInfo->markSwapBuffersCompleted();
#if LOG_FRAMETIME_MMA
float thisFrame = mCurrentFrameInfo->duration(FrameInfoIndex::IssueDrawCommandsStart,
@@ -558,30 +573,73 @@ void CanvasContext::draw() {
mFrameCompleteCallbacks.clear();
}
- mJankTracker.finishFrame(*mCurrentFrameInfo);
- if (CC_UNLIKELY(mFrameMetricsReporter.get() != nullptr)) {
- mFrameMetricsReporter->reportFrameMetrics(mCurrentFrameInfo->data());
- }
-
- if (mLast4FrameInfos.size() == mLast4FrameInfos.capacity()) {
- // By looking 4 frames back, we guarantee all SF stats are available. There are at
- // most 3 buffers in BufferQueue. Surface object keeps stats for the last 8 frames.
- FrameInfo* forthBehind = mLast4FrameInfos.front().first;
- int64_t composedFrameId = mLast4FrameInfos.front().second;
- nsecs_t acquireTime = -1;
- if (mNativeSurface) {
- native_window_get_frame_timestamps(mNativeSurface->getNativeWindow(), composedFrameId,
- nullptr, &acquireTime, nullptr, nullptr, nullptr,
- nullptr, nullptr, nullptr, nullptr);
+ if (requireSwap) {
+ if (mExpectSurfaceStats) {
+ std::lock_guard lock(mLast4FrameInfosMutex);
+ std::pair<FrameInfo*, int64_t>& next = mLast4FrameInfos.next();
+ next.first = mCurrentFrameInfo;
+ next.second = frameCompleteNr;
+ } else {
+ mCurrentFrameInfo->markFrameCompleted();
+ mCurrentFrameInfo->set(FrameInfoIndex::GpuCompleted)
+ = mCurrentFrameInfo->get(FrameInfoIndex::FrameCompleted);
+ finishFrame(mCurrentFrameInfo);
}
- // Ignore default -1, NATIVE_WINDOW_TIMESTAMP_INVALID and NATIVE_WINDOW_TIMESTAMP_PENDING
- forthBehind->set(FrameInfoIndex::GpuCompleted) = acquireTime > 0 ? acquireTime : -1;
- mJankTracker.finishGpuDraw(*forthBehind);
}
mRenderThread.cacheManager().onFrameCompleted();
}
+void CanvasContext::finishFrame(FrameInfo* frameInfo) {
+
+ // TODO (b/169858044): Consolidate this into a single call.
+ mJankTracker.finishFrame(*frameInfo);
+ mJankTracker.finishGpuDraw(*frameInfo);
+
+ // TODO (b/169858044): Move this into JankTracker to adjust deadline when queue is
+ // double-stuffed.
+ if (CC_UNLIKELY(mFrameMetricsReporter.get() != nullptr)) {
+ mFrameMetricsReporter->reportFrameMetrics(frameInfo->data());
+ }
+}
+
+void CanvasContext::onSurfaceStatsAvailable(void* context, ASurfaceControl* control,
+ ASurfaceControlStats* stats) {
+
+ CanvasContext* instance = static_cast<CanvasContext*>(context);
+
+ const ASurfaceControlFunctions& functions =
+ instance->mRenderThread.getASurfaceControlFunctions();
+
+ nsecs_t gpuCompleteTime = functions.getAcquireTimeFunc(stats);
+ uint64_t frameNumber = functions.getFrameNumberFunc(stats);
+
+ FrameInfo* frameInfo = nullptr;
+ {
+ std::lock_guard(instance->mLast4FrameInfosMutex);
+ for (size_t i = 0; i < instance->mLast4FrameInfos.size(); i++) {
+ if (instance->mLast4FrameInfos[i].second == frameNumber) {
+ frameInfo = instance->mLast4FrameInfos[i].first;
+ break;
+ }
+ }
+ }
+ if (frameInfo != nullptr) {
+ if (gpuCompleteTime == -1) {
+ gpuCompleteTime = frameInfo->get(FrameInfoIndex::SwapBuffersCompleted);
+ }
+ if (gpuCompleteTime < frameInfo->get(FrameInfoIndex::SwapBuffers)) {
+ // TODO (b/180488606): Investigate why this can happen for first frames.
+ ALOGW("Impossible GPU complete time swapBuffers=%" PRIi64 " gpuComplete=%" PRIi64,
+ frameInfo->get(FrameInfoIndex::SwapBuffers), gpuCompleteTime);
+ gpuCompleteTime = frameInfo->get(FrameInfoIndex::SwapBuffersCompleted);
+ }
+ frameInfo->set(FrameInfoIndex::FrameCompleted) = gpuCompleteTime;
+ frameInfo->set(FrameInfoIndex::GpuCompleted) = gpuCompleteTime;
+ instance->finishFrame(frameInfo);
+ }
+}
+
// Called by choreographer to do an RT-driven animation
void CanvasContext::doFrame() {
if (!mRenderPipeline->isSurfaceReady()) return;
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index b31883b9ae94..2e7b2f618a8a 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -37,6 +37,7 @@
#include <SkSize.h>
#include <cutils/compiler.h>
#include <utils/Functor.h>
+#include <utils/Mutex.h>
#include <functional>
#include <future>
@@ -112,6 +113,7 @@ public:
void setSwapBehavior(SwapBehavior swapBehavior);
void setSurface(ANativeWindow* window, bool enableTimeout = true);
+ void setSurfaceControl(ASurfaceControl* surfaceControl);
bool pauseSurface();
void setStopped(bool stopped);
bool hasSurface() const { return mNativeSurface.get(); }
@@ -195,6 +197,10 @@ public:
SkISize getNextFrameSize() const;
+ // Called when SurfaceStats are available.
+ static void onSurfaceStatsAvailable(void* context, ASurfaceControl* control,
+ ASurfaceControlStats* stats);
+
private:
CanvasContext(RenderThread& thread, bool translucent, RenderNode* rootRenderNode,
IContextFactory* contextFactory, std::unique_ptr<IRenderPipeline> renderPipeline);
@@ -211,6 +217,7 @@ private:
void setupPipelineSurface();
SkRect computeDirtyRect(const Frame& frame, SkRect* dirty);
+ void finishFrame(FrameInfo* frameInfo);
// The same type as Frame.mWidth and Frame.mHeight
int32_t mLastFrameWidth = 0;
@@ -218,6 +225,9 @@ private:
RenderThread& mRenderThread;
std::unique_ptr<ReliableSurface> mNativeSurface;
+ // The SurfaceControl reference is passed from ViewRootImpl, can be set to
+ // NULL to remove the reference
+ ASurfaceControl* mSurfaceControl = nullptr;
// stopped indicates the CanvasContext will reject actual redraw operations,
// and defer repaint until it is un-stopped
bool mStopped = false;
@@ -257,7 +267,12 @@ private:
std::vector<sp<RenderNode>> mRenderNodes;
FrameInfo* mCurrentFrameInfo = nullptr;
- RingBuffer<std::pair<FrameInfo*, int64_t>, 4> mLast4FrameInfos;
+
+ // List of frames that are awaiting GPU completion reporting
+ RingBuffer<std::pair<FrameInfo*, int64_t>, 4> mLast4FrameInfos
+ GUARDED_BY(mLast4FrameInfosMutex);
+ std::mutex mLast4FrameInfosMutex;
+
std::string mName;
JankTracker mJankTracker;
FrameInfoVisualizer mProfiler;
@@ -272,6 +287,9 @@ private:
std::unique_ptr<IRenderPipeline> mRenderPipeline;
std::vector<std::function<void(int64_t)>> mFrameCompleteCallbacks;
+
+ // If set to true, we expect that callbacks into onSurfaceStatsAvailable
+ bool mExpectSurfaceStats = false;
};
} /* namespace renderthread */
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index 0ade8dde12eb..b9568fcf8e66 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -84,6 +84,19 @@ void RenderProxy::setSurface(ANativeWindow* window, bool enableTimeout) {
});
}
+void RenderProxy::setSurfaceControl(ASurfaceControl* surfaceControl) {
+ auto funcs = mRenderThread.getASurfaceControlFunctions();
+ if (surfaceControl) {
+ funcs.acquireFunc(surfaceControl);
+ }
+ mRenderThread.queue().post([this, control = surfaceControl, funcs]() mutable {
+ mContext->setSurfaceControl(control);
+ if (control) {
+ funcs.releaseFunc(control);
+ }
+ });
+}
+
void RenderProxy::allocateBuffers() {
mRenderThread.queue().post([=]() { mContext->allocateBuffers(); });
}
@@ -202,6 +215,7 @@ void RenderProxy::notifyFramePending() {
void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
mRenderThread.queue().runSync([&]() {
+ std::lock_guard lock(mRenderThread.getJankDataMutex());
mContext->profiler().dumpData(fd);
if (dumpFlags & DumpFlags::FrameStats) {
mContext->dumpFrames(fd);
@@ -221,6 +235,7 @@ void RenderProxy::resetProfileInfo() {
uint32_t RenderProxy::frameTimePercentile(int percentile) {
return mRenderThread.queue().runSync([&]() -> auto {
+ std::lock_guard lock(mRenderThread.globalProfileData().getDataMutex());
return mRenderThread.globalProfileData()->findPercentile(percentile);
});
}
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index a4adb16a930e..366d6b5a172c 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -20,6 +20,7 @@
#include <SkBitmap.h>
#include <android/native_window.h>
#include <cutils/compiler.h>
+#include <android/surface_control.h>
#include <utils/Functor.h>
#include "../FrameMetricsObserver.h"
@@ -72,6 +73,7 @@ public:
void setName(const char* name);
void setSurface(ANativeWindow* window, bool enableTimeout = true);
+ void setSurfaceControl(ASurfaceControl* surfaceControl);
void allocateBuffers();
bool pause();
void setStopped(bool stopped);
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp
index 7750a31b817f..5dc02e8454ac 100644
--- a/libs/hwui/renderthread/RenderThread.cpp
+++ b/libs/hwui/renderthread/RenderThread.cpp
@@ -33,6 +33,7 @@
#include <GrContextOptions.h>
#include <gl/GrGLInterface.h>
+#include <dlfcn.h>
#include <sys/resource.h>
#include <utils/Condition.h>
#include <utils/Log.h>
@@ -49,6 +50,37 @@ static bool gHasRenderThreadInstance = false;
static JVMAttachHook gOnStartHook = nullptr;
+ASurfaceControlFunctions::ASurfaceControlFunctions() {
+ void* handle_ = dlopen("libandroid.so", RTLD_NOW | RTLD_NODELETE);
+ acquireFunc = (ASC_acquire) dlsym(handle_, "ASurfaceControl_acquire");
+ LOG_ALWAYS_FATAL_IF(acquireFunc == nullptr,
+ "Failed to find required symbol ASurfaceControl_acquire!");
+
+ releaseFunc = (ASC_release) dlsym(handle_, "ASurfaceControl_release");
+ LOG_ALWAYS_FATAL_IF(releaseFunc == nullptr,
+ "Failed to find required symbol ASurfaceControl_release!");
+
+ registerListenerFunc = (ASC_registerSurfaceStatsListener) dlsym(handle_,
+ "ASurfaceControl_registerSurfaceStatsListener");
+ LOG_ALWAYS_FATAL_IF(registerListenerFunc == nullptr,
+ "Failed to find required symbol ASurfaceControl_registerSurfaceStatsListener!");
+
+ unregisterListenerFunc = (ASC_unregisterSurfaceStatsListener) dlsym(handle_,
+ "ASurfaceControl_unregisterSurfaceStatsListener");
+ LOG_ALWAYS_FATAL_IF(unregisterListenerFunc == nullptr,
+ "Failed to find required symbol ASurfaceControl_unregisterSurfaceStatsListener!");
+
+ getAcquireTimeFunc = (ASCStats_getAcquireTime) dlsym(handle_,
+ "ASurfaceControlStats_getAcquireTime");
+ LOG_ALWAYS_FATAL_IF(getAcquireTimeFunc == nullptr,
+ "Failed to find required symbol ASurfaceControlStats_getAcquireTime!");
+
+ getFrameNumberFunc = (ASCStats_getFrameNumber) dlsym(handle_,
+ "ASurfaceControlStats_getFrameNumber");
+ LOG_ALWAYS_FATAL_IF(getFrameNumberFunc == nullptr,
+ "Failed to find required symbol ASurfaceControlStats_getFrameNumber!");
+}
+
void RenderThread::frameCallback(int64_t frameTimeNanos, void* data) {
RenderThread* rt = reinterpret_cast<RenderThread*>(data);
int64_t vsyncId = AChoreographer_getVsyncId(rt->mChoreographer);
@@ -134,7 +166,8 @@ RenderThread::RenderThread()
, mFrameCallbackTaskPending(false)
, mRenderState(nullptr)
, mEglManager(nullptr)
- , mFunctorManager(WebViewFunctorManager::instance()) {
+ , mFunctorManager(WebViewFunctorManager::instance())
+ , mGlobalProfileData(mJankDataMutex) {
Properties::load();
start("RenderThread");
}
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index 4fbb07168ac0..a7d1ba8dafd7 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -17,6 +17,7 @@
#ifndef RENDERTHREAD_H_
#define RENDERTHREAD_H_
+#include <surface_control_private.h>
#include <GrDirectContext.h>
#include <SkBitmap.h>
#include <cutils/compiler.h>
@@ -78,6 +79,27 @@ struct VsyncSource {
virtual ~VsyncSource() {}
};
+typedef void (*ASC_acquire)(ASurfaceControl* control);
+typedef void (*ASC_release)(ASurfaceControl* control);
+
+typedef void (*ASC_registerSurfaceStatsListener)(ASurfaceControl* control, void* context,
+ ASurfaceControl_SurfaceStatsListener func);
+typedef void (*ASC_unregisterSurfaceStatsListener)(void* context,
+ ASurfaceControl_SurfaceStatsListener func);
+
+typedef int64_t (*ASCStats_getAcquireTime)(ASurfaceControlStats* stats);
+typedef uint64_t (*ASCStats_getFrameNumber)(ASurfaceControlStats* stats);
+
+struct ASurfaceControlFunctions {
+ ASurfaceControlFunctions();
+ ASC_acquire acquireFunc;
+ ASC_release releaseFunc;
+ ASC_registerSurfaceStatsListener registerListenerFunc;
+ ASC_unregisterSurfaceStatsListener unregisterListenerFunc;
+ ASCStats_getAcquireTime getAcquireTimeFunc;
+ ASCStats_getFrameNumber getFrameNumberFunc;
+};
+
class ChoreographerSource;
class DummyVsyncSource;
@@ -104,6 +126,7 @@ public:
RenderState& renderState() const { return *mRenderState; }
EglManager& eglManager() const { return *mEglManager; }
ProfileDataContainer& globalProfileData() { return mGlobalProfileData; }
+ std::mutex& getJankDataMutex() { return mJankDataMutex; }
Readback& readback();
GrDirectContext* getGrContext() const { return mGrContext.get(); }
@@ -121,6 +144,10 @@ public:
void preload();
+ const ASurfaceControlFunctions& getASurfaceControlFunctions() {
+ return mASurfaceControlFunctions;
+ }
+
/**
* isCurrent provides a way to query, if the caller is running on
* the render thread.
@@ -189,6 +216,9 @@ private:
sk_sp<GrDirectContext> mGrContext;
CacheManager* mCacheManager;
sp<VulkanManager> mVkManager;
+
+ ASurfaceControlFunctions mASurfaceControlFunctions;
+ std::mutex mJankDataMutex;
};
} /* namespace renderthread */
diff --git a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
index 7951537e1525..a1ba70a22581 100644
--- a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
+++ b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
@@ -16,7 +16,6 @@
#include "tests/common/TestUtils.h"
-#include <SkBlurDrawLooper.h>
#include <SkColorMatrixFilter.h>
#include <SkColorSpace.h>
#include <SkImagePriv.h>
@@ -85,15 +84,3 @@ TEST(SkiaBehavior, srgbColorSpaceIsSingleton) {
ASSERT_EQ(sRGB1.get(), sRGB2.get());
}
-TEST(SkiaBehavior, blurDrawLooper) {
- sk_sp<SkDrawLooper> looper = SkBlurDrawLooper::Make(SK_ColorRED, 5.0f, 3.0f, 4.0f);
-
- SkDrawLooper::BlurShadowRec blur;
- bool success = looper->asABlurShadow(&blur);
- ASSERT_TRUE(success);
-
- ASSERT_EQ(SK_ColorRED, blur.fColor);
- ASSERT_EQ(5.0f, blur.fSigma);
- ASSERT_EQ(3.0f, blur.fOffset.fX);
- ASSERT_EQ(4.0f, blur.fOffset.fY);
-}
diff --git a/libs/hwui/tests/unit/SkiaCanvasTests.cpp b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
index f77ca2a8c06c..dae3c9435712 100644
--- a/libs/hwui/tests/unit/SkiaCanvasTests.cpp
+++ b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
@@ -17,7 +17,6 @@
#include "tests/common/TestUtils.h"
#include <hwui/Paint.h>
-#include <SkBlurDrawLooper.h>
#include <SkCanvasStateUtils.h>
#include <SkPicture.h>
#include <SkPictureRecorder.h>
@@ -37,7 +36,7 @@ TEST(SkiaCanvas, drawShadowLayer) {
// it is transparent to ensure that we still draw the rect since it has a looper
paint.setColor(SK_ColorTRANSPARENT);
// this is how view's shadow layers are implemented
- paint.setLooper(SkBlurDrawLooper::Make(0xF0000000, 6.0f, 0, 10));
+ paint.setLooper(BlurDrawLooper::Make({0, 0, 0, 240.0f / 255}, nullptr, 6.0f, {0, 10}));
canvas.drawRect(3, 3, 7, 7, paint);
ASSERT_EQ(TestUtils::getColor(surface, 0, 0), SK_ColorWHITE);
diff --git a/libs/hwui/utils/PaintUtils.h b/libs/hwui/utils/PaintUtils.h
index e2fdf2fcb5a5..09c6a4fdf50d 100644
--- a/libs/hwui/utils/PaintUtils.h
+++ b/libs/hwui/utils/PaintUtils.h
@@ -20,7 +20,6 @@
#include <utils/Blur.h>
#include <SkColorFilter.h>
-#include <SkDrawLooper.h>
#include <SkPaint.h>
#include <SkShader.h>
diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java
index a7e9a0de538a..5e2e5595ba9c 100644
--- a/location/java/android/location/Location.java
+++ b/location/java/android/location/Location.java
@@ -569,7 +569,12 @@ public class Location implements Parcelable {
/** @hide */
public long getElapsedRealtimeAgeMillis() {
- return NANOSECONDS.toMillis(getElapsedRealtimeAgeNanos());
+ return getElapsedRealtimeAgeMillis(SystemClock.elapsedRealtime());
+ }
+
+ /** @hide */
+ public long getElapsedRealtimeAgeMillis(long referenceRealtimeMs) {
+ return referenceRealtimeMs - NANOSECONDS.toMillis(mElapsedRealtimeNanos);
}
/**
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 8d090f824e71..d896c1fc82b5 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -567,6 +567,25 @@ public class AudioManager {
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static final int FLAG_FROM_KEY = 1 << 12;
+ /** @hide */
+ @IntDef(flag = false, prefix = "FLAG", value = {
+ FLAG_SHOW_UI,
+ FLAG_ALLOW_RINGER_MODES,
+ FLAG_PLAY_SOUND,
+ FLAG_REMOVE_SOUND_AND_VIBRATE,
+ FLAG_VIBRATE,
+ FLAG_FIXED_VOLUME,
+ FLAG_BLUETOOTH_ABS_VOLUME,
+ FLAG_SHOW_SILENT_HINT,
+ FLAG_HDMI_SYSTEM_AUDIO_VOLUME,
+ FLAG_ACTIVE_MEDIA_ONLY,
+ FLAG_SHOW_UI_WARNINGS,
+ FLAG_SHOW_VIBRATE_HINT,
+ FLAG_FROM_KEY,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Flags {}
+
// The iterator of TreeMap#entrySet() returns the entries in ascending key order.
private static final TreeMap<Integer, String> FLAG_NAMES = new TreeMap<>();
diff --git a/media/java/android/media/AudioPlaybackConfiguration.java b/media/java/android/media/AudioPlaybackConfiguration.java
index 27f72687ccbe..ede1dbf47d36 100644
--- a/media/java/android/media/AudioPlaybackConfiguration.java
+++ b/media/java/android/media/AudioPlaybackConfiguration.java
@@ -181,6 +181,21 @@ public final class AudioPlaybackConfiguration implements Parcelable {
@Retention(RetentionPolicy.SOURCE)
public @interface PlayerState {}
+ /** @hide */
+ public static String playerStateToString(@PlayerState int state) {
+ switch (state) {
+ case PLAYER_STATE_UNKNOWN: return "PLAYER_STATE_UNKNOWN";
+ case PLAYER_STATE_RELEASED: return "PLAYER_STATE_RELEASED";
+ case PLAYER_STATE_IDLE: return "PLAYER_STATE_IDLE";
+ case PLAYER_STATE_STARTED: return "PLAYER_STATE_STARTED";
+ case PLAYER_STATE_PAUSED: return "PLAYER_STATE_PAUSED";
+ case PLAYER_STATE_STOPPED: return "PLAYER_STATE_STOPPED";
+ case PLAYER_UPDATE_DEVICE_ID: return "PLAYER_UPDATE_DEVICE_ID";
+ default:
+ return "invalid state " + state;
+ }
+ }
+
// immutable data
private final int mPlayerIId;
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index e056d435198a..7fb83f17a9d4 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -2726,8 +2726,10 @@ public class AudioTrack extends PlayerBase
}
}
synchronized(mPlayStateLock) {
+ baseStart(0); // unknown device at this point
native_start();
- baseStart(native_getRoutedDeviceId());
+ // FIXME see b/179218630
+ //baseStart(native_getRoutedDeviceId());
if (mPlayState == PLAYSTATE_PAUSED_STOPPING) {
mPlayState = PLAYSTATE_STOPPING;
} else {
diff --git a/media/java/android/media/ImageWriter.java b/media/java/android/media/ImageWriter.java
index 92db946ab5ba..44f8385b715e 100644
--- a/media/java/android/media/ImageWriter.java
+++ b/media/java/android/media/ImageWriter.java
@@ -23,6 +23,7 @@ import android.graphics.ImageFormat;
import android.graphics.ImageFormat.Format;
import android.graphics.PixelFormat;
import android.graphics.Rect;
+import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.camera2.utils.SurfaceUtils;
import android.hardware.HardwareBuffer;
import android.os.Handler;
@@ -202,6 +203,25 @@ public class ImageWriter implements AutoCloseable {
if (format == ImageFormat.UNKNOWN) {
format = SurfaceUtils.getSurfaceFormat(surface);
}
+ // Several public formats use the same native HAL_PIXEL_FORMAT_BLOB. The native
+ // allocation estimation sequence depends on the public formats values. To avoid
+ // possible errors, convert where necessary.
+ if (format == StreamConfigurationMap.HAL_PIXEL_FORMAT_BLOB) {
+ int surfaceDataspace = SurfaceUtils.getSurfaceDataspace(surface);
+ switch (surfaceDataspace) {
+ case StreamConfigurationMap.HAL_DATASPACE_DEPTH:
+ format = ImageFormat.DEPTH_POINT_CLOUD;
+ break;
+ case StreamConfigurationMap.HAL_DATASPACE_DYNAMIC_DEPTH:
+ format = ImageFormat.DEPTH_JPEG;
+ break;
+ case StreamConfigurationMap.HAL_DATASPACE_HEIF:
+ format = ImageFormat.HEIC;
+ break;
+ default:
+ format = ImageFormat.JPEG;
+ }
+ }
// Estimate the native buffer allocation size and register it so it gets accounted for
// during GC. Note that this doesn't include the buffers required by the buffer queue
// itself and the buffers requested by the producer.
diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java
index 49f9d6612341..adb8a54c0167 100644
--- a/media/java/android/media/MediaDrm.java
+++ b/media/java/android/media/MediaDrm.java
@@ -38,6 +38,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -2493,4 +2494,80 @@ public final class MediaDrm implements AutoCloseable {
return mPlaybackId;
}
}
+
+ /**
+ * Returns recent {@link LogMessage LogMessages} associated with this {@link MediaDrm}
+ * instance.
+ */
+ @NonNull
+ public native List<LogMessage> getLogMessages();
+
+ /**
+ * A {@link LogMessage} records an event in the {@link MediaDrm} framework
+ * or vendor plugin.
+ */
+ public static class LogMessage {
+
+ /**
+ * Timing of the recorded event measured in milliseconds since the Epoch,
+ * 1970-01-01 00:00:00 +0000 (UTC).
+ */
+ public final long timestampMillis;
+
+ /**
+ * Priority of the recorded event.
+ * <p>
+ * Possible priority constants are defined in {@link Log}, e.g.:
+ * <ul>
+ * <li>{@link Log#ASSERT}</li>
+ * <li>{@link Log#ERROR}</li>
+ * <li>{@link Log#WARN}</li>
+ * <li>{@link Log#INFO}</li>
+ * <li>{@link Log#DEBUG}</li>
+ * <li>{@link Log#VERBOSE}</li>
+ * </ul>
+ */
+ @Log.Level
+ public final int priority;
+
+ /**
+ * Description of the recorded event.
+ */
+ @NonNull
+ public final String message;
+
+ private LogMessage(long timestampMillis, int priority, String message) {
+ this.timestampMillis = timestampMillis;
+ if (priority < Log.VERBOSE || priority > Log.ASSERT) {
+ throw new IllegalArgumentException("invalid log priority " + priority);
+ }
+ this.priority = priority;
+ this.message = message;
+ }
+
+ private char logPriorityChar() {
+ switch (priority) {
+ case Log.VERBOSE:
+ return 'V';
+ case Log.DEBUG:
+ return 'D';
+ case Log.INFO:
+ return 'I';
+ case Log.WARN:
+ return 'W';
+ case Log.ERROR:
+ return 'E';
+ case Log.ASSERT:
+ return 'F';
+ default:
+ }
+ return 'U';
+ }
+
+ @Override
+ public String toString() {
+ return String.format("LogMessage{%s %c %s}",
+ Instant.ofEpochMilli(timestampMillis), logPriorityChar(), message);
+ }
+ }
}
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index ca0d29f2f47f..c51c9dd06c24 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -921,7 +921,7 @@ public class MediaPlayer extends PlayerBase
final AudioAttributes aa = audioAttributes != null ? audioAttributes :
new AudioAttributes.Builder().build();
mp.setAudioAttributes(aa);
- mp.setAudioSessionId(audioSessionId);
+ mp.native_setAudioSessionId(audioSessionId);
mp.setDataSource(context, uri);
if (holder != null) {
mp.setDisplay(holder);
@@ -987,7 +987,7 @@ public class MediaPlayer extends PlayerBase
final AudioAttributes aa = audioAttributes != null ? audioAttributes :
new AudioAttributes.Builder().build();
mp.setAudioAttributes(aa);
- mp.setAudioSessionId(audioSessionId);
+ mp.native_setAudioSessionId(audioSessionId);
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
@@ -1356,6 +1356,7 @@ public class MediaPlayer extends PlayerBase
}
private void startImpl() {
+ baseStart(0); // unknown device at this point
stayAwake(true);
_start();
}
@@ -1381,6 +1382,7 @@ public class MediaPlayer extends PlayerBase
public void stop() throws IllegalStateException {
stayAwake(false);
_stop();
+ baseStop();
}
private native void _stop() throws IllegalStateException;
@@ -1394,6 +1396,7 @@ public class MediaPlayer extends PlayerBase
public void pause() throws IllegalStateException {
stayAwake(false);
_pause();
+ basePause();
}
private native void _pause() throws IllegalStateException;
@@ -3479,7 +3482,8 @@ public class MediaPlayer extends PlayerBase
case MEDIA_STOPPED:
{
tryToDisableNativeRoutingCallback();
- baseStop();
+ // FIXME see b/179218630
+ //baseStop();
TimeProvider timeProvider = mTimeProvider;
if (timeProvider != null) {
timeProvider.onStopped();
@@ -3489,15 +3493,17 @@ public class MediaPlayer extends PlayerBase
case MEDIA_STARTED:
{
- baseStart(native_getRoutedDeviceId());
+ // FIXME see b/179218630
+ //baseStart(native_getRoutedDeviceId());
tryToEnableNativeRoutingCallback();
}
// fall through
case MEDIA_PAUSED:
{
- if (msg.what == MEDIA_PAUSED) {
- basePause();
- }
+ // FIXME see b/179218630
+ //if (msg.what == MEDIA_PAUSED) {
+ // basePause();
+ //}
TimeProvider timeProvider = mTimeProvider;
if (timeProvider != null) {
timeProvider.onPaused(msg.what == MEDIA_PAUSED);
diff --git a/media/java/android/media/metrics/Event.java b/media/java/android/media/metrics/Event.java
new file mode 100644
index 000000000000..5646dcdb6c9c
--- /dev/null
+++ b/media/java/android/media/metrics/Event.java
@@ -0,0 +1,44 @@
+/*
+ * 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 android.media.metrics;
+
+import android.annotation.IntRange;
+
+/**
+ * Abstract class for metrics events.
+ */
+public abstract class Event {
+ private final long mTimeSinceCreatedMillis;
+
+ // hide default constructor
+ /* package */ Event() {
+ mTimeSinceCreatedMillis = MediaMetricsManager.INVALID_TIMESTAMP;
+ }
+
+ protected Event(long timeSinceCreatedMillis) {
+ mTimeSinceCreatedMillis = timeSinceCreatedMillis;
+ }
+
+ /**
+ * Gets time since the corresponding instance is created in millisecond.
+ * @return the timestamp since the instance is created, or -1 if unknown.
+ */
+ @IntRange(from = -1)
+ public long getTimeSinceCreatedMillis() {
+ return mTimeSinceCreatedMillis;
+ }
+}
diff --git a/media/java/android/media/metrics/MediaMetricsManager.java b/media/java/android/media/metrics/MediaMetricsManager.java
index f2eae5fad3c3..de780f672b28 100644
--- a/media/java/android/media/metrics/MediaMetricsManager.java
+++ b/media/java/android/media/metrics/MediaMetricsManager.java
@@ -26,7 +26,8 @@ import android.os.RemoteException;
*/
@SystemService(Context.MEDIA_METRICS_SERVICE)
public class MediaMetricsManager {
- // TODO: unhide APIs.
+ public static final long INVALID_TIMESTAMP = -1;
+
private static final String TAG = "MediaMetricsManager";
private IMediaMetricsManager mService;
diff --git a/media/java/android/media/metrics/PlaybackErrorEvent.java b/media/java/android/media/metrics/PlaybackErrorEvent.java
index db7000536299..5a0820d16cb9 100644
--- a/media/java/android/media/metrics/PlaybackErrorEvent.java
+++ b/media/java/android/media/metrics/PlaybackErrorEvent.java
@@ -17,8 +17,10 @@
package android.media.metrics;
import android.annotation.IntDef;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;
@@ -27,17 +29,19 @@ import java.util.Objects;
/**
* Playback error event.
- * @hide
*/
-public final class PlaybackErrorEvent implements Parcelable {
+public final class PlaybackErrorEvent extends Event implements Parcelable {
+ /** Unknown error code. */
public static final int ERROR_CODE_UNKNOWN = 0;
+ /** Error code for other errors */
public static final int ERROR_CODE_OTHER = 1;
+ /** Error code for runtime errors */
public static final int ERROR_CODE_RUNTIME = 2;
private final @Nullable String mExceptionStack;
private final int mErrorCode;
private final int mSubErrorCode;
- private final long mTimeSincePlaybackCreatedMillis;
+ private final long mTimeSinceCreatedMillis;
/** @hide */
@@ -59,11 +63,11 @@ public final class PlaybackErrorEvent implements Parcelable {
@Nullable String exceptionStack,
int errorCode,
int subErrorCode,
- long timeSincePlaybackCreatedMillis) {
+ long timeSinceCreatedMillis) {
this.mExceptionStack = exceptionStack;
this.mErrorCode = errorCode;
this.mSubErrorCode = subErrorCode;
- this.mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis;
+ this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
}
/** @hide */
@@ -72,17 +76,32 @@ public final class PlaybackErrorEvent implements Parcelable {
return mExceptionStack;
}
+
+ /**
+ * Gets error code.
+ */
@ErrorCode
public int getErrorCode() {
return mErrorCode;
}
+
+ /**
+ * Gets sub error code.
+ */
+ @IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE)
public int getSubErrorCode() {
return mSubErrorCode;
}
- public long getTimeSincePlaybackCreatedMillis() {
- return mTimeSincePlaybackCreatedMillis;
+ /**
+ * Gets the timestamp since creation in milliseconds.
+ * @return the timestamp since the playback is created, or -1 if unknown.
+ */
+ @Override
+ @IntRange(from = -1)
+ public long getTimeSinceCreatedMillis() {
+ return mTimeSinceCreatedMillis;
}
@Override
@@ -91,7 +110,7 @@ public final class PlaybackErrorEvent implements Parcelable {
+ "exceptionStack = " + mExceptionStack + ", "
+ "errorCode = " + mErrorCode + ", "
+ "subErrorCode = " + mSubErrorCode + ", "
- + "timeSincePlaybackCreatedMillis = " + mTimeSincePlaybackCreatedMillis
+ + "timeSinceCreatedMillis = " + mTimeSinceCreatedMillis
+ " }";
}
@@ -103,13 +122,13 @@ public final class PlaybackErrorEvent implements Parcelable {
return Objects.equals(mExceptionStack, that.mExceptionStack)
&& mErrorCode == that.mErrorCode
&& mSubErrorCode == that.mSubErrorCode
- && mTimeSincePlaybackCreatedMillis == that.mTimeSincePlaybackCreatedMillis;
+ && mTimeSinceCreatedMillis == that.mTimeSinceCreatedMillis;
}
@Override
public int hashCode() {
return Objects.hash(mExceptionStack, mErrorCode, mSubErrorCode,
- mTimeSincePlaybackCreatedMillis);
+ mTimeSinceCreatedMillis);
}
@Override
@@ -120,7 +139,7 @@ public final class PlaybackErrorEvent implements Parcelable {
if (mExceptionStack != null) dest.writeString(mExceptionStack);
dest.writeInt(mErrorCode);
dest.writeInt(mSubErrorCode);
- dest.writeLong(mTimeSincePlaybackCreatedMillis);
+ dest.writeLong(mTimeSinceCreatedMillis);
}
@Override
@@ -134,14 +153,15 @@ public final class PlaybackErrorEvent implements Parcelable {
String exceptionStack = (flg & 0x1) == 0 ? null : in.readString();
int errorCode = in.readInt();
int subErrorCode = in.readInt();
- long timeSincePlaybackCreatedMillis = in.readLong();
+ long timeSinceCreatedMillis = in.readLong();
this.mExceptionStack = exceptionStack;
this.mErrorCode = errorCode;
this.mSubErrorCode = subErrorCode;
- this.mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis;
+ this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
}
+
public static final @NonNull Parcelable.Creator<PlaybackErrorEvent> CREATOR =
new Parcelable.Creator<PlaybackErrorEvent>() {
@Override
@@ -162,27 +182,18 @@ public final class PlaybackErrorEvent implements Parcelable {
private @Nullable Exception mException;
private int mErrorCode;
private int mSubErrorCode;
- private long mTimeSincePlaybackCreatedMillis;
+ private long mTimeSinceCreatedMillis = -1;
/**
* Creates a new Builder.
- *
- * @hide
*/
- public Builder(
- @Nullable Exception exception,
- int errorCode,
- int subErrorCode,
- long timeSincePlaybackCreatedMillis) {
- mException = exception;
- mErrorCode = errorCode;
- mSubErrorCode = subErrorCode;
- mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis;
+ public Builder() {
}
/**
* Sets the {@link Exception} object.
*/
+ @SuppressLint("MissingGetterMatchingBuilder") // Exception is not parcelable.
public @NonNull Builder setException(@NonNull Exception value) {
mException = value;
return this;
@@ -199,16 +210,19 @@ public final class PlaybackErrorEvent implements Parcelable {
/**
* Sets sub error code.
*/
- public @NonNull Builder setSubErrorCode(int value) {
+ public @NonNull Builder setSubErrorCode(
+ @IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE) int value) {
mSubErrorCode = value;
return this;
}
/**
- * Set the timestamp in milliseconds.
+ * Set the timestamp since creation in milliseconds.
+ * @param value the timestamp since the creation in milliseconds.
+ * -1 indicates the value is unknown.
*/
- public @NonNull Builder setTimeSincePlaybackCreatedMillis(long value) {
- mTimeSincePlaybackCreatedMillis = value;
+ public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
+ mTimeSinceCreatedMillis = value;
return this;
}
@@ -227,7 +241,7 @@ public final class PlaybackErrorEvent implements Parcelable {
stack,
mErrorCode,
mSubErrorCode,
- mTimeSincePlaybackCreatedMillis);
+ mTimeSinceCreatedMillis);
return o;
}
}
diff --git a/media/java/android/media/metrics/PlaybackSession.java b/media/java/android/media/metrics/PlaybackSession.java
index 3056e9820f9d..4cb957f4e597 100644
--- a/media/java/android/media/metrics/PlaybackSession.java
+++ b/media/java/android/media/metrics/PlaybackSession.java
@@ -53,9 +53,8 @@ public final class PlaybackSession implements AutoCloseable {
/**
* Reports error event.
- * @hide
*/
- public void reportPlaybackErrorEvent(PlaybackErrorEvent event) {
+ public void reportPlaybackErrorEvent(@NonNull PlaybackErrorEvent event) {
mManager.reportPlaybackErrorEvent(mId, event);
}
@@ -69,9 +68,8 @@ public final class PlaybackSession implements AutoCloseable {
/**
* Reports playback state event.
- * @hide
*/
- public void reportPlaybackStateEvent(PlaybackStateEvent event) {
+ public void reportPlaybackStateEvent(@NonNull PlaybackStateEvent event) {
mManager.reportPlaybackStateEvent(mId, event);
}
diff --git a/media/java/android/media/metrics/PlaybackStateEvent.java b/media/java/android/media/metrics/PlaybackStateEvent.java
index 6ce5bf0f0f33..8ca5b75dec98 100644
--- a/media/java/android/media/metrics/PlaybackStateEvent.java
+++ b/media/java/android/media/metrics/PlaybackStateEvent.java
@@ -17,6 +17,7 @@
package android.media.metrics;
import android.annotation.IntDef;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
@@ -27,10 +28,8 @@ import java.util.Objects;
/**
* Playback state event.
- * @hide
*/
-public final class PlaybackStateEvent implements Parcelable {
- // TODO: more states
+public final class PlaybackStateEvent extends Event implements Parcelable {
/** Playback has not started (initial state) */
public static final int STATE_NOT_STARTED = 0;
/** Playback is buffering in the background for initial playback start */
@@ -41,23 +40,57 @@ public final class PlaybackStateEvent implements Parcelable {
public static final int STATE_PLAYING = 3;
/** Playback is paused but ready to play */
public static final int STATE_PAUSED = 4;
-
- private int mState;
- private long mTimeSincePlaybackCreatedMillis;
+ /** Playback is handling a seek. */
+ public static final int STATE_SEEKING = 5;
+ /** Playback is buffering to resume active playback. */
+ public static final int STATE_BUFFERING = 6;
+ /** Playback is buffering while paused. */
+ public static final int STATE_PAUSED_BUFFERING = 7;
+ /** Playback is suppressed (e.g. due to audio focus loss). */
+ public static final int STATE_SUPPRESSED = 9;
+ /**
+ * Playback is suppressed (e.g. due to audio focus loss) while buffering to resume a playback.
+ */
+ public static final int STATE_SUPPRESSED_BUFFERING = 10;
+ /** Playback has reached the end of the media. */
+ public static final int STATE_ENDED = 11;
+ /** Playback is stopped and can be restarted. */
+ public static final int STATE_STOPPED = 12;
+ /** Playback is stopped due a fatal error and can be retried. */
+ public static final int STATE_FAILED = 13;
+ /** Playback is interrupted by an ad. */
+ public static final int STATE_INTERRUPTED_BY_AD = 14;
+ /** Playback is abandoned before reaching the end of the media. */
+ public static final int STATE_ABANDONED = 15;
+
+ private final int mState;
+ private final long mTimeSinceCreatedMillis;
// These track ExoPlayer states. See the ExoPlayer documentation for the state transitions.
+ /** @hide */
@IntDef(prefix = "STATE_", value = {
STATE_NOT_STARTED,
STATE_JOINING_BACKGROUND,
STATE_JOINING_FOREGROUND,
STATE_PLAYING,
- STATE_PAUSED
+ STATE_PAUSED,
+ STATE_SEEKING,
+ STATE_BUFFERING,
+ STATE_PAUSED_BUFFERING,
+ STATE_SUPPRESSED,
+ STATE_SUPPRESSED_BUFFERING,
+ STATE_ENDED,
+ STATE_STOPPED,
+ STATE_FAILED,
+ STATE_INTERRUPTED_BY_AD,
+ STATE_ABANDONED,
})
@Retention(java.lang.annotation.RetentionPolicy.SOURCE)
public @interface State {}
/**
* Converts playback state to string.
+ * @hide
*/
public static String stateToString(@State int value) {
switch (value) {
@@ -71,6 +104,26 @@ public final class PlaybackStateEvent implements Parcelable {
return "STATE_PLAYING";
case STATE_PAUSED:
return "STATE_PAUSED";
+ case STATE_SEEKING:
+ return "STATE_SEEKING";
+ case STATE_BUFFERING:
+ return "STATE_BUFFERING";
+ case STATE_PAUSED_BUFFERING:
+ return "STATE_PAUSED_BUFFERING";
+ case STATE_SUPPRESSED:
+ return "STATE_SUPPRESSED";
+ case STATE_SUPPRESSED_BUFFERING:
+ return "STATE_SUPPRESSED_BUFFERING";
+ case STATE_ENDED:
+ return "STATE_ENDED";
+ case STATE_STOPPED:
+ return "STATE_STOPPED";
+ case STATE_FAILED:
+ return "STATE_FAILED";
+ case STATE_INTERRUPTED_BY_AD:
+ return "STATE_INTERRUPTED_BY_AD";
+ case STATE_ABANDONED:
+ return "STATE_ABANDONED";
default:
return Integer.toHexString(value);
}
@@ -83,14 +136,13 @@ public final class PlaybackStateEvent implements Parcelable {
*/
public PlaybackStateEvent(
int state,
- long timeSincePlaybackCreatedMillis) {
+ long timeSinceCreatedMillis) {
+ this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
this.mState = state;
- this.mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis;
}
/**
* Gets playback state.
- * @return
*/
public int getState() {
return mState;
@@ -98,9 +150,12 @@ public final class PlaybackStateEvent implements Parcelable {
/**
* Gets time since the corresponding playback is created in millisecond.
+ * @return the timestamp since the playback is created, or -1 if unknown.
*/
- public long getTimeSincePlaybackCreatedMillis() {
- return mTimeSincePlaybackCreatedMillis;
+ @Override
+ @IntRange(from = -1)
+ public long getTimeSinceCreatedMillis() {
+ return mTimeSinceCreatedMillis;
}
@Override
@@ -109,18 +164,18 @@ public final class PlaybackStateEvent implements Parcelable {
if (o == null || getClass() != o.getClass()) return false;
PlaybackStateEvent that = (PlaybackStateEvent) o;
return mState == that.mState
- && mTimeSincePlaybackCreatedMillis == that.mTimeSincePlaybackCreatedMillis;
+ && mTimeSinceCreatedMillis == that.mTimeSinceCreatedMillis;
}
@Override
public int hashCode() {
- return Objects.hash(mState, mTimeSincePlaybackCreatedMillis);
+ return Objects.hash(mState, mTimeSinceCreatedMillis);
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mState);
- dest.writeLong(mTimeSincePlaybackCreatedMillis);
+ dest.writeLong(mTimeSinceCreatedMillis);
}
@Override
@@ -131,10 +186,10 @@ public final class PlaybackStateEvent implements Parcelable {
/** @hide */
/* package-private */ PlaybackStateEvent(@NonNull Parcel in) {
int state = in.readInt();
- long timeSincePlaybackCreatedMillis = in.readLong();
+ long timeSinceCreatedMillis = in.readLong();
this.mState = state;
- this.mTimeSincePlaybackCreatedMillis = timeSincePlaybackCreatedMillis;
+ this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
}
public static final @NonNull Parcelable.Creator<PlaybackStateEvent> CREATOR =
@@ -150,4 +205,43 @@ public final class PlaybackStateEvent implements Parcelable {
}
};
+ /**
+ * A builder for {@link PlaybackStateEvent}
+ */
+ public static final class Builder {
+ private int mState = STATE_NOT_STARTED;
+ private long mTimeSinceCreatedMillis = -1;
+
+ /**
+ * Creates a new Builder.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Sets playback state.
+ */
+ public @NonNull Builder setState(@State int value) {
+ mState = value;
+ return this;
+ }
+
+ /**
+ * Sets timestamp since the creation in milliseconds.
+ * @param value the timestamp since the creation in milliseconds.
+ * -1 indicates the value is unknown.
+ */
+ public @NonNull Builder setTimeSinceCreatedMillis(@IntRange(from = -1) long value) {
+ mTimeSinceCreatedMillis = value;
+ return this;
+ }
+
+ /** Builds the instance. */
+ public @NonNull PlaybackStateEvent build() {
+ PlaybackStateEvent o = new PlaybackStateEvent(
+ mState,
+ mTimeSinceCreatedMillis);
+ return o;
+ }
+ }
}
diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java
index f580ea5d57de..13a3436569aa 100644
--- a/media/java/android/media/session/MediaSessionManager.java
+++ b/media/java/android/media/session/MediaSessionManager.java
@@ -1127,9 +1127,10 @@ public final class MediaSessionManager {
* toast showing the volume should be shown.
*
* @param sessionToken the remote media session token
- * @param flags extra information about how to handle the volume change
+ * @param flags flags containing extra action or information regarding the volume change
*/
- void onVolumeChanged(@NonNull MediaSession.Token sessionToken, int flags);
+ void onVolumeChanged(@NonNull MediaSession.Token sessionToken,
+ @AudioManager.Flags int flags);
/**
* Called when the default remote session is changed where the default remote session
diff --git a/media/jni/Android.bp b/media/jni/Android.bp
index 4972529eb705..6160b8152295 100644
--- a/media/jni/Android.bp
+++ b/media/jni/Android.bp
@@ -64,6 +64,7 @@ cc_library_shared {
"android.hardware.cas@1.0",
"android.hardware.cas.native@1.0",
"android.hardware.drm@1.3",
+ "android.hardware.drm@1.4",
"android.hidl.memory@1.0",
"android.hidl.token@1.0-utils",
],
diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp
index 0e8719eeb79c..22c3572e963b 100644
--- a/media/jni/android_media_MediaDrm.cpp
+++ b/media/jni/android_media_MediaDrm.cpp
@@ -37,6 +37,7 @@
#include <mediadrm/DrmUtils.h>
#include <mediadrm/IDrmMetricsConsumer.h>
#include <mediadrm/IDrm.h>
+#include <utils/Vector.h>
using ::android::os::PersistableBundle;
namespace drm = ::android::hardware::drm;
@@ -187,6 +188,11 @@ struct KeyStatusFields {
jclass classId;
};
+struct LogMessageFields {
+ jmethodID init;
+ jclass classId;
+};
+
struct fields_t {
jfieldID context;
jmethodID post_event;
@@ -208,6 +214,7 @@ struct fields_t {
jmethodID createFromParcelId;
jclass parcelCreatorClassId;
KeyStatusFields keyStatus;
+ LogMessageFields logMessage;
};
static fields_t gFields;
@@ -224,6 +231,19 @@ jbyteArray hidlVectorToJByteArray(const hardware::hidl_vec<uint8_t> &vector) {
return result;
}
+jobject hidlLogMessagesToJavaList(JNIEnv *env, const Vector<drm::V1_4::LogMessage> &logs) {
+ jclass clazz = gFields.arraylistClassId;
+ jobject arrayList = env->NewObject(clazz, gFields.arraylist.init);
+ clazz = gFields.logMessage.classId;
+ for (auto log: logs) {
+ jobject jLog = env->NewObject(clazz, gFields.logMessage.init,
+ static_cast<jlong>(log.timeMs),
+ static_cast<jint>(log.priority),
+ env->NewStringUTF(log.message.c_str()));
+ env->CallBooleanMethod(arrayList, gFields.arraylist.add, jLog);
+ }
+ return arrayList;
+}
} // namespace anonymous
// ----------------------------------------------------------------------------
@@ -907,6 +927,10 @@ static void android_media_MediaDrm_native_init(JNIEnv *env) {
FIND_CLASS(clazz, "android/media/MediaDrm$KeyStatus");
gFields.keyStatus.classId = static_cast<jclass>(env->NewGlobalRef(clazz));
GET_METHOD_ID(gFields.keyStatus.init, clazz, "<init>", "([BI)V");
+
+ FIND_CLASS(clazz, "android/media/MediaDrm$LogMessage");
+ gFields.logMessage.classId = static_cast<jclass>(env->NewGlobalRef(clazz));
+ GET_METHOD_ID(gFields.logMessage.init, clazz, "<init>", "(JILjava/lang/String;)V");
}
static void android_media_MediaDrm_native_setup(
@@ -1996,6 +2020,22 @@ static void android_media_MediaDrm_setPlaybackId(
throwExceptionAsNecessary(env, err, "Failed to set playbackId");
}
+static jobject android_media_MediaDrm_getLogMessages(
+ JNIEnv *env, jobject thiz) {
+ sp<IDrm> drm = GetDrm(env, thiz);
+ if (!CheckDrm(env, drm)) {
+ return NULL;
+ }
+
+ Vector<drm::V1_4::LogMessage> logs;
+ status_t err = drm->getLogMessages(logs);
+ ALOGI("drm->getLogMessages %zu logs", logs.size());
+ if (throwExceptionAsNecessary(env, err, "Failed to get log messages")) {
+ return NULL;
+ }
+ return hidlLogMessagesToJavaList(env, logs);
+}
+
static const JNINativeMethod gMethods[] = {
{ "native_release", "()V", (void *)android_media_MediaDrm_native_release },
@@ -2123,6 +2163,9 @@ static const JNINativeMethod gMethods[] = {
{ "setPlaybackId", "([BLjava/lang/String;)V",
(void *)android_media_MediaDrm_setPlaybackId },
+
+ { "getLogMessages", "()Ljava/util/List;",
+ (void *)android_media_MediaDrm_getLogMessages },
};
int register_android_media_Drm(JNIEnv *env) {
diff --git a/native/android/Android.bp b/native/android/Android.bp
index 3daaf05fa8d5..253ef679a879 100644
--- a/native/android/Android.bp
+++ b/native/android/Android.bp
@@ -88,7 +88,7 @@ cc_library_shared {
"libarect",
],
- header_libs: [ "libhwui_internal_headers",],
+ header_libs: [ "libhwui_internal_headers", "libandroid_headers_private"],
whole_static_libs: ["libnativewindow"],
diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt
index 7a18bd5ae962..b01878b3070b 100644
--- a/native/android/libandroid.map.txt
+++ b/native/android/libandroid.map.txt
@@ -300,3 +300,13 @@ LIBANDROID {
local:
*;
};
+
+LIBANDROID_PLATFORM {
+ global:
+ extern "C++" {
+ ASurfaceControl_registerSurfaceStatsListener*;
+ ASurfaceControl_unregisterSurfaceStatsListener*;
+ ASurfaceControlStats_getAcquireTime*;
+ ASurfaceControlStats_getFrameNumber*;
+ };
+} LIBANDROID; \ No newline at end of file
diff --git a/native/android/surface_control.cpp b/native/android/surface_control.cpp
index c1b5f1ddd423..e51add276647 100644
--- a/native/android/surface_control.cpp
+++ b/native/android/surface_control.cpp
@@ -17,6 +17,7 @@
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <android/native_window.h>
#include <android/surface_control.h>
+#include <surface_control_private.h>
#include <configstore/Utils.h>
@@ -197,6 +198,48 @@ void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) {
SurfaceControl_release(surfaceControl);
}
+struct ASurfaceControlStats {
+ int64_t acquireTime;
+ sp<Fence> previousReleaseFence;
+ uint64_t frameNumber;
+};
+
+void ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl* control, void* context,
+ ASurfaceControl_SurfaceStatsListener func) {
+ SurfaceStatsCallback callback = [func](void* callback_context,
+ nsecs_t,
+ const sp<Fence>&,
+ const SurfaceStats& surfaceStats) {
+
+ ASurfaceControlStats aSurfaceControlStats;
+
+ ASurfaceControl* aSurfaceControl =
+ reinterpret_cast<ASurfaceControl*>(surfaceStats.surfaceControl.get());
+ aSurfaceControlStats.acquireTime = surfaceStats.acquireTime;
+ aSurfaceControlStats.previousReleaseFence = surfaceStats.previousReleaseFence;
+ aSurfaceControlStats.frameNumber = surfaceStats.eventStats.frameNumber;
+
+ (*func)(callback_context, aSurfaceControl, &aSurfaceControlStats);
+ };
+ TransactionCompletedListener::getInstance()->addSurfaceStatsListener(context,
+ reinterpret_cast<void*>(func), ASurfaceControl_to_SurfaceControl(control), callback);
+}
+
+
+void ASurfaceControl_unregisterSurfaceStatsListener(void* context,
+ ASurfaceControl_SurfaceStatsListener func) {
+ TransactionCompletedListener::getInstance()->removeSurfaceStatsListener(context,
+ reinterpret_cast<void*>(func));
+}
+
+int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
+ return stats->acquireTime;
+}
+
+uint64_t ASurfaceControlStats_getFrameNumber(ASurfaceControlStats* stats) {
+ return stats->frameNumber;
+}
+
ASurfaceTransaction* ASurfaceTransaction_create() {
Transaction* transaction = new Transaction;
return reinterpret_cast<ASurfaceTransaction*>(transaction);
@@ -215,11 +258,6 @@ void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) {
transaction->apply();
}
-typedef struct ASurfaceControlStats {
- int64_t acquireTime;
- sp<Fence> previousReleaseFence;
-} ASurfaceControlStats;
-
struct ASurfaceTransactionStats {
std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats;
int64_t latchTime;
diff --git a/packages/Connectivity/framework/src/android/net/ConnectivityManager.java b/packages/Connectivity/framework/src/android/net/ConnectivityManager.java
index 92d7bf06aa9e..d7c8291c6676 100644
--- a/packages/Connectivity/framework/src/android/net/ConnectivityManager.java
+++ b/packages/Connectivity/framework/src/android/net/ConnectivityManager.java
@@ -456,7 +456,7 @@ public class ConnectivityManager {
* @hide
*/
@SystemApi
- public static final int TETHERING_WIFI = TetheringManager.TETHERING_WIFI;
+ public static final int TETHERING_WIFI = 0;
/**
* USB tethering type.
@@ -464,7 +464,7 @@ public class ConnectivityManager {
* @hide
*/
@SystemApi
- public static final int TETHERING_USB = TetheringManager.TETHERING_USB;
+ public static final int TETHERING_USB = 1;
/**
* Bluetooth tethering type.
@@ -472,7 +472,7 @@ public class ConnectivityManager {
* @hide
*/
@SystemApi
- public static final int TETHERING_BLUETOOTH = TetheringManager.TETHERING_BLUETOOTH;
+ public static final int TETHERING_BLUETOOTH = 2;
/**
* Wifi P2p tethering type.
@@ -2799,7 +2799,7 @@ public class ConnectivityManager {
*/
@SystemApi
@Deprecated
- public static final int TETHER_ERROR_NO_ERROR = TetheringManager.TETHER_ERROR_NO_ERROR;
+ public static final int TETHER_ERROR_NO_ERROR = 0;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_UNKNOWN_IFACE}.
* {@hide}
@@ -2875,8 +2875,7 @@ public class ConnectivityManager {
*/
@SystemApi
@Deprecated
- public static final int TETHER_ERROR_PROVISION_FAILED =
- TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
+ public static final int TETHER_ERROR_PROVISION_FAILED = 11;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_DHCPSERVER_ERROR}.
* {@hide}
@@ -2890,8 +2889,7 @@ public class ConnectivityManager {
*/
@SystemApi
@Deprecated
- public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN =
- TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
+ public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13;
/**
* Get a more detailed error code after a Tethering or Untethering
diff --git a/packages/Connectivity/framework/src/android/net/TestNetworkManager.java b/packages/Connectivity/framework/src/android/net/TestNetworkManager.java
index 4e894143bf91..a174a7be85d1 100644
--- a/packages/Connectivity/framework/src/android/net/TestNetworkManager.java
+++ b/packages/Connectivity/framework/src/android/net/TestNetworkManager.java
@@ -41,7 +41,6 @@ public class TestNetworkManager {
/**
* Prefix for tap interfaces created by this class.
- * @hide
*/
public static final String TEST_TAP_PREFIX = "testtap";
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
index 927da0ae8495..2b357c57b306 100644
--- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
+++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
@@ -396,6 +396,28 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
}
/**
+ * Check if USB data signaling (except from charging functions) is disabled by the admin.
+ * Only a device owner or a profile owner on an organization-owned managed profile can disable
+ * USB data signaling.
+ *
+ * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
+ * or {@code null} if USB data signaling is not disabled.
+ */
+ public static EnforcedAdmin checkIfUsbDataSignalingIsDisabled(Context context, int userId) {
+ DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+ if (dpm == null || dpm.isUsbDataSignalingEnabledForUser(userId)) {
+ return null;
+ } else {
+ EnforcedAdmin admin = getProfileOrDeviceOwner(context, getUserHandleOf(userId));
+ int managedProfileId = getManagedProfileId(context, userId);
+ if (admin == null && managedProfileId != UserHandle.USER_NULL) {
+ admin = getProfileOrDeviceOwner(context, getUserHandleOf(managedProfileId));
+ }
+ return admin;
+ }
+ }
+
+ /**
* Check if {@param packageName} is restricted by the profile or device owner from using
* metered data.
*
diff --git a/packages/SettingsLib/src/com/android/settingslib/connectivity/ConnectivitySubsystemsRecoveryManager.java b/packages/SettingsLib/src/com/android/settingslib/connectivity/ConnectivitySubsystemsRecoveryManager.java
index 64cb0f1b7885..43717aba3abd 100644
--- a/packages/SettingsLib/src/com/android/settingslib/connectivity/ConnectivitySubsystemsRecoveryManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/connectivity/ConnectivitySubsystemsRecoveryManager.java
@@ -196,7 +196,7 @@ public class ConnectivitySubsystemsRecoveryManager {
}
private void stopTrackingWifiRestart() {
- mWifiManager.unregisterWifiSubsystemRestartTrackingCallback(
+ mWifiManager.unregisterSubsystemRestartTrackingCallback(
mWifiSubsystemRestartTrackingCallback);
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java b/packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java
index caabf9af35f6..1474f184775d 100644
--- a/packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java
+++ b/packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java
@@ -16,10 +16,13 @@
package com.android.settingslib.development;
+import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfUsbDataSignalingIsDisabled;
+
import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
@@ -28,9 +31,9 @@ import androidx.annotation.VisibleForTesting;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
import androidx.preference.TwoStatePreference;
+import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.core.ConfirmationDialogController;
public abstract class AbstractEnableAdbPreferenceController extends
@@ -44,7 +47,7 @@ public abstract class AbstractEnableAdbPreferenceController extends
public static final int ADB_SETTING_OFF = 0;
- protected SwitchPreference mPreference;
+ protected RestrictedSwitchPreference mPreference;
public AbstractEnableAdbPreferenceController(Context context) {
super(context);
@@ -54,7 +57,7 @@ public abstract class AbstractEnableAdbPreferenceController extends
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (isAvailable()) {
- mPreference = (SwitchPreference) screen.findPreference(KEY_ENABLE_ADB);
+ mPreference = (RestrictedSwitchPreference) screen.findPreference(KEY_ENABLE_ADB);
}
}
@@ -77,6 +80,10 @@ public abstract class AbstractEnableAdbPreferenceController extends
@Override
public void updateState(Preference preference) {
((TwoStatePreference) preference).setChecked(isAdbEnabled());
+ if (isAvailable()) {
+ ((RestrictedSwitchPreference) preference).setDisabledByAdmin(
+ checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
+ }
}
public void enablePreference(boolean enabled) {
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/development/EnableAdbPreferenceControllerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/development/EnableAdbPreferenceControllerTest.java
index e84a25c0ba4e..5f53a92c131e 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/development/EnableAdbPreferenceControllerTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/development/EnableAdbPreferenceControllerTest.java
@@ -19,18 +19,24 @@ package com.android.settingslib.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
+
+import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -43,26 +49,34 @@ import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class EnableAdbPreferenceControllerTest {
+
+ private static final ComponentName TEST_COMPONENT_NAME = new ComponentName("test", "test");
+
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private UserManager mUserManager;
@Mock
private PackageManager mPackageManager;
+ @Mock
+ private DevicePolicyManager mDevicePolicyManager;
private Context mContext;
- private SwitchPreference mPreference;
+ private RestrictedSwitchPreference mPreference;
private ConcreteEnableAdbPreferenceController mController;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowContext = ShadowApplication.getInstance();
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDevicePolicyManager);
+ doReturn(mContext).when(mContext).createPackageContextAsUser(
+ any(String.class), anyInt(), any(UserHandle.class));
mController = new ConcreteEnableAdbPreferenceController(mContext);
- mPreference = new SwitchPreference(mContext);
+ mPreference = new RestrictedSwitchPreference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@@ -125,6 +139,9 @@ public class EnableAdbPreferenceControllerTest {
@Test
public void updateState_settingsOn_shouldCheck() {
when(mUserManager.isAdminUser()).thenReturn(true);
+ when(mDevicePolicyManager.getProfileOwner()).thenReturn(TEST_COMPONENT_NAME);
+ when(mDevicePolicyManager.isUsbDataSignalingEnabledForUser(
+ UserHandle.myUserId())).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ADB_ENABLED, 1);
mPreference.setChecked(false);
@@ -138,6 +155,9 @@ public class EnableAdbPreferenceControllerTest {
@Test
public void updateState_settingsOff_shouldUncheck() {
when(mUserManager.isAdminUser()).thenReturn(true);
+ when(mDevicePolicyManager.getProfileOwner()).thenReturn(TEST_COMPONENT_NAME);
+ when(mDevicePolicyManager.isUsbDataSignalingEnabledForUser(
+ UserHandle.myUserId())).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ADB_ENABLED, 0);
mPreference.setChecked(true);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
index a6e2af9b1674..9cd7083a2a11 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
@@ -24,6 +24,7 @@ import android.app.backup.FullBackupDataOutput;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.NetworkPolicy;
import android.net.NetworkPolicyManager;
@@ -212,7 +213,6 @@ public class SettingsBackupAgent extends BackupAgentHelper {
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
-
byte[] systemSettingsData = getSystemSettings();
byte[] secureSettingsData = getSecureSettings();
byte[] globalSettingsData = getGlobalSettings();
@@ -1204,17 +1204,25 @@ public class SettingsBackupAgent extends BackupAgentHelper {
}
private byte[] getSimSpecificSettingsData() {
- SubscriptionManager subManager = SubscriptionManager.from(getBaseContext());
- byte[] simSpecificData = subManager.getAllSimSpecificSettingsForBackup();
- Log.i(TAG, "sim specific data of length + " + simSpecificData.length
+ byte[] simSpecificData = new byte[0];
+ PackageManager packageManager = getBaseContext().getPackageManager();
+ if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+ SubscriptionManager subManager = SubscriptionManager.from(getBaseContext());
+ simSpecificData = subManager.getAllSimSpecificSettingsForBackup();
+ Log.i(TAG, "sim specific data of length + " + simSpecificData.length
+ " successfully retrieved");
+ }
return simSpecificData;
}
private void restoreSimSpecificSettings(byte[] data) {
- SubscriptionManager subManager = SubscriptionManager.from(getBaseContext());
- subManager.restoreAllSimSpecificSettingsFromBackup(data);
+ PackageManager packageManager = getBaseContext().getPackageManager();
+ boolean hasTelephony = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
+ if (hasTelephony) {
+ SubscriptionManager subManager = SubscriptionManager.from(getBaseContext());
+ subManager.restoreAllSimSpecificSettingsFromBackup(data);
+ }
}
private void updateWindowManagerIfNeeded(Integer previousDensity) {
diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
index 438cec8ef68f..6719f179ef86 100644
--- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
+++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
@@ -323,6 +323,7 @@ public class SettingsBackupTest {
Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS,
Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS,
Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST,
+ Settings.Global.LOCATION_ENABLE_STATIONARY_THROTTLE,
Settings.Global.LOCATION_IGNORE_SETTINGS_PACKAGE_WHITELIST,
Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
Settings.Global.LOCK_SOUND,
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index 35a4e81eefe4..a15ceb6d8811 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -100,6 +100,7 @@
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.POWER_SAVER" />
+ <uses-permission android:name="android.permission.BATTERY_PREDICTION" />
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" />
<uses-permission android:name="android.permission.BACKUP" />
<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" />
@@ -344,6 +345,12 @@
<!-- Permissions required for CTS test - AdbManagerTest -->
<uses-permission android:name="android.permission.MANAGE_DEBUGGING" />
+ <!-- Permission required for CTS test - CtsTelephonyTestCases -->
+ <uses-permission android:name="android.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE" />
+
+ <!-- Permission required for CTS test - CtsTelephonyTestCases -->
+ <uses-permission android:name="android.permission.PERFORM_IMS_SINGLE_REGISTRATION" />
+
<!-- Permission needed for CTS test - DisplayTest -->
<uses-permission android:name="android.permission.OVERRIDE_DISPLAY_MODE_REQUESTS" />
@@ -405,6 +412,9 @@
<!-- Permission required for CTS test - CtsRebootReadinessTestCases -->
<uses-permission android:name="android.permission.SIGNAL_REBOOT_READINESS" />
+ <!-- Permission required for CTS test - PeopleManagerTest -->
+ <uses-permission android:name="android.permission.READ_PEOPLE_DATA" />
+
<application android:label="@string/app_label"
android:theme="@android:style/Theme.DeviceDefault.DayNight"
android:defaultToDeviceProtectedStorage="true"
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp
index 7bfb42b7cfad..bf5198eadb9c 100644
--- a/packages/SystemUI/Android.bp
+++ b/packages/SystemUI/Android.bp
@@ -194,6 +194,5 @@ android_app {
dxflags: ["--multi-dex"],
required: [
"privapp_whitelist_com.android.systemui",
- "checked-wm_shell_protolog.json",
],
}
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 5af024448987..2faca8dbdcbf 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -600,6 +600,14 @@
android:permission="android.permission.BIND_REMOTEVIEWS"
android:exported="false" />
+ <!-- ContentProvider that returns a People Tile preview for a given shortcut -->
+ <provider
+ android:name="com.android.systemui.people.PeopleProvider"
+ android:authorities="com.android.systemui.people.PeopleProvider"
+ android:exported="true"
+ android:permission="android.permission.GET_PEOPLE_TILE_PREVIEW">
+ </provider>
+
<!-- a gallery of delicious treats -->
<service
android:name=".DessertCaseDream"
diff --git a/packages/SystemUI/README.md b/packages/SystemUI/README.md
index ee8d02301d5d..60994d892b6e 100644
--- a/packages/SystemUI/README.md
+++ b/packages/SystemUI/README.md
@@ -144,6 +144,10 @@ Biometric UI.
Delegates SysUI events to WM Shell controllers.
+### [com.android.systemui.people.widget.PeopleSpaceWidgetEnabler](/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetEnabler.java)
+
+Enables People Space widgets.
+
---
* [Plugins](/packages/SystemUI/docs/plugins.md)
diff --git a/packages/SystemUI/res-keyguard/drawable/ripple_drawable_pin.xml b/packages/SystemUI/res-keyguard/drawable/ripple_drawable_pin.xml
new file mode 100644
index 000000000000..51c442abf2fd
--- /dev/null
+++ b/packages/SystemUI/res-keyguard/drawable/ripple_drawable_pin.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight"
+ android:radius="40dp"/>
diff --git a/packages/SystemUI/res/drawable/circle_green_10dp.xml b/packages/SystemUI/res/drawable/circle_green_10dp.xml
new file mode 100644
index 000000000000..571ec621da9f
--- /dev/null
+++ b/packages/SystemUI/res/drawable/circle_green_10dp.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="10dp"
+ android:width="10dp" />
+ <solid android:color="#34A853" />
+</shape> \ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/people_space_content_background.xml b/packages/SystemUI/res/drawable/people_space_content_background.xml
index 5310840939b8..32314d29277e 100644
--- a/packages/SystemUI/res/drawable/people_space_content_background.xml
+++ b/packages/SystemUI/res/drawable/people_space_content_background.xml
@@ -16,5 +16,5 @@
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="?android:attr/colorControlHighlight" />
- <corners android:radius="@dimen/people_space_widget_radius" />
+ <corners android:radius="@dimen/people_space_image_radius" />
</shape>
diff --git a/packages/SystemUI/res/drawable/people_space_round_tile_view_card.xml b/packages/SystemUI/res/drawable/people_space_new_story_outline.xml
index 59af7750dada..a1737f92fa22 100644
--- a/packages/SystemUI/res/drawable/people_space_round_tile_view_card.xml
+++ b/packages/SystemUI/res/drawable/people_space_new_story_outline.xml
@@ -13,7 +13,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
<solid android:color="?android:attr/colorBackground" />
- <corners android:radius="@dimen/people_space_widget_round_radius" />
+ <stroke android:width="2dp" android:color="?android:attr/colorAccent" />
</shape> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/people_space_large_avatar_tile.xml b/packages/SystemUI/res/layout/people_space_large_avatar_tile.xml
index e9f3424547fa..b1c13287d203 100644
--- a/packages/SystemUI/res/layout/people_space_large_avatar_tile.xml
+++ b/packages/SystemUI/res/layout/people_space_large_avatar_tile.xml
@@ -19,70 +19,78 @@
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
- android:background="@drawable/people_space_round_tile_view_card"
+ android:background="@drawable/people_space_tile_view_card"
android:id="@+id/item"
- android:paddingVertical="6dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
- android:gravity="center_vertical"
- android:paddingStart="12dp"
+ android:gravity="center"
+ android:paddingVertical="2dp"
+ android:paddingHorizontal="8dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+ <LinearLayout
+ android:background="@drawable/people_space_new_story_outline"
+ android:id="@+id/person_icon_with_story"
+ android:gravity="center_horizontal"
+ android:layout_width="60dp"
+ android:layout_height="60dp">
<ImageView
- android:id="@+id/person_icon"
- android:layout_width="60dp"
- android:layout_height="60dp" />
-
- <LinearLayout
- android:background="@drawable/people_space_rounded_border"
- android:layout_marginStart="-12dp"
- android:layout_marginTop="28dp"
- android:layout_marginBottom="14dp"
- android:layout_width="16dp"
- android:layout_height="16dp">
+ android:id="@+id/person_icon_inside_ring"
+ android:layout_marginEnd="4dp"
+ android:layout_marginStart="4dp"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:layout_width="52dp"
+ android:layout_height="52dp"/>
+ </LinearLayout>
+ <ImageView
+ android:id="@+id/person_icon_only"
+ android:layout_width="60dp"
+ android:layout_height="60dp"/>
- <ImageView
- android:id="@+id/package_icon"
- android:layout_width="12dp"
- android:layout_marginStart="2dp"
- android:layout_marginEnd="2dp"
- android:layout_marginBottom="2dp"
- android:layout_marginTop="2dp"
- android:layout_height="12dp" />
- </LinearLayout>
+ <ImageView
+ android:id="@+id/package_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginStart="-20dp"
+ android:layout_marginTop="22dp"/>
<LinearLayout
android:orientation="vertical"
android:paddingStart="8dp"
- android:paddingEnd="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
+ <ImageView
+ android:id="@+id/availability"
+ android:layout_width="10dp"
+ android:layout_height="10dp"
+ android:background="@drawable/circle_green_10dp"/>
<TextView
android:id="@+id/name"
+ android:text="@string/empty_user_name"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
android:textColor="?android:attr/textColorPrimary"
- android:textSize="16sp"
+ android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
+ android:layout_height="wrap_content"/>
<TextView
- android:id="@+id/status"
+ android:id="@+id/last_interaction"
+ android:text="@string/empty_status"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:paddingVertical="3dp"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
- android:ellipsize="end" />
+ android:ellipsize="end"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
diff --git a/packages/SystemUI/res/layout/people_space_notification_content_tile.xml b/packages/SystemUI/res/layout/people_space_notification_content_tile.xml
new file mode 100644
index 000000000000..739738ae9e35
--- /dev/null
+++ b/packages/SystemUI/res/layout/people_space_notification_content_tile.xml
@@ -0,0 +1,154 @@
+<?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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <RelativeLayout
+ android:background="@drawable/people_space_tile_view_card"
+ android:id="@+id/people_tile"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <include layout="@layout/punctuation_layout"/>
+ <RelativeLayout
+ android:gravity="start"
+ android:id="@+id/column_one"
+ android:paddingVertical="10dp"
+ android:paddingStart="8dp"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent">
+ <TextView
+ android:id="@+id/subtext"
+ android:layout_toStartOf="@+id/content_layout"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentTop="true"
+ android:gravity="top|start"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="12sp"
+ android:maxWidth="60dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:maxLines="1"
+ android:ellipsize="end"/>
+ <LinearLayout
+ android:orientation="horizontal"
+ android:id="@+id/avatar_and_app_icon"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentStart="true"
+ android:gravity="center"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+ <LinearLayout
+ android:id="@+id/person_icon_with_story"
+ android:background="@drawable/people_space_new_story_outline"
+ android:gravity="center_horizontal"
+ android:layout_width="48dp"
+ android:layout_height="48dp">
+ <ImageView
+ android:id="@+id/person_icon_inside_ring"
+ android:layout_marginEnd="4dp"
+ android:layout_marginStart="4dp"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:layout_width="40dp"
+ android:layout_height="40dp"/>
+ </LinearLayout>
+ <ImageView
+ android:id="@+id/person_icon_only"
+ android:layout_width="48dp"
+ android:layout_height="48dp"/>
+ <ImageView
+ android:id="@id/package_icon"
+ android:layout_marginStart="-16dp"
+ android:layout_marginTop="18dp"
+ android:paddingBottom="10dp"
+ android:paddingEnd="8dp"
+ android:layout_width="28dp"
+ android:layout_height="32dp"/>
+ </LinearLayout>
+ </RelativeLayout>
+ <LinearLayout
+ android:id="@+id/content_layout"
+ android:paddingBottom="4dp"
+ android:paddingStart="4dp"
+ android:paddingTop="8dp"
+ android:paddingEnd="8dp"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentTop="true"
+ android:layout_toEndOf="@id/column_one"
+ android:gravity="top|end"
+ android:orientation="vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+ <TextView
+ android:id="@+id/content"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textColor="?android:attr/textColorPrimary"
+ android:gravity="top|end"
+ android:textSize="12sp"
+ android:paddingTop="2dp"
+ android:paddingEnd="4dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:maxLines="2"
+ android:ellipsize="end"/>
+ <LinearLayout
+ android:id="@+id/content_background"
+ android:background="@drawable/people_space_content_background"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <ImageView
+ android:id="@+id/image"
+ android:adjustViewBounds="true"
+ android:maxHeight="44dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:scaleType="centerCrop"/>
+ </LinearLayout>
+ </LinearLayout>
+ <LinearLayout
+ android:id="@+id/person_label"
+ android:paddingBottom="10dp"
+ android:paddingEnd="8dp"
+ android:gravity="start|bottom"
+ android:layout_toEndOf="@id/column_one"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true"
+ android:layout_below="@id/content_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <ImageView
+ android:id="@+id/availability"
+ android:layout_width="10dp"
+ android:layout_height="10dp"
+ android:paddingVertical="2dp"
+ android:background="@drawable/circle_green_10dp"/>
+ <TextView
+ android:id="@+id/name"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textColor="?android:attr/textColorPrimary"
+ android:textSize="14sp"
+ android:maxLines="1"
+ android:ellipsize="end"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+ </LinearLayout>
+ </RelativeLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml b/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml
index 03589d34efd2..bb4a20e4108e 100644
--- a/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml
+++ b/packages/SystemUI/res/layout/people_space_small_avatar_tile.xml
@@ -14,183 +14,144 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:background="@drawable/people_space_tile_view_card"
+ android:id="@+id/people_tile"
android:layout_width="match_parent"
android:layout_height="match_parent">
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="start">
- <TextView
- android:id="@+id/punctuation1"
- android:textColor="?android:attr/textColorSecondary"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="36sp"
- android:textStyle="bold"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dp"
- android:maxLines="1"
- android:alpha="0.2"
- android:rotation="350" />
- <TextView
- android:id="@+id/punctuation2"
- android:textColor="?android:attr/textColorSecondary"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="36sp"
- android:textStyle="bold"
+ <RelativeLayout
+ android:gravity="start"
+ android:id="@+id/column_one"
+ android:paddingVertical="8dp"
+ android:paddingStart="8dp"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent">
+ <LinearLayout
+ android:orientation="horizontal"
+ android:id="@+id/content_background"
+ android:background="@drawable/people_space_content_background"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentTop="true"
+ android:layout_width="60dp"
+ android:layout_height="60dp">
+ <ImageView
+ android:id="@+id/image"
+ android:gravity="center"
+ android:background="@drawable/people_space_content_background"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:scaleType="centerCrop"/>
+ <ImageView
+ android:id="@+id/status_defined_icon"
+ android:gravity="start|top"
+ android:layout_marginStart="-52dp"
+ android:layout_marginTop="8dp"
+ android:layout_width="18dp"
+ android:layout_height="18dp"/>
+ </LinearLayout>
+ <LinearLayout
+ android:orientation="horizontal"
+ android:id="@+id/avatar_and_app_icon"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentStart="true"
+ android:paddingStart="4dp"
+ android:gravity="center"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="25dp"
- android:maxLines="1"
- android:alpha="0.2"
- android:rotation="5" />
+ android:layout_height="wrap_content">
+ <LinearLayout
+ android:id="@+id/person_icon_with_story"
+ android:background="@drawable/people_space_new_story_outline"
+ android:gravity="center_horizontal"
+ android:layout_width="48dp"
+ android:layout_height="48dp">
+ <ImageView
+ android:id="@+id/person_icon_inside_ring"
+ android:layout_marginEnd="4dp"
+ android:layout_marginStart="4dp"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:layout_width="40dp"
+ android:layout_height="40dp"/>
+ </LinearLayout>
+ <ImageView
+ android:id="@+id/person_icon_only"
+ android:layout_width="48dp"
+ android:layout_height="48dp"/>
+ <ImageView
+ android:id="@id/package_icon"
+ android:layout_marginStart="-16dp"
+ android:layout_marginTop="18dp"
+ android:paddingBottom="10dp"
+ android:paddingEnd="8dp"
+ android:layout_width="28dp"
+ android:layout_height="32dp"/>
+ </LinearLayout>
+ </RelativeLayout>
+ <LinearLayout
+ android:id="@+id/content_layout"
+ android:paddingTop="10dp"
+ android:paddingBottom="4dp"
+ android:paddingHorizontal="8dp"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentTop="true"
+ android:layout_toEndOf="@id/column_one"
+ android:gravity="top|end"
+ android:orientation="vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
<TextView
- android:id="@+id/punctuation3"
- android:textColor="?android:attr/textColorSecondary"
+ android:id="@+id/status"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="36sp"
- android:textStyle="bold"
+ android:textColor="?android:attr/textColorPrimary"
+ android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="5dp"
- android:layout_marginStart="25dp"
- android:maxLines="1"
- android:alpha="0.2"
- android:rotation="355"/>
+ android:maxLines="2"
+ android:ellipsize="end"/>
+ </LinearLayout>
+ <LinearLayout
+ android:id="@+id/person_label"
+ android:paddingBottom="10dp"
+ android:paddingEnd="8dp"
+ android:gravity="start|bottom"
+ android:layout_toEndOf="@id/column_one"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true"
+ android:layout_below="@id/content_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
<TextView
- android:id="@+id/punctuation4"
+ android:id="@+id/time"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="36sp"
- android:textStyle="bold"
+ android:textSize="12sp"
+ android:paddingVertical="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="-5dp"
- android:layout_marginStart="25dp"
android:maxLines="1"
- android:alpha="0.2"
- android:rotation="10" />
+ android:visibility="gone"
+ android:ellipsize="end"/>
+ <ImageView
+ android:id="@+id/availability"
+ android:layout_width="10dp"
+ android:layout_height="10dp"
+ android:paddingVertical="2dp"
+ android:background="@drawable/circle_green_10dp"/>
<TextView
- android:id="@+id/punctuation5"
- android:textColor="?android:attr/textColorSecondary"
+ android:id="@+id/name"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="36sp"
- android:textStyle="bold"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dp"
- android:layout_marginStart="25dp"
+ android:textColor="?android:attr/textColorPrimary"
+ android:textSize="14sp"
android:maxLines="1"
- android:alpha="0.2"
- android:rotation="15" />
- <TextView
- android:id="@+id/punctuation6"
- android:textColor="?android:attr/textColorSecondary"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="36sp"
- android:textStyle="bold"
+ android:ellipsize="end"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="-5dp"
- android:layout_marginStart="25dp"
- android:maxLines="1"
- android:alpha="0.2"
- android:rotation="345" />
- </LinearLayout>
- <LinearLayout
- android:id="@+id/item"
- android:orientation="vertical"
- android:paddingTop="6dp"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <LinearLayout
- android:orientation="horizontal"
- android:paddingHorizontal="12dp"
- android:paddingBottom="4dp"
- android:gravity="top"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <ImageView
- android:id="@+id/person_icon"
- android:layout_width="34dp"
- android:layout_height="34dp" />
-
- <LinearLayout
- android:background="@drawable/people_space_rounded_border"
- android:layout_marginStart="-5dp"
- android:layout_marginTop="18dp"
- android:layout_width="8dp"
- android:layout_height="8dp">
-
- <ImageView
- android:id="@+id/package_icon"
- android:layout_width="6dp"
- android:layout_marginEnd="1dp"
- android:layout_marginStart="1dp"
- android:layout_marginBottom="1dp"
- android:layout_marginTop="1dp"
- android:layout_height="6dp" />
- </LinearLayout>
-
- <LinearLayout
- android:orientation="vertical"
- android:paddingStart="6dp"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/name"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textColor="?android:attr/textColorPrimary"
- android:textSize="14sp"
- android:maxLines="1"
- android:ellipsize="end"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- <TextView
- android:id="@+id/time"
- android:textColor="?android:attr/textColorSecondary"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="10sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxLines="1"
- android:ellipsize="end" />
- </LinearLayout>
- </LinearLayout>
- <LinearLayout
- android:id="@+id/content_background"
- android:background="@drawable/people_space_content_background"
- android:layout_gravity="center"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView
- android:id="@+id/content"
- android:paddingVertical="3dp"
- android:paddingHorizontal="12dp"
- android:gravity="center"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
- android:textSize="16sp"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:maxLines="2"
- android:ellipsize="end" />
- <ImageView
- android:id="@+id/image"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:visibility="gone"
- android:scaleType="centerCrop"/>
- </LinearLayout>
+ android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/punctuation_layout.xml b/packages/SystemUI/res/layout/punctuation_layout.xml
new file mode 100644
index 000000000000..25c7648530d6
--- /dev/null
+++ b/packages/SystemUI/res/layout/punctuation_layout.xml
@@ -0,0 +1,100 @@
+<?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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/punctuation_layout"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="start">
+ <TextView
+ android:id="@+id/punctuation1"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="36sp"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dp"
+ android:maxLines="1"
+ android:alpha="0.2"
+ android:rotation="350"/>
+ <TextView
+ android:id="@+id/punctuation2"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="36sp"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="25dp"
+ android:maxLines="1"
+ android:alpha="0.2"
+ android:rotation="5"/>
+ <TextView
+ android:id="@+id/punctuation3"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="36sp"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dp"
+ android:layout_marginStart="25dp"
+ android:maxLines="1"
+ android:alpha="0.2"
+ android:rotation="355"/>
+ <TextView
+ android:id="@+id/punctuation4"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="36sp"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="-5dp"
+ android:layout_marginStart="25dp"
+ android:maxLines="1"
+ android:alpha="0.2"
+ android:rotation="10"/>
+ <TextView
+ android:id="@+id/punctuation5"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="36sp"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dp"
+ android:layout_marginStart="25dp"
+ android:maxLines="1"
+ android:alpha="0.2"
+ android:rotation="15"/>
+ <TextView
+ android:id="@+id/punctuation6"
+ android:textColor="?android:attr/textColorSecondary"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.ListItem"
+ android:textSize="36sp"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="-5dp"
+ android:layout_marginStart="25dp"
+ android:maxLines="1"
+ android:alpha="0.2"
+ android:rotation="345"/>
+</LinearLayout> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml
index 67a933df6692..a8ef7c346b95 100644
--- a/packages/SystemUI/res/layout/status_bar_expanded.xml
+++ b/packages/SystemUI/res/layout/status_bar_expanded.xml
@@ -69,6 +69,13 @@
systemui:layout_constraintEnd_toEndOf="parent"
/>
+ <androidx.constraintlayout.widget.Guideline
+ android:id="@+id/qs_edge_guideline"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ systemui:layout_constraintGuide_percent="0.5"
+ android:orientation="vertical"/>
+
<com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout
android:id="@+id/notification_stack_scroller"
android:layout_marginTop="@dimen/notification_panel_margin_top"
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 78927f8bf8d4..13c01102d032 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -312,6 +312,7 @@
<item>com.android.systemui.accessibility.SystemActions</item>
<item>com.android.systemui.toast.ToastUI</item>
<item>com.android.systemui.wmshell.WMShell</item>
+ <item>com.android.systemui.people.widget.PeopleSpaceWidgetEnabler</item>
</string-array>
<!-- QS tile shape store width. negative implies fill configuration instead of stroke-->
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 0d92aea6ed6f..b07df9caa95b 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1348,8 +1348,8 @@
<dimen name="media_output_dialog_icon_corner_radius">16dp</dimen>
<dimen name="media_output_dialog_title_anim_y_delta">12.5dp</dimen>
- <dimen name="people_space_widget_radius">24dp</dimen>
- <dimen name="people_space_widget_round_radius">100dp</dimen>
+ <dimen name="people_space_widget_radius">28dp</dimen>
+ <dimen name="people_space_image_radius">20dp</dimen>
<dimen name="people_space_widget_background_padding">6dp</dimen>
<dimen name="rounded_slider_height">48dp</dimen>
diff --git a/packages/SystemUI/res/values/flags.xml b/packages/SystemUI/res/values/flags.xml
index 6d731f8587b6..d4bb128120e9 100644
--- a/packages/SystemUI/res/values/flags.xml
+++ b/packages/SystemUI/res/values/flags.xml
@@ -38,5 +38,8 @@
<!-- People Tile flag -->
<bool name="flag_conversations">false</bool>
+ <!-- The new animations to/from lockscreen and AOD! -->
+ <bool name="flag_lockscreen_animations">false</bool>
+
<bool name="flag_toast_style">false</bool>
</resources>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index d997ca2fa4a4..3b42600076ac 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -247,6 +247,10 @@
<string name="screenshot_dismiss_description">Dismiss screenshot</string>
<!-- Content description indicating that the view is a preview of the screenshot that was just taken [CHAR LIMIT=NONE] -->
<string name="screenshot_preview_description">Screenshot preview</string>
+ <!-- Content description for the top boundary of the screenshot being cropped [CHAR LIMIT=NONE] -->
+ <string name="screenshot_top_boundary">Top boundary</string>
+ <!-- Content description for the bottom boundary of the screenshot being cropped [CHAR LIMIT=NONE] -->
+ <string name="screenshot_bottom_boundary">Bottom boundary</string>
<!-- Notification title displayed for screen recording [CHAR LIMIT=50]-->
<string name="screenrecord_name">Screen Recorder</string>
@@ -1341,6 +1345,9 @@
<!-- Monitoring dialog: Description of Network Logging. [CHAR LIMIT=NONE]-->
<string name="monitoring_description_management_network_logging">Your admin has turned on network logging, which monitors traffic on your device.</string>
+ <!-- Monitoring dialog: Description of Network Logging in the work profile. [CHAR LIMIT=NONE]-->
+ <string name="monitoring_description_managed_profile_network_logging">Your admin has turned on network logging, which monitors traffic in your work profile but not in your personal profile.</string>
+
<!-- Monitoring dialog: Description of an active VPN. [CHAR LIMIT=NONE]-->
<string name="monitoring_description_named_vpn">You\'re connected to <xliff:g id="vpn_app" example="Foo VPN App">%1$s</xliff:g>, which can monitor your network activity, including emails, apps, and websites.</string>
@@ -2810,8 +2817,26 @@
<string name="less_than_timestamp" translatable="false">Less than <xliff:g id="duration" example="5 hours">%1$s</xliff:g> ago</string>
<!-- Timestamp for notification when over a certain time window [CHAR LIMIT=120] -->
<string name="over_timestamp" translatable="false">Over <xliff:g id="duration" example="1 week">%1$s</xliff:g> ago</string>
- <!-- Status text for a birthday today [CHAR LIMIT=120] -->
- <string name="birthday_status" translatable="false">Today is their birthday!</string>
+ <!-- Status text for a birthday today [CHAR LIMIT=30] -->
+ <string name="birthday_status" translatable="false">Birthday</string>
+ <!-- Status text for an upcoming birthday [CHAR LIMIT=30] -->
+ <string name="upcoming_birthday_status" translatable="false">Birthday soon</string>
+ <!-- Status text for an anniversary [CHAR LIMIT=30] -->
+ <string name="anniversary_status" translatable="false">Anniversary</string>
+ <!-- Status text for sharing location [CHAR LIMIT=30] -->
+ <string name="location_status" translatable="false">Sharing location</string>
+ <!-- Status text for a new story posted [CHAR LIMIT=30] -->
+ <string name="new_story_status" translatable="false">New story</string>
+ <!-- Status text for watching a video [CHAR LIMIT=30] -->
+ <string name="video_status" translatable="false">Watching</string>
+ <!-- Status text for listening to audio [CHAR LIMIT=30] -->
+ <string name="audio_status" translatable="false">Listening</string>
+ <!-- Status text for playing a game [CHAR LIMIT=30] -->
+ <string name="game_status" translatable="false">Playing</string>
+ <!-- Empty user name before user has selected a friend [CHAR LIMIT=30] -->
+ <string name="empty_user_name" translatable="false">Your friend</string>
+ <!-- Empty status shown before user has selected a friend [CHAR LIMIT=30] -->
+ <string name="empty_status" translatable="false">Their status</string>
<!-- Title to display in a notification when ACTION_BATTERY_CHANGED.EXTRA_PRESENT field is false
[CHAR LIMIT=NONE] -->
diff --git a/packages/SystemUI/res/xml/people_space_widget_info.xml b/packages/SystemUI/res/xml/people_space_widget_info.xml
index d0c63a8b180c..fbdac5e1789b 100644
--- a/packages/SystemUI/res/xml/people_space_widget_info.xml
+++ b/packages/SystemUI/res/xml/people_space_widget_info.xml
@@ -16,11 +16,11 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="140dp"
- android:minHeight="40dp"
+ android:minHeight="55dp"
android:minResizeWidth="110dp"
- android:minResizeHeight="40dp"
+ android:minResizeHeight="55dp"
android:updatePeriodMillis="60000"
- android:previewImage="@drawable/ic_android"
+ android:previewImage="@drawable/ic_person"
android:resizeMode="horizontal|vertical"
android:configure="com.android.systemui.people.PeopleSpaceActivity"
android:initialLayout="@layout/people_space_widget">
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PeopleProviderUtils.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PeopleProviderUtils.java
new file mode 100644
index 000000000000..15cf3696fec7
--- /dev/null
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PeopleProviderUtils.java
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package com.android.systemui.shared.system;
+
+/**
+ * These strings are part of the {@link com.android.systemui.people.PeopleProvider} API
+ * contract. The API returns a People Tile preview that can be displayed by calling packages.
+ * The provider is part of the SystemUI service, and the strings live here for shared access with
+ * Launcher (caller).
+ */
+public class PeopleProviderUtils {
+ /**
+ * ContentProvider URI scheme.
+ * @hide
+ */
+ public static final String PEOPLE_PROVIDER_SCHEME = "content://";
+
+ /**
+ * ContentProvider URI authority.
+ * @hide
+ */
+ public static final String PEOPLE_PROVIDER_AUTHORITY =
+ "com.android.systemui.people.PeopleProvider";
+
+ /**
+ * Method name for getting People Tile preview.
+ * @hide
+ */
+ public static final String GET_PEOPLE_TILE_PREVIEW_METHOD = "get_people_tile_preview";
+
+ /**
+ * Extras bundle key specifying shortcut Id of the People Tile preview requested.
+ * @hide
+ */
+ public static final String EXTRAS_KEY_SHORTCUT_ID = "shortcut_id";
+
+ /**
+ * Extras bundle key specifying package name of the People Tile preview requested.
+ * @hide
+ */
+ public static final String EXTRAS_KEY_PACKAGE_NAME = "package_name";
+
+ /**
+ * Extras bundle key specifying {@code UserHandle} of the People Tile preview requested.
+ * @hide
+ */
+ public static final String EXTRAS_KEY_USER_HANDLE = "user_handle";
+
+ /**
+ * Response bundle key to access the returned People Tile preview.
+ * @hide
+ */
+ public static final String RESPONSE_KEY_REMOTE_VIEWS = "remote_views";
+
+ /**
+ * Name of the permission needed to get a People Tile preview for a given conversation shortcut.
+ * @hide
+ */
+ public static final String GET_PEOPLE_TILE_PREVIEW_PERMISSION =
+ "android.permission.GET_PEOPLE_TILE_PREVIEW";
+
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierText.java b/packages/SystemUI/src/com/android/keyguard/CarrierText.java
index f6b03c1fa013..e4f6e131258e 100644
--- a/packages/SystemUI/src/com/android/keyguard/CarrierText.java
+++ b/packages/SystemUI/src/com/android/keyguard/CarrierText.java
@@ -24,41 +24,14 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
-import com.android.systemui.Dependency;
import com.android.systemui.R;
import java.util.Locale;
public class CarrierText extends TextView {
- private static final boolean DEBUG = KeyguardConstants.DEBUG;
- private static final String TAG = "CarrierText";
+ private final boolean mShowMissingSim;
- private static CharSequence mSeparator;
-
- private boolean mShowMissingSim;
-
- private boolean mShowAirplaneMode;
- private boolean mShouldMarquee;
-
- private CarrierTextController mCarrierTextController;
-
- private CarrierTextController.CarrierTextCallback mCarrierTextCallback =
- new CarrierTextController.CarrierTextCallback() {
- @Override
- public void updateCarrierInfo(CarrierTextController.CarrierTextCallbackInfo info) {
- setText(info.carrierText);
- }
-
- @Override
- public void startedGoingToSleep() {
- setSelected(false);
- }
-
- @Override
- public void finishedWakingUp() {
- setSelected(true);
- }
- };
+ private final boolean mShowAirplaneMode;
public CarrierText(Context context) {
this(context, null);
@@ -78,30 +51,6 @@ public class CarrierText extends TextView {
}
setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
}
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mSeparator = getResources().getString(
- com.android.internal.R.string.kg_text_message_separator);
- mCarrierTextController = new CarrierTextController(mContext, mSeparator, mShowAirplaneMode,
- mShowMissingSim);
- mShouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive();
- setSelected(mShouldMarquee); // Allow marquee to work.
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- mCarrierTextController.setListening(mCarrierTextCallback);
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- mCarrierTextController.setListening(null);
- }
-
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
@@ -113,7 +62,15 @@ public class CarrierText extends TextView {
}
}
- private class CarrierTextTransformationMethod extends SingleLineTransformationMethod {
+ public boolean getShowAirplaneMode() {
+ return mShowAirplaneMode;
+ }
+
+ public boolean getShowMissingSim() {
+ return mShowMissingSim;
+ }
+
+ private static class CarrierTextTransformationMethod extends SingleLineTransformationMethod {
private final Locale mLocale;
private final boolean mAllCaps;
diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
index b1e14346c3fa..46a6d8b82911 100644
--- a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
+++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * 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.
@@ -16,680 +16,61 @@
package com.android.keyguard;
-import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE;
-import static android.telephony.PhoneStateListener.LISTEN_NONE;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.res.Resources;
-import android.net.ConnectivityManager;
-import android.net.wifi.WifiManager;
-import android.os.Handler;
-import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Log;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settingslib.WirelessUtils;
-import com.android.systemui.Dependency;
-import com.android.systemui.R;
-import com.android.systemui.dagger.qualifiers.Main;
-import com.android.systemui.keyguard.WakefulnessLifecycle;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicBoolean;
+import com.android.systemui.util.ViewController;
import javax.inject.Inject;
/**
- * Controller that generates text including the carrier names and/or the status of all the SIM
- * interfaces in the device. Through a callback, the updates can be retrieved either as a list or
- * separated by a given separator {@link CharSequence}.
+ * Controller for {@link CarrierText}.
*/
-public class CarrierTextController {
- private static final boolean DEBUG = KeyguardConstants.DEBUG;
- private static final String TAG = "CarrierTextController";
+public class CarrierTextController extends ViewController<CarrierText> {
+ private final CarrierTextManager mCarrierTextManager;
+ private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
- private final boolean mIsEmergencyCallCapable;
- private final Handler mMainHandler;
- private final Handler mBgHandler;
- private boolean mTelephonyCapable;
- private boolean mShowMissingSim;
- private boolean mShowAirplaneMode;
- private final AtomicBoolean mNetworkSupported = new AtomicBoolean();
- @VisibleForTesting
- protected KeyguardUpdateMonitor mKeyguardUpdateMonitor;
- private WifiManager mWifiManager;
- private boolean[] mSimErrorState;
- private final int mSimSlotsNumber;
- @Nullable // Check for nullability before dispatching
- private CarrierTextCallback mCarrierTextCallback;
- private Context mContext;
- private CharSequence mSeparator;
- private WakefulnessLifecycle mWakefulnessLifecycle;
- private final WakefulnessLifecycle.Observer mWakefulnessObserver =
- new WakefulnessLifecycle.Observer() {
+ private final CarrierTextManager.CarrierTextCallback mCarrierTextCallback =
+ new CarrierTextManager.CarrierTextCallback() {
@Override
- public void onFinishedWakingUp() {
- final CarrierTextCallback callback = mCarrierTextCallback;
- if (callback != null) callback.finishedWakingUp();
+ public void updateCarrierInfo(CarrierTextManager.CarrierTextCallbackInfo info) {
+ mView.setText(info.carrierText);
}
@Override
- public void onStartedGoingToSleep() {
- final CarrierTextCallback callback = mCarrierTextCallback;
- if (callback != null) callback.startedGoingToSleep();
+ public void startedGoingToSleep() {
+ mView.setSelected(false);
}
- };
-
- @VisibleForTesting
- protected final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
- @Override
- public void onRefreshCarrierInfo() {
- if (DEBUG) {
- Log.d(TAG, "onRefreshCarrierInfo(), mTelephonyCapable: "
- + Boolean.toString(mTelephonyCapable));
- }
- updateCarrierText();
- }
-
- @Override
- public void onTelephonyCapable(boolean capable) {
- if (DEBUG) {
- Log.d(TAG, "onTelephonyCapable() mTelephonyCapable: "
- + Boolean.toString(capable));
- }
- mTelephonyCapable = capable;
- updateCarrierText();
- }
-
- public void onSimStateChanged(int subId, int slotId, int simState) {
- if (slotId < 0 || slotId >= mSimSlotsNumber) {
- Log.d(TAG, "onSimStateChanged() - slotId invalid: " + slotId
- + " mTelephonyCapable: " + Boolean.toString(mTelephonyCapable));
- return;
- }
-
- if (DEBUG) Log.d(TAG, "onSimStateChanged: " + getStatusForIccState(simState));
- if (getStatusForIccState(simState) == CarrierTextController.StatusMode.SimIoError) {
- mSimErrorState[slotId] = true;
- updateCarrierText();
- } else if (mSimErrorState[slotId]) {
- mSimErrorState[slotId] = false;
- updateCarrierText();
- }
- }
- };
-
- private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
- @Override
- public void onActiveDataSubscriptionIdChanged(int subId) {
- mActiveMobileDataSubscription = subId;
- if (mNetworkSupported.get() && mCarrierTextCallback != null) {
- updateCarrierText();
- }
- }
- };
-
- /**
- * The status of this lock screen. Primarily used for widgets on LockScreen.
- */
- private enum StatusMode {
- Normal, // Normal case (sim card present, it's not locked)
- NetworkLocked, // SIM card is 'network locked'.
- SimMissing, // SIM card is missing.
- SimMissingLocked, // SIM card is missing, and device isn't provisioned; don't allow access
- SimPukLocked, // SIM card is PUK locked because SIM entered wrong too many times
- SimLocked, // SIM card is currently locked
- SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure
- SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM.
- SimIoError, // SIM card is faulty
- SimUnknown // SIM card is unknown
- }
-
- /**
- * Controller that provides updates on text with carriers names or SIM status.
- * Used by {@link CarrierText}.
- *
- * @param separator Separator between different parts of the text
- */
- public CarrierTextController(Context context, CharSequence separator, boolean showAirplaneMode,
- boolean showMissingSim) {
- mContext = context;
- mIsEmergencyCallCapable = getTelephonyManager().isVoiceCapable();
-
- mShowAirplaneMode = showAirplaneMode;
- mShowMissingSim = showMissingSim;
-
- mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- mSeparator = separator;
- mWakefulnessLifecycle = Dependency.get(WakefulnessLifecycle.class);
- mSimSlotsNumber = getTelephonyManager().getSupportedModemCount();
- mSimErrorState = new boolean[mSimSlotsNumber];
- mMainHandler = Dependency.get(Dependency.MAIN_HANDLER);
- mBgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
- mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
- mBgHandler.post(() -> {
- boolean supported = ConnectivityManager.from(mContext).isNetworkSupported(
- ConnectivityManager.TYPE_MOBILE);
- if (supported && mNetworkSupported.compareAndSet(false, supported)) {
- // This will set/remove the listeners appropriately. Note that it will never double
- // add the listeners.
- handleSetListening(mCarrierTextCallback);
- }
- });
- }
-
- private TelephonyManager getTelephonyManager() {
- return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
- }
-
- /**
- * Checks if there are faulty cards. Adds the text depending on the slot of the card
- *
- * @param text: current carrier text based on the sim state
- * @param carrierNames names order by subscription order
- * @param subOrderBySlot array containing the sub index for each slot ID
- * @param noSims: whether a valid sim card is inserted
- * @return text
- */
- private CharSequence updateCarrierTextWithSimIoError(CharSequence text,
- CharSequence[] carrierNames, int[] subOrderBySlot, boolean noSims) {
- final CharSequence carrier = "";
- CharSequence carrierTextForSimIOError = getCarrierTextForSimState(
- TelephonyManager.SIM_STATE_CARD_IO_ERROR, carrier);
- // mSimErrorState has the state of each sim indexed by slotID.
- for (int index = 0; index < getTelephonyManager().getActiveModemCount(); index++) {
- if (!mSimErrorState[index]) {
- continue;
- }
- // In the case when no sim cards are detected but a faulty card is inserted
- // overwrite the text and only show "Invalid card"
- if (noSims) {
- return concatenate(carrierTextForSimIOError,
- getContext().getText(
- com.android.internal.R.string.emergency_calls_only),
- mSeparator);
- } else if (subOrderBySlot[index] != -1) {
- int subIndex = subOrderBySlot[index];
- // prepend "Invalid card" when faulty card is inserted in slot 0 or 1
- carrierNames[subIndex] = concatenate(carrierTextForSimIOError,
- carrierNames[subIndex],
- mSeparator);
- } else {
- // concatenate "Invalid card" when faulty card is inserted in other slot
- text = concatenate(text, carrierTextForSimIOError, mSeparator);
- }
-
- }
- return text;
- }
-
- /**
- * This may be called internally after retrieving the correct value of {@code mNetworkSupported}
- * (assumed false to start). In that case, the following happens:
- * <ul>
- * <li> If there was a registered callback, and the network is supported, it will register
- * listeners.
- * <li> If there was not a registered callback, it will try to remove unregistered listeners
- * which is a no-op
- * </ul>
- *
- * This call will always be processed in a background thread.
- */
- private void handleSetListening(CarrierTextCallback callback) {
- TelephonyManager telephonyManager = getTelephonyManager();
- if (callback != null) {
- mCarrierTextCallback = callback;
- if (mNetworkSupported.get()) {
- // Keyguard update monitor expects callbacks from main thread
- mMainHandler.post(() -> mKeyguardUpdateMonitor.registerCallback(mCallback));
- mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
- telephonyManager.listen(mPhoneStateListener,
- LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
- } else {
- // Don't listen and clear out the text when the device isn't a phone.
- mMainHandler.post(() -> callback.updateCarrierInfo(
- new CarrierTextCallbackInfo("", null, false, null)
- ));
- }
- } else {
- mCarrierTextCallback = null;
- mMainHandler.post(() -> mKeyguardUpdateMonitor.removeCallback(mCallback));
- mWakefulnessLifecycle.removeObserver(mWakefulnessObserver);
- telephonyManager.listen(mPhoneStateListener, LISTEN_NONE);
- }
- }
-
- /**
- * Sets the listening status of this controller. If the callback is null, it is set to
- * not listening.
- *
- * @param callback Callback to provide text updates
- */
- public void setListening(CarrierTextCallback callback) {
- mBgHandler.post(() -> handleSetListening(callback));
- }
-
- protected List<SubscriptionInfo> getSubscriptionInfo() {
- return mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(false);
- }
-
- protected void updateCarrierText() {
- boolean allSimsMissing = true;
- boolean anySimReadyAndInService = false;
- CharSequence displayText = null;
- List<SubscriptionInfo> subs = getSubscriptionInfo();
-
- final int numSubs = subs.size();
- final int[] subsIds = new int[numSubs];
- // This array will contain in position i, the index of subscription in slot ID i.
- // -1 if no subscription in that slot
- final int[] subOrderBySlot = new int[mSimSlotsNumber];
- for (int i = 0; i < mSimSlotsNumber; i++) {
- subOrderBySlot[i] = -1;
- }
- final CharSequence[] carrierNames = new CharSequence[numSubs];
- if (DEBUG) Log.d(TAG, "updateCarrierText(): " + numSubs);
-
- for (int i = 0; i < numSubs; i++) {
- int subId = subs.get(i).getSubscriptionId();
- carrierNames[i] = "";
- subsIds[i] = subId;
- subOrderBySlot[subs.get(i).getSimSlotIndex()] = i;
- int simState = mKeyguardUpdateMonitor.getSimState(subId);
- CharSequence carrierName = subs.get(i).getCarrierName();
- CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
- if (DEBUG) {
- Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
- }
- if (carrierTextForSimState != null) {
- allSimsMissing = false;
- carrierNames[i] = carrierTextForSimState;
- }
- if (simState == TelephonyManager.SIM_STATE_READY) {
- ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
- if (ss != null && ss.getDataRegistrationState() == ServiceState.STATE_IN_SERVICE) {
- // hack for WFC (IWLAN) not turning off immediately once
- // Wi-Fi is disassociated or disabled
- if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN
- || (mWifiManager.isWifiEnabled()
- && mWifiManager.getConnectionInfo() != null
- && mWifiManager.getConnectionInfo().getBSSID() != null)) {
- if (DEBUG) {
- Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss);
- }
- anySimReadyAndInService = true;
- }
- }
- }
- }
- // Only create "No SIM card" if no cards with CarrierName && no wifi when some sim is READY
- // This condition will also be true always when numSubs == 0
- if (allSimsMissing && !anySimReadyAndInService) {
- if (numSubs != 0) {
- // Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
- // This depends on mPlmn containing the text "Emergency calls only" when the radio
- // has some connectivity. Otherwise, it should be null or empty and just show
- // "No SIM card"
- // Grab the first subscripton, because they all should contain the emergency text,
- // described above.
- displayText = makeCarrierStringOnEmergencyCapable(
- getMissingSimMessage(), subs.get(0).getCarrierName());
- } else {
- // We don't have a SubscriptionInfo to get the emergency calls only from.
- // Grab it from the old sticky broadcast if possible instead. We can use it
- // here because no subscriptions are active, so we don't have
- // to worry about MSIM clashing.
- CharSequence text =
- getContext().getText(com.android.internal.R.string.emergency_calls_only);
- Intent i = getContext().registerReceiver(null,
- new IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED));
- if (i != null) {
- String spn = "";
- String plmn = "";
- if (i.getBooleanExtra(TelephonyManager.EXTRA_SHOW_SPN, false)) {
- spn = i.getStringExtra(TelephonyManager.EXTRA_SPN);
- }
- if (i.getBooleanExtra(TelephonyManager.EXTRA_SHOW_PLMN, false)) {
- plmn = i.getStringExtra(TelephonyManager.EXTRA_PLMN);
- }
- if (DEBUG) Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
- if (Objects.equals(plmn, spn)) {
- text = plmn;
- } else {
- text = concatenate(plmn, spn, mSeparator);
- }
- }
- displayText = makeCarrierStringOnEmergencyCapable(getMissingSimMessage(), text);
- }
- }
-
- if (TextUtils.isEmpty(displayText)) displayText = joinNotEmpty(mSeparator, carrierNames);
-
- displayText = updateCarrierTextWithSimIoError(displayText, carrierNames, subOrderBySlot,
- allSimsMissing);
-
- boolean airplaneMode = false;
- // APM (airplane mode) != no carrier state. There are carrier services
- // (e.g. WFC = Wi-Fi calling) which may operate in APM.
- if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) {
- displayText = getAirplaneModeMessage();
- airplaneMode = true;
- }
-
- final CarrierTextCallbackInfo info = new CarrierTextCallbackInfo(
- displayText,
- carrierNames,
- !allSimsMissing,
- subsIds,
- airplaneMode);
- postToCallback(info);
- }
-
- @VisibleForTesting
- protected void postToCallback(CarrierTextCallbackInfo info) {
- final CarrierTextCallback callback = mCarrierTextCallback;
- if (callback != null) {
- mMainHandler.post(() -> callback.updateCarrierInfo(info));
- }
- }
-
- private Context getContext() {
- return mContext;
- }
- private String getMissingSimMessage() {
- return mShowMissingSim && mTelephonyCapable
- ? getContext().getString(R.string.keyguard_missing_sim_message_short) : "";
- }
-
- private String getAirplaneModeMessage() {
- return mShowAirplaneMode
- ? getContext().getString(R.string.airplane_mode) : "";
- }
-
- /**
- * Top-level function for creating carrier text. Makes text based on simState, PLMN
- * and SPN as well as device capabilities, such as being emergency call capable.
- *
- * @return Carrier text if not in missing state, null otherwise.
- */
- private CharSequence getCarrierTextForSimState(int simState, CharSequence text) {
- CharSequence carrierText = null;
- CarrierTextController.StatusMode status = getStatusForIccState(simState);
- switch (status) {
- case Normal:
- carrierText = text;
- break;
-
- case SimNotReady:
- // Null is reserved for denoting missing, in this case we have nothing to display.
- carrierText = ""; // nothing to display yet.
- break;
-
- case NetworkLocked:
- carrierText = makeCarrierStringOnEmergencyCapable(
- mContext.getText(R.string.keyguard_network_locked_message), text);
- break;
-
- case SimMissing:
- carrierText = null;
- break;
-
- case SimPermDisabled:
- carrierText = makeCarrierStringOnEmergencyCapable(
- getContext().getText(
- R.string.keyguard_permanent_disabled_sim_message_short),
- text);
- break;
-
- case SimMissingLocked:
- carrierText = null;
- break;
-
- case SimLocked:
- carrierText = makeCarrierStringOnLocked(
- getContext().getText(R.string.keyguard_sim_locked_message),
- text);
- break;
-
- case SimPukLocked:
- carrierText = makeCarrierStringOnLocked(
- getContext().getText(R.string.keyguard_sim_puk_locked_message),
- text);
- break;
- case SimIoError:
- carrierText = makeCarrierStringOnEmergencyCapable(
- getContext().getText(R.string.keyguard_sim_error_message_short),
- text);
- break;
- case SimUnknown:
- carrierText = null;
- break;
- }
-
- return carrierText;
- }
-
- /*
- * Add emergencyCallMessage to carrier string only if phone supports emergency calls.
- */
- private CharSequence makeCarrierStringOnEmergencyCapable(
- CharSequence simMessage, CharSequence emergencyCallMessage) {
- if (mIsEmergencyCallCapable) {
- return concatenate(simMessage, emergencyCallMessage, mSeparator);
- }
- return simMessage;
- }
-
- /*
- * Add "SIM card is locked" in parenthesis after carrier name, so it is easily associated in
- * DSDS
- */
- private CharSequence makeCarrierStringOnLocked(CharSequence simMessage,
- CharSequence carrierName) {
- final boolean simMessageValid = !TextUtils.isEmpty(simMessage);
- final boolean carrierNameValid = !TextUtils.isEmpty(carrierName);
- if (simMessageValid && carrierNameValid) {
- return mContext.getString(R.string.keyguard_carrier_name_with_sim_locked_template,
- carrierName, simMessage);
- } else if (simMessageValid) {
- return simMessage;
- } else if (carrierNameValid) {
- return carrierName;
- } else {
- return "";
- }
- }
-
- /**
- * Determine the current status of the lock screen given the SIM state and other stuff.
- */
- private CarrierTextController.StatusMode getStatusForIccState(int simState) {
- final boolean missingAndNotProvisioned =
- !mKeyguardUpdateMonitor.isDeviceProvisioned()
- && (simState == TelephonyManager.SIM_STATE_ABSENT
- || simState == TelephonyManager.SIM_STATE_PERM_DISABLED);
-
- // Assume we're NETWORK_LOCKED if not provisioned
- simState = missingAndNotProvisioned ? TelephonyManager.SIM_STATE_NETWORK_LOCKED : simState;
- switch (simState) {
- case TelephonyManager.SIM_STATE_ABSENT:
- return CarrierTextController.StatusMode.SimMissing;
- case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
- return CarrierTextController.StatusMode.SimMissingLocked;
- case TelephonyManager.SIM_STATE_NOT_READY:
- return CarrierTextController.StatusMode.SimNotReady;
- case TelephonyManager.SIM_STATE_PIN_REQUIRED:
- return CarrierTextController.StatusMode.SimLocked;
- case TelephonyManager.SIM_STATE_PUK_REQUIRED:
- return CarrierTextController.StatusMode.SimPukLocked;
- case TelephonyManager.SIM_STATE_READY:
- return CarrierTextController.StatusMode.Normal;
- case TelephonyManager.SIM_STATE_PERM_DISABLED:
- return CarrierTextController.StatusMode.SimPermDisabled;
- case TelephonyManager.SIM_STATE_UNKNOWN:
- return CarrierTextController.StatusMode.SimUnknown;
- case TelephonyManager.SIM_STATE_CARD_IO_ERROR:
- return CarrierTextController.StatusMode.SimIoError;
- }
- return CarrierTextController.StatusMode.SimUnknown;
- }
-
- private static CharSequence concatenate(CharSequence plmn, CharSequence spn,
- CharSequence separator) {
- final boolean plmnValid = !TextUtils.isEmpty(plmn);
- final boolean spnValid = !TextUtils.isEmpty(spn);
- if (plmnValid && spnValid) {
- return new StringBuilder().append(plmn).append(separator).append(spn).toString();
- } else if (plmnValid) {
- return plmn;
- } else if (spnValid) {
- return spn;
- } else {
- return "";
- }
- }
-
- /**
- * Joins the strings in a sequence using a separator. Empty strings are discarded with no extra
- * separator added so there are no extra separators that are not needed.
- */
- private static CharSequence joinNotEmpty(CharSequence separator, CharSequence[] sequences) {
- int length = sequences.length;
- if (length == 0) return "";
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (!TextUtils.isEmpty(sequences[i])) {
- if (!TextUtils.isEmpty(sb)) {
- sb.append(separator);
+ @Override
+ public void finishedWakingUp() {
+ mView.setSelected(true);
}
- sb.append(sequences[i]);
- }
- }
- return sb.toString();
- }
-
- private static List<CharSequence> append(List<CharSequence> list, CharSequence string) {
- if (!TextUtils.isEmpty(string)) {
- list.add(string);
- }
- return list;
- }
-
- private CharSequence getCarrierHelpTextForSimState(int simState,
- String plmn, String spn) {
- int carrierHelpTextId = 0;
- CarrierTextController.StatusMode status = getStatusForIccState(simState);
- switch (status) {
- case NetworkLocked:
- carrierHelpTextId = R.string.keyguard_instructions_when_pattern_disabled;
- break;
-
- case SimMissing:
- carrierHelpTextId = R.string.keyguard_missing_sim_instructions_long;
- break;
-
- case SimPermDisabled:
- carrierHelpTextId = R.string.keyguard_permanent_disabled_sim_instructions;
- break;
-
- case SimMissingLocked:
- carrierHelpTextId = R.string.keyguard_missing_sim_instructions;
- break;
+ };
- case Normal:
- case SimLocked:
- case SimPukLocked:
- break;
- }
+ @Inject
+ public CarrierTextController(CarrierText view,
+ CarrierTextManager.Builder carrierTextManagerBuilder,
+ KeyguardUpdateMonitor keyguardUpdateMonitor) {
+ super(view);
- return mContext.getText(carrierHelpTextId);
+ mCarrierTextManager = carrierTextManagerBuilder
+ .setShowAirplaneMode(mView.getShowAirplaneMode())
+ .setShowMissingSim(mView.getShowMissingSim())
+ .build();
+ mKeyguardUpdateMonitor = keyguardUpdateMonitor;
}
- public static class Builder {
- private final Context mContext;
- private final String mSeparator;
- private boolean mShowAirplaneMode;
- private boolean mShowMissingSim;
-
- @Inject
- public Builder(Context context, @Main Resources resources) {
- mContext = context;
- mSeparator = resources.getString(
- com.android.internal.R.string.kg_text_message_separator);
- }
-
-
- public Builder setShowAirplaneMode(boolean showAirplaneMode) {
- mShowAirplaneMode = showAirplaneMode;
- return this;
- }
-
- public Builder setShowMissingSim(boolean showMissingSim) {
- mShowMissingSim = showMissingSim;
- return this;
- }
-
- public CarrierTextController build() {
- return new CarrierTextController(
- mContext, mSeparator, mShowAirplaneMode, mShowMissingSim);
- }
+ @Override
+ protected void onInit() {
+ super.onInit();
+ mView.setSelected(mKeyguardUpdateMonitor.isDeviceInteractive());
}
- /**
- * Data structure for passing information to CarrierTextController subscribers
- */
- public static final class CarrierTextCallbackInfo {
- public final CharSequence carrierText;
- public final CharSequence[] listOfCarriers;
- public final boolean anySimReady;
- public final int[] subscriptionIds;
- public boolean airplaneMode;
-
- @VisibleForTesting
- public CarrierTextCallbackInfo(CharSequence carrierText, CharSequence[] listOfCarriers,
- boolean anySimReady, int[] subscriptionIds) {
- this(carrierText, listOfCarriers, anySimReady, subscriptionIds, false);
- }
- @VisibleForTesting
- public CarrierTextCallbackInfo(CharSequence carrierText, CharSequence[] listOfCarriers,
- boolean anySimReady, int[] subscriptionIds, boolean airplaneMode) {
- this.carrierText = carrierText;
- this.listOfCarriers = listOfCarriers;
- this.anySimReady = anySimReady;
- this.subscriptionIds = subscriptionIds;
- this.airplaneMode = airplaneMode;
- }
+ @Override
+ protected void onViewAttached() {
+ mCarrierTextManager.setListening(mCarrierTextCallback);
}
- /**
- * Callback to communicate to Views
- */
- public interface CarrierTextCallback {
- /**
- * Provides updated carrier information.
- */
- default void updateCarrierInfo(CarrierTextCallbackInfo info) {};
-
- /**
- * Notifies the View that the device is going to sleep
- */
- default void startedGoingToSleep() {};
-
- /**
- * Notifies the View that the device finished waking up
- */
- default void finishedWakingUp() {};
+ @Override
+ protected void onViewDetached() {
+ mCarrierTextManager.setListening(null);
}
}
diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java
new file mode 100644
index 000000000000..87b01e8671f0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java
@@ -0,0 +1,720 @@
+/*
+ * Copyright (C) 2019 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.keyguard;
+
+import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE;
+import static android.telephony.PhoneStateListener.LISTEN_NONE;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.telephony.PhoneStateListener;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settingslib.WirelessUtils;
+import com.android.systemui.R;
+import com.android.systemui.dagger.qualifiers.Background;
+import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.keyguard.WakefulnessLifecycle;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.inject.Inject;
+
+/**
+ * Controller that generates text including the carrier names and/or the status of all the SIM
+ * interfaces in the device. Through a callback, the updates can be retrieved either as a list or
+ * separated by a given separator {@link CharSequence}.
+ */
+public class CarrierTextManager {
+ private static final boolean DEBUG = KeyguardConstants.DEBUG;
+ private static final String TAG = "CarrierTextController";
+
+ private final boolean mIsEmergencyCallCapable;
+ private final Handler mMainHandler;
+ private final Handler mBgHandler;
+ private boolean mTelephonyCapable;
+ private final boolean mShowMissingSim;
+ private final boolean mShowAirplaneMode;
+ private final AtomicBoolean mNetworkSupported = new AtomicBoolean();
+ @VisibleForTesting
+ protected KeyguardUpdateMonitor mKeyguardUpdateMonitor;
+ private final WifiManager mWifiManager;
+ private final boolean[] mSimErrorState;
+ private final int mSimSlotsNumber;
+ @Nullable // Check for nullability before dispatching
+ private CarrierTextCallback mCarrierTextCallback;
+ private final Context mContext;
+ private final TelephonyManager mTelephonyManager;
+ private final CharSequence mSeparator;
+ private final WakefulnessLifecycle mWakefulnessLifecycle;
+ private final WakefulnessLifecycle.Observer mWakefulnessObserver =
+ new WakefulnessLifecycle.Observer() {
+ @Override
+ public void onFinishedWakingUp() {
+ final CarrierTextCallback callback = mCarrierTextCallback;
+ if (callback != null) callback.finishedWakingUp();
+ }
+
+ @Override
+ public void onStartedGoingToSleep() {
+ final CarrierTextCallback callback = mCarrierTextCallback;
+ if (callback != null) callback.startedGoingToSleep();
+ }
+ };
+
+ @VisibleForTesting
+ protected final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
+ @Override
+ public void onRefreshCarrierInfo() {
+ if (DEBUG) {
+ Log.d(TAG, "onRefreshCarrierInfo(), mTelephonyCapable: "
+ + Boolean.toString(mTelephonyCapable));
+ }
+ updateCarrierText();
+ }
+
+ @Override
+ public void onTelephonyCapable(boolean capable) {
+ if (DEBUG) {
+ Log.d(TAG, "onTelephonyCapable() mTelephonyCapable: "
+ + Boolean.toString(capable));
+ }
+ mTelephonyCapable = capable;
+ updateCarrierText();
+ }
+
+ public void onSimStateChanged(int subId, int slotId, int simState) {
+ if (slotId < 0 || slotId >= mSimSlotsNumber) {
+ Log.d(TAG, "onSimStateChanged() - slotId invalid: " + slotId
+ + " mTelephonyCapable: " + Boolean.toString(mTelephonyCapable));
+ return;
+ }
+
+ if (DEBUG) Log.d(TAG, "onSimStateChanged: " + getStatusForIccState(simState));
+ if (getStatusForIccState(simState) == CarrierTextManager.StatusMode.SimIoError) {
+ mSimErrorState[slotId] = true;
+ updateCarrierText();
+ } else if (mSimErrorState[slotId]) {
+ mSimErrorState[slotId] = false;
+ updateCarrierText();
+ }
+ }
+ };
+
+ private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
+ @Override
+ public void onActiveDataSubscriptionIdChanged(int subId) {
+ if (mNetworkSupported.get() && mCarrierTextCallback != null) {
+ updateCarrierText();
+ }
+ }
+ };
+
+ /**
+ * The status of this lock screen. Primarily used for widgets on LockScreen.
+ */
+ private enum StatusMode {
+ Normal, // Normal case (sim card present, it's not locked)
+ NetworkLocked, // SIM card is 'network locked'.
+ SimMissing, // SIM card is missing.
+ SimMissingLocked, // SIM card is missing, and device isn't provisioned; don't allow access
+ SimPukLocked, // SIM card is PUK locked because SIM entered wrong too many times
+ SimLocked, // SIM card is currently locked
+ SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure
+ SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM.
+ SimIoError, // SIM card is faulty
+ SimUnknown // SIM card is unknown
+ }
+
+ /**
+ * Controller that provides updates on text with carriers names or SIM status.
+ * Used by {@link CarrierText}.
+ *
+ * @param separator Separator between different parts of the text
+ */
+ private CarrierTextManager(Context context, CharSequence separator, boolean showAirplaneMode,
+ boolean showMissingSim, @Nullable WifiManager wifiManager,
+ ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
+ WakefulnessLifecycle wakefulnessLifecycle, @Main Handler mainHandler,
+ @Background Handler bgHandler, KeyguardUpdateMonitor keyguardUpdateMonitor) {
+ mContext = context;
+ mIsEmergencyCallCapable = telephonyManager.isVoiceCapable();
+
+ mShowAirplaneMode = showAirplaneMode;
+ mShowMissingSim = showMissingSim;
+
+ mWifiManager = wifiManager;
+ mTelephonyManager = telephonyManager;
+ mSeparator = separator;
+ mWakefulnessLifecycle = wakefulnessLifecycle;
+ mSimSlotsNumber = getTelephonyManager().getSupportedModemCount();
+ mSimErrorState = new boolean[mSimSlotsNumber];
+ mMainHandler = mainHandler;
+ mBgHandler = bgHandler;
+ mKeyguardUpdateMonitor = keyguardUpdateMonitor;
+ mBgHandler.post(() -> {
+ boolean supported = connectivityManager.isNetworkSupported(
+ ConnectivityManager.TYPE_MOBILE);
+ if (supported && mNetworkSupported.compareAndSet(false, supported)) {
+ // This will set/remove the listeners appropriately. Note that it will never double
+ // add the listeners.
+ handleSetListening(mCarrierTextCallback);
+ }
+ });
+ }
+
+ private TelephonyManager getTelephonyManager() {
+ return mTelephonyManager;
+ }
+
+ /**
+ * Checks if there are faulty cards. Adds the text depending on the slot of the card
+ *
+ * @param text: current carrier text based on the sim state
+ * @param carrierNames names order by subscription order
+ * @param subOrderBySlot array containing the sub index for each slot ID
+ * @param noSims: whether a valid sim card is inserted
+ * @return text
+ */
+ private CharSequence updateCarrierTextWithSimIoError(CharSequence text,
+ CharSequence[] carrierNames, int[] subOrderBySlot, boolean noSims) {
+ final CharSequence carrier = "";
+ CharSequence carrierTextForSimIOError = getCarrierTextForSimState(
+ TelephonyManager.SIM_STATE_CARD_IO_ERROR, carrier);
+ // mSimErrorState has the state of each sim indexed by slotID.
+ for (int index = 0; index < getTelephonyManager().getActiveModemCount(); index++) {
+ if (!mSimErrorState[index]) {
+ continue;
+ }
+ // In the case when no sim cards are detected but a faulty card is inserted
+ // overwrite the text and only show "Invalid card"
+ if (noSims) {
+ return concatenate(carrierTextForSimIOError,
+ getContext().getText(
+ com.android.internal.R.string.emergency_calls_only),
+ mSeparator);
+ } else if (subOrderBySlot[index] != -1) {
+ int subIndex = subOrderBySlot[index];
+ // prepend "Invalid card" when faulty card is inserted in slot 0 or 1
+ carrierNames[subIndex] = concatenate(carrierTextForSimIOError,
+ carrierNames[subIndex],
+ mSeparator);
+ } else {
+ // concatenate "Invalid card" when faulty card is inserted in other slot
+ text = concatenate(text, carrierTextForSimIOError, mSeparator);
+ }
+
+ }
+ return text;
+ }
+
+ /**
+ * This may be called internally after retrieving the correct value of {@code mNetworkSupported}
+ * (assumed false to start). In that case, the following happens:
+ * <ul>
+ * <li> If there was a registered callback, and the network is supported, it will register
+ * listeners.
+ * <li> If there was not a registered callback, it will try to remove unregistered listeners
+ * which is a no-op
+ * </ul>
+ *
+ * This call will always be processed in a background thread.
+ */
+ private void handleSetListening(CarrierTextCallback callback) {
+ TelephonyManager telephonyManager = getTelephonyManager();
+ if (callback != null) {
+ mCarrierTextCallback = callback;
+ if (mNetworkSupported.get()) {
+ // Keyguard update monitor expects callbacks from main thread
+ mMainHandler.post(() -> mKeyguardUpdateMonitor.registerCallback(mCallback));
+ mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
+ telephonyManager.listen(mPhoneStateListener,
+ LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
+ } else {
+ // Don't listen and clear out the text when the device isn't a phone.
+ mMainHandler.post(() -> callback.updateCarrierInfo(
+ new CarrierTextCallbackInfo("", null, false, null)
+ ));
+ }
+ } else {
+ mCarrierTextCallback = null;
+ mMainHandler.post(() -> mKeyguardUpdateMonitor.removeCallback(mCallback));
+ mWakefulnessLifecycle.removeObserver(mWakefulnessObserver);
+ telephonyManager.listen(mPhoneStateListener, LISTEN_NONE);
+ }
+ }
+
+ /**
+ * Sets the listening status of this controller. If the callback is null, it is set to
+ * not listening.
+ *
+ * @param callback Callback to provide text updates
+ */
+ public void setListening(CarrierTextCallback callback) {
+ mBgHandler.post(() -> handleSetListening(callback));
+ }
+
+ protected List<SubscriptionInfo> getSubscriptionInfo() {
+ return mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(false);
+ }
+
+ protected void updateCarrierText() {
+ boolean allSimsMissing = true;
+ boolean anySimReadyAndInService = false;
+ CharSequence displayText = null;
+ List<SubscriptionInfo> subs = getSubscriptionInfo();
+
+ final int numSubs = subs.size();
+ final int[] subsIds = new int[numSubs];
+ // This array will contain in position i, the index of subscription in slot ID i.
+ // -1 if no subscription in that slot
+ final int[] subOrderBySlot = new int[mSimSlotsNumber];
+ for (int i = 0; i < mSimSlotsNumber; i++) {
+ subOrderBySlot[i] = -1;
+ }
+ final CharSequence[] carrierNames = new CharSequence[numSubs];
+ if (DEBUG) Log.d(TAG, "updateCarrierText(): " + numSubs);
+
+ for (int i = 0; i < numSubs; i++) {
+ int subId = subs.get(i).getSubscriptionId();
+ carrierNames[i] = "";
+ subsIds[i] = subId;
+ subOrderBySlot[subs.get(i).getSimSlotIndex()] = i;
+ int simState = mKeyguardUpdateMonitor.getSimState(subId);
+ CharSequence carrierName = subs.get(i).getCarrierName();
+ CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
+ if (DEBUG) {
+ Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
+ }
+ if (carrierTextForSimState != null) {
+ allSimsMissing = false;
+ carrierNames[i] = carrierTextForSimState;
+ }
+ if (simState == TelephonyManager.SIM_STATE_READY) {
+ ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
+ if (ss != null && ss.getDataRegistrationState() == ServiceState.STATE_IN_SERVICE) {
+ // hack for WFC (IWLAN) not turning off immediately once
+ // Wi-Fi is disassociated or disabled
+ if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN
+ || (mWifiManager != null && mWifiManager.isWifiEnabled()
+ && mWifiManager.getConnectionInfo() != null
+ && mWifiManager.getConnectionInfo().getBSSID() != null)) {
+ if (DEBUG) {
+ Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss);
+ }
+ anySimReadyAndInService = true;
+ }
+ }
+ }
+ }
+ // Only create "No SIM card" if no cards with CarrierName && no wifi when some sim is READY
+ // This condition will also be true always when numSubs == 0
+ if (allSimsMissing && !anySimReadyAndInService) {
+ if (numSubs != 0) {
+ // Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
+ // This depends on mPlmn containing the text "Emergency calls only" when the radio
+ // has some connectivity. Otherwise, it should be null or empty and just show
+ // "No SIM card"
+ // Grab the first subscripton, because they all should contain the emergency text,
+ // described above.
+ displayText = makeCarrierStringOnEmergencyCapable(
+ getMissingSimMessage(), subs.get(0).getCarrierName());
+ } else {
+ // We don't have a SubscriptionInfo to get the emergency calls only from.
+ // Grab it from the old sticky broadcast if possible instead. We can use it
+ // here because no subscriptions are active, so we don't have
+ // to worry about MSIM clashing.
+ CharSequence text =
+ getContext().getText(com.android.internal.R.string.emergency_calls_only);
+ Intent i = getContext().registerReceiver(null,
+ new IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED));
+ if (i != null) {
+ String spn = "";
+ String plmn = "";
+ if (i.getBooleanExtra(TelephonyManager.EXTRA_SHOW_SPN, false)) {
+ spn = i.getStringExtra(TelephonyManager.EXTRA_SPN);
+ }
+ if (i.getBooleanExtra(TelephonyManager.EXTRA_SHOW_PLMN, false)) {
+ plmn = i.getStringExtra(TelephonyManager.EXTRA_PLMN);
+ }
+ if (DEBUG) Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
+ if (Objects.equals(plmn, spn)) {
+ text = plmn;
+ } else {
+ text = concatenate(plmn, spn, mSeparator);
+ }
+ }
+ displayText = makeCarrierStringOnEmergencyCapable(getMissingSimMessage(), text);
+ }
+ }
+
+ if (TextUtils.isEmpty(displayText)) displayText = joinNotEmpty(mSeparator, carrierNames);
+
+ displayText = updateCarrierTextWithSimIoError(displayText, carrierNames, subOrderBySlot,
+ allSimsMissing);
+
+ boolean airplaneMode = false;
+ // APM (airplane mode) != no carrier state. There are carrier services
+ // (e.g. WFC = Wi-Fi calling) which may operate in APM.
+ if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) {
+ displayText = getAirplaneModeMessage();
+ airplaneMode = true;
+ }
+
+ final CarrierTextCallbackInfo info = new CarrierTextCallbackInfo(
+ displayText,
+ carrierNames,
+ !allSimsMissing,
+ subsIds,
+ airplaneMode);
+ postToCallback(info);
+ }
+
+ @VisibleForTesting
+ protected void postToCallback(CarrierTextCallbackInfo info) {
+ final CarrierTextCallback callback = mCarrierTextCallback;
+ if (callback != null) {
+ mMainHandler.post(() -> callback.updateCarrierInfo(info));
+ }
+ }
+
+ private Context getContext() {
+ return mContext;
+ }
+
+ private String getMissingSimMessage() {
+ return mShowMissingSim && mTelephonyCapable
+ ? getContext().getString(R.string.keyguard_missing_sim_message_short) : "";
+ }
+
+ private String getAirplaneModeMessage() {
+ return mShowAirplaneMode
+ ? getContext().getString(R.string.airplane_mode) : "";
+ }
+
+ /**
+ * Top-level function for creating carrier text. Makes text based on simState, PLMN
+ * and SPN as well as device capabilities, such as being emergency call capable.
+ *
+ * @return Carrier text if not in missing state, null otherwise.
+ */
+ private CharSequence getCarrierTextForSimState(int simState, CharSequence text) {
+ CharSequence carrierText = null;
+ CarrierTextManager.StatusMode status = getStatusForIccState(simState);
+ switch (status) {
+ case Normal:
+ carrierText = text;
+ break;
+
+ case SimNotReady:
+ // Null is reserved for denoting missing, in this case we have nothing to display.
+ carrierText = ""; // nothing to display yet.
+ break;
+
+ case NetworkLocked:
+ carrierText = makeCarrierStringOnEmergencyCapable(
+ mContext.getText(R.string.keyguard_network_locked_message), text);
+ break;
+
+ case SimMissing:
+ carrierText = null;
+ break;
+
+ case SimPermDisabled:
+ carrierText = makeCarrierStringOnEmergencyCapable(
+ getContext().getText(
+ R.string.keyguard_permanent_disabled_sim_message_short),
+ text);
+ break;
+
+ case SimMissingLocked:
+ carrierText = null;
+ break;
+
+ case SimLocked:
+ carrierText = makeCarrierStringOnLocked(
+ getContext().getText(R.string.keyguard_sim_locked_message),
+ text);
+ break;
+
+ case SimPukLocked:
+ carrierText = makeCarrierStringOnLocked(
+ getContext().getText(R.string.keyguard_sim_puk_locked_message),
+ text);
+ break;
+ case SimIoError:
+ carrierText = makeCarrierStringOnEmergencyCapable(
+ getContext().getText(R.string.keyguard_sim_error_message_short),
+ text);
+ break;
+ case SimUnknown:
+ carrierText = null;
+ break;
+ }
+
+ return carrierText;
+ }
+
+ /*
+ * Add emergencyCallMessage to carrier string only if phone supports emergency calls.
+ */
+ private CharSequence makeCarrierStringOnEmergencyCapable(
+ CharSequence simMessage, CharSequence emergencyCallMessage) {
+ if (mIsEmergencyCallCapable) {
+ return concatenate(simMessage, emergencyCallMessage, mSeparator);
+ }
+ return simMessage;
+ }
+
+ /*
+ * Add "SIM card is locked" in parenthesis after carrier name, so it is easily associated in
+ * DSDS
+ */
+ private CharSequence makeCarrierStringOnLocked(CharSequence simMessage,
+ CharSequence carrierName) {
+ final boolean simMessageValid = !TextUtils.isEmpty(simMessage);
+ final boolean carrierNameValid = !TextUtils.isEmpty(carrierName);
+ if (simMessageValid && carrierNameValid) {
+ return mContext.getString(R.string.keyguard_carrier_name_with_sim_locked_template,
+ carrierName, simMessage);
+ } else if (simMessageValid) {
+ return simMessage;
+ } else if (carrierNameValid) {
+ return carrierName;
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Determine the current status of the lock screen given the SIM state and other stuff.
+ */
+ private CarrierTextManager.StatusMode getStatusForIccState(int simState) {
+ final boolean missingAndNotProvisioned =
+ !mKeyguardUpdateMonitor.isDeviceProvisioned()
+ && (simState == TelephonyManager.SIM_STATE_ABSENT
+ || simState == TelephonyManager.SIM_STATE_PERM_DISABLED);
+
+ // Assume we're NETWORK_LOCKED if not provisioned
+ simState = missingAndNotProvisioned ? TelephonyManager.SIM_STATE_NETWORK_LOCKED : simState;
+ switch (simState) {
+ case TelephonyManager.SIM_STATE_ABSENT:
+ return CarrierTextManager.StatusMode.SimMissing;
+ case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
+ return CarrierTextManager.StatusMode.SimMissingLocked;
+ case TelephonyManager.SIM_STATE_NOT_READY:
+ return CarrierTextManager.StatusMode.SimNotReady;
+ case TelephonyManager.SIM_STATE_PIN_REQUIRED:
+ return CarrierTextManager.StatusMode.SimLocked;
+ case TelephonyManager.SIM_STATE_PUK_REQUIRED:
+ return CarrierTextManager.StatusMode.SimPukLocked;
+ case TelephonyManager.SIM_STATE_READY:
+ return CarrierTextManager.StatusMode.Normal;
+ case TelephonyManager.SIM_STATE_PERM_DISABLED:
+ return CarrierTextManager.StatusMode.SimPermDisabled;
+ case TelephonyManager.SIM_STATE_UNKNOWN:
+ return CarrierTextManager.StatusMode.SimUnknown;
+ case TelephonyManager.SIM_STATE_CARD_IO_ERROR:
+ return CarrierTextManager.StatusMode.SimIoError;
+ }
+ return CarrierTextManager.StatusMode.SimUnknown;
+ }
+
+ private static CharSequence concatenate(CharSequence plmn, CharSequence spn,
+ CharSequence separator) {
+ final boolean plmnValid = !TextUtils.isEmpty(plmn);
+ final boolean spnValid = !TextUtils.isEmpty(spn);
+ if (plmnValid && spnValid) {
+ return new StringBuilder().append(plmn).append(separator).append(spn).toString();
+ } else if (plmnValid) {
+ return plmn;
+ } else if (spnValid) {
+ return spn;
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Joins the strings in a sequence using a separator. Empty strings are discarded with no extra
+ * separator added so there are no extra separators that are not needed.
+ */
+ private static CharSequence joinNotEmpty(CharSequence separator, CharSequence[] sequences) {
+ int length = sequences.length;
+ if (length == 0) return "";
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (!TextUtils.isEmpty(sequences[i])) {
+ if (!TextUtils.isEmpty(sb)) {
+ sb.append(separator);
+ }
+ sb.append(sequences[i]);
+ }
+ }
+ return sb.toString();
+ }
+
+ private static List<CharSequence> append(List<CharSequence> list, CharSequence string) {
+ if (!TextUtils.isEmpty(string)) {
+ list.add(string);
+ }
+ return list;
+ }
+
+ private CharSequence getCarrierHelpTextForSimState(int simState,
+ String plmn, String spn) {
+ int carrierHelpTextId = 0;
+ CarrierTextManager.StatusMode status = getStatusForIccState(simState);
+ switch (status) {
+ case NetworkLocked:
+ carrierHelpTextId = R.string.keyguard_instructions_when_pattern_disabled;
+ break;
+
+ case SimMissing:
+ carrierHelpTextId = R.string.keyguard_missing_sim_instructions_long;
+ break;
+
+ case SimPermDisabled:
+ carrierHelpTextId = R.string.keyguard_permanent_disabled_sim_instructions;
+ break;
+
+ case SimMissingLocked:
+ carrierHelpTextId = R.string.keyguard_missing_sim_instructions;
+ break;
+
+ case Normal:
+ case SimLocked:
+ case SimPukLocked:
+ break;
+ }
+
+ return mContext.getText(carrierHelpTextId);
+ }
+
+ /** Injectable Buildeer for {@#link CarrierTextManager}. */
+ public static class Builder {
+ private final Context mContext;
+ private final String mSeparator;
+ private final WifiManager mWifiManager;
+ private final ConnectivityManager mConnectivityManager;
+ private final TelephonyManager mTelephonyManager;
+ private final WakefulnessLifecycle mWakefulnessLifecycle;
+ private final Handler mMainHandler;
+ private final Handler mBgHandler;
+ private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
+ private boolean mShowAirplaneMode;
+ private boolean mShowMissingSim;
+
+ @Inject
+ public Builder(Context context, @Main Resources resources,
+ @Nullable WifiManager wifiManager, ConnectivityManager connectivityManager,
+ TelephonyManager telephonyManager, WakefulnessLifecycle wakefulnessLifecycle,
+ @Main Handler mainHandler, @Background Handler bgHandler,
+ KeyguardUpdateMonitor keyguardUpdateMonitor) {
+ mContext = context;
+ mSeparator = resources.getString(
+ com.android.internal.R.string.kg_text_message_separator);
+ mWifiManager = wifiManager;
+ mConnectivityManager = connectivityManager;
+ mTelephonyManager = telephonyManager;
+ mWakefulnessLifecycle = wakefulnessLifecycle;
+ mMainHandler = mainHandler;
+ mBgHandler = bgHandler;
+ mKeyguardUpdateMonitor = keyguardUpdateMonitor;
+ }
+
+ /** */
+ public Builder setShowAirplaneMode(boolean showAirplaneMode) {
+ mShowAirplaneMode = showAirplaneMode;
+ return this;
+ }
+
+ /** */
+ public Builder setShowMissingSim(boolean showMissingSim) {
+ mShowMissingSim = showMissingSim;
+ return this;
+ }
+
+ /** Create a CarrierTextManager. */
+ public CarrierTextManager build() {
+ return new CarrierTextManager(
+ mContext, mSeparator, mShowAirplaneMode, mShowMissingSim, mWifiManager,
+ mConnectivityManager, mTelephonyManager, mWakefulnessLifecycle, mMainHandler,
+ mBgHandler, mKeyguardUpdateMonitor);
+ }
+ }
+ /**
+ * Data structure for passing information to CarrierTextController subscribers
+ */
+ public static final class CarrierTextCallbackInfo {
+ public final CharSequence carrierText;
+ public final CharSequence[] listOfCarriers;
+ public final boolean anySimReady;
+ public final int[] subscriptionIds;
+ public boolean airplaneMode;
+
+ @VisibleForTesting
+ public CarrierTextCallbackInfo(CharSequence carrierText, CharSequence[] listOfCarriers,
+ boolean anySimReady, int[] subscriptionIds) {
+ this(carrierText, listOfCarriers, anySimReady, subscriptionIds, false);
+ }
+
+ @VisibleForTesting
+ public CarrierTextCallbackInfo(CharSequence carrierText, CharSequence[] listOfCarriers,
+ boolean anySimReady, int[] subscriptionIds, boolean airplaneMode) {
+ this.carrierText = carrierText;
+ this.listOfCarriers = listOfCarriers;
+ this.anySimReady = anySimReady;
+ this.subscriptionIds = subscriptionIds;
+ this.airplaneMode = airplaneMode;
+ }
+ }
+
+ /**
+ * Callback to communicate to Views
+ */
+ public interface CarrierTextCallback {
+ /**
+ * Provides updated carrier information.
+ */
+ default void updateCarrierInfo(CarrierTextCallbackInfo info) {};
+
+ /**
+ * Notifies the View that the device is going to sleep
+ */
+ default void startedGoingToSleep() {};
+
+ /**
+ * Notifies the View that the device finished waking up
+ */
+ default void finishedWakingUp() {};
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
index 707ee298a55a..c4b02f62f291 100644
--- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
+++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
@@ -16,34 +16,16 @@
package com.android.keyguard;
-import static com.android.systemui.DejankUtils.whitelistIpcs;
-
-import android.app.ActivityOptions;
-import android.app.ActivityTaskManager;
import android.content.Context;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.os.PowerManager;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.telecom.TelecomManager;
-import android.telephony.TelephonyManager;
import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Slog;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.Button;
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.EmergencyAffordanceManager;
import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.Utils;
-import com.android.systemui.Dependency;
-import com.android.systemui.util.EmergencyDialerConstants;
/**
* This class implements a smart emergency button that updates itself based
@@ -53,34 +35,14 @@ import com.android.systemui.util.EmergencyDialerConstants;
*/
public class EmergencyButton extends Button {
- private static final String LOG_TAG = "EmergencyButton";
private final EmergencyAffordanceManager mEmergencyAffordanceManager;
private int mDownX;
private int mDownY;
- KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
-
- @Override
- public void onSimStateChanged(int subId, int slotId, int simState) {
- updateEmergencyCallButton();
- }
-
- @Override
- public void onPhoneStateChanged(int phoneState) {
- updateEmergencyCallButton();
- }
- };
private boolean mLongPressWasDragged;
- public interface EmergencyButtonCallback {
- public void onEmergencyButtonClickedWhenInCall();
- }
-
private LockPatternUtils mLockPatternUtils;
- private PowerManager mPowerManager;
- private EmergencyButtonCallback mEmergencyButtonCallback;
- private final boolean mIsVoiceCapable;
private final boolean mEnableEmergencyCallWhileSimLocked;
public EmergencyButton(Context context) {
@@ -89,34 +51,15 @@ public class EmergencyButton extends Button {
public EmergencyButton(Context context, AttributeSet attrs) {
super(context, attrs);
- mIsVoiceCapable = getTelephonyManager().isVoiceCapable();
mEnableEmergencyCallWhileSimLocked = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked);
mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
}
- private TelephonyManager getTelephonyManager() {
- return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mInfoCallback);
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mInfoCallback);
- }
-
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mLockPatternUtils = new LockPatternUtils(mContext);
- mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
- setOnClickListener(v -> takeEmergencyCallAction());
if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
setOnLongClickListener(v -> {
if (!mLongPressWasDragged
@@ -127,7 +70,6 @@ public class EmergencyButton extends Button {
return false;
});
}
- whitelistIpcs(this::updateEmergencyCallButton);
}
@Override
@@ -165,65 +107,13 @@ public class EmergencyButton extends Button {
return super.performLongClick();
}
- @Override
- protected void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- updateEmergencyCallButton();
- }
-
- /**
- * Shows the emergency dialer or returns the user to the existing call.
- */
- public void takeEmergencyCallAction() {
- MetricsLogger.action(mContext, MetricsEvent.ACTION_EMERGENCY_CALL);
- if (mPowerManager != null) {
- mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
- }
- try {
- ActivityTaskManager.getService().stopSystemLockTaskMode();
- } catch (RemoteException e) {
- Slog.w(LOG_TAG, "Failed to stop app pinning");
- }
- if (isInCall()) {
- resumeCall();
- if (mEmergencyButtonCallback != null) {
- mEmergencyButtonCallback.onEmergencyButtonClickedWhenInCall();
- }
- } else {
- KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
- if (updateMonitor != null) {
- updateMonitor.reportEmergencyCallAction(true /* bypassHandler */);
- } else {
- Log.w(LOG_TAG, "KeyguardUpdateMonitor was null, launching intent anyway.");
- }
- TelecomManager telecomManager = getTelecommManager();
- if (telecomManager == null) {
- Log.wtf(LOG_TAG, "TelecomManager was null, cannot launch emergency dialer");
- return;
- }
- Intent emergencyDialIntent =
- telecomManager.createLaunchEmergencyDialerIntent(null /* number*/)
- .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- | Intent.FLAG_ACTIVITY_CLEAR_TOP)
- .putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
- EmergencyDialerConstants.ENTRY_TYPE_LOCKSCREEN_BUTTON);
-
- getContext().startActivityAsUser(emergencyDialIntent,
- ActivityOptions.makeCustomAnimation(getContext(), 0, 0).toBundle(),
- new UserHandle(KeyguardUpdateMonitor.getCurrentUser()));
- }
- }
-
- private void updateEmergencyCallButton() {
+ void updateEmergencyCallButton(boolean isInCall, boolean isVoiceCapable, boolean simLocked) {
boolean visible = false;
- if (mIsVoiceCapable) {
+ if (isVoiceCapable) {
// Emergency calling requires voice capability.
- if (isInCall()) {
+ if (isInCall) {
visible = true; // always show "return to call" if phone is off-hook
} else {
- final boolean simLocked = Dependency.get(KeyguardUpdateMonitor.class)
- .isSimPinVoiceSecure();
if (simLocked) {
// Some countries can't handle emergency calls while SIM is locked.
visible = mEnableEmergencyCallWhileSimLocked;
@@ -237,7 +127,7 @@ public class EmergencyButton extends Button {
setVisibility(View.VISIBLE);
int textId;
- if (isInCall()) {
+ if (isInCall) {
textId = com.android.internal.R.string.lockscreen_return_to_call;
} else {
textId = com.android.internal.R.string.lockscreen_emergency_call;
@@ -247,26 +137,4 @@ public class EmergencyButton extends Button {
setVisibility(View.GONE);
}
}
-
- public void setCallback(EmergencyButtonCallback callback) {
- mEmergencyButtonCallback = callback;
- }
-
- /**
- * Resumes a call in progress.
- */
- private void resumeCall() {
- getTelecommManager().showInCallScreen(false);
- }
-
- /**
- * @return {@code true} if there is a call currently in progress.
- */
- private boolean isInCall() {
- return getTelecommManager().isInCall();
- }
-
- private TelecomManager getTelecommManager() {
- return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
- }
}
diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java
new file mode 100644
index 000000000000..4275189cfe26
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java
@@ -0,0 +1,196 @@
+/*
+ * 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.
+ */
+
+package com.android.keyguard;
+
+import static com.android.systemui.DejankUtils.whitelistIpcs;
+
+import android.app.ActivityOptions;
+import android.app.ActivityTaskManager;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.telecom.TelecomManager;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+
+import androidx.annotation.Nullable;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.keyguard.dagger.KeyguardBouncerScope;
+import com.android.systemui.statusbar.policy.ConfigurationController;
+import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
+import com.android.systemui.util.EmergencyDialerConstants;
+import com.android.systemui.util.ViewController;
+
+import javax.inject.Inject;
+
+/** View Controller for {@link com.android.keyguard.EmergencyButton}. */
+@KeyguardBouncerScope
+public class EmergencyButtonController extends ViewController<EmergencyButton> {
+ static final String LOG_TAG = "EmergencyButton";
+ private final ConfigurationController mConfigurationController;
+ private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
+ private final TelephonyManager mTelephonyManager;
+ private final PowerManager mPowerManager;
+ private final ActivityTaskManager mActivityTaskManager;
+ private final TelecomManager mTelecomManager;
+ private final MetricsLogger mMetricsLogger;
+
+ private EmergencyButtonCallback mEmergencyButtonCallback;
+
+ private final KeyguardUpdateMonitorCallback mInfoCallback =
+ new KeyguardUpdateMonitorCallback() {
+ @Override
+ public void onSimStateChanged(int subId, int slotId, int simState) {
+ updateEmergencyCallButton();
+ }
+
+ @Override
+ public void onPhoneStateChanged(int phoneState) {
+ updateEmergencyCallButton();
+ }
+ };
+
+ private final ConfigurationListener mConfigurationListener = new ConfigurationListener() {
+ @Override
+ public void onConfigChanged(Configuration newConfig) {
+ updateEmergencyCallButton();
+ }
+ };
+
+ private EmergencyButtonController(@Nullable EmergencyButton view,
+ ConfigurationController configurationController,
+ KeyguardUpdateMonitor keyguardUpdateMonitor, TelephonyManager telephonyManager,
+ PowerManager powerManager, ActivityTaskManager activityTaskManager,
+ @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger) {
+ super(view);
+ mConfigurationController = configurationController;
+ mKeyguardUpdateMonitor = keyguardUpdateMonitor;
+ mTelephonyManager = telephonyManager;
+ mPowerManager = powerManager;
+ mActivityTaskManager = activityTaskManager;
+ mTelecomManager = telecomManager;
+ mMetricsLogger = metricsLogger;
+ }
+
+ @Override
+ protected void onInit() {
+ whitelistIpcs(this::updateEmergencyCallButton);
+ }
+
+ @Override
+ protected void onViewAttached() {
+ mKeyguardUpdateMonitor.registerCallback(mInfoCallback);
+ mConfigurationController.addCallback(mConfigurationListener);
+ mView.setOnClickListener(v -> takeEmergencyCallAction());
+ }
+
+ @Override
+ protected void onViewDetached() {
+ mKeyguardUpdateMonitor.removeCallback(mInfoCallback);
+ mConfigurationController.removeCallback(mConfigurationListener);
+ }
+
+ private void updateEmergencyCallButton() {
+ if (mView != null) {
+ mView.updateEmergencyCallButton(
+ mTelecomManager != null && mTelecomManager.isInCall(),
+ mTelephonyManager.isVoiceCapable(),
+ mKeyguardUpdateMonitor.isSimPinVoiceSecure());
+ }
+ }
+
+ public void setEmergencyButtonCallback(EmergencyButtonCallback callback) {
+ mEmergencyButtonCallback = callback;
+ }
+ /**
+ * Shows the emergency dialer or returns the user to the existing call.
+ */
+ public void takeEmergencyCallAction() {
+ mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_CALL);
+ if (mPowerManager != null) {
+ mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
+ }
+ mActivityTaskManager.stopSystemLockTaskMode();
+ if (mTelecomManager != null && mTelecomManager.isInCall()) {
+ mTelecomManager.showInCallScreen(false);
+ if (mEmergencyButtonCallback != null) {
+ mEmergencyButtonCallback.onEmergencyButtonClickedWhenInCall();
+ }
+ } else {
+ mKeyguardUpdateMonitor.reportEmergencyCallAction(true /* bypassHandler */);
+ if (mTelecomManager == null) {
+ Log.wtf(LOG_TAG, "TelecomManager was null, cannot launch emergency dialer");
+ return;
+ }
+ Intent emergencyDialIntent =
+ mTelecomManager.createLaunchEmergencyDialerIntent(null /* number*/)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
+ | Intent.FLAG_ACTIVITY_CLEAR_TOP)
+ .putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
+ EmergencyDialerConstants.ENTRY_TYPE_LOCKSCREEN_BUTTON);
+
+ getContext().startActivityAsUser(emergencyDialIntent,
+ ActivityOptions.makeCustomAnimation(getContext(), 0, 0).toBundle(),
+ new UserHandle(KeyguardUpdateMonitor.getCurrentUser()));
+ }
+ }
+
+ /** */
+ public interface EmergencyButtonCallback {
+ /** */
+ void onEmergencyButtonClickedWhenInCall();
+ }
+
+ /** Injectable Factory for creating {@link EmergencyButtonController}. */
+ public static class Factory {
+ private final ConfigurationController mConfigurationController;
+ private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
+ private final TelephonyManager mTelephonyManager;
+ private final PowerManager mPowerManager;
+ private final ActivityTaskManager mActivityTaskManager;
+ @Nullable
+ private final TelecomManager mTelecomManager;
+ private final MetricsLogger mMetricsLogger;
+
+ @Inject
+ public Factory(ConfigurationController configurationController,
+ KeyguardUpdateMonitor keyguardUpdateMonitor, TelephonyManager telephonyManager,
+ PowerManager powerManager, ActivityTaskManager activityTaskManager,
+ @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger) {
+
+ mConfigurationController = configurationController;
+ mKeyguardUpdateMonitor = keyguardUpdateMonitor;
+ mTelephonyManager = telephonyManager;
+ mPowerManager = powerManager;
+ mActivityTaskManager = activityTaskManager;
+ mTelecomManager = telecomManager;
+ mMetricsLogger = metricsLogger;
+ }
+
+ /** Construct an {@link com.android.keyguard.EmergencyButtonController}. */
+ public EmergencyButtonController create(EmergencyButton view) {
+ return new EmergencyButtonController(view, mConfigurationController,
+ mKeyguardUpdateMonitor, mTelephonyManager, mPowerManager, mActivityTaskManager,
+ mTelecomManager, mMetricsLogger);
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java
index 5760565aaab1..7a05a17c8010 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java
@@ -31,7 +31,7 @@ import com.android.internal.util.LatencyTracker;
import com.android.internal.widget.LockPatternChecker;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockscreenCredential;
-import com.android.keyguard.EmergencyButton.EmergencyButtonCallback;
+import com.android.keyguard.EmergencyButtonController.EmergencyButtonCallback;
import com.android.keyguard.KeyguardAbsKeyInputView.KeyDownListener;
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
import com.android.systemui.R;
@@ -41,6 +41,7 @@ public abstract class KeyguardAbsKeyInputViewController<T extends KeyguardAbsKey
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final LockPatternUtils mLockPatternUtils;
private final LatencyTracker mLatencyTracker;
+ private final EmergencyButtonController mEmergencyButtonController;
private CountDownTimer mCountdownTimer;
protected KeyguardMessageAreaController mMessageAreaController;
private boolean mDismissing;
@@ -70,11 +71,12 @@ public abstract class KeyguardAbsKeyInputViewController<T extends KeyguardAbsKey
LockPatternUtils lockPatternUtils,
KeyguardSecurityCallback keyguardSecurityCallback,
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
- LatencyTracker latencyTracker) {
- super(view, securityMode, keyguardSecurityCallback);
+ LatencyTracker latencyTracker, EmergencyButtonController emergencyButtonController) {
+ super(view, securityMode, keyguardSecurityCallback, emergencyButtonController);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mLockPatternUtils = lockPatternUtils;
mLatencyTracker = latencyTracker;
+ mEmergencyButtonController = emergencyButtonController;
KeyguardMessageArea kma = KeyguardMessageArea.findSecurityMessageDisplay(mView);
mMessageAreaController = messageAreaControllerFactory.create(kma);
}
@@ -83,6 +85,7 @@ public abstract class KeyguardAbsKeyInputViewController<T extends KeyguardAbsKey
@Override
public void onInit() {
+ super.onInit();
mMessageAreaController.init();
}
@@ -91,10 +94,7 @@ public abstract class KeyguardAbsKeyInputViewController<T extends KeyguardAbsKey
super.onViewAttached();
mView.setKeyDownListener(mKeyDownListener);
mView.setEnableHaptics(mLockPatternUtils.isTactileFeedbackEnabled());
- EmergencyButton button = mView.findViewById(R.id.emergency_call_button);
- if (button != null) {
- button.setCallback(mEmergencyButtonCallback);
- }
+ mEmergencyButtonController.setEmergencyButtonCallback(mEmergencyButtonCallback);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java b/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
index 276036c400e1..76a7473e25e8 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
@@ -36,7 +36,6 @@ import android.view.WindowManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.keyguard.dagger.KeyguardStatusViewComponent;
-import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.navigationbar.NavigationBarController;
@@ -46,12 +45,15 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;
+import dagger.Lazy;
+
public class KeyguardDisplayManager {
protected static final String TAG = "KeyguardDisplayManager";
private static boolean DEBUG = KeyguardConstants.DEBUG;
private MediaRouter mMediaRouter = null;
private final DisplayManager mDisplayService;
+ private final Lazy<NavigationBarController> mNavigationBarControllerLazy;
private final KeyguardStatusViewComponent.Factory mKeyguardStatusViewComponentFactory;
private final Context mContext;
@@ -85,9 +87,11 @@ public class KeyguardDisplayManager {
@Inject
public KeyguardDisplayManager(Context context,
+ Lazy<NavigationBarController> navigationBarControllerLazy,
KeyguardStatusViewComponent.Factory keyguardStatusViewComponentFactory,
@UiBackground Executor uiBgExecutor) {
mContext = context;
+ mNavigationBarControllerLazy = navigationBarControllerLazy;
mKeyguardStatusViewComponentFactory = keyguardStatusViewComponentFactory;
uiBgExecutor.execute(() -> mMediaRouter = mContext.getSystemService(MediaRouter.class));
mDisplayService = mContext.getSystemService(DisplayManager.class);
@@ -240,7 +244,7 @@ public class KeyguardDisplayManager {
// Leave this task to {@link StatusBarKeyguardViewManager}
if (displayId == DEFAULT_DISPLAY) return;
- NavigationBarView navBarView = Dependency.get(NavigationBarController.class)
+ NavigationBarView navBarView = mNavigationBarControllerLazy.get()
.getNavigationBarView(displayId);
// We may not have nav bar on a display.
if (navBarView == null) return;
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java
index 1c691e7098a1..a0c5958284ec 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java
@@ -28,6 +28,7 @@ import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.concurrency.DelayableExecutor;
@@ -41,6 +42,7 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
private final SecurityMode mSecurityMode;
private final KeyguardSecurityCallback mKeyguardSecurityCallback;
private final EmergencyButton mEmergencyButton;
+ private final EmergencyButtonController mEmergencyButtonController;
private boolean mPaused;
@@ -68,11 +70,18 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
};
protected KeyguardInputViewController(T view, SecurityMode securityMode,
- KeyguardSecurityCallback keyguardSecurityCallback) {
+ KeyguardSecurityCallback keyguardSecurityCallback,
+ EmergencyButtonController emergencyButtonController) {
super(view);
mSecurityMode = securityMode;
mKeyguardSecurityCallback = keyguardSecurityCallback;
mEmergencyButton = view == null ? null : view.findViewById(R.id.emergency_call_button);
+ mEmergencyButtonController = emergencyButtonController;
+ }
+
+ @Override
+ protected void onInit() {
+ mEmergencyButtonController.init();
}
@Override
@@ -154,9 +163,11 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
private final InputMethodManager mInputMethodManager;
private final DelayableExecutor mMainExecutor;
private final Resources mResources;
- private LiftToActivateListener mLiftToActivateListener;
- private TelephonyManager mTelephonyManager;
+ private final LiftToActivateListener mLiftToActivateListener;
+ private final TelephonyManager mTelephonyManager;
+ private final EmergencyButtonController.Factory mEmergencyButtonControllerFactory;
private final FalsingCollector mFalsingCollector;
+ private final boolean mIsNewLayoutEnabled;
@Inject
public Factory(KeyguardUpdateMonitor keyguardUpdateMonitor,
@@ -165,7 +176,10 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
InputMethodManager inputMethodManager, @Main DelayableExecutor mainExecutor,
@Main Resources resources, LiftToActivateListener liftToActivateListener,
- TelephonyManager telephonyManager, FalsingCollector falsingCollector) {
+ TelephonyManager telephonyManager,
+ EmergencyButtonController.Factory emergencyButtonControllerFactory,
+ FalsingCollector falsingCollector,
+ FeatureFlags featureFlags) {
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mLockPatternUtils = lockPatternUtils;
mLatencyTracker = latencyTracker;
@@ -175,36 +189,49 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
mResources = resources;
mLiftToActivateListener = liftToActivateListener;
mTelephonyManager = telephonyManager;
+ mEmergencyButtonControllerFactory = emergencyButtonControllerFactory;
mFalsingCollector = falsingCollector;
+ mIsNewLayoutEnabled = featureFlags.isKeyguardLayoutEnabled();
}
/** Create a new {@link KeyguardInputViewController}. */
public KeyguardInputViewController create(KeyguardInputView keyguardInputView,
SecurityMode securityMode, KeyguardSecurityCallback keyguardSecurityCallback) {
+ EmergencyButtonController emergencyButtonController =
+ mEmergencyButtonControllerFactory.create(
+ keyguardInputView.findViewById(R.id.emergency_call_button));
+
if (keyguardInputView instanceof KeyguardPatternView) {
return new KeyguardPatternViewController((KeyguardPatternView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
- keyguardSecurityCallback, mLatencyTracker, mMessageAreaControllerFactory);
+ keyguardSecurityCallback, mLatencyTracker,
+ emergencyButtonController,
+ mMessageAreaControllerFactory);
} else if (keyguardInputView instanceof KeyguardPasswordView) {
return new KeyguardPasswordViewController((KeyguardPasswordView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
- mInputMethodManager, mMainExecutor, mResources);
+ mInputMethodManager, emergencyButtonController, mMainExecutor, mResources);
} else if (keyguardInputView instanceof KeyguardPINView) {
return new KeyguardPinViewController((KeyguardPINView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
- mLiftToActivateListener, mFalsingCollector);
+ mLiftToActivateListener, emergencyButtonController, mFalsingCollector,
+ mIsNewLayoutEnabled);
} else if (keyguardInputView instanceof KeyguardSimPinView) {
return new KeyguardSimPinViewController((KeyguardSimPinView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
- mLiftToActivateListener, mTelephonyManager, mFalsingCollector);
+ mLiftToActivateListener, mTelephonyManager,
+ emergencyButtonController,
+ mFalsingCollector, mIsNewLayoutEnabled);
} else if (keyguardInputView instanceof KeyguardSimPukView) {
return new KeyguardSimPukViewController((KeyguardSimPukView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
- mLiftToActivateListener, mTelephonyManager, mFalsingCollector);
+ mLiftToActivateListener, mTelephonyManager,
+ emergencyButtonController,
+ mFalsingCollector, mIsNewLayoutEnabled);
}
throw new RuntimeException("Unable to find controller for " + keyguardInputView);
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java
index 0f1c3c8a20b7..2e4554592580 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java
@@ -111,10 +111,11 @@ public class KeyguardPasswordViewController
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker,
InputMethodManager inputMethodManager,
+ EmergencyButtonController emergencyButtonController,
@Main DelayableExecutor mainExecutor,
@Main Resources resources) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
- messageAreaControllerFactory, latencyTracker);
+ messageAreaControllerFactory, latencyTracker, emergencyButtonController);
mKeyguardSecurityCallback = keyguardSecurityCallback;
mInputMethodManager = inputMethodManager;
mMainExecutor = mainExecutor;
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java
index 2aaf748e2415..55e348cc06b1 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java
@@ -31,7 +31,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternView;
import com.android.internal.widget.LockPatternView.Cell;
import com.android.internal.widget.LockscreenCredential;
-import com.android.keyguard.EmergencyButton.EmergencyButtonCallback;
+import com.android.keyguard.EmergencyButtonController.EmergencyButtonCallback;
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
import com.android.settingslib.Utils;
import com.android.systemui.R;
@@ -50,6 +50,7 @@ public class KeyguardPatternViewController
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final LockPatternUtils mLockPatternUtils;
private final LatencyTracker mLatencyTracker;
+ private final EmergencyButtonController mEmergencyButtonController;
private final KeyguardMessageAreaController.Factory mMessageAreaControllerFactory;
private KeyguardMessageAreaController mMessageAreaController;
@@ -179,11 +180,13 @@ public class KeyguardPatternViewController
LockPatternUtils lockPatternUtils,
KeyguardSecurityCallback keyguardSecurityCallback,
LatencyTracker latencyTracker,
+ EmergencyButtonController emergencyButtonController,
KeyguardMessageAreaController.Factory messageAreaControllerFactory) {
- super(view, securityMode, keyguardSecurityCallback);
+ super(view, securityMode, keyguardSecurityCallback, emergencyButtonController);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mLockPatternUtils = lockPatternUtils;
mLatencyTracker = latencyTracker;
+ mEmergencyButtonController = emergencyButtonController;
mMessageAreaControllerFactory = messageAreaControllerFactory;
KeyguardMessageArea kma = KeyguardMessageArea.findSecurityMessageDisplay(mView);
mMessageAreaController = mMessageAreaControllerFactory.create(kma);
@@ -205,11 +208,7 @@ public class KeyguardPatternViewController
KeyguardUpdateMonitor.getCurrentUser()));
// vibrate mode will be the same for the life of this screen
mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled());
-
- EmergencyButton button = mView.findViewById(R.id.emergency_call_button);
- if (button != null) {
- button.setCallback(mEmergencyButtonCallback);
- }
+ mEmergencyButtonController.setEmergencyButtonCallback(mEmergencyButtonCallback);
View cancelBtn = mView.findViewById(R.id.cancel_button);
if (cancelBtn != null) {
@@ -224,10 +223,7 @@ public class KeyguardPatternViewController
protected void onViewDetached() {
super.onViewDetached();
mLockPatternView.setOnPatternListener(null);
- EmergencyButton button = mView.findViewById(R.id.emergency_call_button);
- if (button != null) {
- button.setCallback(null);
- }
+ mEmergencyButtonController.setEmergencyButtonCallback(null);
View cancelBtn = mView.findViewById(R.id.cancel_button);
if (cancelBtn != null) {
cancelBtn.setOnClickListener(null);
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
index 6a6b964c2a8f..825ea2570df0 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
@@ -167,6 +167,20 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
}
/**
+ * By default, the new layout will be enabled. When false, revert to the old style.
+ */
+ public void setIsNewLayoutEnabled(boolean isEnabled) {
+ if (!isEnabled) {
+ for (int i = 0; i < mButtons.length; i++) {
+ mButtons[i].disableNewLayout();
+ }
+ mDeleteButton.disableNewLayout();
+ mOkButton.disableNewLayout();
+ reloadColors();
+ }
+ }
+
+ /**
* Reload colors from resources.
**/
public void reloadColors() {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java
index f2479488db0f..1b5aa453ac97 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java
@@ -71,9 +71,10 @@ public abstract class KeyguardPinBasedInputViewController<T extends KeyguardPinB
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker,
LiftToActivateListener liftToActivateListener,
+ EmergencyButtonController emergencyButtonController,
FalsingCollector falsingCollector) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
- messageAreaControllerFactory, latencyTracker);
+ messageAreaControllerFactory, latencyTracker, emergencyButtonController);
mLiftToActivateListener = liftToActivateListener;
mFalsingCollector = falsingCollector;
mPasswordEntry = mView.findViewById(mView.getPasswordTextViewId());
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java
index c0aa2af00a74..a456d42f5be5 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java
@@ -34,11 +34,13 @@ public class KeyguardPinViewController
KeyguardSecurityCallback keyguardSecurityCallback,
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
- FalsingCollector falsingCollector) {
+ EmergencyButtonController emergencyButtonController,
+ FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
- falsingCollector);
+ emergencyButtonController, falsingCollector);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
+ view.setIsNewLayoutEnabled(isNewLayoutEnabled);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
index c77c86711abf..bacd29f661ae 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
@@ -23,7 +23,6 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import com.android.internal.widget.LockPatternUtils;
-import com.android.systemui.Dependency;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
@@ -49,24 +48,27 @@ public class KeyguardSecurityModel {
private final boolean mIsPukScreenAvailable;
private final LockPatternUtils mLockPatternUtils;
+ private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@Inject
- KeyguardSecurityModel(@Main Resources resources, LockPatternUtils lockPatternUtils) {
+ KeyguardSecurityModel(@Main Resources resources, LockPatternUtils lockPatternUtils,
+ KeyguardUpdateMonitor keyguardUpdateMonitor) {
mIsPukScreenAvailable = resources.getBoolean(
com.android.internal.R.bool.config_enable_puk_unlock_screen);
mLockPatternUtils = lockPatternUtils;
+ mKeyguardUpdateMonitor = keyguardUpdateMonitor;
}
public SecurityMode getSecurityMode(int userId) {
- KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class);
-
if (mIsPukScreenAvailable && SubscriptionManager.isValidSubscriptionId(
- monitor.getNextSubIdForState(TelephonyManager.SIM_STATE_PUK_REQUIRED))) {
+ mKeyguardUpdateMonitor.getNextSubIdForState(
+ TelephonyManager.SIM_STATE_PUK_REQUIRED))) {
return SecurityMode.SimPuk;
}
if (SubscriptionManager.isValidSubscriptionId(
- monitor.getNextSubIdForState(TelephonyManager.SIM_STATE_PIN_REQUIRED))) {
+ mKeyguardUpdateMonitor.getNextSubIdForState(
+ TelephonyManager.SIM_STATE_PIN_REQUIRED))) {
return SecurityMode.SimPin;
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java
index f1b504e9f941..33d47fe13f38 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java
@@ -44,15 +44,18 @@ public class KeyguardSecurityViewFlipperController
private final List<KeyguardInputViewController<KeyguardInputView>> mChildren =
new ArrayList<>();
private final LayoutInflater mLayoutInflater;
+ private final EmergencyButtonController.Factory mEmergencyButtonControllerFactory;
private final Factory mKeyguardSecurityViewControllerFactory;
@Inject
protected KeyguardSecurityViewFlipperController(KeyguardSecurityViewFlipper view,
LayoutInflater layoutInflater,
- KeyguardInputViewController.Factory keyguardSecurityViewControllerFactory) {
+ KeyguardInputViewController.Factory keyguardSecurityViewControllerFactory,
+ EmergencyButtonController.Factory emergencyButtonControllerFactory) {
super(view);
mKeyguardSecurityViewControllerFactory = keyguardSecurityViewControllerFactory;
mLayoutInflater = layoutInflater;
+ mEmergencyButtonControllerFactory = emergencyButtonControllerFactory;
}
@Override
@@ -111,7 +114,8 @@ public class KeyguardSecurityViewFlipperController
if (childController == null) {
childController = new NullKeyguardInputViewController(
- securityMode, keyguardSecurityCallback);
+ securityMode, keyguardSecurityCallback,
+ mEmergencyButtonControllerFactory.create(null));
}
return childController;
@@ -140,8 +144,9 @@ public class KeyguardSecurityViewFlipperController
private static class NullKeyguardInputViewController
extends KeyguardInputViewController<KeyguardInputView> {
protected NullKeyguardInputViewController(SecurityMode securityMode,
- KeyguardSecurityCallback keyguardSecurityCallback) {
- super(null, securityMode, keyguardSecurityCallback);
+ KeyguardSecurityCallback keyguardSecurityCallback,
+ EmergencyButtonController emergencyButtonController) {
+ super(null, securityMode, keyguardSecurityCallback, emergencyButtonController);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java
index b21814134607..4d2ebbb4a594 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java
@@ -78,13 +78,15 @@ public class KeyguardSimPinViewController
KeyguardSecurityCallback keyguardSecurityCallback,
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
- TelephonyManager telephonyManager, FalsingCollector falsingCollector) {
+ TelephonyManager telephonyManager, EmergencyButtonController emergencyButtonController,
+ FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
- falsingCollector);
+ emergencyButtonController, falsingCollector);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mTelephonyManager = telephonyManager;
mSimImageView = mView.findViewById(R.id.keyguard_sim);
+ view.setIsNewLayoutEnabled(isNewLayoutEnabled);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java
index 890a17c1cf92..0d9bb6f73b49 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java
@@ -37,7 +37,6 @@ import android.widget.ImageView;
import com.android.internal.util.LatencyTracker;
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
-import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingCollector;
@@ -85,13 +84,15 @@ public class KeyguardSimPukViewController
KeyguardSecurityCallback keyguardSecurityCallback,
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
- TelephonyManager telephonyManager, FalsingCollector falsingCollector) {
+ TelephonyManager telephonyManager, EmergencyButtonController emergencyButtonController,
+ FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
- falsingCollector);
+ emergencyButtonController, falsingCollector);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mTelephonyManager = telephonyManager;
mSimImageView = mView.findViewById(R.id.keyguard_sim);
+ view.setIsNewLayoutEnabled(isNewLayoutEnabled);
}
@Override
@@ -196,8 +197,7 @@ public class KeyguardSimPukViewController
if (count < 2) {
msg = rez.getString(R.string.kg_puk_enter_puk_hint);
} else {
- SubscriptionInfo info = Dependency.get(KeyguardUpdateMonitor.class)
- .getSubscriptionInfoForSubId(mSubId);
+ SubscriptionInfo info = mKeyguardUpdateMonitor.getSubscriptionInfoForSubId(mSubId);
CharSequence displayName = info != null ? info.getDisplayName() : "";
msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
if (info != null) {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
index fb97a30f93fb..1fbf71de47ca 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
@@ -49,10 +49,8 @@ import androidx.slice.widget.SliceContent;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
import com.android.settingslib.Utils;
-import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
-import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.util.wakelock.KeepAwakeAnimationListener;
import java.io.FileDescriptor;
@@ -317,6 +315,22 @@ public class KeyguardSliceView extends LinearLayout {
R.dimen.widget_label_font_size);
mRowWithHeaderTextSize = mContext.getResources().getDimensionPixelSize(
R.dimen.header_row_font_size);
+
+ for (int i = 0; i < mRow.getChildCount(); i++) {
+ View child = mRow.getChildAt(i);
+ if (child instanceof KeyguardSliceTextView) {
+ ((KeyguardSliceTextView) child).onDensityOrFontScaleChanged();
+ }
+ }
+ }
+
+ void onOverlayChanged() {
+ for (int i = 0; i < mRow.getChildCount(); i++) {
+ View child = mRow.getChildAt(i);
+ if (child instanceof KeyguardSliceTextView) {
+ ((KeyguardSliceTextView) child).onOverlayChanged();
+ }
+ }
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -479,8 +493,7 @@ public class KeyguardSliceView extends LinearLayout {
* Representation of an item that appears under the clock on main keyguard message.
*/
@VisibleForTesting
- static class KeyguardSliceTextView extends TextView implements
- ConfigurationController.ConfigurationListener {
+ static class KeyguardSliceTextView extends TextView {
private int mLockScreenMode = KeyguardUpdateMonitor.LOCK_SCREEN_MODE_NORMAL;
@StyleRes
@@ -492,24 +505,10 @@ public class KeyguardSliceView extends LinearLayout {
setEllipsize(TruncateAt.END);
}
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- Dependency.get(ConfigurationController.class).addCallback(this);
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- Dependency.get(ConfigurationController.class).removeCallback(this);
- }
-
- @Override
public void onDensityOrFontScaleChanged() {
updatePadding();
}
- @Override
public void onOverlayChanged() {
setTextAppearance(sStyleId);
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSliceViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSliceViewController.java
index 1b0a7faeddab..8038ce4c7b69 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSliceViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSliceViewController.java
@@ -83,6 +83,10 @@ public class KeyguardSliceViewController extends ViewController<KeyguardSliceVie
public void onDensityOrFontScaleChanged() {
mView.onDensityOrFontScaleChanged();
}
+ @Override
+ public void onOverlayChanged() {
+ mView.onOverlayChanged();
+ }
};
Observer<Slice> mObserver = new Observer<Slice>() {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
index fea152abe36a..5db4f9e61140 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
@@ -34,7 +34,6 @@ import android.widget.TextView;
import androidx.core.graphics.ColorUtils;
import com.android.internal.widget.LockPatternUtils;
-import com.android.systemui.Dependency;
import com.android.systemui.R;
import java.io.FileDescriptor;
@@ -56,7 +55,6 @@ public class KeyguardStatusView extends GridLayout {
private final IActivityManager mIActivityManager;
private TextView mLogoutView;
- private boolean mCanShowLogout = true; // by default, try to show the logout button here
private KeyguardClockSwitch mClockView;
private TextView mOwnerInfo;
private boolean mCanShowOwnerInfo = true; // by default, try to show the owner information here
@@ -130,11 +128,6 @@ public class KeyguardStatusView extends GridLayout {
}
}
- void setCanShowLogout(boolean canShowLogout) {
- mCanShowLogout = canShowLogout;
- updateLogoutView();
- }
-
@Override
protected void onFinishInflate() {
super.onFinishInflate();
@@ -159,10 +152,7 @@ public class KeyguardStatusView extends GridLayout {
mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged);
onSliceContentChanged();
- boolean shouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive();
- setEnableMarquee(shouldMarquee);
updateOwnerInfo();
- updateLogoutView();
updateDark();
}
@@ -209,11 +199,11 @@ public class KeyguardStatusView extends GridLayout {
return mOwnerInfo.getVisibility() == VISIBLE ? mOwnerInfo.getHeight() : 0;
}
- void updateLogoutView() {
+ void updateLogoutView(boolean shouldShowLogout) {
if (mLogoutView == null) {
return;
}
- mLogoutView.setVisibility(mCanShowLogout && shouldShowLogout() ? VISIBLE : GONE);
+ mLogoutView.setVisibility(shouldShowLogout ? VISIBLE : GONE);
// Logout button will stay in language of user 0 if we don't set that manually.
mLogoutView.setText(mContext.getResources().getString(
com.android.internal.R.string.global_action_logout));
@@ -313,11 +303,6 @@ public class KeyguardStatusView extends GridLayout {
}
}
- private boolean shouldShowLogout() {
- return Dependency.get(KeyguardUpdateMonitor.class).isLogoutEnabled()
- && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
- }
-
private void onLogoutClicked(View view) {
int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
try {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java
index 6fb6760be653..bfe7f8c7ebd8 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java
@@ -16,6 +16,7 @@
package com.android.keyguard;
+import android.os.UserHandle;
import android.util.Slog;
import android.view.View;
@@ -78,6 +79,8 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
@Override
public void onInit() {
mKeyguardClockSwitchController.init();
+ mView.setEnableMarquee(mKeyguardUpdateMonitor.isDeviceInteractive());
+ mView.updateLogoutView(shouldShowLogout());
}
@Override
@@ -245,6 +248,11 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
}
}
+ private boolean shouldShowLogout() {
+ return mKeyguardUpdateMonitor.isLogoutEnabled()
+ && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
+ }
+
private final ConfigurationController.ConfigurationListener mConfigurationListener =
new ConfigurationController.ConfigurationListener() {
@Override
@@ -271,12 +279,12 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
mKeyguardSliceViewController.updateTopMargin(
mKeyguardClockSwitchController.getClockTextTopPadding());
mView.setCanShowOwnerInfo(false);
- mView.setCanShowLogout(false);
+ mView.updateLogoutView(false);
} else {
// reset margin
mKeyguardSliceViewController.updateTopMargin(0);
mView.setCanShowOwnerInfo(true);
- mView.setCanShowLogout(false);
+ mView.updateLogoutView(false);
}
updateAodIcons();
}
@@ -302,7 +310,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing);
refreshTime();
mView.updateOwnerInfo();
- mView.updateLogoutView();
+ mView.updateLogoutView(shouldShowLogout());
}
}
@@ -320,12 +328,12 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
public void onUserSwitchComplete(int userId) {
mKeyguardClockSwitchController.refreshFormat();
mView.updateOwnerInfo();
- mView.updateLogoutView();
+ mView.updateLogoutView(shouldShowLogout());
}
@Override
public void onLogoutEnabledChanged() {
- mView.updateLogoutView();
+ mView.updateLogoutView(shouldShowLogout());
}
};
}
diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
index 372810677649..886c3729124b 100644
--- a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
+++ b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
@@ -16,17 +16,23 @@
package com.android.keyguard;
import android.content.Context;
+import android.content.res.ColorStateList;
import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.VectorDrawable;
import android.util.AttributeSet;
+import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
import android.view.ViewGroup;
+import com.android.settingslib.Utils;
+import com.android.systemui.R;
+
/**
* Similar to the {@link NumPadKey}, but displays an image.
*/
public class NumPadButton extends AlphaOptimizedImageButton {
- private final NumPadAnimator mAnimator;
+ private NumPadAnimator mAnimator;
public NumPadButton(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -36,25 +42,34 @@ public class NumPadButton extends AlphaOptimizedImageButton {
}
@Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- mAnimator.updateMargin((ViewGroup.MarginLayoutParams) getLayoutParams());
+ public void setLayoutParams(ViewGroup.LayoutParams params) {
+ if (mAnimator != null) mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
+ super.setLayoutParams(params);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- // Set width/height to the same value to ensure a smooth circle for the bg
- setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
+ // Set width/height to the same value to ensure a smooth circle for the bg, but shrink
+ // the height to match the old pin bouncer
+ int width = getMeasuredWidth();
+ int height = mAnimator == null ? (int) (width * .75f) : width;
+
+ setMeasuredDimension(getMeasuredWidth(), height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
- mAnimator.onLayout(b - t);
+ if (mAnimator != null) mAnimator.onLayout(b - t);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
- mAnimator.start();
+ if (mAnimator != null) mAnimator.start();
return super.onTouchEvent(event);
}
@@ -62,6 +77,23 @@ public class NumPadButton extends AlphaOptimizedImageButton {
* Reload colors from resources.
**/
public void reloadColors() {
- mAnimator.reloadColors(getContext());
+ if (mAnimator != null) {
+ mAnimator.reloadColors(getContext());
+ } else {
+ // Needed for old style pin
+ int textColor = Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary)
+ .getDefaultColor();
+ ((VectorDrawable) getDrawable()).setTintList(ColorStateList.valueOf(textColor));
+ }
+ }
+
+ /**
+ * By default, the new layout will be enabled. Invoking will revert to the old style
+ */
+ public void disableNewLayout() {
+ mAnimator = null;
+ ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
+ setBackground(getContext().getResources().getDrawable(
+ R.drawable.ripple_drawable_pin, ctw.getTheme()));
}
}
diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java
index 756d6107570a..01e1c632ad83 100644
--- a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java
+++ b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java
@@ -22,6 +22,7 @@ import android.graphics.drawable.GradientDrawable;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.AttributeSet;
+import android.view.ContextThemeWrapper;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -47,7 +48,7 @@ public class NumPadKey extends ViewGroup {
private int mTextViewResId;
private PasswordTextView mTextView;
- private final NumPadAnimator mAnimator;
+ private NumPadAnimator mAnimator;
private View.OnClickListener mListener = new View.OnClickListener() {
@Override
@@ -131,6 +132,17 @@ public class NumPadKey extends ViewGroup {
}
/**
+ * By default, the new layout will be enabled. Invoking will revert to the old style
+ */
+ public void disableNewLayout() {
+ findViewById(R.id.klondike_text).setVisibility(View.VISIBLE);
+ mAnimator = null;
+ ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
+ setBackground(getContext().getResources().getDrawable(
+ R.drawable.ripple_drawable_pin, ctw.getTheme()));
+ }
+
+ /**
* Reload colors from resources.
**/
public void reloadColors() {
@@ -141,7 +153,7 @@ public class NumPadKey extends ViewGroup {
mDigitText.setTextColor(textColor);
mKlondikeText.setTextColor(klondikeColor);
- mAnimator.reloadColors(getContext());
+ if (mAnimator != null) mAnimator.reloadColors(getContext());
}
@Override
@@ -150,14 +162,14 @@ public class NumPadKey extends ViewGroup {
doHapticKeyClick();
}
- mAnimator.start();
+ if (mAnimator != null) mAnimator.start();
return super.onTouchEvent(event);
}
@Override
public void setLayoutParams(ViewGroup.LayoutParams params) {
- mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
+ if (mAnimator != null) mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
super.setLayoutParams(params);
}
@@ -167,8 +179,12 @@ public class NumPadKey extends ViewGroup {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
measureChildren(widthMeasureSpec, heightMeasureSpec);
- // Set width/height to the same value to ensure a smooth circle for the bg
- setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
+ // Set width/height to the same value to ensure a smooth circle for the bg, but shrink
+ // the height to match the old pin bouncer
+ int width = getMeasuredWidth();
+ int height = mAnimator == null ? (int) (width * .75f) : width;
+
+ setMeasuredDimension(getMeasuredWidth(), height);
}
@Override
@@ -187,7 +203,7 @@ public class NumPadKey extends ViewGroup {
left = centerX - mKlondikeText.getMeasuredWidth() / 2;
mKlondikeText.layout(left, top, left + mKlondikeText.getMeasuredWidth(), bottom);
- mAnimator.onLayout(b - t);
+ if (mAnimator != null) mAnimator.onLayout(b - t);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/clock/ClockModule.java b/packages/SystemUI/src/com/android/keyguard/clock/ClockModule.java
new file mode 100644
index 000000000000..c4be1ba53503
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/clock/ClockModule.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package com.android.keyguard.clock;
+
+import java.util.List;
+
+import dagger.Module;
+import dagger.Provides;
+
+/** Dagger Module for clock package. */
+@Module
+public abstract class ClockModule {
+
+ /** */
+ @Provides
+ public static List<ClockInfo> provideClockInfoList(ClockManager clockManager) {
+ return clockManager.getClockInfos();
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/clock/ClockOptionsProvider.java b/packages/SystemUI/src/com/android/keyguard/clock/ClockOptionsProvider.java
index 5ef35be8df51..b6413cb61deb 100644
--- a/packages/SystemUI/src/com/android/keyguard/clock/ClockOptionsProvider.java
+++ b/packages/SystemUI/src/com/android/keyguard/clock/ClockOptionsProvider.java
@@ -28,11 +28,12 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.systemui.Dependency;
import java.io.FileNotFoundException;
import java.util.List;
-import java.util.function.Supplier;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
/**
* Exposes custom clock face options and provides realistic preview images.
@@ -65,15 +66,12 @@ public final class ClockOptionsProvider extends ContentProvider {
private static final String CONTENT_SCHEME = "content";
private static final String AUTHORITY = "com.android.keyguard.clock";
- private final Supplier<List<ClockInfo>> mClocksSupplier;
-
- public ClockOptionsProvider() {
- this(() -> Dependency.get(ClockManager.class).getClockInfos());
- }
+ @Inject
+ public Provider<List<ClockInfo>> mClockInfosProvider;
@VisibleForTesting
- ClockOptionsProvider(Supplier<List<ClockInfo>> clocksSupplier) {
- mClocksSupplier = clocksSupplier;
+ ClockOptionsProvider(Provider<List<ClockInfo>> clockInfosProvider) {
+ mClockInfosProvider = clockInfosProvider;
}
@Override
@@ -99,7 +97,7 @@ public final class ClockOptionsProvider extends ContentProvider {
}
MatrixCursor cursor = new MatrixCursor(new String[] {
COLUMN_NAME, COLUMN_TITLE, COLUMN_ID, COLUMN_THUMBNAIL, COLUMN_PREVIEW});
- List<ClockInfo> clocks = mClocksSupplier.get();
+ List<ClockInfo> clocks = mClockInfosProvider.get();
for (int i = 0; i < clocks.size(); i++) {
ClockInfo clock = clocks.get(i);
cursor.newRow()
@@ -139,7 +137,7 @@ public final class ClockOptionsProvider extends ContentProvider {
throw new FileNotFoundException("Invalid preview url, missing id");
}
ClockInfo clock = null;
- List<ClockInfo> clocks = mClocksSupplier.get();
+ List<ClockInfo> clocks = mClockInfosProvider.get();
for (int i = 0; i < clocks.size(); i++) {
if (id.equals(clocks.get(i).getId())) {
clock = clocks.get(i);
diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewComponent.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewComponent.java
new file mode 100644
index 000000000000..49a617eeb6c0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewComponent.java
@@ -0,0 +1,42 @@
+/*
+ * 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.keyguard.dagger;
+
+import com.android.keyguard.KeyguardStatusViewController;
+import com.android.systemui.statusbar.phone.KeyguardStatusBarView;
+import com.android.systemui.statusbar.phone.KeyguardStatusBarViewController;
+
+import dagger.BindsInstance;
+import dagger.Subcomponent;
+
+/**
+ * Subcomponent for helping work with KeyguardStatusView and its children.
+ *
+ * TODO: unify this with {@link KeyguardStatusViewComponent}
+ */
+@Subcomponent(modules = {KeyguardStatusBarViewModule.class})
+@KeyguardStatusBarViewScope
+public interface KeyguardStatusBarViewComponent {
+ /** Simple factory for {@link KeyguardStatusBarViewComponent}. */
+ @Subcomponent.Factory
+ interface Factory {
+ KeyguardStatusBarViewComponent build(@BindsInstance KeyguardStatusBarView view);
+ }
+
+ /** Builds a {@link KeyguardStatusViewController}. */
+ KeyguardStatusBarViewController getKeyguardStatusBarViewController();
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewModule.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewModule.java
new file mode 100644
index 000000000000..a6725234e4af
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewModule.java
@@ -0,0 +1,34 @@
+/*
+ * 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.keyguard.dagger;
+
+import com.android.keyguard.CarrierText;
+import com.android.systemui.R;
+import com.android.systemui.statusbar.phone.KeyguardStatusBarView;
+
+import dagger.Module;
+import dagger.Provides;
+
+/** Dagger module for {@link KeyguardStatusBarViewComponent}. */
+@Module
+public abstract class KeyguardStatusBarViewModule {
+ @Provides
+ @KeyguardStatusBarViewScope
+ static CarrierText getCarrierText(KeyguardStatusBarView view) {
+ return view.findViewById(R.id.keyguard_carrier_text);
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewScope.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewScope.java
new file mode 100644
index 000000000000..ba0642f57a88
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusBarViewScope.java
@@ -0,0 +1,32 @@
+/*
+ * 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.keyguard.dagger;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+
+import javax.inject.Scope;
+
+/**
+ * Scope annotation for singleton items within the StatusBarComponent.
+ */
+@Documented
+@Retention(RUNTIME)
+@Scope
+public @interface KeyguardStatusBarViewScope {}
diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java
index 1b6476ce74df..d342377da49b 100644
--- a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java
+++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardStatusViewComponent.java
@@ -25,6 +25,8 @@ import dagger.Subcomponent;
/**
* Subcomponent for helping work with KeyguardStatusView and its children.
+ *
+ * TODO: unify this with {@link KeyguardStatusBarViewComponent}
*/
@Subcomponent(modules = {KeyguardStatusViewModule.class})
@KeyguardStatusViewScope
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
index 78f7966558ab..865ca40b1f4c 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -19,18 +19,15 @@ package com.android.systemui;
import android.app.ActivityThread;
import android.app.Application;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Process;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
-import android.provider.Settings;
import android.util.Log;
import android.util.TimingsTraceLog;
import android.view.SurfaceControl;
@@ -40,7 +37,6 @@ import com.android.systemui.dagger.ContextComponentHelper;
import com.android.systemui.dagger.GlobalRootComponent;
import com.android.systemui.dagger.SysUIComponent;
import com.android.systemui.dump.DumpManager;
-import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
import com.android.systemui.shared.system.ThreadedRendererCompat;
import com.android.systemui.util.NotificationChannels;
@@ -125,21 +121,6 @@ public class SystemUIApplication extends Application implements
mServices[i].onBootCompleted();
}
}
-
- // If SHOW_PEOPLE_SPACE is true, enable People Space widget provider.
- // TODO(b/170396074): Migrate to new feature flag (go/silk-flags-howto)
- try {
- int showPeopleSpace = Settings.Global.getInt(context.getContentResolver(),
- Settings.Global.SHOW_PEOPLE_SPACE, 1);
- context.getPackageManager().setComponentEnabledSetting(
- new ComponentName(context, PeopleSpaceWidgetProvider.class),
- showPeopleSpace == 1
- ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
- : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
- PackageManager.DONT_KILL_APP);
- } catch (Exception e) {
- Log.w(TAG, "Error enabling People Space widget:", e);
- }
}
}, bootCompletedFilter);
diff --git a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt
index 38a82f8c9908..36937d622b5b 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt
@@ -16,10 +16,19 @@
package com.android.systemui.controls.dagger
+import android.content.ContentResolver
+import android.content.Context
+import android.database.ContentObserver
+import android.provider.Settings
import com.android.systemui.controls.controller.ControlsController
import com.android.systemui.controls.management.ControlsListingController
import com.android.systemui.controls.ui.ControlsUiController
import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.settings.UserTracker
+import com.android.systemui.statusbar.policy.KeyguardStateController
+import com.android.systemui.util.settings.SecureSettings
+import com.android.internal.widget.LockPatternUtils
+import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT
import dagger.Lazy
import java.util.Optional
import javax.inject.Inject
@@ -28,15 +37,43 @@ import javax.inject.Inject
* Pseudo-component to inject into classes outside `com.android.systemui.controls`.
*
* If `featureEnabled` is false, all the optionals should be empty. The controllers will only be
- * instantiated if `featureEnabled` is true.
+ * instantiated if `featureEnabled` is true. Can also be queried for the availability of controls.
*/
@SysUISingleton
class ControlsComponent @Inject constructor(
@ControlsFeatureEnabled private val featureEnabled: Boolean,
+ private val context: Context,
private val lazyControlsController: Lazy<ControlsController>,
private val lazyControlsUiController: Lazy<ControlsUiController>,
- private val lazyControlsListingController: Lazy<ControlsListingController>
+ private val lazyControlsListingController: Lazy<ControlsListingController>,
+ private val lockPatternUtils: LockPatternUtils,
+ private val keyguardStateController: KeyguardStateController,
+ private val userTracker: UserTracker,
+ private val secureSettings: SecureSettings
) {
+
+ private val contentResolver: ContentResolver
+ get() = context.contentResolver
+
+ private var canShowWhileLockedSetting = false
+
+ val showWhileLockedObserver = object : ContentObserver(null) {
+ override fun onChange(selfChange: Boolean) {
+ updateShowWhileLocked()
+ }
+ }
+
+ init {
+ if (featureEnabled) {
+ secureSettings.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT),
+ false, /* notifyForDescendants */
+ showWhileLockedObserver
+ )
+ updateShowWhileLocked()
+ }
+ }
+
fun getControlsController(): Optional<ControlsController> {
return if (featureEnabled) Optional.of(lazyControlsController.get()) else Optional.empty()
}
@@ -52,4 +89,37 @@ class ControlsComponent @Inject constructor(
Optional.empty()
}
}
-} \ No newline at end of file
+
+ /**
+ * @return true if controls are feature-enabled and have available services to serve controls
+ */
+ fun isEnabled() = featureEnabled && lazyControlsController.get().available
+
+ /**
+ * Returns one of 3 states:
+ * * AVAILABLE - Controls can be made visible
+ * * AVAILABLE_AFTER_UNLOCK - Controls can be made visible only after device unlock
+ * * UNAVAILABLE - Controls are not enabled
+ */
+ fun getVisibility(): Visibility {
+ if (!isEnabled()) return Visibility.UNAVAILABLE
+ if (lockPatternUtils.getStrongAuthForUser(userTracker.userHandle.identifier)
+ == STRONG_AUTH_REQUIRED_AFTER_BOOT) {
+ return Visibility.AVAILABLE_AFTER_UNLOCK
+ }
+ if (!canShowWhileLockedSetting && !keyguardStateController.isUnlocked()) {
+ return Visibility.AVAILABLE_AFTER_UNLOCK
+ }
+
+ return Visibility.AVAILABLE
+ }
+
+ private fun updateShowWhileLocked() {
+ canShowWhileLockedSetting = secureSettings.getInt(
+ Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT, 0) != 0
+ }
+
+ enum class Visibility {
+ AVAILABLE, AVAILABLE_AFTER_UNLOCK, UNAVAILABLE
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
index ffb8446f3e21..91c2dcfd9202 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
@@ -16,6 +16,7 @@
package com.android.systemui.dagger;
+import com.android.keyguard.clock.ClockOptionsProvider;
import com.android.systemui.BootCompleteCacheImpl;
import com.android.systemui.Dependency;
import com.android.systemui.InitController;
@@ -146,4 +147,9 @@ public interface SysUIComponent {
* Member injection into the supplied argument.
*/
void inject(KeyguardSliceProvider keyguardSliceProvider);
+
+ /**
+ * Member injection into the supplied argument.
+ */
+ void inject(ClockOptionsProvider clockOptionsProvider);
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java
index e5c9d104ea93..ec3188a6144f 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java
@@ -27,6 +27,7 @@ import com.android.systemui.globalactions.GlobalActionsComponent;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.keyguard.dagger.KeyguardModule;
import com.android.systemui.media.systemsounds.HomeSoundEffectController;
+import com.android.systemui.people.widget.PeopleSpaceWidgetEnabler;
import com.android.systemui.power.PowerUI;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsModule;
@@ -177,4 +178,10 @@ public abstract class SystemUIBinder {
@IntoMap
@ClassKey(HomeSoundEffectController.class)
public abstract SystemUI bindHomeSoundEffectController(HomeSoundEffectController sysui);
+
+ /** Inject into PeopleSpaceWidgetEnabler. */
+ @Binds
+ @IntoMap
+ @ClassKey(PeopleSpaceWidgetEnabler.class)
+ public abstract SystemUI bindPeopleSpaceWidgetEnabler(PeopleSpaceWidgetEnabler sysui);
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
index b0067cd15c1b..b67db03a743c 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
@@ -22,6 +22,7 @@ import android.content.Context;
import androidx.annotation.Nullable;
import com.android.internal.statusbar.IStatusBarService;
+import com.android.keyguard.clock.ClockModule;
import com.android.keyguard.dagger.KeyguardBouncerComponent;
import com.android.systemui.BootCompleteCache;
import com.android.systemui.BootCompleteCacheImpl;
@@ -90,6 +91,7 @@ import dagger.Provides;
@Module(includes = {
AppOpsModule.class,
AssistModule.class,
+ ClockModule.class,
ControlsModule.class,
DemoModeModule.class,
FalsingModule.class,
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index 8af45a5c0ef1..d85b10167697 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -25,6 +25,8 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOM
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
+import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.AVAILABLE;
+import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.AVAILABLE_AFTER_UNLOCK;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_GLOBAL_ACTIONS_SHOWING;
import android.animation.Animator;
@@ -250,6 +252,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
private final IWindowManager mIWindowManager;
private final Executor mBackgroundExecutor;
private List<ControlsServiceInfo> mControlsServiceInfos = new ArrayList<>();
+ private ControlsComponent mControlsComponent;
private Optional<ControlsController> mControlsControllerOptional;
private final RingerModeTracker mRingerModeTracker;
private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms
@@ -338,6 +341,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
mSysuiColorExtractor = colorExtractor;
mStatusBarService = statusBarService;
mNotificationShadeWindowController = notificationShadeWindowController;
+ mControlsComponent = controlsComponent;
mControlsUiControllerOptional = controlsComponent.getControlsUiController();
mIWindowManager = iWindowManager;
mBackgroundExecutor = backgroundExecutor;
@@ -387,7 +391,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
if (mDialog.mWalletViewController != null) {
mDialog.mWalletViewController.onDeviceLockStateChanged(!unlocked);
}
- if (!mDialog.isShowingControls() && shouldShowControls()) {
+ if (!mDialog.isShowingControls()
+ && mControlsComponent.getVisibility() == AVAILABLE) {
mDialog.showControls(mControlsUiControllerOptional.get());
}
if (unlocked) {
@@ -397,14 +402,15 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
}
});
- if (controlsComponent.getControlsListingController().isPresent()) {
- controlsComponent.getControlsListingController().get()
+ if (mControlsComponent.getControlsListingController().isPresent()) {
+ mControlsComponent.getControlsListingController().get()
.addCallback(list -> {
mControlsServiceInfos = list;
// This callback may occur after the dialog has been shown. If so, add
// controls into the already visible space or show the lock msg if needed.
if (mDialog != null) {
- if (!mDialog.isShowingControls() && shouldShowControls()) {
+ if (!mDialog.isShowingControls()
+ && mControlsComponent.getVisibility() == AVAILABLE) {
mDialog.showControls(mControlsUiControllerOptional.get());
} else if (shouldShowLockMessage(mDialog)) {
mDialog.showLockMessage();
@@ -704,7 +710,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
mDepthController.setShowingHomeControls(true);
ControlsUiController uiController = null;
- if (mControlsUiControllerOptional.isPresent() && shouldShowControls()) {
+ if (mControlsComponent.getVisibility() == AVAILABLE) {
uiController = mControlsUiControllerOptional.get();
}
ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, mOverflowAdapter,
@@ -2687,26 +2693,24 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
return isPanelDebugModeEnabled(context);
}
- private boolean shouldShowControls() {
- boolean showOnLockScreen = mShowLockScreenCardsAndControls && mLockPatternUtils
- .getStrongAuthForUser(getCurrentUser().id) != STRONG_AUTH_REQUIRED_AFTER_BOOT;
- return controlsAvailable()
- && (mKeyguardStateController.isUnlocked() || showOnLockScreen);
- }
-
private boolean controlsAvailable() {
return mDeviceProvisioned
- && mControlsUiControllerOptional.isPresent()
- && mControlsUiControllerOptional.get().getAvailable()
+ && mControlsComponent.isEnabled()
&& !mControlsServiceInfos.isEmpty();
}
private boolean shouldShowLockMessage(ActionsDialog dialog) {
+ return mControlsComponent.getVisibility() == AVAILABLE_AFTER_UNLOCK
+ || isWalletAvailableAfterUnlock(dialog);
+ }
+
+ // Temporary while we move items out of the power menu
+ private boolean isWalletAvailableAfterUnlock(ActionsDialog dialog) {
boolean isLockedAfterBoot = mLockPatternUtils.getStrongAuthForUser(getCurrentUser().id)
== STRONG_AUTH_REQUIRED_AFTER_BOOT;
return !mKeyguardStateController.isUnlocked()
&& (!mShowLockScreenCardsAndControls || isLockedAfterBoot)
- && (controlsAvailable() || dialog.isWalletViewAvailable());
+ && dialog.isWalletViewAvailable();
}
private void onPowerMenuLockScreenSettingsChanged() {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndication.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndication.java
index 3a06f7aeb6bf..d65d16951191 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndication.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndication.java
@@ -29,7 +29,7 @@ import android.view.View;
* See {@link com.android.systemui.statusbar.phone.KeyguardBottomAreaView}.
*/
public class KeyguardIndication {
- @NonNull
+ @Nullable
private final CharSequence mMessage;
@NonNull
private final ColorStateList mTextColor;
@@ -146,8 +146,13 @@ public class KeyguardIndication {
* Build the KeyguardIndication.
*/
public KeyguardIndication build() {
- if (mMessage == null) throw new IllegalStateException("message must be set");
- if (mTextColor == null) throw new IllegalStateException("text color must be set");
+ if (mMessage == null && mIcon == null) {
+ throw new IllegalStateException("message or icon must be set");
+ }
+ if (mTextColor == null) {
+ throw new IllegalStateException("text color must be set");
+ }
+
return new KeyguardIndication(
mMessage, mTextColor, mIcon, mOnClickListener, mBackground);
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java
index 8c04143abc54..2e599de1970d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java
@@ -106,7 +106,8 @@ public class KeyguardIndicationRotateTextViewController extends
boolean showImmediately) {
final boolean hasPreviousIndication = mIndicationMessages.get(type) != null;
final boolean hasNewIndication = newIndication != null
- && !TextUtils.isEmpty(newIndication.getMessage());
+ && (!TextUtils.isEmpty(newIndication.getMessage())
+ || newIndication.getIcon() != null);
if (!hasNewIndication) {
mIndicationMessages.remove(type);
mIndicationQueue.removeIf(x -> x == type);
@@ -203,7 +204,6 @@ public class KeyguardIndicationRotateTextViewController extends
mIndicationQueue.add(type); // re-add to show later
}
- // pass the style update to be run right before our new indication is shown:
mView.switchIndication(mIndicationMessages.get(type));
// only schedule next indication if there's more than just this indication in the queue
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 de2e7c476e18..a747edd0580a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
@@ -30,6 +30,7 @@ import com.android.keyguard.KeyguardDisplayManager;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardViewController;
import com.android.keyguard.dagger.KeyguardQsUserSwitchComponent;
+import com.android.keyguard.dagger.KeyguardStatusBarViewComponent;
import com.android.keyguard.dagger.KeyguardStatusViewComponent;
import com.android.keyguard.dagger.KeyguardUserSwitcherComponent;
import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -63,8 +64,11 @@ import dagger.Provides;
/**
* Dagger Module providing {@link StatusBar}.
*/
-@Module(subcomponents = {KeyguardStatusViewComponent.class,
- KeyguardQsUserSwitchComponent.class, KeyguardUserSwitcherComponent.class},
+@Module(subcomponents = {
+ KeyguardQsUserSwitchComponent.class,
+ KeyguardStatusBarViewComponent.class,
+ KeyguardStatusViewComponent.class,
+ KeyguardUserSwitcherComponent.class},
includes = {FalsingModule.class})
public class KeyguardModule {
/**
diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java b/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java
new file mode 100644
index 000000000000..e7458a3df801
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/people/PeopleProvider.java
@@ -0,0 +1,157 @@
+/*
+ * 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.
+ */
+
+package com.android.systemui.people;
+
+import android.app.people.ConversationChannel;
+import android.app.people.IPeopleManager;
+import android.app.people.PeopleSpaceTile;
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.pm.LauncherApps;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.Log;
+import android.widget.RemoteViews;
+
+import com.android.systemui.shared.system.PeopleProviderUtils;
+
+/** API that returns a People Tile preview. */
+public class PeopleProvider extends ContentProvider {
+
+ LauncherApps mLauncherApps;
+ IPeopleManager mPeopleManager;
+
+ private static final String TAG = "PeopleProvider";
+ private static final boolean DEBUG = PeopleSpaceUtils.DEBUG;
+ private static final String EMPTY_STRING = "";
+
+ @Override
+ public Bundle call(String method, String arg, Bundle extras) {
+ if (!doesCallerHavePermission()) {
+ String callingPackage = getCallingPackage();
+ Log.w(TAG, "API not accessible to calling package: " + callingPackage);
+ throw new SecurityException("API not accessible to calling package: " + callingPackage);
+ }
+ if (!PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_METHOD.equals(method)) {
+ Log.w(TAG, "Invalid method");
+ throw new IllegalArgumentException("Invalid method");
+ }
+
+ // If services are not set as mocks in tests, fetch them now.
+ mPeopleManager = mPeopleManager != null ? mPeopleManager
+ : IPeopleManager.Stub.asInterface(
+ ServiceManager.getService(Context.PEOPLE_SERVICE));
+ mLauncherApps = mLauncherApps != null ? mLauncherApps
+ : getContext().getSystemService(LauncherApps.class);
+
+ if (mPeopleManager == null || mLauncherApps == null) {
+ Log.w(TAG, "Null system managers");
+ return null;
+ }
+
+ if (extras == null) {
+ Log.w(TAG, "Extras can't be null");
+ throw new IllegalArgumentException("Extras can't be null");
+ }
+
+ String shortcutId = extras.getString(
+ PeopleProviderUtils.EXTRAS_KEY_SHORTCUT_ID, EMPTY_STRING);
+ String packageName = extras.getString(
+ PeopleProviderUtils.EXTRAS_KEY_PACKAGE_NAME, EMPTY_STRING);
+ UserHandle userHandle = extras.getParcelable(
+ PeopleProviderUtils.EXTRAS_KEY_USER_HANDLE);
+ if (shortcutId.isEmpty()) {
+ Log.w(TAG, "Invalid shortcut id");
+ throw new IllegalArgumentException("Invalid shortcut id");
+ }
+
+ if (packageName.isEmpty()) {
+ Log.w(TAG, "Invalid package name");
+ throw new IllegalArgumentException("Invalid package name");
+ }
+ if (userHandle == null) {
+ Log.w(TAG, "Null user handle");
+ throw new IllegalArgumentException("Null user handle");
+ }
+
+ ConversationChannel channel;
+ try {
+ channel = mPeopleManager.getConversation(
+ packageName, userHandle.getIdentifier(), shortcutId);
+ } catch (Exception e) {
+ Log.w(TAG, "Exception getting tiles: " + e);
+ return null;
+ }
+ PeopleSpaceTile tile = PeopleSpaceUtils.getTile(channel, mLauncherApps);
+
+ if (tile == null) {
+ if (DEBUG) Log.i(TAG, "No tile was returned");
+ return null;
+ }
+
+ if (DEBUG) Log.i(TAG, "Returning tile preview for shortcutId: " + shortcutId);
+ RemoteViews view = PeopleSpaceUtils.createRemoteViews(getContext(), tile, 0);
+ final Bundle bundle = new Bundle();
+ bundle.putParcelable(PeopleProviderUtils.RESPONSE_KEY_REMOTE_VIEWS, view);
+ return bundle;
+ }
+
+ private boolean doesCallerHavePermission() {
+ return getContext().checkPermission(
+ PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_PERMISSION,
+ Binder.getCallingPid(), Binder.getCallingUid())
+ == PackageManager.PERMISSION_GRANTED;
+ }
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder) {
+ throw new IllegalArgumentException("Invalid method");
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ throw new IllegalArgumentException("Invalid method");
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues initialValues) {
+ throw new IllegalArgumentException("Invalid method");
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ throw new IllegalArgumentException("Invalid method");
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ throw new IllegalArgumentException("Invalid method");
+ }
+}
+
diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java
index c67aef618652..2f9b17aece8e 100644
--- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java
@@ -19,6 +19,8 @@ package com.android.systemui.people;
import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
+import static com.android.systemui.people.PeopleSpaceUtils.getUserHandle;
+
import android.app.Activity;
import android.app.INotificationManager;
import android.app.people.IPeopleManager;
@@ -39,6 +41,7 @@ import com.android.internal.logging.UiEventLoggerImpl;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
+import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
@@ -49,6 +52,7 @@ import javax.inject.Inject;
public class PeopleSpaceActivity extends Activity {
private static final String TAG = "PeopleSpaceActivity";
+ private static final boolean DEBUG = PeopleSpaceUtils.DEBUG;
private ViewGroup mPeopleSpaceLayout;
private IPeopleManager mPeopleManager;
@@ -134,9 +138,11 @@ public class PeopleSpaceActivity extends Activity {
/** Stores the user selected configuration for {@code mAppWidgetId}. */
private void storeWidgetConfiguration(PeopleSpaceTile tile) {
if (PeopleSpaceUtils.DEBUG) {
- Log.d(TAG, "Put " + tile.getUserName() + "'s shortcut ID: "
- + tile.getId() + " for widget ID: "
- + mAppWidgetId);
+ if (DEBUG) {
+ Log.d(TAG, "Put " + tile.getUserName() + "'s shortcut ID: "
+ + tile.getId() + " for widget ID: "
+ + mAppWidgetId);
+ }
}
PeopleSpaceUtils.setStorageForTile(mContext, tile, mAppWidgetId);
@@ -144,12 +150,22 @@ public class PeopleSpaceActivity extends Activity {
// TODO: Populate new widget with existing conversation notification, if there is any.
PeopleSpaceUtils.updateSingleConversationWidgets(mContext, widgetIds, mAppWidgetManager,
mPeopleManager);
+ if (mLauncherApps != null) {
+ try {
+ if (DEBUG) Log.d(TAG, "Caching shortcut for PeopleTile: " + tile.getId());
+ mLauncherApps.cacheShortcuts(tile.getPackageName(),
+ Collections.singletonList(tile.getId()),
+ getUserHandle(tile), LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS);
+ } catch (Exception e) {
+ Log.w(TAG, "Exception caching shortcut:" + e);
+ }
+ }
finishActivity();
}
/** Finish activity with a successful widget configuration result. */
private void finishActivity() {
- if (PeopleSpaceUtils.DEBUG) Log.d(TAG, "Widget added!");
+ if (DEBUG) Log.d(TAG, "Widget added!");
mUiEventLogger.log(PeopleSpaceUtils.PeopleSpaceWidgetEvent.PEOPLE_SPACE_WIDGET_ADDED);
setActivityResult(RESULT_OK);
finish();
diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java
index dd054848aed2..cd1131ba3e79 100644
--- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java
+++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java
@@ -17,12 +17,21 @@
package com.android.systemui.people;
import static android.app.Notification.EXTRA_MESSAGES;
+import static android.app.people.ConversationStatus.ACTIVITY_ANNIVERSARY;
+import static android.app.people.ConversationStatus.ACTIVITY_BIRTHDAY;
+import static android.app.people.ConversationStatus.ACTIVITY_GAME;
+import static android.app.people.ConversationStatus.ACTIVITY_LOCATION;
+import static android.app.people.ConversationStatus.ACTIVITY_MEDIA;
+import static android.app.people.ConversationStatus.ACTIVITY_NEW_STORY;
+import static android.app.people.ConversationStatus.ACTIVITY_UPCOMING_BIRTHDAY;
+import static android.app.people.ConversationStatus.AVAILABILITY_AVAILABLE;
import android.annotation.Nullable;
import android.app.INotificationManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.people.ConversationChannel;
+import android.app.people.ConversationStatus;
import android.app.people.IPeopleManager;
import android.app.people.PeopleSpaceTile;
import android.appwidget.AppWidgetManager;
@@ -37,6 +46,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
import android.icu.text.MeasureFormat;
import android.icu.util.Measure;
import android.icu.util.MeasureUnit;
@@ -49,6 +59,7 @@ import android.provider.ContactsContract;
import android.provider.Settings;
import android.service.notification.ConversationChannelWrapper;
import android.service.notification.StatusBarNotification;
+import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
@@ -70,6 +81,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
@@ -286,7 +298,7 @@ public class PeopleSpaceUtils {
SharedPreferences.Editor widgetEditor = widgetSp.edit();
widgetEditor.putString(PeopleSpaceUtils.PACKAGE_NAME, tile.getPackageName());
widgetEditor.putString(PeopleSpaceUtils.SHORTCUT_ID, tile.getId());
- int userId = UserHandle.getUserHandleForUid(tile.getUid()).getIdentifier();
+ int userId = getUserId(tile);
widgetEditor.putInt(PeopleSpaceUtils.USER_ID, userId);
widgetEditor.apply();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
@@ -438,23 +450,147 @@ public class PeopleSpaceUtils {
}
/** Creates a {@link RemoteViews} for {@code tile}. */
- private static RemoteViews createRemoteViews(Context context,
+ public static RemoteViews createRemoteViews(Context context,
PeopleSpaceTile tile, int appWidgetId) {
- RemoteViews views;
+ RemoteViews viewsForTile = getViewForTile(context, tile);
+ RemoteViews views = setCommonRemoteViewsFields(context, viewsForTile, tile);
+ return setLaunchIntents(context, views, tile, appWidgetId);
+ }
+
+ /**
+ * The prioritization for the {@code tile} content is missed calls, followed by notification
+ * content, then birthdays, then the most recent status, and finally last interaction.
+ */
+ private static RemoteViews getViewForTile(Context context, PeopleSpaceTile tile) {
if (tile.getNotificationKey() != null) {
- views = createNotificationRemoteViews(context, tile);
- } else if (tile.getBirthdayText() != null) {
- views = createStatusRemoteViews(context, tile);
+ if (DEBUG) Log.d(TAG, "Create notification view");
+ return createNotificationRemoteViews(context, tile);
+ }
+
+ // TODO: Add sorting when we expose timestamp of statuses.
+ List<ConversationStatus> statusesForEntireView =
+ tile.getStatuses() == null ? Arrays.asList() : tile.getStatuses().stream().filter(
+ c -> isStatusValidForEntireStatusView(c)).collect(Collectors.toList());
+ ConversationStatus birthdayStatus = getBirthdayStatus(tile, statusesForEntireView);
+ if (birthdayStatus != null) {
+ if (DEBUG) Log.d(TAG, "Create birthday view");
+ return createStatusRemoteViews(context, birthdayStatus);
+ }
+
+ if (!statusesForEntireView.isEmpty()) {
+ if (DEBUG) {
+ Log.d(TAG,
+ "Create status view for: " + statusesForEntireView.get(0).getActivity());
+ }
+ return createStatusRemoteViews(context, statusesForEntireView.get(0));
+ }
+
+ return createLastInteractionRemoteViews(context, tile);
+ }
+
+ @Nullable
+ private static ConversationStatus getBirthdayStatus(PeopleSpaceTile tile,
+ List<ConversationStatus> statuses) {
+ Optional<ConversationStatus> birthdayStatus = statuses.stream().filter(
+ c -> c.getActivity() == ACTIVITY_BIRTHDAY).findFirst();
+ if (birthdayStatus.isPresent()) {
+ return birthdayStatus.get();
+ }
+ if (!TextUtils.isEmpty(tile.getBirthdayText())) {
+ return new ConversationStatus.Builder(tile.getId(), ACTIVITY_BIRTHDAY).build();
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns whether a {@code status} should have its own entire templated view.
+ *
+ * <p>A status may still be shown on the view (for example, as a new story ring) even if it's
+ * not valid to compose an entire view.
+ */
+ private static boolean isStatusValidForEntireStatusView(ConversationStatus status) {
+ switch (status.getActivity()) {
+ // Birthday & Anniversary don't require text provided or icon provided.
+ case ACTIVITY_BIRTHDAY:
+ case ACTIVITY_ANNIVERSARY:
+ return true;
+ default:
+ // For future birthday, location, new story, video, music, game, and other, the
+ // app must provide either text or an icon.
+ return !TextUtils.isEmpty(status.getDescription())
+ || status.getIcon() != null;
+ }
+ }
+
+ private static RemoteViews createStatusRemoteViews(Context context, ConversationStatus status) {
+ RemoteViews views = new RemoteViews(
+ context.getPackageName(), R.layout.people_space_small_avatar_tile);
+ CharSequence statusText = status.getDescription();
+ if (TextUtils.isEmpty(statusText)) {
+ statusText = getStatusTextByType(context, status.getActivity());
+ }
+ views.setTextViewText(R.id.status, statusText);
+ Icon statusIcon = status.getIcon();
+ if (statusIcon != null) {
+ views.setImageViewIcon(R.id.image, statusIcon);
+ views.setBoolean(R.id.content_background, "setClipToOutline", true);
} else {
- views = createLastInteractionRemoteViews(context, tile);
+ views.setViewVisibility(R.id.content_background, View.GONE);
+ }
+ // TODO: Set status pre-defined icons
+ return views;
+ }
+
+ private static String getStatusTextByType(Context context, int activity) {
+ switch (activity) {
+ case ACTIVITY_BIRTHDAY:
+ return context.getString(R.string.birthday_status);
+ case ACTIVITY_UPCOMING_BIRTHDAY:
+ return context.getString(R.string.upcoming_birthday_status);
+ case ACTIVITY_ANNIVERSARY:
+ return context.getString(R.string.anniversary_status);
+ case ACTIVITY_LOCATION:
+ return context.getString(R.string.location_status);
+ case ACTIVITY_NEW_STORY:
+ return context.getString(R.string.new_story_status);
+ case ACTIVITY_MEDIA:
+ return context.getString(R.string.video_status);
+ case ACTIVITY_GAME:
+ return context.getString(R.string.game_status);
+ default:
+ return EMPTY_STRING;
}
- return setCommonRemoteViewsFields(context, views, tile, appWidgetId);
}
private static RemoteViews setCommonRemoteViewsFields(Context context, RemoteViews views,
- PeopleSpaceTile tile, int appWidgetId) {
+ PeopleSpaceTile tile) {
try {
+ boolean isAvailable =
+ tile.getStatuses() != null && tile.getStatuses().stream().anyMatch(
+ c -> c.getAvailability() == AVAILABILITY_AVAILABLE);
+ if (isAvailable) {
+ views.setViewVisibility(R.id.availability, View.VISIBLE);
+ } else {
+ views.setViewVisibility(R.id.availability, View.GONE);
+ }
+ boolean hasNewStory =
+ tile.getStatuses() != null && tile.getStatuses().stream().anyMatch(
+ c -> c.getActivity() == ACTIVITY_NEW_STORY);
+ if (hasNewStory) {
+ views.setViewVisibility(R.id.person_icon_with_story, View.VISIBLE);
+ views.setViewVisibility(R.id.person_icon_only, View.GONE);
+ views.setImageViewIcon(R.id.person_icon_inside_ring, tile.getUserIcon());
+ } else {
+ views.setViewVisibility(R.id.person_icon_with_story, View.GONE);
+ views.setViewVisibility(R.id.person_icon_only, View.VISIBLE);
+ views.setImageViewIcon(R.id.person_icon_only, tile.getUserIcon());
+ }
+
views.setTextViewText(R.id.name, tile.getUserName().toString());
+ views.setImageViewIcon(R.id.person_icon, tile.getUserIcon());
+ views.setBoolean(R.id.content_background, "setClipToOutline", true);
+
views.setImageViewBitmap(
R.id.package_icon,
PeopleSpaceUtils.convertDrawableToBitmap(
@@ -462,9 +598,16 @@ public class PeopleSpaceUtils {
tile.getPackageName())
)
);
- views.setImageViewIcon(R.id.person_icon, tile.getUserIcon());
- views.setBoolean(R.id.content_background, "setClipToOutline", true);
+ return views;
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to set common fields: " + e);
+ }
+ return views;
+ }
+ private static RemoteViews setLaunchIntents(Context context, RemoteViews views,
+ PeopleSpaceTile tile, int appWidgetId) {
+ try {
Intent activityIntent = new Intent(context, LaunchConversationActivity.class);
activityIntent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
@@ -482,48 +625,42 @@ public class PeopleSpaceUtils {
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE));
return views;
} catch (Exception e) {
- Log.e(TAG, "Failed to set common fields: " + e);
+ Log.e(TAG, "Failed to add launch intents: " + e);
}
- return null;
+ return views;
}
private static RemoteViews createNotificationRemoteViews(Context context,
PeopleSpaceTile tile) {
RemoteViews views = new RemoteViews(
- context.getPackageName(), R.layout.people_space_small_avatar_tile);
+ context.getPackageName(), R.layout.people_space_notification_content_tile);
Uri image = tile.getNotificationDataUri();
if (image != null) {
- //TODO: Use NotificationInlineImageCache
+ // TODO: Use NotificationInlineImageCache
views.setImageViewUri(R.id.image, image);
- views.setViewVisibility(R.id.image, View.VISIBLE);
+ views.setViewVisibility(R.id.content_background, View.VISIBLE);
+ views.setBoolean(R.id.content_background, "setClipToOutline", true);
views.setViewVisibility(R.id.content, View.GONE);
} else {
CharSequence content = tile.getNotificationContent();
views = setPunctuationRemoteViewsFields(views, content);
views.setTextViewText(R.id.content, content);
views.setViewVisibility(R.id.content, View.VISIBLE);
- views.setViewVisibility(R.id.image, View.GONE);
+ views.setViewVisibility(R.id.content_background, View.GONE);
}
- views.setTextViewText(R.id.time, PeopleSpaceUtils.getLastInteractionString(
+ // TODO: Set subtext as Group Sender name once storing the name in PeopleSpaceTile.
+ views.setTextViewText(R.id.subtext, PeopleSpaceUtils.getLastInteractionString(
context, tile.getLastInteractionTimestamp(), false));
return views;
}
- private static RemoteViews createStatusRemoteViews(Context context,
- PeopleSpaceTile tile) {
- RemoteViews views = new RemoteViews(
- context.getPackageName(), R.layout.people_space_large_avatar_tile);
- views.setTextViewText(R.id.status, tile.getBirthdayText());
- return views;
- }
-
private static RemoteViews createLastInteractionRemoteViews(Context context,
PeopleSpaceTile tile) {
RemoteViews views = new RemoteViews(
context.getPackageName(), R.layout.people_space_large_avatar_tile);
String status = PeopleSpaceUtils.getLastInteractionString(
context, tile.getLastInteractionTimestamp(), true);
- views.setTextViewText(R.id.status, status);
+ views.setTextViewText(R.id.last_interaction, status);
return views;
}
@@ -612,11 +749,27 @@ public class PeopleSpaceUtils {
.collect(Collectors.toList());
}
+ /** Returns {@code PeopleSpaceTile} based on provided {@ConversationChannel}. */
+ public static PeopleSpaceTile getTile(ConversationChannel channel, LauncherApps launcherApps) {
+ if (channel == null) {
+ Log.i(TAG, "ConversationChannel is null");
+ return null;
+ }
+
+ PeopleSpaceTile tile = new PeopleSpaceTile.Builder(channel, launcherApps).build();
+ if (!PeopleSpaceUtils.shouldKeepConversation(tile)) {
+ Log.i(TAG, "PeopleSpaceTile is not valid");
+ return null;
+ }
+
+ return tile;
+ }
+
/** Returns the last interaction time with the user specified by {@code PeopleSpaceTile}. */
private static Long getLastInteraction(IPeopleManager peopleManager,
PeopleSpaceTile tile) {
try {
- int userId = UserHandle.getUserHandleForUid(tile.getUid()).getIdentifier();
+ int userId = getUserId(tile);
String pkg = tile.getPackageName();
return peopleManager.getLastInteraction(pkg, userId, tile.getId());
} catch (Exception e) {
@@ -664,20 +817,35 @@ public class PeopleSpaceUtils {
Duration durationSinceLastInteraction = Duration.ofMillis(now - lastInteraction);
MeasureFormat formatter = MeasureFormat.getInstance(Locale.getDefault(),
MeasureFormat.FormatWidth.WIDE);
+ MeasureFormat shortFormatter = MeasureFormat.getInstance(Locale.getDefault(),
+ MeasureFormat.FormatWidth.SHORT);
if (durationSinceLastInteraction.toHours() < MIN_HOUR) {
- return context.getString(includeLastChatted ? R.string.last_interaction_status_less_than
- : R.string.less_than_timestamp,
- formatter.formatMeasures(new Measure(MIN_HOUR, MeasureUnit.HOUR)));
+ if (includeLastChatted) {
+ return context.getString(R.string.last_interaction_status_less_than,
+ formatter.formatMeasures(new Measure(MIN_HOUR, MeasureUnit.HOUR)));
+ }
+ return context.getString(R.string.timestamp, shortFormatter.formatMeasures(
+ new Measure(durationSinceLastInteraction.toMinutes(), MeasureUnit.MINUTE)));
} else if (durationSinceLastInteraction.toDays() < ONE_DAY) {
- return context.getString(
- includeLastChatted ? R.string.last_interaction_status : R.string.timestamp,
- formatter.formatMeasures(
- new Measure(durationSinceLastInteraction.toHours(), MeasureUnit.HOUR)));
+ if (includeLastChatted) {
+ return context.getString(R.string.last_interaction_status,
+ formatter.formatMeasures(
+ new Measure(durationSinceLastInteraction.toHours(),
+ MeasureUnit.HOUR)));
+ }
+ return context.getString(R.string.timestamp, shortFormatter.formatMeasures(
+ new Measure(durationSinceLastInteraction.toHours(),
+ MeasureUnit.HOUR)));
} else if (durationSinceLastInteraction.toDays() < DAYS_IN_A_WEEK) {
- return context.getString(
- includeLastChatted ? R.string.last_interaction_status : R.string.timestamp,
- formatter.formatMeasures(
- new Measure(durationSinceLastInteraction.toDays(), MeasureUnit.DAY)));
+ if (includeLastChatted) {
+ return context.getString(R.string.last_interaction_status,
+ formatter.formatMeasures(
+ new Measure(durationSinceLastInteraction.toDays(),
+ MeasureUnit.DAY)));
+ }
+ return context.getString(R.string.timestamp, shortFormatter.formatMeasures(
+ new Measure(durationSinceLastInteraction.toHours(),
+ MeasureUnit.DAY)));
} else {
return context.getString(durationSinceLastInteraction.toDays() == DAYS_IN_A_WEEK
? (includeLastChatted ? R.string.last_interaction_status :
@@ -701,7 +869,7 @@ public class PeopleSpaceUtils {
* </li>
*/
public static boolean shouldKeepConversation(PeopleSpaceTile tile) {
- return tile != null && tile.getUserName().length() != 0;
+ return tile != null && !TextUtils.isEmpty(tile.getUserName());
}
private static boolean hasBirthdayStatus(PeopleSpaceTile tile, Context context) {
@@ -792,8 +960,7 @@ public class PeopleSpaceUtils {
private static void updateAppWidgetOptionsAndView(AppWidgetManager appWidgetManager,
Context context, int appWidgetId, PeopleSpaceTile tile) {
updateAppWidgetOptions(appWidgetManager, appWidgetId, tile);
- RemoteViews views = createRemoteViews(context,
- tile, appWidgetId);
+ RemoteViews views = createRemoteViews(context, tile, appWidgetId);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@@ -866,4 +1033,14 @@ public class PeopleSpaceUtils {
public static String getKey(String shortcutId, String packageName, int userId) {
return shortcutId + "/" + userId + "/" + packageName;
}
+
+ /** Returns the userId associated with a {@link PeopleSpaceTile} */
+ public static int getUserId(PeopleSpaceTile tile) {
+ return getUserHandle(tile).getIdentifier();
+ }
+
+ /** Returns the {@link UserHandle} associated with a {@link PeopleSpaceTile} */
+ public static UserHandle getUserHandle(PeopleSpaceTile tile) {
+ return UserHandle.getUserHandleForUid(tile.getUid());
+ }
} \ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetEnabler.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetEnabler.java
new file mode 100644
index 000000000000..b188acbf30f3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetEnabler.java
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+package com.android.systemui.people.widget;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.util.Log;
+
+import com.android.systemui.SystemUI;
+import com.android.systemui.dagger.SysUISingleton;
+import com.android.systemui.statusbar.FeatureFlags;
+
+import javax.inject.Inject;
+
+/**
+ * Enables People Space widgets.
+ */
+@SysUISingleton
+public class PeopleSpaceWidgetEnabler extends SystemUI {
+ private static final String TAG = "PeopleSpaceWdgtEnabler";
+ private Context mContext;
+ private FeatureFlags mFeatureFlags;
+
+ @Inject
+ public PeopleSpaceWidgetEnabler(Context context, FeatureFlags featureFlags) {
+ super(context);
+ mContext = context;
+ mFeatureFlags = featureFlags;
+ }
+
+ @Override
+ public void start() {
+ Log.d(TAG, "Starting service");
+ try {
+ boolean showPeopleSpace = mFeatureFlags.isPeopleTileEnabled();
+ mContext.getPackageManager().setComponentEnabledSetting(
+ new ComponentName(mContext, PeopleSpaceWidgetProvider.class),
+ showPeopleSpace
+ ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ } catch (Exception e) {
+ Log.w(TAG, "Error enabling People Space widget:", e);
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java
index f5577d30c75c..3d1055fdece2 100644
--- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java
@@ -16,13 +16,20 @@
package com.android.systemui.people.widget;
+import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME;
+import static com.android.systemui.people.PeopleSpaceUtils.SHORTCUT_ID;
+import static com.android.systemui.people.PeopleSpaceUtils.USER_ID;
+
import android.app.PendingIntent;
import android.app.people.IPeopleManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.LauncherApps;
import android.os.ServiceManager;
+import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import android.widget.RemoteViews;
@@ -32,6 +39,8 @@ import com.android.internal.logging.UiEventLoggerImpl;
import com.android.systemui.R;
import com.android.systemui.people.PeopleSpaceUtils;
+import java.util.Collections;
+
/** People Space Widget Provider class. */
public class PeopleSpaceWidgetProvider extends AppWidgetProvider {
private static final String TAG = "PeopleSpaceWidgetPvd";
@@ -88,11 +97,31 @@ public class PeopleSpaceWidgetProvider extends AppWidgetProvider {
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
+ LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
+
for (int widgetId : appWidgetIds) {
if (DEBUG) Log.d(TAG, "Widget removed");
mUiEventLogger.log(PeopleSpaceUtils.PeopleSpaceWidgetEvent.PEOPLE_SPACE_WIDGET_DELETED);
+ if (launcherApps != null) {
+ SharedPreferences widgetSp = context.getSharedPreferences(String.valueOf(widgetId),
+ Context.MODE_PRIVATE);
+ String packageName = widgetSp.getString(PACKAGE_NAME, null);
+ String shortcutId = widgetSp.getString(SHORTCUT_ID, null);
+ int userId = widgetSp.getInt(USER_ID, -1);
+
+ if (packageName != null && shortcutId != null && userId != -1) {
+ try {
+ if (DEBUG) Log.d(TAG, "Uncaching shortcut for PeopleTile: " + shortcutId);
+ launcherApps.uncacheShortcuts(packageName,
+ Collections.singletonList(shortcutId),
+ UserHandle.of(userId),
+ LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS);
+ } catch (Exception e) {
+ Log.d(TAG, "Exception uncaching shortcut:" + e);
+ }
+ }
+ }
PeopleSpaceUtils.removeStorageForTile(context, widgetId);
}
}
-
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
index 386638217110..1411fa1ea21f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
@@ -170,7 +170,8 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
// Update visibility of footer
mIsVisible = (isDeviceManaged && !isDemoDevice) || hasCACerts || hasCACertsInWorkProfile
|| vpnName != null || vpnNameWorkProfile != null
- || isProfileOwnerOfOrganizationOwnedDevice || isParentalControlsEnabled;
+ || isProfileOwnerOfOrganizationOwnedDevice || isParentalControlsEnabled
+ || (hasWorkProfile && isNetworkLoggingEnabled);
// Update the string
mFooterTextContent = getFooterText(isDeviceManaged, hasWorkProfile,
hasCACerts, hasCACertsInWorkProfile, isNetworkLoggingEnabled, vpnName,
@@ -275,12 +276,30 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
vpnName);
}
if (isProfileOwnerOfOrganizationOwnedDevice) {
+ if (isNetworkLoggingEnabled) {
+ if (organizationName == null) {
+ return mContext.getString(
+ R.string.quick_settings_disclosure_management_monitoring);
+ }
+ return mContext.getString(
+ R.string.quick_settings_disclosure_named_management_monitoring,
+ organizationName);
+ }
if (workProfileOrganizationName == null) {
return mContext.getString(R.string.quick_settings_disclosure_management);
}
return mContext.getString(R.string.quick_settings_disclosure_named_management,
workProfileOrganizationName);
}
+ if (hasWorkProfile && isNetworkLoggingEnabled) {
+ if (workProfileOrganizationName == null) {
+ return mContext.getString(
+ R.string.quick_settings_disclosure_managed_profile_monitoring);
+ }
+ return mContext.getString(
+ R.string.quick_settings_disclosure_named_managed_profile_monitoring,
+ workProfileOrganizationName);
+ }
return null;
}
@@ -367,7 +386,8 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
}
// network logging section
- CharSequence networkLoggingMessage = getNetworkLoggingMessage(isNetworkLoggingEnabled);
+ CharSequence networkLoggingMessage = getNetworkLoggingMessage(isDeviceManaged,
+ isNetworkLoggingEnabled);
if (networkLoggingMessage == null) {
dialogView.findViewById(R.id.network_logging_disclosures).setVisibility(View.GONE);
} else {
@@ -492,9 +512,15 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen
return mContext.getString(R.string.monitoring_description_ca_certificate);
}
- protected CharSequence getNetworkLoggingMessage(boolean isNetworkLoggingEnabled) {
+ protected CharSequence getNetworkLoggingMessage(boolean isDeviceManaged,
+ boolean isNetworkLoggingEnabled) {
if (!isNetworkLoggingEnabled) return null;
- return mContext.getString(R.string.monitoring_description_management_network_logging);
+ if (isDeviceManaged) {
+ return mContext.getString(R.string.monitoring_description_management_network_logging);
+ } else {
+ return mContext.getString(
+ R.string.monitoring_description_managed_profile_network_logging);
+ }
}
protected CharSequence getVpnMessage(boolean isDeviceManaged, boolean hasWorkProfile,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java
index a567f512b204..aa6bbbda04fb 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java
@@ -34,7 +34,7 @@ import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
-import com.android.keyguard.CarrierTextController;
+import com.android.keyguard.CarrierTextManager;
import com.android.settingslib.AccessibilityContentDescriptions;
import com.android.settingslib.mobile.TelephonyIcons;
import com.android.systemui.R;
@@ -58,7 +58,7 @@ public class QSCarrierGroupController {
private final ActivityStarter mActivityStarter;
private final Handler mBgHandler;
private final NetworkController mNetworkController;
- private final CarrierTextController mCarrierTextController;
+ private final CarrierTextManager mCarrierTextManager;
private final TextView mNoSimTextView;
private final H mMainHandler;
private final Callback mCallback;
@@ -153,7 +153,7 @@ public class QSCarrierGroupController {
}
};
- private static class Callback implements CarrierTextController.CarrierTextCallback {
+ private static class Callback implements CarrierTextManager.CarrierTextCallback {
private H mHandler;
Callback(H handler) {
@@ -161,7 +161,7 @@ public class QSCarrierGroupController {
}
@Override
- public void updateCarrierInfo(CarrierTextController.CarrierTextCallbackInfo info) {
+ public void updateCarrierInfo(CarrierTextManager.CarrierTextCallbackInfo info) {
mHandler.obtainMessage(H.MSG_UPDATE_CARRIER_INFO, info).sendToTarget();
}
}
@@ -169,7 +169,7 @@ public class QSCarrierGroupController {
private QSCarrierGroupController(QSCarrierGroup view, ActivityStarter activityStarter,
@Background Handler bgHandler, @Main Looper mainLooper,
NetworkController networkController,
- CarrierTextController.Builder carrierTextControllerBuilder, Context context) {
+ CarrierTextManager.Builder carrierTextManagerBuilder, Context context) {
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) {
mProviderModel = true;
} else {
@@ -178,7 +178,7 @@ public class QSCarrierGroupController {
mActivityStarter = activityStarter;
mBgHandler = bgHandler;
mNetworkController = networkController;
- mCarrierTextController = carrierTextControllerBuilder
+ mCarrierTextManager = carrierTextManagerBuilder
.setShowAirplaneMode(false)
.setShowMissingSim(false)
.build();
@@ -196,7 +196,6 @@ public class QSCarrierGroupController {
mMainHandler = new H(mainLooper, this::handleUpdateCarrierInfo, this::handleUpdateState);
mCallback = new Callback(mMainHandler);
-
mCarrierGroups[0] = view.getCarrier1View();
mCarrierGroups[1] = view.getCarrier2View();
mCarrierGroups[2] = view.getCarrier3View();
@@ -247,10 +246,10 @@ public class QSCarrierGroupController {
if (mNetworkController.hasVoiceCallingFeature()) {
mNetworkController.addCallback(mSignalCallback);
}
- mCarrierTextController.setListening(mCallback);
+ mCarrierTextManager.setListening(mCallback);
} else {
mNetworkController.removeCallback(mSignalCallback);
- mCarrierTextController.setListening(null);
+ mCarrierTextManager.setListening(null);
}
}
@@ -277,7 +276,7 @@ public class QSCarrierGroupController {
}
@MainThread
- private void handleUpdateCarrierInfo(CarrierTextController.CarrierTextCallbackInfo info) {
+ private void handleUpdateCarrierInfo(CarrierTextManager.CarrierTextCallbackInfo info) {
if (!mMainHandler.getLooper().isCurrentThread()) {
mMainHandler.obtainMessage(H.MSG_UPDATE_CARRIER_INFO, info).sendToTarget();
return;
@@ -331,13 +330,13 @@ public class QSCarrierGroupController {
}
private static class H extends Handler {
- private Consumer<CarrierTextController.CarrierTextCallbackInfo> mUpdateCarrierInfo;
+ private Consumer<CarrierTextManager.CarrierTextCallbackInfo> mUpdateCarrierInfo;
private Runnable mUpdateState;
static final int MSG_UPDATE_CARRIER_INFO = 0;
static final int MSG_UPDATE_STATE = 1;
H(Looper looper,
- Consumer<CarrierTextController.CarrierTextCallbackInfo> updateCarrierInfo,
+ Consumer<CarrierTextManager.CarrierTextCallbackInfo> updateCarrierInfo,
Runnable updateState) {
super(looper);
mUpdateCarrierInfo = updateCarrierInfo;
@@ -349,7 +348,7 @@ public class QSCarrierGroupController {
switch (msg.what) {
case MSG_UPDATE_CARRIER_INFO:
mUpdateCarrierInfo.accept(
- (CarrierTextController.CarrierTextCallbackInfo) msg.obj);
+ (CarrierTextManager.CarrierTextCallbackInfo) msg.obj);
break;
case MSG_UPDATE_STATE:
mUpdateState.run();
@@ -366,13 +365,13 @@ public class QSCarrierGroupController {
private final Handler mHandler;
private final Looper mLooper;
private final NetworkController mNetworkController;
- private final CarrierTextController.Builder mCarrierTextControllerBuilder;
+ private final CarrierTextManager.Builder mCarrierTextControllerBuilder;
private final Context mContext;
@Inject
public Builder(ActivityStarter activityStarter, @Background Handler handler,
@Main Looper looper, NetworkController networkController,
- CarrierTextController.Builder carrierTextControllerBuilder, Context context) {
+ CarrierTextManager.Builder carrierTextControllerBuilder, Context context) {
mActivityStarter = activityStarter;
mHandler = handler;
mLooper = looper;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt
index 6176a5702dcf..41445917a011 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DeviceControlsTile.kt
@@ -25,6 +25,7 @@ import com.android.internal.logging.MetricsLogger
import com.android.systemui.R
import com.android.systemui.controls.ControlsServiceInfo
import com.android.systemui.controls.dagger.ControlsComponent
+import com.android.systemui.controls.dagger.ControlsComponent.Visibility.UNAVAILABLE
import com.android.systemui.controls.management.ControlsListingController
import com.android.systemui.controls.ui.ControlsDialog
import com.android.systemui.dagger.qualifiers.Background
@@ -91,7 +92,7 @@ class DeviceControlsTile @Inject constructor(
override fun isAvailable(): Boolean {
return featureFlags.isKeyguardLayoutEnabled &&
controlsLockscreen &&
- controlsComponent.getControlsUiController().isPresent
+ controlsComponent.getVisibility() != UNAVAILABLE
}
override fun newTileState(): QSTile.State {
@@ -154,4 +155,4 @@ class DeviceControlsTile @Inject constructor(
override fun getTileLabel(): CharSequence {
return mContext.getText(R.string.quick_controls_title)
}
-} \ No newline at end of file
+}
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java b/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java
index 9383aefeb6b6..1386ddfa7692 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java
@@ -24,15 +24,21 @@ import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
+import android.graphics.Rect;
+import android.os.Bundle;
import android.util.AttributeSet;
+import android.util.IntArray;
import android.util.Log;
import android.util.MathUtils;
import android.view.MotionEvent;
import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
import androidx.annotation.Nullable;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
+import com.android.internal.widget.ExploreByTouchHelper;
import com.android.systemui.R;
/**
@@ -80,6 +86,8 @@ public class CropView extends View {
t.recycle();
// 48 dp touchable region around each handle.
mCropTouchMargin = 24 * getResources().getDisplayMetrics().density;
+
+ setAccessibilityDelegate(new AccessibilityHelper());
}
@Override
@@ -231,6 +239,87 @@ public class CropView extends View {
return CropBoundary.NONE;
}
+ private class AccessibilityHelper extends ExploreByTouchHelper {
+
+ private static final int TOP_HANDLE_ID = 1;
+ private static final int BOTTOM_HANDLE_ID = 2;
+
+ AccessibilityHelper() {
+ super(CropView.this);
+ }
+
+ @Override
+ protected int getVirtualViewAt(float x, float y) {
+ if (Math.abs(y - fractionToPixels(mTopCrop)) < mCropTouchMargin) {
+ return TOP_HANDLE_ID;
+ }
+ if (Math.abs(y - fractionToPixels(mBottomCrop)) < mCropTouchMargin) {
+ return BOTTOM_HANDLE_ID;
+ }
+ return ExploreByTouchHelper.INVALID_ID;
+ }
+
+ @Override
+ protected void getVisibleVirtualViews(IntArray virtualViewIds) {
+ virtualViewIds.add(TOP_HANDLE_ID);
+ virtualViewIds.add(BOTTOM_HANDLE_ID);
+ }
+
+ @Override
+ protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
+ switch(virtualViewId) {
+ case TOP_HANDLE_ID:
+ event.setContentDescription(
+ getResources().getString(R.string.screenshot_top_boundary));
+ break;
+ case BOTTOM_HANDLE_ID:
+ event.setContentDescription(
+ getResources().getString(R.string.screenshot_bottom_boundary));
+ break;
+ }
+ }
+
+ @Override
+ protected void onPopulateNodeForVirtualView(int virtualViewId,
+ AccessibilityNodeInfo node) {
+ switch(virtualViewId) {
+ case TOP_HANDLE_ID:
+ node.setContentDescription(
+ getResources().getString(R.string.screenshot_top_boundary));
+ setNodePositions(mTopCrop, node);
+ break;
+ case BOTTOM_HANDLE_ID:
+ node.setContentDescription(
+ getResources().getString(R.string.screenshot_bottom_boundary));
+ setNodePositions(mBottomCrop, node);
+ break;
+ }
+
+ // TODO: need to figure out the full set of actions to support here.
+ node.addAction(
+ AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
+ node.setClickable(true);
+ node.setFocusable(true);
+ }
+
+ @Override
+ protected boolean onPerformActionForVirtualView(
+ int virtualViewId, int action, Bundle arguments) {
+ return false;
+ }
+
+ private void setNodePositions(float fraction, AccessibilityNodeInfo node) {
+ int pixels = fractionToPixels(fraction);
+ Rect rect = new Rect(0, (int) (pixels - mCropTouchMargin),
+ getWidth(), (int) (pixels + mCropTouchMargin));
+ node.setBoundsInParent(rect);
+ int[] pos = new int[2];
+ getLocationOnScreen(pos);
+ rect.offset(pos[0], pos[1]);
+ node.setBoundsInScreen(rect);
+ }
+ }
+
/**
* Listen for crop motion events and state.
*/
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureClient.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureClient.java
index d56c806554d4..dc639dce4951 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureClient.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureClient.java
@@ -95,6 +95,17 @@ public class ScrollCaptureClient {
this.requested = request;
this.captured = captured;
}
+
+ @Override
+ public String toString() {
+ return "CaptureResult{"
+ + "requested=" + requested
+ + " (" + requested.width() + "x" + requested.height() + ")"
+ + ", captured=" + captured
+ + " (" + captured.width() + "x" + captured.height() + ")"
+ + ", image=" + image
+ + '}';
+ }
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
index d97f644c5d23..ad5e637b189e 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
@@ -253,7 +253,7 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
&& result.captured.height() < result.requested.height();
boolean finish = false;
- if (partialResult) {
+ if (partialResult || emptyResult) {
// Potentially reached a vertical boundary. Extend in the other direction.
switch (mDirection) {
case DOWN:
diff --git a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt
index d707bca0383e..9f182e19efaf 100644
--- a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt
@@ -28,6 +28,7 @@ import android.hardware.SensorPrivacyManager.EXTRA_SENSOR
import android.hardware.SensorPrivacyManager.INDIVIDUAL_SENSOR_CAMERA
import android.hardware.SensorPrivacyManager.INDIVIDUAL_SENSOR_MICROPHONE
import android.os.Bundle
+import android.os.Handler
import android.text.Html
import android.util.Log
import com.android.internal.app.AlertActivity
@@ -43,10 +44,13 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
companion object {
private val LOG_TAG = SensorUseStartedActivity::class.java.simpleName
+
+ private const val SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS = 2000L
}
private var sensor = -1
private lateinit var sensorUsePackageName: String
+ private var unsuppressImmediately = false
private lateinit var sensorPrivacyManager: SensorPrivacyManager
private lateinit var appOpsManager: AppOpsManager
@@ -118,6 +122,7 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
super.onStart()
sensorPrivacyManager.suppressIndividualSensorPrivacyReminders(sensorUsePackageName, true)
+ unsuppressImmediately = false
}
override fun onClick(dialog: DialogInterface?, which: Int) {
@@ -131,16 +136,16 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
}
override fun onDismissSucceeded() {
- sensorPrivacyManager
- .setIndividualSensorPrivacyForProfileGroup(sensor, false)
- setResult(RESULT_OK)
+ disableSensorPrivacy()
}
})
} else {
- sensorPrivacyManager.setIndividualSensorPrivacyForProfileGroup(sensor, false)
- setResult(RESULT_OK)
+ disableSensorPrivacy()
}
}
+ BUTTON_NEGATIVE -> {
+ unsuppressImmediately = false
+ }
}
dismiss()
@@ -149,10 +154,24 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
override fun onStop() {
super.onDestroy()
- sensorPrivacyManager.suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
+ if (unsuppressImmediately) {
+ sensorPrivacyManager
+ .suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
+ } else {
+ Handler(mainLooper).postDelayed({
+ sensorPrivacyManager
+ .suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
+ }, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS)
+ }
}
override fun onBackPressed() {
// do not allow backing out
}
+
+ private fun disableSensorPrivacy() {
+ sensorPrivacyManager.setIndividualSensorPrivacyForProfileGroup(sensor, false)
+ unsuppressImmediately = true
+ setResult(RESULT_OK)
+ }
} \ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/FeatureFlags.java b/packages/SystemUI/src/com/android/systemui/statusbar/FeatureFlags.java
index 7aa41e43be3c..862c27907e0f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/FeatureFlags.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/FeatureFlags.java
@@ -67,6 +67,10 @@ public class FeatureFlags {
return mFlagReader.isEnabled(R.bool.flag_brightness_slider);
}
+ public boolean useNewLockscreenAnimations() {
+ return mFlagReader.isEnabled(R.bool.flag_lockscreen_animations);
+ }
+
public boolean isPeopleTileEnabled() {
return mFlagReader.isEnabled(R.bool.flag_conversations);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt b/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt
index 2f0f90d318eb..c1feacaba440 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt
@@ -11,14 +11,10 @@ import android.graphics.PorterDuffColorFilter
import android.graphics.PorterDuffXfermode
import android.graphics.RadialGradient
import android.graphics.Shader
-import android.os.SystemProperties
import android.util.AttributeSet
import android.view.View
import com.android.systemui.Interpolators
-val enableLightReveal =
- SystemProperties.getBoolean("persist.sysui.show_new_screen_on_transitions", false)
-
/**
* Provides methods to modify the various properties of a [LightRevealScrim] to reveal between 0% to
* 100% of the view(s) underneath the scrim.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
index 8c2fa3349e4a..85d8df8e6057 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
@@ -29,6 +29,7 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.doze.AlwaysOnDisplayPolicy;
import com.android.systemui.doze.DozeScreenState;
+import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;
@@ -54,6 +55,7 @@ public class DozeParameters implements TunerService.Tunable,
private final AlwaysOnDisplayPolicy mAlwaysOnPolicy;
private final Resources mResources;
private final BatteryController mBatteryController;
+ private final FeatureFlags mFeatureFlags;
private boolean mDozeAlwaysOn;
private boolean mControlScreenOffAnimation;
@@ -65,7 +67,8 @@ public class DozeParameters implements TunerService.Tunable,
AlwaysOnDisplayPolicy alwaysOnDisplayPolicy,
PowerManager powerManager,
BatteryController batteryController,
- TunerService tunerService) {
+ TunerService tunerService,
+ FeatureFlags featureFlags) {
mResources = resources;
mAmbientDisplayConfiguration = ambientDisplayConfiguration;
mAlwaysOnPolicy = alwaysOnDisplayPolicy;
@@ -74,6 +77,7 @@ public class DozeParameters implements TunerService.Tunable,
mControlScreenOffAnimation = !getDisplayNeedsBlanking();
mPowerManager = powerManager;
mPowerManager.setDozeAfterScreenOff(!mControlScreenOffAnimation);
+ mFeatureFlags = featureFlags;
tunerService.addTunable(
this,
@@ -200,8 +204,7 @@ public class DozeParameters implements TunerService.Tunable,
* then abruptly showing AOD.
*/
public boolean shouldControlUnlockedScreenOff() {
- return getAlwaysOn() && SystemProperties.getBoolean(
- "persist.sysui.show_new_screen_on_transitions", false);
+ return getAlwaysOn() && mFeatureFlags.useNewLockscreenAnimations();
}
private boolean getBoolean(String propName, int resId) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index 2ce0a8776266..986333ce5010 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
+import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.AVAILABLE;
import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInOffset;
import static com.android.systemui.tuner.LockscreenFragment.LOCKSCREEN_LEFT_BUTTON;
import static com.android.systemui.tuner.LockscreenFragment.LOCKSCREEN_LEFT_UNLOCK;
@@ -183,6 +184,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
private ControlsComponent mControlsComponent;
private int mLockScreenMode;
private BroadcastDispatcher mBroadcastDispatcher;
+ private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
public KeyguardBottomAreaView(Context context) {
this(context, null);
@@ -295,7 +297,8 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
getContext().registerReceiverAsUser(mDevicePolicyReceiver,
UserHandle.ALL, filter, null, null);
- Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mUpdateMonitorCallback);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
+ mKeyguardUpdateMonitor.registerCallback(mUpdateMonitorCallback);
mKeyguardStateController.addCallback(this);
}
@@ -307,7 +310,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
mRightExtension.destroy();
mLeftExtension.destroy();
getContext().unregisterReceiver(mDevicePolicyReceiver);
- Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mUpdateMonitorCallback);
+ mKeyguardUpdateMonitor.removeCallback(mUpdateMonitorCallback);
}
private void initAccessibility() {
@@ -410,12 +413,6 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
}
private void updateLeftAffordanceIcon() {
- if (mDozing) {
- mAltLeftButton.setVisibility(GONE);
- } else if (mAltLeftButton.getDrawable() != null) {
- mAltLeftButton.setVisibility(VISIBLE);
- }
-
if (!mShowLeftAffordance || mDozing) {
mLeftAffordanceView.setVisibility(GONE);
return;
@@ -430,6 +427,14 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
mLeftAffordanceView.setContentDescription(state.contentDescription);
}
+ private void updateControlsVisibility() {
+ if (mDozing || mControlsComponent.getVisibility() != AVAILABLE) {
+ mAltLeftButton.setVisibility(GONE);
+ } else {
+ mAltLeftButton.setVisibility(VISIBLE);
+ }
+ }
+
public boolean isLeftVoiceAssist() {
return mLeftIsVoiceAssist;
}
@@ -769,6 +774,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
updateCameraVisibility();
updateLeftAffordanceIcon();
+ updateControlsVisibility();
if (dozing) {
mOverlayContainer.setVisibility(INVISIBLE);
@@ -889,35 +895,27 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
}
private void setupControls() {
- if (mLockScreenMode == KeyguardUpdateMonitor.LOCK_SCREEN_MODE_NORMAL) {
+ boolean inNewLayout = mLockScreenMode != KeyguardUpdateMonitor.LOCK_SCREEN_MODE_NORMAL;
+ boolean settingEnabled = Settings.Global.getInt(mContext.getContentResolver(),
+ "controls_lockscreen", 0) == 1;
+ if (!inNewLayout || !settingEnabled || !mControlsComponent.isEnabled()) {
mAltLeftButton.setVisibility(View.GONE);
- mAltLeftButton.setOnClickListener(null);
- return;
- }
-
- if (Settings.Global.getInt(mContext.getContentResolver(), "controls_lockscreen", 0) == 0) {
return;
}
- if (mControlsComponent.getControlsListingController().isPresent()) {
- mControlsComponent.getControlsListingController().get()
- .addCallback(list -> {
- if (!list.isEmpty()) {
- mAltLeftButton.setImageDrawable(list.get(0).loadIcon());
- mAltLeftButton.setVisibility(View.VISIBLE);
- mAltLeftButton.setOnClickListener((v) -> {
- ControlsUiController ui = mControlsComponent
- .getControlsUiController().get();
- mControlsDialog = new ControlsDialog(mContext, mBroadcastDispatcher)
- .show(ui);
- });
-
- } else {
- mAltLeftButton.setVisibility(View.GONE);
- mAltLeftButton.setOnClickListener(null);
- }
- });
- }
+ mControlsComponent.getControlsListingController().get()
+ .addCallback(list -> {
+ if (!list.isEmpty()) {
+ mAltLeftButton.setImageDrawable(list.get(0).loadIcon());
+ mAltLeftButton.setOnClickListener((v) -> {
+ ControlsUiController ui = mControlsComponent
+ .getControlsUiController().get();
+ mControlsDialog = new ControlsDialog(mContext, mBroadcastDispatcher)
+ .show(ui);
+ });
+ }
+ updateControlsVisibility();
+ });
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java
new file mode 100644
index 000000000000..377fb92ac6ba
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package com.android.systemui.statusbar.phone;
+
+import com.android.keyguard.CarrierTextController;
+import com.android.systemui.util.ViewController;
+
+import javax.inject.Inject;
+
+/** View Controller for {@link com.android.systemui.statusbar.phone.KeyguardStatusBarView}. */
+public class KeyguardStatusBarViewController extends ViewController<KeyguardStatusBarView> {
+ private final CarrierTextController mCarrierTextController;
+
+ @Inject
+ public KeyguardStatusBarViewController(
+ KeyguardStatusBarView view, CarrierTextController carrierTextController) {
+ super(view);
+ mCarrierTextController = carrierTextController;
+ }
+
+ @Override
+ protected void onInit() {
+ super.onInit();
+ mCarrierTextController.init();
+ }
+
+ @Override
+ protected void onViewAttached() {
+ }
+
+ @Override
+ protected void onViewDetached() {
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
index 67f97dc72446..2f9fa9e6ec41 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
@@ -18,6 +18,10 @@ package com.android.systemui.statusbar.phone;
import static android.view.View.GONE;
+import static androidx.constraintlayout.widget.ConstraintSet.END;
+import static androidx.constraintlayout.widget.ConstraintSet.PARENT_ID;
+import static androidx.constraintlayout.widget.ConstraintSet.START;
+
import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_EXPAND_COLLAPSE;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE;
import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
@@ -65,6 +69,8 @@ import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
+import androidx.constraintlayout.widget.ConstraintSet;
+
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.logging.MetricsLogger;
@@ -77,6 +83,7 @@ import com.android.keyguard.KeyguardStatusViewController;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.keyguard.dagger.KeyguardQsUserSwitchComponent;
+import com.android.keyguard.dagger.KeyguardStatusBarViewComponent;
import com.android.keyguard.dagger.KeyguardStatusViewComponent;
import com.android.keyguard.dagger.KeyguardUserSwitcherComponent;
import com.android.systemui.DejankUtils;
@@ -319,6 +326,7 @@ public class NotificationPanelViewController extends PanelViewController {
private final KeyguardStatusViewComponent.Factory mKeyguardStatusViewComponentFactory;
private final KeyguardQsUserSwitchComponent.Factory mKeyguardQsUserSwitchComponentFactory;
private final KeyguardUserSwitcherComponent.Factory mKeyguardUserSwitcherComponentFactory;
+ private final KeyguardStatusBarViewComponent.Factory mKeyguardStatusBarViewComponentFactory;
private final QSDetailDisplayer mQSDetailDisplayer;
private final FeatureFlags mFeatureFlags;
private final ScrimController mScrimController;
@@ -335,6 +343,7 @@ public class NotificationPanelViewController extends PanelViewController {
private boolean mKeyguardUserSwitcherIsShowing;
private KeyguardUserSwitcherController mKeyguardUserSwitcherController;
private KeyguardStatusBarView mKeyguardStatusBar;
+ private KeyguardStatusBarViewController mKeyguarStatusBarViewController;
private ViewGroup mBigClockContainer;
private QS mQs;
private FrameLayout mQsFrame;
@@ -588,6 +597,7 @@ public class NotificationPanelViewController extends PanelViewController {
KeyguardStatusViewComponent.Factory keyguardStatusViewComponentFactory,
KeyguardQsUserSwitchComponent.Factory keyguardQsUserSwitchComponentFactory,
KeyguardUserSwitcherComponent.Factory keyguardUserSwitcherComponentFactory,
+ KeyguardStatusBarViewComponent.Factory keyguardStatusBarViewComponentFactory,
QSDetailDisplayer qsDetailDisplayer,
NotificationGroupManagerLegacy groupManager,
NotificationIconAreaController notificationIconAreaController,
@@ -614,6 +624,7 @@ public class NotificationPanelViewController extends PanelViewController {
mGroupManager = groupManager;
mNotificationIconAreaController = notificationIconAreaController;
mKeyguardStatusViewComponentFactory = keyguardStatusViewComponentFactory;
+ mKeyguardStatusBarViewComponentFactory = keyguardStatusBarViewComponentFactory;
mFeatureFlags = featureFlags;
mKeyguardQsUserSwitchComponentFactory = keyguardQsUserSwitchComponentFactory;
mKeyguardUserSwitcherComponentFactory = keyguardUserSwitcherComponentFactory;
@@ -717,7 +728,9 @@ public class NotificationPanelViewController extends PanelViewController {
}
updateViewControllers(mView.findViewById(R.id.keyguard_status_view),
- userAvatarView, keyguardUserSwitcherView);
+ userAvatarView,
+ mKeyguardStatusBar,
+ keyguardUserSwitcherView);
mNotificationContainerParent = mView.findViewById(R.id.notification_container_parent);
NotificationStackScrollLayout stackScrollLayout = mView.findViewById(
R.id.notification_stack_scroller);
@@ -762,6 +775,10 @@ public class NotificationPanelViewController extends PanelViewController {
});
mView.setAccessibilityDelegate(mAccessibilityDelegate);
+ // dynamically apply the split shade value overrides.
+ if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
+ updateResources();
+ }
}
@Override
@@ -791,13 +808,21 @@ public class NotificationPanelViewController extends PanelViewController {
}
private void updateViewControllers(KeyguardStatusView keyguardStatusView,
- UserAvatarView userAvatarView, KeyguardUserSwitcherView keyguardUserSwitcherView) {
+ UserAvatarView userAvatarView,
+ KeyguardStatusBarView keyguardStatusBarView,
+ KeyguardUserSwitcherView keyguardUserSwitcherView) {
// Re-associate the KeyguardStatusViewController
KeyguardStatusViewComponent statusViewComponent =
mKeyguardStatusViewComponentFactory.build(keyguardStatusView);
mKeyguardStatusViewController = statusViewComponent.getKeyguardStatusViewController();
mKeyguardStatusViewController.init();
+ KeyguardStatusBarViewComponent statusBarViewComponent =
+ mKeyguardStatusBarViewComponentFactory.build(keyguardStatusBarView);
+ mKeyguarStatusBarViewController =
+ statusBarViewComponent.getKeyguardStatusBarViewController();
+ mKeyguarStatusBarViewController.init();
+
// Re-associate the clock container with the keyguard clock switch.
KeyguardClockSwitchController keyguardClockSwitchController =
statusViewComponent.getKeyguardClockSwitchController();
@@ -870,11 +895,21 @@ public class NotificationPanelViewController extends PanelViewController {
mNotificationStackScrollLayoutController.setLayoutParams(lp);
}
+ // In order to change the constraints at runtime, all children of the Constraint Layout
+ // must have ids.
+ ensureAllViewsHaveIds(mNotificationContainerParent);
+ ConstraintSet constraintSet = new ConstraintSet();
+ constraintSet.clone(mNotificationContainerParent);
if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
- // In order to change the constraints at runtime, all children of the Constraint Layout
- // must have ids.
- ensureAllViewsHaveIds(mNotificationContainerParent);
+ constraintSet.connect(R.id.qs_frame, END, R.id.qs_edge_guideline, END);
+ constraintSet.connect(
+ R.id.notification_stack_scroller, START,
+ R.id.qs_edge_guideline, START);
+ } else {
+ constraintSet.connect(R.id.qs_frame, END, PARENT_ID, END);
+ constraintSet.connect(R.id.notification_stack_scroller, START, PARENT_ID, START);
}
+ constraintSet.applyTo(mNotificationContainerParent);
}
private static void ensureAllViewsHaveIds(ViewGroup parentView) {
@@ -935,7 +970,8 @@ public class NotificationPanelViewController extends PanelViewController {
showKeyguardUserSwitcher /* enabled */);
mBigClockContainer.removeAllViews();
- updateViewControllers(keyguardStatusView, userAvatarView, keyguardUserSwitcherView);
+ updateViewControllers(
+ keyguardStatusView, userAvatarView, mKeyguardStatusBar, keyguardUserSwitcherView);
// Update keyguard bottom area
index = mView.indexOfChild(mKeyguardBottomArea);
@@ -2007,6 +2043,10 @@ public class NotificationPanelViewController extends PanelViewController {
}
private float calculateQsTopPadding() {
+ // in split shade mode we want notifications to be directly below status bar
+ if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources) && !mKeyguardShowing) {
+ return 0f;
+ }
if (mKeyguardShowing && (mQsExpandImmediate
|| mIsExpanding && mQsExpandedWhenExpandingStarted)) {
@@ -2646,7 +2686,9 @@ public class NotificationPanelViewController extends PanelViewController {
super.onTrackingStarted();
if (mQsFullyExpanded) {
mQsExpandImmediate = true;
- mNotificationStackScrollLayoutController.setShouldShowShelfOnly(true);
+ if (!Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
+ mNotificationStackScrollLayoutController.setShouldShowShelfOnly(true);
+ }
}
if (mBarState == KEYGUARD || mBarState == StatusBarState.SHADE_LOCKED) {
mAffordanceHelper.animateHideLeftRightIcon();
@@ -2888,12 +2930,12 @@ public class NotificationPanelViewController extends PanelViewController {
}
/**
- * Updates the vertical position of the panel so it is positioned closer to the touch
+ * Updates the horizontal position of the panel so it is positioned closer to the touch
* responsible for opening the panel.
*
* @param x the x-coordinate the touch event
*/
- protected void updateVerticalPanelPosition(float x) {
+ protected void updateHorizontalPanelPosition(float x) {
if (mNotificationStackScrollLayoutController.getWidth() * 1.75f > mView.getWidth()) {
resetHorizontalPanelPosition();
return;
@@ -3477,7 +3519,7 @@ public class NotificationPanelViewController extends PanelViewController {
}
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isFullyCollapsed()) {
mMetricsLogger.count(COUNTER_PANEL_OPEN, 1);
- updateVerticalPanelPosition(event.getX());
+ updateHorizontalPanelPosition(event.getX());
handled = true;
}
handled |= super.onTouch(v, event);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index e63902f26a78..041a97e1d404 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -35,7 +35,6 @@ import static com.android.systemui.charging.WirelessChargingLayout.UNKNOWN_BATTE
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_WAKING;
-import static com.android.systemui.statusbar.LightRevealScrimKt.getEnableLightReveal;
import static com.android.systemui.statusbar.NotificationLockscreenUserManager.PERMISSION_SELF;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT;
@@ -180,6 +179,7 @@ import com.android.systemui.statusbar.AutoHideUiElement;
import com.android.systemui.statusbar.BackDropView;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.CrossFadeHelper;
+import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.GestureRecorder;
import com.android.systemui.statusbar.KeyboardShortcuts;
import com.android.systemui.statusbar.KeyguardIndicationController;
@@ -440,6 +440,7 @@ public class StatusBar extends SystemUI implements DemoMode,
private final KeyguardViewMediator mKeyguardViewMediator;
protected final NotificationInterruptStateProvider mNotificationInterruptStateProvider;
private final BrightnessSlider.Factory mBrightnessSliderFactory;
+ private final FeatureFlags mFeatureFlags;
private final List<ExpansionChangedListener> mExpansionChangedListeners;
@@ -762,7 +763,8 @@ public class StatusBar extends SystemUI implements DemoMode,
Lazy<NotificationShadeDepthController> notificationShadeDepthControllerLazy,
StatusBarTouchableRegionManager statusBarTouchableRegionManager,
NotificationIconAreaController notificationIconAreaController,
- BrightnessSlider.Factory brightnessSliderFactory) {
+ BrightnessSlider.Factory brightnessSliderFactory,
+ FeatureFlags featureFlags) {
super(context);
mNotificationsController = notificationsController;
mLightBarController = lightBarController;
@@ -840,6 +842,7 @@ public class StatusBar extends SystemUI implements DemoMode,
mDemoModeController = demoModeController;
mNotificationIconAreaController = notificationIconAreaController;
mBrightnessSliderFactory = brightnessSliderFactory;
+ mFeatureFlags = featureFlags;
mExpansionChangedListeners = new ArrayList<>();
@@ -1181,9 +1184,11 @@ public class StatusBar extends SystemUI implements DemoMode,
mLightRevealScrim = mNotificationShadeWindowView.findViewById(R.id.light_reveal_scrim);
- if (getEnableLightReveal()) {
+ if (mFeatureFlags.useNewLockscreenAnimations() && mDozeParameters.getAlwaysOn()) {
mLightRevealScrim.setVisibility(View.VISIBLE);
mLightRevealScrim.setRevealEffect(LiftReveal.INSTANCE);
+ } else {
+ mLightRevealScrim.setVisibility(View.GONE);
}
mNotificationPanelViewController.initDependencies(
@@ -3614,7 +3619,7 @@ public class StatusBar extends SystemUI implements DemoMode,
@Override
public void onDozeAmountChanged(float linear, float eased) {
- if (getEnableLightReveal()) {
+ if (mFeatureFlags.useNewLockscreenAnimations()) {
mLightRevealScrim.setRevealAmount(1f - linear);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java
index 9e9533d0e199..b572c57590ae 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java
@@ -47,6 +47,7 @@ import com.android.systemui.recents.ScreenPinningRequest;
import com.android.systemui.settings.brightness.BrightnessSlider;
import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.statusbar.CommandQueue;
+import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.KeyguardIndicationController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
@@ -200,7 +201,8 @@ public interface StatusBarPhoneModule {
DismissCallbackRegistry dismissCallbackRegistry,
StatusBarTouchableRegionManager statusBarTouchableRegionManager,
NotificationIconAreaController notificationIconAreaController,
- BrightnessSlider.Factory brightnessSliderFactory) {
+ BrightnessSlider.Factory brightnessSliderFactory,
+ FeatureFlags featureFlags) {
return new StatusBar(
context,
notificationsController,
@@ -279,6 +281,7 @@ public interface StatusBarPhoneModule {
notificationShadeDepthController,
statusBarTouchableRegionManager,
notificationIconAreaController,
- brightnessSliderFactory);
+ brightnessSliderFactory,
+ featureFlags);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java
index ec61db591324..8505703b9e25 100644
--- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java
+++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java
@@ -366,7 +366,7 @@ public final class WMShell extends SystemUI
switch (args[i]) {
case "enable-text": {
String[] groups = Arrays.copyOfRange(args, i + 1, args.length);
- int result = protoLogImpl.startTextLogging(mContext, groups, pw);
+ int result = protoLogImpl.startTextLogging(groups, pw);
if (result == 0) {
pw.println("Starting logging on groups: " + Arrays.toString(groups));
}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java
index aa4122fd190a..d3f9d641ca9f 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java
@@ -54,7 +54,6 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.text.TextUtils;
-import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.keyguard.WakefulnessLifecycle;
@@ -74,7 +73,7 @@ import java.util.List;
@SmallTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
-public class CarrierTextControllerTest extends SysuiTestCase {
+public class CarrierTextManagerTest extends SysuiTestCase {
private static final CharSequence SEPARATOR = " \u2014 ";
private static final CharSequence INVALID_CARD_TEXT = "Invalid card";
@@ -95,7 +94,9 @@ public class CarrierTextControllerTest extends SysuiTestCase {
@Mock
private WifiManager mWifiManager;
@Mock
- private CarrierTextController.CarrierTextCallback mCarrierTextCallback;
+ private WakefulnessLifecycle mWakefulnessLifecycle;
+ @Mock
+ private CarrierTextManager.CarrierTextCallback mCarrierTextCallback;
@Mock
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@Mock
@@ -104,13 +105,14 @@ public class CarrierTextControllerTest extends SysuiTestCase {
private TelephonyManager mTelephonyManager;
@Mock
private SubscriptionManager mSubscriptionManager;
- private CarrierTextController.CarrierTextCallbackInfo mCarrierTextCallbackInfo;
+ private CarrierTextManager.CarrierTextCallbackInfo mCarrierTextCallbackInfo;
- private CarrierTextController mCarrierTextController;
+ private CarrierTextManager mCarrierTextManager;
private TestableLooper mTestableLooper;
+ private Handler mMainHandler;
private Void checkMainThread(InvocationOnMock inv) {
- Looper mainLooper = Dependency.get(Dependency.MAIN_HANDLER).getLooper();
+ Looper mainLooper = mMainHandler.getLooper();
if (!mainLooper.isCurrentThread()) {
fail("This call should be done from the main thread");
}
@@ -122,35 +124,33 @@ public class CarrierTextControllerTest extends SysuiTestCase {
MockitoAnnotations.initMocks(this);
mTestableLooper = TestableLooper.get(this);
- mContext.addMockSystemService(WifiManager.class, mWifiManager);
- mContext.addMockSystemService(ConnectivityManager.class, mConnectivityManager);
+ mMainHandler = new Handler(mTestableLooper.getLooper());
when(mConnectivityManager.isNetworkSupported(anyInt())).thenReturn(true);
- mContext.addMockSystemService(TelephonyManager.class, mTelephonyManager);
- mContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager);
mContext.getOrCreateTestableResources().addOverride(
R.string.keyguard_sim_error_message_short, INVALID_CARD_TEXT);
mContext.getOrCreateTestableResources().addOverride(
R.string.airplane_mode, AIRPLANE_MODE_TEXT);
- mDependency.injectMockDependency(WakefulnessLifecycle.class);
- mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
- new Handler(mTestableLooper.getLooper()));
- mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
- mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mKeyguardUpdateMonitor);
doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor)
.registerCallback(any(KeyguardUpdateMonitorCallback.class));
doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor)
.removeCallback(any(KeyguardUpdateMonitorCallback.class));
- mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
+ mCarrierTextCallbackInfo = new CarrierTextManager.CarrierTextCallbackInfo("",
new CharSequence[]{}, false, new int[]{});
when(mTelephonyManager.getSupportedModemCount()).thenReturn(3);
when(mTelephonyManager.getActiveModemCount()).thenReturn(3);
- mCarrierTextController = new CarrierTextController(mContext, SEPARATOR, true, true);
+ mCarrierTextManager = new CarrierTextManager.Builder(
+ mContext, mContext.getResources(), mWifiManager, mConnectivityManager,
+ mTelephonyManager, mWakefulnessLifecycle, new Handler(mTestableLooper.getLooper()),
+ mMainHandler, mKeyguardUpdateMonitor)
+ .setShowAirplaneMode(true)
+ .setShowMissingSim(true)
+ .build();
// This should not start listening on any of the real dependencies but will test that
// callbacks in mKeyguardUpdateMonitor are done in the mTestableLooper thread
- mCarrierTextController.setListening(mCarrierTextCallback);
+ mCarrierTextManager.setListening(mCarrierTextCallback);
mTestableLooper.processAllMessages();
}
@@ -165,8 +165,8 @@ public class CarrierTextControllerTest extends SysuiTestCase {
TestableLooper testableLooper = new TestableLooper(thread.getLooper());
Handler h = new Handler(testableLooper.getLooper());
h.post(() -> {
- mCarrierTextController.setListening(null);
- mCarrierTextController.setListening(mCarrierTextCallback);
+ mCarrierTextManager.setListening(null);
+ mCarrierTextManager.setListening(mCarrierTextCallback);
});
testableLooper.processAllMessages();
mTestableLooper.processAllMessages();
@@ -183,11 +183,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(TelephonyManager.SIM_STATE_READY);
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -205,12 +205,12 @@ public class CarrierTextControllerTest extends SysuiTestCase {
TelephonyManager.SIM_STATE_CARD_IO_ERROR);
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- mCarrierTextController.mCallback.onSimStateChanged(3, 1,
+ mCarrierTextManager.mCallback.onSimStateChanged(3, 1,
TelephonyManager.SIM_STATE_CARD_IO_ERROR);
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -223,7 +223,7 @@ public class CarrierTextControllerTest extends SysuiTestCase {
reset(mCarrierTextCallback);
when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
// Update carrier text. It should ignore error state of subId 3 in inactive slotId.
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
assertEquals("TEST_CARRIER", captor.getValue().carrierText);
@@ -237,9 +237,9 @@ public class CarrierTextControllerTest extends SysuiTestCase {
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
TelephonyManager.SIM_STATE_CARD_IO_ERROR);
// This should not produce an out of bounds error, even though there are no subscriptions
- mCarrierTextController.mCallback.onSimStateChanged(0, -3,
+ mCarrierTextManager.mCallback.onSimStateChanged(0, -3,
TelephonyManager.SIM_STATE_CARD_IO_ERROR);
- mCarrierTextController.mCallback.onSimStateChanged(0, 3, TelephonyManager.SIM_STATE_READY);
+ mCarrierTextManager.mCallback.onSimStateChanged(0, 3, TelephonyManager.SIM_STATE_READY);
verify(mCarrierTextCallback, never()).updateCarrierInfo(any());
}
@@ -257,23 +257,23 @@ public class CarrierTextControllerTest extends SysuiTestCase {
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
TelephonyManager.SIM_STATE_CARD_IO_ERROR);
// This should not produce an out of bounds error, even though there are no subscriptions
- mCarrierTextController.mCallback.onSimStateChanged(0, 1,
+ mCarrierTextManager.mCallback.onSimStateChanged(0, 1,
TelephonyManager.SIM_STATE_CARD_IO_ERROR);
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(
- any(CarrierTextController.CarrierTextCallbackInfo.class));
+ any(CarrierTextManager.CarrierTextCallbackInfo.class));
}
@Test
public void testCallback() {
reset(mCarrierTextCallback);
- mCarrierTextController.postToCallback(mCarrierTextCallbackInfo);
+ mCarrierTextManager.postToCallback(mCarrierTextCallbackInfo);
mTestableLooper.processAllMessages();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
assertEquals(mCarrierTextCallbackInfo, captor.getValue());
}
@@ -282,8 +282,8 @@ public class CarrierTextControllerTest extends SysuiTestCase {
public void testNullingCallback() {
reset(mCarrierTextCallback);
- mCarrierTextController.postToCallback(mCarrierTextCallbackInfo);
- mCarrierTextController.setListening(null);
+ mCarrierTextManager.postToCallback(mCarrierTextCallbackInfo);
+ mCarrierTextManager.setListening(null);
// This shouldn't produce NPE
mTestableLooper.processAllMessages();
@@ -301,15 +301,15 @@ public class CarrierTextControllerTest extends SysuiTestCase {
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
- CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
+ CarrierTextManager.CarrierTextCallbackInfo info = captor.getValue();
assertEquals(1, info.listOfCarriers.length);
assertEquals(TEST_CARRIER, info.listOfCarriers[0]);
assertEquals(1, info.subscriptionIds.length);
@@ -326,15 +326,15 @@ public class CarrierTextControllerTest extends SysuiTestCase {
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
- CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
+ CarrierTextManager.CarrierTextCallbackInfo info = captor.getValue();
assertEquals(1, info.listOfCarriers.length);
assertTrue(info.listOfCarriers[0].toString().contains(TEST_CARRIER));
assertEquals(1, info.subscriptionIds.length);
@@ -346,16 +346,16 @@ public class CarrierTextControllerTest extends SysuiTestCase {
List<SubscriptionInfo> list = new ArrayList<>();
list.add(TEST_SUBSCRIPTION_NULL);
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
- TelephonyManager.SIM_STATE_READY);
+ TelephonyManager.SIM_STATE_READY);
when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -380,11 +380,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
when(ss.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE);
mKeyguardUpdateMonitor.mServiceStates.put(TEST_SUBSCRIPTION_NULL.getSubscriptionId(), ss);
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -407,15 +407,15 @@ public class CarrierTextControllerTest extends SysuiTestCase {
when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(
new ArrayList<>());
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
- CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
+ CarrierTextManager.CarrierTextCallbackInfo info = captor.getValue();
assertEquals(0, info.listOfCarriers.length);
assertEquals(0, info.subscriptionIds.length);
@@ -428,16 +428,16 @@ public class CarrierTextControllerTest extends SysuiTestCase {
list.add(TEST_SUBSCRIPTION);
list.add(TEST_SUBSCRIPTION);
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
- TelephonyManager.SIM_STATE_READY);
+ TelephonyManager.SIM_STATE_READY);
when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -458,11 +458,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -483,11 +483,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
@@ -509,11 +509,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
- ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
+ ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
- CarrierTextController.CarrierTextCallbackInfo.class);
+ CarrierTextManager.CarrierTextCallbackInfo.class);
- mCarrierTextController.updateCarrierText();
+ mCarrierTextManager.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java
index c2ade81a9877..d67fe6dfb0b2 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java
@@ -69,6 +69,8 @@ public class KeyguardAbsKeyInputViewControllerTest extends SysuiTestCase {
private KeyguardMessageAreaController mKeyguardMessageAreaController;
@Mock
private LatencyTracker mLatencyTracker;
+ @Mock
+ private EmergencyButtonController mEmergencyButtonController;
private KeyguardAbsKeyInputViewController mKeyguardAbsKeyInputViewController;
@@ -84,7 +86,8 @@ public class KeyguardAbsKeyInputViewControllerTest extends SysuiTestCase {
.thenReturn(mKeyguardMessageArea);
mKeyguardAbsKeyInputViewController = new KeyguardAbsKeyInputViewController(mAbsKeyInputView,
mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
- mKeyguardMessageAreaControllerFactory, mLatencyTracker) {
+ mKeyguardMessageAreaControllerFactory, mLatencyTracker,
+ mEmergencyButtonController) {
@Override
void resetState() {
}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardDisplayManagerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardDisplayManagerTest.java
index 826be2ba0d83..4beec574cd2a 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardDisplayManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardDisplayManagerTest.java
@@ -54,11 +54,11 @@ import java.util.concurrent.Executor;
public class KeyguardDisplayManagerTest extends SysuiTestCase {
@Mock
+ private NavigationBarController mNavigationBarController;
+ @Mock
private KeyguardStatusViewComponent.Factory mKeyguardStatusViewComponentFactory;
-
@Mock
private DisplayManager mDisplayManager;
-
@Mock
private KeyguardDisplayManager.KeyguardPresentation mKeyguardPresentation;
@@ -76,9 +76,8 @@ public class KeyguardDisplayManagerTest extends SysuiTestCase {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext.addMockSystemService(DisplayManager.class, mDisplayManager);
- mDependency.injectMockDependency(NavigationBarController.class);
- mManager = spy(new KeyguardDisplayManager(mContext, mKeyguardStatusViewComponentFactory,
- mBackgroundExecutor));
+ mManager = spy(new KeyguardDisplayManager(mContext, () -> mNavigationBarController,
+ mKeyguardStatusViewComponentFactory, mBackgroundExecutor));
doReturn(mKeyguardPresentation).when(mManager).createPresentation(any());
mDefaultDisplay = new Display(DisplayManagerGlobal.getInstance(), Display.DEFAULT_DISPLAY,
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt
index c69ec1a254c3..6d0c64088abc 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt
@@ -49,6 +49,8 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() {
@Mock
private lateinit var mLatencyTracker: LatencyTracker
@Mock
+ private lateinit var mEmergencyButtonController: EmergencyButtonController
+ @Mock
private lateinit
var mKeyguardMessageAreaControllerFactory: KeyguardMessageAreaController.Factory
@Mock
@@ -72,7 +74,8 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() {
.thenReturn(mKeyguardMessageAreaController)
mKeyguardPatternViewController = KeyguardPatternViewController(mKeyguardPatternView,
mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
- mLatencyTracker, mKeyguardMessageAreaControllerFactory)
+ mLatencyTracker, mEmergencyButtonController,
+ mKeyguardMessageAreaControllerFactory)
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java
index 31cc7bb7c958..8d1e1a4a4463 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java
@@ -67,6 +67,8 @@ public class KeyguardPinBasedInputViewControllerTest extends SysuiTestCase {
private LatencyTracker mLatencyTracker;
@Mock
private LiftToActivateListener mLiftToactivateListener;
+ @Mock
+ private EmergencyButtonController mEmergencyButtonController;
private FalsingCollector mFalsingCollector = new FalsingCollectorFake();
@Mock
private View mDeleteButton;
@@ -92,7 +94,7 @@ public class KeyguardPinBasedInputViewControllerTest extends SysuiTestCase {
mKeyguardPinViewController = new KeyguardPinBasedInputViewController(mPinBasedInputView,
mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
mKeyguardMessageAreaControllerFactory, mLatencyTracker, mLiftToactivateListener,
- mFalsingCollector) {
+ mEmergencyButtonController, mFalsingCollector) {
@Override
public void onResume(int reason) {
super.onResume(reason);
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java
index 3b7f4b839853..9296d3d5ec82 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java
@@ -59,6 +59,10 @@ public class KeyguardSecurityViewFlipperControllerTest extends SysuiTestCase {
@Mock
private KeyguardInputViewController.Factory mKeyguardSecurityViewControllerFactory;
@Mock
+ private EmergencyButtonController.Factory mEmergencyButtonControllerFactory;
+ @Mock
+ private EmergencyButtonController mEmergencyButtonController;
+ @Mock
private KeyguardInputViewController mKeyguardInputViewController;
@Mock
private KeyguardInputView mInputView;
@@ -76,9 +80,12 @@ public class KeyguardSecurityViewFlipperControllerTest extends SysuiTestCase {
any(KeyguardSecurityCallback.class)))
.thenReturn(mKeyguardInputViewController);
when(mView.getWindowInsetsController()).thenReturn(mWindowInsetsController);
+ when(mEmergencyButtonControllerFactory.create(any(EmergencyButton.class)))
+ .thenReturn(mEmergencyButtonController);
mKeyguardSecurityViewFlipperController = new KeyguardSecurityViewFlipperController(mView,
- mLayoutInflater, mKeyguardSecurityViewControllerFactory);
+ mLayoutInflater, mKeyguardSecurityViewControllerFactory,
+ mEmergencyButtonControllerFactory);
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt
index 7fe682793152..b8f91b8d4719 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt
@@ -17,11 +17,18 @@
package com.android.systemui.controls.dagger
import android.testing.AndroidTestingRunner
+import android.provider.Settings
import androidx.test.filters.SmallTest
+import com.android.internal.widget.LockPatternUtils
+import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED
+import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT
import com.android.systemui.SysuiTestCase
import com.android.systemui.controls.controller.ControlsController
import com.android.systemui.controls.management.ControlsListingController
import com.android.systemui.controls.ui.ControlsUiController
+import com.android.systemui.settings.UserTracker
+import com.android.systemui.statusbar.policy.KeyguardStateController
+import com.android.systemui.util.settings.SecureSettings
import dagger.Lazy
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -29,7 +36,11 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.Answers
import org.mockito.Mock
+import org.mockito.Mockito
+import org.mockito.Mockito.anyInt
+import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
@SmallTest
@@ -42,20 +53,29 @@ class ControlsComponentTest : SysuiTestCase() {
private lateinit var uiController: ControlsUiController
@Mock
private lateinit var listingController: ControlsListingController
+ @Mock
+ private lateinit var keyguardStateController: KeyguardStateController
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private lateinit var userTracker: UserTracker
+ @Mock
+ private lateinit var lockPatternUtils: LockPatternUtils
+ @Mock
+ private lateinit var secureSettings: SecureSettings
+
+ companion object {
+ fun <T> eq(value: T): T = Mockito.eq(value) ?: value
+ }
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
+
+ `when`(userTracker.userHandle.identifier).thenReturn(0)
}
@Test
fun testFeatureEnabled() {
- val component = ControlsComponent(
- true,
- Lazy { controller },
- Lazy { uiController },
- Lazy { listingController }
- )
+ val component = setupComponent(true)
assertTrue(component.getControlsController().isPresent)
assertEquals(controller, component.getControlsController().get())
@@ -67,15 +87,80 @@ class ControlsComponentTest : SysuiTestCase() {
@Test
fun testFeatureDisabled() {
- val component = ControlsComponent(
- false,
- Lazy { controller },
- Lazy { uiController },
- Lazy { listingController }
- )
+ val component = setupComponent(false)
assertFalse(component.getControlsController().isPresent)
assertFalse(component.getControlsUiController().isPresent)
assertFalse(component.getControlsListingController().isPresent)
}
-} \ No newline at end of file
+
+ @Test
+ fun testFeatureDisabledVisibility() {
+ val component = setupComponent(false)
+
+ assertEquals(ControlsComponent.Visibility.UNAVAILABLE, component.getVisibility())
+ }
+
+ @Test
+ fun testFeatureEnabledAfterBootVisibility() {
+ `when`(controller.available).thenReturn(true)
+ `when`(lockPatternUtils.getStrongAuthForUser(anyInt()))
+ .thenReturn(STRONG_AUTH_REQUIRED_AFTER_BOOT)
+ val component = setupComponent(true)
+
+ assertEquals(ControlsComponent.Visibility.AVAILABLE_AFTER_UNLOCK, component.getVisibility())
+ }
+
+ @Test
+ fun testFeatureEnabledAndCannotShowOnLockScreenVisibility() {
+ `when`(controller.available).thenReturn(true)
+ `when`(lockPatternUtils.getStrongAuthForUser(anyInt()))
+ .thenReturn(STRONG_AUTH_NOT_REQUIRED)
+ `when`(keyguardStateController.isUnlocked()).thenReturn(false)
+ `when`(secureSettings.getInt(eq(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT), anyInt()))
+ .thenReturn(0)
+ val component = setupComponent(true)
+
+ assertEquals(ControlsComponent.Visibility.AVAILABLE_AFTER_UNLOCK, component.getVisibility())
+ }
+
+ @Test
+ fun testFeatureEnabledAndCanShowOnLockScreenVisibility() {
+ `when`(controller.available).thenReturn(true)
+ `when`(lockPatternUtils.getStrongAuthForUser(anyInt()))
+ .thenReturn(STRONG_AUTH_NOT_REQUIRED)
+ `when`(keyguardStateController.isUnlocked()).thenReturn(false)
+ `when`(secureSettings.getInt(eq(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT), anyInt()))
+ .thenReturn(1)
+ val component = setupComponent(true)
+
+ assertEquals(ControlsComponent.Visibility.AVAILABLE, component.getVisibility())
+ }
+
+ @Test
+ fun testFeatureEnabledAndCanShowWhileUnlockedVisibility() {
+ `when`(secureSettings.getInt(eq(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT), anyInt()))
+ .thenReturn(0)
+ `when`(controller.available).thenReturn(true)
+ `when`(lockPatternUtils.getStrongAuthForUser(anyInt()))
+ .thenReturn(STRONG_AUTH_NOT_REQUIRED)
+ `when`(keyguardStateController.isUnlocked()).thenReturn(true)
+ val component = setupComponent(true)
+
+ assertEquals(ControlsComponent.Visibility.AVAILABLE, component.getVisibility())
+ }
+
+ private fun setupComponent(enabled: Boolean): ControlsComponent {
+ return ControlsComponent(
+ enabled,
+ mContext,
+ Lazy { controller },
+ Lazy { uiController },
+ Lazy { listingController },
+ lockPatternUtils,
+ keyguardStateController,
+ userTracker,
+ secureSettings
+ )
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java
index 069699c271f7..6d8c372a061b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java
@@ -173,4 +173,30 @@ public class DozeUiTest extends SysuiTestCase {
mDozeUi.transitionTo(UNINITIALIZED, DOZE);
verify(mHost).setAnimateWakeup(eq(false));
}
+
+ @Test
+ public void controlScreenOffTrueWhenKeyguardNotShowingAndControlUnlockedScreenOff() {
+ when(mDozeParameters.getAlwaysOn()).thenReturn(true);
+ when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true);
+
+ // Tell doze that keyguard is not visible.
+ mDozeUi.getKeyguardCallback().onKeyguardVisibilityChanged(false /* showing */);
+
+ // Since we're controlling the unlocked screen off animation, verify that we've asked to
+ // control the screen off animation despite being unlocked.
+ verify(mDozeParameters).setControlScreenOffAnimation(true);
+ }
+
+ @Test
+ public void controlScreenOffFalseWhenKeyguardNotShowingAndControlUnlockedScreenOffFalse() {
+ when(mDozeParameters.getAlwaysOn()).thenReturn(true);
+ when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false);
+
+ // Tell doze that keyguard is not visible.
+ mDozeUi.getKeyguardCallback().onKeyguardVisibilityChanged(false /* showing */);
+
+ // Since we're not controlling the unlocked screen off animation, verify that we haven't
+ // asked to control the screen off animation since we're unlocked.
+ verify(mDozeParameters).setControlScreenOffAnimation(false);
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java
index 78ee5936fe0b..1062fae52e7a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java
@@ -74,12 +74,14 @@ import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.GlobalActions;
import com.android.systemui.plugins.GlobalActionsPanelPlugin;
import com.android.systemui.settings.UserContextProvider;
+import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.RingerModeLiveData;
import com.android.systemui.util.RingerModeTracker;
+import com.android.systemui.util.settings.SecureSettings;
import org.junit.Before;
import org.junit.Test;
@@ -135,6 +137,8 @@ public class GlobalActionsDialogTest extends SysuiTestCase {
@Mock GlobalActionsPanelPlugin.PanelViewController mWalletController;
@Mock private Handler mHandler;
@Mock private UserContextProvider mUserContextProvider;
+ @Mock private UserTracker mUserTracker;
+ @Mock private SecureSettings mSecureSettings;
private ControlsComponent mControlsComponent;
private TestableLooper mTestableLooper;
@@ -149,9 +153,14 @@ public class GlobalActionsDialogTest extends SysuiTestCase {
when(mUserContextProvider.getUserContext()).thenReturn(mContext);
mControlsComponent = new ControlsComponent(
true,
+ mContext,
() -> mControlsController,
() -> mControlsUiController,
- () -> mControlsListingController
+ () -> mControlsListingController,
+ mLockPatternUtils,
+ mKeyguardStateController,
+ mUserTracker,
+ mSecureSettings
);
mGlobalActionsDialog = new GlobalActionsDialog(mContext,
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 00943bc53bfd..b8c37fde2ce3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
@@ -18,6 +18,8 @@ package com.android.systemui.keyguard;
import static android.view.WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -27,13 +29,17 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.ActivityManager;
+import android.app.ActivityTaskManager;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
+import android.view.View;
+import com.android.systemui.R;
import androidx.test.filters.SmallTest;
import com.android.internal.widget.LockPatternUtils;
@@ -45,6 +51,7 @@ import com.android.systemui.classifier.FalsingCollectorFake;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
+import com.android.systemui.statusbar.LightRevealScrim;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.util.DeviceConfigProxy;
@@ -117,4 +124,20 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
mViewMediator.mViewMediatorCallback.keyguardGone();
verify(mStatusBarKeyguardViewManager).setKeyguardGoingAwayState(eq(false));
}
+
+ @Test
+ public void testIsAnimatingScreenOff() {
+ when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true);
+
+ mViewMediator.onFinishedGoingToSleep(OFF_BECAUSE_OF_USER, false);
+ mViewMediator.setDozing(true);
+
+ // Mid-doze, we should be animating the screen off animation.
+ mViewMediator.onDozeAmountChanged(0.5f, 0.5f);
+ assertTrue(mViewMediator.isAnimatingScreenOff());
+
+ // Once we're 100% dozed, the screen off animation should be completed.
+ mViewMediator.onDozeAmountChanged(1f, 1f);
+ assertFalse(mViewMediator.isAnimatingScreenOff());
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java
new file mode 100644
index 000000000000..b3ad6ef8da6e
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTest.java
@@ -0,0 +1,156 @@
+/*
+ * 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.
+ */
+
+package com.android.systemui.people;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import android.app.people.ConversationChannel;
+import android.app.people.IPeopleManager;
+import android.content.pm.LauncherApps;
+import android.content.pm.PackageManager;
+import android.content.pm.ShortcutInfo;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.testing.AndroidTestingRunner;
+import android.widget.RemoteViews;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.shared.system.PeopleProviderUtils;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidTestingRunner.class)
+@SmallTest
+public class PeopleProviderTest extends SysuiTestCase {
+ private static final String TAG = "PeopleProviderTest";
+
+ private static final Uri URI = Uri.parse(PeopleProviderUtils.PEOPLE_PROVIDER_SCHEME
+ + PeopleProviderUtils.PEOPLE_PROVIDER_AUTHORITY);
+
+ private static final String SHORTCUT_ID_A = "shortcut_id_a";
+ private static final String PACKAGE_NAME_A = "package_name_a";
+ private static final UserHandle USER_HANDLE_A = UserHandle.of(1);
+ private static final String USERNAME = "username";
+
+ private final ShortcutInfo mShortcutInfo =
+ new ShortcutInfo.Builder(mContext, SHORTCUT_ID_A).setLongLabel(USERNAME).build();
+ private final ConversationChannel mConversationChannel =
+ new ConversationChannel(mShortcutInfo, USER_HANDLE_A.getIdentifier(),
+ null, null, 0L, false);
+
+ private Bundle mExtras = new Bundle();
+
+ @Mock
+ private LauncherApps mLauncherApps;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private IPeopleManager mPeopleManager;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mContext.setMockPackageManager(mPackageManager);
+
+ PeopleProviderTestable provider = new PeopleProviderTestable();
+ provider.initializeForTesting(
+ mContext, PeopleProviderUtils.PEOPLE_PROVIDER_AUTHORITY);
+ provider.setLauncherApps(mLauncherApps);
+ provider.setPeopleManager(mPeopleManager);
+ mContext.getContentResolver().addProvider(
+ PeopleProviderUtils.PEOPLE_PROVIDER_AUTHORITY, provider);
+
+ mContext.getTestablePermissions().setPermission(
+ PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_PERMISSION,
+ PackageManager.PERMISSION_GRANTED);
+
+ when(mPeopleManager.getConversation(
+ eq(PACKAGE_NAME_A), eq(USER_HANDLE_A.getIdentifier()), eq(SHORTCUT_ID_A)))
+ .thenReturn(mConversationChannel);
+
+ mExtras.putString(PeopleProviderUtils.EXTRAS_KEY_SHORTCUT_ID, SHORTCUT_ID_A);
+ mExtras.putString(PeopleProviderUtils.EXTRAS_KEY_PACKAGE_NAME, PACKAGE_NAME_A);
+ mExtras.putParcelable(PeopleProviderUtils.EXTRAS_KEY_USER_HANDLE, USER_HANDLE_A);
+ }
+
+ @Test
+ public void testPermissionDeniedThrowsSecurityException() throws RemoteException {
+ mContext.getTestablePermissions().setPermission(
+ PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_PERMISSION,
+ PackageManager.PERMISSION_DENIED);
+ try {
+ Bundle result = mContext.getContentResolver()
+ .call(URI, PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_METHOD, null, null);
+ Assert.fail("Call should have failed with SecurityException");
+ } catch (SecurityException e) {
+ } catch (Exception e) {
+ Assert.fail("Call should have failed with SecurityException");
+ }
+ }
+
+ @Test
+ public void testPermissionGrantedNoExtraReturnsNull() throws RemoteException {
+ try {
+ Bundle result = mContext.getContentResolver()
+ .call(URI, PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_METHOD, null, null);
+ Assert.fail("Call should have failed with IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ } catch (Exception e) {
+ Assert.fail("Call should have failed with IllegalArgumentException");
+ }
+ }
+
+ @Test
+ public void testPermissionGrantedExtrasReturnsRemoteViews() throws RemoteException {
+ try {
+ Bundle result = mContext.getContentResolver().call(
+ URI, PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_METHOD, null, mExtras);
+ RemoteViews views = result.getParcelable(
+ PeopleProviderUtils.RESPONSE_KEY_REMOTE_VIEWS);
+ assertThat(views).isNotNull();
+ } catch (Exception e) {
+ Assert.fail("Fail " + e);
+ }
+ }
+
+ @Test
+ public void testPermissionGrantedNoConversationForShortcutReturnsNull() throws RemoteException {
+ when(mPeopleManager.getConversation(
+ eq(PACKAGE_NAME_A), eq(USER_HANDLE_A.getIdentifier()), eq(SHORTCUT_ID_A)))
+ .thenReturn(null);
+ try {
+ Bundle result = mContext.getContentResolver().call(
+ URI, PeopleProviderUtils.GET_PEOPLE_TILE_PREVIEW_METHOD, null, mExtras);
+ assertThat(result).isNull();
+ } catch (Exception e) {
+ Assert.fail("Fail " + e);
+ }
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java
new file mode 100644
index 000000000000..ac1893413c50
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleProviderTestable.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package com.android.systemui.people;
+
+import android.app.people.IPeopleManager;
+import android.content.Context;
+import android.content.pm.LauncherApps;
+import android.content.pm.ProviderInfo;
+
+public class PeopleProviderTestable extends PeopleProvider {
+
+ public void initializeForTesting(Context context, String authority) {
+ ProviderInfo info = new ProviderInfo();
+ info.authority = authority;
+
+ attachInfoForTesting(context, info);
+ }
+
+ void setLauncherApps(LauncherApps launcherApps) {
+ mLauncherApps = launcherApps;
+ }
+
+ void setPeopleManager(IPeopleManager peopleManager) {
+ mPeopleManager = peopleManager;
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java
index 4ee2759028a9..d79155cbb2fc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java
@@ -16,11 +16,18 @@
package com.android.systemui.people;
+import static android.app.people.ConversationStatus.ACTIVITY_BIRTHDAY;
+import static android.app.people.ConversationStatus.ACTIVITY_GAME;
+import static android.app.people.ConversationStatus.ACTIVITY_NEW_STORY;
+import static android.app.people.ConversationStatus.AVAILABILITY_AVAILABLE;
+
import static com.android.systemui.people.PeopleSpaceUtils.OPTIONS_PEOPLE_SPACE_TILE;
import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -39,6 +46,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Person;
import android.app.people.ConversationChannel;
+import android.app.people.ConversationStatus;
import android.app.people.IPeopleManager;
import android.app.people.PeopleSpaceTile;
import android.appwidget.AppWidgetManager;
@@ -46,13 +54,13 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherApps;
+import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ShortcutInfo;
import android.database.Cursor;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Bundle;
-import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.ContactsContract;
import android.provider.Settings;
@@ -60,6 +68,9 @@ import android.service.notification.ConversationChannelWrapper;
import android.service.notification.StatusBarNotification;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.view.View;
+import android.widget.RemoteViews;
+import android.widget.TextView;
import com.android.internal.appwidget.IAppWidgetService;
import com.android.systemui.R;
@@ -101,27 +112,45 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
private static final int TEST_COLUMN_INDEX = 1;
private static final Uri URI = Uri.parse("fake_uri");
private static final Icon ICON = Icon.createWithResource("package", R.drawable.ic_android);
+ private static final String GAME_DESCRIPTION = "Playing a game!";
+ private static final String NAME = "username";
private static final Person PERSON = new Person.Builder()
.setName("name")
.setKey("abc")
.setUri(URI.toString())
.setBot(false)
.build();
+ private static final PeopleSpaceTile PERSON_TILE_WITHOUT_NOTIFICATION =
+ new PeopleSpaceTile
+ .Builder(SHORTCUT_ID_1, NAME, ICON, new Intent())
+ .setLastInteractionTimestamp(0L)
+ .build();
private static final PeopleSpaceTile PERSON_TILE =
new PeopleSpaceTile
- .Builder(SHORTCUT_ID_1, "username", ICON, new Intent())
+ .Builder(SHORTCUT_ID_1, NAME, ICON, new Intent())
+ .setLastInteractionTimestamp(123L)
.setNotificationKey(NOTIFICATION_KEY)
.setNotificationContent(NOTIFICATION_CONTENT)
.setNotificationDataUri(URI)
.build();
+ private static final ConversationStatus GAME_STATUS =
+ new ConversationStatus
+ .Builder(PERSON_TILE.getId(), ACTIVITY_GAME)
+ .setDescription(GAME_DESCRIPTION)
+ .build();
+ private static final ConversationStatus NEW_STORY_WITH_AVAILABILITY =
+ new ConversationStatus
+ .Builder(PERSON_TILE.getId(), ACTIVITY_NEW_STORY)
+ .setAvailability(AVAILABILITY_AVAILABLE)
+ .build();
private final ShortcutInfo mShortcutInfo = new ShortcutInfo.Builder(mContext,
SHORTCUT_ID_1).setLongLabel(
- "name").setPerson(PERSON)
+ NAME).setPerson(PERSON)
.build();
private final ShortcutInfo mShortcutInfoWithoutPerson = new ShortcutInfo.Builder(mContext,
SHORTCUT_ID_1).setLongLabel(
- "name")
+ NAME)
.build();
private final Notification mNotification1 = new Notification.Builder(mContext, "test")
.setContentTitle("TEST_TITLE")
@@ -189,10 +218,12 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
@Mock
private Context mMockContext;
@Mock
+ private PackageManager mPackageManager;
+ @Mock
private NotificationEntryManager mNotificationEntryManager;
@Before
- public void setUp() throws RemoteException {
+ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PEOPLE_SPACE_CONVERSATION_TYPE, 0);
@@ -212,6 +243,12 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
isNull())).thenReturn(mMockCursor);
when(mMockContext.getString(R.string.birthday_status)).thenReturn(
mContext.getString(R.string.birthday_status));
+ when(mMockContext.getString(R.string.basic_status)).thenReturn(
+ mContext.getString(R.string.basic_status));
+ when(mMockContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mMockContext.getString(R.string.over_timestamp)).thenReturn(
+ mContext.getString(R.string.over_timestamp));
+ when(mPackageManager.getApplicationIcon(anyString())).thenReturn(null);
when(mNotificationEntryManager.getVisibleNotifications())
.thenReturn(List.of(mNotificationEntry1, mNotificationEntry2, mNotificationEntry3));
}
@@ -621,6 +658,137 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
any());
}
+ @Test
+ public void testCreateRemoteViewsWithLastInteractionTime() {
+ RemoteViews views = PeopleSpaceUtils.createRemoteViews(mMockContext,
+ PERSON_TILE_WITHOUT_NOTIFICATION, 0);
+ View result = views.apply(mContext, null);
+
+ TextView name = (TextView) result.findViewById(R.id.name);
+ assertEquals(name.getText(), NAME);
+ // Has last interaction.
+ TextView lastInteraction = (TextView) result.findViewById(R.id.last_interaction);
+ assertEquals(lastInteraction.getText(), mContext.getString(R.string.basic_status));
+ // No availability.
+ View availability = result.findViewById(R.id.availability);
+ assertEquals(View.GONE, availability.getVisibility());
+ // No new story.
+ View personIcon = result.findViewById(R.id.person_icon_only);
+ View personIconWithStory = result.findViewById(R.id.person_icon_with_story);
+ assertEquals(View.VISIBLE, personIcon.getVisibility());
+ assertEquals(View.GONE, personIconWithStory.getVisibility());
+ // No status.
+ assertThat((View) result.findViewById(R.id.status)).isNull();
+ }
+
+ @Test
+ public void testCreateRemoteViewsWithGameTypeOnlyIsIgnored() {
+ PeopleSpaceTile tileWithAvailabilityAndNewStory =
+ PERSON_TILE_WITHOUT_NOTIFICATION.toBuilder().setStatuses(
+ Arrays.asList(NEW_STORY_WITH_AVAILABILITY,
+ new ConversationStatus.Builder(
+ PERSON_TILE_WITHOUT_NOTIFICATION.getId(),
+ ACTIVITY_GAME).build())).build();
+ RemoteViews views = PeopleSpaceUtils.createRemoteViews(mMockContext,
+ tileWithAvailabilityAndNewStory, 0);
+ View result = views.apply(mContext, null);
+
+ TextView name = (TextView) result.findViewById(R.id.name);
+ assertEquals(name.getText(), NAME);
+ // Has last interaction over status.
+ TextView lastInteraction = (TextView) result.findViewById(R.id.last_interaction);
+ assertEquals(lastInteraction.getText(), mContext.getString(R.string.basic_status));
+ // Has availability.
+ View availability = result.findViewById(R.id.availability);
+ assertEquals(View.VISIBLE, availability.getVisibility());
+ // Has new story.
+ View personIcon = result.findViewById(R.id.person_icon_only);
+ View personIconWithStory = result.findViewById(R.id.person_icon_with_story);
+ assertEquals(View.GONE, personIcon.getVisibility());
+ assertEquals(View.VISIBLE, personIconWithStory.getVisibility());
+ // No status.
+ assertThat((View) result.findViewById(R.id.status)).isNull();
+ }
+
+ @Test
+ public void testCreateRemoteViewsWithBirthdayTypeOnlyIsNotIgnored() {
+ PeopleSpaceTile tileWithStatusTemplate =
+ PERSON_TILE_WITHOUT_NOTIFICATION.toBuilder().setStatuses(
+ Arrays.asList(
+ NEW_STORY_WITH_AVAILABILITY, new ConversationStatus.Builder(
+ PERSON_TILE_WITHOUT_NOTIFICATION.getId(),
+ ACTIVITY_BIRTHDAY).build())).build();
+ RemoteViews views = PeopleSpaceUtils.createRemoteViews(mContext,
+ tileWithStatusTemplate, 0);
+ View result = views.apply(mContext, null);
+
+ TextView name = (TextView) result.findViewById(R.id.name);
+ assertEquals(name.getText(), NAME);
+ // Has availability.
+ View availability = result.findViewById(R.id.availability);
+ assertEquals(View.VISIBLE, availability.getVisibility());
+ // Has new story.
+ View personIcon = result.findViewById(R.id.person_icon_only);
+ View personIconWithStory = result.findViewById(R.id.person_icon_with_story);
+ assertEquals(View.GONE, personIcon.getVisibility());
+ assertEquals(View.VISIBLE, personIconWithStory.getVisibility());
+ // Has status text from backup text.
+ TextView statusContent = (TextView) result.findViewById(R.id.status);
+ assertEquals(statusContent.getText(), mContext.getString(R.string.birthday_status));
+ }
+
+ @Test
+ public void testCreateRemoteViewsWithStatusTemplate() {
+ PeopleSpaceTile tileWithStatusTemplate =
+ PERSON_TILE_WITHOUT_NOTIFICATION.toBuilder().setStatuses(
+ Arrays.asList(GAME_STATUS,
+ NEW_STORY_WITH_AVAILABILITY)).build();
+ RemoteViews views = PeopleSpaceUtils.createRemoteViews(mContext,
+ tileWithStatusTemplate, 0);
+ View result = views.apply(mContext, null);
+
+ TextView name = (TextView) result.findViewById(R.id.name);
+ assertEquals(name.getText(), NAME);
+ // Has availability.
+ View availability = result.findViewById(R.id.availability);
+ assertEquals(View.VISIBLE, availability.getVisibility());
+ // Has new story.
+ View personIcon = result.findViewById(R.id.person_icon_only);
+ View personIconWithStory = result.findViewById(R.id.person_icon_with_story);
+ assertEquals(View.GONE, personIcon.getVisibility());
+ assertEquals(View.VISIBLE, personIconWithStory.getVisibility());
+ // Has status.
+ TextView statusContent = (TextView) result.findViewById(R.id.status);
+ assertEquals(statusContent.getText(), GAME_DESCRIPTION);
+ }
+
+ @Test
+ public void testCreateRemoteViewsWithNotificationTemplate() {
+ PeopleSpaceTile tileWithStatusAndNotification = PERSON_TILE.toBuilder()
+ .setNotificationDataUri(null)
+ .setStatuses(Arrays.asList(GAME_STATUS,
+ NEW_STORY_WITH_AVAILABILITY)).build();
+ RemoteViews views = PeopleSpaceUtils.createRemoteViews(mContext,
+ tileWithStatusAndNotification, 0);
+ View result = views.apply(mContext, null);
+
+ TextView name = (TextView) result.findViewById(R.id.name);
+ assertEquals(name.getText(), NAME);
+ TextView subtext = (TextView) result.findViewById(R.id.subtext);
+ assertTrue(subtext.getText().toString().contains("weeks ago"));
+ // Has availability.
+ View availability = result.findViewById(R.id.availability);
+ assertEquals(View.VISIBLE, availability.getVisibility());
+ // Has new story.
+ View personIcon = result.findViewById(R.id.person_icon_only);
+ View personIconWithStory = result.findViewById(R.id.person_icon_with_story);
+ assertEquals(View.GONE, personIcon.getVisibility());
+ assertEquals(View.VISIBLE, personIconWithStory.getVisibility());
+ // Has notification content.
+ TextView statusContent = (TextView) result.findViewById(R.id.content);
+ assertEquals(statusContent.getText(), NOTIFICATION_CONTENT);
+ }
+
private ConversationChannelWrapper getConversationChannelWrapper(String shortcutId,
boolean importantConversation, long lastInteractionTimestamp) throws Exception {
ConversationChannelWrapper convo = new ConversationChannelWrapper();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
index fd0715bbca29..862e3747f602 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
@@ -443,9 +443,18 @@ public class QSSecurityFooterTest extends SysuiTestCase {
@Test
public void testGetNetworkLoggingMessage() {
- assertEquals(null, mFooter.getNetworkLoggingMessage(false));
+ // Test network logging message on a device with a device owner.
+ // Network traffic may be monitored on the device.
+ assertEquals(null, mFooter.getNetworkLoggingMessage(true, false));
assertEquals(mContext.getString(R.string.monitoring_description_management_network_logging),
- mFooter.getNetworkLoggingMessage(true));
+ mFooter.getNetworkLoggingMessage(true, true));
+
+ // Test network logging message on a device with a managed profile owner
+ // Network traffic may be monitored on the work profile.
+ assertEquals(null, mFooter.getNetworkLoggingMessage(false, false));
+ assertEquals(
+ mContext.getString(R.string.monitoring_description_managed_profile_network_logging),
+ mFooter.getNetworkLoggingMessage(false, true));
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java
index 1ec1da44c0b5..e855834dcad4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java
@@ -33,7 +33,7 @@ import android.widget.TextView;
import androidx.test.filters.SmallTest;
-import com.android.keyguard.CarrierTextController;
+import com.android.keyguard.CarrierTextManager;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.utils.leaks.LeakCheckedTest;
@@ -54,7 +54,7 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
private QSCarrierGroupController mQSCarrierGroupController;
private NetworkController.SignalCallback mSignalCallback;
- private CarrierTextController.CarrierTextCallback mCallback;
+ private CarrierTextManager.CarrierTextCallback mCallback;
@Mock
private QSCarrierGroup mQSCarrierGroup;
@Mock
@@ -62,9 +62,9 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
@Mock
private NetworkController mNetworkController;
@Mock
- private CarrierTextController.Builder mCarrierTextControllerBuilder;
+ private CarrierTextManager.Builder mCarrierTextControllerBuilder;
@Mock
- private CarrierTextController mCarrierTextController;
+ private CarrierTextManager mCarrierTextManager;
private TestableLooper mTestableLooper;
@Before
@@ -83,11 +83,11 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
.thenReturn(mCarrierTextControllerBuilder);
when(mCarrierTextControllerBuilder.setShowMissingSim(anyBoolean()))
.thenReturn(mCarrierTextControllerBuilder);
- when(mCarrierTextControllerBuilder.build()).thenReturn(mCarrierTextController);
+ when(mCarrierTextControllerBuilder.build()).thenReturn(mCarrierTextManager);
doAnswer(invocation -> mCallback = invocation.getArgument(0))
- .when(mCarrierTextController)
- .setListening(any(CarrierTextController.CarrierTextCallback.class));
+ .when(mCarrierTextManager)
+ .setListening(any(CarrierTextManager.CarrierTextCallback.class));
when(mQSCarrierGroup.getNoSimTextView()).thenReturn(new TextView(mContext));
when(mQSCarrierGroup.getCarrier1View()).thenReturn(mock(QSCarrier.class));
@@ -113,8 +113,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
(Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0));
// listOfCarriers length 1, subscriptionIds length 1, anySims false
- CarrierTextController.CarrierTextCallbackInfo
- c1 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c1 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{""},
false,
@@ -122,8 +122,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
mCallback.updateCarrierInfo(c1);
// listOfCarriers length 1, subscriptionIds length 1, anySims true
- CarrierTextController.CarrierTextCallbackInfo
- c2 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c2 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{""},
true,
@@ -131,8 +131,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
mCallback.updateCarrierInfo(c2);
// listOfCarriers length 2, subscriptionIds length 2, anySims false
- CarrierTextController.CarrierTextCallbackInfo
- c3 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c3 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{"", ""},
false,
@@ -140,8 +140,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
mCallback.updateCarrierInfo(c3);
// listOfCarriers length 2, subscriptionIds length 2, anySims true
- CarrierTextController.CarrierTextCallbackInfo
- c4 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c4 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{"", ""},
true,
@@ -159,8 +159,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
(Answer<Integer>) invocationOnMock -> invocationOnMock.getArgument(0));
// listOfCarriers length 2, subscriptionIds length 1, anySims false
- CarrierTextController.CarrierTextCallbackInfo
- c1 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c1 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{"", ""},
false,
@@ -168,8 +168,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
mCallback.updateCarrierInfo(c1);
// listOfCarriers length 2, subscriptionIds length 1, anySims true
- CarrierTextController.CarrierTextCallbackInfo
- c2 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c2 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{"", ""},
true,
@@ -177,8 +177,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
mCallback.updateCarrierInfo(c2);
// listOfCarriers length 1, subscriptionIds length 2, anySims false
- CarrierTextController.CarrierTextCallbackInfo
- c3 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c3 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{""},
false,
@@ -186,8 +186,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
mCallback.updateCarrierInfo(c3);
// listOfCarriers length 1, subscriptionIds length 2, anySims true
- CarrierTextController.CarrierTextCallbackInfo
- c4 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c4 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{""},
true,
@@ -203,8 +203,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
when(spiedCarrierGroupController.getSlotIndex(anyInt())).thenReturn(
SubscriptionManager.INVALID_SIM_SLOT_INDEX);
- CarrierTextController.CarrierTextCallbackInfo
- c4 = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ c4 = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{"", ""},
true,
@@ -223,8 +223,8 @@ public class QSCarrierGroupControllerTest extends LeakCheckedTest {
@Test
public void testNoEmptyVisibleView_airplaneMode() {
- CarrierTextController.CarrierTextCallbackInfo
- info = new CarrierTextController.CarrierTextCallbackInfo(
+ CarrierTextManager.CarrierTextCallbackInfo
+ info = new CarrierTextManager.CarrierTextCallbackInfo(
"",
new CharSequence[]{""},
true,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt
index b7b967866d47..d3dbe2bf7d2b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt
@@ -25,6 +25,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.test.filters.SmallTest
import com.android.internal.logging.MetricsLogger
import com.android.internal.logging.UiEventLogger
+import com.android.internal.widget.LockPatternUtils
import com.android.systemui.SysuiTestCase
import com.android.systemui.controls.ControlsServiceInfo
import com.android.systemui.controls.controller.ControlsController
@@ -36,15 +37,19 @@ import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.qs.QSHost
import com.android.systemui.qs.logging.QSLogger
+import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.FeatureFlags
+import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.settings.FakeSettings
import com.android.systemui.util.settings.GlobalSettings
+import com.android.systemui.util.settings.SecureSettings
import com.google.common.truth.Truth.assertThat
import org.junit.Before
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
@@ -91,6 +96,15 @@ class DeviceControlsTileTest : SysuiTestCase() {
private lateinit var testableLooper: TestableLooper
private lateinit var tile: DeviceControlsTile
+ @Mock
+ private lateinit var keyguardStateController: KeyguardStateController
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private lateinit var userTracker: UserTracker
+ @Mock
+ private lateinit var lockPatternUtils: LockPatternUtils
+ @Mock
+ private lateinit var secureSettings: SecureSettings
+
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
@@ -101,9 +115,14 @@ class DeviceControlsTileTest : SysuiTestCase() {
controlsComponent = ControlsComponent(
true,
+ mContext,
{ controlsController },
{ controlsUiController },
- { controlsListingController }
+ { controlsListingController },
+ lockPatternUtils,
+ keyguardStateController,
+ userTracker,
+ secureSettings
)
globalSettings = FakeSettings()
@@ -111,16 +130,20 @@ class DeviceControlsTileTest : SysuiTestCase() {
globalSettings.putInt(DeviceControlsTile.SETTINGS_FLAG, 1)
`when`(featureFlags.isKeyguardLayoutEnabled).thenReturn(true)
+ `when`(userTracker.userHandle.identifier).thenReturn(0)
+
tile = createTile()
}
@Test
fun testAvailable() {
+ `when`(controlsController.available).thenReturn(true)
assertThat(tile.isAvailable).isTrue()
}
@Test
fun testNotAvailableFeature() {
+ `when`(controlsController.available).thenReturn(true)
`when`(featureFlags.isKeyguardLayoutEnabled).thenReturn(false)
assertThat(tile.isAvailable).isFalse()
@@ -130,9 +153,14 @@ class DeviceControlsTileTest : SysuiTestCase() {
fun testNotAvailableControls() {
controlsComponent = ControlsComponent(
false,
+ mContext,
{ controlsController },
{ controlsUiController },
- { controlsListingController }
+ { controlsListingController },
+ lockPatternUtils,
+ keyguardStateController,
+ userTracker,
+ secureSettings
)
tile = createTile()
@@ -264,4 +292,4 @@ class DeviceControlsTileTest : SysuiTestCase() {
globalSettings
)
}
-} \ No newline at end of file
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java
index fa253e62ef0a..421c6f4aab0b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java
@@ -18,6 +18,8 @@ package com.android.systemui.statusbar.phone;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
@@ -35,6 +37,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.doze.AlwaysOnDisplayPolicy;
import com.android.systemui.doze.DozeScreenState;
+import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;
@@ -57,6 +60,7 @@ public class DozeParametersTest extends SysuiTestCase {
@Mock private PowerManager mPowerManager;
@Mock private TunerService mTunerService;
@Mock private BatteryController mBatteryController;
+ @Mock private FeatureFlags mFeatureFlags;
@Before
public void setup() {
@@ -67,7 +71,8 @@ public class DozeParametersTest extends SysuiTestCase {
mAlwaysOnDisplayPolicy,
mPowerManager,
mBatteryController,
- mTunerService
+ mTunerService,
+ mFeatureFlags
);
}
@Test
@@ -111,4 +116,37 @@ public class DozeParametersTest extends SysuiTestCase {
assertThat(mDozeParameters.getAlwaysOn()).isFalse();
}
+
+ @Test
+ public void testControlUnlockedScreenOffAnimation_dozeAfterScreenOff_false() {
+ when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
+ mDozeParameters.onTuningChanged(Settings.Secure.DOZE_ALWAYS_ON, "1");
+ when(mFeatureFlags.useNewLockscreenAnimations()).thenReturn(true);
+
+ assertTrue(mDozeParameters.shouldControlUnlockedScreenOff());
+
+ // Trigger the setter for the current value.
+ mDozeParameters.setControlScreenOffAnimation(mDozeParameters.shouldControlScreenOff());
+
+ // We should have asked power manager not to doze after screen off no matter what, since
+ // we're animating and controlling screen off.
+ verify(mPowerManager).setDozeAfterScreenOff(eq(false));
+ }
+
+ @Test
+ public void testControlUnlockedScreenOffAnimationDisabled_dozeAfterScreenOff() {
+ when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
+ mDozeParameters.onTuningChanged(Settings.Secure.DOZE_ALWAYS_ON, "1");
+ when(mFeatureFlags.useNewLockscreenAnimations()).thenReturn(false);
+
+ assertFalse(mDozeParameters.shouldControlUnlockedScreenOff());
+
+ // Trigger the setter for the current value.
+ mDozeParameters.setControlScreenOffAnimation(mDozeParameters.shouldControlScreenOff());
+
+ // We should have asked power manager to doze only if we're not controlling screen off
+ // normally.
+ verify(mPowerManager).setDozeAfterScreenOff(
+ eq(!mDozeParameters.shouldControlScreenOff()));
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
index 3f5a6992fcef..d69d2dbdd841 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
@@ -48,6 +48,8 @@ import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
+import androidx.constraintlayout.widget.ConstraintLayout;
+import androidx.constraintlayout.widget.ConstraintSet;
import androidx.test.filters.SmallTest;
import com.android.internal.logging.MetricsLogger;
@@ -59,6 +61,7 @@ import com.android.keyguard.KeyguardStatusView;
import com.android.keyguard.KeyguardStatusViewController;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.dagger.KeyguardQsUserSwitchComponent;
+import com.android.keyguard.dagger.KeyguardStatusBarViewComponent;
import com.android.keyguard.dagger.KeyguardStatusViewComponent;
import com.android.keyguard.dagger.KeyguardUserSwitcherComponent;
import com.android.systemui.R;
@@ -204,10 +207,16 @@ public class NotificationPanelViewTest extends SysuiTestCase {
@Mock
private KeyguardStatusViewComponent mKeyguardStatusViewComponent;
@Mock
+ private KeyguardStatusBarViewComponent.Factory mKeyguardStatusBarViewComponentFactory;
+ @Mock
+ private KeyguardStatusBarViewComponent mKeyguardStatusBarViewComponent;
+ @Mock
private KeyguardClockSwitchController mKeyguardClockSwitchController;
@Mock
private KeyguardStatusViewController mKeyguardStatusViewController;
@Mock
+ private KeyguardStatusBarViewController mKeyguardStatusBarViewController;
+ @Mock
private NotificationStackScrollLayoutController mNotificationStackScrollLayoutController;
@Mock
private AuthController mAuthController;
@@ -222,14 +231,13 @@ public class NotificationPanelViewTest extends SysuiTestCase {
@Mock
private BroadcastDispatcher mBroadcastDispatcher;
@Mock
- private NotificationsQuickSettingsContainer mNotificationContainerParent;
- @Mock
private AmbientState mAmbientState;
@Mock
private UserManager mUserManager;
private NotificationPanelViewController mNotificationPanelViewController;
private View.AccessibilityDelegate mAccessibiltyDelegate;
+ private NotificationsQuickSettingsContainer mNotificationContainerParent;
@Before
public void setup() {
@@ -262,6 +270,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
when(mView.findViewById(R.id.keyguard_status_view))
.thenReturn(mock(KeyguardStatusView.class));
when(mView.findViewById(R.id.keyguard_header)).thenReturn(mKeyguardStatusBar);
+ mNotificationContainerParent = new NotificationsQuickSettingsContainer(getContext(), null);
when(mView.findViewById(R.id.notification_container_parent))
.thenReturn(mNotificationContainerParent);
FlingAnimationUtils.Builder flingAnimationUtilsBuilder = new FlingAnimationUtils.Builder(
@@ -295,6 +304,10 @@ public class NotificationPanelViewTest extends SysuiTestCase {
new ViewGroup.LayoutParams(600, 400));
when(mNotificationStackScrollLayoutController.getLayoutParams()).thenReturn(
new ViewGroup.LayoutParams(600, 400));
+ when(mKeyguardStatusBarViewComponentFactory.build(any()))
+ .thenReturn(mKeyguardStatusBarViewComponent);
+ when(mKeyguardStatusBarViewComponent.getKeyguardStatusBarViewController())
+ .thenReturn(mKeyguardStatusBarViewController);
mNotificationPanelViewController = new NotificationPanelViewController(mView,
mResources,
@@ -313,6 +326,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
mKeyguardStatusViewComponentFactory,
mKeyguardQsUserSwitchComponentFactory,
mKeyguardUserSwitcherComponentFactory,
+ mKeyguardStatusBarViewComponentFactory,
mQSDetailDisplayer,
mGroupManager,
mNotificationAreaController,
@@ -440,16 +454,11 @@ public class NotificationPanelViewTest extends SysuiTestCase {
@Test
public void testAllChildrenOfNotificationContainer_haveIds() {
- when(mNotificationContainerParent.getChildCount()).thenReturn(2);
when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
- View view1 = new View(mContext);
- view1.setId(1);
- when(mNotificationContainerParent.getChildAt(0)).thenReturn(view1);
-
- View view2 = mock(View.class);
- when(mNotificationContainerParent.getChildAt(1)).thenReturn(view2);
+ mNotificationContainerParent.addView(newViewWithId(1));
+ mNotificationContainerParent.addView(newViewWithId(View.NO_ID));
mNotificationPanelViewController.updateResources();
@@ -457,6 +466,51 @@ public class NotificationPanelViewTest extends SysuiTestCase {
assertThat(mNotificationContainerParent.getChildAt(1).getId()).isNotEqualTo(View.NO_ID);
}
+ @Test
+ public void testSinglePaneShadeLayout_isAlignedToParent() {
+ when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(false);
+ mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame));
+ mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller));
+
+ mNotificationPanelViewController.updateResources();
+
+ ConstraintSet constraintSet = new ConstraintSet();
+ constraintSet.clone(mNotificationContainerParent);
+ ConstraintSet.Layout qsFrameLayout = constraintSet.getConstraint(R.id.qs_frame).layout;
+ ConstraintSet.Layout stackScrollerLayout = constraintSet.getConstraint(
+ R.id.notification_stack_scroller).layout;
+ assertThat(qsFrameLayout.endToEnd).isEqualTo(ConstraintSet.PARENT_ID);
+ assertThat(stackScrollerLayout.startToStart).isEqualTo(ConstraintSet.PARENT_ID);
+ }
+
+ @Test
+ public void testSplitShadeLayout_isAlignedToGuideline() {
+ when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
+ when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
+ mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame));
+ mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller));
+
+ mNotificationPanelViewController.updateResources();
+
+ ConstraintSet constraintSet = new ConstraintSet();
+ constraintSet.clone(mNotificationContainerParent);
+ ConstraintSet.Layout qsFrameLayout = constraintSet.getConstraint(R.id.qs_frame).layout;
+ ConstraintSet.Layout stackScrollerLayout = constraintSet.getConstraint(
+ R.id.notification_stack_scroller).layout;
+ assertThat(qsFrameLayout.endToEnd).isEqualTo(R.id.qs_edge_guideline);
+ assertThat(stackScrollerLayout.startToStart).isEqualTo(R.id.qs_edge_guideline);
+ }
+
+ private View newViewWithId(int id) {
+ View view = new View(mContext);
+ view.setId(id);
+ ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ // required as cloning ConstraintSet fails if view doesn't have layout params
+ view.setLayoutParams(layoutParams);
+ return view;
+ }
+
private void onTouchEvent(MotionEvent ev) {
mTouchHandler.onTouch(mView, ev);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index cae488a561a2..253460db0d07 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -97,6 +97,7 @@ import com.android.systemui.recents.ScreenPinningRequest;
import com.android.systemui.settings.brightness.BrightnessSlider;
import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.statusbar.CommandQueue;
+import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.KeyguardIndicationController;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
@@ -258,6 +259,7 @@ public class StatusBarTest extends SysuiTestCase {
@Mock private DemoModeController mDemoModeController;
@Mock private Lazy<NotificationShadeDepthController> mNotificationShadeDepthControllerLazy;
@Mock private BrightnessSlider.Factory mBrightnessSliderFactory;
+ @Mock private FeatureFlags mFeatureFlags;
private ShadeController mShadeController;
private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock());
private InitController mInitController = new InitController();
@@ -418,7 +420,8 @@ public class StatusBarTest extends SysuiTestCase {
mNotificationShadeDepthControllerLazy,
mStatusBarTouchableRegionManager,
mNotificationIconAreaController,
- mBrightnessSliderFactory);
+ mBrightnessSliderFactory,
+ mFeatureFlags);
when(mNotificationShadeWindowView.findViewById(R.id.lock_icon_container)).thenReturn(
mLockIconContainer);
diff --git a/services/Android.bp b/services/Android.bp
index 61591c2c29bd..315462838485 100644
--- a/services/Android.bp
+++ b/services/Android.bp
@@ -33,6 +33,7 @@ filegroup {
":services.startop.iorap-sources",
":services.systemcaptions-sources",
":services.translation-sources",
+ ":services.texttospeech-sources",
":services.usage-sources",
":services.usb-sources",
":services.voiceinteraction-sources",
@@ -83,6 +84,7 @@ java_library {
"services.startop",
"services.systemcaptions",
"services.translation",
+ "services.texttospeech",
"services.usage",
"services.usb",
"services.voiceinteraction",
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index eff410caa2d4..809304bb24ae 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -2624,12 +2624,26 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
info.minWidth = value != null ? value.data : 0;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
info.minHeight = value != null ? value.data : 0;
+
value = sa.peekValue(
com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
info.minResizeWidth = value != null ? value.data : info.minWidth;
value = sa.peekValue(
com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
info.minResizeHeight = value != null ? value.data : info.minHeight;
+
+ value = sa.peekValue(
+ com.android.internal.R.styleable.AppWidgetProviderInfo_maxResizeWidth);
+ info.maxResizeWidth = value != null ? value.data : 0;
+ value = sa.peekValue(
+ com.android.internal.R.styleable.AppWidgetProviderInfo_maxResizeHeight);
+ info.maxResizeHeight = value != null ? value.data : 0;
+
+ info.targetCellWidth = sa.getInt(
+ com.android.internal.R.styleable.AppWidgetProviderInfo_targetCellWidth, 0);
+ info.targetCellHeight = sa.getInt(
+ com.android.internal.R.styleable.AppWidgetProviderInfo_targetCellHeight, 0);
+
info.updatePeriodMillis = sa.getInt(
com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
info.initialLayout = sa.getResourceId(
diff --git a/services/core/Android.bp b/services/core/Android.bp
index 542a260a5130..0725bb277e51 100644
--- a/services/core/Android.bp
+++ b/services/core/Android.bp
@@ -127,10 +127,10 @@ java_library_static {
"android.hardware.health-V2.0-java",
"android.hardware.health-V2.1-java",
"android.hardware.light-V1-java",
- "android.hardware.tv.cec-V1.0-java",
+ "android.hardware.tv.cec-V1.1-java",
"android.hardware.weaver-V1.0-java",
- "android.hardware.biometrics.face-V1.1-java",
"android.hardware.biometrics.face-V1-java",
+ "android.hardware.biometrics.face-V1.0-java",
"android.hardware.biometrics.fingerprint-V2.3-java",
"android.hardware.biometrics.fingerprint-V1-java",
"android.hardware.oemlock-V1.0-java",
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 558fbc25d7df..154e1831ceee 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -3584,10 +3584,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
private void handleRegisterNetworkRequest(@NonNull final NetworkRequestInfo nri) {
- handleRegisterNetworkRequest(Collections.singletonList(nri));
+ handleRegisterNetworkRequests(Collections.singleton(nri));
}
- private void handleRegisterNetworkRequest(@NonNull final List<NetworkRequestInfo> nris) {
+ private void handleRegisterNetworkRequests(@NonNull final Set<NetworkRequestInfo> nris) {
ensureRunningOnConnectivityServiceThread();
for (final NetworkRequestInfo nri : nris) {
mNetworkRequestInfoLogs.log("REGISTER " + nri);
@@ -3718,7 +3718,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
private NetworkRequestInfo getNriForAppRequest(
NetworkRequest request, int callingUid, String requestedOperation) {
- final NetworkRequestInfo nri = mNetworkRequests.get(request);
+ // Looking up the app passed param request in mRequests isn't possible since it may return
+ // null for a request managed by a per-app default. Therefore use getNriForAppRequest() to
+ // do the lookup since that will also find per-app default managed requests.
+ final NetworkRequestInfo nri = getNriForAppRequest(request);
if (nri != null) {
if (Process.SYSTEM_UID != callingUid && Process.NETWORK_STACK_UID != callingUid
@@ -3767,8 +3770,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (nri == null) {
return;
}
- // handleReleaseNetworkRequest() paths don't apply to multilayer requests.
- ensureNotMultilayerRequest(nri, "handleReleaseNetworkRequest");
if (VDBG || (DBG && request.isRequest())) {
log("releasing " + request + " (release request)");
}
@@ -3780,7 +3781,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void handleRemoveNetworkRequest(@NonNull final NetworkRequestInfo nri) {
ensureRunningOnConnectivityServiceThread();
-
nri.unlinkDeathRecipient();
for (final NetworkRequest req : nri.mRequests) {
mNetworkRequests.remove(req);
@@ -3803,6 +3803,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
cancelNpiRequests(nri);
}
+ private void handleRemoveNetworkRequests(@NonNull final Set<NetworkRequestInfo> nris) {
+ for (final NetworkRequestInfo nri : nris) {
+ if (mDefaultRequest == nri) {
+ // Make sure we never remove the default request.
+ continue;
+ }
+ handleRemoveNetworkRequest(nri);
+ }
+ }
+
private void cancelNpiRequests(@NonNull final NetworkRequestInfo nri) {
for (final NetworkRequest req : nri.mRequests) {
cancelNpiRequest(req);
@@ -4973,12 +4983,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
- private void onUserAdded(int userId) {
- mPermissionMonitor.onUserAdded(userId);
+ private void onUserAdded(UserHandle user) {
+ mPermissionMonitor.onUserAdded(user);
}
- private void onUserRemoved(int userId) {
- mPermissionMonitor.onUserRemoved(userId);
+ private void onUserRemoved(UserHandle user) {
+ mPermissionMonitor.onUserRemoved(user);
}
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@@ -4986,15 +4996,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
public void onReceive(Context context, Intent intent) {
ensureRunningOnConnectivityServiceThread();
final String action = intent.getAction();
- final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
+ final UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
- // UserId should be filled for below intents, check the existence.
- if (userId == UserHandle.USER_NULL) return;
+ // User should be filled for below intents, check the existence.
+ if (user == null) {
+ Log.wtf(TAG, intent.getAction() + " broadcast without EXTRA_USER");
+ return;
+ }
if (Intent.ACTION_USER_ADDED.equals(action)) {
- onUserAdded(userId);
+ onUserAdded(user);
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
- onUserRemoved(userId);
+ onUserRemoved(user);
} else {
Log.wtf(TAG, "received unexpected intent: " + action);
}
@@ -5107,6 +5120,21 @@ public class ConnectivityService extends IConnectivityManager.Stub
final int mUid;
@Nullable
final String mCallingAttributionTag;
+ // In order to preserve the mapping of NetworkRequest-to-callback when apps register
+ // callbacks using a returned NetworkRequest, the original NetworkRequest needs to be
+ // maintained for keying off of. This is only a concern when the original nri
+ // mNetworkRequests changes which happens currently for apps that register callbacks to
+ // track the default network. In those cases, the nri is updated to have mNetworkRequests
+ // that match the per-app default nri that currently tracks the calling app's uid so that
+ // callbacks are fired at the appropriate time. When the callbacks fire,
+ // mNetworkRequestForCallback will be used so as to preserve the caller's mapping. When
+ // callbacks are updated to key off of an nri vs NetworkRequest, this stops being an issue.
+ // TODO b/177608132: make sure callbacks are indexed by NRIs and not NetworkRequest objects.
+ @NonNull
+ private final NetworkRequest mNetworkRequestForCallback;
+ NetworkRequest getNetworkRequestForCallback() {
+ return mNetworkRequestForCallback;
+ }
/**
* Get the list of UIDs this nri applies to.
@@ -5122,13 +5150,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
NetworkRequestInfo(@NonNull final NetworkRequest r, @Nullable final PendingIntent pi,
@Nullable String callingAttributionTag) {
- this(Collections.singletonList(r), pi, callingAttributionTag);
+ this(Collections.singletonList(r), r, pi, callingAttributionTag);
}
NetworkRequestInfo(@NonNull final List<NetworkRequest> r,
- @Nullable final PendingIntent pi, @Nullable String callingAttributionTag) {
+ @NonNull final NetworkRequest requestForCallback, @Nullable final PendingIntent pi,
+ @Nullable String callingAttributionTag) {
+ ensureAllNetworkRequestsHaveType(r);
mRequests = initializeRequests(r);
- ensureAllNetworkRequestsHaveType(mRequests);
+ mNetworkRequestForCallback = requestForCallback;
mPendingIntent = pi;
mMessenger = null;
mBinder = null;
@@ -5140,15 +5170,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
NetworkRequestInfo(@NonNull final NetworkRequest r, @Nullable final Messenger m,
@Nullable final IBinder binder, @Nullable String callingAttributionTag) {
- this(Collections.singletonList(r), m, binder, callingAttributionTag);
+ this(Collections.singletonList(r), r, m, binder, callingAttributionTag);
}
- NetworkRequestInfo(@NonNull final List<NetworkRequest> r, @Nullable final Messenger m,
+ NetworkRequestInfo(@NonNull final List<NetworkRequest> r,
+ @NonNull final NetworkRequest requestForCallback, @Nullable final Messenger m,
@Nullable final IBinder binder, @Nullable String callingAttributionTag) {
super();
+ ensureAllNetworkRequestsHaveType(r);
mRequests = initializeRequests(r);
+ mNetworkRequestForCallback = requestForCallback;
mMessenger = m;
- ensureAllNetworkRequestsHaveType(mRequests);
mBinder = binder;
mPid = getCallingPid();
mUid = mDeps.getCallingUid();
@@ -5163,12 +5195,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
+ NetworkRequestInfo(@NonNull final NetworkRequestInfo nri,
+ @NonNull final List<NetworkRequest> r) {
+ super();
+ ensureAllNetworkRequestsHaveType(r);
+ mRequests = initializeRequests(r);
+ mNetworkRequestForCallback = nri.getNetworkRequestForCallback();
+ mMessenger = nri.mMessenger;
+ mBinder = nri.mBinder;
+ mPid = nri.mPid;
+ mUid = nri.mUid;
+ mPendingIntent = nri.mPendingIntent;
+ mCallingAttributionTag = nri.mCallingAttributionTag;
+ }
+
NetworkRequestInfo(@NonNull final NetworkRequest r) {
this(Collections.singletonList(r));
}
NetworkRequestInfo(@NonNull final List<NetworkRequest> r) {
- this(r, null /* pi */, null /* callingAttributionTag */);
+ this(r, r.get(0), null /* pi */, null /* callingAttributionTag */);
}
// True if this NRI is being satisfied. It also accounts for if the nri has its satisifer
@@ -5327,7 +5373,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
// If the request type is TRACK_DEFAULT, the passed {@code networkCapabilities}
// is unused and will be replaced by ones appropriate for the caller.
// This allows callers to keep track of the default network for their app.
- networkCapabilities = createDefaultNetworkCapabilitiesForUid(callingUid);
+ networkCapabilities = copyDefaultNetworkCapabilitiesForUid(
+ defaultNc, callingUid, callingPackageName);
enforceAccessPermission();
break;
case TRACK_SYSTEM_DEFAULT:
@@ -5366,10 +5413,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
ensureValid(networkCapabilities);
- NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType,
+ final NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType,
nextNetworkRequestId(), reqType);
- NetworkRequestInfo nri =
- new NetworkRequestInfo(networkRequest, messenger, binder, callingAttributionTag);
+ final NetworkRequestInfo nri = getNriToRegister(
+ networkRequest, messenger, binder, callingAttributionTag);
if (DBG) log("requestNetwork for " + nri);
// For TRACK_SYSTEM_DEFAULT callbacks, the capabilities have been modified since they were
@@ -5391,6 +5438,30 @@ public class ConnectivityService extends IConnectivityManager.Stub
return networkRequest;
}
+ /**
+ * Return the nri to be used when registering a network request. Specifically, this is used with
+ * requests registered to track the default request. If there is currently a per-app default
+ * tracking the app requestor, then we need to create a version of this nri that mirrors that of
+ * the tracking per-app default so that callbacks are sent to the app requestor appropriately.
+ * @param nr the network request for the nri.
+ * @param msgr the messenger for the nri.
+ * @param binder the binder for the nri.
+ * @param callingAttributionTag the calling attribution tag for the nri.
+ * @return the nri to register.
+ */
+ private NetworkRequestInfo getNriToRegister(@NonNull final NetworkRequest nr,
+ @Nullable final Messenger msgr, @Nullable final IBinder binder,
+ @Nullable String callingAttributionTag) {
+ final List<NetworkRequest> requests;
+ if (NetworkRequest.Type.TRACK_DEFAULT == nr.type) {
+ requests = copyDefaultNetworkRequestsForUid(
+ nr.getRequestorUid(), nr.getRequestorPackageName());
+ } else {
+ requests = Collections.singletonList(nr);
+ }
+ return new NetworkRequestInfo(requests, nr, msgr, binder, callingAttributionTag);
+ }
+
private void enforceNetworkRequestPermissions(NetworkCapabilities networkCapabilities,
String callingPackageName, String callingAttributionTag) {
if (networkCapabilities.hasCapability(NET_CAPABILITY_NOT_RESTRICTED) == false) {
@@ -5684,6 +5755,102 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
/**
+ * Return the default network request currently tracking the given uid.
+ * @param uid the uid to check.
+ * @return the NetworkRequestInfo tracking the given uid.
+ */
+ @NonNull
+ private NetworkRequestInfo getDefaultRequestTrackingUid(@NonNull final int uid) {
+ for (final NetworkRequestInfo nri : mDefaultNetworkRequests) {
+ if (nri == mDefaultRequest) {
+ continue;
+ }
+ // Checking the first request is sufficient as only multilayer requests will have more
+ // than one request and for multilayer, all requests will track the same uids.
+ if (nri.mRequests.get(0).networkCapabilities.appliesToUid(uid)) {
+ return nri;
+ }
+ }
+ return mDefaultRequest;
+ }
+
+ /**
+ * Get a copy of the network requests of the default request that is currently tracking the
+ * given uid.
+ * @param requestorUid the uid to check the default for.
+ * @param requestorPackageName the requestor's package name.
+ * @return a copy of the default's NetworkRequest that is tracking the given uid.
+ */
+ @NonNull
+ private List<NetworkRequest> copyDefaultNetworkRequestsForUid(
+ @NonNull final int requestorUid, @NonNull final String requestorPackageName) {
+ return copyNetworkRequestsForUid(
+ getDefaultRequestTrackingUid(requestorUid).mRequests,
+ requestorUid, requestorPackageName);
+ }
+
+ /**
+ * Copy the given nri's NetworkRequest collection.
+ * @param requestsToCopy the NetworkRequest collection to be copied.
+ * @param requestorUid the uid to set on the copied collection.
+ * @param requestorPackageName the package name to set on the copied collection.
+ * @return the copied NetworkRequest collection.
+ */
+ @NonNull
+ private List<NetworkRequest> copyNetworkRequestsForUid(
+ @NonNull final List<NetworkRequest> requestsToCopy, @NonNull final int requestorUid,
+ @NonNull final String requestorPackageName) {
+ final List<NetworkRequest> requests = new ArrayList<>();
+ for (final NetworkRequest nr : requestsToCopy) {
+ requests.add(new NetworkRequest(copyDefaultNetworkCapabilitiesForUid(
+ nr.networkCapabilities, requestorUid, requestorPackageName),
+ nr.legacyType, nextNetworkRequestId(), nr.type));
+ }
+ return requests;
+ }
+
+ @NonNull
+ private NetworkCapabilities copyDefaultNetworkCapabilitiesForUid(
+ @NonNull final NetworkCapabilities netCapToCopy, @NonNull final int requestorUid,
+ @NonNull final String requestorPackageName) {
+ final NetworkCapabilities netCap = new NetworkCapabilities(netCapToCopy);
+ netCap.removeCapability(NET_CAPABILITY_NOT_VPN);
+ netCap.setSingleUid(requestorUid);
+ netCap.setUids(new ArraySet<>());
+ restrictRequestUidsForCallerAndSetRequestorInfo(
+ netCap, requestorUid, requestorPackageName);
+ return netCap;
+ }
+
+ /**
+ * Get the nri that is currently being tracked for callbacks by per-app defaults.
+ * @param nr the network request to check for equality against.
+ * @return the nri if one exists, null otherwise.
+ */
+ @Nullable
+ private NetworkRequestInfo getNriForAppRequest(@NonNull final NetworkRequest nr) {
+ for (final NetworkRequestInfo nri : mNetworkRequests.values()) {
+ if (nri.getNetworkRequestForCallback().equals(nr)) {
+ return nri;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Check if an nri is currently being managed by per-app default networking.
+ * @param nri the nri to check.
+ * @return true if this nri is currently being managed by per-app default networking.
+ */
+ private boolean isPerAppTrackedNri(@NonNull final NetworkRequestInfo nri) {
+ // nri.mRequests.get(0) is only different from the original request filed in
+ // nri.getNetworkRequestForCallback() if nri.mRequests was changed by per-app default
+ // functionality therefore if these two don't match, it means this particular nri is
+ // currently being managed by a per-app default.
+ return nri.getNetworkRequestForCallback() != nri.mRequests.get(0);
+ }
+
+ /**
* Determine if an nri is a managed default request that disallows default networking.
* @param nri the request to evaluate
* @return true if device-default networking is disallowed
@@ -6761,13 +6928,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
return;
}
Bundle bundle = new Bundle();
- // In the case of multi-layer NRIs, the first request is not necessarily the one that
- // is satisfied. This is vexing, but the ConnectivityManager code that receives this
- // callback is only using the request as a token to identify the callback, so it doesn't
- // matter too much at this point as long as the callback can be found.
// TODO b/177608132: make sure callbacks are indexed by NRIs and not NetworkRequest objects.
// TODO: check if defensive copies of data is needed.
- final NetworkRequest nrForCallback = new NetworkRequest(nri.mRequests.get(0));
+ final NetworkRequest nrForCallback = nri.getNetworkRequestForCallback();
putParcelable(bundle, nrForCallback);
Message msg = Message.obtain();
if (notificationType != ConnectivityManager.CALLBACK_UNAVAIL) {
@@ -8707,7 +8870,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (DBG) {
log("set OEM network preferences :" + preference.toString());
}
- final List<NetworkRequestInfo> nris =
+ final ArraySet<NetworkRequestInfo> nris =
new OemNetworkRequestFactory().createNrisFromOemNetworkPreferences(preference);
updateDefaultNetworksForOemNetworkPreference(nris);
mOemNetworkPreferences = preference;
@@ -8719,27 +8882,88 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
private void updateDefaultNetworksForOemNetworkPreference(
- @NonNull final List<NetworkRequestInfo> nris) {
+ @NonNull final Set<NetworkRequestInfo> nris) {
+ handleRemoveNetworkRequests(mDefaultNetworkRequests);
+ addPerAppDefaultNetworkRequests(nris);
+ }
+
+ private void addPerAppDefaultNetworkRequests(@NonNull final Set<NetworkRequestInfo> nris) {
ensureRunningOnConnectivityServiceThread();
- clearNonDefaultNetworkAgents();
- addDefaultNetworkRequests(nris);
+ mDefaultNetworkRequests.addAll(nris);
+ final ArraySet<NetworkRequestInfo> perAppCallbackRequestsToUpdate =
+ getPerAppCallbackRequestsToUpdate();
+ handleRemoveNetworkRequests(perAppCallbackRequestsToUpdate);
+ final ArraySet<NetworkRequestInfo> nrisToRegister = new ArraySet<>(nris);
+ nrisToRegister.addAll(
+ createPerAppCallbackRequestsToRegister(perAppCallbackRequestsToUpdate));
+ handleRegisterNetworkRequests(nrisToRegister);
}
- private void clearNonDefaultNetworkAgents() {
- // Copy mDefaultNetworkRequests to iterate and remove elements from it in
- // handleRemoveNetworkRequest() without getting a ConcurrentModificationException.
- final NetworkRequestInfo[] nris =
- mDefaultNetworkRequests.toArray(new NetworkRequestInfo[0]);
+ /**
+ * All current requests that are tracking the default network need to be assessed as to whether
+ * or not the current set of per-application default requests will be changing their default
+ * network. If so, those requests will need to be updated so that they will send callbacks for
+ * default network changes at the appropriate time. Additionally, those requests tracking the
+ * default that were previously updated by this flow will need to be reassessed.
+ * @return the nris which will need to be updated.
+ */
+ private ArraySet<NetworkRequestInfo> getPerAppCallbackRequestsToUpdate() {
+ final ArraySet<NetworkRequestInfo> defaultCallbackRequests = new ArraySet<>();
+ // Get the distinct nris to check since for multilayer requests, it is possible to have the
+ // same nri in the map's values for each of its NetworkRequest objects.
+ final ArraySet<NetworkRequestInfo> nris = new ArraySet<>(mNetworkRequests.values());
for (final NetworkRequestInfo nri : nris) {
- if (mDefaultRequest != nri) {
- handleRemoveNetworkRequest(nri);
+ // Include this nri if it is currently being tracked.
+ if (isPerAppTrackedNri(nri)) {
+ defaultCallbackRequests.add(nri);
+ continue;
+ }
+ // We only track callbacks for requests tracking the default.
+ if (NetworkRequest.Type.TRACK_DEFAULT != nri.mRequests.get(0).type) {
+ continue;
+ }
+ // Include this nri if it will be tracked by the new per-app default requests.
+ final boolean isNriGoingToBeTracked =
+ getDefaultRequestTrackingUid(nri.mUid) != mDefaultRequest;
+ if (isNriGoingToBeTracked) {
+ defaultCallbackRequests.add(nri);
}
}
+ return defaultCallbackRequests;
}
- private void addDefaultNetworkRequests(@NonNull final List<NetworkRequestInfo> nris) {
- mDefaultNetworkRequests.addAll(nris);
- handleRegisterNetworkRequest(nris);
+ /**
+ * Create nris for those network requests that are currently tracking the default network that
+ * are being controlled by a per-application default.
+ * @param perAppCallbackRequestsForUpdate the baseline network requests to be used as the
+ * foundation when creating the nri. Important items include the calling uid's original
+ * NetworkRequest to be used when mapping callbacks as well as the caller's uid and name. These
+ * requests are assumed to have already been validated as needing to be updated.
+ * @return the Set of nris to use when registering network requests.
+ */
+ private ArraySet<NetworkRequestInfo> createPerAppCallbackRequestsToRegister(
+ @NonNull final ArraySet<NetworkRequestInfo> perAppCallbackRequestsForUpdate) {
+ final ArraySet<NetworkRequestInfo> callbackRequestsToRegister = new ArraySet<>();
+ for (final NetworkRequestInfo callbackRequest : perAppCallbackRequestsForUpdate) {
+ final NetworkRequestInfo trackingNri =
+ getDefaultRequestTrackingUid(callbackRequest.mUid);
+
+ // If this nri is not being tracked, the change it back to an untracked nri.
+ if (trackingNri == mDefaultRequest) {
+ callbackRequestsToRegister.add(new NetworkRequestInfo(
+ callbackRequest,
+ Collections.singletonList(callbackRequest.getNetworkRequestForCallback())));
+ continue;
+ }
+
+ final String requestorPackageName =
+ callbackRequest.mRequests.get(0).getRequestorPackageName();
+ callbackRequestsToRegister.add(new NetworkRequestInfo(
+ callbackRequest,
+ copyNetworkRequestsForUid(
+ trackingNri.mRequests, callbackRequest.mUid, requestorPackageName)));
+ }
+ return callbackRequestsToRegister;
}
/**
@@ -8747,9 +8971,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/
@VisibleForTesting
final class OemNetworkRequestFactory {
- List<NetworkRequestInfo> createNrisFromOemNetworkPreferences(
+ ArraySet<NetworkRequestInfo> createNrisFromOemNetworkPreferences(
@NonNull final OemNetworkPreferences preference) {
- final List<NetworkRequestInfo> nris = new ArrayList<>();
+ final ArraySet<NetworkRequestInfo> nris = new ArraySet<>();
final SparseArray<Set<Integer>> uids =
createUidsFromOemNetworkPreferences(preference);
for (int i = 0; i < uids.size(); i++) {
diff --git a/services/core/java/com/android/server/SensorPrivacyService.java b/services/core/java/com/android/server/SensorPrivacyService.java
index 0aee78050929..edaf6a90bd4a 100644
--- a/services/core/java/com/android/server/SensorPrivacyService.java
+++ b/services/core/java/com/android/server/SensorPrivacyService.java
@@ -105,8 +105,6 @@ public final class SensorPrivacyService extends SystemService {
private static final String TAG = "SensorPrivacyService";
- private static final int SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS = 2000;
-
/** Version number indicating compatibility parsing the persisted file */
private static final int CURRENT_PERSISTENCE_VERSION = 1;
/** Version number indicating the persisted data needs upgraded to match new internal data
@@ -568,7 +566,7 @@ public final class SensorPrivacyService extends SystemService {
// User may no longer exist or isn't set
continue;
}
- int sensor = parser.getAttributeIndex(null, XML_ATTRIBUTE_SENSOR);
+ int sensor = parser.getAttributeInt(null, XML_ATTRIBUTE_SENSOR);
boolean isEnabled = parser.getAttributeBoolean(null,
XML_ATTRIBUTE_ENABLED);
SparseBooleanArray userIndividualEnabled = individualEnabled.get(
@@ -756,10 +754,7 @@ public final class SensorPrivacyService extends SystemService {
suppressPackageReminderTokens.add(token);
} else {
- mHandler.postDelayed(PooledLambda.obtainRunnable(
- SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
- this, key, token),
- SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS);
+ mHandler.removeSuppressPackageReminderToken(key, token);
}
}
}
@@ -1110,6 +1105,13 @@ public final class SensorPrivacyService extends SystemService {
}
listeners.finishBroadcast();
}
+
+ public void removeSuppressPackageReminderToken(Pair<String, UserHandle> key,
+ IBinder token) {
+ sendMessage(PooledLambda.obtainMessage(
+ SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
+ mSensorPrivacyServiceImpl, key, token));
+ }
}
private final class DeathRecipient implements IBinder.DeathRecipient {
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 26fede1eb950..0b1c1154ba75 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -186,6 +186,7 @@ import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentCaptureOptions;
+import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IIntentReceiver;
@@ -5626,6 +5627,23 @@ public class ActivityManagerService extends IActivityManager.Stub
? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED;
}
+ @Override
+ public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid,
+ final int modeFlags, IBinder callerToken) {
+ final int size = uris.size();
+ int[] res = new int[size];
+ // Default value DENIED.
+ Arrays.fill(res, PackageManager.PERMISSION_DENIED);
+
+ for (int i = 0; i < size; i++) {
+ final Uri uri = uris.get(i);
+ final int userId = ContentProvider.getUserIdFromUri(uri, mContext.getUserId());
+ res[i] = checkUriPermission(ContentProvider.getUriWithoutUserId(uri), pid, uid,
+ modeFlags, userId, callerToken);
+ }
+ return res;
+ }
+
/**
* @param uri This uri must NOT contain an embedded userId.
* @param userId The userId in which the uri is to be resolved.
diff --git a/services/core/java/com/android/server/app/GameManagerService.java b/services/core/java/com/android/server/app/GameManagerService.java
index 76c34678d589..26ce0d77e0af 100644
--- a/services/core/java/com/android/server/app/GameManagerService.java
+++ b/services/core/java/com/android/server/app/GameManagerService.java
@@ -61,7 +61,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
private final Object mLock = new Object();
private final Handler mHandler;
@GuardedBy("mLock")
- private final ArrayMap<Integer, Settings> mSettings = new ArrayMap<>();
+ private final ArrayMap<Integer, GameManagerSettings> mSettings = new ArrayMap<>();
public GameManagerService(Context context) {
this(context, createServiceThread().getLooper());
@@ -99,7 +99,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
synchronized (mLock) {
removeMessages(WRITE_SETTINGS, msg.obj);
if (mSettings.containsKey(userId)) {
- Settings userSettings = mSettings.get(userId);
+ GameManagerSettings userSettings = mSettings.get(userId);
userSettings.writePersistentDataLocked();
}
}
@@ -123,7 +123,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
removeMessages(WRITE_SETTINGS, msg.obj);
removeMessages(REMOVE_SETTINGS, msg.obj);
if (mSettings.containsKey(userId)) {
- final Settings userSettings = mSettings.get(userId);
+ final GameManagerSettings userSettings = mSettings.get(userId);
mSettings.remove(userId);
userSettings.writePersistentDataLocked();
}
@@ -190,7 +190,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
if (!mSettings.containsKey(userId)) {
return GameManager.GAME_MODE_UNSUPPORTED;
}
- Settings userSettings = mSettings.get(userId);
+ GameManagerSettings userSettings = mSettings.get(userId);
return userSettings.getGameModeLocked(packageName);
}
}
@@ -211,7 +211,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
if (!mSettings.containsKey(userId)) {
return;
}
- Settings userSettings = mSettings.get(userId);
+ GameManagerSettings userSettings = mSettings.get(userId);
userSettings.setGameModeLocked(packageName, gameMode);
final Message msg = mHandler.obtainMessage(WRITE_SETTINGS);
msg.obj = userId;
@@ -235,7 +235,8 @@ public final class GameManagerService extends IGameManagerService.Stub {
return;
}
- Settings userSettings = new Settings(Environment.getDataSystemDeDirectory(userId));
+ GameManagerSettings userSettings =
+ new GameManagerSettings(Environment.getDataSystemDeDirectory(userId));
mSettings.put(userId, userSettings);
userSettings.readPersistentDataLocked();
}
diff --git a/services/core/java/com/android/server/app/Settings.java b/services/core/java/com/android/server/app/GameManagerSettings.java
index ab367fb923ac..3e32380b60a9 100644
--- a/services/core/java/com/android/server/app/Settings.java
+++ b/services/core/java/com/android/server/app/GameManagerSettings.java
@@ -41,7 +41,7 @@ import java.util.Map;
* Persists all GameService related settings.
* @hide
*/
-public class Settings {
+public class GameManagerSettings {
// The XML file follows the below format:
// <?xml>
@@ -63,7 +63,7 @@ public class Settings {
// PackageName -> GameMode
private final ArrayMap<String, Integer> mGameModes = new ArrayMap<>();
- Settings(File dataDir) {
+ GameManagerSettings(File dataDir) {
mSystemDir = new File(dataDir, "system");
mSystemDir.mkdirs();
FileUtils.setPermissions(mSystemDir.toString(),
@@ -144,6 +144,7 @@ public class Settings {
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG
&& type != XmlPullParser.END_DOCUMENT) {
+ // Do nothing
}
if (type != XmlPullParser.START_TAG) {
Slog.wtf(GameManagerService.TAG,
diff --git a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
index 68a084e6d249..8af1b5be1517 100644
--- a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
+++ b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
@@ -264,8 +264,8 @@ public final class PlaybackActivityMonitor
*/
public void playerEvent(int piid, int event, int deviceId, int binderUid) {
if (DEBUG) {
- Log.v(TAG, String.format("playerEvent(piid=%d, deviceId=%d, event=%d)",
- piid, deviceId, event));
+ Log.v(TAG, String.format("playerEvent(piid=%d, deviceId=%d, event=%s)",
+ piid, deviceId, AudioPlaybackConfiguration.playerStateToString(event)));
}
final boolean change;
synchronized(mPlayerLock) {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceAuthenticationClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceAuthenticationClient.java
index 0b78dd01f855..a4b3ac57a4df 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceAuthenticationClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceAuthenticationClient.java
@@ -46,7 +46,7 @@ import java.util.ArrayList;
/**
* Face-specific authentication client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
class FaceAuthenticationClient extends AuthenticationClient<IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceEnrollClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceEnrollClient.java
index 1a7544fc7f01..fc1200a4b42a 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceEnrollClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceEnrollClient.java
@@ -41,7 +41,7 @@ import java.util.Arrays;
/**
* Face-specific enroll client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
public class FaceEnrollClient extends EnrollClient<IBiometricsFace> {
@@ -103,18 +103,9 @@ public class FaceEnrollClient extends EnrollClient<IBiometricsFace> {
disabledFeatures.add(disabledFeature);
}
- android.hardware.biometrics.face.V1_1.IBiometricsFace daemon11 =
- android.hardware.biometrics.face.V1_1.IBiometricsFace.castFrom(getFreshDaemon());
try {
- final int status;
- if (daemon11 != null) {
- status = daemon11.enroll_1_1(token, mTimeoutSec, disabledFeatures, mSurfaceHandle);
- } else if (mSurfaceHandle == null) {
- status = getFreshDaemon().enroll(token, mTimeoutSec, disabledFeatures);
- } else {
- Slog.e(TAG, "enroll(): surface is only supported in @1.1 HAL");
- status = BiometricFaceConstants.FACE_ERROR_UNABLE_TO_PROCESS;
- }
+ final int status = getFreshDaemon().enroll(token, mTimeoutSec, disabledFeatures);
+
if (status != Status.OK) {
onError(BiometricFaceConstants.FACE_ERROR_UNABLE_TO_PROCESS, 0 /* vendorCode */);
mCallback.onClientFinished(this, false /* success */);
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGenerateChallengeClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGenerateChallengeClient.java
index c3d54c2b7fbb..72c5ee5e78c4 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGenerateChallengeClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGenerateChallengeClient.java
@@ -29,8 +29,7 @@ import com.android.server.biometrics.sensors.GenerateChallengeClient;
/**
* Face-specific generateChallenge client supporting the
- * {@link android.hardware.biometrics.face.V1_0} and {@link android.hardware.biometrics.face.V1_1}
- * HIDL interfaces.
+ * {@link android.hardware.biometrics.face.V1_0} HIDL interface.
*/
public class FaceGenerateChallengeClient extends GenerateChallengeClient<IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGetFeatureClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGetFeatureClient.java
index 722a3b843e12..b1083d410fec 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGetFeatureClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceGetFeatureClient.java
@@ -33,7 +33,7 @@ import com.android.server.biometrics.sensors.HalClientMonitor;
/**
* Face-specific getFeature client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
public class FaceGetFeatureClient extends HalClientMonitor<IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalCleanupClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalCleanupClient.java
index abfda499cf0f..1e3b92dcbf61 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalCleanupClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalCleanupClient.java
@@ -33,8 +33,7 @@ import java.util.Map;
/**
* Face-specific internal cleanup client supporting the
- * {@link android.hardware.biometrics.face.V1_0} and {@link android.hardware.biometrics.face.V1_1}
- * HIDL interfaces.
+ * {@link android.hardware.biometrics.face.V1_0} HIDL interface.
*/
class FaceInternalCleanupClient extends InternalCleanupClient<Face, IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalEnumerateClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalEnumerateClient.java
index 9a0974b472cb..f2a9afce1ff7 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalEnumerateClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceInternalEnumerateClient.java
@@ -32,8 +32,7 @@ import java.util.List;
/**
* Face-specific internal enumerate client supporting the
- * {@link android.hardware.biometrics.face.V1_0} and {@link android.hardware.biometrics.face.V1_1}
- * HIDL interfaces.
+ * {@link android.hardware.biometrics.face.V1_0} HIDL interface.
*/
class FaceInternalEnumerateClient extends InternalEnumerateClient<IBiometricsFace> {
private static final String TAG = "FaceInternalEnumerateClient";
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRemovalClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRemovalClient.java
index acae89928460..d63791c99dd4 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRemovalClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRemovalClient.java
@@ -33,7 +33,7 @@ import java.util.Map;
/**
* Face-specific removal client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
class FaceRemovalClient extends RemovalClient<Face, IBiometricsFace> {
private static final String TAG = "FaceRemovalClient";
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceResetLockoutClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceResetLockoutClient.java
index 14a46481ddc6..9d977d60e705 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceResetLockoutClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceResetLockoutClient.java
@@ -30,7 +30,7 @@ import java.util.ArrayList;
/**
* Face-specific resetLockout client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
public class FaceResetLockoutClient extends HalClientMonitor<IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRevokeChallengeClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRevokeChallengeClient.java
index e5edfafcef61..28580dece284 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRevokeChallengeClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceRevokeChallengeClient.java
@@ -27,7 +27,7 @@ import com.android.server.biometrics.sensors.RevokeChallengeClient;
/**
* Face-specific revokeChallenge client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
public class FaceRevokeChallengeClient extends RevokeChallengeClient<IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceSetFeatureClient.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceSetFeatureClient.java
index 6290e001f65b..cc3d8f0e28ba 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceSetFeatureClient.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/FaceSetFeatureClient.java
@@ -33,7 +33,7 @@ import java.util.ArrayList;
/**
* Face-specific setFeature client supporting the {@link android.hardware.biometrics.face.V1_0}
- * and {@link android.hardware.biometrics.face.V1_1} HIDL interfaces.
+ * HIDL interface.
*/
public class FaceSetFeatureClient extends HalClientMonitor<IBiometricsFace> {
diff --git a/services/core/java/com/android/server/biometrics/sensors/face/hidl/TestHal.java b/services/core/java/com/android/server/biometrics/sensors/face/hidl/TestHal.java
index 13bd1c27d8c8..4cdb68df70af 100644
--- a/services/core/java/com/android/server/biometrics/sensors/face/hidl/TestHal.java
+++ b/services/core/java/com/android/server/biometrics/sensors/face/hidl/TestHal.java
@@ -18,11 +18,11 @@ package com.android.server.biometrics.sensors.face.hidl;
import android.annotation.Nullable;
import android.hardware.biometrics.face.V1_0.FaceError;
+import android.hardware.biometrics.face.V1_0.IBiometricsFace;
import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback;
import android.hardware.biometrics.face.V1_0.OptionalBool;
import android.hardware.biometrics.face.V1_0.OptionalUint64;
import android.hardware.biometrics.face.V1_0.Status;
-import android.hardware.biometrics.face.V1_1.IBiometricsFace;
import android.os.NativeHandle;
import android.os.RemoteException;
import android.util.Slog;
@@ -129,15 +129,4 @@ public class TestHal extends IBiometricsFace.Stub {
return 0;
}
- @Override
- public int enrollRemotely(ArrayList<Byte> hat, int timeoutSec,
- ArrayList<Integer> disabledFeatures) {
- return 0;
- }
-
- @Override
- public int enroll_1_1(ArrayList<Byte> hat, int timeoutSec, ArrayList<Integer> disabledFeatures,
- NativeHandle nativeHandle) {
- return 0;
- }
}
diff --git a/services/core/java/com/android/server/connectivity/PermissionMonitor.java b/services/core/java/com/android/server/connectivity/PermissionMonitor.java
index 8d21f6f0f59f..8bf188696c27 100644
--- a/services/core/java/com/android/server/connectivity/PermissionMonitor.java
+++ b/services/core/java/com/android/server/connectivity/PermissionMonitor.java
@@ -83,9 +83,8 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
private final INetd mNetd;
private final Dependencies mDeps;
- // Values are User IDs.
@GuardedBy("this")
- private final Set<Integer> mUsers = new HashSet<>();
+ private final Set<UserHandle> mUsers = new HashSet<>();
// Keys are app uids. Values are true for SYSTEM permission and false for NETWORK permission.
@GuardedBy("this")
@@ -173,10 +172,7 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
netdPermsUids.put(uid, netdPermsUids.get(uid) | otherNetdPerms);
}
- final List<UserHandle> users = mUserManager.getUserHandles(true /* excludeDying */);
- for (UserHandle user : users) {
- mUsers.add(user.getIdentifier());
- }
+ mUsers.addAll(mUserManager.getUserHandles(true /* excludeDying */));
final SparseArray<ArraySet<String>> systemPermission =
SystemConfig.getInstance().getSystemPermissions();
@@ -259,16 +255,15 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
return array;
}
- private void update(Set<Integer> users, Map<Integer, Boolean> apps, boolean add) {
+ private void update(Set<UserHandle> users, Map<Integer, Boolean> apps, boolean add) {
List<Integer> network = new ArrayList<>();
List<Integer> system = new ArrayList<>();
for (Entry<Integer, Boolean> app : apps.entrySet()) {
List<Integer> list = app.getValue() ? system : network;
- for (int user : users) {
- final UserHandle handle = UserHandle.of(user);
- if (handle == null) continue;
+ for (UserHandle user : users) {
+ if (user == null) continue;
- list.add(UserHandle.getUid(handle, app.getKey()));
+ list.add(UserHandle.getUid(user, app.getKey()));
}
}
try {
@@ -291,14 +286,10 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
*
* @hide
*/
- public synchronized void onUserAdded(int user) {
- if (user < 0) {
- loge("Invalid user in onUserAdded: " + user);
- return;
- }
+ public synchronized void onUserAdded(@NonNull UserHandle user) {
mUsers.add(user);
- Set<Integer> users = new HashSet<>();
+ Set<UserHandle> users = new HashSet<>();
users.add(user);
update(users, mApps, true);
}
@@ -310,14 +301,10 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
*
* @hide
*/
- public synchronized void onUserRemoved(int user) {
- if (user < 0) {
- loge("Invalid user in onUserRemoved: " + user);
- return;
- }
+ public synchronized void onUserRemoved(@NonNull UserHandle user) {
mUsers.remove(user);
- Set<Integer> users = new HashSet<>();
+ Set<UserHandle> users = new HashSet<>();
users.add(user);
update(users, mApps, false);
}
diff --git a/services/core/java/com/android/server/graphics/fonts/FontManagerService.java b/services/core/java/com/android/server/graphics/fonts/FontManagerService.java
index 1b27572ad8de..09c0937802a5 100644
--- a/services/core/java/com/android/server/graphics/fonts/FontManagerService.java
+++ b/services/core/java/com/android/server/graphics/fonts/FontManagerService.java
@@ -72,11 +72,11 @@ public final class FontManagerService extends IFontManager.Stub {
}
@Override
- public int updateFont(int baseVersion, @NonNull FontUpdateRequest request) {
+ public int updateFontFile(@NonNull FontUpdateRequest request, int baseVersion) {
+ Preconditions.checkArgumentNonnegative(baseVersion);
Objects.requireNonNull(request);
Objects.requireNonNull(request.getFd());
Objects.requireNonNull(request.getSignature());
- Preconditions.checkArgumentNonnegative(baseVersion);
getContext().enforceCallingPermission(Manifest.permission.UPDATE_FONTS,
"UPDATE_FONTS permission required.");
try {
@@ -88,6 +88,21 @@ public final class FontManagerService extends IFontManager.Stub {
}
}
+ @Override
+ public int updateFontFamily(@NonNull List<FontUpdateRequest> requests, int baseVersion) {
+ Preconditions.checkArgumentNonnegative(baseVersion);
+ Objects.requireNonNull(requests);
+ getContext().enforceCallingPermission(Manifest.permission.UPDATE_FONTS,
+ "UPDATE_FONTS permission required.");
+ try {
+ update(baseVersion, requests);
+ return FontManager.RESULT_SUCCESS;
+ } catch (SystemFontException e) {
+ Slog.e(TAG, "Failed to update font family", e);
+ return e.getErrorCode();
+ }
+ }
+
/* package */ static class SystemFontException extends AndroidException {
private final int mErrorCode;
diff --git a/services/core/java/com/android/server/graphics/fonts/TEST_MAPPING b/services/core/java/com/android/server/graphics/fonts/TEST_MAPPING
new file mode 100644
index 000000000000..7fbf426c71c4
--- /dev/null
+++ b/services/core/java/com/android/server/graphics/fonts/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+ "presubmit": [
+ {
+ "name": "UpdatableSystemFontTest"
+ }
+ ]
+}
diff --git a/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java b/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java
index 45f2a38b6773..08ddc6ddf4ae 100644
--- a/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java
+++ b/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java
@@ -45,6 +45,7 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
/**
* Manages set of updatable font files.
@@ -182,8 +183,12 @@ final class UpdatableFontDir {
List<FontConfig.FontFamily> fontFamilies = config.fontFamilies;
for (int i = 0; i < fontFamilies.size(); i++) {
FontConfig.FontFamily fontFamily = fontFamilies.get(i);
- // Ignore failures as updated fonts may be obsoleted by system OTA update.
- addFontFamily(fontFamily);
+ try {
+ addFontFamily(fontFamily);
+ } catch (SystemFontException e) {
+ // Ignore failures as updated fonts may be obsoleted by system OTA update.
+ Slog.i(TAG, "Obsolete font family: " + fontFamily.getName());
+ }
}
success = true;
} catch (Throwable t) {
@@ -236,10 +241,7 @@ final class UpdatableFontDir {
request.getFd().getFileDescriptor(), request.getSignature());
break;
case FontUpdateRequest.TYPE_UPDATE_FONT_FAMILY:
- // TODO: define error code.
- if (!addFontFamily(request.getFontFamily())) {
- throw new IllegalArgumentException("Invalid font family");
- }
+ addFontFamily(request.getFontFamily());
break;
}
}
@@ -495,18 +497,15 @@ final class UpdatableFontDir {
* Unnamed font families are used as other named font family's fallback fonts to guarantee a
* complete glyph coverage.
*/
- private boolean addFontFamily(FontConfig.FontFamily fontFamily) {
- if (fontFamily.getName() == null) {
- Slog.e(TAG, "Name is null.");
- return false;
- }
+ private void addFontFamily(FontConfig.FontFamily fontFamily) throws SystemFontException {
+ Objects.requireNonNull(fontFamily.getName());
FontConfig.FontFamily resolvedFontFamily = resolveFontFiles(fontFamily);
if (resolvedFontFamily == null) {
- Slog.e(TAG, "Required fonts are not available");
- return false;
+ throw new SystemFontException(
+ FontManager.RESULT_ERROR_FONT_NOT_FOUND,
+ "Required fonts are not available");
}
mFontFamilyMap.put(resolvedFontFamily.getName(), resolvedFontFamily);
- return true;
}
@Nullable
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java
index 06bcada84ff9..1643ec162bc2 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecController.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java
@@ -50,6 +50,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
+import java.util.NoSuchElementException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.function.Predicate;
@@ -149,6 +150,12 @@ final class HdmiCecController {
* returns {@code null}.
*/
static HdmiCecController create(HdmiControlService service, HdmiCecAtomWriter atomWriter) {
+ HdmiCecController controller = createWithNativeWrapper(service, new NativeWrapperImpl11(),
+ atomWriter);
+ if (controller != null) {
+ return controller;
+ }
+ HdmiLogger.warning("Unable to use cec@1.1");
return createWithNativeWrapper(service, new NativeWrapperImpl(), atomWriter);
}
@@ -312,7 +319,7 @@ final class HdmiCecController {
}
/**
- * Return CEC version of the device.
+ * Return highest CEC version supported by this device.
*
* <p>Declared as package-private. accessed by {@link HdmiControlService} only.
*/
@@ -745,13 +752,202 @@ final class HdmiCecController {
boolean nativeIsConnected(int port);
}
- private static final class NativeWrapperImpl implements NativeWrapper,
+ private static final class NativeWrapperImpl11 implements NativeWrapper,
IHwBinder.DeathRecipient, getPhysicalAddressCallback {
- private IHdmiCec mHdmiCec;
+ private android.hardware.tv.cec.V1_1.IHdmiCec mHdmiCec;
+ @Nullable private HdmiCecCallback mCallback;
+
private final Object mLock = new Object();
private int mPhysicalAddress = INVALID_PHYSICAL_ADDRESS;
+
+ @Override
+ public String nativeInit() {
+ return (connectToHal() ? mHdmiCec.toString() : null);
+ }
+
+ boolean connectToHal() {
+ try {
+ mHdmiCec = android.hardware.tv.cec.V1_1.IHdmiCec.getService(true);
+ try {
+ mHdmiCec.linkToDeath(this, HDMI_CEC_HAL_DEATH_COOKIE);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Couldn't link to death : ", e);
+ }
+ } catch (RemoteException | NoSuchElementException e) {
+ HdmiLogger.error("Couldn't connect to cec@1.1", e);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void onValues(int result, short addr) {
+ if (result == Result.SUCCESS) {
+ synchronized (mLock) {
+ mPhysicalAddress = new Short(addr).intValue();
+ }
+ }
+ }
+
+ @Override
+ public void serviceDied(long cookie) {
+ if (cookie == HDMI_CEC_HAL_DEATH_COOKIE) {
+ HdmiLogger.error("Service died cookie : " + cookie + "; reconnecting");
+ connectToHal();
+ // Reconnect the callback
+ if (mCallback != null) {
+ setCallback(mCallback);
+ }
+ }
+ }
+
+ @Override
+ public void setCallback(HdmiCecCallback callback) {
+ mCallback = callback;
+ try {
+ mHdmiCec.setCallback_1_1(new HdmiCecCallback11(callback));
+ } catch (RemoteException e) {
+ HdmiLogger.error("Couldn't initialise tv.cec callback : ", e);
+ }
+ }
+
+ @Override
+ public int nativeSendCecCommand(int srcAddress, int dstAddress, byte[] body) {
+ android.hardware.tv.cec.V1_1.CecMessage message =
+ new android.hardware.tv.cec.V1_1.CecMessage();
+ message.initiator = srcAddress;
+ message.destination = dstAddress;
+ message.body = new ArrayList<>(body.length);
+ for (byte b : body) {
+ message.body.add(b);
+ }
+ try {
+ return mHdmiCec.sendMessage_1_1(message);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to send CEC message : ", e);
+ return SendMessageResult.FAIL;
+ }
+ }
+
+ @Override
+ public int nativeAddLogicalAddress(int logicalAddress) {
+ try {
+ return mHdmiCec.addLogicalAddress_1_1(logicalAddress);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to add a logical address : ", e);
+ return Result.FAILURE_INVALID_ARGS;
+ }
+ }
+
+ @Override
+ public void nativeClearLogicalAddress() {
+ try {
+ mHdmiCec.clearLogicalAddress();
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to clear logical address : ", e);
+ }
+ }
+
+ @Override
+ public int nativeGetPhysicalAddress() {
+ try {
+ mHdmiCec.getPhysicalAddress(this);
+ return mPhysicalAddress;
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to get physical address : ", e);
+ return INVALID_PHYSICAL_ADDRESS;
+ }
+ }
+
+ @Override
+ public int nativeGetVersion() {
+ try {
+ return mHdmiCec.getCecVersion();
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to get cec version : ", e);
+ return Result.FAILURE_UNKNOWN;
+ }
+ }
+
+ @Override
+ public int nativeGetVendorId() {
+ try {
+ return mHdmiCec.getVendorId();
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to get vendor id : ", e);
+ return Result.FAILURE_UNKNOWN;
+ }
+ }
+
+ @Override
+ public HdmiPortInfo[] nativeGetPortInfos() {
+ try {
+ ArrayList<android.hardware.tv.cec.V1_0.HdmiPortInfo> hdmiPortInfos =
+ mHdmiCec.getPortInfo();
+ HdmiPortInfo[] hdmiPortInfo = new HdmiPortInfo[hdmiPortInfos.size()];
+ int i = 0;
+ for (android.hardware.tv.cec.V1_0.HdmiPortInfo portInfo : hdmiPortInfos) {
+ hdmiPortInfo[i] = new HdmiPortInfo(portInfo.portId,
+ portInfo.type,
+ portInfo.physicalAddress,
+ portInfo.cecSupported,
+ false,
+ portInfo.arcSupported);
+ i++;
+ }
+ return hdmiPortInfo;
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to get port information : ", e);
+ return null;
+ }
+ }
+
+ @Override
+ public void nativeSetOption(int flag, boolean enabled) {
+ try {
+ mHdmiCec.setOption(flag, enabled);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to set option : ", e);
+ }
+ }
+
+ @Override
+ public void nativeSetLanguage(String language) {
+ try {
+ mHdmiCec.setLanguage(language);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to set language : ", e);
+ }
+ }
+
+ @Override
+ public void nativeEnableAudioReturnChannel(int port, boolean flag) {
+ try {
+ mHdmiCec.enableAudioReturnChannel(port, flag);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to enable/disable ARC : ", e);
+ }
+ }
+
+ @Override
+ public boolean nativeIsConnected(int port) {
+ try {
+ return mHdmiCec.isConnected(port);
+ } catch (RemoteException e) {
+ HdmiLogger.error("Failed to get connection info : ", e);
+ return false;
+ }
+ }
+ }
+
+ private static final class NativeWrapperImpl implements NativeWrapper,
+ IHwBinder.DeathRecipient, getPhysicalAddressCallback {
+ private android.hardware.tv.cec.V1_0.IHdmiCec mHdmiCec;
@Nullable private HdmiCecCallback mCallback;
+ private final Object mLock = new Object();
+ private int mPhysicalAddress = INVALID_PHYSICAL_ADDRESS;
+
@Override
public String nativeInit() {
return (connectToHal() ? mHdmiCec.toString() : null);
@@ -765,8 +961,8 @@ final class HdmiCecController {
} catch (RemoteException e) {
HdmiLogger.error("Couldn't link to death : ", e);
}
- } catch (RemoteException e) {
- HdmiLogger.error("Couldn't get tv.cec service : ", e);
+ } catch (RemoteException | NoSuchElementException e) {
+ HdmiLogger.error("Couldn't connect to cec@1.0", e);
return false;
}
return true;
@@ -776,7 +972,7 @@ final class HdmiCecController {
public void setCallback(@NonNull HdmiCecCallback callback) {
mCallback = callback;
try {
- mHdmiCec.setCallback(callback);
+ mHdmiCec.setCallback(new HdmiCecCallback10(callback));
} catch (RemoteException e) {
HdmiLogger.error("Couldn't initialise tv.cec callback : ", e);
}
@@ -931,20 +1127,69 @@ final class HdmiCecController {
}
}
- final class HdmiCecCallback extends IHdmiCecCallback.Stub {
+ final class HdmiCecCallback {
+ public void onCecMessage(int initiator, int destination, byte[] body) {
+ runOnServiceThread(
+ () -> handleIncomingCecCommand(initiator, destination, body));
+ }
+
+ public void onHotplugEvent(int portId, boolean connected) {
+ runOnServiceThread(() -> handleHotplug(portId, connected));
+ }
+ }
+
+ private static final class HdmiCecCallback10 extends IHdmiCecCallback.Stub {
+ private final HdmiCecCallback mHdmiCecCallback;
+
+ HdmiCecCallback10(HdmiCecCallback hdmiCecCallback) {
+ mHdmiCecCallback = hdmiCecCallback;
+ }
+
@Override
public void onCecMessage(CecMessage message) throws RemoteException {
byte[] body = new byte[message.body.size()];
for (int i = 0; i < message.body.size(); i++) {
body[i] = message.body.get(i);
}
- runOnServiceThread(
- () -> handleIncomingCecCommand(message.initiator, message.destination, body));
+ mHdmiCecCallback.onCecMessage(message.initiator, message.destination, body);
+ }
+
+ @Override
+ public void onHotplugEvent(HotplugEvent event) throws RemoteException {
+ mHdmiCecCallback.onHotplugEvent(event.portId, event.connected);
+ }
+ }
+
+ private static final class HdmiCecCallback11
+ extends android.hardware.tv.cec.V1_1.IHdmiCecCallback.Stub {
+ private final HdmiCecCallback mHdmiCecCallback;
+
+ HdmiCecCallback11(HdmiCecCallback hdmiCecCallback) {
+ mHdmiCecCallback = hdmiCecCallback;
+ }
+
+ @Override
+ public void onCecMessage_1_1(android.hardware.tv.cec.V1_1.CecMessage message)
+ throws RemoteException {
+ byte[] body = new byte[message.body.size()];
+ for (int i = 0; i < message.body.size(); i++) {
+ body[i] = message.body.get(i);
+ }
+ mHdmiCecCallback.onCecMessage(message.initiator, message.destination, body);
+ }
+
+ @Override
+ public void onCecMessage(CecMessage message) throws RemoteException {
+ byte[] body = new byte[message.body.size()];
+ for (int i = 0; i < message.body.size(); i++) {
+ body[i] = message.body.get(i);
+ }
+ mHdmiCecCallback.onCecMessage(message.initiator, message.destination, body);
}
@Override
public void onHotplugEvent(HotplugEvent event) throws RemoteException {
- runOnServiceThread(() -> handleHotplug(event.portId, event.connected));
+ mHdmiCecCallback.onHotplugEvent(event.portId, event.connected);
}
}
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java
index 04acd5187f77..2ed84811250e 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java
@@ -139,8 +139,12 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
@ServiceThreadOnly
void toggleAndFollowTvPower() {
assertRunOnServiceThread();
- // Wake up Android framework to take over CEC control from the microprocessor.
- mService.wakeUp();
+ if (mService.getPowerManager().isInteractive()) {
+ mService.pauseActiveMediaSessions();
+ } else {
+ // Wake up Android framework to take over CEC control from the microprocessor.
+ mService.wakeUp();
+ }
mService.queryDisplayStatus(new IHdmiControlCallback.Stub() {
@Override
public void onComplete(int status) {
diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
index c4c0f688bd67..bd577f35f0a5 100644
--- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
@@ -371,6 +371,9 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
int durationMs) {
Slog.i(mTag, "setTemporaryService(" + userId + ") to " + componentName + " for "
+ durationMs + "ms");
+ if (mServiceNameResolver == null) {
+ return;
+ }
enforceCallingPermissionForManagement();
Objects.requireNonNull(componentName);
@@ -404,6 +407,9 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
enforceCallingPermissionForManagement();
synchronized (mLock) {
+ if (mServiceNameResolver == null) {
+ return false;
+ }
final boolean changed = mServiceNameResolver.setDefaultServiceEnabled(userId, enabled);
if (!changed) {
if (verbose) {
@@ -434,6 +440,10 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
public final boolean isDefaultServiceEnabled(@UserIdInt int userId) {
enforceCallingPermissionForManagement();
+ if (mServiceNameResolver == null) {
+ return false;
+ }
+
synchronized (mLock) {
return mServiceNameResolver.isDefaultServiceEnabled(userId);
}
@@ -958,6 +968,10 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
public void onPackageModified(String packageName) {
if (verbose) Slog.v(mTag, "onPackageModified(): " + packageName);
+ if (mServiceNameResolver == null) {
+ return;
+ }
+
final int userId = getChangingUserId();
final String serviceName = mServiceNameResolver.getDefaultServiceName(userId);
if (serviceName == null) {
diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java
index 47cb43e2d4af..5eec315aa51c 100644
--- a/services/core/java/com/android/server/location/LocationManagerService.java
+++ b/services/core/java/com/android/server/location/LocationManagerService.java
@@ -78,6 +78,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.WorkSource;
import android.os.WorkSource.WorkChain;
+import android.provider.Settings;
import android.stats.location.LocationStatsEnums;
import android.util.ArrayMap;
import android.util.IndentingPrintWriter;
@@ -97,6 +98,8 @@ import com.android.server.location.gnss.hal.GnssNative;
import com.android.server.location.injector.AlarmHelper;
import com.android.server.location.injector.AppForegroundHelper;
import com.android.server.location.injector.AppOpsHelper;
+import com.android.server.location.injector.DeviceIdleHelper;
+import com.android.server.location.injector.DeviceStationaryHelper;
import com.android.server.location.injector.EmergencyHelper;
import com.android.server.location.injector.Injector;
import com.android.server.location.injector.LocationAttributionHelper;
@@ -108,6 +111,8 @@ import com.android.server.location.injector.SettingsHelper;
import com.android.server.location.injector.SystemAlarmHelper;
import com.android.server.location.injector.SystemAppForegroundHelper;
import com.android.server.location.injector.SystemAppOpsHelper;
+import com.android.server.location.injector.SystemDeviceIdleHelper;
+import com.android.server.location.injector.SystemDeviceStationaryHelper;
import com.android.server.location.injector.SystemEmergencyHelper;
import com.android.server.location.injector.SystemLocationPermissionsHelper;
import com.android.server.location.injector.SystemLocationPowerSaveModeHelper;
@@ -120,6 +125,7 @@ import com.android.server.location.provider.LocationProviderManager;
import com.android.server.location.provider.MockLocationProvider;
import com.android.server.location.provider.PassiveLocationProvider;
import com.android.server.location.provider.PassiveLocationProviderManager;
+import com.android.server.location.provider.StationaryThrottlingLocationProvider;
import com.android.server.location.provider.proxy.ProxyLocationProvider;
import com.android.server.pm.permission.LegacyPermissionManagerInternal;
@@ -313,6 +319,18 @@ public class LocationManagerService extends ILocationManager.Stub {
manager.startManager();
if (realProvider != null) {
+
+ // custom logic wrapping all non-passive providers
+ if (manager != mPassiveManager) {
+ boolean enableStationaryThrottling = Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.LOCATION_ENABLE_STATIONARY_THROTTLE, 1) != 0;
+ if (enableStationaryThrottling) {
+ realProvider = new StationaryThrottlingLocationProvider(manager.getName(),
+ mInjector, realProvider, mEventLog);
+ }
+ }
+
manager.setRealProvider(realProvider);
}
mProviderManagers.add(manager);
@@ -1368,6 +1386,8 @@ public class LocationManagerService extends ILocationManager.Stub {
private final SystemAppForegroundHelper mAppForegroundHelper;
private final SystemLocationPowerSaveModeHelper mLocationPowerSaveModeHelper;
private final SystemScreenInteractiveHelper mScreenInteractiveHelper;
+ private final SystemDeviceStationaryHelper mDeviceStationaryHelper;
+ private final SystemDeviceIdleHelper mDeviceIdleHelper;
private final LocationAttributionHelper mLocationAttributionHelper;
private final LocationUsageLogger mLocationUsageLogger;
@@ -1391,6 +1411,8 @@ public class LocationManagerService extends ILocationManager.Stub {
mAppForegroundHelper = new SystemAppForegroundHelper(context);
mLocationPowerSaveModeHelper = new SystemLocationPowerSaveModeHelper(context, eventLog);
mScreenInteractiveHelper = new SystemScreenInteractiveHelper(context);
+ mDeviceStationaryHelper = new SystemDeviceStationaryHelper();
+ mDeviceIdleHelper = new SystemDeviceIdleHelper(context);
mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper);
mLocationUsageLogger = new LocationUsageLogger();
}
@@ -1451,6 +1473,16 @@ public class LocationManagerService extends ILocationManager.Stub {
}
@Override
+ public DeviceStationaryHelper getDeviceStationaryHelper() {
+ return mDeviceStationaryHelper;
+ }
+
+ @Override
+ public DeviceIdleHelper getDeviceIdleHelper() {
+ return mDeviceIdleHelper;
+ }
+
+ @Override
public LocationAttributionHelper getLocationAttributionHelper() {
return mLocationAttributionHelper;
}
diff --git a/services/core/java/com/android/server/location/contexthub/AuthStateDenialTimer.java b/services/core/java/com/android/server/location/contexthub/AuthStateDenialTimer.java
new file mode 100644
index 000000000000..85de4bb1eefc
--- /dev/null
+++ b/services/core/java/com/android/server/location/contexthub/AuthStateDenialTimer.java
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+package com.android.server.location.contexthub;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.SystemClock;
+
+/**
+ * A class that manages a timer used to keep track of how much time is left before a
+ * {@link ContextHubClientBroker} has its authorization state changed with a nanoapp from
+ * DENIED_GRACE_PERIOD to DENIED. Much of this implementation is copied from
+ * {@link android.os.CountDownTimer} while adding the ability to specify the provided looper.
+ *
+ * @hide
+ */
+public class AuthStateDenialTimer {
+ private static final long TIMEOUT_MS = SECONDS.toMillis(60);
+
+ private final ContextHubClientBroker mClient;
+ private final long mNanoAppId;
+ private final Handler mHandler;
+
+ /**
+ * Indicates when the timer should stop in the future.
+ */
+ private long mStopTimeInFuture;
+
+ /**
+ * boolean representing if the timer was cancelled
+ */
+ private boolean mCancelled = false;
+
+ public AuthStateDenialTimer(ContextHubClientBroker client, long nanoAppId, Looper looper) {
+ mClient = client;
+ mNanoAppId = nanoAppId;
+ mHandler = new CountDownHandler(looper);
+ }
+
+ /**
+ * Cancel the countdown.
+ */
+ public synchronized void cancel() {
+ mCancelled = true;
+ mHandler.removeMessages(MSG);
+ }
+
+ /**
+ * Start the countdown.
+ */
+ public synchronized void start() {
+ mCancelled = false;
+ mStopTimeInFuture = SystemClock.elapsedRealtime() + TIMEOUT_MS;
+ mHandler.sendMessage(mHandler.obtainMessage(MSG));
+ }
+
+ /**
+ * Called when the timer has expired.
+ */
+ public void onFinish() {
+ mClient.handleAuthStateTimerExpiry(mNanoAppId);
+ }
+
+ // Message type used to trigger the timer.
+ private static final int MSG = 1;
+
+ private class CountDownHandler extends Handler {
+
+ CountDownHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ synchronized (AuthStateDenialTimer.this) {
+ if (mCancelled) {
+ return;
+ }
+ final long millisLeft = mStopTimeInFuture - SystemClock.elapsedRealtime();
+ if (millisLeft <= 0) {
+ onFinish();
+ } else {
+ sendMessageDelayed(obtainMessage(MSG), millisLeft);
+ }
+ }
+ }
+ };
+}
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java
index cc510fbc38bd..3d294de256ff 100644
--- a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java
@@ -17,31 +17,38 @@
package com.android.server.location.contexthub;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static android.hardware.location.ContextHubManager.AUTHORIZATION_DENIED;
+import static android.hardware.location.ContextHubManager.AUTHORIZATION_DENIED_GRACE_PERIOD;
+import static android.hardware.location.ContextHubManager.AUTHORIZATION_GRANTED;
import android.Manifest;
+import android.annotation.Nullable;
+import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.hardware.contexthub.V1_0.ContextHubMsg;
-import android.hardware.contexthub.V1_0.IContexthub;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubManager;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClientCallback;
+import android.hardware.location.IContextHubTransactionCallback;
import android.hardware.location.NanoAppMessage;
+import android.hardware.location.NanoAppState;
import android.os.Binder;
import android.os.IBinder;
+import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import com.android.server.location.ClientBrokerProto;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.Set;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
@@ -51,14 +58,53 @@ import java.util.function.Supplier;
* notification callbacks. This class implements the IContextHubClient object, and the implemented
* APIs must be thread-safe.
*
+ * Additionally, this class is responsible for enforcing permissions usage and attribution are
+ * handled appropriately for a given client. In general, this works as follows:
+ *
+ * Client sending a message to a nanoapp:
+ * 1) When initially sending a message to nanoapps, clients are by default in a grace period state
+ * which allows them to always send their first message to nanoapps. This is done to allow
+ * clients (especially callback clients) to reset their conection to the nanoapp if they are
+ * killed / restarted (e.g. following a permission revocation).
+ * 2) After the initial message is sent, a check of permissions state is performed. If the
+ * client doesn't have permissions to communicate, it is placed into the denied grace period
+ * state and notified so that it can clean up its communication before it is completely denied
+ * access.
+ * 3) For subsequent messages, the auth state is checked synchronously and messages are denied if
+ * the client is denied authorization
+ *
+ * Client receiving a message from a nanoapp:
+ * 1) If a nanoapp sends a message to the client, the authentication state is checked synchronously.
+ * If there has been no message between the two before, the auth state is assumed granted.
+ * 2) The broker then checks that the client has all permissions the nanoapp requires and attributes
+ * all permissions required to consume the message being sent. If both of those checks pass, then
+ * the message is delivered. Otherwise, it's dropped.
+ *
+ * Client losing or gaining permissions (callback client):
+ * 1) Clients are killed when they lose permissions. This will cause callback clients to completely
+ * disconnect from the service. When they are restarted, their initial message will still be
+ * be allowed through and their permissions will be rechecked at that time.
+ * 2) If they gain a permission, the broker will notify them if that permission allows them to
+ * communicate with a nanoapp again.
+ *
+ * Client losing or gaining permissions (PendingIntent client):
+ * 1) Unlike callback clients, PendingIntent clients are able to maintain their connection to the
+ * service when they are killed. In their case, they will receive notifications of the broker
+ * that they have been denied required permissions or gain required permissions.
+ *
* TODO: Consider refactoring this class via inheritance
*
* @hide
*/
public class ContextHubClientBroker extends IContextHubClient.Stub
- implements IBinder.DeathRecipient {
+ implements IBinder.DeathRecipient, AppOpsManager.OnOpChangedListener {
private static final String TAG = "ContextHubClientBroker";
+ /**
+ * Message used by noteOp when this client receives a message from a nanoapp.
+ */
+ private static final String RECEIVE_MSG_NOTE = "NanoappMessageDelivery ";
+
/*
* The context of the service.
*/
@@ -67,7 +113,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
/*
* The proxy to talk to the Context Hub HAL.
*/
- private final IContexthub mContextHubProxy;
+ private final IContextHubWrapper mContextHubProxy;
/*
* The manager that registered this client.
@@ -95,6 +141,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
*/
private boolean mRegistered = true;
+ /**
+ * String containing an attribution tag that was denoted in the {@link Context} of the
+ * creator of this broker. This is used when attributing the permissions usage of the broker.
+ */
+ private @Nullable String mAttributionTag;
+
/*
* Internal interface used to invoke client callbacks.
*/
@@ -112,6 +164,26 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
*/
private final String mPackage;
+ /**
+ * The PID associated with this client.
+ */
+ private final int mPid;
+
+ /**
+ * The UID associated with this client.
+ */
+ private final int mUid;
+
+ /**
+ * Manager used for noting permissions usage of this broker.
+ */
+ private final AppOpsManager mAppOpsManager;
+
+ /**
+ * Manager used to queue transactions to the context hub.
+ */
+ private final ContextHubTransactionManager mTransactionManager;
+
/*
* True if a PendingIntent has been cancelled.
*/
@@ -123,11 +195,44 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
private final boolean mHasAccessContextHubPermission;
/*
- * The set of nanoapp IDs that represent the group of nanoapps this client has a messaging
- * channel with, i.e. has sent or received messages from this particular nanoapp.
+ * Map containing all nanoapps this client has a messaging channel with and whether it is
+ * allowed to communicate over that channel. A channel is defined to have been opened if the
+ * client has sent or received messages from the particular nanoapp.
*/
- private final Set<Long> mMessageChannelNanoappIdSet =
- Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
+ private final Map<Long, Integer> mMessageChannelNanoappIdMap =
+ new ConcurrentHashMap<Long, Integer>();
+
+ /**
+ * Map containing all nanoapps that have active auth state denial timers.
+ */
+ private final Map<Long, AuthStateDenialTimer> mNappToAuthTimerMap =
+ new ConcurrentHashMap<Long, AuthStateDenialTimer>();
+
+ /**
+ * Callback used to obtain the latest set of nanoapp permissions and verify this client has
+ * each nanoapps permissions granted.
+ */
+ private final IContextHubTransactionCallback mQueryPermsCallback =
+ new IContextHubTransactionCallback.Stub() {
+ @Override
+ public void onTransactionComplete(int result) {
+ }
+
+ @Override
+ public void onQueryResponse(int result, List<NanoAppState> nanoAppStateList) {
+ if (result != ContextHubTransaction.RESULT_SUCCESS && nanoAppStateList != null) {
+ Log.e(TAG, "Permissions query failed, but still received nanoapp state");
+ } else if (nanoAppStateList != null) {
+ for (NanoAppState state : nanoAppStateList) {
+ if (mMessageChannelNanoappIdMap.containsKey(state.getNanoAppId())) {
+ List<String> permissions = state.getNanoAppPermissions();
+ updateNanoAppAuthState(state.getNanoAppId(),
+ hasPermissions(permissions), false /* gracePeriodExpired */);
+ }
+ }
+ }
+ }
+ };
/*
* Helper class to manage registered PendingIntent requests from the client.
@@ -175,37 +280,57 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
}
}
- /* package */ ContextHubClientBroker(
- Context context, IContexthub contextHubProxy, ContextHubClientManager clientManager,
- ContextHubInfo contextHubInfo, short hostEndPointId,
- IContextHubClientCallback callback) {
+ private ContextHubClientBroker(Context context, IContextHubWrapper contextHubProxy,
+ ContextHubClientManager clientManager, ContextHubInfo contextHubInfo,
+ short hostEndPointId, IContextHubClientCallback callback, String attributionTag,
+ ContextHubTransactionManager transactionManager, PendingIntent pendingIntent,
+ long nanoAppId, String packageName) {
mContext = context;
mContextHubProxy = contextHubProxy;
mClientManager = clientManager;
mAttachedContextHubInfo = contextHubInfo;
mHostEndPointId = hostEndPointId;
mCallbackInterface = callback;
- mPendingIntentRequest = new PendingIntentRequest();
- mPackage = mContext.getPackageManager().getNameForUid(Binder.getCallingUid());
+ if (pendingIntent == null) {
+ mPendingIntentRequest = new PendingIntentRequest();
+ } else {
+ mPendingIntentRequest = new PendingIntentRequest(pendingIntent, nanoAppId);
+ }
+ mPackage = packageName;
+ mAttributionTag = attributionTag;
+ mTransactionManager = transactionManager;
+ mPid = Binder.getCallingPid();
+ mUid = Binder.getCallingUid();
mHasAccessContextHubPermission = context.checkCallingPermission(
Manifest.permission.ACCESS_CONTEXT_HUB) == PERMISSION_GRANTED;
+ mAppOpsManager = context.getSystemService(AppOpsManager.class);
+
+ startMonitoringOpChanges();
}
/* package */ ContextHubClientBroker(
- Context context, IContexthub contextHubProxy, ContextHubClientManager clientManager,
- ContextHubInfo contextHubInfo, short hostEndPointId, PendingIntent pendingIntent,
- long nanoAppId) {
- mContext = context;
- mContextHubProxy = contextHubProxy;
- mClientManager = clientManager;
- mAttachedContextHubInfo = contextHubInfo;
- mHostEndPointId = hostEndPointId;
- mPendingIntentRequest = new PendingIntentRequest(pendingIntent, nanoAppId);
- mPackage = pendingIntent.getCreatorPackage();
+ Context context, IContextHubWrapper contextHubProxy,
+ ContextHubClientManager clientManager, ContextHubInfo contextHubInfo,
+ short hostEndPointId, IContextHubClientCallback callback, String attributionTag,
+ ContextHubTransactionManager transactionManager, String packageName) {
+ this(context, contextHubProxy, clientManager, contextHubInfo, hostEndPointId, callback,
+ attributionTag, transactionManager, null /* pendingIntent */, 0 /* nanoAppId */,
+ packageName);
+ }
- mHasAccessContextHubPermission = context.checkCallingPermission(
- Manifest.permission.ACCESS_CONTEXT_HUB) == PERMISSION_GRANTED;
+ /* package */ ContextHubClientBroker(
+ Context context, IContextHubWrapper contextHubProxy,
+ ContextHubClientManager clientManager, ContextHubInfo contextHubInfo,
+ short hostEndPointId, PendingIntent pendingIntent, long nanoAppId,
+ String attributionTag, ContextHubTransactionManager transactionManager) {
+ this(context, contextHubProxy, clientManager, contextHubInfo, hostEndPointId,
+ null /* callback */, attributionTag, transactionManager, pendingIntent, nanoAppId,
+ pendingIntent.getCreatorPackage());
+ }
+
+ private void startMonitoringOpChanges() {
+ mAppOpsManager.startWatchingMode(AppOpsManager.OP_NONE, mPackage, this);
}
/**
@@ -219,9 +344,38 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
public int sendMessageToNanoApp(NanoAppMessage message) {
ContextHubServiceUtil.checkPermissions(mContext);
+ int authState;
+ synchronized (mMessageChannelNanoappIdMap) {
+ // Default to the granted auth state. The true auth state will be checked async if it's
+ // not denied.
+ authState = mMessageChannelNanoappIdMap.getOrDefault(
+ message.getNanoAppId(), AUTHORIZATION_GRANTED);
+ if (authState == AUTHORIZATION_DENIED) {
+ return ContextHubTransaction.RESULT_FAILED_PERMISSION_DENIED;
+ }
+ }
+
int result;
if (isRegistered()) {
- mMessageChannelNanoappIdSet.add(message.getNanoAppId());
+ // Even though the auth state is currently not denied, query the nanoapp permissions
+ // async and verify that the host app currently holds all the requisite permissions.
+ // This can't be done synchronously due to the async query that needs to be performed to
+ // obtain the nanoapp permissions.
+ boolean initialNanoappMessage = false;
+ synchronized (mMessageChannelNanoappIdMap) {
+ if (mMessageChannelNanoappIdMap.get(message.getNanoAppId()) == null) {
+ mMessageChannelNanoappIdMap.put(message.getNanoAppId(), AUTHORIZATION_GRANTED);
+ initialNanoappMessage = true;
+ }
+ }
+
+ if (initialNanoappMessage) {
+ // Only check permissions the first time a nanoapp is queried since nanoapp
+ // permissions don't currently change at runtime. If the host permission changes
+ // later, that'll be checked by onOpChanged.
+ checkNanoappPermsAsync();
+ }
+
ContextHubMsg messageToNanoApp =
ContextHubServiceUtil.createHidlContextHubMessage(mHostEndPointId, message);
@@ -262,6 +416,30 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
onClientExit();
}
+ @Override
+ public void onOpChanged(String op, String packageName) {
+ if (packageName.equals(mPackage)) {
+ if (!mMessageChannelNanoappIdMap.isEmpty()) {
+ checkNanoappPermsAsync();
+ }
+ }
+ }
+
+ /**
+ * Used to override the attribution tag with a newer value if a PendingIntent broker is
+ * retrieved.
+ */
+ /* package */ void setAttributionTag(String attributionTag) {
+ mAttributionTag = attributionTag;
+ }
+
+ /**
+ * @return the attribution tag associated with this broker.
+ */
+ /* package */ String getAttributionTag() {
+ return mAttributionTag;
+ }
+
/**
* @return the ID of the context hub this client is attached to
*/
@@ -280,15 +458,39 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
* Sends a message to the client associated with this object.
*
* @param message the message that came from a nanoapp
- */
- /* package */ void sendMessageToClient(NanoAppMessage message) {
- mMessageChannelNanoappIdSet.add(message.getNanoAppId());
+ * @param nanoappPermissions permissions required to communicate with the nanoapp sending this
+ * message
+ * @param messagePermissions permissions required to consume the message being delivered. These
+ * permissions are what will be attributed to the client through noteOp.
+ */
+ /* package */ void sendMessageToClient(
+ NanoAppMessage message, List<String> nanoappPermissions,
+ List<String> messagePermissions) {
+ long nanoAppId = message.getNanoAppId();
+
+ int authState = mMessageChannelNanoappIdMap.getOrDefault(nanoAppId, AUTHORIZATION_GRANTED);
+
+ // If in the grace period, the host may not receive any messages containing permissions
+ // covered data.
+ if (authState == AUTHORIZATION_DENIED_GRACE_PERIOD && !messagePermissions.isEmpty()) {
+ Log.e(TAG, "Dropping message from " + Long.toHexString(nanoAppId) + ". " + mPackage
+ + " in grace period and napp msg has permissions");
+ return;
+ }
+
+ if (authState == AUTHORIZATION_DENIED || !hasPermissions(nanoappPermissions)
+ || !notePermissions(messagePermissions, RECEIVE_MSG_NOTE + nanoAppId)) {
+ Log.e(TAG, "Dropping message from " + Long.toHexString(nanoAppId) + ". " + mPackage
+ + " doesn't have permission");
+ return;
+ }
+
invokeCallback(callback -> callback.onMessageFromNanoApp(message));
Supplier<Intent> supplier =
- () -> createIntent(ContextHubManager.EVENT_NANOAPP_MESSAGE, message.getNanoAppId())
+ () -> createIntent(ContextHubManager.EVENT_NANOAPP_MESSAGE, nanoAppId)
.putExtra(ContextHubManager.EXTRA_MESSAGE, message);
- sendPendingIntent(supplier, message.getNanoAppId());
+ sendPendingIntent(supplier, nanoAppId);
}
/**
@@ -297,6 +499,10 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
* @param nanoAppId the ID of the nanoapp that was loaded.
*/
/* package */ void onNanoAppLoaded(long nanoAppId) {
+ // Check the latest state to see if the loaded nanoapp's permissions changed such that the
+ // host app can communicate with it again.
+ checkNanoappPermsAsync();
+
invokeCallback(callback -> callback.onNanoAppLoaded(nanoAppId));
sendPendingIntent(
() -> createIntent(ContextHubManager.EVENT_NANOAPP_LOADED, nanoAppId), nanoAppId);
@@ -364,6 +570,43 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
}
/**
+ * Checks that this client has all of the provided permissions.
+ *
+ * @param permissions list of permissions to check
+ * @return true if the client has all of the permissions granted
+ */
+ /* package */ boolean hasPermissions(List<String> permissions) {
+ for (String permission : permissions) {
+ if (mContext.checkPermission(permission, mPid, mUid) != PERMISSION_GRANTED) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Attributes the provided permissions to the package of this client.
+ *
+ * @param permissions list of permissions covering data the client is about to receive
+ * @param noteMessage message that should be noted alongside permissions attribution to
+ * facilitate debugging
+ * @return true if client has ability to use all of the provided permissions
+ */
+ /* package */ boolean notePermissions(List<String> permissions, String noteMessage) {
+ for (String permission : permissions) {
+ int opCode = mAppOpsManager.permissionToOpCode(permission);
+ if (opCode != AppOpsManager.OP_NONE) {
+ if (mAppOpsManager.noteOp(opCode, mUid, mPackage, mAttributionTag, noteMessage)
+ != AppOpsManager.MODE_ALLOWED) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
* @return true if the client is a PendingIntent client that has been cancelled.
*/
/* package */ boolean isPendingIntentCancelled() {
@@ -371,6 +614,92 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
}
/**
+ * Handles timer expiry for a client whose auth state with a nanoapp was previously in the grace
+ * period.
+ */
+ /* package */ void handleAuthStateTimerExpiry(long nanoAppId) {
+ AuthStateDenialTimer timer;
+ synchronized (mMessageChannelNanoappIdMap) {
+ timer = mNappToAuthTimerMap.remove(nanoAppId);
+ }
+
+ if (timer != null) {
+ updateNanoAppAuthState(
+ nanoAppId, false /* hasPermissions */, true /* gracePeriodExpired */);
+ }
+ }
+
+ /**
+ * Verifies this client has the permissions to communicate with all of the nanoapps it has
+ * communicated with in the past.
+ */
+ private void checkNanoappPermsAsync() {
+ ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction(
+ mAttachedContextHubInfo.getId(), mQueryPermsCallback, mPackage);
+ mTransactionManager.addTransaction(transaction);
+ }
+
+ /**
+ * Updates the latest authentication state for this client to be able to communicate with the
+ * given nanoapp.
+ */
+ private void updateNanoAppAuthState(
+ long nanoAppId, boolean hasPermissions, boolean gracePeriodExpired) {
+ int curAuthState;
+ int newAuthState;
+ synchronized (mMessageChannelNanoappIdMap) {
+ curAuthState = mMessageChannelNanoappIdMap.getOrDefault(
+ nanoAppId, AUTHORIZATION_GRANTED);
+ newAuthState = curAuthState;
+ // The below logic ensures that only the following transitions are possible:
+ // GRANTED -> DENIED_GRACE_PERIOD only if permissions have been lost
+ // DENIED_GRACE_PERIOD -> DENIED only if the grace period expires
+ // DENIED/DENIED_GRACE_PERIOD -> GRANTED only if permissions are granted again
+ if (gracePeriodExpired) {
+ if (curAuthState == AUTHORIZATION_DENIED_GRACE_PERIOD) {
+ newAuthState = AUTHORIZATION_DENIED;
+ }
+ } else {
+ if (curAuthState == AUTHORIZATION_GRANTED && !hasPermissions) {
+ newAuthState = AUTHORIZATION_DENIED_GRACE_PERIOD;
+ } else if (curAuthState != AUTHORIZATION_GRANTED && hasPermissions) {
+ newAuthState = AUTHORIZATION_GRANTED;
+ }
+ }
+
+ if (newAuthState == AUTHORIZATION_GRANTED) {
+ AuthStateDenialTimer timer = mNappToAuthTimerMap.remove(nanoAppId);
+ if (timer != null) {
+ timer.cancel();
+ }
+ } else if (curAuthState == AUTHORIZATION_GRANTED
+ && newAuthState == AUTHORIZATION_DENIED_GRACE_PERIOD) {
+ AuthStateDenialTimer timer =
+ new AuthStateDenialTimer(this, nanoAppId, Looper.getMainLooper());
+ mNappToAuthTimerMap.put(nanoAppId, timer);
+ timer.start();
+ }
+
+ if (curAuthState != newAuthState) {
+ mMessageChannelNanoappIdMap.put(nanoAppId, newAuthState);
+ }
+ }
+ if (curAuthState != newAuthState) {
+ // Don't send the callback in the synchronized block or it could end up in a deadlock.
+ sendAuthStateCallback(nanoAppId, newAuthState);
+ }
+ }
+
+ private void sendAuthStateCallback(long nanoAppId, int authState) {
+ invokeCallback(callback -> callback.onClientAuthorizationChanged(nanoAppId, authState));
+
+ Supplier<Intent> supplier =
+ () -> createIntent(ContextHubManager.EVENT_CLIENT_AUTHORIZATION, nanoAppId)
+ .putExtra(ContextHubManager.EXTRA_CLIENT_AUTHORIZATION_STATE, authState);
+ sendPendingIntent(supplier, nanoAppId);
+ }
+
+ /**
* Helper function to invoke a specified client callback, if the connection is open.
*
* @param consumer the consumer specifying the callback to invoke
@@ -479,6 +808,20 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
mClientManager.unregisterClient(mHostEndPointId);
mRegistered = false;
}
+ mAppOpsManager.stopWatchingMode(this);
+ }
+
+ private String authStateToString(@ContextHubManager.AuthorizationState int state) {
+ switch (state) {
+ case AUTHORIZATION_DENIED:
+ return "DENIED";
+ case AUTHORIZATION_DENIED_GRACE_PERIOD:
+ return "DENIED_GRACE_PERIOD";
+ case AUTHORIZATION_GRANTED:
+ return "GRANTED";
+ default:
+ return "UNKNOWN";
+ }
}
/**
@@ -508,17 +851,23 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
String out = "[ContextHubClient ";
out += "endpointID: " + getHostEndPointId() + ", ";
out += "contextHub: " + getAttachedContextHubId() + ", ";
+ if (mAttributionTag != null) {
+ out += "attributionTag: " + getAttributionTag() + ", ";
+ }
if (mPendingIntentRequest.isValid()) {
out += "intentCreatorPackage: " + mPackage + ", ";
out += "nanoAppId: 0x" + Long.toHexString(mPendingIntentRequest.getNanoAppId());
} else {
out += "package: " + mPackage;
}
- if (mMessageChannelNanoappIdSet.size() > 0) {
+ if (mMessageChannelNanoappIdMap.size() > 0) {
out += " messageChannelNanoappSet: (";
- Iterator<Long> it = mMessageChannelNanoappIdSet.iterator();
+ Iterator<Map.Entry<Long, Integer>> it =
+ mMessageChannelNanoappIdMap.entrySet().iterator();
while (it.hasNext()) {
- out += "0x" + Long.toHexString(it.next());
+ Map.Entry<Long, Integer> entry = it.next();
+ out += "0x" + Long.toHexString(entry.getKey()) + " auth state: "
+ + authStateToString(entry.getValue());
if (it.hasNext()) {
out += ",";
}
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubClientManager.java b/services/core/java/com/android/server/location/contexthub/ContextHubClientManager.java
index eda89ab52c6f..bc3f4b1db46d 100644
--- a/services/core/java/com/android/server/location/contexthub/ContextHubClientManager.java
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubClientManager.java
@@ -20,7 +20,6 @@ import android.annotation.IntDef;
import android.app.PendingIntent;
import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHubMsg;
-import android.hardware.contexthub.V1_0.IContexthub;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClientCallback;
@@ -37,6 +36,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
@@ -71,7 +71,7 @@ import java.util.function.Consumer;
/*
* The proxy to talk to the Context Hub.
*/
- private final IContexthub mContextHubProxy;
+ private final IContextHubWrapper mContextHubProxy;
/*
* A mapping of host endpoint IDs to the ContextHubClientBroker object of registered clients.
@@ -137,8 +137,7 @@ import java.util.function.Consumer;
}
}
- /* package */ ContextHubClientManager(
- Context context, IContexthub contextHubProxy) {
+ /* package */ ContextHubClientManager(Context context, IContextHubWrapper contextHubProxy) {
mContext = context;
mContextHubProxy = contextHubProxy;
}
@@ -148,19 +147,23 @@ import java.util.function.Consumer;
*
* @param contextHubInfo the object describing the hub this client is attached to
* @param clientCallback the callback interface of the client to register
+ * @param attributionTag an optional attribution tag within the given package
*
* @return the client interface
*
* @throws IllegalStateException if max number of clients have already registered
*/
/* package */ IContextHubClient registerClient(
- ContextHubInfo contextHubInfo, IContextHubClientCallback clientCallback) {
+ ContextHubInfo contextHubInfo, IContextHubClientCallback clientCallback,
+ String attributionTag, ContextHubTransactionManager transactionManager,
+ String packageName) {
ContextHubClientBroker broker;
synchronized (this) {
short hostEndPointId = getHostEndPointId();
broker = new ContextHubClientBroker(
mContext, mContextHubProxy, this /* clientManager */, contextHubInfo,
- hostEndPointId, clientCallback);
+ hostEndPointId, clientCallback, attributionTag, transactionManager,
+ packageName);
mHostEndPointIdToClientMap.put(hostEndPointId, broker);
mRegistrationRecordDeque.add(
new RegistrationRecord(broker.toString(), ACTION_REGISTERED));
@@ -185,13 +188,15 @@ import java.util.function.Consumer;
* @param pendingIntent the callback interface of the client to register
* @param contextHubInfo the object describing the hub this client is attached to
* @param nanoAppId the ID of the nanoapp to receive Intent events for
+ * @param attributionTag an optional attribution tag within the given package
*
* @return the client interface
*
* @throws IllegalStateException if there were too many registered clients at the service
*/
/* package */ IContextHubClient registerClient(
- ContextHubInfo contextHubInfo, PendingIntent pendingIntent, long nanoAppId) {
+ ContextHubInfo contextHubInfo, PendingIntent pendingIntent, long nanoAppId,
+ String attributionTag, ContextHubTransactionManager transactionManager) {
ContextHubClientBroker broker;
String registerString = "Regenerated";
synchronized (this) {
@@ -201,11 +206,16 @@ import java.util.function.Consumer;
short hostEndPointId = getHostEndPointId();
broker = new ContextHubClientBroker(
mContext, mContextHubProxy, this /* clientManager */, contextHubInfo,
- hostEndPointId, pendingIntent, nanoAppId);
+ hostEndPointId, pendingIntent, nanoAppId, attributionTag,
+ transactionManager);
mHostEndPointIdToClientMap.put(hostEndPointId, broker);
registerString = "Registered";
mRegistrationRecordDeque.add(
new RegistrationRecord(broker.toString(), ACTION_REGISTERED));
+ } else {
+ // Update the attribution tag to the latest value provided by the client app in
+ // case the app was updated and decided to change its tag.
+ broker.setAttributionTag(attributionTag);
}
}
@@ -217,9 +227,14 @@ import java.util.function.Consumer;
* Handles a message sent from a nanoapp.
*
* @param contextHubId the ID of the hub where the nanoapp sent the message from
- * @param message the message send by a nanoapp
+ * @param message the message send by a nanoapp
+ * @param nanoappPermissions the set of permissions the nanoapp holds
+ * @param messagePermissions the set of permissions that should be used for attributing
+ * permissions when this message is consumed by a client
*/
- /* package */ void onMessageFromNanoApp(int contextHubId, ContextHubMsg message) {
+ /* package */ void onMessageFromNanoApp(
+ int contextHubId, ContextHubMsg message, List<String> nanoappPermissions,
+ List<String> messagePermissions) {
NanoAppMessage clientMessage = ContextHubServiceUtil.createNanoAppMessage(message);
if (DEBUG_LOG_ENABLED) {
@@ -227,11 +242,19 @@ import java.util.function.Consumer;
}
if (clientMessage.isBroadcastMessage()) {
- broadcastMessage(contextHubId, clientMessage);
+ // Broadcast messages shouldn't be sent with any permissions tagged per CHRE API
+ // requirements.
+ if (!messagePermissions.isEmpty()) {
+ Log.wtf(TAG, "Received broadcast message with permissions from " + message.appName);
+ }
+
+ broadcastMessage(
+ contextHubId, clientMessage, nanoappPermissions, messagePermissions);
} else {
ContextHubClientBroker proxy = mHostEndPointIdToClientMap.get(message.hostEndPoint);
if (proxy != null) {
- proxy.sendMessageToClient(clientMessage);
+ proxy.sendMessageToClient(
+ clientMessage, nanoappPermissions, messagePermissions);
} else {
Log.e(TAG, "Cannot send message to unregistered client (host endpoint ID = "
+ message.hostEndPoint + ")");
@@ -326,8 +349,12 @@ import java.util.function.Consumer;
* @param contextHubId the ID of the hub where the nanoapp sent the message from
* @param message the message send by a nanoapp
*/
- private void broadcastMessage(int contextHubId, NanoAppMessage message) {
- forEachClientOfHub(contextHubId, client -> client.sendMessageToClient(message));
+ private void broadcastMessage(
+ int contextHubId, NanoAppMessage message, List<String> nanoappPermissions,
+ List<String> messagePermissions) {
+ forEachClientOfHub(contextHubId,
+ client -> client.sendMessageToClient(
+ message, nanoappPermissions, messagePermissions));
}
/**
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java
index 785e6745087f..40986fcf03cb 100644
--- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java
@@ -27,10 +27,10 @@ import android.hardware.SensorPrivacyManager;
import android.hardware.contexthub.V1_0.AsyncEventType;
import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_0.ContextHubMsg;
-import android.hardware.contexthub.V1_0.HubAppInfo;
-import android.hardware.contexthub.V1_0.IContexthubCallback;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.contexthub.V1_0.TransactionResult;
+import android.hardware.contexthub.V1_2.HubAppInfo;
+import android.hardware.contexthub.V1_2.IContexthubCallback;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubMessage;
import android.hardware.location.ContextHubTransaction;
@@ -53,6 +53,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
+import android.util.Pair;
import android.util.proto.ProtoOutputStream;
import com.android.internal.util.DumpUtils;
@@ -63,6 +64,7 @@ import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -97,6 +99,7 @@ public class ContextHubService extends IContextHubService.Stub {
private final Context mContext;
private final Map<Integer, ContextHubInfo> mContextHubIdToInfoMap;
+ private final List<String> mSupportedContextHubPerms;
private final List<ContextHubInfo> mContextHubInfoList;
private final RemoteCallbackList<IContextHubCallback> mCallbacksList =
new RemoteCallbackList<>();
@@ -137,7 +140,9 @@ public class ContextHubService extends IContextHubService.Stub {
@Override
public void handleClientMsg(ContextHubMsg message) {
- handleClientMessageCallback(mContextHubId, message);
+ handleClientMessageCallback(mContextHubId, message,
+ Collections.emptyList() /* nanoappPermissions */,
+ Collections.emptyList() /* messagePermissions */);
}
@Override
@@ -156,7 +161,21 @@ public class ContextHubService extends IContextHubService.Stub {
}
@Override
- public void handleAppsInfo(ArrayList<HubAppInfo> nanoAppInfoList) {
+ public void handleAppsInfo(
+ ArrayList<android.hardware.contexthub.V1_0.HubAppInfo> nanoAppInfoList) {
+ handleQueryAppsCallback(mContextHubId,
+ ContextHubServiceUtil.toHubAppInfo_1_2(nanoAppInfoList));
+ }
+
+ @Override
+ public void handleClientMsg_1_2(android.hardware.contexthub.V1_2.ContextHubMsg message,
+ ArrayList<String> messagePermissions) {
+ handleClientMessageCallback(mContextHubId, message.msg_1_0, message.permissions,
+ messagePermissions);
+ }
+
+ @Override
+ public void handleAppsInfo_1_2(ArrayList<HubAppInfo> nanoAppInfoList) {
handleQueryAppsCallback(mContextHubId, nanoAppInfoList);
}
}
@@ -170,34 +189,37 @@ public class ContextHubService extends IContextHubService.Stub {
mClientManager = null;
mDefaultClientMap = Collections.emptyMap();
mContextHubIdToInfoMap = Collections.emptyMap();
+ mSupportedContextHubPerms = Collections.emptyList();
mContextHubInfoList = Collections.emptyList();
return;
}
- mClientManager = new ContextHubClientManager(mContext, mContextHubWrapper.getHub());
- mTransactionManager = new ContextHubTransactionManager(
- mContextHubWrapper.getHub(), mClientManager, mNanoAppStateManager);
-
- List<ContextHub> hubList;
+ Pair<List<ContextHub>, List<String>> hubInfo;
try {
- hubList = mContextHubWrapper.getHub().getHubs();
+ hubInfo = mContextHubWrapper.getHubs();
} catch (RemoteException e) {
Log.e(TAG, "RemoteException while getting Context Hub info", e);
- hubList = Collections.emptyList();
+ hubInfo = new Pair(Collections.emptyList(), Collections.emptyList());
}
+
mContextHubIdToInfoMap = Collections.unmodifiableMap(
- ContextHubServiceUtil.createContextHubInfoMap(hubList));
+ ContextHubServiceUtil.createContextHubInfoMap(hubInfo.first));
+ mSupportedContextHubPerms = hubInfo.second;
mContextHubInfoList = new ArrayList<>(mContextHubIdToInfoMap.values());
+ mClientManager = new ContextHubClientManager(mContext, mContextHubWrapper);
+ mTransactionManager = new ContextHubTransactionManager(
+ mContextHubWrapper.getHub(), mClientManager, mNanoAppStateManager);
HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>();
for (int contextHubId : mContextHubIdToInfoMap.keySet()) {
ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId);
IContextHubClient client = mClientManager.registerClient(
- contextHubInfo, createDefaultClientCallback(contextHubId));
+ contextHubInfo, createDefaultClientCallback(contextHubId),
+ null /* attributionTag */, mTransactionManager, mContext.getPackageName());
defaultClientMap.put(contextHubId, client);
try {
- mContextHubWrapper.getHub().registerCallback(
+ mContextHubWrapper.registerCallback(
contextHubId, new ContextHubServiceCallback(contextHubId));
} catch (RemoteException e) {
Log.e(TAG, "RemoteException while registering service callback for hub (ID = "
@@ -593,11 +615,15 @@ public class ContextHubService extends IContextHubService.Stub {
/**
* Handles a unicast or broadcast message from a nanoapp.
*
- * @param contextHubId the ID of the hub the message came from
- * @param message the message contents
+ * @param contextHubId the ID of the hub the message came from
+ * @param message the message contents
+ * @param reqPermissions the permissions required to consume this message
*/
- private void handleClientMessageCallback(int contextHubId, ContextHubMsg message) {
- mClientManager.onMessageFromNanoApp(contextHubId, message);
+ private void handleClientMessageCallback(
+ int contextHubId, ContextHubMsg message, List<String> nanoappPermissions,
+ List<String> messagePermissions) {
+ mClientManager.onMessageFromNanoApp(
+ contextHubId, message, nanoappPermissions, messagePermissions);
}
/**
@@ -703,6 +729,7 @@ public class ContextHubService extends IContextHubService.Stub {
* @param contextHubId the ID of the hub this client is attached to
* @param clientCallback the client interface to register with the service
* @param attributionTag an optional attribution tag within the given package
+ * @param packageName the name of the package creating this client
* @return the generated client interface, null if registration was unsuccessful
* @throws IllegalArgumentException if contextHubId is not a valid ID
* @throws IllegalStateException if max number of clients have already registered
@@ -711,7 +738,7 @@ public class ContextHubService extends IContextHubService.Stub {
@Override
public IContextHubClient createClient(
int contextHubId, IContextHubClientCallback clientCallback,
- @Nullable String attributionTag) throws RemoteException {
+ @Nullable String attributionTag, String packageName) throws RemoteException {
checkPermissions();
if (!isValidContextHubId(contextHubId)) {
throw new IllegalArgumentException("Invalid context hub ID " + contextHubId);
@@ -721,7 +748,8 @@ public class ContextHubService extends IContextHubService.Stub {
}
ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId);
- return mClientManager.registerClient(contextHubInfo, clientCallback);
+ return mClientManager.registerClient(
+ contextHubInfo, clientCallback, attributionTag, mTransactionManager, packageName);
}
/**
@@ -745,7 +773,8 @@ public class ContextHubService extends IContextHubService.Stub {
}
ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId);
- return mClientManager.registerClient(contextHubInfo, pendingIntent, nanoAppId);
+ return mClientManager.registerClient(
+ contextHubInfo, pendingIntent, nanoAppId, attributionTag, mTransactionManager);
}
/**
@@ -886,6 +915,8 @@ public class ContextHubService extends IContextHubService.Stub {
for (ContextHubInfo hubInfo : mContextHubIdToInfoMap.values()) {
pw.println(hubInfo);
}
+ pw.println("Supported permissions: "
+ + Arrays.toString(mSupportedContextHubPerms.toArray()));
pw.println("");
pw.println("=================== NANOAPPS ====================");
// Dump nanoAppHash
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java
index 88ed1053616a..8361253dcd4a 100644
--- a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java
@@ -23,8 +23,8 @@ import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.HostEndPoint;
-import android.hardware.contexthub.V1_0.HubAppInfo;
import android.hardware.contexthub.V1_0.Result;
+import android.hardware.contexthub.V1_2.HubAppInfo;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.NanoAppBinary;
@@ -161,7 +161,8 @@ import java.util.Set;
ArrayList<NanoAppState> nanoAppStateList = new ArrayList<>();
for (HubAppInfo appInfo : nanoAppInfoList) {
nanoAppStateList.add(
- new NanoAppState(appInfo.appId, appInfo.version, appInfo.enabled));
+ new NanoAppState(appInfo.info_1_0.appId, appInfo.info_1_0.version,
+ appInfo.info_1_0.enabled, appInfo.permissions));
}
return nanoAppStateList;
@@ -255,4 +256,26 @@ import java.util.Set;
return ContextHubTransaction.RESULT_FAILED_UNKNOWN;
}
}
+
+ /**
+ * Converts old list of HubAppInfo received from the HAL to V1.2 HubAppInfo objects.
+ *
+ * @param oldInfoList list of V1.0 HubAppInfo objects
+ * @return list of V1.2 HubAppInfo objects
+ */
+ /* package */
+ static ArrayList<HubAppInfo> toHubAppInfo_1_2(
+ ArrayList<android.hardware.contexthub.V1_0.HubAppInfo> oldInfoList) {
+ ArrayList newAppInfo = new ArrayList<HubAppInfo>();
+ for (android.hardware.contexthub.V1_0.HubAppInfo oldInfo : oldInfoList) {
+ HubAppInfo newInfo = new HubAppInfo();
+ newInfo.info_1_0.appId = oldInfo.appId;
+ newInfo.info_1_0.version = oldInfo.version;
+ newInfo.info_1_0.memUsage = oldInfo.memUsage;
+ newInfo.info_1_0.enabled = oldInfo.enabled;
+ newInfo.permissions = new ArrayList<String>();
+ newAppInfo.add(newInfo);
+ }
+ return newAppInfo;
+ }
}
diff --git a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java
index c11e289c116b..3a5c220eeeae 100644
--- a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java
+++ b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java
@@ -16,11 +16,17 @@
package com.android.server.location.contexthub;
import android.annotation.Nullable;
+import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_1.Setting;
import android.hardware.contexthub.V1_1.SettingValue;
+import android.hardware.contexthub.V1_2.IContexthubCallback;
import android.os.RemoteException;
import android.util.Log;
+import android.util.Pair;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.NoSuchElementException;
/**
@@ -87,6 +93,23 @@ public abstract class IContextHubWrapper {
}
/**
+ * Calls the appropriate getHubs function depending on the HAL version.
+ */
+ public abstract Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException;
+
+ /**
+ * Calls the appropriate registerCallback function depending on the HAL version.
+ */
+ public abstract void registerCallback(
+ int hubId, IContexthubCallback callback) throws RemoteException;
+
+ /**
+ * Calls the appropriate sendMessageToHub function depending on the HAL version.
+ */
+ public abstract int sendMessageToHub(int hubId,
+ android.hardware.contexthub.V1_0.ContextHubMsg message) throws RemoteException;
+
+ /**
* @return A valid instance of Contexthub HAL 1.0.
*/
public abstract android.hardware.contexthub.V1_0.IContexthub getHub();
@@ -148,6 +171,20 @@ public abstract class IContextHubWrapper {
mHub = hub;
}
+ public Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException {
+ return new Pair(mHub.getHubs(), new ArrayList<String>());
+ }
+
+ public void registerCallback(
+ int hubId, IContexthubCallback callback) throws RemoteException {
+ mHub.registerCallback(hubId, callback);
+ }
+
+ public int sendMessageToHub(int hubId,
+ android.hardware.contexthub.V1_0.ContextHubMsg message) throws RemoteException {
+ return mHub.sendMessageToHub(hubId, message);
+ }
+
public android.hardware.contexthub.V1_0.IContexthub getHub() {
return mHub;
}
@@ -188,6 +225,20 @@ public abstract class IContextHubWrapper {
mHub = hub;
}
+ public Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException {
+ return new Pair(mHub.getHubs(), new ArrayList<String>());
+ }
+
+ public void registerCallback(
+ int hubId, IContexthubCallback callback) throws RemoteException {
+ mHub.registerCallback(hubId, callback);
+ }
+
+ public int sendMessageToHub(int hubId,
+ android.hardware.contexthub.V1_0.ContextHubMsg message) throws RemoteException {
+ return mHub.sendMessageToHub(hubId, message);
+ }
+
public android.hardware.contexthub.V1_0.IContexthub getHub() {
return mHub;
}
@@ -227,13 +278,40 @@ public abstract class IContextHubWrapper {
}
}
- private static class ContextHubWrapperV1_2 extends IContextHubWrapper {
- private android.hardware.contexthub.V1_2.IContexthub mHub;
+ private static class ContextHubWrapperV1_2 extends IContextHubWrapper
+ implements android.hardware.contexthub.V1_2.IContexthub.getHubs_1_2Callback {
+ private final android.hardware.contexthub.V1_2.IContexthub mHub;
+
+ private Pair<List<ContextHub>, List<String>> mHubInfo =
+ new Pair<>(Collections.emptyList(), Collections.emptyList());
ContextHubWrapperV1_2(android.hardware.contexthub.V1_2.IContexthub hub) {
mHub = hub;
}
+ @Override
+ public void onValues(ArrayList<ContextHub> hubs, ArrayList<String> supportedPermissions) {
+ mHubInfo = new Pair(hubs, supportedPermissions);
+ }
+
+ public Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException {
+ mHub.getHubs_1_2(this);
+ return mHubInfo;
+ }
+
+ public void registerCallback(
+ int hubId, IContexthubCallback callback) throws RemoteException {
+ mHub.registerCallback_1_2(hubId, callback);
+ }
+
+ public int sendMessageToHub(int hubId,
+ android.hardware.contexthub.V1_0.ContextHubMsg message) throws RemoteException {
+ android.hardware.contexthub.V1_2.ContextHubMsg newMessage =
+ new android.hardware.contexthub.V1_2.ContextHubMsg();
+ newMessage.msg_1_0 = message;
+ return mHub.sendMessageToHub_1_2(hubId, newMessage);
+ }
+
public android.hardware.contexthub.V1_0.IContexthub getHub() {
return mHub;
}
diff --git a/services/core/java/com/android/server/location/contexthub/NanoAppStateManager.java b/services/core/java/com/android/server/location/contexthub/NanoAppStateManager.java
index 60109fe4b9f6..667fb98f8649 100644
--- a/services/core/java/com/android/server/location/contexthub/NanoAppStateManager.java
+++ b/services/core/java/com/android/server/location/contexthub/NanoAppStateManager.java
@@ -17,7 +17,7 @@
package com.android.server.location.contexthub;
import android.annotation.Nullable;
-import android.hardware.contexthub.V1_0.HubAppInfo;
+import android.hardware.contexthub.V1_2.HubAppInfo;
import android.hardware.location.NanoAppInstanceInfo;
import android.util.Log;
@@ -154,8 +154,8 @@ import java.util.function.Consumer;
synchronized void updateCache(int contextHubId, List<HubAppInfo> nanoAppInfoList) {
HashSet<Long> nanoAppIdSet = new HashSet<>();
for (HubAppInfo appInfo : nanoAppInfoList) {
- handleQueryAppEntry(contextHubId, appInfo.appId, appInfo.version);
- nanoAppIdSet.add(appInfo.appId);
+ handleQueryAppEntry(contextHubId, appInfo.info_1_0.appId, appInfo.info_1_0.version);
+ nanoAppIdSet.add(appInfo.info_1_0.appId);
}
Iterator<NanoAppInstanceInfo> iterator = mNanoAppHash.values().iterator();
diff --git a/services/core/java/com/android/server/location/eventlog/LocationEventLog.java b/services/core/java/com/android/server/location/eventlog/LocationEventLog.java
index 865d41f1baee..dbfd0a52b013 100644
--- a/services/core/java/com/android/server/location/eventlog/LocationEventLog.java
+++ b/services/core/java/com/android/server/location/eventlog/LocationEventLog.java
@@ -60,7 +60,8 @@ public class LocationEventLog extends LocalEventLog {
private static final int EVENT_PROVIDER_UPDATE_REQUEST = 6;
private static final int EVENT_PROVIDER_RECEIVE_LOCATION = 7;
private static final int EVENT_PROVIDER_DELIVER_LOCATION = 8;
- private static final int EVENT_LOCATION_POWER_SAVE_MODE_CHANGE = 9;
+ private static final int EVENT_PROVIDER_STATIONARY_THROTTLED = 9;
+ private static final int EVENT_LOCATION_POWER_SAVE_MODE_CHANGE = 10;
@GuardedBy("mAggregateStats")
private final ArrayMap<String, ArrayMap<String, AggregateStats>> mAggregateStats;
@@ -167,6 +168,11 @@ public class LocationEventLog extends LocalEventLog {
getAggregateStats(provider, identity.getPackageName()).markLocationDelivered();
}
+ /** Logs that a provider has entered or exited stationary throttling. */
+ public void logProviderStationaryThrottled(String provider, boolean throttled) {
+ addLogEvent(EVENT_PROVIDER_STATIONARY_THROTTLED, provider, throttled);
+ }
+
/** Logs that the location power save mode has changed. */
public void logLocationPowerSaveMode(
@LocationPowerSaveMode int locationPowerSaveMode) {
@@ -198,6 +204,9 @@ public class LocationEventLog extends LocalEventLog {
case EVENT_PROVIDER_DELIVER_LOCATION:
return new ProviderDeliverLocationEvent(timeDelta, (String) args[0],
(Integer) args[1], (CallerIdentity) args[2]);
+ case EVENT_PROVIDER_STATIONARY_THROTTLED:
+ return new ProviderStationaryThrottledEvent(timeDelta, (String) args[0],
+ (Boolean) args[1]);
case EVENT_LOCATION_POWER_SAVE_MODE_CHANGE:
return new LocationPowerSaveModeEvent(timeDelta, (Integer) args[0]);
default:
@@ -332,6 +341,23 @@ public class LocationEventLog extends LocalEventLog {
}
}
+ private static final class ProviderStationaryThrottledEvent extends ProviderEvent {
+
+ private final boolean mStationaryThrottled;
+
+ private ProviderStationaryThrottledEvent(long timeDelta, String provider,
+ boolean stationaryThrottled) {
+ super(timeDelta, provider);
+ mStationaryThrottled = stationaryThrottled;
+ }
+
+ @Override
+ public String getLogString() {
+ return mProvider + " provider stationary/idle " + (mStationaryThrottled ? "throttled"
+ : "unthrottled");
+ }
+ }
+
private static final class LocationPowerSaveModeEvent extends LogEvent {
@LocationPowerSaveMode
diff --git a/services/core/java/com/android/server/location/injector/DeviceIdleHelper.java b/services/core/java/com/android/server/location/injector/DeviceIdleHelper.java
new file mode 100644
index 000000000000..e820b00f3714
--- /dev/null
+++ b/services/core/java/com/android/server/location/injector/DeviceIdleHelper.java
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package com.android.server.location.injector;
+
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * Provides accessors and listeners for device idle status.
+ */
+public abstract class DeviceIdleHelper {
+
+ /**
+ * Listener for device stationary status.
+ */
+ public interface DeviceIdleListener {
+ /**
+ * Called when device idle state has changed.
+ */
+ void onDeviceIdleChanged(boolean deviceIdle);
+ }
+
+ private final CopyOnWriteArrayList<DeviceIdleListener> mListeners;
+
+ protected DeviceIdleHelper() {
+ mListeners = new CopyOnWriteArrayList<>();
+ }
+
+ /**
+ * Adds a listener for device idle status.
+ */
+ public final synchronized void addListener(DeviceIdleListener listener) {
+ if (mListeners.add(listener) && mListeners.size() == 1) {
+ registerInternal();
+ }
+ }
+
+ /**
+ * Removes a listener for device idle status.
+ */
+ public final synchronized void removeListener(DeviceIdleListener listener) {
+ if (mListeners.remove(listener) && mListeners.isEmpty()) {
+ unregisterInternal();
+ }
+ }
+
+ protected final void notifyDeviceIdleChanged() {
+ boolean deviceIdle = isDeviceIdle();
+
+ for (DeviceIdleListener listener : mListeners) {
+ listener.onDeviceIdleChanged(deviceIdle);
+ }
+ }
+
+ protected abstract void registerInternal();
+
+ protected abstract void unregisterInternal();
+
+ /**
+ * Returns true if the device is currently idle.
+ */
+ public abstract boolean isDeviceIdle();
+}
diff --git a/services/core/java/com/android/server/location/injector/DeviceStationaryHelper.java b/services/core/java/com/android/server/location/injector/DeviceStationaryHelper.java
new file mode 100644
index 000000000000..b77c0f7dfe7f
--- /dev/null
+++ b/services/core/java/com/android/server/location/injector/DeviceStationaryHelper.java
@@ -0,0 +1,36 @@
+/*
+ * 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.server.location.injector;
+
+import com.android.server.DeviceIdleInternal;
+
+/**
+ * Provides accessors and listeners for device stationary status.
+ */
+public abstract class DeviceStationaryHelper {
+
+ /**
+ * Adds a listener for stationary status. The listener will be immediately invoked with the
+ * current stationary status.
+ */
+ public abstract void addListener(DeviceIdleInternal.StationaryListener listener);
+
+ /**
+ * Removes a listener for stationary status.
+ */
+ public abstract void removeListener(DeviceIdleInternal.StationaryListener listener);
+}
diff --git a/services/core/java/com/android/server/location/injector/Injector.java b/services/core/java/com/android/server/location/injector/Injector.java
index 0e157c22a32b..b0351184ffe5 100644
--- a/services/core/java/com/android/server/location/injector/Injector.java
+++ b/services/core/java/com/android/server/location/injector/Injector.java
@@ -48,6 +48,12 @@ public interface Injector {
/** Returns a ScreenInteractiveHelper. */
ScreenInteractiveHelper getScreenInteractiveHelper();
+ /** Returns a DeviceStationaryHelper. */
+ DeviceStationaryHelper getDeviceStationaryHelper();
+
+ /** Returns a DeviceIdleHelper. */
+ DeviceIdleHelper getDeviceIdleHelper();
+
/** Returns a LocationAttributionHelper. */
LocationAttributionHelper getLocationAttributionHelper();
diff --git a/services/core/java/com/android/server/location/injector/SystemDeviceIdleHelper.java b/services/core/java/com/android/server/location/injector/SystemDeviceIdleHelper.java
new file mode 100644
index 000000000000..6a89079d81ba
--- /dev/null
+++ b/services/core/java/com/android/server/location/injector/SystemDeviceIdleHelper.java
@@ -0,0 +1,70 @@
+/*
+ * 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.server.location.injector;
+
+import android.annotation.Nullable;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.PowerManager;
+
+import com.android.server.FgThread;
+
+/**
+ * Provides accessors and listeners for device stationary state.
+ */
+public class SystemDeviceIdleHelper extends DeviceIdleHelper {
+
+ private final Context mContext;
+ private final PowerManager mPowerManager;
+
+ private @Nullable BroadcastReceiver mReceiver;
+
+ public SystemDeviceIdleHelper(Context context) {
+ mContext = context;
+ mPowerManager = context.getSystemService(PowerManager.class);
+ }
+
+ @Override
+ protected void registerInternal() {
+ if (mReceiver == null) {
+ mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ notifyDeviceIdleChanged();
+ }
+ };
+
+ mContext.registerReceiver(mReceiver,
+ new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED), null,
+ FgThread.getHandler());
+ }
+ }
+
+ @Override
+ protected void unregisterInternal() {
+ if (mReceiver != null) {
+ mContext.unregisterReceiver(mReceiver);
+ }
+ }
+
+ @Override
+ public boolean isDeviceIdle() {
+ return mPowerManager.isDeviceIdleMode();
+ }
+}
diff --git a/services/core/java/com/android/server/location/injector/SystemDeviceStationaryHelper.java b/services/core/java/com/android/server/location/injector/SystemDeviceStationaryHelper.java
new file mode 100644
index 000000000000..6f0e681b808f
--- /dev/null
+++ b/services/core/java/com/android/server/location/injector/SystemDeviceStationaryHelper.java
@@ -0,0 +1,44 @@
+/*
+ * 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.server.location.injector;
+
+import com.android.server.DeviceIdleInternal;
+import com.android.server.LocalServices;
+
+import java.util.Objects;
+
+/**
+ * Provides accessors and listeners for device stationary state.
+ */
+public class SystemDeviceStationaryHelper extends DeviceStationaryHelper {
+
+ private final DeviceIdleInternal mDeviceIdle;
+
+ public SystemDeviceStationaryHelper() {
+ mDeviceIdle = Objects.requireNonNull(LocalServices.getService(DeviceIdleInternal.class));
+ }
+
+ @Override
+ public void addListener(DeviceIdleInternal.StationaryListener listener) {
+ mDeviceIdle.registerStationaryListener(listener);
+ }
+
+ @Override
+ public void removeListener(DeviceIdleInternal.StationaryListener listener) {
+ mDeviceIdle.unregisterStationaryListener(listener);
+ }
+}
diff --git a/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java b/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java
index e22a0145f2bf..4e0a0b89f238 100644
--- a/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java
+++ b/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java
@@ -337,8 +337,10 @@ public abstract class AbstractLocationProvider {
@Override
public State setListener(@Nullable Listener listener) {
- return mInternalState.updateAndGet(
- internalState -> internalState.withListener(listener)).state;
+ InternalState oldInternalState = mInternalState.getAndUpdate(
+ internalState -> internalState.withListener(listener));
+ Preconditions.checkState(listener == null || oldInternalState.listener == null);
+ return oldInternalState.state;
}
@Override
diff --git a/services/core/java/com/android/server/location/provider/DelegateLocationProvider.java b/services/core/java/com/android/server/location/provider/DelegateLocationProvider.java
new file mode 100644
index 000000000000..a3ec867220dd
--- /dev/null
+++ b/services/core/java/com/android/server/location/provider/DelegateLocationProvider.java
@@ -0,0 +1,119 @@
+/*
+ * 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.server.location.provider;
+
+import android.location.LocationResult;
+import android.location.provider.ProviderRequest;
+import android.os.Bundle;
+
+import com.android.internal.util.Preconditions;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.concurrent.Executor;
+
+/**
+ * Helper class for wrapping location providers. Subclasses MUST ensure that
+ * {@link #initializeDelegate()} is invoked before the delegate is used.
+ */
+class DelegateLocationProvider extends AbstractLocationProvider
+ implements AbstractLocationProvider.Listener {
+
+ private final Object mInitializationLock = new Object();
+
+ protected final AbstractLocationProvider mDelegate;
+
+ private boolean mInitialized = false;
+
+ DelegateLocationProvider(Executor executor, AbstractLocationProvider delegate) {
+ super(executor, null, null);
+
+ mDelegate = delegate;
+ }
+
+ /**
+ * This function initializes state from the delegate and allows all other callbacks to be
+ * immediately invoked. If this method is invoked from a subclass constructor, it should be the
+ * last statement in the constructor since it allows the subclass' reference to escape.
+ */
+ protected void initializeDelegate() {
+ synchronized (mInitializationLock) {
+ Preconditions.checkState(!mInitialized);
+ setState(previousState -> mDelegate.getController().setListener(this));
+ mInitialized = true;
+ }
+ }
+
+ // must be invoked in every listener callback to ensure they don't run until initialized
+ protected final void waitForInitialization() {
+ // callbacks can start coming as soon as the setListener() call in initializeDelegate
+ // completes - but we can't allow any to proceed until the setState call afterwards
+ // completes. acquiring the initialization lock here blocks until initialization is
+ // complete, and we verify this wasn't called before initializeDelegate for some reason.
+ synchronized (mInitializationLock) {
+ Preconditions.checkState(mInitialized);
+ }
+ }
+
+ @Override
+ public void onStateChanged(State oldState, State newState) {
+ waitForInitialization();
+ setState(previousState -> newState);
+ }
+
+ @Override
+ public void onReportLocation(LocationResult locationResult) {
+ waitForInitialization();
+ reportLocation(locationResult);
+ }
+
+ @Override
+ protected void onStart() {
+ Preconditions.checkState(mInitialized);
+ mDelegate.getController().start();
+ }
+
+ @Override
+ protected void onStop() {
+ Preconditions.checkState(mInitialized);
+ mDelegate.getController().stop();
+ }
+
+ @Override
+ protected void onSetRequest(ProviderRequest request) {
+ Preconditions.checkState(mInitialized);
+ mDelegate.getController().setRequest(request);
+ }
+
+ @Override
+ protected void onFlush(Runnable callback) {
+ Preconditions.checkState(mInitialized);
+ mDelegate.getController().flush(callback);
+ }
+
+ @Override
+ protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {
+ Preconditions.checkState(mInitialized);
+ mDelegate.getController().sendExtraCommand(uid, pid, command, extras);
+ }
+
+ @Override
+ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ Preconditions.checkState(mInitialized);
+ mDelegate.dump(fd, pw, args);
+ }
+}
diff --git a/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java b/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java
new file mode 100644
index 000000000000..6f4aa642500f
--- /dev/null
+++ b/services/core/java/com/android/server/location/provider/StationaryThrottlingLocationProvider.java
@@ -0,0 +1,294 @@
+/*
+ * 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.server.location.provider;
+
+import static android.location.provider.ProviderRequest.INTERVAL_DISABLED;
+
+import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;
+import static com.android.server.location.LocationManagerService.D;
+import static com.android.server.location.LocationManagerService.TAG;
+
+import android.annotation.Nullable;
+import android.location.Location;
+import android.location.LocationResult;
+import android.location.provider.ProviderRequest;
+import android.os.SystemClock;
+import android.util.Log;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.util.Preconditions;
+import com.android.server.DeviceIdleInternal;
+import com.android.server.FgThread;
+import com.android.server.location.eventlog.LocationEventLog;
+import com.android.server.location.injector.DeviceIdleHelper;
+import com.android.server.location.injector.DeviceStationaryHelper;
+import com.android.server.location.injector.Injector;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * Throttles location providers completely while the device is in doze and stationary, and returns
+ * the last known location as a new location at the appropriate interval instead. Hypothetically,
+ * this throttling could be applied only when the device is stationary - however we don't trust the
+ * accuracy of the on-device SMD (which could allow for 100s of feet of movement without triggering
+ * in some use cases) enough to rely just on this. Instead we require the device to be in doze mode
+ * and stationary to narrow down the effect of false positives/negatives.
+ */
+public final class StationaryThrottlingLocationProvider extends DelegateLocationProvider
+ implements DeviceIdleHelper.DeviceIdleListener, DeviceIdleInternal.StationaryListener {
+
+ private static final long MAX_STATIONARY_LOCATION_AGE_MS = 30000;
+
+ private final Object mLock = new Object();
+
+ private final String mName;
+ private final DeviceIdleHelper mDeviceIdleHelper;
+ private final DeviceStationaryHelper mDeviceStationaryHelper;
+ private final LocationEventLog mEventLog;
+
+ @GuardedBy("mLock")
+ private boolean mDeviceIdle = false;
+ @GuardedBy("mLock")
+ private boolean mDeviceStationary = false;
+ @GuardedBy("mLock")
+ private long mDeviceStationaryRealtimeMs = Long.MIN_VALUE;
+ @GuardedBy("mLock")
+ private ProviderRequest mIncomingRequest = ProviderRequest.EMPTY_REQUEST;
+ @GuardedBy("mLock")
+ private ProviderRequest mOutgoingRequest = ProviderRequest.EMPTY_REQUEST;
+ @GuardedBy("mLock")
+ private long mThrottlingIntervalMs = INTERVAL_DISABLED;
+ @GuardedBy("mLock")
+ private @Nullable DeliverLastLocationRunnable mDeliverLastLocationCallback = null;
+
+ @GuardedBy("mLock")
+ private @Nullable Location mLastLocation;
+
+ public StationaryThrottlingLocationProvider(String name, Injector injector,
+ AbstractLocationProvider delegate, LocationEventLog eventLog) {
+ super(DIRECT_EXECUTOR, delegate);
+
+ mName = name;
+ mDeviceIdleHelper = injector.getDeviceIdleHelper();
+ mDeviceStationaryHelper = injector.getDeviceStationaryHelper();
+ mEventLog = eventLog;
+
+ // must be last statement in the constructor because reference is escaping
+ initializeDelegate();
+ }
+
+ @Override
+ public void onReportLocation(LocationResult locationResult) {
+ super.onReportLocation(locationResult);
+
+ synchronized (mLock) {
+ mLastLocation = locationResult.getLastLocation();
+ onThrottlingChangedLocked(false);
+ }
+ }
+
+ @Override
+ protected void onStart() {
+ mDelegate.getController().start();
+
+ synchronized (mLock) {
+ mDeviceIdleHelper.addListener(this);
+ mDeviceIdle = mDeviceIdleHelper.isDeviceIdle();
+ mDeviceStationaryHelper.addListener(this);
+ mDeviceStationary = false;
+ mDeviceStationaryRealtimeMs = Long.MIN_VALUE;
+
+ onThrottlingChangedLocked(false);
+ }
+ }
+
+ @Override
+ protected void onStop() {
+ synchronized (mLock) {
+ mDeviceStationaryHelper.removeListener(this);
+ mDeviceIdleHelper.removeListener(this);
+
+ mIncomingRequest = ProviderRequest.EMPTY_REQUEST;
+ mOutgoingRequest = ProviderRequest.EMPTY_REQUEST;
+ mThrottlingIntervalMs = INTERVAL_DISABLED;
+
+ if (mDeliverLastLocationCallback != null) {
+ FgThread.getHandler().removeCallbacks(mDeliverLastLocationCallback);
+ mDeliverLastLocationCallback = null;
+ }
+
+ mLastLocation = null;
+ }
+
+ mDelegate.getController().stop();
+ }
+
+ @Override
+ protected void onSetRequest(ProviderRequest request) {
+ synchronized (mLock) {
+ mIncomingRequest = request;
+ onThrottlingChangedLocked(true);
+ }
+ }
+
+ @Override
+ public void onDeviceIdleChanged(boolean deviceIdle) {
+ synchronized (mLock) {
+ if (deviceIdle == mDeviceIdle) {
+ return;
+ }
+
+ mDeviceIdle = deviceIdle;
+ onThrottlingChangedLocked(false);
+ }
+ }
+
+ @Override
+ public void onDeviceStationaryChanged(boolean deviceStationary) {
+ synchronized (mLock) {
+ if (mDeviceStationary == deviceStationary) {
+ return;
+ }
+
+ mDeviceStationary = deviceStationary;
+ if (mDeviceStationary) {
+ mDeviceStationaryRealtimeMs = SystemClock.elapsedRealtime();
+ } else {
+ mDeviceStationaryRealtimeMs = Long.MIN_VALUE;
+ }
+ onThrottlingChangedLocked(false);
+ }
+ }
+
+ @GuardedBy("mLock")
+ private void onThrottlingChangedLocked(boolean deliverImmediate) {
+ long throttlingIntervalMs = INTERVAL_DISABLED;
+ if (mDeviceStationary && mDeviceIdle && !mIncomingRequest.isLocationSettingsIgnored()
+ && mLastLocation != null
+ && mLastLocation.getElapsedRealtimeAgeMillis(mDeviceStationaryRealtimeMs)
+ <= MAX_STATIONARY_LOCATION_AGE_MS) {
+ throttlingIntervalMs = mIncomingRequest.getIntervalMillis();
+ }
+
+ ProviderRequest newRequest;
+ if (throttlingIntervalMs != INTERVAL_DISABLED) {
+ newRequest = ProviderRequest.EMPTY_REQUEST;
+ } else {
+ newRequest = mIncomingRequest;
+ }
+
+ if (!newRequest.equals(mOutgoingRequest)) {
+ mOutgoingRequest = newRequest;
+ mDelegate.getController().setRequest(mOutgoingRequest);
+ }
+
+ if (throttlingIntervalMs == mThrottlingIntervalMs) {
+ return;
+ }
+
+ long oldThrottlingIntervalMs = mThrottlingIntervalMs;
+ mThrottlingIntervalMs = throttlingIntervalMs;
+
+ if (mThrottlingIntervalMs != INTERVAL_DISABLED) {
+ if (oldThrottlingIntervalMs == INTERVAL_DISABLED) {
+ if (D) {
+ Log.d(TAG, mName + " provider stationary throttled");
+ }
+ mEventLog.logProviderStationaryThrottled(mName, true);
+ }
+
+ if (mDeliverLastLocationCallback != null) {
+ FgThread.getHandler().removeCallbacks(mDeliverLastLocationCallback);
+ }
+ mDeliverLastLocationCallback = new DeliverLastLocationRunnable();
+
+ Preconditions.checkState(mLastLocation != null);
+
+ if (deliverImmediate) {
+ FgThread.getHandler().post(mDeliverLastLocationCallback);
+ } else {
+ long delayMs = mThrottlingIntervalMs - mLastLocation.getElapsedRealtimeAgeMillis();
+ FgThread.getHandler().postDelayed(mDeliverLastLocationCallback, delayMs);
+ }
+ } else {
+ if (oldThrottlingIntervalMs != INTERVAL_DISABLED) {
+ mEventLog.logProviderStationaryThrottled(mName, false);
+ if (D) {
+ Log.d(TAG, mName + " provider stationary unthrottled");
+ }
+ }
+
+ FgThread.getHandler().removeCallbacks(mDeliverLastLocationCallback);
+ mDeliverLastLocationCallback = null;
+ }
+ }
+
+ @Override
+ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ if (mThrottlingIntervalMs != INTERVAL_DISABLED) {
+ pw.println("stationary throttled=" + mLastLocation);
+ } else {
+ pw.print("stationary throttled=false");
+ if (!mDeviceIdle) {
+ pw.print(" (not idle)");
+ }
+ if (!mDeviceStationary) {
+ pw.print(" (not stationary)");
+ }
+ pw.println();
+ }
+
+ mDelegate.dump(fd, pw, args);
+ }
+
+ private class DeliverLastLocationRunnable implements Runnable {
+ @Override
+ public void run() {
+ Location location;
+ synchronized (mLock) {
+ if (mDeliverLastLocationCallback != this) {
+ return;
+ }
+ if (mLastLocation == null) {
+ return;
+ }
+
+ location = new Location(mLastLocation);
+ location.setTime(System.currentTimeMillis());
+ location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
+ if (location.hasSpeed()) {
+ location.removeSpeed();
+ if (location.hasSpeedAccuracy()) {
+ location.removeSpeedAccuracy();
+ }
+ }
+ if (location.hasBearing()) {
+ location.removeBearing();
+ if (location.hasBearingAccuracy()) {
+ location.removeBearingAccuracy();
+ }
+ }
+
+ mLastLocation = location;
+ FgThread.getHandler().postDelayed(this, mThrottlingIntervalMs);
+ }
+
+ reportLocation(LocationResult.wrap(location));
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java b/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java
index 32d637ffa730..4c97f645aac9 100644
--- a/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java
+++ b/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java
@@ -140,7 +140,7 @@ public class ProxyLocationProvider extends AbstractLocationProvider {
}
@Override
- public void onSetRequest(ProviderRequest request) {
+ protected void onSetRequest(ProviderRequest request) {
mRequest = request;
mServiceWatcher.runOnBinder(binder -> {
ILocationProvider provider = ILocationProvider.Stub.asInterface(binder);
diff --git a/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java b/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java
index d48b9a4e7879..4f4b4f259762 100644
--- a/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java
+++ b/services/core/java/com/android/server/media/metrics/MediaMetricsManagerService.java
@@ -83,7 +83,14 @@ public final class MediaMetricsManagerService extends SystemService {
@Override
public void reportPlaybackStateEvent(
String sessionId, PlaybackStateEvent event, int userId) {
- // TODO: log it to statsd
+ StatsEvent statsEvent = StatsEvent.newBuilder()
+ .setAtomId(322)
+ .writeString(sessionId)
+ .writeInt(event.getState())
+ .writeLong(event.getTimeSinceCreatedMillis())
+ .usePooledBuffer()
+ .build();
+ StatsLog.write(statsEvent);
}
@Override
@@ -103,7 +110,7 @@ public final class MediaMetricsManagerService extends SystemService {
.writeString(event.getExceptionStack())
.writeInt(event.getErrorCode())
.writeInt(event.getSubErrorCode())
- .writeLong(event.getTimeSincePlaybackCreatedMillis())
+ .writeLong(event.getTimeSinceCreatedMillis())
.usePooledBuffer()
.build();
StatsLog.write(statsEvent);
diff --git a/services/core/java/com/android/server/om/OverlayManagerService.java b/services/core/java/com/android/server/om/OverlayManagerService.java
index 905733cf5c9b..dbd121137b57 100644
--- a/services/core/java/com/android/server/om/OverlayManagerService.java
+++ b/services/core/java/com/android/server/om/OverlayManagerService.java
@@ -1341,7 +1341,9 @@ public final class OverlayManagerService extends SystemService {
}
public void forgetAllPackageInfos(final int userId) {
- for (int i = 0, n = mCache.size(); i < n; i++) {
+ // Iterate in reverse order since removing the package in all users will remove the
+ // package from the cache.
+ for (int i = mCache.size() - 1; i >= 0; i--) {
removePackageUser(mCache.valueAt(i), userId);
}
}
diff --git a/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java b/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java
index fb183f57cac4..799ab4633b2a 100644
--- a/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java
+++ b/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java
@@ -244,7 +244,11 @@ final class OverlayManagerServiceImpl {
@NonNull
Set<PackageAndUser> onPackageAdded(@NonNull final String pkgName,
final int userId) throws OperationFailedException {
- return reconcileSettingsForPackage(pkgName, userId, 0 /* flags */);
+ final Set<PackageAndUser> updatedTargets = new ArraySet<>();
+ // Always update the overlays of newly added packages.
+ updatedTargets.add(new PackageAndUser(pkgName, userId));
+ updatedTargets.addAll(reconcileSettingsForPackage(pkgName, userId, 0 /* flags */));
+ return updatedTargets;
}
@NonNull
@@ -282,7 +286,7 @@ final class OverlayManagerServiceImpl {
private Set<PackageAndUser> removeOverlaysForUser(
@NonNull final Predicate<OverlayInfo> condition, final int userId) {
final List<OverlayInfo> overlays = mSettings.removeIf(
- io -> userId == io.userId && condition.test(io) );
+ io -> userId == io.userId && condition.test(io));
Set<PackageAndUser> targets = Collections.emptySet();
for (int i = 0, n = overlays.size(); i < n; i++) {
final OverlayInfo info = overlays.get(i);
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index b06e84d9df4e..d3a56c6f67c0 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -22,6 +22,7 @@ import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
import static android.content.pm.LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS;
import static android.content.pm.LauncherApps.FLAG_CACHE_NOTIFICATION_SHORTCUTS;
+import static android.content.pm.LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1170,6 +1171,8 @@ public class LauncherAppsService extends SystemService {
ret = ShortcutInfo.FLAG_CACHED_NOTIFICATIONS;
} else if (cacheFlags == FLAG_CACHE_BUBBLE_SHORTCUTS) {
ret = ShortcutInfo.FLAG_CACHED_BUBBLES;
+ } else if (cacheFlags == FLAG_CACHE_PEOPLE_TILE_SHORTCUTS) {
+ ret = ShortcutInfo.FLAG_CACHED_PEOPLE_TILE;
}
Preconditions.checkArgumentPositive(ret, "Invalid cache owner");
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 7b9cf734fd30..e6789d4ba8ac 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -193,7 +193,6 @@ import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.KeySet;
import android.content.pm.ModuleInfo;
-import android.content.pm.overlay.OverlayPaths;
import android.content.pm.PackageChangeEvent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfoLite;
@@ -462,6 +461,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.function.Predicate;
/**
@@ -2586,49 +2586,42 @@ public class PackageManagerService extends IPackageManager.Stub
Intent intent, int matchFlags, List<ResolveInfo> candidates,
CrossProfileDomainInfo xpDomainInfo, int userId, boolean debug) {
final ArrayList<ResolveInfo> result = new ArrayList<>();
- final ArrayList<ResolveInfo> alwaysList = new ArrayList<>();
- final ArrayList<ResolveInfo> undefinedList = new ArrayList<>();
final ArrayList<ResolveInfo> matchAllList = new ArrayList<>();
+
final int count = candidates.size();
- // First, try to use linked apps. Partition the candidates into four lists:
- // one for the final results, one for the "do not use ever", one for "undefined status"
- // and finally one for "browser app type".
- for (int n=0; n<count; n++) {
+ // First, try to use approved apps.
+ for (int n = 0; n < count; n++) {
ResolveInfo info = candidates.get(n);
- String packageName = info.activityInfo.packageName;
- PackageSetting ps = mSettings.getPackageLPr(packageName);
- if (ps != null) {
- // Add to the special match all list (Browser use case)
- if (info.handleAllWebDataURI) {
- matchAllList.add(info);
- continue;
- }
-
- boolean isAlways = mDomainVerificationManager
- .isApprovedForDomain(ps, intent, userId);
- if (isAlways) {
- alwaysList.add(info);
- } else {
- undefinedList.add(info);
- }
- continue;
+ // Add to the special match all list (Browser use case)
+ if (info.handleAllWebDataURI) {
+ matchAllList.add(info);
}
}
+ Pair<List<ResolveInfo>, Integer> infosAndLevel = mDomainVerificationManager
+ .filterToApprovedApp(intent, candidates, userId, mSettings::getPackageLPr);
+ List<ResolveInfo> approvedInfos = infosAndLevel.first;
+ Integer highestApproval = infosAndLevel.second;
+
// We'll want to include browser possibilities in a few cases
boolean includeBrowser = false;
- // First try to add the "always" resolution(s) for the current user, if any
- if (alwaysList.size() > 0) {
- result.addAll(alwaysList);
+ // If no apps are approved for the domain, resolve only to browsers
+ if (approvedInfos.isEmpty()) {
+ // If the other profile has a result, include that and delegate to ResolveActivity
+ if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel
+ > DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE) {
+ result.add(xpDomainInfo.resolveInfo);
+ } else {
+ includeBrowser = true;
+ }
} else {
- // Add all undefined apps as we want them to appear in the disambiguation dialog.
- result.addAll(undefinedList);
- // Maybe add one for the other profile.
- if (xpDomainInfo != null && xpDomainInfo.wereAnyDomainsVerificationApproved) {
+ result.addAll(approvedInfos);
+
+ // If the other profile has an app that's of equal or higher approval, add it
+ if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel >= highestApproval) {
result.add(xpDomainInfo.resolveInfo);
}
- includeBrowser = true;
}
if (includeBrowser) {
@@ -2676,9 +2669,7 @@ public class PackageManagerService extends IPackageManager.Stub
}
}
- // If there is nothing selected, add all candidates and remove the ones that the
- //user
- // has explicitly put into the INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER state
+ // If there is nothing selected, add all candidates
if (result.size() == 0) {
result.addAll(candidates);
}
@@ -2780,10 +2771,12 @@ public class PackageManagerService extends IPackageManager.Stub
sourceUserId, parentUserId);
}
- result.wereAnyDomainsVerificationApproved |= mDomainVerificationManager
- .isApprovedForDomain(ps, intent, riTargetUser.targetUserId);
+ result.highestApprovalLevel = Math.max(mDomainVerificationManager
+ .approvalLevelForDomain(ps, intent, riTargetUser.targetUserId),
+ result.highestApprovalLevel);
}
- if (result != null && !result.wereAnyDomainsVerificationApproved) {
+ if (result != null && result.highestApprovalLevel
+ <= DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE) {
return null;
}
return result;
@@ -3026,9 +3019,10 @@ public class PackageManagerService extends IPackageManager.Stub
final String packageName = info.activityInfo.packageName;
final PackageSetting ps = mSettings.getPackageLPr(packageName);
if (ps.getInstantApp(userId)) {
- if (mDomainVerificationManager.isApprovedForDomain(ps, intent, userId)) {
+ if (hasAnyDomainApproval(mDomainVerificationManager, ps, intent,
+ userId)) {
if (DEBUG_INSTANT) {
- Slog.v(TAG, "Instant app approvd for intent; pkg: "
+ Slog.v(TAG, "Instant app approved for intent; pkg: "
+ packageName);
}
localInstantApp = info;
@@ -3953,7 +3947,8 @@ public class PackageManagerService extends IPackageManager.Stub
if (ps != null) {
// only check domain verification status if the app is not a browser
if (!info.handleAllWebDataURI) {
- if (mDomainVerificationManager.isApprovedForDomain(ps, intent, userId)) {
+ if (hasAnyDomainApproval(mDomainVerificationManager, ps, intent,
+ userId)) {
if (DEBUG_INSTANT) {
Slog.v(TAG, "DENY instant app;" + " pkg: " + packageName
+ ", approved");
@@ -9369,8 +9364,8 @@ public class PackageManagerService extends IPackageManager.Stub
if (ri.activityInfo.applicationInfo.isInstantApp()) {
final String packageName = ri.activityInfo.packageName;
final PackageSetting ps = mSettings.getPackageLPr(packageName);
- if (ps != null && mDomainVerificationManager
- .isApprovedForDomain(ps, intent, userId)) {
+ if (ps != null && hasAnyDomainApproval(mDomainVerificationManager, ps,
+ intent, userId)) {
return ri;
}
}
@@ -9420,6 +9415,19 @@ public class PackageManagerService extends IPackageManager.Stub
}
/**
+ * Do NOT use for intent resolution filtering. That should be done with
+ * {@link DomainVerificationManagerInternal#filterToApprovedApp(Intent, List, int, Function)}.
+ *
+ * @return if the package is approved at any non-zero level for the domain in the intent
+ */
+ private static boolean hasAnyDomainApproval(
+ @NonNull DomainVerificationManagerInternal manager, @NonNull PackageSetting pkgSetting,
+ @NonNull Intent intent, @UserIdInt int userId) {
+ return manager.approvalLevelForDomain(pkgSetting, intent, userId)
+ > DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE;
+ }
+
+ /**
* Return true if the given list is not empty and all of its contents have
* an activityInfo with the given package name.
*/
@@ -9862,7 +9870,7 @@ public class PackageManagerService extends IPackageManager.Stub
private static class CrossProfileDomainInfo {
/* ResolveInfo for IntentForwarderActivity to send the intent to the other profile */
ResolveInfo resolveInfo;
- boolean wereAnyDomainsVerificationApproved;
+ int highestApprovalLevel = DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE;
}
private CrossProfileDomainInfo getCrossProfileDomainPreferredLpr(Intent intent,
@@ -25917,6 +25925,17 @@ public class PackageManagerService extends IPackageManager.Stub
}
@Override
+ public boolean isPackageDebuggable(String packageName) throws RemoteException {
+ int callingUser = UserHandle.getCallingUserId();
+ ApplicationInfo appInfo = getApplicationInfo(packageName, 0, callingUser);
+ if (appInfo != null) {
+ return (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
+ }
+
+ throw new RemoteException("Couldn't get debug flag for package " + packageName);
+ }
+
+ @Override
public boolean[] isAudioPlaybackCaptureAllowed(String[] packageNames)
throws RemoteException {
int callingUser = UserHandle.getUserId(Binder.getCallingUid());
diff --git a/services/core/java/com/android/server/pm/PackageSettingBase.java b/services/core/java/com/android/server/pm/PackageSettingBase.java
index 5364cbfede86..a83a3f81bc00 100644
--- a/services/core/java/com/android/server/pm/PackageSettingBase.java
+++ b/services/core/java/com/android/server/pm/PackageSettingBase.java
@@ -783,6 +783,10 @@ public abstract class PackageSettingBase extends SettingBase {
incrementalStates.onStorageHealthStatusChanged(status);
}
+ public long getFirstInstallTime() {
+ return firstInstallTime;
+ }
+
protected PackageSettingBase updateFrom(PackageSettingBase other) {
super.copyFrom(other);
setPath(other.getPath());
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index a8a6bcec2313..2112247650a5 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -72,7 +72,6 @@ import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
-import android.os.incremental.IncrementalManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.service.pm.PackageServiceDumpProto;
@@ -2615,6 +2614,8 @@ public final class Settings implements Watchable, Snappable {
} else {
serializer.attributeInt(null, "sharedUserId", pkg.appId);
}
+ serializer.attributeFloat(null, "loadingProgress",
+ pkg.getIncrementalStates().getProgress());
writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions);
@@ -3389,6 +3390,9 @@ public final class Settings implements Watchable, Snappable {
if (ps.appId <= 0) {
ps.appId = parser.getAttributeInt(null, "sharedUserId", 0);
}
+ final float loadingProgress =
+ parser.getAttributeFloat(null, "loadingProgress", 0);
+ ps.setLoadingProgress(loadingProgress);
int outerDepth = parser.getDepth();
int type;
@@ -4582,7 +4586,7 @@ public final class Settings implements Watchable, Snappable {
pw.print(prefix); pw.print(" installerAttributionTag=");
pw.println(ps.installSource.installerAttributionTag);
}
- if (IncrementalManager.isIncrementalPath(ps.getPathString())) {
+ if (ps.isPackageLoading()) {
pw.print(prefix); pw.println(" loadingProgress="
+ (int) (ps.getIncrementalStates().getProgress() * 100) + "%");
}
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java
index 37dfea4ee0f3..5ee612b6d55f 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java
@@ -125,8 +125,10 @@ public class AndroidPackageUtils {
public static void validatePackageDexMetadata(AndroidPackage pkg)
throws PackageParserException {
Collection<String> apkToDexMetadataList = getPackageDexMetadata(pkg).values();
+ String packageName = pkg.getPackageName();
+ long versionCode = pkg.toAppInfoWithoutState().longVersionCode;
for (String dexMetadata : apkToDexMetadataList) {
- DexMetadataHelper.validateDexMetadataFile(dexMetadata);
+ DexMetadataHelper.validateDexMetadataFile(dexMetadata, packageName, versionCode);
}
}
diff --git a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationDebug.java b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationDebug.java
index 1925590112f8..b3108c58a11e 100644
--- a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationDebug.java
+++ b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationDebug.java
@@ -38,8 +38,6 @@ import com.android.server.pm.verify.domain.models.DomainVerificationStateMap;
import com.android.server.pm.verify.domain.models.DomainVerificationUserState;
import java.util.Arrays;
-import java.util.Objects;
-import java.util.Set;
import java.util.function.Function;
@SuppressWarnings("PointlessBooleanExpression")
@@ -202,8 +200,7 @@ public class DomainVerificationDebug {
printedHeader = true;
}
- boolean isLinkHandlingAllowed = userState == null
- || !userState.isDisallowLinkHandling();
+ boolean isLinkHandlingAllowed = userState == null || userState.isLinkHandlingAllowed();
writer.increaseIndent();
writer.print("User ");
diff --git a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationManagerInternal.java b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationManagerInternal.java
index 50fd6e3ddea1..5d4370ae5dd4 100644
--- a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationManagerInternal.java
+++ b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationManagerInternal.java
@@ -16,18 +16,22 @@
package com.android.server.pm.verify.domain;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.UserIdInt;
import android.content.Intent;
import android.content.pm.IntentFilterVerificationInfo;
+import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
import android.content.pm.verify.domain.DomainVerificationInfo;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.os.Binder;
import android.os.UserHandle;
import android.util.IndentingPrintWriter;
+import android.util.Pair;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
@@ -39,6 +43,7 @@ import com.android.server.pm.verify.domain.proxy.DomainVerificationProxy;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
@@ -48,6 +53,78 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
UUID DISABLED_ID = new UUID(0, 0);
/**
+ * The app has not been approved for this domain and should never be able to open it through
+ * an implicit web intent.
+ */
+ int APPROVAL_LEVEL_NONE = 0;
+
+ /**
+ * The app has been approved through the legacy
+ * {@link PackageManager#updateIntentVerificationStatusAsUser(String, int, int)} API, which has
+ * been preserved for migration purposes, but is otherwise ignored. Corresponds to
+ * {@link PackageManager#INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} and
+ * {@link PackageManager#INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK}.
+ *
+ * This should be used as the cutoff for showing a picker if no better approved app exists
+ * during the legacy transition period.
+ *
+ * TODO(b/177923646): The legacy values can be removed once the Settings API changes are
+ * shipped. These values are not stable, so just deleting the constant and shifting others is
+ * fine.
+ */
+ int APPROVAL_LEVEL_LEGACY_ASK = 1;
+
+ /**
+ * The app has been approved through the legacy
+ * {@link PackageManager#updateIntentVerificationStatusAsUser(String, int, int)} API, which has
+ * been preserved for migration purposes, but is otherwise ignored. Corresponds to
+ * {@link PackageManager#INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS}.
+ */
+ int APPROVAL_LEVEL_LEGACY_ALWAYS = 1;
+
+ /**
+ * The app has been chosen by the user through
+ * {@link #setDomainVerificationUserSelection(UUID, Set, boolean)}, indictag an explicit
+ * choice to use this app to open an unverified domain.
+ */
+ int APPROVAL_LEVEL_SELECTION = 2;
+
+ /**
+ * The app is approved through the digital asset link statement being hosted at the domain
+ * it is capturing. This is set through {@link #setDomainVerificationStatus(UUID, Set, int)} by
+ * the domain verification agent on device.
+ */
+ int APPROVAL_LEVEL_VERIFIED = 3;
+
+ /**
+ * The app has been installed as an instant app, which grants it total authority on the domains
+ * that it declares. It is expected that the package installer validate the domains the app
+ * declares against the digital asset link statements before allowing it to be installed.
+ *
+ * The user is still able to disable instant app link handling through
+ * {@link #setDomainVerificationLinkHandlingAllowed(String, boolean)}.
+ */
+ int APPROVAL_LEVEL_INSTANT_APP = 4;
+
+ /**
+ * Defines the possible values for {@link #approvalLevelForDomain(PackageSetting, Intent, int)}
+ * which sorts packages by approval priority. A higher numerical value means the package should
+ * override all lower values. This means that comparison using less/greater than IS valid.
+ *
+ * Negative values are possible, although not implemented, reserved if explicit disable of a
+ * package for a domain needs to be tracked.
+ */
+ @IntDef({
+ APPROVAL_LEVEL_NONE,
+ APPROVAL_LEVEL_LEGACY_ASK,
+ APPROVAL_LEVEL_LEGACY_ALWAYS,
+ APPROVAL_LEVEL_SELECTION,
+ APPROVAL_LEVEL_VERIFIED,
+ APPROVAL_LEVEL_INSTANT_APP
+ })
+ @interface ApprovalLevel{}
+
+ /**
* Generate a new domain set ID to be used for attaching new packages.
*/
@NonNull
@@ -211,11 +288,28 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
DomainVerificationCollector getCollector();
/**
- * Check if a resolving URI is approved to takeover the domain as the sole resolved target.
+ * Filters the provided list down to the {@link ResolveInfo} objects that should be allowed
+ * to open the domain inside the {@link Intent}. It is possible for no packages represented in
+ * the list to be approved, in which case an empty list will be returned.
+ *
+ * @return the filtered list and the corresponding approval level
+ */
+ @NonNull
+ Pair<List<ResolveInfo>, Integer> filterToApprovedApp(@NonNull Intent intent,
+ @NonNull List<ResolveInfo> infos, @UserIdInt int userId,
+ @NonNull Function<String, PackageSetting> pkgSettingFunction);
+
+ /**
+ * Check at what precedence a package resolving a URI is approved to takeover the domain.
* This can be because the domain was auto-verified for the package, or if the user manually
- * chose to enable the domain for the package.
+ * chose to enable the domain for the package. If an app is auto-verified, it will be
+ * preferred over apps that were manually selected.
+ *
+ * NOTE: This should not be used for filtering intent resolution. See
+ * {@link #filterToApprovedApp(Intent, List, int, Function)} for that.
*/
- boolean isApprovedForDomain(@NonNull PackageSetting pkgSetting, @NonNull Intent intent,
+ @ApprovalLevel
+ int approvalLevelForDomain(@NonNull PackageSetting pkgSetting, @NonNull Intent intent,
@UserIdInt int userId);
/**
@@ -231,8 +325,7 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
throws IllegalArgumentException, NameNotFoundException;
- interface Connection extends DomainVerificationEnforcer.Callback,
- Function<String, PackageSetting> {
+ interface Connection extends DomainVerificationEnforcer.Callback {
/**
* Notify that a settings change has been made and that eventually
@@ -265,10 +358,5 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
@Nullable
AndroidPackage getPackageLocked(@NonNull String pkgName);
-
- @Override
- default PackageSetting apply(@NonNull String pkgName) {
- return getPackageSettingLocked(pkgName);
- }
}
}
diff --git a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationPersistence.java b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationPersistence.java
index 679f948bb3de..c864b2937f6b 100644
--- a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationPersistence.java
+++ b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationPersistence.java
@@ -53,7 +53,7 @@ public class DomainVerificationPersistence {
public static final String TAG_USER_STATE = "user-state";
public static final String ATTR_USER_ID = "userId";
- public static final String ATTR_DISALLOW_LINK_HANDLING = "disallowLinkHandling";
+ public static final String ATTR_ALLOW_LINK_HANDLING = "allowLinkHandling";
public static final String TAG_ENABLED_HOSTS = "enabled-hosts";
public static final String TAG_HOST = "host";
@@ -252,7 +252,7 @@ public class DomainVerificationPersistence {
return null;
}
- boolean disallowLinkHandling = section.getBoolean(ATTR_DISALLOW_LINK_HANDLING);
+ boolean allowLinkHandling = section.getBoolean(ATTR_ALLOW_LINK_HANDLING, true);
ArraySet<String> enabledHosts = new ArraySet<>();
SettingsXml.ChildSection child = section.children();
@@ -260,7 +260,7 @@ public class DomainVerificationPersistence {
readEnabledHosts(child, enabledHosts);
}
- return new DomainVerificationUserState(userId, enabledHosts, disallowLinkHandling);
+ return new DomainVerificationUserState(userId, enabledHosts, allowLinkHandling);
}
private static void readEnabledHosts(@NonNull SettingsXml.ReadSection section,
@@ -279,8 +279,8 @@ public class DomainVerificationPersistence {
try (SettingsXml.WriteSection section =
parentSection.startSection(TAG_USER_STATE)
.attribute(ATTR_USER_ID, userState.getUserId())
- .attribute(ATTR_DISALLOW_LINK_HANDLING,
- userState.isDisallowLinkHandling())) {
+ .attribute(ATTR_ALLOW_LINK_HANDLING,
+ userState.isLinkHandlingAllowed())) {
ArraySet<String> enabledHosts = userState.getEnabledHosts();
if (!enabledHosts.isEmpty()) {
try (SettingsXml.WriteSection enabledHostsSection =
diff --git a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java
index fa0327414914..86a92d792026 100644
--- a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java
+++ b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java
@@ -16,6 +16,8 @@
package com.android.server.pm.verify.domain;
+import static java.util.Collections.emptyList;
+
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -26,6 +28,8 @@ import android.content.Intent;
import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.pm.parsing.component.ParsedActivity;
import android.content.pm.verify.domain.DomainVerificationInfo;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.pm.verify.domain.DomainVerificationState;
@@ -35,6 +39,7 @@ import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
+import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
@@ -62,6 +67,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
@@ -401,7 +407,7 @@ public class DomainVerificationService extends SystemService
}
pkgState.getOrCreateUserSelectionState(userId)
- .setDisallowLinkHandling(!allowed);
+ .setLinkHandlingAllowed(allowed);
}
mConnection.scheduleWriteSettings();
@@ -423,11 +429,11 @@ public class DomainVerificationService extends SystemService
for (int userStateIndex = 0; userStateIndex < userStatesSize;
userStateIndex++) {
userStates.valueAt(userStateIndex)
- .setDisallowLinkHandling(!allowed);
+ .setLinkHandlingAllowed(allowed);
}
} else {
pkgState.getOrCreateUserSelectionState(userId)
- .setDisallowLinkHandling(!allowed);
+ .setLinkHandlingAllowed(allowed);
}
}
@@ -440,7 +446,7 @@ public class DomainVerificationService extends SystemService
}
pkgState.getOrCreateUserSelectionState(userId)
- .setDisallowLinkHandling(!allowed);
+ .setLinkHandlingAllowed(allowed);
}
}
@@ -468,6 +474,17 @@ public class DomainVerificationService extends SystemService
throw new InvalidDomainSetException(domainSetId, null,
InvalidDomainSetException.REASON_ID_INVALID);
}
+
+ if (enabled) {
+ for (String domain : domains) {
+ if (!getApprovedPackages(domain, userId, APPROVAL_LEVEL_LEGACY_ALWAYS + 1,
+ mConnection::getPackageSettingLocked).first.isEmpty()) {
+ throw new InvalidDomainSetException(domainSetId, null,
+ InvalidDomainSetException.REASON_UNABLE_TO_APPROVE);
+ }
+ }
+ }
+
DomainVerificationPkgState pkgState = getAndValidateAttachedLocked(domainSetId, domains,
false /* forAutoVerify */, callingUid, userId);
DomainVerificationUserState userState = pkgState.getOrCreateUserSelectionState(userId);
@@ -589,10 +606,10 @@ public class DomainVerificationService extends SystemService
hostToUserSelectionMap.put(domains.valueAt(index), false);
}
- boolean openVerifiedLinks = false;
DomainVerificationUserState userState = pkgState.getUserSelectionState(userId);
+ boolean linkHandlingAllowed = true;
if (userState != null) {
- openVerifiedLinks = !userState.isDisallowLinkHandling();
+ linkHandlingAllowed = userState.isLinkHandlingAllowed();
ArraySet<String> enabledHosts = userState.getEnabledHosts();
int hostsSize = enabledHosts.size();
for (int index = 0; index < hostsSize; index++) {
@@ -601,7 +618,7 @@ public class DomainVerificationService extends SystemService
}
return new DomainVerificationUserSelection(pkgState.getId(), packageName,
- UserHandle.of(userId), openVerifiedLinks, hostToUserSelectionMap);
+ UserHandle.of(userId), linkHandlingAllowed, hostToUserSelectionMap);
}
}
@@ -683,7 +700,7 @@ public class DomainVerificationService extends SystemService
ArraySet<String> newEnabledHosts = new ArraySet<>(oldEnabledHosts);
newEnabledHosts.retainAll(newWebDomains);
DomainVerificationUserState newUserState = new DomainVerificationUserState(
- userId, newEnabledHosts, oldUserState.isDisallowLinkHandling());
+ userId, newEnabledHosts, oldUserState.isLinkHandlingAllowed());
newUserStates.put(userId, newUserState);
}
}
@@ -910,7 +927,7 @@ public class DomainVerificationService extends SystemService
// This method is only used by DomainVerificationShell, which doesn't lock PMS, so it's
// safe to pass mConnection directly here and lock PMS. This method is not exposed
// to the general system server/PMS.
- printState(writer, packageName, userId, mConnection);
+ printState(writer, packageName, userId, mConnection::getPackageSettingLocked);
}
@Override
@@ -919,7 +936,7 @@ public class DomainVerificationService extends SystemService
@Nullable Function<String, PackageSetting> pkgSettingFunction)
throws NameNotFoundException {
if (pkgSettingFunction == null) {
- pkgSettingFunction = mConnection;
+ pkgSettingFunction = mConnection::getPackageSettingLocked;
}
synchronized (mLock) {
@@ -1156,46 +1173,211 @@ public class DomainVerificationService extends SystemService
mConnection.scheduleWriteSettings();
}
+ /**
+ * {@inheritDoc}
+ *
+ * Resolving an Intent to an approved app happens in stages:
+ * <ol>
+ * <li>Find all non-zero approved packages for the {@link Intent}'s domain</li>
+ * <li>Filter to packages with the highest approval level, see {@link ApprovalLevel}</li>
+ * <li>Filter out {@link ResolveInfo}s that don't match that approved packages</li>
+ * <li>Take the approved packages with the latest install time</li>
+ * <li>Take the ResolveInfo representing the Activity declared last in the manifest</li>
+ * <li>Return remaining results if any exist</li>
+ * </ol>
+ */
+ @NonNull
+ @Override
+ public Pair<List<ResolveInfo>, Integer> filterToApprovedApp(@NonNull Intent intent,
+ @NonNull List<ResolveInfo> infos, @UserIdInt int userId,
+ @NonNull Function<String, PackageSetting> pkgSettingFunction) {
+ String domain = intent.getData().getHost();
+
+ // Collect package names
+ ArrayMap<String, Integer> packageApprovals = new ArrayMap<>();
+ int infosSize = infos.size();
+ for (int index = 0; index < infosSize; index++) {
+ packageApprovals.put(infos.get(index).getComponentInfo().packageName,
+ APPROVAL_LEVEL_NONE);
+ }
+
+ // Find all approval levels
+ int highestApproval = fillMapWithApprovalLevels(packageApprovals, domain, userId,
+ pkgSettingFunction);
+ if (highestApproval == APPROVAL_LEVEL_NONE) {
+ return Pair.create(emptyList(), highestApproval);
+ }
+
+ // Filter to highest, non-zero packages
+ ArraySet<String> approvedPackages = new ArraySet<>();
+ for (int index = 0; index < infosSize; index++) {
+ if (packageApprovals.valueAt(index) == highestApproval) {
+ approvedPackages.add(packageApprovals.keyAt(index));
+ }
+ }
+
+ ArraySet<String> filteredPackages = new ArraySet<>();
+ if (highestApproval == APPROVAL_LEVEL_LEGACY_ASK) {
+ // To maintain legacy behavior while the Settings API is not implemented,
+ // show the chooser if all approved apps are marked ask, skipping the
+ // last app, last declaration filtering.
+ filteredPackages.addAll(approvedPackages);
+ } else {
+ // Filter to last installed package
+ long latestInstall = Long.MIN_VALUE;
+ int approvedSize = approvedPackages.size();
+ for (int index = 0; index < approvedSize; index++) {
+ String packageName = approvedPackages.valueAt(index);
+ PackageSetting pkgSetting = pkgSettingFunction.apply(packageName);
+ if (pkgSetting == null) {
+ continue;
+ }
+ long installTime = pkgSetting.getFirstInstallTime();
+ if (installTime > latestInstall) {
+ latestInstall = installTime;
+ filteredPackages.clear();
+ filteredPackages.add(packageName);
+ } else if (installTime == latestInstall) {
+ filteredPackages.add(packageName);
+ }
+ }
+ }
+
+ // Filter to approved ResolveInfos
+ ArrayMap<String, List<ResolveInfo>> approvedInfos = new ArrayMap<>();
+ for (int index = 0; index < infosSize; index++) {
+ ResolveInfo info = infos.get(index);
+ String packageName = info.getComponentInfo().packageName;
+ if (filteredPackages.contains(packageName)) {
+ List<ResolveInfo> infosPerPackage = approvedInfos.get(packageName);
+ if (infosPerPackage == null) {
+ infosPerPackage = new ArrayList<>();
+ approvedInfos.put(packageName, infosPerPackage);
+ }
+ infosPerPackage.add(info);
+ }
+ }
+
+ List<ResolveInfo> finalList;
+ if (highestApproval == APPROVAL_LEVEL_LEGACY_ASK) {
+ // If legacy ask, skip the last declaration filtering
+ finalList = new ArrayList<>();
+ int size = approvedInfos.size();
+ for (int index = 0; index < size; index++) {
+ finalList.addAll(approvedInfos.valueAt(index));
+ }
+ } else {
+ // Find the last declared ResolveInfo per package
+ finalList = filterToLastDeclared(approvedInfos, pkgSettingFunction);
+ }
+
+ return Pair.create(finalList, highestApproval);
+ }
+
+ /**
+ * @return highest approval level found
+ */
+ private int fillMapWithApprovalLevels(@NonNull ArrayMap<String, Integer> inputMap,
+ @NonNull String domain, @UserIdInt int userId,
+ @NonNull Function<String, PackageSetting> pkgSettingFunction) {
+ int highestApproval = APPROVAL_LEVEL_NONE;
+ int size = inputMap.size();
+ for (int index = 0; index < size; index++) {
+ String packageName = inputMap.keyAt(index);
+ PackageSetting pkgSetting = pkgSettingFunction.apply(packageName);
+ if (pkgSetting == null) {
+ inputMap.setValueAt(index, APPROVAL_LEVEL_NONE);
+ continue;
+ }
+ int approval = approvalLevelForDomain(pkgSetting, domain, userId, domain);
+ highestApproval = Math.max(highestApproval, approval);
+ inputMap.setValueAt(index, approval);
+ }
+
+ return highestApproval;
+ }
+
+ @NonNull
+ private List<ResolveInfo> filterToLastDeclared(
+ @NonNull ArrayMap<String, List<ResolveInfo>> inputMap,
+ @NonNull Function<String, PackageSetting> pkgSettingFunction) {
+ List<ResolveInfo> finalList = new ArrayList<>(inputMap.size());
+
+ int inputSize = inputMap.size();
+ for (int inputIndex = 0; inputIndex < inputSize; inputIndex++) {
+ String packageName = inputMap.keyAt(inputIndex);
+ List<ResolveInfo> infos = inputMap.valueAt(inputIndex);
+ PackageSetting pkgSetting = pkgSettingFunction.apply(packageName);
+ AndroidPackage pkg = pkgSetting == null ? null : pkgSetting.getPkg();
+ if (pkg == null) {
+ continue;
+ }
+
+ ResolveInfo result = null;
+ int highestIndex = -1;
+ int infosSize = infos.size();
+ for (int infoIndex = 0; infoIndex < infosSize; infoIndex++) {
+ ResolveInfo info = infos.get(infoIndex);
+ List<ParsedActivity> activities = pkg.getActivities();
+ int activitiesSize = activities.size();
+ for (int activityIndex = 0; activityIndex < activitiesSize; activityIndex++) {
+ if (Objects.equals(activities.get(activityIndex).getComponentName(),
+ info.getComponentInfo().getComponentName())) {
+ if (activityIndex > highestIndex) {
+ highestIndex = activityIndex;
+ result = info;
+ }
+ break;
+ }
+ }
+ }
+
+ // Shouldn't be null, but might as well be safe
+ if (result != null) {
+ finalList.add(result);
+ }
+ }
+
+ return finalList;
+ }
+
@Override
- public boolean isApprovedForDomain(@NonNull PackageSetting pkgSetting, @NonNull Intent intent,
+ public int approvalLevelForDomain(@NonNull PackageSetting pkgSetting, @NonNull Intent intent,
@UserIdInt int userId) {
String packageName = pkgSetting.name;
if (!DomainVerificationUtils.isDomainVerificationIntent(intent)) {
if (DEBUG_APPROVAL) {
debugApproval(packageName, intent, userId, false, "not valid intent");
}
- return false;
+ return APPROVAL_LEVEL_NONE;
}
- String host = intent.getData().getHost();
+ return approvalLevelForDomain(pkgSetting, intent.getData().getHost(), userId, intent);
+ }
+
+ /**
+ * @param debugObject Should be an {@link Intent} if checking for resolution or a {@link String}
+ * otherwise.
+ */
+ private int approvalLevelForDomain(@NonNull PackageSetting pkgSetting, @NonNull String host,
+ @UserIdInt int userId, @NonNull Object debugObject) {
+ String packageName = pkgSetting.name;
final AndroidPackage pkg = pkgSetting.getPkg();
// Should never be null, but if it is, skip this and assume that v2 is enabled
- if (pkg != null) {
- // To allow an instant app to immediately open domains after being installed by the
- // user, auto approve them for any declared autoVerify domains.
- if (pkgSetting.getInstantApp(userId)
- && mCollector.collectAutoVerifyDomains(pkg).contains(host)) {
- return true;
- }
-
- if (!DomainVerificationUtils.isChangeEnabled(mPlatformCompat, pkg, SETTINGS_API_V2)) {
- int legacyState = mLegacySettings.getUserState(packageName, userId);
- switch (legacyState) {
- case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED:
- // If nothing specifically set, assume v2 rules
- break;
- case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK:
- case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS:
- case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK:
- // With v2 split into 2 lists, always and undefined, the concept of whether
- // or not to ask is irrelevant. Assume the user wants this application to
- // open the domain.
- return true;
- case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER:
- // Never has the same semantics are before
- return false;
- }
+ if (pkg != null && !DomainVerificationUtils.isChangeEnabled(mPlatformCompat, pkg,
+ SETTINGS_API_V2)) {
+ switch (mLegacySettings.getUserState(packageName, userId)) {
+ case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED:
+ // If nothing specifically set, assume v2 rules
+ break;
+ case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER:
+ return APPROVAL_LEVEL_NONE;
+ case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK:
+ case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK:
+ return APPROVAL_LEVEL_LEGACY_ASK;
+ case PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS:
+ return APPROVAL_LEVEL_LEGACY_ALWAYS;
}
}
@@ -1203,59 +1385,76 @@ public class DomainVerificationService extends SystemService
DomainVerificationPkgState pkgState = mAttachedPkgStates.get(packageName);
if (pkgState == null) {
if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, false, "pkgState unavailable");
+ debugApproval(packageName, debugObject, userId, false, "pkgState unavailable");
}
- return false;
+ return APPROVAL_LEVEL_NONE;
}
- ArrayMap<String, Integer> stateMap = pkgState.getStateMap();
DomainVerificationUserState userState = pkgState.getUserSelectionState(userId);
- // Only allow autoVerify approval if the user hasn't disabled it
- if (userState == null || !userState.isDisallowLinkHandling()) {
- // Check if the exact host matches
- Integer state = stateMap.get(host);
- if (state != null && DomainVerificationManager.isStateVerified(state)) {
- if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, true, "host verified exactly");
- }
- return true;
+ if (userState != null && !userState.isLinkHandlingAllowed()) {
+ if (DEBUG_APPROVAL) {
+ debugApproval(packageName, debugObject, userId, false,
+ "link handling not allowed");
}
+ return APPROVAL_LEVEL_NONE;
+ }
- // Otherwise see if the host matches a verified domain by wildcard
- int stateMapSize = stateMap.size();
- for (int index = 0; index < stateMapSize; index++) {
- if (!DomainVerificationManager.isStateVerified(stateMap.valueAt(index))) {
- continue;
- }
+ // The instant app branch must be run after the link handling check,
+ // since that should also disable instant apps if toggled
+ if (pkg != null) {
+ // To allow an instant app to immediately open domains after being installed by the
+ // user, auto approve them for any declared autoVerify domains.
+ if (pkgSetting.getInstantApp(userId)
+ && mCollector.collectAutoVerifyDomains(pkg).contains(host)) {
+ return APPROVAL_LEVEL_INSTANT_APP;
+ }
+ }
- String domain = stateMap.keyAt(index);
- if (domain.startsWith("*.") && host.endsWith(domain.substring(2))) {
- if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, true,
- "host verified by wildcard");
- }
- return true;
+ ArrayMap<String, Integer> stateMap = pkgState.getStateMap();
+ // Check if the exact host matches
+ Integer state = stateMap.get(host);
+ if (state != null && DomainVerificationManager.isStateVerified(state)) {
+ if (DEBUG_APPROVAL) {
+ debugApproval(packageName, debugObject, userId, true,
+ "host verified exactly");
+ }
+ return APPROVAL_LEVEL_VERIFIED;
+ }
+
+ // Otherwise see if the host matches a verified domain by wildcard
+ int stateMapSize = stateMap.size();
+ for (int index = 0; index < stateMapSize; index++) {
+ if (!DomainVerificationManager.isStateVerified(stateMap.valueAt(index))) {
+ continue;
+ }
+
+ String domain = stateMap.keyAt(index);
+ if (domain.startsWith("*.") && host.endsWith(domain.substring(2))) {
+ if (DEBUG_APPROVAL) {
+ debugApproval(packageName, debugObject, userId, true,
+ "host verified by wildcard");
}
+ return APPROVAL_LEVEL_VERIFIED;
}
}
// Check user state if available
if (userState == null) {
if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, false, "userState unavailable");
+ debugApproval(packageName, debugObject, userId, false, "userState unavailable");
}
- return false;
+ return APPROVAL_LEVEL_NONE;
}
// See if the user has approved the exact host
ArraySet<String> enabledHosts = userState.getEnabledHosts();
if (enabledHosts.contains(host)) {
if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, true,
+ debugApproval(packageName, debugObject, userId, true,
"host enabled by user exactly");
}
- return true;
+ return APPROVAL_LEVEL_SELECTION;
}
// See if the host matches a user selection by wildcard
@@ -1264,24 +1463,85 @@ public class DomainVerificationService extends SystemService
String domain = enabledHosts.valueAt(index);
if (domain.startsWith("*.") && host.endsWith(domain.substring(2))) {
if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, true,
+ debugApproval(packageName, debugObject, userId, true,
"host enabled by user through wildcard");
}
- return true;
+ return APPROVAL_LEVEL_SELECTION;
}
}
if (DEBUG_APPROVAL) {
- debugApproval(packageName, intent, userId, false, "not approved");
+ debugApproval(packageName, debugObject, userId, false, "not approved");
}
- return false;
+ return APPROVAL_LEVEL_NONE;
}
}
- private void debugApproval(@NonNull String packageName, @NonNull Intent intent,
+ /**
+ * @return the filtered list paired with the corresponding approval level
+ */
+ @NonNull
+ private Pair<List<String>, Integer> getApprovedPackages(@NonNull String domain,
+ @UserIdInt int userId, int minimumApproval,
+ @NonNull Function<String, PackageSetting> pkgSettingFunction) {
+ int highestApproval = minimumApproval;
+ List<String> approvedPackages = emptyList();
+
+ synchronized (mLock) {
+ final int size = mAttachedPkgStates.size();
+ for (int index = 0; index < size; index++) {
+ DomainVerificationPkgState pkgState = mAttachedPkgStates.valueAt(index);
+ String packageName = pkgState.getPackageName();
+ PackageSetting pkgSetting = pkgSettingFunction.apply(packageName);
+ if (pkgSetting == null) {
+ continue;
+ }
+
+ int level = approvalLevelForDomain(pkgSetting, domain, userId, domain);
+ if (level < minimumApproval) {
+ continue;
+ }
+
+ if (level > highestApproval) {
+ approvedPackages.clear();
+ approvedPackages = CollectionUtils.add(approvedPackages, packageName);
+ highestApproval = level;
+ } else if (level == highestApproval) {
+ approvedPackages = CollectionUtils.add(approvedPackages, packageName);
+ }
+ }
+ }
+
+ if (approvedPackages.isEmpty()) {
+ return Pair.create(approvedPackages, APPROVAL_LEVEL_NONE);
+ }
+
+ List<String> filteredPackages = new ArrayList<>();
+ long latestInstall = Long.MIN_VALUE;
+ final int approvedSize = approvedPackages.size();
+ for (int index = 0; index < approvedSize; index++) {
+ String packageName = approvedPackages.get(index);
+ PackageSetting pkgSetting = pkgSettingFunction.apply(packageName);
+ if (pkgSetting == null) {
+ continue;
+ }
+ long installTime = pkgSetting.getFirstInstallTime();
+ if (installTime > latestInstall) {
+ latestInstall = installTime;
+ filteredPackages.clear();
+ filteredPackages.add(packageName);
+ } else if (installTime == latestInstall) {
+ filteredPackages.add(packageName);
+ }
+ }
+
+ return Pair.create(filteredPackages, highestApproval);
+ }
+
+ private void debugApproval(@NonNull String packageName, @NonNull Object debugObject,
@UserIdInt int userId, boolean approved, @NonNull String reason) {
String approvalString = approved ? "approved" : "denied";
- Slog.d(TAG + "Approval", packageName + " was " + approvalString + " for " + intent
- + " for user " + userId + ": " + reason);
+ Slog.d(TAG + "Approval", packageName + " was " + approvalString + " for "
+ + debugObject + " for user " + userId + ": " + reason);
}
}
diff --git a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationSettings.java b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationSettings.java
index 073967e00134..a8e937cf2b90 100644
--- a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationSettings.java
+++ b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationSettings.java
@@ -23,7 +23,6 @@ import android.content.pm.verify.domain.DomainVerificationState;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
-import android.util.Pair;
import android.util.SparseArray;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
@@ -229,14 +228,14 @@ class DomainVerificationSettings {
DomainVerificationUserState oldUserState =
oldSelectionStates.get(UserHandle.USER_SYSTEM);
- boolean disallowLinkHandling = newUserState.isDisallowLinkHandling();
+ boolean linkHandlingAllowed = newUserState.isLinkHandlingAllowed();
if (oldUserState == null) {
oldUserState = new DomainVerificationUserState(UserHandle.USER_SYSTEM,
- newEnabledHosts, disallowLinkHandling);
+ newEnabledHosts, linkHandlingAllowed);
oldSelectionStates.put(UserHandle.USER_SYSTEM, oldUserState);
} else {
oldUserState.addHosts(newEnabledHosts)
- .setDisallowLinkHandling(disallowLinkHandling);
+ .setLinkHandlingAllowed(linkHandlingAllowed);
}
}
}
diff --git a/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationUserState.java b/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationUserState.java
index 8e8260899a48..22468640800e 100644
--- a/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationUserState.java
+++ b/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationUserState.java
@@ -25,10 +25,10 @@ import com.android.internal.util.DataClass;
import java.util.Set;
/**
- * Tracks which domains have been explicitly enabled by the user, allowing it to automatically open
- * that domain when a web URL Intent is sent ft.
+ * Tracks which domains have been explicitly enabled by the user, allowing it to open that domain
+ * when a web URL Intent is sent and the application is the highest priority for that domain.
*/
-@DataClass(genSetters = true, genEqualsHashCode = true, genToString = true)
+@DataClass(genSetters = true, genEqualsHashCode = true, genToString = true, genBuilder = false)
public class DomainVerificationUserState {
@UserIdInt
@@ -38,8 +38,10 @@ public class DomainVerificationUserState {
@NonNull
private final ArraySet<String> mEnabledHosts;
- /** Whether to disallow this package from automatically opening links by auto verification. */
- private boolean mDisallowLinkHandling;
+ /**
+ * Whether to allow this package to automatically open links by auto verification.
+ */
+ private boolean mLinkHandlingAllowed = true;
public DomainVerificationUserState(@UserIdInt int userId) {
mUserId = userId;
@@ -67,13 +69,15 @@ public class DomainVerificationUserState {
}
+
// Code below generated by codegen v1.0.22.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
- // $ codegen $ANDROID_BUILD_TOP/frameworks/base/services/core/java/com/android/server/pm/domain/verify/models/DomainVerificationUserState.java
+ // $ codegen $ANDROID_BUILD_TOP/frameworks/base/services/core/java/com/android/server/pm
+ // /verify/domain/models/DomainVerificationUserState.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
@@ -85,19 +89,21 @@ public class DomainVerificationUserState {
*
* @param enabledHosts
* List of domains which have been enabled by the user. *
+ * @param linkHandlingAllowed
+ * Whether to allow this package to automatically open links by auto verification.
*/
@DataClass.Generated.Member
public DomainVerificationUserState(
@UserIdInt int userId,
@NonNull ArraySet<String> enabledHosts,
- boolean disallowLinkHandling) {
+ boolean linkHandlingAllowed) {
this.mUserId = userId;
com.android.internal.util.AnnotationValidations.validate(
UserIdInt.class, null, mUserId);
this.mEnabledHosts = enabledHosts;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mEnabledHosts);
- this.mDisallowLinkHandling = disallowLinkHandling;
+ this.mLinkHandlingAllowed = linkHandlingAllowed;
// onConstructed(); // You can define this method to get a callback
}
@@ -115,14 +121,20 @@ public class DomainVerificationUserState {
return mEnabledHosts;
}
+ /**
+ * Whether to allow this package to automatically open links by auto verification.
+ */
@DataClass.Generated.Member
- public boolean isDisallowLinkHandling() {
- return mDisallowLinkHandling;
+ public boolean isLinkHandlingAllowed() {
+ return mLinkHandlingAllowed;
}
+ /**
+ * Whether to allow this package to automatically open links by auto verification.
+ */
@DataClass.Generated.Member
- public @NonNull DomainVerificationUserState setDisallowLinkHandling( boolean value) {
- mDisallowLinkHandling = value;
+ public @NonNull DomainVerificationUserState setLinkHandlingAllowed( boolean value) {
+ mLinkHandlingAllowed = value;
return this;
}
@@ -135,7 +147,7 @@ public class DomainVerificationUserState {
return "DomainVerificationUserState { " +
"userId = " + mUserId + ", " +
"enabledHosts = " + mEnabledHosts + ", " +
- "disallowLinkHandling = " + mDisallowLinkHandling +
+ "linkHandlingAllowed = " + mLinkHandlingAllowed +
" }";
}
@@ -154,7 +166,7 @@ public class DomainVerificationUserState {
return true
&& mUserId == that.mUserId
&& java.util.Objects.equals(mEnabledHosts, that.mEnabledHosts)
- && mDisallowLinkHandling == that.mDisallowLinkHandling;
+ && mLinkHandlingAllowed == that.mLinkHandlingAllowed;
}
@Override
@@ -166,15 +178,15 @@ public class DomainVerificationUserState {
int _hash = 1;
_hash = 31 * _hash + mUserId;
_hash = 31 * _hash + java.util.Objects.hashCode(mEnabledHosts);
- _hash = 31 * _hash + Boolean.hashCode(mDisallowLinkHandling);
+ _hash = 31 * _hash + Boolean.hashCode(mLinkHandlingAllowed);
return _hash;
}
@DataClass.Generated(
- time = 1608234273324L,
+ time = 1612894390039L,
codegenVersion = "1.0.22",
- sourceFile = "frameworks/base/services/core/java/com/android/server/pm/domain/verify/models/DomainVerificationUserState.java",
- inputSignatures = "private final @android.annotation.UserIdInt int mUserId\nprivate final @android.annotation.NonNull android.util.ArraySet<java.lang.String> mEnabledHosts\nprivate boolean mDisallowLinkHandling\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState addHosts(android.util.ArraySet<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState addHosts(java.util.Set<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState removeHosts(android.util.ArraySet<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState removeHosts(java.util.Set<java.lang.String>)\nclass DomainVerificationUserState extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genSetters=true, genEqualsHashCode=true, genToString=true)")
+ sourceFile = "frameworks/base/services/core/java/com/android/server/pm/verify/domain/models/DomainVerificationUserState.java",
+ inputSignatures = "private final @android.annotation.UserIdInt int mUserId\nprivate final @android.annotation.NonNull android.util.ArraySet<java.lang.String> mEnabledHosts\nprivate boolean mLinkHandlingAllowed\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState addHosts(android.util.ArraySet<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState addHosts(java.util.Set<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState removeHosts(android.util.ArraySet<java.lang.String>)\npublic com.android.server.pm.verify.domain.models.DomainVerificationUserState removeHosts(java.util.Set<java.lang.String>)\nclass DomainVerificationUserState extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genSetters=true, genEqualsHashCode=true, genToString=true, genBuilder=false)")
@Deprecated
private void __metadata() {}
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 88fdc4aad5cf..c0b820293649 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -5138,10 +5138,15 @@ public final class PowerManagerService extends SystemService
// Get current time before acquiring the lock so that the calculated end time is as
// accurate as possible.
final long nowElapsed = SystemClock.elapsedRealtime();
- mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
+ if (mContext.checkCallingOrSelfPermission(
+ android.Manifest.permission.BATTERY_PREDICTION)
+ != PackageManager.PERMISSION_GRANTED) {
+ mContext.enforceCallingOrSelfPermission(
+ android.Manifest.permission.DEVICE_POWER, "setBatteryDischargePrediction");
+ }
final long timeRemainingMs = timeRemaining.getDuration().toMillis();
- // A non-positive number means the battery should be dead right now...
+ // A non-positive number means the battery should be dead right now...
Preconditions.checkArgumentPositive(timeRemainingMs,
"Given time remaining is not positive: " + timeRemainingMs);
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 8a826a422ae1..15c72b34dbc0 100644
--- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
@@ -1720,7 +1720,7 @@ public class StatsPullAtomService extends SystemService {
}
for (int cluster = 0; cluster < clusters; ++cluster) {
pulledData.add(FrameworkStatsLog.buildStatsEvent(
- atomTag, threadGroup, cluster, aggregatedCycles[cluster],
+ atomTag, threadGroup, cluster, aggregatedCycles[cluster] / 1_000_000L,
aggregatedTimesUs[cluster] / 1_000));
}
}
diff --git a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
index 8aab3a66ada3..12590eba81f8 100644
--- a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
+++ b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
@@ -38,10 +38,12 @@ import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkAgent;
+import android.net.NetworkAgent.ValidationStatus;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.RouteInfo;
import android.net.TelephonyNetworkSpecifier;
+import android.net.Uri;
import android.net.annotations.PolicyDirection;
import android.net.ipsec.ike.ChildSessionCallback;
import android.net.ipsec.ike.ChildSessionConfiguration;
@@ -151,6 +153,9 @@ public class VcnGatewayConnection extends StateMachine {
@VisibleForTesting(visibility = Visibility.PRIVATE)
static final String RETRY_TIMEOUT_ALARM = TAG + "_RETRY_TIMEOUT_ALARM";
+ @VisibleForTesting(visibility = Visibility.PRIVATE)
+ static final String SAFEMODE_TIMEOUT_ALARM = TAG + "_SAFEMODE_TIMEOUT_ALARM";
+
private static final int[] MERGED_CAPABILITIES =
new int[] {NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_NOT_ROAMING};
private static final int ARG_NOT_PRESENT = Integer.MIN_VALUE;
@@ -167,6 +172,9 @@ public class VcnGatewayConnection extends StateMachine {
@VisibleForTesting(visibility = Visibility.PRIVATE)
static final int TEARDOWN_TIMEOUT_SECONDS = 5;
+ @VisibleForTesting(visibility = Visibility.PRIVATE)
+ static final int SAFEMODE_TIMEOUT_SECONDS = 30;
+
private interface EventInfo {}
/**
@@ -409,6 +417,23 @@ public class VcnGatewayConnection extends StateMachine {
// TODO(b/178426520): implement handling of this event
private static final int EVENT_SUBSCRIPTIONS_CHANGED = 9;
+ /**
+ * Sent when this VcnGatewayConnection has entered Safemode.
+ *
+ * <p>A VcnGatewayConnection enters Safemode when it takes over {@link
+ * #SAFEMODE_TIMEOUT_SECONDS} to enter {@link ConnectedState}.
+ *
+ * <p>When a VcnGatewayConnection enters safe mode, it will fire {@link
+ * VcnGatewayStatusCallback#onEnteredSafemode()} to notify its Vcn. The Vcn will then shut down
+ * its VcnGatewayConnectin(s).
+ *
+ * <p>Relevant in DisconnectingState, ConnectingState, ConnectedState (if the Vcn Network is not
+ * validated yet), and RetryTimeoutState.
+ *
+ * @param arg1 The "all" token; this signal is always honored.
+ */
+ private static final int EVENT_SAFEMODE_TIMEOUT_EXCEEDED = 10;
+
@VisibleForTesting(visibility = Visibility.PRIVATE)
@NonNull
final DisconnectedState mDisconnectedState = new DisconnectedState();
@@ -520,11 +545,13 @@ public class VcnGatewayConnection extends StateMachine {
* <p>Set in Connected state, always @NonNull in Connected, Migrating states, @Nullable
* otherwise.
*/
- private NetworkAgent mNetworkAgent;
+ @VisibleForTesting(visibility = Visibility.PRIVATE)
+ NetworkAgent mNetworkAgent;
@Nullable private WakeupMessage mTeardownTimeoutAlarm;
@Nullable private WakeupMessage mDisconnectRequestAlarm;
@Nullable private WakeupMessage mRetryTimeoutAlarm;
+ @Nullable private WakeupMessage mSafemodeTimeoutAlarm;
public VcnGatewayConnection(
@NonNull VcnContext vcnContext,
@@ -611,6 +638,7 @@ public class VcnGatewayConnection extends StateMachine {
cancelTeardownTimeoutAlarm();
cancelDisconnectRequestAlarm();
cancelRetryTimeoutAlarm();
+ cancelSafemodeAlarm();
mUnderlyingNetworkTracker.teardown();
}
@@ -899,6 +927,30 @@ public class VcnGatewayConnection extends StateMachine {
removeEqualMessages(EVENT_RETRY_TIMEOUT_EXPIRED);
}
+ @VisibleForTesting(visibility = Visibility.PRIVATE)
+ void setSafemodeAlarm() {
+ // Only schedule a NEW alarm if none is already set.
+ if (mSafemodeTimeoutAlarm != null) {
+ return;
+ }
+
+ final Message delayedMessage = obtainMessage(EVENT_SAFEMODE_TIMEOUT_EXCEEDED, TOKEN_ALL);
+ mSafemodeTimeoutAlarm =
+ createScheduledAlarm(
+ SAFEMODE_TIMEOUT_ALARM,
+ delayedMessage,
+ TimeUnit.SECONDS.toMillis(SAFEMODE_TIMEOUT_SECONDS));
+ }
+
+ private void cancelSafemodeAlarm() {
+ if (mSafemodeTimeoutAlarm != null) {
+ mSafemodeTimeoutAlarm.cancel();
+ mSafemodeTimeoutAlarm = null;
+ }
+
+ removeEqualMessages(EVENT_SAFEMODE_TIMEOUT_EXCEEDED);
+ }
+
private void sessionLost(int token, @Nullable Exception exception) {
sendMessageAndAcquireWakeLock(
EVENT_SESSION_LOST, token, new EventSessionLostInfo(exception));
@@ -1072,6 +1124,8 @@ public class VcnGatewayConnection extends StateMachine {
if (mIkeSession != null || mNetworkAgent != null) {
Slog.wtf(TAG, "Active IKE Session or NetworkAgent in DisconnectedState");
}
+
+ cancelSafemodeAlarm();
}
@Override
@@ -1095,6 +1149,12 @@ public class VcnGatewayConnection extends StateMachine {
break;
}
}
+
+ @Override
+ protected void exitState() {
+ // Safe to blindly set up, as it is cancelled and cleared on entering this state
+ setSafemodeAlarm();
+ }
}
private abstract class ActiveBaseState extends BaseState {
@@ -1185,6 +1245,10 @@ public class VcnGatewayConnection extends StateMachine {
transitionTo(mDisconnectedState);
}
break;
+ case EVENT_SAFEMODE_TIMEOUT_EXCEEDED:
+ mGatewayStatusCallback.onEnteredSafemode();
+ mSafemodeTimeoutAlarm = null;
+ break;
default:
logUnhandledMessage(msg);
break;
@@ -1267,6 +1331,10 @@ public class VcnGatewayConnection extends StateMachine {
case EVENT_DISCONNECT_REQUESTED:
handleDisconnectRequested(((EventDisconnectRequestedInfo) msg.obj).reason);
break;
+ case EVENT_SAFEMODE_TIMEOUT_EXCEEDED:
+ mGatewayStatusCallback.onEnteredSafemode();
+ mSafemodeTimeoutAlarm = null;
+ break;
default:
logUnhandledMessage(msg);
break;
@@ -1310,6 +1378,14 @@ public class VcnGatewayConnection extends StateMachine {
public void unwanted() {
teardownAsynchronously();
}
+
+ @Override
+ public void onValidationStatus(
+ @ValidationStatus int status, @Nullable Uri redirectUri) {
+ if (status == NetworkAgent.VALIDATION_STATUS_VALID) {
+ clearFailedAttemptCounterAndSafeModeAlarm();
+ }
+ }
};
agent.register();
@@ -1318,6 +1394,14 @@ public class VcnGatewayConnection extends StateMachine {
return agent;
}
+ protected void clearFailedAttemptCounterAndSafeModeAlarm() {
+ mVcnContext.ensureRunningOnLooperThread();
+
+ // Validated connection, clear failed attempt counter
+ mFailedAttempts = 0;
+ cancelSafemodeAlarm();
+ }
+
protected void applyTransform(
int token,
@NonNull IpSecTunnelInterface tunnelIface,
@@ -1325,7 +1409,7 @@ public class VcnGatewayConnection extends StateMachine {
@NonNull IpSecTransform transform,
int direction) {
try {
- // TODO: Set underlying network of tunnel interface
+ // TODO(b/180163196): Set underlying network of tunnel interface
// Transforms do not need to be persisted; the IkeSession will keep them alive
mIpSecManager.applyTunnelModeTransform(tunnelIface, direction, transform);
@@ -1397,9 +1481,6 @@ public class VcnGatewayConnection extends StateMachine {
teardownAsynchronously();
}
}
-
- // Successful connection, clear failed attempt counter
- mFailedAttempts = 0;
}
@Override
@@ -1436,6 +1517,10 @@ public class VcnGatewayConnection extends StateMachine {
case EVENT_DISCONNECT_REQUESTED:
handleDisconnectRequested(((EventDisconnectRequestedInfo) msg.obj).reason);
break;
+ case EVENT_SAFEMODE_TIMEOUT_EXCEEDED:
+ mGatewayStatusCallback.onEnteredSafemode();
+ mSafemodeTimeoutAlarm = null;
+ break;
default:
logUnhandledMessage(msg);
break;
@@ -1455,6 +1540,7 @@ public class VcnGatewayConnection extends StateMachine {
// mUnderlying assumed non-null, given check above.
// If network changed, migrate. Otherwise, update any existing networkAgent.
if (oldUnderlying == null || !oldUnderlying.network.equals(mUnderlying.network)) {
+ Slog.v(TAG, "Migrating to new network: " + mUnderlying.network);
mIkeSession.setNetwork(mUnderlying.network);
} else {
// oldUnderlying is non-null & underlying network itself has not changed
@@ -1478,8 +1564,19 @@ public class VcnGatewayConnection extends StateMachine {
mNetworkAgent = buildNetworkAgent(tunnelIface, childConfig);
} else {
updateNetworkAgent(tunnelIface, mNetworkAgent, childConfig);
+
+ // mNetworkAgent not null, so the VCN Network has already been established. Clear
+ // the failed attempt counter and safe mode alarm since this transition is complete.
+ clearFailedAttemptCounterAndSafeModeAlarm();
}
}
+
+ @Override
+ protected void exitState() {
+ // Attempt to set the safe mode alarm - this requires the Vcn Network being validated
+ // while in ConnectedState (which cancels the previous alarm)
+ setSafemodeAlarm();
+ }
}
/**
@@ -1526,6 +1623,10 @@ public class VcnGatewayConnection extends StateMachine {
case EVENT_DISCONNECT_REQUESTED:
handleDisconnectRequested(((EventDisconnectRequestedInfo) msg.obj).reason);
break;
+ case EVENT_SAFEMODE_TIMEOUT_EXCEEDED:
+ mGatewayStatusCallback.onEnteredSafemode();
+ mSafemodeTimeoutAlarm = null;
+ break;
default:
logUnhandledMessage(msg);
break;
@@ -1708,6 +1809,15 @@ public class VcnGatewayConnection extends StateMachine {
}
@Override
+ public void onIpSecTransformsMigrated(
+ @NonNull IpSecTransform inIpSecTransform,
+ @NonNull IpSecTransform outIpSecTransform) {
+ Slog.v(TAG, "ChildTransformsMigrated; token " + mToken);
+ onIpSecTransformCreated(inIpSecTransform, IpSecManager.DIRECTION_IN);
+ onIpSecTransformCreated(outIpSecTransform, IpSecManager.DIRECTION_OUT);
+ }
+
+ @Override
public void onIpSecTransformDeleted(@NonNull IpSecTransform transform, int direction) {
// Nothing to be done; no references to the IpSecTransform are held, and this transform
// will be closed by the IKE library.
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index f440e566d47e..9bf6df41a93b 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -5378,6 +5378,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
}
}
+ mDisplayContent.handleActivitySizeCompatModeIfNeeded(this);
mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS);
}
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index e51d690cabed..86968ed6d175 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -240,6 +240,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
@@ -663,12 +664,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
*/
private boolean mRemoved;
- /**
- * Non-null if the last size compatibility mode activity is using non-native screen
- * configuration. The activity is not able to put in multi-window mode, so it exists only one
- * per display.
- */
- private ActivityRecord mLastCompatModeActivity;
+ /** Set of activities in foreground size compat mode. */
+ private Set<ActivityRecord> mActiveSizeCompatActivities = new ArraySet<>();
// Used in updating the display size
private Point mTmpDisplaySize = new Point();
@@ -5553,24 +5550,23 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
/** Checks whether the given activity is in size compatibility mode and notifies the change. */
void handleActivitySizeCompatModeIfNeeded(ActivityRecord r) {
final Task organizedTask = r.getOrganizedTask();
- if (!r.isState(RESUMED) || r.getWindowingMode() != WINDOWING_MODE_FULLSCREEN
- || organizedTask == null) {
- // The callback is only interested in the foreground changes of fullscreen activity.
+ if (organizedTask == null) {
+ mActiveSizeCompatActivities.remove(r);
return;
}
- // TODO(b/178327644) Update for per Task size compat
- if (!r.inSizeCompatMode()) {
- if (mLastCompatModeActivity != null) {
+
+ if (r.isState(RESUMED) && r.inSizeCompatMode()) {
+ if (mActiveSizeCompatActivities.add(r)) {
+ // Trigger task event for new size compat activity.
organizedTask.onSizeCompatActivityChanged();
}
- mLastCompatModeActivity = null;
return;
}
- if (mLastCompatModeActivity == r) {
- return;
+
+ if (mActiveSizeCompatActivities.remove(r)) {
+ // Trigger task event for activity no longer in foreground size compat.
+ organizedTask.onSizeCompatActivityChanged();
}
- mLastCompatModeActivity = r;
- organizedTask.onSizeCompatActivityChanged();
}
boolean isUidPresent(int uid) {
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 6fbeaa4e944e..bb5e8bf486f4 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -847,7 +847,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
mWmService.openSurfaceTransaction();
try {
applySurfaceChangesTransaction();
- mWmService.mSyncEngine.onSurfacePlacement();
} catch (RuntimeException e) {
Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
} finally {
@@ -861,6 +860,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
// Send any pending task-info changes that were queued-up during a layout deferment
mWmService.mAtmService.mTaskOrganizerController.dispatchPendingEvents();
+ mWmService.mSyncEngine.onSurfacePlacement();
mWmService.mAnimator.executeAfterPrepareSurfacesRunnables();
checkAppTransitionReady(surfacePlacer);
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 8bd4dfd054b6..66d5c77a5c5e 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -5855,12 +5855,8 @@ class Task extends WindowContainer<WindowContainer> {
mTaskSupervisor.acquireLaunchWakelock();
}
- if (didAutoPip) {
- // Already entered PIP mode, no need to keep pausing.
- return true;
- }
-
- if (mPausingActivity != null) {
+ // If already entered PIP mode, no need to keep pausing.
+ if (mPausingActivity != null && !didAutoPip) {
// Have the window manager pause its key dispatching until the new
// activity has started. If we're pausing the activity just because
// the screen is being turned off and the UI is sleeping, don't interrupt
@@ -5883,9 +5879,9 @@ class Task extends WindowContainer<WindowContainer> {
}
} else {
- // This activity failed to schedule the
- // pause, so just treat it as being paused now.
- ProtoLog.v(WM_DEBUG_STATES, "Activity not running, resuming next.");
+ // This activity either failed to schedule the pause or it entered PIP mode,
+ // so just treat it as being paused now.
+ ProtoLog.v(WM_DEBUG_STATES, "Activity not running or entered PiP, resuming next.");
if (resuming == null) {
mRootWindowContainer.resumeFocusedTasksTopActivities();
}
diff --git a/services/core/java/com/android/server/wm/TaskOrganizerController.java b/services/core/java/com/android/server/wm/TaskOrganizerController.java
index 286d31ed7d5f..c0bce6be8c54 100644
--- a/services/core/java/com/android/server/wm/TaskOrganizerController.java
+++ b/services/core/java/com/android/server/wm/TaskOrganizerController.java
@@ -674,7 +674,7 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
// Remove and add for re-ordering.
mPendingTaskEvents.remove(pending);
}
- pending.mForce = force;
+ pending.mForce |= force;
mPendingTaskEvents.add(pending);
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
index 59b7367102c8..e76597d0a2f3 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
@@ -138,6 +138,7 @@ class ActiveAdmin {
private static final String TAG_ENROLLMENT_SPECIFIC_ID = "enrollment-specific-id";
private static final String TAG_ADMIN_CAN_GRANT_SENSORS_PERMISSIONS =
"admin-can-grant-sensors-permissions";
+ private static final String TAG_USB_DATA_SIGNALING = "usb-data-signaling";
private static final String ATTR_VALUE = "value";
private static final String ATTR_LAST_NETWORK_LOGGING_NOTIFICATION = "last-notification";
private static final String ATTR_NUM_NETWORK_LOGGING_NOTIFICATIONS = "num-notifications";
@@ -281,6 +282,9 @@ class ActiveAdmin {
public String mEnrollmentSpecificId;
public boolean mAdminCanGrantSensorsPermissions;
+ private static final boolean USB_DATA_SIGNALING_ENABLED_DEFAULT = true;
+ boolean mUsbDataSignalingEnabled = USB_DATA_SIGNALING_ENABLED_DEFAULT;
+
ActiveAdmin(DeviceAdminInfo info, boolean isParent) {
this.info = info;
this.isParent = isParent;
@@ -548,6 +552,9 @@ class ActiveAdmin {
}
writeAttributeValueToXml(out, TAG_ADMIN_CAN_GRANT_SENSORS_PERMISSIONS,
mAdminCanGrantSensorsPermissions);
+ if (mUsbDataSignalingEnabled != USB_DATA_SIGNALING_ENABLED_DEFAULT) {
+ writeAttributeValueToXml(out, TAG_USB_DATA_SIGNALING, mUsbDataSignalingEnabled);
+ }
}
void writeTextToXml(TypedXmlSerializer out, String tag, String text) throws IOException {
@@ -800,6 +807,9 @@ class ActiveAdmin {
} else if (TAG_ADMIN_CAN_GRANT_SENSORS_PERMISSIONS.equals(tag)) {
mAdminCanGrantSensorsPermissions = parser.getAttributeBoolean(null, ATTR_VALUE,
false);
+ } else if (TAG_USB_DATA_SIGNALING.equals(tag)) {
+ mUsbDataSignalingEnabled = parser.getAttributeBoolean(null, ATTR_VALUE,
+ USB_DATA_SIGNALING_ENABLED_DEFAULT);
} else {
Slog.w(DevicePolicyManagerService.LOG_TAG, "Unknown admin tag: " + tag);
XmlUtils.skipCurrentTag(parser);
@@ -1154,5 +1164,8 @@ class ActiveAdmin {
pw.print("mAdminCanGrantSensorsPermissions");
pw.println(mAdminCanGrantSensorsPermissions);
+
+ pw.print("mUsbDataSignaling=");
+ pw.println(mUsbDataSignalingEnabled);
}
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 498ee38d442a..aa3aedb46868 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -214,6 +214,7 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Bitmap;
+import android.hardware.usb.UsbManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.IAudioService;
@@ -246,6 +247,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
+import android.permission.AdminPermissionControlParams;
import android.permission.IPermissionManager;
import android.permission.PermissionControllerManager;
import android.provider.CalendarContract;
@@ -421,10 +423,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
DELEGATION_CERT_SELECTION,
};
- // Subset of delegations that can only be delegated by Device Owner.
- private static final List<String> DEVICE_OWNER_DELEGATIONS = Arrays.asList(new String[] {
- DELEGATION_NETWORK_LOGGING,
- });
+ // Subset of delegations that can only be delegated by Device Owner or Profile Owner of a
+ // managed profile.
+ private static final List<String> DEVICE_OWNER_OR_MANAGED_PROFILE_OWNER_DELEGATIONS =
+ Arrays.asList(new String[]{
+ DELEGATION_NETWORK_LOGGING,
+ });
// Subset of delegations that only one single package within a given user can hold
private static final List<String> EXCLUSIVE_DELEGATIONS = Arrays.asList(new String[] {
@@ -1356,6 +1360,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return mContext.getSystemService(WifiManager.class);
}
+ UsbManager getUsbManager() {
+ return mContext.getSystemService(UsbManager.class);
+ }
+
@SuppressWarnings("AndroidFrameworkBinderIdentity")
long binderClearCallingIdentity() {
return Binder.clearCallingIdentity();
@@ -2927,6 +2935,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
revertTransferOwnershipIfNecessaryLocked();
}
+ updateUsbDataSignal();
}
private void revertTransferOwnershipIfNecessaryLocked() {
@@ -5878,10 +5887,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
// Retrieve the user ID of the calling process.
final int userId = caller.getUserId();
- final boolean hasDoDelegation = !Collections.disjoint(scopes, DEVICE_OWNER_DELEGATIONS);
// Ensure calling process is device/profile owner.
- if (hasDoDelegation) {
- Preconditions.checkCallAuthorization(isDeviceOwner(caller));
+ if (!Collections.disjoint(scopes, DEVICE_OWNER_OR_MANAGED_PROFILE_OWNER_DELEGATIONS)) {
+ Preconditions.checkCallAuthorization(isDeviceOwner(caller)
+ || (isProfileOwner(caller) && isManagedProfile(caller.getUserId())));
} else {
Preconditions.checkCallAuthorization(isDeviceOwner(caller) || isProfileOwner(caller));
}
@@ -7883,6 +7892,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
updateDeviceOwnerLocked();
setDeviceOwnershipSystemPropertyLocked();
+ //TODO(b/180371154): when provisionFullyManagedDevice is used in tests, remove this
+ // hard-coded default value setting.
+ if (isAdb(caller)) {
+ activeAdmin.mAdminCanGrantSensorsPermissions = true;
+ mPolicyCache.setAdminCanGrantSensorsPermissions(userId, true);
+ saveSettingsLocked(userId);
+ }
+
mInjector.binderWithCleanCallingIdentity(() -> {
// Restrict adding a managed profile when a device owner is set on the device.
// That is to prevent the co-existence of a managed profile and a device owner
@@ -12635,9 +12652,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
if (grantState == DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED
|| grantState == DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED
|| grantState == DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT) {
+ AdminPermissionControlParams permissionParams =
+ new AdminPermissionControlParams(packageName, permission, grantState,
+ canAdminGrantSensorsPermissionsForUser(caller.getUserId()));
mInjector.getPermissionControllerManager(caller.getUserHandle())
.setRuntimePermissionGrantStateByDeviceAdmin(caller.getPackageName(),
- packageName, permission, grantState, mContext.getMainExecutor(),
+ permissionParams, mContext.getMainExecutor(),
(permissionWasSet) -> {
if (isPostQAdmin && !permissionWasSet) {
callback.sendResult(null);
@@ -16623,4 +16643,78 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return mPolicyCache.canAdminGrantSensorsPermissionsForUser(userId);
}
+
+ @Override
+ public void setUsbDataSignalingEnabled(String packageName, boolean enabled) {
+ Objects.requireNonNull(packageName, "Admin package name must be provided");
+ final CallerIdentity caller = getCallerIdentity(packageName);
+ Preconditions.checkCallAuthorization(
+ isDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(caller),
+ "USB data signaling can only be controlled by a device owner or "
+ + "a profile owner on an organization-owned device.");
+ Preconditions.checkState(canUsbDataSignalingBeDisabled(),
+ "USB data signaling cannot be disabled.");
+
+ synchronized (getLockObject()) {
+ final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller);
+ if (admin.mUsbDataSignalingEnabled != enabled) {
+ admin.mUsbDataSignalingEnabled = enabled;
+ saveSettingsLocked(caller.getUserId());
+ updateUsbDataSignal();
+ }
+ }
+ DevicePolicyEventLogger
+ .createEvent(DevicePolicyEnums.SET_USB_DATA_SIGNALING)
+ .setAdmin(packageName)
+ .setBoolean(enabled)
+ .write();
+ }
+
+ private void updateUsbDataSignal() {
+ if (!canUsbDataSignalingBeDisabled()) {
+ return;
+ }
+ final boolean usbEnabled;
+ synchronized (getLockObject()) {
+ final ActiveAdmin admin = getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
+ UserHandle.USER_SYSTEM);
+ usbEnabled = admin != null && admin.mUsbDataSignalingEnabled;
+ }
+ if (!mInjector.binderWithCleanCallingIdentity(
+ () -> mInjector.getUsbManager().enableUsbDataSignal(usbEnabled))) {
+ Slog.w(LOG_TAG, "Failed to set usb data signaling state");
+ }
+ }
+
+ @Override
+ public boolean isUsbDataSignalingEnabled(String packageName) {
+ final CallerIdentity caller = getCallerIdentity(packageName);
+ Preconditions.checkCallAuthorization(
+ isDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(caller),
+ "USB data signaling can only be controlled by a device owner or "
+ + "a profile owner on an organization-owned device.");
+
+ synchronized (getLockObject()) {
+ final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller);
+ return admin.mUsbDataSignalingEnabled;
+ }
+ }
+
+ @Override
+ public boolean isUsbDataSignalingEnabledForUser(int userId) {
+ final CallerIdentity caller = getCallerIdentity();
+ Preconditions.checkCallAuthorization(isSystemUid(caller));
+
+ synchronized (getLockObject()) {
+ final ActiveAdmin admin = getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
+ UserHandle.USER_SYSTEM);
+ return admin != null && admin.mUsbDataSignalingEnabled;
+ }
+ }
+
+ @Override
+ public boolean canUsbDataSignalingBeDisabled() {
+ return mInjector.binderWithCleanCallingIdentity(() ->
+ mInjector.getUsbManager().getUsbHalVersion() >= UsbManager.USB_HAL_V1_3);
+ }
}
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index bd2046490ec9..dd2dd8150165 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -138,6 +138,7 @@ import com.android.server.integrity.AppIntegrityManagerService;
import com.android.server.lights.LightsService;
import com.android.server.location.LocationManagerService;
import com.android.server.media.MediaRouterService;
+import com.android.server.media.metrics.MediaMetricsManagerService;
import com.android.server.media.projection.MediaProjectionManagerService;
import com.android.server.net.NetworkPolicyManagerService;
import com.android.server.net.NetworkStatsService;
@@ -253,6 +254,10 @@ public final class SystemServer implements Dumpable {
"com.android.server.companion.CompanionDeviceManagerService";
private static final String STATS_COMPANION_APEX_PATH =
"/apex/com.android.os.statsd/javalib/service-statsd.jar";
+ private static final String SCHEDULING_APEX_PATH =
+ "/apex/com.android.scheduling/javalib/service-scheduling.jar";
+ private static final String REBOOT_READINESS_LIFECYCLE_CLASS =
+ "com.android.server.scheduling.RebootReadinessManagerService$Lifecycle";
private static final String CONNECTIVITY_SERVICE_APEX_PATH =
"/apex/com.android.tethering/javalib/service-connectivity.jar";
private static final String STATS_COMPANION_LIFECYCLE_CLASS =
@@ -321,6 +326,8 @@ public final class SystemServer implements Dumpable {
"com.android.server.musicrecognition.MusicRecognitionManagerService";
private static final String SYSTEM_CAPTIONS_MANAGER_SERVICE_CLASS =
"com.android.server.systemcaptions.SystemCaptionsManagerService";
+ private static final String TEXT_TO_SPEECH_MANAGER_SERVICE_CLASS =
+ "com.android.server.texttospeech.TextToSpeechManagerService";
private static final String TIME_ZONE_RULES_MANAGER_SERVICE_CLASS =
"com.android.server.timezone.RulesManagerService$Lifecycle";
private static final String IOT_SERVICE_CLASS =
@@ -1708,6 +1715,7 @@ public final class SystemServer implements Dumpable {
startAttentionService(context, t);
startRotationResolverService(context, t);
startSystemCaptionsManagerService(context, t);
+ startTextToSpeechManagerService(context, t);
// System Speech Recognition Service
if (deviceHasConfigString(context,
@@ -2392,6 +2400,10 @@ public final class SystemServer implements Dumpable {
t.traceBegin("StartPeopleService");
mSystemServiceManager.startService(PeopleService.class);
t.traceEnd();
+
+ t.traceBegin("StartMediaMetricsManager");
+ mSystemServiceManager.startService(MediaMetricsManagerService.class);
+ t.traceEnd();
}
if (!isWatch) {
@@ -2447,6 +2459,12 @@ public final class SystemServer implements Dumpable {
STATS_COMPANION_LIFECYCLE_CLASS, STATS_COMPANION_APEX_PATH);
t.traceEnd();
+ // Reboot Readiness
+ t.traceBegin("StartRebootReadinessManagerService");
+ mSystemServiceManager.startServiceFromJar(
+ REBOOT_READINESS_LIFECYCLE_CLASS, SCHEDULING_APEX_PATH);
+ t.traceEnd();
+
// Statsd pulled atoms
t.traceBegin("StartStatsPullAtomService");
mSystemServiceManager.startService(STATS_PULL_ATOM_SERVICE_CLASS);
@@ -2903,6 +2921,13 @@ public final class SystemServer implements Dumpable {
t.traceEnd();
}
+ private void startTextToSpeechManagerService(@NonNull Context context,
+ @NonNull TimingsTraceAndSlog t) {
+ t.traceBegin("StartTextToSpeechManagerService");
+ mSystemServiceManager.startService(TEXT_TO_SPEECH_MANAGER_SERVICE_CLASS);
+ t.traceEnd();
+ }
+
private void startContentCaptureService(@NonNull Context context,
@NonNull TimingsTraceAndSlog t) {
// First check if it was explicitly enabled by DeviceConfig
diff --git a/services/people/java/com/android/server/people/PeopleService.java b/services/people/java/com/android/server/people/PeopleService.java
index 5453de14a5f1..966633701e6f 100644
--- a/services/people/java/com/android/server/people/PeopleService.java
+++ b/services/people/java/com/android/server/people/PeopleService.java
@@ -16,6 +16,7 @@
package com.android.server.people;
+import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -29,6 +30,7 @@ import android.app.prediction.AppTarget;
import android.app.prediction.AppTargetEvent;
import android.app.prediction.IPredictionCallback;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice;
import android.os.Binder;
@@ -184,6 +186,20 @@ public class PeopleService extends SystemService {
}
@Override
+ public boolean isConversation(String packageName, int userId, String shortcutId) {
+ enforceHasReadPeopleDataPermission();
+ handleIncomingUser(userId);
+ return mDataManager.isConversation(packageName, userId, shortcutId);
+ }
+
+ private void enforceHasReadPeopleDataPermission() throws SecurityException {
+ if (getContext().checkCallingPermission(Manifest.permission.READ_PEOPLE_DATA)
+ != PackageManager.PERMISSION_GRANTED) {
+ throw new SecurityException("Caller doesn't have READ_PEOPLE_DATA permission.");
+ }
+ }
+
+ @Override
public long getLastInteraction(String packageName, int userId, String shortcutId) {
enforceSystemRootOrSystemUI(getContext(), "get last interaction");
return mDataManager.getLastInteraction(packageName, userId, shortcutId);
diff --git a/services/people/java/com/android/server/people/data/DataManager.java b/services/people/java/com/android/server/people/data/DataManager.java
index 444f9c685a1b..1048dfdea8e5 100644
--- a/services/people/java/com/android/server/people/data/DataManager.java
+++ b/services/people/java/com/android/server/people/data/DataManager.java
@@ -58,6 +58,7 @@ import android.provider.Telephony.MmsSms;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.telecom.TelecomManager;
+import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -354,6 +355,14 @@ public class DataManager {
});
}
+ /** Returns whether {@code shortcutId} is backed by Conversation. */
+ public boolean isConversation(String packageName, int userId, String shortcutId) {
+ ConversationChannel channel = getConversation(packageName, userId, shortcutId);
+ return channel != null
+ && channel.getShortcutInfo() != null
+ && !TextUtils.isEmpty(channel.getShortcutInfo().getLabel());
+ }
+
/**
* Returns the last notification interaction with the specified conversation. If the
* conversation can't be found or no interactions have been recorded, returns 0L.
diff --git a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationEnforcerTest.kt b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationEnforcerTest.kt
index c2e0b776fc60..2d23fb4990bf 100644
--- a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationEnforcerTest.kt
+++ b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationEnforcerTest.kt
@@ -334,6 +334,7 @@ class DomainVerificationEnforcerTest {
this[0] = PackageUserState()
}
}
+ whenever(getInstantApp(anyInt())) { false }
}
}
diff --git a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt
index a76152c9df7d..a92ab9e35ddc 100644
--- a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt
+++ b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt
@@ -104,14 +104,14 @@ class DomainVerificationPersistenceTest {
userSelectionStates[1] = DomainVerificationUserState(1).apply {
addHosts(setOf("example-user1.com", "example-user1.org"))
- isDisallowLinkHandling = false
+ isLinkHandlingAllowed = true
}
}
val stateOne = mockEmptyPkgState(1).apply {
// It's valid to have a user selection without any autoVerify domains
userSelectionStates[1] = DomainVerificationUserState(1).apply {
addHosts(setOf("example-user1.com", "example-user1.org"))
- isDisallowLinkHandling = true
+ isLinkHandlingAllowed = false
}
}
@@ -137,13 +137,15 @@ class DomainVerificationPersistenceTest {
hasAutoVerifyDomains="true"
>
<state>
- <domain name="example.com" state="${DomainVerificationManager.STATE_SUCCESS}"/>
- <domain name="example.org" state="${DomainVerificationManager.STATE_FIRST_VERIFIER_DEFINED}"/>
+ <domain name="example.com" state="${
+ DomainVerificationManager.STATE_SUCCESS}"/>
+ <domain name="example.org" state="${
+ DomainVerificationManager.STATE_FIRST_VERIFIER_DEFINED}"/>
<not-domain name="not-domain.com" state="1"/>
<domain name="missing-state.com"/>
</state>
<user-states>
- <user-state userId="1" disallowLinkHandling="false">
+ <user-state userId="1" allowLinkHandling="true">
<enabled-hosts>
<host name="example-user1.com"/>
<not-host name="not-host.com"/>
@@ -171,7 +173,7 @@ class DomainVerificationPersistenceTest {
>
<state/>
<user-states>
- <user-state userId="1" disallowLinkHandling="true">
+ <user-state userId="1" allowLinkHandling="false">
<enabled-hosts>
<host name="example-user1.com"/>
<host name="example-user1.org"/>
@@ -214,9 +216,9 @@ class DomainVerificationPersistenceTest {
stateMap["$packageName.com"] = id
userSelectionStates[id] = DomainVerificationUserState(id).apply {
addHosts(setOf("$packageName-user.com"))
- isDisallowLinkHandling = true
+ isLinkHandlingAllowed = true
}
}
- private fun pkgName(id: Int) = "${PKG_PREFIX}.pkg$id"
+ private fun pkgName(id: Int) = "$PKG_PREFIX.pkg$id"
}
diff --git a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationSettingsMutationTest.kt b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationSettingsMutationTest.kt
index 5629d1c1107d..48518f4693dd 100644
--- a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationSettingsMutationTest.kt
+++ b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationSettingsMutationTest.kt
@@ -244,6 +244,7 @@ class DomainVerificationSettingsMutationTest {
this[0] = PackageUserState()
}
}
+ whenever(getInstantApp(anyInt())) { false }
}
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceIdleHelper.java b/services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceIdleHelper.java
new file mode 100644
index 000000000000..d2ab6462d96b
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceIdleHelper.java
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package com.android.server.location.injector;
+
+public class FakeDeviceIdleHelper extends DeviceIdleHelper {
+
+ private boolean mDeviceIdle = false;
+
+ public void setIdle(boolean deviceIdle) {
+ mDeviceIdle = deviceIdle;
+ notifyDeviceIdleChanged();
+ }
+
+ @Override
+ protected void registerInternal() {}
+
+ @Override
+ protected void unregisterInternal() {}
+
+ @Override
+ public boolean isDeviceIdle() {
+ return mDeviceIdle;
+ }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceStationaryHelper.java b/services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceStationaryHelper.java
new file mode 100644
index 000000000000..b1d921aa9db1
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/location/injector/FakeDeviceStationaryHelper.java
@@ -0,0 +1,52 @@
+/*
+ * 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.server.location.injector;
+
+import com.android.server.DeviceIdleInternal;
+
+import java.util.concurrent.CopyOnWriteArrayList;
+
+public class FakeDeviceStationaryHelper extends DeviceStationaryHelper {
+
+ private final CopyOnWriteArrayList<DeviceIdleInternal.StationaryListener> mListeners =
+ new CopyOnWriteArrayList<>();
+
+ private boolean mStationary = false;
+
+ @Override
+ public void addListener(DeviceIdleInternal.StationaryListener listener) {
+ synchronized (mListeners) {
+ mListeners.add(listener);
+ listener.onDeviceStationaryChanged(mStationary);
+ }
+ }
+
+ @Override
+ public void removeListener(DeviceIdleInternal.StationaryListener listener) {
+ mListeners.remove(listener);
+ }
+
+ public void setStationary(boolean stationary) {
+ synchronized (mListeners) {
+ mStationary = stationary;
+ }
+
+ for (DeviceIdleInternal.StationaryListener listener : mListeners) {
+ listener.onDeviceStationaryChanged(stationary);
+ }
+ }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/location/injector/TestInjector.java b/services/tests/mockingservicestests/src/com/android/server/location/injector/TestInjector.java
index 2822d5c69091..1f102ac32a8e 100644
--- a/services/tests/mockingservicestests/src/com/android/server/location/injector/TestInjector.java
+++ b/services/tests/mockingservicestests/src/com/android/server/location/injector/TestInjector.java
@@ -28,6 +28,8 @@ public class TestInjector implements Injector {
private final FakeAppForegroundHelper mAppForegroundHelper;
private final FakeLocationPowerSaveModeHelper mLocationPowerSaveModeHelper;
private final FakeScreenInteractiveHelper mScreenInteractiveHelper;
+ private final FakeDeviceStationaryHelper mDeviceStationaryHelper;
+ private final FakeDeviceIdleHelper mDeviceIdleHelper;
private final LocationAttributionHelper mLocationAttributionHelper;
private final FakeEmergencyHelper mEmergencyHelper;
private final LocationUsageLogger mLocationUsageLogger;
@@ -45,6 +47,8 @@ public class TestInjector implements Injector {
mAppForegroundHelper = new FakeAppForegroundHelper();
mLocationPowerSaveModeHelper = new FakeLocationPowerSaveModeHelper(eventLog);
mScreenInteractiveHelper = new FakeScreenInteractiveHelper();
+ mDeviceStationaryHelper = new FakeDeviceStationaryHelper();
+ mDeviceIdleHelper = new FakeDeviceIdleHelper();
mLocationAttributionHelper = new LocationAttributionHelper(mAppOpsHelper);
mEmergencyHelper = new FakeEmergencyHelper();
mLocationUsageLogger = new LocationUsageLogger();
@@ -91,6 +95,16 @@ public class TestInjector implements Injector {
}
@Override
+ public FakeDeviceStationaryHelper getDeviceStationaryHelper() {
+ return mDeviceStationaryHelper;
+ }
+
+ @Override
+ public FakeDeviceIdleHelper getDeviceIdleHelper() {
+ return mDeviceIdleHelper;
+ }
+
+ @Override
public LocationAttributionHelper getLocationAttributionHelper() {
return mLocationAttributionHelper;
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java b/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java
new file mode 100644
index 000000000000..c3cca64154d6
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/location/provider/StationaryThrottlingLocationProviderTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.server.location.provider;
+
+import static com.android.server.location.LocationUtils.createLocation;
+import static com.android.server.location.LocationUtils.createLocationResult;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.after;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import android.location.Location;
+import android.location.LocationResult;
+import android.location.provider.ProviderRequest;
+import android.platform.test.annotations.Presubmit;
+import android.util.Log;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.server.location.eventlog.LocationEventLog;
+import com.android.server.location.injector.TestInjector;
+import com.android.server.location.test.FakeProvider;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+import java.util.Random;
+
+@Presubmit
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class StationaryThrottlingLocationProviderTest {
+
+ private static final String TAG = "StationaryThrottlingLocationProviderTest";
+
+ private Random mRandom;
+ private TestInjector mInjector;
+ private FakeProvider mDelegateProvider;
+
+ private @Mock AbstractLocationProvider.Listener mListener;
+ private @Mock FakeProvider.FakeProviderInterface mDelegate;
+
+ private StationaryThrottlingLocationProvider mProvider;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ long seed = System.currentTimeMillis();
+ Log.i(TAG, "location random seed: " + seed);
+
+ mRandom = new Random(seed);
+
+ mInjector = new TestInjector();
+ mDelegateProvider = new FakeProvider(mDelegate);
+
+ mProvider = new StationaryThrottlingLocationProvider("test_provider", mInjector,
+ mDelegateProvider, new LocationEventLog());
+ mProvider.getController().setListener(mListener);
+ mProvider.getController().start();
+ }
+
+ @After
+ public void tearDown() {
+ mProvider.getController().setRequest(ProviderRequest.EMPTY_REQUEST);
+ mProvider.getController().stop();
+ }
+
+ @Test
+ public void testThrottle() {
+ ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
+
+ mProvider.getController().setRequest(request);
+ verify(mDelegate).onSetRequest(request);
+
+ mDelegateProvider.reportLocation(createLocationResult("test_provider", mRandom));
+ verify(mListener, times(1)).onReportLocation(any(LocationResult.class));
+
+ mInjector.getDeviceStationaryHelper().setStationary(true);
+ verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+
+ mInjector.getDeviceIdleHelper().setIdle(true);
+ verify(mDelegate).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+ verify(mListener, timeout(75).times(2)).onReportLocation(any(LocationResult.class));
+ verify(mListener, timeout(75).times(3)).onReportLocation(any(LocationResult.class));
+
+ mInjector.getDeviceStationaryHelper().setStationary(false);
+ verify(mDelegate, times(2)).onSetRequest(request);
+ verify(mListener, after(75).times(3)).onReportLocation(any(LocationResult.class));
+ }
+
+ @Test
+ public void testThrottle_NoInitialLocation() {
+ ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
+
+ mProvider.getController().setRequest(request);
+ verify(mDelegate).onSetRequest(request);
+
+ mInjector.getDeviceStationaryHelper().setStationary(true);
+ mInjector.getDeviceIdleHelper().setIdle(true);
+ verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+
+ mDelegateProvider.reportLocation(createLocationResult("test_provider", mRandom));
+ verify(mListener, times(1)).onReportLocation(any(LocationResult.class));
+ verify(mDelegate, times(1)).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+ verify(mListener, timeout(75).times(2)).onReportLocation(any(LocationResult.class));
+
+ mInjector.getDeviceStationaryHelper().setStationary(false);
+ verify(mDelegate, times(2)).onSetRequest(request);
+ verify(mListener, after(75).times(2)).onReportLocation(any(LocationResult.class));
+ }
+
+ @Test
+ public void testNoThrottle_noLocation() {
+ ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
+
+ mProvider.getController().setRequest(request);
+ verify(mDelegate).onSetRequest(request);
+ verify(mListener, never()).onReportLocation(any(LocationResult.class));
+
+ mInjector.getDeviceStationaryHelper().setStationary(true);
+ mInjector.getDeviceIdleHelper().setIdle(true);
+ verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+ verify(mListener, after(75).times(0)).onReportLocation(any(LocationResult.class));
+ }
+
+ @Test
+ public void testNoThrottle_oldLocation() {
+ ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(50).build();
+
+ mProvider.getController().setRequest(request);
+ verify(mDelegate).onSetRequest(request);
+
+ Location l = createLocation("test_provider", mRandom);
+ l.setElapsedRealtimeNanos(0);
+
+ LocationResult loc = LocationResult.wrap(l);
+ mDelegateProvider.reportLocation(loc);
+ verify(mListener, times(1)).onReportLocation(loc);
+
+ mInjector.getDeviceStationaryHelper().setStationary(true);
+ mInjector.getDeviceIdleHelper().setIdle(true);
+ verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+ verify(mListener, after(75).times(1)).onReportLocation(any(LocationResult.class));
+ }
+
+ @Test
+ public void testNoThrottle_locationSettingsIgnored() {
+ ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(
+ 50).setLocationSettingsIgnored(true).build();
+
+ mProvider.getController().setRequest(request);
+ verify(mDelegate).onSetRequest(request);
+
+ LocationResult loc = createLocationResult("test_provider", mRandom);
+ mDelegateProvider.reportLocation(loc);
+ verify(mListener, times(1)).onReportLocation(loc);
+
+ mInjector.getDeviceStationaryHelper().setStationary(true);
+ mInjector.getDeviceIdleHelper().setIdle(true);
+ verify(mDelegate, never()).onSetRequest(ProviderRequest.EMPTY_REQUEST);
+ verify(mListener, after(75).times(1)).onReportLocation(any(LocationResult.class));
+ }
+}
diff --git a/services/tests/servicestests/res/values/strings.xml b/services/tests/servicestests/res/values/values.xml
index 1f07ad50cdbc..0404ebcb60d0 100644
--- a/services/tests/servicestests/res/values/strings.xml
+++ b/services/tests/servicestests/res/values/values.xml
@@ -36,4 +36,12 @@
<string name="module_2_name" translatable="false">module_2_name</string>
<string name="widget_description">widget description string</string>
+ <dimen name="widget_min_width">80dp</dimen>
+ <dimen name="widget_min_height">40dp</dimen>
+ <dimen name="widget_min_resize_width">40dp</dimen>
+ <dimen name="widget_min_resize_height">20dp</dimen>
+ <dimen name="widget_max_resize_width">160dp</dimen>
+ <dimen name="widget_max_resize_height">80dp</dimen>
+ <integer name="widget_target_cell_width">2</integer>
+ <integer name="widget_target_cell_height">1</integer>
</resources>
diff --git a/services/tests/servicestests/res/xml/dummy_appwidget_info.xml b/services/tests/servicestests/res/xml/dummy_appwidget_info.xml
index 72f025dbabe9..de06191ec281 100644
--- a/services/tests/servicestests/res/xml/dummy_appwidget_info.xml
+++ b/services/tests/servicestests/res/xml/dummy_appwidget_info.xml
@@ -16,12 +16,18 @@
-->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
- android:minWidth="40dp"
- android:minHeight="40dp"
+ android:minWidth="@dimen/widget_min_width"
+ android:minHeight="@dimen/widget_min_height"
+ android:minResizeWidth="@dimen/widget_min_resize_width"
+ android:minResizeHeight="@dimen/widget_min_resize_height"
+ android:maxResizeWidth="@dimen/widget_max_resize_width"
+ android:maxResizeHeight="@dimen/widget_max_resize_height"
+ android:targetCellWidth="@integer/widget_target_cell_width"
+ android:targetCellHeight="@integer/widget_target_cell_height"
android:updatePeriodMillis="86400000"
android:previewImage="@drawable/icon1"
android:previewLayout="@layout/widget_preview"
android:resizeMode="horizontal|vertical"
android:description="@string/widget_description"
android:widgetCategory="home_screen">
-</appwidget-provider> \ No newline at end of file
+</appwidget-provider>
diff --git a/services/tests/servicestests/src/com/android/server/app/GameManagerServiceSettingsTests.java b/services/tests/servicestests/src/com/android/server/app/GameManagerServiceSettingsTests.java
index 738f008f9f3f..6d4189eb4168 100644
--- a/services/tests/servicestests/src/com/android/server/app/GameManagerServiceSettingsTests.java
+++ b/services/tests/servicestests/src/com/android/server/app/GameManagerServiceSettingsTests.java
@@ -90,7 +90,7 @@ public class GameManagerServiceSettingsTests {
writeGameServiceXml();
}
- private void verifyGameServiceSettingsData(Settings settings) {
+ private void verifyGameServiceSettingsData(GameManagerSettings settings) {
assertThat(settings.getGameModeLocked(PACKAGE_NAME_1), is(1));
assertThat(settings.getGameModeLocked(PACKAGE_NAME_2), is(2));
assertThat(settings.getGameModeLocked(PACKAGE_NAME_3), is(3));
@@ -107,7 +107,7 @@ public class GameManagerServiceSettingsTests {
/* write out files and read */
writeOldFiles();
final Context context = InstrumentationRegistry.getContext();
- Settings settings = new Settings(context.getFilesDir());
+ GameManagerSettings settings = new GameManagerSettings(context.getFilesDir());
assertThat(settings.readPersistentDataLocked(), is(true));
verifyGameServiceSettingsData(settings);
}
@@ -118,7 +118,7 @@ public class GameManagerServiceSettingsTests {
// write out files and read
writeOldFiles();
final Context context = InstrumentationRegistry.getContext();
- Settings settings = new Settings(context.getFilesDir());
+ GameManagerSettings settings = new GameManagerSettings(context.getFilesDir());
assertThat(settings.readPersistentDataLocked(), is(true));
// write out, read back in and verify the same
diff --git a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java
index 9b6c7234981c..73b0105210c4 100644
--- a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java
@@ -16,8 +16,6 @@
package com.android.server.appsearch.external.localstorage;
-import static android.app.appsearch.AppSearchResult.RESULT_OK;
-
import static com.google.common.truth.Truth.assertThat;
import static org.testng.Assert.expectThrows;
@@ -27,7 +25,7 @@ import android.app.appsearch.GenericDocument;
import android.app.appsearch.SearchResult;
import android.app.appsearch.SearchResultPage;
import android.app.appsearch.SearchSpec;
-import android.app.appsearch.SetSchemaResult;
+import android.app.appsearch.SetSchemaResponse;
import android.app.appsearch.exceptions.AppSearchException;
import android.content.Context;
import android.util.ArraySet;
@@ -66,14 +64,14 @@ public class AppSearchImplTest {
@Before
public void setUp() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
+
// Give ourselves global query permissions
mAppSearchImpl =
AppSearchImpl.create(
mTemporaryFolder.newFolder(),
context,
VisibilityStore.NO_OP_USER_ID,
- /*globalQuerierPackage
- =*/ context.getPackageName());
+ /*globalQuerierPackage=*/ context.getPackageName());
}
// TODO(b/175430168) add test to verify reset is working properly.
@@ -425,18 +423,24 @@ public class AppSearchImplTest {
GetOptimizeInfoResultProto optimizeInfo = mAppSearchImpl.getOptimizeInfoResultLocked();
assertThat(optimizeInfo.getOptimizableDocs()).isEqualTo(0);
- // delete 999 documents , we will reach the threshold to trigger optimize() in next
+ // delete 999 documents, we will reach the threshold to trigger optimize() in next
// deletion.
for (int i = 0; i < AppSearchImpl.OPTIMIZE_THRESHOLD_DOC_COUNT - 1; i++) {
mAppSearchImpl.remove("package", "database", "namespace", "uri" + i);
}
- // optimize() still not be triggered since we are in the interval to call getOptimizeInfo()
+ // Updates the check for optimize counter, checkForOptimize() will be triggered since
+ // CHECK_OPTIMIZE_INTERVAL is reached but optimize() won't since
+ // OPTIMIZE_THRESHOLD_DOC_COUNT is not.
+ mAppSearchImpl.checkForOptimize(
+ /*mutateBatchSize=*/ AppSearchImpl.OPTIMIZE_THRESHOLD_DOC_COUNT - 1);
+
+ // Verify optimize() still not be triggered.
optimizeInfo = mAppSearchImpl.getOptimizeInfoResultLocked();
assertThat(optimizeInfo.getOptimizableDocs())
.isEqualTo(AppSearchImpl.OPTIMIZE_THRESHOLD_DOC_COUNT - 1);
- // Keep delete docs, will reach the interval this time and trigger optimize().
+ // Keep delete docs
for (int i = AppSearchImpl.OPTIMIZE_THRESHOLD_DOC_COUNT;
i
< AppSearchImpl.OPTIMIZE_THRESHOLD_DOC_COUNT
@@ -444,6 +448,9 @@ public class AppSearchImplTest {
i++) {
mAppSearchImpl.remove("package", "database", "namespace", "uri" + i);
}
+ // updates the check for optimize counter, will reach both CHECK_OPTIMIZE_INTERVAL and
+ // OPTIMIZE_THRESHOLD_DOC_COUNT this time and trigger a optimize().
+ mAppSearchImpl.checkForOptimize(/*mutateBatchSize*/ AppSearchImpl.CHECK_OPTIMIZE_INTERVAL);
// Verify optimize() is triggered
optimizeInfo = mAppSearchImpl.getOptimizeInfoResultLocked();
@@ -783,7 +790,7 @@ public class AppSearchImplTest {
Collections.singletonList(new AppSearchSchema.Builder("Email").build());
// set email incompatible and delete text
- SetSchemaResult setSchemaResult =
+ SetSchemaResponse setSchemaResponse =
mAppSearchImpl.setSchema(
"package",
"database1",
@@ -791,9 +798,8 @@ public class AppSearchImplTest {
/*schemasNotPlatformSurfaceable=*/ Collections.emptyList(),
/*schemasPackageAccessible=*/ Collections.emptyMap(),
/*forceOverride=*/ true);
- assertThat(setSchemaResult.getDeletedSchemaTypes()).containsExactly("Text");
- assertThat(setSchemaResult.getIncompatibleSchemaTypes()).containsExactly("Email");
- assertThat(setSchemaResult.getResultCode()).isEqualTo(RESULT_OK);
+ assertThat(setSchemaResponse.getDeletedTypes()).containsExactly("Text");
+ assertThat(setSchemaResponse.getIncompatibleTypes()).containsExactly("Email");
}
@Test
@@ -836,7 +842,7 @@ public class AppSearchImplTest {
final List<AppSearchSchema> finalSchemas =
Collections.singletonList(new AppSearchSchema.Builder("Email").build());
- SetSchemaResult setSchemaResult =
+ SetSchemaResponse setSchemaResponse =
mAppSearchImpl.setSchema(
"package",
"database1",
@@ -846,7 +852,7 @@ public class AppSearchImplTest {
/*forceOverride=*/ false);
// Check the Document type has been deleted.
- assertThat(setSchemaResult.getDeletedSchemaTypes()).containsExactly("Document");
+ assertThat(setSchemaResponse.getDeletedTypes()).containsExactly("Document");
// ForceOverride to delete.
mAppSearchImpl.setSchema(
@@ -1046,4 +1052,136 @@ public class AppSearchImplTest {
strippedDocumentProto.build()));
}
}
+
+ @Test
+ public void testThrowsExceptionIfClosed() throws Exception {
+ Context context = ApplicationProvider.getApplicationContext();
+ AppSearchImpl appSearchImpl =
+ AppSearchImpl.create(
+ mTemporaryFolder.newFolder(),
+ context,
+ VisibilityStore.NO_OP_USER_ID,
+ /*globalQuerierPackage=*/ "");
+
+ // Initial check that we could do something at first.
+ List<AppSearchSchema> schemas =
+ Collections.singletonList(new AppSearchSchema.Builder("type").build());
+ appSearchImpl.setSchema(
+ "package",
+ "database",
+ schemas,
+ /*schemasNotPlatformSurfaceable=*/ Collections.emptyList(),
+ /*schemasPackageAccessible=*/ Collections.emptyMap(),
+ /*forceOverride=*/ false);
+
+ appSearchImpl.close();
+
+ // Check all our public APIs
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.setSchema(
+ "package",
+ "database",
+ schemas,
+ /*schemasNotPlatformSurfaceable=*/ Collections.emptyList(),
+ /*schemasPackageAccessible=*/ Collections.emptyMap(),
+ /*forceOverride=*/ false);
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.getSchema("package", "database");
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.putDocument(
+ "package",
+ "database",
+ new GenericDocument.Builder<>("uri", "type")
+ .setNamespace("namespace")
+ .build());
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.getDocument(
+ "package", "database", "namespace", "uri", Collections.emptyMap());
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.query(
+ "package",
+ "database",
+ "query",
+ new SearchSpec.Builder()
+ .setTermMatch(TermMatchType.Code.PREFIX_VALUE)
+ .build());
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.globalQuery(
+ "query",
+ new SearchSpec.Builder()
+ .setTermMatch(TermMatchType.Code.PREFIX_VALUE)
+ .build(),
+ "package",
+ /*callerUid=*/ 1);
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.getNextPage(/*nextPageToken=*/ 1L);
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.invalidateNextPageToken(/*nextPageToken=*/ 1L);
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.reportUsage(
+ "package",
+ "database",
+ "namespace",
+ "uri",
+ /*usageTimestampMillis=*/ 1000L);
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.remove("package", "database", "namespace", "uri");
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.removeByQuery(
+ "package",
+ "database",
+ "query",
+ new SearchSpec.Builder()
+ .setTermMatch(TermMatchType.Code.PREFIX_VALUE)
+ .build());
+ });
+
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ appSearchImpl.persistToDisk();
+ });
+ }
}
diff --git a/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java b/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java
index 78eb2df58925..ff8fedce9368 100644
--- a/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java
@@ -103,6 +103,26 @@ public class AppWidgetServiceImplTest extends InstrumentationTestCase {
assertEquals(info.loadDescription(mTestContext), "widget description string");
}
+ public void testParseSizeConfiguration() {
+ AppWidgetProviderInfo info =
+ mManager.getInstalledProvidersForPackage(mPkgName, null).get(0);
+
+ assertThat(info.minWidth).isEqualTo(getDimensionResource(R.dimen.widget_min_width));
+ assertThat(info.minHeight).isEqualTo(getDimensionResource(R.dimen.widget_min_height));
+ assertThat(info.minResizeWidth)
+ .isEqualTo(getDimensionResource(R.dimen.widget_min_resize_width));
+ assertThat(info.minResizeHeight)
+ .isEqualTo(getDimensionResource(R.dimen.widget_min_resize_height));
+ assertThat(info.maxResizeWidth)
+ .isEqualTo(getDimensionResource(R.dimen.widget_max_resize_width));
+ assertThat(info.maxResizeHeight)
+ .isEqualTo(getDimensionResource(R.dimen.widget_max_resize_height));
+ assertThat(info.targetCellWidth)
+ .isEqualTo(getIntegerResource(R.integer.widget_target_cell_width));
+ assertThat(info.targetCellHeight)
+ .isEqualTo(getIntegerResource(R.integer.widget_target_cell_height));
+ }
+
public void testRequestPinAppWidget_otherProvider() {
ComponentName otherProvider = null;
for (AppWidgetProviderInfo provider : mManager.getInstalledProviders()) {
@@ -325,6 +345,14 @@ public class AppWidgetServiceImplTest extends InstrumentationTestCase {
latch.await();
}
+ private int getDimensionResource(int resId) {
+ return mTestContext.getResources().getDimensionPixelSize(resId);
+ }
+
+ private int getIntegerResource(int resId) {
+ return mTestContext.getResources().getInteger(resId);
+ }
+
private class TestContext extends ContextWrapper {
public TestContext() {
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
index 5b0704d69a68..61d7ede98f45 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
@@ -28,6 +28,7 @@ import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManagerInternal;
import android.database.ContentObserver;
+import android.hardware.usb.UsbManager;
import android.media.IAudioService;
import android.net.IIpConnectivityMetrics;
import android.net.Uri;
@@ -244,6 +245,11 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi
}
@Override
+ UsbManager getUsbManager() {
+ return services.usbManager;
+ }
+
+ @Override
boolean storageManagerIsFileBasedEncryptionEnabled() {
return services.storageManager.isFileBasedEncryptionEnabled();
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index 4002f5b4939e..5bb65abd3033 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -89,6 +89,7 @@ import android.content.pm.ResolveInfo;
import android.content.pm.StringParceledListSlice;
import android.content.pm.UserInfo;
import android.graphics.Color;
+import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
@@ -7002,6 +7003,82 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.PASSWORD_QUALITY_COMPLEX));
}
+ @Test
+ public void testSetUsbDataSignalingEnabled_noDeviceOwnerOrPoOfOrgOwnedDevice() {
+ assertThrows(SecurityException.class,
+ () -> dpm.setUsbDataSignalingEnabled(true));
+ }
+
+ @Test
+ public void testSetUsbDataSignalingEnabled_asDeviceOwner() throws Exception {
+ setDeviceOwner();
+ when(getServices().usbManager.enableUsbDataSignal(false)).thenReturn(true);
+ when(getServices().usbManager.getUsbHalVersion()).thenReturn(UsbManager.USB_HAL_V1_3);
+
+ assertThat(dpm.isUsbDataSignalingEnabled()).isTrue();
+
+ dpm.setUsbDataSignalingEnabled(false);
+
+ assertThat(dpm.isUsbDataSignalingEnabled()).isFalse();
+ }
+
+ @Test
+ public void testIsUsbDataSignalingEnabledForUser_systemUser() throws Exception {
+ when(getServices().usbManager.enableUsbDataSignal(false)).thenReturn(true);
+ when(getServices().usbManager.getUsbHalVersion()).thenReturn(UsbManager.USB_HAL_V1_3);
+ setDeviceOwner();
+ dpm.setUsbDataSignalingEnabled(false);
+ mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
+
+ assertThat(dpm.isUsbDataSignalingEnabledForUser(UserHandle.myUserId())).isFalse();
+ }
+
+ @Test
+ public void testSetUsbDataSignalingEnabled_asPoOfOrgOwnedDevice() throws Exception {
+ final int managedProfileUserId = 15;
+ final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
+ addManagedProfile(admin1, managedProfileAdminUid, admin1);
+ configureProfileOwnerOfOrgOwnedDevice(admin1, managedProfileUserId);
+ mContext.binder.callingUid = managedProfileAdminUid;
+ when(getServices().usbManager.enableUsbDataSignal(false)).thenReturn(true);
+ when(getServices().usbManager.getUsbHalVersion()).thenReturn(UsbManager.USB_HAL_V1_3);
+
+ assertThat(dpm.isUsbDataSignalingEnabled()).isTrue();
+
+ dpm.setUsbDataSignalingEnabled(false);
+
+ assertThat(dpm.isUsbDataSignalingEnabled()).isFalse();
+ }
+
+ @Test
+ public void testCanUsbDataSignalingBeDisabled_canBeDisabled() throws Exception {
+ when(getServices().usbManager.getUsbHalVersion()).thenReturn(UsbManager.USB_HAL_V1_3);
+
+ assertThat(dpm.canUsbDataSignalingBeDisabled()).isTrue();
+ }
+
+ @Test
+ public void testCanUsbDataSignalingBeDisabled_cannotBeDisabled() throws Exception {
+ setDeviceOwner();
+ when(getServices().usbManager.getUsbHalVersion()).thenReturn(UsbManager.USB_HAL_V1_2);
+
+ assertThat(dpm.canUsbDataSignalingBeDisabled()).isFalse();
+ assertThrows(IllegalStateException.class,
+ () -> dpm.setUsbDataSignalingEnabled(true));
+ }
+
+ @Test
+ public void testSetUsbDataSignalingEnabled_noChangeToActiveAdmin()
+ throws Exception {
+ setDeviceOwner();
+ when(getServices().usbManager.getUsbHalVersion()).thenReturn(UsbManager.USB_HAL_V1_3);
+ boolean enabled = dpm.isUsbDataSignalingEnabled();
+
+ dpm.setUsbDataSignalingEnabled(true);
+
+ assertThat(dpm.isUsbDataSignalingEnabled()).isEqualTo(enabled);
+ }
+
private void setUserUnlocked(int userHandle, boolean unlocked) {
when(getServices().userManager.isUserUnlocked(eq(userHandle))).thenReturn(unlocked);
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java
index 944ef8db4e0d..f6dee385ca07 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java
@@ -45,6 +45,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.UserInfo;
import android.database.Cursor;
+import android.hardware.usb.UsbManager;
import android.media.IAudioService;
import android.net.IIpConnectivityMetrics;
import android.net.Uri;
@@ -119,6 +120,7 @@ public class MockSystemServices {
public final CrossProfileApps crossProfileApps;
public final PersistentDataBlockManagerInternal persistentDataBlockManagerInternal;
public final AppOpsManager appOpsManager;
+ public final UsbManager usbManager;
/** Note this is a partial mock, not a real mock. */
public final PackageManager packageManager;
public final BuildMock buildMock = new BuildMock();
@@ -163,6 +165,7 @@ public class MockSystemServices {
crossProfileApps = mock(CrossProfileApps.class);
persistentDataBlockManagerInternal = mock(PersistentDataBlockManagerInternal.class);
appOpsManager = mock(AppOpsManager.class);
+ usbManager = mock(UsbManager.class);
// Package manager is huge, so we use a partial mock instead.
packageManager = spy(realContext.getPackageManager());
diff --git a/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java b/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java
index 4bbf96fcb7ef..7771afc8c7f1 100644
--- a/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java
+++ b/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java
@@ -684,8 +684,8 @@ public final class UpdatableFontDirTest {
newAddFontFamilyRequest("<family lang='en'>"
+ " <font>test.ttf</font>"
+ "</family>")));
- fail("Expect IllegalArgumentException");
- } catch (IllegalArgumentException e) {
+ fail("Expect NullPointerException");
+ } catch (NullPointerException e) {
// Expect
}
}
@@ -703,9 +703,10 @@ public final class UpdatableFontDirTest {
dir.update(Arrays.asList(newAddFontFamilyRequest("<family name='test'>"
+ " <font>test.ttf</font>"
+ "</family>")));
- fail("Expect IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expect
+ fail("Expect SystemFontException");
+ } catch (FontManagerService.SystemFontException e) {
+ assertThat(e.getErrorCode())
+ .isEqualTo(FontManager.RESULT_ERROR_FONT_NOT_FOUND);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java b/services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java
index bb57a69d6f51..fcbd89781de4 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/FakeNativeWrapper.java
@@ -15,12 +15,9 @@
*/
package com.android.server.hdmi;
+import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiPortInfo;
-import android.hardware.tv.cec.V1_0.CecMessage;
-import android.hardware.tv.cec.V1_0.HotplugEvent;
import android.hardware.tv.cec.V1_0.SendMessageResult;
-import android.os.RemoteException;
-import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.hdmi.HdmiCecController.NativeWrapper;
@@ -99,7 +96,7 @@ final class FakeNativeWrapper implements NativeWrapper {
@Override
public int nativeGetVersion() {
- return 0;
+ return HdmiControlManager.HDMI_CEC_VERSION_2_0;
}
@Override
@@ -139,20 +136,15 @@ final class FakeNativeWrapper implements NativeWrapper {
if (mCallback == null) {
return;
}
- CecMessage message = new CecMessage();
- message.initiator = hdmiCecMessage.getSource();
- message.destination = hdmiCecMessage.getDestination();
- ArrayList<Byte> body = new ArrayList<>();
- body.add((byte) hdmiCecMessage.getOpcode());
+ int source = hdmiCecMessage.getSource();
+ int destination = hdmiCecMessage.getDestination();
+ byte[] body = new byte[hdmiCecMessage.getParams().length + 1];
+ int i = 0;
+ body[i++] = (byte) hdmiCecMessage.getOpcode();
for (byte param : hdmiCecMessage.getParams()) {
- body.add(param);
- }
- message.body = body;
- try {
- mCallback.onCecMessage(message);
- } catch (RemoteException e) {
- Log.e(TAG, "Error sending CEC message", e);
+ body[i++] = param;
}
+ mCallback.onCecMessage(source, destination, body);
}
public void onHotplugEvent(int port, boolean connected) {
@@ -160,15 +152,7 @@ final class FakeNativeWrapper implements NativeWrapper {
return;
}
- HotplugEvent hotplugEvent = new HotplugEvent();
- hotplugEvent.portId = port;
- hotplugEvent.connected = connected;
-
- try {
- mCallback.onHotplugEvent(hotplugEvent);
- } catch (RemoteException e) {
- Log.e(TAG, "Error sending hotplug event", e);
- }
+ mCallback.onHotplugEvent(port, connected);
}
public List<HdmiCecMessage> getResultMessages() {
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java
index 5342486f930b..b11ac24b9a29 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDevicePlaybackTest.java
@@ -24,6 +24,8 @@ import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
@@ -34,6 +36,7 @@ import android.os.IPowerManager;
import android.os.IThermalService;
import android.os.Looper;
import android.os.PowerManager;
+import android.os.RemoteException;
import android.os.test.TestLooper;
import android.platform.test.annotations.Presubmit;
import android.sysprop.HdmiProperties;
@@ -1552,6 +1555,31 @@ public class HdmiCecLocalDevicePlaybackTest {
}
@Test
+ public void toggleAndFollowTvPower_isInteractive() throws RemoteException {
+ when(mIPowerManagerMock.isInteractive()).thenReturn(true);
+ mActiveMediaSessionsPaused = false;
+ mWokenUp = false;
+
+ mHdmiControlService.toggleAndFollowTvPower();
+
+ assertThat(mActiveMediaSessionsPaused).isTrue();
+ assertThat(mWokenUp).isFalse();
+ }
+
+ @Test
+ public void toggleAndFollowTvPower_isNotInteractive() throws RemoteException {
+ when(mIPowerManagerMock.isInteractive()).thenReturn(false);
+ mActiveMediaSessionsPaused = false;
+ mWokenUp = false;
+
+ mHdmiControlService.toggleAndFollowTvPower();
+
+ assertThat(mActiveMediaSessionsPaused).isFalse();
+ assertThat(mWokenUp).isTrue();
+ }
+
+
+ @Test
public void shouldHandleTvPowerKey_CecDisabled() {
mHdmiCecLocalDevicePlayback.mService.getHdmiCecConfig().setIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
diff --git a/services/tests/servicestests/src/com/android/server/job/WorkCountTrackerTest.java b/services/tests/servicestests/src/com/android/server/job/WorkCountTrackerTest.java
index f9b25d9342d3..f87d5993c1b5 100644
--- a/services/tests/servicestests/src/com/android/server/job/WorkCountTrackerTest.java
+++ b/services/tests/servicestests/src/com/android/server/job/WorkCountTrackerTest.java
@@ -30,6 +30,7 @@ import android.annotation.NonNull;
import android.util.Pair;
import android.util.SparseIntArray;
+import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
@@ -496,6 +497,7 @@ public class WorkCountTrackerTest {
}
@Test
+ @LargeTest
public void testRandom13() {
assertThat(EQUAL_PROBABILITY_CDF.length).isEqualTo(NUM_WORK_TYPES);
@@ -508,9 +510,9 @@ public class WorkCountTrackerTest {
Pair.create(WORK_TYPE_BGUSER, 3));
final List<Pair<Integer, Integer>> minLimits =
List.of(Pair.create(WORK_TYPE_EJ, 2), Pair.create(WORK_TYPE_BG, 1));
- final double probStop = 0.01;
- final double[] numTypesCdf = buildCdf(0, 0.05, 0.05, 0.9);
- final double probStart = 0.99;
+ final double probStop = 0.13;
+ final double[] numTypesCdf = buildCdf(0, 0.05, 0.1, 0.85);
+ final double probStart = 0.87;
checkRandom(jobs, numTests, totalMax, minLimits, maxLimits, probStart,
EQUAL_PROBABILITY_CDF, numTypesCdf, probStop);
diff --git a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
index 6e5789686c55..50d9f6165204 100644
--- a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
@@ -601,6 +601,22 @@ public final class DataManagerTest {
}
@Test
+ public void testIsConversation() {
+ mDataManager.onUserUnlocked(USER_ID_PRIMARY);
+ assertThat(mDataManager.isConversation(TEST_PKG_NAME, USER_ID_PRIMARY,
+ TEST_SHORTCUT_ID)).isFalse();
+
+ ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
+ buildPerson());
+ shortcut.setCached(ShortcutInfo.FLAG_PINNED);
+ mDataManager.addOrUpdateConversationInfo(shortcut);
+ assertThat(mDataManager.isConversation(TEST_PKG_NAME, USER_ID_PRIMARY,
+ TEST_SHORTCUT_ID)).isTrue();
+ assertThat(mDataManager.isConversation(TEST_PKG_NAME, USER_ID_PRIMARY,
+ TEST_SHORTCUT_ID + "1")).isFalse();
+ }
+
+ @Test
public void testNotificationChannelCreated() {
mDataManager.onUserUnlocked(USER_ID_PRIMARY);
mDataManager.onUserUnlocked(USER_ID_SECONDARY);
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
index 23fcf701a8bb..4d0beef99cca 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
@@ -103,7 +103,6 @@ import android.util.TypedXmlSerializer;
import android.util.Xml;
import com.android.frameworks.servicestests.R;
-import com.android.internal.util.FastXmlSerializer;
import com.android.server.pm.ShortcutService.ConfigConstants;
import com.android.server.pm.ShortcutService.FileOutputStreamWithPath;
import com.android.server.pm.ShortcutUser.PackageWithUser;
@@ -111,7 +110,6 @@ import com.android.server.pm.ShortcutUser.PackageWithUser;
import org.mockito.ArgumentCaptor;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -141,6 +139,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
private static final int CACHE_OWNER_0 = LauncherApps.FLAG_CACHE_NOTIFICATION_SHORTCUTS;
private static final int CACHE_OWNER_1 = LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS;
+ private static final int CACHE_OWNER_2 = LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS;
@Override
protected void tearDown() throws Exception {
@@ -1531,7 +1530,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"),
makeLongLivedShortcut("s2"), makeLongLivedShortcut("s3"),
- makeLongLivedShortcut("s4"))));
+ makeLongLivedShortcut("s4"), makeLongLivedShortcut("s5"),
+ makeLongLivedShortcut("s6"))));
});
// Pin s2
@@ -1545,28 +1545,30 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
mInjectCheckAccessShortcutsPermission = true;
mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"),
HANDLE_USER_0, CACHE_OWNER_0);
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2", "s4"),
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2", "s4", "s5"),
HANDLE_USER_0, CACHE_OWNER_1);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s5", "s6"),
+ HANDLE_USER_0, CACHE_OWNER_2);
});
setCaller(CALLING_PACKAGE_1);
// Get dynamic shortcuts
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC),
- "s1", "s2", "s3", "s4");
+ "s1", "s2", "s3", "s4", "s5", "s6");
// Get pinned shortcuts
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED),
"s2");
// Get cached shortcuts
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
- "s2", "s4");
+ "s2", "s4", "s5", "s6");
// Remove a dynamic cached shortcut
- mManager.removeDynamicShortcuts(list("s4"));
+ mManager.removeDynamicShortcuts(list("s4", "s5"));
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC),
- "s1", "s2", "s3");
+ "s1", "s2", "s3", "s6");
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
- "s2", "s4");
+ "s2", "s4", "s5", "s6");
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s2", "s4"),
@@ -1574,15 +1576,21 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
});
// s2 still cached by owner1. s4 wasn't cached by owner0 so didn't get removed.
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
- "s2", "s4");
+ "s2", "s4", "s5", "s6");
// uncache a non-dynamic shortcut. Should be removed.
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s4"),
HANDLE_USER_0, CACHE_OWNER_1);
});
+
+ // uncache s6 by its only owner. s5 still cached by owner1
+ runWithCaller(LAUNCHER_1, USER_0, () -> {
+ mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s5", "s6"),
+ HANDLE_USER_0, CACHE_OWNER_2);
+ });
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
- "s2");
+ "s2", "s5");
// Cache another shortcut
runWithCaller(LAUNCHER_1, USER_0, () -> {
@@ -1590,14 +1598,14 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
HANDLE_USER_0, CACHE_OWNER_0);
});
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
- "s2", "s3");
+ "s2", "s3", "s5");
// Remove a dynamic cached pinned long lived shortcut
mManager.removeLongLivedShortcuts(list("s2"));
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC),
- "s1", "s3");
+ "s1", "s3", "s6");
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
- "s3");
+ "s3", "s5");
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED),
"s2");
}
diff --git a/services/tests/servicestests/src/com/android/server/pm/dex/DexMetadataHelperTest.java b/services/tests/servicestests/src/com/android/server/pm/dex/DexMetadataHelperTest.java
index 0dcd608e6bbd..a1b2f38af473 100644
--- a/services/tests/servicestests/src/com/android/server/pm/dex/DexMetadataHelperTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/dex/DexMetadataHelperTest.java
@@ -39,6 +39,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.frameworks.servicestests.R;
import com.android.server.pm.PackageManagerException;
import com.android.server.pm.parsing.TestPackageParser2;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.ParsedPackage;
@@ -55,6 +56,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -64,6 +67,9 @@ import java.util.zip.ZipOutputStream;
public class DexMetadataHelperTest {
private static final String APK_FILE_EXTENSION = ".apk";
private static final String DEX_METADATA_FILE_EXTENSION = ".dm";
+ private static final String DEX_METADATA_PACKAGE_NAME =
+ "com.android.frameworks.servicestests.install_split";
+ private static long DEX_METADATA_VERSION_CODE = 30;
@Rule
public TemporaryFolder mTemporaryFolder = new TemporaryFolder();
@@ -76,12 +82,46 @@ public class DexMetadataHelperTest {
}
private File createDexMetadataFile(String apkFileName) throws IOException {
+ return createDexMetadataFile(apkFileName, /*validManifest=*/true);
+ }
+
+ private File createDexMetadataFile(String apkFileName, boolean validManifest) throws IOException
+ {
+ return createDexMetadataFile(apkFileName,DEX_METADATA_PACKAGE_NAME,
+ DEX_METADATA_VERSION_CODE, /*emptyManifest=*/false, validManifest);
+ }
+
+ private File createDexMetadataFile(String apkFileName, String packageName, Long versionCode,
+ boolean emptyManifest, boolean validManifest) throws IOException {
File dmFile = new File(mTmpDir, apkFileName.replace(APK_FILE_EXTENSION,
DEX_METADATA_FILE_EXTENSION));
try (FileOutputStream fos = new FileOutputStream(dmFile)) {
try (ZipOutputStream zipOs = new ZipOutputStream(fos)) {
zipOs.putNextEntry(new ZipEntry("primary.prof"));
zipOs.closeEntry();
+
+ if (validManifest) {
+ zipOs.putNextEntry(new ZipEntry("manifest.json"));
+ if (!emptyManifest) {
+ String manifestStr = "{";
+
+ if (packageName != null) {
+ manifestStr += "\"packageName\": " + "\"" + packageName + "\"";
+
+ if (versionCode != null) {
+ manifestStr += ", ";
+ }
+ }
+ if (versionCode != null) {
+ manifestStr += " \"versionCode\": " + versionCode;
+ }
+
+ manifestStr += "}";
+ byte[] bytes = manifestStr.getBytes(StandardCharsets.UTF_8);
+ zipOs.write(bytes, /*off=*/0, /*len=*/bytes.length);
+ }
+ zipOs.closeEntry();
+ }
}
}
return dmFile;
@@ -96,17 +136,38 @@ public class DexMetadataHelperTest {
return outFile;
}
+ private static void validatePackageDexMetadata(AndroidPackage pkg, boolean requireManifest)
+ throws PackageParserException {
+ Collection<String> apkToDexMetadataList =
+ AndroidPackageUtils.getPackageDexMetadata(pkg).values();
+ String packageName = pkg.getPackageName();
+ long versionCode = pkg.toAppInfoWithoutState().longVersionCode;
+ for (String dexMetadata : apkToDexMetadataList) {
+ DexMetadataHelper.validateDexMetadataFile(
+ dexMetadata, packageName, versionCode, requireManifest);
+ }
+ }
+
+ private static void validatePackageDexMetatadataVaryingRequireManifest(ParsedPackage pkg)
+ throws PackageParserException {
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/false);
+ }
+
@Test
public void testParsePackageWithDmFileValid() throws IOException, PackageParserException {
copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
createDexMetadataFile("install_split_base.apk");
- ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, 0 /* flags */, false);
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
Map<String, String> packageDexMetadata = AndroidPackageUtils.getPackageDexMetadata(pkg);
assertEquals(1, packageDexMetadata.size());
String baseDexMetadata = packageDexMetadata.get(pkg.getBaseApkPath());
assertNotNull(baseDexMetadata);
assertTrue(isDexMetadataForApk(baseDexMetadata, pkg.getBaseApkPath()));
+
+ // Should throw no exceptions.
+ validatePackageDexMetatadataVaryingRequireManifest(pkg);
}
@Test
@@ -116,7 +177,7 @@ public class DexMetadataHelperTest {
copyApkToToTmpDir("install_split_feature_a.apk", R.raw.install_split_feature_a);
createDexMetadataFile("install_split_base.apk");
createDexMetadataFile("install_split_feature_a.apk");
- ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, 0 /* flags */, false);
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
Map<String, String> packageDexMetadata = AndroidPackageUtils.getPackageDexMetadata(pkg);
assertEquals(2, packageDexMetadata.size());
@@ -127,6 +188,9 @@ public class DexMetadataHelperTest {
String splitDexMetadata = packageDexMetadata.get(pkg.getSplitCodePaths()[0]);
assertNotNull(splitDexMetadata);
assertTrue(isDexMetadataForApk(splitDexMetadata, pkg.getSplitCodePaths()[0]));
+
+ // Should throw no exceptions.
+ validatePackageDexMetatadataVaryingRequireManifest(pkg);
}
@Test
@@ -135,7 +199,7 @@ public class DexMetadataHelperTest {
copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
copyApkToToTmpDir("install_split_feature_a.apk", R.raw.install_split_feature_a);
createDexMetadataFile("install_split_feature_a.apk");
- ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, 0 /* flags */, false);
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
Map<String, String> packageDexMetadata = AndroidPackageUtils.getPackageDexMetadata(pkg);
assertEquals(1, packageDexMetadata.size());
@@ -143,6 +207,9 @@ public class DexMetadataHelperTest {
String splitDexMetadata = packageDexMetadata.get(pkg.getSplitCodePaths()[0]);
assertNotNull(splitDexMetadata);
assertTrue(isDexMetadataForApk(splitDexMetadata, pkg.getSplitCodePaths()[0]));
+
+ // Should throw no exceptions.
+ validatePackageDexMetatadataVaryingRequireManifest(pkg);
}
@Test
@@ -151,9 +218,17 @@ public class DexMetadataHelperTest {
File invalidDmFile = new File(mTmpDir, "install_split_base.dm");
Files.createFile(invalidDmFile.toPath());
try {
- ParsedPackage pkg = new TestPackageParser2()
- .parsePackage(mTmpDir, 0 /* flags */, false);
- AndroidPackageUtils.validatePackageDexMetadata(pkg);
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: empty .dm file");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/false);
+ fail("Should fail validation: empty .dm file");
} catch (PackageParserException e) {
assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
}
@@ -169,9 +244,112 @@ public class DexMetadataHelperTest {
Files.createFile(invalidDmFile.toPath());
try {
- ParsedPackage pkg = new TestPackageParser2()
- .parsePackage(mTmpDir, 0 /* flags */, false);
- AndroidPackageUtils.validatePackageDexMetadata(pkg);
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: empty .dm file");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/false);
+ fail("Should fail validation: empty .dm file");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+ }
+
+ @Test
+ public void testParsePackageWithDmFileInvalidManifest()
+ throws IOException, PackageParserException {
+ copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
+ createDexMetadataFile("install_split_base.apk", /*validManifest=*/false);
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: missing manifest.json in the .dm archive");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+ }
+
+ @Test
+ public void testParsePackageWithDmFileEmptyManifest()
+ throws IOException, PackageParserException {
+ copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
+ createDexMetadataFile("install_split_base.apk", /*packageName=*/"doesn't matter",
+ /*versionCode=*/-12345L, /*emptyManifest=*/true, /*validManifest=*/true);
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: empty manifest.json in the .dm archive");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+ }
+
+ @Test
+ public void testParsePackageWithDmFileBadPackageName()
+ throws IOException, PackageParserException {
+ copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
+ createDexMetadataFile("install_split_base.apk", /*packageName=*/"bad package name",
+ DEX_METADATA_VERSION_CODE, /*emptyManifest=*/false, /*validManifest=*/true);
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: bad package name in the .dm archive");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+ }
+
+ @Test
+ public void testParsePackageWithDmFileBadVersionCode()
+ throws IOException, PackageParserException {
+ copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
+ createDexMetadataFile("install_split_base.apk", DEX_METADATA_PACKAGE_NAME,
+ /*versionCode=*/12345L, /*emptyManifest=*/false, /*validManifest=*/true);
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: bad version code in the .dm archive");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+ }
+
+ @Test
+ public void testParsePackageWithDmFileMissingPackageName()
+ throws IOException, PackageParserException {
+ copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
+ createDexMetadataFile("install_split_base.apk", /*packageName=*/null,
+ DEX_METADATA_VERSION_CODE, /*emptyManifest=*/false, /*validManifest=*/true);
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: missing package name in the .dm archive");
+ } catch (PackageParserException e) {
+ assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
+ }
+ }
+
+ @Test
+ public void testParsePackageWithDmFileMissingVersionCode()
+ throws IOException, PackageParserException {
+ copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
+ createDexMetadataFile("install_split_base.apk", DEX_METADATA_PACKAGE_NAME,
+ /*versionCode=*/null, /*emptyManifest=*/false, /*validManifest=*/true);
+
+ try {
+ ParsedPackage pkg = new TestPackageParser2().parsePackage(mTmpDir, /*flags=*/0, false);
+ validatePackageDexMetadata(pkg, /*requireManifest=*/true);
+ fail("Should fail validation: missing version code in the .dm archive");
} catch (PackageParserException e) {
assertEquals(e.error, PackageManager.INSTALL_FAILED_BAD_DEX_METADATA);
}
@@ -184,7 +362,7 @@ public class DexMetadataHelperTest {
try {
DexMetadataHelper.validateDexPaths(mTmpDir.list());
- fail("Should fail validation");
+ fail("Should fail validation: .dm filename has no match against .apk");
} catch (IllegalStateException e) {
// expected.
}
@@ -200,7 +378,7 @@ public class DexMetadataHelperTest {
try {
DexMetadataHelper.validateDexPaths(mTmpDir.list());
- fail("Should fail validation");
+ fail("Should fail validation: split .dm filename unmatched against .apk");
} catch (IllegalStateException e) {
// expected.
}
@@ -211,7 +389,7 @@ public class DexMetadataHelperTest {
copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base);
final File dm = createDexMetadataFile("install_split_base.apk");
final ParseResult<PackageLite> result = ApkLiteParseUtils.parsePackageLite(
- ParseTypeImpl.forDefaultParsing().reset(), mTmpDir, 0 /* flags */);
+ ParseTypeImpl.forDefaultParsing().reset(), mTmpDir, /*flags=*/0);
if (result.isError()) {
throw new IllegalStateException(result.getErrorMessage(), result.getException());
}
@@ -228,7 +406,7 @@ public class DexMetadataHelperTest {
try (FileInputStream is = new FileInputStream(base)) {
final ParseResult<ApkLite> result = ApkLiteParseUtils.parseApkLite(
ParseTypeImpl.forDefaultParsing().reset(), is.getFD(),
- base.getAbsolutePath(), /* flags */ 0);
+ base.getAbsolutePath(), /*flags=*/0);
if (result.isError()) {
throw new PackageManagerException(result.getErrorCode(),
result.getErrorMessage(), result.getException());
diff --git a/services/tests/servicestests/src/com/android/server/rotationresolver/OWNERS b/services/tests/servicestests/src/com/android/server/rotationresolver/OWNERS
new file mode 100644
index 000000000000..81b6f05a1658
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/rotationresolver/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/rotationresolver/OWNERS
diff --git a/services/tests/servicestests/src/com/android/server/rotationresolver/RotationResolverManagerPerUserServiceTest.java b/services/tests/servicestests/src/com/android/server/rotationresolver/RotationResolverManagerPerUserServiceTest.java
index 5f64249213ec..22c38c1961b8 100644
--- a/services/tests/servicestests/src/com/android/server/rotationresolver/RotationResolverManagerPerUserServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/rotationresolver/RotationResolverManagerPerUserServiceTest.java
@@ -19,15 +19,21 @@ package com.android.server.rotationresolver;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
import android.os.CancellationSignal;
import android.os.RemoteException;
import android.rotationresolver.RotationResolverInternal;
import android.view.Surface;
+import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.SmallTest;
import org.junit.Before;
@@ -41,75 +47,81 @@ import org.mockito.MockitoAnnotations;
*/
@SmallTest
public class RotationResolverManagerPerUserServiceTest {
-
- @Mock
- Context mContext;
+ private static final String PACKAGE_NAME = "test_pkg";
+ private static final String CLASS_NAME = "test_class";
@Mock
RotationResolverInternal.RotationResolverCallbackInternal mMockCallbackInternal;
-
@Mock
- ComponentName mMockComponentName;
+ PackageManager mMockPackageManager;
+ private Context mContext;
private CancellationSignal mCancellationSignal;
-
- private RotationResolverManagerPerUserService mSpyService;
+ private RotationResolverManagerPerUserService mService;
@Before
public void setUp() throws RemoteException {
MockitoAnnotations.initMocks(this);
- // setup context mock
+ // setup context.
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ doReturn(PACKAGE_NAME).when(mMockPackageManager).getRotationResolverPackageName();
+ doReturn(createTestingResolveInfo()).when(mMockPackageManager).resolveServiceAsUser(any(),
+ anyInt(), anyInt());
+ doReturn(mMockPackageManager).when(mContext).getPackageManager();
doReturn(true).when(mContext).bindServiceAsUser(any(), any(), anyInt(), any());
// setup a spy for the RotationResolverManagerPerUserService.
final RotationResolverManagerService mainService = new RotationResolverManagerService(
mContext);
- final RotationResolverManagerPerUserService mService =
- new RotationResolverManagerPerUserService(mainService, /* Lock */ new Object(),
- mContext.getUserId());
+ mService = new RotationResolverManagerPerUserService(mainService, /* Lock */ new Object(),
+ mContext.getUserId());
mCancellationSignal = new CancellationSignal();
- mSpyService = Mockito.spy(mService);
- mSpyService.mCurrentRequest = new RemoteRotationResolverService.RotationRequest(
+ this.mService.mCurrentRequest = new RemoteRotationResolverService.RotationRequest(
mMockCallbackInternal, Surface.ROTATION_0, Surface.ROTATION_0, "", 1000L,
mCancellationSignal);
- mSpyService.getMaster().mIsServiceEnabled = true;
+ this.mService.getMaster().mIsServiceEnabled = true;
- mSpyService.mRemoteService = new MockRemoteRotationResolverService(mContext,
- mMockComponentName, mContext.getUserId(),
+ ComponentName componentName = new ComponentName(PACKAGE_NAME, CLASS_NAME);
+ this.mService.mRemoteService = new MockRemoteRotationResolverService(mContext,
+ componentName, mContext.getUserId(),
/* idleUnbindTimeoutMs */60000L,
/* Lock */ new Object());
}
@Test
public void testResolveRotation_callOnSuccess() {
- doReturn(true).when(mSpyService).isServiceAvailableLocked();
- mSpyService.mCurrentRequest = null;
+ mService.mCurrentRequest = null;
RotationResolverInternal.RotationResolverCallbackInternal callbackInternal =
Mockito.mock(RotationResolverInternal.RotationResolverCallbackInternal.class);
- mSpyService.resolveRotationLocked(callbackInternal, Surface.ROTATION_0, Surface.ROTATION_0,
+ mService.resolveRotationLocked(callbackInternal, Surface.ROTATION_0, Surface.ROTATION_0,
"", 1000L, mCancellationSignal);
verify(callbackInternal).onSuccess(anyInt());
}
@Test
public void testResolveRotation_noCrashWhenCancelled() {
- doReturn(true).when(mSpyService).isServiceAvailableLocked();
-
RotationResolverInternal.RotationResolverCallbackInternal callbackInternal =
Mockito.mock(RotationResolverInternal.RotationResolverCallbackInternal.class);
final CancellationSignal cancellationSignal = new CancellationSignal();
- mSpyService.resolveRotationLocked(callbackInternal, Surface.ROTATION_0, Surface.ROTATION_0,
+ mService.resolveRotationLocked(callbackInternal, Surface.ROTATION_0, Surface.ROTATION_0,
"", 1000L, cancellationSignal);
cancellationSignal.cancel();
+ }
- verify(mSpyService.mCurrentRequest).cancelInternal();
+ private ResolveInfo createTestingResolveInfo() {
+ ResolveInfo resolveInfo = new ResolveInfo();
+ resolveInfo.serviceInfo = new ServiceInfo();
+ resolveInfo.serviceInfo.packageName = PACKAGE_NAME;
+ resolveInfo.serviceInfo.name = CLASS_NAME;
+ resolveInfo.serviceInfo.permission = Manifest.permission.BIND_ROTATION_RESOLVER_SERVICE;
+ return resolveInfo;
}
static class MockRemoteRotationResolverService extends RemoteRotationResolverService {
diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
index cc4d4eaa9e8b..e843dd71381f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
@@ -482,8 +482,7 @@ public class SizeCompatTests extends WindowTestsBase {
public void testHandleActivitySizeCompatModeChanged() {
setUpDisplaySizeWithApp(1000, 2000);
doReturn(true).when(mTask).isOrganized();
- ActivityRecord activity = mActivity;
- activity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatModeChanged");
+ mActivity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatModeChanged");
prepareUnresizable(mActivity, -1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
assertFitted();
@@ -499,12 +498,12 @@ public class SizeCompatTests extends WindowTestsBase {
// Make the activity resizable again by restarting it
clearInvocations(mTask);
- activity.info.resizeMode = RESIZE_MODE_RESIZEABLE;
- activity.mVisibleRequested = true;
- activity.restartProcessIfVisible();
+ mActivity.info.resizeMode = RESIZE_MODE_RESIZEABLE;
+ mActivity.mVisibleRequested = true;
+ mActivity.restartProcessIfVisible();
// The full lifecycle isn't hooked up so manually set state to resumed
- activity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatModeChanged");
- mTask.mDisplayContent.handleActivitySizeCompatModeIfNeeded(activity);
+ mActivity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatModeChanged");
+ mTask.mDisplayContent.handleActivitySizeCompatModeIfNeeded(mActivity);
// Expect null token when switching to non-size-compat mode activity.
verify(mTask).onSizeCompatActivityChanged();
@@ -515,6 +514,46 @@ public class SizeCompatTests extends WindowTestsBase {
}
@Test
+ public void testHandleActivitySizeCompatModeChangedOnDifferentTask() {
+ setUpDisplaySizeWithApp(1000, 2000);
+ doReturn(true).when(mTask).isOrganized();
+ mActivity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatModeChanged");
+ prepareUnresizable(mActivity, -1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
+ assertFitted();
+
+ // Resize the display so that the activity exercises size-compat mode.
+ resizeDisplay(mTask.mDisplayContent, 1000, 2500);
+
+ // Expect the exact token when the activity is in size compatibility mode.
+ verify(mTask).onSizeCompatActivityChanged();
+ ActivityManager.RunningTaskInfo taskInfo = mTask.getTaskInfo();
+
+ assertEquals(mActivity.appToken, taskInfo.topActivityToken);
+ assertTrue(taskInfo.topActivityInSizeCompat);
+
+ // Create another Task to hold another size compat activity.
+ clearInvocations(mTask);
+ final Task secondTask = new TaskBuilder(mSupervisor).setDisplay(mTask.getDisplayContent())
+ .setCreateActivity(true).build();
+ final ActivityRecord secondActivity = secondTask.getTopNonFinishingActivity();
+ doReturn(true).when(secondTask).isOrganized();
+ secondActivity.setState(Task.ActivityState.RESUMED,
+ "testHandleActivitySizeCompatModeChanged");
+ prepareUnresizable(secondActivity, -1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
+
+ // Resize the display so that the activity exercises size-compat mode.
+ resizeDisplay(mTask.mDisplayContent, 1000, 3000);
+
+ // Expect the exact token when the activity is in size compatibility mode.
+ verify(secondTask).onSizeCompatActivityChanged();
+ verify(mTask, never()).onSizeCompatActivityChanged();
+ taskInfo = secondTask.getTaskInfo();
+
+ assertEquals(secondActivity.appToken, taskInfo.topActivityToken);
+ assertTrue(taskInfo.topActivityInSizeCompat);
+ }
+
+ @Test
public void testShouldUseSizeCompatModeOnResizableTask() {
setUpDisplaySizeWithApp(1000, 2500);
diff --git a/services/texttospeech/Android.bp b/services/texttospeech/Android.bp
new file mode 100644
index 000000000000..bacc932f760f
--- /dev/null
+++ b/services/texttospeech/Android.bp
@@ -0,0 +1,13 @@
+filegroup {
+ name: "services.texttospeech-sources",
+ srcs: ["java/**/*.java"],
+ path: "java",
+ visibility: ["//frameworks/base/services"],
+}
+
+java_library_static {
+ name: "services.texttospeech",
+ defaults: ["platform_service_defaults"],
+ srcs: [":services.texttospeech-sources"],
+ libs: ["services.core"],
+} \ No newline at end of file
diff --git a/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java b/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java
new file mode 100644
index 000000000000..f80590420d09
--- /dev/null
+++ b/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java
@@ -0,0 +1,184 @@
+/*
+ * 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.server.texttospeech;
+
+import static com.android.internal.infra.AbstractRemoteService.PERMANENT_BOUND_TIMEOUT_MS;
+
+import android.annotation.NonNull;
+import android.annotation.UserIdInt;
+import android.app.AppGlobals;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ServiceInfo;
+import android.os.IBinder.DeathRecipient;
+import android.os.RemoteException;
+import android.speech.tts.ITextToSpeechService;
+import android.speech.tts.ITextToSpeechSession;
+import android.speech.tts.ITextToSpeechSessionCallback;
+import android.speech.tts.TextToSpeech;
+import android.util.Slog;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.infra.ServiceConnector;
+import com.android.server.infra.AbstractPerUserSystemService;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Manages per-user text to speech session activated by {@link TextToSpeechManagerService}.
+ * Creates {@link TtsClient} interface object with direct connection to
+ * {@link android.speech.tts.TextToSpeechService} provider.
+ *
+ * @see ITextToSpeechSession
+ * @see TextToSpeech
+ */
+final class TextToSpeechManagerPerUserService extends
+ AbstractPerUserSystemService<TextToSpeechManagerPerUserService,
+ TextToSpeechManagerService> {
+
+ private static final String TAG = TextToSpeechManagerPerUserService.class.getSimpleName();
+
+ TextToSpeechManagerPerUserService(
+ @NonNull TextToSpeechManagerService master,
+ @NonNull Object lock, @UserIdInt int userId) {
+ super(master, lock, userId);
+ }
+
+ void createSessionLocked(String engine, ITextToSpeechSessionCallback sessionCallback) {
+ TextToSpeechSessionConnection.start(getContext(), mUserId, engine, sessionCallback);
+ }
+
+ @GuardedBy("mLock")
+ @Override // from PerUserSystemService
+ @NonNull
+ protected ServiceInfo newServiceInfoLocked(
+ @SuppressWarnings("unused") @NonNull ComponentName serviceComponent)
+ throws PackageManager.NameNotFoundException {
+ try {
+ return AppGlobals.getPackageManager().getServiceInfo(serviceComponent,
+ PackageManager.GET_META_DATA, mUserId);
+ } catch (RemoteException e) {
+ throw new PackageManager.NameNotFoundException(
+ "Could not get service for " + serviceComponent);
+ }
+ }
+
+ private static class TextToSpeechSessionConnection extends
+ ServiceConnector.Impl<ITextToSpeechService> {
+
+ private final String mEngine;
+ private final ITextToSpeechSessionCallback mCallback;
+ private final DeathRecipient mUnbindOnDeathHandler;
+
+ static void start(Context context, @UserIdInt int userId, String engine,
+ ITextToSpeechSessionCallback callback) {
+ new TextToSpeechSessionConnection(context, userId, engine, callback).start();
+ }
+
+ private TextToSpeechSessionConnection(Context context, @UserIdInt int userId, String engine,
+ ITextToSpeechSessionCallback callback) {
+ super(context,
+ new Intent(TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE).setPackage(engine),
+ Context.BIND_AUTO_CREATE,
+ userId,
+ ITextToSpeechService.Stub::asInterface);
+ mEngine = engine;
+ mCallback = callback;
+ mUnbindOnDeathHandler = () -> unbindEngine("client process death is reported");
+ }
+
+ private void start() {
+ Slog.d(TAG, "Trying to start connection to TTS engine: " + mEngine);
+
+ connect()
+ .thenAccept(
+ serviceBinder -> {
+ if (serviceBinder != null) {
+ Slog.d(TAG,
+ "Connected successfully to TTS engine: " + mEngine);
+ try {
+ mCallback.onConnected(new ITextToSpeechSession.Stub() {
+ @Override
+ public void disconnect() {
+ unbindEngine("client disconnection request");
+ }
+ }, serviceBinder.asBinder());
+
+ mCallback.asBinder().linkToDeath(mUnbindOnDeathHandler, 0);
+ } catch (RemoteException ex) {
+ Slog.w(TAG, "Error notifying the client on connection", ex);
+
+ unbindEngine(
+ "failed communicating with the client - process "
+ + "is dead");
+ }
+ } else {
+ Slog.w(TAG, "Failed to obtain TTS engine binder");
+ runSessionCallbackMethod(
+ () -> mCallback.onError("Failed creating TTS session"));
+ }
+ })
+ .exceptionally(ex -> {
+ Slog.w(TAG, "TTS engine binding error", ex);
+ runSessionCallbackMethod(
+ () -> mCallback.onError(
+ "Failed creating TTS session: " + ex.getCause()));
+
+ return null;
+ });
+ }
+
+ @Override // from ServiceConnector.Impl
+ protected void onServiceConnectionStatusChanged(
+ ITextToSpeechService service, boolean connected) {
+ if (!connected) {
+ Slog.w(TAG, "Disconnected from TTS engine");
+ runSessionCallbackMethod(mCallback::onDisconnected);
+
+ try {
+ mCallback.asBinder().unlinkToDeath(mUnbindOnDeathHandler, 0);
+ } catch (NoSuchElementException ex) {
+ Slog.d(TAG, "The death recipient was not linked.");
+ }
+ }
+ }
+
+ @Override // from ServiceConnector.Impl
+ protected long getAutoDisconnectTimeoutMs() {
+ return PERMANENT_BOUND_TIMEOUT_MS;
+ }
+
+ private void unbindEngine(String reason) {
+ Slog.d(TAG, "Unbinding TTS engine: " + mEngine + ". Reason: " + reason);
+ unbind();
+ }
+ }
+
+ static void runSessionCallbackMethod(ThrowingRunnable callbackRunnable) {
+ try {
+ callbackRunnable.runOrThrow();
+ } catch (RemoteException ex) {
+ Slog.w(TAG, "Failed running callback method", ex);
+ }
+ }
+
+ interface ThrowingRunnable {
+ void runOrThrow() throws RemoteException;
+ }
+}
diff --git a/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerService.java b/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerService.java
new file mode 100644
index 000000000000..9015563f439e
--- /dev/null
+++ b/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerService.java
@@ -0,0 +1,77 @@
+/*
+ * 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.server.texttospeech;
+
+import static com.android.server.texttospeech.TextToSpeechManagerPerUserService.runSessionCallbackMethod;
+
+import android.annotation.NonNull;
+import android.annotation.UserIdInt;
+import android.content.Context;
+import android.os.UserHandle;
+import android.speech.tts.ITextToSpeechManager;
+import android.speech.tts.ITextToSpeechSessionCallback;
+
+import com.android.server.infra.AbstractMasterSystemService;
+
+
+/**
+ * A service that allows secured synthesizing of text to speech audio. Upon request creates a
+ * session
+ * that is managed by {@link TextToSpeechManagerPerUserService}.
+ *
+ * @see ITextToSpeechManager
+ */
+public final class TextToSpeechManagerService extends
+ AbstractMasterSystemService<TextToSpeechManagerService,
+ TextToSpeechManagerPerUserService> {
+
+ private static final String TAG = TextToSpeechManagerService.class.getSimpleName();
+
+ public TextToSpeechManagerService(@NonNull Context context) {
+ super(context, /* serviceNameResolver= */ null,
+ /* disallowProperty = */null);
+ }
+
+ @Override // from SystemService
+ public void onStart() {
+ publishBinderService(Context.TEXT_TO_SPEECH_MANAGER_SERVICE,
+ new TextToSpeechManagerServiceStub());
+ }
+
+ @Override
+ protected TextToSpeechManagerPerUserService newServiceLocked(
+ @UserIdInt int resolvedUserId, boolean disabled) {
+ return new TextToSpeechManagerPerUserService(this, mLock, resolvedUserId);
+ }
+
+ private final class TextToSpeechManagerServiceStub extends ITextToSpeechManager.Stub {
+ @Override
+ public void createSession(String engine,
+ ITextToSpeechSessionCallback sessionCallback) {
+ synchronized (mLock) {
+ TextToSpeechManagerPerUserService perUserService = getServiceForUserLocked(
+ UserHandle.getCallingUserId());
+ if (perUserService != null) {
+ perUserService.createSessionLocked(engine, sessionCallback);
+ } else {
+ runSessionCallbackMethod(
+ () -> sessionCallback.onError("Service is not available for user"));
+ }
+ }
+ }
+ }
+}
diff --git a/services/usb/Android.bp b/services/usb/Android.bp
index aa8bbde8b32a..89e5d5f15242 100644
--- a/services/usb/Android.bp
+++ b/services/usb/Android.bp
@@ -19,6 +19,7 @@ java_library_static {
"android.hardware.usb-V1.0-java",
"android.hardware.usb-V1.1-java",
"android.hardware.usb-V1.2-java",
+ "android.hardware.usb-V1.3-java",
"android.hardware.usb.gadget-V1.0-java",
"android.hardware.usb.gadget-V1.1-java",
"android.hardware.usb.gadget-V1.2-java",
diff --git a/services/usb/java/com/android/server/usb/UsbPortManager.java b/services/usb/java/com/android/server/usb/UsbPortManager.java
index ca18c57d6f4b..6bf67154efd5 100644
--- a/services/usb/java/com/android/server/usb/UsbPortManager.java
+++ b/services/usb/java/com/android/server/usb/UsbPortManager.java
@@ -42,13 +42,13 @@ import android.hardware.usb.ParcelableUsbPort;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
-import android.hardware.usb.V1_0.IUsb;
import android.hardware.usb.V1_0.PortRole;
import android.hardware.usb.V1_0.PortRoleType;
import android.hardware.usb.V1_0.Status;
import android.hardware.usb.V1_1.PortStatus_1_1;
import android.hardware.usb.V1_2.IUsbCallback;
import android.hardware.usb.V1_2.PortStatus;
+import android.hardware.usb.V1_3.IUsb;
import android.hidl.manager.V1_0.IServiceManager;
import android.hidl.manager.V1_0.IServiceNotification;
import android.os.Bundle;
@@ -156,6 +156,9 @@ public class UsbPortManager {
*/
private int mIsPortContaminatedNotificationId;
+ private boolean mEnableUsbDataSignaling;
+ protected int mCurrentUsbHalVersion;
+
public UsbPortManager(Context context) {
mContext = context;
try {
@@ -181,6 +184,7 @@ public class UsbPortManager {
if (mProxy != null) {
try {
mProxy.queryPortStatus();
+ mEnableUsbDataSignaling = true;
} catch (RemoteException e) {
logAndPrintException(null,
"ServiceStart: Failed to query port status", e);
@@ -346,6 +350,66 @@ public class UsbPortManager {
}
}
+ /**
+ * Enable/disable the USB data signaling
+ *
+ * @param enable enable or disable USB data signaling
+ */
+ public boolean enableUsbDataSignal(boolean enable) {
+ try {
+ mEnableUsbDataSignaling = enable;
+ // Call into the hal. Use the castFrom method from HIDL.
+ android.hardware.usb.V1_3.IUsb proxy = android.hardware.usb.V1_3.IUsb.castFrom(mProxy);
+ return proxy.enableUsbDataSignal(enable);
+ } catch (RemoteException e) {
+ logAndPrintException(null, "Failed to set USB data signaling", e);
+ return false;
+ } catch (ClassCastException e) {
+ logAndPrintException(null, "Method only applicable to V1.3 or above implementation", e);
+ return false;
+ }
+ }
+
+ /**
+ * Get USB HAL version
+ *
+ * @param none
+ */
+ public int getUsbHalVersion() {
+ return mCurrentUsbHalVersion;
+ }
+
+ /**
+ * update USB HAL version
+ *
+ * @param none
+ */
+ private void updateUsbHalVersion() {
+ android.hardware.usb.V1_3.IUsb usbProxy_V1_3 =
+ android.hardware.usb.V1_3.IUsb.castFrom(mProxy);
+ if (usbProxy_V1_3 != null) {
+ mCurrentUsbHalVersion = UsbManager.USB_HAL_V1_3;
+ return;
+ }
+
+ android.hardware.usb.V1_2.IUsb usbProxy_V1_2 =
+ android.hardware.usb.V1_2.IUsb.castFrom(mProxy);
+ if (usbProxy_V1_2 != null) {
+ mCurrentUsbHalVersion = UsbManager.USB_HAL_V1_2;
+ return;
+ }
+
+ android.hardware.usb.V1_1.IUsb usbProxy_V1_1 =
+ android.hardware.usb.V1_1.IUsb.castFrom(mProxy);
+ if (usbProxy_V1_1 != null) {
+ mCurrentUsbHalVersion = UsbManager.USB_HAL_V1_1;
+ return;
+ }
+
+ mCurrentUsbHalVersion = UsbManager.USB_HAL_V1_0;
+ return;
+ }
+
public void setPortRoles(String portId, int newPowerRole, int newDataRole,
IndentingPrintWriter pw) {
synchronized (mLock) {
@@ -610,6 +674,9 @@ public class UsbPortManager {
for (PortInfo portInfo : mPorts.values()) {
portInfo.dump(dump, "usb_ports", UsbPortManagerProto.USB_PORTS);
}
+
+ dump.write("enable_usb_data_signaling", UsbPortManagerProto.ENABLE_USB_DATA_SIGNALING,
+ mEnableUsbDataSignaling);
}
dump.end(token);
@@ -783,6 +850,7 @@ public class UsbPortManager {
mProxy.linkToDeath(new DeathRecipient(pw), USB_HAL_DEATH_COOKIE);
mProxy.setCallback(mHALCallback);
mProxy.queryPortStatus();
+ mCurrentUsbHalVersion = UsbManager.USB_HAL_V1_0;
} catch (NoSuchElementException e) {
logAndPrintException(pw, "connectToProxy: usb hal service not found."
+ " Did the service fail to start?", e);
@@ -1115,6 +1183,7 @@ public class UsbPortManager {
case MSG_SYSTEM_READY: {
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ updateUsbHalVersion();
break;
}
}
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
index edd4a3874c94..9a13d7648be2 100644
--- a/services/usb/java/com/android/server/usb/UsbService.java
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -745,6 +745,38 @@ public class UsbService extends IUsbManager.Stub {
}
@Override
+ public int getUsbHalVersion() {
+ mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ if (mPortManager != null) {
+ return mPortManager.getUsbHalVersion();
+ } else {
+ return UsbManager.USB_HAL_NOT_SUPPORTED;
+ }
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
+ @Override
+ public boolean enableUsbDataSignal(boolean enable) {
+ mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ if (mPortManager != null) {
+ return mPortManager.enableUsbDataSignal(enable);
+ } else {
+ return false;
+ }
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
+ @Override
public void setUsbDeviceConnectionHandler(ComponentName usbDeviceConnectionHandler) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
synchronized (mLock) {
diff --git a/telecomm/java/android/telecom/CallScreeningService.aidl b/telecomm/java/android/telecom/CallScreeningService.aidl
new file mode 100644
index 000000000000..87b5138745f2
--- /dev/null
+++ b/telecomm/java/android/telecom/CallScreeningService.aidl
@@ -0,0 +1,22 @@
+/*
+ * 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
+ */
+
+package android.telecom;
+
+/**
+ * {@hide}
+ */
+parcelable CallScreeningService.ParcelableCallResponse;
diff --git a/telecomm/java/android/telecom/CallScreeningService.java b/telecomm/java/android/telecom/CallScreeningService.java
index 7988b036ccd3..deeb4331bcaa 100644
--- a/telecomm/java/android/telecom/CallScreeningService.java
+++ b/telecomm/java/android/telecom/CallScreeningService.java
@@ -17,6 +17,7 @@
package android.telecom;
import android.Manifest;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
@@ -30,12 +31,18 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.os.RemoteException;
import com.android.internal.os.SomeArgs;
import com.android.internal.telecom.ICallScreeningAdapter;
import com.android.internal.telecom.ICallScreeningService;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
+
/**
* This service can be implemented by the default dialer (see
* {@link TelecomManager#getDefaultDialerPackage()}) or a third party app to allow or disallow
@@ -132,7 +139,10 @@ public abstract class CallScreeningService extends Service {
.createFromParcelableCall((ParcelableCall) args.arg2);
onScreenCall(callDetails);
if (callDetails.getCallDirection() == Call.Details.DIRECTION_OUTGOING) {
- mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId());
+ mCallScreeningAdapter.onScreeningResponse(
+ callDetails.getTelecomCallId(),
+ new ComponentName(getPackageName(), getClass().getName()),
+ null);
}
} catch (RemoteException e) {
Log.w(this, "Exception when screening call: " + e);
@@ -157,16 +167,171 @@ public abstract class CallScreeningService extends Service {
private ICallScreeningAdapter mCallScreeningAdapter;
- /*
- * Information about how to respond to an incoming call.
+ /**
+ * Parcelable version of {@link CallResponse} used to do IPC.
+ * @hide
+ */
+ public static class ParcelableCallResponse implements Parcelable {
+ private final boolean mShouldDisallowCall;
+ private final boolean mShouldRejectCall;
+ private final boolean mShouldSilenceCall;
+ private final boolean mShouldSkipCallLog;
+ private final boolean mShouldSkipNotification;
+ private final boolean mShouldScreenCallViaAudioProcessing;
+
+ private final int mCallComposerAttachmentsToShow;
+
+ private ParcelableCallResponse(
+ boolean shouldDisallowCall,
+ boolean shouldRejectCall,
+ boolean shouldSilenceCall,
+ boolean shouldSkipCallLog,
+ boolean shouldSkipNotification,
+ boolean shouldScreenCallViaAudioProcessing,
+ int callComposerAttachmentsToShow) {
+ mShouldDisallowCall = shouldDisallowCall;
+ mShouldRejectCall = shouldRejectCall;
+ mShouldSilenceCall = shouldSilenceCall;
+ mShouldSkipCallLog = shouldSkipCallLog;
+ mShouldSkipNotification = shouldSkipNotification;
+ mShouldScreenCallViaAudioProcessing = shouldScreenCallViaAudioProcessing;
+ mCallComposerAttachmentsToShow = callComposerAttachmentsToShow;
+ }
+
+ protected ParcelableCallResponse(Parcel in) {
+ mShouldDisallowCall = in.readBoolean();
+ mShouldRejectCall = in.readBoolean();
+ mShouldSilenceCall = in.readBoolean();
+ mShouldSkipCallLog = in.readBoolean();
+ mShouldSkipNotification = in.readBoolean();
+ mShouldScreenCallViaAudioProcessing = in.readBoolean();
+ mCallComposerAttachmentsToShow = in.readInt();
+ }
+
+ public CallResponse toCallResponse() {
+ return new CallResponse.Builder()
+ .setDisallowCall(mShouldDisallowCall)
+ .setRejectCall(mShouldRejectCall)
+ .setSilenceCall(mShouldSilenceCall)
+ .setSkipCallLog(mShouldSkipCallLog)
+ .setSkipNotification(mShouldSkipNotification)
+ .setShouldScreenCallViaAudioProcessing(mShouldScreenCallViaAudioProcessing)
+ .setCallComposerAttachmentsToShow(mCallComposerAttachmentsToShow)
+ .build();
+ }
+
+ public boolean shouldDisallowCall() {
+ return mShouldDisallowCall;
+ }
+
+ public boolean shouldRejectCall() {
+ return mShouldRejectCall;
+ }
+
+ public boolean shouldSilenceCall() {
+ return mShouldSilenceCall;
+ }
+
+ public boolean shouldSkipCallLog() {
+ return mShouldSkipCallLog;
+ }
+
+ public boolean shouldSkipNotification() {
+ return mShouldSkipNotification;
+ }
+
+ public boolean shouldScreenCallViaAudioProcessing() {
+ return mShouldScreenCallViaAudioProcessing;
+ }
+
+ public int getCallComposerAttachmentsToShow() {
+ return mCallComposerAttachmentsToShow;
+ }
+
+ public static final Creator<ParcelableCallResponse> CREATOR =
+ new Creator<ParcelableCallResponse>() {
+ @Override
+ public ParcelableCallResponse createFromParcel(Parcel in) {
+ return new ParcelableCallResponse(in);
+ }
+
+ @Override
+ public ParcelableCallResponse[] newArray(int size) {
+ return new ParcelableCallResponse[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeBoolean(mShouldDisallowCall);
+ dest.writeBoolean(mShouldRejectCall);
+ dest.writeBoolean(mShouldSilenceCall);
+ dest.writeBoolean(mShouldSkipCallLog);
+ dest.writeBoolean(mShouldSkipNotification);
+ dest.writeBoolean(mShouldScreenCallViaAudioProcessing);
+ dest.writeInt(mCallComposerAttachmentsToShow);
+ }
+ }
+
+ /**
+ * Information about how to respond to an incoming call. Call screening apps can construct an
+ * instance of this class using {@link CallResponse.Builder}.
*/
public static class CallResponse {
+ /**
+ * Bit flag indicating whether to show the picture attachment for call composer.
+ *
+ * Used with {@link Builder#setCallComposerAttachmentsToShow(int)}.
+ */
+ public static final int CALL_COMPOSER_ATTACHMENT_PICTURE = 1;
+
+ /**
+ * Bit flag indicating whether to show the location attachment for call composer.
+ *
+ * Used with {@link Builder#setCallComposerAttachmentsToShow(int)}.
+ */
+ public static final int CALL_COMPOSER_ATTACHMENT_LOCATION = 1 << 1;
+
+ /**
+ * Bit flag indicating whether to show the subject attachment for call composer.
+ *
+ * Used with {@link Builder#setCallComposerAttachmentsToShow(int)}.
+ */
+ public static final int CALL_COMPOSER_ATTACHMENT_SUBJECT = 1 << 2;
+
+ /**
+ * Bit flag indicating whether to show the priority attachment for call composer.
+ *
+ * Used with {@link Builder#setCallComposerAttachmentsToShow(int)}.
+ */
+ public static final int CALL_COMPOSER_ATTACHMENT_PRIORITY = 1 << 3;
+
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(prefix = "CALL_COMPOSER_ATTACHMENT_", flag = true,
+ value = {
+ CALL_COMPOSER_ATTACHMENT_PICTURE,
+ CALL_COMPOSER_ATTACHMENT_LOCATION,
+ CALL_COMPOSER_ATTACHMENT_SUBJECT,
+ CALL_COMPOSER_ATTACHMENT_PRIORITY
+ }
+ )
+ public @interface CallComposerAttachmentType {}
+
+ private static final int NUM_CALL_COMPOSER_ATTACHMENT_TYPES = 4;
+
private final boolean mShouldDisallowCall;
private final boolean mShouldRejectCall;
private final boolean mShouldSilenceCall;
private final boolean mShouldSkipCallLog;
private final boolean mShouldSkipNotification;
private final boolean mShouldScreenCallViaAudioProcessing;
+ private final int mCallComposerAttachmentsToShow;
private CallResponse(
boolean shouldDisallowCall,
@@ -174,7 +339,8 @@ public abstract class CallScreeningService extends Service {
boolean shouldSilenceCall,
boolean shouldSkipCallLog,
boolean shouldSkipNotification,
- boolean shouldScreenCallViaAudioProcessing) {
+ boolean shouldScreenCallViaAudioProcessing,
+ int callComposerAttachmentsToShow) {
if (!shouldDisallowCall
&& (shouldRejectCall || shouldSkipCallLog || shouldSkipNotification)) {
throw new IllegalStateException("Invalid response state for allowed call.");
@@ -190,6 +356,7 @@ public abstract class CallScreeningService extends Service {
mShouldSkipNotification = shouldSkipNotification;
mShouldSilenceCall = shouldSilenceCall;
mShouldScreenCallViaAudioProcessing = shouldScreenCallViaAudioProcessing;
+ mCallComposerAttachmentsToShow = callComposerAttachmentsToShow;
}
/*
@@ -237,6 +404,49 @@ public abstract class CallScreeningService extends Service {
return mShouldScreenCallViaAudioProcessing;
}
+ /**
+ * @return A bitmask of call composer attachments that should be shown to the user.
+ */
+ public @CallComposerAttachmentType int getCallComposerAttachmentsToShow() {
+ return mCallComposerAttachmentsToShow;
+ }
+
+ /** @hide */
+ public ParcelableCallResponse toParcelable() {
+ return new ParcelableCallResponse(
+ mShouldDisallowCall,
+ mShouldRejectCall,
+ mShouldSilenceCall,
+ mShouldSkipCallLog,
+ mShouldSkipNotification,
+ mShouldScreenCallViaAudioProcessing,
+ mCallComposerAttachmentsToShow
+ );
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ CallResponse that = (CallResponse) o;
+ return mShouldDisallowCall == that.mShouldDisallowCall &&
+ mShouldRejectCall == that.mShouldRejectCall &&
+ mShouldSilenceCall == that.mShouldSilenceCall &&
+ mShouldSkipCallLog == that.mShouldSkipCallLog &&
+ mShouldSkipNotification == that.mShouldSkipNotification &&
+ mShouldScreenCallViaAudioProcessing
+ == that.mShouldScreenCallViaAudioProcessing &&
+ mCallComposerAttachmentsToShow == that.mCallComposerAttachmentsToShow;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mShouldDisallowCall, mShouldRejectCall, mShouldSilenceCall,
+ mShouldSkipCallLog, mShouldSkipNotification,
+ mShouldScreenCallViaAudioProcessing,
+ mCallComposerAttachmentsToShow);
+ }
+
public static class Builder {
private boolean mShouldDisallowCall;
private boolean mShouldRejectCall;
@@ -244,6 +454,7 @@ public abstract class CallScreeningService extends Service {
private boolean mShouldSkipCallLog;
private boolean mShouldSkipNotification;
private boolean mShouldScreenCallViaAudioProcessing;
+ private int mCallComposerAttachmentsToShow = -1;
/**
* Sets whether the incoming call should be blocked.
@@ -329,6 +540,38 @@ public abstract class CallScreeningService extends Service {
return this;
}
+ /**
+ * Sets the call composer attachments that should be shown to the user.
+ *
+ * Attachments that are not shown will not be passed to the in-call UI responsible for
+ * displaying the call to the user.
+ *
+ * If this method is not called on a {@link Builder}, all attachments will be shown,
+ * except pictures, which will only be shown to users if the call is from a contact.
+ *
+ * Setting attachments to show will have no effect if the call screening service does
+ * not belong to the same package as the system dialer (as returned by
+ * {@link TelecomManager#getSystemDialerPackage()}).
+ *
+ * @param callComposerAttachmentsToShow A bitmask of call composer attachments to show.
+ */
+ public @NonNull Builder setCallComposerAttachmentsToShow(
+ @CallComposerAttachmentType int callComposerAttachmentsToShow) {
+ // If the argument is less than zero (meaning unset), no-op since the conversion
+ // to/from the parcelable version may call with that value.
+ if (callComposerAttachmentsToShow < 0) {
+ return this;
+ }
+
+ if ((callComposerAttachmentsToShow
+ & (1 << NUM_CALL_COMPOSER_ATTACHMENT_TYPES)) != 0) {
+ throw new IllegalArgumentException("Attachment types must match the ones"
+ + " defined in CallResponse");
+ }
+ mCallComposerAttachmentsToShow = callComposerAttachmentsToShow;
+ return this;
+ }
+
public CallResponse build() {
return new CallResponse(
mShouldDisallowCall,
@@ -336,7 +579,8 @@ public abstract class CallScreeningService extends Service {
mShouldSilenceCall,
mShouldSkipCallLog,
mShouldSkipNotification,
- mShouldScreenCallViaAudioProcessing);
+ mShouldScreenCallViaAudioProcessing,
+ mCallComposerAttachmentsToShow);
}
}
}
@@ -423,21 +667,12 @@ public abstract class CallScreeningService extends Service {
public final void respondToCall(@NonNull Call.Details callDetails,
@NonNull CallResponse response) {
try {
- if (response.getDisallowCall()) {
- mCallScreeningAdapter.disallowCall(
- callDetails.getTelecomCallId(),
- response.getRejectCall(),
- !response.getSkipCallLog(),
- !response.getSkipNotification(),
- new ComponentName(getPackageName(), getClass().getName()));
- } else if (response.getSilenceCall()) {
- mCallScreeningAdapter.silenceCall(callDetails.getTelecomCallId());
- } else if (response.getShouldScreenCallViaAudioProcessing()) {
- mCallScreeningAdapter.screenCallFurther(callDetails.getTelecomCallId());
- } else {
- mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId());
- }
+ mCallScreeningAdapter.onScreeningResponse(
+ callDetails.getTelecomCallId(),
+ new ComponentName(getPackageName(), getClass().getName()),
+ response.toParcelable());
} catch (RemoteException e) {
+ Log.e(this, e, "Got remote exception when returning response");
}
}
}
diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java
index 089a948b6e55..942a54eb98ba 100644
--- a/telecomm/java/android/telecom/Connection.java
+++ b/telecomm/java/android/telecom/Connection.java
@@ -3390,11 +3390,20 @@ public abstract class Connection extends Conferenceable {
* {@code true}, {@link #onDisconnect()} will be called soon after
* this is called.
* @param isInContacts Indicates whether the caller is in the user's contacts list.
+ * @param callScreeningResponse The response that was returned from the
+ * {@link CallScreeningService} that handled this call. If no
+ * response was received from a call screening service,
+ * this will be {@code null}.
+ * @param isResponseFromSystemDialer Whether {@code callScreeningResponse} was sent from the
+ * system dialer. If {@code callScreeningResponse} is
+ * {@code null}, this will be {@code false}.
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.READ_CONTACTS)
- public void onCallFilteringCompleted(boolean isBlocked, boolean isInContacts) { }
+ public void onCallFilteringCompleted(boolean isBlocked, boolean isInContacts,
+ @Nullable CallScreeningService.CallResponse callScreeningResponse,
+ boolean isResponseFromSystemDialer) { }
static String toLogSafePhoneNumber(String number) {
// For unknown number, log empty string.
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 170ed3eff614..966ece3a3ba2 100755
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -759,6 +759,8 @@ public abstract class ConnectionService extends Service {
@Override
public void onCallFilteringCompleted(String callId, boolean isBlocked, boolean isInContacts,
+ CallScreeningService.ParcelableCallResponse callScreeningResponse,
+ boolean isResponseFromSystemDialer,
Session.Info sessionInfo) {
Log.startSession(sessionInfo, SESSION_CALL_FILTERING_COMPLETED);
try {
@@ -766,7 +768,9 @@ public abstract class ConnectionService extends Service {
args.arg1 = callId;
args.arg2 = isBlocked;
args.arg3 = isInContacts;
- args.arg4 = Log.createSubsession();
+ args.arg4 = callScreeningResponse;
+ args.arg5 = isResponseFromSystemDialer;
+ args.arg6 = Log.createSubsession();
mHandler.obtainMessage(MSG_ON_CALL_FILTERING_COMPLETED, args).sendToTarget();
} finally {
Log.endSession();
@@ -1437,12 +1441,16 @@ public abstract class ConnectionService extends Service {
case MSG_ON_CALL_FILTERING_COMPLETED: {
SomeArgs args = (SomeArgs) msg.obj;
try {
- Log.continueSession((Session) args.arg4,
+ Log.continueSession((Session) args.arg6,
SESSION_HANDLER + SESSION_CALL_FILTERING_COMPLETED);
String callId = (String) args.arg1;
boolean isBlocked = (boolean) args.arg2;
boolean isInContacts = (boolean) args.arg3;
- onCallFilteringCompleted(callId, isBlocked, isInContacts);
+ CallScreeningService.ParcelableCallResponse callScreeningResponse =
+ (CallScreeningService.ParcelableCallResponse) args.arg4;
+ boolean isResponseFromSystemDialer = (boolean) args.arg5;
+ onCallFilteringCompleted(callId, isBlocked, isInContacts,
+ callScreeningResponse, isResponseFromSystemDialer);
} finally {
args.recycle();
Log.endSession();
@@ -2458,11 +2466,16 @@ public abstract class ConnectionService extends Service {
}
}
- private void onCallFilteringCompleted(String callId, boolean isBlocked, boolean isInContacts) {
- Log.i(this, "onCallFilteringCompleted(%b, %b)", isBlocked, isInContacts);
+ private void onCallFilteringCompleted(String callId, boolean isBlocked, boolean isInContacts,
+ CallScreeningService.ParcelableCallResponse callScreeningResponse,
+ boolean isResponseFromSystemDialer) {
+ Log.i(this, "onCallFilteringCompleted(%s, %b, %b, %s, %b)", callId,
+ isBlocked, isInContacts, callScreeningResponse, isResponseFromSystemDialer);
Connection connection = findConnectionForAction(callId, "onCallFilteringCompleted");
if (connection != null) {
- connection.onCallFilteringCompleted(isBlocked, isInContacts);
+ connection.onCallFilteringCompleted(isBlocked, isInContacts,
+ callScreeningResponse == null ? null : callScreeningResponse.toCallResponse(),
+ isResponseFromSystemDialer);
}
}
diff --git a/telecomm/java/android/telecom/RemoteConnection.java b/telecomm/java/android/telecom/RemoteConnection.java
index feb2ca53bbbe..6c6097ac71e5 100644
--- a/telecomm/java/android/telecom/RemoteConnection.java
+++ b/telecomm/java/android/telecom/RemoteConnection.java
@@ -1204,15 +1204,25 @@ public final class RemoteConnection {
* the results of a contacts lookup for the remote party.
* @param isBlocked Whether call filtering indicates that the call should be blocked
* @param isInContacts Whether the remote party is in the user's contacts
+ * @param callScreeningResponse The response that was returned from the
+ * {@link CallScreeningService} that handled this call. If no
+ * response was received from a call screening service,
+ * this will be {@code null}.
+ * @param isResponseFromSystemDialer Whether {@code callScreeningResponse} was sent from the
+ * system dialer. If {@code callScreeningResponse} is
+ * {@code null}, this will be {@code false}.
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.READ_CONTACTS)
- public void onCallFilteringCompleted(boolean isBlocked, boolean isInContacts) {
+ public void onCallFilteringCompleted(boolean isBlocked, boolean isInContacts,
+ @Nullable CallScreeningService.CallResponse callScreeningResponse,
+ boolean isResponseFromSystemDialer) {
Log.startSession("RC.oCFC", getActiveOwnerInfo());
try {
if (mConnected) {
mConnectionService.onCallFilteringCompleted(mConnectionId, isBlocked, isInContacts,
+ callScreeningResponse.toParcelable(), isResponseFromSystemDialer,
null /*Session.Info*/);
}
} catch (RemoteException ignored) {
diff --git a/telecomm/java/com/android/internal/telecom/ICallScreeningAdapter.aidl b/telecomm/java/com/android/internal/telecom/ICallScreeningAdapter.aidl
index 83c8f62bb3db..0f2e178f1970 100644
--- a/telecomm/java/com/android/internal/telecom/ICallScreeningAdapter.aidl
+++ b/telecomm/java/com/android/internal/telecom/ICallScreeningAdapter.aidl
@@ -17,6 +17,7 @@
package com.android.internal.telecom;
import android.content.ComponentName;
+import android.telecom.CallScreeningService;
/**
* Internal remote callback interface for call screening services.
@@ -26,16 +27,6 @@ import android.content.ComponentName;
* {@hide}
*/
oneway interface ICallScreeningAdapter {
- void allowCall(String callId);
-
- void silenceCall(String callId);
-
- void screenCallFurther(String callId);
-
- void disallowCall(
- String callId,
- boolean shouldReject,
- boolean shouldAddToCallLog,
- boolean shouldShowNotification,
- in ComponentName componentName);
+ void onScreeningResponse(String callId, in ComponentName componentName,
+ in CallScreeningService.ParcelableCallResponse response);
}
diff --git a/telecomm/java/com/android/internal/telecom/IConnectionService.aidl b/telecomm/java/com/android/internal/telecom/IConnectionService.aidl
index 301c2bb6cdb2..7599e189cc37 100644
--- a/telecomm/java/com/android/internal/telecom/IConnectionService.aidl
+++ b/telecomm/java/com/android/internal/telecom/IConnectionService.aidl
@@ -20,6 +20,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.telecom.CallAudioState;
+import android.telecom.CallScreeningService;
import android.telecom.ConnectionRequest;
import android.telecom.Logging.Session;
import android.telecom.PhoneAccountHandle;
@@ -119,7 +120,8 @@ oneway interface IConnectionService {
void sendCallEvent(String callId, String event, in Bundle extras, in Session.Info sessionInfo);
void onCallFilteringCompleted(String callId, boolean isBlocked, boolean isInContacts,
- in Session.Info sessionInfo);
+ in CallScreeningService.ParcelableCallResponse callScreeningResponse,
+ boolean isResponseFromSystemDialer, in Session.Info sessionInfo);
void onExtrasChanged(String callId, in Bundle extras, in Session.Info sessionInfo);
diff --git a/telephony/java/com/android/internal/telephony/uicc/IccUtils.java b/telephony/java/com/android/internal/telephony/uicc/IccUtils.java
index d79225fe5369..ec1204042260 100644
--- a/telephony/java/com/android/internal/telephony/uicc/IccUtils.java
+++ b/telephony/java/com/android/internal/telephony/uicc/IccUtils.java
@@ -16,6 +16,7 @@
package com.android.internal.telephony.uicc;
+import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
@@ -28,6 +29,7 @@ import com.android.internal.telephony.GsmAlphabet;
import com.android.telephony.Rlog;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.util.List;
/**
@@ -253,13 +255,48 @@ public class IccUtils {
}
if ((b & 0x0f) <= 0x09) {
- ret += (b & 0xf);
+ ret += (b & 0xf);
}
return ret;
}
/**
+ * Encodes a string to be formatted like the EF[ADN] alpha identifier.
+ *
+ * <p>See javadoc for {@link #adnStringFieldToString(byte[], int, int)} for more details on
+ * the relevant specs.
+ *
+ * <p>This will attempt to encode using the GSM 7-bit alphabet but will fallback to UCS-2 if
+ * there are characters that are not supported by it.
+ *
+ * @return the encoded string including the prefix byte necessary to identify the encoding.
+ * @see #adnStringFieldToString(byte[], int, int)
+ */
+ @NonNull
+ public static byte[] stringToAdnStringField(@NonNull String alphaTag) {
+ int septets = GsmAlphabet.countGsmSeptetsUsingTables(alphaTag, false, 0, 0);
+ if (septets != -1) {
+ byte[] ret = new byte[septets];
+ GsmAlphabet.stringToGsm8BitUnpackedField(alphaTag, ret, 0, ret.length);
+ return ret;
+ }
+
+ // Strictly speaking UCS-2 disallows surrogate characters but it's much more complicated to
+ // validate that the string contains only valid UCS-2 characters. Since the read path
+ // in most modern software will decode "UCS-2" by treating it as UTF-16 this should be fine
+ // (e.g. the adnStringFieldToString has done this for a long time on Android). Also there's
+ // already a precedent in SMS applications to ignore the UCS-2/UTF-16 distinction.
+ byte[] alphaTagBytes = alphaTag.getBytes(StandardCharsets.UTF_16BE);
+ byte[] ret = new byte[alphaTagBytes.length + 1];
+ // 0x80 tags the remaining bytes as UCS-2
+ ret[0] = (byte) 0x80;
+ System.arraycopy(alphaTagBytes, 0, ret, 1, alphaTagBytes.length);
+
+ return ret;
+ }
+
+ /**
* Decodes a string field that's formatted like the EF[ADN] alpha
* identifier
*
@@ -309,7 +346,7 @@ public class IccUtils {
ret = new String(data, offset + 1, ucslen * 2, "utf-16be");
} catch (UnsupportedEncodingException ex) {
Rlog.e(LOG_TAG, "implausible UnsupportedEncodingException",
- ex);
+ ex);
}
if (ret != null) {
@@ -342,7 +379,7 @@ public class IccUtils {
len = length - 4;
base = (char) (((data[offset + 2] & 0xFF) << 8) |
- (data[offset + 3] & 0xFF));
+ (data[offset + 3] & 0xFF));
offset += 4;
isucs2 = true;
}
@@ -366,7 +403,7 @@ public class IccUtils {
count++;
ret.append(GsmAlphabet.gsm8BitUnpackedToString(data,
- offset, count));
+ offset, count));
offset += count;
len -= count;
diff --git a/tests/UpdatableSystemFontTest/TEST_MAPPING b/tests/UpdatableSystemFontTest/TEST_MAPPING
index a5c447934f43..7fbf426c71c4 100644
--- a/tests/UpdatableSystemFontTest/TEST_MAPPING
+++ b/tests/UpdatableSystemFontTest/TEST_MAPPING
@@ -1,5 +1,5 @@
{
- "postsubmit": [
+ "presubmit": [
{
"name": "UpdatableSystemFontTest"
}
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 2a693eb94015..13584109b093 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -66,6 +66,8 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
+import static android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PAID;
+import static android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE;
import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY;
import static android.net.NetworkCapabilities.NET_CAPABILITY_RCS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_SUPL;
@@ -169,6 +171,7 @@ import android.net.INetworkMonitor;
import android.net.INetworkMonitorCallbacks;
import android.net.INetworkPolicyListener;
import android.net.INetworkStatsService;
+import android.net.IOnSetOemNetworkPreferenceListener;
import android.net.IQosCallback;
import android.net.InetAddresses;
import android.net.InterfaceConfigurationParcel;
@@ -192,6 +195,7 @@ import android.net.NetworkStack;
import android.net.NetworkStackClient;
import android.net.NetworkState;
import android.net.NetworkTestResultParcelable;
+import android.net.OemNetworkPreferences;
import android.net.ProxyInfo;
import android.net.QosCallbackException;
import android.net.QosFilter;
@@ -300,6 +304,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -359,6 +364,7 @@ public class ConnectivityServiceTest {
private static final String WIFI_WOL_IFNAME = "test_wlan_wol";
private static final String VPN_IFNAME = "tun10042";
private static final String TEST_PACKAGE_NAME = "com.android.test.package";
+ private static final int TEST_PACKAGE_UID = 123;
private static final String ALWAYS_ON_PACKAGE = "com.android.test.alwaysonvpn";
private static final String INTERFACE_NAME = "interface";
@@ -418,6 +424,7 @@ public class ConnectivityServiceTest {
@Mock EthernetManager mEthernetManager;
@Mock NetworkPolicyManager mNetworkPolicyManager;
@Mock KeyStore mKeyStore;
+ @Mock IOnSetOemNetworkPreferenceListener mOnSetOemNetworkPreferenceListener;
private ArgumentCaptor<ResolverParamsParcel> mResolverParamsParcelCaptor =
ArgumentCaptor.forClass(ResolverParamsParcel.class);
@@ -9422,4 +9429,264 @@ public class ConnectivityServiceTest {
}
fail("TOO_MANY_REQUESTS never thrown");
}
+
+ private void mockGetApplicationInfo(@NonNull final String packageName, @NonNull final int uid)
+ throws PackageManager.NameNotFoundException {
+ final ApplicationInfo applicationInfo = new ApplicationInfo();
+ applicationInfo.uid = uid;
+ when(mPackageManager.getApplicationInfo(eq(packageName), anyInt()))
+ .thenReturn(applicationInfo);
+ }
+
+ private void mockHasSystemFeature(@NonNull final String featureName,
+ @NonNull final boolean hasFeature) {
+ when(mPackageManager.hasSystemFeature(eq(featureName)))
+ .thenReturn(hasFeature);
+ }
+
+ private UidRange getNriFirstUidRange(
+ @NonNull final ConnectivityService.NetworkRequestInfo nri) {
+ return nri.mRequests.get(0).networkCapabilities.getUids().iterator().next();
+ }
+
+ private OemNetworkPreferences createDefaultOemNetworkPreferences(
+ @OemNetworkPreferences.OemNetworkPreference final int preference)
+ throws PackageManager.NameNotFoundException {
+ // Arrange PackageManager mocks
+ mockGetApplicationInfo(TEST_PACKAGE_NAME, TEST_PACKAGE_UID);
+
+ // Build OemNetworkPreferences object
+ return new OemNetworkPreferences.Builder()
+ .addNetworkPreference(TEST_PACKAGE_NAME, preference)
+ .build();
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryPreferenceUninitializedThrowsError()
+ throws PackageManager.NameNotFoundException {
+ @OemNetworkPreferences.OemNetworkPreference final int prefToTest =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_UNINITIALIZED;
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ assertThrows(IllegalArgumentException.class,
+ () -> mService.new OemNetworkRequestFactory()
+ .createNrisFromOemNetworkPreferences(
+ createDefaultOemNetworkPreferences(prefToTest)));
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryPreferenceOemPaid()
+ throws PackageManager.NameNotFoundException {
+ // Expectations
+ final int expectedNumOfNris = 1;
+ final int expectedNumOfRequests = 3;
+
+ @OemNetworkPreferences.OemNetworkPreference final int prefToTest =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID;
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final ArraySet<ConnectivityService.NetworkRequestInfo> nris =
+ mService.new OemNetworkRequestFactory()
+ .createNrisFromOemNetworkPreferences(
+ createDefaultOemNetworkPreferences(prefToTest));
+
+ final List<NetworkRequest> mRequests = nris.iterator().next().mRequests;
+ assertEquals(expectedNumOfNris, nris.size());
+ assertEquals(expectedNumOfRequests, mRequests.size());
+ assertTrue(mRequests.get(0).isListen());
+ assertTrue(mRequests.get(0).hasCapability(NET_CAPABILITY_NOT_METERED));
+ assertTrue(mRequests.get(0).hasCapability(NET_CAPABILITY_VALIDATED));
+ assertTrue(mRequests.get(1).isRequest());
+ assertTrue(mRequests.get(1).hasCapability(NET_CAPABILITY_OEM_PAID));
+ assertTrue(mRequests.get(2).isRequest());
+ assertTrue(mService.getDefaultRequest().networkCapabilities.equalsNetCapabilities(
+ mRequests.get(2).networkCapabilities));
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryPreferenceOemPaidNoFallback()
+ throws PackageManager.NameNotFoundException {
+ // Expectations
+ final int expectedNumOfNris = 1;
+ final int expectedNumOfRequests = 2;
+
+ @OemNetworkPreferences.OemNetworkPreference final int prefToTest =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK;
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final ArraySet<ConnectivityService.NetworkRequestInfo> nris =
+ mService.new OemNetworkRequestFactory()
+ .createNrisFromOemNetworkPreferences(
+ createDefaultOemNetworkPreferences(prefToTest));
+
+ final List<NetworkRequest> mRequests = nris.iterator().next().mRequests;
+ assertEquals(expectedNumOfNris, nris.size());
+ assertEquals(expectedNumOfRequests, mRequests.size());
+ assertTrue(mRequests.get(0).isListen());
+ assertTrue(mRequests.get(0).hasCapability(NET_CAPABILITY_NOT_METERED));
+ assertTrue(mRequests.get(0).hasCapability(NET_CAPABILITY_VALIDATED));
+ assertTrue(mRequests.get(1).isRequest());
+ assertTrue(mRequests.get(1).hasCapability(NET_CAPABILITY_OEM_PAID));
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryPreferenceOemPaidOnly()
+ throws PackageManager.NameNotFoundException {
+ // Expectations
+ final int expectedNumOfNris = 1;
+ final int expectedNumOfRequests = 1;
+
+ @OemNetworkPreferences.OemNetworkPreference final int prefToTest =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY;
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final ArraySet<ConnectivityService.NetworkRequestInfo> nris =
+ mService.new OemNetworkRequestFactory()
+ .createNrisFromOemNetworkPreferences(
+ createDefaultOemNetworkPreferences(prefToTest));
+
+ final List<NetworkRequest> mRequests = nris.iterator().next().mRequests;
+ assertEquals(expectedNumOfNris, nris.size());
+ assertEquals(expectedNumOfRequests, mRequests.size());
+ assertTrue(mRequests.get(0).isRequest());
+ assertTrue(mRequests.get(0).hasCapability(NET_CAPABILITY_OEM_PAID));
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryPreferenceOemPrivateOnly()
+ throws PackageManager.NameNotFoundException {
+ // Expectations
+ final int expectedNumOfNris = 1;
+ final int expectedNumOfRequests = 1;
+
+ @OemNetworkPreferences.OemNetworkPreference final int prefToTest =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY;
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final ArraySet<ConnectivityService.NetworkRequestInfo> nris =
+ mService.new OemNetworkRequestFactory()
+ .createNrisFromOemNetworkPreferences(
+ createDefaultOemNetworkPreferences(prefToTest));
+
+ final List<NetworkRequest> mRequests = nris.iterator().next().mRequests;
+ assertEquals(expectedNumOfNris, nris.size());
+ assertEquals(expectedNumOfRequests, mRequests.size());
+ assertTrue(mRequests.get(0).isRequest());
+ assertTrue(mRequests.get(0).hasCapability(NET_CAPABILITY_OEM_PRIVATE));
+ assertFalse(mRequests.get(0).hasCapability(NET_CAPABILITY_OEM_PAID));
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryCreatesCorrectNumOfNris()
+ throws PackageManager.NameNotFoundException {
+ // Expectations
+ final int expectedNumOfNris = 2;
+
+ // Arrange PackageManager mocks
+ final String testPackageName2 = "com.google.apps.dialer";
+ mockGetApplicationInfo(TEST_PACKAGE_NAME, TEST_PACKAGE_UID);
+ mockGetApplicationInfo(testPackageName2, TEST_PACKAGE_UID);
+
+ // Build OemNetworkPreferences object
+ final int testOemPref = OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID;
+ final int testOemPref2 = OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK;
+ final OemNetworkPreferences pref = new OemNetworkPreferences.Builder()
+ .addNetworkPreference(TEST_PACKAGE_NAME, testOemPref)
+ .addNetworkPreference(testPackageName2, testOemPref2)
+ .build();
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final ArraySet<ConnectivityService.NetworkRequestInfo> nris =
+ mService.new OemNetworkRequestFactory().createNrisFromOemNetworkPreferences(pref);
+
+ assertNotNull(nris);
+ assertEquals(expectedNumOfNris, nris.size());
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryCorrectlySetsUids()
+ throws PackageManager.NameNotFoundException {
+ // Arrange PackageManager mocks
+ final String testPackageName2 = "com.google.apps.dialer";
+ final int testPackageNameUid2 = 456;
+ mockGetApplicationInfo(TEST_PACKAGE_NAME, TEST_PACKAGE_UID);
+ mockGetApplicationInfo(testPackageName2, testPackageNameUid2);
+
+ // Build OemNetworkPreferences object
+ final int testOemPref = OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID;
+ final int testOemPref2 = OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK;
+ final OemNetworkPreferences pref = new OemNetworkPreferences.Builder()
+ .addNetworkPreference(TEST_PACKAGE_NAME, testOemPref)
+ .addNetworkPreference(testPackageName2, testOemPref2)
+ .build();
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final List<ConnectivityService.NetworkRequestInfo> nris =
+ new ArrayList<>(
+ mService.new OemNetworkRequestFactory().createNrisFromOemNetworkPreferences(
+ pref));
+
+ // Sort by uid to access nris by index
+ nris.sort(Comparator.comparingInt(nri -> getNriFirstUidRange(nri).start));
+ assertEquals(TEST_PACKAGE_UID, getNriFirstUidRange(nris.get(0)).start);
+ assertEquals(TEST_PACKAGE_UID, getNriFirstUidRange(nris.get(0)).stop);
+ assertEquals(testPackageNameUid2, getNriFirstUidRange(nris.get(1)).start);
+ assertEquals(testPackageNameUid2, getNriFirstUidRange(nris.get(1)).stop);
+ }
+
+ @Test
+ public void testOemNetworkRequestFactoryAddsPackagesToCorrectPreference()
+ throws PackageManager.NameNotFoundException {
+ // Expectations
+ final int expectedNumOfNris = 1;
+ final int expectedNumOfAppUids = 2;
+
+ // Arrange PackageManager mocks
+ final String testPackageName2 = "com.google.apps.dialer";
+ final int testPackageNameUid2 = 456;
+ mockGetApplicationInfo(TEST_PACKAGE_NAME, TEST_PACKAGE_UID);
+ mockGetApplicationInfo(testPackageName2, testPackageNameUid2);
+
+ // Build OemNetworkPreferences object
+ final int testOemPref = OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID;
+ final OemNetworkPreferences pref = new OemNetworkPreferences.Builder()
+ .addNetworkPreference(TEST_PACKAGE_NAME, testOemPref)
+ .addNetworkPreference(testPackageName2, testOemPref)
+ .build();
+
+ // Act on OemNetworkRequestFactory.createNrisFromOemNetworkPreferences()
+ final ArraySet<ConnectivityService.NetworkRequestInfo> nris =
+ mService.new OemNetworkRequestFactory().createNrisFromOemNetworkPreferences(pref);
+
+ assertEquals(expectedNumOfNris, nris.size());
+ assertEquals(expectedNumOfAppUids,
+ nris.iterator().next().mRequests.get(0).networkCapabilities.getUids().size());
+ }
+
+ @Test
+ public void testSetOemNetworkPreferenceNullListenerAndPrefParamThrowsNpe() {
+ mockHasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, true);
+ @OemNetworkPreferences.OemNetworkPreference final int networkPref =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY;
+
+ // Act on ConnectivityService.setOemNetworkPreference()
+ assertThrows(NullPointerException.class,
+ () -> mService.setOemNetworkPreference(
+ null,
+ null));
+ }
+
+ @Test
+ public void testSetOemNetworkPreferenceFailsForNonAutomotive()
+ throws PackageManager.NameNotFoundException, RemoteException {
+ mockHasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, false);
+ @OemNetworkPreferences.OemNetworkPreference final int networkPref =
+ OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY;
+
+ // Act on ConnectivityService.setOemNetworkPreference()
+ assertThrows(UnsupportedOperationException.class,
+ () -> mService.setOemNetworkPreference(
+ createDefaultOemNetworkPreferences(networkPref),
+ mOnSetOemNetworkPreferenceListener));
+ }
}
diff --git a/tests/net/java/com/android/server/connectivity/PermissionMonitorTest.java b/tests/net/java/com/android/server/connectivity/PermissionMonitorTest.java
index 3556c72776dc..8f5ae97bc4c5 100644
--- a/tests/net/java/com/android/server/connectivity/PermissionMonitorTest.java
+++ b/tests/net/java/com/android/server/connectivity/PermissionMonitorTest.java
@@ -89,8 +89,8 @@ import java.util.Set;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class PermissionMonitorTest {
- private static final int MOCK_USER1 = 0;
- private static final int MOCK_USER2 = 1;
+ private static final UserHandle MOCK_USER1 = UserHandle.of(0);
+ private static final UserHandle MOCK_USER2 = UserHandle.of(1);
private static final int MOCK_UID1 = 10001;
private static final int MOCK_UID2 = 10086;
private static final int SYSTEM_UID1 = 1000;
@@ -123,10 +123,7 @@ public class PermissionMonitorTest {
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mUserManager);
when(mUserManager.getUserHandles(eq(true))).thenReturn(
- Arrays.asList(new UserHandle[] {
- new UserHandle(MOCK_USER1),
- new UserHandle(MOCK_USER2),
- }));
+ Arrays.asList(new UserHandle[] { MOCK_USER1, MOCK_USER2 }));
mPermissionMonitor = spy(new PermissionMonitor(mContext, mNetdService, mDeps));
@@ -184,7 +181,8 @@ public class PermissionMonitorTest {
return packageInfo;
}
- private static PackageInfo buildPackageInfo(boolean hasSystemPermission, int uid, int userId) {
+ private static PackageInfo buildPackageInfo(boolean hasSystemPermission, int uid,
+ UserHandle user) {
final PackageInfo pkgInfo;
if (hasSystemPermission) {
pkgInfo = systemPackageInfoWithPermissions(
@@ -192,7 +190,7 @@ public class PermissionMonitorTest {
} else {
pkgInfo = packageInfoWithPermissions(REQUESTED_PERMISSION_GRANTED, new String[] {}, "");
}
- pkgInfo.applicationInfo.uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
+ pkgInfo.applicationInfo.uid = UserHandle.getUid(user, UserHandle.getAppId(uid));
return pkgInfo;
}
@@ -382,8 +380,8 @@ public class PermissionMonitorTest {
}).when(mockNetd).networkClearPermissionForUser(any(int[].class));
}
- public void expectPermission(Boolean permission, int[] users, int[] apps) {
- for (final int user : users) {
+ public void expectPermission(Boolean permission, UserHandle[] users, int[] apps) {
+ for (final UserHandle user : users) {
for (final int app : apps) {
final int uid = UserHandle.getUid(user, app);
if (!mApps.containsKey(uid)) {
@@ -396,8 +394,8 @@ public class PermissionMonitorTest {
}
}
- public void expectNoPermission(int[] users, int[] apps) {
- for (final int user : users) {
+ public void expectNoPermission(UserHandle[] users, int[] apps) {
+ for (final UserHandle user : users) {
for (final int app : apps) {
final int uid = UserHandle.getUid(user, app);
if (mApps.containsKey(uid)) {
@@ -425,46 +423,48 @@ public class PermissionMonitorTest {
// Add SYSTEM_PACKAGE2, expect only have network permission.
mPermissionMonitor.onUserAdded(MOCK_USER1);
- addPackageForUsers(new int[]{MOCK_USER1}, SYSTEM_PACKAGE2, SYSTEM_UID);
- mNetdMonitor.expectPermission(NETWORK, new int[]{MOCK_USER1}, new int[]{SYSTEM_UID});
+ addPackageForUsers(new UserHandle[]{MOCK_USER1}, SYSTEM_PACKAGE2, SYSTEM_UID);
+ mNetdMonitor.expectPermission(NETWORK, new UserHandle[]{MOCK_USER1}, new int[]{SYSTEM_UID});
// Add SYSTEM_PACKAGE1, expect permission escalate.
- addPackageForUsers(new int[]{MOCK_USER1}, SYSTEM_PACKAGE1, SYSTEM_UID);
- mNetdMonitor.expectPermission(SYSTEM, new int[]{MOCK_USER1}, new int[]{SYSTEM_UID});
+ addPackageForUsers(new UserHandle[]{MOCK_USER1}, SYSTEM_PACKAGE1, SYSTEM_UID);
+ mNetdMonitor.expectPermission(SYSTEM, new UserHandle[]{MOCK_USER1}, new int[]{SYSTEM_UID});
mPermissionMonitor.onUserAdded(MOCK_USER2);
- mNetdMonitor.expectPermission(SYSTEM, new int[]{MOCK_USER1, MOCK_USER2},
+ mNetdMonitor.expectPermission(SYSTEM, new UserHandle[]{MOCK_USER1, MOCK_USER2},
new int[]{SYSTEM_UID});
- addPackageForUsers(new int[]{MOCK_USER1, MOCK_USER2}, MOCK_PACKAGE1, MOCK_UID1);
- mNetdMonitor.expectPermission(SYSTEM, new int[]{MOCK_USER1, MOCK_USER2},
+ addPackageForUsers(new UserHandle[]{MOCK_USER1, MOCK_USER2}, MOCK_PACKAGE1, MOCK_UID1);
+ mNetdMonitor.expectPermission(SYSTEM, new UserHandle[]{MOCK_USER1, MOCK_USER2},
new int[]{SYSTEM_UID});
- mNetdMonitor.expectPermission(NETWORK, new int[]{MOCK_USER1, MOCK_USER2},
+ mNetdMonitor.expectPermission(NETWORK, new UserHandle[]{MOCK_USER1, MOCK_USER2},
new int[]{MOCK_UID1});
// Remove MOCK_UID1, expect no permission left for all user.
mPermissionMonitor.onPackageRemoved(MOCK_PACKAGE1, MOCK_UID1);
- removePackageForUsers(new int[]{MOCK_USER1, MOCK_USER2}, MOCK_PACKAGE1, MOCK_UID1);
- mNetdMonitor.expectNoPermission(new int[]{MOCK_USER1, MOCK_USER2}, new int[]{MOCK_UID1});
+ removePackageForUsers(new UserHandle[]{MOCK_USER1, MOCK_USER2}, MOCK_PACKAGE1, MOCK_UID1);
+ mNetdMonitor.expectNoPermission(new UserHandle[]{MOCK_USER1, MOCK_USER2},
+ new int[]{MOCK_UID1});
// Remove SYSTEM_PACKAGE1, expect permission downgrade.
when(mPackageManager.getPackagesForUid(anyInt())).thenReturn(new String[]{SYSTEM_PACKAGE2});
- removePackageForUsers(new int[]{MOCK_USER1, MOCK_USER2}, SYSTEM_PACKAGE1, SYSTEM_UID);
- mNetdMonitor.expectPermission(NETWORK, new int[]{MOCK_USER1, MOCK_USER2},
+ removePackageForUsers(new UserHandle[]{MOCK_USER1, MOCK_USER2},
+ SYSTEM_PACKAGE1, SYSTEM_UID);
+ mNetdMonitor.expectPermission(NETWORK, new UserHandle[]{MOCK_USER1, MOCK_USER2},
new int[]{SYSTEM_UID});
mPermissionMonitor.onUserRemoved(MOCK_USER1);
- mNetdMonitor.expectPermission(NETWORK, new int[]{MOCK_USER2}, new int[]{SYSTEM_UID});
+ mNetdMonitor.expectPermission(NETWORK, new UserHandle[]{MOCK_USER2}, new int[]{SYSTEM_UID});
// Remove all packages, expect no permission left.
when(mPackageManager.getPackagesForUid(anyInt())).thenReturn(new String[]{});
- removePackageForUsers(new int[]{MOCK_USER2}, SYSTEM_PACKAGE2, SYSTEM_UID);
- mNetdMonitor.expectNoPermission(new int[]{MOCK_USER1, MOCK_USER2},
+ removePackageForUsers(new UserHandle[]{MOCK_USER2}, SYSTEM_PACKAGE2, SYSTEM_UID);
+ mNetdMonitor.expectNoPermission(new UserHandle[]{MOCK_USER1, MOCK_USER2},
new int[]{SYSTEM_UID, MOCK_UID1});
// Remove last user, expect no redundant clearPermission is invoked.
mPermissionMonitor.onUserRemoved(MOCK_USER2);
- mNetdMonitor.expectNoPermission(new int[]{MOCK_USER1, MOCK_USER2},
+ mNetdMonitor.expectNoPermission(new UserHandle[]{MOCK_USER1, MOCK_USER2},
new int[]{SYSTEM_UID, MOCK_UID1});
}
@@ -548,14 +548,14 @@ public class PermissionMonitorTest {
// Normal package add/remove operations will trigger multiple intent for uids corresponding to
// each user. To simulate generic package operations, the onPackageAdded/Removed will need to be
// called multiple times with the uid corresponding to each user.
- private void addPackageForUsers(int[] users, String packageName, int uid) {
- for (final int user : users) {
+ private void addPackageForUsers(UserHandle[] users, String packageName, int uid) {
+ for (final UserHandle user : users) {
mPermissionMonitor.onPackageAdded(packageName, UserHandle.getUid(user, uid));
}
}
- private void removePackageForUsers(int[] users, String packageName, int uid) {
- for (final int user : users) {
+ private void removePackageForUsers(UserHandle[] users, String packageName, int uid) {
+ for (final UserHandle user : users) {
mPermissionMonitor.onPackageRemoved(packageName, UserHandle.getUid(user, uid));
}
}
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
index faa8b234cf51..e7154802f1f2 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
@@ -34,8 +34,10 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import android.net.LinkProperties;
+import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import androidx.test.filters.SmallTest;
@@ -73,6 +75,11 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
}
@Test
+ public void testEnterStateDoesNotCancelSafemodeAlarm() {
+ verifySafemodeTimeoutAlarmAndGetCallback(false /* expectCanceled */);
+ }
+
+ @Test
public void testNullNetworkDoesNotTriggerDisconnect() throws Exception {
mGatewayConnection
.getUnderlyingNetworkTrackerCallback()
@@ -121,7 +128,24 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
}
@Test
+ public void testMigratedTransformsAreApplied() throws Exception {
+ getChildSessionCallback()
+ .onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform());
+ mTestLooper.dispatchAll();
+
+ for (int direction : new int[] {DIRECTION_IN, DIRECTION_OUT}) {
+ verify(mIpSecSvc)
+ .applyTunnelModeTransform(
+ eq(TEST_IPSEC_TUNNEL_RESOURCE_ID), eq(direction), anyInt(), any());
+ }
+ assertEquals(mGatewayConnection.mConnectedState, mGatewayConnection.getCurrentState());
+ }
+
+ @Test
public void testChildOpenedRegistersNetwork() throws Exception {
+ // Verify scheduled but not canceled when entering ConnectedState
+ verifySafemodeTimeoutAlarmAndGetCallback(false /* expectCanceled */);
+
final VcnChildSessionConfiguration mMockChildSessionConfig =
mock(VcnChildSessionConfiguration.class);
doReturn(Collections.singletonList(TEST_INTERNAL_ADDR))
@@ -163,24 +187,41 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
for (int cap : mConfig.getAllExposedCapabilities()) {
assertTrue(nc.hasCapability(cap));
}
+
+ // Now that Vcn Network is up, notify it as validated and verify the Safemode alarm is
+ // canceled
+ mGatewayConnection.mNetworkAgent.onValidationStatus(
+ NetworkAgent.VALIDATION_STATUS_VALID, null /* redirectUri */);
+ verify(mSafemodeTimeoutAlarm).cancel();
}
@Test
public void testChildSessionClosedTriggersDisconnect() throws Exception {
+ // Verify scheduled but not canceled when entering ConnectedState
+ verifySafemodeTimeoutAlarmAndGetCallback(false /* expectCanceled */);
+
getChildSessionCallback().onClosed();
mTestLooper.dispatchAll();
assertEquals(mGatewayConnection.mDisconnectingState, mGatewayConnection.getCurrentState());
verifyTeardownTimeoutAlarmAndGetCallback(false /* expectCanceled */);
+
+ // Since network never validated, verify mSafemodeTimeoutAlarm not canceled
+ verifyNoMoreInteractions(mSafemodeTimeoutAlarm);
}
@Test
public void testIkeSessionClosedTriggersDisconnect() throws Exception {
+ // Verify scheduled but not canceled when entering ConnectedState
+ verifySafemodeTimeoutAlarmAndGetCallback(false /* expectCanceled */);
+
getIkeSessionCallback().onClosed();
mTestLooper.dispatchAll();
assertEquals(mGatewayConnection.mRetryTimeoutState, mGatewayConnection.getCurrentState());
verify(mIkeSession).close();
- verifyTeardownTimeoutAlarmAndGetCallback(true /* expectCanceled */);
+
+ // Since network never validated, verify mSafemodeTimeoutAlarm not canceled
+ verifyNoMoreInteractions(mSafemodeTimeoutAlarm);
}
}
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectingStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectingStateTest.java
index 760379d6649d..07282c920088 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectingStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectingStateTest.java
@@ -106,4 +106,9 @@ public class VcnGatewayConnectionConnectingStateTest extends VcnGatewayConnectio
verify(mIkeSession).close();
verifyTeardownTimeoutAlarmAndGetCallback(true /* expectCanceled */);
}
+
+ @Test
+ public void testSafemodeTimeoutNotifiesCallback() {
+ verifySafemodeTimeoutNotifiesCallback(mGatewayConnection.mConnectingState);
+ }
}
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java
index 1a1787ac19d9..49ce54d4f684 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java
@@ -48,7 +48,8 @@ public class VcnGatewayConnectionDisconnectedStateTest extends VcnGatewayConnect
.createIpSecTunnelInterface(
DUMMY_ADDR, DUMMY_ADDR, TEST_UNDERLYING_NETWORK_RECORD_1.network);
mGatewayConnection.setTunnelInterface(tunnelIface);
- mGatewayConnection.transitionTo(mGatewayConnection.mDisconnectedState);
+
+ // Don't need to transition to DisconnectedState because it is the starting state
mTestLooper.dispatchAll();
}
@@ -78,6 +79,7 @@ public class VcnGatewayConnectionDisconnectedStateTest extends VcnGatewayConnect
mTestLooper.dispatchAll();
assertEquals(mGatewayConnection.mConnectingState, mGatewayConnection.getCurrentState());
+ verifySafemodeTimeoutAlarmAndGetCallback(false /* expectCanceled */);
}
@Test
@@ -98,5 +100,6 @@ public class VcnGatewayConnectionDisconnectedStateTest extends VcnGatewayConnect
assertNull(mGatewayConnection.getCurrentState());
verify(mIpSecSvc).deleteTunnelInterface(eq(TEST_IPSEC_TUNNEL_RESOURCE_ID), any());
+ verifySafemodeTimeoutAlarmAndGetCallback(true /* expectCanceled */);
}
}
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectingStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectingStateTest.java
index b09f3a008c29..22eab2a1aa65 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectingStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectingStateTest.java
@@ -80,4 +80,9 @@ public class VcnGatewayConnectionDisconnectingStateTest extends VcnGatewayConnec
assertEquals(mGatewayConnection.mDisconnectingState, mGatewayConnection.getCurrentState());
verifyTeardownTimeoutAlarmAndGetCallback(false /* expectCanceled */);
}
+
+ @Test
+ public void testSafemodeTimeoutNotifiesCallback() {
+ verifySafemodeTimeoutNotifiesCallback(mGatewayConnection.mDisconnectingState);
+ }
}
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionRetryTimeoutStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionRetryTimeoutStateTest.java
index d37e92f661cc..6c2607586629 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionRetryTimeoutStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionRetryTimeoutStateTest.java
@@ -91,4 +91,9 @@ public class VcnGatewayConnectionRetryTimeoutStateTest extends VcnGatewayConnect
assertEquals(mGatewayConnection.mConnectingState, mGatewayConnection.getCurrentState());
verifyRetryTimeoutAlarmAndGetCallback(mFirstRetryInterval, true /* expectCanceled */);
}
+
+ @Test
+ public void testSafemodeTimeoutNotifiesCallback() {
+ verifySafemodeTimeoutNotifiesCallback(mGatewayConnection.mRetryTimeoutState);
+ }
}
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java
index 0b44e03a5e5a..ac9ec0663df2 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java
@@ -20,6 +20,7 @@ import static com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkR
import static com.android.server.vcn.VcnGatewayConnection.VcnIkeSession;
import static com.android.server.vcn.VcnTestUtils.setupIpSecManager;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
@@ -50,6 +51,7 @@ import android.os.ParcelUuid;
import android.os.PowerManager;
import android.os.test.TestLooper;
+import com.android.internal.util.State;
import com.android.internal.util.WakeupMessage;
import com.android.server.IpSecService;
import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
@@ -108,6 +110,7 @@ public class VcnGatewayConnectionTestBase {
@NonNull protected final WakeupMessage mTeardownTimeoutAlarm;
@NonNull protected final WakeupMessage mDisconnectRequestAlarm;
@NonNull protected final WakeupMessage mRetryTimeoutAlarm;
+ @NonNull protected final WakeupMessage mSafemodeTimeoutAlarm;
@NonNull protected final IpSecService mIpSecSvc;
@NonNull protected final ConnectivityManager mConnMgr;
@@ -128,6 +131,7 @@ public class VcnGatewayConnectionTestBase {
mTeardownTimeoutAlarm = mock(WakeupMessage.class);
mDisconnectRequestAlarm = mock(WakeupMessage.class);
mRetryTimeoutAlarm = mock(WakeupMessage.class);
+ mSafemodeTimeoutAlarm = mock(WakeupMessage.class);
mIpSecSvc = mock(IpSecService.class);
setupIpSecManager(mContext, mIpSecSvc);
@@ -150,6 +154,7 @@ public class VcnGatewayConnectionTestBase {
setUpWakeupMessage(mTeardownTimeoutAlarm, VcnGatewayConnection.TEARDOWN_TIMEOUT_ALARM);
setUpWakeupMessage(mDisconnectRequestAlarm, VcnGatewayConnection.DISCONNECT_REQUEST_ALARM);
setUpWakeupMessage(mRetryTimeoutAlarm, VcnGatewayConnection.RETRY_TIMEOUT_ALARM);
+ setUpWakeupMessage(mSafemodeTimeoutAlarm, VcnGatewayConnection.SAFEMODE_TIMEOUT_ALARM);
doReturn(ELAPSED_REAL_TIME).when(mDeps).getElapsedRealTime();
}
@@ -253,4 +258,24 @@ public class VcnGatewayConnectionTestBase {
delayInMillis,
expectCanceled);
}
+
+ protected Runnable verifySafemodeTimeoutAlarmAndGetCallback(boolean expectCanceled) {
+ return verifyWakeupMessageSetUpAndGetCallback(
+ VcnGatewayConnection.SAFEMODE_TIMEOUT_ALARM,
+ mSafemodeTimeoutAlarm,
+ TimeUnit.SECONDS.toMillis(VcnGatewayConnection.SAFEMODE_TIMEOUT_SECONDS),
+ expectCanceled);
+ }
+
+ protected void verifySafemodeTimeoutNotifiesCallback(@NonNull State expectedState) {
+ // Safemode timer starts when VcnGatewayConnection exits DisconnectedState (the initial
+ // state)
+ final Runnable delayedEvent =
+ verifySafemodeTimeoutAlarmAndGetCallback(false /* expectCanceled */);
+ delayedEvent.run();
+ mTestLooper.dispatchAll();
+
+ verify(mGatewayStatusCallback).onEnteredSafemode();
+ assertEquals(expectedState, mGatewayConnection.getCurrentState());
+ }
}