Android AlarmClock 鬧鐘應用 簡單分析

來源:互聯網
上載者:User

作者:徐建祥(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||

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.