Commit 6fadd24a authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[InstalledApp] Limit the number of related apps used.

Only take the first 3 related apps declared in the web manifest into
account when determining if there are any related apps.

Change-Id: I4a0ba7372351f3b4e541a920794aaaab812184f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1953715
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722532}
parent a959702f
......@@ -50,6 +50,11 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
@VisibleForTesting
public static final String INSTANT_APP_HOLDBACK_ID_STRING = "instantapp:holdback";
// The maximum number of related apps declared in the Web Manifest taken into account when
// determining whether the related app is installed and mutually related.
@VisibleForTesting
static final int MAX_ALLOWED_RELATED_APPS = 3;
private static final String TAG = "InstalledAppProvider";
private final FrameUrlDelegate mFrameUrlDelegate;
......@@ -85,7 +90,6 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
public void filterInstalledApps(
final RelatedApplication[] relatedApps, final FilterInstalledAppsResponse callback) {
final URI frameUrl = mFrameUrlDelegate.getUrl();
// Use an AsyncTask to execute the installed/related checks on a background thread (so as
// not to block the UI thread).
new AsyncTask<Pair<RelatedApplication[], Integer>>() {
......@@ -133,7 +137,8 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
ArrayList<RelatedApplication> installedApps = new ArrayList<RelatedApplication>();
int delayMillis = 0;
PackageManager pm = mContext.getPackageManager();
for (RelatedApplication app : relatedApps) {
for (int i = 0; i < Math.min(relatedApps.length, MAX_ALLOWED_RELATED_APPS); i++) {
RelatedApplication app = relatedApps[i];
// If the package is of type "play", it is installed, and the origin is associated with
// package, add the package to the list of valid packages.
// NOTE: For security, it must not be possible to distinguish (from the response)
......
......@@ -47,6 +47,8 @@ public class InstalledAppProviderTest {
InstalledAppProviderImpl.ASSET_STATEMENT_NAMESPACE_WEB;
private static final String PLATFORM_ANDROID =
InstalledAppProviderImpl.RELATED_APP_PLATFORM_ANDROID;
private static final int MAX_ALLOWED_RELATED_APPS =
InstalledAppProviderImpl.MAX_ALLOWED_RELATED_APPS;
private static final String PLATFORM_OTHER = "itunes";
// Note: Android package name and origin deliberately unrelated (there is no requirement that
// they be the same).
......@@ -785,14 +787,13 @@ public class InstalledAppProviderTest {
RelatedApplication[] manifestRelatedApps = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null),
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_2, null),
createRelatedApplication(PLATFORM_OTHER, PACKAGE_NAME_2, null),
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_3, null)};
setAssetStatement(PACKAGE_NAME_2, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN);
setAssetStatement(PACKAGE_NAME_3, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN);
RelatedApplication[] expectedInstalledRelatedApps =
new RelatedApplication[] {manifestRelatedApps[1], manifestRelatedApps[3]};
new RelatedApplication[] {manifestRelatedApps[1], manifestRelatedApps[2]};
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
}
......@@ -829,10 +830,6 @@ public class InstalledAppProviderTest {
public void testMultipleAppsIncludingInstantApps() {
RelatedApplication[] manifestRelatedApps = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null),
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_2, null),
createRelatedApplication(PLATFORM_OTHER, PACKAGE_NAME_2, null),
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_3, null),
// Instant Apps:
createRelatedApplication(
PLATFORM_ANDROID, InstalledAppProviderImpl.INSTANT_APP_ID_STRING, ORIGIN),
......@@ -843,7 +840,30 @@ public class InstalledAppProviderTest {
mFakeInstantAppsHandler.addInstantApp(ORIGIN, true);
RelatedApplication[] expectedInstalledRelatedApps =
new RelatedApplication[] {manifestRelatedApps[0], manifestRelatedApps[5]};
new RelatedApplication[] {manifestRelatedApps[0], manifestRelatedApps[2]};
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
}
/**
* Multiple related uninstalled apps (over the allowed limit) followed by one related Android
* app which is installed and mutually related.
*/
@Test
@Feature({"InstalledApp"})
public void testRelatedAppsOverAllowedThreshold() {
RelatedApplication manifestRelatedApps[] =
new RelatedApplication[MAX_ALLOWED_RELATED_APPS + 1];
for (int i = 0; i < MAX_ALLOWED_RELATED_APPS; i++) {
manifestRelatedApps[i] = createRelatedApplication(
PLATFORM_ANDROID, PACKAGE_NAME_2 + String.valueOf(i), null);
}
manifestRelatedApps[MAX_ALLOWED_RELATED_APPS] =
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null);
setAssetStatement(PACKAGE_NAME_1, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN);
// Although the app is installed, and verifiable, it was included after the maximum allowed
// number of related apps.
RelatedApplication[] expectedInstalledRelatedApps = new RelatedApplication[] {};
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
}
}
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