blob: 539dba8dd71d17b5f756b05395d2ed03bdcfc5e7 [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;
Eric Erfanian8369df02017-05-03 10:27:13 -070027import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080028import com.android.incallui.call.CallList;
29import com.android.incallui.call.ExternalCallList;
30import com.android.incallui.call.TelecomAdapter;
31
32/**
33 * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
34 * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
35 * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
36 * service triggering InCallActivity (via CallList) to finish soon after.
37 */
38public class InCallServiceImpl extends InCallService {
39
Eric Erfanian2ca43182017-08-31 06:57:16 -070040 private ReturnToCallController returnToCallController;
Eric Erfanian938468d2017-10-24 14:05:52 -070041 private NewReturnToCallController newReturnToCallController;
Eric Erfanian2ca43182017-08-31 06:57:16 -070042
Eric Erfanianccca3152017-02-22 16:32:36 -080043 @Override
44 public void onCallAudioStateChanged(CallAudioState audioState) {
wangqi9982f0d2017-10-11 17:46:07 -070045 Trace.beginSection("InCallServiceImpl.onCallAudioStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080046 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
wangqi9982f0d2017-10-11 17:46:07 -070047 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080048 }
49
50 @Override
51 public void onBringToForeground(boolean showDialpad) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070052 Trace.beginSection("InCallServiceImpl.onBringToForeground");
Eric Erfanianccca3152017-02-22 16:32:36 -080053 InCallPresenter.getInstance().onBringToForeground(showDialpad);
Eric Erfanian2ca43182017-08-31 06:57:16 -070054 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080055 }
56
57 @Override
58 public void onCallAdded(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070059 Trace.beginSection("InCallServiceImpl.onCallAdded");
Eric Erfanianccca3152017-02-22 16:32:36 -080060 InCallPresenter.getInstance().onCallAdded(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070061 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080062 }
63
64 @Override
65 public void onCallRemoved(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070066 Trace.beginSection("InCallServiceImpl.onCallRemoved");
Eric Erfanianccca3152017-02-22 16:32:36 -080067 InCallPresenter.getInstance().onCallRemoved(call);
Eric Erfanian2ca43182017-08-31 06:57:16 -070068 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080069 }
70
71 @Override
72 public void onCanAddCallChanged(boolean canAddCall) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070073 Trace.beginSection("InCallServiceImpl.onCanAddCallChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -080074 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
Eric Erfanian2ca43182017-08-31 06:57:16 -070075 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -080076 }
77
78 @Override
79 public IBinder onBind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -070080 Trace.beginSection("InCallServiceImpl.onBind");
Eric Erfanianccca3152017-02-22 16:32:36 -080081 final Context context = getApplicationContext();
82 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
Eric Erfanian2ca43182017-08-31 06:57:16 -070083 AudioModeProvider.getInstance().initializeAudioState(this);
Eric Erfanianccca3152017-02-22 16:32:36 -080084 InCallPresenter.getInstance()
85 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -070086 context,
Eric Erfanianccca3152017-02-22 16:32:36 -080087 CallList.getInstance(),
88 new ExternalCallList(),
89 new StatusBarNotifier(context, contactInfoCache),
90 new ExternalCallNotifier(context, contactInfoCache),
91 contactInfoCache,
92 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -070093 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
94 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -080095 InCallPresenter.getInstance().onServiceBind();
96 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
97 TelecomAdapter.getInstance().setInCallService(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -070098 if (ReturnToCallController.isEnabled(this)) {
99 returnToCallController = new ReturnToCallController(this);
100 }
Eric Erfanian938468d2017-10-24 14:05:52 -0700101 if (NewReturnToCallController.isEnabled(this)) {
yuega5a08d82017-10-31 14:11:53 -0700102 newReturnToCallController =
103 new NewReturnToCallController(this, ContactInfoCache.getInstance(context));
Eric Erfanian938468d2017-10-24 14:05:52 -0700104 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800105
Eric Erfanian2ca43182017-08-31 06:57:16 -0700106 IBinder iBinder = super.onBind(intent);
107 Trace.endSection();
108 return iBinder;
Eric Erfanianccca3152017-02-22 16:32:36 -0800109 }
110
111 @Override
112 public boolean onUnbind(Intent intent) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700113 Trace.beginSection("InCallServiceImpl.onUnbind");
Eric Erfanianccca3152017-02-22 16:32:36 -0800114 super.onUnbind(intent);
115
116 InCallPresenter.getInstance().onServiceUnbind();
117 tearDown();
118
Eric Erfanian2ca43182017-08-31 06:57:16 -0700119 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800120 return false;
121 }
122
123 private void tearDown() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700124 Trace.beginSection("InCallServiceImpl.tearDown");
Eric Erfanianccca3152017-02-22 16:32:36 -0800125 Log.v(this, "tearDown");
126 // Tear down the InCall system
Eric Erfanianccca3152017-02-22 16:32:36 -0800127 InCallPresenter.getInstance().tearDown();
yuegc18ad7a2017-10-18 14:45:05 -0700128 TelecomAdapter.getInstance().clearInCallService();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700129 if (returnToCallController != null) {
130 returnToCallController.tearDown();
131 returnToCallController = null;
132 }
Eric Erfanian938468d2017-10-24 14:05:52 -0700133 if (newReturnToCallController != null) {
134 newReturnToCallController.tearDown();
135 newReturnToCallController = null;
136 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700137 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800138 }
139}