Skip to content

Commit

Permalink
Refactor Geolocator Android (#1352)
Browse files Browse the repository at this point in the history
* Refactor Geolocator Android

* Bump version

* Switch to NOT_EXPORTED broadcase receiver

* Switch back to EXPORTED flag

* Address PR feedback

* Update version in pubspec.yaml
  • Loading branch information
vbuberen authored Oct 26, 2023
1 parent 322eaf6 commit 524720d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 51 deletions.
5 changes: 5 additions & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.3.3

- Removes deprecated support for Android V1 embedding from the JAVA code base. Note that the geolocator's Flutter version restrictions already don't support V1 embedding anymore.
- Registers location services state change broadcast receiver with required exported flags

## 4.3.2

- Updates the following dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public void onServiceDisconnected(ComponentName name) {
};
@Nullable private LocationServiceHandlerImpl locationServiceHandler;

@SuppressWarnings("deprecation")
@Nullable
private io.flutter.plugin.common.PluginRegistry.Registrar pluginRegistrar;

@Nullable private ActivityPluginBinding pluginBinding;

public GeolocatorPlugin() {
Expand All @@ -65,38 +61,6 @@ public GeolocatorPlugin() {
locationAccuracyManager = new LocationAccuracyManager();
}

// This static function is optional and equivalent to onAttachedToEngine. It supports the old
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
// plugin registration via this function while apps migrate to use the new Android APIs
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
//
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
GeolocatorPlugin geolocatorPlugin = new GeolocatorPlugin();
geolocatorPlugin.pluginRegistrar = registrar;
geolocatorPlugin.registerListeners();

MethodCallHandlerImpl methodCallHandler =
new MethodCallHandlerImpl(
geolocatorPlugin.permissionManager,
geolocatorPlugin.geolocationManager,
geolocatorPlugin.locationAccuracyManager);
methodCallHandler.startListening(registrar.context(), registrar.messenger());
methodCallHandler.setActivity(registrar.activity());

StreamHandlerImpl streamHandler = new StreamHandlerImpl(geolocatorPlugin.permissionManager);
streamHandler.startListening(registrar.context(), registrar.messenger());

LocationServiceHandlerImpl locationServiceHandler = new LocationServiceHandlerImpl();
locationServiceHandler.startListening(registrar.context(), registrar.messenger());
locationServiceHandler.setContext(registrar.activeContext());
geolocatorPlugin.bindForegroundService(registrar.activeContext());
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
methodCallHandler =
Expand Down Expand Up @@ -168,10 +132,7 @@ public void onDetachedFromActivity() {
}

private void registerListeners() {
if (pluginRegistrar != null) {
pluginRegistrar.addActivityResultListener(this.geolocationManager);
pluginRegistrar.addRequestPermissionsResultListener(this.permissionManager);
} else if (pluginBinding != null) {
if (pluginBinding != null) {
pluginBinding.addActivityResultListener(this.geolocationManager);
pluginBinding.addRequestPermissionsResultListener(this.permissionManager);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.baseflow.geolocator;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.baseflow.geolocator.location.LocationServiceStatusReceiver;

Expand Down Expand Up @@ -55,7 +55,7 @@ public void onListen(Object arguments, EventChannel.EventSink events) {
IntentFilter filter = new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION);
filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
receiver = new LocationServiceStatusReceiver(events);
context.registerReceiver(receiver, filter);
ContextCompat.registerReceiver(context, receiver, filter, ContextCompat.RECEIVER_EXPORTED);
}

@Override
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion geolocator_android/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion geolocator_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: geolocator_android
description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
version: 4.3.2
version: 4.3.3

environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down

0 comments on commit 524720d

Please sign in to comment.