From f927014d065ac63225a67054da85cfebfe808d71 Mon Sep 17 00:00:00 2001 From: Guillem Perez Date: Sun, 28 Mar 2021 14:49:39 +0200 Subject: [PATCH] fix(android): Avoid Crash Report: ConcurrentModificationException (#1073) Authored-by: lempere --- .../src/org/apache/cordova/PluginManager.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java index f7a2e410..21aec73e 100755 --- a/framework/src/org/apache/cordova/PluginManager.java +++ b/framework/src/org/apache/cordova/PluginManager.java @@ -30,6 +30,7 @@ import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.os.Debug; +import android.os.Build; /** * PluginManager is exposed to JavaScript in the Cordova WebView. @@ -331,11 +332,19 @@ public class PluginManager { public Object postMessage(String id, Object data) { LOG.d(TAG, "postMessage: " + id); synchronized (this.pluginMap) { - for (CordovaPlugin plugin : this.pluginMap.values()) { - if (plugin != null) { - Object obj = plugin.onMessage(id, data); - if (obj != null) { - return obj; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + this.pluginMap.forEach((s, plugin) -> { + if (plugin != null) { + plugin.onMessage(id, data); + } + }); + } else { + for (CordovaPlugin plugin : this.pluginMap.values()) { + if (plugin != null) { + Object obj = plugin.onMessage(id, data); + if (obj != null) { + return obj; + } } } }