Commit 319e254a authored by Zhiheng Li's avatar Zhiheng Li Committed by Commit Bot

Add conversation ID to the intent sent to CastWindowManager

Bug: b/149024372

Test: cast_shell_junit_tests

Change-Id: I75acbf9adf659f3e61d1855ea6771e895a305fe4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2052246
Commit-Queue: Zhiheng(Vincent) Li <vincentli@google.com>
Auto-Submit: Zhiheng(Vincent) Li <vincentli@google.com>
Reviewed-by: default avatarSimeon Anfinrud <sanfin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741186}
parent 5e458696
......@@ -106,9 +106,12 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp
@SuppressWarnings("unused")
@CalledByNative
private void setInteractionId(int interactionId) {
if (DEBUG) Log.d(TAG, "setInteractionid interactionId=" + interactionId);
mComponent.setInteractionId(interactionId);
private void setHostContext(int interactionId, String conversationId) {
if (DEBUG) {
Log.d(TAG, "setInteractionid interactionId=%s; conversationID=%s", interactionId,
conversationId);
}
mComponent.setHostContext(interactionId, conversationId);
}
@Override
......
......@@ -299,9 +299,13 @@ public class CastWebContentsComponent {
sendIntentSync(CastWebContentsIntentUtils.enableTouchInput(mSessionId, enabled));
}
public void setInteractionId(int interactionId) {
if (DEBUG) Log.d(TAG, "setInteractionid interactionId=" + interactionId);
sendIntentSync(CastWebContentsIntentUtils.setInteractionId(mSessionId, interactionId));
public void setHostContext(int interactionId, String conversationId) {
if (DEBUG) {
Log.d(TAG, "setInteractionid interactionId=%s; conversationID=%s", interactionId,
conversationId);
}
sendIntentSync(CastWebContentsIntentUtils.setHostContext(
mSessionId, interactionId, conversationId));
}
public static void onComponentClosed(String sessionId) {
......
......@@ -81,11 +81,11 @@ public class CastWebContentsIntentUtils {
"com.google.android.apps.castshell.intent.action.ENABLE_TOUCH_INPUT";
/**
* Action type of intent from CastWebContentsComponent to set interaction ID to cast window
* host.
* Action type of intent from CastWebContentsComponent to set interaction ID and conversation ID
* to cast window host.
*/
public static final String ACTION_SET_INTERACTION_ID =
"com.google.android.apps.castshell.intent.action.SET_INTERACTION_ID";
public static final String ACTION_SET_HOST_CONTEXT =
"com.google.android.apps.castshell.intent.action.SET_HOST_CONTEXT";
/** Key of extra value in an intent, the value is a URI of cast://webcontents/<instanceId> */
static final String INTENT_EXTRA_URI = "content_uri";
......@@ -151,12 +151,19 @@ public class CastWebContentsIntentUtils {
"com.google.android.apps.castshell.intent.extra.GESTURE_CONSUMED";
/**
* Key of extra value of the intent ACTION_SET_INTERACTION_ID, value is an int of
* Key of extra value of the intent ACTION_SET_HOST_CONTEXT, value is an int of
* interaction ID.
*/
private static final String INTENT_EXTRA_INTERACTION_ID =
"com.google.android.apps.castshell.intent.extra.INTERACTION_ID";
/**
* Key of extra value of the intent ACTION_SET_HOST_CONTEXT, value is a string of
* conversation ID.
*/
private static final String INTENT_EXTRA_CONVERSATION_ID =
"com.google.android.apps.castshell.intent.extra.CONVERSATION_ID";
@VisibilityType
static final int VISIBITY_TYPE_UNKNOWN = VisibilityType.UNKNOWN;
@VisibilityType
......@@ -280,11 +287,16 @@ public class CastWebContentsIntentUtils {
return bundle.getBoolean(INTENT_EXTRA_GESTURE_CONSUMED);
}
// Used by intent of ACTION_SET_INTERACTION_ID
// Used by intent of ACTION_SET_HOST_CONTEXT
public static int getInteractionId(Intent in) {
return in.getIntExtra(INTENT_EXTRA_INTERACTION_ID, 0);
}
// Used by intent of ACTION_SET_HOST_CONTEXT
public static String getConversationId(Intent in) {
return in.getStringExtra(INTENT_EXTRA_CONVERSATION_ID);
}
public static boolean isIntentOfActivityStopped(Intent in) {
return in.getAction().equals(ACTION_ACTIVITY_STOPPED);
}
......@@ -441,11 +453,16 @@ public class CastWebContentsIntentUtils {
}
// CastWebContentsComponent -> CastWindowManager
public static Intent setInteractionId(String instanceId, int interactionId) {
if (DEBUG) Log.d(TAG, "setInteractionid interactionId=" + interactionId);
Intent intent = new Intent(ACTION_SET_INTERACTION_ID);
public static Intent setHostContext(
String instanceId, int interactionId, String conversationId) {
if (DEBUG) {
Log.d(TAG, "setInteractionid interactionId=%s; conversationID=%s", interactionId,
conversationId);
}
Intent intent = new Intent(ACTION_SET_HOST_CONTEXT);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
intent.putExtra(INTENT_EXTRA_INTERACTION_ID, interactionId);
intent.putExtra(INTENT_EXTRA_CONVERSATION_ID, conversationId);
return intent;
}
......
......@@ -36,6 +36,7 @@ base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow(
}
constexpr char kContextInteractionId[] = "interactionId";
constexpr char kContextConversationId[] = "conversationId";
} // namespace
......@@ -103,13 +104,17 @@ void CastContentWindowAndroid::SetActivityContext(
void CastContentWindowAndroid::SetHostContext(base::Value host_context) {
auto* found_interaction_id = host_context.FindKey(kContextInteractionId);
if (found_interaction_id) {
auto* found_conversation_id = host_context.FindKey(kContextConversationId);
if (found_interaction_id && found_conversation_id) {
int interaction_id = found_interaction_id->GetInt();
std::string& conversation_id = found_conversation_id->GetString();
JNIEnv* env = base::android::AttachCurrentThread();
Java_CastContentWindowAndroid_setInteractionId(
env, java_window_, static_cast<int>(interaction_id));
} else
LOG(ERROR) << "Interaction ID not found";
Java_CastContentWindowAndroid_setHostContext(
env, java_window_, static_cast<int>(interaction_id),
ConvertUTF8ToJavaString(env, conversation_id));
} else {
LOG(ERROR) << "Interaction ID or Conversation ID is not found";
}
}
void CastContentWindowAndroid::NotifyVisibilityChange(
......
......@@ -257,12 +257,13 @@ public class CastWebContentsIntentUtilsTest {
}
@Test
public void testSetInteractionId() {
Intent in = CastWebContentsIntentUtils.setInteractionId(SESSION_ID, 123);
public void testSetHostContext() {
Intent in = CastWebContentsIntentUtils.setHostContext(SESSION_ID, 123, "foo");
String uri = CastWebContentsIntentUtils.getUriString(in);
Assert.assertNotNull(uri);
Assert.assertEquals(EXPECTED_URI, uri);
Assert.assertEquals(CastWebContentsIntentUtils.ACTION_SET_INTERACTION_ID, in.getAction());
Assert.assertEquals(CastWebContentsIntentUtils.ACTION_SET_HOST_CONTEXT, in.getAction());
Assert.assertEquals(CastWebContentsIntentUtils.getInteractionId(in), 123);
Assert.assertEquals(CastWebContentsIntentUtils.getConversationId(in), "foo");
}
}
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