blob: c0dbb7b6073e0e0995865d0a7d7d0e5c712929fb [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
22import com.android.internal.telecomm.IInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080023
Santos Cordone3d76ab2014-01-28 17:25:20 -080024/**
25 * Receives call commands and updates from in-call app and passes them through to CallsManager.
26 * {@link InCallController} creates an instance of this class and passes it to the in-call app after
27 * binding to it. This adapter can receive commands and updates until the in-call app is unbound.
28 */
29class InCallAdapter extends IInCallAdapter.Stub {
Sailesh Nepal10ea4602014-04-01 17:23:32 -070030 private static final int MSG_ANSWER_CALL = 0;
31 private static final int MSG_REJECT_CALL = 1;
32 private static final int MSG_PLAY_DTMF_TONE = 2;
33 private static final int MSG_STOP_DTMF_TONE = 3;
34 private static final int MSG_POST_DIAL_CONTINUE = 4;
35 private static final int MSG_DISCONNECT_CALL = 5;
36 private static final int MSG_HOLD_CALL = 6;
37 private static final int MSG_UNHOLD_CALL = 7;
38 private static final int MSG_MUTE = 8;
39 private static final int MSG_SET_AUDIO_ROUTE = 9;
40
41 private final class InCallAdapterHandler extends Handler {
42 @Override
43 public void handleMessage(Message msg) {
44 switch (msg.what) {
45 case MSG_ANSWER_CALL:
46 mCallsManager.answerCall((String) msg.obj);
47 break;
48 case MSG_REJECT_CALL:
49 mCallsManager.rejectCall((String) msg.obj);
50 break;
51 case MSG_PLAY_DTMF_TONE:
52 mCallsManager.playDtmfTone((String) msg.obj, (char) msg.arg1);
53 break;
54 case MSG_STOP_DTMF_TONE:
55 mCallsManager.stopDtmfTone((String) msg.obj);
56 break;
57 case MSG_POST_DIAL_CONTINUE:
58 mCallsManager.postDialContinue((String) msg.obj);
59 break;
60 case MSG_DISCONNECT_CALL:
61 mCallsManager.disconnectCall((String) msg.obj);
62 break;
63 case MSG_HOLD_CALL:
64 mCallsManager.holdCall((String) msg.obj);
65 break;
66 case MSG_UNHOLD_CALL:
67 mCallsManager.unholdCall((String) msg.obj);
68 break;
69 case MSG_MUTE:
70 mCallsManager.mute(msg.arg1 == 1 ? true : false);
71 break;
72 case MSG_SET_AUDIO_ROUTE:
73 mCallsManager.setAudioRoute(msg.arg1);
74 break;
75 }
76 }
77 }
Santos Cordon61d0f702014-02-19 02:52:23 -080078
Santos Cordone3d76ab2014-01-28 17:25:20 -080079 private final CallsManager mCallsManager;
Sailesh Nepal10ea4602014-04-01 17:23:32 -070080 private final Handler mHandler = new InCallAdapterHandler();
Santos Cordone3d76ab2014-01-28 17:25:20 -080081
82 /** Persists the specified parameters. */
83 public InCallAdapter(CallsManager callsManager) {
Sailesh Nepal10ea4602014-04-01 17:23:32 -070084 ThreadUtil.checkOnMainThread();
Santos Cordone3d76ab2014-01-28 17:25:20 -080085 mCallsManager = callsManager;
86 }
87
88 /** {@inheritDoc} */
89 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -070090 public void answerCall(String callId) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080091 Log.d(this, "answerCall(%s)", callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070092 mHandler.obtainMessage(MSG_ANSWER_CALL, callId).sendToTarget();
Santos Cordone3d76ab2014-01-28 17:25:20 -080093 }
94
95 /** {@inheritDoc} */
96 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -070097 public void rejectCall(String callId) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080098 Log.d(this, "rejectCall(%s)", callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -070099 mHandler.obtainMessage(MSG_REJECT_CALL, callId).sendToTarget();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800100 }
101
102 /** {@inheritDoc} */
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700103 @Override
104 public void playDtmfTone(String callId, char digit) {
Ihab Awad74549ec2014-03-10 15:33:25 -0700105 Log.d(this, "playDtmfTone(%s,%c)", callId, digit);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700106 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, (int) digit, 0, callId).sendToTarget();
Ihab Awad74549ec2014-03-10 15:33:25 -0700107 }
108
109 /** {@inheritDoc} */
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700110 @Override
111 public void stopDtmfTone(String callId) {
Ihab Awad74549ec2014-03-10 15:33:25 -0700112 Log.d(this, "stopDtmfTone(%s)", callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700113 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget();
Ihab Awad74549ec2014-03-10 15:33:25 -0700114 }
115
116 /** {@inheritDoc} */
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700117 @Override
118 public void postDialContinue(String callId) {
Ihab Awad74549ec2014-03-10 15:33:25 -0700119 Log.d(this, "postDialContinue(%s)", callId);
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700120 mHandler.obtainMessage(MSG_POST_DIAL_CONTINUE, callId).sendToTarget();
Ihab Awad74549ec2014-03-10 15:33:25 -0700121 }
122
123 /** {@inheritDoc} */
Santos Cordone3d76ab2014-01-28 17:25:20 -0800124 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700125 public void disconnectCall(String callId) {
126 mHandler.obtainMessage(MSG_DISCONNECT_CALL, callId).sendToTarget();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800127 }
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700128
129 /** {@inheritDoc} */
130 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700131 public void holdCall(String callId) {
132 mHandler.obtainMessage(MSG_HOLD_CALL, callId).sendToTarget();
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700133 }
134
135 /** {@inheritDoc} */
136 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700137 public void unholdCall(String callId) {
138 mHandler.obtainMessage(MSG_UNHOLD_CALL, callId).sendToTarget();
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700139 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700140
141 /** {@inheritDoc} */
142 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700143 public void mute(boolean shouldMute) {
144 mHandler.obtainMessage(MSG_MUTE, shouldMute ? 1 : 0, 0).sendToTarget();
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700145 }
146
147 /** {@inheritDoc} */
148 @Override
Sailesh Nepal10ea4602014-04-01 17:23:32 -0700149 public void setAudioRoute(int route) {
150 mHandler.obtainMessage(MSG_SET_AUDIO_ROUTE, route, 0).sendToTarget();
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700151 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800152}