blob: a7095f818c2a30cef4df851cd8718daba85a63a6 [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 Erfanian938468d2017-10-24 14:05:52 -070043 private NewReturnToCallController newReturnToCallController;
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)),
110 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -0800111 InCallPresenter.getInstance().onServiceBind();
112 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
113 TelecomAdapter.getInstance().setInCallService(this);
Eric Erfanian938468d2017-10-24 14:05:52 -0700114 if (NewReturnToCallController.isEnabled(this)) {
yuega5a08d82017-10-31 14:11:53 -0700115 newReturnToCallController =
116 new NewReturnToCallController(this, ContactInfoCache.getInstance(context));
Eric Erfanian938468d2017-10-24 14:05:52 -0700117 }
Android Dialer974fc292018-02-01 16:12:25 -0800118 feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener();
119 CallList.getInstance().addListener(feedbackListener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800120
Eric Erfanian2ca43182017-08-31 06:57:16 -0700121 IBinder iBinder = super.onBind(intent);
122 Trace.endSection();
123 return iBinder;
Eric Erfanianccca3152017-02-22 16:32:36 -0800124 }
125
126 @Override
127 public boolean onUnbind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700128 Trace.beginSection("InCallServiceImpl.onUnbind");
Eric Erfanianccca3152017-02-22 16:32:36 -0800129 super.onUnbind(intent);
130
131 InCallPresenter.getInstance().onServiceUnbind();
132 tearDown();
133
Eric Erfanian2ca43182017-08-31 06:57:16 -0700134 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800135 return false;
136 }
137
138 private void tearDown() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700139 Trace.beginSection("InCallServiceImpl.tearDown");
Eric Erfanianccca3152017-02-22 16:32:36 -0800140 Log.v(this, "tearDown");
141 // Tear down the InCall system
Eric Erfanianccca3152017-02-22 16:32:36 -0800142 InCallPresenter.getInstance().tearDown();
yuegc18ad7a2017-10-18 14:45:05 -0700143 TelecomAdapter.getInstance().clearInCallService();
Eric Erfanian938468d2017-10-24 14:05:52 -0700144 if (newReturnToCallController != null) {
145 newReturnToCallController.tearDown();
146 newReturnToCallController = null;
147 }
Android Dialer974fc292018-02-01 16:12:25 -0800148 if (feedbackListener != null) {
149 CallList.getInstance().removeListener(feedbackListener);
150 feedbackListener = null;
151 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700152 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800153 }
154}