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 - simple project source - 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>
返回
Android: Add a service
。
导航菜单
个人工具
   
个人维基
注册
登录
名字空间
页面
变换
查看
阅读
查看源代码
统计
查看历史
操作
搜索
导航
首页
最近更改
随机页面
工具箱
所有页面
文件列表
特殊页面