Commit 68c71019 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer MediaRouter: remove feature flag in favor of manifest entry.

Instead of using a command line flag, the feature is toggled by an
AndroidManifest entry. This is more ergonomic for developers as they
don't need to use a debug build of Android to toggle the feature.

Bug: 1057100
Change-Id: Icdc6676d1b15e43a46ebb6d14276cef89ff4942f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480705
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818779}
parent 83a7b6c4
......@@ -87,7 +87,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
PrerenderLinkManagerFactory::GetInstance();
PrerenderManagerFactory::GetInstance();
#if defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(features::kMediaRouter)) {
if (MediaRouterFactory::IsFeatureEnabled()) {
LocalPresentationManagerFactory::GetInstance();
MediaRouterFactory::GetInstance();
}
......
......@@ -641,7 +641,7 @@ ContentBrowserClientImpl::GetControllerPresentationServiceDelegate(
if (WebLayerFactoryImplAndroid::GetClientMajorVersion() < 88)
return nullptr;
if (base::FeatureList::IsEnabled(features::kMediaRouter)) {
if (MediaRouterFactory::IsFeatureEnabled()) {
MediaRouterFactory::DoPlatformInitIfNeeded();
return media_router::PresentationServiceDelegateImpl::
GetOrCreateForWebContents(web_contents);
......
......@@ -6,5 +6,11 @@ package org.chromium.weblayer_private.interfaces;
/** Keys for remote media service intent extras. */
public interface RemoteMediaServiceConstants {
String NOTIFICATION_ID_KEY = "remote_media_service_notification_id_key";
// Used as a key in the client's AndroidManifest.xml to enable remote media playback, i.e.
// Presentation API, Remote Playback API, and Media Fling (automatic casting of html5 videos).
String FEATURE_ENABLED_KEY = "org.chromium.weblayer.ENABLE_REMOTE_MEDIA";
// Used internally by WebLayer as a key to the various values of remote media service
// notification IDs.
String NOTIFICATION_ID_KEY = "REMOTE_MEDIA_SERVICE_NOTIFICATION_ID_KEY";
}
......@@ -5,11 +5,16 @@
package org.chromium.weblayer_private.media;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.support.v4.media.session.MediaSessionCompat;
import androidx.fragment.app.FragmentManager;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.components.browser_ui.media.MediaNotificationController;
......@@ -87,6 +92,18 @@ public class MediaRouterClientImpl extends MediaRouterClient {
MediaRouterClient.setInstance(new MediaRouterClientImpl());
}
@CalledByNative
public static boolean isMediaRouterEnabled() {
Context context = ContextUtils.getApplicationContext();
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
return ai.metaData.getBoolean(RemoteMediaServiceConstants.FEATURE_ENABLED_KEY);
} catch (NameNotFoundException e) {
return false;
}
}
private static class MediaRouterNotificationControllerDelegate
implements MediaNotificationController.Delegate {
// The ID distinguishes between Presentation and Remoting services/notifications.
......
......@@ -20,6 +20,13 @@ MediaRouterFactory* MediaRouterFactory::GetInstance() {
return instance.get();
}
// static
bool MediaRouterFactory::IsFeatureEnabled() {
static bool enabled = Java_MediaRouterClientImpl_isMediaRouterEnabled(
base::android::AttachCurrentThread());
return enabled;
}
// static
void MediaRouterFactory::DoPlatformInitIfNeeded() {
static bool init_done = false;
......
......@@ -25,6 +25,9 @@ class MediaRouterFactory : public media_router::MediaRouterFactory {
static MediaRouterFactory* GetInstance();
// Determines if media router related features should be enabled.
static bool IsFeatureEnabled();
// Performs platform and WebLayer-specific initialization for media_router.
static void DoPlatformInitIfNeeded();
......
......@@ -9,11 +9,6 @@ namespace features {
// Weblayer features in alphabetical order.
// Covers all media router features, i.e. Presentation API, Remote Playback API,
// and Media Fling (automatic casting of html5 videos).
const base::Feature kMediaRouter{"WebLayerMediaRouter",
base::FEATURE_DISABLED_BY_DEFAULT};
// Safebrowsing support for weblayer.
const base::Feature kWebLayerSafeBrowsing{"WebLayerSafeBrowsing",
base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -12,8 +12,6 @@ namespace features {
// Weblayer features in alphabetical order.
extern const base::Feature kMediaRouter;
extern const base::Feature kWebLayerSafeBrowsing;
} // namespace features
......
......@@ -17,7 +17,18 @@ import org.chromium.weblayer_private.interfaces.RemoteMediaServiceConstants;
*
* Like {@link MediaSessionService}, this class is associated with a notification for an ongoing
* media session. The difference is that the media for this service is played back on a remote
* device, i.e. casting.
* device, i.e. casting. This class can be considered an implementation detail of WebLayer.
*
* In order to set the Cast application (optional but recommended), the client should add the
* following to its manifest:
*
* <meta-data
* android:name="org.chromium.content.browser.REMOTE_PLAYBACK_APP_ID"
* android:value="$APP_ID"/>
*
* Where $APP_ID is the value assigned to your app by the Google Cast SDK Developer Console. If
* the cast application ID is not set, the app will appear as "Default Media Receiver" in the
* notification, device selection dialog, etc.
*
* @since 88
*/
......
......@@ -54,6 +54,8 @@
</activity>
<!-- Cast support -->
<meta-data
android:name="org.chromium.weblayer.ENABLE_REMOTE_MEDIA" android:value="true"/>
<meta-data
android:name=
"com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment