很久之前写的一个流程文档,从上层界面一直调用到内核的过程,最近同事跟我要,我看了下又在整理了下,纯属个人分析(不过都运行验证过),不对的请大牛指出
涉及代码;
./packages/apps/DeskClock/src/com/android/deskclock/Alarms.java
./frameworks/base/core/java/android/app/AlarmManager.java
./frameworks/base/services/java/com/android/server/AlarmManagerService.java
./frameworks/base/services/jni/com_android_server_AlarmManagerService.cpp
./kernel/kernel/drivers/rtc/alarm-dev.c
./kernel/kernel/include/linux/android_alarm.h
./kernel/kernel/drivers/rtc/alarm.c
./kernel/kernel/drivers/rtc/interface.c
./kernel/kernel/drivers/rtc/rtc-pcf8563.c
./packages/apps/DeskClock/src/com/android/deskclock/AlarmReceiver.java
./kernel/arch/arm/configs/mmp2_android_defconfig
./kernel/kernel/kernel/.config
点击Clock 应用程序,然后设置新闹钟,会调到 Alarms.java 里面的
public static long setAlarm(Context context, Alarm alarm) {
....
setNextAlert(context);
....
}
然后这里面也会调用到
public static void setNextAlert(final Context context) {
if (!enableSnoozeAlert(context)) {
Alarm alarm = calculateNextAlert(context); //new 一个新的alarm
if (alarm != null) {
enableAlert(context, alarm, alarm.time);
} else {
disableAlert(context);
}
}
}
然后继续调用到
private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) {
.......
am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); //这里是RTC_WAKEUP, 这就保证了即使系统睡眠了,都能唤醒,闹钟工作(android平台关机闹钟好像不行)
.....
}
然后就调用到了AlarmManager.java 里面方法
public void set(int type, long triggerAtTime, PendingIntent operation) {
try {
mService.set(type, triggerAtTime, operation);
} catch (RemoteException ex) {
}
}
然后就调用到了AlarmManagerService.java 里面方法
public void set(int type, long triggerAtTime, PendingIntent operation) {
setRepeating(type, triggerAtTime, 0, operation);
}
然后继续调用
public void setRepeating(int type, long triggerAtTime,