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  * When calls are made, they may contain gateway information for services which route phone calls
     27  * through their own service/numbers. The data consists of a number to call and the package name of
     28  * the service. This data is used in two ways:
     29  * <ol>
     30  * <li> Call the appropriate routing number
     31  * <li> Display information about how the call is being routed to the user
     32  * </ol>
     33  * @hide
     34  */
     35 @SystemApi
     36 public class GatewayInfo implements Parcelable {
     37 
     38     private final String mGatewayProviderPackageName;
     39     private final Uri mGatewayAddress;
     40     private final Uri mOriginalAddress;
     41 
     42     /** @hide */
     43     @SystemApi
     44     public GatewayInfo(String packageName, Uri gatewayUri, Uri originalAddress) {
     45         mGatewayProviderPackageName = packageName;
     46         mGatewayAddress = gatewayUri;
     47         mOriginalAddress = originalAddress;
     48     }
     49 
     50     /**
     51      * Package name of the gateway provider service. used to place the call with.
     52      */
     53     public String getGatewayProviderPackageName() {
     54         return mGatewayProviderPackageName;
     55     }
     56 
     57     /**
     58      * Gateway provider address to use when actually placing the call.
     59      */
     60     public Uri getGatewayAddress() {
     61         return mGatewayAddress;
     62     }
     63 
     64     /**
     65      * The actual call address that the user is trying to connect to via the gateway.
     66      */
     67     public Uri getOriginalAddress() {
     68         return mOriginalAddress;
     69     }
     70 
     71     public boolean isEmpty() {
     72         return TextUtils.isEmpty(mGatewayProviderPackageName) || mGatewayAddress == null;
     73     }
     74 
     75     /** Implement the Parcelable interface */
     76     public static final Parcelable.Creator<GatewayInfo> CREATOR =
     77             new Parcelable.Creator<GatewayInfo> () {
     78 
     79         @Override
     80         public GatewayInfo createFromParcel(Parcel source) {
     81             String gatewayPackageName = source.readString();
     82             Uri gatewayUri = Uri.CREATOR.createFromParcel(source);
     83             Uri originalAddress = Uri.CREATOR.createFromParcel(source);
     84             return new GatewayInfo(gatewayPackageName, gatewayUri, originalAddress);
     85         }
     86 
     87         @Override
     88         public GatewayInfo[] newArray(int size) {
     89             return new GatewayInfo[size];
     90         }
     91     };
     92 
     93     /**
     94      * {@inheritDoc}
     95      */
     96     @Override
     97     public int describeContents() {
     98         return 0;
     99     }
    100 
    101     /**
    102      * {@inheritDoc}
    103      */
    104     @Override
    105     public void writeToParcel(Parcel destination, int flags) {
    106         destination.writeString(mGatewayProviderPackageName);
    107         mGatewayAddress.writeToParcel(destination, 0);
    108         mOriginalAddress.writeToParcel(destination, 0);
    109     }
    110 }
    111