Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90476172 authored by Sarah Chin's avatar Sarah Chin Committed by Sarah Kim
Browse files

Add dismissFlow callback to SlicePurchaseWebInterface

Changes are to be consistent with TS.43 upsell call flow

Test: manual verify no regression of purchase behavior
Bug: 269356100
Change-Id: I58875f7d8ba3499cc7bf91699b5ceb9d417e1bfe
parent e1574fc0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -75,5 +75,11 @@
        Notify purchase failed
    </button>
    <p id="purchase_failed"></p>

    <h2>Dismiss flow</h2>
    <button type="button" onclick="testDismissFlow()">
        Dismiss flow
    </button>
    <p id="dismiss_flow"></p>
</body>
</html>
+6 −0
Original line number Diff line number Diff line
@@ -31,3 +31,9 @@ function testNotifyPurchaseFailed(failure_code = 0, failure_reason = "unknown")
    document.getElementById("purchase_failed").innerHTML =
            "Notified purchase failed.";
}

function testDismissFlow() {
    DataBoostWebServiceFlow.dismissFlow();
    document.getElementById("dismiss_flow").innerHTML =
            "Called dismiss flow.";
}
+17 −0
Original line number Diff line number Diff line
@@ -88,4 +88,21 @@ public class DataBoostWebServiceFlow {
            @Nullable String failureReason) {
        mActivity.onPurchaseFailed(failureCode, failureReason);
    }

    /**
     * Interface method allowing the carrier website to notify the slice purchase application that
     * the service flow ended prematurely. This can be due to user action, an error in the
     * web sheet logic, or an error on the network side.
     *
     * This can be called using the JavaScript below:
     * <script type="text/javascript">
     *     function dismissFlow() {
     *         DataBoostWebServiceFlow.dismissFlow();
     *     }
     * </script>
     */
    @JavascriptInterface
    public void dismissFlow() {
        mActivity.onDismissFlow();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -137,6 +137,14 @@ public class SlicePurchaseActivity extends Activity {
        finishAndRemoveTask();
    }

    protected void onDismissFlow() {
        logd("onDismissFlow: Dismiss flow called while purchasing premium capability "
                + TelephonyManager.convertPremiumCapabilityToString(mCapability));
        SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponse(
                mIntent, SlicePurchaseController.EXTRA_INTENT_REQUEST_FAILED);
        finishAndRemoveTask();
    }

    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        // Pressing back in the WebView will go to the previous page instead of closing
+13 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas
    @Mock PendingIntent mPendingIntent;
    @Mock PendingIntent mSuccessfulIntent;
    @Mock PendingIntent mCanceledIntent;
    @Mock PendingIntent mRequestFailedIntent;
    @Mock CarrierConfigManager mCarrierConfigManager;
    @Mock NotificationManager mNotificationManager;
    @Mock PersistableBundle mPersistableBundle;
@@ -112,6 +113,11 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas
        doReturn(true).when(mSuccessfulIntent).isBroadcast();
        doReturn(mSuccessfulIntent).when(spiedIntent).getParcelableExtra(
                eq(SlicePurchaseController.EXTRA_INTENT_SUCCESS), eq(PendingIntent.class));
        doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mRequestFailedIntent)
                .getCreatorPackage();
        doReturn(true).when(mRequestFailedIntent).isBroadcast();
        doReturn(mRequestFailedIntent).when(spiedIntent).getParcelableExtra(
                eq(SlicePurchaseController.EXTRA_INTENT_REQUEST_FAILED), eq(PendingIntent.class));

        mSlicePurchaseActivity = startActivity(spiedIntent, null, null);
    }
@@ -124,7 +130,7 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas

    @Test
    public void testOnPurchaseFailed() throws Exception {
        int failureCode = SlicePurchaseController.FAILURE_CODE_SERVER_UNREACHABLE;
        int failureCode = SlicePurchaseController.FAILURE_CODE_CARRIER_URL_UNAVAILABLE;
        String failureReason = "Server unreachable";
        mSlicePurchaseActivity.onPurchaseFailed(failureCode, failureReason);
        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -141,4 +147,10 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas
        mSlicePurchaseActivity.onDestroy();
        verify(mCanceledIntent).send();
    }

    @Test
    public void testOnDismissFlow() throws Exception {
        mSlicePurchaseActivity.onDismissFlow();
        verify(mRequestFailedIntent).send();
    }
}