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..88522433f 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(); + unawaited(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; + unawaited(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: