一、系统编程

1.SystemServer.java类中提供了main()方法,说明它是以一个进程的方式存在的,启动后直接执行其run()

2.注册服务
ServiceManager.addService("vibrator", vibrator);
通过addService来告诉系统,告诉系统指的是service_manager.c表示的进程。service_manager管理着系统中的所有service。要想这些服务
能被应用程序使用,就必须要注册进service_manager中。
应用程序向service_manager查询获得某一个service。然后应用程序通过接口ILedService把对硬件操作请求发送给LedService.java,然后由
这个LedService来实现对硬件的操作。

3.AIDL文件的实现
对于一个应用程序来说,它只需要调用ioctl()去控制LED,并不需要open()和close(),因此LED的ILedService.aidl文件中的interface ILedService中
只需要实现ledIoctl()这一个函数即可。模仿IVibratorService.aidl放到对应的目录下,然后修改Android.mk文件添加:core/java/android/os/ILedService.aidl
然后执行mmm .命令系统会帮我们在根目录下的out目录下生成ILedService.java文件.

/* ILedService.aidl文件 */
package android.os;

/** {@hide} */
interface ILedService
{
    int ledControl(int which, int status);
}
View Code

相关文章:

  • 2021-09-26
  • 2022-12-23
  • 2021-08-25
  • 2021-12-02
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案