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

Commit 35d773f0 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Send sms to DatagramDispatcher only after checking all conditions

Send P2P SMS to DatagramDispatcher if all of the following conditions are met:
- Device is in carrier roaming nb iot ntn mode
- Device is not in demo mode
- Carrier supports P2P SMS.

Start P2P SMS inactivity timer, Screen off timer if all of the following
conditions are met:
- Device supports P2P SMS
- Carrier has P2P SMS service when it is connected to carrier roaming
  ntn.

Bug: 377028534
Test: atest SmsDispatchersControllerTest, atest
SatelliteSessionControllerTest, atest SatelliteControllerTest
Test: Manlly tested SMS/MMS/CALLS/DATA
FLAG: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn

Change-Id: Icadb1422ecacc204f6694e60870d03ab80618a87
parent 076b637f
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Binder;
@@ -46,13 +45,14 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.satellite.SatelliteManager;
import android.text.TextUtils;

import com.android.ims.ImsManager;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.SomeArgs;
import com.android.internal.telephony.cdma.CdmaInboundSmsHandler;
@@ -67,18 +67,17 @@ import com.android.internal.telephony.gsm.GsmInboundSmsHandler;
import com.android.internal.telephony.gsm.GsmSMSDispatcher;
import com.android.internal.telephony.satellite.DatagramDispatcher;
import com.android.internal.telephony.satellite.SatelliteController;
import com.android.internal.R;
import com.android.telephony.Rlog;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;

/**
 *
@@ -1258,7 +1257,7 @@ public class SmsDispatchersController extends Handler {
    }

    private void notifySmsSentToDatagramDispatcher(long messageId, boolean success) {
        if (SatelliteController.getInstance().isInCarrierRoamingNbIotNtn(mPhone)) {
        if (SatelliteController.getInstance().shouldSendSmsToDatagramDispatcher(mPhone)) {
            DatagramDispatcher.getInstance().onSendSmsDone(mPhone.getSubId(), messageId, success);
        }
    }
@@ -1866,7 +1865,7 @@ public class SmsDispatchersController extends Handler {
                messageUri, persistMessage, priority, expectMore, validityPeriod, messageId,
                skipShortCodeCheck, false);

        if (SatelliteController.getInstance().isInCarrierRoamingNbIotNtn(mPhone)) {
        if (SatelliteController.getInstance().shouldSendSmsToDatagramDispatcher(mPhone)) {
            // Send P2P SMS using carrier roaming NB IOT NTN
            DatagramDispatcher.getInstance().sendSms(pendingRequest);
            return;
@@ -2031,7 +2030,7 @@ public class SmsDispatchersController extends Handler {
                null, 0, parts, messageUri, persistMessage, priority, expectMore,
                validityPeriod, messageId, false, false);

        if (SatelliteController.getInstance().isInCarrierRoamingNbIotNtn(mPhone)) {
        if (SatelliteController.getInstance().shouldSendSmsToDatagramDispatcher(mPhone)) {
            // Send multipart P2P SMS using carrier roaming NB IOT NTN
            DatagramDispatcher.getInstance().sendSms(pendingRequest);
            return;
@@ -2241,7 +2240,7 @@ public class SmsDispatchersController extends Handler {
     * to trigger SMSC to send all pending SMS to the particular subscription.
     */
    public void sendMtSmsPollingMessage() {
        if (!SatelliteController.getInstance().isInCarrierRoamingNbIotNtn(mPhone)) {
        if (!SatelliteController.getInstance().shouldSendSmsToDatagramDispatcher(mPhone)) {
            logd("sendMtSmsPollingMessage: not in roaming nb iot ntn");
            return;
        }
@@ -2268,8 +2267,10 @@ public class SmsDispatchersController extends Handler {
                asArrayList(null), false, null, 0, asArrayList(mtSmsPollingText), null, false, 0,
                false, 5, 0L, true, true);

        if (SatelliteController.getInstance().shouldSendSmsToDatagramDispatcher(mPhone)) {
            DatagramDispatcher.getInstance().sendSms(pendingRequest);
        }
    }

    public interface SmsInjectionCallback {
        void onSmsInjectedResult(int result);
+38 −8
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ import com.android.internal.telephony.satellite.metrics.ProvisionMetricsStats;
import com.android.internal.telephony.satellite.metrics.SessionMetricsStats;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.telephony.util.ArrayUtils;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.internal.util.FunctionalUtils;

@@ -3830,7 +3831,7 @@ public class SatelliteController extends Handler {
     * @return {@code true} if phone is in carrier roaming nb iot ntn mode,
     * else {@return false}
     */
    public boolean isInCarrierRoamingNbIotNtn(@NonNull Phone phone) {
    private boolean isInCarrierRoamingNbIotNtn(@NonNull Phone phone) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("isInCarrierRoamingNbIotNtn: carrier roaming nb iot ntn "
                    + "feature flag is disabled");
@@ -3848,6 +3849,14 @@ public class SatelliteController extends Handler {
                      + " is not carrier roaming ntn eligible.");
            return false;
        }

        int subId = phone.getSubId();
        if (subId != getSelectedSatelliteSubId()) {
            plogd("isInCarrierRoamingNbIotNtn: subId=" + subId
                    + " does not match satellite subId=" + getSelectedSatelliteSubId());
            return false;
        }

        plogd("isInCarrierRoamingNbIotNtn: carrier roaming ntn eligible for phone"
                  + " associated with subId " + phone.getSubId());
        return true;
@@ -7054,8 +7063,9 @@ public class SatelliteController extends Handler {
            return false;
        }

        if (!isSatelliteServiceSupportedByCarrier(subId,
                NetworkRegistrationInfo.SERVICE_TYPE_SMS)) {

        int[] services = getSupportedServicesOnCarrierRoamingNtn(subId);
        if (!ArrayUtils.contains(services, NetworkRegistrationInfo.SERVICE_TYPE_SMS)) {
            plogd("isCarrierRoamingNtnEligible[phoneId=" + phone.getPhoneId()
                    + "]: SMS is not supported by carrier");
            return false;
@@ -7475,25 +7485,30 @@ public class SatelliteController extends Handler {
            return;
        }
        plogd("updateLastNotifiedNtnAvailableServicesAndNotify: phoneId= " + phone.getPhoneId());
        int[] services = getSupportedServicesOnCarrierRoamingNtn(subId);
        phone.notifyCarrierRoamingNtnAvailableServicesChanged(services);
    }

    /** Return services that are supported on carrier roaming non-terrestrial network. */
    public int[] getSupportedServicesOnCarrierRoamingNtn(int subId) {
        SatelliteManager satelliteManager = mContext.getSystemService(SatelliteManager.class);
        if (satelliteManager == null) {
            plogd("updateLastNotifiedNtnAvailableServicesAndNotify: satelliteManager is null");
            phone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]);
            return;
            return new int[0];
        }

        List<Integer> satelliteDisallowedReasons = satelliteManager.getSatelliteDisallowedReasons();
        if (isSatelliteSupportedViaCarrier(subId)
                && (satelliteDisallowedReasons != null && !satelliteDisallowedReasons.isEmpty())) {
            // TODO: b/377367448 Cleanup get supported satellite services to align with starlink.
            int[] services = getSupportedSatelliteServicesForCarrier(subId);
            if (isP2PSmsDisallowedOnCarrierRoamingNtn(subId)) {
                services = Arrays.stream(services).filter(
                        value -> value != NetworkRegistrationInfo.SERVICE_TYPE_SMS).toArray();
            }
            phone.notifyCarrierRoamingNtnAvailableServicesChanged(services);
        } else {
            phone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]);
            return services;
        }
        return new int[0];
    }

    /**
@@ -7575,6 +7590,7 @@ public class SatelliteController extends Handler {
                mContext.RECEIVER_EXPORTED);
    }


    private void notifyEnabledStateChanged(boolean isEnabled) {
        TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class);
        if (trm == null) {
@@ -7585,4 +7601,18 @@ public class SatelliteController extends Handler {
        trm.notifySatelliteStateChanged(isEnabled);
        logd("notifyEnabledStateChanged to " + isEnabled);
    }

    /** Returns whether to send SMS to DatagramDispatcher or not. */
    public boolean shouldSendSmsToDatagramDispatcher(@NonNull Phone phone) {
        if (!isInCarrierRoamingNbIotNtn(phone)) {
            return false;
        }

        if (isDemoModeEnabled()) {
            return false;
        }

        int[] services = getSupportedServicesOnCarrierRoamingNtn(phone.getSubId());
        return ArrayUtils.contains(services, NetworkRegistrationInfo.SERVICE_TYPE_SMS);
    }
}
+33 −6
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.WorkSource;
import android.telephony.DropBoxManagerLoggerBackend;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PersistentLogger;
import android.telephony.ServiceState;
import android.telephony.satellite.ISatelliteModemStateCallback;
@@ -76,6 +77,7 @@ import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.flags.FeatureFlags;
import com.android.internal.telephony.satellite.metrics.SessionMetricsStats;
import com.android.internal.telephony.util.ArrayUtils;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.telephony.Rlog;
@@ -1680,6 +1682,12 @@ public class SatelliteSessionController extends StateMachine {
            return;
        }

        int subId = getSubId();
        if (!isP2pSmsSupportedOnCarrierRoamingNtn(subId)) {
            if (DBG) plogd("handleEventScreenStateChanged: P2P_SMS is not supported");
            return;
        }

        if (!screenOn) {
            // Screen off, start timer
            int timeoutMillis = getScreenOffInactivityTimeoutDurationSec() * 1000;
@@ -1791,19 +1799,19 @@ public class SatelliteSessionController extends StateMachine {
        }

        if (isP2pSmsInActivityTimerStarted()) {
            plogd("isEsosInActivityTimerStarted: "
            plogd("isP2pSmsInActivityTimerStarted: "
                    + "P2P_SMS inactivity timer already started");
            return;
        }

        int subId = getSubId();
        if (!mSatelliteController.isSatelliteRoamingP2pSmSSupported(subId)) {
            plogd("evaluateStartingEsosInactivityTimer: P2P_SMS is not supported");
        if (!isP2pSmsSupportedOnCarrierRoamingNtn(subId)) {
            if (DBG) plogd("evaluateStartingP2pSmsInactivityTimer: P2P_SMS is not supported");
            return;
        }

        if (mIsDeviceAlignedWithSatellite) {
            plogd("evaluateStartingEsosInactivityTimer: "
            plogd("evaluateStartingP2pSmsInactivityTimer: "
                    + "can't start P2P_SMS inactivity timer due to device aligned satellite");
            return;
        }
@@ -1813,10 +1821,10 @@ public class SatelliteSessionController extends StateMachine {
        if (datagramController.isSendingInIdleState()
                && datagramController.isPollingInIdleState()) {
            sendMessageDelayed(EVENT_P2P_SMS_INACTIVITY_TIMER_TIMED_OUT, timeOutMillis);
            plogd("evaluateStartingEsosInactivityTimer: start P2P_SMS inactivity timer "
            plogd("evaluateStartingP2pSmsInactivityTimer: start P2P_SMS inactivity timer "
                    + timeOutMillis);
        } else {
            plogd("evaluateStartingEsosInactivityTimer: "
            plogd("evaluateStartingP2pSmsInactivityTimer: "
                    + "can't start P2P_SMS inactivity timer");
        }
    }
@@ -1938,6 +1946,25 @@ public class SatelliteSessionController extends StateMachine {
        return true;
    }

    private boolean isP2pSmsSupportedOnCarrierRoamingNtn(int subId) {
        if (!mSatelliteController.isSatelliteRoamingP2pSmSSupported(subId)) {
            if (DBG) plogd("isP2pSmsSupportedOnCarrierRoamingNtn: P2P_SMS is not supported");
            return false;
        }

        int[] services = mSatelliteController.getSupportedServicesOnCarrierRoamingNtn(subId);
        if (!ArrayUtils.contains(services, NetworkRegistrationInfo.SERVICE_TYPE_SMS)) {
            if (DBG) {
                plogd("isP2pSmsSupportedOnCarrierRoamingNtn: P2P_SMS service is not supported "
                        + "on carrier roaming ntn.");
            }
            return false;
        }

        if (DBG) plogd("isP2pSmsSupportedOnCarrierRoamingNtn: P2_SMS is supported");
        return true;
    }

    private boolean isSatellitePersistentLoggingEnabled(
            @NonNull Context context, @NonNull FeatureFlags featureFlags) {
        if (featureFlags.satellitePersistentLogging()) {
+2 −1
Original line number Diff line number Diff line
@@ -1086,7 +1086,8 @@ public class SmsDispatchersControllerTest extends TelephonyTest {

    @Test
    public void testSendSmsToDatagramDispatcher() {
        when(mSatelliteController.isInCarrierRoamingNbIotNtn(any(Phone.class))).thenReturn(true);
        when(mSatelliteController.shouldSendSmsToDatagramDispatcher(any(Phone.class)))
                .thenReturn(true);
        mSmsDispatchersController.sendText("1111", "2222", "text", mSentIntent, null, null,
                "test-app", mCallingUserId, false, 0, false, 10, false, 1L, false);
        processAllMessages();
+14 −0
Original line number Diff line number Diff line
@@ -4089,6 +4089,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);
        when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        mSatelliteControllerUT.mIsApplicationSupportsP2P = true;
        mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true);
        mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 1);
        mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL, true);
@@ -4147,6 +4148,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);
        when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        mSatelliteControllerUT.mIsApplicationSupportsP2P = true;
        mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true);
        mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, 1);
        mCarrierConfigBundle.putInt(
@@ -5737,6 +5739,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        public static boolean isApplicationUpdated;
        public String packageName = "com.example.app";
        public boolean isSatelliteBeingDisabled = false;
        public boolean mIsApplicationSupportsP2P = false;

        TestSatelliteController(
                Context context, Looper looper, @NonNull FeatureFlags featureFlags) {
@@ -5832,6 +5835,17 @@ public class SatelliteControllerTest extends TelephonyTest {
            isApplicationUpdated = true;
        }

        @Override
        public boolean isApplicationSupportsP2P(String packageName) {
            return mIsApplicationSupportsP2P;
        }

        @Override
        public int[] getSupportedServicesOnCarrierRoamingNtn(int subId) {
            return new int[]{3, 5};
        }


        void setSatelliteProvisioned(@Nullable Boolean isProvisioned) {
            synchronized (mDeviceProvisionLock) {
                mIsDeviceProvisioned = isProvisioned;
Loading