blob: 7ae12ab95c1d53bffe5db4af203b50b1894bbb49 [file] [log] [blame]
Santos Cordone3d76ab2014-01-28 17:25:20 -08001/*
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 Gilad9f2bed32013-12-12 17:43:26 -080017package com.android.telecomm;
18
Santos Cordone3d76ab2014-01-28 17:25:20 -080019import android.os.Handler;
Sailesh Nepal10ea4602014-04-01 17:23:32 -070020import android.os.Message;
Sailesh Nepala439e1b2014-03-11 18:19:58 -070021
Evan Charlton352105c2014-06-03 14:10:54 -070022import com.android.internal.os.SomeArgs;
Sailesh Nepala439e1b2014-03-11 18:19:58 -070023import com.android.internal.telecomm.IInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080024
Santos Cordone3d76ab2014-01-28 17:25:20 -080025/**
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 */
30class InCallAdapter extends IInCallAdapter.Stub {
Sailesh Nepal10ea4602014-04-01 17:23:32 -070031 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 Nepal84fa5f82014-04-02 11:01:11 -070039 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;
Santos Cordona1610702014-06-04 20:22:56 -070042 private static final int MSG_CONFERENCE = 11;
43 private static final int MSG_SPLIT_FROM_CONFERENCE = 12;
Sailesh Nepal10ea4602014-04-01 17:23:32 -070044
45 private final class InCallAdapterHandler extends Handler {
46 @Override
47 public void handleMessage(Message msg) {
Sailesh Nepale59bb192014-04-01 18:33:59 -070048 Call call = null;
49 if (msg.obj != null) {
50 call = mCallIdMapper.getCall(msg.obj);
51 if (call == null) {
52 Log.w(this, "Unknown call id: %s, msg: %d", msg.obj, msg.what);
53 return;
54 }
55 }
56
Sailesh Nepal10ea4602014-04-01 17:23:32 -070057 switch (msg.what) {
58 case MSG_ANSWER_CALL:
Sailesh Nepale59bb192014-04-01 18:33:59 -070059 mCallsManager.answerCall(call);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070060 break;
61 case MSG_REJECT_CALL:
Sailesh Nepale59bb192014-04-01 18:33:59 -070062 mCallsManager.rejectCall(call);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070063 break;
64 case MSG_PLAY_DTMF_TONE:
Sailesh Nepale59bb192014-04-01 18:33:59 -070065 mCallsManager.playDtmfTone(call, (char) msg.arg1);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070066 break;
67 case MSG_STOP_DTMF_TONE:
Sailesh Nepale59bb192014-04-01 18:33:59 -070068 mCallsManager.stopDtmfTone(call);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070069 break;
70 case MSG_POST_DIAL_CONTINUE:
Evan Charlton352105c2014-06-03 14:10:54 -070071 mCallsManager.postDialContinue(call, msg.arg1 == 1);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070072 break;
73 case MSG_DISCONNECT_CALL:
Sailesh Nepale59bb192014-04-01 18:33:59 -070074 mCallsManager.disconnectCall(call);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070075 break;
76 case MSG_HOLD_CALL:
Sailesh Nepale59bb192014-04-01 18:33:59 -070077 mCallsManager.holdCall(call);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070078 break;
79 case MSG_UNHOLD_CALL:
Sailesh Nepale59bb192014-04-01 18:33:59 -070080 mCallsManager.unholdCall(call);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070081 break;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070082 case MSG_HANDOFF_CALL:
83 mCallsManager.startHandoffForCall(call);
84 break;
Sailesh Nepal10ea4602014-04-01 17:23:32 -070085 case MSG_MUTE:
86 mCallsManager.mute(msg.arg1 == 1 ? true : false);
87 break;
88 case MSG_SET_AUDIO_ROUTE:
89 mCallsManager.setAudioRoute(msg.arg1);
90 break;
Santos Cordona1610702014-06-04 20:22:56 -070091 case MSG_CONFERENCE:
92 mCallsManager.conference(call);
93 break;
94 case MSG_SPLIT_FROM_CONFERENCE:
95 call.splitFromConference();
96 break;
Sailesh Nepal10ea4602014-04-01 17:23:32 -070097 }
98 }
99 }
Santos Cordon61d0f702014-02-19 02:52:23 -0800100
Santos Cordone3d76ab2014-01-28 17:25:20 -0800101 private final CallsManager mCallsManager;
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700102 private final Handler mHandler = new InCallAdapterHandler();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700103 private final CallIdMapper mCallIdMapper;
Santos Cordone3d76ab2014-01-28 17:25:20 -0800104
105 /** Persists the specified parameters. */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700106 public InCallAdapter(CallsManager callsManager, CallIdMapper callIdMapper) {
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700107 ThreadUtil.checkOnMainThread();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800108 mCallsManager = callsManager;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700109 mCallIdMapper = callIdMapper;
Santos Cordone3d76ab2014-01-28 17:25:20 -0800110 }
111
112 /** {@inheritDoc} */
113 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700114 public void answerCall(String callId) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800115 Log.d(this, "answerCall(%s)", callId);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700116 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700117 mHandler.obtainMessage(MSG_ANSWER_CALL, callId).sendToTarget();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800118 }
119
120 /** {@inheritDoc} */
121 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700122 public void rejectCall(String callId) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800123 Log.d(this, "rejectCall(%s)", callId);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700124 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700125 mHandler.obtainMessage(MSG_REJECT_CALL, callId).sendToTarget();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800126 }
127
128 /** {@inheritDoc} */
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700129 @Override
130 public void playDtmfTone(String callId, char digit) {
Ihab Awad74549ec2014-03-10 15:33:25 -0700131 Log.d(this, "playDtmfTone(%s,%c)", callId, digit);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700132 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700133 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, (int) digit, 0, callId).sendToTarget();
Ihab Awad74549ec2014-03-10 15:33:25 -0700134 }
135
136 /** {@inheritDoc} */
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700137 @Override
138 public void stopDtmfTone(String callId) {
Ihab Awad74549ec2014-03-10 15:33:25 -0700139 Log.d(this, "stopDtmfTone(%s)", callId);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700140 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700141 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget();
Ihab Awad74549ec2014-03-10 15:33:25 -0700142 }
143
144 /** {@inheritDoc} */
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700145 @Override
Evan Charlton352105c2014-06-03 14:10:54 -0700146 public void postDialContinue(String callId, boolean proceed) {
Ihab Awad74549ec2014-03-10 15:33:25 -0700147 Log.d(this, "postDialContinue(%s)", callId);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700148 mCallIdMapper.checkValidCallId(callId);
Evan Charlton352105c2014-06-03 14:10:54 -0700149 mHandler.obtainMessage(MSG_POST_DIAL_CONTINUE, proceed ? 1 : 0, 0, callId).sendToTarget();
Ihab Awad74549ec2014-03-10 15:33:25 -0700150 }
151
152 /** {@inheritDoc} */
Santos Cordone3d76ab2014-01-28 17:25:20 -0800153 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700154 public void disconnectCall(String callId) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700155 Log.v(this, "disconnectCall: %s", callId);
156 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700157 mHandler.obtainMessage(MSG_DISCONNECT_CALL, callId).sendToTarget();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800158 }
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700159
160 /** {@inheritDoc} */
161 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700162 public void holdCall(String callId) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700163 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700164 mHandler.obtainMessage(MSG_HOLD_CALL, callId).sendToTarget();
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700165 }
166
167 /** {@inheritDoc} */
168 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700169 public void unholdCall(String callId) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700170 mCallIdMapper.checkValidCallId(callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700171 mHandler.obtainMessage(MSG_UNHOLD_CALL, callId).sendToTarget();
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700172 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700173
174 /** {@inheritDoc} */
175 @Override
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700176 public void handoffCall(String callId) {
177 mCallIdMapper.checkValidCallId(callId);
178 mHandler.obtainMessage(MSG_HANDOFF_CALL, callId).sendToTarget();
179 }
180
181 /** {@inheritDoc} */
182 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700183 public void mute(boolean shouldMute) {
184 mHandler.obtainMessage(MSG_MUTE, shouldMute ? 1 : 0, 0).sendToTarget();
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700185 }
186
187 /** {@inheritDoc} */
188 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700189 public void setAudioRoute(int route) {
190 mHandler.obtainMessage(MSG_SET_AUDIO_ROUTE, route, 0).sendToTarget();
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700191 }
Santos Cordon8f3282c2014-06-01 13:56:02 -0700192
193 /** ${inheritDoc} */
194 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700195 public void conference(String callId) {
196 mHandler.obtainMessage(MSG_CONFERENCE, callId).sendToTarget();
Santos Cordon8f3282c2014-06-01 13:56:02 -0700197 }
198
199 /** ${inheritDoc} */
200 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700201 public void splitFromConference(String callId) {
202 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget();
Santos Cordon8f3282c2014-06-01 13:56:02 -0700203 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800204}