[
https://issues.apache.org/jira/browse/CB-11534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16261739#comment-16261739
]
ASF GitHub Bot commented on CB-11534:
-------------------------------------
maverickmishra closed pull request #150: CB-11534 This plugin should support
Android Marshmallow runtime permission
URL: https://github.com/apache/cordova-plugin-file-transfer/pull/150
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/plugin.xml b/plugin.xml
index 2b0e057..ff4222a 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -30,6 +30,7 @@
<issue>https://issues.apache.org/jira/browse/CB/component/12320650</issue>
<dependency id="cordova-plugin-file" version="^4.0.0" />
+ <dependency id="cordova-plugin-compat" version="^1.0.0" />
<js-module src="www/FileTransferError.js" name="FileTransferError">
<clobbers target="window.FileTransferError" />
diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index 86176a2..fc279d9 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -48,10 +48,10 @@ Licensed to the Apache Software Foundation (ASF) under one
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-import org.apache.cordova.Config;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaResourceApi;
+import org.apache.cordova.PermissionHelper;
import org.apache.cordova.CordovaResourceApi.OpenForReadResult;
import org.apache.cordova.PluginManager;
import org.apache.cordova.PluginResult;
@@ -61,6 +61,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.json.JSONException;
import org.json.JSONObject;
+import android.Manifest;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
@@ -78,9 +80,18 @@ Licensed to the Apache Software Foundation (ASF) under one
public static int CONNECTION_ERR = 3;
public static int ABORTED_ERR = 4;
public static int NOT_MODIFIED_ERR = 5;
+ public static int PERMISSION_DENIED_ERR = 6;
private static HashMap<String, RequestContext> activeRequests = new
HashMap<String, RequestContext>();
private static final int MAX_BUFFER_SIZE = 16 * 1024;
+
+ private final int PERMISSIONS_REQUEST_ID=1;
+ private String sourceStore;
+ private String targetStore;
+ private JSONArray argsStore;
+ private Boolean isDownload=true;
+ private CallbackContext callbackContextStore;
+ protected final static String[] permissions = {
Manifest.permission.WRITE_EXTERNAL_STORAGE };
private static final class RequestContext {
String source;
@@ -176,13 +187,28 @@ public long getTotalRawBytesRead() {
@Override
public boolean execute(String action, JSONArray args, final
CallbackContext callbackContext) throws JSONException {
if (action.equals("upload") || action.equals("download")) {
+ boolean permissionHas=true;
+ if(!PermissionHelper.hasPermission(this, permissions[0])){
+ permissionHas=false;
+ }
String source = args.getString(0);
String target = args.getString(1);
-
- if (action.equals("upload")) {
- upload(source, target, args, callbackContext);
- } else {
- download(source, target, args, callbackContext);
+ if(permissionHas){
+ if (action.equals("upload")) {
+ upload(source, target, args, callbackContext);
+ } else {
+ download(source, target, args, callbackContext);
+ }
+ }
+ else{
+ if(action.equals("upload")){
+ this.isDownload=false;
+ }
+ this.sourceStore=source;
+ this.targetStore=target;
+ this.argsStore=args;
+ this.callbackContextStore=callbackContext;
+ PermissionHelper.requestPermission(this,
PERMISSIONS_REQUEST_ID, permissions[0]);
}
return true;
} else if (action.equals("abort")) {
@@ -795,7 +821,6 @@ private void download(final String source, final String
target, JSONArray args,
synchronized (activeRequests) {
activeRequests.put(objectId, context);
}
-
cordova.getThreadPool().execute(new Runnable() {
public void run() {
if (context.aborted) {
@@ -1021,4 +1046,24 @@ public void run() {
});
}
}
+ public void onRequestPermissionResult(int requestCode, String[]
permissions, int[] grantResults)
+ throws JSONException {
+ for (int r : grantResults) {
+ if (r == PackageManager.PERMISSION_DENIED) {
+ JSONObject error =
createFileTransferError(PERMISSION_DENIED_ERR, this.sourceStore,
this.targetStore, "Permision denied", null, null);
+
this.callbackContextStore.sendPluginResult(new
PluginResult(PluginResult.Status.ERROR, error));
+ return;
+ }
+ }
+ switch (requestCode) {
+ case PERMISSIONS_REQUEST_ID:
+ if(this.isDownload){
+ download(this.sourceStore,
this.targetStore, this.argsStore, this.callbackContextStore);
+ }
+ else{
+ upload(this.sourceStore,
this.targetStore, this.argsStore, this.callbackContextStore);
+ }
+ break;
+ }
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Cordova file-transfer-plugin should support Android Marshmallow runtime
> permission
> ----------------------------------------------------------------------------------
>
> Key: CB-11534
> URL: https://issues.apache.org/jira/browse/CB-11534
> Project: Apache Cordova
> Issue Type: New Feature
> Components: cordova-plugin-file-transfer (DEPRECATED)
> Environment: Android Marshmallow,Android target platform 23.
> Reporter: Homen Borgohain
> Assignee: Filip Maj
> Labels: Android, android6.0, permission
> Original Estimate: 10m
> Remaining Estimate: 10m
>
> In Android Marshmallow file-transfer-plugin should show a pop up if storage
> permission is not granted.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]