安卓11上调双屏异显功能,系统驱动默认支持双背光功能,老一点的系统不支持双背光驱动,所以老版本的双屏异显都是同时控制2个屏的背光,客户也没做特别要求,新版本客户有这个需求了,所以就想办法去实现;底层已经出现了2个背光节点,但是上层就没有做这个功能,硬件上2个背光也是分开的,默认双屏点亮后系统只能调默认原生的那个背光,自己修改节点的背光要想办法去实现,不说了,直接上货:
1.从系统状态栏滑竿调整背光的代码开始追起,
frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.javapublic void onChanged(ToggleSlider toggleSlider, boolean tracking, boolean automatic,int value, boolean stopTracking) ->final float valFloat = convertGammaToLinearFloat(value,minBacklight, maxBacklight);if (stopTracking) {// TODO(brightnessfloat): change to use float value instead.MetricsLogger.action(mContext, metric,BrightnessSynchronizer.brightnessFloatToInt(mContext, valFloat));}setBrightness(valFloat);private void setBrightness(float brightness) {mDisplayManager.setTemporaryBrightness(brightness);}
->
frameworks/base/core/java/android/hardware/display/DisplayManager.javapublic void setTemporaryBrightness(float brightness) {mGlobal.setTemporaryBrightness(brightness);}
->
frameworks/base/core/java/android/hardware/display/DisplayManagerGlobal.javapublic void setTemporaryBrightness(float brightness) {try {mDm.setTemporaryBrightness(brightness);} catch (RemoteException ex) {throw ex.rethrowFromSystemServer();}}
2.中间代码有兴趣的自己追,我不追了,最终会调用到hal层里面,修改补丁如下:
Index: hardware/rockchip/light_aidl/Android.bp
===================================================================
--- hardware/rockchip/light_aidl/Android.bp (revision 844)
+++ hardware/rockchip/light_aidl/Android.bp (working copy)
@@ -7,6 +7,7 @@shared_libs: ["libbase","liblog",
+ "libcutils", //加这个是为了在cpp文件调用property接口"libbinder_ndk","android.hardware.light-ndk_platform",],
Index: hardware/rockchip/light_aidl/Lights.cpp
===================================================================
--- hardware/rockchip/light_aidl/Lights.cpp (revision 844)
+++ hardware/rockchip/light_aidl/Lights.cpp (working copy)
@@ -23,6 +23,7 @@#include <aidl/android/hardware/light/LightType.h>#include <aidl/android/hardware/light/FlashMode.h>
+#include <cutils/properties.h>using namespace std;@@ -54,9 +55,19 @@}const char* getDriverPath(LightType type) {
+
+switch (type) {case LightType::BACKLIGHT:
- return "/sys/class/backlight/backlight/brightness";
+ char value[PROPERTY_VALUE_MAX];
+ property_get("persist.sys.backlight", value, "");
+
+ if(!strcmp(value,"1")){
+ return "/sys/class/backlight/backlight1/brightness";
+ }
+ else{
+ return "/sys/class/backlight/backlight/brightness";
+ }case LightType::BUTTONS:return "/sys/class/leds/button-backlight/brightness";case LightType::BATTERY: