Added a check for File Write

Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/769eead9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/769eead9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/769eead9

Branch: refs/heads/master
Commit: 769eead9a62632818b87aa946720566ab4eb4728
Parents: 4cc748b
Author: Joe Bowser <[email protected]>
Authored: Wed Sep 30 11:22:00 2015 -0700
Committer: Joe Bowser <[email protected]>
Committed: Wed Oct 28 10:39:07 2015 -0700

----------------------------------------------------------------------
 src/android/FileUtils.java | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/769eead9/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index c690cb5..931e2ee 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -175,7 +175,7 @@ public class FileUtils extends CordovaPlugin {
        Activity activity = cordova.getActivity();
        String packageName = activity.getPackageName();
 
-        String location = 
preferences.getString("androidpersistentfilelocation", "internal");
+        String location = 
preferences.getString("androidpersistentfilelocation", "compatibility");
 
        tempRoot = activity.getCacheDir().getAbsolutePath();
        if ("internal".equalsIgnoreCase(location)) {
@@ -347,8 +347,18 @@ public class FileUtils extends CordovaPlugin {
                     String data=args.getString(1);
                     int offset=args.getInt(2);
                     Boolean isBinary=args.getBoolean(3);
-                    long fileSize = write(fname, data, offset, isBinary);
-                    callbackContext.sendPluginResult(new 
PluginResult(PluginResult.Status.OK, fileSize));
+                    /*
+                     * If we don't have the package name in the path, we're 
reading and writing to places we need permission for
+                     */
+                    if(fname.contains(cordova.getActivity().getPackageName()) 
||
+                            hasReadPermission()) {
+                        long fileSize = write(fname, data, offset, isBinary);
+                        callbackContext.sendPluginResult(new 
PluginResult(PluginResult.Status.OK, fileSize));
+                    }
+                    else {
+                        getWritePermission();
+                    }
+
                 }
             }, rawArgs, callbackContext);
         }
@@ -1105,7 +1115,16 @@ public class FileUtils extends CordovaPlugin {
                 }, lastRawArgs, callback);
                 break;
             case WRITE_PERM:
-
+                threadhelper( new FileOp( ){
+                    public void run(JSONArray args) throws JSONException, 
FileNotFoundException, IOException, NoModificationAllowedException {
+                        String fname=args.getString(0);
+                        String data=args.getString(1);
+                        int offset=args.getInt(2);
+                        Boolean isBinary=args.getBoolean(3);
+                        long fileSize = write(fname, data, offset, isBinary);
+                        callback.sendPluginResult(new 
PluginResult(PluginResult.Status.OK, fileSize));
+                    }
+                }, lastRawArgs, callback);
                 break;
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to