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

Commit b6105c72 authored by Sarah Chin's avatar Sarah Chin
Browse files

Add support for daily and monthly notification maximums

Slice purchase app notifies SlicePurchaseController when a notification
is shown to the user.
If the daily or monthly limit has been reached, return result throttled.

Test: atest TeleServiceTests, CarrierDefaultAppUnitTests
Bug: 248533515
Change-Id: I99cb6ea2ae9bfb85b630810b9f4bf42b1692231d
parent 27c37b94
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -175,7 +175,9 @@ public class SlicePurchaseBroadcastReceiver extends BroadcastReceiver{
                && isPendingIntentValid(intent, SlicePurchaseController.EXTRA_INTENT_REQUEST_FAILED)
                && isPendingIntentValid(intent,
                        SlicePurchaseController.EXTRA_INTENT_NOT_DEFAULT_DATA_SUBSCRIPTION)
                && isPendingIntentValid(intent, SlicePurchaseController.EXTRA_INTENT_SUCCESS);
                && isPendingIntentValid(intent, SlicePurchaseController.EXTRA_INTENT_SUCCESS)
                && isPendingIntentValid(intent,
                        SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN);
    }

    private static boolean isPendingIntentValid(@NonNull Intent intent, @NonNull String extra) {
@@ -208,6 +210,8 @@ public class SlicePurchaseBroadcastReceiver extends BroadcastReceiver{
            case SlicePurchaseController.EXTRA_INTENT_NOT_DEFAULT_DATA_SUBSCRIPTION:
                return "not default data subscription";
            case SlicePurchaseController.EXTRA_INTENT_SUCCESS: return "success";
            case SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN:
                return "notification shown";
            default: {
                loge("Unknown pending intent extra: " + extra);
                return "unknown(" + extra + ")";
@@ -220,7 +224,7 @@ public class SlicePurchaseBroadcastReceiver extends BroadcastReceiver{
        logd("onReceive intent: " + intent.getAction());
        switch (intent.getAction()) {
            case SlicePurchaseController.ACTION_START_SLICE_PURCHASE_APP:
                onDisplayBoosterNotification(context, intent);
                onDisplayNetworkBoostNotification(context, intent);
                break;
            case SlicePurchaseController.ACTION_SLICE_PURCHASE_APP_RESPONSE_TIMEOUT:
                onTimeout(context, intent);
@@ -233,7 +237,8 @@ public class SlicePurchaseBroadcastReceiver extends BroadcastReceiver{
        }
    }

    private void onDisplayBoosterNotification(@NonNull Context context, @NonNull Intent intent) {
    private void onDisplayNetworkBoostNotification(@NonNull Context context,
            @NonNull Intent intent) {
        if (!isIntentValid(intent)) {
            sendSlicePurchaseAppResponse(intent,
                    SlicePurchaseController.EXTRA_INTENT_REQUEST_FAILED);
@@ -280,10 +285,12 @@ public class SlicePurchaseBroadcastReceiver extends BroadcastReceiver{

        int capability = intent.getIntExtra(SlicePurchaseController.EXTRA_PREMIUM_CAPABILITY,
                SlicePurchaseController.PREMIUM_CAPABILITY_INVALID);
        logd("Display the booster notification for capability "
        logd("Display the network boost notification for capability "
                + TelephonyManager.convertPremiumCapabilityToString(capability));
        context.getSystemService(NotificationManager.class).notifyAsUser(
                NETWORK_BOOST_NOTIFICATION_TAG, capability, notification, UserHandle.ALL);
        sendSlicePurchaseAppResponse(intent,
                SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN);
    }

    /**
@@ -338,7 +345,7 @@ public class SlicePurchaseBroadcastReceiver extends BroadcastReceiver{
                + " timed out.");
        if (sSlicePurchaseActivities.get(capability) == null) {
            // Notification is still active
            logd("Closing booster notification since the user did not respond in time.");
            logd("Closing network boost notification since the user did not respond in time.");
            context.getSystemService(NotificationManager.class).cancelAsUser(
                    NETWORK_BOOST_NOTIFICATION_TAG, capability, UserHandle.ALL);
        } else {
+12 −3
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ public class SlicePurchaseBroadcastReceiverTest {
    @Mock PendingIntent mCanceledIntent;
    @Mock PendingIntent mContentIntent1;
    @Mock PendingIntent mContentIntent2;
    @Mock PendingIntent mNotificationShownIntent;
    @Mock Context mContext;
    @Mock Resources mResources;
    @Mock NotificationManager mNotificationManager;
@@ -136,7 +137,7 @@ public class SlicePurchaseBroadcastReceiverTest {
    }

    @Test
    public void testDisplayBoosterNotification() {
    public void testDisplayNetworkBoostNotification() throws Exception {
        // set up intent
        doReturn(SlicePurchaseController.ACTION_START_SLICE_PURCHASE_APP).when(mIntent).getAction();
        doReturn(PHONE_ID).when(mIntent).getIntExtra(
@@ -148,11 +149,17 @@ public class SlicePurchaseBroadcastReceiverTest {
        doReturn(TAG).when(mIntent).getStringExtra(
                eq(SlicePurchaseController.EXTRA_REQUESTING_APP_NAME));

        // set up pending intent
        // set up pending intents
        doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mPendingIntent).getCreatorPackage();
        doReturn(true).when(mPendingIntent).isBroadcast();
        doReturn(mPendingIntent).when(mIntent).getParcelableExtra(
                anyString(), eq(PendingIntent.class));
        doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mNotificationShownIntent)
                .getCreatorPackage();
        doReturn(true).when(mNotificationShownIntent).isBroadcast();
        doReturn(mNotificationShownIntent).when(mIntent).getParcelableExtra(
                eq(SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN),
                eq(PendingIntent.class));

        // set up notification
        doReturn(mResources).when(mContext).getResources();
@@ -185,8 +192,10 @@ public class SlicePurchaseBroadcastReceiverTest {
        assertEquals(2, notification.actions.length);
        assertEquals(mCanceledIntent, notification.actions[0].actionIntent);
        assertEquals(mContentIntent2, notification.actions[1].actionIntent);
    }

        // verify SlicePurchaseController was notified
        verify(mNotificationShownIntent).send();
    }

    @Test
    public void testNotificationCanceled() {