blob: d2b0297417e5c236ecd9f404af28dd60699250a6 [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;
22import android.telecom.Call;
23import android.telecom.CallAudioState;
24import android.telecom.InCallService;
Eric Erfanian83b20212017-05-31 08:53:10 -070025import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
Eric Erfanian8369df02017-05-03 10:27:13 -070026import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080027import com.android.incallui.call.CallList;
28import com.android.incallui.call.ExternalCallList;
29import com.android.incallui.call.TelecomAdapter;
30
31/**
32 * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
33 * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
34 * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
35 * service triggering InCallActivity (via CallList) to finish soon after.
36 */
37public class InCallServiceImpl extends InCallService {
38
Eric Erfanian91ce7d22017-06-05 13:35:02 -070039 private ReturnToCallController returnToCallController;
40
Eric Erfanianccca3152017-02-22 16:32:36 -080041 @Override
42 public void onCallAudioStateChanged(CallAudioState audioState) {
43 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
44 }
45
46 @Override
47 public void onBringToForeground(boolean showDialpad) {
48 InCallPresenter.getInstance().onBringToForeground(showDialpad);
49 }
50
51 @Override
52 public void onCallAdded(Call call) {
53 InCallPresenter.getInstance().onCallAdded(call);
54 }
55
56 @Override
57 public void onCallRemoved(Call call) {
58 InCallPresenter.getInstance().onCallRemoved(call);
59 }
60
61 @Override
62 public void onCanAddCallChanged(boolean canAddCall) {
63 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
64 }
65
66 @Override
67 public IBinder onBind(Intent intent) {
68 final Context context = getApplicationContext();
69 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
70 InCallPresenter.getInstance()
71 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -070072 context,
Eric Erfanianccca3152017-02-22 16:32:36 -080073 CallList.getInstance(),
74 new ExternalCallList(),
75 new StatusBarNotifier(context, contactInfoCache),
76 new ExternalCallNotifier(context, contactInfoCache),
77 contactInfoCache,
78 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -070079 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
80 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -080081 InCallPresenter.getInstance().onServiceBind();
82 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
83 TelecomAdapter.getInstance().setInCallService(this);
Eric Erfanianea7890c2017-06-19 12:40:59 -070084 if (ReturnToCallController.isEnabled(this)) {
Eric Erfanian91ce7d22017-06-05 13:35:02 -070085 returnToCallController = new ReturnToCallController(this);
86 }
Eric Erfanianccca3152017-02-22 16:32:36 -080087
88 return super.onBind(intent);
89 }
90
91 @Override
92 public boolean onUnbind(Intent intent) {
93 super.onUnbind(intent);
94
95 InCallPresenter.getInstance().onServiceUnbind();
96 tearDown();
97
98 return false;
99 }
100
101 private void tearDown() {
102 Log.v(this, "tearDown");
103 // Tear down the InCall system
104 TelecomAdapter.getInstance().clearInCallService();
105 InCallPresenter.getInstance().tearDown();
Eric Erfanian91ce7d22017-06-05 13:35:02 -0700106 if (returnToCallController != null) {
107 returnToCallController.tearDown();
108 returnToCallController = null;
109 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800110 }
111}