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

Commit a389ceb8 authored by pjgowtham's avatar pjgowtham Committed by Bruno Martins
Browse files

SystemUI: Remove udfps fwk dimming support

This will be replaced with a superior and less intrusive solution.

Change-Id: I32ddad5d5cd433b9a53d6e2a5880d82c185d7f6d
parent 2744c92a
Loading
Loading
Loading
Loading
+0 −36
Original line number Original line Diff line number Diff line
@@ -18,42 +18,6 @@
    <!-- Color of the UDFPS pressed view -->
    <!-- Color of the UDFPS pressed view -->
    <color name="config_udfpsColor">#ffffffff</color>
    <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? -->
    <!-- Doze: does the double tap sensor need a proximity check? -->
    <bool name="doze_double_tap_proximity_check">false</bool>
    <bool name="doze_double_tap_proximity_check">false</bool>


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


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

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


        initUdfpsFrameworkDimming();

        final IntentFilter filter = new IntentFilter();
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        context.registerReceiver(mBroadcastReceiver, filter,
        context.registerReceiver(mBroadcastReceiver, filter,
@@ -989,64 +983,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        return mSensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
        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() {
    public boolean isFingerDown() {
        return mOnFingerDown;
        return mOnFingerDown;
    }
    }
@@ -1055,7 +991,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mFingerprintManager.onUdfpsUiEvent(FingerprintManager.UDFPS_UI_READY, requestId,
        mFingerprintManager.onUdfpsUiEvent(FingerprintManager.UDFPS_UI_READY, requestId,
                mSensorProps.sensorId);
                mSensorProps.sensorId);
        mLatencyTracker.onActionEnd(LatencyTracker.ACTION_UDFPS_ILLUMINATE);
        mLatencyTracker.onActionEnd(LatencyTracker.ACTION_UDFPS_ILLUMINATE);
        updateViewDimAmount();
    }
    }


    private void onFingerDown(
    private void onFingerDown(
@@ -1177,23 +1112,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mOnFingerDown = false;
        mOnFingerDown = false;
        unconfigureDisplay(view);
        unconfigureDisplay(view);
        cancelAodSendFingerUpAction();
        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();
        }
    }
    }


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


    private var overlayTouchListener: TouchExplorationStateChangeListener? = null
    private var overlayTouchListener: TouchExplorationStateChangeListener? = null


    private val frameworkDimming = context.getResources().getBoolean(
        R.bool.config_udfpsFrameworkDimming)
    private val coreLayoutParams = WindowManager.LayoutParams(
    private val coreLayoutParams = WindowManager.LayoutParams(
        WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
        WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
        0 /* flags set in computeLayoutParams() */,
        0 /* flags set in computeLayoutParams() */,
@@ -171,23 +169,12 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
        layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
        layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
        flags = (Utils.FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS or
        flags = (Utils.FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS or
                WindowManager.LayoutParams.FLAG_SPLIT_TOUCH)
                WindowManager.LayoutParams.FLAG_SPLIT_TOUCH)
        if (frameworkDimming) {
            flags = flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
        }
        privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY
        privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY
        dimAmount = 0.0f
        // Avoid announcing window title.
        // Avoid announcing window title.
        accessibilityTitle = " "
        accessibilityTitle = " "
        inputFeatures = WindowManager.LayoutParams.INPUT_FEATURE_SPY
        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. */
    /** If the overlay is currently showing. */
    val isShowing: Boolean
    val isShowing: Boolean
        get() = getTouchOverlay() != null
        get() = getTouchOverlay() != null