Skip to content

Commit

Permalink
RMET-3930 - Prepare to release version 4.2.0-OS53 (#149)
Browse files Browse the repository at this point in the history
* RMET-3653 - Add support for capacitor and add missing permissions (#139)

* test: remove hook to test plugin

* test: use edit-config instead of config-file

* fix: replace config-file with edit-config and remove unnecessary hook

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* chore: remove unused hook

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* chore: remove the usage of kotlin-kapt plugin

Context: It wasn't being used.

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* feat: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* test: use manifest as parent

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* chore: don't need to specify Manifest as parent

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3653

* fix: add necessary permissions to AndroidManifest.xml

Context: MABS 11 was updated with the latest version of the native shell, which removes this permissions, so plugins need to add them.

References: https://outsystemsrd.atlassian.net/browse/RMET-3856

* chore(release): prepare to release version 4.2.0-OS51

References: https://outsystemsrd.atlassian.net/browse/RMET-3857

* RMET-3810 ::: Generated Thumbnail Bigger than Expected (#136)

* chore: update libraries for testing

This adds the fix on the library side.

References: https://outsystemsrd.atlassian.net/browse/RMET-3810

* chore: migrating theses codes from library

These are only used here, so this is where they belong.

* chore: remove unused variables

* chore: add CHANGELOG entry

References: https://outsystemsrd.atlassian.net/browse/RMET-3810

---------

Co-authored-by: Alexandre Jacinto <alexandre.jacinto@outsystems.com>

* RMET-3812 - Use PhotoPicker API to select media from gallery (#141)

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: include Jetpack Compose dependencies

Context: Without these, the Photo Picker is not launched for Android 12 devices.

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: remove unnecessary dependencies

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: include activity dependency

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3812

* RMET-3875 - Fix issue in permission request for `EditURIPicture` and remove unnecessary permissions (#142)

* fix: properly check if gallery permissions are needed

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* fix: avoid requesting unnecessary permission when choosing media from the gallery

Context: When using intents or the Photo Picker API for the user to select media (images and videos) we don't need to request the READ_EXTERNAL_STORAGE permission. That is only necessary when accessing files in the external storage (e.g. when calling editURIPicture)

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* fix: remove unnecessary permissions from plugin

Context: We actually never request these permissions, so there's no point in declaring them in the AndroidManifest.xml file.

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* refactor: avoid asking unnecessary permissions

Context: As we use the MediaStore to fetch and store photos in the device's gallery, these permissions aren't necessary.

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* chore: set lib to dev version

* Revert "refactor: avoid asking unnecessary permissions"

This reverts commit 28d61e4.

* revert: revert commit where we removed the READ_EXTERNAL_STORAGE permission request for Android < 13

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* chore: remove entry from changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* chore(release): raise to version 4.2.0-OS52

References: https://outsystemsrd.atlassian.net/browse/RMET-3875

* RMET-3894 ::: Improve Error Handling for Size (#144)

* fix(ios): improve error handling for OSCAMRTakePictureParameters

Make 'targetWidth' and 'targetHeight' optional and 'includeMetadata' and 'latestVersion' mandatory.
Validate all optional fields and, when the result is missing or out of bounds, return the new OSCAMRTakePictureParametersError invalid error. This error is also managed on OSCamera's takePicture method.
Update iOS library, that also adds error handling on its side.

References: https://outsystemsrd.atlassian.net/browse/RMET-3894

* fix(js): remove default value for takePicture's targetWidth and targetHeight

The nil values are supposed to go into the native code for proper error handling.
Sync default quality value with Outsystems.

References: https://outsystemsrd.atlassian.net/browse/RMET-3894

* chore(android): adapt code to new JavaScript structure

'targetWidth' and 'targetHeight' can be passed as 'null', so they need a fallback value when retrieved.

References: https://outsystemsrd.atlassian.net/browse/RMET-3894

* refactor(android): code cleanse

Remove unused and unnecessary variable definition.
Simplify 'includeMetadata' and 'latestVersion' value retrieval.

References: https://outsystemsrd.atlassian.net/browse/RMET-3894

* chore: add CHANGELOG entry

References: https://outsystemsrd.atlassian.net/browse/RMET-3894

* chore(release): set to version 4.2.0-OS52 (#145)

References: https://outsystemsrd.atlassian.net/browse/RMET-3888

* Revert "Merge branch 'outsystems' into development"

This reverts commit 5e44264, reversing
changes made to b9bd0e9.

* chore: remove unnecessary entry from changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3888

* chore: add missing entries to CHANGELOG.md

References: https://outsystemsrd.atlassian.net/browse/RMET-3888

* Fix ::: RMET-3806 ::: Checking camera permission in Android (#147)

* fix: Only request camera permission if declared

References:
- https://outsystemsrd.atlassian.net/browse/RMET-3806
- https://developer.android.com/reference/android/provider/MediaStore#ACTION_IMAGE_CAPTURE
- https://developer.android.com/reference/android/provider/MediaStore#ACTION_VIDEO_CAPTURE

* chore: Update CHANGELOG.md

References:
- https://outsystemsrd.atlassian.net/browse/RMET-3806

* RMET-3930 - Review external storage permissions (#148)

* fix: avoid asking for storage permissions if saveToPhotoAlbum is false (and refactor code)

Context: If saveToPhotoAlbum is false, we don't need to request storage permissions.

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: simplify code for callCaptureVideo

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* refactor: only request storage permissions for TakePicture and RecordVideo for Android <= 10

Context: For Android <= 10, if these permissions aren't requested, a SecurityException is thrown. For Android >= 11, these permissions aren't necessary.

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* refactor: refactoring editURIPicture to only ask for storage permissions for Android <= 10

Context: These permissions aren't necessary starting on Android 11.

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* fix: only ask for storage permissions in chooseFromGallery for Android <= 10

Context: These permissions aren't necessary starting on Android 11.

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* fix: only request external storage permission for Android <= 10

Context: This permissions isn't necessary for Android >= 11.

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: add comments explaining if conditions

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* refactor: remove extra lines

* fix: only include external storage permissions in Manifest for Android <= 10

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: revert previous commit

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: update dependency to OSCameraLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore(release): raise to version 4.2.0-OS53

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

* chore: add missing changelog entries

References: https://outsystemsrd.atlassian.net/browse/RMET-3930

---------

Co-authored-by: Ricardo Silva <97543217+OS-ricardomoreirasilva@users.noreply.github.com>
Co-authored-by: Pedro Bilro <pedro.gustavo.bilro@outsystems.com>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent c2c8ce0 commit 58bd206
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 50 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-camera"
version="4.2.0-OS52">
version="4.2.0-OS53">
<name>Camera</name>
<description>Cordova Camera Plugin</description>
<license>Apache 2.0</license>
Expand Down Expand Up @@ -64,7 +64,6 @@
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
</config-file>

<edit-config target="AndroidManifest.xml" parent="application">
Expand Down
92 changes: 46 additions & 46 deletions src/android/CameraLauncher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 58bd206

Please sign in to comment.