Skip to content

Commit e771775

Browse files
committed
fix(firebase_dart_flutter): fixes error for phone auth and mfa
Fixes: "One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified"
1 parent 8d78be2 commit e771775

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

packages/firebase_dart_flutter/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ apply plugin: 'com.android.library'
3939
android {
4040
namespace 'be.appsup.firebase_dart_flutter'
4141

42-
compileSdkVersion 29
42+
compileSdkVersion 34
4343

4444
defaultConfig {
4545
minSdkVersion 16

packages/firebase_dart_flutter/android/src/main/java/be/appsup/firebase_dart_flutter/FirebaseDartFlutterPlugin.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.content.pm.Signature;
1010
import android.net.Uri;
1111
import android.os.Bundle;
12+
import android.os.Build;
13+
1214

1315
import androidx.annotation.NonNull;
1416

@@ -96,22 +98,26 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
9698
}
9799
break;
98100
case "getAuthResult":
99-
binding.getApplicationContext().registerReceiver(new BroadcastReceiver() {
101+
BroadcastReceiver receiver = new BroadcastReceiver() {
100102
@Override
101103
public void onReceive(Context context, Intent intent) {
102104
result.success(bundleToMap(intent.getExtras()));
103105
binding.getApplicationContext().unregisterReceiver(this);
104106
}
105-
}, new IntentFilter(ACTION_AUTH_RECEIVED));
107+
};
108+
IntentFilter filter = new IntentFilter(ACTION_AUTH_RECEIVED);
109+
binding.getApplicationContext().registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
106110
break;
107111
case "getVerifyResult":
108-
binding.getApplicationContext().registerReceiver(new BroadcastReceiver() {
112+
receiver = new BroadcastReceiver() {
109113
@Override
110114
public void onReceive(Context context, Intent intent) {
111115
result.success(bundleToMap(intent.getExtras()));
112116
binding.getApplicationContext().unregisterReceiver(this);
113117
}
114-
}, new IntentFilter(ACTION_RECAPTCHA_RECEIVED));
118+
};
119+
filter = new IntentFilter(ACTION_RECAPTCHA_RECEIVED);
120+
binding.getApplicationContext().registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
115121
break;
116122
case "isGooglePlayServicesAvailable":
117123
int v = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(binding.getApplicationContext(), 12451000);
@@ -173,8 +179,7 @@ public void onFailure(@NonNull Exception e) {
173179
}
174180
});
175181

176-
177-
binding.getApplicationContext().registerReceiver(new BroadcastReceiver() {
182+
BroadcastReceiver receiver = new BroadcastReceiver() {
178183
@Override
179184
public void onReceive(Context context, Intent intent) {
180185
Bundle extras = intent.getExtras();
@@ -193,7 +198,9 @@ public void onReceive(Context context, Intent intent) {
193198
}
194199
binding.getApplicationContext().unregisterReceiver(this);
195200
}
196-
}, new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION));
201+
};
202+
IntentFilter filter = new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION);
203+
binding.getApplicationContext().registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
197204
}
198205

199206
private String getAppSignatureHash() throws PackageManager.NameNotFoundException, NoSuchAlgorithmException {

packages/firebase_dart_flutter/lib/src/auth_handlers.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,12 @@ class AndroidSmsRetriever extends SmsRetriever {
253253
@override
254254
Future<String?> retrieveSms() {
255255
if (!kIsWeb && platform_info.Platform.instance.android) {
256-
return Future(() async {
256+
return Future<String?>(() async {
257257
var v = (await _channel.invokeMethod<String>('retrieveSms'))!;
258258
return v;
259+
}).catchError((e, tr) {
260+
Logger('firebase_dart_flutter').warning('Failed retrieving SMS', e, tr);
261+
return null;
259262
});
260263
}
261264
return Future.value();

0 commit comments

Comments
 (0)