| 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 | |
| 17 | package android.telecomm; |
| 18 | |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 19 | import android.os.RemoteException; |
| 20 | |
| 21 | import com.android.internal.telecomm.IInCallAdapter; |
| 22 | |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 23 | /** |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 24 | * Receives commands from {@link InCallService} implementations which should be executed by |
| 25 | * Telecomm. When Telecomm 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] | 26 | * the in-call service through which it can manipulate live (active, dialing, ringing) calls. When |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 27 | * the in-call service is notified of new calls ({@link InCallService#addCall}), it can use the |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 28 | * given call IDs to execute commands such as {@link #answerCall} for incoming calls or |
| 29 | * {@link #disconnectCall} for active calls the user would like to end. Some commands are only |
| 30 | * appropriate for calls in certain states; please consult each method for such limitations. |
| 31 | * TODO(santoscordon): Needs more/better comments once the API is finalized. |
| 32 | * TODO(santoscordon): Specify the adapter will stop functioning when there are no more calls. |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 33 | */ |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 34 | public final class InCallAdapter { |
| 35 | private final IInCallAdapter mAdapter; |
| 36 | |
| 37 | /** |
| 38 | * {@hide} |
| 39 | */ |
| 40 | public InCallAdapter(IInCallAdapter adapter) { |
| 41 | mAdapter = adapter; |
| 42 | } |
| 43 | |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 44 | /** |
| 45 | * Instructs Telecomm to answer the specified call. |
| 46 | * |
| 47 | * @param callId The identifier of the call to answer. |
| 48 | */ |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 49 | public void answerCall(String callId) { |
| 50 | try { |
| 51 | mAdapter.answerCall(callId); |
| 52 | } catch (RemoteException e) { |
| 53 | } |
| 54 | } |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Instructs Telecomm to reject the specified call. |
| 58 | * TODO(santoscordon): Add reject-with-text-message parameter when that feature |
| 59 | * is ported over. |
| 60 | * |
| 61 | * @param callId The identifier of the call to reject. |
| 62 | */ |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 63 | public void rejectCall(String callId) { |
| 64 | try { |
| 65 | mAdapter.rejectCall(callId); |
| 66 | } catch (RemoteException e) { |
| 67 | } |
| 68 | } |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Instructs Telecomm to disconnect the specified call. |
| 72 | * |
| 73 | * @param callId The identifier of the call to disconnect. |
| 74 | */ |
| Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 75 | public void disconnectCall(String callId) { |
| 76 | try { |
| 77 | mAdapter.disconnectCall(callId); |
| 78 | } catch (RemoteException e) { |
| 79 | } |
| 80 | } |
| Yorke Lee | 81ccaaa | 2014-03-12 18:33:19 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Instructs Telecomm to put the specified call on hold. |
| 84 | * |
| 85 | * @param callId The identifier of the call to put on hold. |
| 86 | */ |
| 87 | public void holdCall(String callId) { |
| 88 | try { |
| 89 | mAdapter.holdCall(callId); |
| 90 | } catch (RemoteException e) { |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Instructs Telecomm to release the specified call from hold. |
| 96 | * |
| 97 | * @param callId The identifier of the call to release from hold. |
| 98 | */ |
| 99 | public void unholdCall(String callId) { |
| 100 | try { |
| 101 | mAdapter.unholdCall(callId); |
| 102 | } catch (RemoteException e) { |
| 103 | } |
| 104 | } |
| Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Mute the microphone. |
| 108 | * |
| 109 | * @param shouldMute True if the microphone should be muted. |
| 110 | */ |
| 111 | public void mute(boolean shouldMute) { |
| 112 | try { |
| 113 | mAdapter.mute(shouldMute); |
| 114 | } catch (RemoteException e) { |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}. |
| 120 | * |
| 121 | * @param route The audio route to use. |
| 122 | */ |
| 123 | public void setAudioRoute(int route) { |
| 124 | try { |
| 125 | mAdapter.setAudioRoute(route); |
| 126 | } catch (RemoteException e) { |
| 127 | } |
| 128 | } |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Instructs Telecomm to play a dual-tone multi-frequency signaling (DTMF) tone in a call. |
| 132 | * |
| 133 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 134 | * |
| 135 | * @param callId The unique ID of the call in which the tone will be played. |
| 136 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 137 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 138 | */ |
| 139 | public void playDtmfTone(String callId, char digit) { |
| 140 | try { |
| 141 | mAdapter.playDtmfTone(callId, digit); |
| 142 | } catch (RemoteException e) { |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Instructs Telecomm to stop any dual-tone multi-frequency signaling (DTMF) tone currently |
| 148 | * playing. |
| 149 | * |
| 150 | * DTMF tones are played by calling {@link #playDtmfTone(String,char)}. If no DTMF tone is |
| 151 | * currently playing, this method will do nothing. |
| 152 | * |
| 153 | * @param callId The unique ID of the call in which any currently playing tone will be stopped. |
| 154 | */ |
| 155 | public void stopDtmfTone(String callId) { |
| 156 | try { |
| 157 | mAdapter.stopDtmfTone(callId); |
| 158 | } catch (RemoteException e) { |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Instructs Telecomm to continue playing a post-dial DTMF string. |
| 164 | * |
| 165 | * A post-dial DTMF string is a string of digits entered after a phone number, when dialed, |
| 166 | * that are immediately sent as DTMF tones to the recipient as soon as the connection is made. |
| 167 | * While these tones are playing, Telecomm will notify the {@link InCallService} that the call |
| Evan Charlton | 8acdbb8 | 2014-04-01 13:50:07 -0700 | [diff] [blame^] | 168 | * is in the {@link InCallService#setPostDial(String,String)} state. |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 169 | * |
| Evan Charlton | 8acdbb8 | 2014-04-01 13:50:07 -0700 | [diff] [blame^] | 170 | * If the DTMF string contains a {@link TelecommConstants#DTMF_CHARACTER_PAUSE} symbol, Telecomm |
| 171 | * 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] | 172 | * |
| Evan Charlton | 8acdbb8 | 2014-04-01 13:50:07 -0700 | [diff] [blame^] | 173 | * If the DTMF string contains a {@link TelecommConstants#DTMF_CHARACTER_WAIT} symbol, Telecomm |
| 174 | * will pause playing the tones and notify the {@link InCallService} that the call is in the |
| 175 | * {@link InCallService#setPostDialWait(String,String)} state. When the user decides to continue |
| 176 | * the postdial sequence, the {@link InCallService} should invoke the |
| Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 177 | * {@link #postDialContinue(String)} method. |
| 178 | * |
| 179 | * @param callId The unique ID of the call for which postdial string playing should continue. |
| 180 | */ |
| 181 | public void postDialContinue(String callId) { |
| 182 | try { |
| 183 | mAdapter.postDialContinue(callId); |
| 184 | } catch (RemoteException e) { |
| 185 | } |
| 186 | } |
| Santos Cordon | 8f3fd30 | 2014-01-27 08:46:21 -0800 | [diff] [blame] | 187 | } |