47897
查看Android: Add a service的源代码
Android: Add a service
0
←
Android: Add a service
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
你被禁止执行你刚才请求的操作。
您可以查看并复制此页面的源代码:
#1. aosp/hardware/interfaces/<myservice>/1.0 * Android.bp <source lang="c"> hidl_interface { name: "android.hardware.<myservice>@1.0", root: "android.hardware", vndk: { enabled: false, }, srcs: [ "types.hal", "I<Myservice>.hal", ], interfaces: [ "android.hidl.base@1.0", ], gen_java: false, } </source> * I<Myservice>.hal <source lang="c"> package android.hardware.<myservice>@1.0; interface I<Myservice> { func1() generates (<Myservice>Error error); func2(handle h, Param1 p1) generates (<MyService>Error error); }; </source> * types.hal <source lang="c"> package android.hardware.<myservie>@1.0; enum <MyService>Error : uint8_t { <MYSERVICE>_SUCCESS = 0, }; struct Param1 { .... }; </source> * default/ - Android.bp - abstraction layer (@-impl) source code - service.cpp <source lang="c"> #include <sched.h> #include <android/hardware/<myservice>/1.0/I<Myservice>.h> #include <binder/ProcessState.h> #include <hidl/HidlTransportSupport.h> using android::hardware::myservice::V1_0::I<Myservice>; int main() { // the conventional HAL might start binder services android::ProcessState::initWithDriver("/dev/vndbinder"); android::ProcessState::self()->setThreadPoolMaxThreadCount(4); android::ProcessState::self()->startThreadPool(); // same as SF main thread struct sched_param param = {0}; param.sched_priority = 2; if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, ¶m) != 0) { ALOGE("Couldn't set SCHED_FIFO: %d", errno); } android::hardware::configureRpcThreadpool(4, true /* will join */); android::sp<IMyservice> service = new android::hardware::<myservice>::implementation::<Myservice>(); if (service == nullptr) { ALOGE("failed to create device!"); return -1; } if (service ->func1() != <Myservice>Error::<MYSERVICE>_SUCCESS) { ALOGE("failed to init device"); return -1; } if (service->registerAsService() != android::NO_ERROR) { ALOGE("failed to register service"); return 1; } android::hardware::joinRpcThreadpool(); ALOGE("service is terminating"); return 1; } </source> - <myservice>.rc <source lang="c"> </source> #2. Block diagram #3. How to register as a server in <vendor>/<device>/manifest.xml, add <source lang="awk"> <hal format="hidl"> <name>android.hardware.myservice</name> <transport>hwbinder</transport> <version>1.0</version> <interface> <name>IMyservice</name> <instance>default</instance> </interface> </hal> </source> in <vendor>/<device>/device.mk, add <source lang="awk"> PRODUCT_PACKAGES += \ android.hardware.<myservice>@1.0 \ android.hardware.<myservice>@1.0-service myservice.myplatform </source> #4. How to load our implementation, e.g. myservice.myplatform.so (1) define a global and unique hardware module id in a header file <source lang="c"> #define <MYSERVICE>_HARDWARE_ID "myservice" </source> (2)<service>-imple call hw_get_module(<MYSERVICE>_HARDWARE_ID (== "myservice")) //it get prop from "ro.hardware.myservice", in our case, "myservice" //check all variants listed in property variant_keys[], start from // "ro.hardware", "ro.product.board", "ro.board.platform", "ro.arch" // in our case, ro.product.board ="myplatform" //now search if the file "myservice.myplatform.so" in <source lang="c"> /** Base path of the hal modules */ #if defined(__LP64__) #define HAL_LIBRARY_PATH1 "/system/lib64/hw" #define HAL_LIBRARY_PATH2 "/vendor/lib64/hw" #define HAL_LIBRARY_PATH3 "/odm/lib64/hw" #else #define HAL_LIBRARY_PATH1 "/system/lib/hw" #define HAL_LIBRARY_PATH2 "/vendor/lib/hw" #define HAL_LIBRARY_PATH3 "/odm/lib/hw" #endif </source> //if not exist, check the default file in above paths //in our case, myservice.default.so Notes: 1. Default lib myservice.myplatform.so is decided by ro.product.board 2. To change default implementation, we can name our lib as myservice.myhardware.so #5. How to call I<Myservice>
返回
Android: Add a service
。
导航菜单
个人工具
   
个人维基
注册
登录
名字空间
页面
变换
查看
阅读
查看源代码
统计
查看历史
操作
搜索
导航
首页
最近更改
随机页面
工具箱
所有页面
文件列表
特殊页面