Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 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.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.os.IBinder; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 22 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 23 | import android.telecom.Call; |
| 24 | import android.telecom.CallAudioState; |
| 25 | import android.telecom.InCallService; |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 26 | import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 27 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 28 | import com.android.incallui.call.CallList; |
| 29 | import com.android.incallui.call.ExternalCallList; |
| 30 | import com.android.incallui.call.TelecomAdapter; |
| 31 | |
| 32 | /** |
| 33 | * Used to receive updates about calls from the Telecom component. This service is bound to Telecom |
| 34 | * while there exist calls which potentially require UI. This includes ringing (incoming), dialing |
| 35 | * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the |
| 36 | * service triggering InCallActivity (via CallList) to finish soon after. |
| 37 | */ |
| 38 | public class InCallServiceImpl extends InCallService { |
| 39 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 40 | private ReturnToCallController returnToCallController; |
| 41 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 42 | @Override |
| 43 | public void onCallAudioStateChanged(CallAudioState audioState) { |
| 44 | AudioModeProvider.getInstance().onAudioStateChanged(audioState); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void onBringToForeground(boolean showDialpad) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 49 | Trace.beginSection("InCallServiceImpl.onBringToForeground"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 50 | InCallPresenter.getInstance().onBringToForeground(showDialpad); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 51 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void onCallAdded(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 56 | Trace.beginSection("InCallServiceImpl.onCallAdded"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 57 | InCallPresenter.getInstance().onCallAdded(call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 58 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void onCallRemoved(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 63 | Trace.beginSection("InCallServiceImpl.onCallRemoved"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 64 | InCallPresenter.getInstance().onCallRemoved(call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 65 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void onCanAddCallChanged(boolean canAddCall) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 70 | Trace.beginSection("InCallServiceImpl.onCanAddCallChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 71 | InCallPresenter.getInstance().onCanAddCallChanged(canAddCall); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 72 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public IBinder onBind(Intent intent) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 77 | Trace.beginSection("InCallServiceImpl.onBind"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 78 | final Context context = getApplicationContext(); |
| 79 | final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 80 | AudioModeProvider.getInstance().initializeAudioState(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 81 | InCallPresenter.getInstance() |
| 82 | .setUp( |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 83 | context, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 84 | CallList.getInstance(), |
| 85 | new ExternalCallList(), |
| 86 | new StatusBarNotifier(context, contactInfoCache), |
| 87 | new ExternalCallNotifier(context, contactInfoCache), |
| 88 | contactInfoCache, |
| 89 | new ProximitySensor( |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 90 | context, AudioModeProvider.getInstance(), new AccelerometerListener(context)), |
| 91 | new FilteredNumberAsyncQueryHandler(context)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 92 | InCallPresenter.getInstance().onServiceBind(); |
| 93 | InCallPresenter.getInstance().maybeStartRevealAnimation(intent); |
| 94 | TelecomAdapter.getInstance().setInCallService(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 95 | if (ReturnToCallController.isEnabled(this)) { |
| 96 | returnToCallController = new ReturnToCallController(this); |
| 97 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 98 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 99 | IBinder iBinder = super.onBind(intent); |
| 100 | Trace.endSection(); |
| 101 | return iBinder; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean onUnbind(Intent intent) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 106 | Trace.beginSection("InCallServiceImpl.onUnbind"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 107 | super.onUnbind(intent); |
| 108 | |
| 109 | InCallPresenter.getInstance().onServiceUnbind(); |
| 110 | tearDown(); |
| 111 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 112 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 113 | return false; |
| 114 | } |
| 115 | |
| 116 | private void tearDown() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 117 | Trace.beginSection("InCallServiceImpl.tearDown"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 118 | Log.v(this, "tearDown"); |
| 119 | // Tear down the InCall system |
| 120 | TelecomAdapter.getInstance().clearInCallService(); |
| 121 | InCallPresenter.getInstance().tearDown(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 122 | if (returnToCallController != null) { |
| 123 | returnToCallController.tearDown(); |
| 124 | returnToCallController = null; |
| 125 | } |
| 126 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 127 | } |
| 128 | } |