cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rkn...@apache.org
Subject [1/2] cordova-plugin-camera git commit: CB-10120 android: Fix missing CAMERA permission for Android M
Date Tue, 15 Mar 2016 17:34:14 GMT
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 <evgeny@ochakov.com>
Authored: Tue Dec 1 16:10:43 2015 -0500
Committer: Richard Knoll <richard.b.knoll@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


Mime
View raw message