源码:
base\services\core\java\com\android\server\lights\LightsService.java
功能:
1:构造了setBrightness接口函数供调用
2:发布了一个本地服务供使用
源码分析:
发布了本地服务,该本地服务中包含getLight方法
public void onStart() { publishLocalService(LightsManager.class, mService); }
private final LightsManager mService = new LightsManager() { public com.android.server.lights.Light getLight(int id) { if (id < LIGHT_ID_COUNT) return mLights[id]; } };
LightsService构造函数:
调用JNI的init方法
public LightsService(Context context) { super(context); // 调用jni方法 mNativePointer = init_native(); for (int i = 0; i < LightsManager.LIGHT_ID_COUNT; i++) { mLights[i] = new LightImpl(i); } }
setBrightness:
传入brightness参数调用JNI的setLight方法进行背光调节
public void setBrightness(int brightness) setBrightness(brightness, BRIGHTNESS_MODE_USER); setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode); setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode); // JNI