fix(android): Avoid Crash Report: ConcurrentModificationException (#1073)

Authored-by: lempere <lempere@lempere.com>
This commit is contained in:
Guillem Perez 2021-03-28 14:49:39 +02:00 committed by GitHub
parent 19a5feb875
commit f927014d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,7 @@ import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Debug; import android.os.Debug;
import android.os.Build;
/** /**
* PluginManager is exposed to JavaScript in the Cordova WebView. * PluginManager is exposed to JavaScript in the Cordova WebView.
@ -331,11 +332,19 @@ public class PluginManager {
public Object postMessage(String id, Object data) { public Object postMessage(String id, Object data) {
LOG.d(TAG, "postMessage: " + id); LOG.d(TAG, "postMessage: " + id);
synchronized (this.pluginMap) { synchronized (this.pluginMap) {
for (CordovaPlugin plugin : this.pluginMap.values()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (plugin != null) { this.pluginMap.forEach((s, plugin) -> {
Object obj = plugin.onMessage(id, data); if (plugin != null) {
if (obj != null) { plugin.onMessage(id, data);
return obj; }
});
} else {
for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
Object obj = plugin.onMessage(id, data);
if (obj != null) {
return obj;
}
} }
} }
} }