ParcelableCall.java revision 95d5587d0aad9dfd49f798408f4212f95ce68fc7
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;
24
25import java.util.ArrayList;
26import java.util.Collections;
27import java.util.List;
28
29import com.android.internal.telecom.IVideoProvider;
30
31/**
32 * Information about a call that is used between InCallService and Telecom.
33 * @hide
34 */
35public 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 int mSupportedAudioRoutes;
43    private final long mConnectTimeMillis;
44    private final Uri mHandle;
45    private final int mHandlePresentation;
46    private final String mCallerDisplayName;
47    private final int mCallerDisplayNamePresentation;
48    private final GatewayInfo mGatewayInfo;
49    private final PhoneAccountHandle mAccountHandle;
50    private final boolean mIsVideoCallProviderChanged;
51    private final IVideoProvider mVideoCallProvider;
52    private VideoCallImpl mVideoCall;
53    private final boolean mIsRttCallChanged;
54    private final ParcelableRttCall mRttCall;
55    private final String mParentCallId;
56    private final List<String> mChildCallIds;
57    private final StatusHints mStatusHints;
58    private final int mVideoState;
59    private final List<String> mConferenceableCallIds;
60    private final Bundle mIntentExtras;
61    private final Bundle mExtras;
62
63    public ParcelableCall(
64            String id,
65            int state,
66            DisconnectCause disconnectCause,
67            List<String> cannedSmsResponses,
68            int capabilities,
69            int properties,
70            int supportedAudioRoutes,
71            long connectTimeMillis,
72            Uri handle,
73            int handlePresentation,
74            String callerDisplayName,
75            int callerDisplayNamePresentation,
76            GatewayInfo gatewayInfo,
77            PhoneAccountHandle accountHandle,
78            boolean isVideoCallProviderChanged,
79            IVideoProvider videoCallProvider,
80            boolean isRttCallChanged,
81            ParcelableRttCall rttCall,
82            String parentCallId,
83            List<String> childCallIds,
84            StatusHints statusHints,
85            int videoState,
86            List<String> conferenceableCallIds,
87            Bundle intentExtras,
88            Bundle extras) {
89        mId = id;
90        mState = state;
91        mDisconnectCause = disconnectCause;
92        mCannedSmsResponses = cannedSmsResponses;
93        mCapabilities = capabilities;
94        mProperties = properties;
95        mSupportedAudioRoutes = supportedAudioRoutes;
96        mConnectTimeMillis = connectTimeMillis;
97        mHandle = handle;
98        mHandlePresentation = handlePresentation;
99        mCallerDisplayName = callerDisplayName;
100        mCallerDisplayNamePresentation = callerDisplayNamePresentation;
101        mGatewayInfo = gatewayInfo;
102        mAccountHandle = accountHandle;
103        mIsVideoCallProviderChanged = isVideoCallProviderChanged;
104        mVideoCallProvider = videoCallProvider;
105        mIsRttCallChanged = isRttCallChanged;
106        mRttCall = rttCall;
107        mParentCallId = parentCallId;
108        mChildCallIds = childCallIds;
109        mStatusHints = statusHints;
110        mVideoState = videoState;
111        mConferenceableCallIds = Collections.unmodifiableList(conferenceableCallIds);
112        mIntentExtras = intentExtras;
113        mExtras = extras;
114    }
115
116    /** The unique ID of the call. */
117    public String getId() {
118        return mId;
119    }
120
121    /** The current state of the call. */
122    public int getState() {
123        return mState;
124    }
125
126    /**
127     * Reason for disconnection, as described by {@link android.telecomm.DisconnectCause}. Valid
128     * when call state is {@link CallState#DISCONNECTED}.
129     */
130    public DisconnectCause getDisconnectCause() {
131        return mDisconnectCause;
132    }
133
134    /**
135     * The set of possible text message responses when this call is incoming.
136     */
137    public List<String> getCannedSmsResponses() {
138        return mCannedSmsResponses;
139    }
140
141    // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
142    public int getCapabilities() {
143        return mCapabilities;
144    }
145
146    /** Bitmask of properties of the call. */
147    public int getProperties() { return mProperties; }
148
149    /** Bitmask of supported routes of the call */
150    public int getSupportedAudioRoutes() {
151        return mSupportedAudioRoutes;
152    }
153
154    /** The time that the call switched to the active state. */
155    public long getConnectTimeMillis() {
156        return mConnectTimeMillis;
157    }
158
159    /** The endpoint to which the call is connected. */
160    public Uri getHandle() {
161        return mHandle;
162    }
163
164    /**
165     * The presentation requirements for the handle. See {@link TelecomManager} for valid values.
166     */
167    public int getHandlePresentation() {
168        return mHandlePresentation;
169    }
170
171    /** The endpoint to which the call is connected. */
172    public String getCallerDisplayName() {
173        return mCallerDisplayName;
174    }
175
176    /**
177     * The presentation requirements for the caller display name.
178     * See {@link TelecomManager} for valid values.
179     */
180    public int getCallerDisplayNamePresentation() {
181        return mCallerDisplayNamePresentation;
182    }
183
184    /** Gateway information for the call. */
185    public GatewayInfo getGatewayInfo() {
186        return mGatewayInfo;
187    }
188
189    /** PhoneAccountHandle information for the call. */
190    public PhoneAccountHandle getAccountHandle() {
191        return mAccountHandle;
192    }
193
194    /**
195     * Returns an object for remotely communicating through the video call provider's binder.
196
197     * @return The video call.
198     */
199    public VideoCallImpl getVideoCallImpl(String callingPackageName) {
200        if (mVideoCall == null && mVideoCallProvider != null) {
201            try {
202                mVideoCall = new VideoCallImpl(mVideoCallProvider, callingPackageName);
203            } catch (RemoteException ignored) {
204                // Ignore RemoteException.
205            }
206        }
207
208        return mVideoCall;
209    }
210
211    public boolean getIsRttCallChanged() {
212        return mIsRttCallChanged;
213    }
214
215    /**
216     * RTT communication channel information
217     * @return The ParcelableRttCall
218     */
219    public ParcelableRttCall getParcelableRttCall() {
220        return mRttCall;
221    }
222
223    /**
224     * The conference call to which this call is conferenced. Null if not conferenced.
225     */
226    public String getParentCallId() {
227        return mParentCallId;
228    }
229
230    /**
231     * The child call-IDs if this call is a conference call. Returns an empty list if this is not
232     * a conference call or if the conference call contains no children.
233     */
234    public List<String> getChildCallIds() {
235        return mChildCallIds;
236    }
237
238    public List<String> getConferenceableCallIds() {
239        return mConferenceableCallIds;
240    }
241
242    /**
243     * The status label and icon.
244     *
245     * @return Status hints.
246     */
247    public StatusHints getStatusHints() {
248        return mStatusHints;
249    }
250
251    /**
252     * The video state.
253     * @return The video state of the call.
254     */
255    public int getVideoState() {
256        return mVideoState;
257    }
258
259    /**
260     * Any extras associated with this call.
261     *
262     * @return a bundle of extras
263     */
264    public Bundle getExtras() {
265        return mExtras;
266    }
267
268    /**
269     * Extras passed in as part of the original call intent.
270     *
271     * @return The intent extras.
272     */
273    public Bundle getIntentExtras() {
274        return mIntentExtras;
275    }
276
277    /**
278     * Indicates to the receiver of the {@link ParcelableCall} whether a change has occurred in the
279     * {@link android.telecom.InCallService.VideoCall} associated with this call.  Since
280     * {@link #getVideoCall()} creates a new {@link VideoCallImpl}, it is useful to know whether
281     * the provider has changed (which can influence whether it is accessed).
282     *
283     * @return {@code true} if the video call changed, {@code false} otherwise.
284     */
285    public boolean isVideoCallProviderChanged() {
286        return mIsVideoCallProviderChanged;
287    }
288
289    /** Responsible for creating ParcelableCall objects for deserialized Parcels. */
290    public static final Parcelable.Creator<ParcelableCall> CREATOR =
291            new Parcelable.Creator<ParcelableCall> () {
292        @Override
293        public ParcelableCall createFromParcel(Parcel source) {
294            ClassLoader classLoader = ParcelableCall.class.getClassLoader();
295            String id = source.readString();
296            int state = source.readInt();
297            DisconnectCause disconnectCause = source.readParcelable(classLoader);
298            List<String> cannedSmsResponses = new ArrayList<>();
299            source.readList(cannedSmsResponses, classLoader);
300            int capabilities = source.readInt();
301            int properties = source.readInt();
302            long connectTimeMillis = source.readLong();
303            Uri handle = source.readParcelable(classLoader);
304            int handlePresentation = source.readInt();
305            String callerDisplayName = source.readString();
306            int callerDisplayNamePresentation = source.readInt();
307            GatewayInfo gatewayInfo = source.readParcelable(classLoader);
308            PhoneAccountHandle accountHandle = source.readParcelable(classLoader);
309            boolean isVideoCallProviderChanged = source.readByte() == 1;
310            IVideoProvider videoCallProvider =
311                    IVideoProvider.Stub.asInterface(source.readStrongBinder());
312            String parentCallId = source.readString();
313            List<String> childCallIds = new ArrayList<>();
314            source.readList(childCallIds, classLoader);
315            StatusHints statusHints = source.readParcelable(classLoader);
316            int videoState = source.readInt();
317            List<String> conferenceableCallIds = new ArrayList<>();
318            source.readList(conferenceableCallIds, classLoader);
319            Bundle intentExtras = source.readBundle(classLoader);
320            Bundle extras = source.readBundle(classLoader);
321            int supportedAudioRoutes = source.readInt();
322            boolean isRttCallChanged = source.readByte() == 1;
323            ParcelableRttCall rttCall = source.readParcelable(classLoader);
324            return new ParcelableCall(
325                    id,
326                    state,
327                    disconnectCause,
328                    cannedSmsResponses,
329                    capabilities,
330                    properties,
331                    supportedAudioRoutes,
332                    connectTimeMillis,
333                    handle,
334                    handlePresentation,
335                    callerDisplayName,
336                    callerDisplayNamePresentation,
337                    gatewayInfo,
338                    accountHandle,
339                    isVideoCallProviderChanged,
340                    videoCallProvider,
341                    isRttCallChanged,
342                    rttCall,
343                    parentCallId,
344                    childCallIds,
345                    statusHints,
346                    videoState,
347                    conferenceableCallIds,
348                    intentExtras,
349                    extras);
350        }
351
352        @Override
353        public ParcelableCall[] newArray(int size) {
354            return new ParcelableCall[size];
355        }
356    };
357
358    /** {@inheritDoc} */
359    @Override
360    public int describeContents() {
361        return 0;
362    }
363
364    /** Writes ParcelableCall object into a Parcel. */
365    @Override
366    public void writeToParcel(Parcel destination, int flags) {
367        destination.writeString(mId);
368        destination.writeInt(mState);
369        destination.writeParcelable(mDisconnectCause, 0);
370        destination.writeList(mCannedSmsResponses);
371        destination.writeInt(mCapabilities);
372        destination.writeInt(mProperties);
373        destination.writeLong(mConnectTimeMillis);
374        destination.writeParcelable(mHandle, 0);
375        destination.writeInt(mHandlePresentation);
376        destination.writeString(mCallerDisplayName);
377        destination.writeInt(mCallerDisplayNamePresentation);
378        destination.writeParcelable(mGatewayInfo, 0);
379        destination.writeParcelable(mAccountHandle, 0);
380        destination.writeByte((byte) (mIsVideoCallProviderChanged ? 1 : 0));
381        destination.writeStrongBinder(
382                mVideoCallProvider != null ? mVideoCallProvider.asBinder() : null);
383        destination.writeString(mParentCallId);
384        destination.writeList(mChildCallIds);
385        destination.writeParcelable(mStatusHints, 0);
386        destination.writeInt(mVideoState);
387        destination.writeList(mConferenceableCallIds);
388        destination.writeBundle(mIntentExtras);
389        destination.writeBundle(mExtras);
390        destination.writeInt(mSupportedAudioRoutes);
391        destination.writeByte((byte) (mIsRttCallChanged ? 1 : 0));
392        destination.writeParcelable(mRttCall, 0);
393    }
394
395    @Override
396    public String toString() {
397        return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds);
398    }
399}
400