随笔-1  评论-68  文章-98  trackbacks-0
作者:徐建祥(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||
posted on 2010-01-06 17:27 Xu Jianxiang 阅读(3925) 评论(0)  编辑  收藏 所属分类: Android

只有注册用户登录后才能发表评论。


网站导航: