Fix a crash when mediaSource is null
am: 1b6f499ade
Change-Id: I0816652abb048faa34b13fd3a1eb5deeec296b7e
diff --git a/service/src/com/android/car/CarMediaService.java b/service/src/com/android/car/CarMediaService.java
index 70d3b7e..4841b0d 100644
--- a/service/src/com/android/car/CarMediaService.java
+++ b/service/src/com/android/car/CarMediaService.java
@@ -529,9 +529,18 @@
if (!matchPrimaryMediaSource(newPackageName, newClassName)) {
ComponentName mediaSource = getMediaSource(newPackageName, newClassName);
if (Log.isLoggable(CarLog.TAG_MEDIA, Log.INFO)) {
- Log.i(CarLog.TAG_MEDIA,
- "Changing media source due to playback state change: "
- + mediaSource.flattenToString());
+ if (mediaSource != null) {
+ Log.i(CarLog.TAG_MEDIA,
+ "MediaController changed, updating media source to: "
+ + mediaSource.flattenToString());
+ } else {
+ // Some apps, like Chrome, have a MediaSession but no
+ // MediaBrowseService. Media Center doesn't consider such apps as
+ // valid media sources.
+ Log.i(CarLog.TAG_MEDIA,
+ "MediaController changed, but no media browse service found "
+ + "in package: " + newPackageName);
+ }
}
setPrimaryMediaSource(mediaSource);
}