MediaRouter: Check sGlobal before call RouteInfo.isDefault
RouteInfo.isDefault() is called while sGlobal is null in
setSelectedRouteInternal(). This CL fixes the issue by checking
the value of sGlobal and adds a log for debugging purpose.
Bug: 63134119
Test: ./gradlew support-mediarouter-v7:connectedCheck
Change-Id: I9e5a1b4b6cb84ba7a455e4af4a1be57d69ea7385
diff --git a/v7/mediarouter/src/android/support/v7/media/MediaRouter.java b/v7/mediarouter/src/android/support/v7/media/MediaRouter.java
index 8b64688..cc5648f 100644
--- a/v7/mediarouter/src/android/support/v7/media/MediaRouter.java
+++ b/v7/mediarouter/src/android/support/v7/media/MediaRouter.java
@@ -2562,7 +2562,7 @@
private void setSelectedRouteInternal(RouteInfo route, int unselectReason) {
// TODO: Remove the following logging when no longer needed.
- if (mBluetoothRoute != null && route != null && route.isDefault()) {
+ if (sGlobal == null || mBluetoothRoute != null && route != null && route.isDefault()) {
final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
StringBuffer sb = new StringBuffer();
// callStack[3] is the caller of this method.
@@ -2571,8 +2571,13 @@
sb.append(caller.getClassName() + "." + caller.getMethodName()
+ ":" + caller.getLineNumber()).append(" ");
}
- Log.w(TAG, "Default route is selected while a BT route is available: pkgName="
- + mApplicationContext.getPackageName() + ", callers=" + sb.toString());
+ if (sGlobal == null) {
+ Log.w(TAG, "setSelectedRouteInternal is called while sGlobal is null: pkgName="
+ + mApplicationContext.getPackageName() + ", callers=" + sb.toString());
+ } else {
+ Log.w(TAG, "Default route is selected while a BT route is available: pkgName="
+ + mApplicationContext.getPackageName() + ", callers=" + sb.toString());
+ }
}
if (mSelectedRoute != route) {