blob: ca6b82dd9572faa0081065ac2e8c18b219a2fcf6 [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()) {
Rayan Osseiran38206c62019-05-15 14:49:03 -040095 mCallService.setAudioPlugin(mCallService.getCurrentAudioOutputPlugin());
96 }
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éraud057e9a32018-09-30 17:48:55 -0400121 mCompositeDisposable.add(mHardwareService
122 .getBluetoothEvents()
123 .subscribe(event -> {
Rayan Osseiran7f77c8a2019-07-17 16:40:50 -0400124 if (!event.connected && mSipCall == null) {
Adrien Béraud057e9a32018-09-30 17:48:55 -0400125 hangupCall();
126 }
127 }));
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400128 }
129
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500130 public void initOutGoing(String accountId, String contactRingId, boolean audioOnly) {
Adrien Béraud85683c22018-05-23 11:18:43 -0400131 if (accountId == null || contactRingId == null) {
132 Log.e(TAG, "initOutGoing: null account or contact");
133 getView().finish();
134 return;
135 }
Hadrien De Sousafcf2a992017-12-15 11:08:56 -0500136 if (mHardwareService.getCameraCount() == 0) {
Adrien Béraudd3bf4e42018-02-14 14:44:41 +0100137 audioOnly = true;
Hadrien De Sousafcf2a992017-12-15 11:08:56 -0500138 }
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400139 //getView().blockScreenRotation();
Adrien Béraudace37a22018-06-22 14:58:36 -0400140
141 mCompositeDisposable.add(mCallService
142 .placeCallObservable(accountId, StringUtils.toNumber(contactRingId), audioOnly)
143 .observeOn(mUiScheduler)
Rayan Osseiran38206c62019-05-15 14:49:03 -0400144 .subscribe(call -> {
Adrien Béraud2c378b32018-07-11 15:24:02 -0400145 contactUpdate(call);
Adrien Béraud99fd4202018-12-13 13:02:21 -0500146 confUpdate(call);
Rayan Osseirandb4667e2019-05-31 09:41:54 -0400147 }, e -> {
148 hangupCall();
149 Log.e(TAG, "Error with initOutgoing: " + e.getMessage());
150 }));
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400151 }
152
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400153
Rayan Osseiraned9feeb2019-07-05 16:04:30 -0400154 /**
155 * Returns to or starts an incoming call
156 *
157 * @param confId the call id
158 * @param actionViewOnly true if only returning to call or if using full screen intent
159 */
160 public void initIncomingCall(String confId, boolean actionViewOnly) {
161 //getView().blockScreenRotation();
162
163 // if the call is incoming through a full intent, this allows the incoming call to display
164 incomingIsFullIntent = actionViewOnly;
165
166 Observable<SipCall> callObservable = mCallService.getCallUpdates(confId).observeOn(mUiScheduler).share();
167
168 // Handles the case where the call has been accepted, emits a single so as to only check for permissions and start the call once
169 mCompositeDisposable.add(callObservable.firstOrError().subscribe(call -> {
170 if (!actionViewOnly) {
171 contactUpdate(call);
172 confUpdate(call);
173 callInitialized = true;
174 getView().prepareCall(true);
175 }
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400176 }, e -> {
177 hangupCall();
Rayan Osseiraned9feeb2019-07-05 16:04:30 -0400178 Log.e(TAG, "Error with initIncoming, preparing call flow :" , e);
179 }));
180
181 // Handles retrieving call updates. Items emitted are only used if call is already in process or if user is returning to a call.
182 mCompositeDisposable.add(callObservable.subscribe(call -> {
183 if (callInitialized || actionViewOnly) {
184 contactUpdate(call);
185 confUpdate(call);
186 }
187 }, e -> {
188 hangupCall();
189 Log.e(TAG, "Error with initIncoming, action view flow: ", e);
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400190 }));
191 }
192
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400193 public void prepareOptionMenu() {
194 boolean isSpeakerOn = mHardwareService.isSpeakerPhoneOn();
195 boolean hasContact = mSipCall != null && null != mSipCall.getContact() && mSipCall.getContact().isUnknown();
196 boolean canDial = mOnGoingCall && mSipCall != null && !mSipCall.isIncoming();
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500197 boolean hasMultipleCamera = mHardwareService.getCameraCount() > 1 && mOnGoingCall && !mAudioOnly;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400198 getView().initMenu(isSpeakerOn, hasContact, hasMultipleCamera, canDial, mOnGoingCall);
199 }
200
201 public void chatClick() {
202 if (mSipCall == null
203 || mSipCall.getContact() == null
204 || mSipCall.getContact().getIds() == null
205 || mSipCall.getContact().getIds().isEmpty()) {
206 return;
207 }
Adrien Béraudace37a22018-06-22 14:58:36 -0400208 getView().goToConversation(mSipCall.getAccount(), mSipCall.getContact().getIds().get(0));
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400209 }
210
Adrien Béraudbc0898e2018-08-23 14:31:11 -0400211 public void speakerClick(boolean checked) {
Rayan Osseiran7f77c8a2019-07-17 16:40:50 -0400212 mCallService.restartAudioLayer();
Adrien Béraudbc0898e2018-08-23 14:31:11 -0400213 mHardwareService.toggleSpeakerphone(checked);
214 }
215
216 public void muteMicrophoneToggled(boolean checked) {
217 mCallService.setMuted(checked);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400218 }
219
Rayan Osseiran38206c62019-05-15 14:49:03 -0400220
Adrien Béraudec19fad2018-12-30 16:51:05 -0500221 public boolean isMicrophoneMuted() {
222 return mCallService.isCaptureMuted();
223 }
224
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400225 public void switchVideoInputClick() {
Rayan Osseiranca0436c2019-07-16 10:11:06 -0400226 if(mSipCall == null)
227 return;
228
Adrien Béraud335d32e2019-05-31 09:31:40 -0400229 mHardwareService.switchInput(mSipCall.getCallId(), false);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400230 getView().switchCameraIcon(mHardwareService.isPreviewFromFrontCamera());
231 }
232
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400233 public void configurationChanged(int rotation) {
234 mHardwareService.setDeviceOrientation(rotation);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400235 }
236
237 public void dialpadClick() {
238 getView().displayDialPadKeyboard();
239 }
240
241 public void acceptCall() {
242 if (mSipCall == null) {
243 return;
244 }
245 mCallService.accept(mSipCall.getCallId());
246 }
247
248 public void hangupCall() {
249 if (mSipCall != null) {
250 mCallService.hangUp(mSipCall.getCallId());
251 }
252 finish();
253 }
254
255 public void refuseCall() {
Adrien Béraudace37a22018-06-22 14:58:36 -0400256 final SipCall call = mSipCall;
257 if (call != null) {
258 mCallService.refuse(call.getCallId());
259 mNotificationService.cancelCallNotification(call.getCallId().hashCode());
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400260 }
261 finish();
262 }
263
264 public void videoSurfaceCreated(Object holder) {
Alexandre Lisione4d40262016-12-12 14:30:09 -0500265 if (mSipCall == null) {
266 return;
267 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400268 mHardwareService.addVideoSurface(mSipCall.getCallId(), holder);
269 getView().displayContactBubble(false);
270 }
271
272 public void previewVideoSurfaceCreated(Object holder) {
Adrien Béraud0c14a9e2019-06-01 19:28:14 -0400273 mHardwareService.addPreviewVideoSurface(holder, mSipCall);
Adrien Béraud30532a52018-09-11 15:10:05 -0400274 //mHardwareService.startCapture(null);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400275 }
276
277 public void videoSurfaceDestroyed() {
278 if (mSipCall == null) {
279 return;
280 }
281 mHardwareService.removeVideoSurface(mSipCall.getCallId());
282 }
283
284 public void previewVideoSurfaceDestroyed() {
285 mHardwareService.removePreviewVideoSurface();
Adrien Béraud30532a52018-09-11 15:10:05 -0400286 mHardwareService.endCapture();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400287 }
288
289 public void displayChanged() {
Adrien Béraud335d32e2019-05-31 09:31:40 -0400290 mHardwareService.switchInput(mSipCall.getCallId(), false);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400291 }
292
293 public void layoutChanged() {
Adrien Béraudde0d4522018-12-12 12:11:02 -0500294 //getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400295 }
296
Rayan Osseiran38206c62019-05-15 14:49:03 -0400297
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400298 public void uiVisibilityChanged(boolean displayed) {
Adrien Béraud665faa22018-07-26 16:51:20 -0400299 CallView view = getView();
300 if (view != null)
301 view.displayHangupButton(mOnGoingCall && displayed);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400302 }
303
304 private void finish() {
Adrien Béraud3aeed5d2018-07-26 11:26:13 -0400305 if (timeUpdateTask != null && !timeUpdateTask.isDisposed()) {
306 timeUpdateTask.dispose();
307 timeUpdateTask = null;
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400308 }
309 mSipCall = null;
Adrien Béraud8d6baf32018-08-03 23:37:31 -0400310 CallView view = getView();
311 if (view != null)
312 view.finish();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400313 }
314
Adrien Béraud2c378b32018-07-11 15:24:02 -0400315 private void contactUpdate(final SipCall call) {
316 if (mSipCall != call) {
317 mSipCall = call;
Adrien Béraud8d710752019-02-20 13:53:59 -0500318 mCompositeDisposable.add(mContactService.observeContact(call.getAccount(), call.getContact())
Adrien Béraud2c378b32018-07-11 15:24:02 -0400319 .observeOn(mUiScheduler)
Rayan Osseirandb4667e2019-05-31 09:41:54 -0400320 .subscribe(c -> getView().updateContactBubble(c), e -> Log.e(TAG, e.getMessage())));
Adrien Béraud2c378b32018-07-11 15:24:02 -0400321 }
322 }
323
Adrien Béraud99fd4202018-12-13 13:02:21 -0500324 private void confUpdate(SipCall call) {
325 mAudioOnly = call.isAudioOnly();
Adrien Béraudace37a22018-06-22 14:58:36 -0400326 CallView view = getView();
Adrien Béraud99fd4202018-12-13 13:02:21 -0500327 if (view == null)
328 return;
329 view.updateMenu();
330 if (call.isOnGoing()) {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400331 mOnGoingCall = true;
Rayan Osseiran7f77c8a2019-07-17 16:40:50 -0400332 mCallService.restartAudioLayer();
333 mHardwareService.toggleSpeakerphone(mHardwareService.shouldPlaySpeaker());
Adrien Béraudec19fad2018-12-30 16:51:05 -0500334 view.initNormalStateDisplay(mAudioOnly, mHardwareService.isSpeakerPhoneOn(), isMicrophoneMuted());
Adrien Béraudace37a22018-06-22 14:58:36 -0400335 view.updateMenu();
Hadrien De Sousa203164c2017-12-05 17:41:42 -0500336 if (!mAudioOnly) {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400337 mHardwareService.setPreviewSettings();
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400338 view.displayVideoSurface(true, mDeviceRuntimeService.hasVideoPermission());
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400339 if (permissionChanged) {
Adrien Béraud335d32e2019-05-31 09:31:40 -0400340 mHardwareService.switchInput(mSipCall.getCallId(), permissionChanged);
341 permissionChanged = false;
Rayan Osseiran38206c62019-05-15 14:49:03 -0400342 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400343 }
Adrien Béraud3aeed5d2018-07-26 11:26:13 -0400344 if (timeUpdateTask != null)
345 timeUpdateTask.dispose();
Adrien Béraud99fd4202018-12-13 13:02:21 -0500346 timeUpdateTask = mUiScheduler.schedulePeriodicallyDirect(this::updateTime, 0, 1, TimeUnit.SECONDS);
347 } else if (call.isRinging()) {
Rayan Osseirande9ac142019-07-02 13:01:32 -0400348 view.handleCallWakelock(mAudioOnly);
Adrien Béraud99fd4202018-12-13 13:02:21 -0500349 if (call.isIncoming()) {
350 if (mAccountService.getAccount(call.getAccount()).isAutoanswerEnabled()) {
351 mCallService.accept(call.getCallId());
Rayan Osseiran3dd04662019-06-28 16:47:48 -0400352 // only display the incoming call screen if the notification is a full screen intent
353 } else if (incomingIsFullIntent) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400354 view.initIncomingCallDisplay();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400355 }
356 } else {
357 mOnGoingCall = false;
Adrien Béraud99fd4202018-12-13 13:02:21 -0500358 view.updateCallStatus(call.getCallState());
Adrien Béraudace37a22018-06-22 14:58:36 -0400359 view.initOutGoingCallDisplay();
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400360 }
361 } else {
362 finish();
363 }
364 }
365
366 private void updateTime() {
Adrien Béraud6325fad2018-08-15 15:34:11 -0400367 CallView view = getView();
368 if (view != null && mSipCall != null) {
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400369 long duration = System.currentTimeMillis() - mSipCall.getTimestampStart();
370 duration = duration / 1000;
371 if (mSipCall.isOnGoing()) {
Adrien Béraud6325fad2018-08-15 15:34:11 -0400372 view.updateTime(duration);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400373 }
374 }
375 }
376
Adrien Béraudace37a22018-06-22 14:58:36 -0400377 private void onVideoEvent(HardwareService.VideoEvent event) {
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400378 Log.d(TAG, "VIDEO_EVENT: " + event.start + " " + event.callId + " " + event.w + "x" + event.h);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400379
Adrien Béraudace37a22018-06-22 14:58:36 -0400380 if (event.start) {
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400381 getView().displayVideoSurface(true, !isPipMode() && mDeviceRuntimeService.hasVideoPermission());
Adrien Béraudace37a22018-06-22 14:58:36 -0400382 } else if (mSipCall != null && mSipCall.getCallId().equals(event.callId)) {
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400383 getView().displayVideoSurface(event.started, event.started && !isPipMode() && mDeviceRuntimeService.hasVideoPermission());
Adrien Béraudace37a22018-06-22 14:58:36 -0400384 if (event.started) {
385 videoWidth = event.w;
386 videoHeight = event.h;
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400387 getView().resetVideoSize(videoWidth, videoHeight);
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400388 }
Adrien Béraud30532a52018-09-11 15:10:05 -0400389 } else if (event.callId == null) {
390 if (event.started) {
391 previewWidth = event.w;
392 previewHeight = event.h;
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400393 getView().resetPreviewVideoSize(previewWidth, previewHeight, event.rot);
Adrien Béraud30532a52018-09-11 15:10:05 -0400394 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400395 }
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400396 /*if (event.started || event.start) {
Adrien Béraudde0d4522018-12-12 12:11:02 -0500397 getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight);
Adrien Béraudeb4bb002019-03-14 15:52:48 -0400398 }*/
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400399 }
Pierre Duchemin8b2c1b52017-12-29 17:17:13 -0500400
401 public void positiveButtonClicked() {
402 if (mSipCall.isRinging() && mSipCall.isIncoming()) {
403 acceptCall();
404 } else {
405 hangupCall();
406 }
407 }
408
409 public void negativeButtonClicked() {
410 if (mSipCall.isRinging() && mSipCall.isIncoming()) {
411 refuseCall();
412 } else {
413 hangupCall();
414 }
415 }
416
417 public void toggleButtonClicked() {
418 if (!(mSipCall.isRinging() && mSipCall.isIncoming())) {
419 hangupCall();
420 }
421 }
Adrien Béraud79808d02018-02-20 00:16:28 +0100422
Rayan Osseiran38206c62019-05-15 14:49:03 -0400423 public boolean isAudioOnly() {
424 return mAudioOnly;
425 }
426
Adrien Béraud79808d02018-02-20 00:16:28 +0100427 public void requestPipMode() {
Adrien Béraud6325fad2018-08-15 15:34:11 -0400428 if (mSipCall != null && mSipCall.isOnGoing() && !mSipCall.isAudioOnly()) {
Adrien Béraud79808d02018-02-20 00:16:28 +0100429 getView().enterPipMode(mSipCall);
430 }
431 }
432
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400433 public boolean isPipMode() {
434 return pipIsActive;
435 }
436
Adrien Béraud79808d02018-02-20 00:16:28 +0100437 public void pipModeChanged(boolean pip) {
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400438 pipIsActive = pip;
Adrien Béraud79808d02018-02-20 00:16:28 +0100439 if (pip) {
440 getView().displayHangupButton(false);
441 getView().displayPreviewSurface(false);
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400442 getView().displayVideoSurface(true, false);
Adrien Béraud79808d02018-02-20 00:16:28 +0100443 } else {
444 getView().displayPreviewSurface(true);
Rayan Osseiranc1532d42019-06-05 13:17:53 -0400445 getView().displayVideoSurface(true, mDeviceRuntimeService.hasVideoPermission());
Adrien Béraud79808d02018-02-20 00:16:28 +0100446 }
447 }
Adrien Béraudbc0898e2018-08-23 14:31:11 -0400448
449 public boolean isSpeakerphoneOn() {
450 return mHardwareService.isSpeakerPhoneOn();
451 }
Adrien Béraudbcbb4d42018-12-08 16:06:39 -0500452
453 public void sendDtmf(CharSequence s) {
454 mCallService.playDtmf(s.toString());
455 }
Hadrien De Sousaccc947d2017-04-12 14:26:52 -0400456}