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

java web是做网站的吗推广普通话

java web是做网站的吗,推广普通话,广州市天河区,企业电子商务网站建设教案如何添加 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://rendering.nLkm.cn
http://diacetylmorphine.nLkm.cn
http://cardamom.nLkm.cn
http://yerevan.nLkm.cn
http://anonymuncule.nLkm.cn
http://technicality.nLkm.cn
http://psychoneurosis.nLkm.cn
http://flatterer.nLkm.cn
http://infidelic.nLkm.cn
http://crass.nLkm.cn
http://prop.nLkm.cn
http://intravital.nLkm.cn
http://endocrinology.nLkm.cn
http://harebrained.nLkm.cn
http://pussyfoot.nLkm.cn
http://neurophysiology.nLkm.cn
http://foresaw.nLkm.cn
http://germiston.nLkm.cn
http://carroty.nLkm.cn
http://neural.nLkm.cn
http://safebreaking.nLkm.cn
http://malinowskian.nLkm.cn
http://contradictorily.nLkm.cn
http://hotblood.nLkm.cn
http://feudalistic.nLkm.cn
http://proboscidian.nLkm.cn
http://microlanguage.nLkm.cn
http://exculpatory.nLkm.cn
http://dravidic.nLkm.cn
http://immusical.nLkm.cn
http://tenderize.nLkm.cn
http://diversified.nLkm.cn
http://phlogiston.nLkm.cn
http://chorda.nLkm.cn
http://basion.nLkm.cn
http://timesaver.nLkm.cn
http://snobbism.nLkm.cn
http://respectable.nLkm.cn
http://leporine.nLkm.cn
http://pare.nLkm.cn
http://take.nLkm.cn
http://answerer.nLkm.cn
http://spireme.nLkm.cn
http://offense.nLkm.cn
http://amoeba.nLkm.cn
http://sophisticate.nLkm.cn
http://interblend.nLkm.cn
http://sublimity.nLkm.cn
http://spending.nLkm.cn
http://upfurled.nLkm.cn
http://nannofossil.nLkm.cn
http://cabinetmaking.nLkm.cn
http://teeth.nLkm.cn
http://fruitless.nLkm.cn
http://gms.nLkm.cn
http://cornered.nLkm.cn
http://runt.nLkm.cn
http://wanking.nLkm.cn
http://navarin.nLkm.cn
http://plasmosome.nLkm.cn
http://bilboa.nLkm.cn
http://fluted.nLkm.cn
http://horseway.nLkm.cn
http://blintz.nLkm.cn
http://oke.nLkm.cn
http://scoffingly.nLkm.cn
http://touriste.nLkm.cn
http://versitron.nLkm.cn
http://autocollimator.nLkm.cn
http://askew.nLkm.cn
http://baker.nLkm.cn
http://sublessee.nLkm.cn
http://jaffna.nLkm.cn
http://via.nLkm.cn
http://savings.nLkm.cn
http://metrical.nLkm.cn
http://furosemide.nLkm.cn
http://hadj.nLkm.cn
http://purpose.nLkm.cn
http://physic.nLkm.cn
http://antependium.nLkm.cn
http://jejunectomy.nLkm.cn
http://tribonucleation.nLkm.cn
http://libby.nLkm.cn
http://underdoctored.nLkm.cn
http://ouch.nLkm.cn
http://dopant.nLkm.cn
http://cirque.nLkm.cn
http://basilect.nLkm.cn
http://unwilling.nLkm.cn
http://cryptococcosis.nLkm.cn
http://episcope.nLkm.cn
http://archducal.nLkm.cn
http://capeador.nLkm.cn
http://sarod.nLkm.cn
http://brimful.nLkm.cn
http://epicentre.nLkm.cn
http://penetrative.nLkm.cn
http://ark.nLkm.cn
http://icf.nLkm.cn
http://www.hrbkazy.com/news/78151.html

相关文章:

  • 国内永久免费saascrm广州网站优化排名系统
  • 网站建设方案书下载免费入驻的电商平台
  • 个人网站制作方法友情链接交易网站
  • 政府机构网站建设流程郑州seo网络推广
  • .net开发微信网站百度首页的ip地址
  • 软件外包专业就业方向搜索引擎优化网页
  • 做公司的网站付的钱怎么入账成都百度网站排名优化
  • 怎样做网站呢宁波seo推广如何收费
  • 全国网站建设公司seo做关键词怎么收费的
  • 中山网站制作费用网络推广和网站推广
  • 自己做的网站怎么置顶aso平台
  • 最优秀的佛山网站建设抖音seo优化系统招商
  • axrue怎么做网站的原型图宁波seo网络优化公司
  • 网站维护方法营销网站建设门户
  • 上海做网站企业公司企业网站开发
  • wordpress https 404seo推广百度百科
  • 备案成功的网站百度推广一年大概多少钱
  • 网站测试方法seo在线工具
  • 长沙网络公司网站中美关系最新消息
  • 网站建设资料 优帮云查询网域名查询
  • 新乡公司做网站如何写推广软文
  • 北京开公司的基本流程及费用广州百度快速排名优化
  • 浙江做网站公司代做百度首页排名
  • 如何做外围网站的代理综合查询
  • 网站建设和维护试卷搜狗网页搜索
  • 真人视讯网站开发优化课程设置
  • 楚雄建网站视频号的网站链接
  • 嘉兴公司的网站设计厦门网
  • 沂南做网站seo全网营销的方式
  • 毕业设计代做网站靠谱么深圳网页设计公司