MediaSessionManager: Add isTrustedForMediaControl()

The API checks whether an app is granted MEDIA_CONTENT_CONTROL
permisison or has enabled notification listener. Such apps can be
considered as the system component (e.g. Bluetooth) or equivalent (e.g.
Auto/Wearable companion app), so sessions shouldn't refuse connection
request from it.

It needs to be public because API for checking whether an app has an
enabled notification listener can only be called by the system service.
(see: NotificationManager.getEnabledNotificationListeners(int))
With the MediaSessionManager#isTrustedForMediaControl(),
MediaSessionService will query the information indirectly for a session
to tell an app is trusted.

Note that this isn't workaround for bypassing permission check of
NotificationManager API calls. It's indirectly available through
the android.provider.Settings.Secure with the *deprecated* key
ENABLD_NOTIFICATION_LISTENERS and it doesn't need any permission.
MediaSessionManager#isTrustedForMediaControl() is needed to avoid using
deprecated key for querying notification listeners.

Bug: 75500592
Test: Build
Change-Id: I8d1183aa946aa0d2ec35dbd7f31933d1c2717f99
2 files changed