Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/geolocator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 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 `requestTemporaryFullAccuracy` is called.
* Fix a possible crash when `openAppSettings` or `openLocationSettings` is called.
* Add support for `getLocationAccuracy`.

## 1.1.0

* Update geolocator_platform_interface to 4.4.0.
Expand Down
4 changes: 2 additions & 2 deletions packages/geolocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.0
```

Then you can import `geolocator` in your Dart code:
Expand Down Expand Up @@ -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)
23 changes: 23 additions & 0 deletions packages/geolocator/example/integration_test/geolocator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,6 +30,28 @@ Future<void> main() async {
expect(await Geolocator.getCurrentPosition(), isA<Position>());
}, timeout: const Timeout(Duration(seconds: 10)));

test('concurrent get current position calls all complete', () async {
final List<Position> positions = await Future.wait(<Future<Position>>[
Geolocator.getCurrentPosition(),
Geolocator.getCurrentPosition(),
]);
expect(positions, everyElement(isA<Position>()));
}, timeout: const Timeout(Duration(seconds: 10)));

test('unimplemented method throws MissingPluginException', () async {
await expectLater(
Geolocator.requestTemporaryFullAccuracy(purposeKey: 'test'),
throwsA(isA<MissingPluginException>()),
);
}, 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));
Expand Down
2 changes: 1 addition & 1 deletion packages/geolocator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.0

environment:
sdk: ^3.5.0
Expand Down
11 changes: 9 additions & 2 deletions packages/geolocator/tizen/src/geolocator_tizen_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef flutter::StreamHandlerError<flutter::EncodableValue>

constexpr char kPrivilegeLocation[] = "http://tizen.org/privilege/location";

enum class LocationAccuracyStatus { kReduced, kPrecise };

class LocationStreamHandler : public FlStreamHandler {
protected:
std::unique_ptr<FlStreamHandlerError> OnListenInternal(
Expand Down Expand Up @@ -139,7 +141,8 @@ class GeolocatorTizenPlugin : public flutter::Plugin {

GeolocatorTizenPlugin()
: permission_manager_(std::make_unique<PermissionManager>()),
location_manager_(std::make_unique<LocationManager>()) {}
location_manager_(std::make_unique<LocationManager>()),
app_settings_manager_(std::make_unique<AppSettingsManager>()) {}

virtual ~GeolocatorTizenPlugin() {}

Expand All @@ -160,14 +163,18 @@ class GeolocatorTizenPlugin : public flutter::Plugin {
OnGetLastKnownPosition();
} else if (method_name == "getCurrentPosition") {
OnGetCurrentPosition();
} else if (method_name == "getLocationAccuracy") {
SendResult(flutter::EncodableValue(
static_cast<int>(LocationAccuracyStatus::kPrecise)));
} else if (method_name == "openAppSettings") {
bool opened = app_settings_manager_->OpenAppSettings();
SendResult(flutter::EncodableValue(opened));
} else if (method_name == "openLocationSettings") {
bool opened = app_settings_manager_->OpenLocationSettings();
SendResult(flutter::EncodableValue(opened));
} else {
result->NotImplemented();
result_->NotImplemented();
result_ = nullptr;
}
}

Expand Down
42 changes: 23 additions & 19 deletions packages/geolocator/tizen/src/location_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocationManager *>(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));
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/geolocator/tizen/src/location_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <functional>
#include <string>
#include <utility>
#include <vector>

#include "position.h"

Expand Down Expand Up @@ -62,8 +64,8 @@ class LocationManager {

ServiceStatusCallback service_status_update_callback_;
LocationCallback location_update_callback_;
LocationCallback location_callback_;
LocationErrorCallback error_callback_;
std::vector<std::pair<LocationCallback, LocationErrorCallback>>
current_position_callbacks_;
};

#endif // FLUTTER_PLUGIN_LOCATION_MANAGER_H_