blob: 9d64f1870f56afeca77656e69b508f720f6eaf5b [file] [log] [blame]
Hall Liu874c0f82016-04-29 18:13:18 -07001/*
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
17package com.android.server.telecom.tests;
18
19import android.content.Context;
Tyler Gunn115c06e2017-03-02 09:29:07 -080020import android.os.Build;
Hall Liu37f18d52017-08-18 14:20:26 -070021import android.os.Handler;
22import android.os.Looper;
23import android.telecom.CallAudioState;
Hall Liud7fe6862016-09-09 16:36:14 -070024import android.telecom.Connection;
Hall Liu874c0f82016-04-29 18:13:18 -070025import android.telecom.DisconnectCause;
Hall Liu2f4f0a02016-08-08 17:23:20 -070026import android.telecom.InCallService;
Brad Ebingera3eccfe2016-10-05 15:45:22 -070027import android.telecom.Log;
Hall Liu37f18d52017-08-18 14:20:26 -070028import android.telecom.Logging.EventManager;
Hall Liu874c0f82016-04-29 18:13:18 -070029import android.telecom.ParcelableCallAnalytics;
30import android.telecom.TelecomAnalytics;
31import android.telecom.TelecomManager;
Hall Liu2f4f0a02016-08-08 17:23:20 -070032import android.telecom.VideoCallImpl;
33import android.telecom.VideoProfile;
Brad Ebinger68d17c62017-04-11 17:14:11 -070034import android.support.test.filters.FlakyTest;
Hall Liu874c0f82016-04-29 18:13:18 -070035import android.test.suitebuilder.annotation.MediumTest;
36import android.test.suitebuilder.annotation.SmallTest;
Hall Liu2f4f0a02016-08-08 17:23:20 -070037import android.util.Base64;
Hall Liu874c0f82016-04-29 18:13:18 -070038
39import com.android.internal.util.IndentingPrintWriter;
40import com.android.server.telecom.Analytics;
Hall Liu37f18d52017-08-18 14:20:26 -070041import com.android.server.telecom.CallAudioRouteStateMachine;
Brad Ebingera3eccfe2016-10-05 15:45:22 -070042import com.android.server.telecom.LogUtils;
Tamas Berghammer83e88282016-09-22 16:23:24 +010043import com.android.server.telecom.nano.TelecomLogClass;
Hall Liu874c0f82016-04-29 18:13:18 -070044
Hall Liuc8a396b2017-12-27 18:23:28 -080045import org.junit.After;
46import org.junit.Before;
47import org.junit.Test;
48import org.junit.runner.RunWith;
49import org.junit.runners.JUnit4;
50
Hall Liu2f4f0a02016-08-08 17:23:20 -070051import java.io.PrintWriter;
Hall Liu874c0f82016-04-29 18:13:18 -070052import java.io.StringWriter;
Hall Liud93b9ec2017-01-05 18:06:30 -080053import java.util.Arrays;
Hall Liu874c0f82016-04-29 18:13:18 -070054import java.util.HashSet;
Hall Liu37f18d52017-08-18 14:20:26 -070055import java.util.LinkedList;
Hall Liu874c0f82016-04-29 18:13:18 -070056import java.util.List;
57import java.util.Map;
58import java.util.Set;
Hall Liu2f4f0a02016-08-08 17:23:20 -070059import java.util.concurrent.CountDownLatch;
60import java.util.concurrent.TimeUnit;
61
Hall Liuc8a396b2017-12-27 18:23:28 -080062import static org.junit.Assert.assertEquals;
63import static org.junit.Assert.assertFalse;
64import static org.junit.Assert.assertNotNull;
65import static org.junit.Assert.assertNull;
66import static org.junit.Assert.assertTrue;
Hall Liu2f4f0a02016-08-08 17:23:20 -070067import static org.mockito.Matchers.any;
68import static org.mockito.Matchers.anyInt;
69import static org.mockito.Mockito.doAnswer;
70import static org.mockito.Mockito.mock;
Hall Liu874c0f82016-04-29 18:13:18 -070071
Hall Liuc8a396b2017-12-27 18:23:28 -080072@RunWith(JUnit4.class)
Hall Liu874c0f82016-04-29 18:13:18 -070073public class AnalyticsTests extends TelecomSystemTest {
Hall Liuc8a396b2017-12-27 18:23:28 -080074 @Override
75 @Before
76 public void setUp() throws Exception {
77 super.setUp();
78 }
79
80 @Override
81 @After
82 public void tearDown() throws Exception {
83 super.tearDown();
84 }
85
Hall Liu874c0f82016-04-29 18:13:18 -070086 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -080087 @Test
Hall Liu874c0f82016-04-29 18:13:18 -070088 public void testAnalyticsSingleCall() throws Exception {
89 IdPair testCall = startAndMakeActiveIncomingCall(
90 "650-555-1212",
91 mPhoneAccountA0.getAccountHandle(),
92 mConnectionServiceFixtureA);
Hall Liud7fe6862016-09-09 16:36:14 -070093
Hall Liu874c0f82016-04-29 18:13:18 -070094 Map<String, Analytics.CallInfoImpl> analyticsMap = Analytics.cloneData();
95
96 assertTrue(analyticsMap.containsKey(testCall.mCallId));
97
98 Analytics.CallInfoImpl callAnalytics = analyticsMap.get(testCall.mCallId);
99 assertTrue(callAnalytics.startTime > 0);
100 assertEquals(0, callAnalytics.endTime);
101 assertEquals(Analytics.INCOMING_DIRECTION, callAnalytics.callDirection);
102 assertFalse(callAnalytics.isInterrupted);
103 assertNull(callAnalytics.callTerminationReason);
104 assertEquals(mConnectionServiceComponentNameA.flattenToShortString(),
105 callAnalytics.connectionService);
106
107 mConnectionServiceFixtureA.
108 sendSetDisconnected(testCall.mConnectionId, DisconnectCause.ERROR);
109
110 analyticsMap = Analytics.cloneData();
111 callAnalytics = analyticsMap.get(testCall.mCallId);
112 assertTrue(callAnalytics.endTime > 0);
113 assertNotNull(callAnalytics.callTerminationReason);
114 assertEquals(DisconnectCause.ERROR, callAnalytics.callTerminationReason.getCode());
115
116 StringWriter sr = new StringWriter();
117 IndentingPrintWriter ip = new IndentingPrintWriter(sr, " ");
118 Analytics.dump(ip);
119 String dumpResult = sr.toString();
120 String[] expectedFields = {"startTime", "endTime", "direction", "isAdditionalCall",
121 "isInterrupted", "callTechnologies", "callTerminationReason", "connectionService"};
122 for (String field : expectedFields) {
123 assertTrue(dumpResult.contains(field));
124 }
125 }
126
Brad Ebinger68d17c62017-04-11 17:14:11 -0700127 @FlakyTest
Hall Liu874c0f82016-04-29 18:13:18 -0700128 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800129 @Test
Hall Liu874c0f82016-04-29 18:13:18 -0700130 public void testAnalyticsDumping() throws Exception {
131 Analytics.reset();
132 IdPair testCall = startAndMakeActiveIncomingCall(
133 "650-555-1212",
134 mPhoneAccountA0.getAccountHandle(),
135 mConnectionServiceFixtureA);
136
137 mConnectionServiceFixtureA.
138 sendSetDisconnected(testCall.mConnectionId, DisconnectCause.ERROR);
139 Analytics.CallInfoImpl expectedAnalytics = Analytics.cloneData().get(testCall.mCallId);
140
141 TelecomManager tm = (TelecomManager) mSpyContext.getSystemService(Context.TELECOM_SERVICE);
142 List<ParcelableCallAnalytics> analyticsList = tm.dumpAnalytics().getCallAnalytics();
143
144 assertEquals(1, analyticsList.size());
145 ParcelableCallAnalytics pCA = analyticsList.get(0);
146
147 assertTrue(Math.abs(expectedAnalytics.startTime - pCA.getStartTimeMillis()) <
148 ParcelableCallAnalytics.MILLIS_IN_5_MINUTES);
149 assertEquals(0, pCA.getStartTimeMillis() % ParcelableCallAnalytics.MILLIS_IN_5_MINUTES);
150 assertTrue(Math.abs((expectedAnalytics.endTime - expectedAnalytics.startTime) -
151 pCA.getCallDurationMillis()) < ParcelableCallAnalytics.MILLIS_IN_1_SECOND);
152 assertEquals(0, pCA.getCallDurationMillis() % ParcelableCallAnalytics.MILLIS_IN_1_SECOND);
153
154 assertEquals(expectedAnalytics.callDirection, pCA.getCallType());
155 assertEquals(expectedAnalytics.isAdditionalCall, pCA.isAdditionalCall());
156 assertEquals(expectedAnalytics.isInterrupted, pCA.isInterrupted());
157 assertEquals(expectedAnalytics.callTechnologies, pCA.getCallTechnologies());
158 assertEquals(expectedAnalytics.callTerminationReason.getCode(),
159 pCA.getCallTerminationCode());
160 assertEquals(expectedAnalytics.connectionService, pCA.getConnectionService());
161 List<ParcelableCallAnalytics.AnalyticsEvent> analyticsEvents = pCA.analyticsEvents();
162 Set<Integer> capturedEvents = new HashSet<>();
163 for (ParcelableCallAnalytics.AnalyticsEvent e : analyticsEvents) {
164 capturedEvents.add(e.getEventName());
Hall Liu2f4f0a02016-08-08 17:23:20 -0700165 assertIsRoundedToOneSigFig(e.getTimeSinceLastEvent());
Hall Liu874c0f82016-04-29 18:13:18 -0700166 }
167 assertTrue(capturedEvents.contains(ParcelableCallAnalytics.AnalyticsEvent.SET_ACTIVE));
168 assertTrue(capturedEvents.contains(
169 ParcelableCallAnalytics.AnalyticsEvent.FILTERING_INITIATED));
170 }
171
172 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800173 @Test
Hall Liu874c0f82016-04-29 18:13:18 -0700174 public void testAnalyticsTwoCalls() throws Exception {
175 IdPair testCall1 = startAndMakeActiveIncomingCall(
176 "650-555-1212",
177 mPhoneAccountA0.getAccountHandle(),
178 mConnectionServiceFixtureA);
179 IdPair testCall2 = startAndMakeActiveOutgoingCall(
180 "650-555-1213",
181 mPhoneAccountA0.getAccountHandle(),
182 mConnectionServiceFixtureA);
183
184 Map<String, Analytics.CallInfoImpl> analyticsMap = Analytics.cloneData();
185 assertTrue(analyticsMap.containsKey(testCall1.mCallId));
186 assertTrue(analyticsMap.containsKey(testCall2.mCallId));
187
188 Analytics.CallInfoImpl callAnalytics1 = analyticsMap.get(testCall1.mCallId);
189 Analytics.CallInfoImpl callAnalytics2 = analyticsMap.get(testCall2.mCallId);
190 assertTrue(callAnalytics1.startTime > 0);
191 assertTrue(callAnalytics2.startTime > 0);
192 assertEquals(0, callAnalytics1.endTime);
193 assertEquals(0, callAnalytics2.endTime);
194
195 assertEquals(Analytics.INCOMING_DIRECTION, callAnalytics1.callDirection);
196 assertEquals(Analytics.OUTGOING_DIRECTION, callAnalytics2.callDirection);
197
198 assertTrue(callAnalytics1.isInterrupted);
199 assertTrue(callAnalytics2.isAdditionalCall);
200
201 assertNull(callAnalytics1.callTerminationReason);
202 assertNull(callAnalytics2.callTerminationReason);
203
204 assertEquals(mConnectionServiceComponentNameA.flattenToShortString(),
205 callAnalytics1.connectionService);
206 assertEquals(mConnectionServiceComponentNameA.flattenToShortString(),
207 callAnalytics1.connectionService);
208
209 mConnectionServiceFixtureA.
210 sendSetDisconnected(testCall2.mConnectionId, DisconnectCause.REMOTE);
211 mConnectionServiceFixtureA.
212 sendSetDisconnected(testCall1.mConnectionId, DisconnectCause.ERROR);
213
214 analyticsMap = Analytics.cloneData();
215 callAnalytics1 = analyticsMap.get(testCall1.mCallId);
216 callAnalytics2 = analyticsMap.get(testCall2.mCallId);
217 assertTrue(callAnalytics1.endTime > 0);
218 assertTrue(callAnalytics2.endTime > 0);
219 assertNotNull(callAnalytics1.callTerminationReason);
220 assertNotNull(callAnalytics2.callTerminationReason);
221 assertEquals(DisconnectCause.ERROR, callAnalytics1.callTerminationReason.getCode());
222 assertEquals(DisconnectCause.REMOTE, callAnalytics2.callTerminationReason.getCode());
223 }
224
Hall Liu2f4f0a02016-08-08 17:23:20 -0700225 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800226 @Test
Hall Liu2f4f0a02016-08-08 17:23:20 -0700227 public void testAnalyticsVideo() throws Exception {
228 Analytics.reset();
229 IdPair callIds = startAndMakeActiveOutgoingCall(
230 "650-555-1212",
231 mPhoneAccountA0.getAccountHandle(),
232 mConnectionServiceFixtureA);
233
234 CountDownLatch counter = new CountDownLatch(1);
235 InCallService.VideoCall.Callback callback = mock(InCallService.VideoCall.Callback.class);
236
237 doAnswer(invocation -> {
238 counter.countDown();
239 return null;
240 }).when(callback)
241 .onSessionModifyResponseReceived(anyInt(), any(VideoProfile.class),
242 any(VideoProfile.class));
243
244 mConnectionServiceFixtureA.sendSetVideoProvider(
245 mConnectionServiceFixtureA.mLatestConnectionId);
246 InCallService.VideoCall videoCall =
Tyler Gunna0a43d52016-11-09 14:09:58 -0800247 mInCallServiceFixtureX.getCall(callIds.mCallId).getVideoCallImpl(
Tyler Gunn115c06e2017-03-02 09:29:07 -0800248 mInCallServiceComponentNameX.getPackageName(), Build.VERSION.SDK_INT);
Hall Liu2f4f0a02016-08-08 17:23:20 -0700249 videoCall.registerCallback(callback);
250 ((VideoCallImpl) videoCall).setVideoState(VideoProfile.STATE_BIDIRECTIONAL);
251
252 videoCall.sendSessionModifyRequest(new VideoProfile(VideoProfile.STATE_RX_ENABLED));
253 counter.await(10000, TimeUnit.MILLISECONDS);
254
255 StringWriter sw = new StringWriter();
256 PrintWriter pw = new PrintWriter(sw);
257 Analytics.dumpToEncodedProto(pw, new String[]{});
258 TelecomLogClass.TelecomLog analyticsProto =
259 TelecomLogClass.TelecomLog.parseFrom(Base64.decode(sw.toString(), Base64.DEFAULT));
260
261 assertEquals(1, analyticsProto.callLogs.length);
262 TelecomLogClass.VideoEvent[] videoEvents = analyticsProto.callLogs[0].videoEvents;
263 assertEquals(2, videoEvents.length);
264
265 assertEquals(Analytics.SEND_LOCAL_SESSION_MODIFY_REQUEST, videoEvents[0].getEventName());
266 assertEquals(VideoProfile.STATE_RX_ENABLED, videoEvents[0].getVideoState());
267 assertEquals(-1, videoEvents[0].getTimeSinceLastEventMillis());
268
269 assertEquals(Analytics.RECEIVE_REMOTE_SESSION_MODIFY_RESPONSE,
270 videoEvents[1].getEventName());
271 assertEquals(VideoProfile.STATE_RX_ENABLED, videoEvents[1].getVideoState());
272 assertIsRoundedToOneSigFig(videoEvents[1].getTimeSinceLastEventMillis());
273 }
274
Hall Liu874c0f82016-04-29 18:13:18 -0700275 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800276 @Test
Hall Liu874c0f82016-04-29 18:13:18 -0700277 public void testAnalyticsRounding() {
278 long[] testVals = {0, -1, -10, -100, -57836, 1, 10, 100, 1000, 458457};
279 long[] expected = {0, -1, -10, -100, -60000, 1, 10, 100, 1000, 500000};
280 for (int i = 0; i < testVals.length; i++) {
281 assertEquals(expected[i], Analytics.roundToOneSigFig(testVals[i]));
282 }
283 }
284
285 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800286 @Test
Hall Liu874c0f82016-04-29 18:13:18 -0700287 public void testAnalyticsLogSessionTiming() throws Exception {
288 long minTime = 50;
Brad Ebingera3eccfe2016-10-05 15:45:22 -0700289 Log.startSession(LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL);
Hall Liu874c0f82016-04-29 18:13:18 -0700290 Thread.sleep(minTime);
291 Log.endSession();
292 TelecomManager tm = (TelecomManager) mSpyContext.getSystemService(Context.TELECOM_SERVICE);
293 List<TelecomAnalytics.SessionTiming> sessions = tm.dumpAnalytics().getSessionTimings();
294 sessions.stream()
Brad Ebingera3eccfe2016-10-05 15:45:22 -0700295 .filter(s -> LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL.equals(
Hall Liu874c0f82016-04-29 18:13:18 -0700296 Analytics.sSessionIdToLogSession.get(s.getKey())))
Hall Liu609992b2016-08-31 15:48:51 -0700297 .forEach(s -> assertTrue(s.getTime() >= minTime));
Hall Liu874c0f82016-04-29 18:13:18 -0700298 }
Hall Liu2f4f0a02016-08-08 17:23:20 -0700299
300 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800301 @Test
Hall Liu2f4f0a02016-08-08 17:23:20 -0700302 public void testAnalyticsDumpToProto() throws Exception {
303 Analytics.reset();
304 IdPair testCall = startAndMakeActiveIncomingCall(
305 "650-555-1212",
306 mPhoneAccountA0.getAccountHandle(),
307 mConnectionServiceFixtureA);
308
309 mConnectionServiceFixtureA.
310 sendSetDisconnected(testCall.mConnectionId, DisconnectCause.ERROR);
311 Analytics.CallInfoImpl expectedAnalytics = Analytics.cloneData().get(testCall.mCallId);
312
313 StringWriter sw = new StringWriter();
314 PrintWriter pw = new PrintWriter(sw);
315 Analytics.dumpToEncodedProto(pw, new String[]{});
316 TelecomLogClass.TelecomLog analyticsProto =
317 TelecomLogClass.TelecomLog.parseFrom(Base64.decode(sw.toString(), Base64.DEFAULT));
318
319 assertEquals(1, analyticsProto.callLogs.length);
320 TelecomLogClass.CallLog callLog = analyticsProto.callLogs[0];
321
322 assertTrue(Math.abs(expectedAnalytics.startTime - callLog.getStartTime5Min()) <
323 ParcelableCallAnalytics.MILLIS_IN_5_MINUTES);
324 assertEquals(0, callLog.getStartTime5Min() % ParcelableCallAnalytics.MILLIS_IN_5_MINUTES);
325 assertTrue(Math.abs((expectedAnalytics.endTime - expectedAnalytics.startTime) -
326 callLog.getCallDurationMillis()) < ParcelableCallAnalytics.MILLIS_IN_1_SECOND);
327 assertEquals(0,
328 callLog.getCallDurationMillis() % ParcelableCallAnalytics.MILLIS_IN_1_SECOND);
329
330 assertEquals(expectedAnalytics.callDirection, callLog.getType());
331 assertEquals(expectedAnalytics.isAdditionalCall, callLog.getIsAdditionalCall());
332 assertEquals(expectedAnalytics.isInterrupted, callLog.getIsInterrupted());
333 assertEquals(expectedAnalytics.callTechnologies, callLog.getCallTechnologies());
334 assertEquals(expectedAnalytics.callTerminationReason.getCode(),
335 callLog.getCallTerminationCode());
336 assertEquals(expectedAnalytics.connectionService, callLog.connectionService[0]);
337 TelecomLogClass.Event[] analyticsEvents = callLog.callEvents;
338 Set<Integer> capturedEvents = new HashSet<>();
339 for (TelecomLogClass.Event e : analyticsEvents) {
340 capturedEvents.add(e.getEventName());
341 assertIsRoundedToOneSigFig(e.getTimeSinceLastEventMillis());
342 }
343 assertTrue(capturedEvents.contains(ParcelableCallAnalytics.AnalyticsEvent.SET_ACTIVE));
344 assertTrue(capturedEvents.contains(
345 ParcelableCallAnalytics.AnalyticsEvent.FILTERING_INITIATED));
346 }
347
Hall Liud7fe6862016-09-09 16:36:14 -0700348 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800349 @Test
Hall Liu37f18d52017-08-18 14:20:26 -0700350 public void testAnalyticsAudioRoutes() throws Exception {
351 Analytics.reset();
352 IdPair testCall = startAndMakeActiveIncomingCall(
353 "650-555-1212",
354 mPhoneAccountA0.getAccountHandle(),
355 mConnectionServiceFixtureA);
356 List<Integer> audioRoutes = new LinkedList<>();
357
358 waitForHandlerAction(
359 mTelecomSystem.getCallsManager().getCallAudioManager()
360 .getCallAudioRouteStateMachine().getHandler(),
361 TEST_TIMEOUT);
Hall Liu25c84252017-11-15 14:01:12 -0800362 waitForHandlerAction(
363 mTelecomSystem.getCallsManager().getCallAudioManager()
364 .getCallAudioModeStateMachine().getHandler(),
365 TEST_TIMEOUT);
Hall Liu37f18d52017-08-18 14:20:26 -0700366 audioRoutes.add(mInCallServiceFixtureX.mCallAudioState.getRoute());
Hall Liu9086fb12017-11-07 18:01:53 -0800367 mInCallServiceFixtureX.getInCallAdapter().setAudioRoute(CallAudioState.ROUTE_SPEAKER, null);
Hall Liu37f18d52017-08-18 14:20:26 -0700368 waitForHandlerAction(
369 mTelecomSystem.getCallsManager().getCallAudioManager()
370 .getCallAudioRouteStateMachine().getHandler(),
371 TEST_TIMEOUT);
Hall Liu25c84252017-11-15 14:01:12 -0800372 waitForHandlerAction(
373 mTelecomSystem.getCallsManager().getCallAudioManager()
374 .getCallAudioModeStateMachine().getHandler(),
375 TEST_TIMEOUT);
Hall Liu37f18d52017-08-18 14:20:26 -0700376 audioRoutes.add(CallAudioState.ROUTE_SPEAKER);
377
378 Map<String, Analytics.CallInfoImpl> analyticsMap = Analytics.cloneData();
379 assertTrue(analyticsMap.containsKey(testCall.mCallId));
380
381 Analytics.CallInfoImpl callAnalytics = analyticsMap.get(testCall.mCallId);
382 List<EventManager.Event> events = callAnalytics.callEvents.getEvents();
383 for (int route : audioRoutes) {
384 String logEvent = CallAudioRouteStateMachine.AUDIO_ROUTE_TO_LOG_EVENT.get(route);
385 assertTrue(events.stream().anyMatch(event -> event.eventId.equals(logEvent)));
386 }
387 }
388
389 @MediumTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800390 @Test
Hall Liud7fe6862016-09-09 16:36:14 -0700391 public void testAnalyticsConnectionProperties() throws Exception {
392 Analytics.reset();
393 IdPair testCall = startAndMakeActiveIncomingCall(
394 "650-555-1212",
395 mPhoneAccountA0.getAccountHandle(),
396 mConnectionServiceFixtureA);
397
398 int properties1 = Connection.PROPERTY_IS_DOWNGRADED_CONFERENCE
399 | Connection.PROPERTY_WIFI
400 | Connection.PROPERTY_EMERGENCY_CALLBACK_MODE;
401 int properties2 = Connection.PROPERTY_HIGH_DEF_AUDIO
402 | Connection.PROPERTY_WIFI;
403 int expectedProperties = properties1 | properties2;
404
405 mConnectionServiceFixtureA.mConnectionById.get(testCall.mConnectionId).properties =
406 properties1;
407 mConnectionServiceFixtureA.sendSetConnectionProperties(testCall.mConnectionId);
408 mConnectionServiceFixtureA.mConnectionById.get(testCall.mConnectionId).properties =
409 properties2;
410 mConnectionServiceFixtureA.sendSetConnectionProperties(testCall.mConnectionId);
411
412 mConnectionServiceFixtureA.
413 sendSetDisconnected(testCall.mConnectionId, DisconnectCause.ERROR);
414
415 StringWriter sw = new StringWriter();
416 PrintWriter pw = new PrintWriter(sw);
417 Analytics.dumpToEncodedProto(pw, new String[]{});
418 TelecomLogClass.TelecomLog analyticsProto =
419 TelecomLogClass.TelecomLog.parseFrom(Base64.decode(sw.toString(), Base64.DEFAULT));
420
421 assertEquals(expectedProperties,
422 analyticsProto.callLogs[0].getConnectionProperties() & expectedProperties);
423 }
424
Hall Liud93b9ec2017-01-05 18:06:30 -0800425 @SmallTest
Hall Liuc8a396b2017-12-27 18:23:28 -0800426 @Test
Hall Liud93b9ec2017-01-05 18:06:30 -0800427 public void testAnalyticsMaxSize() throws Exception {
428 Analytics.reset();
429 for (int i = 0; i < Analytics.MAX_NUM_CALLS_TO_STORE * 2; i++) {
430 Analytics.initiateCallAnalytics(String.valueOf(i), Analytics.INCOMING_DIRECTION)
431 .addCallTechnology(i);
432 }
433
434 StringWriter sw = new StringWriter();
435 PrintWriter pw = new PrintWriter(sw);
436 Analytics.dumpToEncodedProto(pw, new String[]{});
437 TelecomLogClass.TelecomLog analyticsProto =
438 TelecomLogClass.TelecomLog.parseFrom(Base64.decode(sw.toString(), Base64.DEFAULT));
439
440 assertEquals(Analytics.MAX_NUM_CALLS_TO_STORE, analyticsProto.callLogs.length);
441 assertEquals(Arrays.stream(analyticsProto.callLogs)
442 .filter(x -> x.getCallTechnologies() < 100)
443 .count(), 0);
444 }
445
Hall Liu2f4f0a02016-08-08 17:23:20 -0700446 private void assertIsRoundedToOneSigFig(long x) {
447 assertEquals(x, Analytics.roundToOneSigFig(x));
448 }
Hall Liu874c0f82016-04-29 18:13:18 -0700449}