1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.carrierdefaultapp; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.telephony.TelephonyManager; 22 import android.webkit.JavascriptInterface; 23 24 import com.android.phone.slice.SlicePurchaseController; 25 26 /** 27 * Data boost web service flow interface allowing carrier websites to send responses back to the 28 * slice purchase application using JavaScript. 29 */ 30 public class DataBoostWebServiceFlow { 31 @NonNull SlicePurchaseActivity mActivity; 32 DataBoostWebServiceFlow(@onNull SlicePurchaseActivity activity)33 public DataBoostWebServiceFlow(@NonNull SlicePurchaseActivity activity) { 34 mActivity = activity; 35 } 36 37 /** 38 * Interface method allowing the carrier website to get the premium capability 39 * that was requested to purchase. 40 * 41 * This can be called using the JavaScript below: 42 * <script type="text/javascript"> 43 * function getRequestedCapability(duration) { 44 * DataBoostWebServiceFlow.getRequestedCapability(); 45 * } 46 * </script> 47 */ 48 @JavascriptInterface getRequestedCapability()49 @TelephonyManager.PremiumCapability public int getRequestedCapability() { 50 return mActivity.mCapability; 51 } 52 53 /** 54 * Interface method allowing the carrier website to notify the slice purchase application of 55 * a successful premium capability purchase and the duration for which the premium capability is 56 * purchased. 57 * 58 * This can be called using the JavaScript below: 59 * <script type="text/javascript"> 60 * function notifyPurchaseSuccessful() { 61 * DataBoostWebServiceFlow.notifyPurchaseSuccessful(); 62 * } 63 * </script> 64 */ 65 @JavascriptInterface notifyPurchaseSuccessful()66 public void notifyPurchaseSuccessful() { 67 mActivity.onPurchaseSuccessful(); 68 } 69 70 /** 71 * Interface method allowing the carrier website to notify the slice purchase application of 72 * a failed premium capability purchase. 73 * 74 * This can be called using the JavaScript below: 75 * <script type="text/javascript"> 76 * function notifyPurchaseFailed(failure_code = 0, failure_reason = "unknown") { 77 * DataBoostWebServiceFlow.notifyPurchaseFailed(); 78 * } 79 * </script> 80 * 81 * @param failureCode The failure code. 82 * @param failureReason If the failure code is 83 * {@link SlicePurchaseController#FAILURE_CODE_UNKNOWN}, 84 * the human-readable reason for failure. 85 */ 86 @JavascriptInterface notifyPurchaseFailed(@licePurchaseController.FailureCode int failureCode, @Nullable String failureReason)87 public void notifyPurchaseFailed(@SlicePurchaseController.FailureCode int failureCode, 88 @Nullable String failureReason) { 89 mActivity.onPurchaseFailed(failureCode, failureReason); 90 } 91 92 /** 93 * Interface method allowing the carrier website to notify the slice purchase application that 94 * the service flow ended prematurely. This can be due to user action, an error in the 95 * web sheet logic, or an error on the network side. 96 * 97 * This can be called using the JavaScript below: 98 * <script type="text/javascript"> 99 * function dismissFlow() { 100 * DataBoostWebServiceFlow.dismissFlow(); 101 * } 102 * </script> 103 */ 104 @JavascriptInterface dismissFlow()105 public void dismissFlow() { 106 mActivity.onDismissFlow(); 107 } 108 } 109