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
This commit is contained in:
Sarah Chin
2023-04-11 17:15:18 -07:00
parent 0f59388c3a
commit 1e26c2445b

View File

@@ -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);