Commit 09e5fabe authored by Juan Mojica's avatar Juan Mojica Committed by Commit Bot

Added feature param to enable direct intent for Lens integration.

Bug: 1098431
Change-Id: I59d6d61731c4eb515ee1bc648adf7c8607133f65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261258
Auto-Submit: Juan Mojica <juanmojica@google.com>
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarSinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#782018}
parent e44a32d3
......@@ -30,6 +30,7 @@ import org.chromium.components.variations.VariationsAssociatedData;
*/
public class LensUtils {
private static final String LENS_CONTRACT_URI = "googleapp://lens";
private static final String LENS_DIRECT_INTENT_CONTRACT_URI = "google://lens";
private static final String LENS_BITMAP_URI_KEY = "LensBitmapUriKey";
private static final String ACCOUNT_NAME_URI_KEY = "AccountNameUriKey";
private static final String INCOGNITO_URI_KEY = "IncognitoUriKey";
......@@ -48,6 +49,7 @@ public class LensUtils {
private static final String LOG_UKM_PARAM_NAME = "logUkm";
private static final String SEND_SRC_PARAM_NAME = "sendSrc";
private static final String SEND_ALT_PARAM_NAME = "sendAlt";
private static final String USE_DIRECT_INTENT_FEATURE_PARAM_NAME = "useDirectIntent";
private static final String MIN_AGSA_VERSION_NAME_FOR_LENS_POSTCAPTURE = "8.19";
private static final String MIN_AGSA_VERSION_NAME_FOR_LENS_CHROME_SHOPPING_INTENT = "11.16";
private static final String LENS_INTENT_TYPE_LENS_CHROME_SHOPPING = "18";
......@@ -232,7 +234,8 @@ public class LensUtils {
final String signedInAccountName =
(coreAccountInfo == null || isIncognito) ? "" : coreAccountInfo.getEmail();
Uri lensUri = Uri.parse(LENS_CONTRACT_URI);
Uri lensUri = useDirectIntent() ? Uri.parse(LENS_DIRECT_INTENT_CONTRACT_URI)
: Uri.parse(LENS_CONTRACT_URI);
if (!Uri.EMPTY.equals(imageUri)) {
final Uri.Builder lensUriBuilder =
lensUri.buildUpon()
......@@ -298,6 +301,16 @@ public class LensUtils {
|| useLensWithSearchSimilarProducts();
}
/**
* Enables the starting of LenActivity directly, rather than going through the Lens
* session running in AGSA.
*/
public static boolean useDirectIntent() {
return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS,
USE_DIRECT_INTENT_FEATURE_PARAM_NAME, false);
}
/**
* Whether to display the lens menu item with the search by image text
*/
......
......@@ -58,6 +58,39 @@ public class LensUtilsTest {
intentWithContentUri.getAction());
}
/**
* Test {@link LensUtils#getShareWithGoogleLensIntent()} method when user is signed
* in and the direct intent experiment is enabled.
*/
@CommandLineFlags.Add({"enable-features="
+ ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS + "<FakeStudyName",
"force-fieldtrials=FakeStudyName/Enabled",
"force-fieldtrial-params=FakeStudyName.Enabled:useDirectIntent/true"})
@Test
@SmallTest
public void
getShareWithGoogleLensIntentSignedInTest_directIntentEnabled() {
mBrowserTestRule.addAndSignInTestAccount();
Intent intentNoUri = getShareWithGoogleLensIntentOnUiThread(Uri.EMPTY,
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
Assert.assertEquals("Intent without image has incorrect URI", "google://lens",
intentNoUri.getData().toString());
Assert.assertEquals("Intent without image has incorrect action", Intent.ACTION_VIEW,
intentNoUri.getAction());
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
Assert.assertEquals("Intent with image has incorrect URI",
"google://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url"
+ "&AccountNameUriKey=test%40gmail.com&IncognitoUriKey=false"
+ "&ActivityLaunchTimestampNanos=1234",
intentWithContentUri.getData().toString());
Assert.assertEquals("Intent with image has incorrect action", Intent.ACTION_VIEW,
intentWithContentUri.getAction());
}
/**
* Test {@link LensUtils#getShareWithGoogleLensIntent()} method when user is
* incognito.
......
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