fix(admob,android): null check activity in consent form (#2985)

* Added missing null checks for getCurrentActivity()

* Added null check in Consent module form.
Wrapped consentForm.show() with try-catch.

Co-authored-by: Mike Hardy <github@mikehardy.net>
Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
This commit is contained in:
Juan
2020-01-30 08:48:09 -03:00
committed by GitHub
parent 7db4cd883a
commit b5243cf25a

View File

@@ -86,6 +86,10 @@ public class ReactNativeFirebaseAdMobConsentModule extends ReactNativeFirebaseMo
@ReactMethod
public void showForm(ReadableMap options, Promise promise) {
if (getCurrentActivity() == null) {
rejectPromiseWithCodeAndMessage(promise, "null-activity", "Consent form attempted to show but the current Activity was null.");
return;
}
getCurrentActivity().runOnUiThread(() -> {
URL privacyUrl = null;
@@ -98,7 +102,11 @@ public class ReactNativeFirebaseAdMobConsentModule extends ReactNativeFirebaseMo
ConsentFormListener listener = new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
consentForm.show();
try {
consentForm.show();
} catch (Exception e) {
rejectPromiseWithCodeAndMessage(promise, "consent-form-error", e.toString());
}
}
@Override