1ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu/* 2ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * Copyright (C) 2016 The Android Open Source Project 3ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * 4ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * Licensed under the Apache License, Version 2.0 (the "License"); 5ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * you may not use this file except in compliance with the License. 6ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * You may obtain a copy of the License at 7ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * 8ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * http://www.apache.org/licenses/LICENSE-2.0 9ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * 10ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * Unless required by applicable law or agreed to in writing, software 11ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * distributed under the License is distributed on an "AS IS" BASIS, 12ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * See the License for the specific language governing permissions and 14ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu * limitations under the License. 15ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu */ 16ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxupackage com.android.internal.telephony; 17ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 18ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport org.junit.After; 19ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport org.junit.Before; 20ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport org.junit.Test; 21ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport org.mockito.Mock; 22ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 23ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport java.util.List; 24ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport java.util.ArrayList; 25ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 26ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport static org.mockito.Matchers.anyString; 27ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport static org.mockito.Matchers.eq; 28ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport static org.mockito.Mockito.doReturn; 29ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport static org.junit.Assert.assertEquals; 30ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport static org.mockito.Mockito.verify; 31efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport static org.mockito.Mockito.anyInt; 32efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport static org.mockito.Mockito.times; 33ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport org.mockito.ArgumentCaptor; 34ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport android.telephony.CellInfo; 35efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport android.telephony.DisconnectCause; 36efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport android.telephony.PreciseCallState; 37efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport android.telephony.PreciseDisconnectCause; 38ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport android.telephony.SignalStrength; 39ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport android.telephony.TelephonyManager; 40efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport android.telephony.VoLteServiceState; 41efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport android.telephony.gsm.GsmCellLocation; 42efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxuimport android.os.Bundle; 438e2a1c76f67ebaeebd8401c4ebf7d0515b522d5eSooraj Sasindranimport android.os.Process; 448e2a1c76f67ebaeebd8401c4ebf7d0515b522d5eSooraj Sasindranimport android.os.WorkSource; 45ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxuimport android.test.suitebuilder.annotation.SmallTest; 46ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 47ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxupublic class DefaultPhoneNotifierTest extends TelephonyTest { 48ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 49ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu private DefaultPhoneNotifier mDefaultPhoneNotifierUT; 50ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Mock 51d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu ITelephonyRegistry.Stub mTelephonyRegisteryMock; 52ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Mock 53ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu SignalStrength mSignalStrength; 54ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Mock 55ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu CellInfo mCellInfo; 56efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Mock 57efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu GsmCdmaCall mForeGroundCall; 58efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Mock 59efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu GsmCdmaCall mBackGroundCall; 60efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Mock 61efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu GsmCdmaCall mRingingCall; 62ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 63ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Before 64ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu public void setUp() throws Exception { 65ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu super.setUp(getClass().getSimpleName()); 66ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mServiceManagerMockedServices.put("telephony.registry", mTelephonyRegisteryMock); 67ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(mTelephonyRegisteryMock).when(mTelephonyRegisteryMock) 68ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu .queryLocalInterface(anyString()); 69ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 70ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT = new DefaultPhoneNotifier(); 71ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu } 72ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 73ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @After 74ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu public void tearDown() throws Exception { 75ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu super.tearDown(); 76ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu } 77ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 78ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Test @SmallTest 79ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu public void testNotifyCallForwarding() throws Exception { 80ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifyCallForwardingChanged(mPhone); 81ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu verify(mTelephonyRegisteryMock).notifyCallForwardingChangedForSubscriber(eq(0), eq(false)); 82ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 83ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(true).when(mPhone).getCallForwardingIndicator(); 84ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(1).when(mPhone).getSubId(); 85ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifyCallForwardingChanged(mPhone); 86ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu verify(mTelephonyRegisteryMock).notifyCallForwardingChangedForSubscriber(eq(1), eq(true)); 87ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu } 88ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 89ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Test @SmallTest 90ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu public void testNotifyDataActivity() throws Exception { 91ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu //mock data activity state 92ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(Phone.DataActivityState.NONE).when(mPhone).getDataActivityState(); 93ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifyDataActivity(mPhone); 94ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu verify(mTelephonyRegisteryMock).notifyDataActivityForSubscriber(eq(0), 95ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu eq(TelephonyManager.DATA_ACTIVITY_NONE)); 96ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 97ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(1).when(mPhone).getSubId(); 98ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(Phone.DataActivityState.DATAIN).when(mPhone).getDataActivityState(); 99ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifyDataActivity(mPhone); 100ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu verify(mTelephonyRegisteryMock).notifyDataActivityForSubscriber(eq(1), 101ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu eq(TelephonyManager.DATA_ACTIVITY_IN)); 102ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu } 103ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 104ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Test @SmallTest 105ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu public void testNotifySignalStrength() throws Exception { 106ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu //mock signal strength value 107ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(99).when(mSignalStrength).getGsmSignalStrength(); 108ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(mSignalStrength).when(mPhone).getSignalStrength(); 109ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu ArgumentCaptor<SignalStrength> signalStrengthArgumentCaptor = 110ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu ArgumentCaptor.forClass(SignalStrength.class); 111ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 112ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifySignalStrength(mPhone); 113bd3158360ca73324921350a1c61336af7f9c6d8dShishir Agrawal verify(mTelephonyRegisteryMock).notifySignalStrengthForPhoneId(eq(0), eq(0), 114ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu signalStrengthArgumentCaptor.capture()); 115ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu assertEquals(99, signalStrengthArgumentCaptor.getValue().getGsmSignalStrength()); 116ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 117ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu doReturn(1).when(mPhone).getSubId(); 118bd3158360ca73324921350a1c61336af7f9c6d8dShishir Agrawal doReturn(2).when(mPhone).getPhoneId(); 119ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifySignalStrength(mPhone); 120bd3158360ca73324921350a1c61336af7f9c6d8dShishir Agrawal verify(mTelephonyRegisteryMock).notifySignalStrengthForPhoneId(eq(2), eq(1), 121ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu signalStrengthArgumentCaptor.capture()); 122ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu assertEquals(99, signalStrengthArgumentCaptor.getValue().getGsmSignalStrength()); 123ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu } 124ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 125ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu @Test @SmallTest 126ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu public void testNotifyCellInfo() throws Exception { 127ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu //mock cellinfo 128ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu List<CellInfo> mCellInfoList = new ArrayList<>(); 129ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mCellInfoList.add(mCellInfo); 130ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu ArgumentCaptor<List> cellInfoArgumentCaptor = ArgumentCaptor.forClass(List.class); 131ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 132ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu mDefaultPhoneNotifierUT.notifyCellInfo(mPhone, mCellInfoList); 133ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 134ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu verify(mTelephonyRegisteryMock).notifyCellInfoForSubscriber(eq(0), 135ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu cellInfoArgumentCaptor.capture()); 136ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu assertEquals(mCellInfo, cellInfoArgumentCaptor.getValue().get(0)); 137ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu } 138ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu 139efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 140d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyMessageWaiting() throws Exception { 141efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(1).when(mPhone).getPhoneId(); 142efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyMessageWaitingChanged(mPhone); 143efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyMessageWaitingChangedForPhoneId(1, 0, false); 144efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 145efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(2).when(mPhone).getPhoneId(); 146efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyMessageWaitingChanged(mPhone); 147efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyMessageWaitingChangedForPhoneId(2, 0, false); 148efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 149efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(1).when(mPhone).getSubId(); 150efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyMessageWaitingChanged(mPhone); 151efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyMessageWaitingChangedForPhoneId(2, 1, false); 152efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 153efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(true).when(mPhone).getMessageWaitingIndicator(); 154efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyMessageWaitingChanged(mPhone); 155efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyMessageWaitingChangedForPhoneId(2, 1, true); 156efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 157efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 158efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 159d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyDisconnectCause() throws Exception { 160efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyDisconnectCause(DisconnectCause.NOT_VALID, 161efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseDisconnectCause.FDN_BLOCKED); 162efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyDisconnectCause(DisconnectCause.NOT_VALID, 163efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseDisconnectCause.FDN_BLOCKED); 164efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 165efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyDisconnectCause(DisconnectCause.LOCAL, 166efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseDisconnectCause.CHANNEL_NOT_AVAIL); 167efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyDisconnectCause(DisconnectCause.LOCAL, 168efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseDisconnectCause.CHANNEL_NOT_AVAIL); 169efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 170efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 171efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 172d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyDataConnectionFailed() throws Exception { 173efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyDataConnectionFailed(mPhone, "BUSY", "APN_0"); 174efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyDataConnectionFailedForSubscriber(0, "BUSY", "APN_0"); 175efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 176efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyDataConnectionFailed(mPhone, "LOCAL", "APN_0"); 177efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyDataConnectionFailedForSubscriber(0, "LOCAL", 178efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu "APN_0"); 179efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 180efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyDataConnectionFailed(mPhone, "LOCAL", "APN_1"); 181efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyDataConnectionFailedForSubscriber(0, "LOCAL", 182efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu "APN_1"); 183efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 184efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(1).when(mPhone).getSubId(); 185efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyDataConnectionFailed(mPhone, "LOCAL", "APN_1"); 186efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyDataConnectionFailedForSubscriber(1, "LOCAL", 187efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu "APN_1"); 188efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 189efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 190efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 191d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyPreciseCallState() throws Exception { 192efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 193efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu //mock forground/background/ringing call and call state 194efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(Call.State.IDLE).when(mForeGroundCall).getState(); 195efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(Call.State.IDLE).when(mBackGroundCall).getState(); 196efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(Call.State.IDLE).when(mRingingCall).getState(); 197efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 198efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 199efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(0)).notifyPreciseCallState(anyInt(), anyInt(), 200efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu anyInt()); 201efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 202efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(mForeGroundCall).when(mPhone).getForegroundCall(); 203efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 204efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(0)).notifyPreciseCallState(anyInt(), anyInt(), 205efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu anyInt()); 206efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 207efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(mBackGroundCall).when(mPhone).getBackgroundCall(); 208efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 209efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(0)).notifyPreciseCallState(anyInt(), anyInt(), 210efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu anyInt()); 211efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 212efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(mRingingCall).when(mPhone).getRingingCall(); 213efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 214efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(1)).notifyPreciseCallState( 215efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_IDLE, 216efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_IDLE, 217efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_IDLE); 218efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 219efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(Call.State.ACTIVE).when(mForeGroundCall).getState(); 220efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 221efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(1)).notifyPreciseCallState( 222efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_IDLE, 223efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_ACTIVE, 224efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_IDLE); 225efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 226efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(Call.State.HOLDING).when(mBackGroundCall).getState(); 227efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 228efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(1)).notifyPreciseCallState( 229efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_IDLE, 230efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_ACTIVE, 231efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_HOLDING); 232efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 233efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(Call.State.ALERTING).when(mRingingCall).getState(); 234efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyPreciseCallState(mPhone); 235efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock, times(1)).notifyPreciseCallState( 236efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_ALERTING, 237efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_ACTIVE, 238efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu PreciseCallState.PRECISE_CALL_STATE_HOLDING); 239efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 240efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 241efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 242d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyCellLocation() throws Exception { 243efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu // mock gsm cell location 244efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu GsmCellLocation mGsmCellLocation = new GsmCellLocation(); 245efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mGsmCellLocation.setLacAndCid(2, 3); 246efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(mGsmCellLocation).when(mPhone).getCellLocation(); 247efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu ArgumentCaptor<Bundle> cellLocationCapture = 248efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu ArgumentCaptor.forClass(Bundle.class); 249efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 250efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyCellLocation(mPhone); 251efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyCellLocationForSubscriber(eq(0), 252efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu cellLocationCapture.capture()); 253efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu assertEquals(2, cellLocationCapture.getValue().getInt("lac")); 254efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu assertEquals(3, cellLocationCapture.getValue().getInt("cid")); 255efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu assertEquals(-1, cellLocationCapture.getValue().getInt("psc")); 256efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 257efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu doReturn(1).when(mPhone).getSubId(); 258efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mGsmCellLocation.setPsc(5); 259efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyCellLocation(mPhone); 260efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyCellLocationForSubscriber(eq(1), 261efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu cellLocationCapture.capture()); 262efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu assertEquals(2, cellLocationCapture.getValue().getInt("lac")); 263efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu assertEquals(3, cellLocationCapture.getValue().getInt("cid")); 264efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu assertEquals(5, cellLocationCapture.getValue().getInt("psc")); 265efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 266efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 267efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 268d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyOtaspChanged() throws Exception { 2696432c2f4a4f438b72fa0d4b51d5098b179935868Nathan Harold mDefaultPhoneNotifierUT.notifyOtaspChanged(mPhone, TelephonyManager.OTASP_NEEDED); 2706432c2f4a4f438b72fa0d4b51d5098b179935868Nathan Harold verify(mTelephonyRegisteryMock).notifyOtaspChanged(TelephonyManager.OTASP_NEEDED); 271efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 2726432c2f4a4f438b72fa0d4b51d5098b179935868Nathan Harold mDefaultPhoneNotifierUT.notifyOtaspChanged(mPhone, TelephonyManager.OTASP_UNKNOWN); 2736432c2f4a4f438b72fa0d4b51d5098b179935868Nathan Harold verify(mTelephonyRegisteryMock).notifyOtaspChanged(TelephonyManager.OTASP_UNKNOWN); 274efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 275efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 276efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu @Test @SmallTest 277d58f5ac4f8d9c0ef35ea16849fad21c2d3c638b6fionaxu public void testNotifyVoLteServiceStateChanged() throws Exception { 278efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu VoLteServiceState state = new VoLteServiceState(VoLteServiceState.NOT_SUPPORTED); 279efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyVoLteServiceStateChanged(mPhone, state); 280efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyVoLteServiceStateChanged(state); 281efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu 282efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu state = new VoLteServiceState(VoLteServiceState.HANDOVER_COMPLETED); 283efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu mDefaultPhoneNotifierUT.notifyVoLteServiceStateChanged(mPhone, state); 284efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu verify(mTelephonyRegisteryMock).notifyVoLteServiceStateChanged(state); 285efe268c9e4dea78a03170684fa11d0f7e9e54cd0fionaxu } 286ec6e2f9f13bac23cdfa0de0a56826b21050b6487fionaxu} 287