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

Can't write to /data/local/tmp on Android API >= 30 #69

Closed
Tracked by #3243
guillemcordoba opened this issue Oct 31, 2023 · 5 comments
Closed
Tracked by #3243

Can't write to /data/local/tmp on Android API >= 30 #69

guillemcordoba opened this issue Oct 31, 2023 · 5 comments

Comments

@guillemcordoba
Copy link
Contributor

This is more my way of explaining everything I've learned in my latest explorations trying to run holochain in android, than an issue in this library, although there is an error that I get in my Redmi Note 7 when running it.

So, it seems that from Android 11 (API level 30) on, Android tightened security around file system reads and writes, and doesn't allow applications to just write to /data/local/tmp. This is the error I get when running tx5 on android, I get it from this line.

I was trying to override the result for this line by forking dirs-rs and redirecting the get_local_dir call to app_dirs2 get_app_dir, but I had no luck with this, it complained that the file didn't exist in this line (are we missing a .create(true) in that line??). I tried to add the .create(true), but then I bumped into another error: InvalidArgument, from that same function, but not sure which line...

After this, I discovered this issue, and that worked! Seems that by setting the TMPDIR env var, we can change where the tempdir crate creates new files. So, I can now compile and run holochain in android, by adding this workaround to my initialization code:

    let dir = app_dirs2::app_root(
        app_dirs2::AppDataType::UserCache,
        &app_dirs2::AppInfo {
            name: "studio.darksoil.rostangatest",
            author: "darksoil.studio",
        },
    )?;
    std::env::set_var("TMPDIR", dir);

After this, no more permission denied error, and networking works! I am able to communicate with a holochain node running in my laptop, and fetches for records work correctly! So this is really exciting.

Now, what needs to happen with this issue and tx5, I am not sure. Maybe tx5 could itself incorporate my workaround? Not sure, but right now I'm not blocked by tx5, and the workaround is sufficiently simple and clean that it doesn't bother me at all. Maybe in the future others will bump into it though.

Thanks for the hard work! @neonphog @abe-njama

@guillemcordoba
Copy link
Contributor Author

guillemcordoba commented Oct 31, 2023

I spoke too soon. I am getting an error still even with the workaround:

10-31 15:24:52.852 16603 16653 I RustStdoutStderr:
10-31 15:24:52.852 16603 16653 I RustStdoutStderr: ###HOLOCHAIN_SETUP###
10-31 15:24:52.852 16603 16653 I RustStdoutStderr: ###ADMIN_PORT:24972###
10-31 15:24:52.852 16603 16653 I RustStdoutStderr: ###HOLOCHAIN_SETUP_END###
10-31 15:24:52.857 16603 16653 I RustStdoutStderr: FATAL PANIC PanicInfo {
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:     payload: Any { .. },
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:     message: Some(
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:         failed to get data_local_dir,
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:     ),
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:     location: Location {
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:         file: "/home/guillem/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tx5-core-0.0.2-alpha/src/file_check.rs",
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:         line: 30,
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:         col: 32,
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:     },
10-31 15:24:52.857 16603 16653 I RustStdoutStderr:     can_unwind: true,
10-31 15:24:52.857 16603 16653 I RustStdoutStderr: }
10-31 15:24:52.857 16603 16653 I RustStdoutStderr: thread 'tokio-runtime-worker' panicked at 'failed to get data_local_dir', /home/guillem/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tx5-core-0.0.2-alpha/src/file_check.rs:30:32

So I have to still keep my fork of dirs-rs to point to some folder in android, even if it then fails and needs to actually go through with the temp file.

So yeah I would consider this a bug, in that in Android API level 33 dirs::get_local_dir returns None and tx5 is just doing an expect() on it. Maybe a better if/else handling of that option would help, or even better, migrate to a library like app_dirs2 that supports android (AFAIU dirs-rs doesn't).

Copy link

github-actions bot commented Dec 2, 2023

This item has been open for 30 days with no activity.

@github-actions github-actions bot added the stale This item has been open for 30 days with no activity. label Dec 2, 2023
@neonphog neonphog removed the stale This item has been open for 30 days with no activity. label Dec 4, 2023
Copy link

github-actions bot commented Jan 4, 2024

This item has been open for 30 days with no activity.

@github-actions github-actions bot added the stale This item has been open for 30 days with no activity. label Jan 4, 2024
@neonphog neonphog removed the stale This item has been open for 30 days with no activity. label Jan 4, 2024
Copy link

github-actions bot commented Feb 4, 2024

This item has been open for 30 days with no activity.

@github-actions github-actions bot added the stale This item has been open for 30 days with no activity. label Feb 4, 2024
@neonphog neonphog removed the stale This item has been open for 30 days with no activity. label Feb 5, 2024
@neonphog
Copy link
Collaborator

neonphog commented Feb 6, 2024

This should have been addressed with #77 and subsequently holochain/holochain#3287. Note that it is only planned to be included in holochain develop (0.3) because it is a breaking protocol change.

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

No branches or pull requests

2 participants