1 /* 2 * Copyright 2021 HIMSA II K/S - www.himsa.com. 3 * Represented by EHIMA - www.ehima.com 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package android.bluetooth; 19 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.os.Parcel; 23 import android.os.ParcelUuid; 24 import android.os.Parcelable; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 import java.util.Objects; 29 import java.util.UUID; 30 31 /** 32 * Representation of Call 33 * 34 * @hide 35 */ 36 public final class BluetoothLeCall implements Parcelable { 37 38 /** @hide */ 39 @IntDef( 40 prefix = "STATE_", 41 value = { 42 STATE_INCOMING, 43 STATE_DIALING, 44 STATE_ALERTING, 45 STATE_ACTIVE, 46 STATE_LOCALLY_HELD, 47 STATE_REMOTELY_HELD, 48 STATE_LOCALLY_AND_REMOTELY_HELD 49 }) 50 @Retention(RetentionPolicy.SOURCE) 51 public @interface State {} 52 53 /** 54 * A remote party is calling (incoming call). 55 * 56 * @hide 57 */ 58 public static final int STATE_INCOMING = 0x00; 59 60 /** 61 * The process to call the remote party has started but the remote party is not being alerted 62 * (outgoing call). 63 * 64 * @hide 65 */ 66 public static final int STATE_DIALING = 0x01; 67 68 /** 69 * A remote party is being alerted (outgoing call). 70 * 71 * @hide 72 */ 73 public static final int STATE_ALERTING = 0x02; 74 75 /** 76 * The call is in an active conversation. 77 * 78 * @hide 79 */ 80 public static final int STATE_ACTIVE = 0x03; 81 82 /** 83 * The call is connected but held locally. “Locally Held” implies that either the server or the 84 * client can affect the state. 85 * 86 * @hide 87 */ 88 public static final int STATE_LOCALLY_HELD = 0x04; 89 90 /** 91 * The call is connected but held remotely. “Remotely Held” means that the state is controlled 92 * by the remote party of a call. 93 * 94 * @hide 95 */ 96 public static final int STATE_REMOTELY_HELD = 0x05; 97 98 /** 99 * The call is connected but held both locally and remotely. 100 * 101 * @hide 102 */ 103 public static final int STATE_LOCALLY_AND_REMOTELY_HELD = 0x06; 104 105 /** 106 * Whether the call direction is outgoing. 107 * 108 * @hide 109 */ 110 public static final int FLAG_OUTGOING_CALL = 0x00000001; 111 112 /** 113 * Whether the call URI and Friendly Name are withheld by server. 114 * 115 * @hide 116 */ 117 public static final int FLAG_WITHHELD_BY_SERVER = 0x00000002; 118 119 /** 120 * Whether the call URI and Friendly Name are withheld by network. 121 * 122 * @hide 123 */ 124 public static final int FLAG_WITHHELD_BY_NETWORK = 0x00000004; 125 126 /** Unique UUID that identifies this call */ 127 private UUID mUuid; 128 129 /** Remote Caller URI */ 130 private String mUri; 131 132 /** Caller friendly name */ 133 private String mFriendlyName; 134 135 /** Call state */ 136 private @State int mState; 137 138 /** Call flags */ 139 private int mCallFlags; 140 141 /** @hide */ BluetoothLeCall(@onNull BluetoothLeCall that)142 public BluetoothLeCall(@NonNull BluetoothLeCall that) { 143 mUuid = 144 new UUID( 145 that.getUuid().getMostSignificantBits(), 146 that.getUuid().getLeastSignificantBits()); 147 mUri = that.mUri; 148 mFriendlyName = that.mFriendlyName; 149 mState = that.mState; 150 mCallFlags = that.mCallFlags; 151 } 152 153 /** @hide */ BluetoothLeCall( @onNull UUID uuid, @NonNull String uri, @NonNull String friendlyName, @State int state, int callFlags)154 public BluetoothLeCall( 155 @NonNull UUID uuid, 156 @NonNull String uri, 157 @NonNull String friendlyName, 158 @State int state, 159 int callFlags) { 160 mUuid = uuid; 161 mUri = uri; 162 mFriendlyName = friendlyName; 163 mState = state; 164 mCallFlags = callFlags; 165 } 166 167 @Override equals(Object o)168 public boolean equals(Object o) { 169 170 if (this == o) return true; 171 172 if (o == null || getClass() != o.getClass()) return false; 173 174 BluetoothLeCall that = (BluetoothLeCall) o; 175 return mUuid.equals(that.mUuid) 176 && mUri.equals(that.mUri) 177 && mFriendlyName.equals(that.mFriendlyName) 178 && mState == that.mState 179 && mCallFlags == that.mCallFlags; 180 } 181 182 @Override hashCode()183 public int hashCode() { 184 return Objects.hash(mUuid, mUri, mFriendlyName, mState, mCallFlags); 185 } 186 187 /** 188 * Returns a string representation of this BluetoothLeCall. 189 * 190 * <p>Currently this is the UUID. 191 * 192 * @return string representation of this BluetoothLeCall 193 */ 194 @Override toString()195 public String toString() { 196 return mUuid.toString(); 197 } 198 199 @Override describeContents()200 public int describeContents() { 201 return 0; 202 } 203 204 @Override writeToParcel(@onNull Parcel out, int flags)205 public void writeToParcel(@NonNull Parcel out, int flags) { 206 out.writeParcelable(new ParcelUuid(mUuid), 0); 207 out.writeString(mUri); 208 out.writeString(mFriendlyName); 209 out.writeInt(mState); 210 out.writeInt(mCallFlags); 211 } 212 213 public static final @NonNull Creator<BluetoothLeCall> CREATOR = 214 new Creator<>() { 215 public BluetoothLeCall createFromParcel(Parcel in) { 216 return new BluetoothLeCall(in); 217 } 218 219 public BluetoothLeCall[] newArray(int size) { 220 return new BluetoothLeCall[size]; 221 } 222 }; 223 BluetoothLeCall(Parcel in)224 private BluetoothLeCall(Parcel in) { 225 mUuid = ((ParcelUuid) in.readParcelable(null)).getUuid(); 226 mUri = in.readString(); 227 mFriendlyName = in.readString(); 228 mState = in.readInt(); 229 mCallFlags = in.readInt(); 230 } 231 232 /** 233 * Returns an UUID of this BluetoothLeCall. 234 * 235 * <p>An UUID is unique identifier of a BluetoothLeCall. 236 * 237 * @return UUID of this BluetoothLeCall 238 * @hide 239 */ getUuid()240 public @NonNull UUID getUuid() { 241 return mUuid; 242 } 243 244 /** 245 * Returns a URI of the remote party of this BluetoothLeCall. 246 * 247 * @return string representation of this BluetoothLeCall 248 * @hide 249 */ getUri()250 public @NonNull String getUri() { 251 return mUri; 252 } 253 254 /** 255 * Returns a friendly name of the call. 256 * 257 * @return friendly name representation of this BluetoothLeCall 258 * @hide 259 */ getFriendlyName()260 public @NonNull String getFriendlyName() { 261 return mFriendlyName; 262 } 263 264 /** 265 * Returns the call state. 266 * 267 * @return the state of this BluetoothLeCall 268 * @hide 269 */ getState()270 public @State int getState() { 271 return mState; 272 } 273 274 /** 275 * Returns the call flags. 276 * 277 * @return call flags 278 * @hide 279 */ getCallFlags()280 public int getCallFlags() { 281 return mCallFlags; 282 } 283 284 /** 285 * Whether the call direction is incoming. 286 * 287 * @return true if incoming call, false otherwise 288 * @hide 289 */ isIncomingCall()290 public boolean isIncomingCall() { 291 return (mCallFlags & FLAG_OUTGOING_CALL) == 0; 292 } 293 } 294