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 { ...@@ -218,9 +218,14 @@ public final class WebPaymentIntentHelperTypeConverter {
if (update == null) return null; if (update == null) return null;
return new WebPaymentIntentHelperType.PaymentRequestDetailsUpdate( return new WebPaymentIntentHelperType.PaymentRequestDetailsUpdate(
fromMojoPaymentCurrencyAmount(update.total), fromMojoPaymentCurrencyAmount(update.total),
fromMojoShippingOptionList(Arrays.asList(update.shippingOptions)), // Arrays.asList does not accept null.
fromMojoPaymentHandlerModifierList(Arrays.asList(update.modifiers)), update.error, update.shippingOptions == null
update.stringifiedPaymentMethodErrors, ? null
: fromMojoShippingOptionList(Arrays.asList(update.shippingOptions)),
update.modifiers == null
? null
: fromMojoPaymentHandlerModifierList(Arrays.asList(update.modifiers)),
update.error, update.stringifiedPaymentMethodErrors,
fromMojoShippingAddressErrors(update.shippingAddressErrors)); fromMojoShippingAddressErrors(update.shippingAddressErrors));
} }
} }
...@@ -84,6 +84,14 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -84,6 +84,14 @@ public class PaymentDetailsUpdateServiceHelperTest {
return bundle; 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 boolean mBound;
private IPaymentDetailsUpdateService mIPaymentDetailsUpdateService; private IPaymentDetailsUpdateService mIPaymentDetailsUpdateService;
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {
...@@ -297,11 +305,8 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -297,11 +305,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
public void testConnectWhenPaymentAppNotInvoked() throws Throwable { public void testConnectWhenPaymentAppNotInvoked() throws Throwable {
installPaymentApp(); installPaymentApp();
startPaymentDetailsUpdateService(); startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method name");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
mIPaymentDetailsUpdateService.changePaymentMethod( mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback()); defaultMethodDataBundle(), new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(false); verifyIsWaitingForPaymentDetailsUpdate(false);
Assert.assertFalse(mMethodChangeListenerNotified); Assert.assertFalse(mMethodChangeListenerNotified);
// An unauthorized app won't get a callback with error. // An unauthorized app won't get a callback with error.
...@@ -315,11 +320,8 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -315,11 +320,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
public void testSuccessfulChangePaymentMethod() throws Throwable { public void testSuccessfulChangePaymentMethod() throws Throwable {
installAndInvokePaymentApp(); installAndInvokePaymentApp();
startPaymentDetailsUpdateService(); startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method name");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
mIPaymentDetailsUpdateService.changePaymentMethod( mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback()); defaultMethodDataBundle(), new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(true); verifyIsWaitingForPaymentDetailsUpdate(true);
Assert.assertTrue(mMethodChangeListenerNotified); Assert.assertTrue(mMethodChangeListenerNotified);
updateWithDefaultDetails(); updateWithDefaultDetails();
...@@ -347,7 +349,7 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -347,7 +349,7 @@ public class PaymentDetailsUpdateServiceHelperTest {
installAndInvokePaymentApp(); installAndInvokePaymentApp();
startPaymentDetailsUpdateService(); startPaymentDetailsUpdateService();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details"); bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "data");
mIPaymentDetailsUpdateService.changePaymentMethod( mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback()); bundle, new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(false); verifyIsWaitingForPaymentDetailsUpdate(false);
...@@ -417,11 +419,8 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -417,11 +419,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
public void testChangeWhileWaitingForPaymentDetailsUpdate() throws Throwable { public void testChangeWhileWaitingForPaymentDetailsUpdate() throws Throwable {
installAndInvokePaymentApp(); installAndInvokePaymentApp();
startPaymentDetailsUpdateService(); startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method name");
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "details");
mIPaymentDetailsUpdateService.changePaymentMethod( mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback()); defaultMethodDataBundle(), new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(true); verifyIsWaitingForPaymentDetailsUpdate(true);
Assert.assertTrue(mMethodChangeListenerNotified); Assert.assertTrue(mMethodChangeListenerNotified);
......
...@@ -27,9 +27,10 @@ public class PaymentDetailsUpdateService extends Service { ...@@ -27,9 +27,10 @@ public class PaymentDetailsUpdateService extends Service {
@Override @Override
public void changePaymentMethod(Bundle paymentHandlerMethodData, public void changePaymentMethod(Bundle paymentHandlerMethodData,
IPaymentDetailsUpdateServiceCallback callback) { IPaymentDetailsUpdateServiceCallback callback) {
int callingUid = Binder.getCallingUid();
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized( if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized(
Binder.getCallingUid())) { callingUid)) {
return; return;
} }
PaymentDetailsUpdateServiceHelper.getInstance().changePaymentMethod( PaymentDetailsUpdateServiceHelper.getInstance().changePaymentMethod(
...@@ -39,9 +40,10 @@ public class PaymentDetailsUpdateService extends Service { ...@@ -39,9 +40,10 @@ public class PaymentDetailsUpdateService extends Service {
@Override @Override
public void changeShippingOption( public void changeShippingOption(
String shippingOptionId, IPaymentDetailsUpdateServiceCallback callback) { String shippingOptionId, IPaymentDetailsUpdateServiceCallback callback) {
int callingUid = Binder.getCallingUid();
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized( if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized(
Binder.getCallingUid())) { callingUid)) {
return; return;
} }
PaymentDetailsUpdateServiceHelper.getInstance().changeShippingOption( PaymentDetailsUpdateServiceHelper.getInstance().changeShippingOption(
...@@ -51,9 +53,10 @@ public class PaymentDetailsUpdateService extends Service { ...@@ -51,9 +53,10 @@ public class PaymentDetailsUpdateService extends Service {
@Override @Override
public void changeShippingAddress( public void changeShippingAddress(
Bundle shippingAddress, IPaymentDetailsUpdateServiceCallback callback) { Bundle shippingAddress, IPaymentDetailsUpdateServiceCallback callback) {
int callingUid = Binder.getCallingUid();
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized( if (!PaymentDetailsUpdateServiceHelper.getInstance().isCallerAuthorized(
Binder.getCallingUid())) { callingUid)) {
return; return;
} }
PaymentDetailsUpdateServiceHelper.getInstance().changeShippingAddress( 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