| /* |
| * Copyright (C) 2016 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.services.telephony; |
| |
| import android.telephony.RadioAccessFamily; |
| import android.telephony.ServiceState; |
| import android.support.test.runner.AndroidJUnit4; |
| import android.telephony.TelephonyManager; |
| import android.test.suitebuilder.annotation.SmallTest; |
| |
| import com.android.TelephonyTestBase; |
| import com.android.internal.telephony.Phone; |
| |
| import org.junit.After; |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.mockito.Mock; |
| |
| import static junit.framework.Assert.assertEquals; |
| import static org.mockito.Matchers.eq; |
| import static org.mockito.Mockito.mock; |
| import static org.mockito.Mockito.when; |
| |
| /** |
| * Unit tests for TelephonyConnectionService. |
| */ |
| |
| @RunWith(AndroidJUnit4.class) |
| public class TelephonyConnectionServiceTest extends TelephonyTestBase { |
| |
| private static final int SLOT_0_PHONE_ID = 0; |
| private static final int SLOT_1_PHONE_ID = 1; |
| |
| @Mock TelephonyConnectionService.TelephonyManagerProxy mTelephonyManagerProxy; |
| @Mock TelephonyConnectionService.SubscriptionManagerProxy mSubscriptionManagerProxy; |
| @Mock TelephonyConnectionService.PhoneFactoryProxy mPhoneFactoryProxy; |
| |
| TelephonyConnectionService mTestConnectionService; |
| |
| @Before |
| public void setUp() throws Exception { |
| super.setUp(); |
| mTestConnectionService = new TelephonyConnectionService(); |
| mTestConnectionService.setPhoneFactoryProxy(mPhoneFactoryProxy); |
| mTestConnectionService.setTelephonyManagerProxy(mTelephonyManagerProxy); |
| mTestConnectionService.setSubscriptionManagerProxy(mSubscriptionManagerProxy); |
| } |
| |
| @After |
| public void tearDown() throws Exception { |
| mTestConnectionService = null; |
| super.tearDown(); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Users default Voice SIM choice is IN_SERVICE |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the default Voice SIM choice. |
| */ |
| @Test |
| @SmallTest |
| public void testDefaultVoiceSimInService() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_IN_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| true /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 0 is OUT_OF_SERVICE, Slot 1 is OUT_OF_SERVICE (emergency calls only) |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone |
| */ |
| @Test |
| @SmallTest |
| public void testSlot1EmergencyOnly() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| true /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 0 is OUT_OF_SERVICE, Slot 1 is IN_SERVICE |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone |
| */ |
| @Test |
| @SmallTest |
| public void testSlot1InService() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_IN_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 0 is PUK locked, Slot 1 is ready |
| * - Slot 0 is LTE capable, Slot 1 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone. Although Slot 0 is more |
| * capable, it is locked, so use the other slot. |
| */ |
| @Test |
| @SmallTest |
| public void testSlot0PukLocked() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| // Set Slot 0 to be PUK locked |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_PUK_REQUIRED); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| // Make Slot 0 higher capability |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_GSM); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 0 is PIN locked, Slot 1 is ready |
| * - Slot 0 is LTE capable, Slot 1 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone. Although Slot 0 is more |
| * capable, it is locked, so use the other slot. |
| */ |
| @Test |
| @SmallTest |
| public void testSlot0PinLocked() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| // Set Slot 0 to be PUK locked |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_PIN_REQUIRED); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| // Make Slot 0 higher capability |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_GSM); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 1 is PUK locked, Slot 0 is ready |
| * - Slot 1 is LTE capable, Slot 0 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 0 phone. Although Slot 1 is more |
| * capable, it is locked, so use the other slot. |
| */ |
| @Test |
| @SmallTest |
| public void testSlot1PukLocked() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| // Set Slot 1 to be PUK locked |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_PUK_REQUIRED); |
| // Make Slot 1 higher capability |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_GSM); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 1 is PIN locked, Slot 0 is ready |
| * - Slot 1 is LTE capable, Slot 0 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 0 phone. Although Slot 1 is more |
| * capable, it is locked, so use the other slot. |
| */ |
| @Test |
| @SmallTest |
| public void testSlot1PinLocked() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| // Set Slot 1 to be PUK locked |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_PIN_REQUIRED); |
| // Make Slot 1 higher capability |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_GSM); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 1 is LTE capable, Slot 0 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone because it is more capable |
| */ |
| @Test |
| @SmallTest |
| public void testSlot1HigherCapablity() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| // Make Slot 1 higher capability |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_GSM); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Slot 1 is GSM/LTE capable, Slot 0 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone because it has more |
| * capabilities. |
| */ |
| @Test |
| @SmallTest |
| public void testSlot1MoreCapabilities() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| // Make Slot 1 more capable |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, |
| RadioAccessFamily.RAF_GSM | RadioAccessFamily.RAF_LTE); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Both SIMs PUK Locked |
| * - Slot 0 is LTE capable, Slot 1 is GSM capable |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 0 phone because it is more capable, |
| * ignoring that both SIMs are PUK locked. |
| */ |
| @Test |
| @SmallTest |
| public void testSlot0MoreCapableBothPukLocked() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_PUK_REQUIRED); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_PUK_REQUIRED); |
| // Make Slot 0 higher capability |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_GSM); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, two slots with SIMs inserted |
| * - Both SIMs have the same capability |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 0 phone because it is the first slot. |
| */ |
| @Test |
| @SmallTest |
| public void testEqualCapabilityTwoSimsInserted() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| // Make Capability the same |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| // Two SIMs inserted |
| setSlotHasIccCard(SLOT_0_PHONE_ID, true /*isInserted*/); |
| setSlotHasIccCard(SLOT_1_PHONE_ID, true /*isInserted*/); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, only slot 0 inserted |
| * - Both SIMs have the same capability |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 0 phone because it is the only one |
| * with a SIM inserted |
| */ |
| @Test |
| @SmallTest |
| public void testEqualCapabilitySim0Inserted() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_ABSENT); |
| // Make Capability the same |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| // Slot 0 has SIM inserted. |
| setSlotHasIccCard(SLOT_0_PHONE_ID, true /*isInserted*/); |
| setSlotHasIccCard(SLOT_1_PHONE_ID, false /*isInserted*/); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, only slot 1 inserted |
| * - Both SIMs have the same capability |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone because it is the only one |
| * with a SIM inserted |
| */ |
| @Test |
| @SmallTest |
| public void testEqualCapabilitySim1Inserted() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_ABSENT); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_READY); |
| // Make Capability the same |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_LTE); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| // Slot 1 has SIM inserted. |
| setSlotHasIccCard(SLOT_0_PHONE_ID, false /*isInserted*/); |
| setSlotHasIccCard(SLOT_1_PHONE_ID, true /*isInserted*/); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, no SIMs inserted |
| * - SIM 1 has the higher capability |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 1 phone, since it is a higher |
| * capability |
| */ |
| @Test |
| @SmallTest |
| public void testSim1HigherCapabilityNoSimsInserted() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_ABSENT); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_ABSENT); |
| // Make Capability the same |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_GSM); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_LTE); |
| // No SIMs inserted |
| setSlotHasIccCard(SLOT_0_PHONE_ID, false /*isInserted*/); |
| setSlotHasIccCard(SLOT_1_PHONE_ID, false /*isInserted*/); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot1Phone, resultPhone); |
| } |
| |
| /** |
| * Prerequisites: |
| * - MSIM Device, no SIMs inserted |
| * - Both SIMs have the same capability (Unknown) |
| * |
| * Result: getFirstPhoneForEmergencyCall returns the slot 0 phone, since it is the first slot. |
| */ |
| @Test |
| @SmallTest |
| public void testEqualCapabilityNoSimsInserted() { |
| Phone slot0Phone = makeTestPhone(SLOT_0_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| Phone slot1Phone = makeTestPhone(SLOT_1_PHONE_ID, ServiceState.STATE_OUT_OF_SERVICE, |
| false /*isEmergencyOnly*/); |
| setDefaultPhone(slot0Phone); |
| setupDeviceConfig(slot0Phone, slot1Phone, SLOT_0_PHONE_ID); |
| setPhoneSlotState(SLOT_0_PHONE_ID, TelephonyManager.SIM_STATE_ABSENT); |
| setPhoneSlotState(SLOT_1_PHONE_ID, TelephonyManager.SIM_STATE_ABSENT); |
| // Make Capability the same |
| setPhoneRadioAccessFamily(slot0Phone, RadioAccessFamily.RAF_UNKNOWN); |
| setPhoneRadioAccessFamily(slot1Phone, RadioAccessFamily.RAF_UNKNOWN); |
| // No SIMs inserted |
| setSlotHasIccCard(SLOT_0_PHONE_ID, false /*isInserted*/); |
| setSlotHasIccCard(SLOT_1_PHONE_ID, false /*isInserted*/); |
| |
| Phone resultPhone = mTestConnectionService.getFirstPhoneForEmergencyCall(); |
| |
| assertEquals(slot0Phone, resultPhone); |
| } |
| |
| private Phone makeTestPhone(int phoneId, int serviceState, boolean isEmergencyOnly) { |
| Phone phone = mock(Phone.class); |
| ServiceState testServiceState = new ServiceState(); |
| testServiceState.setState(serviceState); |
| testServiceState.setEmergencyOnly(isEmergencyOnly); |
| when(phone.getServiceState()).thenReturn(testServiceState); |
| when(phone.getPhoneId()).thenReturn(phoneId); |
| return phone; |
| } |
| |
| // Setup 2 SIM device |
| private void setupDeviceConfig(Phone slot0Phone, Phone slot1Phone, int defaultVoicePhoneId) { |
| when(mTelephonyManagerProxy.getPhoneCount()).thenReturn(2); |
| when(mSubscriptionManagerProxy.getDefaultVoicePhoneId()).thenReturn(defaultVoicePhoneId); |
| when(mPhoneFactoryProxy.getPhone(eq(SLOT_0_PHONE_ID))).thenReturn(slot0Phone); |
| when(mPhoneFactoryProxy.getPhone(eq(SLOT_1_PHONE_ID))).thenReturn(slot1Phone); |
| } |
| |
| private void setPhoneRadioAccessFamily(Phone phone, int radioAccessFamily) { |
| when(phone.getRadioAccessFamily()).thenReturn(radioAccessFamily); |
| } |
| |
| private void setPhoneSlotState(int slotId, int slotState) { |
| when(mSubscriptionManagerProxy.getSimStateForSlotIdx(slotId)).thenReturn(slotState); |
| } |
| |
| private void setSlotHasIccCard(int slotId, boolean isInserted) { |
| when(mTelephonyManagerProxy.hasIccCard(slotId)).thenReturn(isInserted); |
| } |
| |
| private void setDefaultPhone(Phone phone) { |
| when(mPhoneFactoryProxy.getDefaultPhone()).thenReturn(phone); |
| } |
| } |