blob: 7105602a0bbadfc510d72a727dc984ff4741dfa4 [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>
37 */
38public class GatewayInfo implements Parcelable {
39
40 private final String mGatewayProviderPackageName;
Nancy Chen9d568c02014-09-08 14:17:59 -070041 private final Uri mGatewayAddress;
42 private final Uri mOriginalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070043
44 /** @hide */
Nancy Chen9d568c02014-09-08 14:17:59 -070045 @SystemApi
46 public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) {
Yorke Lee93fb1d02014-03-19 11:47:02 -070047 mGatewayProviderPackageName = packageName;
Nancy Chen9d568c02014-09-08 14:17:59 -070048 mGatewayAddress = gatewayUri;
49 mOriginalAddress = originalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070050 }
51
52 /**
Santos Cordon17424132014-10-29 10:38:40 -070053 * Package name of the gateway provider service that provided the gateway information.
54 * This can be used to identify the gateway address source and to load an appropriate icon when
55 * displaying gateway information in the in-call UI.
Yorke Lee93fb1d02014-03-19 11:47:02 -070056 */
57 public String getGatewayProviderPackageName() {
58 return mGatewayProviderPackageName;
59 }
60
61 /**
Santos Cordon17424132014-10-29 10:38:40 -070062 * Returns the gateway address to dial when placing the call.
Yorke Lee93fb1d02014-03-19 11:47:02 -070063 */
Nancy Chen9d568c02014-09-08 14:17:59 -070064 public Uri getGatewayAddress() {
65 return mGatewayAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070066 }
67
68 /**
Santos Cordon17424132014-10-29 10:38:40 -070069 * Returns the address that the user is trying to connect to via the gateway.
Yorke Lee93fb1d02014-03-19 11:47:02 -070070 */
Nancy Chen9d568c02014-09-08 14:17:59 -070071 public Uri getOriginalAddress() {
72 return mOriginalAddress;
Yorke Lee93fb1d02014-03-19 11:47:02 -070073 }
74
Santos Cordon17424132014-10-29 10:38:40 -070075 /**
76 * Indicates whether this {@code GatewayInfo} instance contains any data. A returned value of
77 * false indicates that no gateway number is being used for the call.
78 */
Yorke Lee93fb1d02014-03-19 11:47:02 -070079 public boolean isEmpty() {
Nancy Chen9d568c02014-09-08 14:17:59 -070080 return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null;
Yorke Lee93fb1d02014-03-19 11:47:02 -070081 }
82
Santos Cordon17424132014-10-29 10:38:40 -070083 /**
84 * The Parcelable interface.
85 * */
Yorke Lee93fb1d02014-03-19 11:47:02 -070086 public static final Parcelable.Creator<GatewayInfo> CREATOR =
87 new Parcelable.Creator<GatewayInfo> () {
88
89 @Override
90 public GatewayInfo createFromParcel(Parcel source) {
91 String gatewayPackageName = source.readString();
92 Uri gatewayUri = Uri.CREATOR.createFromParcel(source);
Nancy Chen9d568c02014-09-08 14:17:59 -070093 Uri originalAddress = Uri.CREATOR.createFromParcel(source);
94 return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress);
Yorke Lee93fb1d02014-03-19 11:47:02 -070095 }
96
97 @Override
98 public GatewayInfo[] newArray(int size) {
99 return new GatewayInfo[size];
100 }
101 };
102
103 /**
104 * {@inheritDoc}
105 */
106 @Override
107 public int describeContents() {
108 return 0;
109 }
110
111 /**
112 * {@inheritDoc}
113 */
114 @Override
115 public void writeToParcel(Parcel destination, int flags) {
116 destination.writeString(mGatewayProviderPackageName);
Nancy Chen9d568c02014-09-08 14:17:59 -0700117 mGatewayAddress.writeToParcel(destination, 0);
118 mOriginalAddress.writeToParcel(destination, 0);
Yorke Lee93fb1d02014-03-19 11:47:02 -0700119 }
120}