From 1e26c2445bcc16f3da94649fa0eead32678e5bac Mon Sep 17 00:00:00 2001 From: Sarah Chin Date: Tue, 11 Apr 2023 17:15:18 -0700 Subject: [PATCH] SlicePurchaseActivity don't send canceled on manual finish onDestroy is called when the user closes the app or when finish() is called programatically. We call finish after sending a response from the slice purchase activity, but we shouldn't send the canceled response because the user didn't close the application. Add a check to see whether onDestroy was called programatically or due to user action. Test: manual, CTS Bug: 276703840 Change-Id: Iae1f5e77a1b6d75b911f4bd5314869b36157afda --- .../carrierdefaultapp/SlicePurchaseActivity.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseActivity.java b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseActivity.java index 5f067e9836a22..b888739016c73 100644 --- a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseActivity.java +++ b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseActivity.java @@ -60,6 +60,7 @@ public class SlicePurchaseActivity extends Activity { @NonNull private Intent mIntent; @NonNull private URL mUrl; @TelephonyManager.PremiumCapability protected int mCapability; + private boolean mIsUserTriggeredFinish; @Override protected void onCreate(Bundle savedInstanceState) { @@ -71,6 +72,7 @@ public class SlicePurchaseActivity extends Activity { SlicePurchaseController.PREMIUM_CAPABILITY_INVALID); String url = mIntent.getStringExtra(SlicePurchaseController.EXTRA_PURCHASE_URL); mApplicationContext = getApplicationContext(); + mIsUserTriggeredFinish = true; logd("onCreate: subId=" + subId + ", capability=" + TelephonyManager.convertPremiumCapabilityToString(mCapability) + ", url=" + url); @@ -153,12 +155,20 @@ public class SlicePurchaseActivity extends Activity { @Override protected void onDestroy() { - logd("onDestroy: User canceled the purchase by closing the application."); - SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponse( - mIntent, SlicePurchaseController.EXTRA_INTENT_CANCELED); + if (mIsUserTriggeredFinish) { + logd("onDestroy: User canceled the purchase by closing the application."); + SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponse( + mIntent, SlicePurchaseController.EXTRA_INTENT_CANCELED); + } super.onDestroy(); } + @Override + public void finishAndRemoveTask() { + mIsUserTriggeredFinish = false; + super.finishAndRemoveTask(); + } + private void setupWebView() { // Create WebView mWebView = new WebView(this);