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.Bundle;
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 
     24 import com.android.internal.telecom.IVideoProvider;
     25 
     26 import java.util.ArrayList;
     27 import java.util.List;
     28 
     29 /**
     30  * Information about a connection that is used between Telecom and the ConnectionService.
     31  * This is used to send initial Connection information to Telecom when the connection is
     32  * first created.
     33  * @hide
     34  */
     35 public final class ParcelableConnection implements Parcelable {
     36     private final PhoneAccountHandle mPhoneAccount;
     37     private final int mState;
     38     private final int mConnectionCapabilities;
     39     private final Uri mAddress;
     40     private final int mAddressPresentation;
     41     private final String mCallerDisplayName;
     42     private final int mCallerDisplayNamePresentation;
     43     private final IVideoProvider mVideoProvider;
     44     private final int mVideoState;
     45     private final boolean mRingbackRequested;
     46     private final boolean mIsVoipAudioMode;
     47     private final long mConnectTimeMillis;
     48     private final StatusHints mStatusHints;
     49     private final DisconnectCause mDisconnectCause;
     50     private final List<String> mConferenceableConnectionIds;
     51     private final Bundle mExtras;
     52 
     53     /** @hide */
     54     public ParcelableConnection(
     55             PhoneAccountHandle phoneAccount,
     56             int state,
     57             int capabilities,
     58             Uri address,
     59             int addressPresentation,
     60             String callerDisplayName,
     61             int callerDisplayNamePresentation,
     62             IVideoProvider videoProvider,
     63             int videoState,
     64             boolean ringbackRequested,
     65             boolean isVoipAudioMode,
     66             long connectTimeMillis,
     67             StatusHints statusHints,
     68             DisconnectCause disconnectCause,
     69             List<String> conferenceableConnectionIds,
     70             Bundle extras) {
     71         mPhoneAccount = phoneAccount;
     72         mState = state;
     73         mConnectionCapabilities = capabilities;
     74         mAddress = address;
     75         mAddressPresentation = addressPresentation;
     76         mCallerDisplayName = callerDisplayName;
     77         mCallerDisplayNamePresentation = callerDisplayNamePresentation;
     78         mVideoProvider = videoProvider;
     79         mVideoState = videoState;
     80         mRingbackRequested = ringbackRequested;
     81         mIsVoipAudioMode = isVoipAudioMode;
     82         mConnectTimeMillis = connectTimeMillis;
     83         mStatusHints = statusHints;
     84         mDisconnectCause = disconnectCause;
     85         mConferenceableConnectionIds = conferenceableConnectionIds;
     86         mExtras = extras;
     87     }
     88 
     89     public PhoneAccountHandle getPhoneAccount() {
     90         return mPhoneAccount;
     91     }
     92 
     93     public int getState() {
     94         return mState;
     95     }
     96 
     97     // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
     98     public int getConnectionCapabilities() {
     99         return mConnectionCapabilities;
    100     }
    101 
    102     public Uri getHandle() {
    103         return mAddress;
    104     }
    105 
    106     public int getHandlePresentation() {
    107         return mAddressPresentation;
    108     }
    109 
    110     public String getCallerDisplayName() {
    111         return mCallerDisplayName;
    112     }
    113 
    114     public int getCallerDisplayNamePresentation() {
    115         return mCallerDisplayNamePresentation;
    116     }
    117 
    118     public IVideoProvider getVideoProvider() {
    119         return mVideoProvider;
    120     }
    121 
    122     public int getVideoState() {
    123         return mVideoState;
    124     }
    125 
    126     public boolean isRingbackRequested() {
    127         return mRingbackRequested;
    128     }
    129 
    130     public boolean getIsVoipAudioMode() {
    131         return mIsVoipAudioMode;
    132     }
    133 
    134     public long getConnectTimeMillis() {
    135         return mConnectTimeMillis;
    136     }
    137 
    138     public final StatusHints getStatusHints() {
    139         return mStatusHints;
    140     }
    141 
    142     public final DisconnectCause getDisconnectCause() {
    143         return mDisconnectCause;
    144     }
    145 
    146     public final List<String> getConferenceableConnectionIds() {
    147         return mConferenceableConnectionIds;
    148     }
    149 
    150     public final Bundle getExtras() {
    151         return mExtras;
    152     }
    153 
    154     @Override
    155     public String toString() {
    156         return new StringBuilder()
    157                 .append("ParcelableConnection [act:")
    158                 .append(mPhoneAccount)
    159                 .append("], state:")
    160                 .append(mState)
    161                 .append(", capabilities:")
    162                 .append(Connection.capabilitiesToString(mConnectionCapabilities))
    163                 .append(", extras:")
    164                 .append(mExtras)
    165                 .toString();
    166     }
    167 
    168     public static final Parcelable.Creator<ParcelableConnection> CREATOR =
    169             new Parcelable.Creator<ParcelableConnection> () {
    170         @Override
    171         public ParcelableConnection createFromParcel(Parcel source) {
    172             ClassLoader classLoader = ParcelableConnection.class.getClassLoader();
    173 
    174             PhoneAccountHandle phoneAccount = source.readParcelable(classLoader);
    175             int state = source.readInt();
    176             int capabilities = source.readInt();
    177             Uri address = source.readParcelable(classLoader);
    178             int addressPresentation = source.readInt();
    179             String callerDisplayName = source.readString();
    180             int callerDisplayNamePresentation = source.readInt();
    181             IVideoProvider videoCallProvider =
    182                     IVideoProvider.Stub.asInterface(source.readStrongBinder());
    183             int videoState = source.readInt();
    184             boolean ringbackRequested = source.readByte() == 1;
    185             boolean audioModeIsVoip = source.readByte() == 1;
    186             long connectTimeMillis = source.readLong();
    187             StatusHints statusHints = source.readParcelable(classLoader);
    188             DisconnectCause disconnectCause = source.readParcelable(classLoader);
    189             List<String> conferenceableConnectionIds = new ArrayList<>();
    190             source.readStringList(conferenceableConnectionIds);
    191             Bundle extras = source.readBundle(classLoader);
    192 
    193             return new ParcelableConnection(
    194                     phoneAccount,
    195                     state,
    196                     capabilities,
    197                     address,
    198                     addressPresentation,
    199                     callerDisplayName,
    200                     callerDisplayNamePresentation,
    201                     videoCallProvider,
    202                     videoState,
    203                     ringbackRequested,
    204                     audioModeIsVoip,
    205                     connectTimeMillis,
    206                     statusHints,
    207                     disconnectCause,
    208                     conferenceableConnectionIds,
    209                     extras);
    210         }
    211 
    212         @Override
    213         public ParcelableConnection[] newArray(int size) {
    214             return new ParcelableConnection[size];
    215         }
    216     };
    217 
    218     /** {@inheritDoc} */
    219     @Override
    220     public int describeContents() {
    221         return 0;
    222     }
    223 
    224     /** Writes ParcelableConnection object into a Parcel. */
    225     @Override
    226     public void writeToParcel(Parcel destination, int flags) {
    227         destination.writeParcelable(mPhoneAccount, 0);
    228         destination.writeInt(mState);
    229         destination.writeInt(mConnectionCapabilities);
    230         destination.writeParcelable(mAddress, 0);
    231         destination.writeInt(mAddressPresentation);
    232         destination.writeString(mCallerDisplayName);
    233         destination.writeInt(mCallerDisplayNamePresentation);
    234         destination.writeStrongBinder(
    235                 mVideoProvider != null ? mVideoProvider.asBinder() : null);
    236         destination.writeInt(mVideoState);
    237         destination.writeByte((byte) (mRingbackRequested ? 1 : 0));
    238         destination.writeByte((byte) (mIsVoipAudioMode ? 1 : 0));
    239         destination.writeLong(mConnectTimeMillis);
    240         destination.writeParcelable(mStatusHints, 0);
    241         destination.writeParcelable(mDisconnectCause, 0);
    242         destination.writeStringList(mConferenceableConnectionIds);
    243         destination.writeBundle(mExtras);
    244     }
    245 }
    246