Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 20 | import android.os.Bundle; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 21 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 22 | import android.support.v4.app.Fragment; |
| 23 | import android.support.v4.os.UserManagerCompat; |
| 24 | import android.telecom.CallAudioState; |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 25 | import android.telecom.PhoneAccountHandle; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 26 | import com.android.contacts.common.compat.CallCompat; |
| 27 | import com.android.dialer.common.Assert; |
| 28 | import com.android.dialer.common.LogUtil; |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 29 | import com.android.dialer.common.concurrent.DialerExecutorComponent; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 30 | import com.android.dialer.logging.DialerImpression; |
twyen | fc1f9cf | 2017-11-27 13:22:48 -0800 | [diff] [blame] | 31 | import com.android.dialer.logging.DialerImpression.Type; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 32 | import com.android.dialer.logging.Logger; |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 33 | import com.android.dialer.telecom.TelecomUtil; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 34 | import com.android.incallui.InCallCameraManager.Listener; |
| 35 | import com.android.incallui.InCallPresenter.CanAddCallListener; |
| 36 | import com.android.incallui.InCallPresenter.InCallDetailsListener; |
| 37 | import com.android.incallui.InCallPresenter.InCallState; |
| 38 | import com.android.incallui.InCallPresenter.InCallStateListener; |
| 39 | import com.android.incallui.InCallPresenter.IncomingCallListener; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 40 | import com.android.incallui.audiomode.AudioModeProvider; |
| 41 | import com.android.incallui.audiomode.AudioModeProvider.AudioModeListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 42 | import com.android.incallui.call.CallList; |
| 43 | import com.android.incallui.call.DialerCall; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 44 | import com.android.incallui.call.DialerCall.CameraDirection; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 45 | import com.android.incallui.call.TelecomAdapter; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 46 | import com.android.incallui.call.state.DialerCallState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 47 | import com.android.incallui.incall.protocol.InCallButtonIds; |
| 48 | import com.android.incallui.incall.protocol.InCallButtonUi; |
| 49 | import com.android.incallui.incall.protocol.InCallButtonUiDelegate; |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 50 | import com.android.incallui.multisim.SwapSimWorker; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 51 | import com.android.incallui.videotech.utils.VideoUtils; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 52 | |
| 53 | /** Logic for call buttons. */ |
| 54 | public class CallButtonPresenter |
| 55 | implements InCallStateListener, |
| 56 | AudioModeListener, |
| 57 | IncomingCallListener, |
| 58 | InCallDetailsListener, |
| 59 | CanAddCallListener, |
| 60 | Listener, |
| 61 | InCallButtonUiDelegate { |
| 62 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 63 | private final Context context; |
| 64 | private InCallButtonUi inCallButtonUi; |
| 65 | private DialerCall call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 66 | private boolean isInCallButtonUiReady; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 67 | private PhoneAccountHandle otherAccount; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 68 | |
| 69 | public CallButtonPresenter(Context context) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 70 | this.context = context.getApplicationContext(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void onInCallButtonUiReady(InCallButtonUi ui) { |
| 75 | Assert.checkState(!isInCallButtonUiReady); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 76 | inCallButtonUi = ui; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 77 | AudioModeProvider.getInstance().addListener(this); |
| 78 | |
| 79 | // register for call state changes last |
| 80 | final InCallPresenter inCallPresenter = InCallPresenter.getInstance(); |
| 81 | inCallPresenter.addListener(this); |
| 82 | inCallPresenter.addIncomingCallListener(this); |
| 83 | inCallPresenter.addDetailsListener(this); |
| 84 | inCallPresenter.addCanAddCallListener(this); |
| 85 | inCallPresenter.getInCallCameraManager().addCameraSelectionListener(this); |
| 86 | |
| 87 | // Update the buttons state immediately for the current call |
| 88 | onStateChange(InCallState.NO_CALLS, inCallPresenter.getInCallState(), CallList.getInstance()); |
| 89 | isInCallButtonUiReady = true; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void onInCallButtonUiUnready() { |
| 94 | Assert.checkState(isInCallButtonUiReady); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 95 | inCallButtonUi = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 96 | InCallPresenter.getInstance().removeListener(this); |
| 97 | AudioModeProvider.getInstance().removeListener(this); |
| 98 | InCallPresenter.getInstance().removeIncomingCallListener(this); |
| 99 | InCallPresenter.getInstance().removeDetailsListener(this); |
| 100 | InCallPresenter.getInstance().getInCallCameraManager().removeCameraSelectionListener(this); |
| 101 | InCallPresenter.getInstance().removeCanAddCallListener(this); |
| 102 | isInCallButtonUiReady = false; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onStateChange(InCallState oldState, InCallState newState, CallList callList) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 107 | Trace.beginSection("CallButtonPresenter.onStateChange"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 108 | if (newState == InCallState.OUTGOING) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 109 | call = callList.getOutgoingCall(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 110 | } else if (newState == InCallState.INCALL) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 111 | call = callList.getActiveOrBackgroundCall(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 112 | |
| 113 | // When connected to voice mail, automatically shows the dialpad. |
| 114 | // (On previous releases we showed it when in-call shows up, before waiting for |
| 115 | // OUTGOING. We may want to do that once we start showing "Voice mail" label on |
| 116 | // the dialpad too.) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 117 | if (oldState == InCallState.OUTGOING && call != null) { |
| 118 | if (call.isVoiceMailNumber() && getActivity() != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 119 | getActivity().showDialpadFragment(true /* show */, true /* animate */); |
| 120 | } |
| 121 | } |
| 122 | } else if (newState == InCallState.INCOMING) { |
| 123 | if (getActivity() != null) { |
| 124 | getActivity().showDialpadFragment(false /* show */, true /* animate */); |
| 125 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 126 | call = callList.getIncomingCall(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 127 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 128 | call = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 129 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 130 | updateUi(newState, call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 131 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Updates the user interface in response to a change in the details of a call. Currently handles |
| 136 | * changes to the call buttons in response to a change in the details for a call. This is |
| 137 | * important to ensure changes to the active call are reflected in the available buttons. |
| 138 | * |
| 139 | * @param call The active call. |
| 140 | * @param details The call details. |
| 141 | */ |
| 142 | @Override |
| 143 | public void onDetailsChanged(DialerCall call, android.telecom.Call.Details details) { |
| 144 | // Only update if the changes are for the currently active call |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 145 | if (inCallButtonUi != null && call != null && call.equals(this.call)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 146 | updateButtonsState(call); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void onIncomingCall(InCallState oldState, InCallState newState, DialerCall call) { |
| 152 | onStateChange(oldState, newState, CallList.getInstance()); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public void onCanAddCallChanged(boolean canAddCall) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 157 | if (inCallButtonUi != null && call != null) { |
| 158 | updateButtonsState(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void onAudioStateChanged(CallAudioState audioState) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 164 | if (inCallButtonUi != null) { |
| 165 | inCallButtonUi.setAudioState(audioState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public CallAudioState getCurrentAudioState() { |
| 171 | return AudioModeProvider.getInstance().getAudioState(); |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void setAudioRoute(int route) { |
| 176 | LogUtil.i( |
| 177 | "CallButtonPresenter.setAudioRoute", |
| 178 | "sending new audio route: " + CallAudioState.audioRouteToString(route)); |
| 179 | TelecomAdapter.getInstance().setAudioRoute(route); |
| 180 | } |
| 181 | |
| 182 | /** Function assumes that bluetooth is not supported. */ |
| 183 | @Override |
| 184 | public void toggleSpeakerphone() { |
| 185 | // This function should not be called if bluetooth is available. |
| 186 | CallAudioState audioState = getCurrentAudioState(); |
| 187 | if (0 != (CallAudioState.ROUTE_BLUETOOTH & audioState.getSupportedRouteMask())) { |
| 188 | // It's clear the UI is wrong, so update the supported mode once again. |
| 189 | LogUtil.e( |
| 190 | "CallButtonPresenter", "toggling speakerphone not allowed when bluetooth supported."); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 191 | inCallButtonUi.setAudioState(audioState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
| 195 | int newRoute; |
| 196 | if (audioState.getRoute() == CallAudioState.ROUTE_SPEAKER) { |
| 197 | newRoute = CallAudioState.ROUTE_WIRED_OR_EARPIECE; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 198 | Logger.get(context) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 199 | .logCallImpression( |
| 200 | DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_WIRED_OR_EARPIECE, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 201 | call.getUniqueCallId(), |
| 202 | call.getTimeAddedMs()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 203 | } else { |
| 204 | newRoute = CallAudioState.ROUTE_SPEAKER; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 205 | Logger.get(context) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 206 | .logCallImpression( |
| 207 | DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_SPEAKERPHONE, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 208 | call.getUniqueCallId(), |
| 209 | call.getTimeAddedMs()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | setAudioRoute(newRoute); |
| 213 | } |
| 214 | |
| 215 | @Override |
Eric Erfanian | 9a090c8 | 2017-03-16 19:22:24 -0700 | [diff] [blame] | 216 | public void muteClicked(boolean checked, boolean clickedByUser) { |
| 217 | LogUtil.i( |
| 218 | "CallButtonPresenter", "turning on mute: %s, clicked by user: %s", checked, clickedByUser); |
| 219 | if (clickedByUser) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 220 | Logger.get(context) |
Eric Erfanian | 9a090c8 | 2017-03-16 19:22:24 -0700 | [diff] [blame] | 221 | .logCallImpression( |
| 222 | checked |
| 223 | ? DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_MUTE |
| 224 | : DialerImpression.Type.IN_CALL_SCREEN_TURN_OFF_MUTE, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 225 | call.getUniqueCallId(), |
| 226 | call.getTimeAddedMs()); |
Eric Erfanian | 9a090c8 | 2017-03-16 19:22:24 -0700 | [diff] [blame] | 227 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 228 | TelecomAdapter.getInstance().mute(checked); |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public void holdClicked(boolean checked) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 233 | if (call == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 234 | return; |
| 235 | } |
| 236 | if (checked) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 237 | LogUtil.i("CallButtonPresenter", "putting the call on hold: " + call); |
| 238 | call.hold(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 239 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 240 | LogUtil.i("CallButtonPresenter", "removing the call from hold: " + call); |
| 241 | call.unhold(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public void swapClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 247 | if (call == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 248 | return; |
| 249 | } |
| 250 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 251 | LogUtil.i("CallButtonPresenter", "swapping the call: " + call); |
| 252 | TelecomAdapter.getInstance().swap(call.getId()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public void mergeClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 257 | Logger.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 258 | .logCallImpression( |
| 259 | DialerImpression.Type.IN_CALL_MERGE_BUTTON_PRESSED, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 260 | call.getUniqueCallId(), |
| 261 | call.getTimeAddedMs()); |
| 262 | TelecomAdapter.getInstance().merge(call.getId()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public void addCallClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 267 | Logger.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 268 | .logCallImpression( |
| 269 | DialerImpression.Type.IN_CALL_ADD_CALL_BUTTON_PRESSED, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 270 | call.getUniqueCallId(), |
| 271 | call.getTimeAddedMs()); |
Sekine Yasuaki | a702084 | 2018-05-31 17:10:12 +0900 | [diff] [blame^] | 272 | InCallPresenter.getInstance().addCallClicked(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void showDialpadClicked(boolean checked) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 277 | Logger.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 278 | .logCallImpression( |
| 279 | DialerImpression.Type.IN_CALL_SHOW_DIALPAD_BUTTON_PRESSED, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 280 | call.getUniqueCallId(), |
| 281 | call.getTimeAddedMs()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 282 | LogUtil.v("CallButtonPresenter", "show dialpad " + String.valueOf(checked)); |
| 283 | getActivity().showDialpadFragment(checked /* show */, true /* animate */); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void changeToVideoClicked() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 288 | LogUtil.enterBlock("CallButtonPresenter.changeToVideoClicked"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 289 | Logger.get(context) |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 290 | .logCallImpression( |
| 291 | DialerImpression.Type.VIDEO_CALL_UPGRADE_REQUESTED, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 292 | call.getUniqueCallId(), |
| 293 | call.getTimeAddedMs()); |
| 294 | call.getVideoTech().upgradeToVideo(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | @Override |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 298 | public void changeToRttClicked() { |
| 299 | LogUtil.enterBlock("CallButtonPresenter.changeToRttClicked"); |
| 300 | call.sendRttUpgradeRequest(); |
| 301 | } |
| 302 | |
| 303 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 304 | public void onEndCallClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 305 | LogUtil.i("CallButtonPresenter.onEndCallClicked", "call: " + call); |
| 306 | if (call != null) { |
| 307 | call.disconnect(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void showAudioRouteSelector() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 313 | inCallButtonUi.showAudioRouteSelector(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 314 | } |
| 315 | |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 316 | @Override |
| 317 | public void swapSimClicked() { |
| 318 | LogUtil.enterBlock("CallButtonPresenter.swapSimClicked"); |
twyen | fc1f9cf | 2017-11-27 13:22:48 -0800 | [diff] [blame] | 319 | Logger.get(getContext()).logImpression(Type.DUAL_SIM_CHANGE_SIM_PRESSED); |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 320 | SwapSimWorker worker = |
| 321 | new SwapSimWorker( |
| 322 | getContext(), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 323 | call, |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 324 | InCallPresenter.getInstance().getCallList(), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 325 | otherAccount, |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 326 | InCallPresenter.getInstance().acquireInCallUiLock("swapSim")); |
| 327 | DialerExecutorComponent.get(getContext()) |
| 328 | .dialerExecutorFactory() |
| 329 | .createNonUiTaskBuilder(worker) |
| 330 | .build() |
| 331 | .executeParallel(null); |
| 332 | } |
| 333 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 334 | /** |
| 335 | * Switches the camera between the front-facing and back-facing camera. |
| 336 | * |
| 337 | * @param useFrontFacingCamera True if we should switch to using the front-facing camera, or false |
| 338 | * if we should switch to using the back-facing camera. |
| 339 | */ |
| 340 | @Override |
| 341 | public void switchCameraClicked(boolean useFrontFacingCamera) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 342 | updateCamera(useFrontFacingCamera); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void toggleCameraClicked() { |
| 347 | LogUtil.i("CallButtonPresenter.toggleCameraClicked", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 348 | if (call == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 349 | return; |
| 350 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 351 | Logger.get(context) |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 352 | .logCallImpression( |
| 353 | DialerImpression.Type.IN_CALL_SCREEN_SWAP_CAMERA, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 354 | call.getUniqueCallId(), |
| 355 | call.getTimeAddedMs()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 356 | switchCameraClicked( |
| 357 | !InCallPresenter.getInstance().getInCallCameraManager().isUsingFrontFacingCamera()); |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Stop or start client's video transmission. |
| 362 | * |
| 363 | * @param pause True if pausing the local user's video, or false if starting the local user's |
| 364 | * video. |
| 365 | */ |
| 366 | @Override |
| 367 | public void pauseVideoClicked(boolean pause) { |
| 368 | LogUtil.i("CallButtonPresenter.pauseVideoClicked", "%s", pause ? "pause" : "unpause"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 369 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 370 | Logger.get(context) |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 371 | .logCallImpression( |
| 372 | pause |
| 373 | ? DialerImpression.Type.IN_CALL_SCREEN_TURN_OFF_VIDEO |
| 374 | : DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_VIDEO, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 375 | call.getUniqueCallId(), |
| 376 | call.getTimeAddedMs()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 377 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 378 | if (pause) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 379 | call.getVideoTech().setCamera(null); |
| 380 | call.getVideoTech().stopTransmission(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 381 | } else { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 382 | updateCamera( |
| 383 | InCallPresenter.getInstance().getInCallCameraManager().isUsingFrontFacingCamera()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 384 | call.getVideoTech().resumeTransmission(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 385 | } |
| 386 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 387 | inCallButtonUi.setVideoPaused(pause); |
| 388 | inCallButtonUi.enableButton(InCallButtonIds.BUTTON_PAUSE_VIDEO, false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 391 | private void updateCamera(boolean useFrontFacingCamera) { |
| 392 | InCallCameraManager cameraManager = InCallPresenter.getInstance().getInCallCameraManager(); |
| 393 | cameraManager.setUseFrontFacingCamera(useFrontFacingCamera); |
| 394 | |
| 395 | String cameraId = cameraManager.getActiveCameraId(); |
| 396 | if (cameraId != null) { |
| 397 | final int cameraDir = |
| 398 | cameraManager.isUsingFrontFacingCamera() |
| 399 | ? CameraDirection.CAMERA_DIRECTION_FRONT_FACING |
| 400 | : CameraDirection.CAMERA_DIRECTION_BACK_FACING; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 401 | call.setCameraDir(cameraDir); |
| 402 | call.getVideoTech().setCamera(cameraId); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 406 | private void updateUi(InCallState state, DialerCall call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 407 | LogUtil.v("CallButtonPresenter", "updating call UI for call: %s", call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 408 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 409 | if (inCallButtonUi == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | |
Eric Erfanian | 92854e0 | 2018-07-10 18:37:33 +0000 | [diff] [blame] | 413 | if (call != null) { |
| 414 | inCallButtonUi.updateInCallButtonUiColors( |
| 415 | InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor()); |
| 416 | } |
| 417 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 418 | final boolean isEnabled = |
| 419 | state.isConnectingOrConnected() && !state.isIncoming() && call != null; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 420 | inCallButtonUi.setEnabled(isEnabled); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 421 | |
| 422 | if (call == null) { |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | updateButtonsState(call); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Updates the buttons applicable for the UI. |
| 431 | * |
| 432 | * @param call The active call. |
| 433 | */ |
linyuh | 60c1e57 | 2018-06-28 20:13:52 -0700 | [diff] [blame] | 434 | @SuppressWarnings(value = {"MissingPermission"}) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 435 | private void updateButtonsState(DialerCall call) { |
| 436 | LogUtil.v("CallButtonPresenter.updateButtonsState", ""); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 437 | final boolean isVideo = call.isVideoCall(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 438 | |
| 439 | // Common functionality (audio, hold, etc). |
| 440 | // Show either HOLD or SWAP, but not both. If neither HOLD or SWAP is available: |
| 441 | // (1) If the device normally can hold, show HOLD in a disabled state. |
| 442 | // (2) If the device doesn't have the concept of hold/swap, remove the button. |
| 443 | final boolean showSwap = call.can(android.telecom.Call.Details.CAPABILITY_SWAP_CONFERENCE); |
| 444 | final boolean showHold = |
| 445 | !showSwap |
| 446 | && call.can(android.telecom.Call.Details.CAPABILITY_SUPPORT_HOLD) |
| 447 | && call.can(android.telecom.Call.Details.CAPABILITY_HOLD); |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 448 | final boolean isCallOnHold = call.getState() == DialerCallState.ONHOLD; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 449 | |
| 450 | final boolean showAddCall = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 451 | TelecomAdapter.getInstance().canAddCall() && UserManagerCompat.isUserUnlocked(context); |
erfanian | 9dfd6a4 | 2018-04-17 15:01:17 -0700 | [diff] [blame] | 452 | // There can only be two calls so don't show the ability to merge when one of them |
| 453 | // is a speak easy call. |
| 454 | final boolean showMerge = |
| 455 | InCallPresenter.getInstance() |
| 456 | .getCallList() |
| 457 | .getAllCalls() |
| 458 | .stream() |
| 459 | .noneMatch(c -> c != null && c.isSpeakEasyCall()) |
| 460 | && call.can(android.telecom.Call.Details.CAPABILITY_MERGE_CONFERENCE); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 461 | final boolean showUpgradeToVideo = !isVideo && (hasVideoCallCapabilities(call)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 462 | final boolean showDowngradeToAudio = isVideo && isDowngradeToAudioSupported(call); |
| 463 | final boolean showMute = call.can(android.telecom.Call.Details.CAPABILITY_MUTE); |
| 464 | |
| 465 | final boolean hasCameraPermission = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 466 | isVideo && VideoUtils.hasCameraPermissionAndShownPrivacyToast(context); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 467 | // Disabling local video doesn't seem to work when dialing. See a bug. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 468 | final boolean showPauseVideo = |
| 469 | isVideo |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 470 | && call.getState() != DialerCallState.DIALING |
| 471 | && call.getState() != DialerCallState.CONNECTING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 472 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 473 | otherAccount = TelecomUtil.getOtherAccount(getContext(), call.getAccountHandle()); |
twyen | 38af651 | 2017-11-22 17:12:49 -0800 | [diff] [blame] | 474 | boolean showSwapSim = |
twyen | ea3b162 | 2018-04-24 10:45:08 -0700 | [diff] [blame] | 475 | !call.isEmergencyCall() |
| 476 | && otherAccount != null |
twyen | 2c6803d | 2017-11-28 11:41:49 -0800 | [diff] [blame] | 477 | && !call.isVoiceMailNumber() |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 478 | && DialerCallState.isDialing(call.getState()) |
twyen | 38af651 | 2017-11-22 17:12:49 -0800 | [diff] [blame] | 479 | // Most devices cannot make calls on 2 SIMs at the same time. |
| 480 | && InCallPresenter.getInstance().getCallList().getAllCalls().size() == 1; |
twyen | 00623aa | 2017-10-10 12:15:08 -0700 | [diff] [blame] | 481 | |
wangqi | 01b7827 | 2018-04-03 17:02:44 -0700 | [diff] [blame] | 482 | boolean showUpgradeToRtt = call.canUpgradeToRttCall(); |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 483 | boolean enableUpgradeToRtt = showUpgradeToRtt && call.getState() == DialerCallState.ACTIVE; |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 484 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 485 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_AUDIO, true); |
| 486 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_SWAP, showSwap); |
| 487 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_HOLD, showHold); |
| 488 | inCallButtonUi.setHold(isCallOnHold); |
| 489 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_MUTE, showMute); |
| 490 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_SWAP_SIM, showSwapSim); |
| 491 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_ADD_CALL, true); |
| 492 | inCallButtonUi.enableButton(InCallButtonIds.BUTTON_ADD_CALL, showAddCall); |
| 493 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_UPGRADE_TO_VIDEO, showUpgradeToVideo); |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 494 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_UPGRADE_TO_RTT, showUpgradeToRtt); |
wangqi | 15514ef | 2018-04-04 10:50:13 -0700 | [diff] [blame] | 495 | inCallButtonUi.enableButton(InCallButtonIds.BUTTON_UPGRADE_TO_RTT, enableUpgradeToRtt); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 496 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_DOWNGRADE_TO_AUDIO, showDowngradeToAudio); |
| 497 | inCallButtonUi.showButton( |
roldenburg | f15085f | 2017-11-06 12:02:06 -0800 | [diff] [blame] | 498 | InCallButtonIds.BUTTON_SWITCH_CAMERA, |
| 499 | isVideo && hasCameraPermission && call.getVideoTech().isTransmitting()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 500 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_PAUSE_VIDEO, showPauseVideo); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 501 | if (isVideo) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 502 | inCallButtonUi.setVideoPaused(!call.getVideoTech().isTransmitting() || !hasCameraPermission); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 503 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 504 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_DIALPAD, true); |
| 505 | inCallButtonUi.showButton(InCallButtonIds.BUTTON_MERGE, showMerge); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 506 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 507 | inCallButtonUi.updateButtonStates(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | private boolean hasVideoCallCapabilities(DialerCall call) { |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 511 | return call.getVideoTech().isAvailable(context, call.getAccountHandle()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Determines if downgrading from a video call to an audio-only call is supported. In order to |
| 516 | * support downgrade to audio, the SDK version must be >= N and the call should NOT have the |
| 517 | * {@link android.telecom.Call.Details#CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO}. |
| 518 | * |
| 519 | * @param call The call. |
| 520 | * @return {@code true} if downgrading to an audio-only call from a video call is supported. |
| 521 | */ |
| 522 | private boolean isDowngradeToAudioSupported(DialerCall call) { |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 523 | // TODO(a bug): If there is an RCS video share session, return true here |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 524 | return !call.can(CallCompat.Details.CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO); |
| 525 | } |
| 526 | |
| 527 | @Override |
Sekine Yasuaki | a702084 | 2018-05-31 17:10:12 +0900 | [diff] [blame^] | 528 | public void onSaveInstanceState(Bundle outState) {} |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 529 | |
| 530 | @Override |
Sekine Yasuaki | a702084 | 2018-05-31 17:10:12 +0900 | [diff] [blame^] | 531 | public void onRestoreInstanceState(Bundle savedInstanceState) {} |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 532 | |
| 533 | @Override |
| 534 | public void onCameraPermissionGranted() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 535 | if (call != null) { |
| 536 | updateButtonsState(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
| 540 | @Override |
| 541 | public void onActiveCameraSelectionChanged(boolean isUsingFrontFacingCamera) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 542 | if (inCallButtonUi == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 543 | return; |
| 544 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 545 | inCallButtonUi.setCameraSwitched(!isUsingFrontFacingCamera); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public Context getContext() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 550 | return context; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | private InCallActivity getActivity() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 554 | if (inCallButtonUi != null) { |
| 555 | Fragment fragment = inCallButtonUi.getInCallButtonUiFragment(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 556 | if (fragment != null) { |
| 557 | return (InCallActivity) fragment.getActivity(); |
| 558 | } |
| 559 | } |
| 560 | return null; |
| 561 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 562 | } |