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 aunique 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)





更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 临摹应该从哪里开始?绘画中的临摹技巧
  2. tensorflow-cpu/gpu速度 cpu(3分钟)vs gpu(4
  3. php中Workerman框架实例讲解
  4. PHP优化教程之解决嵌套问题
  5. php中unable to fork报错简单解决方法
  6. PHP超级全局变量、魔术变量和魔术函数汇
  7. Node 模块
  8. 怎么画好人体动态?漫画人体结构绘画入门
  9. 事件,条件,列表渲染,计算属性与侦听器,组件之
  10. vue常用术语与常用指令