Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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.telecomm; |
| 18 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 19 | import com.android.internal.telecomm.IConnectionService; |
| 20 | |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 21 | import android.app.PendingIntent; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 23 | import android.os.RemoteException; |
| 24 | import android.telephony.DisconnectCause; |
| 25 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 26 | import java.util.ArrayList; |
Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame^] | 27 | import java.util.Collections; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 28 | import java.util.HashSet; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 29 | import java.util.List; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 30 | import java.util.Set; |
Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame^] | 31 | import java.util.concurrent.ConcurrentHashMap; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 34 | * A connection provided to a {@link ConnectionService} by another {@code ConnectionService} |
| 35 | * running in a different process. |
| 36 | * |
| 37 | * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest) |
| 38 | * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest) |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 39 | */ |
| 40 | public final class RemoteConnection { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 41 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 42 | public static abstract class Listener { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Invoked when the state of this {@code RemoteConnection} has changed. See |
| 45 | * {@link #getState()}. |
| 46 | * |
| 47 | * @param connection The {@code RemoteConnection} invoking this method. |
| 48 | * @param state The new state of the {@code RemoteConnection}. |
| 49 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 50 | public void onStateChanged(RemoteConnection connection, int state) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Invoked when the parent of this {@code RemoteConnection} has changed. See |
| 54 | * {@link #getParent()}. |
| 55 | * |
| 56 | * @param connection The {@code RemoteConnection} invoking this method. |
| 57 | * @param parent The new parent of the {@code RemoteConnection}. |
| 58 | */ |
| 59 | public void onParentChanged(RemoteConnection connection, RemoteConnection parent) {} |
| 60 | |
| 61 | /** |
| 62 | * Invoked when the children of this {@code RemoteConnection} have changed. See |
| 63 | * {@link #getChildren()}. |
| 64 | * |
| 65 | * @param connection The {@code RemoteConnection} invoking this method. |
| 66 | * @param children The new children of the {@code RemoteConnection}. |
| 67 | */ |
| 68 | public void onChildrenChanged( |
| 69 | RemoteConnection connection, List<RemoteConnection> children) {} |
| 70 | |
| 71 | /** |
| 72 | * Invoked when this {@code RemoteConnection} is disconnected. |
| 73 | * |
| 74 | * @param connection The {@code RemoteConnection} invoking this method. |
| 75 | * @param disconnectCauseCode The failure code ({@see DisconnectCause}) associated with this |
| 76 | * failed connection. |
| 77 | * @param disconnectCauseMessage The reason for the connection failure. This will not be |
| 78 | * displayed to the user. |
| 79 | */ |
| 80 | public void onDisconnected( |
| 81 | RemoteConnection connection, |
| 82 | int disconnectCauseCode, |
| 83 | String disconnectCauseMessage) {} |
| 84 | |
| 85 | /** |
| 86 | * Invoked when this {@code RemoteConnection} is requesting ringback. See |
| 87 | * {@link #isRequestingRingback()}. |
| 88 | * |
| 89 | * @param connection The {@code RemoteConnection} invoking this method. |
| 90 | * @param ringback Whether the {@code RemoteConnection} is requesting ringback. |
| 91 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 92 | public void onRequestingRingback(RemoteConnection connection, boolean ringback) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Indicates that the call capabilities of this {@code RemoteConnection} have changed. |
| 96 | * See {@link #getCallCapabilities()}. |
| 97 | * |
| 98 | * @param connection The {@code RemoteConnection} invoking this method. |
| 99 | * @param callCapabilities The new call capabilities of the {@code RemoteConnection}. |
| 100 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 101 | public void onCallCapabilitiesChanged(RemoteConnection connection, int callCapabilities) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a |
| 105 | * pause character. This causes the post-dial signals to stop pending user confirmation. An |
| 106 | * implementation should present this choice to the user and invoke |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 107 | * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 108 | * |
| 109 | * @param connection The {@code RemoteConnection} invoking this method. |
| 110 | * @param remainingPostDialSequence The post-dial characters that remain to be sent. |
| 111 | */ |
| 112 | public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {} |
| 113 | |
| 114 | /** |
| 115 | * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed. |
| 116 | * See {@link #getAudioModeIsVoip()}. |
| 117 | * |
| 118 | * @param connection The {@code RemoteConnection} invoking this method. |
| 119 | * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP. |
| 120 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 121 | public void onAudioModeIsVoipChanged(RemoteConnection connection, boolean isVoip) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * Indicates that the status hints of this {@code RemoteConnection} have changed. See |
| 125 | * {@link #getStatusHints()} ()}. |
| 126 | * |
| 127 | * @param connection The {@code RemoteConnection} invoking this method. |
| 128 | * @param statusHints The new status hints of the {@code RemoteConnection}. |
| 129 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 130 | public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Indicates that the handle (e.g., phone number) of this {@code RemoteConnection} has |
| 134 | * changed. See {@link #getHandle()} and {@link #getHandlePresentation()}. |
| 135 | * |
| 136 | * @param connection The {@code RemoteConnection} invoking this method. |
| 137 | * @param handle The new handle of the {@code RemoteConnection}. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 138 | * @param presentation The {@link PropertyPresentation} which controls how the |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 139 | * handle is shown. |
| 140 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 141 | public void onHandleChanged(RemoteConnection connection, Uri handle, int presentation) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Indicates that the caller display name of this {@code RemoteConnection} has changed. |
| 145 | * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}. |
| 146 | * |
| 147 | * @param connection The {@code RemoteConnection} invoking this method. |
| 148 | * @param callerDisplayName The new caller display name of the {@code RemoteConnection}. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 149 | * @param presentation The {@link PropertyPresentation} which controls how the |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 150 | * caller display name is shown. |
| 151 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 152 | public void onCallerDisplayNameChanged( |
| 153 | RemoteConnection connection, String callerDisplayName, int presentation) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 154 | |
| 155 | /** |
| 156 | * Indicates that the video state of this {@code RemoteConnection} has changed. |
| 157 | * See {@link #getVideoState()}. |
| 158 | * |
| 159 | * @param connection The {@code RemoteConnection} invoking this method. |
| 160 | * @param videoState The new video state of the {@code RemoteConnection}. |
| 161 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 162 | public void onVideoStateChanged(RemoteConnection connection, int videoState) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Indicates that this {@code RemoteConnection} is requesting that the in-call UI |
| 166 | * launch the specified activity. |
| 167 | * |
| 168 | * @param connection The {@code RemoteConnection} invoking this method. |
| 169 | * @param intent A {@link PendingIntent} that the {@code RemoteConnection} wishes to |
| 170 | * have launched on its behalf. |
| 171 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 172 | public void onStartActivityFromInCall(RemoteConnection connection, PendingIntent intent) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Indicates that this {@code RemoteConnection} has been destroyed. No further requests |
| 176 | * should be made to the {@code RemoteConnection}, and references to it should be cleared. |
| 177 | * |
| 178 | * @param connection The {@code RemoteConnection} invoking this method. |
| 179 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 180 | public void onDestroyed(RemoteConnection connection) {} |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 181 | public void onConferenceableConnectionsChanged( |
| 182 | RemoteConnection connection, List<RemoteConnection> conferenceableConnections) {} |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 185 | private IConnectionService mConnectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 186 | private final String mConnectionId; |
Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame^] | 187 | private final Set<Listener> mListeners = Collections.newSetFromMap( |
| 188 | new ConcurrentHashMap<Listener, Boolean>(2)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 189 | private final Set<RemoteConnection> mConferenceableConnections = new HashSet<>(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 190 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 191 | private int mState = Connection.STATE_NEW; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 192 | private int mDisconnectCauseCode = DisconnectCause.NOT_VALID; |
| 193 | private String mDisconnectCauseMessage; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 194 | private boolean mRequestingRingback; |
| 195 | private boolean mConnected; |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 196 | private int mCallCapabilities; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 197 | private int mVideoState; |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 198 | private boolean mAudioModeIsVoip; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 199 | private StatusHints mStatusHints; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 200 | private Uri mHandle; |
| 201 | private int mHandlePresentation; |
| 202 | private String mCallerDisplayName; |
| 203 | private int mCallerDisplayNamePresentation; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 204 | private int mFailureCode; |
| 205 | private String mFailureMessage; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * @hide |
| 209 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 210 | RemoteConnection( |
| 211 | String id, |
| 212 | IConnectionService connectionService, |
| 213 | ConnectionRequest request) { |
| 214 | mConnectionId = id; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 215 | mConnectionService = connectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 216 | mConnected = true; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 217 | mState = Connection.STATE_INITIALIZING; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Create a RemoteConnection which is used for failed connections. Note that using it for any |
| 222 | * "real" purpose will almost certainly fail. Callers should note the failure and act |
| 223 | * accordingly (moving on to another RemoteConnection, for example) |
| 224 | * |
| 225 | * @param failureCode |
| 226 | * @param failureMessage |
| 227 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 228 | RemoteConnection(int failureCode, String failureMessage) { |
| 229 | this("NULL", null, null); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 230 | mConnected = false; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 231 | mState = Connection.STATE_FAILED; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 232 | mFailureCode = failureCode; |
| 233 | mFailureMessage = failureMessage; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 236 | /** |
| 237 | * Adds a listener to this {@code RemoteConnection}. |
| 238 | * |
| 239 | * @param listener A {@code Listener}. |
| 240 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 241 | public void addListener(Listener listener) { |
| 242 | mListeners.add(listener); |
| 243 | } |
| 244 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 245 | /** |
| 246 | * Removes a listener from this {@code RemoteConnection}. |
| 247 | * |
| 248 | * @param listener A {@code Listener}. |
| 249 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 250 | public void removeListener(Listener listener) { |
| 251 | mListeners.remove(listener); |
| 252 | } |
| 253 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 254 | /** |
| 255 | * Obtains the parent of this {@code RemoteConnection} in a conference, if any. |
| 256 | * |
| 257 | * @return The parent {@code RemoteConnection}, or {@code null} if this {@code RemoteConnection} |
| 258 | * is not a child of any conference {@code RemoteConnection}s. |
| 259 | */ |
| 260 | public RemoteConnection getParent() { return null; } |
| 261 | |
| 262 | /** |
| 263 | * Obtains the children of this conference {@code RemoteConnection}, if any. |
| 264 | * |
| 265 | * @return The children of this {@code RemoteConnection} if this {@code RemoteConnection} is |
| 266 | * a conference, or an empty {@code List} otherwise. |
| 267 | */ |
| 268 | public List<RemoteConnection> getChildren() { return null; } |
| 269 | |
| 270 | /** |
| 271 | * Obtains the state of this {@code RemoteConnection}. |
| 272 | * |
| 273 | * @return A state value, chosen from the {@code STATE_*} constants. |
| 274 | */ |
Sailesh Nepal | ade3f25 | 2014-07-01 17:25:37 -0700 | [diff] [blame] | 275 | public int getState() { |
| 276 | return mState; |
| 277 | } |
| 278 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 279 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 280 | * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 281 | * disconnect cause expressed as a code chosen from among those declared in |
| 282 | * {@link DisconnectCause}. |
| 283 | */ |
| 284 | public int getDisconnectCauseCode() { |
| 285 | return mDisconnectCauseCode; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 288 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 289 | * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, an optional |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 290 | * reason for disconnection expressed as a free text message. |
| 291 | */ |
| 292 | public String getDisconnectCauseMessage() { |
| 293 | return mDisconnectCauseMessage; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 296 | /** |
| 297 | * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 298 | * {@link PhoneCapabilities}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 299 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 300 | public int getCallCapabilities() { |
| 301 | return mCallCapabilities; |
| 302 | } |
| 303 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 304 | /** |
| 305 | * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP. |
| 306 | */ |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 307 | public boolean getAudioModeIsVoip() { |
| 308 | return mAudioModeIsVoip; |
| 309 | } |
| 310 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 311 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 312 | * @return The current {@link StatusHints} of this {@code RemoteConnection}, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 313 | * or {@code null} if none have been set. |
| 314 | */ |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 315 | public StatusHints getStatusHints() { |
| 316 | return mStatusHints; |
| 317 | } |
| 318 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 319 | /** |
| 320 | * @return The handle (e.g., phone number) to which the {@code RemoteConnection} is currently |
| 321 | * connected. |
| 322 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 323 | public Uri getHandle() { |
| 324 | return mHandle; |
| 325 | } |
| 326 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 327 | /** |
| 328 | * @return The presentation requirements for the handle. See |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 329 | * {@link PropertyPresentation} for valid values. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 330 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 331 | public int getHandlePresentation() { |
| 332 | return mHandlePresentation; |
| 333 | } |
| 334 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 335 | /** |
| 336 | * @return The display name for the caller. |
| 337 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 338 | public String getCallerDisplayName() { |
| 339 | return mCallerDisplayName; |
| 340 | } |
| 341 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 342 | /** |
| 343 | * @return The presentation requirements for the caller display name. See |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 344 | * {@link PropertyPresentation} for valid values. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 345 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 346 | public int getCallerDisplayNamePresentation() { |
| 347 | return mCallerDisplayNamePresentation; |
| 348 | } |
| 349 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 350 | /** |
| 351 | * @return The video state of the {@code RemoteConnection}. See |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 352 | * {@link VideoProfile.VideoState}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 353 | */ |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 354 | public int getVideoState() { |
| 355 | return mVideoState; |
| 356 | } |
| 357 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 358 | /** |
| 359 | * @return The failure code ({@see DisconnectCause}) associated with this failed |
| 360 | * {@code RemoteConnection}. |
| 361 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 362 | public int getFailureCode() { |
| 363 | return mFailureCode; |
| 364 | } |
| 365 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 366 | /** |
| 367 | * @return The reason for the connection failure. This will not be displayed to the user. |
| 368 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 369 | public String getFailureMessage() { |
| 370 | return mFailureMessage; |
| 371 | } |
| 372 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 373 | /** |
| 374 | * @return Whether the {@code RemoteConnection} is requesting that the framework play a |
| 375 | * ringback tone on its behalf. |
| 376 | */ |
| 377 | public boolean isRequestingRingback() { |
| 378 | return false; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Instructs this {@code RemoteConnection} to abort. |
| 383 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 384 | public void abort() { |
| 385 | try { |
| 386 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 387 | mConnectionService.abort(mConnectionId); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 388 | } |
| 389 | } catch (RemoteException ignored) { |
| 390 | } |
| 391 | } |
| 392 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 393 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 394 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 395 | * @param videoState The video state in which to answer the call. |
| 396 | */ |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 397 | public void answer(int videoState) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 398 | try { |
| 399 | if (mConnected) { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 400 | mConnectionService.answer(mConnectionId, videoState); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 401 | } |
| 402 | } catch (RemoteException ignored) { |
| 403 | } |
| 404 | } |
| 405 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 406 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 407 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 408 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 409 | public void reject() { |
| 410 | try { |
| 411 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 412 | mConnectionService.reject(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 413 | } |
| 414 | } catch (RemoteException ignored) { |
| 415 | } |
| 416 | } |
| 417 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 418 | /** |
| 419 | * Instructs this {@code RemoteConnection} to go on hold. |
| 420 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 421 | public void hold() { |
| 422 | try { |
| 423 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 424 | mConnectionService.hold(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 425 | } |
| 426 | } catch (RemoteException ignored) { |
| 427 | } |
| 428 | } |
| 429 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 430 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 431 | * Instructs this {@link Connection#STATE_HOLDING} call to release from hold. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 432 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 433 | public void unhold() { |
| 434 | try { |
| 435 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 436 | mConnectionService.unhold(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 437 | } |
| 438 | } catch (RemoteException ignored) { |
| 439 | } |
| 440 | } |
| 441 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 442 | /** |
| 443 | * Instructs this {@code RemoteConnection} to disconnect. |
| 444 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 445 | public void disconnect() { |
| 446 | try { |
| 447 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 448 | mConnectionService.disconnect(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 449 | } |
| 450 | } catch (RemoteException ignored) { |
| 451 | } |
| 452 | } |
| 453 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 454 | /** |
| 455 | * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling |
| 456 | * (DTMF) tone. |
| 457 | * |
| 458 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 459 | * |
| 460 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 461 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 462 | */ |
| 463 | public void playDtmfTone(char digit) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 464 | try { |
| 465 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 466 | mConnectionService.playDtmfTone(mConnectionId, digit); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 467 | } |
| 468 | } catch (RemoteException ignored) { |
| 469 | } |
| 470 | } |
| 471 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 472 | /** |
| 473 | * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling |
| 474 | * (DTMF) tone currently playing. |
| 475 | * |
| 476 | * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is |
| 477 | * currently playing, this method will do nothing. |
| 478 | */ |
| 479 | public void stopDtmfTone() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 480 | try { |
| 481 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 482 | mConnectionService.stopDtmfTone(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 483 | } |
| 484 | } catch (RemoteException ignored) { |
| 485 | } |
| 486 | } |
| 487 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 488 | /** |
| 489 | * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string. |
| 490 | * |
| 491 | * A post-dial DTMF string is a string of digits following the first instance of either |
| 492 | * {@link TelecommManager#DTMF_CHARACTER_WAIT} or {@link TelecommManager#DTMF_CHARACTER_PAUSE}. |
| 493 | * These digits are immediately sent as DTMF tones to the recipient as soon as the |
| 494 | * connection is made. |
| 495 | * |
| 496 | * If the DTMF string contains a {@link TelecommManager#DTMF_CHARACTER_PAUSE} symbol, this |
| 497 | * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period |
| 498 | * of time. |
| 499 | * |
| 500 | * If the DTMF string contains a {@link TelecommManager#DTMF_CHARACTER_WAIT} symbol, this |
| 501 | * {@code RemoteConnection} will pause playing the tones and notify listeners via |
| 502 | * {@link Listener#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app |
| 503 | * should display to the user an indication of this state and an affordance to continue |
| 504 | * the postdial sequence. When the user decides to continue the postdial sequence, the in-call |
| 505 | * app should invoke the {@link #postDialContinue(boolean)} method. |
| 506 | * |
| 507 | * @param proceed Whether or not to continue with the post-dial sequence. |
| 508 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 509 | public void postDialContinue(boolean proceed) { |
| 510 | try { |
| 511 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 512 | mConnectionService.onPostDialContinue(mConnectionId, proceed); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 513 | } |
| 514 | } catch (RemoteException ignored) { |
| 515 | } |
| 516 | } |
| 517 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 518 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 519 | * Set the audio state of this {@code RemoteConnection}. |
| 520 | * |
| 521 | * @param state The audio state of this {@code RemoteConnection}. |
| 522 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 523 | public void setAudioState(AudioState state) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 524 | try { |
| 525 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 526 | mConnectionService.onAudioStateChanged(mConnectionId, state); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 527 | } |
| 528 | } catch (RemoteException ignored) { |
| 529 | } |
| 530 | } |
| 531 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 532 | /** |
| 533 | * @hide |
| 534 | */ |
| 535 | void setState(int state) { |
| 536 | if (mState != state) { |
| 537 | mState = state; |
| 538 | for (Listener l: mListeners) { |
| 539 | l.onStateChanged(this, state); |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * @hide |
| 546 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 547 | void setDisconnected(int cause, String message) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 548 | if (mState != Connection.STATE_DISCONNECTED) { |
| 549 | mState = Connection.STATE_DISCONNECTED; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 550 | mDisconnectCauseCode = cause; |
| 551 | mDisconnectCauseMessage = message; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 552 | |
| 553 | for (Listener l : mListeners) { |
| 554 | l.onDisconnected(this, cause, message); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * @hide |
| 561 | */ |
| 562 | void setRequestingRingback(boolean ringback) { |
| 563 | if (mRequestingRingback != ringback) { |
| 564 | mRequestingRingback = ringback; |
| 565 | for (Listener l : mListeners) { |
| 566 | l.onRequestingRingback(this, ringback); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * @hide |
| 573 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 574 | void setCallCapabilities(int callCapabilities) { |
| 575 | mCallCapabilities = callCapabilities; |
| 576 | for (Listener l : mListeners) { |
| 577 | l.onCallCapabilitiesChanged(this, callCapabilities); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * @hide |
| 583 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 584 | void setDestroyed() { |
| 585 | if (!mListeners.isEmpty()) { |
| 586 | // Make sure that the listeners are notified that the call is destroyed first. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 587 | if (mState != Connection.STATE_DISCONNECTED) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 588 | setDisconnected(DisconnectCause.ERROR_UNSPECIFIED, "Connection destroyed."); |
| 589 | } |
| 590 | |
| 591 | Set<Listener> listeners = new HashSet<Listener>(mListeners); |
| 592 | mListeners.clear(); |
| 593 | for (Listener l : listeners) { |
| 594 | l.onDestroyed(this); |
| 595 | } |
| 596 | |
| 597 | mConnected = false; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * @hide |
| 603 | */ |
| 604 | void setPostDialWait(String remainingDigits) { |
| 605 | for (Listener l : mListeners) { |
| 606 | l.onPostDialWait(this, remainingDigits); |
| 607 | } |
| 608 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 609 | |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 610 | /** |
| 611 | * @hide |
| 612 | */ |
| 613 | void setVideoState(int videoState) { |
| 614 | mVideoState = videoState; |
| 615 | for (Listener l : mListeners) { |
| 616 | l.onVideoStateChanged(this, videoState); |
| 617 | } |
| 618 | } |
| 619 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 620 | /** @hide */ |
| 621 | void setAudioModeIsVoip(boolean isVoip) { |
| 622 | mAudioModeIsVoip = isVoip; |
| 623 | for (Listener l : mListeners) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 624 | l.onAudioModeIsVoipChanged(this, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 625 | } |
| 626 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 627 | |
| 628 | /** @hide */ |
| 629 | void setStatusHints(StatusHints statusHints) { |
| 630 | mStatusHints = statusHints; |
| 631 | for (Listener l : mListeners) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 632 | l.onStatusHintsChanged(this, statusHints); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /** @hide */ |
| 637 | void setHandle(Uri handle, int presentation) { |
| 638 | mHandle = handle; |
| 639 | mHandlePresentation = presentation; |
| 640 | for (Listener l : mListeners) { |
| 641 | l.onHandleChanged(this, handle, presentation); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | /** @hide */ |
| 646 | void setCallerDisplayName(String callerDisplayName, int presentation) { |
| 647 | mCallerDisplayName = callerDisplayName; |
| 648 | mCallerDisplayNamePresentation = presentation; |
| 649 | for (Listener l : mListeners) { |
| 650 | l.onCallerDisplayNameChanged(this, callerDisplayName, presentation); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 653 | |
| 654 | /** @hide */ |
| 655 | void startActivityFromInCall(PendingIntent intent) { |
| 656 | for (Listener l : mListeners) { |
| 657 | l.onStartActivityFromInCall(this, intent); |
| 658 | } |
| 659 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 660 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 661 | /** @hide */ |
| 662 | void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) { |
| 663 | mConferenceableConnections.clear(); |
| 664 | mConferenceableConnections.addAll(conferenceableConnections); |
| 665 | for (Listener l : mListeners) { |
| 666 | l.onConferenceableConnectionsChanged( |
| 667 | this, new ArrayList<RemoteConnection>(mConferenceableConnections)); |
| 668 | } |
| 669 | } |
| 670 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 671 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 672 | * Create a RemoteConnection which is in the {@link Connection#STATE_FAILED} state. Attempting |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 673 | * to use it for anything will almost certainly result in bad things happening. Do not do this. |
| 674 | * |
| 675 | * @return a failed {@link RemoteConnection} |
| 676 | * |
| 677 | * @hide |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 678 | */ |
| 679 | public static RemoteConnection failure(int failureCode, String failureMessage) { |
| 680 | return new RemoteConnection(failureCode, failureMessage); |
| 681 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 682 | } |