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) {}