Commit d3eaf40b authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payment][Android] Fix minor delegation issues

This cl contains the following changes:

1-PaymentRequestUpdateDetails can have null shippingOptions/modifiers
The cl modifies the TypeConverter to check for null arrays before
passing them to Arrays.asList

2-changePaymentMethod/changeShipping[Address|Option] from
PaymentDetailsUpdateService should get the binder's calling uid before
posting the task to the browser's UI thread.

Bug: 1026667
Change-Id: I94aaf4caa0d3b08db89993b0450cd3baf7b77a60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252199Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780313}
parent 77e0de82
......@@ -218,9 +218,14 @@ public final class WebPaymentIntentHelperTypeConverter {
if (update == null) return null;
return new WebPaymentIntentHelperType.PaymentRequestDetailsUpdate(
fromMojoPaymentCurrencyAmount(update.total),
fromMojoShippingOptionList(Arrays.asList(update.shippingOptions)),
fromMojoPaymentHandlerModifierList(Arrays.asList(update.modifiers)), update.error,
update.stringifiedPaymentMethodErrors,
// Arrays.asList does not accept null.
update.shippingOptions == null
? null
: fromMojoShippingOptionList(Arrays.asList(update.shippingOptions)),
update.modifiers == null
? null
: fromMojoPaymentHandlerModifierList(Arrays.asList(update.modifiers)),
update.error, update.stringifiedPaymentMethodErrors,
fromMojoShippingAddressErrors(update.shippingAddressErrors));
}
}
......@@ -84,6 +84,14 @@ public class PaymentDetailsUpdateServiceHelperTest {
return bundle;
}
private Bundle defaultMethodDataBundle() {
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method-name");
bundle.putString(
PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "{\"key\": \"value\"}");
return bundle;
}
private boolean mBound;
private IPaymentDetailsUpdateService mIPaymentDetailsUpdateService;
private ServiceConnection mConnection = new ServiceConnection() {
......@@ -297,11 +305,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
public void testConnectWhenPaymentAppNotInvoked() throws Throwable {
installPaymentApp();
startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method name");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback());
defaultMethodDataBundle(), new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(false);
Assert.assertFalse(mMethodChangeListenerNotified);
// An unauthorized app won't get a callback with error.
......@@ -315,11 +320,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
public void testSuccessfulChangePaymentMethod() throws Throwable {
installAndInvokePaymentApp();
startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method name");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback());
defaultMethodDataBundle(), new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(true);
Assert.assertTrue(mMethodChangeListenerNotified);
updateWithDefaultDetails();
......@@ -347,7 +349,7 @@ public class PaymentDetailsUpdateServiceHelperTest {
installAndInvokePaymentApp();
startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "data");
mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(false);
......@@ -417,11 +419,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
public void testChangeWhileWaitingForPaymentDetailsUpdate() throws Throwable {
installAndInvokePaymentApp();
startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method name");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback());
defaultMethodDataBundle(), new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(true);
Assert.assertTrue(mMethodChangeListenerNotified);
......
......@@ -27,9 +27,10 @@ public class PaymentDetailsUpdateService extends Service {
@Override
public void changePaymentMethod(Bundle paymentHandlerMethodData,
IPaymentDetailsUpdateServiceCallback callback) {
int callingUid = Binder.getCallingUid();
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized(
Binder.getCallingUid())) {
callingUid)) {
return;
}
PaymentDetailsUpdateServiceHelper.getInstance().changePaymentMethod(
......@@ -39,9 +40,10 @@ public class PaymentDetailsUpdateService extends Service {
@Override
public void changeShippingOption(
String shippingOptionId, IPaymentDetailsUpdateServiceCallback callback) {
int callingUid = Binder.getCallingUid();
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized(
Binder.getCallingUid())) {
callingUid)) {
return;
}
PaymentDetailsUpdateServiceHelper.getInstance().changeShippingOption(
......@@ -51,9 +53,10 @@ public class PaymentDetailsUpdateService extends Service {
@Override
public void changeShippingAddress(
Bundle shippingAddress, IPaymentDetailsUpdateServiceCallback callback) {
int callingUid = Binder.getCallingUid();
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized(
Binder.getCallingUid())) {
callingUid)) {
return;
}
PaymentDetailsUpdateServiceHelper.getInstance().changeShippingAddress(
......
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