blob: e02a2f4ae5d3fb329de2187c67e4b056124db7c5 [file] [log] [blame]
Hemant Gupta7aca90f2013-08-19 19:03:51 +05301/*
2 * Copyright (C) 2014 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.bluetooth;
18
Mathew Inwood4dc66d32018-08-01 15:07:20 +010019import android.annotation.UnsupportedAppUsage;
Hemant Gupta7aca90f2013-08-19 19:03:51 +053020import android.os.Parcel;
21import android.os.Parcelable;
Sanket Agarwal40bb6f32016-06-27 20:13:54 -070022import android.os.SystemClock;
Hemant Gupta7aca90f2013-08-19 19:03:51 +053023
Bryce Leee457fa42015-12-16 15:33:59 -080024import java.util.UUID;
25
Hemant Gupta7aca90f2013-08-19 19:03:51 +053026/**
27 * This class represents a single call, its state and properties.
28 * It implements {@link Parcelable} for inter-process message passing.
Jack Hea355e5e2017-08-22 16:06:54 -070029 *
Hemant Gupta7aca90f2013-08-19 19:03:51 +053030 * @hide
31 */
Mike Lockwoodcf916d32014-06-12 11:23:40 -070032public final class BluetoothHeadsetClientCall implements Parcelable {
Hemant Gupta7aca90f2013-08-19 19:03:51 +053033
34 /* Call state */
35 /**
36 * Call is active.
37 */
38 public static final int CALL_STATE_ACTIVE = 0;
39 /**
40 * Call is in held state.
41 */
42 public static final int CALL_STATE_HELD = 1;
43 /**
44 * Outgoing call that is being dialed right now.
45 */
46 public static final int CALL_STATE_DIALING = 2;
47 /**
48 * Outgoing call that remote party has already been alerted about.
49 */
50 public static final int CALL_STATE_ALERTING = 3;
51 /**
52 * Incoming call that can be accepted or rejected.
53 */
54 public static final int CALL_STATE_INCOMING = 4;
55 /**
56 * Waiting call state when there is already an active call.
57 */
58 public static final int CALL_STATE_WAITING = 5;
59 /**
60 * Call that has been held by response and hold
61 * (see Bluetooth specification for further references).
62 */
63 public static final int CALL_STATE_HELD_BY_RESPONSE_AND_HOLD = 6;
64 /**
65 * Call that has been already terminated and should not be referenced as a valid call.
66 */
67 public static final int CALL_STATE_TERMINATED = 7;
68
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -070069 private final BluetoothDevice mDevice;
Hemant Gupta7aca90f2013-08-19 19:03:51 +053070 private final int mId;
71 private int mState;
72 private String mNumber;
73 private boolean mMultiParty;
74 private final boolean mOutgoing;
Bryce Leee457fa42015-12-16 15:33:59 -080075 private final UUID mUUID;
Sanket Agarwal40bb6f32016-06-27 20:13:54 -070076 private final long mCreationElapsedMilli;
Joseph Pirozzo843d3802018-01-03 08:59:57 -080077 private final boolean mInBandRing;
Hemant Gupta7aca90f2013-08-19 19:03:51 +053078
79 /**
Mike Lockwoodcf916d32014-06-12 11:23:40 -070080 * Creates BluetoothHeadsetClientCall instance.
Hemant Gupta7aca90f2013-08-19 19:03:51 +053081 */
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -070082 public BluetoothHeadsetClientCall(BluetoothDevice device, int id, int state, String number,
Joseph Pirozzo843d3802018-01-03 08:59:57 -080083 boolean multiParty, boolean outgoing, boolean inBandRing) {
84 this(device, id, UUID.randomUUID(), state, number, multiParty, outgoing, inBandRing);
Bryce Leee457fa42015-12-16 15:33:59 -080085 }
86
87 public BluetoothHeadsetClientCall(BluetoothDevice device, int id, UUID uuid, int state,
Joseph Pirozzo843d3802018-01-03 08:59:57 -080088 String number, boolean multiParty, boolean outgoing, boolean inBandRing) {
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -070089 mDevice = device;
Hemant Gupta7aca90f2013-08-19 19:03:51 +053090 mId = id;
Bryce Leee457fa42015-12-16 15:33:59 -080091 mUUID = uuid;
Hemant Gupta7aca90f2013-08-19 19:03:51 +053092 mState = state;
93 mNumber = number != null ? number : "";
94 mMultiParty = multiParty;
95 mOutgoing = outgoing;
Joseph Pirozzo843d3802018-01-03 08:59:57 -080096 mInBandRing = inBandRing;
Sanket Agarwal40bb6f32016-06-27 20:13:54 -070097 mCreationElapsedMilli = SystemClock.elapsedRealtime();
Hemant Gupta7aca90f2013-08-19 19:03:51 +053098 }
99
100 /**
101 * Sets call's state.
102 *
103 * <p>Note: This is an internal function and shouldn't be exposed</p>
104 *
Jack Hea355e5e2017-08-22 16:06:54 -0700105 * @param state new call state.
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530106 */
107 public void setState(int state) {
108 mState = state;
109 }
110
111 /**
112 * Sets call's number.
113 *
114 * <p>Note: This is an internal function and shouldn't be exposed</p>
115 *
Jack Hea355e5e2017-08-22 16:06:54 -0700116 * @param number String representing phone number.
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530117 */
118 public void setNumber(String number) {
119 mNumber = number;
120 }
121
122 /**
123 * Sets this call as multi party call.
124 *
125 * <p>Note: This is an internal function and shouldn't be exposed</p>
126 *
Jack Hea355e5e2017-08-22 16:06:54 -0700127 * @param multiParty if <code>true</code> sets this call as a part of multi party conference.
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530128 */
129 public void setMultiParty(boolean multiParty) {
130 mMultiParty = multiParty;
131 }
132
133 /**
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -0700134 * Gets call's device.
135 *
136 * @return call device.
137 */
138 public BluetoothDevice getDevice() {
139 return mDevice;
140 }
141
142 /**
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530143 * Gets call's Id.
144 *
145 * @return call id.
146 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100147 @UnsupportedAppUsage
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530148 public int getId() {
149 return mId;
150 }
151
152 /**
Bryce Leee457fa42015-12-16 15:33:59 -0800153 * Gets call's UUID.
154 *
155 * @return call uuid
156 * @hide
157 */
158 public UUID getUUID() {
159 return mUUID;
160 }
161
162 /**
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530163 * Gets call's current state.
164 *
165 * @return state of this particular phone call.
166 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100167 @UnsupportedAppUsage
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530168 public int getState() {
169 return mState;
170 }
171
172 /**
173 * Gets call's number.
174 *
175 * @return string representing phone number.
176 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100177 @UnsupportedAppUsage
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530178 public String getNumber() {
179 return mNumber;
180 }
181
182 /**
Sanket Agarwal40bb6f32016-06-27 20:13:54 -0700183 * Gets call's creation time in millis since epoch.
184 *
185 * @return long representing the creation time.
186 */
187 public long getCreationElapsedMilli() {
188 return mCreationElapsedMilli;
189 }
190
191 /**
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530192 * Checks if call is an active call in a conference mode (aka multi party).
193 *
Jack Hea355e5e2017-08-22 16:06:54 -0700194 * @return <code>true</code> if call is a multi party call, <code>false</code> otherwise.
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530195 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100196 @UnsupportedAppUsage
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530197 public boolean isMultiParty() {
198 return mMultiParty;
199 }
200
201 /**
202 * Checks if this call is an outgoing call.
203 *
Jack Hea355e5e2017-08-22 16:06:54 -0700204 * @return <code>true</code> if its outgoing call, <code>false</code> otherwise.
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530205 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100206 @UnsupportedAppUsage
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530207 public boolean isOutgoing() {
208 return mOutgoing;
209 }
210
Joseph Pirozzo843d3802018-01-03 08:59:57 -0800211 /**
212 * Checks if the ringtone will be generated by the connected phone
213 *
214 * @return <code>true</code> if in band ring is enabled, <code>false</code> otherwise.
215 */
216 public boolean isInBandRing() {
217 return mInBandRing;
218 }
219
220
Jack He2992cd02017-08-22 21:21:23 -0700221 @Override
Mike Lockwood0b611b52014-06-12 13:10:07 -0700222 public String toString() {
Bryce Lee3c67873f2015-12-08 11:22:31 -0800223 return toString(false);
224 }
225
Jack He2992cd02017-08-22 21:21:23 -0700226 /**
227 * Generate a log string for this call
228 * @param loggable whether device address should be logged
229 * @return log string
230 */
Bryce Lee3c67873f2015-12-08 11:22:31 -0800231 public String toString(boolean loggable) {
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -0700232 StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mDevice: ");
Bryce Lee18116c02016-01-21 14:29:42 -0800233 builder.append(loggable ? mDevice : mDevice.hashCode());
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -0700234 builder.append(", mId: ");
Mike Lockwood0b611b52014-06-12 13:10:07 -0700235 builder.append(mId);
Bryce Leee457fa42015-12-16 15:33:59 -0800236 builder.append(", mUUID: ");
237 builder.append(mUUID);
Mike Lockwood0b611b52014-06-12 13:10:07 -0700238 builder.append(", mState: ");
239 switch (mState) {
Jack Hea355e5e2017-08-22 16:06:54 -0700240 case CALL_STATE_ACTIVE:
241 builder.append("ACTIVE");
242 break;
243 case CALL_STATE_HELD:
244 builder.append("HELD");
245 break;
246 case CALL_STATE_DIALING:
247 builder.append("DIALING");
248 break;
249 case CALL_STATE_ALERTING:
250 builder.append("ALERTING");
251 break;
252 case CALL_STATE_INCOMING:
253 builder.append("INCOMING");
254 break;
255 case CALL_STATE_WAITING:
256 builder.append("WAITING");
257 break;
258 case CALL_STATE_HELD_BY_RESPONSE_AND_HOLD:
259 builder.append("HELD_BY_RESPONSE_AND_HOLD");
260 break;
261 case CALL_STATE_TERMINATED:
262 builder.append("TERMINATED");
263 break;
264 default:
265 builder.append(mState);
266 break;
Mike Lockwood0b611b52014-06-12 13:10:07 -0700267 }
268 builder.append(", mNumber: ");
Bryce Lee18116c02016-01-21 14:29:42 -0800269 builder.append(loggable ? mNumber : mNumber.hashCode());
Mike Lockwood0b611b52014-06-12 13:10:07 -0700270 builder.append(", mMultiParty: ");
271 builder.append(mMultiParty);
272 builder.append(", mOutgoing: ");
273 builder.append(mOutgoing);
Joseph Pirozzo843d3802018-01-03 08:59:57 -0800274 builder.append(", mInBandRing: ");
275 builder.append(mInBandRing);
Mike Lockwood0b611b52014-06-12 13:10:07 -0700276 builder.append("}");
277 return builder.toString();
278 }
279
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530280 /**
281 * {@link Parcelable.Creator} interface implementation.
282 */
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700283 public static final Parcelable.Creator<BluetoothHeadsetClientCall> CREATOR =
284 new Parcelable.Creator<BluetoothHeadsetClientCall>() {
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530285 @Override
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700286 public BluetoothHeadsetClientCall createFromParcel(Parcel in) {
Jack Hea355e5e2017-08-22 16:06:54 -0700287 return new BluetoothHeadsetClientCall((BluetoothDevice) in.readParcelable(null),
Bryce Leee457fa42015-12-16 15:33:59 -0800288 in.readInt(), UUID.fromString(in.readString()), in.readInt(),
Joseph Pirozzo843d3802018-01-03 08:59:57 -0800289 in.readString(), in.readInt() == 1, in.readInt() == 1,
290 in.readInt() == 1);
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530291 }
292
293 @Override
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700294 public BluetoothHeadsetClientCall[] newArray(int size) {
295 return new BluetoothHeadsetClientCall[size];
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530296 }
297 };
298
299 @Override
300 public void writeToParcel(Parcel out, int flags) {
Mike Lockwoodddbfc9a2014-08-22 10:33:21 -0700301 out.writeParcelable(mDevice, 0);
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530302 out.writeInt(mId);
Bryce Leee457fa42015-12-16 15:33:59 -0800303 out.writeString(mUUID.toString());
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530304 out.writeInt(mState);
305 out.writeString(mNumber);
306 out.writeInt(mMultiParty ? 1 : 0);
307 out.writeInt(mOutgoing ? 1 : 0);
Joseph Pirozzo843d3802018-01-03 08:59:57 -0800308 out.writeInt(mInBandRing ? 1 : 0);
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530309 }
310
311 @Override
312 public int describeContents() {
313 return 0;
314 }
315}