1 /* 2 * Copyright (C) 2023 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 android.telecom.cts; 18 19 import static android.telecom.DisconnectCauseEnum.LOCAL; 20 import static android.telecom.DisconnectCauseEnum.UNKNOWN; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import android.compat.cts.CompatChangeGatingTestCase; 25 import android.cts.statsdatom.lib.AtomTestUtils; 26 import android.cts.statsdatom.lib.ConfigUtils; 27 import android.cts.statsdatom.lib.DeviceUtils; 28 import android.cts.statsdatom.lib.ReportUtils; 29 30 import com.android.compatibility.common.util.NonApiTest; 31 import com.android.os.AtomsProto; 32 import com.android.os.StatsLog.EventMetricData; 33 import com.android.os.telecom.EmergencyNumberDialed; 34 import com.android.os.telecom.TelecomExtensionAtom; 35 import com.android.tradefed.log.LogUtil.CLog; 36 import com.android.tradefed.util.RunUtil; 37 38 import com.google.protobuf.ExtensionRegistry; 39 40 import java.util.List; 41 42 /** Tests for Telecom metrics atom logging to statsd */ 43 @NonApiTest( 44 exemptionReasons = {}, 45 justification = "METRIC") 46 public class TelecomHostStatsTest extends CompatChangeGatingTestCase { 47 48 private static final String TELECOM_CTS_TEST_PKG = "android.telecom.cts"; 49 private static final String FEATURE_TELECOM = "android.software.telecom"; 50 private static final String FEATURE_TELEPHONY = "android.hardware.telephony"; 51 52 @Override setUp()53 protected void setUp() throws Exception { 54 super.setUp(); 55 assertThat(mCtsBuild).isNotNull(); 56 ConfigUtils.removeConfig(getDevice()); 57 ReportUtils.clearReports(getDevice()); 58 RunUtil.getDefault().sleep(AtomTestUtils.WAIT_TIME_LONG); 59 } 60 61 @Override tearDown()62 protected void tearDown() throws Exception { 63 ConfigUtils.removeConfig(getDevice()); 64 ReportUtils.clearReports(getDevice()); 65 super.tearDown(); 66 } 67 68 // basic verification of CallStateChanged atom 69 // being logged to statsd when a call is made testCallStateChangedAtom_basicTest()70 public void testCallStateChangedAtom_basicTest() throws Exception { 71 if (!DeviceUtils.hasFeature(getDevice(), FEATURE_TELECOM) || !DeviceUtils.hasFeature( 72 getDevice(), FEATURE_TELEPHONY)) { 73 return; 74 } 75 76 ConfigUtils.uploadConfigForPushedAtom( 77 getDevice(), TELECOM_CTS_TEST_PKG, AtomsProto.Atom.CALL_STATE_CHANGED_FIELD_NUMBER); 78 79 // run CTS test case for outgoing call 80 DeviceUtils.runDeviceTests( 81 getDevice(), 82 TELECOM_CTS_TEST_PKG, 83 ".OutgoingCallTest", 84 "testStartCallWithSpeakerphoneTrue_SpeakerphoneOnInCall"); 85 86 RunUtil.getDefault().sleep(AtomTestUtils.WAIT_TIME_LONG); 87 // Verify that we have three atoma for callstatechange 88 List<EventMetricData> data = ReportUtils.getEventMetricDataList(getDevice()); 89 AtomsProto.CallStateChanged callStateChangedAtom = null; 90 CLog.d("metrics list size: " + data.size()); 91 92 assertEquals(data.size(), 3); // DIALING, CONNECTING, DISCONNECTED 93 94 boolean state_dialing = false, state_connecting = false, state_disconnected = false; 95 for (EventMetricData d : data) { 96 callStateChangedAtom = d.getAtom().getCallStateChanged(); 97 98 // common checks 99 assertThat(callStateChangedAtom.getEmergencyCall()).isFalse(); 100 assertThat(callStateChangedAtom.getSelfManaged()).isFalse(); 101 assertThat(callStateChangedAtom.getExternalCall()).isFalse(); 102 assertThat(callStateChangedAtom.getExistingCallCount()).isEqualTo(0); 103 assertThat(callStateChangedAtom.getHeldCallCount()).isEqualTo(0); 104 105 switch (callStateChangedAtom.getCallState()) { 106 case CONNECTING: 107 assertThat(state_connecting).isFalse(); 108 state_connecting = true; 109 assertThat(callStateChangedAtom.getDisconnectCause()).isEqualTo(UNKNOWN); 110 break; 111 case DIALING: 112 assertThat(state_dialing).isFalse(); 113 state_dialing = true; 114 assertThat(callStateChangedAtom.getDisconnectCause()).isEqualTo(UNKNOWN); 115 break; 116 case DISCONNECTED: 117 assertThat(state_disconnected).isFalse(); 118 state_disconnected = true; 119 assertThat(callStateChangedAtom.getDisconnectCause()).isEqualTo(LOCAL); 120 break; 121 default: 122 } 123 } 124 assertThat(state_connecting).isTrue(); 125 assertThat(state_dialing).isTrue(); 126 assertThat(state_disconnected).isTrue(); 127 } 128 129 // Verification for EmergencyNumberDialed atom 130 // being logged to statsd when a sos call is made testEmergencyNumberDialedAtom()131 public void testEmergencyNumberDialedAtom() throws Exception { 132 if (!DeviceUtils.hasFeature(getDevice(), FEATURE_TELECOM) || !DeviceUtils.hasFeature( 133 getDevice(), FEATURE_TELEPHONY)) { 134 return; 135 } 136 137 ConfigUtils.uploadConfigForPushedAtom( 138 getDevice(), 139 TELECOM_CTS_TEST_PKG, 140 TelecomExtensionAtom.EMERGENCY_NUMBER_DIALED_FIELD_NUMBER); 141 142 DeviceUtils.runDeviceTests( 143 getDevice(), TELECOM_CTS_TEST_PKG, ".EmergencyCallTests", "testStartEmergencyCall"); 144 145 RunUtil.getDefault().sleep(AtomTestUtils.WAIT_TIME_LONG); 146 ExtensionRegistry registry = ExtensionRegistry.newInstance(); 147 TelecomExtensionAtom.registerAllExtensions(registry); 148 List<EventMetricData> data = ReportUtils.getEventMetricDataList(getDevice(), registry); 149 CLog.d("metrics list size: " + data.size()); 150 assertEquals(data.size(), 1); 151 EmergencyNumberDialed emergencyNumberDialedAtom = 152 data.get(0).getAtom().getExtension(TelecomExtensionAtom.emergencyNumberDialed); 153 assertThat(emergencyNumberDialedAtom.getNumber()) 154 .isEqualTo("5553637"); // Test emergency number 155 assertThat(emergencyNumberDialedAtom.getSystemDialerPackage()) 156 .isEqualTo(TELECOM_CTS_TEST_PKG); 157 } 158 } 159