Skip to content
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)!: support API 33+ permissions #262

Merged
merged 2 commits into from
Jul 20, 2023
Merged

Conversation

ochakov
Copy link
Contributor

@ochakov ochakov commented Oct 13, 2022

Platforms affected

Android

Motivation and Context

Allow building applications using Android SDK 33, support for Android 13

Description

Remove deprecated READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions and replace with new READ_MEDIA_IMAGES, READ_MEDIA_VIDEO and READ_MEDIA_AUDIO

Testing

Capture video and audio

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

Replace READ_EXTERNAL_STORAGE permission with READ_MEDIA_AUDIO, READ_MEDIA_VIDEO and READ_MEDIA_IMAGES
Do not request new permissions on older SDKs as they do not support
Copy link
Contributor

@breautek breautek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codewise I think is okay. I haven't ran these changes.

I did find the changes hard to follow, we may want to refactor this at some point in the future for readability, but I don't consider this a blocker for a merge.

private static String[] storagePermissions;
static {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
storagePermissions = new String[]{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally thought this was a mistake, however reading through the PR I see the list is added onto on demand.

Not a merge blocker but perhaps add a comment to make this clear.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it dont seem to work i have added all changes but on android 13 it gives permission denied error

@FrancescoPaiola
Copy link

any update on this?

@erisu erisu changed the title Android 13 support feat(android)!: support Android 13 permissions Jul 12, 2023
@erisu erisu changed the title feat(android)!: support Android 13 permissions feat(android)!: support API 33+ permissions Jul 12, 2023
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erisu erisu merged commit f21e0a0 into apache:master Jul 20, 2023
@PabbleDabble
Copy link

PabbleDabble commented Jul 25, 2023

Anyone else getting Android manifest merger errors with this? Our app uses a bunch of different plugins and it looks like these two items are being placed in the manifest from other plugins...

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

...and these these items appear to be coming from this (cordova-plugin-media-capture)

    <uses-permission android:maxSdkVersion="32" android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:maxSdkVersion="32" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

It looked like I might be able to do something in my app's config.xml in order to replace them ( https://stackoverflow.com/questions/25981156/tools-replace-not-replacing-in-android-manifest ) but I wasn't fully understanding it / created more errors in Android studio.

Apologies if I'm off base, I'm not blaming this change, this looks like the better way to specify it, just not sure if there's anything else that needs done? Or maybe it's something on my end and need to find out what other plugins might be adding this and get them upgraded as well?

Sorry if this is off topic.

EDIT/UPDATE: I had to fork this plugin locally and remove the android:maxSdkVersion="32" portion of each of those permission requests because we use a VM to build and editing the AndroidManifest manually before packaging was not an option. If I get a better solution to this I may update.

@ath0mas
Copy link
Contributor

ath0mas commented Jul 30, 2023

About @PabbleDabble feedback, please review PR #211 again and merge it? to fix Issue #209.

kemp pushed a commit to kemp/cordova-plugin-media-capture that referenced this pull request Aug 22, 2023
@jmelvin
Copy link

jmelvin commented Sep 10, 2023

@PabbleDabble I also ran into this exact scenario. We include cordova-plugin-camera which requests WRITE_EXTERNAL_STORAGE permissions... without the maxSdkVersion qualifier. AndroidManifest.xml includes the following entries after plugin installs...

cordova-plugin-camera

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

cordova-plugin-media-capture

<uses-permission android:maxSdkVersion="32" android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:maxSdkVersion="32" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The maxSdkVersion qualifier foils the manifest merge process and the build throws up an error...

Task :app:processReleaseMainManifest FAILED
/Users/jmelvin/dev/sizzlescene/repos/mobile/platforms/android/app/src/main/AndroidManifest.xml:47:5-108 Error:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:47:5-108 duplicated with element declared at AndroidManifest.xml:26:5-81

From a pending PR, the temporary workaround is to manually remove the maxSdkVersion qualifier before the cordova build. See SO post I made before seeing this comment...

https://stackoverflow.com/questions/77074389/duplicate-write-external-storage-permissions-in-androidmanifest-using-cordova-12

@ath0mas
Copy link
Contributor

ath0mas commented Sep 10, 2023

Except from fixing the merge process, a proper solution may be to have this maxSdk attribute identically set on both sides? And so to have a PR for the camera plugin and to make it be released soon.

@jmelvin
Copy link

jmelvin commented Sep 10, 2023

@ath0mas Indeed, adding the maxSdk qualifier to the camera plugin entry would resolve the merge problem. However, is that the correct end result for READ/WRITE_EXTERNAL_STORAGE permission? I'm not an expert in the permissions minefield.

Or, does API 33+ just safely ignore the permissions and the maxSdk qualifier is not required?

I can temporarily script either solution before the build.

@ath0mas
Copy link
Contributor

ath0mas commented Sep 10, 2023

In API 33 these two permissions are ineffective when required from the code, so plugins are moving to conditionally calling these and thus the use of maxSdkVersion is a follow-up for the Manifest part.

Better to add it into all applicable plugins, and make the corresponding code changes, even if not having it at all would still work but be possibly reported as incorrect.

@breautek
Copy link
Contributor

@PabbleDabble I also ran into this exact scenario. We include cordova-plugin-camera which requests WRITE_EXTERNAL_STORAGE permissions... without the maxSdkVersion qualifier. AndroidManifest.xml includes the following entries after plugin installs...

cordova-plugin-camera

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

cordova-plugin-media-capture

<uses-permission android:maxSdkVersion="32" android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:maxSdkVersion="32" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The maxSdkVersion qualifier foils the manifest merge process and the build throws up an error...

Task :app:processReleaseMainManifest FAILED
/Users/jmelvin/dev/sizzlescene/repos/mobile/platforms/android/app/src/main/AndroidManifest.xml:47:5-108 Error:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:47:5-108 duplicated with element declared at AndroidManifest.xml:26:5-81

From a pending PR, the temporary workaround is to manually remove the maxSdkVersion qualifier before the cordova build. See SO post I made before seeing this comment...

https://stackoverflow.com/questions/77074389/duplicate-write-external-storage-permissions-in-androidmanifest-using-cordova-12

I posted an answer on SO, but cross-posting here, I have a gist that will clean extra WRITE_EXTERNAL_STORAGE permissions. It can be used as a after_prepare hook:

https://gist.github.com/breautek/bd157b8598f9a816f2ec0d45e3d932c8

A more detailed answer on that topic can be found at https://stackoverflow.com/a/77078295/4685664

davidofwatkins pushed a commit to zenput/cordova-plugin-media-capture that referenced this pull request Oct 25, 2023
* Replace READ_EXTERNAL_STORAGE permission with READ_MEDIA_AUDIO, READ_MEDIA_VIDEO and READ_MEDIA_IMAGES
* Fix READ_MEDIA_* permission on older SDKs
* Do not request new permissions on older SDKs as they do not support
davidofwatkins added a commit to zenput/cordova-plugin-media-capture that referenced this pull request Oct 25, 2023
* feat(android)!: support API 33+ permissions (apache#262)

* Replace READ_EXTERNAL_STORAGE permission with READ_MEDIA_AUDIO, READ_MEDIA_VIDEO and READ_MEDIA_IMAGES
* Fix READ_MEDIA_* permission on older SDKs
* Do not request new permissions on older SDKs as they do not support

* Bump version

---------

Co-authored-by: ochakov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants