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