blob: d803956e68c5e34f690aa78cd0a058c0a8ff84a5 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -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
17package com.android.incallui;
18
19import android.content.Context;
20import android.content.Intent;
21import android.os.IBinder;
Eric Erfanian2ca43182017-08-31 06:57:16 -070022import android.os.Trace;
Eric Erfanianccca3152017-02-22 16:32:36 -080023import android.telecom.Call;
24import android.telecom.CallAudioState;
25import android.telecom.InCallService;
Eric Erfanian83b20212017-05-31 08:53:10 -070026import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
Android Dialer974fc292018-02-01 16:12:25 -080027import com.android.dialer.feedback.FeedbackComponent;
Eric Erfanian8369df02017-05-03 10:27:13 -070028import com.android.incallui.audiomode.AudioModeProvider;
yuegef6d3792018-04-18 12:46:18 -070029import com.android.incallui.audiomode.BluetoothDeviceProviderComponent;
Eric Erfanianccca3152017-02-22 16:32:36 -080030import com.android.incallui.call.CallList;
31import com.android.incallui.call.ExternalCallList;
32import com.android.incallui.call.TelecomAdapter;
erfaniana7927922018-02-02 16:36:11 -080033import com.android.incallui.speakeasy.SpeakEasyCallManager;
34import com.android.incallui.speakeasy.SpeakEasyComponent;
Eric Erfanianccca3152017-02-22 16:32:36 -080035
36/**
37 * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
38 * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
39 * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
40 * service triggering InCallActivity (via CallList) to finish soon after.
41 */
42public class InCallServiceImpl extends InCallService {
43
yueg48f93f42018-03-09 16:49:38 -080044 private ReturnToCallController returnToCallController;
Android Dialer974fc292018-02-01 16:12:25 -080045 private CallList.Listener feedbackListener;
erfaniana7927922018-02-02 16:36:11 -080046 // We only expect there to be one speakEasyCallManager to be instantiated at a time.
47 // We did not use a singleton SpeakEasyCallManager to avoid holding on to state beyond the
48 // lifecycle of this service, because the singleton is associated with the state of the
49 // Application, not this service.
50 private SpeakEasyCallManager speakEasyCallManager;
Eric Erfanian2ca43182017-08-31 06:57:16 -070051
Eric Erfanianccca3152017-02-22 16:32:36 -080052 @Override
53 public void onCallAudioStateChanged(CallAudioState audioState) {
wangqi9982f0d2017-10-11 17:46:07 -070054 Trace.beginSection("InCallServiceImpl.onCallAudioStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080055 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
wangqi9982f0d2017-10-11 17:46:07 -070056 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080057 }
58
59 @Override
60 public void onBringToForeground(boolean showDialpad) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070061 Trace.beginSection("InCallServiceImpl.onBringToForeground");
Eric Erfanianccca3152017-02-22 16:32:36 -080062 InCallPresenter.getInstance().onBringToForeground(showDialpad);
Eric Erfanian2ca43182017-08-31 06:57:16 -070063 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080064 }
65
66 @Override
67 public void onCallAdded(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070068 Trace.beginSection("InCallServiceImpl.onCallAdded");
Eric Erfanianccca3152017-02-22 16:32:36 -080069 InCallPresenter.getInstance().onCallAdded(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070070 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080071 }
72
73 @Override
74 public void onCallRemoved(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070075 Trace.beginSection("InCallServiceImpl.onCallRemoved");
erfaniana7927922018-02-02 16:36:11 -080076 speakEasyCallManager.onCallRemoved(CallList.getInstance().getDialerCallFromTelecomCall(call));
77
Eric Erfanianccca3152017-02-22 16:32:36 -080078 InCallPresenter.getInstance().onCallRemoved(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070079 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080080 }
81
82 @Override
83 public void onCanAddCallChanged(boolean canAddCall) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070084 Trace.beginSection("InCallServiceImpl.onCanAddCallChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080085 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
Eric Erfanian2ca43182017-08-31 06:57:16 -070086 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080087 }
88
89 @Override
erfaniana7927922018-02-02 16:36:11 -080090 public void onCreate() {
91 super.onCreate();
92 this.speakEasyCallManager = SpeakEasyComponent.get(this).speakEasyCallManager();
93 }
94
95 @Override
Eric Erfanianccca3152017-02-22 16:32:36 -080096 public IBinder onBind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070097 Trace.beginSection("InCallServiceImpl.onBind");
Eric Erfanianccca3152017-02-22 16:32:36 -080098 final Context context = getApplicationContext();
99 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700100 AudioModeProvider.getInstance().initializeAudioState(this);
yuegef6d3792018-04-18 12:46:18 -0700101 BluetoothDeviceProviderComponent.get(context).bluetoothDeviceProvider().setUp();
Eric Erfanianccca3152017-02-22 16:32:36 -0800102 InCallPresenter.getInstance()
103 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -0700104 context,
Eric Erfanianccca3152017-02-22 16:32:36 -0800105 CallList.getInstance(),
106 new ExternalCallList(),
107 new StatusBarNotifier(context, contactInfoCache),
108 new ExternalCallNotifier(context, contactInfoCache),
109 contactInfoCache,
110 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -0700111 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
erfaniand05d8992018-03-20 19:42:26 -0700112 new FilteredNumberAsyncQueryHandler(context),
yueg4613e8f2018-04-23 13:35:33 -0700113 speakEasyCallManager);
Eric Erfanianccca3152017-02-22 16:32:36 -0800114 InCallPresenter.getInstance().onServiceBind();
115 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
116 TelecomAdapter.getInstance().setInCallService(this);
yueg448dc902018-03-15 12:12:50 -0700117 returnToCallController =
118 new ReturnToCallController(this, ContactInfoCache.getInstance(context));
Android Dialer974fc292018-02-01 16:12:25 -0800119 feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener();
120 CallList.getInstance().addListener(feedbackListener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800121
Eric Erfanian2ca43182017-08-31 06:57:16 -0700122 IBinder iBinder = super.onBind(intent);
123 Trace.endSection();
124 return iBinder;
Eric Erfanianccca3152017-02-22 16:32:36 -0800125 }
126
127 @Override
128 public boolean onUnbind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700129 Trace.beginSection("InCallServiceImpl.onUnbind");
Eric Erfanianccca3152017-02-22 16:32:36 -0800130 super.onUnbind(intent);
131
132 InCallPresenter.getInstance().onServiceUnbind();
133 tearDown();
134
Eric Erfanian2ca43182017-08-31 06:57:16 -0700135 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800136 return false;
137 }
138
139 private void tearDown() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700140 Trace.beginSection("InCallServiceImpl.tearDown");
Eric Erfanianccca3152017-02-22 16:32:36 -0800141 Log.v(this, "tearDown");
142 // Tear down the InCall system
Eric Erfanianccca3152017-02-22 16:32:36 -0800143 InCallPresenter.getInstance().tearDown();
yuegc18ad7a2017-10-18 14:45:05 -0700144 TelecomAdapter.getInstance().clearInCallService();
yuegef6d3792018-04-18 12:46:18 -0700145 BluetoothDeviceProviderComponent.get(this).bluetoothDeviceProvider().tearDown();
yueg48f93f42018-03-09 16:49:38 -0800146 if (returnToCallController != null) {
147 returnToCallController.tearDown();
148 returnToCallController = null;
Eric Erfanian938468d2017-10-24 14:05:52 -0700149 }
Android Dialer974fc292018-02-01 16:12:25 -0800150 if (feedbackListener != null) {
151 CallList.getInstance().removeListener(feedbackListener);
152 feedbackListener = null;
153 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700154 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800155 }
156}