blob: c4d6d064f495c3996d56c24e5ec9050d124a54a2 [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
Eric Erfanian2ca43182017-08-31 06:57:16 -070043 private ReturnToCallController returnToCallController;
Eric Erfanian938468d2017-10-24 14:05:52 -070044 private NewReturnToCallController newReturnToCallController;
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);
Eric Erfanianccca3152017-02-22 16:32:36 -0800101 InCallPresenter.getInstance()
102 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -0700103 context,
Eric Erfanianccca3152017-02-22 16:32:36 -0800104 CallList.getInstance(),
105 new ExternalCallList(),
106 new StatusBarNotifier(context, contactInfoCache),
107 new ExternalCallNotifier(context, contactInfoCache),
108 contactInfoCache,
109 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -0700110 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
111 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -0800112 InCallPresenter.getInstance().onServiceBind();
113 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
114 TelecomAdapter.getInstance().setInCallService(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700115 if (ReturnToCallController.isEnabled(this)) {
116 returnToCallController = new ReturnToCallController(this);
117 }
Eric Erfanian938468d2017-10-24 14:05:52 -0700118 if (NewReturnToCallController.isEnabled(this)) {
yuega5a08d82017-10-31 14:11:53 -0700119 newReturnToCallController =
120 new NewReturnToCallController(this, ContactInfoCache.getInstance(context));
Eric Erfanian938468d2017-10-24 14:05:52 -0700121 }
Android Dialer974fc292018-02-01 16:12:25 -0800122 feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener();
123 CallList.getInstance().addListener(feedbackListener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800124
Eric Erfanian2ca43182017-08-31 06:57:16 -0700125 IBinder iBinder = super.onBind(intent);
126 Trace.endSection();
127 return iBinder;
Eric Erfanianccca3152017-02-22 16:32:36 -0800128 }
129
130 @Override
131 public boolean onUnbind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700132 Trace.beginSection("InCallServiceImpl.onUnbind");
Eric Erfanianccca3152017-02-22 16:32:36 -0800133 super.onUnbind(intent);
134
135 InCallPresenter.getInstance().onServiceUnbind();
136 tearDown();
137
Eric Erfanian2ca43182017-08-31 06:57:16 -0700138 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800139 return false;
140 }
141
142 private void tearDown() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700143 Trace.beginSection("InCallServiceImpl.tearDown");
Eric Erfanianccca3152017-02-22 16:32:36 -0800144 Log.v(this, "tearDown");
145 // Tear down the InCall system
Eric Erfanianccca3152017-02-22 16:32:36 -0800146 InCallPresenter.getInstance().tearDown();
yuegc18ad7a2017-10-18 14:45:05 -0700147 TelecomAdapter.getInstance().clearInCallService();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700148 if (returnToCallController != null) {
149 returnToCallController.tearDown();
150 returnToCallController = null;
151 }
Eric Erfanian938468d2017-10-24 14:05:52 -0700152 if (newReturnToCallController != null) {
153 newReturnToCallController.tearDown();
154 newReturnToCallController = null;
155 }
Android Dialer974fc292018-02-01 16:12:25 -0800156 if (feedbackListener != null) {
157 CallList.getInstance().removeListener(feedbackListener);
158 feedbackListener = null;
159 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700160 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800161 }
162}