Skip to content

Commit

Permalink
fix: handling ActivityNotFoundExceptions [WPB-9794] (#3163)
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk authored Jul 5, 2024
1 parent de00641 commit 7d32939
Show file tree
Hide file tree
Showing 52 changed files with 817 additions and 1,425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.permission.PermissionDenialType

@Composable
fun CallOptionsControls(
Expand All @@ -47,7 +46,7 @@ fun CallOptionsControls(
toggleVideo: () -> Unit,
modifier: Modifier = Modifier,
shouldShowSpeakerButton: Boolean = true,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit
onCameraPermissionPermanentlyDenied: () -> Unit
) {
ConstraintLayout(
modifier = modifier
Expand Down Expand Up @@ -83,7 +82,7 @@ fun CallOptionsControls(
end.linkTo(cameraEndLink)
},
isCameraOn = isCameraOn,
onPermissionPermanentlyDenied = onPermissionPermanentlyDenied,
onPermissionPermanentlyDenied = onCameraPermissionPermanentlyDenied,
onCameraButtonClicked = toggleVideo
)
CallControlLabel(
Expand Down Expand Up @@ -141,6 +140,6 @@ fun PreviewCallOptionsControls() {
toggleSpeaker = { },
toggleMute = { },
toggleVideo = { },
onPermissionPermanentlyDenied = {}
onCameraPermissionPermanentlyDenied = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@ import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.permission.PermissionDenialType
import com.wire.android.util.permission.rememberCallingCameraRequestFlow
import com.wire.android.util.permission.rememberCameraPermissionFlow
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
fun CameraButton(
isCameraOn: Boolean = false,
onCameraButtonClicked: () -> Unit,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit,
size: Dp = dimensions().defaultCallingControlsSize,
onPermissionPermanentlyDenied: () -> Unit,
modifier: Modifier = Modifier,
isCameraOn: Boolean = false,
size: Dp = dimensions().defaultCallingControlsSize,
) {
val cameraPermissionCheck = CameraPermissionCheckFlow(
onPermissionGranted = onCameraButtonClicked,
onPermanentPermissionDecline = {
onPermissionPermanentlyDenied(
PermissionDenialType.CallingCamera
)
}
val cameraPermissionCheck = rememberCameraPermissionFlow(
onPermissionGranted = {
appLogger.d("Camera permission granted")
onCameraButtonClicked()
},
onPermissionDenied = { },
onPermissionPermanentlyDenied = onPermissionPermanentlyDenied
)

WireCallControlButton(
Expand All @@ -62,19 +61,6 @@ fun CameraButton(
)
}

@Composable
private fun CameraPermissionCheckFlow(
onPermissionGranted: () -> Unit,
onPermanentPermissionDecline: () -> Unit
) = rememberCallingCameraRequestFlow(
onPermissionGranted = {
appLogger.d("Camera permission granted")
onPermissionGranted()
},
onPermissionDenied = { },
onPermissionPermanentlyDenied = onPermanentPermissionDecline
)

@PreviewMultipleThemes
@Composable
fun PreviewComposableCameraButtonOn() = WireTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,21 @@ import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.permission.PermissionDenialType
import com.wire.android.util.permission.rememberCallingRecordAudioRequestFlow
import com.wire.android.util.permission.rememberRecordAudioPermissionFlow
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
fun JoinButton(
buttonClick: () -> Unit,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit,
onAudioPermissionPermanentlyDenied: () -> Unit,
modifier: Modifier = Modifier,
minSize: DpSize = MaterialTheme.wireDimensions.buttonMediumMinSize,
minClickableSize: DpSize = MaterialTheme.wireDimensions.buttonMinClickableSize,
horizontalPadding: Dp = MaterialTheme.wireDimensions.spacing8x,
horizontalPadding: Dp = MaterialTheme.wireDimensions.spacing8x
) {
val audioPermissionCheck = AudioPermissionCheckFlow(
onJoinCall = buttonClick,
onPermanentPermissionDecline = {
onPermissionPermanentlyDenied(
PermissionDenialType.CallingMicrophone
)
}
onPermanentPermissionDecline = onAudioPermissionPermanentlyDenied,
)

WirePrimaryButton(
Expand All @@ -65,7 +61,7 @@ fun JoinButton(
state = WireButtonState.Positive,
minSize = minSize,
minClickableSize = minClickableSize,
modifier = Modifier.padding(
modifier = modifier.padding(
horizontal = horizontalPadding
),
contentPadding = PaddingValues(
Expand All @@ -79,20 +75,20 @@ fun JoinButton(
private fun AudioPermissionCheckFlow(
onJoinCall: () -> Unit,
onPermanentPermissionDecline: () -> Unit
) = rememberCallingRecordAudioRequestFlow(
onAudioPermissionGranted = {
) = rememberRecordAudioPermissionFlow(
onPermissionGranted = {
appLogger.d("IncomingCall - Audio permission granted")
onJoinCall()
},
onAudioPermissionDenied = { },
onAudioPermissionPermanentlyDenied = onPermanentPermissionDecline
onPermissionDenied = { },
onPermissionPermanentlyDenied = onPermanentPermissionDecline
)

@PreviewMultipleThemes
@Composable
fun PreviewJoinButton() = WireTheme {
JoinButton(
buttonClick = {},
onPermissionPermanentlyDenied = {}
onAudioPermissionPermanentlyDenied = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.DpSize
Expand All @@ -34,26 +35,23 @@ import com.wire.android.ui.common.button.WireSecondaryButton
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.util.permission.PermissionDenialType
import com.wire.android.util.permission.rememberCallingRecordAudioRequestFlow
import com.wire.android.util.permission.rememberRecordAudioPermissionFlow
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
fun StartCallButton(
onPhoneButtonClick: () -> Unit,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit,
isCallingEnabled: Boolean
onAudioPermissionPermanentlyDenied: () -> Unit,
isCallingEnabled: Boolean,
modifier: Modifier = Modifier,
) {
val audioPermissionCheck = AudioPermissionCheckFlow(
startCall = onPhoneButtonClick,
onPermanentPermissionDecline = {
onPermissionPermanentlyDenied(
PermissionDenialType.CallingMicrophone
)
}
onPermanentPermissionDecline = onAudioPermissionPermanentlyDenied
)

WireSecondaryButton(
modifier = modifier,
onClick = audioPermissionCheck::launch,
leadingIcon = {
Icon(
Expand All @@ -78,21 +76,21 @@ fun StartCallButton(
private fun AudioPermissionCheckFlow(
startCall: () -> Unit,
onPermanentPermissionDecline: () -> Unit
) = rememberCallingRecordAudioRequestFlow(
onAudioPermissionGranted = {
) = rememberRecordAudioPermissionFlow(
onPermissionGranted = {
appLogger.d("startCall - Audio permission granted")
startCall()
},
onAudioPermissionDenied = { },
onAudioPermissionPermanentlyDenied = onPermanentPermissionDecline
onPermissionDenied = { },
onPermissionPermanentlyDenied = onPermanentPermissionDecline
)

@PreviewMultipleThemes
@Composable
fun PreviewStartCallButton() = WireTheme {
StartCallButton(
onPhoneButtonClick = {},
onPermissionPermanentlyDenied = {},
onAudioPermissionPermanentlyDenied = {},
isCallingEnabled = true
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.visbility.rememberVisibilityState
import com.wire.android.ui.home.conversations.PermissionPermanentlyDeniedDialogState
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.permission.PermissionDenialType
import com.wire.android.util.permission.rememberCallingRecordAudioRequestFlow
import com.wire.android.util.permission.rememberRecordAudioPermissionFlow
import com.wire.kalium.logic.data.call.ConversationType
import com.wire.kalium.logic.data.id.ConversationId

Expand Down Expand Up @@ -137,15 +136,13 @@ fun IncomingCallScreen(
acceptCall = audioPermissionCheck::launch,
onVideoPreviewCreated = ::setVideoPreview,
onSelfClearVideoPreview = ::clearVideoPreview,
onPermissionPermanentlyDenied = {
if (it is PermissionDenialType.CallingCamera) {
permissionPermanentlyDeniedDialogState.show(
PermissionPermanentlyDeniedDialogState.Visible(
title = R.string.app_permission_dialog_title,
description = R.string.camera_permission_dialog_description
)
onCameraPermissionPermanentlyDenied = {
permissionPermanentlyDeniedDialogState.show(
PermissionPermanentlyDeniedDialogState.Visible(
title = R.string.app_permission_dialog_title,
description = R.string.camera_permission_dialog_description
)
}
)
},
onMinimiseScreen = {
activity.moveTaskToBack(true)
Expand All @@ -169,7 +166,7 @@ private fun IncomingCallContent(
acceptCall: () -> Unit,
onVideoPreviewCreated: (view: View) -> Unit,
onSelfClearVideoPreview: () -> Unit,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit,
onCameraPermissionPermanentlyDenied: () -> Unit,
onMinimiseScreen: () -> Unit
) {
BackHandler {
Expand All @@ -191,7 +188,7 @@ private fun IncomingCallContent(
toggleMute = toggleMute,
toggleVideo = toggleVideo,
shouldShowSpeakerButton = false,
onPermissionPermanentlyDenied = onPermissionPermanentlyDenied
onCameraPermissionPermanentlyDenied = onCameraPermissionPermanentlyDenied
)
Box(
modifier = Modifier
Expand Down Expand Up @@ -276,13 +273,13 @@ private fun IncomingCallContent(
fun AudioPermissionCheckFlow(
onAcceptCall: () -> Unit,
onPermanentPermissionDecline: () -> Unit,
) = rememberCallingRecordAudioRequestFlow(
onAudioPermissionGranted = {
) = rememberRecordAudioPermissionFlow(
onPermissionGranted = {
appLogger.d("IncomingCall - Audio permission granted")
onAcceptCall()
},
onAudioPermissionDenied = { /* Nothing to do */ },
onAudioPermissionPermanentlyDenied = onPermanentPermissionDecline
onPermissionDenied = { /* Nothing to do */ },
onPermissionPermanentlyDenied = onPermanentPermissionDecline
)

@Preview
Expand All @@ -296,7 +293,7 @@ fun PreviewIncomingCallScreen() {
acceptCall = { },
onVideoPreviewCreated = { },
onSelfClearVideoPreview = { },
onPermissionPermanentlyDenied = { },
onCameraPermissionPermanentlyDenied = { },
onMinimiseScreen = { }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.permission.PermissionDenialType
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.conversation.Conversation
Expand Down Expand Up @@ -144,15 +143,13 @@ fun OngoingCallScreen(
onCollapse = { activity.moveTaskToBack(true) },
requestVideoStreams = ongoingCallViewModel::requestVideoStreams,
hideDoubleTapToast = ongoingCallViewModel::hideDoubleTapToast,
onPermissionPermanentlyDenied = {
if (it is PermissionDenialType.CallingCamera) {
permissionPermanentlyDeniedDialogState.show(
PermissionPermanentlyDeniedDialogState.Visible(
title = R.string.app_permission_dialog_title,
description = R.string.camera_permission_dialog_description
)
onCameraPermissionPermanentlyDenied = {
permissionPermanentlyDeniedDialogState.show(
PermissionPermanentlyDeniedDialogState.Visible(
title = R.string.app_permission_dialog_title,
description = R.string.camera_permission_dialog_description
)
}
)
}
)
BackHandler {
Expand All @@ -171,7 +168,7 @@ fun OngoingCallScreen(
startSendingVideoFeed = ongoingCallViewModel::startSendingVideoFeed,
stopSendingVideoFeed = ongoingCallViewModel::stopSendingVideoFeed,
clearVideoPreview = sharedCallingViewModel::clearVideoPreview,
)
)
}

@Composable
Expand Down Expand Up @@ -240,7 +237,7 @@ private fun OngoingCallContent(
clearVideoPreview: () -> Unit,
onCollapse: () -> Unit,
hideDoubleTapToast: () -> Unit,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit,
onCameraPermissionPermanentlyDenied: () -> Unit,
requestVideoStreams: (participants: List<UICallParticipant>) -> Unit
) {

Expand Down Expand Up @@ -286,7 +283,7 @@ private fun OngoingCallContent(
onHangUpCall = hangUpCall,
onToggleVideo = toggleVideo,
flipCamera = flipCamera,
onPermissionPermanentlyDenied = onPermissionPermanentlyDenied
onCameraPermissionPermanentlyDenied = onCameraPermissionPermanentlyDenied
)
},
) {
Expand Down Expand Up @@ -433,7 +430,7 @@ private fun CallingControls(
onHangUpCall: () -> Unit,
onToggleVideo: () -> Unit,
flipCamera: () -> Unit,
onPermissionPermanentlyDenied: (type: PermissionDenialType) -> Unit
onCameraPermissionPermanentlyDenied: () -> Unit
) {
Column(
modifier = Modifier.height(dimensions().defaultSheetPeekHeight)
Expand All @@ -449,7 +446,7 @@ private fun CallingControls(
MicrophoneButton(isMuted = isMuted, onMicrophoneButtonClicked = toggleMute)
CameraButton(
isCameraOn = isCameraOn,
onPermissionPermanentlyDenied = onPermissionPermanentlyDenied,
onPermissionPermanentlyDenied = onCameraPermissionPermanentlyDenied,
onCameraButtonClicked = onToggleVideo
)

Expand Down Expand Up @@ -497,7 +494,7 @@ fun PreviewOngoingCallScreen() = WireTheme {
clearVideoPreview = {},
onCollapse = {},
hideDoubleTapToast = {},
onPermissionPermanentlyDenied = {},
onCameraPermissionPermanentlyDenied = {},
requestVideoStreams = {},
)
}
Expand Down
Loading

0 comments on commit 7d32939

Please sign in to comment.