Loading tests/telephonytests/src/com/android/internal/telephony/DefaultPhoneNotifierTest.java +8 −9 Original line number Diff line number Diff line Loading @@ -41,13 +41,12 @@ import android.telephony.VoLteServiceState; import android.telephony.gsm.GsmCellLocation; import android.os.Bundle; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.mocks.TelephonyRegistryMock; public class DefaultPhoneNotifierTest extends TelephonyTest { private DefaultPhoneNotifier mDefaultPhoneNotifierUT; @Mock TelephonyRegistryMock mTelephonyRegisteryMock; ITelephonyRegistry.Stub mTelephonyRegisteryMock; @Mock SignalStrength mSignalStrength; @Mock Loading Loading @@ -135,7 +134,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyMessageWaiting() { public void testNotifyMessageWaiting() throws Exception { doReturn(1).when(mPhone).getPhoneId(); mDefaultPhoneNotifierUT.notifyMessageWaitingChanged(mPhone); verify(mTelephonyRegisteryMock).notifyMessageWaitingChangedForPhoneId(1, 0, false); Loading @@ -154,7 +153,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyDisconnectCause() { public void testNotifyDisconnectCause() throws Exception { mDefaultPhoneNotifierUT.notifyDisconnectCause(DisconnectCause.NOT_VALID, PreciseDisconnectCause.FDN_BLOCKED); verify(mTelephonyRegisteryMock).notifyDisconnectCause(DisconnectCause.NOT_VALID, Loading @@ -167,7 +166,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyDataConnectionFailed() { public void testNotifyDataConnectionFailed() throws Exception { mDefaultPhoneNotifierUT.notifyDataConnectionFailed(mPhone, "BUSY", "APN_0"); verify(mTelephonyRegisteryMock).notifyDataConnectionFailedForSubscriber(0, "BUSY", "APN_0"); Loading @@ -186,7 +185,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyPreciseCallState() { public void testNotifyPreciseCallState() throws Exception { //mock forground/background/ringing call and call state doReturn(Call.State.IDLE).when(mForeGroundCall).getState(); Loading Loading @@ -237,7 +236,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyCellLocation() { public void testNotifyCellLocation() throws Exception { // mock gsm cell location GsmCellLocation mGsmCellLocation = new GsmCellLocation(); mGsmCellLocation.setLacAndCid(2, 3); Loading @@ -263,7 +262,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyOtaspChanged() { public void testNotifyOtaspChanged() throws Exception { mDefaultPhoneNotifierUT.notifyOtaspChanged(mPhone, ServiceStateTracker.OTASP_NEEDED); verify(mTelephonyRegisteryMock).notifyOtaspChanged(ServiceStateTracker.OTASP_NEEDED); Loading @@ -272,7 +271,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyVoLteServiceStateChanged() { public void testNotifyVoLteServiceStateChanged() throws Exception { VoLteServiceState state = new VoLteServiceState(VoLteServiceState.NOT_SUPPORTED); mDefaultPhoneNotifierUT.notifyVoLteServiceStateChanged(mPhone, state); verify(mTelephonyRegisteryMock).notifyVoLteServiceStateChanged(state); Loading tests/telephonytests/src/com/android/internal/telephony/PhoneStateListenerTest.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * 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.internal.telephony; import android.os.HandlerThread; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.test.suitebuilder.annotation.SmallTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.lang.reflect.Field; import static org.mockito.Mockito.verify; public class PhoneStateListenerTest extends TelephonyTest { private PhoneStateListener mPhoneStateListenerUT; private class PhoneStateListenerHandler extends HandlerThread { private PhoneStateListenerHandler(String name) { super(name); } @Override public void onLooperPrepared() { mPhoneStateListenerUT = new PhoneStateListener() { @Override public void onServiceStateChanged(ServiceState serviceState) { logd("Service State Changed"); mServiceState.setVoiceRegState(serviceState.getVoiceRegState()); mServiceState.setDataRegState(serviceState.getDataRegState()); setReady(true); } }; setReady(true); } } @Before public void setUp() throws Exception { this.setUp(this.getClass().getSimpleName()); new PhoneStateListenerHandler(TAG).start(); waitUntilReady(); } @After public void tearDown() throws Exception { super.tearDown(); } @Test @SmallTest public void testTriggerServiceStateChanged() throws Exception { Field field = PhoneStateListener.class.getDeclaredField("callback"); field.setAccessible(true); ServiceState ss = new ServiceState(); ss.setDataRegState(ServiceState.STATE_IN_SERVICE); ss.setVoiceRegState(ServiceState.STATE_EMERGENCY_ONLY); setReady(false); ((IPhoneStateListener) field.get(mPhoneStateListenerUT)).onServiceStateChanged(ss); waitUntilReady(); verify(mServiceState).setDataRegState(ServiceState.STATE_IN_SERVICE); verify(mServiceState).setVoiceRegState(ServiceState.STATE_EMERGENCY_ONLY); } } tests/telephonytests/src/com/android/internal/telephony/mocks/TelephonyRegistryMock.java +1 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.internal.telephony.mocks; import android.content.Context; import android.content.Intent; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.os.Bundle; Loading @@ -25,7 +23,6 @@ import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.CellInfo; import android.telephony.DataConnectionRealTimeInfo; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SubscriptionManager; Loading Loading
tests/telephonytests/src/com/android/internal/telephony/DefaultPhoneNotifierTest.java +8 −9 Original line number Diff line number Diff line Loading @@ -41,13 +41,12 @@ import android.telephony.VoLteServiceState; import android.telephony.gsm.GsmCellLocation; import android.os.Bundle; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.mocks.TelephonyRegistryMock; public class DefaultPhoneNotifierTest extends TelephonyTest { private DefaultPhoneNotifier mDefaultPhoneNotifierUT; @Mock TelephonyRegistryMock mTelephonyRegisteryMock; ITelephonyRegistry.Stub mTelephonyRegisteryMock; @Mock SignalStrength mSignalStrength; @Mock Loading Loading @@ -135,7 +134,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyMessageWaiting() { public void testNotifyMessageWaiting() throws Exception { doReturn(1).when(mPhone).getPhoneId(); mDefaultPhoneNotifierUT.notifyMessageWaitingChanged(mPhone); verify(mTelephonyRegisteryMock).notifyMessageWaitingChangedForPhoneId(1, 0, false); Loading @@ -154,7 +153,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyDisconnectCause() { public void testNotifyDisconnectCause() throws Exception { mDefaultPhoneNotifierUT.notifyDisconnectCause(DisconnectCause.NOT_VALID, PreciseDisconnectCause.FDN_BLOCKED); verify(mTelephonyRegisteryMock).notifyDisconnectCause(DisconnectCause.NOT_VALID, Loading @@ -167,7 +166,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyDataConnectionFailed() { public void testNotifyDataConnectionFailed() throws Exception { mDefaultPhoneNotifierUT.notifyDataConnectionFailed(mPhone, "BUSY", "APN_0"); verify(mTelephonyRegisteryMock).notifyDataConnectionFailedForSubscriber(0, "BUSY", "APN_0"); Loading @@ -186,7 +185,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyPreciseCallState() { public void testNotifyPreciseCallState() throws Exception { //mock forground/background/ringing call and call state doReturn(Call.State.IDLE).when(mForeGroundCall).getState(); Loading Loading @@ -237,7 +236,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyCellLocation() { public void testNotifyCellLocation() throws Exception { // mock gsm cell location GsmCellLocation mGsmCellLocation = new GsmCellLocation(); mGsmCellLocation.setLacAndCid(2, 3); Loading @@ -263,7 +262,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyOtaspChanged() { public void testNotifyOtaspChanged() throws Exception { mDefaultPhoneNotifierUT.notifyOtaspChanged(mPhone, ServiceStateTracker.OTASP_NEEDED); verify(mTelephonyRegisteryMock).notifyOtaspChanged(ServiceStateTracker.OTASP_NEEDED); Loading @@ -272,7 +271,7 @@ public class DefaultPhoneNotifierTest extends TelephonyTest { } @Test @SmallTest public void testNotifyVoLteServiceStateChanged() { public void testNotifyVoLteServiceStateChanged() throws Exception { VoLteServiceState state = new VoLteServiceState(VoLteServiceState.NOT_SUPPORTED); mDefaultPhoneNotifierUT.notifyVoLteServiceStateChanged(mPhone, state); verify(mTelephonyRegisteryMock).notifyVoLteServiceStateChanged(state); Loading
tests/telephonytests/src/com/android/internal/telephony/PhoneStateListenerTest.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * 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.internal.telephony; import android.os.HandlerThread; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.test.suitebuilder.annotation.SmallTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.lang.reflect.Field; import static org.mockito.Mockito.verify; public class PhoneStateListenerTest extends TelephonyTest { private PhoneStateListener mPhoneStateListenerUT; private class PhoneStateListenerHandler extends HandlerThread { private PhoneStateListenerHandler(String name) { super(name); } @Override public void onLooperPrepared() { mPhoneStateListenerUT = new PhoneStateListener() { @Override public void onServiceStateChanged(ServiceState serviceState) { logd("Service State Changed"); mServiceState.setVoiceRegState(serviceState.getVoiceRegState()); mServiceState.setDataRegState(serviceState.getDataRegState()); setReady(true); } }; setReady(true); } } @Before public void setUp() throws Exception { this.setUp(this.getClass().getSimpleName()); new PhoneStateListenerHandler(TAG).start(); waitUntilReady(); } @After public void tearDown() throws Exception { super.tearDown(); } @Test @SmallTest public void testTriggerServiceStateChanged() throws Exception { Field field = PhoneStateListener.class.getDeclaredField("callback"); field.setAccessible(true); ServiceState ss = new ServiceState(); ss.setDataRegState(ServiceState.STATE_IN_SERVICE); ss.setVoiceRegState(ServiceState.STATE_EMERGENCY_ONLY); setReady(false); ((IPhoneStateListener) field.get(mPhoneStateListenerUT)).onServiceStateChanged(ss); waitUntilReady(); verify(mServiceState).setDataRegState(ServiceState.STATE_IN_SERVICE); verify(mServiceState).setVoiceRegState(ServiceState.STATE_EMERGENCY_ONLY); } }
tests/telephonytests/src/com/android/internal/telephony/mocks/TelephonyRegistryMock.java +1 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.internal.telephony.mocks; import android.content.Context; import android.content.Intent; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.os.Bundle; Loading @@ -25,7 +23,6 @@ import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.CellInfo; import android.telephony.DataConnectionRealTimeInfo; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SubscriptionManager; Loading