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

Commit d03a7826 authored by Megha Patil's avatar Megha Patil Committed by Android (Google) Code Review
Browse files

Merge changes from topic "CarrierConfigSMS"

* changes:
  Unit Test for SMS Retry based on Configuration
  Implementation for SMS retry based on config
  Implementation for SMS retry based on config
parents 2c95c1a8 654b2710
Loading
Loading
Loading
Loading
+87 −2
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class ImsSmsDispatcher extends SMSDispatcher {

    private static final String TAG = "ImsSmsDispatcher";
    private static final int CONNECT_DELAY_MS = 5000; // 5 seconds;
    public static final int MAX_SEND_RETRIES_OVER_IMS = MAX_SEND_RETRIES;

    /**
     * Creates FeatureConnector instances for ImsManager, used during testing to inject mock
@@ -171,10 +172,19 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                        mTrackers.remove(token);
                        break;
                    case ImsSmsImplBase.SEND_STATUS_ERROR_RETRY:
                        if (tracker.mRetryCount < MAX_SEND_RETRIES) {
                        int maxRetryCountOverIms = getMaxRetryCountOverIms();
                        if (tracker.mRetryCount < getMaxSmsRetryCount()) {
                            if (maxRetryCountOverIms < getMaxSmsRetryCount()
                                    && tracker.mRetryCount >= maxRetryCountOverIms) {
                                tracker.mRetryCount += 1;
                                mTrackers.remove(token);
                                fallbackToPstn(tracker);
                                break;
                            }
                            tracker.mRetryCount += 1;
                            sendMessageDelayed(
                                    obtainMessage(EVENT_SEND_RETRY, tracker), SEND_RETRY_DELAY);
                                    obtainMessage(EVENT_SEND_RETRY, tracker),
                                    getSmsRetryDelayValue());
                        } else {
                            tracker.onFailed(mContext, reason, networkReasonCode);
                            mTrackers.remove(token);
@@ -405,6 +415,81 @@ public class ImsSmsDispatcher extends SMSDispatcher {
        }
    }

    @Override
    public int getMaxSmsRetryCount() {
        int retryCount = MAX_SEND_RETRIES;
        CarrierConfigManager mConfigManager;

        mConfigManager = (CarrierConfigManager)  mContext.getSystemService(
                Context.CARRIER_CONFIG_SERVICE);

        if (mConfigManager != null) {
            PersistableBundle carrierConfig = mConfigManager.getConfigForSubId(
                    getSubId());

            if (carrierConfig != null) {
                retryCount = carrierConfig.getInt(
                        CarrierConfigManager.ImsSms.KEY_SMS_MAX_RETRY_COUNT_INT);
            }
        }

        Rlog.d(TAG, "Retry Count: " + retryCount);

        return retryCount;
    }

    /**
     * Returns the number of times SMS can be sent over IMS
     *
     * @return  retry count over Ims from  carrier configuration
     */
    @VisibleForTesting
    public int getMaxRetryCountOverIms() {
        int retryCountOverIms = MAX_SEND_RETRIES_OVER_IMS;
        CarrierConfigManager mConfigManager;

        mConfigManager = (CarrierConfigManager) mContext.getSystemService(Context
                                                        .CARRIER_CONFIG_SERVICE);

        if (mConfigManager != null) {
            PersistableBundle carrierConfig = mConfigManager.getConfigForSubId(
                    getSubId());


            if (carrierConfig != null) {
                retryCountOverIms = carrierConfig.getInt(
                        CarrierConfigManager.ImsSms.KEY_SMS_MAX_RETRY_COUNT_OVER_IMS_INT);
            }
        }

        Rlog.d(TAG, "Retry Count Over Ims: " + retryCountOverIms);

        return retryCountOverIms;
    }

    @Override
    public int getSmsRetryDelayValue() {
        int retryDelay = SEND_RETRY_DELAY;
        CarrierConfigManager mConfigManager;

        mConfigManager = (CarrierConfigManager)  mContext.getSystemService(
                Context.CARRIER_CONFIG_SERVICE);

        if (mConfigManager != null) {
            PersistableBundle carrierConfig = mConfigManager.getConfigForSubId(
                    getSubId());

            if (carrierConfig != null) {
                retryDelay = carrierConfig.getInt(
                        CarrierConfigManager.ImsSms.KEY_SMS_OVER_IMS_SEND_RETRY_DELAY_MILLIS_INT);
            }
        }

        Rlog.d(TAG, "Retry delay: " + retryDelay);

        return retryDelay;
    }

    @Override
    protected boolean shouldBlockSmsForEcbm() {
        // We should not block outgoing SMS during ECM on IMS. It only applies to outgoing CDMA
+23 −3
Original line number Diff line number Diff line
@@ -315,6 +315,26 @@ public abstract class SMSDispatcher extends Handler {
     */
    protected abstract String getFormat();

    /**
     * Gets the maximum number of times the SMS can be retried upon Failure,
     * from the {@link android.telephony.CarrierConfigManager}
     *
     * @return the default maximum number of times SMS can be sent
     */
    protected int getMaxSmsRetryCount() {
        return MAX_SEND_RETRIES;
    }

    /**
     * Gets the Time delay before next send attempt on a failed SMS,
     * from the {@link android.telephony.CarrierConfigManager}
     *
     * @return the Time in miiliseconds for delay before next send attempt on a failed SMS
     */
    protected int getSmsRetryDelayValue() {
        return SEND_RETRY_DELAY;
    }

    /**
     * Called when a status report is received. This should correspond to a previously successful
     * SEND.
@@ -1014,7 +1034,7 @@ public abstract class SMSDispatcher extends Handler {
                // This is retry after failure over IMS but voice is not available.
                // Set retry to max allowed, so no retry is sent and cause
                // SmsManager.RESULT_ERROR_GENERIC_FAILURE to be returned to app.
                tracker.mRetryCount = MAX_SEND_RETRIES;
                tracker.mRetryCount = getMaxSmsRetryCount();

                Rlog.d(TAG, "handleSendComplete: Skipping retry: "
                        + " isIms()=" + isIms()
@@ -1037,7 +1057,7 @@ public abstract class SMSDispatcher extends Handler {
                        tracker.isFromDefaultSmsApplication(mContext),
                        tracker.getInterval());
            } else if (error == SmsManager.RESULT_RIL_SMS_SEND_FAIL_RETRY
                    && tracker.mRetryCount < MAX_SEND_RETRIES) {
                    && tracker.mRetryCount < getMaxSmsRetryCount()) {
                // Retry after a delay if needed.
                // TODO: According to TS 23.040, 9.2.3.6, we should resend
                //       with the same TP-MR as the failed message, and
@@ -1049,7 +1069,7 @@ public abstract class SMSDispatcher extends Handler {
                tracker.mRetryCount++;
                int errorCode = (smsResponse != null) ? smsResponse.mErrorCode : NO_ERROR_CODE;
                Message retryMsg = obtainMessage(EVENT_SEND_RETRY, tracker);
                sendMessageDelayed(retryMsg, SEND_RETRY_DELAY);
                sendMessageDelayed(retryMsg, getSmsRetryDelayValue());
                mPhone.getSmsStats().onOutgoingSms(
                        tracker.mImsRetry > 0 /* isOverIms */,
                        SmsConstants.FORMAT_3GPP2.equals(getFormat()),
+80 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SmsMessage;
import android.telephony.ims.stub.ImsSmsImplBase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -64,7 +66,9 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
    private FeatureConnector.Listener<ImsManager> mImsManagerListener;
    private HashMap<String, Object> mTrackerData;
    private ImsSmsDispatcher mImsSmsDispatcher;
    PersistableBundle mBundle = new PersistableBundle();
    private static final int SUB_0 = 0;
    private static final String TAG = "ImsSmsDispatcherTest";

    @Before
    public void setUp() throws Exception {
@@ -168,6 +172,13 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
    @SmallTest
    public void testErrorImsRetry() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                .KEY_SMS_OVER_IMS_SEND_RETRY_DELAY_MILLIS_INT,
                                2000);
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_MAX_RETRY_COUNT_OVER_IMS_INT, 3);
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_MAX_RETRY_COUNT_INT, 3);
        mTrackerData.put("pdu", com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(null,
                "+15555551212", "Test", false).encodedMessage);
        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
@@ -285,6 +296,13 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
    public void testErrorImsRetrywithMessageRef() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int messageRef = mImsSmsDispatcher.nextMessageRef() + 1;
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_OVER_IMS_SEND_RETRY_DELAY_MILLIS_INT,
                                                2000);
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_MAX_RETRY_COUNT_OVER_IMS_INT, 3);
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_MAX_RETRY_COUNT_INT, 3);
        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();
@@ -309,4 +327,66 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        assertEquals(messageRef, pdu[1]);
        assertEquals(0x04, (pdu[0] & 0x04));
    }

    @Test
    public void testErrorImsRetrywithRetryConfig() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int messageRef = mImsSmsDispatcher.nextMessageRef() + 1;
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_OVER_IMS_SEND_RETRY_DELAY_MILLIS_INT,
                                                3000);
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_MAX_RETRY_COUNT_OVER_IMS_INT, 2);
        mContextFixture.getCarrierConfigBundle().putInt(CarrierConfigManager.ImsSms
                                                .KEY_SMS_MAX_RETRY_COUNT_INT, 3);
        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();
        mImsSmsDispatcher.sendText("+15555551212", null, "Retry test",
                null, null, null, null, false,
                -1, false, -1, false, 0);
        verify(mImsManager).sendSms(eq(token + 1), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(false), (byte[]) any());
        assertEquals(2, mImsSmsDispatcher.getMaxRetryCountOverIms());
        assertEquals(3, mImsSmsDispatcher.getMaxSmsRetryCount());
        assertEquals(3000, mImsSmsDispatcher.getSmsRetryDelayValue());
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token + 1, messageRef,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, 0, SmsResponse.NO_ERROR_CODE);
        waitForMs(mImsSmsDispatcher.getSmsRetryDelayValue() + 200);
        processAllMessages();

        // Make sure tpmr value is same and retry bit set
        ArgumentCaptor<byte[]> byteCaptor = ArgumentCaptor.forClass(byte[].class);
        verify(mImsManager).sendSms(eq(token + 2), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(true), byteCaptor.capture());
        byte[] pdu = byteCaptor.getValue();
        assertEquals(messageRef, pdu[1]);
        assertEquals(0x04, (pdu[0] & 0x04));
        // Retry over IMS for the second time
        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token + 2, messageRef,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, 0, SmsResponse.NO_ERROR_CODE);
        waitForMs(mImsSmsDispatcher.getSmsRetryDelayValue() + 200);
        processAllMessages();
        // Make sure tpmr value is same and retry bit set
        ArgumentCaptor<byte[]> byteCaptor2 = ArgumentCaptor.forClass(byte[].class);
        verify(mImsManager).sendSms(eq(token + 3), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(true), byteCaptor2.capture());
        byte[] pdu2 = byteCaptor2.getValue();
        assertEquals(messageRef, pdu2[1]);
        assertEquals(0x04, (pdu2[0] & 0x04));

        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token + 3, messageRef,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, 0, SmsResponse.NO_ERROR_CODE);
        waitForMs(mImsSmsDispatcher.getSmsRetryDelayValue() + 200);
        processAllMessages();
        // Make sure tpmr value is same and retry bit set
        ArgumentCaptor<SMSDispatcher.SmsTracker> captor =
                ArgumentCaptor.forClass(SMSDispatcher.SmsTracker.class);
        // Ensure GsmSmsDispatcher calls sendSms
        verify(mSmsDispatchersController).sendRetrySms(captor.capture());

        assertNotNull(captor.getValue());
        assertTrue(captor.getValue().mRetryCount > 0);
    }
}