Commit 8b7d5a9d authored by benwgold's avatar benwgold Committed by Commit Bot

Add restriction in code to prevent Lens integration below android O.

Bug: 1010708
Change-Id: I8fb61b726ffd4ac964cdbe0909689e0b15021fcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856619Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Ben Goldberger <benwgold@google.com>
Auto-Submit: Ben Goldberger <benwgold@google.com>
Cr-Commit-Position: refs/heads/master@{#705740}
parent 4d109d52
...@@ -214,7 +214,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -214,7 +214,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
// Only add new values at the end, right before NUM_ENTRIES. // Only add new values at the end, right before NUM_ENTRIES.
@IntDef({LensSupportStatus.LENS_SUPPORTED, LensSupportStatus.NON_GOOGLE_SEARCH_ENGINE, @IntDef({LensSupportStatus.LENS_SUPPORTED, LensSupportStatus.NON_GOOGLE_SEARCH_ENGINE,
LensSupportStatus.ACTIVITY_NOT_ACCESSIBLE, LensSupportStatus.OUT_OF_DATE, LensSupportStatus.ACTIVITY_NOT_ACCESSIBLE, LensSupportStatus.OUT_OF_DATE,
LensSupportStatus.SEARCH_BY_IMAGE_UNAVAILABLE}) LensSupportStatus.SEARCH_BY_IMAGE_UNAVAILABLE, LensSupportStatus.LEGACY_OS})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface LensSupportStatus { public @interface LensSupportStatus {
int LENS_SUPPORTED = 0; int LENS_SUPPORTED = 0;
...@@ -222,7 +222,8 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -222,7 +222,8 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
int ACTIVITY_NOT_ACCESSIBLE = 2; int ACTIVITY_NOT_ACCESSIBLE = 2;
int OUT_OF_DATE = 3; int OUT_OF_DATE = 3;
int SEARCH_BY_IMAGE_UNAVAILABLE = 4; int SEARCH_BY_IMAGE_UNAVAILABLE = 4;
int NUM_ENTRIES = 5; int LEGACY_OS = 5;
int NUM_ENTRIES = 6;
} }
/** /**
...@@ -630,6 +631,11 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -630,6 +631,11 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
return false; return false;
} }
if (LensUtils.isDeviceOsBelowMinimum()) {
ContextMenuUma.recordLensSupportStatus(ContextMenuUma.LensSupportStatus.LEGACY_OS);
return false;
}
ContextMenuUma.recordLensSupportStatus(ContextMenuUma.LensSupportStatus.LENS_SUPPORTED); ContextMenuUma.recordLensSupportStatus(ContextMenuUma.LensSupportStatus.LENS_SUPPORTED);
return true; return true;
} }
......
...@@ -10,6 +10,7 @@ import android.content.Intent; ...@@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
...@@ -31,15 +32,16 @@ public class LensUtils { ...@@ -31,15 +32,16 @@ public class LensUtils {
/** /**
* See function for details. * See function for details.
*/ */
private static boolean sFakePassableLensVersionForTesting; private static boolean sFakePassableLensEnvironmentForTesting;
/* /*
* If true, short-circuit the version name intent check to always return a high enough version. * If true, short-circuit the version name intent check to always return a high enough version.
* Also hardcode the device OS check to return true.
* Used by test cases. * Used by test cases.
* @param shouldFake Whether to fake the version check. * @param shouldFake Whether to fake the version check.
*/ */
public static void setFakePassableLensVersionForTesting(boolean shouldFake) { public static void setFakePassableLensEnvironmentForTesting(boolean shouldFake) {
sFakePassableLensVersionForTesting = shouldFake; sFakePassableLensEnvironmentForTesting = shouldFake;
} }
/** /**
...@@ -51,7 +53,7 @@ public class LensUtils { ...@@ -51,7 +53,7 @@ public class LensUtils {
*/ */
public static String getLensActivityVersionNameIfAvailable(Context context) { public static String getLensActivityVersionNameIfAvailable(Context context) {
// Use this syntax to avoid NPE if unset. // Use this syntax to avoid NPE if unset.
if (Boolean.TRUE.equals(sFakePassableLensVersionForTesting)) { if (Boolean.TRUE.equals(sFakePassableLensEnvironmentForTesting)) {
// Returns the minimum version which will meet the bar and allow future AGSA version // Returns the minimum version which will meet the bar and allow future AGSA version
// checks to succeed. // checks to succeed.
return MIN_AGSA_VERSION_NAME_FOR_LENS_POSTCAPTURE; return MIN_AGSA_VERSION_NAME_FOR_LENS_POSTCAPTURE;
...@@ -133,6 +135,20 @@ public class LensUtils { ...@@ -133,6 +135,20 @@ public class LensUtils {
return agsaNumbers.length < targetAgsaNumbers.length; return agsaNumbers.length < targetAgsaNumbers.length;
} }
/**
* Checks whether the device is below Android O. We restrict to these versions
* to limit to OS"s where image processing vulnerabilities can be retroactively
* fixed if they are discovered in the future.
* @return Whether the device is below Android O.
*/
public static boolean isDeviceOsBelowMinimum() {
if (sFakePassableLensEnvironmentForTesting) {
return false;
}
return Build.VERSION.SDK_INT < Build.VERSION_CODES.O;
}
/** /**
* Get a deeplink intent to Google Lens with an optional content provider image URI. * Get a deeplink intent to Google Lens with an optional content provider image URI.
* @param imageUri The content provider URI generated by chrome (or empty URI) * @param imageUri The content provider URI generated by chrome (or empty URI)
......
...@@ -96,7 +96,7 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -96,7 +96,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
TestThreadUtils.runOnUiThreadBlocking(() -> FirstRunStatus.setFirstRunFlowComplete(false)); TestThreadUtils.runOnUiThreadBlocking(() -> FirstRunStatus.setFirstRunFlowComplete(false));
deleteTestFiles(); deleteTestFiles();
ContextMenuHelper.setHardcodedImageBytesForTesting(null); ContextMenuHelper.setHardcodedImageBytesForTesting(null);
LensUtils.setFakePassableLensVersionForTesting(false); LensUtils.setFakePassableLensEnvironmentForTesting(false);
} }
@Override @Override
...@@ -105,7 +105,7 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -105,7 +105,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
mTestUrl = mTestServer.getURL(TEST_PATH); mTestUrl = mTestServer.getURL(TEST_PATH);
deleteTestFiles(); deleteTestFiles();
ContextMenuHelper.setHardcodedImageBytesForTesting(null); ContextMenuHelper.setHardcodedImageBytesForTesting(null);
LensUtils.setFakePassableLensVersionForTesting(false); LensUtils.setFakePassableLensEnvironmentForTesting(false);
mDownloadTestRule.startMainActivityWithURL(mTestUrl); mDownloadTestRule.startMainActivityWithURL(mTestUrl);
mDownloadTestRule.assertWaitForPageScaleFactorMatch(0.5f); mDownloadTestRule.assertWaitForPageScaleFactorMatch(0.5f);
} }
...@@ -142,7 +142,7 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -142,7 +142,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void testSearchWithGoogleLensFiresIntent() throws Throwable { public void testSearchWithGoogleLensFiresIntent() throws Throwable {
Tab tab = mDownloadTestRule.getActivity().getActivityTab(); Tab tab = mDownloadTestRule.getActivity().getActivityTab();
LensUtils.setFakePassableLensVersionForTesting(true); LensUtils.setFakePassableLensEnvironmentForTesting(true);
ShareHelper.setIgnoreActivityNotFoundExceptionForTesting(true); ShareHelper.setIgnoreActivityNotFoundExceptionForTesting(true);
hardcodeTestImageForSharing(); hardcodeTestImageForSharing();
...@@ -415,7 +415,7 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -415,7 +415,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
@Feature({"Browser", "ContextMenu"}) @Feature({"Browser", "ContextMenu"})
@EnableFeatures({ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS}) @EnableFeatures({ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS})
public void testContextMenuRetrievesImageOptionsLensEnabled() throws TimeoutException { public void testContextMenuRetrievesImageOptionsLensEnabled() throws TimeoutException {
LensUtils.setFakePassableLensVersionForTesting(true); LensUtils.setFakePassableLensEnvironmentForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab(); Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage"); ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
...@@ -455,7 +455,7 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -455,7 +455,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
@EnableFeatures({ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS}) @EnableFeatures({ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS})
public void testContextMenuRetrievesImageOptions_NoDefaultSearchEngineLensEnabled() public void testContextMenuRetrievesImageOptions_NoDefaultSearchEngineLensEnabled()
throws TimeoutException { throws TimeoutException {
LensUtils.setFakePassableLensVersionForTesting(true); LensUtils.setFakePassableLensEnvironmentForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab(); Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage"); ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
...@@ -495,7 +495,7 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -495,7 +495,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
@EnableFeatures({ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS}) @EnableFeatures({ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS})
public void testContextMenuRetrievesImageLinkOptionsSearchLensEnabled() public void testContextMenuRetrievesImageLinkOptionsSearchLensEnabled()
throws TimeoutException { throws TimeoutException {
LensUtils.setFakePassableLensVersionForTesting(true); LensUtils.setFakePassableLensEnvironmentForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab(); Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink"); ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink");
......
...@@ -10194,6 +10194,7 @@ Called by update_net_error_codes.py.--> ...@@ -10194,6 +10194,7 @@ Called by update_net_error_codes.py.-->
<int value="2" label="Activity Not Accessible"/> <int value="2" label="Activity Not Accessible"/>
<int value="3" label="Out of Date"/> <int value="3" label="Out of Date"/>
<int value="4" label="Search by Image Unavailable"/> <int value="4" label="Search by Image Unavailable"/>
<int value="5" label="OS Below Android O"/>
</enum> </enum>
<enum name="ContextMenuOption"> <enum name="ContextMenuOption">
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