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