Ah. I also found that the AAssetManager reference is used incorrectly; it's being queried and added a reference on each open stream, but these references are never deleted.
According to
this page you got to call DeleteGlobalRef on objects that were received with the NewGlobalRef.
This may also be seen in the SDL2 sources, where it initializes AAssetManager only once and also has a function that releases its reference.
I don't know which yet, but we need to either have similar global create/delete functions in the Common, and explicitly call them on engine start/quit, or alternatively make AAssetManager owned by the platform driver and somehow call it from the common lib.
EDIT: I did this for now:
https://github.com/ivan-mogilko/ags-refactoring/commits/android--filefuncs2where platform driver calls initialization in Common. Alternatively, can make platform driver contain AAssetmanager's reference, and only pass it into the Common.
Will investigate the AAsset functions you linked now, hopefully it's not too complicated to make it work consistently with file funcs.
... although i keep wondering why we are not using SDL2 directly, as it seems to be doing all this already. Maybe this requires moving to use its RW Ops? In which case I'd delay such transition until next version.
EDIT 2: After more thinking, I realized there's a way and sense to also simplify AGS AssetManager further, and do something similar to your proposal, where it opens a stream right away, so to avoid extra steps.
CMake sets case insensitiveness forced here for Linux (and this is the only place):
https://github.com/adventuregamestudio/ags/blob/9887c180e10175bf8d67908d219d711f16088924/Common/CMakeLists.txt#L198
This is not currently set for Android. Is this flag needed beyond backward compatibility?
This is a good question. Yes, if Android is case sensitive system then it should also use case insensitive file handling, at least in 3.* branch, which is supposed to be a backward compatible, otherwise some existing games may fail on Android with the AGS player/launcher.
Also, in theory, because the engine suppose to work same way on case sensitive and insensitive systems, it may be necessary in general; for example someone has a file with lowercase name in the game, but calls it uppercase in script. That script will work on Windows, but not on Linux.
That is, unless we explicitly state that we hold no responsibility for such mistakes.
On the other hand, this case-insensitive handling currently only works when searching for existing files, but not when e.g. writing a file. If the game script writes two files which differ only by letter case, both of these may be opened on Linux, but not on Windows, where you won't be even able to create second one without overwriting first.
But this is also a question of how engine is supposed to work by design. I recall there have been already a small discussion some time in the past, but I don't remember in which forum topic. I believe for ags4 it's important to make a definitive decision on this.