blob: e7c96726053231c2d1a920be779baad45dc4c2ad [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
23/**
24 * @hide
25 */
26@SystemApi
27public class ParcelableCallAnalytics implements Parcelable {
28 public static final int CALLTYPE_UNKNOWN = 0;
29 public static final int CALLTYPE_INCOMING = 1;
30 public static final int CALLTYPE_OUTGOING = 2;
31
32 // Constants for call technology
33 public static final int CDMA_PHONE = 0x1;
34 public static final int GSM_PHONE = 0x2;
35 public static final int IMS_PHONE = 0x4;
36 public static final int SIP_PHONE = 0x8;
37 public static final int THIRD_PARTY_PHONE = 0x10;
38
39 public static final long MILLIS_IN_5_MINUTES = 1000 * 60 * 5;
40 public static final long MILLIS_IN_1_SECOND = 1000;
41
42 public static final int STILL_CONNECTED = -1;
43
44 public static final Parcelable.Creator<ParcelableCallAnalytics> CREATOR =
45 new Parcelable.Creator<ParcelableCallAnalytics> () {
46
47 @Override
48 public ParcelableCallAnalytics createFromParcel(Parcel in) {
49 return new ParcelableCallAnalytics(in);
50 }
51
52 @Override
53 public ParcelableCallAnalytics[] newArray(int size) {
54 return new ParcelableCallAnalytics[size];
55 }
56 };
57
58 // The start time of the call in milliseconds since Jan. 1, 1970, rounded to the nearest
59 // 5 minute increment.
60 private final long startTimeMillis;
61
62 // The duration of the call, in milliseconds.
63 private final long callDurationMillis;
64
65 // ONE OF calltype_unknown, calltype_incoming, or calltype_outgoing
66 private final int callType;
67
68 // true if the call came in while another call was in progress or if the user dialed this call
69 // while in the middle of another call.
70 private final boolean isAdditionalCall;
71
72 // true if the call was interrupted by an incoming or outgoing call.
73 private final boolean isInterrupted;
74
75 // bitmask denoting which technologies a call used.
76 private final int callTechnologies;
77
78 // Any of the DisconnectCause codes, or STILL_CONNECTED.
79 private final int callTerminationCode;
80
81 // Whether the call is an emergency call
82 private final boolean isEmergencyCall;
83
84 // The package name of the connection service that this call used.
85 private final String connectionService;
86
87 // Whether the call object was created from an existing connection.
88 private final boolean isCreatedFromExistingConnection;
89
90 public ParcelableCallAnalytics(long startTimeMillis, long callDurationMillis, int callType,
91 boolean isAdditionalCall, boolean isInterrupted, int callTechnologies,
92 int callTerminationCode, boolean isEmergencyCall, String connectionService,
93 boolean isCreatedFromExistingConnection) {
94 this.startTimeMillis = startTimeMillis;
95 this.callDurationMillis = callDurationMillis;
96 this.callType = callType;
97 this.isAdditionalCall = isAdditionalCall;
98 this.isInterrupted = isInterrupted;
99 this.callTechnologies = callTechnologies;
100 this.callTerminationCode = callTerminationCode;
101 this.isEmergencyCall = isEmergencyCall;
102 this.connectionService = connectionService;
103 this.isCreatedFromExistingConnection = isCreatedFromExistingConnection;
104 }
105
106 public ParcelableCallAnalytics(Parcel in) {
107 startTimeMillis = in.readLong();
108 callDurationMillis = in.readLong();
109 callType = in.readInt();
110 isAdditionalCall = readByteAsBoolean(in);
111 isInterrupted = readByteAsBoolean(in);
112 callTechnologies = in.readInt();
113 callTerminationCode = in.readInt();
114 isEmergencyCall = readByteAsBoolean(in);
115 connectionService = in.readString();
116 isCreatedFromExistingConnection = readByteAsBoolean(in);
117 }
118
119 public void writeToParcel(Parcel out, int flags) {
120 out.writeLong(startTimeMillis);
121 out.writeLong(callDurationMillis);
122 out.writeInt(callType);
123 writeBooleanAsByte(out, isAdditionalCall);
124 writeBooleanAsByte(out, isInterrupted);
125 out.writeInt(callTechnologies);
126 out.writeInt(callTerminationCode);
127 writeBooleanAsByte(out, isEmergencyCall);
128 out.writeString(connectionService);
129 writeBooleanAsByte(out, isCreatedFromExistingConnection);
130 }
131
132 public long getStartTimeMillis() {
133 return startTimeMillis;
134 }
135
136 public long getCallDurationMillis() {
137 return callDurationMillis;
138 }
139
140 public int getCallType() {
141 return callType;
142 }
143
144 public boolean isAdditionalCall() {
145 return isAdditionalCall;
146 }
147
148 public boolean isInterrupted() {
149 return isInterrupted;
150 }
151
152 public int getCallTechnologies() {
153 return callTechnologies;
154 }
155
156 public int getCallTerminationCode() {
157 return callTerminationCode;
158 }
159
160 public boolean isEmergencyCall() {
161 return isEmergencyCall;
162 }
163
164 public String getConnectionService() {
165 return connectionService;
166 }
167
168 public boolean isCreatedFromExistingConnection() {
169 return isCreatedFromExistingConnection;
170 }
171
172 @Override
173 public int describeContents() {
174 return 0;
175 }
176
177 private static void writeBooleanAsByte(Parcel out, boolean b) {
178 out.writeByte((byte) (b ? 1 : 0));
179 }
180
181 private static boolean readByteAsBoolean(Parcel in) {
182 return (in.readByte() == 1);
183 }
184}