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

Commit 2ca39364 authored by Sarah Chin's avatar Sarah Chin
Browse files

Add support for network boost purchase, failure, and expiry

Create a JavaScript interface allowing websites to send responses to
SliceStore
Add support for premium capability purchase, failure, and expiry
Create new result for success but pending network setup

Bug: 245882601
Test: manual test response, purchase, expiry, failure
Test: atest TelephonyManagerReadNonDangerousPermissionTest#testPremiumCapabilities
Change-Id: I51fc674f37679fb0eb1314e7b0939555d0767f87
parent 70ec9d52
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41754,6 +41754,7 @@ package android.telephony {
    field public static final String KEY_PING_TEST_BEFORE_DATA_SWITCH_BOOL = "ping_test_before_data_switch_bool";
    field public static final String KEY_PREFER_2G_BOOL = "prefer_2g_bool";
    field public static final String KEY_PREMIUM_CAPABILITY_MAXIMUM_NOTIFICATION_COUNT_INT_ARRAY = "premium_capability_maximum_notification_count_int_array";
    field public static final String KEY_PREMIUM_CAPABILITY_NETWORK_SETUP_TIME_MILLIS_LONG = "premium_capability_network_setup_time_millis_long";
    field public static final String KEY_PREMIUM_CAPABILITY_NOTIFICATION_BACKOFF_HYSTERESIS_TIME_MILLIS_LONG = "premium_capability_notification_backoff_hysteresis_time_millis_long";
    field public static final String KEY_PREMIUM_CAPABILITY_NOTIFICATION_DISPLAY_TIMEOUT_MILLIS_LONG = "premium_capability_notification_display_timeout_millis_long";
    field public static final String KEY_PREMIUM_CAPABILITY_PURCHASE_CONDITION_BACKOFF_HYSTERESIS_TIME_MILLIS_LONG = "premium_capability_purchase_condition_backoff_hysteresis_time_millis_long";
@@ -44048,6 +44049,7 @@ package android.telephony {
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_NETWORK_NOT_AVAILABLE = 12; // 0xc
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_DEFAULT_DATA = 14; // 0xe
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_OVERRIDDEN = 5; // 0x5
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_PENDING_NETWORK_SETUP = 15; // 0xf
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED = 11; // 0xb
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_SUCCESS = 1; // 0x1
    field public static final int PURCHASE_PREMIUM_CAPABILITY_RESULT_THROTTLED = 2; // 0x2
+5 −0
Original line number Diff line number Diff line
@@ -13,4 +13,9 @@ android_app {
    libs: ["SliceStore"],
    platform_apis: true,
    certificate: "platform",
    optimize: {
        proguard_flags_files: [
            "proguard.flags",
        ],
    },
}
+78 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="description" content="
    This is a HTML page that calls and verifies responses from the @JavascriptInterface functions of
    SliceStoreWebInterface. Test SliceStore APIs using ADB shell commands and the APIs below:

    FROM TERMINAL:
    Allow device to override carrier configs:
    $ adb root
    Set PREMIUM_CAPABILITY_PRIORITIZE_LATENCY enabled:
    $ adb shell cmd phone cc set-value -p supported_premium_capabilities_int_array 34
    Set the carrier purchase URL to this test HTML file:
    $ adb shell cmd phone cc set-value -p premium_capability_purchase_url_string \
      file:///android_asset/slice_store_test.html
    OPTIONAL: Allow premium capability purchase on LTE:
    $ adb shell cmd phone cc set-value -p premium_capability_supported_on_lte_bool true
    OPTIONAL: Override ServiceState to fake a NR SA connection:
    $ adb shell am broadcast -a com.android.internal.telephony.TestServiceState --ei data_rat 20

    FROM TEST ACTIVITY:
    TelephonyManager tm = getApplicationContext().getSystemService(TelephonyManager.class)
    tm.isPremiumCapabilityAvailable(TelephonyManager.PREMIUM_CAPABILITY_PRIORITIZE_LATENCY);
    LinkedBlockingQueue<Integer> purchaseRequests = new LinkedBlockingQueue<>();
    tm.purchasePremiumCapability(TelephonyManager.PREMIUM_CAPABILITY_PRIORITIZE_LATENCY,
            this.getMainExecutor(), request::offer);

    When the test application starts, this HTML will be loaded into the WebView along with the
    associated JavaScript functions in file:///android_asset/slice_store_test.js.
    Click on the buttons in the HTML to call the corresponding @JavascriptInterface APIs.

    RESET DEVICE STATE:
    Clear carrier configurations that were set:
    $ adb shell cmd phone cc clear-values
    Clear ServiceState override that was set:
    $ adb shell am broadcast -a com.android.internal.telephony.TestServiceState --es action reset
    ">
    <title>Test SliceStoreActivity</title>
    <script type="text/javascript" src="slice_store_test.js"></script>
</head>
<body>
    <h1>Test SliceStoreActivity</h1>
    <h2>Get requested premium capability</h2>
    <button type="button" onclick="testGetRequestedCapability()">
        Get requested premium capability
    </button>
    <p id="requested_capability"></p>

    <h2>Notify purchase successful</h2>
    <button type="button" onclick="testNotifyPurchaseSuccessful(60000)">
        Notify purchase successful for 1 minute
    </button>
    <p id="purchase_successful"></p>

    <h2>Notify purchase failed</h2>
    <button type="button" onclick="testNotifyPurchaseFailed()">
        Notify purchase failed
    </button>
    <p id="purchase_failed"></p>
</body>
</html>
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function testGetRequestedCapability() {
    let capability = SliceStoreWebInterface.getRequestedCapability();
    document.getElementById("requested_capability").innerHTML =
            "Premium capability requested: " + capability;
}

function testNotifyPurchaseSuccessful(duration_ms_long = 0) {
    SliceStoreWebInterface.notifyPurchaseSuccessful(duration);
    document.getElementById("purchase_successful").innerHTML =
            "Notified purchase success for duration: " + duration;
}

function testNotifyPurchaseFailed() {
    SliceStoreWebInterface.notifyPurchaseFailed();
    document.getElementById("purchase_failed").innerHTML =
            "Notified purchase failed.";
}
+4 −0
Original line number Diff line number Diff line
# Keep classes and methods that have the @JavascriptInterface annotation
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}
Loading