blob: 0ee9babe665915cb4b207595326ffd7d472a9ff4 [file] [log] [blame]
Hall Liu0464b9b2016-01-12 15:32:58 -08001/*
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 android.telecom;
18
19import android.annotation.SystemApi;
20import android.os.Parcel;
21import android.os.Parcelable;
22
Hall Liu057def52016-05-05 17:17:07 -070023import java.util.ArrayList;
24import java.util.List;
25
Hall Liu0464b9b2016-01-12 15:32:58 -080026/**
27 * @hide
28 */
29@SystemApi
30public class ParcelableCallAnalytics implements Parcelable {
Hall Liu057def52016-05-05 17:17:07 -070031 public static final class AnalyticsEvent implements Parcelable {
32 public static final int SET_SELECT_PHONE_ACCOUNT = 0;
33 public static final int SET_ACTIVE = 1;
34 public static final int SET_DISCONNECTED = 2;
35 public static final int START_CONNECTION = 3;
36 public static final int SET_DIALING = 4;
37 public static final int BIND_CS = 5;
38 public static final int CS_BOUND = 6;
39 public static final int REQUEST_ACCEPT = 7;
40 public static final int REQUEST_REJECT = 8;
41
42 public static final int SCREENING_SENT = 100;
43 public static final int SCREENING_COMPLETED = 101;
44 public static final int DIRECT_TO_VM_INITIATED = 102;
45 public static final int DIRECT_TO_VM_FINISHED = 103;
46 public static final int BLOCK_CHECK_INITIATED = 104;
47 public static final int BLOCK_CHECK_FINISHED = 105;
48 public static final int FILTERING_INITIATED = 106;
49 public static final int FILTERING_COMPLETED = 107;
50 public static final int FILTERING_TIMED_OUT = 108;
51
52 public static final int SKIP_RINGING = 200;
53 public static final int SILENCE = 201;
54 public static final int MUTE = 202;
55 public static final int UNMUTE = 203;
56 public static final int AUDIO_ROUTE_BT = 204;
57 public static final int AUDIO_ROUTE_EARPIECE = 205;
58 public static final int AUDIO_ROUTE_HEADSET = 206;
59 public static final int AUDIO_ROUTE_SPEAKER = 207;
60
61 public static final int CONFERENCE_WITH = 300;
62 public static final int SPLIT_CONFERENCE = 301;
63 public static final int SET_PARENT = 302;
64
65 public static final int REQUEST_HOLD = 400;
66 public static final int REQUEST_UNHOLD = 401;
67 public static final int REMOTELY_HELD = 402;
68 public static final int REMOTELY_UNHELD = 403;
69 public static final int SET_HOLD = 404;
70 public static final int SWAP = 405;
71
72 public static final int REQUEST_PULL = 500;
73
74
75 public static final Parcelable.Creator<AnalyticsEvent> CREATOR =
76 new Parcelable.Creator<AnalyticsEvent> () {
77
78 @Override
79 public AnalyticsEvent createFromParcel(Parcel in) {
80 return new AnalyticsEvent(in);
81 }
82
83 @Override
84 public AnalyticsEvent[] newArray(int size) {
85 return new AnalyticsEvent[size];
86 }
87 };
88
89 private int mEventName;
90 private long mTimeSinceLastEvent;
91
92 public AnalyticsEvent(int eventName, long timestamp) {
93 mEventName = eventName;
94 mTimeSinceLastEvent = timestamp;
95 }
96
97 AnalyticsEvent(Parcel in) {
98 mEventName = in.readInt();
99 mTimeSinceLastEvent = in.readLong();
100 }
101
102 public int getEventName() {
103 return mEventName;
104 }
105
106 public long getTimeSinceLastEvent() {
107 return mTimeSinceLastEvent;
108 }
109
110 @Override
111 public int describeContents() {
112 return 0;
113 }
114
115 @Override
116 public void writeToParcel(Parcel out, int flags) {
117 out.writeInt(mEventName);
118 out.writeLong(mTimeSinceLastEvent);
119 }
120 }
121
122 public static final class EventTiming implements Parcelable {
123 public static final int ACCEPT_TIMING = 0;
124 public static final int REJECT_TIMING = 1;
125 public static final int DISCONNECT_TIMING = 2;
126 public static final int HOLD_TIMING = 3;
127 public static final int UNHOLD_TIMING = 4;
128 public static final int OUTGOING_TIME_TO_DIALING_TIMING = 5;
129 public static final int BIND_CS_TIMING = 6;
130 public static final int SCREENING_COMPLETED_TIMING = 7;
131 public static final int DIRECT_TO_VM_FINISHED_TIMING = 8;
132 public static final int BLOCK_CHECK_FINISHED_TIMING = 9;
133 public static final int FILTERING_COMPLETED_TIMING = 10;
134 public static final int FILTERING_TIMED_OUT_TIMING = 11;
135
136 public static final int INVALID = 999999;
137
138 public static final Parcelable.Creator<EventTiming> CREATOR =
139 new Parcelable.Creator<EventTiming> () {
140
141 @Override
142 public EventTiming createFromParcel(Parcel in) {
143 return new EventTiming(in);
144 }
145
146 @Override
147 public EventTiming[] newArray(int size) {
148 return new EventTiming[size];
149 }
150 };
151
152 private int mName;
153 private long mTime;
154
155 public EventTiming(int name, long time) {
156 this.mName = name;
157 this.mTime = time;
158 }
159
160 private EventTiming(Parcel in) {
161 mName = in.readInt();
162 mTime = in.readLong();
163 }
164
165 public int getName() {
166 return mName;
167 }
168
169 public long getTime() {
170 return mTime;
171 }
172
173 @Override
174 public int describeContents() {
175 return 0;
176 }
177
178 @Override
179 public void writeToParcel(Parcel out, int flags) {
180 out.writeInt(mName);
181 out.writeLong(mTime);
182 }
183 }
184
Hall Liu0464b9b2016-01-12 15:32:58 -0800185 public static final int CALLTYPE_UNKNOWN = 0;
186 public static final int CALLTYPE_INCOMING = 1;
187 public static final int CALLTYPE_OUTGOING = 2;
188
189 // Constants for call technology
190 public static final int CDMA_PHONE = 0x1;
191 public static final int GSM_PHONE = 0x2;
192 public static final int IMS_PHONE = 0x4;
193 public static final int SIP_PHONE = 0x8;
194 public static final int THIRD_PARTY_PHONE = 0x10;
195
196 public static final long MILLIS_IN_5_MINUTES = 1000 * 60 * 5;
197 public static final long MILLIS_IN_1_SECOND = 1000;
198
199 public static final int STILL_CONNECTED = -1;
200
201 public static final Parcelable.Creator<ParcelableCallAnalytics> CREATOR =
202 new Parcelable.Creator<ParcelableCallAnalytics> () {
203
204 @Override
205 public ParcelableCallAnalytics createFromParcel(Parcel in) {
206 return new ParcelableCallAnalytics(in);
207 }
208
209 @Override
210 public ParcelableCallAnalytics[] newArray(int size) {
211 return new ParcelableCallAnalytics[size];
212 }
213 };
214
215 // The start time of the call in milliseconds since Jan. 1, 1970, rounded to the nearest
216 // 5 minute increment.
217 private final long startTimeMillis;
218
219 // The duration of the call, in milliseconds.
220 private final long callDurationMillis;
221
222 // ONE OF calltype_unknown, calltype_incoming, or calltype_outgoing
223 private final int callType;
224
225 // true if the call came in while another call was in progress or if the user dialed this call
226 // while in the middle of another call.
227 private final boolean isAdditionalCall;
228
229 // true if the call was interrupted by an incoming or outgoing call.
230 private final boolean isInterrupted;
231
232 // bitmask denoting which technologies a call used.
233 private final int callTechnologies;
234
235 // Any of the DisconnectCause codes, or STILL_CONNECTED.
236 private final int callTerminationCode;
237
238 // Whether the call is an emergency call
239 private final boolean isEmergencyCall;
240
241 // The package name of the connection service that this call used.
242 private final String connectionService;
243
244 // Whether the call object was created from an existing connection.
245 private final boolean isCreatedFromExistingConnection;
246
Hall Liu057def52016-05-05 17:17:07 -0700247 // A list of events that are associated with this call
248 private final List<AnalyticsEvent> analyticsEvents;
249
250 // A map from event-pair names to their durations.
251 private final List<EventTiming> eventTimings;
252
Hall Liu0464b9b2016-01-12 15:32:58 -0800253 public ParcelableCallAnalytics(long startTimeMillis, long callDurationMillis, int callType,
254 boolean isAdditionalCall, boolean isInterrupted, int callTechnologies,
255 int callTerminationCode, boolean isEmergencyCall, String connectionService,
Hall Liu057def52016-05-05 17:17:07 -0700256 boolean isCreatedFromExistingConnection, List<AnalyticsEvent> analyticsEvents,
257 List<EventTiming> eventTimings) {
Hall Liu0464b9b2016-01-12 15:32:58 -0800258 this.startTimeMillis = startTimeMillis;
259 this.callDurationMillis = callDurationMillis;
260 this.callType = callType;
261 this.isAdditionalCall = isAdditionalCall;
262 this.isInterrupted = isInterrupted;
263 this.callTechnologies = callTechnologies;
264 this.callTerminationCode = callTerminationCode;
265 this.isEmergencyCall = isEmergencyCall;
266 this.connectionService = connectionService;
267 this.isCreatedFromExistingConnection = isCreatedFromExistingConnection;
Hall Liu057def52016-05-05 17:17:07 -0700268 this.analyticsEvents = analyticsEvents;
269 this.eventTimings = eventTimings;
Hall Liu0464b9b2016-01-12 15:32:58 -0800270 }
271
272 public ParcelableCallAnalytics(Parcel in) {
273 startTimeMillis = in.readLong();
274 callDurationMillis = in.readLong();
275 callType = in.readInt();
276 isAdditionalCall = readByteAsBoolean(in);
277 isInterrupted = readByteAsBoolean(in);
278 callTechnologies = in.readInt();
279 callTerminationCode = in.readInt();
280 isEmergencyCall = readByteAsBoolean(in);
281 connectionService = in.readString();
282 isCreatedFromExistingConnection = readByteAsBoolean(in);
Hall Liu057def52016-05-05 17:17:07 -0700283 analyticsEvents = new ArrayList<>();
284 in.readTypedList(analyticsEvents, AnalyticsEvent.CREATOR);
285 eventTimings = new ArrayList<>();
286 in.readTypedList(eventTimings, EventTiming.CREATOR);
Hall Liu0464b9b2016-01-12 15:32:58 -0800287 }
288
289 public void writeToParcel(Parcel out, int flags) {
290 out.writeLong(startTimeMillis);
291 out.writeLong(callDurationMillis);
292 out.writeInt(callType);
293 writeBooleanAsByte(out, isAdditionalCall);
294 writeBooleanAsByte(out, isInterrupted);
295 out.writeInt(callTechnologies);
296 out.writeInt(callTerminationCode);
297 writeBooleanAsByte(out, isEmergencyCall);
298 out.writeString(connectionService);
299 writeBooleanAsByte(out, isCreatedFromExistingConnection);
Hall Liu057def52016-05-05 17:17:07 -0700300 out.writeTypedList(analyticsEvents);
301 out.writeTypedList(eventTimings);
Hall Liu0464b9b2016-01-12 15:32:58 -0800302 }
303
304 public long getStartTimeMillis() {
305 return startTimeMillis;
306 }
307
308 public long getCallDurationMillis() {
309 return callDurationMillis;
310 }
311
312 public int getCallType() {
313 return callType;
314 }
315
316 public boolean isAdditionalCall() {
317 return isAdditionalCall;
318 }
319
320 public boolean isInterrupted() {
321 return isInterrupted;
322 }
323
324 public int getCallTechnologies() {
325 return callTechnologies;
326 }
327
328 public int getCallTerminationCode() {
329 return callTerminationCode;
330 }
331
332 public boolean isEmergencyCall() {
333 return isEmergencyCall;
334 }
335
336 public String getConnectionService() {
337 return connectionService;
338 }
339
340 public boolean isCreatedFromExistingConnection() {
341 return isCreatedFromExistingConnection;
342 }
343
Hall Liu057def52016-05-05 17:17:07 -0700344 public List<AnalyticsEvent> analyticsEvents() {
345 return analyticsEvents;
346 }
347
348 public List<EventTiming> getEventTimings() {
349 return eventTimings;
350 }
351
Hall Liu0464b9b2016-01-12 15:32:58 -0800352 @Override
353 public int describeContents() {
354 return 0;
355 }
356
357 private static void writeBooleanAsByte(Parcel out, boolean b) {
358 out.writeByte((byte) (b ? 1 : 0));
359 }
360
361 private static boolean readByteAsBoolean(Parcel in) {
362 return (in.readByte() == 1);
363 }
364}