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 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * This class represents a single call, its state and properties.
24  * It implements {@link Parcelable} for inter-process message passing.
25  * @hide
26  */
27 public final class BluetoothHeadsetClientCall implements Parcelable {
28 
29     /* Call state */
30     /**
31      * Call is active.
32      */
33     public static final int CALL_STATE_ACTIVE = 0;
34     /**
35      * Call is in held state.
36      */
37     public static final int CALL_STATE_HELD = 1;
38     /**
39      * Outgoing call that is being dialed right now.
40      */
41     public static final int CALL_STATE_DIALING = 2;
42     /**
43      * Outgoing call that remote party has already been alerted about.
44      */
45     public static final int CALL_STATE_ALERTING = 3;
46     /**
47      * Incoming call that can be accepted or rejected.
48      */
49     public static final int CALL_STATE_INCOMING = 4;
50     /**
51      * Waiting call state when there is already an active call.
52      */
53     public static final int CALL_STATE_WAITING = 5;
54     /**
55      * Call that has been held by response and hold
56      * (see Bluetooth specification for further references).
57      */
58     public static final int CALL_STATE_HELD_BY_RESPONSE_AND_HOLD = 6;
59     /**
60      * Call that has been already terminated and should not be referenced as a valid call.
61      */
62     public static final int CALL_STATE_TERMINATED = 7;
63 
64     private final BluetoothDevice mDevice;
65     private final int mId;
66     private int mState;
67     private String mNumber;
68     private boolean mMultiParty;
69     private final boolean mOutgoing;
70 
71     /**
72      * Creates BluetoothHeadsetClientCall instance.
73      */
BluetoothHeadsetClientCall(BluetoothDevice device, int id, int state, String number, boolean multiParty, boolean outgoing)74     public BluetoothHeadsetClientCall(BluetoothDevice device, int id, int state, String number,
75             boolean multiParty, boolean outgoing) {
76         mDevice = device;
77         mId = id;
78         mState = state;
79         mNumber = number != null ? number : "";
80         mMultiParty = multiParty;
81         mOutgoing = outgoing;
82     }
83 
84     /**
85      * Sets call's state.
86      *
87      * <p>Note: This is an internal function and shouldn't be exposed</p>
88      *
89      * @param  state    new call state.
90      */
setState(int state)91     public void setState(int state) {
92         mState = state;
93     }
94 
95     /**
96      * Sets call's number.
97      *
98      * <p>Note: This is an internal function and shouldn't be exposed</p>
99      *
100      * @param number    String representing phone number.
101      */
setNumber(String number)102     public void setNumber(String number) {
103         mNumber = number;
104     }
105 
106     /**
107      * Sets this call as multi party call.
108      *
109      * <p>Note: This is an internal function and shouldn't be exposed</p>
110      *
111      * @param multiParty    if <code>true</code> sets this call as a part
112      *                      of multi party conference.
113      */
setMultiParty(boolean multiParty)114     public void setMultiParty(boolean multiParty) {
115         mMultiParty = multiParty;
116     }
117 
118     /**
119      * Gets call's device.
120      *
121      * @return call device.
122      */
getDevice()123     public BluetoothDevice getDevice() {
124         return mDevice;
125     }
126 
127     /**
128      * Gets call's Id.
129      *
130      * @return call id.
131      */
getId()132     public int getId() {
133         return mId;
134     }
135 
136     /**
137      * Gets call's current state.
138      *
139      * @return state of this particular phone call.
140      */
getState()141     public int getState() {
142         return mState;
143     }
144 
145     /**
146      * Gets call's number.
147      *
148      * @return string representing phone number.
149      */
getNumber()150     public String getNumber() {
151         return mNumber;
152     }
153 
154     /**
155      * Checks if call is an active call in a conference mode (aka multi party).
156      *
157      * @return <code>true</code> if call is a multi party call,
158      *         <code>false</code> otherwise.
159      */
isMultiParty()160     public boolean isMultiParty() {
161         return mMultiParty;
162     }
163 
164     /**
165      * Checks if this call is an outgoing call.
166      *
167      * @return <code>true</code> if its outgoing call,
168      *         <code>false</code> otherwise.
169      */
isOutgoing()170     public boolean isOutgoing() {
171         return mOutgoing;
172     }
173 
toString()174     public String toString() {
175         StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mDevice: ");
176         builder.append(mDevice);
177         builder.append(", mId: ");
178         builder.append(mId);
179         builder.append(", mState: ");
180         switch (mState) {
181             case CALL_STATE_ACTIVE: builder.append("ACTIVE"); break;
182             case CALL_STATE_HELD: builder.append("HELD"); break;
183             case CALL_STATE_DIALING: builder.append("DIALING"); break;
184             case CALL_STATE_ALERTING: builder.append("ALERTING"); break;
185             case CALL_STATE_INCOMING: builder.append("INCOMING"); break;
186             case CALL_STATE_WAITING: builder.append("WAITING"); break;
187             case CALL_STATE_HELD_BY_RESPONSE_AND_HOLD: builder.append("HELD_BY_RESPONSE_AND_HOLD"); break;
188             case CALL_STATE_TERMINATED: builder.append("TERMINATED"); break;
189             default: builder.append(mState); break;
190         }
191         builder.append(", mNumber: ");
192         builder.append(mNumber);
193         builder.append(", mMultiParty: ");
194         builder.append(mMultiParty);
195         builder.append(", mOutgoing: ");
196         builder.append(mOutgoing);
197         builder.append("}");
198         return builder.toString();
199     }
200 
201     /**
202      * {@link Parcelable.Creator} interface implementation.
203      */
204     public static final Parcelable.Creator<BluetoothHeadsetClientCall> CREATOR =
205             new Parcelable.Creator<BluetoothHeadsetClientCall>() {
206                 @Override
207                 public BluetoothHeadsetClientCall createFromParcel(Parcel in) {
208                     return new BluetoothHeadsetClientCall((BluetoothDevice)in.readParcelable(null),
209                             in.readInt(), in.readInt(), in.readString(),
210                             in.readInt() == 1, in.readInt() == 1);
211                 }
212 
213                 @Override
214                 public BluetoothHeadsetClientCall[] newArray(int size) {
215                     return new BluetoothHeadsetClientCall[size];
216                 }
217             };
218 
219     @Override
writeToParcel(Parcel out, int flags)220     public void writeToParcel(Parcel out, int flags) {
221         out.writeParcelable(mDevice, 0);
222         out.writeInt(mId);
223         out.writeInt(mState);
224         out.writeString(mNumber);
225         out.writeInt(mMultiParty ? 1 : 0);
226         out.writeInt(mOutgoing ? 1 : 0);
227     }
228 
229     @Override
describeContents()230     public int describeContents() {
231         return 0;
232     }
233 }
234