blob: 1cb6c478e1c0b51cf25ab4c208c2d4c9e7ced14b [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;
32
33/**
34 * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
35 * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
36 * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
37 * service triggering InCallActivity (via CallList) to finish soon after.
38 */
39public class InCallServiceImpl extends InCallService {
40
Eric Erfanian2ca43182017-08-31 06:57:16 -070041 private ReturnToCallController returnToCallController;
Eric Erfanian938468d2017-10-24 14:05:52 -070042 private NewReturnToCallController newReturnToCallController;
Android Dialer974fc292018-02-01 16:12:25 -080043 private CallList.Listener feedbackListener;
Eric Erfanian2ca43182017-08-31 06:57:16 -070044
Eric Erfanianccca3152017-02-22 16:32:36 -080045 @Override
46 public void onCallAudioStateChanged(CallAudioState audioState) {
wangqi9982f0d2017-10-11 17:46:07 -070047 Trace.beginSection("InCallServiceImpl.onCallAudioStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080048 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
wangqi9982f0d2017-10-11 17:46:07 -070049 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080050 }
51
52 @Override
53 public void onBringToForeground(boolean showDialpad) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070054 Trace.beginSection("InCallServiceImpl.onBringToForeground");
Eric Erfanianccca3152017-02-22 16:32:36 -080055 InCallPresenter.getInstance().onBringToForeground(showDialpad);
Eric Erfanian2ca43182017-08-31 06:57:16 -070056 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080057 }
58
59 @Override
60 public void onCallAdded(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070061 Trace.beginSection("InCallServiceImpl.onCallAdded");
Eric Erfanianccca3152017-02-22 16:32:36 -080062 InCallPresenter.getInstance().onCallAdded(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070063 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080064 }
65
66 @Override
67 public void onCallRemoved(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070068 Trace.beginSection("InCallServiceImpl.onCallRemoved");
Eric Erfanianccca3152017-02-22 16:32:36 -080069 InCallPresenter.getInstance().onCallRemoved(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 onCanAddCallChanged(boolean canAddCall) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070075 Trace.beginSection("InCallServiceImpl.onCanAddCallChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080076 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
Eric Erfanian2ca43182017-08-31 06:57:16 -070077 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080078 }
79
80 @Override
81 public IBinder onBind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070082 Trace.beginSection("InCallServiceImpl.onBind");
Eric Erfanianccca3152017-02-22 16:32:36 -080083 final Context context = getApplicationContext();
84 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
Eric Erfanian2ca43182017-08-31 06:57:16 -070085 AudioModeProvider.getInstance().initializeAudioState(this);
Eric Erfanianccca3152017-02-22 16:32:36 -080086 InCallPresenter.getInstance()
87 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -070088 context,
Eric Erfanianccca3152017-02-22 16:32:36 -080089 CallList.getInstance(),
90 new ExternalCallList(),
91 new StatusBarNotifier(context, contactInfoCache),
92 new ExternalCallNotifier(context, contactInfoCache),
93 contactInfoCache,
94 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -070095 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
96 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -080097 InCallPresenter.getInstance().onServiceBind();
98 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
99 TelecomAdapter.getInstance().setInCallService(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700100 if (ReturnToCallController.isEnabled(this)) {
101 returnToCallController = new ReturnToCallController(this);
102 }
Eric Erfanian938468d2017-10-24 14:05:52 -0700103 if (NewReturnToCallController.isEnabled(this)) {
yuega5a08d82017-10-31 14:11:53 -0700104 newReturnToCallController =
105 new NewReturnToCallController(this, ContactInfoCache.getInstance(context));
Eric Erfanian938468d2017-10-24 14:05:52 -0700106 }
Android Dialer974fc292018-02-01 16:12:25 -0800107 feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener();
108 CallList.getInstance().addListener(feedbackListener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800109
Eric Erfanian2ca43182017-08-31 06:57:16 -0700110 IBinder iBinder = super.onBind(intent);
111 Trace.endSection();
112 return iBinder;
Eric Erfanianccca3152017-02-22 16:32:36 -0800113 }
114
115 @Override
116 public boolean onUnbind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700117 Trace.beginSection("InCallServiceImpl.onUnbind");
Eric Erfanianccca3152017-02-22 16:32:36 -0800118 super.onUnbind(intent);
119
120 InCallPresenter.getInstance().onServiceUnbind();
121 tearDown();
122
Eric Erfanian2ca43182017-08-31 06:57:16 -0700123 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800124 return false;
125 }
126
127 private void tearDown() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700128 Trace.beginSection("InCallServiceImpl.tearDown");
Eric Erfanianccca3152017-02-22 16:32:36 -0800129 Log.v(this, "tearDown");
130 // Tear down the InCall system
Eric Erfanianccca3152017-02-22 16:32:36 -0800131 InCallPresenter.getInstance().tearDown();
yuegc18ad7a2017-10-18 14:45:05 -0700132 TelecomAdapter.getInstance().clearInCallService();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700133 if (returnToCallController != null) {
134 returnToCallController.tearDown();
135 returnToCallController = null;
136 }
Eric Erfanian938468d2017-10-24 14:05:52 -0700137 if (newReturnToCallController != null) {
138 newReturnToCallController.tearDown();
139 newReturnToCallController = null;
140 }
Android Dialer974fc292018-02-01 16:12:25 -0800141 if (feedbackListener != null) {
142 CallList.getInstance().removeListener(feedbackListener);
143 feedbackListener = null;
144 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700145 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800146 }
147}