System Monitor for Android SDK 開發者指南說明書
1. 技術項目簡介 對於應用程式開發人員而言, 其開發程式的執行效能, 攸關使用者的使用意願 故開發時最好能夠兼顧所開發之軟體於執行時期, 對於系統的資源使用情況 本技術可以幫助程式開發人員瞭解所欲開發之應用軟體, 對於系統效能的影響, 進而進行效能改善 有別於市面上的應用程式, 本軟體開發套件可以深入到開發者自行定義的功能, 針對特定功能區段, 進行中央處理器, 記憶體使用量, 網路使用流量, 或是電池耗電量等系統效能監測, 以了解所開發之程式, 需針對哪個部分進行效能上的優化, 增加開發軟體之價值 2. 應用範圍說明 要提昇智慧裝置的軟 硬體之效能品質或是使用者體驗, 最重要的一點便是要先將數值量化, 本技術模組可協助研發人員進行 API 層級的資源剖析, 應用情境包含 : 分析 IM 軟體不同功能的耗電情形 影片播放時 CPU 負載狀態以及裝置待機時背景系統資源應用情形等
3. 安裝指南說明 3.1. 基本開發環境需求 採用 Windows XP/Vista/7, Mac OS X (intel) or Linux (i386) O.S 的 PC JavaSE JDK & JRE Version 5 or later, website: http://www.oracle.com/technetwork/java/javase/downloads/ Eclipse IDE Version 3.3(Europa) or later for JAVA Developer (including the Java Developer Tools (JDT), Web Developer Tooler (WDT) is included in the Eclipse installation package), website:http://www.eclipse.org [option] Android SDK: download the appropriate package from following link, then read the guide to Install the Android SDK. website: http://developer.android.com/sdk/installing.html Android Development Tools plug-in for Eclipse, website: http://developer.android.com/ Android System Monitor SDK Library is in the SDK package.
3.2. 開發環境設定 本範例程式可在 PC 端執行, 或者在 Android 2.3 版 SDK AVD 模擬器或是 Android 1.6 版本以上之手機上執行 3.2.1. 開發範例程式 ( 以 PC 端程式為例 ) Step 1. Open a java project with Eclipse or other Android IDE Step 2. Import the project "SystemStatusMonitorController" Step 3. Copy AndroidSystemMonitor.jar into folder lib Step 4. Select Project > Properties > Java Build Path Step 5. Click Add JARs button to select the AndroidSystemMonitor.jar file to the build path. Step 6. Click OK to finish Java Build path. 3.3. 執行範例程式 Step 1. Open Run\Run as\run Configuration Step 2. Press one or many CPU Loading Memory Wifi or Battery Status button Step 3. Choose "Show on Screen" or "Write to Log" Step 4. Click Apply, and then click Run Step 5. Edit Interval seconds and Press "Start Monitoring" to start the monitor
3.4. 範例程式操作說明 Step 1. 勾選任意複數欲監控的項目 (ex: CPU Loading, Memory, Wi-Fi, or Battery Status) 選項. Step 2. 勾選 Show on screen or write to log 選項 Step 3. 於輸入欄位輸入 Interval 秒數 Step 4. 按下 Start Monitoring 按鈕, 則即時的系統監控資訊會依照設定的時間間隔 (Interval) 顯示在螢幕或是寫入至手機, 儲存成 log 檔案 Step 4. 按下 Stop Monitoring 按鈕, 則停止系統監控 Step 5. 按下 View Log 按鈕, Step 6. 按下 View Graph 按鈕 Step 7. 使用連接線連接 PC 與手機, 開啟 Adroid SDK, 使用 ADB PULL 指令將儲存在手機的 Log 檔案複製到 PC 端 Step 8. 開啟 PC 端對應資料夾, 檢視 Log 檔是否存在 Step 9. 開啟 PC_Adroid_System_Monitor Step 10. 按下 Choose Log File 按鈕, 選擇對應的 Log 檔 Step 11. 按下 CPU Usage 按鈕 or Memory Usage 按鈕 or Network Usage Tx/Rx 按鈕 or Battery Level 按鈕 or Battery Temperature 按鈕, 則在 PC 端顯示監控資訊
4. 範例程式碼說明 本範例程式包含 IWannaUseSDKActivity.java 及 AndroidSystemMonitor.jar IWannaUseSDKActivity.java 程式碼撰寫重點如下 : 欄位宣告 : 一般性欄位宣告 Service 欄位宣告以及 ServiceConnection 欄位宣告 mconnection: 此物件用來表示與 Service 之間建立的連線 dobindservice(): 此類方法建立 Activity.java SystemStatusmotonitorSevice.class 之間的連線 getconnection(): 此類方法用來取得與 Service 之間建立的連線 dounbindservice(): 此類方法中斷 Activity.java 與 SystemStatusmotonitorSevice.class 之間的連線 StartService(): 此類方法用來開啟相對應的 Service StopService(): 此類方法用來關閉相對應的 Service tooglemonitorservice(boolean): 此類方法用來傳送相關監控設定至 SystemStatusmotonitorSevice.class showserviceview(int, boolean): 此類方法用以接收監控中的 Service 資訊
5.SDK 與 Function List API 說明 5.1. SystemStatusMonitorService Class Overview The class is to manage the system monitoring, which can get the setting about what is intend to monitor, and start or stop the monitoring. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver and stop monitoring IBinder onbind(intent intent) Return incoming messenger with getbinder()
5.2. CpuInfoService Class Overview The class is to get and parse the system information of CPU and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver void parsetopinfo () To parse the information and send it within intent by broadcast
5.3. MemoryInfoService Class Overview The class is to get and parse the system information of Memory and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver void parsememinfo () To parse the information and send it within intent by broadcast
5.4. NetCounterService Class Overview The class is to get and parse the system information of Wi-Fi Net Counter and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver void parserxresult () To parse the information and send it within intent by broadcast void parsetxresult () To parse the information and send it within intent by broadcast
5.4. BatteryStatusService Class Overview The class is to get and parse the system information of Battery Status and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver
6. 參考文獻 Android SDK & Developer Guide http://developer.android.com/guide/basics/what-is-android.html