diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/CallScreen.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/CallScreen.kt index 76241015..bb63857f 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/CallScreen.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/CallScreen.kt @@ -6,6 +6,7 @@ import android.Manifest import android.app.Activity import android.content.Context import android.content.ContextWrapper +import android.content.pm.ActivityInfo import android.content.pm.PackageManager import android.os.Build import androidx.activity.compose.BackHandler @@ -134,6 +135,31 @@ fun CallScreen( val locked = phase == CallPhase.ACTIVE && route == AudioRoute.EARPIECE && proximityNear val context = LocalContext.current + // Ориентация принадлежит экрану звонка; краткое переподключение Surface не должно поворачивать его обратно. + DisposableEffect(video, phase == CallPhase.ACTIVE) { + val activity = context.findActivity(); val previous = activity?.requestedOrientation + onDispose { + if (activity != null && previous != null && activity.requestedOrientation != previous) { + activity.requestedOrientation = previous + LogManager.addLog("INFO", "call", "video screen orientation restored=$previous") + } + } + } + LaunchedEffect(video, phase, remote?.width, remote?.height, remote?.rotation) { + val format = remote + val activity = context.findActivity() + if (phase == CallPhase.ACTIVE && format != null && activity != null) { + val rotated = format.rotation % 180 != 0 + val width = if (rotated) format.height else format.width + val height = if (rotated) format.width else format.height + val orientation = if (width > height) ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + else ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + if (activity.requestedOrientation != orientation) { + activity.requestedOrientation = orientation + LogManager.addLog("INFO", "call", "video screen orientation=$orientation display=${width}x$height rotation=${format.rotation}") + } + } + } val hasBtPermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED