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.net.Uri;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 import android.text.TextUtils;
     23 
     24 /**
     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:
     32  * <ol>
     33  * <li> Call the appropriate gateway address.
     34  * <li> Display information about how the call is being routed to the user.
     35  * </ol>
     36  */
     37 public class GatewayInfo implements Parcelable {
     38 
     39     private final String mGatewayProviderPackageName;
     40     private final Uri mGatewayAddress;
     41     private final Uri mOriginalAddress;
     42 
     43     public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) {
     44         mGatewayProviderPackageName = packageName;
     45         mGatewayAddress = gatewayUri;
     46         mOriginalAddress = originalAddress;
     47     }
     48 
     49     /**
     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.
     53      */
     54     public String getGatewayProviderPackageName() {
     55         return mGatewayProviderPackageName;
     56     }
     57 
     58     /**
     59      * Returns the gateway address to dial when placing the call.
     60      */
     61     public Uri getGatewayAddress() {
     62         return mGatewayAddress;
     63     }
     64 
     65     /**
     66      * Returns the address that the user is trying to connect to via the gateway.
     67      */
     68     public Uri getOriginalAddress() {
     69         return mOriginalAddress;
     70     }
     71 
     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      */
     76     public boolean isEmpty() {
     77         return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null;
     78     }
     79 
     80     /**
     81      * The Parcelable interface.
     82      * */
     83     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);
     90             Uri originalAddress = Uri.CREATOR.createFromParcel(source);
     91             return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress);
     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);
    114         mGatewayAddress.writeToParcel(destination, 0);
    115         mOriginalAddress.writeToParcel(destination, 0);
    116     }
    117 }
    118