mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Getting rid of two TODOs regarding asking permissions during call
This commit is contained in:
parent
fa5eb6a285
commit
ee8c36f70b
2 changed files with 65 additions and 4 deletions
|
|
@ -19,10 +19,12 @@
|
|||
*/
|
||||
package org.linphone.ui.call
|
||||
|
||||
import android.Manifest
|
||||
import android.app.PictureInPictureParams
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.core.view.WindowCompat
|
||||
|
|
@ -72,6 +74,28 @@ class CallActivity : GenericActivity() {
|
|||
|
||||
private var bottomSheetDialog: BottomSheetDialogFragment? = null
|
||||
|
||||
private val requestCameraPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
if (isGranted) {
|
||||
Log.i("$TAG CAMERA permission has been granted, enabling video")
|
||||
callViewModel.toggleVideo()
|
||||
} else {
|
||||
Log.e("$TAG CAMERA permission has been denied")
|
||||
}
|
||||
}
|
||||
|
||||
private val requestRecordAudioPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
if (isGranted) {
|
||||
Log.i("$TAG RECORD_AUDIO permission has been granted, un-muting microphone")
|
||||
callViewModel.toggleMuteMicrophone()
|
||||
} else {
|
||||
Log.e("$TAG RECORD_AUDIO permission has been denied")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -178,6 +202,20 @@ class CallActivity : GenericActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
callViewModel.requestRecordAudioPermission.observe(this) {
|
||||
it.consume {
|
||||
Log.w("$TAG Asking for RECORD_AUDIO permission")
|
||||
requestRecordAudioPermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
|
||||
}
|
||||
}
|
||||
|
||||
callViewModel.requestCameraPermission.observe(this) {
|
||||
it.consume {
|
||||
Log.w("$TAG Asking for CAMERA permission")
|
||||
requestCameraPermissionLauncher.launch(Manifest.permission.CAMERA)
|
||||
}
|
||||
}
|
||||
|
||||
callsViewModel.showIncomingCallEvent.observe(this) {
|
||||
it.consume {
|
||||
val action = IncomingCallFragmentDirections.actionGlobalIncomingCallFragment()
|
||||
|
|
|
|||
|
|
@ -117,6 +117,14 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val requestRecordAudioPermission: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val requestCameraPermission: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
// To synchronize chronometers in UI
|
||||
val callDuration = MutableLiveData<Int>()
|
||||
|
||||
|
|
@ -391,8 +399,11 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
|
||||
isVideoEnabled.value = false
|
||||
isMicrophoneMuted.value = false
|
||||
fullScreenMode.value = false
|
||||
isMicrophoneMuted.value = ActivityCompat.checkSelfPermission(
|
||||
coreContext.context,
|
||||
Manifest.permission.RECORD_AUDIO
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
|
||||
numpadModel = NumpadModel(
|
||||
{ digit -> // onDigitClicked
|
||||
|
|
@ -463,7 +474,7 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
Manifest.permission.RECORD_AUDIO
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
// TODO: request record audio permission
|
||||
requestRecordAudioPermission.postValue(Event(true))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +575,7 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
Manifest.permission.CAMERA
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
// TODO: request video permission
|
||||
requestCameraPermission.postValue(Event(true))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -808,7 +819,19 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
isVideoEnabled.postValue(call.currentParams.isVideoEnabled)
|
||||
}
|
||||
|
||||
isMicrophoneMuted.postValue(call.microphoneMuted)
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
coreContext.context,
|
||||
Manifest.permission.RECORD_AUDIO
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
Log.w(
|
||||
"$TAG RECORD_AUDIO permission wasn't granted yet, considering microphone as muted!"
|
||||
)
|
||||
isMicrophoneMuted.postValue(false)
|
||||
} else {
|
||||
isMicrophoneMuted.postValue(call.microphoneMuted)
|
||||
}
|
||||
|
||||
val audioDevice = call.outputAudioDevice
|
||||
updateOutputAudioDevice(audioDevice)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue