MediaSessionManager.RemoteUserInfo

public static final class MediaSessionManager.RemoteUserInfo
extends Object

java.lang.Object
   ↳ androidx.media.MediaSessionManager.RemoteUserInfo


Information of a remote user of MediaSessionCompat or MediaBrowserServiceCompat. This can be used to decide whether the remote user is trusted app, and also differentiate caller of MediaSessionCompat and MediaBrowserServiceCompat callbacks.

See equals(Object) to take a look at how it differentiate media controller.

Summary

Constants

String LEGACY_CONTROLLER

Used by getPackageName() when the session is connected to the legacy controller whose exact package name cannot be obtained.

Public constructors

MediaSessionManager.RemoteUserInfo(String packageName, int pid, int uid)

Public constructor.

Public methods

boolean equals(Object obj)

Returns equality of two RemoteUserInfo.

String getPackageName()
int getPid()
int getUid()
int hashCode()

Inherited methods

Constants

LEGACY_CONTROLLER

public static final String LEGACY_CONTROLLER

Used by getPackageName() when the session is connected to the legacy controller whose exact package name cannot be obtained.

Constant Value: "android.media.session.MediaController"

Public constructors

MediaSessionManager.RemoteUserInfo

public MediaSessionManager.RemoteUserInfo (String packageName, 
                int pid, 
                int uid)

Public constructor.

Can be used for MediaSessionManager.isTrustedForMediaControl(RemoteUserInfo)}.

Parameters
packageName String: package name of the remote user

pid int: pid of the remote user

uid int: uid of the remote user

Public methods

equals

public boolean equals (Object obj)

Returns equality of two RemoteUserInfo.

Prior to P (API < 28), two RemoteUserInfo objects are equal only if they are from same package and from same process.

On P and beyond (API >= 28), two RemoteUserInfo objects are equal only if they're sent from the same controller (either MediaControllerCompat or MediaBrowserCompat. If it's not nor one of them is triggered by the key presses, they would be considered as different one.

If you only want to compare the caller's package, compare them with the getPackageName(), getPid(), and/or getUid() directly.

Parameters
obj Object: the reference object with which to compare.

Returns
boolean true if equals, false otherwise

getPackageName

public String getPackageName ()

Returns
String package name of the controller. Can be LEGACY_CONTROLLER if the package name cannot be obtained.

getPid

public int getPid ()

Returns
int pid of the controller. Can be a negative value if the pid cannot be obtained.

getUid

public int getUid ()

Returns
int uid of the controller. Can be a negative value if the uid cannot be obtained.

hashCode

public int hashCode ()

Returns
int