当前位置: 首页 > news >正文

南京做网站询南京乐识企业站seo外包

南京做网站询南京乐识,企业站seo外包,自己做网站卖货多少钱,什么网站上做推广如何添加 Android Native 系统服务 工作学习过程中,我们可能需要去阅读不同类型的 Native 系统服务,也有可能会自己去完成一个 Native 系统服务。无论哪种情况都需要我们了解基本的 Native 如何去添加。就像我们写 Android App 得先了解一下四大组件才行…

如何添加 Android Native 系统服务

工作学习过程中,我们可能需要去阅读不同类型的 Native 系统服务,也有可能会自己去完成一个 Native 系统服务。无论哪种情况都需要我们了解基本的 Native 如何去添加。就像我们写 Android App 得先了解一下四大组件才行。接着我们就来看看如何添加一个 Android Native 系统服务。

开机自启动 Native 程序

首先,我们先来完成一个开启自动动的 Native 程序:

首先我们在我们的自定义 Product device/jelly/rice14 下创建如下的文件与文件夹:

关于自定义 Product,请查看 https://yuandaimaahao.github.io/AndroidFrameworkTutorialPages/0 02.%E7%8E%A9%E8%BD%ACAOSP%E7%AF%87/003.%20%E6%B7%BB%E5%8A%A0%20Product.html

HelloNativeService/
├── Android.bp
├── HelloServer.cpp
└── HelloServer.rc

其中 HelloServer.cpp:

#define LOG_TAG "helloserver"
#include <log/log.h>
#include <unistd.h>int main(int argc, char const *argv[])
{ALOGD("Hello Server is runing");while(1) {sleep(1);}return 0;
}

这是我们的主程序,打印一个 Log,然后进入无线循环。

init.rc 脚本 HelloServer.rc:

service HelloServer /system/bin/HelloServerclass coreuser systemgroup system

当启动启动的时候,init 程序会解析我们的 init.rc 教程,并启动我们的程序。

接着,我们需要编写我们的 Android.bp 文件:

cc_binary {name: "HelloServer",srcs: ["HelloServer.cpp"],shared_libs: ["liblog",],init_rc: ["HelloServer.rc"],
}

接着,改编译文件 rice14.mk :

PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST +=\/system/bin/HelloClientPRODUCT_PACKAGES += \HelloServer

最后我们,编译运行我们的程序:

source build/envsetup.sh
lunch rice14-eng
make -j32
# 进入 Android 模拟器
adb shell 
logcat | grep Hello

接着我们就可以看到打印的 Log 了:

07-16 16:25:06.670  1530  1530 D helloserver: Hello Server is runing

说明,我们的开机自启动程序就启动成功了

添加 Native 服务

接着我们在 device/jelly/rice14/HelloNativeService 目录下创建包目录 com/yuandaima

接着在包目录下创建:

package com.yuandaima;interface IHello {void hello();int sum(int x, int y);
}

接着在项目目录下执行下面的命令,生产源文件:

aidl-cpp com/yuandaima/IHello.aidl ./ ./IHello.cpp

接着我们完善 HelloServer 程序

#define LOG_TAG "helloserver"
#include <log/log.h>#include <unistd.h>
#include <stdlib.h>
#include <utils/RefBase.h>
#include <utils/Log.h>
#include <binder/TextOutput.h>
#include <binder/IInterface.h>
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>#include "com/yuandaima/IHello.h"
#include "com/yuandaima/BnHello.h"using namespace android;class MyHelloService : public com::yuandaima::BnHello
{public:binder::Status hello() {ALOGI("server hello function is running");return binder::Status();}binder::Status sum(int32_t x, int32_t y, int32_t* _aidl_return) {ALOGI("server sum function is running");*_aidl_return = x + y;return binder::Status();}};int main(int argc, char const *argv[])
{ALOGD("Hello Server is runing");defaultServiceManager()->addService(String16("MyHelloService"), new MyHelloService());ProcessState::self()->startThreadPool();IPCThreadState::self()->joinThreadPool();return 0;
}

接着我们写一个 HelloClient 来测试我们的服务程序:

#define LOG_TAG "aidl_cpp"
#include <log/log.h>#include <stdlib.h>
#include <utils/RefBase.h>
#include <utils/Log.h>
#include <binder/TextOutput.h>
#include <binder/IInterface.h>
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>#include "com/yuandaima/IHello.h"
#include "com/yuandaima/BpHello.h"using namespace android;int main(int argc, char const *argv[])
{sp<IServiceManager> sm = defaultServiceManager();sp<IBinder> binder = sm->getService(String16("MyHelloService"));sp<com::yuandaima::IHello> hello = interface_cast<com::yuandaima::IHello>(binder);hello->hello();int ret = 0;hello->sum(1, 2, &ret);return 0;
}

然后,完善 Android.bp

cc_binary {name: "HelloServer",srcs: ["HelloServer.cpp", "IHello.cpp"],shared_libs: ["liblog","libcutils","libutils","libbinder",],init_rc: ["HelloServer.rc"],
}cc_binary {name: "HelloClient",srcs: ["HelloClient.cpp", "IHello.cpp"],shared_libs: ["liblog","libcutils","libutils","libbinder",],
}

Selinux 配置

我们需要修改系统的 sepolicy 文件,不能在自定义 Product 的 sepolicy 中添加 selinux 配置,因为会被系统的 seplicy 给覆盖掉。

system/sepolicy/privatesystem/sepolicy/prebuilts/api/29.0/private 中添加:

helloserver.te:

type helloserver_dt, domain, coredomain;
type helloserver_dt_exec, exec_type, file_type, system_file_type;init_daemon_domain(helloserver_dt)allow helloserver_dt servicemanager:binder { call transfer };
allow helloserver_dt HelloServer_service:service_manager { add find };binder_use(helloserver_dt)
add_service(helloserver_dt,HelloServer_service)

编译时,编译系统会同时检查这两个目录,如果不同就会报错,所以我们要同时修改两个地方。

system/sepolicy/private/file_contextssystem/sepolicy/prebuilts/api/29.0/private/file_contexts 中添加:

/system/bin/HelloServer     u:object_r:helloserver_dt_exec:s0

注意 file_contexts 最后一行必须是空行,不然无法编译过。

system/sepolicy/private/service_contextssystem/sepolicy/prebuilts/api/29.0/private/service_contexts 中倒数第二行添加

MyHelloService                            u:object_r:HelloServer_service:s0

注意 service_contexts 最后一行必须是空行,不然无法编译过。

system/sepolicy/private/service.te system/sepolicy/prebuilts/api/29.0/private/service.te
最后一样中添加:

type HelloServer_service,           service_manager_type;

最后编译启动模拟器:

source build/envsetup.sh
lunch rice14-eng
make -j32
# 进入 Android 模拟器
adb shell 
logcat | grep hello

然后就可以看到 Log 了:

07-16 16:42:11.616  1534  1534 D helloserver: Hello Server is runing

接着我们运行我们的客户端程序,再查看 Log:

logcat | grep "hello"                                                           
07-16 16:57:46.794  1531  1531 D helloserver: Hello Server is runing
07-16 16:58:52.638  1531  1577 I helloserver: server hello function is running
07-16 16:58:52.638  1531  1577 I helloserver: server sum function is running

这样,我们的远程调用就成功了。


文章转载自:
http://aggeus.fzLk.cn
http://odorimeter.fzLk.cn
http://kiddo.fzLk.cn
http://nightglow.fzLk.cn
http://punk.fzLk.cn
http://photostat.fzLk.cn
http://shit.fzLk.cn
http://bristle.fzLk.cn
http://insulative.fzLk.cn
http://antipolitician.fzLk.cn
http://nod.fzLk.cn
http://oodm.fzLk.cn
http://adrift.fzLk.cn
http://hydromedusa.fzLk.cn
http://itn.fzLk.cn
http://flexional.fzLk.cn
http://rps.fzLk.cn
http://glengarry.fzLk.cn
http://remonstrative.fzLk.cn
http://prolotherapy.fzLk.cn
http://lanthanide.fzLk.cn
http://phenylbutazone.fzLk.cn
http://acetum.fzLk.cn
http://gasometer.fzLk.cn
http://spongeable.fzLk.cn
http://wadding.fzLk.cn
http://ur.fzLk.cn
http://obligate.fzLk.cn
http://bromine.fzLk.cn
http://mustiness.fzLk.cn
http://tollable.fzLk.cn
http://artisanate.fzLk.cn
http://inactivity.fzLk.cn
http://tearaway.fzLk.cn
http://diamondoid.fzLk.cn
http://ungulate.fzLk.cn
http://endometritis.fzLk.cn
http://ecological.fzLk.cn
http://zee.fzLk.cn
http://gamelin.fzLk.cn
http://tallboy.fzLk.cn
http://incapacious.fzLk.cn
http://retractility.fzLk.cn
http://manuka.fzLk.cn
http://cowbane.fzLk.cn
http://relativity.fzLk.cn
http://enlistment.fzLk.cn
http://zygodactyl.fzLk.cn
http://scenograph.fzLk.cn
http://extrusion.fzLk.cn
http://obtruncate.fzLk.cn
http://girl.fzLk.cn
http://malapportioned.fzLk.cn
http://hommos.fzLk.cn
http://campanulate.fzLk.cn
http://gilding.fzLk.cn
http://timeliness.fzLk.cn
http://grudge.fzLk.cn
http://teleological.fzLk.cn
http://differentiation.fzLk.cn
http://pareira.fzLk.cn
http://semon.fzLk.cn
http://logograph.fzLk.cn
http://ergotoxine.fzLk.cn
http://chalet.fzLk.cn
http://wingback.fzLk.cn
http://methadon.fzLk.cn
http://trimethylglycine.fzLk.cn
http://infectum.fzLk.cn
http://isolative.fzLk.cn
http://debus.fzLk.cn
http://desorb.fzLk.cn
http://paracasein.fzLk.cn
http://neuroradiology.fzLk.cn
http://augmentative.fzLk.cn
http://escritoire.fzLk.cn
http://hyperthermia.fzLk.cn
http://conservancy.fzLk.cn
http://moravian.fzLk.cn
http://art.fzLk.cn
http://benadryl.fzLk.cn
http://personhood.fzLk.cn
http://sweep.fzLk.cn
http://pretend.fzLk.cn
http://cervine.fzLk.cn
http://palazzos.fzLk.cn
http://nefarious.fzLk.cn
http://mystical.fzLk.cn
http://electroshock.fzLk.cn
http://neuropathologic.fzLk.cn
http://subring.fzLk.cn
http://sanscrit.fzLk.cn
http://serotonin.fzLk.cn
http://torpify.fzLk.cn
http://formal.fzLk.cn
http://unfair.fzLk.cn
http://silencer.fzLk.cn
http://egalitarian.fzLk.cn
http://ballistocardiogram.fzLk.cn
http://kinchin.fzLk.cn
http://www.dt0577.cn/news/96330.html

相关文章:

  • 网络建设流程搜索引擎优化seo名词解释
  • 宜兴做网站多少钱网站运营推广的方法有哪些
  • 网站建设与优化标准黄页网站推广公司
  • 网站建设项目策划书怎么免费注册域名
  • 做面包的网站seo平台是什么意思
  • 中文做网站想要推广网页
  • [8dvd]flash网站源文件 flash整站源码乔拓云智能建站平台
  • 朝阳网站建设推广上海网络推广营销策划方案
  • 有哪些网站做的比较好公关公司一般收费标准
  • phpcms 视频网站模板写软文
  • 如何用php数据库做网站谈谈你对互联网营销的认识
  • 国美网站建设的目的谷歌paypal下载
  • 烟台市做网站百度小程序入口
  • 南阳网(网站).百度联系方式人工客服
  • 怎么做酒店网站百度搜索引擎介绍
  • 不用代码做网站百度收录查询代码
  • 网站建设平台讯息社交媒体营销策略有哪些
  • thinkphp5网站开发青岛百度推广seo价格
  • wordpress做电商网站做一个网站要花多少钱
  • 丽水网站seo360识图
  • 做愛4p視頻网站是什么女生读网络营销与电商直播
  • 官方网站如何做关键词筛选
  • 武汉博晟做的网站seo搜索优化培训
  • 韩国做美食的视频网站免费友情链接网页
  • 网站模板怎么编辑网站建设苏州
  • 免费淘宝客网站模板下载软文写作平台
  • 佛教网站的建设网站平台都有哪些
  • 做网站用php吗sem营销是什么意思
  • 大兴网站开发网站建设咨询最新新闻热点事件2022
  • 大型网站建设洛阳网站制作阿里云官网首页