-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(android)!: Android 13 support #814
Conversation
Replace READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions with READ_MEDIA_IMAGES on SDK 33
Request storage permission even without saving to photo album enabled. Required by design.
@ochakov I tested your fork in my project and got 2 issues : => removing android:maxSdkVersion="32" solved the compilation issue. 2°) At runtime when trying to capture photo (either from camera or library), on Android 13, I always get permission refused. It seems that READ_MEDIA_IMAGES permission does not have to be requested. => Removing Manifest.permission.READ_MEDIA_IMAGES from requested permissions in CameraLauncher:129-130 solve the issue |
This is a breaking change as it requires at least apps compiled with API 33 and I'm sure the current tests are failing due to that reason since cordova-android@11 by default compiles with API 32. So I created a new 7.0.0 milestone for this PR to be added to so this can be looked at after cordova-android is updated for API 33 support. |
with from my other plugins. => removing android:maxSdkVersion="32" solved the compilation issue. Removing In other words, I think this PR has the right path moving forward, and the other plugins requires updates.
It seems that READ_MEDIA_IMAGES permission does not have to be requested. => Removing Manifest.permission.READ_MEDIA_IMAGES from requested permissions in CameraLauncher:129-130 solve the issue The Andoid Docs states that |
It does work for me, using Pixel 4 and 7 and it does not allow taking pictures if this permission is not granted. I think we must compare the parameters sent to the plugin when taking pictures. In my case, I am using destination type file without saving to album. |
On my side, i'm using destination type data URI on pixel 5. When using your fork, the permission popup is not shown at all. i get immediate callback with permission refused. |
according to Android docs , WRITE_EXTERNAL_STORAGE permission has no effect since Android 11 (API 30). As a result the exact max sdk to set would be 29 on this permission entry. |
Yes, it's actually been obsolete since scoped storage, which enabled in API 29, but can be opt out back to API 28 behaviour via |
Ok understood. |
Any time period for the reintegration of this PR? Thanks |
indeed, it is strange that the Android 12 test suite fails, but I can't see the test logs anymore @ochakov can you kindly amend your commits such that it is Android 12 (SDK v 32) compatible? I.e., it passes the Test suite for Android 12. |
It depends on cordova-android 12 which is unreleased and still in development.
There's nothing to be done at this time. The code should work fine, it just needs to be compiled with SDK 33. The test fails because it uses the latest cordova-android version, which by default targets with SDK 32. This PR should be usable as is if you set the |
is this achievable merely by adding to config.xml this? <platform name="android">
<preference name="android-compileSdkVersion" value="33"/>
<preference name="android-targetSdkVersion" value="33"/> |
got it, thanks |
Usually at cordova-android level, support just entails bumping build tools version to the next API level, and compiling for that target. Sometimes it may require more changes but in my experience that's usually all that is required.
cordova-android@12 will have these values set to 33 by default. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Have you tested this PR for taking videos? I noticed that right now we are only handling the |
This comment was marked as off-topic.
This comment was marked as off-topic.
@@ -55,7 +55,7 @@ | |||
</feature> | |||
</config-file> | |||
<config-file target="AndroidManifest.xml" parent="/*"> | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> | |||
</config-file> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you should add here also
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" android:minSdkVersion="33" />
based on suggestion from @felicienfrancois
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ochakov could you add that to this PR, such that I can use this PR in my project?
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle video permission Add permissions to manifest
Only require media storage permissions when taking picture when save to album is requested
Final fixes
@ochakov thanks a lot for your amendments I just tested now and On the other hand Do kindly thus amend to the following: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" android:minSdkVersion="33" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" android:minSdkVersion="33" /> I tested now with these amendments on both Android 12 (API 32) and 13 (API 33) and it builds and works just fine. I guess with API 33 Android simply ignores |
@jfoclpf |
Hi @ochakov
By having minSdk we ensure these new permissions are only used with API 33 and above without any building conflicts, since these permissions are totally new with API 33. @breautek do you have any opinion therefor? |
Maybe we should also raise an issue on the manifest merger. The conflict issue is caused my manifest merger not being able to merge 2 permissions having a different maxSdkVersion / minSdkVersion. |
That's off topic but it's a very good point IMHO, to merge considering the
most restrictive feature, for example if there are two different maxSdk
select the lowest.
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Any updates to this PR? |
Like the last few comments stated, this PR depends on cordova-android@12 which is in development. This PR is blocked until cordova-android@12 is released, and only then this PR will resume (cordova-android@12 should fix the failing tests). Locking to keep the discussion history clean. Will unlock once cordova-android@12 is released to allow for further comments. |
Closing/reopening to restart tests. |
else { | ||
switch (mediaType) { | ||
case PICTURE: | ||
return new String[]{ Manifest.permission.CAMERA, Manifest.permission.CAMERA, Manifest.permission.READ_MEDIA_IMAGES }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new String[]{ Manifest.permission.CAMERA, Manifest.permission.CAMERA, Manifest.permission.READ_MEDIA_IMAGES }; | |
return new String[]{ Manifest.permission.CAMERA, Manifest.permission.READ_MEDIA_IMAGES }; |
Duplicate permission ?
This PR works well on my Android s20 FE. The only issue remaining is the Gallery, for some reason, it just complains about permissions being denied and the dined permission is (READ_MEDIA_IMAGES) when trying to access the gallery. But that permission is never requested in the app. Removing the check and request for permissions makes it all work for me (even gallery). Even though I clearly see that READ_MEDIA_IMAGES is not granted.
So just doing this.getImage(this.srcType, destType);
I'm a bit confused because I have done a fresh install of the app on both my Android s20 FE and A Pixel 3 emulator on API 30... And both now NEVER request permissions for camera or gallery and both actually just work. |
if (storageOnly) { | ||
switch (mediaType) { | ||
case PICTURE: | ||
return new String[]{ Manifest.permission.READ_MEDIA_IMAGES }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to test this.
the CAMERA
permission is not something normally required, but if the android manifest declares the permisison, then the app must have it granted (even if we the app doesn't use any camera APIs itself). So requesting the CAMERA
permission before was required. I'm not sure that bug is still present in the Android SDK in API 33.
String[] storagePermissions = getPermissions(true, mediaType); | ||
boolean saveAlbumPermission; | ||
if (this.saveToPhotoAlbum) { | ||
saveAlbumPermission = hasPermissions(storagePermissions); | ||
} else { | ||
saveAlbumPermission = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will produce an issue with Android < 8.0. I've replace the code above with this and it works.
String[] storagePermissions = getPermissions(true, mediaType);
boolean saveAlbumPermission = hasPermissions(storagePermissions);
is keep add duplicate writes to external into manifest I think it conflict with Android permissions plugin
|
Use READ_MEDIA_IMAGES and READ_MEDIA_VIDEO permissions when plugin is used with Android 13 or newer. Based on apache#814 WR-Issue: #17645
In our testing, this PR works for us with Cordova Android 12 |
* feat(android)!: Android 13 support * refactor(android): simplify getPermissions logic * feat(android)!: bump cordova-android requirement to >=12.0.0 * feat(android): update saveAlbumPermission to include Android 9 and below use case --------- Co-authored-by: ochakov <[email protected]>
Platforms affected
Android
Motivation and Context
Allow building applications using Android SDK 33, support for Android 13
Closes #825
Description
Remove deprecated READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions and replace with new READ_MEDIA_IMAGES
Testing
Taking pictures and accessing gallery, save pictures into album
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)