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