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. }  
  • 相关阅读:
    html中script标签的使用方法
    css关于浮动的高度塌陷
    canvas用数组方式做出下雨效果
    canvas简易画板。
    html5新标签
    闭包的意义及用法
    字符串的添加方法
    js几种数组遍历方法.
    简易网页打卡页面.
    回忆继承多态
  • 原文地址:https://www.cnblogs.com/muhuacat/p/5261100.html
Copyright © 2011-2022 走看看