MediaSession.ControllerInfo


class MediaSession.ControllerInfo


Information of a MediaController or a MediaBrowser.

Summary

Constants

const String!
@UnstableApi
FALLBACK_PACKAGE_NAME = "androidx.media3.session.MediaSessionService"

The getPackageName of a fallback ControllerInfo created by MediaSessionService when a more specific package name is not available (for example, when the service is started by a media button intent without a component name, or restarted by the system after a crash).

const Int

The getInterfaceVersion interface version} of a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

const String!
LEGACY_CONTROLLER_PACKAGE_NAME = "android.media.session.MediaController"

The getPackageName of a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat if a more precise package cannot be obtained.

const Int

The controller version of a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

const String!
@UnstableApi
TYPE_CRASH_RECOVERY = "androidx.media3.session.sticky.crash"

The value for CONNECTION_HINT_KEY_CONTROLLER_INFO_TYPE in getConnectionHints when a fallback ControllerInfo is created because MediaSessionService was restarted by the system after a crash with a null intent (START_STICKY).

Public functions

java-static MediaSession.ControllerInfo!
@UnstableApi
@VisibleForTesting(otherwise = 2)
createTestOnlyControllerInfo(
    packageName: String!,
    pid: Int,
    uid: Int,
    libraryVersion: Int,
    interfaceVersion: Int,
    trusted: Boolean,
    connectionHints: Bundle!,
    isPackageNameVerified: Boolean
)

Returns a ControllerInfo suitable for use when testing client code.

Boolean
equals(obj: Any?)
Int

Returns the library version of the controller.

String!

Returns the package name, or LEGACY_CONTROLLER_PACKAGE_NAME if the package name cannot be obtained.

Int

Returns the UID of the controller.

Int
String!

Public properties

Bundle!

Returns the connection hints sent from controller.

Int

Returns the INTERFACE_VERSION of the controller, or LEGACY_CONTROLLER_INTERFACE_VERSION if the controller is a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

Boolean

Returns whether the value returned from getPackageName has been verified to be a valid package name belonging to getUid.

Boolean

Returns whether the controller is trusted by the user to control and access media.

Int

Returns the max number of commands for a media item.

Constants

FALLBACK_PACKAGE_NAME

@UnstableApi
const val FALLBACK_PACKAGE_NAME = "androidx.media3.session.MediaSessionService": String!

The getPackageName of a fallback ControllerInfo created by MediaSessionService when a more specific package name is not available (for example, when the service is started by a media button intent without a component name, or restarted by the system after a crash).

LEGACY_CONTROLLER_INTERFACE_VERSION

@UnstableApi
const val LEGACY_CONTROLLER_INTERFACE_VERSION = 0: Int

The getInterfaceVersion interface version} of a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

LEGACY_CONTROLLER_PACKAGE_NAME

const val LEGACY_CONTROLLER_PACKAGE_NAME = "android.media.session.MediaController": String!

The getPackageName of a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat if a more precise package cannot be obtained.

LEGACY_CONTROLLER_VERSION

const val LEGACY_CONTROLLER_VERSION = 0: Int

The controller version of a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

TYPE_CRASH_RECOVERY

@UnstableApi
const val TYPE_CRASH_RECOVERY = "androidx.media3.session.sticky.crash": String!

The value for CONNECTION_HINT_KEY_CONTROLLER_INFO_TYPE in getConnectionHints when a fallback ControllerInfo is created because MediaSessionService was restarted by the system after a crash with a null intent (START_STICKY).

Public functions

createTestOnlyControllerInfo

@UnstableApi
@VisibleForTesting(otherwise = 2)
java-static fun createTestOnlyControllerInfo(
    packageName: String!,
    pid: Int,
    uid: Int,
    libraryVersion: Int,
    interfaceVersion: Int,
    trusted: Boolean,
    connectionHints: Bundle!,
    isPackageNameVerified: Boolean
): MediaSession.ControllerInfo!

Returns a ControllerInfo suitable for use when testing client code.

equals

fun equals(obj: Any?): Boolean

getControllerVersion

fun getControllerVersion(): Int

Returns the library version of the controller.

It will be the same as VERSION_INT of the controller, or LEGACY_CONTROLLER_VERSION if the controller is a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

getPackageName

fun getPackageName(): String!

Returns the package name, or LEGACY_CONTROLLER_PACKAGE_NAME if the package name cannot be obtained.

In some cases the correctness of the package name cannot be verified, for example when a controller from another app connects directly with a SessionToken and the app's package is not visible from this app. Refer to the package visibility guidelines for more details and how to ensure specific packages are visible if required.

getUid

fun getUid(): Int

Returns the UID of the controller. Can be a negative value for interoperability.

Interoperability: If SDK_INT < 28, then UID would be a negative value because it cannot be obtained.

hashCode

fun hashCode(): Int

toString

fun toString(): String!

Public properties

connectionHints

val connectionHints: Bundle!

Returns the connection hints sent from controller.

interfaceVersion

val interfaceVersion: Int

Returns the INTERFACE_VERSION of the controller, or LEGACY_CONTROLLER_INTERFACE_VERSION if the controller is a platform android.media.session.MediaController or legacy android.support.v4.media.session.MediaControllerCompat.

isPackageNameVerified

val isPackageNameVerified: Boolean

Returns whether the value returned from getPackageName has been verified to be a valid package name belonging to getUid.

isTrusted

val isTrusted: Boolean

Returns whether the controller is trusted by the user to control and access media.

One or more of the following must be true for the controller to be trusted:

  • The controller is part of the current app and user (using myUid).
  • The controller is part of the Android system (using SYSTEM_UID).
  • The controller has been granted android.permission.MEDIA_CONTENT_CONTROL.
  • The controller has been granted android.permission.EXECUTE_APP_FUNCTIONS (from API 36).
  • The controller has been granted android.permission.STATUS_BAR_SERVICE.
  • The controller has an enabled notification listener.

maxCommandsForMediaItems

val maxCommandsForMediaItems: Int

Returns the max number of commands for a media item. A positive number or 0 (zero) to indicate that the feature is not supported by the controller.