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

Commit 559e5b70 authored by arunvoddu's avatar arunvoddu
Browse files

saving null alphaTag if exceeds the uicc allowed limit in

voicemailAlphatag case

Bug: 143508861
Test: aTest verification passed,Manually verified with testapp
Change-Id: Ia28e65337dc341d177996a2f5123f5571979212b
parent 34c143fb
Loading
Loading
Loading
Loading
+33 −7
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class AdnRecordLoader extends Handler {
    static final int EVENT_EF_LINEAR_RECORD_SIZE_DONE = 4;
    static final int EVENT_UPDATE_RECORD_DONE = 5;

    static final int VOICEMAIL_ALPHATAG_ARG = 1;
    //***** Constructor

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@@ -176,15 +177,35 @@ public class AdnRecordLoader extends Handler {

                    data = adn.buildAdnString(recordSize[0]);

                    if(data == null) {
                        /**
                         * The voicemail number saving to the SIM is in name(alphaTag) and number
                         * format. {@link recordSize[0]} indicates the SIM EF memory size that the
                         * sim can have to save both voicemail name and number. 14 byte of memory
                         * is reserved to save the voicemail number and remaining memory is reserved
                         * for the alphaTag. In case if we receive the alphaTag which is more than
                         * the reserved memory size then SIM will throw the exception and it don't
                         * save both the voicemail number and alphaTag. To avoid this problem, in
                         * case alphaTag length is more we nullify the alphaTag and save the same.
                         */
                        if (mUserResponse.arg1 == VOICEMAIL_ALPHATAG_ARG) {
                            adn.mAlphaTag = null;
                            data = adn.buildAdnString(recordSize[0]);
                        }
                        if (data == null) {
                            throw new RuntimeException("wrong ADN format",
                                    ar.exception);
                        }
                    }


                    // Send adn record to caller to track the changes made to alphaTag
                    if (mUserResponse.arg1 == VOICEMAIL_ALPHATAG_ARG) {
                        mFh.updateEFLinearFixed(mEf, getEFPath(mEf), mRecordNumber,
                                data, mPin2, obtainMessage(EVENT_UPDATE_RECORD_DONE, adn));
                    } else {
                        mFh.updateEFLinearFixed(mEf, getEFPath(mEf), mRecordNumber,
                                data, mPin2, obtainMessage(EVENT_UPDATE_RECORD_DONE));

                    }
                    mPendingExtLoads = 1;

                    break;
@@ -195,7 +216,12 @@ public class AdnRecordLoader extends Handler {
                                ar.exception);
                    }
                    mPendingExtLoads = 0;
                    // send the adn record back to caller through the result of AsyncResult
                    if (mUserResponse.arg1 == VOICEMAIL_ALPHATAG_ARG) {
                        mResult =  ar.userObj;
                    } else {
                        mResult = null;
                    }
                    break;
                case EVENT_ADN_LOAD_DONE:
                    ar = (AsyncResult)(msg.obj);
+30 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.MccTable;
import com.android.internal.telephony.SmsConstants;
@@ -397,18 +398,20 @@ public class SIMRecords extends IccRecords {
        mNewVoiceMailTag = alphaTag;

        AdnRecord adn = new AdnRecord(mNewVoiceMailTag, mNewVoiceMailNum);

        if (mMailboxIndex != 0 && mMailboxIndex != 0xff) {

            new AdnRecordLoader(mFh).updateEF(adn, EF_MBDN, EF_EXT6,
                    mMailboxIndex, null,
                    obtainMessage(EVENT_SET_MBDN_DONE, onComplete));
                    obtainMessage(EVENT_SET_MBDN_DONE, AdnRecordLoader.VOICEMAIL_ALPHATAG_ARG,
                            0 /* ignored arg2 */, onComplete));

        } else if (isCphsMailboxEnabled()) {

            new AdnRecordLoader(mFh).updateEF(adn, EF_MAILBOX_CPHS,
                    EF_EXT1, 1, null,
                    obtainMessage(EVENT_SET_CPHS_MAILBOX_DONE, onComplete));
                    obtainMessage(EVENT_SET_CPHS_MAILBOX_DONE,
                            AdnRecordLoader.VOICEMAIL_ALPHATAG_ARG,
                            0 /* ignored arg2 */, onComplete));

        } else {
            AsyncResult.forMessage((onComplete)).exception =
@@ -1031,10 +1034,20 @@ public class SIMRecords extends IccRecords {

                    if (DBG) log("EVENT_SET_MBDN_DONE ex:" + ar.exception);
                    if (ar.exception == null) {
                        /**
                         * Check for any changes made to voicemail alphaTag while saving to SIM.
                         * if voicemail alphaTag length is more than allowed limit of SIM EF then
                         * null alphaTag will be saved to SIM {@code AdnRecordLoader}.
                         */
                        if (ar.result != null) {
                            AdnRecord adnRecord = (AdnRecord) (ar.result);
                            if (adnRecord != null) {
                                mNewVoiceMailTag = adnRecord.mAlphaTag;
                            }
                        }
                        mVoiceMailNum = mNewVoiceMailNum;
                        mVoiceMailTag = mNewVoiceMailTag;
                    }

                    if (isCphsMailboxEnabled()) {
                        adn = new AdnRecord(mVoiceMailTag, mVoiceMailNum);
                        Message onCphsCompleted = (Message) ar.userObj;
@@ -1058,7 +1071,8 @@ public class SIMRecords extends IccRecords {
                        new AdnRecordLoader(mFh)
                                .updateEF(adn, EF_MAILBOX_CPHS, EF_EXT1, 1, null,
                                obtainMessage(EVENT_SET_CPHS_MAILBOX_DONE,
                                        onCphsCompleted));
                                       AdnRecordLoader.VOICEMAIL_ALPHATAG_ARG,
                                        0 /* ignored arg2 */, onCphsCompleted));
                    } else {
                        if (ar.userObj != null) {
                            CarrierConfigManager configManager = (CarrierConfigManager)
@@ -1090,6 +1104,12 @@ public class SIMRecords extends IccRecords {
                    isRecordLoadResponse = false;
                    ar = (AsyncResult) msg.obj;
                    if (ar.exception == null) {
                        if (ar.result != null) {
                            AdnRecord adnRecord = (AdnRecord) (ar.result);
                            if (adnRecord != null) {
                                mNewVoiceMailTag = adnRecord.mAlphaTag;
                            }
                        }
                        mVoiceMailNum = mNewVoiceMailNum;
                        mVoiceMailTag = mNewVoiceMailTag;
                    } else {
@@ -2163,6 +2183,11 @@ public class SIMRecords extends IccRecords {
        log("[CSP] Value Added Service Group (0xC0), not found!");
    }

    @VisibleForTesting
    public void setMailboxIndex(int mailboxIndex) {
        mMailboxIndex = mailboxIndex;
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("SIMRecords: " + this);
+220 −0
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.content.Context;
@@ -41,6 +43,7 @@ import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.uicc.IccRecords.OperatorPlmnInfo;
import com.android.internal.telephony.uicc.IccRecords.PlmnNetworkName;
import com.android.telephony.Rlog;

import org.junit.After;
import org.junit.Before;
@@ -50,6 +53,8 @@ import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@RunWith(AndroidJUnit4.class)
public class SIMRecordsTest extends TelephonyTest {
@@ -716,4 +721,219 @@ public class SIMRecordsTest extends TelephonyTest {
        String resultSst = mSIMRecordsUT.getSimServiceTable();
        assertEquals(mockSst, resultSst);
    }

    @Test
    public void testSetVoiceMailNumber() throws InterruptedException {

        String voiceMailNumber = "1234567890";
        String alphaTag = "Voicemail";
        final CountDownLatch latch = new CountDownLatch(2);
        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation1");
                    Message response = invocation.getArgument(2);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));

        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation2");
                    Message response = invocation.getArgument(5);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .updateEFLinearFixed(anyInt(), eq(null), anyInt(), any(byte[].class),
                        eq(null), any(Message.class));


        mSIMRecordsUT.setMailboxIndex(1);
        Message message = Message.obtain(mTestHandler);
        mSIMRecordsUT.setVoiceMailNumber(alphaTag, voiceMailNumber, message);
        latch.await(5, TimeUnit.SECONDS);
        mTestLooper.startAutoDispatch();
        verify(mFhMock, times(1)).getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));
        verify(mFhMock, times(1)).updateEFLinearFixed(anyInt(), eq(null),
                anyInt(), any(byte[].class), eq(null), any(Message.class));

        assertEquals(voiceMailNumber, mSIMRecordsUT.getVoiceMailNumber());
        assertEquals(alphaTag, mSIMRecordsUT.getVoiceMailAlphaTag());
    }

    @Test
    public void testSetVoiceMailNumberBigAlphatag() throws InterruptedException {

        String voiceMailNumber = "1234567890";
        String alphaTag = "VoicemailAlphaTag-VoicemailAlphaTag";
        final CountDownLatch latch = new CountDownLatch(2);
        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation1");
                    Message response = invocation.getArgument(2);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));

        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation2");
                    Message response = invocation.getArgument(5);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .updateEFLinearFixed(anyInt(), eq(null), anyInt(), any(byte[].class),
                        eq(null), any(Message.class));


        mSIMRecordsUT.setMailboxIndex(1);
        Message message = Message.obtain(mTestHandler);
        mSIMRecordsUT.setVoiceMailNumber(alphaTag, voiceMailNumber, message);
        latch.await(8, TimeUnit.SECONDS);
        mTestLooper.startAutoDispatch();
        verify(mFhMock, times(1)).getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));
        verify(mFhMock, times(1)).updateEFLinearFixed(anyInt(), eq(null),
                anyInt(), any(byte[].class), eq(null), any(Message.class));

        //if attempt to save bugAlphatag which sim don't support so we will make it null
        assertEquals(null, mSIMRecordsUT.getVoiceMailAlphaTag());
        assertEquals(voiceMailNumber, mSIMRecordsUT.getVoiceMailNumber());
    }

    @Test
    public void testSetVoiceMailNumberUtf16Alphatag() throws InterruptedException {

        String voiceMailNumber = "1234567890";
        String alphaTag = "หมายเลขข้อความเสียง"; // Messagerie vocale
        final CountDownLatch latch = new CountDownLatch(2);
        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation1");
                    Message response = invocation.getArgument(2);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));

        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation2");
                    Message response = invocation.getArgument(5);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .updateEFLinearFixed(anyInt(), eq(null), anyInt(), any(byte[].class),
                        eq(null), any(Message.class));


        mSIMRecordsUT.setMailboxIndex(1);
        Message message = Message.obtain(mTestHandler);
        mSIMRecordsUT.setVoiceMailNumber(alphaTag, voiceMailNumber, message);
        latch.await(5, TimeUnit.SECONDS);
        mTestLooper.startAutoDispatch();
        verify(mFhMock, times(1)).getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));
        verify(mFhMock, times(1)).updateEFLinearFixed(anyInt(), eq(null),
                anyInt(), any(byte[].class), eq(null), any(Message.class));

        assertEquals(voiceMailNumber, mSIMRecordsUT.getVoiceMailNumber());
        //if attempt to save bugAlphatag which sim don't support so we will make it null
        assertEquals(null, mSIMRecordsUT.getVoiceMailAlphaTag());
    }


    @Test
    public void testSetVoiceMailNullNumber() throws InterruptedException {

        String voiceMailNumber = null;
        String alphaTag = "VoicemailAlphaTag"; // Messagerie vocale
        final CountDownLatch latch = new CountDownLatch(2);
        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation1");
                    Message response = invocation.getArgument(2);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));

        doAnswer(
                invocation -> {
                    int[] result = new int[3];
                    result[0] = 32;
                    result[1] = 32;
                    result[2] = 1;
                    Rlog.d("SIMRecordsTest", "Executing the test invocation2");
                    Message response = invocation.getArgument(5);
                    AsyncResult.forMessage(response, result, null);
                    response.sendToTarget();
                    latch.countDown();
                    return null;
                })
                .when(mFhMock)
                .updateEFLinearFixed(anyInt(), eq(null), anyInt(), any(byte[].class),
                        eq(null), any(Message.class));


        mSIMRecordsUT.setMailboxIndex(1);
        Message message = Message.obtain(mTestHandler);
        mSIMRecordsUT.setVoiceMailNumber(alphaTag, voiceMailNumber, message);
        latch.await(5, TimeUnit.SECONDS);
        mTestLooper.startAutoDispatch();
        verify(mFhMock, times(1)).getEFLinearRecordSize(anyInt(), isNull(), any(Message.class));
        verify(mFhMock, times(1)).updateEFLinearFixed(anyInt(), eq(null),
                anyInt(), any(byte[].class), eq(null), any(Message.class));

        assertEquals(null, mSIMRecordsUT.getVoiceMailNumber());
        assertEquals(alphaTag, mSIMRecordsUT.getVoiceMailAlphaTag());
    }
}