aboutsummaryrefslogtreecommitdiff
path: root/tests/telephonytests/src/com/android/internal/telephony/ImsSmsDispatcherTest.java
blob: fe1404bcef5fe5ac858b0f623c43f48abebc7814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.internal.telephony;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
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;

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;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import com.android.ims.FeatureConnector;
import com.android.ims.ImsManager;
import com.android.internal.util.HexDump;

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

import java.util.HashMap;

@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class ImsSmsDispatcherTest extends TelephonyTest {
    // Mocked classes
    private SmsDispatchersController mSmsDispatchersController;
    private SMSDispatcher.SmsTracker mSmsTracker;
    private ImsSmsDispatcher.FeatureConnectorFactory mConnectorFactory;
    private FeatureConnector<ImsManager> mMockConnector;

    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 {
        super.setUp(getClass().getSimpleName());
        mSmsDispatchersController = mock(SmsDispatchersController.class);
        mSmsTracker = mock(SMSDispatcher.SmsTracker.class);
        mConnectorFactory = mock(ImsSmsDispatcher.FeatureConnectorFactory.class);
        mMockConnector = mock(FeatureConnector.class);
        doAnswer((Answer<FeatureConnector<ImsManager>>) invocation -> {
            mImsManagerListener =
                    (FeatureConnector.Listener<ImsManager>) invocation.getArguments()[3];
            return mMockConnector;
        }).when(mConnectorFactory).create(any(), anyInt(), anyString(), any(), any());
        mImsSmsDispatcher = new ImsSmsDispatcher(mPhone, mSmsDispatchersController,
                mConnectorFactory);
        processAllMessages();
        // set the ImsManager instance
        verify(mMockConnector).connect();
        mImsManagerListener.connectionReady(mImsManager, SUB_0);
        when(mSmsDispatchersController.isIms()).thenReturn(true);
        mTrackerData = new HashMap<>(1);
        when(mSmsTracker.getData()).thenReturn(mTrackerData);
        verify(mSmsDispatchersController).setImsManager(mImsManager);
    }

    @After
    public void tearDown() throws Exception {
        mImsSmsDispatcher = null;
        mImsManagerListener = null;
        mTrackerData = null;
        super.tearDown();
    }

   /**
     * Send Memory Availability Notification and verify that the token is correct.
     */
    @Test
    @SmallTest
    public void testOnMemoryAvailable() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        //Send SMMA
        mImsSmsDispatcher.onMemoryAvailable();
        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.
     */
    @Test
    @SmallTest
    public void testSendSms() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int trackersSize = mImsSmsDispatcher.mTrackers.size();

        byte[] pdu = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(null,
                "+15555551212", "Test", false).encodedMessage;
        mTrackerData.put("pdu", pdu);
        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);

        //Send an SMS
        mImsSmsDispatcher.sendSms(mSmsTracker);

        assertEquals(token + 1, mImsSmsDispatcher.mNextToken.get());
        assertEquals(trackersSize + 1, mImsSmsDispatcher.mTrackers.size());
        verify(mImsManager).sendSms(eq(token + 1), anyInt(), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(false), eq(pdu));
    }

    /**
     * Ensure that when sending a GSM text fails with SEND_STATUS_ERROR_FALLBACK, retry with
     * a non-zero retry count (set TP-RD).
     */
    @Test
    @SmallTest
    public void testFallbackGsmRetry() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        mTrackerData.put("pdu", com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(null,
                "+15555551212", "Test", false).encodedMessage);
        mImsSmsDispatcher.mTrackers.put(token, mSmsTracker);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);

        // Fallback over GSM
        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token, 0,
                ImsSmsImplBase.SEND_STATUS_ERROR_FALLBACK, 0, SmsResponse.NO_ERROR_CODE);
        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);

    }

    /**
     * Ensure that when an outgoing SMS has failed over IMS with SEND_STATUS_ERROR_RETRY, it is
     * sent over the IMS channel again with the TP-RD bit set.
     */
    @Test
    @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_OVER_IMS_COUNT_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);
        mImsSmsDispatcher.mTrackers.put(token, mSmsTracker);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);

        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token, 0,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, 0, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 200);
        processAllMessages();

        // Make sure retry bit set
        ArgumentCaptor<byte[]> byteCaptor = ArgumentCaptor.forClass(byte[].class);
        verify(mImsManager).sendSms(eq(token + 1), anyInt(), nullable(String.class),
                nullable(String.class), eq(true), byteCaptor.capture());
        byte[] pdu = byteCaptor.getValue();
        // Make sure that TP-RD is set for this message
        assertNotNull(pdu);
        assertEquals(0x04, (pdu[0] & 0x04));
    }

    /**
     * Ensure that when a GSM status report is received, it calls acknowledgeSmsReport with correct
     * token and message reference.
     */
    @Test
    @SmallTest
    public void testReceiveGsmSmsStatusReport() throws Exception {
        int statusReportToken = 456; // Generated by IMS providers
        int messageRef = 123; // TP-MR for sent SMS
        // PDU for SMS-STATUS-REPORT
        byte[] pdu = HexDump.hexStringToByteArray("0006000681214365919061800000639190618000006300");

        // Set TP-MR
        pdu[2] = (byte) messageRef;

        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);

        // Receive the status report
        mImsSmsDispatcher
                .getSmsListener()
                .onSmsStatusReportReceived(statusReportToken, SmsMessage.FORMAT_3GPP, pdu);

        // Ensure it calls acknowledgeSmsReport with correct token and message reference
        verify(mImsManager)
                .acknowledgeSmsReport(
                        eq(statusReportToken),
                        eq(messageRef),
                        eq(ImsSmsImplBase.STATUS_REPORT_STATUS_OK));
    }

    /**
     * Ensure that when an outgoing SMS has failed over IMS with SEND_STATUS_ERROR and an associated
     * networkErrorCode, the error is sent to the tracker properly.
     */
    @Test
    @SmallTest
    public void testNetworkError() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        mTrackerData.put("pdu", com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(null,
                "+15555551212", "Test", false).encodedMessage);
        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
        mImsSmsDispatcher.mTrackers.put(token, mSmsTracker);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);

        // network error 41
        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token, 0,
                ImsSmsImplBase.SEND_STATUS_ERROR, 0, 41);
        verify(mSmsTracker).onFailed(any(Context.class), anyInt(), eq(41));
    }

    @Test
    public void testSendSmswithMessageRef() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int messageRef = mImsSmsDispatcher.nextMessageRef();
        if (mImsSmsDispatcher.isMessageRefIncrementViaTelephony()) {
            messageRef += 1;
        }

        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();

        mImsSmsDispatcher.sendText("+15555551212", null, "MessageRef 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());
    }

    @Test
    public void testFallbackGsmRetrywithMessageRef() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int messageRef = mImsSmsDispatcher.nextMessageRef();

        when(mImsManager.getSmsFormat()).thenReturn(SmsMessage.FORMAT_3GPP);
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();

        mImsSmsDispatcher.sendText("+15555551212", null, "MessageRef 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());

        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token + 1, messageRef,
                ImsSmsImplBase.SEND_STATUS_ERROR_FALLBACK, 0, SmsResponse.NO_ERROR_CODE);
        processAllMessages();

        ArgumentCaptor<SMSDispatcher.SmsTracker> captor =
                ArgumentCaptor.forClass(SMSDispatcher.SmsTracker.class);
        verify(mSmsDispatchersController).sendRetrySms(captor.capture());
        assertTrue(messageRef == captor.getValue().mMessageRef);
    }

    @Test
    public void testErrorImsRetrywithMessageRef() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int messageRef = mImsSmsDispatcher.nextMessageRef();
        if (mImsSmsDispatcher.isMessageRefIncrementViaTelephony()) {
            messageRef += 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_OVER_IMS_COUNT_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();

        mImsSmsDispatcher.sendText("+15555551212", null, "MessageRef 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());

        // Retry over IMS
        mImsSmsDispatcher.getSmsListener().onSendSmsResult(token + 1, messageRef,
                ImsSmsImplBase.SEND_STATUS_ERROR_RETRY, 0, SmsResponse.NO_ERROR_CODE);
        waitForMs(SMSDispatcher.SEND_RETRY_DELAY + 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));
    }

    @Test
    public void testErrorImsRetrywithRetryConfig() throws Exception {
        int token = mImsSmsDispatcher.mNextToken.get();
        int messageRef = mImsSmsDispatcher.nextMessageRef();
        if (mImsSmsDispatcher.isMessageRefIncrementViaTelephony()) {
            messageRef += 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_OVER_IMS_COUNT_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);
    }
}