MediaRouter: Black magic to bring custom media metadata back

MediaMetadataCompat and MediaMetadata are internally converted into each
other on platform version 21 or higher as the framework
(e.g. MediaSession) does not understand MediaMetadataCompat. When this
happens, custom key-value pairs are lost.

The difficulty here is that the current framework API does not provide a
way to tell the type of each custom key-value pair in MediaMetadata
making it impossible to extract them while converting.
This could've been avoided if there is a way to retrieve data as a
generic object such as Object or Bundle but the current design offers
get-methods only for specific types.

The code change here tries to overcome this problem by copying the
underlying Bundle object that represents the whole media metadata as is
when performing the conversion hence preserving the entirety of the
data. Care was taken to replace RatingCompat values in metadata with
Rating values such that the metadata Bundle can be unmarshalled on the
framework side.

Bug: 25328581
Change-Id: Ic83b73e18e31baf9446ca845b7e49aa508b3f108
2 files changed