How to add a system service to the Android Framework

前端 未结 4 686
死守一世寂寞
死守一世寂寞 2020-12-23 17:58

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

相关标签:
4条回答
  • 2020-12-23 18:32

    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

    0 讨论(0)
  • 2020-12-23 18:32

    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.

    0 讨论(0)
  • 2020-12-23 18:39

    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)
    
    0 讨论(0)
  • 2020-12-23 18:48

    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

    0 讨论(0)
提交回复
热议问题