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