Home | History | Annotate | Download | only in metrics
      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.metrics;
     18 
     19 import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
     20 import static android.telephony.ServiceState.ROAMING_TYPE_DOMESTIC;
     21 
     22 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEACTIVATE_DATA_CALL;
     23 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS;
     24 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SETUP_DATA_CALL;
     25 import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_ADDRESS;
     26 import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_DNS;
     27 import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_GATEWAY;
     28 import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_IFNAME;
     29 import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_PCSCF_ADDRESS;
     30 import static com.android.internal.telephony.nano.TelephonyProto.PdpType.PDP_TYPE_IPV4V6;
     31 
     32 import static org.junit.Assert.assertArrayEquals;
     33 import static org.junit.Assert.assertEquals;
     34 import static org.junit.Assert.assertFalse;
     35 import static org.junit.Assert.assertTrue;
     36 import static org.mockito.Mockito.doReturn;
     37 
     38 import android.support.test.filters.FlakyTest;
     39 import android.telephony.ServiceState;
     40 import android.test.suitebuilder.annotation.SmallTest;
     41 import android.util.Base64;
     42 
     43 import com.android.ims.ImsConfig;
     44 import com.android.ims.ImsReasonInfo;
     45 import com.android.ims.internal.ImsCallSession;
     46 import com.android.internal.telephony.Call;
     47 import com.android.internal.telephony.GsmCdmaConnection;
     48 import com.android.internal.telephony.PhoneConstants;
     49 import com.android.internal.telephony.SmsResponse;
     50 import com.android.internal.telephony.TelephonyTest;
     51 import com.android.internal.telephony.UUSInfo;
     52 import com.android.internal.telephony.dataconnection.DataCallResponse;
     53 import com.android.internal.telephony.nano.TelephonyProto;
     54 import com.android.internal.telephony.nano.TelephonyProto.ImsConnectionState;
     55 import com.android.internal.telephony.nano.TelephonyProto.RadioAccessTechnology;
     56 import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
     57 import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession;
     58 import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.CallState;
     59 import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.ImsCommand;
     60 import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.RilCall;
     61 import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
     62 import com.android.internal.telephony.nano.TelephonyProto.TelephonyLog;
     63 import com.android.internal.telephony.nano.TelephonyProto.TelephonyServiceState;
     64 import com.android.internal.telephony.nano.TelephonyProto.TelephonyServiceState.RoamingType;
     65 
     66 import org.junit.After;
     67 import org.junit.Before;
     68 import org.junit.Test;
     69 import org.mockito.Mock;
     70 
     71 import java.lang.reflect.Method;
     72 
     73 public class TelephonyMetricsTest extends TelephonyTest {
     74 
     75     @Mock
     76     private ImsCallSession mImsCallSession;
     77 
     78     @Mock
     79     private ImsReasonInfo mImsReasonInfo;
     80 
     81     @Mock
     82     private ServiceState mServiceState;
     83 
     84     @Mock
     85     private GsmCdmaConnection mConnection;
     86 
     87     private TelephonyMetrics mMetrics;
     88 
     89     private UUSInfo mUusInfo;
     90 
     91     @Before
     92     public void setUp() throws Exception {
     93         super.setUp(getClass().getSimpleName());
     94         mMetrics = new TelephonyMetrics();
     95         mUusInfo = new UUSInfo(1, 2, new byte[]{1, 2});
     96         doReturn("123").when(mImsCallSession).getCallId();
     97         doReturn("extramessage").when(mImsReasonInfo).getExtraMessage();
     98         doReturn(123).when(mImsReasonInfo).getCode();
     99         doReturn(456).when(mImsReasonInfo).getExtraCode();
    100 
    101         doReturn(ROAMING_TYPE_DOMESTIC).when(mServiceState).getVoiceRoamingType();
    102         doReturn(ROAMING_TYPE_DOMESTIC).when(mServiceState).getDataRoamingType();
    103         doReturn("voiceshort").when(mServiceState).getVoiceOperatorAlphaShort();
    104         doReturn("voicelong").when(mServiceState).getVoiceOperatorAlphaLong();
    105         doReturn("datashort").when(mServiceState).getDataOperatorAlphaShort();
    106         doReturn("datalong").when(mServiceState).getDataOperatorAlphaLong();
    107         doReturn("123456").when(mServiceState).getVoiceOperatorNumeric();
    108         doReturn("123456").when(mServiceState).getDataOperatorNumeric();
    109         doReturn(RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState).getRilVoiceRadioTechnology();
    110         doReturn(RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState).getRilDataRadioTechnology();
    111     }
    112 
    113     @After
    114     public void tearDown() throws Exception {
    115         super.tearDown();
    116     }
    117 
    118     private TelephonyLog buildProto() throws Exception {
    119         Method method = TelephonyMetrics.class.getDeclaredMethod("buildProto");
    120         method.setAccessible(true);
    121         return (TelephonyLog) method.invoke(mMetrics);
    122     }
    123 
    124     private void reset() throws Exception {
    125         Method method = TelephonyMetrics.class.getDeclaredMethod("reset");
    126         method.setAccessible(true);
    127         method.invoke(mMetrics);
    128     }
    129 
    130     private String convertProtoToBase64String(TelephonyLog log) throws Exception {
    131         Class[] cArgs = new Class[1];
    132         cArgs[0] = TelephonyLog.class;
    133         Method method = TelephonyMetrics.class.getDeclaredMethod("convertProtoToBase64String",
    134                 cArgs);
    135         method.setAccessible(true);
    136         return (String) method.invoke(null, log);
    137     }
    138 
    139     @Test
    140     @SmallTest
    141     public void testEventDropped() throws Exception {
    142         for (int i = 0; i < 1001; i++) {
    143             mMetrics.writeDataStallEvent(mPhone.getPhoneId(), i);
    144         }
    145         TelephonyLog log = buildProto();
    146         assertEquals(1000, log.events.length);
    147         assertEquals(0, log.callSessions.length);
    148         assertEquals(0, log.smsSessions.length);
    149         assertTrue(log.eventsDropped);
    150         assertEquals(1, log.events[0].dataStallAction);
    151     }
    152 
    153     // Test write data stall event
    154     @Test
    155     @SmallTest
    156     public void testWriteDataStallEvent() throws Exception {
    157         mMetrics.writeDataStallEvent(mPhone.getPhoneId(), 3);
    158         TelephonyLog log = buildProto();
    159 
    160         assertEquals(1, log.events.length);
    161         assertEquals(0, log.callSessions.length);
    162         assertEquals(0, log.smsSessions.length);
    163         assertEquals(mPhone.getPhoneId(), log.events[0].phoneId);
    164         assertEquals(3, log.events[0].dataStallAction);
    165     }
    166 
    167     // Test write modem restart event
    168     @Test
    169     @SmallTest
    170     public void testModemRestartEvent() throws Exception {
    171         mMetrics.writeModemRestartEvent(mPhone.getPhoneId(), "Test");
    172         TelephonyLog log = buildProto();
    173 
    174         assertEquals(1, log.events.length);
    175         assertEquals(0, log.callSessions.length);
    176         assertEquals(0, log.smsSessions.length);
    177 
    178         assertEquals(mPhone.getPhoneId(), log.events[0].phoneId);
    179         assertEquals("Test", log.events[0].modemRestart.reason);
    180     }
    181 
    182     // Test write on IMS call start
    183     @Test
    184     @SmallTest
    185     public void testWriteOnImsCallStart() throws Exception {
    186         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    187         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    188         TelephonyLog log = buildProto();
    189 
    190         assertEquals(0, log.events.length);
    191         assertEquals(1, log.callSessions.length);
    192         assertEquals(0, log.smsSessions.length);
    193 
    194         assertEquals(mPhone.getPhoneId(), log.callSessions[0].phoneId);
    195 
    196         assertFalse(log.callSessions[0].eventsDropped);
    197 
    198         assertEquals(1, log.callSessions[0].events.length);
    199 
    200         assertEquals(123, log.callSessions[0].events[0].callIndex);
    201 
    202         assertEquals(ImsCommand.IMS_CMD_START, log.callSessions[0].events[0].imsCommand);
    203     }
    204 
    205     // Test write on IMS call received
    206     @Test
    207     @SmallTest
    208     public void testWriteOnImsCallReceive() throws Exception {
    209         mMetrics.writeOnImsCallReceive(mPhone.getPhoneId(), mImsCallSession);
    210         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    211         TelephonyLog log = buildProto();
    212 
    213         assertEquals(0, log.events.length);
    214         assertEquals(1, log.callSessions.length);
    215         assertEquals(0, log.smsSessions.length);
    216         assertEquals(mPhone.getPhoneId(), log.callSessions[0].phoneId);
    217 
    218         assertFalse(log.callSessions[0].eventsDropped);
    219 
    220         assertEquals(1, log.callSessions[0].events.length);
    221 
    222         assertEquals(123, log.callSessions[0].events[0].callIndex);
    223     }
    224 
    225     // Test write ims call state
    226     @Test
    227     @SmallTest
    228     public void testWriteImsCallState() throws Exception {
    229         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    230         mMetrics.writeImsCallState(mPhone.getPhoneId(), mImsCallSession, Call.State.ACTIVE);
    231         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    232         TelephonyLog log = buildProto();
    233 
    234         assertEquals(0, log.events.length);
    235         assertEquals(1, log.callSessions.length);
    236         assertEquals(0, log.smsSessions.length);
    237         assertEquals(2, log.callSessions[0].events.length);
    238         assertFalse(log.callSessions[0].eventsDropped);
    239 
    240         assertEquals(123, log.callSessions[0].events[1].callIndex);
    241 
    242         assertEquals(CallState.CALL_ACTIVE, log.callSessions[0].events[1].callState);
    243     }
    244 
    245     // Test write ims set feature value
    246     @Test
    247     @SmallTest
    248     public void testWriteImsSetFeatureValue() throws Exception {
    249         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    250         mMetrics.writeImsSetFeatureValue(mPhone.getPhoneId(),
    251                 ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE, 0, 1, 0);
    252         mMetrics.writeImsSetFeatureValue(mPhone.getPhoneId(),
    253                 ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE, 0, 1, 0);
    254         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    255         TelephonyLog log = buildProto();
    256 
    257         assertEquals(1, log.events.length);
    258         assertEquals(1, log.callSessions.length);
    259         assertEquals(0, log.smsSessions.length);
    260         assertEquals(2, log.callSessions[0].events.length);
    261         assertFalse(log.callSessions[0].eventsDropped);
    262         assertTrue(log.callSessions[0].events[1].settings.isEnhanced4GLteModeEnabled);
    263     }
    264 
    265     // Test write on ims call handover event
    266     @Test
    267     @SmallTest
    268     public void testWriteOnImsCallHandoverEvent() throws Exception {
    269         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    270         mMetrics.writeOnImsCallHandoverEvent(mPhone.getPhoneId(),
    271                 TelephonyCallSession.Event.Type.IMS_CALL_HANDOVER, mImsCallSession, 5, 6,
    272                 mImsReasonInfo);
    273         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    274         TelephonyLog log = buildProto();
    275 
    276         assertEquals(0, log.events.length);
    277         assertEquals(1, log.callSessions.length);
    278         assertEquals(0, log.smsSessions.length);
    279         assertEquals(2, log.callSessions[0].events.length);
    280         assertFalse(log.callSessions[0].eventsDropped);
    281         assertEquals(TelephonyCallSession.Event.Type.IMS_CALL_HANDOVER,
    282                 log.callSessions[0].events[1].type);
    283         assertEquals(123, log.callSessions[0].events[1].callIndex);
    284         assertEquals(5, log.callSessions[0].events[1].srcAccessTech);
    285         assertEquals(6, log.callSessions[0].events[1].targetAccessTech);
    286 
    287         assertEquals("extramessage", log.callSessions[0].events[1].reasonInfo.extraMessage);
    288         assertEquals(456, log.callSessions[0].events[1].reasonInfo.extraCode);
    289         assertEquals(123, log.callSessions[0].events[1].reasonInfo.reasonCode);
    290     }
    291 
    292     // Test write on ims command
    293     @Test
    294     @SmallTest
    295     public void testWriteOnImsCommand() throws Exception {
    296         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    297         mMetrics.writeOnImsCommand(mPhone.getPhoneId(), mImsCallSession, 123);
    298         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    299         TelephonyLog log = buildProto();
    300 
    301         assertEquals(0, log.events.length);
    302         assertEquals(1, log.callSessions.length);
    303         assertEquals(0, log.smsSessions.length);
    304         assertEquals(2, log.callSessions[0].events.length);
    305 
    306         assertFalse(log.callSessions[0].eventsDropped);
    307 
    308         assertEquals(TelephonyCallSession.Event.Type.IMS_COMMAND,
    309                 log.callSessions[0].events[1].type);
    310 
    311         assertEquals(123, log.callSessions[0].events[1].imsCommand);
    312 
    313         assertEquals(123, log.callSessions[0].events[1].callIndex);
    314     }
    315 
    316     // Test write on ims connection state
    317     @Test
    318     @SmallTest
    319     public void testWriteOnImsConnectionState() throws Exception {
    320         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    321         mMetrics.writeOnImsConnectionState(mPhone.getPhoneId(),
    322                 ImsConnectionState.State.CONNECTED, mImsReasonInfo);
    323         mMetrics.writeOnImsConnectionState(mPhone.getPhoneId(),
    324                 ImsConnectionState.State.CONNECTED, mImsReasonInfo);
    325         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    326         TelephonyLog log = buildProto();
    327 
    328         assertEquals(1, log.events.length);
    329         assertEquals(1, log.callSessions.length);
    330         assertEquals(0, log.smsSessions.length);
    331         assertEquals(2, log.callSessions[0].events.length);
    332         assertFalse(log.eventsDropped);
    333         assertEquals(TelephonyEvent.Type.IMS_CONNECTION_STATE_CHANGED, log.events[0].type);
    334         assertEquals(ImsConnectionState.State.CONNECTED,
    335                 log.events[0].imsConnectionState.state);
    336         assertEquals(123, log.events[0].imsConnectionState.reasonInfo.reasonCode);
    337         assertEquals(456, log.events[0].imsConnectionState.reasonInfo.extraCode);
    338         assertEquals("extramessage", log.events[0].imsConnectionState.reasonInfo.extraMessage);
    339         assertFalse(log.callSessions[0].eventsDropped);
    340         assertEquals(TelephonyCallSession.Event.Type.IMS_CONNECTION_STATE_CHANGED,
    341                 log.callSessions[0].events[1].type);
    342         assertEquals(ImsConnectionState.State.CONNECTED,
    343                 log.callSessions[0].events[1].imsConnectionState.state);
    344     }
    345 
    346     // Test write on setup data call response
    347     @Test
    348     @SmallTest
    349     public void testWriteOnSetupDataCallResponse() throws Exception {
    350         DataCallResponse response = new DataCallResponse(5, 6, 7, 8, "IPV4V6", FAKE_IFNAME,
    351                 FAKE_ADDRESS, FAKE_DNS, FAKE_GATEWAY, FAKE_PCSCF_ADDRESS, 1440);
    352 
    353         mMetrics.writeOnRilSolicitedResponse(mPhone.getPhoneId(), 1, 2,
    354                 RIL_REQUEST_SETUP_DATA_CALL, response);
    355         TelephonyLog log = buildProto();
    356 
    357         assertEquals(1, log.events.length);
    358         assertEquals(0, log.callSessions.length);
    359         assertEquals(0, log.smsSessions.length);
    360         assertFalse(log.eventsDropped);
    361 
    362         TelephonyEvent.RilSetupDataCallResponse respProto = log.events[0].setupDataCallResponse;
    363 
    364         assertEquals(5, respProto.status);
    365         assertEquals(6, respProto.suggestedRetryTimeMillis);
    366         assertEquals(7, respProto.call.cid);
    367         assertEquals(PDP_TYPE_IPV4V6, respProto.call.type);
    368         assertEquals(FAKE_IFNAME, respProto.call.iframe);
    369     }
    370 
    371     // Test write on deactivate data call response
    372     @Test
    373     @SmallTest
    374     public void testWriteOnDeactivateDataCallResponse() throws Exception {
    375         mMetrics.writeOnRilSolicitedResponse(mPhone.getPhoneId(), 2, 3,
    376                 RIL_REQUEST_DEACTIVATE_DATA_CALL, null);
    377         TelephonyLog log = buildProto();
    378 
    379         assertEquals(1, log.events.length);
    380         assertEquals(0, log.callSessions.length);
    381         assertEquals(0, log.smsSessions.length);
    382         assertFalse(log.eventsDropped);
    383 
    384         assertEquals(TelephonyEvent.Type.DATA_CALL_DEACTIVATE_RESPONSE, log.events[0].type);
    385         assertEquals(4, log.events[0].error);
    386     }
    387 
    388     // Test write RIL send SMS
    389     @Test
    390     @SmallTest
    391     public void testWriteRilSendSms() throws Exception {
    392         mMetrics.writeRilSendSms(mPhone.getPhoneId(), 1, 2, 1);
    393         mMetrics.writeRilSendSms(mPhone.getPhoneId(), 4, 5, 2);
    394 
    395         SmsResponse response = new SmsResponse(0, null, 123);
    396 
    397         mMetrics.writeOnRilSolicitedResponse(mPhone.getPhoneId(), 1, 0, RIL_REQUEST_SEND_SMS,
    398                 response);
    399         response = new SmsResponse(0, null, 456);
    400         mMetrics.writeOnRilSolicitedResponse(mPhone.getPhoneId(), 4, 0, RIL_REQUEST_SEND_SMS,
    401                 response);
    402         TelephonyLog log = buildProto();
    403 
    404         assertEquals(0, log.events.length);
    405         assertEquals(0, log.callSessions.length);
    406         assertEquals(1, log.smsSessions.length);
    407         assertFalse(log.eventsDropped);
    408 
    409         SmsSession.Event[] events = log.smsSessions[0].events;
    410         assertEquals(4, events.length);
    411         assertEquals(SmsSession.Event.Type.SMS_SEND, events[0].type);
    412         assertEquals(1, events[0].rilRequestId);
    413         assertEquals(2, events[0].tech);
    414         assertEquals(1, events[0].format);
    415 
    416         assertEquals(SmsSession.Event.Type.SMS_SEND, events[1].type);
    417         assertEquals(4, events[1].rilRequestId);
    418         assertEquals(5, events[1].tech);
    419         assertEquals(2, events[1].format);
    420 
    421         assertEquals(SmsSession.Event.Type.SMS_SEND_RESULT, events[2].type);
    422         assertEquals(1, events[2].rilRequestId);
    423         assertEquals(1, events[2].error);
    424         assertEquals(123, events[2].errorCode);
    425 
    426         assertEquals(SmsSession.Event.Type.SMS_SEND_RESULT, events[3].type);
    427         assertEquals(4, events[3].rilRequestId);
    428         assertEquals(1, events[3].error);
    429         assertEquals(456, events[3].errorCode);
    430     }
    431 
    432     // Test write phone state
    433     @Test
    434     @SmallTest
    435     public void testWritePhoneState() throws Exception {
    436         mMetrics.writeOnImsCallStart(mPhone.getPhoneId(), mImsCallSession);
    437         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.OFFHOOK);
    438         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    439         TelephonyLog log = buildProto();
    440 
    441         assertEquals(0, log.events.length);
    442         assertEquals(1, log.callSessions.length);
    443         assertEquals(0, log.smsSessions.length);
    444         assertFalse(log.eventsDropped);
    445 
    446         assertEquals(mPhone.getPhoneId(), log.callSessions[0].phoneId);
    447         assertEquals(2, log.callSessions[0].events.length);
    448         assertEquals(TelephonyCallSession.Event.Type.PHONE_STATE_CHANGED,
    449                 log.callSessions[0].events[1].type);
    450         assertEquals(TelephonyCallSession.Event.PhoneState.STATE_OFFHOOK,
    451                 log.callSessions[0].events[1].phoneState);
    452     }
    453 
    454     // Test write RIL dial and hangup
    455     @Test
    456     @SmallTest
    457     public void testWriteRilDialHangup() throws Exception {
    458         doReturn(Call.State.DIALING).when(mConnection).getState();
    459         mMetrics.writeRilDial(mPhone.getPhoneId(), mConnection, 2, mUusInfo);
    460         doReturn(Call.State.DISCONNECTED).when(mConnection).getState();
    461         mMetrics.writeRilHangup(mPhone.getPhoneId(), mConnection, 3);
    462         mMetrics.writePhoneState(mPhone.getPhoneId(), PhoneConstants.State.IDLE);
    463         TelephonyLog log = buildProto();
    464 
    465         assertEquals(0, log.events.length);
    466         assertEquals(1, log.callSessions.length);
    467         assertEquals(0, log.smsSessions.length);
    468         assertFalse(log.eventsDropped);
    469 
    470         TelephonyCallSession.Event[] events = log.callSessions[0].events;
    471 
    472         assertEquals(2, events.length);
    473         assertEquals(TelephonyCallSession.Event.Type.RIL_REQUEST, events[0].type);
    474 
    475         assertEquals(TelephonyCallSession.Event.RilRequest.RIL_REQUEST_DIAL,
    476                 events[0].rilRequest);
    477         RilCall[] calls = events[0].calls;
    478         assertEquals(CallState.CALL_DIALING, calls[0].state);
    479 
    480         assertEquals(TelephonyCallSession.Event.RilRequest.RIL_REQUEST_HANGUP,
    481                 events[1].rilRequest);
    482         calls = events[1].calls;
    483         assertEquals(3, calls[0].index);
    484         assertEquals(CallState.CALL_DISCONNECTED, calls[0].state);
    485     }
    486 
    487     // Test write RIL setup data call
    488     @Test
    489     @SmallTest
    490     public void testWriteRilSetupDataCall() throws Exception {
    491         mMetrics.writeRilSetupDataCall(
    492                 mPhone.getPhoneId(), 1, 14, 3, "apn", 0, "IPV4V6");
    493 
    494         TelephonyLog log = buildProto();
    495 
    496         assertEquals(1, log.events.length);
    497         assertEquals(0, log.callSessions.length);
    498         assertEquals(0, log.smsSessions.length);
    499 
    500         assertFalse(log.eventsDropped);
    501 
    502 
    503         assertEquals(TelephonyEvent.Type.DATA_CALL_SETUP, log.events[0].type);
    504 
    505         TelephonyEvent.RilSetupDataCall setupDataCall = log.events[0].setupDataCall;
    506 
    507         assertEquals("apn", setupDataCall.apn);
    508 
    509         assertEquals(14, setupDataCall.rat);
    510 
    511         assertEquals(4, setupDataCall.dataProfile);
    512 
    513         assertEquals(PDP_TYPE_IPV4V6, setupDataCall.type);
    514     }
    515 
    516     // Test write service state changed
    517     @Test
    518     @SmallTest
    519     public void testWriteServiceStateChanged() throws Exception {
    520         mMetrics.writeServiceStateChanged(mPhone.getPhoneId(), mServiceState);
    521         mMetrics.writeServiceStateChanged(mPhone.getPhoneId(), mServiceState);
    522         TelephonyLog log = buildProto();
    523 
    524         assertEquals(1, log.events.length);
    525         assertEquals(0, log.callSessions.length);
    526         assertEquals(0, log.smsSessions.length);
    527 
    528         assertFalse(log.eventsDropped);
    529 
    530         TelephonyEvent event = log.events[0];
    531 
    532         assertEquals(TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED, event.type);
    533 
    534         TelephonyServiceState state = event.serviceState;
    535 
    536         assertEquals(RadioAccessTechnology.RAT_LTE, state.voiceRat);
    537 
    538         assertEquals(RadioAccessTechnology.RAT_LTE, state.dataRat);
    539 
    540         assertEquals(RoamingType.ROAMING_TYPE_DOMESTIC, state.voiceRoamingType);
    541 
    542         assertEquals(RoamingType.ROAMING_TYPE_DOMESTIC, state.dataRoamingType);
    543 
    544         assertEquals("voicelong", state.voiceOperator.alphaLong);
    545 
    546         assertEquals("voiceshort", state.voiceOperator.alphaShort);
    547 
    548         assertEquals("123456", state.voiceOperator.numeric);
    549 
    550         assertEquals("datalong", state.dataOperator.alphaLong);
    551 
    552         assertEquals("datashort", state.dataOperator.alphaShort);
    553 
    554         assertEquals("123456", state.dataOperator.numeric);
    555     }
    556 
    557     // Test reset scenario
    558     @Test
    559     @SmallTest
    560     public void testReset() throws Exception {
    561         mMetrics.writeServiceStateChanged(mPhone.getPhoneId(), mServiceState);
    562         reset();
    563         TelephonyLog log = buildProto();
    564 
    565         assertEquals(1, log.events.length);
    566         assertEquals(0, log.callSessions.length);
    567         assertEquals(0, log.smsSessions.length);
    568 
    569         assertFalse(log.eventsDropped);
    570 
    571         TelephonyEvent event = log.events[0];
    572 
    573         assertEquals(TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED, event.type);
    574 
    575         TelephonyServiceState state = event.serviceState;
    576 
    577         assertEquals(RadioAccessTechnology.RAT_LTE, state.voiceRat);
    578 
    579         assertEquals(RadioAccessTechnology.RAT_LTE, state.dataRat);
    580 
    581         assertEquals(RoamingType.ROAMING_TYPE_DOMESTIC, state.voiceRoamingType);
    582 
    583         assertEquals(RoamingType.ROAMING_TYPE_DOMESTIC, state.dataRoamingType);
    584 
    585         assertEquals("voicelong", state.voiceOperator.alphaLong);
    586 
    587         assertEquals("voiceshort", state.voiceOperator.alphaShort);
    588 
    589         assertEquals("123456", state.voiceOperator.numeric);
    590 
    591         assertEquals("datalong", state.dataOperator.alphaLong);
    592 
    593         assertEquals("datashort", state.dataOperator.alphaShort);
    594 
    595         assertEquals("123456", state.dataOperator.numeric);
    596     }
    597 
    598     // Test Proto Encoding/Decoding
    599     @Test
    600     @SmallTest
    601     public void testProtoEncodingDecoding() throws Exception {
    602         mMetrics.writeServiceStateChanged(mPhone.getPhoneId(), mServiceState);
    603         TelephonyLog log = buildProto();
    604         String encodedString = convertProtoToBase64String(log);
    605 
    606         byte[] decodedString = Base64.decode(encodedString, Base64.DEFAULT);
    607         assertArrayEquals(TelephonyProto.TelephonyLog.toByteArray(log), decodedString);
    608     }
    609 
    610     // Test write ims capabilities changed
    611     @Test
    612     @SmallTest
    613     public void testWriteOnImsCapabilities() throws Exception {
    614         boolean[] caps1 = new boolean[]{true, false, true, false, true, false};
    615         mMetrics.writeOnImsCapabilities(mPhone.getPhoneId(), caps1);
    616         boolean[] caps2 = new boolean[]{true, false, true, false, true, false};
    617         // The duplicate one should be filtered out.
    618         mMetrics.writeOnImsCapabilities(mPhone.getPhoneId(), caps2);
    619         boolean[] caps3 = new boolean[]{false, true, false, true, false, true};
    620         mMetrics.writeOnImsCapabilities(mPhone.getPhoneId(), caps3);
    621         TelephonyLog log = buildProto();
    622 
    623         assertEquals(2, log.events.length);
    624         assertEquals(0, log.callSessions.length);
    625         assertEquals(0, log.smsSessions.length);
    626 
    627         TelephonyEvent event = log.events[0];
    628 
    629         assertEquals(TelephonyEvent.Type.IMS_CAPABILITIES_CHANGED, event.type);
    630         assertEquals(caps1[0], event.imsCapabilities.voiceOverLte);
    631         assertEquals(caps1[1], event.imsCapabilities.videoOverLte);
    632         assertEquals(caps1[2], event.imsCapabilities.voiceOverWifi);
    633         assertEquals(caps1[3], event.imsCapabilities.videoOverWifi);
    634         assertEquals(caps1[4], event.imsCapabilities.utOverLte);
    635         assertEquals(caps1[5], event.imsCapabilities.utOverWifi);
    636 
    637         event = log.events[1];
    638 
    639         assertEquals(TelephonyEvent.Type.IMS_CAPABILITIES_CHANGED, event.type);
    640         assertEquals(caps3[0], event.imsCapabilities.voiceOverLte);
    641         assertEquals(caps3[1], event.imsCapabilities.videoOverLte);
    642         assertEquals(caps3[2], event.imsCapabilities.voiceOverWifi);
    643         assertEquals(caps3[3], event.imsCapabilities.videoOverWifi);
    644         assertEquals(caps3[4], event.imsCapabilities.utOverLte);
    645         assertEquals(caps3[5], event.imsCapabilities.utOverWifi);
    646     }
    647 }
    648