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

Commit 14da7d6b authored by Ling Ma's avatar Ling Ma
Browse files

Add manual connect notification

Add a notification to notify user to use satellite.

Fix: 350397109
Test: manual produce, cancel, and override the notification
Test: basic voice call + data browsing
Test: unit test
Flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn

Change-Id: I51b31814133643bed7c624a8e1f85f29dd7f4676
parent 3ce6d435
Loading
Loading
Loading
Loading
+47 −11
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.satellite;

import static android.provider.Settings.ACTION_SATELLITE_SETTING;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_SATELLITE_DEFAULT_SERVICES_INT_ARRAY;
@@ -4616,7 +4617,6 @@ public class SatelliteController extends Handler {
    private void handleEventServiceStateChanged() {
        handleStateChangedForCarrierRoamingNtnEligibility();
        handleServiceStateForSatelliteConnectionViaCarrier();
        determineSystemNotification();
    }

    private void handleServiceStateForSatelliteConnectionViaCarrier() {
@@ -4677,6 +4677,7 @@ public class SatelliteController extends Handler {
                updateLastNotifiedNtnModeAndNotify(phone);
            }
        }
        determineAutoConnectSystemNotification();
    }

    private void updateLastNotifiedNtnModeAndNotify(@Nullable Phone phone) {
@@ -4804,6 +4805,9 @@ public class SatelliteController extends Handler {
                    || mLastNotifiedNtnEligibility != currentNtnEligibility) {
                mLastNotifiedNtnEligibility = currentNtnEligibility;
                mSatellitePhone.notifyCarrierRoamingNtnEligibleStateChanged(currentNtnEligibility);
                updateSatelliteSystemNotification(mSatellitePhone.getSubId(),
                        CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL,
                        currentNtnEligibility);
            }
        }
    }
@@ -5069,7 +5073,7 @@ public class SatelliteController extends Handler {
        return true;
    }

    private void determineSystemNotification() {
    private void determineAutoConnectSystemNotification() {
        if (!mFeatureFlags.carrierEnabledSatelliteFlag()) {
            logd("determineSystemNotification: carrierEnabledSatelliteFlag is disabled");
            return;
@@ -5090,15 +5094,32 @@ public class SatelliteController extends Handler {
                return;
            }
            if (!mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)) {
                showSatelliteSystemNotification(isNtn.second);
                updateSatelliteSystemNotification(isNtn.second,
                        CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC,
                        /*visible*/ true);
                mSharedPreferences.edit().putBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY,
                        true).apply();
            }
        }
    }

    private void showSatelliteSystemNotification(int subId) {
        plogd("showSatelliteSystemNotification");
    /**
     * Update the system notification to reflect the current satellite status, that's either already
     * connected OR needs to be manually enabled. The device should only display one notification
     * at a time to prevent confusing the user, so the same NOTIFICATION_CHANNEL and NOTIFICATION_ID
     * are used.
     *
     * @param subId The subId that provides the satellite connection.
     * @param carrierRoamingNtnConnectType {@link CarrierConfigManager
     * .CARRIER_ROAMING_NTN_CONNECT_TYPE}
     * @param visible {@code true} to show the notification, {@code false} to cancel it.
     */
    private void updateSatelliteSystemNotification(int subId,
            @CARRIER_ROAMING_NTN_CONNECT_TYPE int carrierRoamingNtnConnectType, boolean visible) {
        plogd("updateSatelliteSystemNotification subId=" + subId
                + ", carrierRoamingNtnConnectType=" + SatelliteServiceUtils
                .carrierRoamingNtnConnectTypeToString(carrierRoamingNtnConnectType)
                + ", visible=" + visible);
        final NotificationChannel notificationChannel = new NotificationChannel(
                NOTIFICATION_CHANNEL_ID,
                NOTIFICATION_CHANNEL,
@@ -5107,15 +5128,30 @@ public class SatelliteController extends Handler {
        notificationChannel.setSound(null, null);
        NotificationManager notificationManager = mContext.getSystemService(
                NotificationManager.class);
        if (notificationManager == null) {
            ploge("updateSatelliteSystemNotification: notificationManager is null");
            return;
        }
        if (!visible) { // Cancel if any.
            notificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, UserHandle.ALL);
            return;
        }
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builder notificationBuilder = new Notification.Builder(mContext)
                .setContentTitle(mContext.getResources().getString(
                        R.string.satellite_notification_title))
                .setContentText(mContext.getResources().getString(
                        R.string.satellite_notification_summary))
        // if carrierRoamingNtnConnectType is CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC
        int title = R.string.satellite_notification_title;
        int summary = R.string.satellite_notification_summary;
        if (carrierRoamingNtnConnectType
                == CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL) {
            title = R.string.satellite_notification_manual_title;
            summary = R.string.satellite_notification_manual_summary;
        }

        Notification.Builder notificationBuilder = new Notification.Builder(mContext,
                NOTIFICATION_CHANNEL_ID)
                .setContentTitle(mContext.getResources().getString(title))
                .setContentText(mContext.getResources().getString(summary))
                .setSmallIcon(R.drawable.ic_android_satellite_24px)
                .setChannelId(NOTIFICATION_CHANNEL_ID)
                .setAutoCancel(true)
                .setColor(mContext.getColor(
                        com.android.internal.R.color.system_notification_accent_color))
+16 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.AsyncResult;
import android.os.Binder;
import android.os.PersistableBundle;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
import android.telephony.CellIdentity;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.Rlog;
@@ -63,6 +64,21 @@ import java.util.stream.Collectors;
public class SatelliteServiceUtils {
    private static final String TAG = "SatelliteServiceUtils";

    /**
     * Converts a carrier roaming NTN (Non-Terrestrial Network) connect type constant
     * from {@link CarrierConfigManager} to string.
     * @param type The carrier roaming NTN connect type constant.
     * @return A string representation of the connect type, or "Unknown(type)" if not recognized.
     */
    public static String carrierRoamingNtnConnectTypeToString(
            @CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE int type) {
        return switch (type) {
            case CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC -> "AUTOMATIC";
            case CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL -> "MANUAL";
            default -> "Unknown(" + type + ")";
        };
    }

    /**
     * Convert radio technology from service definition to framework definition.
     * @param radioTechnology The NTRadioTechnology from the satellite service.
+7 −5
Original line number Diff line number Diff line
@@ -3394,14 +3394,13 @@ public class SatelliteControllerTest extends TelephonyTest {
    }

    @Test
    public void testHandleEventServiceStateChanged() throws Exception {
    public void testHandleEventServiceStateChanged() {
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);
        // Do nothing when the satellite is not connected
        doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork();
        sendServiceStateChangedEvent();
        processAllMessages();
        assertEquals(false,
                mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false));
        assertFalse(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false));
        verify(mMockNotificationManager, never()).notifyAsUser(anyString(), anyInt(), any(), any());

        // Check sending a system notification when the satellite is connected
@@ -3410,8 +3409,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        processAllMessages();
        verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(),
                any());
        assertEquals(true,
                mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false));
        assertTrue(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false));

        // Check don't display again after displayed already a system notification.
        sendServiceStateChangedEvent();
@@ -3904,6 +3902,8 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
        verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
        verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());
        verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(),
                any());
        clearInvocations(mPhone);

        when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
@@ -3935,6 +3935,8 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
        verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
        verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());
        verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), anyInt(),
                any());
    }

    @Test