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 com.android.internal.telephony.nano.TelephonyProto.ImsCapabilities;
     20 import static com.android.internal.telephony.nano.TelephonyProto.ImsConnectionState;
     21 import static com.android.internal.telephony.nano.TelephonyProto.RilDataCall;
     22 import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent;
     23 import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.ModemRestart;
     24 import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
     25 import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCall;
     26 import static com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCallResponse;
     27 import static com.android.internal.telephony.nano.TelephonyProto.TelephonyServiceState;
     28 import static com.android.internal.telephony.nano.TelephonyProto.TelephonySettings;
     29 
     30 import android.os.SystemClock;
     31 
     32 public class TelephonyEventBuilder {
     33     private final TelephonyEvent mEvent = new TelephonyEvent();
     34 
     35     public TelephonyEvent build() {
     36         return mEvent;
     37     }
     38 
     39     public TelephonyEventBuilder(int phoneId) {
     40         this(SystemClock.elapsedRealtime(), phoneId);
     41     }
     42 
     43     public TelephonyEventBuilder(long timestamp, int phoneId) {
     44         mEvent.timestampMillis = timestamp;
     45         mEvent.phoneId = phoneId;
     46     }
     47 
     48     public TelephonyEventBuilder setSettings(TelephonySettings settings) {
     49         mEvent.type = TelephonyEvent.Type.SETTINGS_CHANGED;
     50         mEvent.settings = settings;
     51         return this;
     52     }
     53 
     54     public TelephonyEventBuilder setServiceState(TelephonyServiceState state) {
     55         mEvent.type = TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED;
     56         mEvent.serviceState = state;
     57         return this;
     58     }
     59 
     60     public TelephonyEventBuilder setImsConnectionState(ImsConnectionState state) {
     61         mEvent.type = TelephonyEvent.Type.IMS_CONNECTION_STATE_CHANGED;
     62         mEvent.imsConnectionState = state;
     63         return this;
     64     }
     65 
     66     public TelephonyEventBuilder setImsCapabilities(ImsCapabilities capabilities) {
     67         mEvent.type = TelephonyEvent.Type.IMS_CAPABILITIES_CHANGED;
     68         mEvent.imsCapabilities = capabilities;
     69         return this;
     70     }
     71 
     72     public TelephonyEventBuilder setDataStallRecoveryAction(int action) {
     73         mEvent.type = TelephonyEvent.Type.DATA_STALL_ACTION;
     74         mEvent.dataStallAction = action;
     75         return this;
     76     }
     77 
     78     public TelephonyEventBuilder setSetupDataCall(RilSetupDataCall request) {
     79         mEvent.type = TelephonyEvent.Type.DATA_CALL_SETUP;
     80         mEvent.setupDataCall = request;
     81         return this;
     82     }
     83 
     84     public TelephonyEventBuilder setSetupDataCallResponse(RilSetupDataCallResponse rsp) {
     85         mEvent.type = TelephonyEvent.Type.DATA_CALL_SETUP_RESPONSE;
     86         mEvent.setupDataCallResponse = rsp;
     87         return this;
     88     }
     89 
     90     public TelephonyEventBuilder setDeactivateDataCall(RilDeactivateDataCall request) {
     91         mEvent.type = TelephonyEvent.Type.DATA_CALL_DEACTIVATE;
     92         mEvent.deactivateDataCall = request;
     93         return this;
     94     }
     95 
     96     public TelephonyEventBuilder setDeactivateDataCallResponse(int errno) {
     97         mEvent.type = TelephonyEvent.Type.DATA_CALL_DEACTIVATE_RESPONSE;
     98         mEvent.error = errno;
     99         return this;
    100     }
    101 
    102     public TelephonyEventBuilder setDataCalls(RilDataCall[] dataCalls) {
    103         mEvent.type = TelephonyEvent.Type.DATA_CALL_LIST_CHANGED;
    104         mEvent.dataCalls = dataCalls;
    105         return this;
    106     }
    107 
    108     public TelephonyEventBuilder setNITZ(long timestamp) {
    109         mEvent.type = TelephonyEvent.Type.NITZ_TIME;
    110         mEvent.nitzTimestampMillis = timestamp;
    111         return this;
    112     }
    113 
    114     public TelephonyEventBuilder setModemRestart(ModemRestart modemRestart) {
    115         mEvent.type = TelephonyEvent.Type.MODEM_RESTART;
    116         mEvent.modemRestart = modemRestart;
    117         return this;
    118     }
    119 }
    120