From 9d93a378c5158d14f80d46af70433234330ec568 Mon Sep 17 00:00:00 2001 From: "P.Y. Laligand" Date: Thu, 16 Apr 2015 16:22:35 -0700 Subject: Consistent null-checking in MediaRouter. b/19747094 Change-Id: I5f8d086f717a11a9d03874e633471efed787a6c3 --- media/java/android/media/MediaRouter.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'media') diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index c227eb7..a046512 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -18,6 +18,7 @@ package android.media; import android.Manifest; import android.annotation.DrawableRes; +import android.annotation.NonNull; import android.app.ActivityThread; import android.content.BroadcastReceiver; import android.content.Context; @@ -882,8 +883,12 @@ public class MediaRouter { * @param types type flags indicating which types this route should be used for. * The route must support at least a subset. * @param route Route to select + * @throws IllegalArgumentException if the given route is {@code null} */ - public void selectRoute(int types, RouteInfo route) { + public void selectRoute(int types, @NonNull RouteInfo route) { + if (route == null) { + throw new IllegalArgumentException("Route cannot be null."); + } selectRouteStatic(types, route, true); } @@ -894,7 +899,8 @@ public class MediaRouter { selectRouteStatic(types, route, explicit); } - static void selectRouteStatic(int types, RouteInfo route, boolean explicit) { + static void selectRouteStatic(int types, @NonNull RouteInfo route, boolean explicit) { + assert(route != null); final RouteInfo oldRoute = sStatic.mSelectedRoute; if (oldRoute == route) return; if (!route.matchesTypes(types)) { @@ -917,7 +923,7 @@ public class MediaRouter { final WifiDisplay activeDisplay = sStatic.mDisplayService.getWifiDisplayStatus().getActiveDisplay(); final boolean oldRouteHasAddress = oldRoute != null && oldRoute.mDeviceAddress != null; - final boolean newRouteHasAddress = route != null && route.mDeviceAddress != null; + final boolean newRouteHasAddress = route.mDeviceAddress != null; if (activeDisplay != null || oldRouteHasAddress || newRouteHasAddress) { if (newRouteHasAddress && !matchesDeviceAddress(activeDisplay, route)) { if (sStatic.mCanConfigureWifiDisplays) { -- cgit v1.1