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; |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 27 | import com.android.dialer.feedback.FeedbackComponent; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 28 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 29 | import com.android.incallui.call.CallList; |
| 30 | import com.android.incallui.call.ExternalCallList; |
| 31 | import com.android.incallui.call.TelecomAdapter; |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame^] | 32 | import com.android.incallui.speakeasy.SpeakEasyCallManager; |
| 33 | import com.android.incallui.speakeasy.SpeakEasyComponent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Used to receive updates about calls from the Telecom component. This service is bound to Telecom |
| 37 | * while there exist calls which potentially require UI. This includes ringing (incoming), dialing |
| 38 | * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the |
| 39 | * service triggering InCallActivity (via CallList) to finish soon after. |
| 40 | */ |
| 41 | public class InCallServiceImpl extends InCallService { |
| 42 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 43 | private ReturnToCallController returnToCallController; |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 44 | private NewReturnToCallController newReturnToCallController; |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 45 | private CallList.Listener feedbackListener; |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame^] | 46 | // We only expect there to be one speakEasyCallManager to be instantiated at a time. |
| 47 | // We did not use a singleton SpeakEasyCallManager to avoid holding on to state beyond the |
| 48 | // lifecycle of this service, because the singleton is associated with the state of the |
| 49 | // Application, not this service. |
| 50 | private SpeakEasyCallManager speakEasyCallManager; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 51 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 52 | @Override |
| 53 | public void onCallAudioStateChanged(CallAudioState audioState) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 54 | Trace.beginSection("InCallServiceImpl.onCallAudioStateChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 55 | AudioModeProvider.getInstance().onAudioStateChanged(audioState); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 56 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void onBringToForeground(boolean showDialpad) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 61 | Trace.beginSection("InCallServiceImpl.onBringToForeground"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 62 | InCallPresenter.getInstance().onBringToForeground(showDialpad); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 63 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void onCallAdded(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 68 | Trace.beginSection("InCallServiceImpl.onCallAdded"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 69 | InCallPresenter.getInstance().onCallAdded(call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 70 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void onCallRemoved(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 75 | Trace.beginSection("InCallServiceImpl.onCallRemoved"); |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame^] | 76 | speakEasyCallManager.onCallRemoved(CallList.getInstance().getDialerCallFromTelecomCall(call)); |
| 77 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 78 | InCallPresenter.getInstance().onCallRemoved(call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 79 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public void onCanAddCallChanged(boolean canAddCall) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 84 | Trace.beginSection("InCallServiceImpl.onCanAddCallChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 85 | InCallPresenter.getInstance().onCanAddCallChanged(canAddCall); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 86 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame^] | 90 | public void onCreate() { |
| 91 | super.onCreate(); |
| 92 | this.speakEasyCallManager = SpeakEasyComponent.get(this).speakEasyCallManager(); |
| 93 | } |
| 94 | |
| 95 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 96 | public IBinder onBind(Intent intent) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 97 | Trace.beginSection("InCallServiceImpl.onBind"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 98 | final Context context = getApplicationContext(); |
| 99 | final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 100 | AudioModeProvider.getInstance().initializeAudioState(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 101 | InCallPresenter.getInstance() |
| 102 | .setUp( |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 103 | context, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 104 | CallList.getInstance(), |
| 105 | new ExternalCallList(), |
| 106 | new StatusBarNotifier(context, contactInfoCache), |
| 107 | new ExternalCallNotifier(context, contactInfoCache), |
| 108 | contactInfoCache, |
| 109 | new ProximitySensor( |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 110 | context, AudioModeProvider.getInstance(), new AccelerometerListener(context)), |
| 111 | new FilteredNumberAsyncQueryHandler(context)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 112 | InCallPresenter.getInstance().onServiceBind(); |
| 113 | InCallPresenter.getInstance().maybeStartRevealAnimation(intent); |
| 114 | TelecomAdapter.getInstance().setInCallService(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 115 | if (ReturnToCallController.isEnabled(this)) { |
| 116 | returnToCallController = new ReturnToCallController(this); |
| 117 | } |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 118 | if (NewReturnToCallController.isEnabled(this)) { |
yueg | a5a08d8 | 2017-10-31 14:11:53 -0700 | [diff] [blame] | 119 | newReturnToCallController = |
| 120 | new NewReturnToCallController(this, ContactInfoCache.getInstance(context)); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 121 | } |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 122 | feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener(); |
| 123 | CallList.getInstance().addListener(feedbackListener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 124 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 125 | IBinder iBinder = super.onBind(intent); |
| 126 | Trace.endSection(); |
| 127 | return iBinder; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public boolean onUnbind(Intent intent) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 132 | Trace.beginSection("InCallServiceImpl.onUnbind"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 133 | super.onUnbind(intent); |
| 134 | |
| 135 | InCallPresenter.getInstance().onServiceUnbind(); |
| 136 | tearDown(); |
| 137 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 138 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 139 | return false; |
| 140 | } |
| 141 | |
| 142 | private void tearDown() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 143 | Trace.beginSection("InCallServiceImpl.tearDown"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 144 | Log.v(this, "tearDown"); |
| 145 | // Tear down the InCall system |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 146 | InCallPresenter.getInstance().tearDown(); |
yueg | c18ad7a | 2017-10-18 14:45:05 -0700 | [diff] [blame] | 147 | TelecomAdapter.getInstance().clearInCallService(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 148 | if (returnToCallController != null) { |
| 149 | returnToCallController.tearDown(); |
| 150 | returnToCallController = null; |
| 151 | } |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 152 | if (newReturnToCallController != null) { |
| 153 | newReturnToCallController.tearDown(); |
| 154 | newReturnToCallController = null; |
| 155 | } |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 156 | if (feedbackListener != null) { |
| 157 | CallList.getInstance().removeListener(feedbackListener); |
| 158 | feedbackListener = null; |
| 159 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 160 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 161 | } |
| 162 | } |