以MTK 6737源代码分析:
软件架构:
APP/system
|
| Binder
|
java framework
|
|JNI
|
Native Framework
|
|hw_get_module()
|
HAL
|
|
Kernel Driver
|
|
hardware
代码路径:
system:
./frameworks/base/services/java/com/android/server/SystemServer.java 启动LightsService
./frameworks/base/services/core/java/com/android/server/SystemServiceManager.java
startService(String className)-->service.onStart()
framework:
封装LightsService
./frameworks/base/services/core/java/com/android/server/lights/LightsService.java
./frameworks/base/services/core/java/com/android/server/lights/LightsManager.java
./frameworks/base/services/core/java/com/android/server/lights/Light.java
JNI
./frameworks/base/services/core/jni/com_android_server_lights_LightsService.cpp
HAL
./vendor/mediatek/proprietary/hardware/liblights/lights.c
kernel
驱动
./kernel-3.18/drivers/misc/mediatek/leds/leds_drv.c
./kernel-3.18/drivers/misc/mediatek/leds/mt6735/leds.c
dts
./kernel-3.18/arch/arm/boot/dts/*.dts
./kernel-3.18/arch/arm64/boot/dts/*.dts
代码分析:
开机kernel -> init进程 –> Zygote进程 –> SystemServer进程 —> LightsService
lightservice start
mSystemServiceManager.startService(LightsService.class); //SystemServer.java
startService(serviceClass)->mServices.add(service)/service.onStart(); //SystemServiceManager.java
public void onStart() {
publishLocalService(LightsManager.class, mService); //LightsService.java
}
private final LightsManager mService = new LightsManager() {
public Light getLight(int id) {
if (id < LIGHT_ID_COUNT) {
return mLights[id];
} else {
return null;
}
}
};
final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT]; //LightsService 成员变量
private final class LightImpl extends Light{ //继承Light类
}
应用使用 lightservice
final LightsManager lights = getLocalService(LightsManager.class); //publishLocalService(LightsManager.class, mService);
mNotificationLight = lights.getLight(LightsManager.LIGHT_ID_NOTIFICATIONS); //获取到LightImpl的实例,
mNotificationLight.setFlashing(ledARGB, Light.LIGHT_FLASH_TIMED,ledOnMS, ledOffMS); //设置亮度