Android System Service how-to

${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
廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s


%d 位部落客按了讚: