You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by rk...@apache.org on 2016/03/15 18:34:14 UTC

[1/2] cordova-plugin-camera git commit: CB-10120 android: Fix missing CAMERA permission for Android M

Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master 826aca352 -> 0cd962466


CB-10120 android: Fix missing CAMERA permission for Android M

According to the PR conversation, when android.permission.CAMERA
is not set in the package, there is no need to ask for the
camera permission. Also, checking now camera and storage
permissions separately, so if only one of them is missing, the
other one will be requested and not both.

Rebased by MatthewBooth and riknoll

This closes #142, closes #174


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/c12206eb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/c12206eb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/c12206eb

Branch: refs/heads/master
Commit: c12206ebc8ec337613e0751970536d692de6f572
Parents: 826aca3
Author: ochakov <ev...@ochakov.com>
Authored: Tue Dec 1 16:10:43 2015 -0500
Committer: Richard Knoll <ri...@gmail.com>
Committed: Mon Mar 14 17:03:26 2016 -0700

----------------------------------------------------------------------
 src/android/CameraLauncher.java | 43 ++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/c12206eb/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index 1bb6dac..f7ada36 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -58,6 +58,9 @@ import android.provider.MediaStore;
 import android.util.Base64;
 import android.util.Log;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PermissionInfo;
+
 /**
  * This class launches the camera view, allows the user to take a picture, closes the camera view,
  * and returns the captured image.  When the camera view is closed, the screen displayed before
@@ -105,7 +108,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 };
+    protected final static String[] permissions = { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
 
     public CallbackContext callbackContext;
     private int numPics;
@@ -114,6 +117,11 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private Uri scanMe;                     // Uri of image to be added to content store
     private Uri croppedUri;
 
+    protected void getReadPermission(int requestCode)
+    {
+        cordova.requestPermission(this, requestCode, permissions[requestCode]);
+    }
+
     /**
      * Executes the request and returns PluginResult.
      *
@@ -229,14 +237,41 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
      * @param returnType        Set the type of image to return.
      */
     public void callTakePicture(int returnType, int encodingType) {
-        if (PermissionHelper.hasPermission(this, permissions[0])) {
+		boolean takePicturePermission = cordova.hasPermission(permissions[TAKE_PIC_SEC]);
+
+		if (!takePicturePermission) {
+			takePicturePermission = true; // This permission is not required, unless we find android.permission.CAMERA in the package
+			try {
+				PackageManager packageManager = this.cordova.getActivity().getPackageManager();
+				String[] permissionsInPackage = packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions;
+				if (permissionsInPackage != null) {
+					for (String permission : permissionsInPackage) {
+						if (permission.equals(Manifest.permission.CAMERA)) {
+							takePicturePermission = false;
+							break;
+						}
+					}
+				}
+			} catch (NameNotFoundException e) {	}
+		}
+
+		boolean saveAlbumPermission = cordova.hasPermission(permissions[SAVE_TO_ALBUM_SEC]);
+        if (takePicturePermission && saveAlbumPermission) {
             takePicture(returnType, encodingType);
         } else {
-            PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.READ_EXTERNAL_STORAGE);
+			if (saveAlbumPermission && !takePicturePermission) {
+				cordova.requestPermission(this, TAKE_PIC_SEC, permissions[TAKE_PIC_SEC]);
+			}
+			else if (!saveAlbumPermission && takePicturePermission) {
+				cordova.requestPermission(this, TAKE_PIC_SEC, permissions[SAVE_TO_ALBUM_SEC]);
+			}
+			else
+			{
+				cordova.requestPermissions(this, TAKE_PIC_SEC, permissions);
+			}
         }
     }
 
-
     public void takePicture(int returnType, int encodingType)
     {
         // Save the number of images currently on disk for later


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


[2/2] cordova-plugin-camera git commit: CB-10120 android: Fixing use of constants and PermissionHelper

Posted by rk...@apache.org.
CB-10120 android: Fixing use of constants and PermissionHelper

This closes #179


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/0cd96246
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/0cd96246
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/0cd96246

Branch: refs/heads/master
Commit: 0cd962466d2641fcd05155690e23432db02cc79a
Parents: c12206e
Author: riknoll <ri...@gmail.com>
Authored: Wed Feb 24 14:51:52 2016 -0800
Committer: Richard Knoll <ri...@gmail.com>
Committed: Mon Mar 14 17:56:52 2016 -0700

----------------------------------------------------------------------
 src/android/CameraLauncher.java | 64 +++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/0cd96246/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index f7ada36..0240990 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -117,10 +117,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private Uri scanMe;                     // Uri of image to be added to content store
     private Uri croppedUri;
 
-    protected void getReadPermission(int requestCode)
-    {
-        cordova.requestPermission(this, requestCode, permissions[requestCode]);
-    }
 
     /**
      * Executes the request and returns PluginResult.
@@ -237,38 +233,40 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
      * @param returnType        Set the type of image to return.
      */
     public void callTakePicture(int returnType, int encodingType) {
-		boolean takePicturePermission = cordova.hasPermission(permissions[TAKE_PIC_SEC]);
-
-		if (!takePicturePermission) {
-			takePicturePermission = true; // This permission is not required, unless we find android.permission.CAMERA in the package
-			try {
-				PackageManager packageManager = this.cordova.getActivity().getPackageManager();
-				String[] permissionsInPackage = packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions;
-				if (permissionsInPackage != null) {
-					for (String permission : permissionsInPackage) {
-						if (permission.equals(Manifest.permission.CAMERA)) {
-							takePicturePermission = false;
-							break;
-						}
-					}
-				}
-			} catch (NameNotFoundException e) {	}
-		}
-
-		boolean saveAlbumPermission = cordova.hasPermission(permissions[SAVE_TO_ALBUM_SEC]);
+        boolean saveAlbumPermission = PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
+        boolean takePicturePermission = PermissionHelper.hasPermission(this, Manifest.permission.CAMERA);
+
+        // CB-10120: The CAMERA permission does not need to be requested unless it is declared
+        // in AndroidManifest.xml. This plugin does not declare it, but others may and so we must
+        // check the package info to determine if the permission is present.
+
+        if (!takePicturePermission) {
+            takePicturePermission = true;
+            try {
+                PackageManager packageManager = this.cordova.getActivity().getPackageManager();
+                String[] permissionsInPackage = packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions;
+                if (permissionsInPackage != null) {
+                    for (String permission : permissionsInPackage) {
+                        if (permission.equals(Manifest.permission.CAMERA)) {
+                            takePicturePermission = false;
+                            break;
+                        }
+                    }
+                }
+            } catch (NameNotFoundException e) {
+                // We are requesting the info for our package, so this should
+                // never be caught
+            }
+        }
+
         if (takePicturePermission && saveAlbumPermission) {
             takePicture(returnType, encodingType);
+        } else if (saveAlbumPermission && !takePicturePermission) {
+            PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.CAMERA);
+        } else if (!saveAlbumPermission && takePicturePermission) {
+            PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.READ_EXTERNAL_STORAGE);
         } else {
-			if (saveAlbumPermission && !takePicturePermission) {
-				cordova.requestPermission(this, TAKE_PIC_SEC, permissions[TAKE_PIC_SEC]);
-			}
-			else if (!saveAlbumPermission && takePicturePermission) {
-				cordova.requestPermission(this, TAKE_PIC_SEC, permissions[SAVE_TO_ALBUM_SEC]);
-			}
-			else
-			{
-				cordova.requestPermissions(this, TAKE_PIC_SEC, permissions);
-			}
+            PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, permissions);
         }
     }
 


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