1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.internal.telephony.imsphone; 18 19 import static junit.framework.Assert.assertNotNull; 20 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.assertFalse; 23 import static org.junit.Assert.assertNotEquals; 24 import static org.junit.Assert.assertTrue; 25 import static org.junit.Assert.fail; 26 import static org.mockito.ArgumentMatchers.any; 27 import static org.mockito.Mockito.doReturn; 28 import static org.mockito.Mockito.mock; 29 import static org.mockito.Mockito.verify; 30 import static org.mockito.Mockito.when; 31 32 import android.os.Bundle; 33 import android.telephony.ServiceState; 34 import android.telephony.TelephonyManager; 35 import android.telephony.ims.ImsCallProfile; 36 import android.telephony.ims.ImsCallSession; 37 import android.telephony.ims.ImsStreamMediaProfile; 38 import android.test.suitebuilder.annotation.SmallTest; 39 40 import com.android.ims.ImsCall; 41 import com.android.internal.telephony.TelephonyTest; 42 43 import org.junit.After; 44 import org.junit.Before; 45 import org.junit.Test; 46 import org.mockito.ArgumentCaptor; 47 48 import java.util.concurrent.Executor; 49 50 public class ImsCallTest extends TelephonyTest { 51 52 private Bundle mBundle; 53 private ImsCallProfile mTestCallProfile; 54 55 private final Executor mExecutor = Runnable::run; 56 57 @Before setUp()58 public void setUp() throws Exception { 59 super.setUp(getClass().getSimpleName()); 60 mTestCallProfile = new ImsCallProfile(); 61 mBundle = mTestCallProfile.mCallExtras; 62 doReturn(mExecutor).when(mContext).getMainExecutor(); 63 } 64 65 @After tearDown()66 public void tearDown() throws Exception { 67 mBundle = null; 68 mTestCallProfile = null; 69 super.tearDown(); 70 } 71 72 @Test 73 @SmallTest testCallSessionProgressingAppliedMediaCaps()74 public void testCallSessionProgressingAppliedMediaCaps() throws Exception { 75 ImsCallSession mockSession = mock(ImsCallSession.class); 76 ImsCall testImsCall = new ImsCall(mContext, mTestCallProfile); 77 ImsCallProfile profile = new ImsCallProfile(); 78 when(mockSession.getCallProfile()).thenReturn(profile); 79 testImsCall.attachSession(mockSession); 80 81 ArgumentCaptor<ImsCallSession.Listener> listenerCaptor = 82 ArgumentCaptor.forClass(ImsCallSession.Listener.class); 83 verify(mockSession).setListener(listenerCaptor.capture(), any()); 84 ImsCallSession.Listener listener = listenerCaptor.getValue(); 85 assertNotNull(listener); 86 87 // Set new profile with direction of none 88 ImsStreamMediaProfile newProfile = new ImsStreamMediaProfile( 89 ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB, 90 ImsStreamMediaProfile.DIRECTION_INACTIVE, 91 ImsStreamMediaProfile.VIDEO_QUALITY_NONE, 92 ImsStreamMediaProfile.DIRECTION_INACTIVE, 93 ImsStreamMediaProfile.RTT_MODE_DISABLED); 94 listener.callSessionProgressing(mockSession, newProfile); 95 96 ImsStreamMediaProfile testProfile = testImsCall.getCallProfile().getMediaProfile(); 97 assertNotNull(testProfile); 98 // Assert that the new direction was applied to the profile 99 assertEquals(ImsStreamMediaProfile.DIRECTION_INACTIVE, testProfile.getAudioDirection()); 100 } 101 102 @Test 103 @SmallTest testSetWifiDeprecated()104 public void testSetWifiDeprecated() { 105 ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile); 106 assertFalse(mTestImsCall.isWifiCall()); 107 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 108 // use deprecated API 109 mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE, 110 ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + ""); 111 assertTrue(mTestImsCall.isWifiCall()); 112 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 113 } 114 115 @Test 116 @SmallTest testNullCallProfile()117 public void testNullCallProfile() { 118 ImsCall imsCall = new ImsCall(mContext, null /* imsCallProfile */); 119 assertNotNull(imsCall); 120 assertFalse(imsCall.wasVideoCall()); 121 } 122 123 @Test 124 @SmallTest testNonNulllVideoProfile()125 public void testNonNulllVideoProfile() { 126 ImsCallProfile profile = new ImsCallProfile(); 127 profile.mCallType = ImsCallProfile.CALL_TYPE_VT_TX; 128 129 ImsCall imsCall = new ImsCall(mContext, profile); 130 assertNotNull(imsCall); 131 assertTrue(imsCall.wasVideoCall()); 132 } 133 134 @Test 135 @SmallTest testNullCallProfileAfterNonNull()136 public void testNullCallProfileAfterNonNull() { 137 ImsCallProfile profile = new ImsCallProfile(); 138 profile.mCallType = ImsCallProfile.CALL_TYPE_VT_TX; 139 140 ImsCall imsCall = new ImsCall(mContext, profile); 141 assertNotNull(imsCall); 142 assertTrue(imsCall.wasVideoCall()); 143 144 imsCall.setCallProfile(null); 145 assertTrue(imsCall.wasVideoCall()); 146 } 147 148 @Test 149 @SmallTest testCloseImsCallRtt()150 public void testCloseImsCallRtt() throws Exception { 151 ImsCallSession mockSession = mock(ImsCallSession.class); 152 ImsStreamMediaProfile streamProfile = new ImsStreamMediaProfile( 153 ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB, 154 ImsStreamMediaProfile.DIRECTION_SEND_RECEIVE, 155 ImsStreamMediaProfile.VIDEO_QUALITY_NONE, 156 ImsStreamMediaProfile.DIRECTION_INACTIVE, 157 // Full RTT mode 158 ImsStreamMediaProfile.RTT_MODE_FULL); 159 ImsCallProfile profile = new ImsCallProfile(ImsCallProfile.SERVICE_TYPE_NORMAL, 160 ImsCallProfile.CALL_TYPE_VOICE, null /*extras*/, streamProfile); 161 profile.mCallType = ImsCallProfile.CALL_TYPE_VOICE; 162 ImsCall imsCall = new ImsCall(mContext, profile); 163 imsCall.attachSession(mockSession); 164 165 imsCall.sendRttMessage("test"); 166 verify(mockSession).sendRttMessage("test"); 167 168 //called by ImsPhoneCallTracker when the call is terminated 169 imsCall.close(); 170 171 try { 172 // Ensure RTT cases are handled gracefully. 173 imsCall.sendRttMessage("test"); 174 imsCall.sendRttModifyRequest(true); 175 imsCall.sendRttModifyResponse(true); 176 } catch (Exception e) { 177 fail("Unexpected exception: " + e); 178 } 179 } 180 181 @Test 182 @SmallTest testSetWifi()183 public void testSetWifi() { 184 ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile); 185 assertFalse(mTestImsCall.isWifiCall()); 186 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 187 mBundle.putInt(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE, 188 TelephonyManager.NETWORK_TYPE_IWLAN); 189 assertTrue(mTestImsCall.isWifiCall()); 190 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 191 } 192 193 @Test 194 @SmallTest testSetWifiAlt()195 public void testSetWifiAlt() { 196 ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile); 197 assertFalse(mTestImsCall.isWifiCall()); 198 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 199 mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT, 200 ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + ""); 201 assertTrue(mTestImsCall.isWifiCall()); 202 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 203 } 204 205 @Test 206 @SmallTest testSetLteNoWifiDeprecated()207 public void testSetLteNoWifiDeprecated() { 208 ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile); 209 assertFalse(mTestImsCall.isWifiCall()); 210 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 211 mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE, 212 ServiceState.RIL_RADIO_TECHNOLOGY_LTE + ""); 213 assertFalse(mTestImsCall.isWifiCall()); 214 assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 215 } 216 217 @Test 218 @SmallTest testSetLteNoWifi()219 public void testSetLteNoWifi() { 220 ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile); 221 assertFalse(mTestImsCall.isWifiCall()); 222 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 223 mBundle.putInt(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE, 224 TelephonyManager.NETWORK_TYPE_LTE); 225 assertFalse(mTestImsCall.isWifiCall()); 226 assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 227 } 228 229 @Test 230 @SmallTest testSetLteNoWifiAlt()231 public void testSetLteNoWifiAlt() { 232 ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile); 233 assertFalse(mTestImsCall.isWifiCall()); 234 assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 235 mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT, 236 ServiceState.RIL_RADIO_TECHNOLOGY_LTE + ""); 237 assertFalse(mTestImsCall.isWifiCall()); 238 assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE); 239 } 240 } 241