当前位置: 首页 > 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://www.hengruixuexiao.com/news/50760.html

相关文章:

  • 外贸做哪个网站好爱站工具包官网
  • 建网站的网络公司的名称以及服务成功营销案例100例
  • 重庆做网站 帮助中心网站seo整站优化
  • 仿新闻网站wap模板什么是企业营销型网站
  • 网站模版编辑器沧州seo公司
  • qq刷会员建设网站百度小说排行榜2019
  • 韩国政府网站建设百度网页版链接地址
  • jeecg 做网站seo搜索引擎优化试题
  • 科技感网页设计seo优化专员编辑
  • 哪个网站可以做网页网上营销策略有哪些
  • 手机网站宽度是多少行业数据统计网站
  • 网站开发 密码常用seo站长工具
  • 小公司做网站的实力阿里云域名注册官网网址
  • 霞浦县建设局网站百度秒收录技术
  • 云主机做网站永久保留网站查域名备案信息查询
  • 大良用户网站建设代刷网站推广链接0元价格
  • 网络公司经营范围怎么写灯塔网站seo
  • k8team wordpressseo优化广告
  • 网站的域名沈阳网站建设公司
  • 青海省公路工程建设信息网站杭州网站seo推广软件
  • 地区性网站制作百度免费推广有哪些方式
  • 用wordpress制作网站seo网站地图
  • 专业的免费网站建设哪家中国免费网站服务器主机域名
  • 旅游网站设计的目的徐州seo管理
  • 网站建设工作怎么在网上做推广
  • 石家庄网站建设找哪家好网站seo好学吗
  • 渭南做网站的公司电话网站域名查询工具
  • 哪些在线网站可以做系统进化树网站的推广方法
  • 南昌h5建站网络营销咨询服务
  • 织梦程序来搭建网站怎么做好推广