ARM-software / devlib

Library for interaction with and instrumentation of remote devices.
Apache License 2.0
47 stars 78 forks source link

target: Add persistent_data_path to AndroidTarget #622

Closed mrkajetanp closed 1 year ago

mrkajetanp commented 1 year ago

Some apps, such as Unity-based applications, can store some files in their 'persistent data path' which is usually under '/storage/emulated/0/Android/data'. Add a handle to easily access the path within AndroidTarget in the same way as package_data_directory currently is accessible.

douglas-raillard-arm commented 1 year ago

All I can find when looking for "persistent data path" is Unity, are we sure we want to add some app-specific concepts in AndroidTarget ? Unless there is an android API doc I missed. Maybe there is a related property that could just be queried (adb shell getprop) ?

mrkajetanp commented 1 year ago

All I can find when looking for "persistent data path" is Unity, are we sure we want to add some app-specific concepts in AndroidTarget ?

That's the only place I found the name itself used but the path is definitely used by other apps as well here and there. It's analogous to the /data/data one but does not require root access. I'm not sure Android has any 'official' name for it which is why "persistent data path" is what I went with but if we have any better names then that works just as well I think.

douglas-raillard-arm commented 1 year ago

That makes sense, does Android allow querying for that path in any way or do apps have to know it in advance ?

mrkajetanp commented 1 year ago

Ah apparently it can, Android's Context has a method for getting the application's data directory:

https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)

We could always rename this from persistent_data_path to external_files_path or dir?

marcbonnici commented 1 year ago

Looking into this more it looks like the persistent_data_path or external_files_path term actually refers a specific applications data path. From [1].

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.

So we would be providing the root of this directory and users would need to manually join the package name to this path.

IIUC looking at how this path is generated [2] it uses the external directory function (which we expose with external_storage) along with the constant sub-path Android/data. Therefore I think we can avoid adding a new parameter for this and instead add a convenience property with the equivalent of target.path.join(target.external_storage', 'Android', 'data').

As for the name perhaps to keep inline with the android terminology we could expose something like external_storage_app_dir? (Open to better naming suggestions).

What do you think?

[1] https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String) [2] https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/Environment.java#225

mrkajetanp commented 1 year ago

instead add a convenience property

Ah yeah that makes a lot of sense, /sdcard is a symlink to /storage/emulated/0 so that works. This also allows us to do it exclusively here instead of needing a separate WA PR so that's a win.

What do you think?

The name seems fine to me. I've updated this PR accordingly and will close the WA one.

mrkajetanp commented 1 year ago

Updated, sorry for the delay..