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