blob: a35f64bf8e1ddf4dd1b53aaf81ecedd6b214f386 [file] [log] [blame]
/*
* Copyright (C) 2019 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 org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import android.os.Message;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class CarrierServiceBindHelperTest extends TelephonyTest {
CarrierServiceBindHelper mCarrierServiceBindHelper;
@Before
public void setUp() throws Exception {
super.setUp(getClass().getSimpleName());
doReturn(1).when(mTelephonyManager).getActiveModemCount();
}
@After
public void tearDown() throws Exception {
// Restore system properties.
super.tearDown();
}
@Test
@SmallTest
public void testMultiSimConfigChanged() throws Exception {
clearInvocations(mPhoneConfigurationManager);
mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext);
assertEquals(1, mCarrierServiceBindHelper.mBindings.size());
assertEquals(1, mCarrierServiceBindHelper.mLastSimState.size());
assertNotNull(mCarrierServiceBindHelper.mBindings.get(0));
assertNotNull(mCarrierServiceBindHelper.mLastSimState.get(0));
// Verify registration of EVENT_MULTI_SIM_CONFIG_CHANGED.
doReturn(2).when(mTelephonyManager).getActiveModemCount();
PhoneConfigurationManager.notifyMultiSimConfigChange(2);
processAllMessages();
assertEquals(2, mCarrierServiceBindHelper.mBindings.size());
assertEquals(2, mCarrierServiceBindHelper.mLastSimState.size());
assertNotNull(mCarrierServiceBindHelper.mBindings.get(0));
assertNotNull(mCarrierServiceBindHelper.mBindings.get(1));
assertNotNull(mCarrierServiceBindHelper.mLastSimState.get(0));
assertNotNull(mCarrierServiceBindHelper.mLastSimState.get(1));
// Switch back to single SIM.
doReturn(1).when(mTelephonyManager).getActiveModemCount();
PhoneConfigurationManager.notifyMultiSimConfigChange(1);
processAllMessages();
assertEquals(1, mCarrierServiceBindHelper.mBindings.size());
assertEquals(1, mCarrierServiceBindHelper.mLastSimState.size());
assertNotNull(mCarrierServiceBindHelper.mBindings.get(0));
assertNotNull(mCarrierServiceBindHelper.mLastSimState.get(0));
}
@Test
public void testUnbindWhenNotBound() throws Exception {
mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext);
// Try unbinding without binding and make sure we don't throw an Exception
mCarrierServiceBindHelper.mHandler.handleMessage(
Message.obtain(mCarrierServiceBindHelper.mHandler,
CarrierServiceBindHelper.EVENT_PERFORM_IMMEDIATE_UNBIND,
new Integer(0)));
}
}