当前位置:   article > 正文

安卓11双屏双背光修改方法_android 双屏幕背光

android 双屏幕背光

安卓11上调双屏异显功能,系统驱动默认支持双背光功能,老一点的系统不支持双背光驱动,所以老版本的双屏异显都是同时控制2个屏的背光,客户也没做特别要求,新版本客户有这个需求了,所以就想办法去实现;底层已经出现了2个背光节点,但是上层就没有做这个功能,硬件上2个背光也是分开的,默认双屏点亮后系统只能调默认原生的那个背光,自己修改节点的背光要想办法去实现,不说了,直接上货:
1.从系统状态栏滑竿调整背光的代码开始追起,

  frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
  public 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.java
    public void setTemporaryBrightness(float brightness) {
        mGlobal.setTemporaryBrightness(brightness);
    }
->   
frameworks/base/core/java/android/hardware/display/DisplayManagerGlobal.java
    public void setTemporaryBrightness(float brightness) {
        try {
            mDm.setTemporaryBrightness(brightness);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

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:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

仅仅按上面改还有个问题,就是背光设置完再切换另一个背光亮度的控制条时候,进度条显示的时钟是上一次进度条设置的值,就是亮度进度条没有反应正确的亮度值,要完美适配各自的亮度进度条指示,修改如下:

Index: frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
===================================================================
--- frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java	(revision 855)
+++ frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java	(working copy)
@@ -47,6 +47,8 @@
 import com.android.settingslib.RestrictedLockUtilsInternal;
 import com.android.systemui.Dependency;
 import com.android.systemui.broadcast.BroadcastDispatcher;
+import android.os.SystemProperties;
+import android.os.yx.YxDeviceManager;
 
 import java.util.ArrayList;
 
@@ -82,6 +84,7 @@
     private final DisplayManager mDisplayManager;
     private final CurrentUserTracker mUserTracker;
     private final IVrManager mVrManager;
+	private YxDeviceManager yx;
 
     private final Handler mBackgroundHandler;
     private final BrightnessObserver mBrightnessObserver;
@@ -96,6 +99,7 @@
     private boolean mControlValueInitialized;
 
     private ValueAnimator mSliderAnimator;
+	private int readBrightness= 0;
 
     public interface BrightnessStateChangeCallback {
         public void onBrightnessLevelChanged();
@@ -116,7 +120,7 @@
         @Override
         public void onChange(boolean selfChange, Uri uri) {
             if (selfChange) return;
-
+            Log.i("fan","onBrightnessLevel Changed");
             if (BRIGHTNESS_MODE_URI.equals(uri)) {
                 mBackgroundHandler.post(mUpdateModeRunnable);
                 mBackgroundHandler.post(mUpdateSliderRunnable);
@@ -238,6 +242,16 @@
         public void run() {
             final float valFloat;
             final boolean inVrMode = mIsVrModeEnabled;
+			int mbacklight = SystemProperties.getInt("persist.sys.backlight",0);
+
+		/*	if(mbacklight==1){
+				Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, yx.getSystemBrightnessExtend());
+			    Log.i("fan","backlight-1 brightness="+yx.getSystemBrightnessExtend());
+			}
+			else{
+				Log.i("fan","backlight brightness="+yx.getSystemBrightness());
+				Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, yx.getSystemBrightness());
+			}*/
             if (inVrMode) {
                 valFloat = Settings.System.getFloatForUser(mContext.getContentResolver(),
                         Settings.System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT, mDefaultBacklightForVr,
@@ -297,10 +311,12 @@
         mContext = context;
         mControl = control;
         mControl.setMax(GAMMA_SPACE_MAX);
+		yx = YxDeviceManager.getInstance(context);
         mBackgroundHandler = new Handler((Looper) Dependency.get(Dependency.BG_LOOPER));
         mUserTracker = new CurrentUserTracker(broadcastDispatcher) {
             @Override
-            public void onUserSwitched(int newUserId) {
+            public void onUserSwitched(int newUserId) {
+               Log.i("fan","onUserSwitched");
                 mBackgroundHandler.post(mUpdateModeRunnable);
                 mBackgroundHandler.post(mUpdateSliderRunnable);
             }
@@ -356,7 +372,7 @@
     public void onChanged(ToggleSlider toggleSlider, boolean tracking, boolean automatic,
             int value, boolean stopTracking) {
         if (mExternalChange) return;
-
+        Log.i("fan","ToggleSlider  onChanged");
         if (mSliderAnimator != null) {
             mSliderAnimator.cancel();
         }
@@ -434,7 +450,8 @@
 
     private void updateSlider(float brightnessValue, boolean inVrMode) {
         final float min;
-        final float max;
+        final float max;
+		float result;
         if (inVrMode) {
             min = mMinimumBacklightForVr;
             max = mMaximumBacklightForVr;
@@ -450,14 +467,31 @@
             return;
         }
         // Returns GAMMA_SPACE_MIN - GAMMA_SPACE_MAX
-        final int sliderVal = convertLinearToGammaFloat(brightnessValue, min, max);
-        animateSliderTo(sliderVal);
+        //Log.i("fan","read brightnessValue="+brightnessValue+"min="+min+"max="+max);
+		int mbacklight = SystemProperties.getInt("persist.sys.backlight",0);
+		if(mbacklight==1){
+		    readBrightness= yx.getSystemBrightnessExtend();
+		    //Log.i("fan","backlight-1 brightness="+readBrightness);
+		}
+		else{
+			readBrightness= yx.getSystemBrightness();
+			//Log.i("fan","backlight brightness="+readBrightness);
+		}
+		 result = (float)(readBrightness/255.0000f);
+		//Log.i("fan","send brightnessValue="+brightnessValue);
+		//brightnessValue = result;
+		//Log.i("fan","read brightnessValue="+result);
+		final int sliderVal = convertLinearToGammaFloat(result, min, max);
+
+		//Log.i("fan","read sliderVal="+sliderVal);
+
+		animateSliderTo(sliderVal);
     }
 
     private void animateSliderTo(int target) {
         if (!mControlValueInitialized) {
             // Don't animate the first value since its default state isn't meaningful to users.
-            mControl.setValue(target);
+			mControl.setValue(target);
             mControlValueInitialized = true;
         }
         if (mSliderAnimator != null && mSliderAnimator.isStarted()) {
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/713791
推荐阅读
相关标签
  

闽ICP备14008679号