如何向Android框架添加系统服务

发布于 2024-09-10 06:19:47 字数 669 浏览 2 评论 0原文

我想添加我自己的在 Android“system_server”中运行的框架代码(处理所有系统级服务)。我的服务加载一个 JNI 库,该库与我添加到内核中的驱动程序进行通信。该服务旨在允许应用程序向其注册侦听器以从驱动程序获取更新。我发现了一篇非常好的博客文章(http://www .androidenea.com/2009/12/adding-system-server-to-android.html)解释了如何添加系统服务,但我无法让它完全工作。

首先,该帖子提到应该使用“适当的”Android.mk 文件来编写客户端/测试应用程序,但没有给出这方面的示例。当我尝试构建它时,我收到构建错误,指出它找不到我添加的服务。有人可以举例说明这可能是什么样子吗?

另外,我想在供应商目录(或 froyo 中的设备目录)中而不是在 Android 开源代码中实现此功能。该博客文章提到,正确的位置是供应商目录,但没有给出它应该是什么样子的示例。有人知道吗?

有关在 Android 中实现您自己的系统服务的任何其他信息都会有所帮助。同样我的具体工作流程是:

Android App ->系统服务-> JNI(本机)库 ->设备驱动程序

I want to add my own framework code that runs in the Android "system_server" (handles all the system level services). My service loads a JNI library that talks to a driver I have added to the kernel. The service is designed to allow an app to register a listener with it to get updates from the driver. I found a pretty good blog post (http://www.androidenea.com/2009/12/adding-system-server-to-android.html) that explains how to add a system service, but I cannot get it completely working.

First of all, the post mentions that an "appropriate" Android.mk file should be used to write the client/test application, but does not give an example of this. When I try to build it, I get build errors saying it can't find the service I have added. Could someone give an example of what this might look like?

Also, I'd like to implement this in the vendor directory (or device directory in froyo) rather than in the Android open source code. The blog post mentions that the proper place for this is the vendor directory, but does not give an example of what this should look like. Anyone know?

ANY additional information on implementing your own system service in Android would be helpful. Again my specific workflow is:

Android App -> System Service -> JNI (native) library -> Device Driver

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

菊凝晚露 2024-09-17 06:19:47

德州仪器提供了一个很好的例子:

http://processors.wiki.ti.com /index.php/Android-Adding_SystemService

此外,CyanogenMod SystemServer.java 还具有用于动态加载系统服务的代码,如 config.xml 中的数组“config_vendorServices”中所定义(请参阅 core/res/res/values/config .xml),我相信可以使用覆盖层在供应商或设备目录中覆盖它。这是 CyanogenMod 特定的添加,在此提交中添加:

https://github.com/CyanogenMod/ android_frameworks_base/commit/88fff90131f54d45dc496c45127ac1d16ad257df

Texas instruments has provided a nice example:

http://processors.wiki.ti.com/index.php/Android-Adding_SystemService

Additionally, the CyanogenMod SystemServer.java has also code for dynamically loading system services as defined in the array "config_vendorServices" in config.xml (see core/res/res/values/config.xml), which I believe can be overwritten in the vendor or device directories using the overlays. This is a CyanogenMod-specific addition, added in this commit:

https://github.com/CyanogenMod/android_frameworks_base/commit/88fff90131f54d45dc496c45127ac1d16ad257df

淑女气质 2024-09-17 06:19:47

添加系统服务有多种方式(或者说有 6 种方式,只是为了明确)。

您尝试过的(Android 应用程序 -> 系统服务 -> JNI(本机)库 -> 设备驱动程序)就是其中之一。您可能需要查看这篇文章关于系统服务实现模式的深入解释。

在此处输入图像描述

There are multiply way (or 6 ways, just to be explicit) of adding a system service.

What you tried (Android App -> System Service -> JNI (native) library -> Device Driver) is one of them. You might want check out this article for an in-depth explanation regarding system service implementation patterns.

enter image description here

ぇ气 2024-09-17 06:19:47

按照以下步骤在 android 框架中编写自己的系统服务。

  1. 使用通过继承存根公开的 API 编写您自己的服务/管理器。
  2. 为您的服务创建一个aidl 文件以公开和使用包含在构建中。
  3. 在 System Server 中添加您的服务,您的服务将与所有核心服务一起启动。
  4. 在 context impl 文件中注册您的服务上下文。
  5. 通过调用 getSystemService(您的服务的上下文)

PS; 在应用程序中使用您的服务;如果您的服务遇到致命异常,设备将软重启,因为您的服务在系统服务下运行。

Follow the below steps for writing your own System Service in android framework.

  1. Write your Own Service/Manager with API's exposed by inheriting the stub.
  2. Create an aidl file for your service to expose & include in build.
  3. Add your service in System Server, you service will start along with all core services.
  4. Register your service context in context impl file.
  5. Use your service in application by calling getSystemService(Context of your service)

PS; if your service get some fatal exception, device will soft reboot, as your service is running under system service.

清晨说晚安 2024-09-17 06:19:47

下面是一个用于编译位于 system/extras/JNITest 的 JNItest.c 的 Android.mk 示例。 Android.mk 也在 system/extras/JNITest 目录中。

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= JNITest1.c

LOCAL_MODULE:= JNITest

#LOCAL_FORCE_STATIC_EXECUTABLE := true

#LOCAL_STATIC_LIBRARIES := libc
LOCAL_SHARED_LIBRARIES := libc

#LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE_TAGS := eng

include $(BUILD_EXECUTABLE)

Here is an example of an Android.mk used to compile a JNItest.c located at system/extras/JNITest. The Android.mk is also inside system/extras/JNITest directory.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= JNITest1.c

LOCAL_MODULE:= JNITest

#LOCAL_FORCE_STATIC_EXECUTABLE := true

#LOCAL_STATIC_LIBRARIES := libc
LOCAL_SHARED_LIBRARIES := libc

#LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE_TAGS := eng

include $(BUILD_EXECUTABLE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文