Commit 2f53d66e authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

Work around BadTokenException in PaymentRequest UI's DimmingDialog

Context:
DimmingDialog#show() could throw BadTokenException which is an Android
internal programming error. To work around this issue,
DimmingDialog#show() catch this exception and uses its return to
indicate the failure to PaymentUiService. When the failure happens,
close the PaymentRequest and report the error to the user.

Bug: 1139441

Change-Id: Ia2a23b61b249c25d068e201be0a41b1d57ebf249
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484043Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819042}
parent 81b161d9
...@@ -20,6 +20,7 @@ import android.view.View.OnLayoutChangeListener; ...@@ -20,6 +20,7 @@ import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.Window; import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
...@@ -116,9 +117,18 @@ import java.util.Collection; ...@@ -116,9 +117,18 @@ import java.util.Collection;
bottomSheetView.addOnLayoutChangeListener(new FadeInAnimator()); bottomSheetView.addOnLayoutChangeListener(new FadeInAnimator());
} }
/** Show the dialog. */ /**
/* package */ void show() { * Show the dialog.
mDialog.show(); * @return Whether the show is successful.
*/
/* package */ boolean show() {
try {
mDialog.show();
return true;
} catch (WindowManager.BadTokenException badToken) {
// The exception could be thrown according to https://crbug.com/1139441.
return false;
}
} }
/** Hide the dialog without dismissing it. */ /** Hide the dialog without dismissing it. */
......
...@@ -1452,12 +1452,14 @@ public class PaymentRequestUI implements DimmingDialog.OnDismissListener, View.O ...@@ -1452,12 +1452,14 @@ public class PaymentRequestUI implements DimmingDialog.OnDismissListener, View.O
* showPaymentRequestDialogWhenNoBottomSheet() and hidePaymentRequestDialog() instead of calling * showPaymentRequestDialogWhenNoBottomSheet() and hidePaymentRequestDialog() instead of calling
* this method directly. * this method directly.
* @param visible True to show the dialog, false to hide the dialog. * @param visible True to show the dialog, false to hide the dialog.
* @return Whether setting visibility is successful.
*/ */
public void setVisible(boolean visible) { public boolean setVisible(boolean visible) {
if (visible) { if (visible) {
mDialog.show(); return mDialog.show();
} else { } else {
mDialog.hide(); mDialog.hide();
return true;
} }
} }
......
...@@ -215,7 +215,11 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -215,7 +215,11 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
private void updatePaymentRequestDialogShowState() { private void updatePaymentRequestDialogShowState() {
if (mPaymentRequestUI == null) return; if (mPaymentRequestUI == null) return;
mPaymentRequestUI.setVisible(!mShowingBottomSheet && mShouldShowDialog); boolean isSuccess =
mPaymentRequestUI.setVisible(!mShowingBottomSheet && mShouldShowDialog);
if (!isSuccess) {
mObserver.onUiServiceError(ErrorStrings.FAIL_TO_SHOW_PAYMENT_REQUEST_UI);
}
} }
} }
......
...@@ -59,6 +59,9 @@ public abstract class ErrorStrings {{ ...@@ -59,6 +59,9 @@ public abstract class ErrorStrings {{
public static final String UNATHORIZED_SERVICE_REQUEST = public static final String UNATHORIZED_SERVICE_REQUEST =
"Caller's signuature or package name does not match invoked app's."; "Caller's signuature or package name does not match invoked app's.";
public static final String FAIL_TO_SHOW_PAYMENT_REQUEST_UI =
"Fails to show payment request UI. Please try again.";
// Prevent instantiation. // Prevent instantiation.
private ErrorStrings() {{}} private ErrorStrings() {{}}
}} }}
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