Commit b79f523c authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Add custom remote playback app ID

The RemotePlaybackAppLauncher CL was reverted due to a regression
(see cb04d0bc). Since the revert, needs
have changed, and we no longer need a fully dynamically chosen app ID.

This CL adds the ability to define a custom RemotePlayback app ID from
the AndroidManifest, which can be overriden downstream. The info is
stored in a static field, since it does not change at runtime.

Bug: 790766
Change-Id: I2b2d466304234f4c07a4b617dc336f936aabc585
Reviewed-on: https://chromium-review.googlesource.com/c/1334660
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarZhiqiang Zhang <zqzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609840}
parent b0432d14
...@@ -3,11 +3,16 @@ ...@@ -3,11 +3,16 @@
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.chrome.browser.media.router.cast.remoting; package org.chromium.chrome.browser.media.router.cast.remoting;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.media.MediaRouteSelector; import android.support.v7.media.MediaRouteSelector;
import android.util.Base64; import android.util.Base64;
import com.google.android.gms.cast.CastMediaControlIntent; import com.google.android.gms.cast.CastMediaControlIntent;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.chrome.browser.media.router.MediaSource; import org.chromium.chrome.browser.media.router.MediaSource;
...@@ -24,16 +29,18 @@ public class RemotingMediaSource implements MediaSource { ...@@ -24,16 +29,18 @@ public class RemotingMediaSource implements MediaSource {
// Need to be in sync with third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp. // Need to be in sync with third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp.
// TODO(avayvod): Find a way to share the constants somehow. // TODO(avayvod): Find a way to share the constants somehow.
private static final String SOURCE_PREFIX = "remote-playback://"; private static final String SOURCE_PREFIX = "remote-playback://";
private static final String REMOTE_PLAYBACK_APP_ID_KEY =
"org.chromium.content.browser.REMOTE_PLAYBACK_APP_ID";
/** /**
* The original source URL that the {@link MediaSource} object was created from. * The Cast application id.
*/ */
private final String mSourceId; private static String sApplicationId;
/** /**
* The Cast application id. * The original source URL that the {@link MediaSource} object was created from.
*/ */
private final String mApplicationId; private final String mSourceId;
/** /**
* The URL to fling to the Cast device. * The URL to fling to the Cast device.
...@@ -61,9 +68,7 @@ public class RemotingMediaSource implements MediaSource { ...@@ -61,9 +68,7 @@ public class RemotingMediaSource implements MediaSource {
return null; return null;
} }
// TODO(avayvod): check the content URL and override the app id if needed. return new RemotingMediaSource(sourceId, mediaUrl);
String applicationId = CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
return new RemotingMediaSource(sourceId, applicationId, mediaUrl);
} }
/** /**
...@@ -75,16 +80,46 @@ public class RemotingMediaSource implements MediaSource { ...@@ -75,16 +80,46 @@ public class RemotingMediaSource implements MediaSource {
@Override @Override
public MediaRouteSelector buildRouteSelector() { public MediaRouteSelector buildRouteSelector() {
return new MediaRouteSelector.Builder() return new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId)) .addControlCategory(CastMediaControlIntent.categoryForCast(getApplicationId()))
.build(); .build();
} }
/**
* Lazily loads a custom App ID from the AndroidManifest, which can be overriden
* downstream. This app ID will never change, so we can store it in a static field.
* If there is no custom app ID defined, or if there is an error retreiving the app ID,
* we fallback to the default media receiver app ID.
*
* @return a custom app ID or the default media receiver app ID.
*/
private static String applicationId() {
if (sApplicationId == null) {
String customAppId = null;
try {
Context context = ContextUtils.getApplicationContext();
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = ai.metaData;
customAppId = bundle.getString(REMOTE_PLAYBACK_APP_ID_KEY);
} catch (Exception e) {
// Should never happen, implies a corrupt AndroidManifest.
}
sApplicationId = (customAppId != null)
? customAppId
: CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
}
return sApplicationId;
}
/** /**
* @return the Cast application id corresponding to the source. Can be overridden downstream. * @return the Cast application id corresponding to the source. Can be overridden downstream.
*/ */
@Override @Override
public String getApplicationId() { public String getApplicationId() {
return mApplicationId; return applicationId();
} }
/** /**
...@@ -102,9 +137,8 @@ public class RemotingMediaSource implements MediaSource { ...@@ -102,9 +137,8 @@ public class RemotingMediaSource implements MediaSource {
return mMediaUrl; return mMediaUrl;
} }
private RemotingMediaSource(String sourceId, String applicationId, String mediaUrl) { private RemotingMediaSource(String sourceId, String mediaUrl) {
mSourceId = sourceId; mSourceId = sourceId;
mApplicationId = applicationId;
mMediaUrl = mediaUrl; mMediaUrl = mediaUrl;
} }
} }
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