inotify in android

android_util_FileObserver.cpp  uses inotify to notice the changes of appointed files , and report these changes to FileObserver.


android_os_fileobserver_init()  call inotify_init  to create an inotify instance.  a file descriptor is returned to the caller,

the caller will pass it  in android_os_fileobserver_startWatching, android_os_fileobserver_stopWatching etc. functions.



static jint android_os_fileobserver_startWatching(JNIEnv* env, jobject object, jint fd, jstring pathString, jint mask): 


The function call inotify _add_watch(fd, pathname, mask)  to  watch the inode pointed to by pathname.

inotify _add_watch returns a unique watch descriptor to the inode pointed by the pathname.

notes: the parameter fd is a file descriptor created by  android_os_fileobserver_init,  inotify instance.


static void android_os_fileobserver_stopWatching(JNIEnv* env, jobject object, jint fd, jint wfd):

the function call inotify_rm_watch to cancel a watch on the watch descriptor wfd in an inotify instance appointed by  fd .


static void android_os_fileobserver_observe(JNIEnv* env, jobject object, jint fd):


This function  enters into a dead loop, it  continously read event information from the  inotify instance appointed by fd.

The function do not return unless encounter an error when reading and the error is not EINTR.

after read events, the events is splited to single event, then call method_onEvent( it is a global variant be metioned later)  to send the event to FileObserver.



int register_android_os_FileObserver(JNIEnv* env):

this funtion will get method id of    "android/os/FileObserver$ObserverThread/onEvent",

and save the method id in method_onEvent,

and register all methods to androidruntime metioned above .

from what the function do , we should guess the function is called very early, 

in fact the function's address  is declared in array  gRegJNI[] (static const RegJNIRec ),

each gRegJNI's element  is called at androidRuntime's startup. (in function startreg)





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值