rtc关机闹钟6 AlarmManagerService研究

这个是

    private void setLocked(int type, long when) {

        if (mNativeData != 0) {
            // The kernel never triggers alarms with negative wakeup times
            
// so we ensure they are positive.
            long alarmSeconds, alarmNanoseconds;
            if (when < 0) {
                alarmSeconds = 0;
                alarmNanoseconds = 0;
            } else {
                alarmSeconds = when / 1000;
                alarmNanoseconds = (when % 1000) * 1000 * 1000;
            }
            
            set(mNativeData, type, alarmSeconds, alarmNanoseconds);
        } else {
            Message msg = Message.obtain();
            msg.what = ALARM_EVENT;
            
            mHandler.removeMessages(ALARM_EVENT);
            mHandler.sendMessageAtTime(msg, when);
        }

    }

 

 

 setLocked()内部会调用native函数set():

[java] view plain copy
  1. private native void set(int fd, int type, long seconds, long nanoseconds);  


重新设置“实体闹钟”的激发时间。这个函数内部会调用ioctl()和底层打交道。具体代码可参考frameworks/base/services/jni/com_android_server_AlarmManagerService.cpp文件:

[java] view plain copy
  1. static void android_server_AlarmManagerService_set(JNIEnv* env, jobject obj, jint fd,   
  2. jint type, jlong seconds, jlong nanoseconds)  
  3. {  
  4.     struct timespec ts;  
  5.     ts.tv_sec = seconds;  
  6.     ts.tv_nsec = nanoseconds;  
  7.   
  8.     int result = ioctl(fd, ANDROID_ALARM_SET(type), &ts);  
  9.     if (result < 0)  
  10.     {  
  11.         ALOGE("Unable to set alarm to %lld.%09lld: %s\n", seconds, nanoseconds, strerror(errno));  
  12.     }  
  13. }  

 

posted on 2016-03-10 11:15  木花猫  阅读(523)  评论(0编辑  收藏  举报

导航