blob: 1653334a19e4d902c3d12318b8b735b1df922fd6 [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 Erfanian91ce7d22017-06-05 13:35:02 -070026import com.android.dialer.common.ConfigProviderBindings;
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 Erfanian91ce7d22017-06-05 13:35:02 -070040 private ReturnToCallController returnToCallController;
41
Eric Erfanianccca3152017-02-22 16:32:36 -080042 @Override
43 public void onCallAudioStateChanged(CallAudioState audioState) {
44 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
45 }
46
47 @Override
48 public void onBringToForeground(boolean showDialpad) {
49 InCallPresenter.getInstance().onBringToForeground(showDialpad);
50 }
51
52 @Override
53 public void onCallAdded(Call call) {
54 InCallPresenter.getInstance().onCallAdded(call);
55 }
56
57 @Override
58 public void onCallRemoved(Call call) {
59 InCallPresenter.getInstance().onCallRemoved(call);
60 }
61
62 @Override
63 public void onCanAddCallChanged(boolean canAddCall) {
64 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
65 }
66
67 @Override
68 public IBinder onBind(Intent intent) {
69 final Context context = getApplicationContext();
70 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
71 InCallPresenter.getInstance()
72 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -070073 context,
Eric Erfanianccca3152017-02-22 16:32:36 -080074 CallList.getInstance(),
75 new ExternalCallList(),
76 new StatusBarNotifier(context, contactInfoCache),
77 new ExternalCallNotifier(context, contactInfoCache),
78 contactInfoCache,
79 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -070080 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
81 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -080082 InCallPresenter.getInstance().onServiceBind();
83 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
84 TelecomAdapter.getInstance().setInCallService(this);
Eric Erfanian91ce7d22017-06-05 13:35:02 -070085 if (ConfigProviderBindings.get(this).getBoolean("enable_return_to_call_bubble", false)) {
86 returnToCallController = new ReturnToCallController(this);
87 }
Eric Erfanianccca3152017-02-22 16:32:36 -080088
89 return super.onBind(intent);
90 }
91
92 @Override
93 public boolean onUnbind(Intent intent) {
94 super.onUnbind(intent);
95
96 InCallPresenter.getInstance().onServiceUnbind();
97 tearDown();
98
99 return false;
100 }
101
102 private void tearDown() {
103 Log.v(this, "tearDown");
104 // Tear down the InCall system
105 TelecomAdapter.getInstance().clearInCallService();
106 InCallPresenter.getInstance().tearDown();
Eric Erfanian91ce7d22017-06-05 13:35:02 -0700107 if (returnToCallController != null) {
108 returnToCallController.tearDown();
109 returnToCallController = null;
110 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800111 }
112}