diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a190e2f2..37fb5e591 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The changes documented here do not include those from the original repository. +## 4.2.0-OS53 + +### Fixes +- (android) Only request external storage permissions in `TakePicture` if `saveToGallery` is true (https://outsystemsrd.atlassian.net/browse/RMET-3930) +- (android) Only request external storage permissions for Android <= 10 (https://outsystemsrd.atlassian.net/browse/RMET-3930) +- (android) Only request camera permission for photo and video if declared (https://outsystemsrd.atlassian.net/browse/RMET-3806) +- (android) Cropping in edit image when rotating in landscape mode (https://outsystemsrd.atlassian.net/browse/RMET-3840) +- (android) Crash when trying to edit video (https://outsystemsrd.atlassian.net/browse/RMET-3891) + ## 4.2.0-OS52 ### Features diff --git a/libs/android/build.gradle b/libs/android/build.gradle index 43328dfe2..b983816f9 100644 --- a/libs/android/build.gradle +++ b/libs/android/build.gradle @@ -7,6 +7,6 @@ repositories { } dependencies { - implementation("com.github.outsystems:oscamera-android:1.3.0@aar") + implementation("com.github.outsystems:oscamera-android:1.3.2@aar") implementation 'androidx.activity:activity-ktx:1.9.3' } diff --git a/package.json b/package.json index bf8ab09ba..403c0a359 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-camera", - "version": "4.2.0-OS52", + "version": "4.2.0-OS53", "description": "Cordova Camera Plugin", "types": "./types/index.d.ts", "cordova": { diff --git a/plugin.xml b/plugin.xml index 5b2898592..f435c9737 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,7 @@ + version="4.2.0-OS53"> Camera Cordova Camera Plugin Apache 2.0 @@ -64,7 +64,6 @@ - diff --git a/src/android/CameraLauncher.kt b/src/android/CameraLauncher.kt index 583411247..85a245365 100644 --- a/src/android/CameraLauncher.kt +++ b/src/android/CameraLauncher.kt @@ -269,40 +269,21 @@ class CameraLauncher : CordovaPlugin() { * @param encodingType Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) */ fun callTakePicture(returnType: Int, encodingType: Int) { - val saveAlbumPermission = Build.VERSION.SDK_INT < 33 && - PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) && - PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) - var 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 { - val packageManager = cordova.activity.packageManager - val permissionsInPackage = packageManager.getPackageInfo( - cordova.activity.packageName, - PackageManager.GET_PERMISSIONS - ).requestedPermissions - if (permissionsInPackage != null) { - for (permission in permissionsInPackage) { - if (permission == Manifest.permission.CAMERA) { - takePicturePermission = false - break - } - } - } - } catch (e: Exception) { - Log.d(LOG_TAG, e.message.toString()) - } - } - if (takePicturePermission && saveAlbumPermission) { + // we don't want to ask for these permissions from Android 11 onwards + val saveAlbumPermission = Build.VERSION.SDK_INT >= 30 || !saveToPhotoAlbum || + (PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) && + PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) + + val takePicturePermission = PermissionHelper.hasPermission(this, Manifest.permission.CAMERA) || + !hasCameraPermissionDeclared() + + if (takePicturePermission && saveAlbumPermission) { // no permissions need to be requested cordova.setActivityResultCallback(this) camController?.takePicture(cordova.activity, returnType, encodingType) - } else if (saveAlbumPermission && !takePicturePermission) { + } else if (saveAlbumPermission) { // we need to request camera permissions PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.CAMERA) - } else if (!saveAlbumPermission && takePicturePermission && Build.VERSION.SDK_INT < 33) { + } else if (takePicturePermission) { // we need to request storage permissions PermissionHelper.requestPermissions( this, TAKE_PIC_SEC, @@ -311,12 +292,7 @@ class CameraLauncher : CordovaPlugin() { Manifest.permission.WRITE_EXTERNAL_STORAGE ) ) - } - // we don't want to ask for this permission from Android 13 onwards - else if (!saveAlbumPermission && takePicturePermission && Build.VERSION.SDK_INT >= 33) { - cordova.setActivityResultCallback(this) - camController?.takePicture(cordova.activity, returnType, encodingType) - } else { + } else { // we need to request both permissions PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, permissions) } } @@ -330,7 +306,8 @@ class CameraLauncher : CordovaPlugin() { */ fun callGetImage(srcType: Int, returnType: Int, encodingType: Int) { - if (Build.VERSION.SDK_INT < 33 && !PermissionHelper.hasPermission( + // we don't want to ask for this permission from Android 11 onwards + if (Build.VERSION.SDK_INT < 30 && !PermissionHelper.hasPermission( this, Manifest.permission.READ_EXTERNAL_STORAGE ) @@ -364,12 +341,12 @@ class CameraLauncher : CordovaPlugin() { fun callEditUriImage(editParameters: OSCAMREditParameters) { - val galleryPermissionNeeded = Build.VERSION.SDK_INT < 33 && + // we don't want to ask for these permissions from Android 11 onwards + val galleryPermissionNeeded = Build.VERSION.SDK_INT < 30 && (!PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) || (editParameters.saveToGallery && !PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE))) - // we don't want to ask for this permission from Android 13 onwards - if (galleryPermissionNeeded && Build.VERSION.SDK_INT < 33) { + if (galleryPermissionNeeded) { var permissions = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) if (editParameters.saveToGallery) { permissions += Manifest.permission.WRITE_EXTERNAL_STORAGE @@ -396,9 +373,11 @@ class CameraLauncher : CordovaPlugin() { fun callCaptureVideo(saveVideoToGallery: Boolean) { val cameraPermissionNeeded = !PermissionHelper.hasPermission(this, Manifest.permission.CAMERA) + && hasCameraPermissionDeclared() - val galleryPermissionNeeded = saveVideoToGallery && !(Build.VERSION.SDK_INT < 33 && - PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) && + // we don't want to ask for these permissions from Android 11 onwards + val galleryPermissionNeeded = Build.VERSION.SDK_INT < 30 && saveVideoToGallery && + !(PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) && PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) if (cameraPermissionNeeded && galleryPermissionNeeded) { @@ -414,8 +393,8 @@ class CameraLauncher : CordovaPlugin() { ) return } - // we don't want to ask for this permission from Android 13 onwards - else if (galleryPermissionNeeded && Build.VERSION.SDK_INT < 33) { + + else if (galleryPermissionNeeded) { PermissionHelper.requestPermissions( this, CAPTURE_VIDEO_SEC, @@ -451,7 +430,8 @@ class CameraLauncher : CordovaPlugin() { return } - if (Build.VERSION.SDK_INT < 33 + // we don't want to ask for this permission from Android 11 onwards + if (Build.VERSION.SDK_INT < 30 && !PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { PermissionHelper.requestPermission( @@ -460,7 +440,6 @@ class CameraLauncher : CordovaPlugin() { Manifest.permission.READ_EXTERNAL_STORAGE ) } - // we don't want to ask for this permission from Android 13 onwards else { callChooseFromGallery() } @@ -902,6 +881,27 @@ class CameraLauncher : CordovaPlugin() { return ERROR_FORMAT_PREFIX + "0000$stringCode".substring(stringCode.length) } + private fun hasCameraPermissionDeclared(): Boolean { + // CB-10120: The CAMERA permission does not need to be requested unless it is declared + // in AndroidManifest.xml -> If it's declared, Media Store intents will throw SecurityException if permission is not granted + // This plugin does not declare it, but others may and so we must check the package info to determine if the permission is present. + try { + val packageManager = cordova.activity.packageManager + val permissionsInPackage = packageManager.getPackageInfo( + cordova.activity.packageName, + PackageManager.GET_PERMISSIONS + ).requestedPermissions ?: arrayOf() + for (permission in permissionsInPackage) { + if (permission == Manifest.permission.CAMERA) { + return true + } + } + } catch (e: Exception) { + Log.d(LOG_TAG, e.message.toString()) + } + return false + } + companion object { private const val FILE_URI = 1 // Return file uri (content://media/external/images/media/2 for Android)