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
17package android.bluetooth;
18
19import android.os.Parcel;
20import 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 */
27public 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 int mId;
65    private int mState;
66    private String mNumber;
67    private boolean mMultiParty;
68    private final boolean mOutgoing;
69
70    /**
71     * Creates BluetoothHeadsetClientCall instance.
72     */
73    public BluetoothHeadsetClientCall(int id, int state, String number, boolean multiParty,
74            boolean outgoing) {
75        mId = id;
76        mState = state;
77        mNumber = number != null ? number : "";
78        mMultiParty = multiParty;
79        mOutgoing = outgoing;
80    }
81
82    /**
83     * Sets call's state.
84     *
85     * <p>Note: This is an internal function and shouldn't be exposed</p>
86     *
87     * @param  state    new call state.
88     */
89    public void setState(int state) {
90        mState = state;
91    }
92
93    /**
94     * Sets call's number.
95     *
96     * <p>Note: This is an internal function and shouldn't be exposed</p>
97     *
98     * @param number    String representing phone number.
99     */
100    public void setNumber(String number) {
101        mNumber = number;
102    }
103
104    /**
105     * Sets this call as multi party call.
106     *
107     * <p>Note: This is an internal function and shouldn't be exposed</p>
108     *
109     * @param multiParty    if <code>true</code> sets this call as a part
110     *                      of multi party conference.
111     */
112    public void setMultiParty(boolean multiParty) {
113        mMultiParty = multiParty;
114    }
115
116    /**
117     * Gets call's Id.
118     *
119     * @return call id.
120     */
121    public int getId() {
122        return mId;
123    }
124
125    /**
126     * Gets call's current state.
127     *
128     * @return state of this particular phone call.
129     */
130    public int getState() {
131        return mState;
132    }
133
134    /**
135     * Gets call's number.
136     *
137     * @return string representing phone number.
138     */
139    public String getNumber() {
140        return mNumber;
141    }
142
143    /**
144     * Checks if call is an active call in a conference mode (aka multi party).
145     *
146     * @return <code>true</code> if call is a multi party call,
147     *         <code>false</code> otherwise.
148     */
149    public boolean isMultiParty() {
150        return mMultiParty;
151    }
152
153    /**
154     * Checks if this call is an outgoing call.
155     *
156     * @return <code>true</code> if its outgoing call,
157     *         <code>false</code> otherwise.
158     */
159    public boolean isOutgoing() {
160        return mOutgoing;
161    }
162
163    public String toString() {
164        StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mId: ");
165        builder.append(mId);
166        builder.append(", mState: ");
167        switch (mState) {
168            case CALL_STATE_ACTIVE: builder.append("ACTIVE"); break;
169            case CALL_STATE_HELD: builder.append("HELD"); break;
170            case CALL_STATE_DIALING: builder.append("DIALING"); break;
171            case CALL_STATE_ALERTING: builder.append("ALERTING"); break;
172            case CALL_STATE_INCOMING: builder.append("INCOMING"); break;
173            case CALL_STATE_WAITING: builder.append("WAITING"); break;
174            case CALL_STATE_HELD_BY_RESPONSE_AND_HOLD: builder.append("HELD_BY_RESPONSE_AND_HOLD"); break;
175            case CALL_STATE_TERMINATED: builder.append("TERMINATED"); break;
176            default: builder.append(mState); break;
177        }
178        builder.append(", mNumber: ");
179        builder.append(mNumber);
180        builder.append(", mMultiParty: ");
181        builder.append(mMultiParty);
182        builder.append(", mOutgoing: ");
183        builder.append(mOutgoing);
184        builder.append("}");
185        return builder.toString();
186    }
187
188    /**
189     * {@link Parcelable.Creator} interface implementation.
190     */
191    public static final Parcelable.Creator<BluetoothHeadsetClientCall> CREATOR =
192            new Parcelable.Creator<BluetoothHeadsetClientCall>() {
193                @Override
194                public BluetoothHeadsetClientCall createFromParcel(Parcel in) {
195                    return new BluetoothHeadsetClientCall(in.readInt(), in.readInt(),
196                            in.readString(), in.readInt() == 1, in.readInt() == 1);
197                }
198
199                @Override
200                public BluetoothHeadsetClientCall[] newArray(int size) {
201                    return new BluetoothHeadsetClientCall[size];
202                }
203            };
204
205    @Override
206    public void writeToParcel(Parcel out, int flags) {
207        out.writeInt(mId);
208        out.writeInt(mState);
209        out.writeString(mNumber);
210        out.writeInt(mMultiParty ? 1 : 0);
211        out.writeInt(mOutgoing ? 1 : 0);
212    }
213
214    @Override
215    public int describeContents() {
216        return 0;
217    }
218}
219