ParcelableConnection.java revision 5c9c86ec0f95d1f5e1aca212967f508fc736b895
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.Parcel;
21import android.os.Parcelable;
22
23import com.android.internal.telecom.IVideoProvider;
24
25import java.util.ArrayList;
26import java.util.List;
27
28/**
29 * Information about a connection that is used between Telecom and the ConnectionService.
30 * This is used to send initial Connection information to Telecom when the connection is
31 * first created.
32 * @hide
33 */
34public final class ParcelableConnection implements Parcelable {
35    private final PhoneAccountHandle mPhoneAccount;
36    private final int mState;
37    private final int mConnectionCapabilities;
38    private final Uri mAddress;
39    private final int mAddressPresentation;
40    private final String mCallerDisplayName;
41    private final int mCallerDisplayNamePresentation;
42    private final IVideoProvider mVideoProvider;
43    private final int mVideoState;
44    private final boolean mRingbackRequested;
45    private final boolean mIsVoipAudioMode;
46    private final StatusHints mStatusHints;
47    private final DisconnectCause mDisconnectCause;
48    private final List<String> mConferenceableConnectionIds;
49
50    /** @hide */
51    public ParcelableConnection(
52            PhoneAccountHandle phoneAccount,
53            int state,
54            int capabilities,
55            Uri address,
56            int addressPresentation,
57            String callerDisplayName,
58            int callerDisplayNamePresentation,
59            IVideoProvider videoProvider,
60            int videoState,
61            boolean ringbackRequested,
62            boolean isVoipAudioMode,
63            StatusHints statusHints,
64            DisconnectCause disconnectCause,
65            List<String> conferenceableConnectionIds) {
66        mPhoneAccount = phoneAccount;
67        mState = state;
68        mConnectionCapabilities = capabilities;
69        mAddress = address;
70        mAddressPresentation = addressPresentation;
71        mCallerDisplayName = callerDisplayName;
72        mCallerDisplayNamePresentation = callerDisplayNamePresentation;
73        mVideoProvider = videoProvider;
74        mVideoState = videoState;
75        mRingbackRequested = ringbackRequested;
76        mIsVoipAudioMode = isVoipAudioMode;
77        mStatusHints = statusHints;
78        mDisconnectCause = disconnectCause;
79        this.mConferenceableConnectionIds = conferenceableConnectionIds;
80    }
81
82    public PhoneAccountHandle getPhoneAccount() {
83        return mPhoneAccount;
84    }
85
86    public int getState() {
87        return mState;
88    }
89
90    // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
91    public int getConnectionCapabilities() {
92        return mConnectionCapabilities;
93    }
94
95    public Uri getHandle() {
96        return mAddress;
97    }
98
99    public int getHandlePresentation() {
100        return mAddressPresentation;
101    }
102
103    public String getCallerDisplayName() {
104        return mCallerDisplayName;
105    }
106
107    public int getCallerDisplayNamePresentation() {
108        return mCallerDisplayNamePresentation;
109    }
110
111    public IVideoProvider getVideoProvider() {
112        return mVideoProvider;
113    }
114
115    public int getVideoState() {
116        return mVideoState;
117    }
118
119    public boolean isRingbackRequested() {
120        return mRingbackRequested;
121    }
122
123    public boolean getIsVoipAudioMode() {
124        return mIsVoipAudioMode;
125    }
126
127    public final StatusHints getStatusHints() {
128        return mStatusHints;
129    }
130
131    public final DisconnectCause getDisconnectCause() {
132        return mDisconnectCause;
133    }
134
135    public final List<String> getConferenceableConnectionIds() {
136        return mConferenceableConnectionIds;
137    }
138
139    @Override
140    public String toString() {
141        return new StringBuilder()
142                .append("ParcelableConnection [act:")
143                .append(mPhoneAccount)
144                .append(", state:")
145                .append(mState)
146                .append(", capabilities:")
147                .append(Connection.capabilitiesToString(mConnectionCapabilities))
148                .toString();
149    }
150
151    public static final Parcelable.Creator<ParcelableConnection> CREATOR =
152            new Parcelable.Creator<ParcelableConnection> () {
153        @Override
154        public ParcelableConnection createFromParcel(Parcel source) {
155            ClassLoader classLoader = ParcelableConnection.class.getClassLoader();
156
157            PhoneAccountHandle phoneAccount = source.readParcelable(classLoader);
158            int state = source.readInt();
159            int capabilities = source.readInt();
160            Uri address = source.readParcelable(classLoader);
161            int addressPresentation = source.readInt();
162            String callerDisplayName = source.readString();
163            int callerDisplayNamePresentation = source.readInt();
164            IVideoProvider videoCallProvider =
165                    IVideoProvider.Stub.asInterface(source.readStrongBinder());
166            int videoState = source.readInt();
167            boolean ringbackRequested = source.readByte() == 1;
168            boolean audioModeIsVoip = source.readByte() == 1;
169            StatusHints statusHints = source.readParcelable(classLoader);
170            DisconnectCause disconnectCause = source.readParcelable(classLoader);
171            List<String> conferenceableConnectionIds = new ArrayList<>();
172            source.readStringList(conferenceableConnectionIds);
173
174            return new ParcelableConnection(
175                    phoneAccount,
176                    state,
177                    capabilities,
178                    address,
179                    addressPresentation,
180                    callerDisplayName,
181                    callerDisplayNamePresentation,
182                    videoCallProvider,
183                    videoState,
184                    ringbackRequested,
185                    audioModeIsVoip,
186                    statusHints,
187                    disconnectCause,
188                    conferenceableConnectionIds);
189        }
190
191        @Override
192        public ParcelableConnection[] newArray(int size) {
193            return new ParcelableConnection[size];
194        }
195    };
196
197    /** {@inheritDoc} */
198    @Override
199    public int describeContents() {
200        return 0;
201    }
202
203    /** Writes ParcelableConnection object into a Parcel. */
204    @Override
205    public void writeToParcel(Parcel destination, int flags) {
206        destination.writeParcelable(mPhoneAccount, 0);
207        destination.writeInt(mState);
208        destination.writeInt(mConnectionCapabilities);
209        destination.writeParcelable(mAddress, 0);
210        destination.writeInt(mAddressPresentation);
211        destination.writeString(mCallerDisplayName);
212        destination.writeInt(mCallerDisplayNamePresentation);
213        destination.writeStrongBinder(
214                mVideoProvider != null ? mVideoProvider.asBinder() : null);
215        destination.writeInt(mVideoState);
216        destination.writeByte((byte) (mRingbackRequested ? 1 : 0));
217        destination.writeByte((byte) (mIsVoipAudioMode ? 1 : 0));
218        destination.writeParcelable(mStatusHints, 0);
219        destination.writeParcelable(mDisconnectCause, 0);
220        destination.writeStringList(mConferenceableConnectionIds);
221    }
222}
223