Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1 | /* |
Sébastien Blin | ab53ada | 2019-01-02 17:23:00 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2019 Savoir-faire Linux Inc. |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Hadrien De Sousa <hadrien.desousa@savoirfairelinux.com> |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 5 | * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 6 | * |
| 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 | */ |
| 21 | package cx.ring.call; |
| 22 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 23 | import java.util.concurrent.TimeUnit; |
| 24 | |
| 25 | import javax.inject.Inject; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 26 | import javax.inject.Named; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 27 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 28 | import cx.ring.model.SipCall; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 29 | import cx.ring.mvp.RootPresenter; |
| 30 | import cx.ring.services.AccountService; |
| 31 | import cx.ring.services.CallService; |
Adrien Béraud | 8d71075 | 2019-02-20 13:53:59 -0500 | [diff] [blame] | 32 | import cx.ring.services.ContactService; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 33 | import cx.ring.services.DeviceRuntimeService; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 34 | import cx.ring.services.HardwareService; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 35 | import cx.ring.services.NotificationService; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 36 | import cx.ring.utils.Log; |
Hadrien De Sousa | c165e9b | 2017-11-24 12:33:32 -0500 | [diff] [blame] | 37 | import cx.ring.utils.StringUtils; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 38 | import io.reactivex.Scheduler; |
Adrien Béraud | 3aeed5d | 2018-07-26 11:26:13 -0400 | [diff] [blame] | 39 | import io.reactivex.disposables.Disposable; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 40 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 41 | public class CallPresenter extends RootPresenter<CallView> { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 42 | |
| 43 | public final static String TAG = CallPresenter.class.getSimpleName(); |
| 44 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 45 | private AccountService mAccountService; |
Adrien Béraud | 8d71075 | 2019-02-20 13:53:59 -0500 | [diff] [blame] | 46 | private ContactService mContactService; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 47 | private NotificationService mNotificationService; |
| 48 | private HardwareService mHardwareService; |
| 49 | private CallService mCallService; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 50 | private DeviceRuntimeService mDeviceRuntimeService; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 51 | |
| 52 | private SipCall mSipCall; |
| 53 | private boolean mOnGoingCall = false; |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 54 | private boolean mAudioOnly = true; |
Adrien Béraud | 335d32e | 2019-05-31 09:31:40 -0400 | [diff] [blame] | 55 | private boolean permissionChanged = false; |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 56 | private boolean pipIsActive = false; |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame^] | 57 | private boolean incomingIsFullIntent = true; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 58 | |
| 59 | private int videoWidth = -1; |
| 60 | private int videoHeight = -1; |
| 61 | private int previewWidth = -1; |
| 62 | private int previewHeight = -1; |
| 63 | |
Adrien Béraud | 3aeed5d | 2018-07-26 11:26:13 -0400 | [diff] [blame] | 64 | private Disposable timeUpdateTask = null; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 65 | |
| 66 | @Inject |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 67 | @Named("UiScheduler") |
| 68 | protected Scheduler mUiScheduler; |
| 69 | |
| 70 | @Inject |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 71 | public CallPresenter(AccountService accountService, |
Adrien Béraud | 8d71075 | 2019-02-20 13:53:59 -0500 | [diff] [blame] | 72 | ContactService contactService, |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 73 | NotificationService notificationService, |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 74 | HardwareService hardwareService, |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 75 | CallService callService, DeviceRuntimeService deviceRuntimeService) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 76 | mAccountService = accountService; |
Adrien Béraud | 8d71075 | 2019-02-20 13:53:59 -0500 | [diff] [blame] | 77 | mContactService = contactService; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 78 | mNotificationService = notificationService; |
| 79 | mHardwareService = hardwareService; |
| 80 | mCallService = callService; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 81 | mDeviceRuntimeService = deviceRuntimeService; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 84 | public void cameraPermissionChanged(boolean isGranted) { |
| 85 | if (isGranted && mHardwareService.isVideoAvailable()) { |
| 86 | mHardwareService.initVideo(); |
Adrien Béraud | 335d32e | 2019-05-31 09:31:40 -0400 | [diff] [blame] | 87 | permissionChanged = true; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | public void audioPermissionChanged(boolean isGranted) { |
Rayan Osseiran | db4667e | 2019-05-31 09:41:54 -0400 | [diff] [blame] | 92 | if (isGranted && mHardwareService.hasMicrophone()) { |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 93 | mCallService.setAudioPlugin(mCallService.getCurrentAudioOutputPlugin()); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 98 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 99 | public void unbindView() { |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 100 | if (!mAudioOnly) { |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 101 | mHardwareService.endCapture(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 102 | } |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 103 | super.unbindView(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void bindView(CallView view) { |
| 108 | super.bindView(view); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 109 | mCompositeDisposable.add(mAccountService.getRegisteredNames() |
| 110 | .observeOn(mUiScheduler) |
| 111 | .subscribe(r -> { |
| 112 | if (mSipCall != null && mSipCall.getContact() != null) { |
| 113 | getView().updateContactBubble(mSipCall.getContact()); |
| 114 | } |
| 115 | })); |
| 116 | mCompositeDisposable.add(mHardwareService.getVideoEvents() |
| 117 | .observeOn(mUiScheduler) |
| 118 | .subscribe(this::onVideoEvent)); |
Adrien Béraud | 057e9a3 | 2018-09-30 17:48:55 -0400 | [diff] [blame] | 119 | mCompositeDisposable.add(mHardwareService |
| 120 | .getBluetoothEvents() |
| 121 | .subscribe(event -> { |
| 122 | if (!event.connected && mSipCall != null) { |
| 123 | hangupCall(); |
| 124 | } |
| 125 | })); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 128 | public void initOutGoing(String accountId, String contactRingId, boolean audioOnly) { |
Adrien Béraud | 85683c2 | 2018-05-23 11:18:43 -0400 | [diff] [blame] | 129 | if (accountId == null || contactRingId == null) { |
| 130 | Log.e(TAG, "initOutGoing: null account or contact"); |
| 131 | getView().finish(); |
| 132 | return; |
| 133 | } |
Hadrien De Sousa | fcf2a99 | 2017-12-15 11:08:56 -0500 | [diff] [blame] | 134 | if (mHardwareService.getCameraCount() == 0) { |
Adrien Béraud | d3bf4e4 | 2018-02-14 14:44:41 +0100 | [diff] [blame] | 135 | audioOnly = true; |
Hadrien De Sousa | fcf2a99 | 2017-12-15 11:08:56 -0500 | [diff] [blame] | 136 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 137 | //getView().blockScreenRotation(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 138 | |
| 139 | mCompositeDisposable.add(mCallService |
| 140 | .placeCallObservable(accountId, StringUtils.toNumber(contactRingId), audioOnly) |
| 141 | .observeOn(mUiScheduler) |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 142 | .subscribe(call -> { |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 143 | contactUpdate(call); |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 144 | confUpdate(call); |
Rayan Osseiran | db4667e | 2019-05-31 09:41:54 -0400 | [diff] [blame] | 145 | }, e -> { |
| 146 | hangupCall(); |
| 147 | Log.e(TAG, "Error with initOutgoing: " + e.getMessage()); |
| 148 | })); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame^] | 151 | public void updateIncomingCall(String confId) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 152 | //getView().blockScreenRotation(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 153 | mCompositeDisposable.add(mCallService.getCallUpdates(confId) |
| 154 | .observeOn(mUiScheduler) |
| 155 | .subscribe(call -> { |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 156 | contactUpdate(call); |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 157 | confUpdate(call); |
Rayan Osseiran | db4667e | 2019-05-31 09:41:54 -0400 | [diff] [blame] | 158 | }, e -> { |
| 159 | hangupCall(); |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame^] | 160 | Log.e(TAG, "Error with updateIncoming: " + e.getMessage()); |
Rayan Osseiran | db4667e | 2019-05-31 09:41:54 -0400 | [diff] [blame] | 161 | })); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame^] | 164 | public void initIncoming(String confId) { |
| 165 | mCompositeDisposable.add(mCallService.getCallUpdates(confId).observeOn(mUiScheduler).firstOrError().subscribe(call -> { |
| 166 | incomingIsFullIntent = false; |
| 167 | contactUpdate(call); |
| 168 | confUpdate(call); |
| 169 | getView().prepareCall(true); |
| 170 | }, e -> { |
| 171 | hangupCall(); |
| 172 | Log.e(TAG, "Error with initIncoming: " + e.getMessage()); |
| 173 | })); |
| 174 | } |
| 175 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 176 | public void prepareOptionMenu() { |
| 177 | boolean isSpeakerOn = mHardwareService.isSpeakerPhoneOn(); |
| 178 | boolean hasContact = mSipCall != null && null != mSipCall.getContact() && mSipCall.getContact().isUnknown(); |
| 179 | boolean canDial = mOnGoingCall && mSipCall != null && !mSipCall.isIncoming(); |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 180 | boolean hasMultipleCamera = mHardwareService.getCameraCount() > 1 && mOnGoingCall && !mAudioOnly; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 181 | getView().initMenu(isSpeakerOn, hasContact, hasMultipleCamera, canDial, mOnGoingCall); |
| 182 | } |
| 183 | |
| 184 | public void chatClick() { |
| 185 | if (mSipCall == null |
| 186 | || mSipCall.getContact() == null |
| 187 | || mSipCall.getContact().getIds() == null |
| 188 | || mSipCall.getContact().getIds().isEmpty()) { |
| 189 | return; |
| 190 | } |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 191 | getView().goToConversation(mSipCall.getAccount(), mSipCall.getContact().getIds().get(0)); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 194 | public void speakerClick(boolean checked) { |
| 195 | mHardwareService.toggleSpeakerphone(checked); |
| 196 | } |
| 197 | |
| 198 | public void muteMicrophoneToggled(boolean checked) { |
| 199 | mCallService.setMuted(checked); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 202 | |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 203 | public boolean isMicrophoneMuted() { |
| 204 | return mCallService.isCaptureMuted(); |
| 205 | } |
| 206 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 207 | public void switchVideoInputClick() { |
Adrien Béraud | 335d32e | 2019-05-31 09:31:40 -0400 | [diff] [blame] | 208 | mHardwareService.switchInput(mSipCall.getCallId(), false); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 209 | getView().switchCameraIcon(mHardwareService.isPreviewFromFrontCamera()); |
| 210 | } |
| 211 | |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 212 | public void configurationChanged(int rotation) { |
| 213 | mHardwareService.setDeviceOrientation(rotation); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | public void dialpadClick() { |
| 217 | getView().displayDialPadKeyboard(); |
| 218 | } |
| 219 | |
| 220 | public void acceptCall() { |
| 221 | if (mSipCall == null) { |
| 222 | return; |
| 223 | } |
| 224 | mCallService.accept(mSipCall.getCallId()); |
| 225 | } |
| 226 | |
| 227 | public void hangupCall() { |
| 228 | if (mSipCall != null) { |
| 229 | mCallService.hangUp(mSipCall.getCallId()); |
| 230 | } |
| 231 | finish(); |
| 232 | } |
| 233 | |
| 234 | public void refuseCall() { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 235 | final SipCall call = mSipCall; |
| 236 | if (call != null) { |
| 237 | mCallService.refuse(call.getCallId()); |
| 238 | mNotificationService.cancelCallNotification(call.getCallId().hashCode()); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 239 | } |
| 240 | finish(); |
| 241 | } |
| 242 | |
| 243 | public void videoSurfaceCreated(Object holder) { |
Alexandre Lision | e4d4026 | 2016-12-12 14:30:09 -0500 | [diff] [blame] | 244 | if (mSipCall == null) { |
| 245 | return; |
| 246 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 247 | mHardwareService.addVideoSurface(mSipCall.getCallId(), holder); |
| 248 | getView().displayContactBubble(false); |
| 249 | } |
| 250 | |
| 251 | public void previewVideoSurfaceCreated(Object holder) { |
Adrien Béraud | 0c14a9e | 2019-06-01 19:28:14 -0400 | [diff] [blame] | 252 | mHardwareService.addPreviewVideoSurface(holder, mSipCall); |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 253 | //mHardwareService.startCapture(null); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | public void videoSurfaceDestroyed() { |
| 257 | if (mSipCall == null) { |
| 258 | return; |
| 259 | } |
| 260 | mHardwareService.removeVideoSurface(mSipCall.getCallId()); |
| 261 | } |
| 262 | |
| 263 | public void previewVideoSurfaceDestroyed() { |
| 264 | mHardwareService.removePreviewVideoSurface(); |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 265 | mHardwareService.endCapture(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | public void displayChanged() { |
Adrien Béraud | 335d32e | 2019-05-31 09:31:40 -0400 | [diff] [blame] | 269 | mHardwareService.switchInput(mSipCall.getCallId(), false); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | public void layoutChanged() { |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 273 | //getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 276 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 277 | public void uiVisibilityChanged(boolean displayed) { |
Adrien Béraud | 665faa2 | 2018-07-26 16:51:20 -0400 | [diff] [blame] | 278 | CallView view = getView(); |
| 279 | if (view != null) |
| 280 | view.displayHangupButton(mOnGoingCall && displayed); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | private void finish() { |
Adrien Béraud | 3aeed5d | 2018-07-26 11:26:13 -0400 | [diff] [blame] | 284 | if (timeUpdateTask != null && !timeUpdateTask.isDisposed()) { |
| 285 | timeUpdateTask.dispose(); |
| 286 | timeUpdateTask = null; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 287 | } |
| 288 | mSipCall = null; |
Adrien Béraud | 8d6baf3 | 2018-08-03 23:37:31 -0400 | [diff] [blame] | 289 | CallView view = getView(); |
| 290 | if (view != null) |
| 291 | view.finish(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 292 | } |
| 293 | |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 294 | private void contactUpdate(final SipCall call) { |
| 295 | if (mSipCall != call) { |
| 296 | mSipCall = call; |
Adrien Béraud | 8d71075 | 2019-02-20 13:53:59 -0500 | [diff] [blame] | 297 | mCompositeDisposable.add(mContactService.observeContact(call.getAccount(), call.getContact()) |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 298 | .observeOn(mUiScheduler) |
Rayan Osseiran | db4667e | 2019-05-31 09:41:54 -0400 | [diff] [blame] | 299 | .subscribe(c -> getView().updateContactBubble(c), e -> Log.e(TAG, e.getMessage()))); |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 303 | private void confUpdate(SipCall call) { |
| 304 | mAudioOnly = call.isAudioOnly(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 305 | CallView view = getView(); |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 306 | if (view == null) |
| 307 | return; |
| 308 | view.updateMenu(); |
| 309 | if (call.isOnGoing()) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 310 | mOnGoingCall = true; |
Rayan Osseiran | 8c59d2e | 2019-06-28 11:06:08 -0400 | [diff] [blame] | 311 | mHardwareService.toggleSpeakerphone(!mAudioOnly); |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 312 | view.initNormalStateDisplay(mAudioOnly, mHardwareService.isSpeakerPhoneOn(), isMicrophoneMuted()); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 313 | view.updateMenu(); |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 314 | if (!mAudioOnly) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 315 | mHardwareService.setPreviewSettings(); |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 316 | view.displayVideoSurface(true, mDeviceRuntimeService.hasVideoPermission()); |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame^] | 317 | if (permissionChanged) { |
Adrien Béraud | 335d32e | 2019-05-31 09:31:40 -0400 | [diff] [blame] | 318 | mHardwareService.switchInput(mSipCall.getCallId(), permissionChanged); |
| 319 | permissionChanged = false; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 320 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 321 | } |
Adrien Béraud | 3aeed5d | 2018-07-26 11:26:13 -0400 | [diff] [blame] | 322 | if (timeUpdateTask != null) |
| 323 | timeUpdateTask.dispose(); |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 324 | timeUpdateTask = mUiScheduler.schedulePeriodicallyDirect(this::updateTime, 0, 1, TimeUnit.SECONDS); |
| 325 | } else if (call.isRinging()) { |
| 326 | if (call.isIncoming()) { |
| 327 | if (mAccountService.getAccount(call.getAccount()).isAutoanswerEnabled()) { |
| 328 | mCallService.accept(call.getCallId()); |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame^] | 329 | // only display the incoming call screen if the notification is a full screen intent |
| 330 | } else if (incomingIsFullIntent) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 331 | view.initIncomingCallDisplay(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 332 | } |
| 333 | } else { |
| 334 | mOnGoingCall = false; |
Adrien Béraud | 99fd420 | 2018-12-13 13:02:21 -0500 | [diff] [blame] | 335 | view.updateCallStatus(call.getCallState()); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 336 | view.initOutGoingCallDisplay(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 337 | } |
| 338 | } else { |
| 339 | finish(); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | private void updateTime() { |
Adrien Béraud | 6325fad | 2018-08-15 15:34:11 -0400 | [diff] [blame] | 344 | CallView view = getView(); |
| 345 | if (view != null && mSipCall != null) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 346 | long duration = System.currentTimeMillis() - mSipCall.getTimestampStart(); |
| 347 | duration = duration / 1000; |
| 348 | if (mSipCall.isOnGoing()) { |
Adrien Béraud | 6325fad | 2018-08-15 15:34:11 -0400 | [diff] [blame] | 349 | view.updateTime(duration); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 354 | private void onVideoEvent(HardwareService.VideoEvent event) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 355 | Log.d(TAG, "VIDEO_EVENT: " + event.start + " " + event.callId + " " + event.w + "x" + event.h); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 356 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 357 | if (event.start) { |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 358 | getView().displayVideoSurface(true, !isPipMode() && mDeviceRuntimeService.hasVideoPermission()); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 359 | } else if (mSipCall != null && mSipCall.getCallId().equals(event.callId)) { |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 360 | getView().displayVideoSurface(event.started, event.started && !isPipMode() && mDeviceRuntimeService.hasVideoPermission()); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 361 | if (event.started) { |
| 362 | videoWidth = event.w; |
| 363 | videoHeight = event.h; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 364 | getView().resetVideoSize(videoWidth, videoHeight); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 365 | } |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 366 | } else if (event.callId == null) { |
| 367 | if (event.started) { |
| 368 | previewWidth = event.w; |
| 369 | previewHeight = event.h; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 370 | getView().resetPreviewVideoSize(previewWidth, previewHeight, event.rot); |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 371 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 372 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 373 | /*if (event.started || event.start) { |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 374 | getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 375 | }*/ |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 376 | } |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 377 | |
| 378 | public void positiveButtonClicked() { |
| 379 | if (mSipCall.isRinging() && mSipCall.isIncoming()) { |
| 380 | acceptCall(); |
| 381 | } else { |
| 382 | hangupCall(); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | public void negativeButtonClicked() { |
| 387 | if (mSipCall.isRinging() && mSipCall.isIncoming()) { |
| 388 | refuseCall(); |
| 389 | } else { |
| 390 | hangupCall(); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | public void toggleButtonClicked() { |
| 395 | if (!(mSipCall.isRinging() && mSipCall.isIncoming())) { |
| 396 | hangupCall(); |
| 397 | } |
| 398 | } |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 399 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 400 | public boolean isAudioOnly() { |
| 401 | return mAudioOnly; |
| 402 | } |
| 403 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 404 | public void requestPipMode() { |
Adrien Béraud | 6325fad | 2018-08-15 15:34:11 -0400 | [diff] [blame] | 405 | if (mSipCall != null && mSipCall.isOnGoing() && !mSipCall.isAudioOnly()) { |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 406 | getView().enterPipMode(mSipCall); |
| 407 | } |
| 408 | } |
| 409 | |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 410 | public boolean isPipMode() { |
| 411 | return pipIsActive; |
| 412 | } |
| 413 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 414 | public void pipModeChanged(boolean pip) { |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 415 | pipIsActive = pip; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 416 | if (pip) { |
| 417 | getView().displayHangupButton(false); |
| 418 | getView().displayPreviewSurface(false); |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 419 | getView().displayVideoSurface(true, false); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 420 | } else { |
| 421 | getView().displayPreviewSurface(true); |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 422 | getView().displayVideoSurface(true, mDeviceRuntimeService.hasVideoPermission()); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 423 | } |
| 424 | } |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 425 | |
| 426 | public boolean isSpeakerphoneOn() { |
| 427 | return mHardwareService.isSpeakerPhoneOn(); |
| 428 | } |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 429 | |
| 430 | public void sendDtmf(CharSequence s) { |
| 431 | mCallService.playDtmf(s.toString()); |
| 432 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 433 | } |