Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.bluetooth; |
| 18 | |
Mathew Inwood | 7acad5e | 2018-08-01 15:00:35 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 22 | import android.os.SystemClock; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 23 | |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 24 | import java.util.UUID; |
| 25 | |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 26 | /** |
| 27 | * This class represents a single call, its state and properties. |
| 28 | * It implements {@link Parcelable} for inter-process message passing. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 29 | * |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 30 | * @hide |
| 31 | */ |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 32 | public final class BluetoothHeadsetClientCall implements Parcelable { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 33 | |
| 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 Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 69 | private final BluetoothDevice mDevice; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 70 | private final int mId; |
| 71 | private int mState; |
| 72 | private String mNumber; |
| 73 | private boolean mMultiParty; |
| 74 | private final boolean mOutgoing; |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 75 | private final UUID mUUID; |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 76 | private final long mCreationElapsedMilli; |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 77 | private final boolean mInBandRing; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 78 | |
| 79 | /** |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 80 | * Creates BluetoothHeadsetClientCall instance. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 81 | */ |
Mike Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 82 | public BluetoothHeadsetClientCall(BluetoothDevice device, int id, int state, String number, |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 83 | boolean multiParty, boolean outgoing, boolean inBandRing) { |
| 84 | this(device, id, UUID.randomUUID(), state, number, multiParty, outgoing, inBandRing); |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | public BluetoothHeadsetClientCall(BluetoothDevice device, int id, UUID uuid, int state, |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 88 | String number, boolean multiParty, boolean outgoing, boolean inBandRing) { |
Mike Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 89 | mDevice = device; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 90 | mId = id; |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 91 | mUUID = uuid; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 92 | mState = state; |
| 93 | mNumber = number != null ? number : ""; |
| 94 | mMultiParty = multiParty; |
| 95 | mOutgoing = outgoing; |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 96 | mInBandRing = inBandRing; |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 97 | mCreationElapsedMilli = SystemClock.elapsedRealtime(); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Sets call's state. |
| 102 | * |
| 103 | * <p>Note: This is an internal function and shouldn't be exposed</p> |
| 104 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 105 | * @param state new call state. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 106 | */ |
| 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 He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 116 | * @param number String representing phone number. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 117 | */ |
| 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 He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 127 | * @param multiParty if <code>true</code> sets this call as a part of multi party conference. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 128 | */ |
| 129 | public void setMultiParty(boolean multiParty) { |
| 130 | mMultiParty = multiParty; |
| 131 | } |
| 132 | |
| 133 | /** |
Mike Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 134 | * Gets call's device. |
| 135 | * |
| 136 | * @return call device. |
| 137 | */ |
| 138 | public BluetoothDevice getDevice() { |
| 139 | return mDevice; |
| 140 | } |
| 141 | |
| 142 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 143 | * Gets call's Id. |
| 144 | * |
| 145 | * @return call id. |
| 146 | */ |
Mathew Inwood | 7acad5e | 2018-08-01 15:00:35 +0100 | [diff] [blame] | 147 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 148 | public int getId() { |
| 149 | return mId; |
| 150 | } |
| 151 | |
| 152 | /** |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 153 | * Gets call's UUID. |
| 154 | * |
| 155 | * @return call uuid |
| 156 | * @hide |
| 157 | */ |
| 158 | public UUID getUUID() { |
| 159 | return mUUID; |
| 160 | } |
| 161 | |
| 162 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 163 | * Gets call's current state. |
| 164 | * |
| 165 | * @return state of this particular phone call. |
| 166 | */ |
Mathew Inwood | 7acad5e | 2018-08-01 15:00:35 +0100 | [diff] [blame] | 167 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 168 | public int getState() { |
| 169 | return mState; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Gets call's number. |
| 174 | * |
| 175 | * @return string representing phone number. |
| 176 | */ |
Mathew Inwood | 7acad5e | 2018-08-01 15:00:35 +0100 | [diff] [blame] | 177 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 178 | public String getNumber() { |
| 179 | return mNumber; |
| 180 | } |
| 181 | |
| 182 | /** |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 183 | * 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 Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 192 | * Checks if call is an active call in a conference mode (aka multi party). |
| 193 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 194 | * @return <code>true</code> if call is a multi party call, <code>false</code> otherwise. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 195 | */ |
Mathew Inwood | 7acad5e | 2018-08-01 15:00:35 +0100 | [diff] [blame] | 196 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 197 | public boolean isMultiParty() { |
| 198 | return mMultiParty; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Checks if this call is an outgoing call. |
| 203 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 204 | * @return <code>true</code> if its outgoing call, <code>false</code> otherwise. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 205 | */ |
Mathew Inwood | 7acad5e | 2018-08-01 15:00:35 +0100 | [diff] [blame] | 206 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 207 | public boolean isOutgoing() { |
| 208 | return mOutgoing; |
| 209 | } |
| 210 | |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 211 | /** |
| 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 He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 221 | @Override |
Mike Lockwood | 0b611b5 | 2014-06-12 13:10:07 -0700 | [diff] [blame] | 222 | public String toString() { |
Bryce Lee | 3c67873f | 2015-12-08 11:22:31 -0800 | [diff] [blame] | 223 | return toString(false); |
| 224 | } |
| 225 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 226 | /** |
| 227 | * Generate a log string for this call |
| 228 | * @param loggable whether device address should be logged |
| 229 | * @return log string |
| 230 | */ |
Bryce Lee | 3c67873f | 2015-12-08 11:22:31 -0800 | [diff] [blame] | 231 | public String toString(boolean loggable) { |
Mike Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 232 | StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mDevice: "); |
Bryce Lee | 18116c0 | 2016-01-21 14:29:42 -0800 | [diff] [blame] | 233 | builder.append(loggable ? mDevice : mDevice.hashCode()); |
Mike Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 234 | builder.append(", mId: "); |
Mike Lockwood | 0b611b5 | 2014-06-12 13:10:07 -0700 | [diff] [blame] | 235 | builder.append(mId); |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 236 | builder.append(", mUUID: "); |
| 237 | builder.append(mUUID); |
Mike Lockwood | 0b611b5 | 2014-06-12 13:10:07 -0700 | [diff] [blame] | 238 | builder.append(", mState: "); |
| 239 | switch (mState) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 240 | 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 Lockwood | 0b611b5 | 2014-06-12 13:10:07 -0700 | [diff] [blame] | 267 | } |
| 268 | builder.append(", mNumber: "); |
Bryce Lee | 18116c0 | 2016-01-21 14:29:42 -0800 | [diff] [blame] | 269 | builder.append(loggable ? mNumber : mNumber.hashCode()); |
Mike Lockwood | 0b611b5 | 2014-06-12 13:10:07 -0700 | [diff] [blame] | 270 | builder.append(", mMultiParty: "); |
| 271 | builder.append(mMultiParty); |
| 272 | builder.append(", mOutgoing: "); |
| 273 | builder.append(mOutgoing); |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 274 | builder.append(", mInBandRing: "); |
| 275 | builder.append(mInBandRing); |
Mike Lockwood | 0b611b5 | 2014-06-12 13:10:07 -0700 | [diff] [blame] | 276 | builder.append("}"); |
| 277 | return builder.toString(); |
| 278 | } |
| 279 | |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 280 | /** |
| 281 | * {@link Parcelable.Creator} interface implementation. |
| 282 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 283 | public static final @android.annotation.NonNull Parcelable.Creator<BluetoothHeadsetClientCall> CREATOR = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 284 | new Parcelable.Creator<BluetoothHeadsetClientCall>() { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 285 | @Override |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 286 | public BluetoothHeadsetClientCall createFromParcel(Parcel in) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 287 | return new BluetoothHeadsetClientCall((BluetoothDevice) in.readParcelable(null), |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 288 | in.readInt(), UUID.fromString(in.readString()), in.readInt(), |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 289 | in.readString(), in.readInt() == 1, in.readInt() == 1, |
| 290 | in.readInt() == 1); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Override |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 294 | public BluetoothHeadsetClientCall[] newArray(int size) { |
| 295 | return new BluetoothHeadsetClientCall[size]; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 296 | } |
| 297 | }; |
| 298 | |
| 299 | @Override |
| 300 | public void writeToParcel(Parcel out, int flags) { |
Mike Lockwood | ddbfc9a | 2014-08-22 10:33:21 -0700 | [diff] [blame] | 301 | out.writeParcelable(mDevice, 0); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 302 | out.writeInt(mId); |
Bryce Lee | e457fa4 | 2015-12-16 15:33:59 -0800 | [diff] [blame] | 303 | out.writeString(mUUID.toString()); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 304 | out.writeInt(mState); |
| 305 | out.writeString(mNumber); |
| 306 | out.writeInt(mMultiParty ? 1 : 0); |
| 307 | out.writeInt(mOutgoing ? 1 : 0); |
Joseph Pirozzo | 843d380 | 2018-01-03 08:59:57 -0800 | [diff] [blame] | 308 | out.writeInt(mInBandRing ? 1 : 0); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public int describeContents() { |
| 313 | return 0; |
| 314 | } |
| 315 | } |