notify-rs/notify

Not working on aarch64/android

Closed this issue · 13 comments

Not working on my android device :-(
It didn't crash or anything, the thing is there are no incoming events
I tried multiple file explorer and tried delete/rename/create and nothing has happened.
It worked really well my desktop but for android it simply won't work

Information:-

  • OS: Android
  • Environment: Termux
  • Architecture: aarch64
  • lib version: v5.0.0
  • source code: here

You code specifically does not print any errors and simply ends the loop returning ok. Could you add something that at least prints errors ?

Regarding android: I know that android does not really like to give full directory access, are you sure that you have permissions to watch those files & folder and that it's possible to use the inotify API on android?

Here is an example for using the FileObserver from the android SDK (which also uses inotify), together with the required permissions
https://stackoverflow.com/a/51062416

It specifically requires you to ask for the full-file-access permissions via system callbacks, showing a popup the user has to agree, which then gives your application feedback about whether it was granted that permission.

You may already have tried all of this, but I'm just trying to make sure we're on the same page and that you're not just simply missing permissions. I've been bitten by this a few times (unrelated to notify).

You code specifically does not print any errors and simply ends the loop returning ok. Could you add something that at least prints errors ?

Oops, I'll match the errors if any and let you know

Regarding android: I know that android does not really like to give full directory access, are you sure that you have permissions to watch those files & folder and that it's possible to use the inotify API on android?

I can rwx them easily via shell I totally sure that I've give it the needed permissions

Here is an example for using the FileObserver from the android SDK (which also uses inotify), together with the required permissions
https://stackoverflow.com/a/51062416
It specifically requires you to ask for the full-file-access permissions via an system callback that shows a popup.
You may already have tried all of this, but I'm just trying to make sure we're on the same page and that you're not just simply missing permissions. I've been bitten by this a few times (unrelated to notify).

I really don't know much about it. I just complied my source code to run within termux and runs well except this library

Ah yeah termux is kinda special (and AFAIK increasingly hard to get fully working in modern androids), you have to lookup whether it is possible in termux to use inotify and probably ask them.

Read access is a good start but sadly doesn't say much.

My android is 10 which is kinda old, isn't it?

You could fallback to the PollWatcher for now in android, using for example the #[cfg(target_os = "android")] conditional compilation.

You code specifically does not print any errors and simply ends the loop returning ok. Could you add something that at least prints errors ?

      while let Ok(event) = rx.recv() {
            let event = match event {
                Ok(e) => e,
                Err(err) => {
                    println!("Notify Error: {:?}", err);
                    continue;
                }
            };

            println!("{:?}", event);

After changeing a few lines of code there are no errors and not even regular events.
I'll try the PollWatcher tomorrow and let you know the updates, thanks <3

isn't the RecommendedWatcher lib.rs - 360L may already picked me PollWatcher? the target build is android which is not mentioned in the code so it should be PollWatcher by default for my case

Good catch, you can verify this is actually the case by looking what kind of watcher you're looking at.

as I expected the RecommendedWatcher was PollWatcher.
Anyway I think the problem comes from termux I changed the syncing path to the home directory of termux and now it works.

But the events are missing information

  • EventKind::Create always contain CreateKind::Any
  • EventKind::Remove always contain RemoveKind::Any
  • EventKind::Modify always contain Metadata(WriteTime)

And others wasn't even working

  • Renaming file will execute Create(Any) twice and then Remove(Any) twice

But the events are missing information

That's to be expected. PollWatcher can't detect anything else.

Renaming file will execute Create(Any) twice and then Remove(Any) twice

Not sure about that one. But PollWatcher is essentially just checking for changes in the amount of files and their changed-timestamp as reported by the filesystem.

Renaming file will execute Create(Any) twice and then Remove(Any) twice

Not sure about that one. But PollWatcher is essentially just checking for changes in the amount of files and their changed-timestamp as reported by the filesystem.

Solved, I refactored some of my code and now works really well. 👍