Home | History | Annotate | Download | only in telecom
      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 
     17 package android.telecom;
     18 
     19 import android.annotation.SystemApi;
     20 import android.net.Uri;
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 import android.text.TextUtils;
     24 
     25 /**
     26  * 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:
     33  * <ol>
     34  * <li> Call the appropriate gateway address.
     35  * <li> Display information about how the call is being routed to the user.
     36  * </ol>
     37  * @hide
     38  */
     39 @SystemApi
     40 public class GatewayInfo implements Parcelable {
     41 
     42     private final String mGatewayProviderPackageName;
     43     private final Uri mGatewayAddress;
     44     private final Uri mOriginalAddress;
     45 
     46     /** @hide */
     47     @SystemApi
     48     public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) {
     49         mGatewayProviderPackageName = packageName;
     50         mGatewayAddress = gatewayUri;
     51         mOriginalAddress = originalAddress;
     52     }
     53 
     54     /**
     55      * 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.
     58      */
     59     public String getGatewayProviderPackageName() {
     60         return mGatewayProviderPackageName;
     61     }
     62 
     63     /**
     64      * Returns the gateway address to dial when placing the call.
     65      */
     66     public Uri getGatewayAddress() {
     67         return mGatewayAddress;
     68     }
     69 
     70     /**
     71      * Returns the address that the user is trying to connect to via the gateway.
     72      */
     73     public Uri getOriginalAddress() {
     74         return mOriginalAddress;
     75     }
     76 
     77     /**
     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      */
     81     public boolean isEmpty() {
     82         return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null;
     83     }
     84 
     85     /**
     86      * The Parcelable interface.
     87      * */
     88     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);
     95             Uri originalAddress = Uri.CREATOR.createFromParcel(source);
     96             return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress);
     97         }
     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);
    119         mGatewayAddress.writeToParcel(destination, 0);
    120         mOriginalAddress.writeToParcel(destination, 0);
    121     }
    122 }
    123