Android SystemService

我想我会记得你
https://www.cnblogs.com/chorm590/p/7258001.html

    modified:   device/rockchip/common/BoardConfig.mk
    modified:   device/rockchip/common/init.rk30board.rc
    modified:   frameworks/base/Android.mk
    modified:   frameworks/base/api/current.txt
    modified:   frameworks/base/api/system-current.txt
    modified:   frameworks/base/core/java/android/app/ContextImpl.java
    modified:   frameworks/base/core/java/android/content/Context.java
    modified:   frameworks/base/services/java/com/android/server/SystemServer.java

Untracked files:
  (use "git add <file>..." to include in what will be committed)
  
    frameworks/base/core/java/android/app/GAManager.java
    frameworks/base/core/java/android/app/IGAManager.aidl
    frameworks/base/gaapimanager/
    frameworks/base/services/core/java/com/android/server/GAService.java

 

Android创建系统服务(XHService)
实现功能:调用自己的Service,实现控制红蓝灯。


一、接口
首先定义一个 AIDL 文件,接口

frameworks/base/core/java/android/app/IGAManager.aidl

 

二、封装
Manager 这个就是一个封装类,用来封装 aidl接口的


三、功能
功能实现在Service

 

四、注册与编译
1、 aidl 接口参与编译

frameworks/base/Android.mk
    core/java/android/app/IAlarmManager.aidl \
    core/java/android/app/IXHManager.aidl \
    core/java/android/app/IGAManager.aidl \

2、注册成为系统服务,开机自动运行

frameworks/base/services/java/com/android/server/SystemServer.java

     gaService = new GAService(context);
     ServiceManager.addService(Context.GA_SERVICE,gaService);

3、定义标识符 (规范)

frameworks/base/core/java/android/content/Context.java
在 Context 中添加用于识别这个服务的标识符
public static final String GA_SERVICE = "GA_SERVICE";

4、功能和封装方法建立联系

GAManager.java & GAService.java
frameworks/base/core/java/android/app/ContextImpl.java

 

5、编译
更新系统api接口需要同时提交current.txt
解释一下什么是current.txt?
修改framework/base下面的api时要注意更新api/current.txt

so,要make update-api,更新一下,编译完之后,文件自动生成定义的方法
如果编译成功,current.txt 会生成定义的方法

 

五、封装成api 给应用调用
封装成api,资源更小,客户调用更方便

 

 

posted @ 2020-05-18 19:35  CrushGirl  阅读(437)  评论(0编辑  收藏  举报