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