Commit 0db6cad8 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Payments] Multiple payment apps in single web app manifest.

Before this patch, if a single web app manifest specified multiple
sections of "related_applications" with different "id" (package name)
fields and the user had several of these payment apps installed, then
Chrome would display only one of these payment apps.

The problem arose from an erroneous assumption of 1:1 relationship
between web app manifests and payment apps. In fact, a single web app
manifest can correspond to multiple payment apps, e.g., a dev and a prod
version of the same app.

The fix is to loop through the full web app manifest when looking for
matching payment apps, instead of early-exiting when the first matching
payment app is found.

After this patch, if a single web app manifest specified multiple
sections of "related_applications" with different "id" fields and the
user had several of these payment apps installed, then Chrome displays
all of the matching payment apps.

Bug: 745765
Change-Id: I70f287cb792ac8b0b073c22e9c08eebec6ffae3e
Reviewed-on: https://chromium-review.googlesource.com/579964Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488399}
parent f3d8718a
......@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.payments;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.support.annotation.Nullable;
import org.chromium.base.Log;
import org.chromium.chrome.browser.UrlConstants;
......@@ -277,12 +276,9 @@ public class PaymentManifestVerifier
return;
}
String verifiedAppPackageName = verifyAppWithWebAppManifest(manifest);
if (verifiedAppPackageName != null) {
// Do not notify onValidPaymentApp immediately in case of fetching the other web app's
// manifest failed. Switch to download manifest online in that case immediately.
mVerifiedAppPackageNamesByCachedManifest.add(verifiedAppPackageName);
}
// Do not notify onValidPaymentApp immediately in case of fetching the other web app's
// manifest failed. Switch to download manifest online in that case immediately.
mVerifiedAppPackageNamesByCachedManifest.addAll(verifyAppWithWebAppManifest(manifest));
mPendingWebAppManifestsCount--;
if (mPendingWebAppManifestsCount != 0) return;
......@@ -341,11 +337,11 @@ public class PaymentManifestVerifier
// Do not verify payment app if it has already been verified by cached manifest.
if (mIsManifestCacheStaleOrUnusable) {
String verifiedAppPackageName = verifyAppWithWebAppManifest(manifest);
if (verifiedAppPackageName != null) {
Set<String> verifiedAppPackageNames = verifyAppWithWebAppManifest(manifest);
for (String packageName : verifiedAppPackageNames) {
mCallback.onValidPaymentApp(
mMethodName, mMatchingApps.get(verifiedAppPackageName).resolveInfo);
mMatchingApps.remove(verifiedAppPackageName);
mMethodName, mMatchingApps.get(packageName).resolveInfo);
mMatchingApps.remove(packageName);
}
}
......@@ -372,8 +368,11 @@ public class PaymentManifestVerifier
mCallback.onVerifyFinished(this);
}
@Nullable
private String verifyAppWithWebAppManifest(WebAppManifestSection[] manifest) {
/**
* @return The set of package names of payment apps that match the manifest. Could be empty,
* but never null.
*/
private Set<String> verifyAppWithWebAppManifest(WebAppManifestSection[] manifest) {
List<Set<String>> sectionsFingerprints = new ArrayList<>();
for (int i = 0; i < manifest.length; i++) {
WebAppManifestSection section = manifest[i];
......@@ -384,17 +383,18 @@ public class PaymentManifestVerifier
sectionsFingerprints.add(fingerprints);
}
Set<String> packageNames = new HashSet<>();
for (int i = 0; i < manifest.length; i++) {
WebAppManifestSection section = manifest[i];
AppInfo appInfo = mMatchingApps.get(section.id);
if (appInfo != null && appInfo.version >= section.minVersion
&& appInfo.sha256CertFingerprints != null
&& appInfo.sha256CertFingerprints.equals(sectionsFingerprints.get(i))) {
return section.id;
packageNames.add(section.id);
}
}
return null;
return packageNames;
}
@Override
......
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