1/*
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.telecom.InCallService;
20import android.telecom.Phone;
21
22/**
23 * Used to receive updates about calls from the Telecomm component.  This service is bound to
24 * Telecomm while there exist calls which potentially require UI. This includes ringing (incoming),
25 * dialing (outgoing), and active calls. When the last call is disconnected, Telecomm will unbind to
26 * the service triggering InCallActivity (via CallList) to finish soon after.
27 */
28public class InCallServiceImpl extends InCallService {
29
30    @Override
31    public void onPhoneCreated(Phone phone) {
32        Log.v(this, "onPhoneCreated");
33        CallList.getInstance().setPhone(phone);
34        AudioModeProvider.getInstance().setPhone(phone);
35        TelecomAdapter.getInstance().setPhone(phone);
36        InCallPresenter.getInstance().setPhone(phone);
37        InCallPresenter.getInstance().setUp(
38                getApplicationContext(),
39                CallList.getInstance(),
40                AudioModeProvider.getInstance());
41        TelecomAdapter.getInstance().setContext(InCallServiceImpl.this);
42    }
43
44    @Override
45    public void onPhoneDestroyed(Phone phone) {
46        Log.v(this, "onPhoneDestroyed");
47        // Tear down the InCall system
48        CallList.getInstance().clearPhone();
49        AudioModeProvider.getInstance().clearPhone();
50        TelecomAdapter.getInstance().clearPhone();
51        TelecomAdapter.getInstance().setContext(null);
52        CallList.getInstance().clearOnDisconnect();
53        InCallPresenter.getInstance().tearDown();
54    }
55}
56