blob: 5b8e4ab3d533735e2544e4973dd5445f833f128b [file] [log] [blame]
Yorke Lee93fb1d02014-03-19 11:47:02 -07001/*
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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Yorke Lee93fb1d02014-03-19 11:47:02 -070018
Nancy Chen9d568c02014-09-08 14:17:59 -070019import android.annotation.SystemApi;
Yorke Lee93fb1d02014-03-19 11:47:02 -070020import android.net.Uri;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.text.TextUtils;
24
25/**
Santos Cordon17424132014-10-29 10:38:40 -070026 * Encapsulated gateway address information for outgoing call. When calls are made, the system
27 * provides a facility to specify two addresses for the call: one to display as the address being
28 * dialed and a separate (gateway) address to actually dial. Telecom provides this information to
29 * {@link ConnectionService}s when placing the call as an instance of {@code GatewayInfo}.
30 * <p>
31 * The data consists of an address to call, an address to display and the package name of the
32 * service. This data is used in two ways:
Yorke Lee93fb1d02014-03-19 11:47:02 -070033 * <ol>
Santos Cordon17424132014-10-29 10:38:40 -070034 * <li> Call the appropriate gateway address.
35 * <li> Display information about how the call is being routed to the user.
Yorke Lee93fb1d02014-03-19 11:47:02 -070036 * </ol>
Evan Charlton0e094d92014-11-08 15:49:16 -080037 * @hide
Yorke Lee93fb1d02014-03-19 11:47:02 -070038 */
Evan Charlton0e094d92014-11-08 15:49:16 -080039@SystemApi
Yorke Lee93fb1d02014-03-19 11:47:02 -070040public class GatewayInfo implements Parcelable {
41
42 private final String mGatewayProviderPackageName;
Nancy Chen9d568c02014-09-08 14:17:59 -070043 private final Uri mGatewayAddress;
44 private final Uri mOriginalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070045
46 /** @hide */
Nancy Chen9d568c02014-09-08 14:17:59 -070047 @SystemApi
48 public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) {
Yorke Lee93fb1d02014-03-19 11:47:02 -070049 mGatewayProviderPackageName = packageName;
Nancy Chen9d568c02014-09-08 14:17:59 -070050 mGatewayAddress = gatewayUri;
51 mOriginalAddress = originalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070052 }
53
54 /**
Santos Cordon17424132014-10-29 10:38:40 -070055 * Package name of the gateway provider service that provided the gateway information.
56 * This can be used to identify the gateway address source and to load an appropriate icon when
57 * displaying gateway information in the in-call UI.
Yorke Lee93fb1d02014-03-19 11:47:02 -070058 */
59 public String getGatewayProviderPackageName() {
60 return mGatewayProviderPackageName;
61 }
62
63 /**
Santos Cordon17424132014-10-29 10:38:40 -070064 * Returns the gateway address to dial when placing the call.
Yorke Lee93fb1d02014-03-19 11:47:02 -070065 */
Nancy Chen9d568c02014-09-08 14:17:59 -070066 public Uri getGatewayAddress() {
67 return mGatewayAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070068 }
69
70 /**
Santos Cordon17424132014-10-29 10:38:40 -070071 * Returns the address that the user is trying to connect to via the gateway.
Yorke Lee93fb1d02014-03-19 11:47:02 -070072 */
Nancy Chen9d568c02014-09-08 14:17:59 -070073 public Uri getOriginalAddress() {
74 return mOriginalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070075 }
76
Santos Cordon17424132014-10-29 10:38:40 -070077 /**
78 * Indicates whether this {@code GatewayInfo} instance contains any data. A returned value of
79 * false indicates that no gateway number is being used for the call.
80 */
Yorke Lee93fb1d02014-03-19 11:47:02 -070081 public boolean isEmpty() {
Nancy Chen9d568c02014-09-08 14:17:59 -070082 return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null;
Yorke Lee93fb1d02014-03-19 11:47:02 -070083 }
84
Santos Cordon17424132014-10-29 10:38:40 -070085 /**
86 * The Parcelable interface.
87 * */
Yorke Lee93fb1d02014-03-19 11:47:02 -070088 public static final Parcelable.Creator<GatewayInfo> CREATOR =
89 new Parcelable.Creator<GatewayInfo> () {
90
91 @Override
92 public GatewayInfo createFromParcel(Parcel source) {
93 String gatewayPackageName = source.readString();
94 Uri gatewayUri = Uri.CREATOR.createFromParcel(source);
Nancy Chen9d568c02014-09-08 14:17:59 -070095 Uri originalAddress = Uri.CREATOR.createFromParcel(source);
96 return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress);
Yorke Lee93fb1d02014-03-19 11:47:02 -070097 }
98
99 @Override
100 public GatewayInfo[] newArray(int size) {
101 return new GatewayInfo[size];
102 }
103 };
104
105 /**
106 * {@inheritDoc}
107 */
108 @Override
109 public int describeContents() {
110 return 0;
111 }
112
113 /**
114 * {@inheritDoc}
115 */
116 @Override
117 public void writeToParcel(Parcel destination, int flags) {
118 destination.writeString(mGatewayProviderPackageName);
Nancy Chen9d568c02014-09-08 14:17:59 -0700119 mGatewayAddress.writeToParcel(destination, 0);
120 mOriginalAddress.writeToParcel(destination, 0);
Yorke Lee93fb1d02014-03-19 11:47:02 -0700121 }
122}