ConnectionRequest.java revision 1cf9b6bec12c027a0d551540a6e01f3ac2d0a9d4
1/*
2 * Copyright (C) 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
24/**
25 * Simple data container encapsulating a request to some entity to
26 * create a new {@link Connection}.
27 */
28public final class ConnectionRequest implements Parcelable {
29
30    // TODO: Token to limit recursive invocations
31    private final PhoneAccountHandle mAccountHandle;
32    private final Uri mAddress;
33    private final Bundle mExtras;
34    private final int mVideoState;
35
36    /**
37     * @param accountHandle The accountHandle which should be used to place the call.
38     * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
39     * @param extras Application-specific extra data.
40     */
41    public ConnectionRequest(
42            PhoneAccountHandle accountHandle,
43            Uri handle,
44            Bundle extras) {
45        this(accountHandle, handle, extras, VideoProfile.VideoState.AUDIO_ONLY);
46    }
47
48    /**
49     * @param accountHandle The accountHandle which should be used to place the call.
50     * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
51     * @param extras Application-specific extra data.
52     * @param videoState Determines the video state for the connection.
53     * @hide
54     */
55    public ConnectionRequest(
56            PhoneAccountHandle accountHandle,
57            Uri handle,
58            Bundle extras,
59            int videoState) {
60        mAccountHandle = accountHandle;
61        mAddress = handle;
62        mExtras = extras;
63        mVideoState = videoState;
64    }
65
66    private ConnectionRequest(Parcel in) {
67        mAccountHandle = in.readParcelable(getClass().getClassLoader());
68        mAddress = in.readParcelable(getClass().getClassLoader());
69        mExtras = in.readParcelable(getClass().getClassLoader());
70        mVideoState = in.readInt();
71    }
72
73    /**
74     * The account which should be used to place the call.
75     */
76    public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
77
78    /**
79     * The handle (e.g., phone number) to which the {@link Connection} is to connect.
80     */
81    public Uri getAddress() { return mAddress; }
82
83    /**
84     * Application-specific extra data. Used for passing back information from an incoming
85     * call {@code Intent}, and for any proprietary extensions arranged between a client
86     * and servant {@code ConnectionService} which agree on a vocabulary for such data.
87     */
88    public Bundle getExtras() { return mExtras; }
89
90    /**
91     * Describes the video states supported by the client requesting the connection.
92     * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
93     * {@link VideoProfile.VideoState#BIDIRECTIONAL},
94     * {@link VideoProfile.VideoState#TX_ENABLED},
95     * {@link VideoProfile.VideoState#RX_ENABLED}.
96     *
97     * @return The video state for the connection.
98     * @hide
99     */
100    public int getVideoState() {
101        return mVideoState;
102    }
103
104    @Override
105    public String toString() {
106        return String.format("ConnectionRequest %s %s",
107                mAddress == null
108                        ? Uri.EMPTY
109                        : Connection.toLogSafePhoneNumber(mAddress.toString()),
110                mExtras == null ? "" : mExtras);
111    }
112
113    public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
114        @Override
115        public ConnectionRequest createFromParcel(Parcel source) {
116            return new ConnectionRequest(source);
117        }
118
119        @Override
120        public ConnectionRequest[] newArray(int size) {
121            return new ConnectionRequest[size];
122        }
123    };
124
125    /**
126     * {@inheritDoc}
127     */
128    @Override
129    public int describeContents() {
130        return 0;
131    }
132
133    @Override
134    public void writeToParcel(Parcel destination, int flags) {
135        destination.writeParcelable(mAccountHandle, 0);
136        destination.writeParcelable(mAddress, 0);
137        destination.writeParcelable(mExtras, 0);
138        destination.writeInt(mVideoState);
139    }
140}
141