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