資源描述:
《android鬧鐘功能報告》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、ADROID2.1架構(gòu)解析——鬧鐘分析透徹,有點(diǎn)基礎(chǔ)都能看懂!1設(shè)置定時時間文件:packages/apps/alarmclock/src/com/android/alarmclock/Alarms.javaprivatestaticvoidenableAlert(Contextcontext,finalAlarmalarm,finallongatTimelnMillis){AlarmManageram=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);??參am.set(Al
2、armManager.RTC_WAKEUP,atTimelnMillis,sender);}由鬧鐘管理器設(shè)置定時時間。2鬧鐘管理器2.1定時設(shè)置文件:frameworks/base/core/java/android/app/AlarmManager.javapublicstaticfinalintRTC_WAKEUP=0;publicstaticfinalintRTC=1;publicstaticfinalintELAPSED_REALT1ME_WAKEUP=2;publicstaticfinalintELAPSED_REALTIME=3;Alar
3、mManager(IAlarmManagerservice){mService=service;}publicvoidset(inttype,longtriggerAtTime,Pendinglntentoperation){try{mService.set(type,triggerAtTime,operation);}catch(RemoteExceptionex){}}將type,triggerAtTime,operation等參數(shù)轉(zhuǎn)向鬧鐘管理器服務(wù)。3鬧鐘管理器服務(wù)文件:frameworks/base/services/java/com/and
4、roid/server/AlarmManagerService.java3.1定時設(shè)置publicAlarmManagerService(Contextcontext){mDescriptor=init();)publicvoidset(inttype,longtriggerAtTime,Pendinglntentoperation){setRepeating(type,triggerAtTime,0,operation);publicvoidsetRepeating(inttype,longtriggerAtTirne,longinterval,P
5、endinglntentoperation){if(operation==null){Log.w(TAQnset/setRepeatingignoredbecausethereisnointent’’);return;}synchronized(mLock){Alarmalarm=newAlarm();alarm.type=type;alarm.when=triggerAtTime;alarm.repeatlnterval=interval;alarm.operation=operation;//Removethisalarmifalreadysch
6、eduled.removeLocked(operation);if(localLOGV)Log.v(TAG,"set:"+alarm);intindex=addAlarmLocked(alarm);if(index==0){setLocked(alarm);}}}privatevoidsetLocked(Alarmalarm){if(mDescriptor!=-1){set(mDescriptor,alarm.type,(alarm.when*1000*1000));}else{Messagemsg=Message.obtain();msg.what
7、=ALARM_EVENT;mHandIer.removeMessages(ALARM_EVENT);mHandler.sendMessageAtTime(msg,alarm.when);}}Init,set為底層操作函數(shù),$et(mDescriptor,alarm.type,(alarm.when*1000*1000));由底層來完成定時設(shè)置。3.2等待計時結(jié)束privateclassAlarmThreadextendsThreadpublicvoidrun()while(true)intresult=waitForAlarm(mDe$criptor
8、);if((result&RTC_WAKEUP_MASK)!=0)triggerAlarmsLocked(m