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 
17 package com.android.incallui;
18 
19 import android.content.Intent;
20 import android.os.IBinder;
21 import android.telecom.InCallService;
22 import android.telecom.Phone;
23 
24 /**
25  * Used to receive updates about calls from the Telecomm component.  This service is bound to
26  * Telecomm while there exist calls which potentially require UI. This includes ringing (incoming),
27  * dialing (outgoing), and active calls. When the last call is disconnected, Telecomm will unbind to
28  * the service triggering InCallActivity (via CallList) to finish soon after.
29  */
30 public class InCallServiceImpl extends InCallService {
31 
32     @Override
onPhoneCreated(Phone phone)33     public void onPhoneCreated(Phone phone) {
34         Log.v(this, "onPhoneCreated");
35         CallList.getInstance().setPhone(phone);
36         AudioModeProvider.getInstance().setPhone(phone);
37         TelecomAdapter.getInstance().setPhone(phone);
38         InCallPresenter.getInstance().setPhone(phone);
39         TelecomAdapter.getInstance().setContext(InCallServiceImpl.this);
40     }
41 
42     @Override
onPhoneDestroyed(Phone phone)43     public void onPhoneDestroyed(Phone phone) {
44         Log.v(this, "onPhoneDestroyed");
45         // Tear down the InCall system
46         CallList.getInstance().clearPhone();
47         AudioModeProvider.getInstance().clearPhone();
48         TelecomAdapter.getInstance().clearPhone();
49         TelecomAdapter.getInstance().setContext(null);
50         CallList.getInstance().clearOnDisconnect();
51         InCallPresenter.getInstance().tearDown();
52     }
53 
54     @Override
onBind(Intent intent)55     public IBinder onBind(Intent intent) {
56         InCallPresenter.getInstance().setUp(
57                 getApplicationContext(),
58                 CallList.getInstance(),
59                 AudioModeProvider.getInstance());
60         InCallPresenter.getInstance().onServiceBind();
61         InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
62         return super.onBind(intent);
63     }
64 
65     @Override
onUnbind(Intent intent)66     public boolean onUnbind(Intent intent) {
67         InCallPresenter.getInstance().onServiceUnbind();
68         return super.onUnbind(intent);
69     }
70 }
71