From 7768e36c6296e1acc03ba30f1a9cdb93fa3a8fc7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 23 Apr 2020 17:37:12 +0200 Subject: [PATCH] Lock device awake during calls --- lib/ui/screens/call_screen.dart | 6 ++++++ lib/utils/device_utils.dart | 9 +++++++++ pubspec.lock | 7 +++++++ pubspec.yaml | 3 +++ 4 files changed, 25 insertions(+) create mode 100644 lib/utils/device_utils.dart diff --git a/lib/ui/screens/call_screen.dart b/lib/ui/screens/call_screen.dart index bcb5bbb..4eb8d88 100644 --- a/lib/ui/screens/call_screen.dart +++ b/lib/ui/screens/call_screen.dart @@ -10,6 +10,7 @@ import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/routes/main_route.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; import 'package:comunic/utils/account_utils.dart'; +import 'package:comunic/utils/device_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; @@ -147,6 +148,9 @@ class _CallScreenState extends SafeState { await this._memberReady(peer.userID); setState(() {}); + + // Lock device await + await setWakeLock(true); } catch (e, stack) { print("Could not initialize call! $e\n$stack"); setState(() => _error = true); @@ -156,6 +160,8 @@ class _CallScreenState extends SafeState { /// Do clean up operations when call screen is destroyed void _endCall() async { try { + await setWakeLock(false); + // Close all ready members for (final member in _membersList.readyPeers) await _removeMember(member.userID); diff --git a/lib/utils/device_utils.dart b/lib/utils/device_utils.dart new file mode 100644 index 0000000..acd7552 --- /dev/null +++ b/lib/utils/device_utils.dart @@ -0,0 +1,9 @@ +import 'package:wakelock/wakelock.dart'; + +/// Device utilities +/// +/// @author Pierre Hubert + +/// Interface for requesting device wake locking +Future setWakeLock(bool enabled) async => + await Wakelock.toggle(on: enabled); diff --git a/pubspec.lock b/pubspec.lock index 6eff9a5..0f2e402 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -455,6 +455,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + wakelock: + dependency: "direct main" + description: + name: wakelock + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4+1" web_socket_channel: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0e25b97..9734821 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -78,6 +78,9 @@ dependencies: # WebRTC calls flutter_webrtc: ^0.2.7 + # Prevent phone from auto-locking during calls + wakelock: ^0.1.4+1 + dev_dependencies: flutter_test: sdk: flutter