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

Commit e63a50fe authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Block premium SMS in satellite mode.

Bug: 395930717
Test: atest SatelliteManagerTestOnMockService
Test: 402193100
Flag: EXEMPT bugfix
Change-Id: Ibd2fb263efe91f172b0cb200ae5c34ae1914b6de
parent 06456c32
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.service.carrier.CarrierMessagingServiceWrapper;
import android.service.carrier.CarrierMessagingServiceWrapper.CarrierMessagingCallback;
import android.telephony.AnomalyReporter;
import android.telephony.CarrierConfigManager;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.telephony.SmsManager;
@@ -90,9 +91,11 @@ import com.android.internal.telephony.analytics.TelephonyAnalytics;
import com.android.internal.telephony.analytics.TelephonyAnalytics.SmsMmsAnalytics;
import com.android.internal.telephony.cdma.sms.UserData;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.satellite.SatelliteController;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.util.ArrayUtils;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

@@ -2226,6 +2229,7 @@ public abstract class SMSDispatcher extends Handler {
        if (mContext.checkCallingOrSelfPermission(SEND_SMS_NO_CONFIRMATION)
                == PackageManager.PERMISSION_GRANTED || trackers[0].mIsForVvm
                || trackers[0].mSkipShortCodeDestAddrCheck) {
            Rlog.d(TAG, "checkDestination: app pre-approved");
            return true;            // app is pre-approved to send to short codes
        } else {
            int rule = mPremiumSmsRule.get();
@@ -2245,6 +2249,7 @@ public abstract class SMSDispatcher extends Handler {
                        mSmsDispatchersController
                                .getUsageMonitor()
                                .checkDestination(trackers[0].mDestAddress, simCountryIso);
                Rlog.d(TAG, "checkDestination: simCountryIso=" + simCountryIso);
            }
            if (rule == PREMIUM_RULE_USE_NETWORK || rule == PREMIUM_RULE_USE_BOTH) {
                String networkCountryIso =
@@ -2264,7 +2269,9 @@ public abstract class SMSDispatcher extends Handler {
                                        .getUsageMonitor()
                                        .checkDestination(
                                                trackers[0].mDestAddress, networkCountryIso));
                Rlog.d(TAG, "checkDestination: networkCountryIso=" + networkCountryIso);
            }
            Rlog.d(TAG, "checkDestination: smsCategory=" + smsCategory);

            if (smsCategory != SmsManager.SMS_CATEGORY_NOT_SHORT_CODE) {
                int xmlVersion = mSmsDispatchersController.getUsageMonitor()
@@ -2286,6 +2293,14 @@ public abstract class SMSDispatcher extends Handler {
                return false;
            }

            // Check whether to block premium sms in satellite mode.
            if (shouldBlockPremiumSmsInSatelliteMode()) {
                Rlog.d(TAG, "Block premium SMS in satellite mode."
                        + " messageId=" + SmsController.formatCrossStackMessageId(
                                getMultiTrackermessageId(trackers)));
                return false;
            }

            // Wait for user confirmation unless the user has set permission to always allow/deny
            int premiumSmsPermission =
                    mSmsDispatchersController
@@ -2325,6 +2340,32 @@ public abstract class SMSDispatcher extends Handler {
        }
    }

    /** Block premium sms in satellite mode. */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public boolean shouldBlockPremiumSmsInSatelliteMode() {
        SatelliteController sc = SatelliteController.getInstance();

        if (sc.isSatelliteBeingEnabled()) {
            Rlog.d(TAG, "shouldBlockPremiumSmsInSatelliteMode: block premium sms when "
                    + "satellite is being enabled");
            return true;
        }

        if (sc.isSatelliteEnabled()) {
            int satelliteSubId = sc.getSelectedSatelliteSubId();
            int[] services = sc.getSupportedServicesOnCarrierRoamingNtn(satelliteSubId);
            boolean isSmsSupported = ArrayUtils.contains(
                    services, NetworkRegistrationInfo.SERVICE_TYPE_SMS);
            Rlog.d(TAG, "shouldBlockPremiumSmsInSatelliteMode: satelliteSubId="
                    + satelliteSubId + " isSmsSupported=" + isSmsSupported
                    + " services=" + Arrays.toString(services));
            return !isSmsSupported;
        }

        Rlog.d(TAG, "shouldBlockPremiumSmsInSatelliteMode: return false.");
        return false;
    }

    /**
     * Deny sending a single or a multi-part SMS if the outgoing queue limit is reached. Used when
     * the message must be confirmed by the user due to excessive usage or potential premium SMS
+2 −2
Original line number Diff line number Diff line
@@ -2627,7 +2627,7 @@ public class SatelliteController extends Handler {
     *
     * @return {@code true} if the satellite modem is enabled and {@code false} otherwise.
     */
    private boolean isSatelliteEnabled() {
    public boolean isSatelliteEnabled() {
        synchronized (mIsSatelliteEnabledLock) {
            if (mIsSatelliteEnabled == null) return false;
            return mIsSatelliteEnabled;
@@ -2639,7 +2639,7 @@ public class SatelliteController extends Handler {
     *
     * @return {@code true} if the satellite modem is being enabled and {@code false} otherwise.
     */
    private boolean isSatelliteBeingEnabled() {
    public boolean isSatelliteBeingEnabled() {
        if (mSatelliteSessionController != null
                && mSatelliteSessionController.isInEnablingState()) {
            return true;
+29 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.content.IntentFilter;
import android.content.pm.ServiceInfo;
import android.location.Country;
import android.location.CountryDetector;
import android.net.Uri;
import android.os.Binder;
import android.os.HandlerThread;
import android.os.Message;
@@ -56,6 +55,7 @@ import android.provider.Settings;
import android.service.carrier.CarrierMessagingService;
import android.service.carrier.ICarrierMessagingCallback;
import android.service.carrier.ICarrierMessagingService;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SmsManager;
import android.testing.AndroidTestingRunner;
@@ -75,6 +75,7 @@ import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.TelephonyTestUtils;
import com.android.internal.telephony.TestApplication;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.satellite.SatelliteController;
import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.uicc.IsimUiccRecords;

@@ -103,6 +104,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
    private SMSDispatcher.SmsTracker mSmsTracker;
    private ISub.Stub mISubStub;
    private ICarrierMessagingService.Stub mICarrierAppMessagingService;
    private SatelliteController mMockSatelliteController;

    private Object mLock = new Object();
    private boolean mReceivedTestIntent;
@@ -145,6 +147,9 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        mSmsTracker = mock(SMSDispatcher.SmsTracker.class);
        mISubStub = mock(ISub.Stub.class);
        mICarrierAppMessagingService = mock(ICarrierMessagingService.Stub.class);
        mMockSatelliteController = mock(SatelliteController.class);
        replaceInstance(SatelliteController.class, "sInstance", null,
                mMockSatelliteController);

        // Note that this replaces only cached services in ServiceManager. If a service is not found
        // in the cache, a real instance is used.
@@ -696,4 +701,27 @@ public class GsmSmsDispatcherTest extends TelephonyTest {

        assertFalse(isMtSmsPollingMessage);
    }

    @Test
    public void testShouldBlockPremiumSmsInSatelliteMode() {
        doReturn(true).when(mMockSatelliteController).isSatelliteBeingEnabled();
        assertTrue(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode());

        int subId = mPhone.getSubId();
        doReturn(subId).when(mMockSatelliteController).getSelectedSatelliteSubId();
        doReturn(false).when(mMockSatelliteController).isSatelliteBeingEnabled();
        doReturn(true).when(mMockSatelliteController).isSatelliteEnabled();
        doReturn(new int[]{NetworkRegistrationInfo.SERVICE_TYPE_DATA}).when(
                mMockSatelliteController).getSupportedServicesOnCarrierRoamingNtn(anyInt());
        assertTrue(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode());

        doReturn(true).when(mMockSatelliteController).isSatelliteEnabled();
        doReturn(new int[]{NetworkRegistrationInfo.SERVICE_TYPE_DATA,
                NetworkRegistrationInfo.SERVICE_TYPE_SMS}).when(
                mMockSatelliteController).getSupportedServicesOnCarrierRoamingNtn(anyInt());
        assertFalse(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode());

        doReturn(false).when(mMockSatelliteController).isSatelliteEnabled();
        assertFalse(mGsmSmsDispatcher.shouldBlockPremiumSmsInSatelliteMode());
    }
}