From 80474a0b15f5d03b5656dce559bc41aa7930fbdf Mon Sep 17 00:00:00 2001 From: Seungsoo Lee Date: Thu, 29 Oct 2026 04:25:33 +0900 Subject: [PATCH 1/3] [geolocator] Fix concurrent getCurrentPosition calls and unimplemented methods getCurrentPosition kept a single pair of callbacks, so a call made while an earlier one was pending replaced them and the earlier call's Future never completed. Pending requests now join the request in flight and all complete with the same position or error. Upstream geolocator_apple had the same problem and fixed it the same way in https://github.com/Baseflow/flutter-geolocator/pull/1813. Calling a method the plugin does not implement, such as getLocationAccuracy, called NotImplemented() on the moved-from result and crashed the app. Reply through result_ instead. --- packages/geolocator/CHANGELOG.md | 5 +++ packages/geolocator/README.md | 2 +- .../integration_test/geolocator_test.dart | 16 +++++++ packages/geolocator/pubspec.yaml | 2 +- .../tizen/src/geolocator_tizen_plugin.cc | 3 +- .../geolocator/tizen/src/location_manager.cc | 42 ++++++++++--------- .../geolocator/tizen/src/location_manager.h | 6 ++- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/packages/geolocator/CHANGELOG.md b/packages/geolocator/CHANGELOG.md index 52b25023a..b0d328272 100644 --- a/packages/geolocator/CHANGELOG.md +++ b/packages/geolocator/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.1 + +* Fix `getCurrentPosition` never completing when it is called again before an earlier call completes. +* Fix a crash when an unimplemented method such as `getLocationAccuracy` is called. + ## 1.1.0 * Update geolocator_platform_interface to 4.4.0. diff --git a/packages/geolocator/README.md b/packages/geolocator/README.md index c20976efa..3a8ea4b28 100644 --- a/packages/geolocator/README.md +++ b/packages/geolocator/README.md @@ -11,7 +11,7 @@ The Tizen implementation of [`geolocator`](https://pub.dev/packages/geolocator). ```yaml dependencies: geolocator: ^14.0.3 - geolocator_tizen: ^1.1.0 + geolocator_tizen: ^1.1.1 ``` Then you can import `geolocator` in your Dart code: diff --git a/packages/geolocator/example/integration_test/geolocator_test.dart b/packages/geolocator/example/integration_test/geolocator_test.dart index 2cea758cf..a0c82a4be 100644 --- a/packages/geolocator/example/integration_test/geolocator_test.dart +++ b/packages/geolocator/example/integration_test/geolocator_test.dart @@ -4,6 +4,7 @@ import 'dart:async'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:geolocator/geolocator.dart'; import 'package:integration_test/integration_test.dart'; @@ -29,6 +30,21 @@ Future main() async { expect(await Geolocator.getCurrentPosition(), isA()); }, timeout: const Timeout(Duration(seconds: 10))); + test('concurrent get current position calls all complete', () async { + final List positions = await Future.wait(>[ + Geolocator.getCurrentPosition(), + Geolocator.getCurrentPosition(), + ]); + expect(positions, everyElement(isA())); + }, timeout: const Timeout(Duration(seconds: 10))); + + test('unimplemented method throws MissingPluginException', () async { + await expectLater( + Geolocator.getLocationAccuracy(), + throwsA(isA()), + ); + }, timeout: const Timeout(Duration(seconds: 10))); + test('position timestamp is in milliseconds', () async { final Position position = await Geolocator.getCurrentPosition(); expect(position.timestamp.year, greaterThan(2000)); diff --git a/packages/geolocator/pubspec.yaml b/packages/geolocator/pubspec.yaml index a7a30e8cb..a9dd78e4a 100644 --- a/packages/geolocator/pubspec.yaml +++ b/packages/geolocator/pubspec.yaml @@ -2,7 +2,7 @@ name: geolocator_tizen description: Tizen implementation of the geolocator plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/main/packages/geolocator -version: 1.1.0 +version: 1.1.1 environment: sdk: ^3.5.0 diff --git a/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc b/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc index 2dd0f9e10..7449f8143 100644 --- a/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc +++ b/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc @@ -167,7 +167,8 @@ class GeolocatorTizenPlugin : public flutter::Plugin { bool opened = app_settings_manager_->OpenLocationSettings(); SendResult(flutter::EncodableValue(opened)); } else { - result->NotImplemented(); + result_->NotImplemented(); + result_ = nullptr; } } diff --git a/packages/geolocator/tizen/src/location_manager.cc b/packages/geolocator/tizen/src/location_manager.cc index 5757cc81f..db1829c1d 100644 --- a/packages/geolocator/tizen/src/location_manager.cc +++ b/packages/geolocator/tizen/src/location_manager.cc @@ -71,36 +71,40 @@ Position LocationManager::GetLastKnownPosition() { void LocationManager::GetCurrentPosition(LocationCallback on_location, LocationErrorCallback on_error) { - location_callback_ = on_location; - error_callback_ = on_error; + current_position_callbacks_.emplace_back(on_location, on_error); + if (current_position_callbacks_.size() > 1) { + return; + } int ret = location_manager_request_single_location( manager_for_current_location_, 5, [](location_error_e error, double latitude, double longitude, double altitude, time_t timestamp, double speed, double direction, double climb, void *user_data) { LocationManager *self = static_cast(user_data); + auto callbacks = std::exchange(self->current_position_callbacks_, {}); - if (error != LOCATIONS_ERROR_NONE && self->error_callback_) { - self->error_callback_(LocationManagerError(error)); - } else if (self->location_callback_) { - Position position = {}; - position.latitude = latitude; - position.longitude = longitude; - position.altitude = altitude; - position.timestamp = timestamp; - position.speed = KmPerHourToMetersPerSecond(speed); - position.heading = direction; - position.verticalSpeed = KmPerHourToMetersPerSecond(climb); - - self->location_callback_(position); + if (error != LOCATIONS_ERROR_NONE) { + for (const auto &callback : callbacks) { + callback.second(LocationManagerError(error)); + } + return; + } + Position position = {}; + position.latitude = latitude; + position.longitude = longitude; + position.altitude = altitude; + position.timestamp = timestamp; + position.speed = KmPerHourToMetersPerSecond(speed); + position.heading = direction; + position.verticalSpeed = KmPerHourToMetersPerSecond(climb); + for (const auto &callback : callbacks) { + callback.first(position); } - self->location_callback_ = nullptr; - self->error_callback_ = nullptr; }, this); if (LOCATIONS_ERROR_NONE != ret) { - error_callback_(LocationManagerError(ret)); - error_callback_ = nullptr; + current_position_callbacks_.clear(); + on_error(LocationManagerError(ret)); } } diff --git a/packages/geolocator/tizen/src/location_manager.h b/packages/geolocator/tizen/src/location_manager.h index 6bd3f9de5..f7e52dd07 100644 --- a/packages/geolocator/tizen/src/location_manager.h +++ b/packages/geolocator/tizen/src/location_manager.h @@ -10,6 +10,8 @@ #include #include +#include +#include #include "position.h" @@ -62,8 +64,8 @@ class LocationManager { ServiceStatusCallback service_status_update_callback_; LocationCallback location_update_callback_; - LocationCallback location_callback_; - LocationErrorCallback error_callback_; + std::vector> + current_position_callbacks_; }; #endif // FLUTTER_PLUGIN_LOCATION_MANAGER_H_ From 191184084c601b113b78dfc2b54198d04aedc81f Mon Sep 17 00:00:00 2001 From: Seungsoo Lee Date: Fri, 30 Oct 2026 04:24:46 +0900 Subject: [PATCH 2/3] [geolocator] Add support for getLocationAccuracy getLocationAccuracy fell through to NotImplemented, so Geolocator.getLocationAccuracy() threw MissingPluginException on Tizen. Tizen has a single location privilege and no approximate-location mode, so always report LocationAccuracyStatus.precise, as geolocator_windows does for its high-accuracy mode: https://github.com/Baseflow/flutter-geolocator/blob/main/geolocator_windows/windows/geolocator_plugin.cpp The unimplemented-method test now uses requestTemporaryFullAccuracy, which is iOS-only and still unimplemented. Bump the unreleased version to 1.2.0 since this adds a feature. --- packages/geolocator/CHANGELOG.md | 5 +++-- packages/geolocator/README.md | 4 ++-- .../example/integration_test/geolocator_test.dart | 9 ++++++++- packages/geolocator/pubspec.yaml | 2 +- packages/geolocator/tizen/src/geolocator_tizen_plugin.cc | 5 +++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/geolocator/CHANGELOG.md b/packages/geolocator/CHANGELOG.md index b0d328272..b5960af3b 100644 --- a/packages/geolocator/CHANGELOG.md +++ b/packages/geolocator/CHANGELOG.md @@ -1,7 +1,8 @@ -## 1.1.1 +## 1.2.0 * Fix `getCurrentPosition` never completing when it is called again before an earlier call completes. -* Fix a crash when an unimplemented method such as `getLocationAccuracy` is called. +* Fix a crash when an unimplemented method such as `requestTemporaryFullAccuracy` is called. +* Add support for `getLocationAccuracy`. ## 1.1.0 diff --git a/packages/geolocator/README.md b/packages/geolocator/README.md index 3a8ea4b28..90ec21028 100644 --- a/packages/geolocator/README.md +++ b/packages/geolocator/README.md @@ -11,7 +11,7 @@ The Tizen implementation of [`geolocator`](https://pub.dev/packages/geolocator). ```yaml dependencies: geolocator: ^14.0.3 - geolocator_tizen: ^1.1.1 + geolocator_tizen: ^1.2.0 ``` Then you can import `geolocator` in your Dart code: @@ -47,7 +47,7 @@ To use this plugin, you need to declare privileges in `tizen-manifest.xml` of yo - [x] `Geolocator.getLastKnownPosition` - [x] `Geolocator.getCurrentPosition` (supported arguments: `timeLimit`) - [x] `Geolocator.getPositionStream` (supported arguments: `locationSettings.timeLimit`) -- [ ] `Geolocator.getLocationAccuracy` +- [x] `Geolocator.getLocationAccuracy` - [ ] `Geolocator.requestTemporaryFullAccuracy` (iOS-only) - [x] `Geolocator.openAppSettings` (not supported on emulators) - [x] `Geolocator.openLocationSettings` (not supported on emulators) diff --git a/packages/geolocator/example/integration_test/geolocator_test.dart b/packages/geolocator/example/integration_test/geolocator_test.dart index a0c82a4be..5168a2dcb 100644 --- a/packages/geolocator/example/integration_test/geolocator_test.dart +++ b/packages/geolocator/example/integration_test/geolocator_test.dart @@ -40,11 +40,18 @@ Future main() async { test('unimplemented method throws MissingPluginException', () async { await expectLater( - Geolocator.getLocationAccuracy(), + Geolocator.requestTemporaryFullAccuracy(purposeKey: 'test'), throwsA(isA()), ); }, timeout: const Timeout(Duration(seconds: 10))); + test('location accuracy is precise', () async { + expect( + await Geolocator.getLocationAccuracy(), + LocationAccuracyStatus.precise, + ); + }, timeout: const Timeout(Duration(seconds: 10))); + test('position timestamp is in milliseconds', () async { final Position position = await Geolocator.getCurrentPosition(); expect(position.timestamp.year, greaterThan(2000)); diff --git a/packages/geolocator/pubspec.yaml b/packages/geolocator/pubspec.yaml index a9dd78e4a..6cc32275e 100644 --- a/packages/geolocator/pubspec.yaml +++ b/packages/geolocator/pubspec.yaml @@ -2,7 +2,7 @@ name: geolocator_tizen description: Tizen implementation of the geolocator plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/main/packages/geolocator -version: 1.1.1 +version: 1.2.0 environment: sdk: ^3.5.0 diff --git a/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc b/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc index 7449f8143..3aee48801 100644 --- a/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc +++ b/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc @@ -31,6 +31,8 @@ typedef flutter::StreamHandlerError constexpr char kPrivilegeLocation[] = "http://tizen.org/privilege/location"; +enum class LocationAccuracyStatus { kReduced, kPrecise }; + class LocationStreamHandler : public FlStreamHandler { protected: std::unique_ptr OnListenInternal( @@ -160,6 +162,9 @@ class GeolocatorTizenPlugin : public flutter::Plugin { OnGetLastKnownPosition(); } else if (method_name == "getCurrentPosition") { OnGetCurrentPosition(); + } else if (method_name == "getLocationAccuracy") { + SendResult(flutter::EncodableValue( + static_cast(LocationAccuracyStatus::kPrecise))); } else if (method_name == "openAppSettings") { bool opened = app_settings_manager_->OpenAppSettings(); SendResult(flutter::EncodableValue(opened)); From 44cb5dc86f1e114c884bc58b63d115f0bea1a819 Mon Sep 17 00:00:00 2001 From: Seungsoo Lee Date: Thu, 5 Nov 2026 04:25:07 +0900 Subject: [PATCH 3/3] [geolocator] Create AppSettingsManager in the plugin constructor app_settings_manager_ was declared but never created, so openAppSettings and openLocationSettings called a member function through a null unique_ptr. This is undefined behavior; it only worked because the methods do not access any members. --- packages/geolocator/CHANGELOG.md | 1 + packages/geolocator/tizen/src/geolocator_tizen_plugin.cc | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/geolocator/CHANGELOG.md b/packages/geolocator/CHANGELOG.md index b5960af3b..110b60bf9 100644 --- a/packages/geolocator/CHANGELOG.md +++ b/packages/geolocator/CHANGELOG.md @@ -2,6 +2,7 @@ * Fix `getCurrentPosition` never completing when it is called again before an earlier call completes. * Fix a crash when an unimplemented method such as `requestTemporaryFullAccuracy` is called. +* Fix a possible crash when `openAppSettings` or `openLocationSettings` is called. * Add support for `getLocationAccuracy`. ## 1.1.0 diff --git a/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc b/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc index 3aee48801..5eeadc788 100644 --- a/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc +++ b/packages/geolocator/tizen/src/geolocator_tizen_plugin.cc @@ -141,7 +141,8 @@ class GeolocatorTizenPlugin : public flutter::Plugin { GeolocatorTizenPlugin() : permission_manager_(std::make_unique()), - location_manager_(std::make_unique()) {} + location_manager_(std::make_unique()), + app_settings_manager_(std::make_unique()) {} virtual ~GeolocatorTizenPlugin() {}