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; |
| 20 | import android.os.Looper; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 21 | |
| 22 | import com.android.internal.telecomm.IInCallAdapter; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 23 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 24 | /** |
| 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 | */ |
| 29 | class InCallAdapter extends IInCallAdapter.Stub { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 30 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 31 | private final CallsManager mCallsManager; |
| 32 | |
| 33 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
| 34 | |
| 35 | /** Persists the specified parameters. */ |
| 36 | public InCallAdapter(CallsManager callsManager) { |
| 37 | mCallsManager = callsManager; |
| 38 | } |
| 39 | |
| 40 | /** {@inheritDoc} */ |
| 41 | @Override |
Ben Gilad | 4074c2a | 2014-03-06 14:02:48 -0800 | [diff] [blame] | 42 | public void answerCall(final String callId) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 43 | Log.d(this, "answerCall(%s)", callId); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 44 | mHandler.post(new Runnable() { |
| 45 | @Override public void run() { |
| 46 | mCallsManager.answerCall(callId); |
| 47 | } |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | /** {@inheritDoc} */ |
| 52 | @Override |
Ben Gilad | 4074c2a | 2014-03-06 14:02:48 -0800 | [diff] [blame] | 53 | public void rejectCall(final String callId) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 54 | Log.d(this, "rejectCall(%s)", callId); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 55 | mHandler.post(new Runnable() { |
| 56 | @Override public void run() { |
| 57 | mCallsManager.rejectCall(callId); |
| 58 | } |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | /** {@inheritDoc} */ |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame^] | 63 | public void playDtmfTone(final String callId, final char digit) { |
| 64 | Log.d(this, "playDtmfTone(%s,%c)", callId, digit); |
| 65 | mHandler.post(new Runnable() { |
| 66 | @Override public void run() { |
| 67 | mCallsManager.playDtmfTone(callId, digit); |
| 68 | } |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | /** {@inheritDoc} */ |
| 73 | public void stopDtmfTone(final String callId) { |
| 74 | Log.d(this, "stopDtmfTone(%s)", callId); |
| 75 | mHandler.post(new Runnable() { |
| 76 | @Override public void run() { |
| 77 | mCallsManager.stopDtmfTone(callId); |
| 78 | } |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | /** {@inheritDoc} */ |
| 83 | public void postDialContinue(final String callId) { |
| 84 | Log.d(this, "postDialContinue(%s)", callId); |
| 85 | mHandler.post(new Runnable() { |
| 86 | @Override public void run() { |
| 87 | mCallsManager.postDialContinue(callId); |
| 88 | } |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | /** {@inheritDoc} */ |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 93 | @Override |
Ben Gilad | 4074c2a | 2014-03-06 14:02:48 -0800 | [diff] [blame] | 94 | public void disconnectCall(final String callId) { |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 95 | mHandler.post(new Runnable() { |
| 96 | @Override public void run() { |
| 97 | mCallsManager.disconnectCall(callId); |
| 98 | } |
| 99 | }); |
| 100 | } |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 101 | |
| 102 | /** {@inheritDoc} */ |
| 103 | @Override |
| 104 | public void holdCall(final String callId) { |
| 105 | mHandler.post(new Runnable() { |
| 106 | @Override public void run() { |
| 107 | mCallsManager.holdCall(callId); |
| 108 | } |
| 109 | }); |
| 110 | } |
| 111 | |
| 112 | /** {@inheritDoc} */ |
| 113 | @Override |
| 114 | public void unholdCall(final String callId) { |
| 115 | mHandler.post(new Runnable() { |
| 116 | @Override public void run() { |
| 117 | mCallsManager.unholdCall(callId); |
| 118 | } |
| 119 | }); |
| 120 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 121 | |
| 122 | /** {@inheritDoc} */ |
| 123 | @Override |
| 124 | public void mute(final boolean shouldMute) { |
| 125 | mHandler.post(new Runnable() { |
| 126 | @Override public void run() { |
| 127 | mCallsManager.mute(shouldMute); |
| 128 | } |
| 129 | }); |
| 130 | } |
| 131 | |
| 132 | /** {@inheritDoc} */ |
| 133 | @Override |
| 134 | public void setAudioRoute(final int route) { |
| 135 | mHandler.post(new Runnable() { |
| 136 | @Override public void run() { |
| 137 | mCallsManager.setAudioRoute(route); |
| 138 | } |
| 139 | }); |
| 140 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 141 | } |