ParcelableCall.java revision 5ffbfccea007e6aebc9ba53b3666664d08a666b4
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.telecomm;
18
19import android.net.Uri;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.telephony.DisconnectCause;
23
24import java.util.ArrayList;
25import java.util.Collections;
26import java.util.List;
27
28/**
29 * Information about a call that is used between InCallService and Telecomm.
30 */
31public final class InCallCall implements Parcelable {
32    private final String mId;
33    private final CallState mState;
34    private final int mDisconnectCauseCode;
35    private final String mDisconnectCauseMsg;
36    private final List<String> mCannedSmsResponses;
37    private final int mCapabilities;
38    private final long mConnectTimeMillis;
39    private final Uri mHandle;
40    private final GatewayInfo mGatewayInfo;
41    private final Subscription mSubscription;
42    private final CallServiceDescriptor mCurrentCallServiceDescriptor;
43    private final CallServiceDescriptor mHandoffCallServiceDescriptor;
44    private final String mParentCallId;
45    private final List<String> mChildCallIds;
46
47    /** @hide */
48    @SuppressWarnings("unchecked")
49    public InCallCall(
50            String id,
51            CallState state,
52            int disconnectCauseCode,
53            String disconnectCauseMsg,
54            List<String> cannedSmsResponses,
55            int capabilities,
56            long connectTimeMillis,
57            Uri handle,
58            GatewayInfo gatewayInfo,
59            Subscription subscription,
60            CallServiceDescriptor descriptor,
61            CallServiceDescriptor handoffDescriptor) {
62        this(id, state, disconnectCauseCode, disconnectCauseMsg, cannedSmsResponses,
63                capabilities, connectTimeMillis, handle, gatewayInfo, subscription, descriptor,
64                handoffDescriptor, null, Collections.EMPTY_LIST);
65    }
66
67    /** @hide */
68    public InCallCall(
69            String id,
70            CallState state,
71            int disconnectCauseCode,
72            String disconnectCauseMsg,
73            List<String> cannedSmsResponses,
74            int capabilities,
75            long connectTimeMillis,
76            Uri handle,
77            GatewayInfo gatewayInfo,
78            Subscription subscription,
79            CallServiceDescriptor descriptor,
80            CallServiceDescriptor handoffDescriptor,
81            String parentCallId,
82            List<String> childCallIds) {
83        mId = id;
84        mState = state;
85        mDisconnectCauseCode = disconnectCauseCode;
86        mDisconnectCauseMsg = disconnectCauseMsg;
87        mCannedSmsResponses = cannedSmsResponses;
88        mCapabilities = capabilities;
89        mConnectTimeMillis = connectTimeMillis;
90        mHandle = handle;
91        mGatewayInfo = gatewayInfo;
92        mSubscription = subscription;
93        mCurrentCallServiceDescriptor = descriptor;
94        mHandoffCallServiceDescriptor = handoffDescriptor;
95        mParentCallId = parentCallId;
96        mChildCallIds = childCallIds;
97    }
98
99    /** The unique ID of the call. */
100    public String getId() {
101        return mId;
102    }
103
104    /** The current state of the call. */
105    public CallState getState() {
106        return mState;
107    }
108
109    /**
110     * Reason for disconnection, values are defined in {@link DisconnectCause}. Valid when call
111     * state is {@link CallState#DISCONNECTED}.
112     */
113    public int getDisconnectCauseCode() {
114        return mDisconnectCauseCode;
115    }
116
117    /**
118     * Further optional textual information about the reason for disconnection. Valid when call
119     * state is {@link CallState#DISCONNECTED}.
120     */
121    public String getDisconnectCauseMsg() {
122        return mDisconnectCauseMsg;
123    }
124
125    /**
126     * The set of possible text message responses when this call is incoming.
127     */
128    public List<String> getCannedSmsResponses() {
129        return mCannedSmsResponses;
130    }
131
132    // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
133    public int getCapabilities() {
134        return mCapabilities;
135    }
136
137    /** The time that the call switched to the active state. */
138    public long getConnectTimeMillis() {
139        return mConnectTimeMillis;
140    }
141
142    /** The endpoint to which the call is connected. */
143    public Uri getHandle() {
144        return mHandle;
145    }
146
147    /** Gateway information for the call. */
148    public GatewayInfo getGatewayInfo() {
149        return mGatewayInfo;
150    }
151
152    /** Subscription information for the call. */
153    public Subscription getSubscription() {
154        return mSubscription;
155    }
156
157    /** The descriptor for the call service currently routing this call. */
158    public CallServiceDescriptor getCurrentCallServiceDescriptor() {
159        return mCurrentCallServiceDescriptor;
160    }
161
162    /**
163     * The descriptor for the call service that this call is being switched to, null if handoff is
164     * not in progress.
165     */
166    public CallServiceDescriptor getHandoffCallServiceDescriptor() {
167        return mHandoffCallServiceDescriptor;
168    }
169
170    /**
171     * The conference call to which this call is conferenced. Null if not conferenced.
172     * @hide
173     */
174    public String getParentCallId() {
175        return mParentCallId;
176    }
177
178    /**
179     * The child call-IDs if this call is a conference call. Returns an empty list if this is not
180     * a conference call or if the conference call contains no children.
181     * @hide
182     */
183    public List<String> getChildCallIds() {
184        return mChildCallIds;
185    }
186
187    /** Responsible for creating InCallCall objects for deserialized Parcels. */
188    public static final Parcelable.Creator<InCallCall> CREATOR =
189            new Parcelable.Creator<InCallCall> () {
190        @Override
191        public InCallCall createFromParcel(Parcel source) {
192            ClassLoader classLoader = InCallCall.class.getClassLoader();
193            String id = source.readString();
194            CallState state = CallState.valueOf(source.readString());
195            int disconnectCauseCode = source.readInt();
196            String disconnectCauseMsg = source.readString();
197            List<String> cannedSmsResponses = new ArrayList<>();
198            source.readList(cannedSmsResponses, classLoader);
199            int capabilities = source.readInt();
200            long connectTimeMillis = source.readLong();
201            Uri handle = source.readParcelable(classLoader);
202            GatewayInfo gatewayInfo = source.readParcelable(classLoader);
203            Subscription subscription = source.readParcelable(classLoader);
204            CallServiceDescriptor descriptor = source.readParcelable(classLoader);
205            CallServiceDescriptor handoffDescriptor = source.readParcelable(classLoader);
206            String parentCallId = source.readString();
207            List<String> childCallIds = new ArrayList<>();
208            source.readList(childCallIds, classLoader);
209            return new InCallCall(id, state, disconnectCauseCode, disconnectCauseMsg,
210                    cannedSmsResponses, capabilities, connectTimeMillis, handle, gatewayInfo,
211                    subscription, descriptor, handoffDescriptor, parentCallId, childCallIds);
212        }
213
214        @Override
215        public InCallCall[] newArray(int size) {
216            return new InCallCall[size];
217        }
218    };
219
220    /** {@inheritDoc} */
221    @Override
222    public int describeContents() {
223        return 0;
224    }
225
226    /** Writes InCallCall object into a Parcel. */
227    @Override
228    public void writeToParcel(Parcel destination, int flags) {
229        destination.writeString(mId);
230        destination.writeString(mState.name());
231        destination.writeInt(mDisconnectCauseCode);
232        destination.writeString(mDisconnectCauseMsg);
233        destination.writeList(mCannedSmsResponses);
234        destination.writeInt(mCapabilities);
235        destination.writeLong(mConnectTimeMillis);
236        destination.writeParcelable(mHandle, 0);
237        destination.writeParcelable(mGatewayInfo, 0);
238        destination.writeParcelable(mSubscription, 0);
239        destination.writeParcelable(mCurrentCallServiceDescriptor, 0);
240        destination.writeParcelable(mHandoffCallServiceDescriptor, 0);
241        destination.writeString(mParentCallId);
242        destination.writeList(mChildCallIds);
243    }
244
245    @Override
246    public String toString() {
247        return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds);
248    }
249}
250