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

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

Merge changes from topic "RPSMMA_RESULT"

* changes:
  Unit Tests for onMemoryAvailaleResult Api
  Handle the result of sending RP-SMMA in framework
parents 8723d4ea 4f746244
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@ import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.util.SMSDispatcherUtil;
import com.android.telephony.Rlog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
@@ -74,6 +76,7 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                FeatureConnector.Listener<ImsManager> listener, Executor executor);
    }

    public List<Integer> mMemoryAvailableNotifierList = new ArrayList<Integer>();
    @VisibleForTesting
    public Map<Integer, SmsTracker> mTrackers = new ConcurrentHashMap<>();
    @VisibleForTesting
@@ -141,6 +144,37 @@ public class ImsSmsDispatcher extends SMSDispatcher {
    };

    private final IImsSmsListener mImsSmsListener = new IImsSmsListener.Stub() {
        @Override
        public void onMemoryAvailableResult(int token, @SendStatusResult int status,
                int networkReasonCode) {
            final long identity = Binder.clearCallingIdentity();
            try {
                logd("onMemoryAvailableResult token=" + token + " status=" + status
                        + " networkReasonCode=" + networkReasonCode);
                if (!mMemoryAvailableNotifierList.contains(token)) {
                    loge("onMemoryAvailableResult Invalid token");
                    return;
                }
                mMemoryAvailableNotifierList.remove(Integer.valueOf(token));

                /**
                 * The Retrans flag is set and reset As per section 6.3.3.1.2 in TS 124011
                 * Note: Assuming that SEND_STATUS_ERROR_RETRY is sent in case of temporary failure
                 */
                if (status ==  ImsSmsImplBase.SEND_STATUS_ERROR_RETRY) {
                    if (!mRPSmmaRetried) {
                        sendMessageDelayed(obtainMessage(EVENT_RETRY_SMMA), SEND_RETRY_DELAY);
                        mRPSmmaRetried = true;
                    } else {
                        mRPSmmaRetried = false;
                    }
                } else {
                    mRPSmmaRetried = false;
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
        @Override
        public void onSendSmsResult(int token, int messageRef, @SendStatusResult int status,
                @SmsManager.Result int reason, int networkReasonCode) {
@@ -293,6 +327,10 @@ public class ImsSmsDispatcher extends SMSDispatcher {
                logd("SMS retry..");
                sendSms((SmsTracker) msg.obj);
                break;
            case EVENT_RETRY_SMMA:
                logd("SMMA Notification retry..");
                onMemoryAvailable();
                break;
            default:
                super.handleMessage(msg);
        }
@@ -540,9 +578,13 @@ public class ImsSmsDispatcher extends SMSDispatcher {
        int token = mNextToken.incrementAndGet();
        try {
            logd("onMemoryAvailable: token = " + token);
            mMemoryAvailableNotifierList.add(token);
            getImsManager().onMemoryAvailable(token);
        } catch (ImsException e) {
            loge("onMemoryAvailable failed: " + e.getMessage());
            if (mMemoryAvailableNotifierList.contains(token)) {
                mMemoryAvailableNotifierList.remove(Integer.valueOf(token));
            }
        }
    }

+10 −0
Original line number Diff line number Diff line
@@ -149,6 +149,8 @@ public abstract class SMSDispatcher extends Handler {
    /** New status report received. */
    protected static final int EVENT_NEW_SMS_STATUS_REPORT = 10;

    /** Retry Sending RP-SMMA Notification */
    protected static final int EVENT_RETRY_SMMA = 11;
    // other
    protected static final int EVENT_NEW_ICC_SMS = 14;
    protected static final int EVENT_ICC_CHANGED = 15;
@@ -186,6 +188,14 @@ public abstract class SMSDispatcher extends Handler {

    /** Maximum number of times to retry sending a failed SMS. */
    protected static final int MAX_SEND_RETRIES = 3;

    /** Retransmitted Flag as specified in section 6.3.1.2 in TS 124011
     * true:  RP-SMMA Retried once and no more transmissions are permitted
     * false: not retried at all and at least another transmission of the RP-SMMA message
     * is currently permitted
     */
    protected boolean mRPSmmaRetried = false;

    /** Delay before next send attempt on a failed SMS, in milliseconds. */
    @VisibleForTesting
    public static final int SEND_RETRY_DELAY = 2000;
+68 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -114,6 +115,73 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
    }

    /**
     * Receive SEND_STATUS_ERROR_RETRY with onMemoryAvailableResult Api and check if
     * sending SMMA Notification is retried once
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailableResultErrorRetry() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 1,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager).onMemoryAvailable(eq(token + 2));
        //2nd Failure should not retry
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 2,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager, times(0)).onMemoryAvailable(eq(token + 3));

    }
    /**
     * Receive SEND_STATUS_OK with onMemoryAvailableResult Api and check if
     * sending SMMA Notification behaviour is correct
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailableResultSuccess() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 1,
                ImsSmsImplBase.SEND_STATUS_OK, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager, times(0)).onMemoryAvailable(eq(token + 2));

    }
    /**
     * Receive SEND_STATUS_ERROR with onMemoryAvailableResult Api and check if
     * sending SMMA Notification behaviour is correct
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailableResultError() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        verify(mImsManager).onMemoryAvailable(eq(token + 1));
        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onMemoryAvailableResult(token + 1,
                ImsSmsImplBase.SEND_STATUS_ERROR, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();
        verify(mImsManager, times(0)).onMemoryAvailable(eq(token + 2));

    }
    /**
     * Send an SMS and verify that the token and PDU is correct.
     */