| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 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 |  | 
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 18 |  | 
|  | 19 | import android.net.Uri; | 
|  | 20 | import android.os.Parcel; | 
|  | 21 | import android.os.Parcelable; | 
|  | 22 | import android.text.TextUtils; | 
|  | 23 |  | 
|  | 24 | /** | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 25 | * 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 Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 32 | * <ol> | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 33 | * <li> Call the appropriate gateway address. | 
|  | 34 | * <li> Display information about how the call is being routed to the user. | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 35 | * </ol> | 
|  | 36 | */ | 
|  | 37 | public class GatewayInfo implements Parcelable { | 
|  | 38 |  | 
|  | 39 | private final String mGatewayProviderPackageName; | 
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 40 | private final Uri mGatewayAddress; | 
|  | 41 | private final Uri mOriginalAddress; | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 42 |  | 
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 43 | public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) { | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 44 | mGatewayProviderPackageName = packageName; | 
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 45 | mGatewayAddress = gatewayUri; | 
|  | 46 | mOriginalAddress = originalAddress; | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
|  | 49 | /** | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 50 | * 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 Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 53 | */ | 
|  | 54 | public String getGatewayProviderPackageName() { | 
|  | 55 | return mGatewayProviderPackageName; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | /** | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 59 | * Returns the gateway address to dial when placing the call. | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 60 | */ | 
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 61 | public Uri getGatewayAddress() { | 
|  | 62 | return mGatewayAddress; | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
|  | 65 | /** | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 66 | * Returns the address that the user is trying to connect to via the gateway. | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 67 | */ | 
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 68 | public Uri getOriginalAddress() { | 
|  | 69 | return mOriginalAddress; | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 70 | } | 
|  | 71 |  | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 72 | /** | 
|  | 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 Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 76 | public boolean isEmpty() { | 
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 77 | return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null; | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
| Santos Cordon | 1742413 | 2014-10-29 10:38:40 -0700 | [diff] [blame] | 80 | /** | 
|  | 81 | * The Parcelable interface. | 
|  | 82 | * */ | 
| Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 83 | public static final @android.annotation.NonNull Parcelable.Creator<GatewayInfo> CREATOR = | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 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 Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 90 | Uri originalAddress = Uri.CREATOR.createFromParcel(source); | 
|  | 91 | return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress); | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 92 | } | 
|  | 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); | 
| Tyler Gunn | 7c61306 | 2020-04-13 17:19:24 -0700 | [diff] [blame] | 114 | Uri.writeToParcel(destination, mGatewayAddress); | 
|  | 115 | Uri.writeToParcel(destination, mOriginalAddress); | 
| Yorke Lee | 93fb1d0 | 2014-03-19 11:47:02 -0700 | [diff] [blame] | 116 | } | 
|  | 117 | } |