zoukankan      html  css  js  c++  java
  • 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 ", seconds, nanoseconds, strerror(errno));  
    12.     }  
    13. }  
  • 相关阅读:
    MySQL for mac使用记录
    Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
    前端学数据库之基础操作
    前端CSS预处理器Sass
    ionic + cordova+angularJs 搭建的H5 App完整版总结
    HTML5的新语义化的标签
    angularJS- $http请求
    SEO优化---学会建立高转化率的网站关键词库
    当AngularJS POST方法碰上PHP
    从一个程序员的角度看——微信小应用
  • 原文地址:https://www.cnblogs.com/muhuacat/p/5261100.html
Copyright © 2011-2022 走看看