blob: 318d8411931b5619959727817b3fcce6f9cb2c99 [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;
Hall Liubd72c9f2016-06-22 17:11:08 -070024import java.util.LinkedList;
Hall Liu057def52016-05-05 17:17:07 -070025import java.util.List;
26
Hall Liu0464b9b2016-01-12 15:32:58 -080027/**
28 * @hide
29 */
30@SystemApi
31public class ParcelableCallAnalytics implements Parcelable {
Hall Liubd72c9f2016-06-22 17:11:08 -070032 public static final class VideoEvent implements Parcelable {
33 public static final int SEND_LOCAL_SESSION_MODIFY_REQUEST = 0;
34 public static final int SEND_LOCAL_SESSION_MODIFY_RESPONSE = 1;
35 public static final int RECEIVE_REMOTE_SESSION_MODIFY_REQUEST = 2;
36 public static final int RECEIVE_REMOTE_SESSION_MODIFY_RESPONSE = 3;
37
38 public static final Parcelable.Creator<VideoEvent> CREATOR =
39 new Parcelable.Creator<VideoEvent> () {
40
41 @Override
42 public VideoEvent createFromParcel(Parcel in) {
43 return new VideoEvent(in);
44 }
45
46 @Override
47 public VideoEvent[] newArray(int size) {
48 return new VideoEvent[size];
49 }
50 };
51
52 private int mEventName;
53 private long mTimeSinceLastEvent;
54 private int mVideoState;
55
56 public VideoEvent(int eventName, long timeSinceLastEvent, int videoState) {
57 mEventName = eventName;
58 mTimeSinceLastEvent = timeSinceLastEvent;
59 mVideoState = videoState;
60 }
61
62 VideoEvent(Parcel in) {
63 mEventName = in.readInt();
64 mTimeSinceLastEvent = in.readLong();
65 mVideoState = in.readInt();
66 }
67
68 public int getEventName() {
69 return mEventName;
70 }
71
72 public long getTimeSinceLastEvent() {
73 return mTimeSinceLastEvent;
74 }
75
76 public int getVideoState() {
77 return mVideoState;
78 }
79
80 @Override
81 public int describeContents() {
82 return 0;
83 }
84
85 @Override
86 public void writeToParcel(Parcel out, int flags) {
87 out.writeInt(mEventName);
88 out.writeLong(mTimeSinceLastEvent);
89 out.writeInt(mVideoState);
90 }
91 }
92
Hall Liu057def52016-05-05 17:17:07 -070093 public static final class AnalyticsEvent implements Parcelable {
94 public static final int SET_SELECT_PHONE_ACCOUNT = 0;
95 public static final int SET_ACTIVE = 1;
96 public static final int SET_DISCONNECTED = 2;
97 public static final int START_CONNECTION = 3;
98 public static final int SET_DIALING = 4;
99 public static final int BIND_CS = 5;
100 public static final int CS_BOUND = 6;
101 public static final int REQUEST_ACCEPT = 7;
102 public static final int REQUEST_REJECT = 8;
103
104 public static final int SCREENING_SENT = 100;
105 public static final int SCREENING_COMPLETED = 101;
106 public static final int DIRECT_TO_VM_INITIATED = 102;
107 public static final int DIRECT_TO_VM_FINISHED = 103;
108 public static final int BLOCK_CHECK_INITIATED = 104;
109 public static final int BLOCK_CHECK_FINISHED = 105;
110 public static final int FILTERING_INITIATED = 106;
111 public static final int FILTERING_COMPLETED = 107;
112 public static final int FILTERING_TIMED_OUT = 108;
113
114 public static final int SKIP_RINGING = 200;
115 public static final int SILENCE = 201;
116 public static final int MUTE = 202;
117 public static final int UNMUTE = 203;
118 public static final int AUDIO_ROUTE_BT = 204;
119 public static final int AUDIO_ROUTE_EARPIECE = 205;
120 public static final int AUDIO_ROUTE_HEADSET = 206;
121 public static final int AUDIO_ROUTE_SPEAKER = 207;
122
123 public static final int CONFERENCE_WITH = 300;
124 public static final int SPLIT_CONFERENCE = 301;
125 public static final int SET_PARENT = 302;
126
127 public static final int REQUEST_HOLD = 400;
128 public static final int REQUEST_UNHOLD = 401;
129 public static final int REMOTELY_HELD = 402;
130 public static final int REMOTELY_UNHELD = 403;
131 public static final int SET_HOLD = 404;
132 public static final int SWAP = 405;
133
134 public static final int REQUEST_PULL = 500;
135
136
137 public static final Parcelable.Creator<AnalyticsEvent> CREATOR =
138 new Parcelable.Creator<AnalyticsEvent> () {
139
140 @Override
141 public AnalyticsEvent createFromParcel(Parcel in) {
142 return new AnalyticsEvent(in);
143 }
144
145 @Override
146 public AnalyticsEvent[] newArray(int size) {
147 return new AnalyticsEvent[size];
148 }
149 };
150
151 private int mEventName;
152 private long mTimeSinceLastEvent;
153
154 public AnalyticsEvent(int eventName, long timestamp) {
155 mEventName = eventName;
156 mTimeSinceLastEvent = timestamp;
157 }
158
159 AnalyticsEvent(Parcel in) {
160 mEventName = in.readInt();
161 mTimeSinceLastEvent = in.readLong();
162 }
163
164 public int getEventName() {
165 return mEventName;
166 }
167
168 public long getTimeSinceLastEvent() {
169 return mTimeSinceLastEvent;
170 }
171
172 @Override
173 public int describeContents() {
174 return 0;
175 }
176
177 @Override
178 public void writeToParcel(Parcel out, int flags) {
179 out.writeInt(mEventName);
180 out.writeLong(mTimeSinceLastEvent);
181 }
182 }
183
184 public static final class EventTiming implements Parcelable {
185 public static final int ACCEPT_TIMING = 0;
186 public static final int REJECT_TIMING = 1;
187 public static final int DISCONNECT_TIMING = 2;
188 public static final int HOLD_TIMING = 3;
189 public static final int UNHOLD_TIMING = 4;
190 public static final int OUTGOING_TIME_TO_DIALING_TIMING = 5;
191 public static final int BIND_CS_TIMING = 6;
192 public static final int SCREENING_COMPLETED_TIMING = 7;
193 public static final int DIRECT_TO_VM_FINISHED_TIMING = 8;
194 public static final int BLOCK_CHECK_FINISHED_TIMING = 9;
195 public static final int FILTERING_COMPLETED_TIMING = 10;
196 public static final int FILTERING_TIMED_OUT_TIMING = 11;
197
198 public static final int INVALID = 999999;
199
200 public static final Parcelable.Creator<EventTiming> CREATOR =
201 new Parcelable.Creator<EventTiming> () {
202
203 @Override
204 public EventTiming createFromParcel(Parcel in) {
205 return new EventTiming(in);
206 }
207
208 @Override
209 public EventTiming[] newArray(int size) {
210 return new EventTiming[size];
211 }
212 };
213
214 private int mName;
215 private long mTime;
216
217 public EventTiming(int name, long time) {
218 this.mName = name;
219 this.mTime = time;
220 }
221
222 private EventTiming(Parcel in) {
223 mName = in.readInt();
224 mTime = in.readLong();
225 }
226
227 public int getName() {
228 return mName;
229 }
230
231 public long getTime() {
232 return mTime;
233 }
234
235 @Override
236 public int describeContents() {
237 return 0;
238 }
239
240 @Override
241 public void writeToParcel(Parcel out, int flags) {
242 out.writeInt(mName);
243 out.writeLong(mTime);
244 }
245 }
246
Hall Liu0464b9b2016-01-12 15:32:58 -0800247 public static final int CALLTYPE_UNKNOWN = 0;
248 public static final int CALLTYPE_INCOMING = 1;
249 public static final int CALLTYPE_OUTGOING = 2;
250
251 // Constants for call technology
252 public static final int CDMA_PHONE = 0x1;
253 public static final int GSM_PHONE = 0x2;
254 public static final int IMS_PHONE = 0x4;
255 public static final int SIP_PHONE = 0x8;
256 public static final int THIRD_PARTY_PHONE = 0x10;
257
258 public static final long MILLIS_IN_5_MINUTES = 1000 * 60 * 5;
259 public static final long MILLIS_IN_1_SECOND = 1000;
260
261 public static final int STILL_CONNECTED = -1;
262
263 public static final Parcelable.Creator<ParcelableCallAnalytics> CREATOR =
264 new Parcelable.Creator<ParcelableCallAnalytics> () {
265
266 @Override
267 public ParcelableCallAnalytics createFromParcel(Parcel in) {
268 return new ParcelableCallAnalytics(in);
269 }
270
271 @Override
272 public ParcelableCallAnalytics[] newArray(int size) {
273 return new ParcelableCallAnalytics[size];
274 }
275 };
276
277 // The start time of the call in milliseconds since Jan. 1, 1970, rounded to the nearest
278 // 5 minute increment.
279 private final long startTimeMillis;
280
281 // The duration of the call, in milliseconds.
282 private final long callDurationMillis;
283
284 // ONE OF calltype_unknown, calltype_incoming, or calltype_outgoing
285 private final int callType;
286
287 // true if the call came in while another call was in progress or if the user dialed this call
288 // while in the middle of another call.
289 private final boolean isAdditionalCall;
290
291 // true if the call was interrupted by an incoming or outgoing call.
292 private final boolean isInterrupted;
293
294 // bitmask denoting which technologies a call used.
295 private final int callTechnologies;
296
297 // Any of the DisconnectCause codes, or STILL_CONNECTED.
298 private final int callTerminationCode;
299
300 // Whether the call is an emergency call
301 private final boolean isEmergencyCall;
302
303 // The package name of the connection service that this call used.
304 private final String connectionService;
305
306 // Whether the call object was created from an existing connection.
307 private final boolean isCreatedFromExistingConnection;
308
Hall Liu057def52016-05-05 17:17:07 -0700309 // A list of events that are associated with this call
310 private final List<AnalyticsEvent> analyticsEvents;
311
312 // A map from event-pair names to their durations.
313 private final List<EventTiming> eventTimings;
314
Hall Liubd72c9f2016-06-22 17:11:08 -0700315 // Whether the call has ever been a video call.
316 private boolean isVideoCall = false;
317
318 // A list of video events that have occurred.
319 private List<VideoEvent> videoEvents;
320
Hall Liu0464b9b2016-01-12 15:32:58 -0800321 public ParcelableCallAnalytics(long startTimeMillis, long callDurationMillis, int callType,
322 boolean isAdditionalCall, boolean isInterrupted, int callTechnologies,
323 int callTerminationCode, boolean isEmergencyCall, String connectionService,
Hall Liu057def52016-05-05 17:17:07 -0700324 boolean isCreatedFromExistingConnection, List<AnalyticsEvent> analyticsEvents,
325 List<EventTiming> eventTimings) {
Hall Liu0464b9b2016-01-12 15:32:58 -0800326 this.startTimeMillis = startTimeMillis;
327 this.callDurationMillis = callDurationMillis;
328 this.callType = callType;
329 this.isAdditionalCall = isAdditionalCall;
330 this.isInterrupted = isInterrupted;
331 this.callTechnologies = callTechnologies;
332 this.callTerminationCode = callTerminationCode;
333 this.isEmergencyCall = isEmergencyCall;
334 this.connectionService = connectionService;
335 this.isCreatedFromExistingConnection = isCreatedFromExistingConnection;
Hall Liu057def52016-05-05 17:17:07 -0700336 this.analyticsEvents = analyticsEvents;
337 this.eventTimings = eventTimings;
Hall Liu0464b9b2016-01-12 15:32:58 -0800338 }
339
340 public ParcelableCallAnalytics(Parcel in) {
341 startTimeMillis = in.readLong();
342 callDurationMillis = in.readLong();
343 callType = in.readInt();
344 isAdditionalCall = readByteAsBoolean(in);
345 isInterrupted = readByteAsBoolean(in);
346 callTechnologies = in.readInt();
347 callTerminationCode = in.readInt();
348 isEmergencyCall = readByteAsBoolean(in);
349 connectionService = in.readString();
350 isCreatedFromExistingConnection = readByteAsBoolean(in);
Hall Liu057def52016-05-05 17:17:07 -0700351 analyticsEvents = new ArrayList<>();
352 in.readTypedList(analyticsEvents, AnalyticsEvent.CREATOR);
353 eventTimings = new ArrayList<>();
354 in.readTypedList(eventTimings, EventTiming.CREATOR);
Hall Liubd72c9f2016-06-22 17:11:08 -0700355 isVideoCall = readByteAsBoolean(in);
356 videoEvents = new LinkedList<>();
357 in.readTypedList(videoEvents, VideoEvent.CREATOR);
Hall Liu0464b9b2016-01-12 15:32:58 -0800358 }
359
360 public void writeToParcel(Parcel out, int flags) {
361 out.writeLong(startTimeMillis);
362 out.writeLong(callDurationMillis);
363 out.writeInt(callType);
364 writeBooleanAsByte(out, isAdditionalCall);
365 writeBooleanAsByte(out, isInterrupted);
366 out.writeInt(callTechnologies);
367 out.writeInt(callTerminationCode);
368 writeBooleanAsByte(out, isEmergencyCall);
369 out.writeString(connectionService);
370 writeBooleanAsByte(out, isCreatedFromExistingConnection);
Hall Liu057def52016-05-05 17:17:07 -0700371 out.writeTypedList(analyticsEvents);
372 out.writeTypedList(eventTimings);
Hall Liubd72c9f2016-06-22 17:11:08 -0700373 writeBooleanAsByte(out, isVideoCall);
374 out.writeTypedList(videoEvents);
375 }
376 public void setIsVideoCall(boolean isVideoCall) {
377 this.isVideoCall = isVideoCall;
378 }
379
380 public void setVideoEvents(List<VideoEvent> videoEvents) {
381 this.videoEvents = videoEvents;
Hall Liu0464b9b2016-01-12 15:32:58 -0800382 }
383
384 public long getStartTimeMillis() {
385 return startTimeMillis;
386 }
387
388 public long getCallDurationMillis() {
389 return callDurationMillis;
390 }
391
392 public int getCallType() {
393 return callType;
394 }
395
396 public boolean isAdditionalCall() {
397 return isAdditionalCall;
398 }
399
400 public boolean isInterrupted() {
401 return isInterrupted;
402 }
403
404 public int getCallTechnologies() {
405 return callTechnologies;
406 }
407
408 public int getCallTerminationCode() {
409 return callTerminationCode;
410 }
411
412 public boolean isEmergencyCall() {
413 return isEmergencyCall;
414 }
415
416 public String getConnectionService() {
417 return connectionService;
418 }
419
420 public boolean isCreatedFromExistingConnection() {
421 return isCreatedFromExistingConnection;
422 }
423
Hall Liu057def52016-05-05 17:17:07 -0700424 public List<AnalyticsEvent> analyticsEvents() {
425 return analyticsEvents;
426 }
427
428 public List<EventTiming> getEventTimings() {
429 return eventTimings;
430 }
431
Hall Liubd72c9f2016-06-22 17:11:08 -0700432 public boolean isVideoCall() {
433 return isVideoCall;
434 }
435
436 public List<VideoEvent> getVideoEvents() {
437 return videoEvents;
438 }
439
Hall Liu0464b9b2016-01-12 15:32:58 -0800440 @Override
441 public int describeContents() {
442 return 0;
443 }
444
445 private static void writeBooleanAsByte(Parcel out, boolean b) {
446 out.writeByte((byte) (b ? 1 : 0));
447 }
448
449 private static boolean readByteAsBoolean(Parcel in) {
450 return (in.readByte() == 1);
451 }
452}