blob: 4ab92a797bf91c338e96b94d9f4e138242c01e49 [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
39 @Override
40 public void onCallAudioStateChanged(CallAudioState audioState) {
41 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
42 }
43
44 @Override
45 public void onBringToForeground(boolean showDialpad) {
46 InCallPresenter.getInstance().onBringToForeground(showDialpad);
47 }
48
49 @Override
50 public void onCallAdded(Call call) {
51 InCallPresenter.getInstance().onCallAdded(call);
52 }
53
54 @Override
55 public void onCallRemoved(Call call) {
56 InCallPresenter.getInstance().onCallRemoved(call);
57 }
58
59 @Override
60 public void onCanAddCallChanged(boolean canAddCall) {
61 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
62 }
63
64 @Override
65 public IBinder onBind(Intent intent) {
66 final Context context = getApplicationContext();
67 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
68 InCallPresenter.getInstance()
69 .setUp(
Eric Erfanian83b20212017-05-31 08:53:10 -070070 context,
Eric Erfanianccca3152017-02-22 16:32:36 -080071 CallList.getInstance(),
72 new ExternalCallList(),
73 new StatusBarNotifier(context, contactInfoCache),
74 new ExternalCallNotifier(context, contactInfoCache),
75 contactInfoCache,
76 new ProximitySensor(
Eric Erfanian83b20212017-05-31 08:53:10 -070077 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
78 new FilteredNumberAsyncQueryHandler(context));
Eric Erfanianccca3152017-02-22 16:32:36 -080079 InCallPresenter.getInstance().onServiceBind();
80 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
81 TelecomAdapter.getInstance().setInCallService(this);
82
83 return super.onBind(intent);
84 }
85
86 @Override
87 public boolean onUnbind(Intent intent) {
88 super.onUnbind(intent);
89
90 InCallPresenter.getInstance().onServiceUnbind();
91 tearDown();
92
93 return false;
94 }
95
96 private void tearDown() {
97 Log.v(this, "tearDown");
98 // Tear down the InCall system
99 TelecomAdapter.getInstance().clearInCallService();
100 InCallPresenter.getInstance().tearDown();
101 }
102}