AlarmManager

1.  文件 frameworks/base/core/java/android/app/AlarmManager.java

     //设置

     public void set(int type, long triggerAtTime, PendingIntent operation) {

         try {

             mService.set(type, triggerAtTime, operation);

         } catch (RemoteExcepton ex) {

         }

     }

 

2. 文件 frameworks/base/services/java/com/android/server/AlarmManagerService.java

    //设置

    public void set(int type, long triggerAtTime, PendingIntent operation) {

         setRepeating(type, triggerAtTime, 0, operation);

    }

   

    public void setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation) {

        if (operation == null) {

            Log.w("chenlong", "alarmManager/set/setRepeating ignored because of there is no intent");

            return;

        }

   

        sychronized(mlock) {

            Alarm alarm = new Alarm();

            alarm.type = type;

            alarm.when = triggerAtTime;

            alarm.repeatInterval = interval;

            alarm.operation = operation;

 

            //Remove this alarm if already scheduled.

            removeLocked(operation);

 

           int index = addAlarmLocked(alarm);

           if(index == 0) {

               setLocked(alarm);

           }

        }

    }

 

    //等待

    private class AlarmThread extends Thread {}

 

3. 文件 framewoks/base/services/jni/com_android_server_AlarmManagerService.cpp

    static void android_server_AlarmManagerService_set(JNIEnv* env, jobject obj, jint fd, jint type, jlong seconds, jlong nanosceconds) {

         #if HAVE_ANDROID_OS

         struct timespec ts;

         ts.tv_sec = seconds;

         ts.tv_nsec = nanoseconds;

        

         int result = ioctl(fd, ANDROID_ALARM_SET(type), &ts);

         if(result < 0) {

             LOGE("unable set alarm to %lld.%09lld: %s\n", seconds, nanoseconds, strerror(errno));

         }

         #endif

    }

    static jint android_server_AlarmManagerService_waitForAlarm(JNIEnv* env, jobject obj, jint fd) {

        #if HAVE_ANDROID_OS

        int result = 0;

       

         do {

             result = ioctl(fd, ANDROID_ALARM_WAIT);

         } while (result < 0 && errno == EINTR);

 

        if(result < 0) {

            LOGE("unable to wait on alarm: %s\n", strerror(errno));

           return0;

        }

 

        return result;

        #endif

    }

 

4. 文件 kernel/drivers/rtc/alarm-dev.c

    static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值