• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 
29 import android.os.Bundle;
30 import android.telephony.ServiceState;
31 import android.telephony.TelephonyManager;
32 import android.telephony.ims.ImsCallProfile;
33 import android.telephony.ims.ImsCallSession;
34 import android.telephony.ims.ImsStreamMediaProfile;
35 import android.test.suitebuilder.annotation.SmallTest;
36 
37 import com.android.ims.ImsCall;
38 import com.android.internal.telephony.TelephonyTest;
39 
40 import org.junit.After;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.mockito.ArgumentCaptor;
44 
45 public class ImsCallTest extends TelephonyTest {
46 
47     private Bundle mBundle;
48     private ImsCallProfile mTestCallProfile;
49 
50     @Before
setUp()51     public void setUp() throws Exception {
52         super.setUp(getClass().getSimpleName());
53         mTestCallProfile = new ImsCallProfile();
54         mBundle = mTestCallProfile.mCallExtras;
55     }
56 
57     @After
tearDown()58     public void tearDown() throws Exception {
59         super.tearDown();
60     }
61 
62     @Test
63     @SmallTest
testCallSessionProgressingAppliedMediaCaps()64     public void testCallSessionProgressingAppliedMediaCaps() throws Exception {
65         ImsCallSession mockSession = mock(ImsCallSession.class);
66         ImsCall testImsCall = new ImsCall(mContext, mTestCallProfile);
67         ImsCallProfile profile = new ImsCallProfile();
68         when(mockSession.getCallProfile()).thenReturn(profile);
69         testImsCall.attachSession(mockSession);
70 
71         ArgumentCaptor<ImsCallSession.Listener> listenerCaptor =
72                 ArgumentCaptor.forClass(ImsCallSession.Listener.class);
73         verify(mockSession).setListener(listenerCaptor.capture());
74         ImsCallSession.Listener listener = listenerCaptor.getValue();
75         assertNotNull(listener);
76 
77         // Set new profile with direction of none
78         ImsStreamMediaProfile newProfile = new ImsStreamMediaProfile(
79                 ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB,
80                 ImsStreamMediaProfile.DIRECTION_INACTIVE,
81                 ImsStreamMediaProfile.VIDEO_QUALITY_NONE,
82                 ImsStreamMediaProfile.DIRECTION_INACTIVE,
83                 ImsStreamMediaProfile.RTT_MODE_DISABLED);
84         listener.callSessionProgressing(mockSession, newProfile);
85 
86         ImsStreamMediaProfile testProfile = testImsCall.getCallProfile().getMediaProfile();
87         assertNotNull(testProfile);
88         // Assert that the new direction was applied to the profile
89         assertEquals(ImsStreamMediaProfile.DIRECTION_INACTIVE, testProfile.getAudioDirection());
90     }
91 
92     @Test
93     @SmallTest
testSetWifiDeprecated()94     public void testSetWifiDeprecated() {
95         ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
96         assertFalse(mTestImsCall.isWifiCall());
97         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
98         // use deprecated API
99         mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE,
100                 ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + "");
101         assertTrue(mTestImsCall.isWifiCall());
102         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
103     }
104 
105     @Test
106     @SmallTest
testNullCallProfile()107     public void testNullCallProfile() {
108         ImsCall imsCall = new ImsCall(mContext, null /* imsCallProfile */);
109         assertNotNull(imsCall);
110         assertFalse(imsCall.wasVideoCall());
111     }
112 
113     @Test
114     @SmallTest
testNonNulllVideoProfile()115     public void testNonNulllVideoProfile() {
116         ImsCallProfile profile = new ImsCallProfile();
117         profile.mCallType = ImsCallProfile.CALL_TYPE_VT_TX;
118 
119         ImsCall imsCall = new ImsCall(mContext, profile);
120         assertNotNull(imsCall);
121         assertTrue(imsCall.wasVideoCall());
122     }
123 
124     @Test
125     @SmallTest
testNullCallProfileAfterNonNull()126     public void testNullCallProfileAfterNonNull() {
127         ImsCallProfile profile = new ImsCallProfile();
128         profile.mCallType = ImsCallProfile.CALL_TYPE_VT_TX;
129 
130         ImsCall imsCall = new ImsCall(mContext, profile);
131         assertNotNull(imsCall);
132         assertTrue(imsCall.wasVideoCall());
133 
134         imsCall.setCallProfile(null);
135         assertTrue(imsCall.wasVideoCall());
136     }
137 
138     @Test
139     @SmallTest
testSetWifi()140     public void testSetWifi() {
141         ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
142         assertFalse(mTestImsCall.isWifiCall());
143         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
144         mBundle.putInt(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE,
145                 TelephonyManager.NETWORK_TYPE_IWLAN);
146         assertTrue(mTestImsCall.isWifiCall());
147         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
148     }
149 
150     @Test
151     @SmallTest
testSetWifiAlt()152     public void testSetWifiAlt() {
153         ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
154         assertFalse(mTestImsCall.isWifiCall());
155         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
156         mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT,
157                 ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + "");
158         assertTrue(mTestImsCall.isWifiCall());
159         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
160     }
161 
162     @Test
163     @SmallTest
testSetLteNoWifiDeprecated()164     public void testSetLteNoWifiDeprecated() {
165         ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
166         assertFalse(mTestImsCall.isWifiCall());
167         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
168         mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE,
169                 ServiceState.RIL_RADIO_TECHNOLOGY_LTE + "");
170         assertFalse(mTestImsCall.isWifiCall());
171         assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
172     }
173 
174     @Test
175     @SmallTest
testSetLteNoWifi()176     public void testSetLteNoWifi() {
177         ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
178         assertFalse(mTestImsCall.isWifiCall());
179         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
180         mBundle.putInt(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE,
181                 TelephonyManager.NETWORK_TYPE_LTE);
182         assertFalse(mTestImsCall.isWifiCall());
183         assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
184     }
185 
186     @Test
187     @SmallTest
testSetLteNoWifiAlt()188     public void testSetLteNoWifiAlt() {
189         ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
190         assertFalse(mTestImsCall.isWifiCall());
191         assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
192         mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT,
193                 ServiceState.RIL_RADIO_TECHNOLOGY_LTE + "");
194         assertFalse(mTestImsCall.isWifiCall());
195         assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
196     }
197 }
198