.
Android 上层界面到内核代码的完整的流程分析,以alarm为例子
很久之前写的一个流程文档,从上层界面一直调用到内核的过程,最近同事跟我要,我看了下又在整理了下,纯属个人分析(不过都运行验证过),不对的请大牛指出。Alarm 调用流程,alarm的流程实现了从上层应用一直到下面driver的调用流程,下面简单阐述:涉及代码;
./packages/apps/DeskClock/src//android/deskclock/Alarms.java ./frameworks/base/core/java/android/app/AlarmManager.java
./frameworks/base/services/java//android/server/AlarmManagerService.java
./frameworks/base/services/jni/_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//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, long interval, PendingIntent operation) { .....
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) Slog.v(TAG, \
专心.