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 { ...@@ -50,6 +50,11 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
@VisibleForTesting @VisibleForTesting
public static final String INSTANT_APP_HOLDBACK_ID_STRING = "instantapp:holdback"; 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 static final String TAG = "InstalledAppProvider";
private final FrameUrlDelegate mFrameUrlDelegate; private final FrameUrlDelegate mFrameUrlDelegate;
...@@ -85,7 +90,6 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -85,7 +90,6 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
public void filterInstalledApps( public void filterInstalledApps(
final RelatedApplication[] relatedApps, final FilterInstalledAppsResponse callback) { final RelatedApplication[] relatedApps, final FilterInstalledAppsResponse callback) {
final URI frameUrl = mFrameUrlDelegate.getUrl(); final URI frameUrl = mFrameUrlDelegate.getUrl();
// Use an AsyncTask to execute the installed/related checks on a background thread (so as // Use an AsyncTask to execute the installed/related checks on a background thread (so as
// not to block the UI thread). // not to block the UI thread).
new AsyncTask<Pair<RelatedApplication[], Integer>>() { new AsyncTask<Pair<RelatedApplication[], Integer>>() {
...@@ -133,7 +137,8 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -133,7 +137,8 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
ArrayList<RelatedApplication> installedApps = new ArrayList<RelatedApplication>(); ArrayList<RelatedApplication> installedApps = new ArrayList<RelatedApplication>();
int delayMillis = 0; int delayMillis = 0;
PackageManager pm = mContext.getPackageManager(); 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 // 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. // package, add the package to the list of valid packages.
// NOTE: For security, it must not be possible to distinguish (from the response) // NOTE: For security, it must not be possible to distinguish (from the response)
......
...@@ -47,6 +47,8 @@ public class InstalledAppProviderTest { ...@@ -47,6 +47,8 @@ public class InstalledAppProviderTest {
InstalledAppProviderImpl.ASSET_STATEMENT_NAMESPACE_WEB; InstalledAppProviderImpl.ASSET_STATEMENT_NAMESPACE_WEB;
private static final String PLATFORM_ANDROID = private static final String PLATFORM_ANDROID =
InstalledAppProviderImpl.RELATED_APP_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"; private static final String PLATFORM_OTHER = "itunes";
// Note: Android package name and origin deliberately unrelated (there is no requirement that // Note: Android package name and origin deliberately unrelated (there is no requirement that
// they be the same). // they be the same).
...@@ -785,14 +787,13 @@ public class InstalledAppProviderTest { ...@@ -785,14 +787,13 @@ public class InstalledAppProviderTest {
RelatedApplication[] manifestRelatedApps = new RelatedApplication[] { RelatedApplication[] manifestRelatedApps = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null), createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null),
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_2, null), createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_2, null),
createRelatedApplication(PLATFORM_OTHER, PACKAGE_NAME_2, null),
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_3, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_3, null)};
setAssetStatement(PACKAGE_NAME_2, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN); setAssetStatement(PACKAGE_NAME_2, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN);
setAssetStatement(PACKAGE_NAME_3, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN); setAssetStatement(PACKAGE_NAME_3, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN);
RelatedApplication[] expectedInstalledRelatedApps = RelatedApplication[] expectedInstalledRelatedApps =
new RelatedApplication[] {manifestRelatedApps[1], manifestRelatedApps[3]}; new RelatedApplication[] {manifestRelatedApps[1], manifestRelatedApps[2]};
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps); verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
} }
...@@ -829,10 +830,6 @@ public class InstalledAppProviderTest { ...@@ -829,10 +830,6 @@ public class InstalledAppProviderTest {
public void testMultipleAppsIncludingInstantApps() { public void testMultipleAppsIncludingInstantApps() {
RelatedApplication[] manifestRelatedApps = new RelatedApplication[] { RelatedApplication[] manifestRelatedApps = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null), 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: // Instant Apps:
createRelatedApplication( createRelatedApplication(
PLATFORM_ANDROID, InstalledAppProviderImpl.INSTANT_APP_ID_STRING, ORIGIN), PLATFORM_ANDROID, InstalledAppProviderImpl.INSTANT_APP_ID_STRING, ORIGIN),
...@@ -843,7 +840,30 @@ public class InstalledAppProviderTest { ...@@ -843,7 +840,30 @@ public class InstalledAppProviderTest {
mFakeInstantAppsHandler.addInstantApp(ORIGIN, true); mFakeInstantAppsHandler.addInstantApp(ORIGIN, true);
RelatedApplication[] expectedInstalledRelatedApps = 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); 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