Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34ba6c09 authored by Santos Cordon's avatar Santos Cordon
Browse files

Add logging for AutomaticBrightness

Adding more readable table for relationship between
lux, nits and display brightness.

  Difference between current config and default:
             lux:  0.00,   1.0,   2.0,   3.0...
         default:   5.1,  10.0,    18,    22...
       long-term:   5.1,  10.0,    18,    22...
         current:   2.3,   3.0,   5.0,   5.8...
     current(bl): 0.000, 0.001, 0.004, 0.005...
      current(%):     0,    14,    24,    32...

Test: adb shell dumpsys display
Bug: 220586744
Change-Id: Idb3df2ae446de1df760907a9f2f7601c41663988
parent 0effa340
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -535,11 +535,11 @@ class AutomaticBrightnessController {
        pw.println("  Idle mode active=" + mCurrentBrightnessMapper.isForIdleMode());

        pw.println();
        pw.println("  mActiveMapper=");
        mInteractiveModeBrightnessMapper.dump(pw);
        pw.println("  mInteractiveMapper=");
        mInteractiveModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax());
        if (mIdleModeBrightnessMapper != null) {
            pw.println("  mIdleMapper=");
            mIdleModeBrightnessMapper.dump(pw);
            mIdleModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax());
        }

        pw.println();
+119 −3
Original line number Diff line number Diff line
@@ -358,7 +358,10 @@ public abstract class BrightnessMappingStrategy {
     */
    public abstract long getShortTermModelTimeout();

    public abstract void dump(PrintWriter pw);
    /**
     * Prints dump output for display dumpsys.
     */
    public abstract void dump(PrintWriter pw, float hbmTransition);

    /**
     * We can designate a mapping strategy to be used for idle screen brightness mode.
@@ -714,7 +717,7 @@ public abstract class BrightnessMappingStrategy {
        }

        @Override
        public void dump(PrintWriter pw) {
        public void dump(PrintWriter pw, float hbmTransition) {
            pw.println("SimpleMappingStrategy");
            pw.println("  mSpline=" + mSpline);
            pw.println("  mMaxGamma=" + mMaxGamma);
@@ -947,7 +950,7 @@ public abstract class BrightnessMappingStrategy {
        }

        @Override
        public void dump(PrintWriter pw) {
        public void dump(PrintWriter pw, float hbmTransition) {
            pw.println("PhysicalMappingStrategy");
            pw.println("  mConfig=" + mConfig);
            pw.println("  mBrightnessSpline=" + mBrightnessSpline);
@@ -959,6 +962,8 @@ public abstract class BrightnessMappingStrategy {
            pw.println("  mUserBrightness=" + mUserBrightness);
            pw.println("  mDefaultConfig=" + mDefaultConfig);
            pw.println("  mBrightnessRangeAdjustmentApplied=" + mBrightnessRangeAdjustmentApplied);

            dumpConfigDiff(pw, hbmTransition);
        }

        @Override
@@ -966,6 +971,117 @@ public abstract class BrightnessMappingStrategy {
            return mIsForIdleMode;
        }

        /**
         * Prints out the default curve and how it differs from the long-term curve
         * and the current curve (in case the current curve includes short-term adjustments).
         *
         * @param pw The print-writer to write to.
         */
        private void dumpConfigDiff(PrintWriter pw, float hbmTransition) {
            pw.println("  Difference between current config and default: ");

            Pair<float[], float[]> currentCurve = mConfig.getCurve();
            Spline currSpline = Spline.createSpline(currentCurve.first, currentCurve.second);

            Pair<float[], float[]> defaultCurve = mDefaultConfig.getCurve();
            Spline defaultSpline = Spline.createSpline(defaultCurve.first, defaultCurve.second);

            // Add the short-term curve lux point if present
            float[] luxes = currentCurve.first;
            if (mUserLux >= 0) {
                luxes = Arrays.copyOf(currentCurve.first, currentCurve.first.length + 1);
                luxes[luxes.length - 1] = mUserLux;
                Arrays.sort(luxes);
            }

            StringBuffer sbLux = null;
            StringBuffer sbNits = null;
            StringBuffer sbLong = null;
            StringBuffer sbShort = null;
            StringBuffer sbBrightness = null;
            StringBuffer sbPercent = null;
            StringBuffer sbPercentHbm = null;
            boolean needsHeaders = true;
            String separator = "";
            for (int i = 0; i < luxes.length; i++) {
                float lux = luxes[i];
                if (needsHeaders) {
                    sbLux = new StringBuffer("           lux: ");
                    sbNits = new StringBuffer("       default: ");
                    sbLong = new StringBuffer("     long-term: ");
                    sbShort = new StringBuffer("       current: ");
                    sbBrightness = new StringBuffer("   current(bl): ");
                    sbPercent = new StringBuffer("    current(%): ");
                    sbPercentHbm = new StringBuffer(" current(%hbm): ");
                    needsHeaders = false;
                }

                float defaultNits = defaultSpline.interpolate(lux);
                float longTermNits = currSpline.interpolate(lux);
                float shortTermNits = mBrightnessSpline.interpolate(lux);
                float brightness = mNitsToBrightnessSpline.interpolate(shortTermNits);

                String luxPrefix = (lux == mUserLux ? "^" : "");
                String strLux = luxPrefix + toStrFloatForDump(lux);
                String strNits = toStrFloatForDump(defaultNits);
                String strLong = toStrFloatForDump(longTermNits);
                String strShort = toStrFloatForDump(shortTermNits);
                String strBrightness = toStrFloatForDump(brightness);
                String strPercent = String.valueOf(
                        Math.round(100.0f * BrightnessUtils.convertLinearToGamma(
                            (brightness / hbmTransition))));
                String strPercentHbm = String.valueOf(
                        Math.round(100.0f * BrightnessUtils.convertLinearToGamma(brightness)));

                int maxLen = Math.max(strLux.length(),
                        Math.max(strNits.length(),
                        Math.max(strBrightness.length(),
                        Math.max(strPercent.length(),
                        Math.max(strPercentHbm.length(),
                        Math.max(strLong.length(), strShort.length()))))));
                String format = separator + "%" + maxLen + "s";
                separator = ", ";

                sbLux.append(String.format(format, strLux));
                sbNits.append(String.format(format, strNits));
                sbLong.append(String.format(format, strLong));
                sbShort.append(String.format(format, strShort));
                sbBrightness.append(String.format(format, strBrightness));
                sbPercent.append(String.format(format, strPercent));
                sbPercentHbm.append(String.format(format, strPercentHbm));

                // At 80 chars, start another row
                if (sbLux.length() > 80 || (i == luxes.length - 1)) {
                    pw.println(sbLux);
                    pw.println(sbNits);
                    pw.println(sbLong);
                    pw.println(sbShort);
                    pw.println(sbBrightness);
                    pw.println(sbPercent);
                    if (hbmTransition < PowerManager.BRIGHTNESS_MAX) {
                        pw.println(sbPercentHbm);
                    }
                    pw.println("");
                    needsHeaders = true;
                    separator = "";
                }
            }
        }

        private String toStrFloatForDump(float value) {
            if (value == 0.0f) {
                return "0";
            } else if (value < 0.1f) {
                return String.format("%.3f", value);
            } else if (value < 1) {
                return String.format("%.2f", value);
            } else if (value < 10) {
                return String.format("%.1f", value);
            } else {
                return String.format("%d", Math.round(value));
            }
        }

        private void computeNitsBrightnessSplines(float[] nits) {
            mNitsToBrightnessSpline = Spline.createSpline(nits, mBrightness);
            mBrightnessToNitsSpline = Spline.createSpline(mBrightness, nits);