From ac63aff3a725dab6ab725065246fb76133d0b4b7 Mon Sep 17 00:00:00 2001 From: Rasul Date: Mon, 26 Feb 2024 22:38:16 +0300 Subject: [PATCH 1/3] Added ability to skip checking access background permission in android --- .../lyokone/location/MethodCallHandlerImpl.java | 3 ++- packages/location/lib/location.dart | 10 ++++++++-- packages/location/pubspec.yaml | 6 ++++-- .../lib/location_platform_interface.dart | 6 +++++- .../lib/src/method_channel_location.dart | 14 ++++++++++---- packages/location_web/pubspec.yaml | 3 ++- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/location/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java b/packages/location/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java index b2985f68..491ab3b1 100644 --- a/packages/location/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java +++ b/packages/location/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java @@ -163,8 +163,9 @@ private void isBackgroundModeEnabled(Result result) { private void enableBackgroundMode(MethodCall call, Result result) { final Boolean enable = call.argument("enable"); + final Boolean checkBackgroundPermissions = call.argument("checkBackgroundPermissions"); if (locationService != null && enable != null) { - if (locationService.checkBackgroundPermissions()) { + if (!checkBackgroundPermissions || locationService.checkBackgroundPermissions()) { if (enable) { locationService.enableBackgroundMode(); diff --git a/packages/location/lib/location.dart b/packages/location/lib/location.dart index 92a109ae..43787d52 100644 --- a/packages/location/lib/location.dart +++ b/packages/location/lib/location.dart @@ -47,8 +47,14 @@ class Location implements LocationPlatform { /// Enables or disables service in the background mode. @override - Future enableBackgroundMode({bool? enable = true}) { - return LocationPlatform.instance.enableBackgroundMode(enable: enable); + Future enableBackgroundMode({ + bool? enable = true, + bool? checkBackgroundPermissions = false, + }) { + return LocationPlatform.instance.enableBackgroundMode( + enable: enable, + checkBackgroundPermissions: checkBackgroundPermissions, + ); } /// Gets the current location of the user. diff --git a/packages/location/pubspec.yaml b/packages/location/pubspec.yaml index 0ff0f300..7a810b59 100644 --- a/packages/location/pubspec.yaml +++ b/packages/location/pubspec.yaml @@ -25,8 +25,10 @@ flutter: dependencies: flutter: sdk: flutter - location_platform_interface: ^3.1.1 - location_web: ^4.1.1 + location_platform_interface: + path: ../location_platform_interface + location_web: + path: ../location_web dev_dependencies: async: ^2.5.0 build_runner: ^2.3.3 diff --git a/packages/location_platform_interface/lib/location_platform_interface.dart b/packages/location_platform_interface/lib/location_platform_interface.dart index 2fff3c90..42b35911 100644 --- a/packages/location_platform_interface/lib/location_platform_interface.dart +++ b/packages/location_platform_interface/lib/location_platform_interface.dart @@ -8,6 +8,7 @@ import 'package:flutter/services.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; part 'src/method_channel_location.dart'; + part 'src/types.dart'; /// The interface that implementations of `location` must extend. @@ -53,7 +54,10 @@ class LocationPlatform extends PlatformInterface { } /// Enables or disables service in the background mode. - Future enableBackgroundMode({bool? enable}) { + Future enableBackgroundMode({ + bool? enable, + bool? checkBackgroundPermissions, + }) { throw UnimplementedError(); } diff --git a/packages/location_platform_interface/lib/src/method_channel_location.dart b/packages/location_platform_interface/lib/src/method_channel_location.dart index 0aea662b..b9ad6ba3 100644 --- a/packages/location_platform_interface/lib/src/method_channel_location.dart +++ b/packages/location_platform_interface/lib/src/method_channel_location.dart @@ -58,16 +58,22 @@ class MethodChannelLocation extends LocationPlatform { @override Future isBackgroundModeEnabled() async { final result = - await _methodChannel!.invokeMethod('isBackgroundModeEnabled'); + await _methodChannel!.invokeMethod('isBackgroundModeEnabled'); return result == 1; } /// Enables or disables service in the background mode. @override - Future enableBackgroundMode({bool? enable}) async { + Future enableBackgroundMode({ + bool? enable, + bool? checkBackgroundPermissions, + }) async { final result = await _methodChannel!.invokeMethod( 'enableBackgroundMode', - {'enable': enable}, + { + 'enable': enable, + 'checkBackgroundPermissions': checkBackgroundPermissions, + }, ); return result == 1; @@ -80,7 +86,7 @@ class MethodChannelLocation extends LocationPlatform { @override Future getLocation() async { final resultMap = - await _methodChannel!.invokeMapMethod('getLocation'); + await _methodChannel!.invokeMapMethod('getLocation'); if (resultMap == null) { throw PlatformException( code: 'NULL_RESULT', diff --git a/packages/location_web/pubspec.yaml b/packages/location_web/pubspec.yaml index cce5e25a..87b26abe 100644 --- a/packages/location_web/pubspec.yaml +++ b/packages/location_web/pubspec.yaml @@ -16,7 +16,8 @@ dependencies: sdk: flutter http_parser: ^4.0.0 js: ^0.6.3 - location_platform_interface: ^3.1.1 + location_platform_interface: + path: ../location_platform_interface dev_dependencies: flutter_test: From e688e1b1560fbc5abd7f742d822fe9523ef46e27 Mon Sep 17 00:00:00 2001 From: Rasul Date: Wed, 3 Apr 2024 21:50:31 +0300 Subject: [PATCH 2/3] reverted packages/location_web/pubspec.yaml --- packages/location_web/pubspec.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/location_web/pubspec.yaml b/packages/location_web/pubspec.yaml index 87b26abe..cce5e25a 100644 --- a/packages/location_web/pubspec.yaml +++ b/packages/location_web/pubspec.yaml @@ -16,8 +16,7 @@ dependencies: sdk: flutter http_parser: ^4.0.0 js: ^0.6.3 - location_platform_interface: - path: ../location_platform_interface + location_platform_interface: ^3.1.1 dev_dependencies: flutter_test: From 22e1076b4da3cf65574481107d4b410dac808ce7 Mon Sep 17 00:00:00 2001 From: Rasul Date: Wed, 3 Apr 2024 21:56:40 +0300 Subject: [PATCH 3/3] reverted packages/location/pubspec.yaml --- packages/location/pubspec.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/location/pubspec.yaml b/packages/location/pubspec.yaml index 7a810b59..0ff0f300 100644 --- a/packages/location/pubspec.yaml +++ b/packages/location/pubspec.yaml @@ -25,10 +25,8 @@ flutter: dependencies: flutter: sdk: flutter - location_platform_interface: - path: ../location_platform_interface - location_web: - path: ../location_web + location_platform_interface: ^3.1.1 + location_web: ^4.1.1 dev_dependencies: async: ^2.5.0 build_runner: ^2.3.3