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

Commit b3bd0657 authored by Sahil Sonar's avatar Sahil Sonar 💬
Browse files

Revert "SystemUI: Remove udfps fwk dimming support"

This reverts commit a389ceb8.
parent 94d0d8f6
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -18,6 +18,42 @@
    <!-- Color of the UDFPS pressed view -->
    <color name="config_udfpsColor">#ffffffff</color>

    <!-- Whether to enable framework dimming for UDFPS -->
    <bool name="config_udfpsFrameworkDimming">false</bool>

    <!-- Array of brightness-alpha LUT for framework dimming -->
    <string-array name="config_udfpsDimmingBrightnessAlphaArray" translatable="false">
          <!-- Example:
          <item>0,255</item>
          <item>1,234</item>
          <item>3,227</item>
          <item>8,208</item>
          <item>16,192</item>
          <item>27,176</item>
          <item>41,160</item>
          <item>61,144</item>
          <item>80,128</item>
          <item>104,112</item>
          <item>130,96</item>
          <item>158,80</item>
          <item>188,64</item>
          <item>221,48</item>
          <item>250,36</item>
          <item>255,33</item>
          -->
    </string-array>

    <!-- Brightness range min for UDFPS dimming -->
    <integer name="config_udfpsDimmingBrightnessMin">0</integer>

    <!-- Brightness range max for UDFPS dimming -->
    <integer name="config_udfpsDimmingBrightnessMax">0</integer>

    <!-- The amount of delay to add when disabling the dimming.
         This is used to prevent flickers due to the dimming being disabled
         before the screen has had chance to switch out of HBM mode -->
    <integer name="config_udfpsDimmingDisableDelay">0</integer>

    <!-- Doze: does the double tap sensor need a proximity check? -->
    <bool name="doze_double_tap_proximity_check">false</bool>

+82 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.os.PowerManager;
import android.os.Trace;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.provider.Settings;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
@@ -221,6 +222,9 @@ public class UdfpsController implements DozeReceiver, Dumpable {
    private boolean mAttemptedToDismissKeyguard;
    private final Set<Callback> mCallbacks = new HashSet<>();

    private boolean mUseFrameworkDimming;
    private int[][] mBrightnessAlphaArray;

    @VisibleForTesting
    public static final VibrationAttributes UDFPS_VIBRATION_ATTRIBUTES =
            new VibrationAttributes.Builder()
@@ -761,6 +765,8 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        final UdfpsOverlayController mUdfpsOverlayController = new UdfpsOverlayController();
        mFingerprintManager.setUdfpsOverlayController(mUdfpsOverlayController);

        initUdfpsFrameworkDimming();

        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        context.registerReceiver(mBroadcastReceiver, filter,
@@ -983,6 +989,64 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        return mSensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
    }

    private void initUdfpsFrameworkDimming() {
        mUseFrameworkDimming = mContext.getResources().getBoolean(
                com.android.systemui.res.R.bool.config_udfpsFrameworkDimming);

        if (mUseFrameworkDimming) {
            String[] array = mContext.getResources().getStringArray(
                    com.android.systemui.res.R.array.config_udfpsDimmingBrightnessAlphaArray);
            mBrightnessAlphaArray = new int[array.length][2];
            for (int i = 0; i < array.length; i++) {
                String[] s = array[i].split(",");
                mBrightnessAlphaArray[i][0] = Integer.parseInt(s[0]);
                mBrightnessAlphaArray[i][1] = Integer.parseInt(s[1]);
            }
        }
    }

    private static int interpolate(int x, int xa, int xb, int ya, int yb) {
        return ya - (ya - yb) * (x - xa) / (xb - xa);
    }

    private int getBrightness() {
        int brightness = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, 100);
        // Since the brightness is taken from the system settings, we need to interpolate it
        final int brightnessMin = mContext.getResources().getInteger(
                com.android.systemui.res.R.integer.config_udfpsDimmingBrightnessMin);
        final int brightnessMax = mContext.getResources().getInteger(
                com.android.systemui.res.R.integer.config_udfpsDimmingBrightnessMax);
        if (brightnessMax > 0) {
            brightness = interpolate(brightness, 0, 255, brightnessMin, brightnessMax);
        }
        return brightness;
    }

    private void updateViewDimAmount() {
        if (mOverlay == null || !mUseFrameworkDimming) {
            return;
        } else if (isFingerDown()) {
            int curBrightness = getBrightness();
            int i, dimAmount;
            for (i = 0; i < mBrightnessAlphaArray.length; i++) {
                if (mBrightnessAlphaArray[i][0] >= curBrightness) break;
            }
            if (i == 0) {
                dimAmount = mBrightnessAlphaArray[i][1];
            } else if (i == mBrightnessAlphaArray.length) {
                dimAmount = mBrightnessAlphaArray[i-1][1];
            } else {
                dimAmount = interpolate(curBrightness,
                        mBrightnessAlphaArray[i][0], mBrightnessAlphaArray[i-1][0],
                        mBrightnessAlphaArray[i][1], mBrightnessAlphaArray[i-1][1]);
            }
            mOverlay.setDimAmount(dimAmount / 255.0f);
        } else {
            mOverlay.setDimAmount(0.0f);
        }
    }

    public boolean isFingerDown() {
        return mOnFingerDown;
    }
@@ -991,6 +1055,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mFingerprintManager.onUdfpsUiEvent(FingerprintManager.UDFPS_UI_READY, requestId,
                mSensorProps.sensorId);
        mLatencyTracker.onActionEnd(LatencyTracker.ACTION_UDFPS_ILLUMINATE);
        updateViewDimAmount();
    }

    private void onFingerDown(
@@ -1112,6 +1177,23 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mOnFingerDown = false;
        unconfigureDisplay(view);
        cancelAodSendFingerUpAction();

        // Add a delay to ensure that the dim amount is updated after the display has had chance
        // to switch out of HBM mode. The delay, in ms is stored in config_udfpsDimmingDisableDelay.
        // If the delay is 0, the dim amount will be updated immediately.
        final int delay = mContext.getResources().getInteger(
                com.android.systemui.res.R.integer.config_udfpsDimmingDisableDelay);
        if (delay > 0) {
            mFgExecutor.executeDelayed(() -> {
                // A race condition exists where the overlay is destroyed before the dim amount
                // is updated. This check ensures that the overlay is still valid.
                if (mOverlay != null && mOverlay.matchesRequestId(requestId)) {
                    updateViewDimAmount();
                }
            }, delay);
        } else {
            updateViewDimAmount();
        }
    }

    /**
+13 −0
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ class UdfpsControllerOverlay @JvmOverloads constructor(

    private var overlayTouchListener: TouchExplorationStateChangeListener? = null

    private val frameworkDimming = context.getResources().getBoolean(
        R.bool.config_udfpsFrameworkDimming)
    private val coreLayoutParams = WindowManager.LayoutParams(
        WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
        0 /* flags set in computeLayoutParams() */,
@@ -169,12 +171,23 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
        layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
        flags = (Utils.FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS or
                WindowManager.LayoutParams.FLAG_SPLIT_TOUCH)
        if (frameworkDimming) {
            flags = flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
        }
        privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY
        dimAmount = 0.0f
        // Avoid announcing window title.
        accessibilityTitle = " "
        inputFeatures = WindowManager.LayoutParams.INPUT_FEATURE_SPY
    }

    var dimAmount
        get() = coreLayoutParams.dimAmount
        set(value) {
            coreLayoutParams.dimAmount = value
            windowManager.updateViewLayout(getTouchOverlay(), coreLayoutParams)
        }

    /** If the overlay is currently showing. */
    val isShowing: Boolean
        get() = getTouchOverlay() != null