• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Parcelable;
24 import android.os.ParcelUuid;
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(prefix = "STATE_", value = {
40             STATE_INCOMING,
41             STATE_DIALING,
42             STATE_ALERTING,
43             STATE_ACTIVE,
44             STATE_LOCALLY_HELD,
45             STATE_REMOTELY_HELD,
46             STATE_LOCALLY_AND_REMOTELY_HELD
47     })
48     @Retention(RetentionPolicy.SOURCE)
49     public @interface State {
50     }
51 
52     /**
53      * A remote party is calling (incoming call).
54      *
55      * @hide
56      */
57     public static final int STATE_INCOMING = 0x00;
58 
59     /**
60      * The process to call the remote party has started but the remote party is not
61      * being alerted (outgoing call).
62      *
63      * @hide
64      */
65     public static final int STATE_DIALING = 0x01;
66 
67     /**
68      * A remote party is being alerted (outgoing call).
69      *
70      * @hide
71      */
72     public static final int STATE_ALERTING = 0x02;
73 
74     /**
75      * The call is in an active conversation.
76      *
77      * @hide
78      */
79     public static final int STATE_ACTIVE = 0x03;
80 
81     /**
82      * The call is connected but held locally. “Locally Held” implies that either
83      * the server or the client can affect the state.
84      *
85      * @hide
86      */
87     public static final int STATE_LOCALLY_HELD = 0x04;
88 
89     /**
90      * The call is connected but held remotely. “Remotely Held” means that the state
91      * is controlled by the remote party of a call.
92      *
93      * @hide
94      */
95     public static final int STATE_REMOTELY_HELD = 0x05;
96 
97     /**
98      * The call is connected but held both locally and remotely.
99      *
100      * @hide
101      */
102     public static final int STATE_LOCALLY_AND_REMOTELY_HELD = 0x06;
103 
104     /**
105      * Whether the call direction is outgoing.
106      *
107      * @hide
108      */
109     public static final int FLAG_OUTGOING_CALL = 0x00000001;
110 
111     /**
112      * Whether the call URI and Friendly Name are withheld by server.
113      *
114      * @hide
115      */
116     public static final int FLAG_WITHHELD_BY_SERVER = 0x00000002;
117 
118     /**
119      * Whether the call URI and Friendly Name are withheld by network.
120      *
121      * @hide
122      */
123     public static final int FLAG_WITHHELD_BY_NETWORK = 0x00000004;
124 
125     /** Unique UUID that identifies this call */
126     private UUID mUuid;
127 
128     /** Remote Caller URI */
129     private String mUri;
130 
131     /** Caller friendly name */
132     private String mFriendlyName;
133 
134     /** Call state */
135     private @State int mState;
136 
137     /** Call flags */
138     private int mCallFlags;
139 
140     /** @hide */
BluetoothLeCall(@onNull BluetoothLeCall that)141     public BluetoothLeCall(@NonNull BluetoothLeCall that) {
142         mUuid = new UUID(that.getUuid().getMostSignificantBits(),
143                 that.getUuid().getLeastSignificantBits());
144         mUri = that.mUri;
145         mFriendlyName = that.mFriendlyName;
146         mState = that.mState;
147         mCallFlags = that.mCallFlags;
148     }
149 
150     /** @hide */
BluetoothLeCall(@onNull UUID uuid, @NonNull String uri, @NonNull String friendlyName, @State int state, int callFlags)151     public BluetoothLeCall(@NonNull UUID uuid, @NonNull String uri, @NonNull String friendlyName,
152             @State int state, int callFlags) {
153         mUuid = uuid;
154         mUri = uri;
155         mFriendlyName = friendlyName;
156         mState = state;
157         mCallFlags = callFlags;
158     }
159 
160     @Override
equals(Object o)161     public boolean equals(Object o) {
162         if (this == o)
163             return true;
164         if (o == null || getClass() != o.getClass())
165             return false;
166         BluetoothLeCall that = (BluetoothLeCall) o;
167         return mUuid.equals(that.mUuid) && mUri.equals(that.mUri)
168                 && mFriendlyName.equals(that.mFriendlyName) && mState == that.mState
169                 && mCallFlags == that.mCallFlags;
170     }
171 
172     @Override
hashCode()173     public int hashCode() {
174         return Objects.hash(mUuid, mUri, mFriendlyName, mState, mCallFlags);
175     }
176 
177     /**
178      * Returns a string representation of this BluetoothLeCall.
179      *
180      * <p>
181      * Currently this is the UUID.
182      *
183      * @return string representation of this BluetoothLeCall
184      */
185     @Override
toString()186     public String toString() {
187         return mUuid.toString();
188     }
189 
190     @Override
describeContents()191     public int describeContents() {
192         return 0;
193     }
194 
195     @Override
writeToParcel(@onNull Parcel out, int flags)196     public void writeToParcel(@NonNull Parcel out, int flags) {
197         out.writeParcelable(new ParcelUuid(mUuid), 0);
198         out.writeString(mUri);
199         out.writeString(mFriendlyName);
200         out.writeInt(mState);
201         out.writeInt(mCallFlags);
202     }
203 
204     public static final @android.annotation.NonNull Parcelable.Creator<BluetoothLeCall> CREATOR =
205     						    new Parcelable.Creator<BluetoothLeCall>() {
206         public BluetoothLeCall createFromParcel(Parcel in) {
207             return new BluetoothLeCall(in);
208         }
209 
210         public BluetoothLeCall[] newArray(int size) {
211             return new BluetoothLeCall[size];
212         }
213     };
214 
BluetoothLeCall(Parcel in)215     private BluetoothLeCall(Parcel in) {
216         mUuid = ((ParcelUuid) in.readParcelable(null)).getUuid();
217         mUri = in.readString();
218         mFriendlyName = in.readString();
219         mState = in.readInt();
220         mCallFlags = in.readInt();
221     }
222 
223     /**
224      * Returns an UUID of this BluetoothLeCall.
225      *
226      * <p>
227      * An UUID is unique identifier of a BluetoothLeCall.
228      *
229      * @return UUID of this BluetoothLeCall
230      * @hide
231      */
getUuid()232     public @NonNull UUID getUuid() {
233         return mUuid;
234     }
235 
236     /**
237      * Returns a URI of the remote party of this BluetoothLeCall.
238      *
239      * @return string representation of this BluetoothLeCall
240      * @hide
241      */
getUri()242     public @NonNull String getUri() {
243         return mUri;
244     }
245 
246     /**
247      * Returns a friendly name of the call.
248      *
249      * @return friendly name representation of this BluetoothLeCall
250      * @hide
251      */
getFriendlyName()252     public @NonNull String getFriendlyName() {
253         return mFriendlyName;
254     }
255 
256     /**
257      * Returns the call state.
258      *
259      * @return the state of this BluetoothLeCall
260      * @hide
261      */
getState()262     public @State int getState() {
263         return mState;
264     }
265 
266     /**
267      * Returns the call flags.
268      *
269      * @return call flags
270      * @hide
271      */
getCallFlags()272     public int getCallFlags() {
273         return mCallFlags;
274     }
275 
276     /**
277      * Whether the call direction is incoming.
278      *
279      * @return true if incoming call, false otherwise
280      * @hide
281      */
isIncomingCall()282     public boolean isIncomingCall() {
283         return (mCallFlags & FLAG_OUTGOING_CALL) == 0;
284     }
285 }
286