From 15530a4820001dc6e4e831e7cac66feeda0632de Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Wed, 18 Mar 2015 10:47:23 -0400 Subject: [PATCH] Add `CordovaPlugin.getServiceName()` --- framework/src/org/apache/cordova/CordovaPlugin.java | 11 ++++++++++- framework/src/org/apache/cordova/PluginManager.java | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaPlugin.java b/framework/src/org/apache/cordova/CordovaPlugin.java index e4b3ace2..ee111bc2 100644 --- a/framework/src/org/apache/cordova/CordovaPlugin.java +++ b/framework/src/org/apache/cordova/CordovaPlugin.java @@ -35,13 +35,15 @@ public class CordovaPlugin { public CordovaWebView webView; public CordovaInterface cordova; protected CordovaPreferences preferences; + private String serviceName; /** * Call this after constructing to initialize the plugin. * Final because we want to be able to change args without breaking plugins. */ - public final void privateInitialize(CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) { + public final void privateInitialize(String serviceName, CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) { assert this.cordova == null; + this.serviceName = serviceName; this.cordova = cordova; this.webView = webView; this.preferences = preferences; @@ -62,6 +64,13 @@ public class CordovaPlugin { */ protected void pluginInitialize() { } + + /** + * Returns the plugin's service name (what you'd use when calling pluginManger.getPlugin()) + */ + public String getServiceName() { + return serviceName; + } /** * Executes the request. diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java index 72ce8d0b..93060096 100755 --- a/framework/src/org/apache/cordova/PluginManager.java +++ b/framework/src/org/apache/cordova/PluginManager.java @@ -165,7 +165,7 @@ public class PluginManager { } else { ret = instantiatePlugin(pe.pluginClass); } - ret.privateInitialize(ctx, app, app.getPreferences()); + ret.privateInitialize(service, ctx, app, app.getPreferences()); pluginMap.put(service, ret); } return ret; @@ -192,7 +192,7 @@ public class PluginManager { public void addService(PluginEntry entry) { this.entryMap.put(entry.service, entry); if (entry.plugin != null) { - entry.plugin.privateInitialize(ctx, app, app.getPreferences()); + entry.plugin.privateInitialize(entry.service, ctx, app, app.getPreferences()); pluginMap.put(entry.service, entry.plugin); } }