Android9.0手动亮度调节流程

前言

最近在改平台的亮度设置,顺便整理一下亮度调节的过程,使他人能方便理解亮度流程。

Kernel: v4.4.179

Device: rk3328

Platform Version: Android 9.0

流程如下

  1. frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
    1

  2. DisplayManager.java

    public void setTemporaryBrightness(int brightness) {
            mGlobal.setTemporaryBrightness(brightness);
    }
  3. DisplayManagerGlobal.java

    public void setTemporaryBrightness(int brightness) {
        try {
            mDm.setTemporaryBrightness(brightness);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }
  4. DisplayManagerService.java

    public void setTemporaryBrightness(int brightness) {
    ...
          mDisplayPowerController.setTemporaryBrightness(brightness);
    ...
    }
  5. DisplayPowerController.java

    public void setTemporaryBrightness(int brightness) {
        Message msg = mHandler.obtainMessage(MSG_SET_TEMPORARY_BRIGHTNESS,
            brightness, 0 /*unused*/);
            msg.sendToTarget();
    }
    ...
    private void updatePowerState() {
        //此方法比较长,里面有大量的判断,下面只写关键语句
        ...
        animateScreenBrightness(brightness, 0);
        ...
    }
    ...
    private void animateScreenBrightness(int target, int rate) {
        //这一句就是关键的设置语句
        if (mScreenBrightnessRampAnimator.animateTo(target, rate)) {
         }
      }
  6. 下面的就不太好跟了,直接贴图 RampAnimator.java
    1

  7. DisplayPowerState.java
    1

    setScreenBrightness(int brightness){...}
    scheduleScreenUpdate() {...}
    postScreenUpdateThreadSafe(){...}
    Runnable mScreenUpdateRunnable = new Runnable() {
        ...
        mPhotonicModulator.setState(mScreenState, brightness)
        ...
    }
  8. PhotonicModulator.java
    1
    1

  9. 又调回到了DisplayManagerService.java
    1
    1

  10. LocalDisplayAdapter.java
    1
    1

  11. LightsService.java
    1
    1

  12. com_android_server_lights_LightsService.cpp
    1

后记

在这个之后的就是调用hal层的.so库, 根据不同厂商、不同Anroid版本可能实现有所不同。

转载请注明出处:http://www.wolfnx.com/2020/03/16/Brightness-Set-Stream

作者 : wolfnx
邮箱 : wolfnx@outlook.com
邮箱2 : lostnx@gmail.com

Click Me