Skip to content

Commit aac2a40

Browse files
committed
Version 2.0.3+hotfix.1
2 parents f1d8b9a + 59b5e8f commit aac2a40

File tree

6 files changed

+124
-114
lines changed

6 files changed

+124
-114
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.3+hotfix.1
2+
3+
* Android: Fix a possible null reference when the plugin is called from an App running in the background.
4+
15
## 2.0.3
26

37
* Android: Migrate to FlutterPlugin Android API (better support for Add-to-App);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To use this plugin, add `google_api_availability` as a [dependency in your pubsp
1919

2020
```yaml
2121
dependencies:
22-
google_api_availability: ^2.0.3
22+
google_api_availability: ^2.0.3+hotfix.1
2323
```
2424
2525
> **NOTE:** There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. See issue [Flutter#16049](https://github.com/flutter/flutter/issues/16049) for help on integration.

android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.java

Lines changed: 116 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55

66
import androidx.annotation.IntDef;
7+
import androidx.annotation.Nullable;
78

89
import com.google.android.gms.common.ConnectionResult;
910
import com.google.android.gms.common.GoogleApiAvailability;
@@ -25,117 +26,122 @@
2526
* GoogleApiAvailabilityPlugin
2627
*/
2728
public class GoogleApiAvailabilityPlugin implements MethodCallHandler, FlutterPlugin, ActivityAware {
28-
private static final int REQUEST_GOOGLE_PLAY_SERVICES = 1000;
29-
30-
//GOOGLE_PLAY_SERVICES_AVAILABILITY
31-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS = 0;
32-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING = 1;
33-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING = 2;
34-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED = 3;
35-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED = 4;
36-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID = 5;
37-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM = 6;
38-
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN = 7;
39-
40-
@Retention(RetentionPolicy.SOURCE)
41-
@IntDef({
42-
GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS,
43-
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING,
44-
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING,
45-
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED,
46-
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED,
47-
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID,
48-
GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM,
49-
GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN,
50-
})
51-
private @interface GooglePlayServicesAvailability {
52-
}
53-
54-
private Context context;
55-
56-
57-
public void setContext(Context newContext) {
58-
context = newContext;
59-
}
60-
61-
@Override
62-
public void onAttachedToActivity(ActivityPluginBinding binding) {
63-
setContext(binding.getActivity());
64-
}
65-
66-
@Override
67-
public void onDetachedFromActivityForConfigChanges() {
68-
setContext(null);
69-
}
70-
71-
@Override
72-
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
73-
setContext(binding.getActivity());
74-
}
75-
76-
@Override
77-
public void onDetachedFromActivity() {
78-
setContext(null);
79-
}
80-
81-
@Override
82-
public void onAttachedToEngine(FlutterPluginBinding binding) {
83-
this.registerPlugin(null, binding.getBinaryMessenger());
84-
}
85-
86-
@Override
87-
public void onDetachedFromEngine(FlutterPluginBinding binding) {}
88-
89-
private void registerPlugin(Context context, BinaryMessenger messenger) {
90-
final MethodChannel channel = new MethodChannel(messenger, "flutter.baseflow.com/google_api_availability/methods");
91-
if (context != null) setContext(context);
92-
channel.setMethodCallHandler(this);
93-
}
94-
95-
public static void registerWith(Registrar registrar) {
96-
final GoogleApiAvailabilityPlugin plugin = new GoogleApiAvailabilityPlugin();
97-
plugin.registerPlugin(registrar.context(), registrar.messenger());
98-
}
99-
100-
@Override
101-
public void onMethodCall(MethodCall call, Result result) {
102-
if (call.method.equals("checkPlayServicesAvailability")) {
103-
final Boolean showDialog = call.argument("showDialog");
104-
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
105-
final int connectionResult = googleApiAvailability.isGooglePlayServicesAvailable(context);
106-
107-
108-
if (context instanceof Activity) {
109-
Activity activity = (Activity) context;
110-
if (showDialog != null && showDialog) {
111-
googleApiAvailability.showErrorDialogFragment(activity, connectionResult, REQUEST_GOOGLE_PLAY_SERVICES);
112-
}
113-
}
29+
private static final int REQUEST_GOOGLE_PLAY_SERVICES = 1000;
30+
31+
//GOOGLE_PLAY_SERVICES_AVAILABILITY
32+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS = 0;
33+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING = 1;
34+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING = 2;
35+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED = 3;
36+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED = 4;
37+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID = 5;
38+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM = 6;
39+
private static final int GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN = 7;
40+
41+
@Retention(RetentionPolicy.SOURCE)
42+
@IntDef({
43+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS,
44+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING,
45+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING,
46+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED,
47+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED,
48+
GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID,
49+
GOOGLE_PLAY_SERVICES_AVAILABILITY_NOT_AVAILABLE_ON_PLATFORM,
50+
GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN,
51+
})
52+
private @interface GooglePlayServicesAvailability {
53+
}
54+
55+
private Context applicationContext;
56+
private @Nullable Activity activity;
57+
private MethodChannel methodChannel;
58+
59+
60+
public static void registerWith(Registrar registrar) {
61+
final GoogleApiAvailabilityPlugin plugin = new GoogleApiAvailabilityPlugin();
62+
plugin.registerPlugin(
63+
registrar.context(),
64+
registrar.activity(),
65+
registrar.messenger());
66+
}
67+
68+
@Override
69+
public void onAttachedToEngine(FlutterPluginBinding binding) {
70+
registerPlugin(
71+
binding.getApplicationContext(),
72+
null,
73+
binding.getBinaryMessenger());
74+
}
75+
76+
@Override
77+
public void onDetachedFromEngine(FlutterPluginBinding binding) {
78+
applicationContext = null;
79+
methodChannel.setMethodCallHandler(null);
80+
methodChannel = null;
81+
}
82+
83+
@Override
84+
public void onAttachedToActivity(ActivityPluginBinding binding) {
85+
activity = binding.getActivity();
86+
}
11487

115-
final int availability = toPlayServiceAvailability(connectionResult);
116-
result.success(availability);
117-
} else {
118-
result.notImplemented();
88+
@Override
89+
public void onDetachedFromActivityForConfigChanges() {
90+
activity = null;
11991
}
120-
}
121-
122-
@GooglePlayServicesAvailability
123-
private int toPlayServiceAvailability(int connectionResult) {
124-
switch (connectionResult) {
125-
case ConnectionResult.SUCCESS:
126-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS;
127-
case ConnectionResult.SERVICE_MISSING:
128-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING;
129-
case ConnectionResult.SERVICE_UPDATING:
130-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING;
131-
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
132-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED;
133-
case ConnectionResult.SERVICE_DISABLED:
134-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED;
135-
case ConnectionResult.SERVICE_INVALID:
136-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID;
137-
default:
138-
return GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN;
92+
93+
@Override
94+
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
95+
activity = binding.getActivity();
96+
}
97+
98+
@Override
99+
public void onDetachedFromActivity() {
100+
activity = null;
101+
}
102+
103+
private void registerPlugin(Context applicationContext, Activity activity, BinaryMessenger messenger) {
104+
this.applicationContext = applicationContext;
105+
this.activity = activity;
106+
methodChannel = new MethodChannel(messenger, "flutter.baseflow.com/google_api_availability/methods");
107+
methodChannel.setMethodCallHandler(this);
108+
}
109+
110+
@Override
111+
public void onMethodCall(MethodCall call, Result result) {
112+
if (call.method.equals("checkPlayServicesAvailability")) {
113+
final Boolean showDialog = call.argument("showDialog");
114+
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
115+
final int connectionResult = googleApiAvailability.isGooglePlayServicesAvailable(applicationContext);
116+
117+
if (activity != null && showDialog != null && showDialog) {
118+
googleApiAvailability.showErrorDialogFragment(activity, connectionResult, REQUEST_GOOGLE_PLAY_SERVICES);
119+
}
120+
121+
final int availability = toPlayServiceAvailability(connectionResult);
122+
result.success(availability);
123+
} else {
124+
result.notImplemented();
125+
}
126+
}
127+
128+
@GooglePlayServicesAvailability
129+
private int toPlayServiceAvailability(int connectionResult) {
130+
switch (connectionResult) {
131+
case ConnectionResult.SUCCESS:
132+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SUCCESS;
133+
case ConnectionResult.SERVICE_MISSING:
134+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_MISSING;
135+
case ConnectionResult.SERVICE_UPDATING:
136+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_UPDATING;
137+
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
138+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_VERSION_UPDATE_REQUIRED;
139+
case ConnectionResult.SERVICE_DISABLED:
140+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_DISABLED;
141+
case ConnectionResult.SERVICE_INVALID:
142+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_SERVICE_INVALID;
143+
default:
144+
return GOOGLE_PLAY_SERVICES_AVAILABILITY_UNKNOWN;
145+
}
139146
}
140-
}
141147
}

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ packages:
8080
path: ".."
8181
relative: true
8282
source: path
83-
version: "2.0.3"
83+
version: "2.0.3+hotfix.1"
8484
image:
8585
dependency: transitive
8686
description:

ios/google_api_availability.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'google_api_availability'
6-
s.version = '2.0.3'
6+
s.version = '2.0.3+hotfix.1'
77
s.summary = 'A Flutter plugin to check the availability of Google Play Services on an Android device.'
88
s.description = <<-DESC
99
A Flutter plugin to check the availability of Google Play Services on an Android device.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: google_api_availability
22
description: A Flutter plugin to check the availability of Google Play Services on an Android device.
3-
version: 2.0.3
3+
version: 2.0.3+hotfix.1
44
homepage: https://github.com/baseflowit/flutter-google-api-availability
55

66
environment:

0 commit comments

Comments
 (0)