blob: 479acb7b11ff6d158ed7274e9c4ba158cbc4af17 [file] [log] [blame]
/*
* Copyright (C) 2017 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.uicc;
import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
import android.os.HandlerThread;
import android.support.test.filters.FlakyTest;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
import com.android.internal.telephony.uicc.IccCardStatus.CardState;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;
public class IccCardProxyTest extends TelephonyTest {
private IccCardProxy mIccCardProxyUT;
// private UiccCard mUiccCard;
private IccCardProxyHandlerThread mIccCardProxyHandlerThread;
private static final int PHONE_ID = 0;
private static final int PHONE_COUNT = 1;
private static final int SCARY_SLEEP_MS = 200;
// Must match IccCardProxy.EVENT_ICC_CHANGED
private static final int EVENT_ICC_CHANGED = 3;
@Mock private IccCardStatus mIccCardStatus;
@Mock private UiccCard mUiccCard;
@Mock private UiccCardApplication mUiccCardApplication;
private class IccCardProxyHandlerThread extends HandlerThread {
private IccCardProxyHandlerThread(String name) {
super(name);
}
@Override
public void onLooperPrepared() {
/* create a new UICC Controller associated with the simulated Commands */
mIccCardProxyUT = new IccCardProxy(mContext, mSimulatedCommands, PHONE_ID);
setReady(true);
}
}
@Before
public void setUp() throws Exception {
super.setUp(this.getClass().getSimpleName());
doReturn(PHONE_COUNT).when(mTelephonyManager).getPhoneCount();
doReturn(PHONE_COUNT).when(mTelephonyManager).getSimCount();
mSimulatedCommands.setIccCardStatus(mIccCardStatus);
mIccCardProxyHandlerThread = new IccCardProxyHandlerThread(TAG);
mIccCardProxyHandlerThread.start();
waitUntilReady();
}
@After
public void tearDown() throws Exception {
mIccCardProxyHandlerThread.quitSafely();
super.tearDown();
}
@Test
@SmallTest
public void testInitialCardState() {
assertEquals(mIccCardProxyUT.getState(), State.UNKNOWN);
}
@Test
@Ignore
@FlakyTest
@SmallTest
public void testPowerOn() {
mSimulatedCommands.setRadioPower(true, null);
mSimulatedCommands.notifyRadioOn();
doReturn(mUiccCard).when(mUiccController).getUiccCard(anyInt());
mIccCardProxyUT.sendMessage(mIccCardProxyUT.obtainMessage(EVENT_ICC_CHANGED));
waitForMs(SCARY_SLEEP_MS);
assertEquals(CommandsInterface.RadioState.RADIO_ON, mSimulatedCommands.getRadioState());
assertEquals(mIccCardProxyUT.getState(), State.NOT_READY);
logd("IccCardProxy state = " + mIccCardProxyUT.getState());
}
@Test
@Ignore
@FlakyTest
@SmallTest
public void testCardLoaded() {
testPowerOn();
doReturn(CardState.CARDSTATE_PRESENT).when(mUiccCard).getCardState();
mIccCardProxyUT.sendMessage(mIccCardProxyUT.obtainMessage(EVENT_ICC_CHANGED));
waitForMs(SCARY_SLEEP_MS);
assertEquals(mIccCardProxyUT.getState(), State.NOT_READY);
}
@Test
@Ignore
@FlakyTest
@SmallTest
public void testAppNotLoaded() {
testPowerOn();
doReturn(CardState.CARDSTATE_PRESENT).when(mUiccCard).getCardState();
mIccCardProxyUT.sendMessage(mIccCardProxyUT.obtainMessage(EVENT_ICC_CHANGED));
doReturn(AppState.APPSTATE_UNKNOWN).when(mUiccCardApplication).getState();
doReturn(mUiccCardApplication).when(mUiccCard).getApplication(anyInt());
waitForMs(SCARY_SLEEP_MS);
assertEquals(mIccCardProxyUT.getState(), State.NOT_READY);
}
@Test
@Ignore
@FlakyTest
@SmallTest
public void testAppReady() {
testPowerOn();
doReturn(CardState.CARDSTATE_PRESENT).when(mUiccCard).getCardState();
mIccCardProxyUT.sendMessage(mIccCardProxyUT.obtainMessage(EVENT_ICC_CHANGED));
doReturn(AppState.APPSTATE_READY).when(mUiccCardApplication).getState();
doReturn(mUiccCardApplication).when(mUiccCard).getApplication(anyInt());
waitForMs(SCARY_SLEEP_MS);
assertEquals(mIccCardProxyUT.getState(), State.READY);
}
}