2010年11月23日 星期二

android 的 user space HAL

網路上一個有關user space HAL的問題
Q:
Hi All,

  I would like to know if there is any documents or related web links
for device driver development on "User Space Abstraction Layer ".
  I would appreciate if anyone can give me how this really works in
real world scenario.

 Thanks...

A:
I would suggest you to have a look of the overlay code in
hardware/libhardware/moudule/overlay.
In the new HAL architecutre, it introduced a "stub" concept which replaced
the legacy architecture which load the c/c++ library from java
application/service directly. In "stub", you need to implement some
interfaces and provide them to hardware service. For example if you wanna
implement a LED, the architecture will be:
Kernel Driver (driver to control the LED hardware) <-> syscall (open, close,
ioctl for LED, etc.) <-> hardware/libhardware/module/led (the led HAL
interfaces or "stub" ) <-> framework/base/services/jni/
com_android_server_LedService.cpp (the java native interface for LED )<->
framework/base/service/java/com/android/server/LedService.java (the java
interface of LED service <-> framwork/base/core/java
/android/hardware/LedManager (the java code of LED manager) and
ILedService.aidl (the android interface description language file for LED)
<-> LED application

這裡有一個文章連結

jollen的blog也有相關介紹文章

2010年11月16日 星期二

android 的 local service 與 thread 的差別

android 官網中提到要執行 background 的 long running 動作時 最好要用 service
但是 service 既然也是在同一個 process 中 create 一個 thread 來做這些 long running 的動作
為什麼不直接在 activity 裡直接 create thread 來做就好了

官網最下面有解答
1.
    一個有 service 在跑的 process 權限會比只有 background activity 在跑的 process高
    也就是當系統要砍 process 的時候比較不容易砍到你

2.
    用 service 的話 不管 activity 發生什麼事 都不會影響到 service, process 最少可以是 "service process" priority

android的application component是run在哪個thread

依照 android 官網所說 android 的 application component 包括 activity service broadcast receiver 等等
都是 run 在同一個 linux process 之中(除非這些 component 有特別指名要 run 在其他 process, 可以在 androidmanifest.xml 中指定)

官網又有說到 所有這些 component object 的實例化都發生在 process 的 main thread 中
而且有關 life cycle 的 method (例如 onCreate) 也都是在 main thread 中執行
所以在這些 method 中不能執行太花費時間的動作 免得阻擋到其他 component 的執行
如果需要作這些動作 應該 create 其他 thread 來做

2010年11月7日 星期日

vim 的自動完成

vim 也可以有自動完成的功能
在ubuntu 10.04下面裝的 vim 7 有預設支援自動完成的語言的資訊在 /usr/share/vim/vim72/autoload/ 下面

以php 為例 要開啟 php 自動完成功能 只要在 .vimrc 裡加上一行
    autocmd FileType php set omnifunc=phpcomplete#CompletePHP
就可以了

接下來在編輯 php 檔案時 只要用 ctrl+x ctrl+o 就可以使用自動完成

但是我最需要的 C/C++ 語言似乎需要額外的套件支援才能使用自動完成

C 的話有關鍵字自動完成可以用 不用在 .vimrc 中設定任何選項
只要在編輯 c 檔案時有 include 任何標頭檔 例如 stdio.h
在打入 print 時按下 ctrl+p 就會從 stdio.h 中找出符合的函式供你挑選

C++的話就沒有了 完全需要額外套件的支援
不知道為什麼 vim 不預設支援標準函式庫的自動完成 明明這是最需要的
關於 C/C++ 的自動完成之後再研究