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 | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 43 | private NewReturnToCallController newReturnToCallController; |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 44 | private CallList.Listener feedbackListener; |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame] | 45 | // We only expect there to be one speakEasyCallManager to be instantiated at a time. |
| 46 | // We did not use a singleton SpeakEasyCallManager to avoid holding on to state beyond the |
| 47 | // lifecycle of this service, because the singleton is associated with the state of the |
| 48 | // Application, not this service. |
| 49 | private SpeakEasyCallManager speakEasyCallManager; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 50 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 51 | @Override |
| 52 | public void onCallAudioStateChanged(CallAudioState audioState) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 53 | Trace.beginSection("InCallServiceImpl.onCallAudioStateChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 54 | AudioModeProvider.getInstance().onAudioStateChanged(audioState); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 55 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onBringToForeground(boolean showDialpad) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 60 | Trace.beginSection("InCallServiceImpl.onBringToForeground"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 61 | InCallPresenter.getInstance().onBringToForeground(showDialpad); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 62 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void onCallAdded(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 67 | Trace.beginSection("InCallServiceImpl.onCallAdded"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 68 | InCallPresenter.getInstance().onCallAdded(call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 69 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void onCallRemoved(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 74 | Trace.beginSection("InCallServiceImpl.onCallRemoved"); |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame] | 75 | speakEasyCallManager.onCallRemoved(CallList.getInstance().getDialerCallFromTelecomCall(call)); |
| 76 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 77 | InCallPresenter.getInstance().onCallRemoved(call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 78 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void onCanAddCallChanged(boolean canAddCall) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 83 | Trace.beginSection("InCallServiceImpl.onCanAddCallChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 84 | InCallPresenter.getInstance().onCanAddCallChanged(canAddCall); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 85 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @Override |
erfanian | a792792 | 2018-02-02 16:36:11 -0800 | [diff] [blame] | 89 | public void onCreate() { |
| 90 | super.onCreate(); |
| 91 | this.speakEasyCallManager = SpeakEasyComponent.get(this).speakEasyCallManager(); |
| 92 | } |
| 93 | |
| 94 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 95 | public IBinder onBind(Intent intent) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 96 | Trace.beginSection("InCallServiceImpl.onBind"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 97 | final Context context = getApplicationContext(); |
| 98 | final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 99 | AudioModeProvider.getInstance().initializeAudioState(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 100 | InCallPresenter.getInstance() |
| 101 | .setUp( |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 102 | context, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 103 | CallList.getInstance(), |
| 104 | new ExternalCallList(), |
| 105 | new StatusBarNotifier(context, contactInfoCache), |
| 106 | new ExternalCallNotifier(context, contactInfoCache), |
| 107 | contactInfoCache, |
| 108 | new ProximitySensor( |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 109 | context, AudioModeProvider.getInstance(), new AccelerometerListener(context)), |
| 110 | new FilteredNumberAsyncQueryHandler(context)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 111 | InCallPresenter.getInstance().onServiceBind(); |
| 112 | InCallPresenter.getInstance().maybeStartRevealAnimation(intent); |
| 113 | TelecomAdapter.getInstance().setInCallService(this); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 114 | if (NewReturnToCallController.isEnabled(this)) { |
yueg | a5a08d8 | 2017-10-31 14:11:53 -0700 | [diff] [blame] | 115 | newReturnToCallController = |
| 116 | new NewReturnToCallController(this, ContactInfoCache.getInstance(context)); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 117 | } |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 118 | feedbackListener = FeedbackComponent.get(context).getCallFeedbackListener(); |
| 119 | CallList.getInstance().addListener(feedbackListener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 120 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 121 | IBinder iBinder = super.onBind(intent); |
| 122 | Trace.endSection(); |
| 123 | return iBinder; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public boolean onUnbind(Intent intent) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 128 | Trace.beginSection("InCallServiceImpl.onUnbind"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 129 | super.onUnbind(intent); |
| 130 | |
| 131 | InCallPresenter.getInstance().onServiceUnbind(); |
| 132 | tearDown(); |
| 133 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 134 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | |
| 138 | private void tearDown() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 139 | Trace.beginSection("InCallServiceImpl.tearDown"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 140 | Log.v(this, "tearDown"); |
| 141 | // Tear down the InCall system |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 142 | InCallPresenter.getInstance().tearDown(); |
yueg | c18ad7a | 2017-10-18 14:45:05 -0700 | [diff] [blame] | 143 | TelecomAdapter.getInstance().clearInCallService(); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 144 | if (newReturnToCallController != null) { |
| 145 | newReturnToCallController.tearDown(); |
| 146 | newReturnToCallController = null; |
| 147 | } |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 148 | if (feedbackListener != null) { |
| 149 | CallList.getInstance().removeListener(feedbackListener); |
| 150 | feedbackListener = null; |
| 151 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 152 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 153 | } |
| 154 | } |