Bug 18609 - Android FileObserver invalid mask
Summary: Android FileObserver invalid mask
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.13.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2014-03-27 05:54 UTC by michele.scandura
Modified: 2014-06-04 14:04 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

FileObserver implementation and sample usage (1.25 KB, text/plain)
2014-03-27 05:54 UTC, michele.scandura

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description michele.scandura 2014-03-27 05:54:59 UTC
Created attachment 6418 [details]
FileObserver implementation and sample usage

I'm having a few issues using the native FileObserver

- FileObserverEvents is not marked as [Flags]. Not a major issue, as you can still do the binary operations, but a bit annoying.

- The FileObserver does not recognize the flags I'm passing, and returns significantly different values. 
  Example: the following mask FileObserverEvents.Create | FileObserverEvents.Delete | FileObserverEvents.MovedFrom | FileObserverEvents.MovedTo returns 960 which looks correct, but the FileObserver doesn't show anything. When I look at the return values without using the mask I'm seeing values like 1073741840, 1073741856, 1073741840. The last 3 figures look correct, but everything else doesn't make any sense to me.
Comment 1 Atsushi Eno 2014-04-22 07:11:36 UTC
I have added [Flags] attribute on FileObserverEvents enum for monodroid 4.14. Thanks for the report.

Those returned values do make sense. You have to use logical calculation with the returned values.

1073741840 = 40000010 means FileObserver.CLOSE_NOWRITE (0x10)
1073741856 = 40000020 means FileObserver.OPEN (0x20)

I found some example usage on this API here:

[master 9a085bd]
Comment 2 michele.scandura 2014-04-22 09:41:19 UTC
Thanks, I didn't think that the values were in hex...
Comment 3 michele.scandura 2014-04-28 05:37:12 UTC
Thanks for the link.
After further investigation, I found this link http://rswiki.csie.org/lxr/http/source/include/linux/inotify.h?a=m68k#L45 , which shows a few additional flags.
The interesting one is 
#define IN_ISDIR                0x40000000      /* event occurred against dir */
which is not exposed by the Android docs, but it's actually been used by Android.
The values I got (0x40000020) where against a folder, which now makes sense.
How would you manage this? Should I implement this check in my library, or is something that Xamarin.Android could pick up?
Comment 4 Atsushi Eno 2014-04-28 09:52:02 UTC
That seems to be non-public API, so we wouldn't bind it. There should be reason that Google does not expose it i.e. it is not supposed by developers in their code. You should be able to write code without it, like using logical operations mentioned earlier.
Comment 5 Udham Singh 2014-06-04 14:04:25 UTC
To verify this issue I have checked the "Assemble Browser" and observed that a [Flags] attribute is added on FileObserverEvents enum. But I am not sure how to verify the values of following mask FileObserverEvents.Create |
FileObserverEvents.Delete | FileObserverEvents.MovedFrom |
FileObserverEvents.MovedTo .

Screencast : http://www.screencast.com/t/EI1MawskXN

Environment Info :

=== Xamarin Studio ===

Version 4.2.5 (build 0)
Installation UUID: 312d4e9a-339c-433f-a27b-88ce0777af8f
	Microsoft .NET 4.0.30319.34014
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.25

=== Xamarin.Android ===

Version: 4.15.0 (Enterprise Edition)
Android SDK: D:\SDK\AndroidSDK
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_31
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode)

=== Build Information ===

Release ID: 402050000
Git revision: 95ac543f224a70960a9ab71e24ce341eb87de06f
Build date: 2014-05-02 12:59:15-04
Xamarin addins: b81285ac0156281956135adb96685f98922893a1

=== Operating System ===

Windows 6.2.9200.0 (64-bit)