You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2015/10/23 01:19:32 UTC

[1/4] cordova-plugin-camera git commit: Fix permission handling

Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master 933b35b0d -> 44475d9df


Fix permission handling


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

Branch: refs/heads/master
Commit: cbe17eec213c810695f257a93799a2fb88111def
Parents: 8024c5d
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 3 09:08:47 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Oct 22 16:19:12 2015 -0700

----------------------------------------------------------------------
 src/android/CameraLauncher.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/cbe17eec/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index 981efcc..28e96bc 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -1167,6 +1167,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
             if(r == PackageManager.PERMISSION_DENIED)
             {
                 this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
+                return;
             }
         }
         switch(requestCode)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[2/4] cordova-plugin-camera git commit: CB-9583: Permissions for Marshmallow

Posted by bo...@apache.org.
CB-9583: Permissions for Marshmallow


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/8024c5de
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/8024c5de
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/8024c5de

Branch: refs/heads/master
Commit: 8024c5de49888442992f8841740697ae151e1125
Parents: 933b35b
Author: Joe Bowser <bo...@apache.org>
Authored: Wed Sep 2 15:33:36 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Oct 22 16:19:12 2015 -0700

----------------------------------------------------------------------
 src/android/CameraLauncher.java | 87 +++++++++++++++++++++++++++++++-----
 1 file changed, 77 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/8024c5de/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index d7e9be0..981efcc 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -37,6 +37,7 @@ import org.apache.cordova.PluginResult;
 import org.json.JSONArray;
 import org.json.JSONException;
 
+import android.Manifest;
 import android.app.Activity;
 import android.content.ActivityNotFoundException;
 import android.content.ContentValues;
@@ -49,6 +50,7 @@ import android.graphics.Matrix;
 import android.media.MediaScannerConnection;
 import android.media.MediaScannerConnection.MediaScannerConnectionClient;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.provider.MediaStore;
@@ -79,7 +81,11 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private static final String GET_PICTURE = "Get Picture";
     private static final String GET_VIDEO = "Get Video";
     private static final String GET_All = "Get All";
-    
+
+    public static final int PERMISSION_DENIED_ERROR = 20;
+    public static final int TAKE_PIC_SEC = 0;
+    public static final int SAVE_TO_ALBUM_SEC = 1;
+
     private static final String LOG_TAG = "CameraLauncher";
 
     //Where did this come from?
@@ -91,11 +97,16 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private Uri imageUri;                   // Uri of captured image
     private int encodingType;               // Type of encoding to use
     private int mediaType;                  // What type of media to retrieve
+    private int destType;                   // Source type (needs to be saved for the permission handling)
+    private int srcType;                    // Destination type (needs to be saved for permission handling)
     private boolean saveToPhotoAlbum;       // Should the picture be saved to the device's photo album
     private boolean correctOrientation;     // Should the pictures orientation be corrected
     private boolean orientationCorrected;   // Has the picture's orientation been corrected
     private boolean allowEdit;              // Should we allow the user to crop the image.
 
+
+
+
     public CallbackContext callbackContext;
     private int numPics;
 
@@ -103,6 +114,29 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private Uri scanMe;                     // Uri of image to be added to content store
     private Uri croppedUri;
 
+
+    /**
+     *  This plugin requires read access to the storage.
+     */
+
+    protected int checkReadStorage()
+    {
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+        {
+            return cordova.getActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
+        }
+        else
+        {
+            return PackageManager.PERMISSION_GRANTED;
+        }
+    }
+
+    protected void getReadPermission(int requestCode)
+    {
+        cordova.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
+    }
+
+
     /**
      * Executes the request and returns PluginResult.
      *
@@ -115,8 +149,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
         this.callbackContext = callbackContext;
 
         if (action.equals("takePicture")) {
-            int srcType = CAMERA;
-            int destType = FILE_URI;
+            this.srcType = CAMERA;
+            this.destType = FILE_URI;
             this.saveToPhotoAlbum = false;
             this.targetHeight = 0;
             this.targetWidth = 0;
@@ -124,9 +158,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
             this.mediaType = PICTURE;
             this.mQuality = 80;
 
+            //Take the values from the arguments if they're not already defined (this is tricky)
+            this.destType = args.getInt(1);
+            this.srcType = args.getInt(2);
             this.mQuality = args.getInt(0);
-            destType = args.getInt(1);
-            srcType = args.getInt(2);
             this.targetWidth = args.getInt(3);
             this.targetHeight = args.getInt(4);
             this.encodingType = args.getInt(5);
@@ -145,11 +180,11 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
             }
 
              try {
-                if (srcType == CAMERA) {
-                    this.takePicture(destType, encodingType);
+                if (this.srcType == CAMERA) {
+                    this.callTakePicture(destType, encodingType);
                 }
-                else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
-                    this.getImage(srcType, destType, encodingType);
+                else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
+                    this.getImage(this.srcType, destType, encodingType);
                 }
             }
             catch (IllegalArgumentException e)
@@ -205,7 +240,17 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
      * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
      * @param returnType        Set the type of image to return.
      */
-    public void takePicture(int returnType, int encodingType) {
+    public void callTakePicture(int returnType, int encodingType) {
+        if (checkReadStorage() == PackageManager.PERMISSION_GRANTED) {
+            takePicture(returnType, encodingType);
+        } else {
+            getReadPermission(TAKE_PIC_SEC);
+        }
+    }
+
+
+    public void takePicture(int returnType, int encodingType)
+    {
         // Save the number of images currently on disk for later
         this.numPics = queryImgDB(whichContentStore()).getCount();
 
@@ -1112,4 +1157,26 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
     public void onScanCompleted(String path, Uri uri) {
         this.conn.disconnect();
     }
+
+
+    public void onRequestPermissionResult(int requestCode, String[] permissions,
+                                          int[] grantResults) throws JSONException
+    {
+        for(int r:grantResults)
+        {
+            if(r == PackageManager.PERMISSION_DENIED)
+            {
+                this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
+            }
+        }
+        switch(requestCode)
+        {
+            case TAKE_PIC_SEC:
+                takePicture(this.destType, this.encodingType);
+                break;
+            case SAVE_TO_ALBUM_SEC:
+                break;
+
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[3/4] cordova-plugin-camera git commit: Add engine tag for Cordova-Android 5.0.x

Posted by bo...@apache.org.
Add engine tag for Cordova-Android 5.0.x


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/2714060b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/2714060b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/2714060b

Branch: refs/heads/master
Commit: 2714060b09c4d2765cf924d22f80a74d2502530f
Parents: cbe17ee
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 24 15:07:57 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Oct 22 16:19:13 2015 -0700

----------------------------------------------------------------------
 plugin.xml | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/2714060b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 0cb9d9f..6854550 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -30,6 +30,10 @@
     <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git</repo>
     <issue>https://issues.apache.org/jira/browse/CB/component/12320645</issue>
 
+    <engines>
+      <engine name="cordova-android" version=">=5.0.0-dev" />
+    </engines>
+
     <js-module src="www/CameraConstants.js" name="Camera">
         <clobbers target="Camera" />
     </js-module>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[4/4] cordova-plugin-camera git commit: Using the CordovaResourceApi to fine paths of files in the background thread. If the file doesn't exist, return the content URI We also do a refactor to bring this in line. This code got bike-shedded a bit.

Posted by bo...@apache.org.
Using the CordovaResourceApi to fine paths of files in the background thread.  If the file doesn't exist, return the content URI
We also do a refactor to bring this in line.  This code got bike-shedded
a bit.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/44475d9d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/44475d9d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/44475d9d

Branch: refs/heads/master
Commit: 44475d9df98f7e004a529f1e0d8851bf786788a7
Parents: 2714060
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Oct 1 16:19:06 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Oct 22 16:19:13 2015 -0700

----------------------------------------------------------------------
 src/android/CameraLauncher.java | 54 ++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/44475d9d/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index 28e96bc..8a7f9e7 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -32,6 +32,7 @@ import java.util.Date;
 
 import org.apache.cordova.CallbackContext;
 import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaResourceApi;
 import org.apache.cordova.LOG;
 import org.apache.cordova.PluginResult;
 import org.json.JSONArray;
@@ -104,8 +105,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private boolean orientationCorrected;   // Has the picture's orientation been corrected
     private boolean allowEdit;              // Should we allow the user to crop the image.
 
-
-
+    protected final static String[] permissions = { Manifest.permission.READ_EXTERNAL_STORAGE };
 
     public CallbackContext callbackContext;
     private int numPics;
@@ -115,28 +115,11 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private Uri croppedUri;
 
 
-    /**
-     *  This plugin requires read access to the storage.
-     */
-
-    protected int checkReadStorage()
-    {
-        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
-        {
-            return cordova.getActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
-        }
-        else
-        {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-    }
-
     protected void getReadPermission(int requestCode)
     {
         cordova.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
     }
 
-
     /**
      * Executes the request and returns PluginResult.
      *
@@ -241,7 +224,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
      * @param returnType        Set the type of image to return.
      */
     public void callTakePicture(int returnType, int encodingType) {
-        if (checkReadStorage() == PackageManager.PERMISSION_GRANTED) {
+        if (cordova.hasPermission(permissions[0])) {
             takePicture(returnType, encodingType);
         } else {
             getReadPermission(TAKE_PIC_SEC);
@@ -589,6 +572,21 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
         return modifiedPath;
     }
 
+
+
+    /**
+     * We already have shared code to resolve URIs, don't need any more.
+     */
+    private String getRealFileFromUri(Uri uri)
+    {
+        CordovaResourceApi api = webView.getResourceApi();
+        File f = api.mapUriToFile(uri);
+        if(f != null)
+            return "file://" + f.getAbsolutePath();
+        else
+            return uri.toString();
+    }
+
 /**
      * Applies all needed transformation to the image received from the gallery.
      *
@@ -607,10 +605,13 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
         }
         int rotate = 0;
 
+        String fileLocation = getRealFileFromUri(uri);
+        Log.d(LOG_TAG, "File locaton is: " + fileLocation);
+
         // If you ask for video or all media type you will automatically get back a file URI
         // and there will be no attempt to resize any returned data
         if (this.mediaType != PICTURE) {
-            this.callbackContext.success(uri.toString());
+            this.callbackContext.success(fileLocation);
         }
         else {
             // This is a special case to just return the path as no scaling,
@@ -675,7 +676,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
                         }
                     }
                     else {
-                        this.callbackContext.success(uri.toString());
+                        this.callbackContext.success(fileLocation);
                     }
                 }
                 if (bitmap != null) {
@@ -757,7 +758,13 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
         // If retrieving photo from library
         else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
             if (resultCode == Activity.RESULT_OK && intent != null) {
-                this.processResultFromGallery(destType, intent);
+                final Intent i = intent;
+                final int finalDestType = destType;
+                cordova.getThreadPool().execute(new Runnable() {
+                    public void run() {
+                        processResultFromGallery(finalDestType, i);
+                    }
+                });
             }
             else if (resultCode == Activity.RESULT_CANCELED) {
                 this.failPicture("Selection cancelled.");
@@ -1177,7 +1184,6 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
                 break;
             case SAVE_TO_ALBUM_SEC:
                 break;
-
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org