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