Home | History | Annotate | Download | only in telecom
      1 /*
      2  * Copyright 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.telecom;
     18 
     19 import android.net.Uri;
     20 import android.os.Bundle;
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 import android.os.RemoteException;
     24 
     25 import java.util.ArrayList;
     26 import java.util.Collections;
     27 import java.util.List;
     28 
     29 import com.android.internal.telecom.IVideoProvider;
     30 
     31 /**
     32  * Information about a call that is used between InCallService and Telecom.
     33  * @hide
     34  */
     35 public final class ParcelableCall implements Parcelable {
     36     private final String mId;
     37     private final int mState;
     38     private final DisconnectCause mDisconnectCause;
     39     private final List<String> mCannedSmsResponses;
     40     private final int mCapabilities;
     41     private final int mProperties;
     42     private final long mConnectTimeMillis;
     43     private final Uri mHandle;
     44     private final int mHandlePresentation;
     45     private final String mCallerDisplayName;
     46     private final int mCallerDisplayNamePresentation;
     47     private final GatewayInfo mGatewayInfo;
     48     private final PhoneAccountHandle mAccountHandle;
     49     private final IVideoProvider mVideoCallProvider;
     50     private InCallService.VideoCall mVideoCall;
     51     private final String mParentCallId;
     52     private final List<String> mChildCallIds;
     53     private final StatusHints mStatusHints;
     54     private final int mVideoState;
     55     private final List<String> mConferenceableCallIds;
     56     private final Bundle mExtras;
     57 
     58     public ParcelableCall(
     59             String id,
     60             int state,
     61             DisconnectCause disconnectCause,
     62             List<String> cannedSmsResponses,
     63             int capabilities,
     64             int properties,
     65             long connectTimeMillis,
     66             Uri handle,
     67             int handlePresentation,
     68             String callerDisplayName,
     69             int callerDisplayNamePresentation,
     70             GatewayInfo gatewayInfo,
     71             PhoneAccountHandle accountHandle,
     72             IVideoProvider videoCallProvider,
     73             String parentCallId,
     74             List<String> childCallIds,
     75             StatusHints statusHints,
     76             int videoState,
     77             List<String> conferenceableCallIds,
     78             Bundle extras) {
     79         mId = id;
     80         mState = state;
     81         mDisconnectCause = disconnectCause;
     82         mCannedSmsResponses = cannedSmsResponses;
     83         mCapabilities = capabilities;
     84         mProperties = properties;
     85         mConnectTimeMillis = connectTimeMillis;
     86         mHandle = handle;
     87         mHandlePresentation = handlePresentation;
     88         mCallerDisplayName = callerDisplayName;
     89         mCallerDisplayNamePresentation = callerDisplayNamePresentation;
     90         mGatewayInfo = gatewayInfo;
     91         mAccountHandle = accountHandle;
     92         mVideoCallProvider = videoCallProvider;
     93         mParentCallId = parentCallId;
     94         mChildCallIds = childCallIds;
     95         mStatusHints = statusHints;
     96         mVideoState = videoState;
     97         mConferenceableCallIds = Collections.unmodifiableList(conferenceableCallIds);
     98         mExtras = extras;
     99     }
    100 
    101     /** The unique ID of the call. */
    102     public String getId() {
    103         return mId;
    104     }
    105 
    106     /** The current state of the call. */
    107     public int getState() {
    108         return mState;
    109     }
    110 
    111     /**
    112      * Reason for disconnection, as described by {@link android.telecomm.DisconnectCause}. Valid
    113      * when call state is {@link CallState#DISCONNECTED}.
    114      */
    115     public DisconnectCause getDisconnectCause() {
    116         return mDisconnectCause;
    117     }
    118 
    119     /**
    120      * The set of possible text message responses when this call is incoming.
    121      */
    122     public List<String> getCannedSmsResponses() {
    123         return mCannedSmsResponses;
    124     }
    125 
    126     // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
    127     public int getCapabilities() {
    128         return mCapabilities;
    129     }
    130 
    131     /** Bitmask of properties of the call. */
    132     public int getProperties() { return mProperties; }
    133 
    134     /** The time that the call switched to the active state. */
    135     public long getConnectTimeMillis() {
    136         return mConnectTimeMillis;
    137     }
    138 
    139     /** The endpoint to which the call is connected. */
    140     public Uri getHandle() {
    141         return mHandle;
    142     }
    143 
    144     /**
    145      * The presentation requirements for the handle. See {@link TelecomManager} for valid values.
    146      */
    147     public int getHandlePresentation() {
    148         return mHandlePresentation;
    149     }
    150 
    151     /** The endpoint to which the call is connected. */
    152     public String getCallerDisplayName() {
    153         return mCallerDisplayName;
    154     }
    155 
    156     /**
    157      * The presentation requirements for the caller display name.
    158      * See {@link TelecomManager} for valid values.
    159      */
    160     public int getCallerDisplayNamePresentation() {
    161         return mCallerDisplayNamePresentation;
    162     }
    163 
    164     /** Gateway information for the call. */
    165     public GatewayInfo getGatewayInfo() {
    166         return mGatewayInfo;
    167     }
    168 
    169     /** PhoneAccountHandle information for the call. */
    170     public PhoneAccountHandle getAccountHandle() {
    171         return mAccountHandle;
    172     }
    173 
    174     /**
    175      * Returns an object for remotely communicating through the video call provider's binder.
    176      * @return The video call.
    177      */
    178     public InCallService.VideoCall getVideoCall() {
    179         if (mVideoCall == null && mVideoCallProvider != null) {
    180             try {
    181                 mVideoCall = new VideoCallImpl(mVideoCallProvider);
    182             } catch (RemoteException ignored) {
    183                 // Ignore RemoteException.
    184             }
    185         }
    186 
    187         return mVideoCall;
    188     }
    189 
    190     /**
    191      * The conference call to which this call is conferenced. Null if not conferenced.
    192      */
    193     public String getParentCallId() {
    194         return mParentCallId;
    195     }
    196 
    197     /**
    198      * The child call-IDs if this call is a conference call. Returns an empty list if this is not
    199      * a conference call or if the conference call contains no children.
    200      */
    201     public List<String> getChildCallIds() {
    202         return mChildCallIds;
    203     }
    204 
    205     public List<String> getConferenceableCallIds() {
    206         return mConferenceableCallIds;
    207     }
    208 
    209     /**
    210      * The status label and icon.
    211      *
    212      * @return Status hints.
    213      */
    214     public StatusHints getStatusHints() {
    215         return mStatusHints;
    216     }
    217 
    218     /**
    219      * The video state.
    220      * @return The video state of the call.
    221      */
    222     public int getVideoState() {
    223         return mVideoState;
    224     }
    225 
    226     /**
    227      * Any extras to pass with the call
    228      *
    229      * @return a bundle of extras
    230      */
    231     public Bundle getExtras() {
    232         return mExtras;
    233     }
    234 
    235     /** Responsible for creating ParcelableCall objects for deserialized Parcels. */
    236     public static final Parcelable.Creator<ParcelableCall> CREATOR =
    237             new Parcelable.Creator<ParcelableCall> () {
    238         @Override
    239         public ParcelableCall createFromParcel(Parcel source) {
    240             ClassLoader classLoader = ParcelableCall.class.getClassLoader();
    241             String id = source.readString();
    242             int state = source.readInt();
    243             DisconnectCause disconnectCause = source.readParcelable(classLoader);
    244             List<String> cannedSmsResponses = new ArrayList<>();
    245             source.readList(cannedSmsResponses, classLoader);
    246             int capabilities = source.readInt();
    247             int properties = source.readInt();
    248             long connectTimeMillis = source.readLong();
    249             Uri handle = source.readParcelable(classLoader);
    250             int handlePresentation = source.readInt();
    251             String callerDisplayName = source.readString();
    252             int callerDisplayNamePresentation = source.readInt();
    253             GatewayInfo gatewayInfo = source.readParcelable(classLoader);
    254             PhoneAccountHandle accountHandle = source.readParcelable(classLoader);
    255             IVideoProvider videoCallProvider =
    256                     IVideoProvider.Stub.asInterface(source.readStrongBinder());
    257             String parentCallId = source.readString();
    258             List<String> childCallIds = new ArrayList<>();
    259             source.readList(childCallIds, classLoader);
    260             StatusHints statusHints = source.readParcelable(classLoader);
    261             int videoState = source.readInt();
    262             List<String> conferenceableCallIds = new ArrayList<>();
    263             source.readList(conferenceableCallIds, classLoader);
    264             Bundle extras = source.readParcelable(classLoader);
    265             return new ParcelableCall(
    266                     id,
    267                     state,
    268                     disconnectCause,
    269                     cannedSmsResponses,
    270                     capabilities,
    271                     properties,
    272                     connectTimeMillis,
    273                     handle,
    274                     handlePresentation,
    275                     callerDisplayName,
    276                     callerDisplayNamePresentation,
    277                     gatewayInfo,
    278                     accountHandle,
    279                     videoCallProvider,
    280                     parentCallId,
    281                     childCallIds,
    282                     statusHints,
    283                     videoState,
    284                     conferenceableCallIds,
    285                     extras);
    286         }
    287 
    288         @Override
    289         public ParcelableCall[] newArray(int size) {
    290             return new ParcelableCall[size];
    291         }
    292     };
    293 
    294     /** {@inheritDoc} */
    295     @Override
    296     public int describeContents() {
    297         return 0;
    298     }
    299 
    300     /** Writes ParcelableCall object into a Parcel. */
    301     @Override
    302     public void writeToParcel(Parcel destination, int flags) {
    303         destination.writeString(mId);
    304         destination.writeInt(mState);
    305         destination.writeParcelable(mDisconnectCause, 0);
    306         destination.writeList(mCannedSmsResponses);
    307         destination.writeInt(mCapabilities);
    308         destination.writeInt(mProperties);
    309         destination.writeLong(mConnectTimeMillis);
    310         destination.writeParcelable(mHandle, 0);
    311         destination.writeInt(mHandlePresentation);
    312         destination.writeString(mCallerDisplayName);
    313         destination.writeInt(mCallerDisplayNamePresentation);
    314         destination.writeParcelable(mGatewayInfo, 0);
    315         destination.writeParcelable(mAccountHandle, 0);
    316         destination.writeStrongBinder(
    317                 mVideoCallProvider != null ? mVideoCallProvider.asBinder() : null);
    318         destination.writeString(mParentCallId);
    319         destination.writeList(mChildCallIds);
    320         destination.writeParcelable(mStatusHints, 0);
    321         destination.writeInt(mVideoState);
    322         destination.writeList(mConferenceableCallIds);
    323         destination.writeParcelable(mExtras, 0);
    324     }
    325 
    326     @Override
    327     public String toString() {
    328         return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds);
    329     }
    330 }
    331