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

Commit 84a1dc18 authored by Jack Yu's avatar Jack Yu Committed by Android (Google) Code Review
Browse files

Merge "Fixed failed unit test cases"

parents 879fd789 1315bca1
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -56,9 +56,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;

import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE;

/**
 *@hide
 */
@@ -193,10 +190,11 @@ public class SubscriptionInfoUpdater extends Handler {
                return;
            }

            int slotId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
            int slotIndex = intent.getIntExtra(PhoneConstants.PHONE_KEY,
                    SubscriptionManager.INVALID_SIM_SLOT_INDEX);
            logd("slotId: " + slotId);
            if (slotId == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
            logd("slotIndex: " + slotIndex);
            if (!SubscriptionManager.isValidSlotIndex(slotIndex)) {
                logd("ACTION_SIM_STATE_CHANGED contains invalid slotIndex: " + slotIndex);
                return;
            }

@@ -204,15 +202,15 @@ public class SubscriptionInfoUpdater extends Handler {
            logd("simStatus: " + simStatus);

            if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
                rebroadcastIntentsOnUnlock.put(slotId, intent);
                rebroadcastIntentsOnUnlock.put(slotIndex, intent);
                if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(simStatus)) {
                    sendMessage(obtainMessage(EVENT_SIM_ABSENT, slotId, -1));
                    sendMessage(obtainMessage(EVENT_SIM_ABSENT, slotIndex, -1));
                } else if (IccCardConstants.INTENT_VALUE_ICC_UNKNOWN.equals(simStatus)) {
                    sendMessage(obtainMessage(EVENT_SIM_UNKNOWN, slotId, -1));
                    sendMessage(obtainMessage(EVENT_SIM_UNKNOWN, slotIndex, -1));
                } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(simStatus)) {
                    sendMessage(obtainMessage(EVENT_SIM_IO_ERROR, slotId, -1));
                    sendMessage(obtainMessage(EVENT_SIM_IO_ERROR, slotIndex, -1));
                } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED.equals(simStatus)) {
                    sendMessage(obtainMessage(EVENT_SIM_RESTRICTED, slotId, -1));
                    sendMessage(obtainMessage(EVENT_SIM_RESTRICTED, slotIndex, -1));
                } else {
                    logd("Ignoring simStatus: " + simStatus);
                }
@@ -220,9 +218,9 @@ public class SubscriptionInfoUpdater extends Handler {
                if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(simStatus)) {
                    String reason = intent.getStringExtra(
                        IccCardConstants.INTENT_KEY_LOCKED_REASON);
                    sendMessage(obtainMessage(EVENT_SIM_LOCKED, slotId, -1, reason));
                    sendMessage(obtainMessage(EVENT_SIM_LOCKED, slotIndex, -1, reason));
                } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus)) {
                    sendMessage(obtainMessage(EVENT_SIM_LOADED, slotId, -1));
                    sendMessage(obtainMessage(EVENT_SIM_LOADED, slotIndex, -1));
                } else {
                    logd("Ignoring simStatus: " + simStatus);
                }
@@ -552,7 +550,7 @@ public class SubscriptionInfoUpdater extends Handler {
            List<SubscriptionInfo> oldSubInfo =
                    SubscriptionController.getInstance().getSubInfoUsingSlotIndexWithCheck(i, false,
                    mContext.getOpPackageName());
            if (oldSubInfo != null) {
            if (oldSubInfo != null && oldSubInfo.size() > 0) {
                oldIccId[i] = oldSubInfo.get(0).getIccId();
                logd("updateSubscriptionInfoByIccId: oldSubId = "
                        + oldSubInfo.get(0).getSubscriptionId());
+43 −52
Original line number Diff line number Diff line
@@ -15,6 +15,18 @@
 */
package com.android.internal.telephony;

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

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
@@ -37,7 +49,6 @@ import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.IccUtils;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -47,17 +58,6 @@ import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.HashMap;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    private static final int FAKE_SUB_ID_1 = 0;
@@ -107,18 +107,13 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
    public void setUp() throws Exception {
        super.setUp(this.getClass().getSimpleName());

        replaceInstance(SubscriptionInfoUpdater.class, "mIccId", null,
                new String[SubscriptionInfoUpdater.STATUS_SIM1_INSERTED]);
        replaceInstance(SubscriptionInfoUpdater.class, "mInsertSimState", null,
                new int[SubscriptionInfoUpdater.STATUS_SIM1_INSERTED]);
        replaceInstance(SubscriptionInfoUpdater.class, "mIccId", null, new String[1]);
        replaceInstance(SubscriptionInfoUpdater.class, "mInsertSimState", null, new int[1]);
        replaceInstance(SubscriptionInfoUpdater.class, "mContext", null, null);
        replaceInstance(SubscriptionInfoUpdater.class, "PROJECT_SIM_NUM", null,
                SubscriptionInfoUpdater.STATUS_SIM1_INSERTED);
        replaceInstance(SubscriptionInfoUpdater.class, "PROJECT_SIM_NUM", null, 1);

        doReturn(SubscriptionInfoUpdater.STATUS_SIM1_INSERTED)
                .when(mTelephonyManager).getSimCount();
        doReturn(SubscriptionInfoUpdater.STATUS_SIM1_INSERTED)
                .when(mTelephonyManager).getPhoneCount();
        doReturn(1).when(mTelephonyManager).getSimCount();
        doReturn(1).when(mTelephonyManager).getPhoneCount();

        doReturn(mUserInfo).when(mIActivityManager).getCurrentUser();
        doReturn(new int[]{FAKE_SUB_ID_1}).when(mSubscriptionController).getSubId(0);
@@ -142,7 +137,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimAbsent() {
    public void testSimAbsent() throws Exception {
        doReturn(Arrays.asList(mSubInfo)).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
        Intent mIntent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
@@ -165,7 +160,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimUnknown() {
    public void testSimUnknown() throws Exception {
        Intent mIntent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        mIntent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_UNKNOWN);
@@ -184,25 +179,25 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimError() {
    public void testSimError() throws Exception {
        Intent mIntent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        mIntent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
        mIntent.putExtra(PhoneConstants.PHONE_KEY, 2);
        mIntent.putExtra(PhoneConstants.PHONE_KEY, 0);

        mContext.sendBroadcast(mIntent);
        waitForMs(100);
        verify(mSubscriptionContent, times(0)).put(anyString(), any());
        CarrierConfigManager mConfigManager = (CarrierConfigManager)
                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        verify(mConfigManager).updateConfigForPhoneId(eq(2),
        verify(mConfigManager).updateConfigForPhoneId(eq(0),
                eq(IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR));
        verify(mSubscriptionController, times(0)).notifySubscriptionInfoChanged();
        verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
    }

    @Test
    @SmallTest
    public void testWrongSimState() {
    public void testWrongSimState() throws Exception {
        Intent mIntent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        mIntent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_IMSI);
@@ -220,7 +215,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimLoaded() {
    public void testSimLoaded() throws Exception {
        /* mock new sim got loaded and there is no sim loaded before */
        doReturn(null).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
@@ -287,7 +282,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimLoadedEmptyOperatorNumeric() {
    public void testSimLoadedEmptyOperatorNumeric() throws Exception {
        /* mock new sim got loaded and there is no sim loaded before */
        doReturn(null).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
@@ -315,7 +310,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimLockedWithOutIccId() {
    public void testSimLockedWithOutIccId() throws Exception {
        /* mock no IccId Info present and try to query IccId
         after IccId query, update subscriptionDB */
        doReturn(mIccFileHandler).when(mIccCardProxy).getIccFileHandler();
@@ -358,9 +353,9 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testDualSimLoaded() {
    public void testDualSimLoaded() throws Exception {
        // Mock there is two sim cards
        try {

        replaceInstance(SubscriptionInfoUpdater.class, "mIccId", null,
                new String[]{null, null});
        replaceInstance(SubscriptionInfoUpdater.class, "PROJECT_SIM_NUM", null, 2);
@@ -369,13 +364,12 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        replaceInstance(SubscriptionInfoUpdater.class, "mInsertSimState", null,
                new int[]{SubscriptionInfoUpdater.SIM_NOT_CHANGE,
                        SubscriptionInfoUpdater.SIM_NOT_CHANGE});
        } catch (Exception ex) {
            Assert.fail("unexpected exception thrown" + ex.getMessage());
        }

        doReturn(new int[]{FAKE_SUB_ID_1, FAKE_SUB_ID_2}).when(mSubscriptionManager)
                .getActiveSubscriptionIdList();
        doReturn(FAKE_SUB_ID_1).when(mSubscriptionController).getPhoneId(eq(FAKE_SUB_ID_1));
        doReturn(FAKE_SUB_ID_2).when(mSubscriptionController).getPhoneId(eq(FAKE_SUB_ID_2));
        doReturn(2).when(mTelephonyManager).getSimCount();
        doReturn(FAKE_MCC_MNC_1).when(mTelephonyManager).getSimOperatorNumeric(eq(FAKE_SUB_ID_1));
        doReturn(FAKE_MCC_MNC_2).when(mTelephonyManager).getSimOperatorNumeric(eq(FAKE_SUB_ID_2));
        // Mock there is no sim inserted before
@@ -416,14 +410,11 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testSimLockWIthIccId() {
    public void testSimLockWIthIccId() throws Exception {
        /* no need for IccId query */
        try {

        replaceInstance(SubscriptionInfoUpdater.class, "mIccId", null,
                new String[]{"89012604200000000000"});
        } catch (Exception ex) {
            Assert.fail("unexpected exception thrown" + ex.getMessage());
        }
        doReturn(mIccFileHandler).when(mIccCardProxy).getIccFileHandler();

        Intent mIntent = new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);