Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions android/capacitor/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@
}

-keep public class * extends com.getcapacitor.Plugin { *; }

# Rules for Capacitor v2 plugins and annotations
# These are deprecated but can still be used with Capacitor for now
-keep @com.getcapacitor.NativePlugin public class * {
@com.getcapacitor.PluginMethod public <methods>;
}
146 changes: 21 additions & 125 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,17 +618,6 @@ public void registerPluginInstances(Plugin[] pluginInstances) {
}
}

@SuppressWarnings("deprecation")
private String getLegacyPluginName(Class<? extends Plugin> pluginClass) {
NativePlugin legacyPluginAnnotation = pluginClass.getAnnotation(NativePlugin.class);
if (legacyPluginAnnotation == null) {
Logger.error("Plugin doesn't have the @CapacitorPlugin annotation. Please add it");
return null;
}

return legacyPluginAnnotation.name();
}

/**
* Register a plugin class
* @param pluginClass a class inheriting from Plugin
Expand Down Expand Up @@ -671,78 +660,31 @@ private String pluginId(Class<? extends Plugin> clazz) {
}

private String pluginName(Class<? extends Plugin> clazz) {
String pluginName;
CapacitorPlugin pluginAnnotation = clazz.getAnnotation(CapacitorPlugin.class);
if (pluginAnnotation == null) {
pluginName = this.getLegacyPluginName(clazz);
} else {
pluginName = pluginAnnotation.name();
Logger.error("Plugin doesn't have the @CapacitorPlugin annotation. Please add it");
return null;
}

return pluginName;
return pluginAnnotation.name();
}

private void logInvalidPluginException(Class<? extends Plugin> clazz) {
Logger.error(
"NativePlugin " +
"Plugin " +
clazz.getName() +
" is invalid. Ensure the @CapacitorPlugin annotation exists on the plugin class and" +
" the class extends Plugin"
);
}

private void logPluginLoadException(Class<? extends Plugin> clazz, Exception ex) {
Logger.error("NativePlugin " + clazz.getName() + " failed to load", ex);
Logger.error("Plugin " + clazz.getName() + " failed to load", ex);
}

public PluginHandle getPlugin(String pluginId) {
return this.plugins.get(pluginId);
}

/**
* Find the plugin handle that responds to the given request code. This will
* fire after certain Android OS intent results/permission checks/etc.
* @param requestCode
* @return
*/
@Deprecated
@SuppressWarnings("deprecation")
public PluginHandle getPluginWithRequestCode(int requestCode) {
for (PluginHandle handle : this.plugins.values()) {
int[] requestCodes;

CapacitorPlugin pluginAnnotation = handle.getPluginAnnotation();
if (pluginAnnotation == null) {
// Check for legacy plugin annotation, @NativePlugin
NativePlugin legacyPluginAnnotation = handle.getLegacyPluginAnnotation();
if (legacyPluginAnnotation == null) {
continue;
}

if (legacyPluginAnnotation.permissionRequestCode() == requestCode) {
return handle;
}

requestCodes = legacyPluginAnnotation.requestCodes();

for (int rc : requestCodes) {
if (rc == requestCode) {
return handle;
}
}
} else {
requestCodes = pluginAnnotation.requestCodes();

for (int rc : requestCodes) {
if (rc == requestCode) {
return handle;
}
}
}
}
return null;
}

/**
* Call a method on a plugin.
* @param pluginId the plugin id to use to lookup the plugin handle
Expand Down Expand Up @@ -1042,18 +984,8 @@ public void saveInstanceState(Bundle outState) {
}
}

@Deprecated
@SuppressWarnings("deprecation")
public void startActivityForPluginWithResult(PluginCall call, Intent intent, int requestCode) {
Logger.debug("Starting activity for result");

pluginCallForLastActivity = call;

getActivity().startActivityForResult(intent, requestCode);
}

/**
* Check for legacy Capacitor or Cordova plugins that may have registered to handle a permission
* Check for Cordova plugins that may have registered to handle a permission
* request, and handle them if so. If not handled, false is returned.
*
* @param requestCode the code that was requested
Expand All @@ -1063,26 +995,13 @@ public void startActivityForPluginWithResult(PluginCall call, Intent intent, int
*/
@SuppressWarnings("deprecation")
boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
PluginHandle plugin = getPluginWithRequestCode(requestCode);

if (plugin == null) {
boolean permissionHandled = false;
Logger.debug("Unable to find a Capacitor plugin to handle permission requestCode, trying Cordova plugins " + requestCode);
PluginHandle cordovaHandle = getPlugin("__CordovaPlugin");

if (cordovaHandle != null) {
Plugin cordovaPlugin = cordovaHandle.getInstance();
cordovaPlugin.handleRequestPermissionsResult(requestCode, permissions, grantResults);
permissionHandled = cordovaPlugin.hasDefinedRequiredPermissions();
}
Logger.debug("Trying Cordova plugins for permission requestCode " + requestCode);
PluginHandle cordovaHandle = getPlugin("__CordovaPlugin");

return permissionHandled;
}

// Call deprecated method if using deprecated NativePlugin annotation
if (plugin.getPluginAnnotation() == null) {
plugin.getInstance().handleRequestPermissionsResult(requestCode, permissions, grantResults);
return true;
if (cordovaHandle != null) {
Plugin cordovaPlugin = cordovaHandle.getInstance();
cordovaPlugin.handleRequestPermissionsResult(requestCode, permissions, grantResults);
return cordovaPlugin.hasDefinedRequiredPermissions();
}

return false;
Expand Down Expand Up @@ -1198,45 +1117,22 @@ protected Map<String, PermissionState> getPermissionStates(Plugin plugin) {
}

/**
* Handle an activity result and pass it to a plugin that has indicated it wants to
* handle the result.
* Handle an activity result by delegating it to Cordova plugins if any are registered.
* @param requestCode
* @param resultCode
* @param data
*/
@SuppressWarnings("deprecation")
boolean onActivityResult(int requestCode, int resultCode, Intent data) {
PluginHandle plugin = getPluginWithRequestCode(requestCode);

if (plugin == null || plugin.getInstance() == null) {
Logger.debug("Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins " + requestCode);
PluginHandle cordovaHandle = getPlugin("__CordovaPlugin");
if (cordovaHandle != null) {
Plugin cordovaPlugin = cordovaHandle.getInstance();
cordovaPlugin.handleOnActivityResult(requestCode, resultCode, data);
// This is a bit hacky but required to return the boolean out of the cordova interface
return cordovaPlugin.hasRequiredPermissions();
}
return false;
Logger.debug("Trying Cordova plugins for activity requestCode " + requestCode);
PluginHandle cordovaHandle = getPlugin("__CordovaPlugin");
if (cordovaHandle != null) {
Plugin cordovaPlugin = cordovaHandle.getInstance();
cordovaPlugin.handleOnActivityResult(requestCode, resultCode, data);
// This is a bit hacky but required to return the boolean out of the cordova interface
return cordovaPlugin.hasRequiredPermissions();
}

// deprecated, to be removed
PluginCall lastCall = plugin.getInstance().getSavedCall();

// If we don't have a saved last call (because our app was killed and restarted, for example),
// Then we should see if we have any saved plugin call information and generate a new,
// "dangling" plugin call (a plugin call that doesn't have a corresponding web callback)
// and then send that to the plugin
if (lastCall == null && pluginCallForLastActivity != null) {
plugin.getInstance().saveCall(pluginCallForLastActivity);
}

plugin.getInstance().handleOnActivityResult(requestCode, resultCode, data);

// Clear the plugin call we may have re-hydrated on app launch
pluginCallForLastActivity = null;

return true;
return false;
}

/**
Expand Down
37 changes: 0 additions & 37 deletions android/capacitor/src/main/java/com/getcapacitor/NativePlugin.java

This file was deleted.

Loading
Loading