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

Commit 9016bb3b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fetching smsc value from Usim/Isim Apis for every SMS sent."

parents 4221f2bb 91aef910
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Binder;
import android.os.Handler;
import android.os.Message;
import android.os.UserManager;
@@ -242,6 +243,21 @@ public class SmsDispatchersController extends Handler {
        }
    }

    private String getSmscAddressFromUSIM(String callingPkg) {
        IccSmsInterfaceManager iccSmsIntMgr = mPhone.getIccSmsInterfaceManager();
        if (iccSmsIntMgr != null) {
            long identity = Binder.clearCallingIdentity();
            try {
                return iccSmsIntMgr.getSmscAddressFromIccEf(callingPkg);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        } else {
            Rlog.d(TAG, "getSmscAddressFromIccEf iccSmsIntMgr is null");
        }
        return null;
    }

    private void reevaluateTimerStatus() {
        long currentTime = System.currentTimeMillis();

@@ -671,6 +687,9 @@ public class SmsDispatchersController extends Handler {
     */
    protected void sendData(String callingPackage, String destAddr, String scAddr, int destPort,
            byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent, boolean isForVvm) {
        if (scAddr == null) {
            scAddr = getSmscAddressFromUSIM(callingPackage);
        }
        if (mImsSmsDispatcher.isAvailable()) {
            mImsSmsDispatcher.sendData(callingPackage, destAddr, scAddr, destPort, data, sentIntent,
                    deliveryIntent, isForVvm);
@@ -784,6 +803,9 @@ public class SmsDispatchersController extends Handler {
            PendingIntent deliveryIntent, Uri messageUri, String callingPkg, boolean persistMessage,
            int priority, boolean expectMore, int validityPeriod, boolean isForVvm,
            long messageId) {
        if (scAddr == null) {
            scAddr = getSmscAddressFromUSIM(callingPkg);
        }
        if (mImsSmsDispatcher.isAvailable() || mImsSmsDispatcher.isEmergencySmsSupport(destAddr)) {
            mImsSmsDispatcher.sendText(destAddr, scAddr, text, sentIntent, deliveryIntent,
                    messageUri, callingPkg, persistMessage, priority, false /*expectMore*/,
@@ -910,6 +932,9 @@ public class SmsDispatchersController extends Handler {
            ArrayList<PendingIntent> deliveryIntents, Uri messageUri, String callingPkg,
            boolean persistMessage, int priority, boolean expectMore, int validityPeriod,
            long messageId) {
        if (scAddr == null) {
            scAddr = getSmscAddressFromUSIM(callingPkg);
        }
        if (mImsSmsDispatcher.isAvailable()) {
            mImsSmsDispatcher.sendMultipartText(destAddr, scAddr, parts, sentIntents,
                    deliveryIntents, messageUri, callingPkg, persistMessage, priority,
+1 −1
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        verify(mImsManager).sendSms(eq(token + 2), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(true), byteCaptor.capture());
        byte[] pdu = byteCaptor.getValue();
        assertEquals(pdu[1], messageRef);
        assertEquals(messageRef, pdu[1]);
        assertEquals(0x04, (pdu[0] & 0x04));
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.os.Message;
import android.provider.Telephony.Sms.Intents;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.test.FlakyTest;
import android.test.suitebuilder.annotation.SmallTest;
@@ -42,11 +43,14 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Singleton;

import com.android.internal.telephony.uicc.IccUtils;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import java.util.HashMap;

@@ -179,6 +183,24 @@ public class SmsDispatchersControllerTest extends TelephonyTest {
        assertEquals(true, mInjectionCallbackTriggered);
    }

    @Test @SmallTest
    public void testSendImsGmsTestWithSmsc() {
        IccSmsInterfaceManager iccSmsInterfaceManager = Mockito.mock(IccSmsInterfaceManager.class);
        when(mPhone.getIccSmsInterfaceManager()).thenReturn(iccSmsInterfaceManager);
        when(iccSmsInterfaceManager.getSmscAddressFromIccEf("com.android.messaging"))
                .thenReturn("222");
        switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM);

        mSmsDispatchersController.sendText("111", null /*scAddr*/, TAG,
                null, null, null, "com.android.messaging",
                false, -1, false, -1, false, 0L);
        byte[] smscbyte = PhoneNumberUtils.networkPortionToCalledPartyBCDWithLength(
                "222");
        String smsc = IccUtils.bytesToHexString(smscbyte);
        verify(mSimulatedCommandsVerifier).sendImsGsmSms(eq(smsc), anyString(),
                anyInt(), anyInt(), any(Message.class));
    }

    private void switchImsSmsFormat(int phoneType) {
        mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType});
        mSimulatedCommands.notifyImsNetworkStateChanged();
+11 −12
Original line number Diff line number Diff line
@@ -518,7 +518,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
                any(Message.class));
        byte[] pdu = IccUtils.hexStringToBytes(pduCaptor.getValue());
        assertEquals(pdu[1], messageRef);
        assertEquals(messageRef, pdu[1]);
    }

    @Test
@@ -539,7 +539,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
                any(Message.class));
        byte[] pdu = IccUtils.hexStringToBytes(pduCaptor.getValue());
        assertEquals(pdu[1], messageRef);
        assertEquals(messageRef, pdu[1]);
    }

    @Test
@@ -553,11 +553,11 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        mGsmSmsDispatcher.sendText("111", "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);

        ArgumentCaptor<String> pduCaptor1 = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor1.capture(),
        ArgumentCaptor<String> pduCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
                any(Message.class));
        byte[] pdu1 = IccUtils.hexStringToBytes(pduCaptor1.getValue());
        assertEquals(pdu1[1], 0);
        byte[] pdu = IccUtils.hexStringToBytes(pduCaptor.getValue());
        assertEquals(0, pdu[1]);
    }

    @Test
@@ -566,15 +566,14 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
                mSimulatedCommands);
        doReturn(mIsimUiccRecords).when(mPhone).getIccRecords();
        Message msg = mGsmSmsDispatcher.obtainMessage(17);

        mPhone.getIccRecords().setSmssTpmrValue(255, null);
        mPhone.getIccRecords().setSmssTpmrValue(255, msg);
        mGsmSmsDispatcher.sendText("111", "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);

        ArgumentCaptor<String> pduCaptor2 = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor2.capture(),
        ArgumentCaptor<String> pduCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
                any(Message.class));
        byte[] pdu2 = IccUtils.hexStringToBytes(pduCaptor2.getValue());
        assertEquals(pdu2[1], 0);
        byte[] pdu = IccUtils.hexStringToBytes(pduCaptor.getValue());
        assertEquals(0, pdu[1]);
    }
}