Skip to content

Commit

Permalink
fix: call gui not visible on devices with android version > android 11
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanA101a committed Nov 20, 2023
1 parent 9c6db3d commit 485b44f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
10 changes: 10 additions & 0 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,16 @@
"type": "text",
"placeholders": {}
},
"phonePermissionDeniedNotice": "Phone permission denied. Please grant it to be able to properly send and recieve calls.",
"@phonePermissionDeniedNotice": {
"type": "text",
"placeholders": {}
},
"phonePermissionPermanentlyDeniedNotice": "Phone permission permanently denied. Calling functionality will not work as intended. Visit settings to set the right permission.",
"@phonePermissionPermanentlyDeniedNotice": {
"type": "text",
"placeholders": {}
},
"login": "Login",
"@login": {
"type": "text",
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class ChatListController extends State<ChatList>
scrollController.addListener(_onScroll);
_waitForFirstSync();
_hackyWebRTCFixForWeb();
CallKeepManager().initialize();
CallKeepManager().initialize(context: context);
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
searchServer =
Expand Down
36 changes: 35 additions & 1 deletion lib/utils/voip/callkeep_manager.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'dart:async';
import 'dart:developer';

import 'package:flutter/material.dart';

import 'package:callkeep/callkeep.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:permission_handler/permission_handler.dart';

import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/voip_plugin.dart';

class CallKeeper {
Expand Down Expand Up @@ -167,7 +170,33 @@ class CallKeepManager {
Logs().v('[onPushKitToken] token => ${event.token}');
}

Future<void> initialize() async {
Future<void> initialize({BuildContext? context}) async {
if (PlatformInfos.isAndroid) {
tryReadPhoneStatePermission().then((pStatus) {
log(pStatus.toString());
if (context != null) {
if (pStatus == PermissionStatus.denied ||
pStatus == PermissionStatus.permanentlyDenied) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 4),
content: Text(
pStatus == PermissionStatus.denied
? L10n.of(context)!.phonePermissionDeniedNotice
: L10n.of(context)!
.phonePermissionPermanentlyDeniedNotice,
),
action: SnackBarAction(
label: L10n.of(context)!.settings,
onPressed: openAppSettings,
),
),
);
}
}
});
}

_callKeep.on(CallKeepPerformAnswerCallAction(), answerCall);
_callKeep.on(CallKeepDidPerformDTMFAction(), didPerformDTMFAction);
_callKeep.on(
Expand Down Expand Up @@ -365,3 +394,8 @@ class CallKeepManager {
setCallHeld(event.callUUID, event.hold);
}
}

Future<PermissionStatus?> tryReadPhoneStatePermission() async {
final info = await DeviceInfoPlugin().androidInfo;
return info.version.sdkInt > 30 ? await Permission.phone.request() : null;
}

0 comments on commit 485b44f

Please # to comment.