Android AlarmClock 闹钟应用 简单分析

作者:徐建祥(netpirate@gmail.com)
日期:2010/01/06
网址:http://www.anymobile.org

1/ set a alarm clock
1.1 update alarms.db
1.2 update com.android.alarmclock_preferences.xml
1.3 update Settings.System.NEXT_ALARM_FORMATTED for status bar
1.4 set Kernel RTC alarm or send a message if no driver

flow:
com.android.alarmclock.AlarmClock.onCreate() -> SetAlarm.onPreferenceTreeClick() -> SetAlarm.saveAlarm() -> 
Alarm.setAlarm() -> Alarm.setNextAlert() -> Alarm.enableAlert(ALARM_ALERT_ACTION)/saveNextAlarm(Settings.System.NEXT_ALARM_FORMATTED) ->
android.app.AlarmManager.set() -> AlarmManagerService.set() -> AlarmManagerService.setRepeating -> AlarmManagerService.setLocked() ->
android.app.IAlarmManager.set() -> RTC.save()// /dev/alarms

2/ play a clarm clock

flow:
RTC (WAKEUP) -> AlarmReceiver.onReceive(ALARM_ALERT_ACTION) -> AlarmAlert.onCreate() -> 
AlarmAlertWakeLock.acquire()/KeyguardManager.newKeyguardLock().disableKeyguard() -> 
AlarmKlaxon.postPlay() ->  AlarmKlaxon.KillerCallback().onKilled() -> AlarmAlert.dismiss() -> 
AlarmAlertWakeLock.release()/KeyguardManager.newKeyguardLock().reenableKeyguard()

some description:

/**
 * Days of week coded as single int, convenient for DB storage:
 *
 * 0x00:  no day
 * 0x01:  Monday
 * 0x02:  Tuesday
 * 0x04:  Wednesday
 * 0x08:  Thursday
 * 0x10:  Friday
 * 0x20:  Saturday
 * 0x40:  Sunday
 */

/**
 * Alarm type
 *
 * ELAPSED_REALTIME            Alarm time in time since boot, including sleep, This alarm does not wake the device up.
 * ELAPSED_REALTIME_WAKEUP    Alarm time in time since boot, including sleep, This alarm will wake up the device when it goes off.
 * RTC            Alarm time in wall clock time in UTC, This alarm does not wake the device up.
 * RTC_WAKEUP    Alarm time in wall clock time in UTC, This alarm will wake up the device when it goes off.
 */

db example:

# cat /data/data/com.android.alarmclock/shared_prefs/com.android.alarmclock_preferences.xml

1  <? xml version='1.0' encoding='utf-8' standalone='yes'  ?>
2  < map >
3  < string  name ="label" > 警报 </ string >
4  < boolean  name ="vibrate"  value ="true"   />
5  < boolean  name ="on"  value ="true"   />
6  </ map >

# sqlite3 /data/data/com.android.alarmclock/databases/alarms.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
alarms            android_metadata
sqlite> .schema alarms
CREATE TABLE alarms (_id INTEGER PRIMARY KEY,hour INTEGER, minutes INTEGER, daysofweek INTEGER, alarmtime INTEGER, enabled INTEGER, vibrate INTEGER, message TEXT, alert TEXT);
sqlite> select * from alarms;
1|7|0|127|0|0|1||
2|8|30|31|1262766600000|1|1|警报|content://media/internal/audio/media/21
3|9|0|0|0|0|1||

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值