Loading packages/CarrierDefaultApp/assets/slice_purchase_test.html +3 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ <meta charset="UTF-8"> <meta name="description" content=" This is a HTML page that calls and verifies responses from the @JavascriptInterface functions of SlicePurchaseWebInterface. Test slice purchase application behavior using ADB shell commands and DataBoostWebServiceFlow. Test slice purchase application behavior using ADB shell commands and the APIs below: FROM TERMINAL: Loading Loading @@ -65,8 +65,8 @@ <p id="requested_capability"></p> <h2>Notify purchase successful</h2> <button type="button" onclick="testNotifyPurchaseSuccessful(60000)"> Notify purchase successful for 1 minute <button type="button" onclick="testNotifyPurchaseSuccessful()"> Notify purchase successful </button> <p id="purchase_successful"></p> Loading packages/CarrierDefaultApp/assets/slice_purchase_test.js +5 −5 Original line number Diff line number Diff line Loading @@ -15,19 +15,19 @@ */ function testGetRequestedCapability() { let capability = SlicePurchaseWebInterface.getRequestedCapability(); let capability = DataBoostWebServiceFlow.getRequestedCapability(); document.getElementById("requested_capability").innerHTML = "Premium capability requested: " + capability; } function testNotifyPurchaseSuccessful(duration_ms_long = 0) { SlicePurchaseWebInterface.notifyPurchaseSuccessful(duration_ms_long); function testNotifyPurchaseSuccessful() { DataBoostWebServiceFlow.notifyPurchaseSuccessful(); document.getElementById("purchase_successful").innerHTML = "Notified purchase success for duration: " + duration_ms_long; "Notified purchase successful."; } function testNotifyPurchaseFailed(failure_code = 0, failure_reason = "unknown") { SlicePurchaseWebInterface.notifyPurchaseFailed(failure_code, failure_reason); DataBoostWebServiceFlow.notifyPurchaseFailed(failure_code, failure_reason); document.getElementById("purchase_failed").innerHTML = "Notified purchase failed."; } packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseWebInterface.java→packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/DataBoostWebServiceFlow.java +9 −11 Original line number Diff line number Diff line Loading @@ -24,13 +24,13 @@ import android.webkit.JavascriptInterface; import com.android.phone.slice.SlicePurchaseController; /** * Slice purchase web interface class allowing carrier websites to send responses back to the * Data boost web service flow interface allowing carrier websites to send responses back to the * slice purchase application using JavaScript. */ public class SlicePurchaseWebInterface { public class DataBoostWebServiceFlow { @NonNull SlicePurchaseActivity mActivity; public SlicePurchaseWebInterface(@NonNull SlicePurchaseActivity activity) { public DataBoostWebServiceFlow(@NonNull SlicePurchaseActivity activity) { mActivity = activity; } Loading @@ -41,7 +41,7 @@ public class SlicePurchaseWebInterface { * This can be called using the JavaScript below: * <script type="text/javascript"> * function getRequestedCapability(duration) { * SlicePurchaseWebInterface.getRequestedCapability(); * DataBoostWebServiceFlow.getRequestedCapability(); * } * </script> */ Loading @@ -57,16 +57,14 @@ public class SlicePurchaseWebInterface { * * This can be called using the JavaScript below: * <script type="text/javascript"> * function notifyPurchaseSuccessful(duration_ms_long = 0) { * SlicePurchaseWebInterface.notifyPurchaseSuccessful(duration_ms_long); * function notifyPurchaseSuccessful() { * DataBoostWebServiceFlow.notifyPurchaseSuccessful(); * } * </script> * * @param duration The duration for which the premium capability is purchased in milliseconds. */ @JavascriptInterface public void notifyPurchaseSuccessful(long duration) { mActivity.onPurchaseSuccessful(duration); public void notifyPurchaseSuccessful() { mActivity.onPurchaseSuccessful(); } /** Loading @@ -76,7 +74,7 @@ public class SlicePurchaseWebInterface { * This can be called using the JavaScript below: * <script type="text/javascript"> * function notifyPurchaseFailed(failure_code = 0, failure_reason = "unknown") { * SlicePurchaseWebInterface.notifyPurchaseFailed(); * DataBoostWebServiceFlow.notifyPurchaseFailed(); * } * </script> * Loading packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseActivity.java +8 −14 Original line number Diff line number Diff line Loading @@ -32,21 +32,19 @@ import android.webkit.WebView; import com.android.phone.slice.SlicePurchaseController; import java.net.URL; import java.util.concurrent.TimeUnit; /** * Activity that launches when the user clicks on the performance boost notification. * This will open a {@link WebView} for the carrier website to allow the user to complete the * premium capability purchase. * The carrier website can get the requested premium capability using the JavaScript interface * method {@code SlicePurchaseWebInterface.getRequestedCapability()}. * method {@code DataBoostWebServiceFlow.getRequestedCapability()}. * If the purchase is successful, the carrier website shall notify the slice purchase application * using the JavaScript interface method * {@code SlicePurchaseWebInterface.notifyPurchaseSuccessful(duration)}, where {@code duration} is * the optional duration of the performance boost. * {@code DataBoostWebServiceFlow.notifyPurchaseSuccessful()}. * If the purchase was not successful, the carrier website shall notify the slice purchase * application using the JavaScript interface method * {@code SlicePurchaseWebInterface.notifyPurchaseFailed(code, reason)}, where {@code code} is the * {@code DataBoostWebServiceFlow.notifyPurchaseFailed(code, reason)}, where {@code code} is the * {@link SlicePurchaseController.FailureCode} indicating the reason for failure and {@code reason} * is the human-readable reason for failure if the failure code is * {@link SlicePurchaseController#FAILURE_CODE_UNKNOWN}. Loading Loading @@ -118,15 +116,11 @@ public class SlicePurchaseActivity extends Activity { setupWebView(); } protected void onPurchaseSuccessful(long duration) { protected void onPurchaseSuccessful() { logd("onPurchaseSuccessful: Carrier website indicated successfully purchased premium " + "capability " + TelephonyManager.convertPremiumCapabilityToString(mCapability) + (duration > 0 ? " for " + TimeUnit.MILLISECONDS.toMinutes(duration) + " minutes." : ".")); Intent intent = new Intent(); intent.putExtra(SlicePurchaseController.EXTRA_PURCHASE_DURATION, duration); SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponseWithData(mApplicationContext, mIntent, SlicePurchaseController.EXTRA_INTENT_SUCCESS, intent); + "capability " + TelephonyManager.convertPremiumCapabilityToString(mCapability)); SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponse( mIntent, SlicePurchaseController.EXTRA_INTENT_SUCCESS); finishAndRemoveTask(); } Loading Loading @@ -178,7 +172,7 @@ public class SlicePurchaseActivity extends Activity { // the slice purchase application. mWebView.getSettings().setJavaScriptEnabled(true); mWebView.addJavascriptInterface( new SlicePurchaseWebInterface(this), "SlicePurchaseWebInterface"); new DataBoostWebServiceFlow(this), "DataBoostWebServiceFlow"); // Display WebView setContentView(mWebView); Loading packages/CarrierDefaultApp/tests/unit/src/com/android/carrierdefaultapp/SlicePurchaseActivityTest.java +7 −8 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas private static final int PHONE_ID = 0; @Mock PendingIntent mPendingIntent; @Mock PendingIntent mSuccessfulIntent; @Mock PendingIntent mCanceledIntent; @Mock CarrierConfigManager mCarrierConfigManager; @Mock NotificationManager mNotificationManager; Loading Loading @@ -107,20 +108,18 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas doReturn(true).when(mCanceledIntent).isBroadcast(); doReturn(mCanceledIntent).when(spiedIntent).getParcelableExtra( eq(SlicePurchaseController.EXTRA_INTENT_CANCELED), eq(PendingIntent.class)); doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mSuccessfulIntent).getCreatorPackage(); doReturn(true).when(mSuccessfulIntent).isBroadcast(); doReturn(mSuccessfulIntent).when(spiedIntent).getParcelableExtra( eq(SlicePurchaseController.EXTRA_INTENT_SUCCESS), eq(PendingIntent.class)); mSlicePurchaseActivity = startActivity(spiedIntent, null, null); } @Test public void testOnPurchaseSuccessful() throws Exception { int duration = 5 * 60 * 1000; // 5 minutes int invalidDuration = -1; mSlicePurchaseActivity.onPurchaseSuccessful(duration); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mPendingIntent).send(eq(mContext), eq(0), intentCaptor.capture()); Intent intent = intentCaptor.getValue(); assertEquals(duration, intent.getLongExtra( SlicePurchaseController.EXTRA_PURCHASE_DURATION, invalidDuration)); mSlicePurchaseActivity.onPurchaseSuccessful(); verify(mSuccessfulIntent).send(); } @Test Loading Loading
packages/CarrierDefaultApp/assets/slice_purchase_test.html +3 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ <meta charset="UTF-8"> <meta name="description" content=" This is a HTML page that calls and verifies responses from the @JavascriptInterface functions of SlicePurchaseWebInterface. Test slice purchase application behavior using ADB shell commands and DataBoostWebServiceFlow. Test slice purchase application behavior using ADB shell commands and the APIs below: FROM TERMINAL: Loading Loading @@ -65,8 +65,8 @@ <p id="requested_capability"></p> <h2>Notify purchase successful</h2> <button type="button" onclick="testNotifyPurchaseSuccessful(60000)"> Notify purchase successful for 1 minute <button type="button" onclick="testNotifyPurchaseSuccessful()"> Notify purchase successful </button> <p id="purchase_successful"></p> Loading
packages/CarrierDefaultApp/assets/slice_purchase_test.js +5 −5 Original line number Diff line number Diff line Loading @@ -15,19 +15,19 @@ */ function testGetRequestedCapability() { let capability = SlicePurchaseWebInterface.getRequestedCapability(); let capability = DataBoostWebServiceFlow.getRequestedCapability(); document.getElementById("requested_capability").innerHTML = "Premium capability requested: " + capability; } function testNotifyPurchaseSuccessful(duration_ms_long = 0) { SlicePurchaseWebInterface.notifyPurchaseSuccessful(duration_ms_long); function testNotifyPurchaseSuccessful() { DataBoostWebServiceFlow.notifyPurchaseSuccessful(); document.getElementById("purchase_successful").innerHTML = "Notified purchase success for duration: " + duration_ms_long; "Notified purchase successful."; } function testNotifyPurchaseFailed(failure_code = 0, failure_reason = "unknown") { SlicePurchaseWebInterface.notifyPurchaseFailed(failure_code, failure_reason); DataBoostWebServiceFlow.notifyPurchaseFailed(failure_code, failure_reason); document.getElementById("purchase_failed").innerHTML = "Notified purchase failed."; }
packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseWebInterface.java→packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/DataBoostWebServiceFlow.java +9 −11 Original line number Diff line number Diff line Loading @@ -24,13 +24,13 @@ import android.webkit.JavascriptInterface; import com.android.phone.slice.SlicePurchaseController; /** * Slice purchase web interface class allowing carrier websites to send responses back to the * Data boost web service flow interface allowing carrier websites to send responses back to the * slice purchase application using JavaScript. */ public class SlicePurchaseWebInterface { public class DataBoostWebServiceFlow { @NonNull SlicePurchaseActivity mActivity; public SlicePurchaseWebInterface(@NonNull SlicePurchaseActivity activity) { public DataBoostWebServiceFlow(@NonNull SlicePurchaseActivity activity) { mActivity = activity; } Loading @@ -41,7 +41,7 @@ public class SlicePurchaseWebInterface { * This can be called using the JavaScript below: * <script type="text/javascript"> * function getRequestedCapability(duration) { * SlicePurchaseWebInterface.getRequestedCapability(); * DataBoostWebServiceFlow.getRequestedCapability(); * } * </script> */ Loading @@ -57,16 +57,14 @@ public class SlicePurchaseWebInterface { * * This can be called using the JavaScript below: * <script type="text/javascript"> * function notifyPurchaseSuccessful(duration_ms_long = 0) { * SlicePurchaseWebInterface.notifyPurchaseSuccessful(duration_ms_long); * function notifyPurchaseSuccessful() { * DataBoostWebServiceFlow.notifyPurchaseSuccessful(); * } * </script> * * @param duration The duration for which the premium capability is purchased in milliseconds. */ @JavascriptInterface public void notifyPurchaseSuccessful(long duration) { mActivity.onPurchaseSuccessful(duration); public void notifyPurchaseSuccessful() { mActivity.onPurchaseSuccessful(); } /** Loading @@ -76,7 +74,7 @@ public class SlicePurchaseWebInterface { * This can be called using the JavaScript below: * <script type="text/javascript"> * function notifyPurchaseFailed(failure_code = 0, failure_reason = "unknown") { * SlicePurchaseWebInterface.notifyPurchaseFailed(); * DataBoostWebServiceFlow.notifyPurchaseFailed(); * } * </script> * Loading
packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseActivity.java +8 −14 Original line number Diff line number Diff line Loading @@ -32,21 +32,19 @@ import android.webkit.WebView; import com.android.phone.slice.SlicePurchaseController; import java.net.URL; import java.util.concurrent.TimeUnit; /** * Activity that launches when the user clicks on the performance boost notification. * This will open a {@link WebView} for the carrier website to allow the user to complete the * premium capability purchase. * The carrier website can get the requested premium capability using the JavaScript interface * method {@code SlicePurchaseWebInterface.getRequestedCapability()}. * method {@code DataBoostWebServiceFlow.getRequestedCapability()}. * If the purchase is successful, the carrier website shall notify the slice purchase application * using the JavaScript interface method * {@code SlicePurchaseWebInterface.notifyPurchaseSuccessful(duration)}, where {@code duration} is * the optional duration of the performance boost. * {@code DataBoostWebServiceFlow.notifyPurchaseSuccessful()}. * If the purchase was not successful, the carrier website shall notify the slice purchase * application using the JavaScript interface method * {@code SlicePurchaseWebInterface.notifyPurchaseFailed(code, reason)}, where {@code code} is the * {@code DataBoostWebServiceFlow.notifyPurchaseFailed(code, reason)}, where {@code code} is the * {@link SlicePurchaseController.FailureCode} indicating the reason for failure and {@code reason} * is the human-readable reason for failure if the failure code is * {@link SlicePurchaseController#FAILURE_CODE_UNKNOWN}. Loading Loading @@ -118,15 +116,11 @@ public class SlicePurchaseActivity extends Activity { setupWebView(); } protected void onPurchaseSuccessful(long duration) { protected void onPurchaseSuccessful() { logd("onPurchaseSuccessful: Carrier website indicated successfully purchased premium " + "capability " + TelephonyManager.convertPremiumCapabilityToString(mCapability) + (duration > 0 ? " for " + TimeUnit.MILLISECONDS.toMinutes(duration) + " minutes." : ".")); Intent intent = new Intent(); intent.putExtra(SlicePurchaseController.EXTRA_PURCHASE_DURATION, duration); SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponseWithData(mApplicationContext, mIntent, SlicePurchaseController.EXTRA_INTENT_SUCCESS, intent); + "capability " + TelephonyManager.convertPremiumCapabilityToString(mCapability)); SlicePurchaseBroadcastReceiver.sendSlicePurchaseAppResponse( mIntent, SlicePurchaseController.EXTRA_INTENT_SUCCESS); finishAndRemoveTask(); } Loading Loading @@ -178,7 +172,7 @@ public class SlicePurchaseActivity extends Activity { // the slice purchase application. mWebView.getSettings().setJavaScriptEnabled(true); mWebView.addJavascriptInterface( new SlicePurchaseWebInterface(this), "SlicePurchaseWebInterface"); new DataBoostWebServiceFlow(this), "DataBoostWebServiceFlow"); // Display WebView setContentView(mWebView); Loading
packages/CarrierDefaultApp/tests/unit/src/com/android/carrierdefaultapp/SlicePurchaseActivityTest.java +7 −8 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas private static final int PHONE_ID = 0; @Mock PendingIntent mPendingIntent; @Mock PendingIntent mSuccessfulIntent; @Mock PendingIntent mCanceledIntent; @Mock CarrierConfigManager mCarrierConfigManager; @Mock NotificationManager mNotificationManager; Loading Loading @@ -107,20 +108,18 @@ public class SlicePurchaseActivityTest extends ActivityUnitTestCase<SlicePurchas doReturn(true).when(mCanceledIntent).isBroadcast(); doReturn(mCanceledIntent).when(spiedIntent).getParcelableExtra( eq(SlicePurchaseController.EXTRA_INTENT_CANCELED), eq(PendingIntent.class)); doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mSuccessfulIntent).getCreatorPackage(); doReturn(true).when(mSuccessfulIntent).isBroadcast(); doReturn(mSuccessfulIntent).when(spiedIntent).getParcelableExtra( eq(SlicePurchaseController.EXTRA_INTENT_SUCCESS), eq(PendingIntent.class)); mSlicePurchaseActivity = startActivity(spiedIntent, null, null); } @Test public void testOnPurchaseSuccessful() throws Exception { int duration = 5 * 60 * 1000; // 5 minutes int invalidDuration = -1; mSlicePurchaseActivity.onPurchaseSuccessful(duration); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mPendingIntent).send(eq(mContext), eq(0), intentCaptor.capture()); Intent intent = intentCaptor.getValue(); assertEquals(duration, intent.getLongExtra( SlicePurchaseController.EXTRA_PURCHASE_DURATION, invalidDuration)); mSlicePurchaseActivity.onPurchaseSuccessful(); verify(mSuccessfulIntent).send(); } @Test Loading