From fbcfab1d840c9eee4a11ce7fab6914208af51e18 Mon Sep 17 00:00:00 2001 From: mechtech-mind Date: Fri, 17 Apr 2026 15:40:47 +0530 Subject: [PATCH 1/6] fix(android): prevent screen from turning off during active video calls --- .../kotlin/io/livekit/example/MainActivity.kt | 66 ++++++++++++++++++- example/lib/pages/room.dart | 13 ++++ pubspec.lock | 8 +-- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt b/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt index 8096b9cae..412d92990 100644 --- a/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt @@ -1,6 +1,68 @@ package io.livekit.example +import android.os.Build +import android.os.Bundle +import android.view.WindowManager import io.flutter.embedding.android.FlutterActivity +import io.flutter.embedding.engine.FlutterEngine +import io.flutter.plugin.common.MethodChannel -class MainActivity: FlutterActivity() { -} +class MainActivity : FlutterActivity() { + + private val CHANNEL = "livekit_incall" + + override fun configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + + MethodChannel( + flutterEngine.dartExecutor.binaryMessenger, + CHANNEL + ).setMethodCallHandler { call, result -> + when (call.method) { + "enableInCall" -> { + setInCallScreenFlags() + result.success(null) + } + "disableInCall" -> { + clearInCallScreenFlags() + result.success(null) + } + else -> result.notImplemented() + } + } + } + + private fun setInCallScreenFlags() { + val window = window + + // Keep screen on during call + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + + // Show over lock screen (modern way) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setTurnScreenOn(true) + setShowWhenLocked(true) + } else { + window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) + window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) + window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) + } + } + + private fun clearInCallScreenFlags() { + val window = window + + // Remove keep screen on + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + + // Reset lock screen behavior + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setTurnScreenOn(false) + setShowWhenLocked(false) + } else { + window.clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) + window.clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) + window.clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) + } + } +} \ No newline at end of file diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index 9551325ed..f583f3f4e 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:math' as math; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:livekit_client/livekit_client.dart'; import '../exts.dart'; @@ -34,6 +35,7 @@ class _RoomPageState extends State { @override void initState() { super.initState(); + enableInCallFlags(); // add callback for a `RoomEvent` as opposed to a `ParticipantEvent` widget.room.addListener(_onRoomDidUpdate); // add callbacks for finer grained events @@ -63,6 +65,7 @@ class _RoomPageState extends State { widget.room.removeListener(_onRoomDidUpdate); unawaited(_disposeRoomAsync()); onWindowShouldClose = null; + disableInCallFlags(); super.dispose(); } @@ -71,6 +74,16 @@ class _RoomPageState extends State { await widget.room.dispose(); } + static const platform = MethodChannel('livekit_incall'); + + Future enableInCallFlags() async { + await platform.invokeMethod('enableInCall'); + } + + Future disableInCallFlags() async { + await platform.invokeMethod('disableInCall'); + } + /// for more information, see [event types](https://docs.livekit.io/client/events/#events) void _setUpListeners() => _listener ..on((event) async { diff --git a/pubspec.lock b/pubspec.lock index 91eec853f..78c63498d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -436,10 +436,10 @@ packages: dependency: transitive description: name: matcher - sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 + sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6" url: "https://pub.dev" source: hosted - version: "0.12.19" + version: "0.12.18" material_color_utilities: dependency: transitive description: @@ -737,10 +737,10 @@ packages: dependency: transitive description: name: test_api - sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" + sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636" url: "https://pub.dev" source: hosted - version: "0.7.10" + version: "0.7.9" timing: dependency: transitive description: From 090e945a711a001725ba6f489451c6f2747173a7 Mon Sep 17 00:00:00 2001 From: mechtech-mind Date: Fri, 17 Apr 2026 15:55:50 +0530 Subject: [PATCH 2/6] wrapped functions in unawaited --- example/lib/pages/room.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index f583f3f4e..88522433f 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -35,7 +35,7 @@ class _RoomPageState extends State { @override void initState() { super.initState(); - enableInCallFlags(); + unawaited(enableInCallFlags()); // add callback for a `RoomEvent` as opposed to a `ParticipantEvent` widget.room.addListener(_onRoomDidUpdate); // add callbacks for finer grained events @@ -65,7 +65,7 @@ class _RoomPageState extends State { widget.room.removeListener(_onRoomDidUpdate); unawaited(_disposeRoomAsync()); onWindowShouldClose = null; - disableInCallFlags(); + unawaited(disableInCallFlags()); super.dispose(); } @@ -74,15 +74,15 @@ class _RoomPageState extends State { await widget.room.dispose(); } - static const platform = MethodChannel('livekit_incall'); + static const platform = MethodChannel('livekit_incall'); - Future enableInCallFlags() async { - await platform.invokeMethod('enableInCall'); - } + Future enableInCallFlags() async { + await platform.invokeMethod('enableInCall'); + } - Future disableInCallFlags() async { - await platform.invokeMethod('disableInCall'); - } + Future disableInCallFlags() async { + await platform.invokeMethod('disableInCall'); + } /// for more information, see [event types](https://docs.livekit.io/client/events/#events) void _setUpListeners() => _listener From d640649c1bc500a4e7ea65b9a34f1a3c23e9f978 Mon Sep 17 00:00:00 2001 From: mechtech-mind Date: Fri, 15 May 2026 11:48:59 +0530 Subject: [PATCH 3/6] Refine keep-awake implementation --- .../kotlin/io/livekit/example/MainActivity.kt | 20 ------------------- example/lib/pages/room.dart | 7 ++++++- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt b/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt index 412d92990..9a7fa8afb 100644 --- a/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/io/livekit/example/MainActivity.kt @@ -37,16 +37,6 @@ class MainActivity : FlutterActivity() { // Keep screen on during call window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - - // Show over lock screen (modern way) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - setTurnScreenOn(true) - setShowWhenLocked(true) - } else { - window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) - window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) - window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) - } } private fun clearInCallScreenFlags() { @@ -54,15 +44,5 @@ class MainActivity : FlutterActivity() { // Remove keep screen on window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - - // Reset lock screen behavior - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - setTurnScreenOn(false) - setShowWhenLocked(false) - } else { - window.clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) - window.clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) - window.clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) - } } } \ No newline at end of file diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index 88522433f..42a5cf1cb 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -35,7 +36,11 @@ class _RoomPageState extends State { @override void initState() { super.initState(); - unawaited(enableInCallFlags()); + + if(Platform.isAndroid){ + unawaited(enableInCallFlags()); + } + // add callback for a `RoomEvent` as opposed to a `ParticipantEvent` widget.room.addListener(_onRoomDidUpdate); // add callbacks for finer grained events From e7086944174180f7ab610e7ed32c3c381de16055 Mon Sep 17 00:00:00 2001 From: mechtech-mind Date: Fri, 15 May 2026 11:58:17 +0530 Subject: [PATCH 4/6] dart format --- example/lib/pages/room.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index 42a5cf1cb..fc2d68c13 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -37,10 +37,10 @@ class _RoomPageState extends State { void initState() { super.initState(); - if(Platform.isAndroid){ + if (Platform.isAndroid) { unawaited(enableInCallFlags()); } - + // add callback for a `RoomEvent` as opposed to a `ParticipantEvent` widget.room.addListener(_onRoomDidUpdate); // add callbacks for finer grained events From eddf371899839621c84ad989990547a57ee5bd46 Mon Sep 17 00:00:00 2001 From: Aayush Saurabh <85521656+mechtech-mind@users.noreply.github.com> Date: Fri, 15 May 2026 12:05:15 +0530 Subject: [PATCH 5/6] removed unreferenced pubspec.lock --- pubspec.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 1b633767a..9a7a4b124 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -436,10 +436,10 @@ packages: dependency: transitive description: name: matcher - sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6" + sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 url: "https://pub.dev" source: hosted - version: "0.12.18" + version: "0.12.19" material_color_utilities: dependency: transitive description: @@ -737,10 +737,10 @@ packages: dependency: transitive description: name: test_api - sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636" + sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" url: "https://pub.dev" source: hosted - version: "0.7.9" + version: "0.7.10" timing: dependency: transitive description: From 06982bab68eb7d9b364a974e71355f66f2f1f2e9 Mon Sep 17 00:00:00 2001 From: Aayush Saurabh <85521656+mechtech-mind@users.noreply.github.com> Date: Fri, 15 May 2026 13:32:24 +0530 Subject: [PATCH 6/6] Replace Platform.isAndroid with lkPlatformIs check Refactor platform check for enabling and disabling in-call flags also removed dart.io import --- example/lib/pages/room.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index fc2d68c13..27aa394b8 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -37,7 +36,7 @@ class _RoomPageState extends State { void initState() { super.initState(); - if (Platform.isAndroid) { + if (lkPlatformIs(PlatformType.android)) { unawaited(enableInCallFlags()); } @@ -70,7 +69,9 @@ class _RoomPageState extends State { widget.room.removeListener(_onRoomDidUpdate); unawaited(_disposeRoomAsync()); onWindowShouldClose = null; - unawaited(disableInCallFlags()); + if (lkPlatformIs(PlatformType.android)) { + unawaited(disableInCallFlags()); + } super.dispose(); }