android闹钟功能报告_第1页
android闹钟功能报告_第2页
android闹钟功能报告_第3页
android闹钟功能报告_第4页
android闹钟功能报告_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ADROID 2 1 架构解析架构解析 闹钟闹钟 分析透彻 有点基础都能看懂 1 设置定时时间设置定时时间 文件 packages apps alarmclock src com android alarmclock Alarms java private static void enableAlert Context context final Alarm alarm final long atTimeInMillis AlarmManager am AlarmManager context getSystemService Context ALARM SERVICE am set AlarmManager RTC WAKEUP atTimeInMillis sender 由闹钟管理器设置定时时间 2 闹钟管理器闹钟管理器 2 1 定时设置定时设置 文件 frameworks base core java android app AlarmManager java public static final int RTC WAKEUP 0 public static final int RTC 1 public static final int ELAPSED REALTIME WAKEUP 2 public static final int ELAPSED REALTIME 3 AlarmManager IAlarmManager service mService service public void set int type long triggerAtTime PendingIntent operation try mService set type triggerAtTime operation catch RemoteException ex 将 type triggerAtTime operation 等参数转向闹钟管理器服务 3 闹钟管理器服务闹钟管理器服务 文件 frameworks base services java com android server AlarmManagerService java 3 1 定时设置定时设置 public AlarmManagerService Context context mDescriptor init 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 TAG set setRepeating ignored because there is no intent return synchronized 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 if localLOGV Log v TAG set alarm int index addAlarmLocked alarm if index 0 setLocked alarm private void setLocked Alarm alarm if mDescriptor 1 set mDescriptor alarm type alarm when 1000 1000 else Message msg Message obtain msg what ALARM EVENT mHandler removeMessages ALARM EVENT mHandler sendMessageAtTime msg alarm when Init set 为底层操作函数 set mDescriptor alarm type alarm when 1000 1000 由底层来完 成定时设置 3 2 等待计时结束等待计时结束 private class AlarmThread extends Thread public void run while true int result waitForAlarm mDescriptor if result if result if result if result 在服务里采用线程来处理计时结束返回的信息 根据等待计时结束返回的信息触发不同的操 作 4 硬件调用 硬件调用 JNI 机制 机制 文件 frameworks base services jni com android server AlarmManagerService cpp 4 1 定时设置定时设置 static jint android server AlarmManagerService init JNIEnv env jobject obj if HAVE ANDROID OS return open dev alarm O RDWR else return 1 endif static void android server AlarmManagerService close JNIEnv env jobject obj jint fd if HAVE ANDROID OS close fd endif static void android server AlarmManagerService set JNIEnv env jobject obj jint fd jint type jlong nanoseconds if HAVE ANDROID OS struct timespec ts ts tv sec NANOSECONDS TO SECONDS nanoseconds ts tv nsec nanoseconds SECONDS TO NANOSECONDS ts tv sec int result ioctl fd ANDROID ALARM SET type if result 0 LOGE Unable to set alarm to lld s n nanoseconds strerror errno endif 以上函数的绑定如下 init I void android server AlarmManagerService init close I V void android server AlarmManagerService close set IIJ V void android server AlarmManagerService set 由上可知 通过 ioctl 接口 设置定时时间 4 2 等待计时结束等待计时结束 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 if result 0 LOGE Unable to wait on alarm s n strerror errno return 0 return result endif 以上函数的绑定如下 waitForAlarm I I void android server AlarmManagerService waitForAlarm 由上可知 代码阻塞方式等待计时结束或由意外中断结束 4 杂项杂项 4 1 闹钟类型闹钟类型 public static final int ELAPSED REALTIME 当系统进入睡眠状态时 这种类型的闹铃不会唤醒系统 直到系统下次被唤醒才传递它 该闹铃所用的时间是相对时间 是从系统启动后开始计时的 包括睡眠时间 可以通过调用 SystemClock elapsedRealtime 获得 系统值是 3 0 x00000003 public static final int ELAPSED REALTIME WAKEUP 能唤醒系统 用法同 ELAPSED REALTIME 系统值是 2 0 x00000002 public static final int RTC 当系统进入睡眠状态时 这种类型的闹铃不会唤醒系统 直到系统下次被唤醒才传递它 该闹铃所用的时间是绝对时间 所用时间是 UTC 时间 可以通过调用 System currentTimeMillis 获得 系统值是 1 0 x00000001 public static final int RTC WAKEUP 能唤醒系统 用法同 RTC 类型 系统值为 0 0 x00000000 Public static final int POWER OFF WAKEUP 能唤醒系统 它是一种关机闹铃 就是说设备在关机状态下也可以唤醒系统 所以我们把 它称之为关机闹铃 使用方法同 RTC 类型 系统值为 4 0 x00000004 4 2 底层实现底层实现 在 IOCTL 中 ANDROID ALARM SET 0 设置闹钟 在 IOCTL

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论