InCallAdapter.java revision 11623a354be47205bf3bc686ed8fdfc278958983
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 try { 45 Log.startSession("ICA.aC"); 46 long token = Binder.clearCallingIdentity(); 47 try { 48 synchronized (mLock) { 49 Log.d(this, "answerCall(%s,%d)", callId, videoState); 50 Call call = mCallIdMapper.getCall(callId); 51 if (call != null) { 52 mCallsManager.answerCall(call, videoState); 53 } else { 54 Log.w(this, "answerCall, unknown call id: %s", callId); 55 } 56 } 57 } finally { 58 Binder.restoreCallingIdentity(token); 59 } 60 } finally { 61 Log.endSession(); 62 } 63 } 64 65 @Override 66 public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) { 67 try { 68 Log.startSession("ICA.aC"); 69 long token = Binder.clearCallingIdentity(); 70 try { 71 synchronized (mLock) { 72 Log.d(this, "rejectCall(%s,%b,%s)", callId, rejectWithMessage, textMessage); 73 Call call = mCallIdMapper.getCall(callId); 74 if (call != null) { 75 mCallsManager.rejectCall(call, rejectWithMessage, textMessage); 76 } else { 77 Log.w(this, "setRingback, unknown call id: %s", callId); 78 } 79 } 80 } finally { 81 Binder.restoreCallingIdentity(token); 82 } 83 } finally { 84 Log.endSession(); 85 } 86 } 87 88 @Override 89 public void playDtmfTone(String callId, char digit) { 90 try { 91 Log.startSession("ICA.pDT"); 92 long token = Binder.clearCallingIdentity(); 93 try { 94 synchronized (mLock) { 95 Log.d(this, "playDtmfTone(%s,%c)", callId, digit); 96 Call call = mCallIdMapper.getCall(callId); 97 if (call != null) { 98 mCallsManager.playDtmfTone(call, digit); 99 } else { 100 Log.w(this, "playDtmfTone, unknown call id: %s", callId); 101 } 102 } 103 } finally { 104 Binder.restoreCallingIdentity(token); 105 } 106 } finally { 107 Log.endSession(); 108 } 109 } 110 111 @Override 112 public void stopDtmfTone(String callId) { 113 try { 114 Log.startSession("ICA.sDT"); 115 long token = Binder.clearCallingIdentity(); 116 try { 117 synchronized (mLock) { 118 Log.d(this, "stopDtmfTone(%s)", callId); 119 Call call = mCallIdMapper.getCall(callId); 120 if (call != null) { 121 mCallsManager.stopDtmfTone(call); 122 } else { 123 Log.w(this, "stopDtmfTone, unknown call id: %s", callId); 124 } 125 } 126 } finally { 127 Binder.restoreCallingIdentity(token); 128 } 129 } finally { 130 Log.endSession(); 131 } 132 } 133 134 @Override 135 public void postDialContinue(String callId, boolean proceed) { 136 try { 137 Log.startSession("ICA.pDC"); 138 long token = Binder.clearCallingIdentity(); 139 try { 140 synchronized (mLock) { 141 Log.d(this, "postDialContinue(%s)", callId); 142 Call call = mCallIdMapper.getCall(callId); 143 if (call != null) { 144 mCallsManager.postDialContinue(call, proceed); 145 } else { 146 Log.w(this, "postDialContinue, unknown call id: %s", callId); 147 } 148 } 149 } finally { 150 Binder.restoreCallingIdentity(token); 151 } 152 } finally { 153 Log.endSession(); 154 } 155 } 156 157 @Override 158 public void disconnectCall(String callId) { 159 try { 160 Log.startSession("ICA.dC"); 161 long token = Binder.clearCallingIdentity(); 162 try { 163 synchronized (mLock) { 164 Log.v(this, "disconnectCall: %s", callId); 165 Call call = mCallIdMapper.getCall(callId); 166 if (call != null) { 167 mCallsManager.disconnectCall(call); 168 } else { 169 Log.w(this, "disconnectCall, unknown call id: %s", callId); 170 } 171 } 172 } finally { 173 Binder.restoreCallingIdentity(token); 174 } 175 } finally { 176 Log.endSession(); 177 } 178 } 179 180 @Override 181 public void holdCall(String callId) { 182 try { 183 Log.startSession("ICA.hC"); 184 long token = Binder.clearCallingIdentity(); 185 try { 186 synchronized (mLock) { 187 Call call = mCallIdMapper.getCall(callId); 188 if (call != null) { 189 mCallsManager.holdCall(call); 190 } else { 191 Log.w(this, "holdCall, unknown call id: %s", callId); 192 } 193 } 194 } finally { 195 Binder.restoreCallingIdentity(token); 196 } 197 } finally { 198 Log.endSession(); 199 } 200 } 201 202 @Override 203 public void unholdCall(String callId) { 204 try { 205 Log.startSession("ICA.uC"); 206 long token = Binder.clearCallingIdentity(); 207 try { 208 synchronized (mLock) { 209 Call call = mCallIdMapper.getCall(callId); 210 if (call != null) { 211 mCallsManager.unholdCall(call); 212 } else { 213 Log.w(this, "unholdCall, unknown call id: %s", callId); 214 } 215 } 216 } finally { 217 Binder.restoreCallingIdentity(token); 218 } 219 } finally { 220 Log.endSession(); 221 } 222 } 223 224 @Override 225 public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle, 226 boolean setDefault) { 227 try { 228 Log.startSession("ICA.pAS"); 229 long token = Binder.clearCallingIdentity(); 230 try { 231 synchronized (mLock) { 232 Call call = mCallIdMapper.getCall(callId); 233 if (call != null) { 234 mCallsManager.phoneAccountSelected(call, accountHandle, setDefault); 235 } else { 236 Log.w(this, "phoneAccountSelected, unknown call id: %s", callId); 237 } 238 } 239 } finally { 240 Binder.restoreCallingIdentity(token); 241 } 242 } finally { 243 Log.endSession(); 244 } 245 } 246 247 @Override 248 public void mute(boolean shouldMute) { 249 try { 250 Log.startSession("ICA.m"); 251 long token = Binder.clearCallingIdentity(); 252 try { 253 synchronized (mLock) { 254 mCallsManager.mute(shouldMute); 255 } 256 } finally { 257 Binder.restoreCallingIdentity(token); 258 } 259 } finally { 260 Log.endSession(); 261 } 262 } 263 264 @Override 265 public void setAudioRoute(int route) { 266 try { 267 Log.startSession("ICA.sAR"); 268 long token = Binder.clearCallingIdentity(); 269 try { 270 synchronized (mLock) { 271 mCallsManager.setAudioRoute(route); 272 } 273 } finally { 274 Binder.restoreCallingIdentity(token); 275 } 276 } finally { 277 Log.endSession(); 278 } 279 } 280 281 @Override 282 public void conference(String callId, String otherCallId) { 283 try { 284 Log.startSession("ICA.c"); 285 long token = Binder.clearCallingIdentity(); 286 try { 287 synchronized (mLock) { 288 Call call = mCallIdMapper.getCall(callId); 289 Call otherCall = mCallIdMapper.getCall(otherCallId); 290 if (call != null && otherCall != null) { 291 mCallsManager.conference(call, otherCall); 292 } else { 293 Log.w(this, "conference, unknown call id: %s or %s", callId, otherCallId); 294 } 295 } 296 } finally { 297 Binder.restoreCallingIdentity(token); 298 } 299 } finally { 300 Log.endSession(); 301 } 302 } 303 304 @Override 305 public void splitFromConference(String callId) { 306 try { 307 Log.startSession("ICA.sFC"); 308 long token = Binder.clearCallingIdentity(); 309 try { 310 synchronized (mLock) { 311 Call call = mCallIdMapper.getCall(callId); 312 if (call != null) { 313 call.splitFromConference(); 314 } else { 315 Log.w(this, "splitFromConference, unknown call id: %s", callId); 316 } 317 } 318 } finally { 319 Binder.restoreCallingIdentity(token); 320 } 321 } finally { 322 Log.endSession(); 323 } 324 } 325 326 @Override 327 public void mergeConference(String callId) { 328 try { 329 Log.startSession("ICA.mC"); 330 long token = Binder.clearCallingIdentity(); 331 try { 332 synchronized (mLock) { 333 Call call = mCallIdMapper.getCall(callId); 334 if (call != null) { 335 call.mergeConference(); 336 } else { 337 Log.w(this, "mergeConference, unknown call id: %s", callId); 338 } 339 } 340 } finally { 341 Binder.restoreCallingIdentity(token); 342 } 343 } finally { 344 Log.endSession(); 345 } 346 } 347 348 @Override 349 public void swapConference(String callId) { 350 try { 351 Log.startSession("ICA.sC"); 352 long token = Binder.clearCallingIdentity(); 353 try { 354 synchronized (mLock) { 355 Call call = mCallIdMapper.getCall(callId); 356 if (call != null) { 357 call.swapConference(); 358 } else { 359 Log.w(this, "swapConference, unknown call id: %s", callId); 360 } 361 } 362 } finally { 363 Binder.restoreCallingIdentity(token); 364 } 365 } finally { 366 Log.endSession(); 367 } 368 } 369 370 @Override 371 public void turnOnProximitySensor() { 372 try { 373 Log.startSession("tOPS"); 374 long token = Binder.clearCallingIdentity(); 375 try { 376 synchronized (mLock) { 377 mCallsManager.turnOnProximitySensor(); 378 } 379 } finally { 380 Binder.restoreCallingIdentity(token); 381 } 382 } finally { 383 Log.endSession(); 384 } 385 } 386 387 @Override 388 public void turnOffProximitySensor(boolean screenOnImmediately) { 389 try { 390 Log.startSession("ICA.tOPS"); 391 long token = Binder.clearCallingIdentity(); 392 try { 393 synchronized (mLock) { 394 mCallsManager.turnOffProximitySensor(screenOnImmediately); 395 } 396 } finally { 397 Binder.restoreCallingIdentity(token); 398 } 399 } finally { 400 Log.endSession(); 401 } 402 } 403} 404