Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -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 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 19 | import android.os.Handler; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 20 | import android.os.Message; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 21 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame^] | 22 | import com.android.internal.os.SomeArgs; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 23 | import com.android.internal.telecomm.IInCallAdapter; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 24 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Receives call commands and updates from in-call app and passes them through to CallsManager. |
| 27 | * {@link InCallController} creates an instance of this class and passes it to the in-call app after |
| 28 | * binding to it. This adapter can receive commands and updates until the in-call app is unbound. |
| 29 | */ |
| 30 | class InCallAdapter extends IInCallAdapter.Stub { |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 31 | private static final int MSG_ANSWER_CALL = 0; |
| 32 | private static final int MSG_REJECT_CALL = 1; |
| 33 | private static final int MSG_PLAY_DTMF_TONE = 2; |
| 34 | private static final int MSG_STOP_DTMF_TONE = 3; |
| 35 | private static final int MSG_POST_DIAL_CONTINUE = 4; |
| 36 | private static final int MSG_DISCONNECT_CALL = 5; |
| 37 | private static final int MSG_HOLD_CALL = 6; |
| 38 | private static final int MSG_UNHOLD_CALL = 7; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 39 | private static final int MSG_HANDOFF_CALL = 8; |
| 40 | private static final int MSG_MUTE = 9; |
| 41 | private static final int MSG_SET_AUDIO_ROUTE = 10; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 42 | |
| 43 | private final class InCallAdapterHandler extends Handler { |
| 44 | @Override |
| 45 | public void handleMessage(Message msg) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 46 | Call call = null; |
| 47 | if (msg.obj != null) { |
| 48 | call = mCallIdMapper.getCall(msg.obj); |
| 49 | if (call == null) { |
| 50 | Log.w(this, "Unknown call id: %s, msg: %d", msg.obj, msg.what); |
| 51 | return; |
| 52 | } |
| 53 | } |
| 54 | |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 55 | switch (msg.what) { |
| 56 | case MSG_ANSWER_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 57 | mCallsManager.answerCall(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 58 | break; |
| 59 | case MSG_REJECT_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 60 | mCallsManager.rejectCall(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 61 | break; |
| 62 | case MSG_PLAY_DTMF_TONE: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 63 | mCallsManager.playDtmfTone(call, (char) msg.arg1); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 64 | break; |
| 65 | case MSG_STOP_DTMF_TONE: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 66 | mCallsManager.stopDtmfTone(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 67 | break; |
| 68 | case MSG_POST_DIAL_CONTINUE: |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame^] | 69 | mCallsManager.postDialContinue(call, msg.arg1 == 1); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 70 | break; |
| 71 | case MSG_DISCONNECT_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 72 | mCallsManager.disconnectCall(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 73 | break; |
| 74 | case MSG_HOLD_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 75 | mCallsManager.holdCall(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 76 | break; |
| 77 | case MSG_UNHOLD_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 78 | mCallsManager.unholdCall(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 79 | break; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 80 | case MSG_HANDOFF_CALL: |
| 81 | mCallsManager.startHandoffForCall(call); |
| 82 | break; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 83 | case MSG_MUTE: |
| 84 | mCallsManager.mute(msg.arg1 == 1 ? true : false); |
| 85 | break; |
| 86 | case MSG_SET_AUDIO_ROUTE: |
| 87 | mCallsManager.setAudioRoute(msg.arg1); |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | } |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 92 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 93 | private final CallsManager mCallsManager; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 94 | private final Handler mHandler = new InCallAdapterHandler(); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 95 | private final CallIdMapper mCallIdMapper; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 96 | |
| 97 | /** Persists the specified parameters. */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 98 | public InCallAdapter(CallsManager callsManager, CallIdMapper callIdMapper) { |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 99 | ThreadUtil.checkOnMainThread(); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 100 | mCallsManager = callsManager; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 101 | mCallIdMapper = callIdMapper; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** {@inheritDoc} */ |
| 105 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 106 | public void answerCall(String callId) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 107 | Log.d(this, "answerCall(%s)", callId); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 108 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 109 | mHandler.obtainMessage(MSG_ANSWER_CALL, callId).sendToTarget(); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** {@inheritDoc} */ |
| 113 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 114 | public void rejectCall(String callId) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 115 | Log.d(this, "rejectCall(%s)", callId); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 116 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 117 | mHandler.obtainMessage(MSG_REJECT_CALL, callId).sendToTarget(); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 121 | @Override |
| 122 | public void playDtmfTone(String callId, char digit) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 123 | Log.d(this, "playDtmfTone(%s,%c)", callId, digit); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 124 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 125 | mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, (int) digit, 0, callId).sendToTarget(); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 129 | @Override |
| 130 | public void stopDtmfTone(String callId) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 131 | Log.d(this, "stopDtmfTone(%s)", callId); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 132 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 133 | mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget(); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 137 | @Override |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame^] | 138 | public void postDialContinue(String callId, boolean proceed) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 139 | Log.d(this, "postDialContinue(%s)", callId); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 140 | mCallIdMapper.checkValidCallId(callId); |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame^] | 141 | mHandler.obtainMessage(MSG_POST_DIAL_CONTINUE, proceed ? 1 : 0, 0, callId).sendToTarget(); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** {@inheritDoc} */ |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 145 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 146 | public void disconnectCall(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 147 | Log.v(this, "disconnectCall: %s", callId); |
| 148 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 149 | mHandler.obtainMessage(MSG_DISCONNECT_CALL, callId).sendToTarget(); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 150 | } |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 151 | |
| 152 | /** {@inheritDoc} */ |
| 153 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 154 | public void holdCall(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 155 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 156 | mHandler.obtainMessage(MSG_HOLD_CALL, callId).sendToTarget(); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** {@inheritDoc} */ |
| 160 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 161 | public void unholdCall(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 162 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 163 | mHandler.obtainMessage(MSG_UNHOLD_CALL, callId).sendToTarget(); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 164 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 165 | |
| 166 | /** {@inheritDoc} */ |
| 167 | @Override |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 168 | public void handoffCall(String callId) { |
| 169 | mCallIdMapper.checkValidCallId(callId); |
| 170 | mHandler.obtainMessage(MSG_HANDOFF_CALL, callId).sendToTarget(); |
| 171 | } |
| 172 | |
| 173 | /** {@inheritDoc} */ |
| 174 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 175 | public void mute(boolean shouldMute) { |
| 176 | mHandler.obtainMessage(MSG_MUTE, shouldMute ? 1 : 0, 0).sendToTarget(); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** {@inheritDoc} */ |
| 180 | @Override |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 181 | public void setAudioRoute(int route) { |
| 182 | mHandler.obtainMessage(MSG_SET_AUDIO_ROUTE, route, 0).sendToTarget(); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 183 | } |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 184 | |
| 185 | /** ${inheritDoc} */ |
| 186 | @Override |
| 187 | public void conferenceWith(String arg0, String arg1) { |
| 188 | } |
| 189 | |
| 190 | /** ${inheritDoc} */ |
| 191 | @Override |
| 192 | public void splitFromConference(String arg0) { |
| 193 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 194 | } |