blob: 4fed014c63ecc3ab575fe829d5d3121539e66b7f [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 Erfanian8369df02017-05-03 10:27:13 -070025import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080026import com.android.incallui.call.CallList;
27import com.android.incallui.call.ExternalCallList;
28import com.android.incallui.call.TelecomAdapter;
29
30/**
31 * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
32 * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
33 * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
34 * service triggering InCallActivity (via CallList) to finish soon after.
35 */
36public class InCallServiceImpl extends InCallService {
37
38 @Override
39 public void onCallAudioStateChanged(CallAudioState audioState) {
40 AudioModeProvider.getInstance().onAudioStateChanged(audioState);
41 }
42
43 @Override
44 public void onBringToForeground(boolean showDialpad) {
45 InCallPresenter.getInstance().onBringToForeground(showDialpad);
46 }
47
48 @Override
49 public void onCallAdded(Call call) {
50 InCallPresenter.getInstance().onCallAdded(call);
51 }
52
53 @Override
54 public void onCallRemoved(Call call) {
55 InCallPresenter.getInstance().onCallRemoved(call);
56 }
57
58 @Override
59 public void onCanAddCallChanged(boolean canAddCall) {
60 InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
61 }
62
63 @Override
64 public IBinder onBind(Intent intent) {
65 final Context context = getApplicationContext();
66 final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
67 InCallPresenter.getInstance()
68 .setUp(
69 getApplicationContext(),
70 CallList.getInstance(),
71 new ExternalCallList(),
72 new StatusBarNotifier(context, contactInfoCache),
73 new ExternalCallNotifier(context, contactInfoCache),
74 contactInfoCache,
75 new ProximitySensor(
76 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)));
77 InCallPresenter.getInstance().onServiceBind();
78 InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
79 TelecomAdapter.getInstance().setInCallService(this);
80
81 return super.onBind(intent);
82 }
83
84 @Override
85 public boolean onUnbind(Intent intent) {
86 super.onUnbind(intent);
87
88 InCallPresenter.getInstance().onServiceUnbind();
89 tearDown();
90
91 return false;
92 }
93
94 private void tearDown() {
95 Log.v(this, "tearDown");
96 // Tear down the InCall system
97 TelecomAdapter.getInstance().clearInCallService();
98 InCallPresenter.getInstance().tearDown();
99 }
100}