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