CB-8031 Fix race condition that shows as ConcurrentModificationException

This commit is contained in:
Andrew Grieve 2014-11-17 22:11:21 -08:00
parent ac284fd39c
commit 1feaa7fed7

View File

@ -110,8 +110,12 @@ public class PluginManager {
@Deprecated // Should not be exposed as public. @Deprecated // Should not be exposed as public.
public void startupPlugins() { public void startupPlugins() {
for (PluginEntry entry : entryMap.values()) { for (PluginEntry entry : entryMap.values()) {
// Add a null entry to for each non-startup plugin to avoid ConcurrentModificationException
// When iterating plugins.
if (entry.onload) { if (entry.onload) {
getPlugin(entry.service); getPlugin(entry.service);
} else {
pluginMap.put(entry.service, null);
} }
} }
} }
@ -232,9 +236,11 @@ public class PluginManager {
*/ */
public void onPause(boolean multitasking) { public void onPause(boolean multitasking) {
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onPause(multitasking); plugin.onPause(multitasking);
} }
} }
}
/** /**
* Called when the activity will start interacting with the user. * Called when the activity will start interacting with the user.
@ -243,18 +249,22 @@ public class PluginManager {
*/ */
public void onResume(boolean multitasking) { public void onResume(boolean multitasking) {
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onResume(multitasking); plugin.onResume(multitasking);
} }
} }
}
/** /**
* The final call you receive before your activity is destroyed. * The final call you receive before your activity is destroyed.
*/ */
public void onDestroy() { public void onDestroy() {
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onDestroy(); plugin.onDestroy();
} }
} }
}
/** /**
* Send a message to all plugins. * Send a message to all plugins.
@ -269,11 +279,13 @@ public class PluginManager {
return obj; return obj;
} }
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
obj = plugin.onMessage(id, data); obj = plugin.onMessage(id, data);
if (obj != null) { if (obj != null) {
return obj; return obj;
} }
} }
}
return null; return null;
} }
@ -282,9 +294,11 @@ public class PluginManager {
*/ */
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onNewIntent(intent); plugin.onNewIntent(intent);
} }
} }
}
/** /**
* Called when the URL of the webview changes. * Called when the URL of the webview changes.
@ -320,17 +334,21 @@ public class PluginManager {
*/ */
public void onReset() { public void onReset() {
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
plugin.onReset(); plugin.onReset();
} }
} }
}
Uri remapUri(Uri uri) { Uri remapUri(Uri uri) {
for (CordovaPlugin plugin : this.pluginMap.values()) { for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
Uri ret = plugin.remapUri(uri); Uri ret = plugin.remapUri(uri);
if (ret != null) { if (ret != null) {
return ret; return ret;
} }
} }
}
return null; return null;
} }