Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMEA Messages on Android #932

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8510573
Add NMEA functionality
rickcasson Jan 4, 2022
edd2058
Update geolocator_platform_interface.dart
rickcasson Jan 4, 2022
0bbb181
Update method_channel_geolocator.dart
rickcasson Jan 4, 2022
912c572
NmeaMessageManager setup changes
rickcasson Jan 5, 2022
16fb1f1
move permissionmanager to nmea handler
rickcasson Jan 5, 2022
2e34eac
Update NmeaMessageaClient.java
rickcasson Jan 5, 2022
aed919a
fix imports and method calls
rickcasson Jan 5, 2022
2278239
fix formatting
rickcasson Jan 6, 2022
c264940
fix error catching and dependency issues
rickcasson Jan 6, 2022
33983e2
override dependency in example pubspec
rickcasson Jan 6, 2022
affa8a0
fix path
rickcasson Jan 6, 2022
2d2c857
Update pubspec.yaml
rickcasson Jan 6, 2022
a3e529c
Merge remote-tracking branch 'upstream/master' into nmea
rickcasson Jan 17, 2022
80c52c9
add test to expand coverage
rickcasson Jan 18, 2022
11a37ad
fix code coverage issue
rickcasson Jan 19, 2022
35c7a8e
Merge remote-tracking branch 'upstream/master' into nmea
rickcasson Jan 24, 2022
05e5177
fix export
rickcasson Jan 24, 2022
e908603
Merge branch 'master' into nmea
rickcasson Jan 25, 2022
f47964b
Merge remote-tracking branch 'upstream/master' into nmea
rickcasson Mar 1, 2022
25f6797
Merge remote-tracking branch 'upstream/main' into nmea-new
rickcasson May 12, 2022
76af741
Cleanup Nmea interfaces
rickcasson May 13, 2022
bebd9aa
fix imports
rickcasson May 13, 2022
63623c3
Merge pull request #4 from Baseflow/main
rickcasson May 13, 2022
e0845ab
Fix code coverage
rickcasson May 15, 2022
8ef3680
Merge pull request #3 from rickcasson/nmea-new
rickcasson May 15, 2022
26127a8
update nmea channel name
rickcasson May 15, 2022
1f02cff
add test increase coverage
rickcasson May 15, 2022
8951952
expand coverage
rickcasson May 15, 2022
fb89040
remove empty tests
rickcasson May 15, 2022
466f9d9
Merge remote-tracking branch 'upstream/main'
rickcasson Sep 1, 2022
4550d49
Merge branch 'main' into nmea-new
rickcasson Sep 1, 2022
895e4b4
fix for deprecated button
rickcasson Sep 1, 2022
e705197
use new plugin template tagged version
rickcasson Sep 14, 2022
62789e7
Merge branch 'main' into nmea
rickcasson Sep 19, 2022
c88ef1f
Merge branch 'main' into nmea
rickcasson Sep 27, 2022
068eb28
remove unnecessary import
rickcasson Sep 27, 2022
96976ce
Merge branch 'main' into nmea
rickcasson Oct 11, 2022
582ef8f
Merge branch 'main' into nmea
rickcasson Oct 17, 2022
f95c494
Merge branch 'main' into nmea
rickcasson Nov 21, 2022
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
25 changes: 15 additions & 10 deletions geolocator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.1.0

- Added functionality to receive NMEA messages.

## 9.0.2

- Updated dependency on geolocator_android to version 4.1.3
Expand Down Expand Up @@ -33,6 +37,7 @@

- Endorses the geolocator_windows package.


## 8.0.5

- Fix code coverage issues by adding iOS specific test for getCurrentPosition
Expand All @@ -51,7 +56,7 @@

## 8.0.1

- Fix "forceAndroidLocationManager" for getLastKnownPosition
- Fix "forceAndroidLocationManager" for getLastKnownPosition
- Upgrade geolocator_platform_interface to 3.0.1
- Upgrade geolocator_web to 2.1.1

Expand Down Expand Up @@ -124,7 +129,7 @@
## 7.0.3

- Android: Throw the `ActivityMissingException` when requesting permissions while the activity is not available (e.g. when the App is in the background);
- iOS: Support the `NSLocationAlwaysAndWhenInUseUsageDescription` key on iOS 11+ (this key replaces the `NSLocationAlwaysDescription` key which has been marked [deprecated](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysusagedescription?language=objc)).
- iOS: Support the `NSLocationAlwaysAndWhenInUseUsageDescription` key on iOS 11+ (this key replaces the `NSLocationAlwaysDescription` key which has been marked [deprecated](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysusagedescription?language=objc)).

## 7.0.2

Expand All @@ -136,7 +141,7 @@

## 7.0.0

This release contains the following **breaking changes**:
This release contains the following **breaking changes**:
- Stable release of null safety migration;
- Checking permissions on Android can no longer result in `LocationPermissions.deniedForever`. More details can be found in issue [#653](https://github.com/Baseflow/flutter-geolocator/issues/653) and the [wiki](https://github.com/Baseflow/flutter-geolocator/wiki/Breaking-changes-in-7.0.0#android-permission-update);
- Removed deprecated `timeInterval` parameter from the `getPositionStream` method;
Expand Down Expand Up @@ -419,7 +424,7 @@ Complete rebuild of the geolocator plugin. Please note the this version contains
## 1.7.0

- Added timestamp to instances of the `Position` class indicating when the GPS fix was acquired;
- Updated the dependency on the `PermissionHandler` to version >=2.0.0 <3.0.0.
- Updated the dependency on the `PermissionHandler` to version >=2.0.0 <3.0.0.

## 1.6.5

Expand Down Expand Up @@ -459,14 +464,14 @@ Complete rebuild of the geolocator plugin. Please note the this version contains
- Solved a bug on Android where requesting permissions twice would cause the App to crash [[ISSUE #61](https://github.com/BaseflowIT/flutter-geolocator/issues/61)]

> **Important:**
>
>
> To be able to correctly fix [issue #58](https://github.com/BaseflowIT/flutter-geolocator/issues/58) we had to change the `getPositionStream` method into a `async` method. This means the signature of the method has been changed from:
>
> `Stream<Position> getPositionStream([LocationOptions locationOptions = const LocationOptions()])`
> `Stream<Position> getPositionStream([LocationOptions locationOptions = const LocationOptions()])`
>
> to
> to
>
> `Future<Stream<Position>> getPositionStream([LocationOptions locationOptions = const LocationOptions()])`.
> `Future<Stream<Position>> getPositionStream([LocationOptions locationOptions = const LocationOptions()])`.
>
> Meaning as a developer you'll now have to `await` the result of the method to get access to the actual stream.

Expand Down Expand Up @@ -515,9 +520,9 @@ Complete rebuild of the geolocator plugin. Please note the this version contains

## 1.1.0

- Introduced the option to supply a desired accuracy.
- Introduced the option to supply a desired accuracy.

> **Important:*-
> **Important:*-
>
>This introduces a breaking change, the `getPosition` and `onPositionChanged` properties have been replaced by methods (`getPosition([LocationAccuracy desiredAccuracy = LocationAccuracy.Best])` and `getPositionStream([LocationAccuracy desiredAccuracy = LocationAccuracy.Best])` respectively) accepting a parameter to indicate the desired accuracy.
- Updated the Android part to make use of the [LocationManager](https://developer.android.com/reference/android/location/LocationManager) instead of the [FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient)
Expand Down
5 changes: 5 additions & 0 deletions geolocator/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
final GeolocatorPlatform _geolocatorPlatform = GeolocatorPlatform.instance;
final List<_PositionItem> _positionItems = <_PositionItem>[];
StreamSubscription<Position>? _positionStreamSubscription;
StreamSubscription<NmeaMessage>? _nmeaStreamSubscription;
StreamSubscription<ServiceStatus>? _serviceStatusStreamSubscription;
bool positionStreamStarted = false;

Expand Down Expand Up @@ -337,6 +338,10 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
_positionStreamSubscription!.cancel();
_positionStreamSubscription = null;
}
if (_nmeaStreamSubscription != null) {
_nmeaStreamSubscription!.cancel();
_nmeaStreamSubscription = null;
}

super.dispose();
}
Expand Down
7 changes: 7 additions & 0 deletions geolocator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ dev_dependencies:
sdk: flutter
flutter_lints: ^1.0.4

# TODO: REMOVE BEFORE MERGING
dependency_overrides:
geolocator_platform_interface:
path: ../../geolocator_platform_interface/
geolocator_android:
path: ../../geolocator_android/

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
29 changes: 29 additions & 0 deletions geolocator/lib/geolocator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ class Geolocator {
.getCurrentPosition(locationSettings: locationSettings);
}

/// Returns a stream emitting NMEA-0183 sentences Android only, no-op on iOS.
///
/// With devices running an Android API level lower than 24 NMEA-0183
/// sentences are received from the GPS engine. From API level 24 and up the
/// GNSS engine is used.
///
/// This event starts all location sensors on the device and will keep them
/// active until you cancel listening to the stream or when the application
/// is killed.
///
/// ```
/// StreamSubscription<NmeaMessage> nmeaStream =
/// Geolocator.getNmeaStream().listen((NmeaMessage nmea) {
/// // Handle NMEA changes
/// });
/// ```
///
/// When no longer needed cancel the subscription
/// nmeaStream.cancel();
///
/// Throws a [PermissionDeniedException] when trying to request the device's
/// location when the user denied access.
/// Throws a [LocationServiceDisabledException] when the user allowed access,
/// but the location services of the device are disabled.
///
/// for more info about NMEA 0183 see https://en.wikipedia.org/wiki/NMEA_0183
static Stream<NmeaMessage> getNmeaStream() =>
GeolocatorPlatform.instance.getNmeaStream();

/// Fires whenever the location changes inside the bounds of the
/// supplied [LocationSettings.accuracy].
///
Expand Down
13 changes: 10 additions & 3 deletions geolocator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: geolocator
description: Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
version: 9.0.2
version: 9.1.0

environment:
sdk: ">=2.15.0 <3.0.0"
Expand All @@ -26,8 +26,8 @@ dependencies:
flutter:
sdk: flutter

geolocator_platform_interface: ^4.0.3
geolocator_android: ^4.1.3
geolocator_platform_interface: ^4.1.0
geolocator_android: ^4.2.0
geolocator_apple: ^2.1.1+1
geolocator_web: ^2.1.3
geolocator_windows: ^0.1.0
Expand All @@ -38,3 +38,10 @@ dev_dependencies:
flutter_lints: ^1.0.4
mockito: ^5.0.0-nullsafety.7
plugin_platform_interface: ^2.0.0

# TODO: REMOVE BEFORE MERGING
dependency_overrides:
geolocator_platform_interface:
path: ../geolocator_platform_interface/
geolocator_android:
path: ../geolocator_android/
16 changes: 16 additions & 0 deletions geolocator/test/geolocator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Position get mockPosition => Position(
speed: 0.0,
speedAccuracy: 0.0);

NmeaMessage get mockNmeaMessage => NmeaMessage(
message:
"GPGGA,170834,4124.8963,N,08151.6838,W,1,05,1.5,280.2,M,-34.0,M,,,*75",
timestamp: DateTime.fromMillisecondsSinceEpoch(
500,
isUtc: true,
));

void main() {
group('Geolocator', () {
setUp(() {
Expand Down Expand Up @@ -97,6 +105,11 @@ void main() {
expect(position, emitsInOrder([emits(mockPosition), emitsDone]));
});

test('getNmeaStream', () async {
final nmeaMessage = Geolocator.getNmeaStream();
expect(nmeaMessage, emitsInOrder([emits(mockNmeaMessage), emitsDone]));
});

test('openAppSettings', () async {
final hasOpened = await Geolocator.openAppSettings();
expect(hasOpened, true);
Expand Down Expand Up @@ -177,6 +190,9 @@ class MockGeolocatorPlatform extends Mock
);
}

@override
Stream<NmeaMessage> getNmeaStream() => Stream.value(mockNmeaMessage);

@override
Future<bool> openAppSettings() => Future.value(true);

Expand Down
4 changes: 4 additions & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.0

- Additional functionality to receive NMEA messages.

## 4.1.5

- Mark `geolocator_android` as implementation of `geolocator`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;

/** GeolocatorPlugin */
public class GeolocatorPlugin implements FlutterPlugin, ActivityAware {
Expand Down Expand Up @@ -53,6 +54,8 @@ public void onServiceDisconnected(ComponentName name) {
};
@Nullable private LocationServiceHandlerImpl locationServiceHandler;

@Nullable private NmeaStreamHandlerImpl nmeaStreamHandler;

@SuppressWarnings("deprecation")
@Nullable
private io.flutter.plugin.common.PluginRegistry.Registrar pluginRegistrar;
Expand Down Expand Up @@ -94,14 +97,21 @@ public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registra
LocationServiceHandlerImpl locationServiceHandler = new LocationServiceHandlerImpl();
locationServiceHandler.startListening(registrar.context(), registrar.messenger());
locationServiceHandler.setContext(registrar.activeContext());

NmeaStreamHandlerImpl nmeaStreamHandler = new NmeaStreamHandlerImpl(geolocatorPlugin.permissionManager);
nmeaStreamHandler.startListening(registrar.context(), registrar.messenger());
nmeaStreamHandler.setActivity(registrar.activity());

geolocatorPlugin.bindForegroundService(registrar.activeContext());
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
methodCallHandler =
new MethodCallHandlerImpl(
this.permissionManager, this.geolocationManager, this.locationAccuracyManager);
this.permissionManager,
this.geolocationManager,
this.locationAccuracyManager);
methodCallHandler.startListening(
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());
streamHandler = new StreamHandlerImpl(this.permissionManager);
Expand All @@ -113,6 +123,10 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
locationServiceHandler.startListening(
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());

nmeaStreamHandler = new NmeaStreamHandlerImpl(this.permissionManager);
nmeaStreamHandler.startListening(
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());

bindForegroundService(flutterPluginBinding.getApplicationContext());
}

Expand All @@ -134,6 +148,9 @@ public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
if (streamHandler != null) {
streamHandler.setActivity(binding.getActivity());
}
if (nmeaStreamHandler != null) {
nmeaStreamHandler.setActivity(binding.getActivity());
}
if (foregroundLocationService != null) {
foregroundLocationService.setActivity(pluginBinding.getActivity());
}
Expand Down Expand Up @@ -162,6 +179,9 @@ public void onDetachedFromActivity() {
if (foregroundLocationService != null) {
foregroundLocationService.setActivity(null);
}
if (nmeaStreamHandler != null) {
nmeaStreamHandler.setActivity(null);
}
if (pluginBinding != null) {
pluginBinding = null;
}
Expand Down Expand Up @@ -225,6 +245,11 @@ private void dispose() {
locationServiceHandler.stopListening();
locationServiceHandler = null;
}
if (nmeaStreamHandler != null) {
nmeaStreamHandler.stopListening();
nmeaStreamHandler.setActivity(null);
nmeaStreamHandler = null;
}
if (foregroundLocationService != null) {
foregroundLocationService.setActivity(null);
}
Expand Down
Loading