InCallAdapter.java revision 8452be0e1e82e0d12cfb884bbf683ec5f95c9781
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 17package com.android.server.telecom; 18 19import android.os.Binder; 20import android.telecom.PhoneAccountHandle; 21 22import com.android.internal.telecom.IInCallAdapter; 23 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 */ 29class InCallAdapter extends IInCallAdapter.Stub { 30 private final CallsManager mCallsManager; 31 private final CallIdMapper mCallIdMapper; 32 private final TelecomSystem.SyncRoot mLock; 33 34 /** Persists the specified parameters. */ 35 public InCallAdapter(CallsManager callsManager, CallIdMapper callIdMapper, 36 TelecomSystem.SyncRoot lock) { 37 mCallsManager = callsManager; 38 mCallIdMapper = callIdMapper; 39 mLock = lock; 40 } 41 42 @Override 43 public void answerCall(String callId, int videoState) { 44 long token = Binder.clearCallingIdentity(); 45 try { 46 synchronized (mLock) { 47 Log.d(this, "answerCall(%s,%d)", callId, videoState); 48 Call call = mCallIdMapper.getCall(callId); 49 if (call != null) { 50 mCallsManager.answerCall(call, videoState); 51 } else { 52 Log.w(this, "answerCall, unknown call id: %s", callId); 53 } 54 } 55 } finally { 56 Binder.restoreCallingIdentity(token); 57 } 58 } 59 60 @Override 61 public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) { 62 long token = Binder.clearCallingIdentity(); 63 try { 64 synchronized (mLock) { 65 Log.d(this, "rejectCall(%s,%b,%s)", callId, rejectWithMessage, textMessage); 66 Call call = mCallIdMapper.getCall(callId); 67 if (call != null) { 68 mCallsManager.rejectCall(call, rejectWithMessage, textMessage); 69 } else { 70 Log.w(this, "setRingback, unknown call id: %s", callId); 71 } 72 } 73 } finally { 74 Binder.restoreCallingIdentity(token); 75 } 76 } 77 78 @Override 79 public void playDtmfTone(String callId, char digit) { 80 long token = Binder.clearCallingIdentity(); 81 try { 82 synchronized (mLock) { 83 Log.d(this, "playDtmfTone(%s,%c)", callId, digit); 84 Call call = mCallIdMapper.getCall(callId); 85 if (call != null) { 86 mCallsManager.playDtmfTone(call, digit); 87 } else { 88 Log.w(this, "playDtmfTone, unknown call id: %s", callId); 89 } 90 } 91 } finally { 92 Binder.restoreCallingIdentity(token); 93 } 94 } 95 96 @Override 97 public void stopDtmfTone(String callId) { 98 long token = Binder.clearCallingIdentity(); 99 try { 100 synchronized (mLock) { 101 Log.d(this, "stopDtmfTone(%s)", callId); 102 Call call = mCallIdMapper.getCall(callId); 103 if (call != null) { 104 mCallsManager.stopDtmfTone(call); 105 } else { 106 Log.w(this, "stopDtmfTone, unknown call id: %s", callId); 107 } 108 } 109 } finally { 110 Binder.restoreCallingIdentity(token); 111 } 112 } 113 114 @Override 115 public void postDialContinue(String callId, boolean proceed) { 116 long token = Binder.clearCallingIdentity(); 117 try { 118 synchronized (mLock) { 119 Log.d(this, "postDialContinue(%s)", callId); 120 Call call = mCallIdMapper.getCall(callId); 121 if (call != null) { 122 mCallsManager.postDialContinue(call, proceed); 123 } else { 124 Log.w(this, "postDialContinue, unknown call id: %s", callId); 125 } 126 } 127 } finally { 128 Binder.restoreCallingIdentity(token); 129 } 130 } 131 132 @Override 133 public void disconnectCall(String callId) { 134 long token = Binder.clearCallingIdentity(); 135 try { 136 synchronized (mLock) { 137 Log.v(this, "disconnectCall: %s", callId); 138 Call call = mCallIdMapper.getCall(callId); 139 if (call != null) { 140 mCallsManager.disconnectCall(call); 141 } else { 142 Log.w(this, "disconnectCall, unknown call id: %s", callId); 143 } 144 } 145 } finally { 146 Binder.restoreCallingIdentity(token); 147 } 148 } 149 150 @Override 151 public void holdCall(String callId) { 152 long token = Binder.clearCallingIdentity(); 153 try { 154 synchronized (mLock) { 155 Call call = mCallIdMapper.getCall(callId); 156 if (call != null) { 157 mCallsManager.holdCall(call); 158 } else { 159 Log.w(this, "holdCall, unknown call id: %s", callId); 160 } 161 } 162 } finally { 163 Binder.restoreCallingIdentity(token); 164 } 165 } 166 167 @Override 168 public void unholdCall(String callId) { 169 long token = Binder.clearCallingIdentity(); 170 try { 171 synchronized (mLock) { 172 Call call = mCallIdMapper.getCall(callId); 173 if (call != null) { 174 mCallsManager.unholdCall(call); 175 } else { 176 Log.w(this, "unholdCall, unknown call id: %s", callId); 177 } 178 } 179 } finally { 180 Binder.restoreCallingIdentity(token); 181 } 182 } 183 184 @Override 185 public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle, 186 boolean setDefault) { 187 long token = Binder.clearCallingIdentity(); 188 try { 189 synchronized (mLock) { 190 Call call = mCallIdMapper.getCall(callId); 191 if (call != null) { 192 mCallsManager.phoneAccountSelected(call, accountHandle, setDefault); 193 } else { 194 Log.w(this, "phoneAccountSelected, unknown call id: %s", callId); 195 } 196 } 197 } finally { 198 Binder.restoreCallingIdentity(token); 199 } 200 } 201 202 @Override 203 public void mute(boolean shouldMute) { 204 long token = Binder.clearCallingIdentity(); 205 try { 206 synchronized (mLock) { 207 mCallsManager.mute(shouldMute); 208 } 209 } finally { 210 Binder.restoreCallingIdentity(token); 211 } 212 } 213 214 @Override 215 public void setAudioRoute(int route) { 216 long token = Binder.clearCallingIdentity(); 217 try { 218 synchronized (mLock) { 219 mCallsManager.setAudioRoute(route); 220 } 221 } finally { 222 Binder.restoreCallingIdentity(token); 223 } 224 } 225 226 @Override 227 public void conference(String callId, String otherCallId) { 228 long token = Binder.clearCallingIdentity(); 229 try { 230 synchronized (mLock) { 231 Call call = mCallIdMapper.getCall(callId); 232 Call otherCall = mCallIdMapper.getCall(otherCallId); 233 if (call != null && otherCall != null) { 234 mCallsManager.conference(call, otherCall); 235 } else { 236 Log.w(this, "conference, unknown call id: %s or %s", callId, otherCallId); 237 } 238 } 239 } finally { 240 Binder.restoreCallingIdentity(token); 241 } 242 } 243 244 @Override 245 public void splitFromConference(String callId) { 246 long token = Binder.clearCallingIdentity(); 247 try { 248 synchronized (mLock) { 249 Call call = mCallIdMapper.getCall(callId); 250 if (call != null) { 251 call.splitFromConference(); 252 } else { 253 Log.w(this, "splitFromConference, unknown call id: %s", callId); 254 } 255 } 256 } finally { 257 Binder.restoreCallingIdentity(token); 258 } 259 } 260 261 @Override 262 public void mergeConference(String callId) { 263 long token = Binder.clearCallingIdentity(); 264 try { 265 synchronized (mLock) { 266 Call call = mCallIdMapper.getCall(callId); 267 if (call != null) { 268 call.mergeConference(); 269 } else { 270 Log.w(this, "mergeConference, unknown call id: %s", callId); 271 } 272 } 273 } finally { 274 Binder.restoreCallingIdentity(token); 275 } 276 } 277 278 @Override 279 public void swapConference(String callId) { 280 long token = Binder.clearCallingIdentity(); 281 try { 282 synchronized (mLock) { 283 Call call = mCallIdMapper.getCall(callId); 284 if (call != null) { 285 call.swapConference(); 286 } else { 287 Log.w(this, "swapConference, unknown call id: %s", callId); 288 } 289 } 290 } finally { 291 Binder.restoreCallingIdentity(token); 292 } 293 } 294 295 @Override 296 public void turnOnProximitySensor() { 297 long token = Binder.clearCallingIdentity(); 298 try { 299 synchronized (mLock) { 300 mCallsManager.turnOnProximitySensor(); 301 } 302 } finally { 303 Binder.restoreCallingIdentity(token); 304 } 305 } 306 307 @Override 308 public void turnOffProximitySensor(boolean screenOnImmediately) { 309 long token = Binder.clearCallingIdentity(); 310 try { 311 synchronized (mLock) { 312 mCallsManager.turnOffProximitySensor(screenOnImmediately); 313 } 314 } finally { 315 Binder.restoreCallingIdentity(token); 316 } 317 } 318} 319