blob: b9d0eccbafcf26351f0eb1ea0fe688ed811acc05 [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;
Eric Erfanianccca3152017-02-22 16:32:36 -080029import com.android.incallui.call.CallList;
30import com.android.incallui.call.ExternalCallList;
31import com.android.incallui.call.TelecomAdapter;
erfaniana7927922018-02-02 16:36:11 -080032import com.android.incallui.speakeasy.SpeakEasyCallManager;
33import com.android.incallui.speakeasy.SpeakEasyComponent;
Eric Erfanianccca3152017-02-22 16:32:36 -080034
35/**
36 * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
37 * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
38 * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
39 * service triggering InCallActivity (via CallList) to finish soon after.
40 */
41public class InCallServiceImpl extends InCallService {
42
yueg48f93f42018-03-09 16:49:38 -080043 private ReturnToCallController returnToCallController;
Android Dialer974fc292018-02-01 16:12:25 -080044 private CallList.Listener feedbackListener;
erfaniana7927922018-02-02 16:36:11 -080045 // We only expect there to be one speakEasyCallManager to be instantiated at a time.
46 // We did not use a singleton SpeakEasyCallManager to avoid holding on to state beyond the
47 // lifecycle of this service, because the singleton is associated with the state of the
48 // Application, not this service.
49 private SpeakEasyCallManager speakEasyCallManager;
Eric Erfanian2ca43182017-08-31 06:57:16 -070050
Eric Erfanianccca3152017-02-22 16:32:36 -080051 @Override
52 public void onCallAudioStateChanged(CallAudioState audioState) {
wangqi9982f0d2017-10-11 17:46:07 -070053 Trace.beginSection("InCallServiceImpl.onCallAudioStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080054 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
wangqi9982f0d2017-10-11 17:46:07 -070055 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080056 }
57
58 @Override
59 public void onBringToForeground(boolean showDialpad) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070060 Trace.beginSection("InCallServiceImpl.onBringToForeground");
Eric Erfanianccca3152017-02-22 16:32:36 -080061 InCallPresenter.getInstance().onBringToForeground(showDialpad);
Eric Erfanian2ca43182017-08-31 06:57:16 -070062 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080063 }
64
65 @Override
66 public void onCallAdded(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070067 Trace.beginSection("InCallServiceImpl.onCallAdded");
Eric Erfanianccca3152017-02-22 16:32:36 -080068 InCallPresenter.getInstance().onCallAdded(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070069 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080070 }
71
72 @Override
73 public void onCallRemoved(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070074 Trace.beginSection("InCallServiceImpl.onCallRemoved");
erfaniana7927922018-02-02 16:36:11 -080075 speakEasyCallManager.onCallRemoved(CallList.getInstance().getDialerCallFromTelecomCall(call));
76
Eric Erfanianccca3152017-02-22 16:32:36 -080077 InCallPresenter.getInstance().onCallRemoved(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070078 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080079 }
80
81 @Override
82 public void onCanAddCallChanged(boolean canAddCall) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070083 Trace.beginSection("InCallServiceImpl.onCanAddCallChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080084 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
Eric Erfanian2ca43182017-08-31 06:57:16 -070085 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080086 }
87
88 @Override
erfaniana7927922018-02-02 16:36:11 -080089 public void onCreate() {
90 super.onCreate();
91 this.speakEasyCallManager = SpeakEasyComponent.get(this).speakEasyCallManager();
92 }
93
94 @Override
Eric Erfanianccca3152017-02-22 16:32:36 -080095 public IBinder onBind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070096 Trace.beginSection("InCallServiceImpl.onBind");
Eric Erfanianccca3152017-02-22 16:32:36 -080097 final Context context = getApplicationContext();
98 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
Eric Erfanian2ca43182017-08-31 06:57:16 -070099 AudioModeProvider.getInstance().initializeAudioState(this);
Eric Erfanianccca3152017-02-22 16:32:36 -0800100 InCallPresenter.getInstance()
101 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -0700102 context,
Eric Erfanianccca3152017-02-22 16:32:36 -0800103 CallList.getInstance(),
104 new ExternalCallList(),
105 new StatusBarNotifier(context, contactInfoCache),
106 new ExternalCallNotifier(context, contactInfoCache),
107 contactInfoCache,
108 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -0700109 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
erfaniand05d8992018-03-20 19:42:26 -0700110 new FilteredNumberAsyncQueryHandler(context),
yueg4613e8f2018-04-23 13:35:33 -0700111 speakEasyCallManager);
Eric Erfanianccca3152017-02-22 16:32:36 -0800112 InCallPresenter.getInstance().onServiceBind();
113 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
114 TelecomAdapter.getInstance().setInCallService(this);
yueg448dc902018-03-15 12:12:50 -0700115 returnToCallController =
116 new ReturnToCallController(this, ContactInfoCache.getInstance(context));
Android Dialer974fc292018-02-01 16:12:25 -0800117 feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener();
118 CallList.getInstance().addListener(feedbackListener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800119
Eric Erfanian2ca43182017-08-31 06:57:16 -0700120 IBinder iBinder = super.onBind(intent);
121 Trace.endSection();
122 return iBinder;
Eric Erfanianccca3152017-02-22 16:32:36 -0800123 }
124
125 @Override
126 public boolean onUnbind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700127 Trace.beginSection("InCallServiceImpl.onUnbind");
Eric Erfanianccca3152017-02-22 16:32:36 -0800128 super.onUnbind(intent);
129
130 InCallPresenter.getInstance().onServiceUnbind();
131 tearDown();
132
Eric Erfanian2ca43182017-08-31 06:57:16 -0700133 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800134 return false;
135 }
136
137 private void tearDown() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700138 Trace.beginSection("InCallServiceImpl.tearDown");
Eric Erfanianccca3152017-02-22 16:32:36 -0800139 Log.v(this, "tearDown");
140 // Tear down the InCall system
Eric Erfanianccca3152017-02-22 16:32:36 -0800141 InCallPresenter.getInstance().tearDown();
yuegc18ad7a2017-10-18 14:45:05 -0700142 TelecomAdapter.getInstance().clearInCallService();
yueg48f93f42018-03-09 16:49:38 -0800143 if (returnToCallController != null) {
144 returnToCallController.tearDown();
145 returnToCallController = null;
Eric Erfanian938468d2017-10-24 14:05:52 -0700146 }
Android Dialer974fc292018-02-01 16:12:25 -0800147 if (feedbackListener != null) {
148 CallList.getInstance().removeListener(feedbackListener);
149 feedbackListener = null;
150 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700151 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800152 }
153}