ParcelableConnection.java revision 4e22d6dc453de8e15e19e842c189522796c1cf80
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;
23
24import com.android.internal.telecom.IVideoProvider;
25
26import java.util.ArrayList;
27import java.util.List;
28
29/**
30 * Information about a connection that is used between Telecom and the ConnectionService.
31 * This is used to send initial Connection information to Telecom when the connection is
32 * first created.
33 * @hide
34 */
35public final class ParcelableConnection implements Parcelable {
36    private final PhoneAccountHandle mPhoneAccount;
37    private final int mState;
38    private final int mConnectionCapabilities;
39    private final int mConnectionProperties;
40    private final int mSupportedAudioRoutes;
41    private final Uri mAddress;
42    private final int mAddressPresentation;
43    private final String mCallerDisplayName;
44    private final int mCallerDisplayNamePresentation;
45    private final IVideoProvider mVideoProvider;
46    private final int mVideoState;
47    private final boolean mRingbackRequested;
48    private final boolean mIsVoipAudioMode;
49    private final long mConnectTimeMillis;
50    private final StatusHints mStatusHints;
51    private final DisconnectCause mDisconnectCause;
52    private final List<String> mConferenceableConnectionIds;
53    private final Bundle mExtras;
54
55    /** @hide */
56    public ParcelableConnection(
57            PhoneAccountHandle phoneAccount,
58            int state,
59            int capabilities,
60            int properties,
61            int supportedAudioRoutes,
62            Uri address,
63            int addressPresentation,
64            String callerDisplayName,
65            int callerDisplayNamePresentation,
66            IVideoProvider videoProvider,
67            int videoState,
68            boolean ringbackRequested,
69            boolean isVoipAudioMode,
70            long connectTimeMillis,
71            StatusHints statusHints,
72            DisconnectCause disconnectCause,
73            List<String> conferenceableConnectionIds,
74            Bundle extras) {
75        mPhoneAccount = phoneAccount;
76        mState = state;
77        mConnectionCapabilities = capabilities;
78        mConnectionProperties = properties;
79        mSupportedAudioRoutes = supportedAudioRoutes;
80        mAddress = address;
81        mAddressPresentation = addressPresentation;
82        mCallerDisplayName = callerDisplayName;
83        mCallerDisplayNamePresentation = callerDisplayNamePresentation;
84        mVideoProvider = videoProvider;
85        mVideoState = videoState;
86        mRingbackRequested = ringbackRequested;
87        mIsVoipAudioMode = isVoipAudioMode;
88        mConnectTimeMillis = connectTimeMillis;
89        mStatusHints = statusHints;
90        mDisconnectCause = disconnectCause;
91        mConferenceableConnectionIds = conferenceableConnectionIds;
92        mExtras = extras;
93    }
94
95    public PhoneAccountHandle getPhoneAccount() {
96        return mPhoneAccount;
97    }
98
99    public int getState() {
100        return mState;
101    }
102
103    /**
104     * Returns the current connection capabilities bit-mask.  Connection capabilities are defined as
105     * {@code CAPABILITY_*} constants in {@link Connection}.
106     *
107     * @return Bit-mask containing capabilities of the connection.
108     */
109    public int getConnectionCapabilities() {
110        return mConnectionCapabilities;
111    }
112
113    /**
114     * Returns the current connection properties bit-mask.  Connection properties are defined as
115     * {@code PROPERTY_*} constants in {@link Connection}.
116     *
117     * @return Bit-mask containing properties of the connection.
118     */
119    public int getConnectionProperties() {
120        return mConnectionProperties;
121    }
122
123    public int getSupportedAudioRoutes() {
124        return mSupportedAudioRoutes;
125    }
126
127    public Uri getHandle() {
128        return mAddress;
129    }
130
131    public int getHandlePresentation() {
132        return mAddressPresentation;
133    }
134
135    public String getCallerDisplayName() {
136        return mCallerDisplayName;
137    }
138
139    public int getCallerDisplayNamePresentation() {
140        return mCallerDisplayNamePresentation;
141    }
142
143    public IVideoProvider getVideoProvider() {
144        return mVideoProvider;
145    }
146
147    public int getVideoState() {
148        return mVideoState;
149    }
150
151    public boolean isRingbackRequested() {
152        return mRingbackRequested;
153    }
154
155    public boolean getIsVoipAudioMode() {
156        return mIsVoipAudioMode;
157    }
158
159    public long getConnectTimeMillis() {
160        return mConnectTimeMillis;
161    }
162
163    public final StatusHints getStatusHints() {
164        return mStatusHints;
165    }
166
167    public final DisconnectCause getDisconnectCause() {
168        return mDisconnectCause;
169    }
170
171    public final List<String> getConferenceableConnectionIds() {
172        return mConferenceableConnectionIds;
173    }
174
175    public final Bundle getExtras() {
176        return mExtras;
177    }
178
179    @Override
180    public String toString() {
181        return new StringBuilder()
182                .append("ParcelableConnection [act:")
183                .append(mPhoneAccount)
184                .append("], state:")
185                .append(mState)
186                .append(", capabilities:")
187                .append(Connection.capabilitiesToString(mConnectionCapabilities))
188                .append(", properties:")
189                .append(Connection.propertiesToString(mConnectionProperties))
190                .append(", extras:")
191                .append(mExtras)
192                .toString();
193    }
194
195    public static final Parcelable.Creator<ParcelableConnection> CREATOR =
196            new Parcelable.Creator<ParcelableConnection> () {
197        @Override
198        public ParcelableConnection createFromParcel(Parcel source) {
199            ClassLoader classLoader = ParcelableConnection.class.getClassLoader();
200
201            PhoneAccountHandle phoneAccount = source.readParcelable(classLoader);
202            int state = source.readInt();
203            int capabilities = source.readInt();
204            Uri address = source.readParcelable(classLoader);
205            int addressPresentation = source.readInt();
206            String callerDisplayName = source.readString();
207            int callerDisplayNamePresentation = source.readInt();
208            IVideoProvider videoCallProvider =
209                    IVideoProvider.Stub.asInterface(source.readStrongBinder());
210            int videoState = source.readInt();
211            boolean ringbackRequested = source.readByte() == 1;
212            boolean audioModeIsVoip = source.readByte() == 1;
213            long connectTimeMillis = source.readLong();
214            StatusHints statusHints = source.readParcelable(classLoader);
215            DisconnectCause disconnectCause = source.readParcelable(classLoader);
216            List<String> conferenceableConnectionIds = new ArrayList<>();
217            source.readStringList(conferenceableConnectionIds);
218            Bundle extras = Bundle.setDefusable(source.readBundle(classLoader), true);
219            int properties = source.readInt();
220            int supportedAudioRoutes = source.readInt();
221
222            return new ParcelableConnection(
223                    phoneAccount,
224                    state,
225                    capabilities,
226                    properties,
227                    supportedAudioRoutes,
228                    address,
229                    addressPresentation,
230                    callerDisplayName,
231                    callerDisplayNamePresentation,
232                    videoCallProvider,
233                    videoState,
234                    ringbackRequested,
235                    audioModeIsVoip,
236                    connectTimeMillis,
237                    statusHints,
238                    disconnectCause,
239                    conferenceableConnectionIds,
240                    extras);
241        }
242
243        @Override
244        public ParcelableConnection[] newArray(int size) {
245            return new ParcelableConnection[size];
246        }
247    };
248
249    /** {@inheritDoc} */
250    @Override
251    public int describeContents() {
252        return 0;
253    }
254
255    /** Writes ParcelableConnection object into a Parcel. */
256    @Override
257    public void writeToParcel(Parcel destination, int flags) {
258        destination.writeParcelable(mPhoneAccount, 0);
259        destination.writeInt(mState);
260        destination.writeInt(mConnectionCapabilities);
261        destination.writeParcelable(mAddress, 0);
262        destination.writeInt(mAddressPresentation);
263        destination.writeString(mCallerDisplayName);
264        destination.writeInt(mCallerDisplayNamePresentation);
265        destination.writeStrongBinder(
266                mVideoProvider != null ? mVideoProvider.asBinder() : null);
267        destination.writeInt(mVideoState);
268        destination.writeByte((byte) (mRingbackRequested ? 1 : 0));
269        destination.writeByte((byte) (mIsVoipAudioMode ? 1 : 0));
270        destination.writeLong(mConnectTimeMillis);
271        destination.writeParcelable(mStatusHints, 0);
272        destination.writeParcelable(mDisconnectCause, 0);
273        destination.writeStringList(mConferenceableConnectionIds);
274        destination.writeBundle(mExtras);
275        destination.writeInt(mConnectionProperties);
276        destination.writeInt(mSupportedAudioRoutes);
277    }
278}
279