openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
753 stars 366 forks source link

Add support for `maxSdkVersion` attribute in `permission` element. #1812

Open MAJigsaw77 opened 2 months ago

MAJigsaw77 commented 2 months ago

There's currently no support for having a permission with a maxSdkVersion attribute, which could be useful to limit permissions to specific Android versions, ensuring compatibility.

player-03 commented 2 months ago

Interesting. I didn't know that was a thing.

The problem is we don't have anywhere to store that data. If you typed <config:android permission="android.permission.WRITE_EXTERNAL_STORAGE" maxSdkVersion="18" />, you'd be setting two entirely separate config values. Fortunately, maxSdkVersion doesn't do anything, but if it did, it would limit your whole app to <= SDK 18.

Permissions are stored as an Array<String>. Add another string to the array, that's another permission. There's nowhere to store an integer in that array, and Haxe's templates aren't powerful enough to handle two side-by-side arrays.

It is possible to do a bit of string injection, though it isn't pretty: <config:android permission='android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18' />. Not recommended.

I guess we could add a entire separate attribute, like <config:android permission-max-sdk-18="android.permission.WRITE_EXTERNAL_STORAGE" />. And that would work for SDK 18, but if you wanted some other SDK, we'd have to go back and add a whole new attribute for that.