| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [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 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 18 | |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 19 | import android.os.Bundle; |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 20 | import android.os.RemoteException; |
| 21 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 22 | import com.android.internal.telecom.IInCallAdapter; |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 23 | |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 24 | /** |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 25 | * Receives commands from {@link InCallService} implementations which should be executed by |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 26 | * Telecom. When Telecom binds to a {@link InCallService}, an instance of this class is given to |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 27 | * the in-call service through which it can manipulate live (active, dialing, ringing) calls. When |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 28 | * the in-call service is notified of new calls, it can use the |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 29 | * given call IDs to execute commands such as {@link #answerCall} for incoming calls or |
| 30 | * {@link #disconnectCall} for active calls the user would like to end. Some commands are only |
| 31 | * appropriate for calls in certain states; please consult each method for such limitations. |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 32 | * <p> |
| 33 | * The adapter will stop functioning when there are no more calls. |
| 34 | * |
| 35 | * {@hide} |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 36 | */ |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 37 | public final class InCallAdapter { |
| 38 | private final IInCallAdapter mAdapter; |
| 39 | |
| 40 | /** |
| 41 | * {@hide} |
| 42 | */ |
| 43 | public InCallAdapter(IInCallAdapter adapter) { |
| 44 | mAdapter = adapter; |
| 45 | } |
| 46 | |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 47 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 48 | * Instructs Telecom to answer the specified call. |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 49 | * |
| 50 | * @param callId The identifier of the call to answer. |
| Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 51 | * @param videoState The video state in which to answer the call. |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 52 | */ |
| Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 53 | public void answerCall(String callId, int videoState) { |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 54 | try { |
| Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 55 | mAdapter.answerCall(callId, videoState); |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 56 | } catch (RemoteException e) { |
| 57 | } |
| 58 | } |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 61 | * Instructs Telecom to reject the specified call. |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 62 | * |
| 63 | * @param callId The identifier of the call to reject. |
| Ihab Awad | c067754 | 2014-06-10 13:29:47 -0700 | [diff] [blame] | 64 | * @param rejectWithMessage Whether to reject with a text message. |
| 65 | * @param textMessage An optional text message with which to respond. |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 66 | */ |
| Ihab Awad | c067754 | 2014-06-10 13:29:47 -0700 | [diff] [blame] | 67 | public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) { |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 68 | try { |
| Ihab Awad | c067754 | 2014-06-10 13:29:47 -0700 | [diff] [blame] | 69 | mAdapter.rejectCall(callId, rejectWithMessage, textMessage); |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 70 | } catch (RemoteException e) { |
| 71 | } |
| 72 | } |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 75 | * Instructs Telecom to disconnect the specified call. |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 76 | * |
| 77 | * @param callId The identifier of the call to disconnect. |
| 78 | */ |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 79 | public void disconnectCall(String callId) { |
| 80 | try { |
| 81 | mAdapter.disconnectCall(callId); |
| 82 | } catch (RemoteException e) { |
| 83 | } |
| 84 | } |
| Yorke Lee | 81ccaaa | 2014-03-12 18:33:19 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 87 | * Instructs Telecom to put the specified call on hold. |
| Yorke Lee | 81ccaaa | 2014-03-12 18:33:19 -0700 | [diff] [blame] | 88 | * |
| 89 | * @param callId The identifier of the call to put on hold. |
| 90 | */ |
| 91 | public void holdCall(String callId) { |
| 92 | try { |
| 93 | mAdapter.holdCall(callId); |
| 94 | } catch (RemoteException e) { |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 99 | * Instructs Telecom to release the specified call from hold. |
| Yorke Lee | 81ccaaa | 2014-03-12 18:33:19 -0700 | [diff] [blame] | 100 | * |
| 101 | * @param callId The identifier of the call to release from hold. |
| 102 | */ |
| 103 | public void unholdCall(String callId) { |
| 104 | try { |
| 105 | mAdapter.unholdCall(callId); |
| 106 | } catch (RemoteException e) { |
| 107 | } |
| 108 | } |
| Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Mute the microphone. |
| 112 | * |
| 113 | * @param shouldMute True if the microphone should be muted. |
| 114 | */ |
| 115 | public void mute(boolean shouldMute) { |
| 116 | try { |
| 117 | mAdapter.mute(shouldMute); |
| 118 | } catch (RemoteException e) { |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 123 | * Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}. |
| Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 124 | * |
| 125 | * @param route The audio route to use. |
| 126 | */ |
| 127 | public void setAudioRoute(int route) { |
| 128 | try { |
| 129 | mAdapter.setAudioRoute(route); |
| 130 | } catch (RemoteException e) { |
| 131 | } |
| 132 | } |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 133 | |
| 134 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 135 | * Instructs Telecom to play a dual-tone multi-frequency signaling (DTMF) tone in a call. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 136 | * |
| 137 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 138 | * |
| 139 | * @param callId The unique ID of the call in which the tone will be played. |
| 140 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 141 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 142 | */ |
| 143 | public void playDtmfTone(String callId, char digit) { |
| 144 | try { |
| 145 | mAdapter.playDtmfTone(callId, digit); |
| 146 | } catch (RemoteException e) { |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 151 | * Instructs Telecom to stop any dual-tone multi-frequency signaling (DTMF) tone currently |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 152 | * playing. |
| 153 | * |
| 154 | * DTMF tones are played by calling {@link #playDtmfTone(String,char)}. If no DTMF tone is |
| 155 | * currently playing, this method will do nothing. |
| 156 | * |
| 157 | * @param callId The unique ID of the call in which any currently playing tone will be stopped. |
| 158 | */ |
| 159 | public void stopDtmfTone(String callId) { |
| 160 | try { |
| 161 | mAdapter.stopDtmfTone(callId); |
| 162 | } catch (RemoteException e) { |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 167 | * Instructs Telecom to continue playing a post-dial DTMF string. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 168 | * |
| 169 | * A post-dial DTMF string is a string of digits entered after a phone number, when dialed, |
| 170 | * that are immediately sent as DTMF tones to the recipient as soon as the connection is made. |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 171 | * While these tones are playing, Telecom will notify the {@link InCallService} that the call |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 172 | * is in the post dial state. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 173 | * |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 174 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, Telecom |
| Evan Charlton | 8acdbb8 | 2014-04-01 13:50:07 -0700 | [diff] [blame] | 175 | * will temporarily pause playing the tones for a pre-defined period of time. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 176 | * |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 177 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, Telecom |
| Evan Charlton | 8acdbb8 | 2014-04-01 13:50:07 -0700 | [diff] [blame] | 178 | * will pause playing the tones and notify the {@link InCallService} that the call is in the |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 179 | * post dial wait state. When the user decides to continue the postdial sequence, the |
| 180 | * {@link InCallService} should invoke the {@link #postDialContinue(String,boolean)} method. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 181 | * |
| 182 | * @param callId The unique ID of the call for which postdial string playing should continue. |
| Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 183 | * @param proceed Whether or not to continue with the post-dial sequence. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 184 | */ |
| Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 185 | public void postDialContinue(String callId, boolean proceed) { |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 186 | try { |
| Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 187 | mAdapter.postDialContinue(callId, proceed); |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 188 | } catch (RemoteException e) { |
| 189 | } |
| 190 | } |
| Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 193 | * Instructs Telecom to add a PhoneAccountHandle to the specified call. |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 194 | * |
| Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 195 | * @param callId The identifier of the call. |
| 196 | * @param accountHandle The PhoneAccountHandle through which to place the call. |
| 197 | * @param setDefault {@code True} if this account should be set as the default for calls. |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 198 | */ |
| Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 199 | public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle, |
| 200 | boolean setDefault) { |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 201 | try { |
| Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 202 | mAdapter.phoneAccountSelected(callId, accountHandle, setDefault); |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 203 | } catch (RemoteException e) { |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 208 | * Instructs Telecom to conference the specified call. |
| Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 209 | * |
| 210 | * @param callId The unique ID of the call. |
| Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 211 | * @hide |
| 212 | */ |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 213 | public void conference(String callId, String otherCallId) { |
| Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 214 | try { |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 215 | mAdapter.conference(callId, otherCallId); |
| Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 216 | } catch (RemoteException ignored) { |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 221 | * Instructs Telecom to split the specified call from any conference call with which it may be |
| Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 222 | * connected. |
| 223 | * |
| 224 | * @param callId The unique ID of the call. |
| 225 | * @hide |
| 226 | */ |
| Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 227 | public void splitFromConference(String callId) { |
| Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 228 | try { |
| 229 | mAdapter.splitFromConference(callId); |
| 230 | } catch (RemoteException ignored) { |
| 231 | } |
| 232 | } |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 233 | |
| 234 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 235 | * Instructs Telecom to merge child calls of the specified conference call. |
| Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 236 | */ |
| 237 | public void mergeConference(String callId) { |
| 238 | try { |
| 239 | mAdapter.mergeConference(callId); |
| 240 | } catch (RemoteException ignored) { |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 245 | * Instructs Telecom to swap the child calls of the specified conference call. |
| Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 246 | */ |
| 247 | public void swapConference(String callId) { |
| 248 | try { |
| 249 | mAdapter.swapConference(callId); |
| 250 | } catch (RemoteException ignored) { |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 255 | * Instructs Telecom to pull an external call to the local device. |
| 256 | * |
| 257 | * @param callId The callId to pull. |
| 258 | */ |
| 259 | public void pullExternalCall(String callId) { |
| 260 | try { |
| 261 | mAdapter.pullExternalCall(callId); |
| 262 | } catch (RemoteException ignored) { |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Intructs Telecom to send a call event. |
| 268 | * |
| 269 | * @param callId The callId to send the event for. |
| 270 | * @param event The event. |
| 271 | * @param extras Extras associated with the event. |
| 272 | */ |
| 273 | public void sendCallEvent(String callId, String event, Bundle extras) { |
| 274 | try { |
| 275 | mAdapter.sendCallEvent(callId, event, extras); |
| 276 | } catch (RemoteException ignored) { |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 281 | * Instructs Telecom to turn the proximity sensor on. |
| Yorke Lee | 0d6ea71 | 2014-07-28 14:39:23 -0700 | [diff] [blame] | 282 | */ |
| 283 | public void turnProximitySensorOn() { |
| 284 | try { |
| 285 | mAdapter.turnOnProximitySensor(); |
| 286 | } catch (RemoteException ignored) { |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 291 | * Instructs Telecom to turn the proximity sensor off. |
| Yorke Lee | 0d6ea71 | 2014-07-28 14:39:23 -0700 | [diff] [blame] | 292 | * |
| 293 | * @param screenOnImmediately If true, the screen will be turned on immediately if it was |
| 294 | * previously off. Otherwise, the screen will only be turned on after the proximity sensor |
| 295 | * is no longer triggered. |
| 296 | */ |
| 297 | public void turnProximitySensorOff(boolean screenOnImmediately) { |
| 298 | try { |
| 299 | mAdapter.turnOffProximitySensor(screenOnImmediately); |
| 300 | } catch (RemoteException ignored) { |
| 301 | } |
| 302 | } |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 303 | } |