Move more logic to the plugin javascript to reduce duplication in the native code implementations. (Android)