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