From b89b3db077cb1c0731e7735a4f5e6c1a73d1a44f Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 31 Aug 2020 14:06:15 +0300 Subject: [PATCH] Use proximity manager to turn the screen off while the ear speaker is used. --- .../app/features/call/VectorCallViewModel.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt index 8ad1b1a267..1fb9f83e1f 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt @@ -87,7 +87,8 @@ class VectorCallViewModel @AssistedInject constructor( @Assisted initialState: VectorCallViewState, @Assisted val args: CallArgs, val session: Session, - val webRtcPeerConnectionManager: WebRtcPeerConnectionManager + val webRtcPeerConnectionManager: WebRtcPeerConnectionManager, + val proximityManager: CallProximityManager ) : VectorViewModel(initialState) { var call: MxCall? = null @@ -145,10 +146,17 @@ class VectorCallViewModel @AssistedInject constructor( } override fun onAudioDevicesChange(mgr: WebRtcPeerConnectionManager) { + val currentSoundDevice = mgr.audioManager.getCurrentSoundDevice() + if (currentSoundDevice == CallAudioManager.SoundDevice.PHONE) { + proximityManager.start() + } else { + proximityManager.stop() + } + setState { copy( availableSoundDevices = mgr.audioManager.getAvailableSoundDevices(), - soundDevice = mgr.audioManager.getCurrentSoundDevice() + soundDevice = currentSoundDevice ) } } @@ -175,12 +183,18 @@ class VectorCallViewModel @AssistedInject constructor( val item: MatrixItem? = session.getUser(mxCall.otherUserId)?.toMatrixItem() mxCall.addListener(callStateListener) + + val currentSoundDevice = webRtcPeerConnectionManager.audioManager.getCurrentSoundDevice() + if (currentSoundDevice == CallAudioManager.SoundDevice.PHONE) { + proximityManager.start() + } + setState { copy( isVideoCall = mxCall.isVideoCall, callState = Success(mxCall.state), otherUserMatrixItem = item?.let { Success(it) } ?: Uninitialized, - soundDevice = webRtcPeerConnectionManager.audioManager.getCurrentSoundDevice(), + soundDevice = currentSoundDevice, availableSoundDevices = webRtcPeerConnectionManager.audioManager.getAvailableSoundDevices(), isFrontCamera = webRtcPeerConnectionManager.currentCameraType() == CameraType.FRONT, canSwitchCamera = webRtcPeerConnectionManager.canSwitchCamera(), @@ -201,6 +215,7 @@ class VectorCallViewModel @AssistedInject constructor( // session.callService().removeCallListener(callServiceListener) webRtcPeerConnectionManager.removeCurrentCallListener(currentCallListener) this.call?.removeListener(callStateListener) + proximityManager.stop() super.onCleared() }