Archive for 2009 年 12 月

Enable Dalvik JIT feature

十二月 8, 2009

by creating a buildspec.mk file in your AOSP root which includes the
line “WITH_JIT := true".

廣告

Android System Service how-to

十二月 4, 2009

${android-source}build/core/pathmap.mk

FRAMEWORKS_BASE_SUBDIRS := \

//Add library that application can link against

${android-source}frameworks/base/data/etc/platform.xml

<library name="android.awt"  file="/system/framework/android.awt.jar" />
Modify services/java/com/android/server/SystemServer.java
@Modify ServerThread:run method, adding our service to ServiceManager
try {
Log.i(TAG, “Starting Your Service.");
ServiceManager.addService(Context.YOUR_SERVICE, new YourService(context));
} catch (Throwable e) {
Log.e(TAG, “Failure starting Your Service", e);
}
}
Modify  core/java/android/content/Context.java
@add service constant string to context class
public static final String WIMAX_SERVICE = “wimax";
Modify core/java/android/app/ApplicationContext.java
@add class field to contain your service
private static YourManager sYourManager;
@change getSystemService ( ) method to return your service instance
if (YOUR_SERVICE.equals(name)) {
return getYourManager();
}
@add class method to retrieve IBinder stub from ServiceManager
private YourManager getYourManager()
{
synchronized (sSync) {
if (sYourManager == null) {
IBinder b = ServiceManager.getService(YOUR_SERVICE);
IYourManager service = IYourManager.Stub.asInterface(b);
sYourManager = new YourManager(service, mMainThread.getHandler());
}
}
return sYourManager;
}
Update current.xml by execute following commands
make update-api

Handler 與 HandlerThread 原理

十二月 2, 2009

在Android 程式裡 我們常用Handler來做 跨Thread的訊息溝通

Handler 允許你對 與Hanlder相互關聯的Thread MessageQueue,進行 “傳送" 及 “處理訊息(Message) 或 將可執行(Runable)的程序公布至這個Thread的MessageQueue, 待稍候 由這個Thread 來執行Runable 的內容.

當一個Handler被新建時…Handler 與 新建這個Handler的Thead MessageQueue 產生綁定,之後這個Handler 就會將訊息與可執行(Runable)的程序 傳送至這個Thread 的 MessageQueue

以下為Handler類別 常用的方法列表…post方法是將可執行的Runable 物件加入MessageQueue, 而send 方法 則為將訊息加入MessageQueue,

class Handler {

public interface Callback {
public boolean handleMessage(Message msg);
}

//將這個Handler 與建立這個Handler的Thread的MessageQueue 產生連結,當訊息自這個MessageQueue被Dispatch後 由這個handler的handleMessage(Message msg); 處理

public Handler();

//將這個Handler 與建立這個Handler的Thread的MessageQueue 產生連結,當訊息自這個MessageQueue被Dispatch後 由callback object的handleMessage方法處理

public Handler(Callback callback);

//將這個Handler 連結至 looper 的MessageQueue (Looper 只能跟Thread 並存), 當訊息自這個MessageQueue被Dispatch後 由這個handler的handleMessage(Message msg); 處理
public Handler(Looper looper);

//將這個Handler 連結至 looper 的MessageQueue (Looper 只能跟Thread 並存),當訊息自這個MessageQueue被Dispatch後 由callback object的handleMessage方法處理
public Handler(Looper looper, Callback callback);

//用來處理與這個Handler關聯Message Queue 的 non post message,在extend handler 假如你需要處理訊息 則override handleMessage
public void handleMessage(Message msg);

//Looper 自MessageQueue內取出 Message 後 假如這個訊息 由這個handler 所產生… 此dispatchMessage 就會被呼叫.
//當它為一般訊息時 呼叫handleMessage或與constructor傳進來的MessageCallback:handleMessage
//若為post message則執行message內的callback (從 post傳進的 runnable)

public void dispatchMessage(Message msg);

//將Runnable object 包裝成postMessage 並丟到這個Handler 連結的 MessageQueue
post(Runnable);
postAtTime(Runnable, long);
postDelayed(Runnable, long);

sendEmptyMessage(int);
sendMessage(Message);
sendMessageAtTime(Message, long);
sendMessageDelayed(Message, long);

}

class Looper {
public static final void prepare(); //新增一個looper instance至ThreadLocal
public static final Looper myLooper(); //從ThreadLocal 取回looper instance

public static final void loop(); //取回與這個Thread 關聯的looper, 並於迴圈內 取得MessageQueue 裡的訊息 並dispatch
public void quit(); //送出一個空訊息給Message 代表結束looper 迴圈

public static final MessageQueue myQueue(); 取得與這個Thread 關聯的MessageQueue
public Thread getThread(); 取得與這個looper 關聯的 Thread

}

class HandlerThread extends Thread{

public void run(); //呼叫Looper.prepare 新增Looper 至 Thread, 並呼叫Looper.loop 執行 MessageQueue

}

Porting udev to android

十二月 1, 2009

CONFIG_HOTPLUG=y
CONFIG_UEVENT_HELPER_PATH=""
CONFIG_NET=y
CONFIG_UNIX=y
CONFIG_SYSFS=y
CONFIG_SYSFS_DEPRECATED*=n
CONFIG_PROC_FS=y
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_INOTIFY=y
CONFIG_SIGNALFD=y