blob: 072878688a787169a48fae2746c455d044af446f [file] [log] [blame]
Hadrien De Sousaccc947d2017-04-12 14:26:52 -04001/*
Sébastien Blinab53ada2019-01-02 17:23:00 -05002 * Copyright (C) 2004-2019 Savoir-faire Linux Inc.
Hadrien De Sousaccc947d2017-04-12 14:26:52 -04003 *
4 * Author: Hadrien De Sousa <hadrien.desousa@savoirfairelinux.com>
Adrien Béraudace37a22018-06-22 14:58:36 -04005 * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
Hadrien De Sousaccc947d2017-04-12 14:26:52 -04006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21package cx.ring.call;
22
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040023import java.util.concurrent.TimeUnit;
24
25import javax.inject.Inject;
Adrien Béraudace37a22018-06-22 14:58:36 -040026import javax.inject.Named;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040027
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040028import cx.ring.model.SipCall;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040029import cx.ring.mvp.RootPresenter;
30import cx.ring.services.AccountService;
31import cx.ring.services.CallService;
Adrien Béraud8d710752019-02-20 13:53:59 -050032import cx.ring.services.ContactService;
Rayan Osseiran38206c62019-05-15 14:49:03 -040033import cx.ring.services.DeviceRuntimeService;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040034import cx.ring.services.HardwareService;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040035import cx.ring.services.NotificationService;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040036import cx.ring.utils.Log;
Hadrien De Sousac165e9b2017-11-24 12:33:32 -050037import cx.ring.utils.StringUtils;
Rayan Osseiraned9feeb2019-07-05 16:04:30 -040038import io.reactivex.Observable;
Adrien Béraudace37a22018-06-22 14:58:36 -040039import io.reactivex.Scheduler;
Adrien Béraud3aeed5d2018-07-26 11:26:13 -040040import io.reactivex.disposables.Disposable;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040041
Adrien Béraudace37a22018-06-22 14:58:36 -040042public class CallPresenter extends RootPresenter<CallView> {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040043
44 public final static String TAG = CallPresenter.class.getSimpleName();
45
Adrien Béraudace37a22018-06-22 14:58:36 -040046 private AccountService mAccountService;
Adrien Béraud8d710752019-02-20 13:53:59 -050047 private ContactService mContactService;
Adrien Béraudace37a22018-06-22 14:58:36 -040048 private NotificationService mNotificationService;
49 private HardwareService mHardwareService;
50 private CallService mCallService;
Rayan Osseiran38206c62019-05-15 14:49:03 -040051 private DeviceRuntimeService mDeviceRuntimeService;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040052
53 private SipCall mSipCall;
54 private boolean mOnGoingCall = false;
Hadrien De Sousa203164c2017-12-05 17:41:42 -050055 private boolean mAudioOnly = true;
Adrien Béraud335d32e2019-05-31 09:31:40 -040056 private boolean permissionChanged = false;
Rayan Osseiranc1532d42019-06-05 13:17:53 -040057 private boolean pipIsActive = false;
Rayan Osseiran3dd04662019-06-28 16:47:48 -040058 private boolean incomingIsFullIntent = true;
Rayan Osseiraned9feeb2019-07-05 16:04:30 -040059 private boolean callInitialized = false;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040060
61 private int videoWidth = -1;
62 private int videoHeight = -1;
63 private int previewWidth = -1;
64 private int previewHeight = -1;
65
Adrien Béraud3aeed5d2018-07-26 11:26:13 -040066 private Disposable timeUpdateTask = null;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040067
68 @Inject
Adrien Béraudace37a22018-06-22 14:58:36 -040069 @Named("UiScheduler")
70 protected Scheduler mUiScheduler;
71
72 @Inject
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040073 public CallPresenter(AccountService accountService,
Adrien Béraud8d710752019-02-20 13:53:59 -050074 ContactService contactService,
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040075 NotificationService notificationService,
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040076 HardwareService hardwareService,
Rayan Osseiran38206c62019-05-15 14:49:03 -040077 CallService callService, DeviceRuntimeService deviceRuntimeService) {
Adrien Béraudace37a22018-06-22 14:58:36 -040078 mAccountService = accountService;
Adrien Béraud8d710752019-02-20 13:53:59 -050079 mContactService = contactService;
Adrien Béraudace37a22018-06-22 14:58:36 -040080 mNotificationService = notificationService;
81 mHardwareService = hardwareService;
82 mCallService = callService;
Rayan Osseiran38206c62019-05-15 14:49:03 -040083 mDeviceRuntimeService = deviceRuntimeService;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -040084 }
85
Rayan Osseiran38206c62019-05-15 14:49:03 -040086 public void cameraPermissionChanged(boolean isGranted) {
87 if (isGranted && mHardwareService.isVideoAvailable()) {
88 mHardwareService.initVideo();
Adrien Béraud335d32e2019-05-31 09:31:40 -040089 permissionChanged = true;
Rayan Osseiran38206c62019-05-15 14:49:03 -040090 }
91 }
92
93 public void audioPermissionChanged(boolean isGranted) {
Rayan Osseirandb4667e2019-05-31 09:41:54 -040094 if (isGranted && mHardwareService.hasMicrophone()) {
Adrien Béraud22ec8b82019-07-27 21:53:50 -040095 mCallService.restartAudioLayer();
Rayan Osseiran38206c62019-05-15 14:49:03 -040096 }
97 }
98
99
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400100 @Override
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400101 public void unbindView() {
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500102 if (!mAudioOnly) {
Adrien Béraud30532a52018-09-11 15:10:05 -0400103 mHardwareService.endCapture();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400104 }
Adrien Béraud99fd4202018-12-13 13:02:21 -0500105 super.unbindView();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400106 }
107
108 @Override
109 public void bindView(CallView view) {
110 super.bindView(view);
Adrien Béraudace37a22018-06-22 14:58:36 -0400111 mCompositeDisposable.add(mAccountService.getRegisteredNames()
112 .observeOn(mUiScheduler)
113 .subscribe(r -> {
114 if (mSipCall != null && mSipCall.getContact() != null) {
115 getView().updateContactBubble(mSipCall.getContact());
116 }
117 }));
118 mCompositeDisposable.add(mHardwareService.getVideoEvents()
119 .observeOn(mUiScheduler)
120 .subscribe(this::onVideoEvent));
Adrien Béraud34a6fa22019-07-28 16:02:59 -0400121 mCompositeDisposable.add(mHardwareService.getAudioState()
122 .observeOn(mUiScheduler)
123 .subscribe(state -> getView().updateAudioState(state)));
124
Adrien Béraud22ec8b82019-07-27 21:53:50 -0400125 /*mCompositeDisposable.add(mHardwareService
Adrien Béraud057e9a32018-09-30 17:48:55 -0400126 .getBluetoothEvents()
127 .subscribe(event -> {
Rayan Osseiran7f77c8a2019-07-17 16:40:50 -0400128 if (!event.connected && mSipCall == null) {
Adrien Béraud057e9a32018-09-30 17:48:55 -0400129 hangupCall();
130 }
Adrien Béraud22ec8b82019-07-27 21:53:50 -0400131 }));*/
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400132 }
133
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500134 public void initOutGoing(String accountId, String contactRingId, boolean audioOnly) {
Adrien Béraud85683c22018-05-23 11:18:43 -0400135 if (accountId == null || contactRingId == null) {
136 Log.e(TAG, "initOutGoing: null account or contact");
137 getView().finish();
138 return;
139 }
Hadrien De Sousafcf2a992017-12-15 11:08:56 -0500140 if (mHardwareService.getCameraCount() == 0) {
Adrien Béraudd3bf4e42018-02-14 14:44:41 +0100141 audioOnly = true;
Hadrien De Sousafcf2a992017-12-15 11:08:56 -0500142 }
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400143 //getView().blockScreenRotation();
Adrien Béraudace37a22018-06-22 14:58:36 -0400144
145 mCompositeDisposable.add(mCallService
146 .placeCallObservable(accountId, StringUtils.toNumber(contactRingId), audioOnly)
147 .observeOn(mUiScheduler)
Rayan Osseiran38206c62019-05-15 14:49:03 -0400148 .subscribe(call -> {
Adrien Béraud2c378b32018-07-11 15:24:02 -0400149 contactUpdate(call);
Adrien Béraud99fd4202018-12-13 13:02:21 -0500150 confUpdate(call);
Rayan Osseirandb4667e2019-05-31 09:41:54 -0400151 }, e -> {
152 hangupCall();
153 Log.e(TAG, "Error with initOutgoing: " + e.getMessage());
154 }));
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400155 }
156
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400157
Rayan Osseiraned9feeb2019-07-05 16:04:30 -0400158 /**
159 * Returns to or starts an incoming call
160 *
161 * @param confId the call id
162 * @param actionViewOnly true if only returning to call or if using full screen intent
163 */
164 public void initIncomingCall(String confId, boolean actionViewOnly) {
165 //getView().blockScreenRotation();
166
167 // if the call is incoming through a full intent, this allows the incoming call to display
168 incomingIsFullIntent = actionViewOnly;
169
170 Observable<SipCall> callObservable = mCallService.getCallUpdates(confId).observeOn(mUiScheduler).share();
171
172 // Handles the case where the call has been accepted, emits a single so as to only check for permissions and start the call once
173 mCompositeDisposable.add(callObservable.firstOrError().subscribe(call -> {
174 if (!actionViewOnly) {
175 contactUpdate(call);
176 confUpdate(call);
177 callInitialized = true;
178 getView().prepareCall(true);
179 }
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400180 }, e -> {
181 hangupCall();
Rayan Osseiraned9feeb2019-07-05 16:04:30 -0400182 Log.e(TAG, "Error with initIncoming, preparing call flow :" , e);
183 }));
184
185 // Handles retrieving call updates. Items emitted are only used if call is already in process or if user is returning to a call.
186 mCompositeDisposable.add(callObservable.subscribe(call -> {
187 if (callInitialized || actionViewOnly) {
188 contactUpdate(call);
189 confUpdate(call);
190 }
191 }, e -> {
192 hangupCall();
193 Log.e(TAG, "Error with initIncoming, action view flow: ", e);
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400194 }));
195 }
196
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400197 public void prepareOptionMenu() {
198 boolean isSpeakerOn = mHardwareService.isSpeakerPhoneOn();
199 boolean hasContact = mSipCall != null && null != mSipCall.getContact() && mSipCall.getContact().isUnknown();
200 boolean canDial = mOnGoingCall && mSipCall != null && !mSipCall.isIncoming();
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500201 boolean hasMultipleCamera = mHardwareService.getCameraCount() > 1 && mOnGoingCall && !mAudioOnly;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400202 getView().initMenu(isSpeakerOn, hasContact, hasMultipleCamera, canDial, mOnGoingCall);
203 }
204
205 public void chatClick() {
206 if (mSipCall == null
207 || mSipCall.getContact() == null
208 || mSipCall.getContact().getIds() == null
209 || mSipCall.getContact().getIds().isEmpty()) {
210 return;
211 }
Adrien Béraudace37a22018-06-22 14:58:36 -0400212 getView().goToConversation(mSipCall.getAccount(), mSipCall.getContact().getIds().get(0));
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400213 }
214
Adrien Béraudbc0898e2018-08-23 14:31:11 -0400215 public void speakerClick(boolean checked) {
216 mHardwareService.toggleSpeakerphone(checked);
217 }
218
219 public void muteMicrophoneToggled(boolean checked) {
220 mCallService.setMuted(checked);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400221 }
222
Rayan Osseiran38206c62019-05-15 14:49:03 -0400223
Adrien Béraudec19fad2018-12-30 16:51:05 -0500224 public boolean isMicrophoneMuted() {
225 return mCallService.isCaptureMuted();
226 }
227
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400228 public void switchVideoInputClick() {
Rayan Osseiranca0436c2019-07-16 10:11:06 -0400229 if(mSipCall == null)
230 return;
231
Adrien Béraud335d32e2019-05-31 09:31:40 -0400232 mHardwareService.switchInput(mSipCall.getCallId(), false);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400233 getView().switchCameraIcon(mHardwareService.isPreviewFromFrontCamera());
234 }
235
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400236 public void configurationChanged(int rotation) {
237 mHardwareService.setDeviceOrientation(rotation);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400238 }
239
240 public void dialpadClick() {
241 getView().displayDialPadKeyboard();
242 }
243
244 public void acceptCall() {
245 if (mSipCall == null) {
246 return;
247 }
248 mCallService.accept(mSipCall.getCallId());
249 }
250
251 public void hangupCall() {
252 if (mSipCall != null) {
253 mCallService.hangUp(mSipCall.getCallId());
254 }
255 finish();
256 }
257
258 public void refuseCall() {
Adrien Béraudace37a22018-06-22 14:58:36 -0400259 final SipCall call = mSipCall;
260 if (call != null) {
261 mCallService.refuse(call.getCallId());
262 mNotificationService.cancelCallNotification(call.getCallId().hashCode());
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400263 }
264 finish();
265 }
266
267 public void videoSurfaceCreated(Object holder) {
Alexandre Lisione4d40262016-12-12 14:30:09 -0500268 if (mSipCall == null) {
269 return;
270 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400271 mHardwareService.addVideoSurface(mSipCall.getCallId(), holder);
272 getView().displayContactBubble(false);
273 }
274
275 public void previewVideoSurfaceCreated(Object holder) {
Adrien Béraud0c14a9e2019-06-01 19:28:14 -0400276 mHardwareService.addPreviewVideoSurface(holder, mSipCall);
Adrien Béraud30532a52018-09-11 15:10:05 -0400277 //mHardwareService.startCapture(null);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400278 }
279
280 public void videoSurfaceDestroyed() {
281 if (mSipCall == null) {
282 return;
283 }
284 mHardwareService.removeVideoSurface(mSipCall.getCallId());
285 }
286
287 public void previewVideoSurfaceDestroyed() {
288 mHardwareService.removePreviewVideoSurface();
Adrien Béraud30532a52018-09-11 15:10:05 -0400289 mHardwareService.endCapture();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400290 }
291
292 public void displayChanged() {
Adrien Béraud335d32e2019-05-31 09:31:40 -0400293 mHardwareService.switchInput(mSipCall.getCallId(), false);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400294 }
295
296 public void layoutChanged() {
Adrien Béraudde0d4522018-12-12 12:11:02 -0500297 //getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400298 }
299
Rayan Osseiran38206c62019-05-15 14:49:03 -0400300
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400301 public void uiVisibilityChanged(boolean displayed) {
Adrien Béraud665faa22018-07-26 16:51:20 -0400302 CallView view = getView();
303 if (view != null)
304 view.displayHangupButton(mOnGoingCall && displayed);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400305 }
306
307 private void finish() {
Adrien Béraud3aeed5d2018-07-26 11:26:13 -0400308 if (timeUpdateTask != null && !timeUpdateTask.isDisposed()) {
309 timeUpdateTask.dispose();
310 timeUpdateTask = null;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400311 }
312 mSipCall = null;
Adrien Béraud8d6baf32018-08-03 23:37:31 -0400313 CallView view = getView();
314 if (view != null)
315 view.finish();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400316 }
317
Adrien Béraud2c378b32018-07-11 15:24:02 -0400318 private void contactUpdate(final SipCall call) {
319 if (mSipCall != call) {
320 mSipCall = call;
Adrien Béraud8d710752019-02-20 13:53:59 -0500321 mCompositeDisposable.add(mContactService.observeContact(call.getAccount(), call.getContact())
Adrien Béraud2c378b32018-07-11 15:24:02 -0400322 .observeOn(mUiScheduler)
Rayan Osseirandb4667e2019-05-31 09:41:54 -0400323 .subscribe(c -> getView().updateContactBubble(c), e -> Log.e(TAG, e.getMessage())));
Adrien Béraud2c378b32018-07-11 15:24:02 -0400324 }
325 }
326
Adrien Béraud99fd4202018-12-13 13:02:21 -0500327 private void confUpdate(SipCall call) {
328 mAudioOnly = call.isAudioOnly();
Adrien Béraudace37a22018-06-22 14:58:36 -0400329 CallView view = getView();
Adrien Béraud99fd4202018-12-13 13:02:21 -0500330 if (view == null)
331 return;
332 view.updateMenu();
333 if (call.isOnGoing()) {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400334 mOnGoingCall = true;
Adrien Béraud34a6fa22019-07-28 16:02:59 -0400335 view.initNormalStateDisplay(mAudioOnly, isMicrophoneMuted());
Adrien Béraudace37a22018-06-22 14:58:36 -0400336 view.updateMenu();
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500337 if (!mAudioOnly) {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400338 mHardwareService.setPreviewSettings();
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400339 view.displayVideoSurface(true, mDeviceRuntimeService.hasVideoPermission());
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400340 if (permissionChanged) {
Adrien Béraud335d32e2019-05-31 09:31:40 -0400341 mHardwareService.switchInput(mSipCall.getCallId(), permissionChanged);
342 permissionChanged = false;
Rayan Osseiran38206c62019-05-15 14:49:03 -0400343 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400344 }
Adrien Béraud3aeed5d2018-07-26 11:26:13 -0400345 if (timeUpdateTask != null)
346 timeUpdateTask.dispose();
Adrien Béraud99fd4202018-12-13 13:02:21 -0500347 timeUpdateTask = mUiScheduler.schedulePeriodicallyDirect(this::updateTime, 0, 1, TimeUnit.SECONDS);
348 } else if (call.isRinging()) {
Rayan Osseirande9ac142019-07-02 13:01:32 -0400349 view.handleCallWakelock(mAudioOnly);
Adrien Béraud99fd4202018-12-13 13:02:21 -0500350 if (call.isIncoming()) {
351 if (mAccountService.getAccount(call.getAccount()).isAutoanswerEnabled()) {
352 mCallService.accept(call.getCallId());
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400353 // only display the incoming call screen if the notification is a full screen intent
354 } else if (incomingIsFullIntent) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400355 view.initIncomingCallDisplay();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400356 }
357 } else {
358 mOnGoingCall = false;
Adrien Béraud99fd4202018-12-13 13:02:21 -0500359 view.updateCallStatus(call.getCallState());
Adrien Béraudace37a22018-06-22 14:58:36 -0400360 view.initOutGoingCallDisplay();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400361 }
362 } else {
363 finish();
364 }
365 }
366
367 private void updateTime() {
Adrien Béraud6325fad2018-08-15 15:34:11 -0400368 CallView view = getView();
369 if (view != null && mSipCall != null) {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400370 long duration = System.currentTimeMillis() - mSipCall.getTimestampStart();
371 duration = duration / 1000;
372 if (mSipCall.isOnGoing()) {
Adrien Béraud6325fad2018-08-15 15:34:11 -0400373 view.updateTime(duration);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400374 }
375 }
376 }
377
Adrien Béraudace37a22018-06-22 14:58:36 -0400378 private void onVideoEvent(HardwareService.VideoEvent event) {
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400379 Log.d(TAG, "VIDEO_EVENT: " + event.start + " " + event.callId + " " + event.w + "x" + event.h);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400380
Adrien Béraudace37a22018-06-22 14:58:36 -0400381 if (event.start) {
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400382 getView().displayVideoSurface(true, !isPipMode() && mDeviceRuntimeService.hasVideoPermission());
Adrien Béraudace37a22018-06-22 14:58:36 -0400383 } else if (mSipCall != null && mSipCall.getCallId().equals(event.callId)) {
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400384 getView().displayVideoSurface(event.started, event.started && !isPipMode() && mDeviceRuntimeService.hasVideoPermission());
Adrien Béraudace37a22018-06-22 14:58:36 -0400385 if (event.started) {
386 videoWidth = event.w;
387 videoHeight = event.h;
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400388 getView().resetVideoSize(videoWidth, videoHeight);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400389 }
Adrien Béraud30532a52018-09-11 15:10:05 -0400390 } else if (event.callId == null) {
391 if (event.started) {
392 previewWidth = event.w;
393 previewHeight = event.h;
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400394 getView().resetPreviewVideoSize(previewWidth, previewHeight, event.rot);
Adrien Béraud30532a52018-09-11 15:10:05 -0400395 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400396 }
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400397 /*if (event.started || event.start) {
Adrien Béraudde0d4522018-12-12 12:11:02 -0500398 getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight);
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400399 }*/
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400400 }
Pierre Duchemin8b2c1b52017-12-29 17:17:13 -0500401
402 public void positiveButtonClicked() {
403 if (mSipCall.isRinging() && mSipCall.isIncoming()) {
404 acceptCall();
405 } else {
406 hangupCall();
407 }
408 }
409
410 public void negativeButtonClicked() {
411 if (mSipCall.isRinging() && mSipCall.isIncoming()) {
412 refuseCall();
413 } else {
414 hangupCall();
415 }
416 }
417
418 public void toggleButtonClicked() {
419 if (!(mSipCall.isRinging() && mSipCall.isIncoming())) {
420 hangupCall();
421 }
422 }
Adrien Béraud79808d02018-02-20 00:16:28 +0100423
Rayan Osseiran38206c62019-05-15 14:49:03 -0400424 public boolean isAudioOnly() {
425 return mAudioOnly;
426 }
427
Adrien Béraud79808d02018-02-20 00:16:28 +0100428 public void requestPipMode() {
Adrien Béraud6325fad2018-08-15 15:34:11 -0400429 if (mSipCall != null && mSipCall.isOnGoing() && !mSipCall.isAudioOnly()) {
Adrien Béraud79808d02018-02-20 00:16:28 +0100430 getView().enterPipMode(mSipCall);
431 }
432 }
433
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400434 public boolean isPipMode() {
435 return pipIsActive;
436 }
437
Adrien Béraud79808d02018-02-20 00:16:28 +0100438 public void pipModeChanged(boolean pip) {
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400439 pipIsActive = pip;
Adrien Béraud79808d02018-02-20 00:16:28 +0100440 if (pip) {
441 getView().displayHangupButton(false);
442 getView().displayPreviewSurface(false);
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400443 getView().displayVideoSurface(true, false);
Adrien Béraud79808d02018-02-20 00:16:28 +0100444 } else {
445 getView().displayPreviewSurface(true);
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400446 getView().displayVideoSurface(true, mDeviceRuntimeService.hasVideoPermission());
Adrien Béraud79808d02018-02-20 00:16:28 +0100447 }
448 }
Adrien Béraudbc0898e2018-08-23 14:31:11 -0400449
450 public boolean isSpeakerphoneOn() {
451 return mHardwareService.isSpeakerPhoneOn();
452 }
Adrien Béraudbcbb4d42018-12-08 16:06:39 -0500453
454 public void sendDtmf(CharSequence s) {
455 mCallService.playDtmf(s.toString());
456 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400457}