| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.media.router; | 5 package org.chromium.chrome.browser.media.router; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.support.v7.media.MediaRouter; | 7 import android.support.v7.media.MediaRouter; |
| 9 | 8 |
| 9 import org.chromium.base.ContextUtils; |
| 10 import org.chromium.base.SysUtils; | 10 import org.chromium.base.SysUtils; |
| 11 import org.chromium.base.VisibleForTesting; | 11 import org.chromium.base.VisibleForTesting; |
| 12 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
| 13 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
| 14 import org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider; | 14 import org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider; |
| 15 import org.chromium.chrome.browser.media.router.cast.MediaSink; | 15 import org.chromium.chrome.browser.media.router.cast.MediaSink; |
| 16 import org.chromium.chrome.browser.media.router.cast.MediaSource; | 16 import org.chromium.chrome.browser.media.router.cast.MediaSource; |
| 17 | 17 |
| 18 import java.util.ArrayList; | 18 import java.util.ArrayList; |
| 19 import java.util.HashMap; | 19 import java.util.HashMap; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return mSinksPerSourcePerProvider; | 65 return mSinksPerSourcePerProvider; |
| 66 } | 66 } |
| 67 | 67 |
| 68 @VisibleForTesting | 68 @VisibleForTesting |
| 69 protected Map<String, List<MediaSink>> getSinksPerSourceForTest() { | 69 protected Map<String, List<MediaSink>> getSinksPerSourceForTest() { |
| 70 return mSinksPerSource; | 70 return mSinksPerSource; |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Obtains the {@link MediaRouter} instance given the application context. | 74 * Obtains the {@link MediaRouter} instance given the application context. |
| 75 * @param applicationContext The context to get the Android media router ser
vice for. | |
| 76 * @return Null if the media router API is not supported, the service instan
ce otherwise. | 75 * @return Null if the media router API is not supported, the service instan
ce otherwise. |
| 77 */ | 76 */ |
| 78 @Nullable | 77 @Nullable |
| 79 public static MediaRouter getAndroidMediaRouter(Context applicationContext)
{ | 78 public static MediaRouter getAndroidMediaRouter() { |
| 80 try { | 79 try { |
| 81 // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, | 80 // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, |
| 82 // so getting the MediaRouter instance will throw an exception. | 81 // so getting the MediaRouter instance will throw an exception. |
| 83 return MediaRouter.getInstance(applicationContext); | 82 return MediaRouter.getInstance(ContextUtils.getApplicationContext())
; |
| 84 } catch (NoSuchMethodError e) { | 83 } catch (NoSuchMethodError e) { |
| 85 return null; | 84 return null; |
| 86 } catch (NoClassDefFoundError e) { | 85 } catch (NoClassDefFoundError e) { |
| 87 // TODO(mlamouri): happens with Robolectric. | 86 // TODO(mlamouri): happens with Robolectric. |
| 88 return null; | 87 return null; |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 @Override | 91 @Override |
| 93 public void onSinksReceived( | 92 public void onSinksReceived( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 150 } |
| 152 | 151 |
| 153 @Override | 152 @Override |
| 154 public void onMessage(String mediaRouteId, String message) { | 153 public void onMessage(String mediaRouteId, String message) { |
| 155 nativeOnMessage(mNativeMediaRouterAndroid, mediaRouteId, message); | 154 nativeOnMessage(mNativeMediaRouterAndroid, mediaRouteId, message); |
| 156 } | 155 } |
| 157 | 156 |
| 158 /** | 157 /** |
| 159 * Initializes the media router and its providers. | 158 * Initializes the media router and its providers. |
| 160 * @param nativeMediaRouterAndroid the handler for the native counterpart of
this instance | 159 * @param nativeMediaRouterAndroid the handler for the native counterpart of
this instance |
| 161 * @param applicationContext the application context to use to obtain system
APIs | |
| 162 * @return an initialized {@link ChromeMediaRouter} instance | 160 * @return an initialized {@link ChromeMediaRouter} instance |
| 163 */ | 161 */ |
| 164 @CalledByNative | 162 @CalledByNative |
| 165 public static ChromeMediaRouter create(long nativeMediaRouterAndroid, | 163 public static ChromeMediaRouter create(long nativeMediaRouterAndroid) { |
| 166 Context applicationContext) { | |
| 167 ChromeMediaRouter router = new ChromeMediaRouter(nativeMediaRouterAndroi
d); | 164 ChromeMediaRouter router = new ChromeMediaRouter(nativeMediaRouterAndroi
d); |
| 168 MediaRouteProvider provider = sRouteProviderBuilder.create(applicationCo
ntext, router); | 165 MediaRouteProvider provider = sRouteProviderBuilder.create(router); |
| 169 if (provider != null) router.addMediaRouteProvider(provider); | 166 if (provider != null) router.addMediaRouteProvider(provider); |
| 170 | 167 |
| 171 return router; | 168 return router; |
| 172 } | 169 } |
| 173 | 170 |
| 174 /** | 171 /** |
| 175 * Starts background monitoring for available media sinks compatible with th
e given | 172 * Starts background monitoring for available media sinks compatible with th
e given |
| 176 * |sourceUrn| if the device is in a state that allows it. | 173 * |sourceUrn| if the device is in a state that allows it. |
| 177 * @param sourceId a URL to use for filtering of the available media sinks | 174 * @param sourceId a URL to use for filtering of the available media sinks |
| 178 * @return whether the monitoring started (ie. was allowed). | 175 * @return whether the monitoring started (ie. was allowed). |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 boolean wasLaunched); | 356 boolean wasLaunched); |
| 360 native void nativeOnRouteRequestError( | 357 native void nativeOnRouteRequestError( |
| 361 long nativeMediaRouterAndroid, String errorText, int createRouteRequ
estId); | 358 long nativeMediaRouterAndroid, String errorText, int createRouteRequ
estId); |
| 362 native void nativeOnRouteClosed(long nativeMediaRouterAndroid, String mediaR
outeId); | 359 native void nativeOnRouteClosed(long nativeMediaRouterAndroid, String mediaR
outeId); |
| 363 native void nativeOnRouteClosedWithError( | 360 native void nativeOnRouteClosedWithError( |
| 364 long nativeMediaRouterAndroid, String mediaRouteId, String message); | 361 long nativeMediaRouterAndroid, String mediaRouteId, String message); |
| 365 native void nativeOnMessageSentResult( | 362 native void nativeOnMessageSentResult( |
| 366 long nativeMediaRouterAndroid, boolean success, int callbackId); | 363 long nativeMediaRouterAndroid, boolean success, int callbackId); |
| 367 native void nativeOnMessage(long nativeMediaRouterAndroid, String mediaRoute
Id, String message); | 364 native void nativeOnMessage(long nativeMediaRouterAndroid, String mediaRoute
Id, String message); |
| 368 } | 365 } |
| OLD | NEW |