blob: 928570e2ec6929cf5e3a3b9198d155fde38970f9 [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
19import android.net.Uri;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.text.TextUtils;
23
24/**
Santos Cordon17424132014-10-29 10:38:40 -070025 * Encapsulated gateway address information for outgoing call. When calls are made, the system
26 * provides a facility to specify two addresses for the call: one to display as the address being
27 * dialed and a separate (gateway) address to actually dial. Telecom provides this information to
28 * {@link ConnectionService}s when placing the call as an instance of {@code GatewayInfo}.
29 * <p>
30 * The data consists of an address to call, an address to display and the package name of the
31 * service. This data is used in two ways:
Yorke Lee93fb1d02014-03-19 11:47:02 -070032 * <ol>
Santos Cordon17424132014-10-29 10:38:40 -070033 * <li> Call the appropriate gateway address.
34 * <li> Display information about how the call is being routed to the user.
Yorke Lee93fb1d02014-03-19 11:47:02 -070035 * </ol>
36 */
37public class GatewayInfo implements Parcelable {
38
39 private final String mGatewayProviderPackageName;
Nancy Chen9d568c02014-09-08 14:17:59 -070040 private final Uri mGatewayAddress;
41 private final Uri mOriginalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070042
Nancy Chen9d568c02014-09-08 14:17:59 -070043 public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) {
Yorke Lee93fb1d02014-03-19 11:47:02 -070044 mGatewayProviderPackageName = packageName;
Nancy Chen9d568c02014-09-08 14:17:59 -070045 mGatewayAddress = gatewayUri;
46 mOriginalAddress = originalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070047 }
48
49 /**
Santos Cordon17424132014-10-29 10:38:40 -070050 * Package name of the gateway provider service that provided the gateway information.
51 * This can be used to identify the gateway address source and to load an appropriate icon when
52 * displaying gateway information in the in-call UI.
Yorke Lee93fb1d02014-03-19 11:47:02 -070053 */
54 public String getGatewayProviderPackageName() {
55 return mGatewayProviderPackageName;
56 }
57
58 /**
Santos Cordon17424132014-10-29 10:38:40 -070059 * Returns the gateway address to dial when placing the call.
Yorke Lee93fb1d02014-03-19 11:47:02 -070060 */
Nancy Chen9d568c02014-09-08 14:17:59 -070061 public Uri getGatewayAddress() {
62 return mGatewayAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070063 }
64
65 /**
Santos Cordon17424132014-10-29 10:38:40 -070066 * Returns the address that the user is trying to connect to via the gateway.
Yorke Lee93fb1d02014-03-19 11:47:02 -070067 */
Nancy Chen9d568c02014-09-08 14:17:59 -070068 public Uri getOriginalAddress() {
69 return mOriginalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070070 }
71
Santos Cordon17424132014-10-29 10:38:40 -070072 /**
73 * Indicates whether this {@code GatewayInfo} instance contains any data. A returned value of
74 * false indicates that no gateway number is being used for the call.
75 */
Yorke Lee93fb1d02014-03-19 11:47:02 -070076 public boolean isEmpty() {
Nancy Chen9d568c02014-09-08 14:17:59 -070077 return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null;
Yorke Lee93fb1d02014-03-19 11:47:02 -070078 }
79
Santos Cordon17424132014-10-29 10:38:40 -070080 /**
81 * The Parcelable interface.
82 * */
Yorke Lee93fb1d02014-03-19 11:47:02 -070083 public static final Parcelable.Creator<GatewayInfo> CREATOR =
84 new Parcelable.Creator<GatewayInfo> () {
85
86 @Override
87 public GatewayInfo createFromParcel(Parcel source) {
88 String gatewayPackageName = source.readString();
89 Uri gatewayUri = Uri.CREATOR.createFromParcel(source);
Nancy Chen9d568c02014-09-08 14:17:59 -070090 Uri originalAddress = Uri.CREATOR.createFromParcel(source);
91 return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress);
Yorke Lee93fb1d02014-03-19 11:47:02 -070092 }
93
94 @Override
95 public GatewayInfo[] newArray(int size) {
96 return new GatewayInfo[size];
97 }
98 };
99
100 /**
101 * {@inheritDoc}
102 */
103 @Override
104 public int describeContents() {
105 return 0;
106 }
107
108 /**
109 * {@inheritDoc}
110 */
111 @Override
112 public void writeToParcel(Parcel destination, int flags) {
113 destination.writeString(mGatewayProviderPackageName);
Nancy Chen9d568c02014-09-08 14:17:59 -0700114 mGatewayAddress.writeToParcel(destination, 0);
115 mOriginalAddress.writeToParcel(destination, 0);
Yorke Lee93fb1d02014-03-19 11:47:02 -0700116 }
117}