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.incallui; 18 19import android.content.Context; 20import android.content.Intent; 21import android.os.IBinder; 22import android.telecom.Call; 23import android.telecom.CallAudioState; 24import android.telecom.InCallService; 25 26/** 27 * Used to receive updates about calls from the Telecom component. This service is bound to 28 * Telecom while there exist calls which potentially require UI. This includes ringing (incoming), 29 * dialing (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to 30 * the service triggering InCallActivity (via CallList) to finish soon after. 31 */ 32public class InCallServiceImpl extends InCallService { 33 34 @Override 35 public void onCallAudioStateChanged(CallAudioState audioState) { 36 AudioModeProvider.getInstance().onAudioStateChanged(audioState.isMuted(), 37 audioState.getRoute(), audioState.getSupportedRouteMask()); 38 } 39 40 @Override 41 public void onBringToForeground(boolean showDialpad) { 42 InCallPresenter.getInstance().onBringToForeground(showDialpad); 43 } 44 45 @Override 46 public void onCallAdded(Call call) { 47 InCallPresenter.getInstance().onCallAdded(call); 48 } 49 50 @Override 51 public void onCallRemoved(Call call) { 52 InCallPresenter.getInstance().onCallRemoved(call); 53 } 54 55 @Override 56 public void onCanAddCallChanged(boolean canAddCall) { 57 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall); 58 } 59 60 @Override 61 public IBinder onBind(Intent intent) { 62 final Context context = getApplicationContext(); 63 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context); 64 InCallPresenter.getInstance().setUp( 65 getApplicationContext(), 66 CallList.getInstance(), 67 AudioModeProvider.getInstance(), 68 new StatusBarNotifier(context, contactInfoCache), 69 contactInfoCache, 70 new ProximitySensor( 71 context, 72 AudioModeProvider.getInstance(), 73 new AccelerometerListener(context)) 74 ); 75 InCallPresenter.getInstance().onServiceBind(); 76 InCallPresenter.getInstance().maybeStartRevealAnimation(intent); 77 TelecomAdapter.getInstance().setInCallService(this); 78 79 return super.onBind(intent); 80 } 81 82 @Override 83 public boolean onUnbind(Intent intent) { 84 super.onUnbind(intent); 85 86 InCallPresenter.getInstance().onServiceUnbind(); 87 tearDown(); 88 89 return false; 90 } 91 92 private void tearDown() { 93 Log.v(this, "tearDown"); 94 // Tear down the InCall system 95 TelecomAdapter.getInstance().clearInCallService(); 96 InCallPresenter.getInstance().tearDown(); 97 } 98} 99