-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[3.x] Add full support for Android scoped storage. #51815
[3.x] Add full support for Android scoped storage. #51815
Conversation
4e87aa5
to
06828a7
Compare
Does this allow read/write external access on Android 11 equivalent to Android 10 "use_legacy_storage" option? |
Yes it should. Granted this still needs to go through testing in order to validate the behavior. |
Ok, I'll test it today, thanks! |
Gradle 7.2Build time: 2021-08-17 09:59:03 UTC Kotlin: 1.5.21 I'm getting this warning: Task :java:lib:compileReleaseKotlin Which version of java should I be using? |
@HEAVYPOLY Your java version is fine; the deprecation warnings are expected, and shouldn't affect the build process. |
It built successfully, but program crashes after splash screen :/ This is on Android 10 device (Samsung note 9) also see this in build:
|
@HEAVYPOLY Can you send me the crash stack traces, I'll take a look. |
https://pastebin.com/CkPinEr6 Also just tried with a friend's Android 11 device and got the crash after splash screen (Samsung note 20) |
07ba04a
to
182c35b
Compare
@HEAVYPOLY I fixed the issues causing the crash and rebased the PR. I did a quick test, and starting and loading a Godot app seems to work as expected. I still need to fully validate scoped storage, and I'm working to complete that later this week. |
@m4gr3d thanks! Look forward to testing, this is huge! |
Please let me know when this can be tested. I am excited to test this as well. |
729320c
to
43acc60
Compare
@m4gr3d The project I am using for a test is a Mono project. Would it be possible to get a mono editor build with the export templates to test this? |
43acc60
to
1bd5bda
Compare
1bd5bda
to
603d3d7
Compare
platform/android/java/lib/src/org/godotengine/godot/io/directory/AssetsDirectoryAccess.kt
Outdated
Show resolved
Hide resolved
603d3d7
to
e3bd05f
Compare
Needs a rebase after cherry-pick of #62297 (which in retrospective could also have been merged only for |
I made a test build with the official buildsystem upgraded to use NDK r23 (#61691) and including this PR to add full support for Android scoped storage. Could you test @HEAVYPOLY @ondesic @m4gr3d? There's both Android templates and the desktop editor builds as you need the same version to export. If I get some confirmations that this work as intended quickly, then we should be able to include it in 3.5-stable too (first in 3.5 RC 5). |
@m4gr3d I've got a report that audio doesn't seem to work in my test build, while it works in 3.5 RC 4: https://twitter.com/MagellanicGames/status/1540251677772730368 |
e3bd05f
to
b00c992
Compare
Hi, I was asked to provide a repro for the audio bug. I've tested this in the build @akien-mga provided and it will play the sound effect upon pressing the button on desktop but not on the Android device. The android device is a Samsung Galaxy s6, running Android v7.0. I found the bug in my game as the code is used for triggering effects for all manner of entites, whether they be UI, enemies etc. Apologies that it's just smashed together, it is ripped from my production code and didn't have long to get it done. Hope it is of use. |
I can confirm the regression with @MagellanicGames' reproduction project. The It seems like it boils down to func dir_contents(path):
var contents = []
var dir = Directory.new()
if dir.open(path) == OK: # Fails here on Android with this PR.
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
print("Found directory: " + file_name)
else:
print("Found file: " + file_name)
contents.append(file_name)
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
return contents
func _ready():
# Should find ".." and "." directories, "hello" and "world" files.
# On Android, fails opening the folder so doesn't find anything.
$TextEdit.text = str(dir_contents("res://somedir")) |
b00c992
to
d6efa13
Compare
@akien-mga @MagellanicGames Thanks for the repro instructions! I found and fixed the issue, so this should be good to go now! |
d6efa13
to
15b59e4
Compare
This was done by refactoring directory and file access handling for the Android platform so that any general filesystem access type go through the Android layer. This allows us to validate whether the access is unrestricted, or whether it falls under scoped storage and thus act appropriately.
15b59e4
to
24e3b3b
Compare
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.
Looks great to me!
Tested on Poco F1 (MIUI 12 based on Android 10), I could read from res://
, write to and read from user://
, and write to and read from Documents (using Manage Documents
). Didn't test external storage.
Thanks! |
Just tested my mono project and it is crashing. Says "Permission to access file: /storage/emulated/0/Documents/Data/Custom.txt is denied" Also, I changed my Target SDK to 32 to allow RC_5 to run. I will try to create a test |
Here are my findings with the included test mono project.
side note: I even tried to copy the Test.txt file manually to the Test folder. Pressing the button in the app should read the content but it still won't work. |
@ondesic To ensure this is properly captured and addressed, you should create a new issue. |
This was done by refactoring directory and file access handling for the Android platform so that any general filesystem access type go through the Android layer.
This allows us to validate whether the access is unrestricted, or whether it falls under scoped storage and thus act appropriately.
Fix #38913
Fix #45467
Fix #48636