Class SessionCallbackBuilder.DefaultAllowedCommandProvider
- All Implemented Interfaces:
SessionCallbackBuilder.AllowedCommandProvider
- Enclosing class:
SessionCallbackBuilder
SessionCallbackBuilder.AllowedCommandProvider that behaves as follows:
- Accepts connection requests from controller if any of the following conditions are met:
- Controller is in the same package as the session.
- Controller is allowed via
setTrustedPackageNames(List). - Controller has package name
MediaSessionManager.RemoteUserInfo.LEGACY_CONTROLLER. Seepackage name limitationfor details. - Controller is trusted (i.e. has MEDIA_CONTENT_CONTROL permission or has enabled notification manager).
- Allows all commands that the current player can handle.
- Accepts all command requests for allowed commands.
Note: this implementation matches the behavior of the ExoPlayer MediaSession extension and
MediaSessionCompat.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptConnection(androidx.media2.session.MediaSession session, androidx.media2.session.MediaSession.ControllerInfo controllerInfo) Called to query whether to allow connection from the controller.androidx.media2.session.SessionCommandGroupgetAllowedCommands(androidx.media2.session.MediaSession session, androidx.media2.session.MediaSession.ControllerInfo controllerInfo, androidx.media2.session.SessionCommandGroup baseAllowedSessionCommands) Called to query allowed commands in following cases: AMediaControllerrequests to connect, and allowed commands is required to tell initial allowed commands.intonCommandRequest(androidx.media2.session.MediaSession session, androidx.media2.session.MediaSession.ControllerInfo controllerInfo, androidx.media2.session.SessionCommand command) Called when aMediaControllerhas called an API that controlsSessionPlayerset to theMediaSession.voidsetTrustedPackageNames(List<String> packageNames) Sets the package names from which the session will accept incoming connections.
-
Constructor Details
-
DefaultAllowedCommandProvider
-
-
Method Details
-
acceptConnection
public boolean acceptConnection(androidx.media2.session.MediaSession session, androidx.media2.session.MediaSession.ControllerInfo controllerInfo) Description copied from interface:SessionCallbackBuilder.AllowedCommandProviderCalled to query whether to allow connection from the controller.If it returns
trueto accept connection, thenSessionCallbackBuilder.AllowedCommandProvider.getAllowedCommands(androidx.media2.session.MediaSession, androidx.media2.session.MediaSession.ControllerInfo, androidx.media2.session.SessionCommandGroup)will be immediately followed to return initial allowed command.Prefer use
SessionCallbackBuilder.PostConnectCallbackfor any extra initialization about controller, where controller is connected and session can send commands to the controller.- Specified by:
acceptConnectionin interfaceSessionCallbackBuilder.AllowedCommandProvider- Parameters:
session- The media session.controllerInfo- TheMediaSession.ControllerInfofor the controller that is requesting connect.- Returns:
trueto accept connection.falseotherwise.
-
getAllowedCommands
public androidx.media2.session.SessionCommandGroup getAllowedCommands(androidx.media2.session.MediaSession session, androidx.media2.session.MediaSession.ControllerInfo controllerInfo, androidx.media2.session.SessionCommandGroup baseAllowedSessionCommands) Description copied from interface:SessionCallbackBuilder.AllowedCommandProviderCalled to query allowed commands in following cases:- A
MediaControllerrequests to connect, and allowed commands is required to tell initial allowed commands. - Underlying
SessionPlayerstate changes, and allowed commands may be updated viaMediaSession.setAllowedCommands(androidx.media2.session.MediaSession.ControllerInfo, androidx.media2.session.SessionCommandGroup).
The provided
baseAllowedSessionCommandis built automatically based on the state of theSessionPlayer,SessionCallbackBuilder.RatingCallback,SessionCallbackBuilder.MediaItemProvider,SessionCallbackBuilder.CustomCommandProvider, andSessionCallbackBuilder.SkipCallbackso may be a useful starting point for any required customizations.- Specified by:
getAllowedCommandsin interfaceSessionCallbackBuilder.AllowedCommandProvider- Parameters:
session- The media session.controllerInfo- TheMediaSession.ControllerInfofor the controller for which allowed commands are being queried.baseAllowedSessionCommands- Base allowed session commands for customization.- Returns:
- The allowed commands for the controller.
- See Also:
- A
-
onCommandRequest
public int onCommandRequest(androidx.media2.session.MediaSession session, androidx.media2.session.MediaSession.ControllerInfo controllerInfo, androidx.media2.session.SessionCommand command) Description copied from interface:SessionCallbackBuilder.AllowedCommandProviderCalled when aMediaControllerhas called an API that controlsSessionPlayerset to theMediaSession.- Specified by:
onCommandRequestin interfaceSessionCallbackBuilder.AllowedCommandProvider- Parameters:
session- The media session.controllerInfo- AMediaSession.ControllerInfothat needs allowed command update.command- ASessionCommandfrom the controller.- Returns:
- A session result code defined in
SessionResult. - See Also:
-
setTrustedPackageNames
Sets the package names from which the session will accept incoming connections.Apps that have
android.Manifest.permission.MEDIA_CONTENT_CONTROL, packages listed in enabled_notification_listeners and the current package are always trusted, even if they are not specified here.- Parameters:
packageNames- Package names from which the session will accept incoming connections.- See Also:
-