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

Commit 747b443d authored by Sahil Sonar's avatar Sahil Sonar 💬
Browse files

Merge branch '1188devices-u-cmf_fp' into 'v2.6-u'

biometrics: Introduce node handling for onPress events

See merge request e/os/android_frameworks_base!251
parents ce55d5df 2dddad26
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6,4 +6,7 @@
<resources>
    <!-- Whether the mobile signal icon pipeline should ignore IWlan status -->
    <bool name="config_mobileIconIgnoresIWlan">false</bool>

    <!-- Boolean to enable/disable the UDFPS onPress node functionality -->
    <bool name="config_enableUdfpsSysfsNodes">false</bool>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@
          <item>4095,0</item>
    </string-array>

    <!-- Array of UDFPS node paths -->
    <string-array name="config_udfpsSysfsNodePaths">
    </string-array>

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

+78 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.hardware.fingerprint.IUdfpsOverlayControllerCallback;
import android.hardware.input.InputManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.os.Trace;
import android.os.VibrationAttributes;
@@ -110,9 +111,14 @@ import dagger.Lazy;

import kotlin.Unit;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

@@ -221,6 +227,52 @@ public class UdfpsController implements DozeReceiver, Dumpable {
    private boolean mAttemptedToDismissKeyguard;
    private final Set<Callback> mCallbacks = new HashSet<>();

    private final boolean mIsUdfpsNodeFeatureEnabled;
    private final List<String> mUdfpsSysfsNodePaths;
    private Handler mHandler;

    private void updateUdfpsNodes(String value) {
        if (!mIsUdfpsNodeFeatureEnabled) {
            Log.d(TAG, "UDFPS node functionality is disabled via overlay.");
            return;
        }

        if (mUdfpsSysfsNodePaths == null || mUdfpsSysfsNodePaths.isEmpty()) {
            Log.e(TAG, "UDFPS node paths are not properly initialized.");
            return;
        }

        for (String path : mUdfpsSysfsNodePaths) {
            writeToUdfpsNode(path, value);
        }
    }

    private void writeToUdfpsNode(String path, String value) {
         mBiometricExecutor.execute(() -> {
             if (isFileWritable(path)) {
                 try (FileWriter writer = new FileWriter(path)) {
                      writer.write(value);
                      Log.d(TAG, "Successfully set " + path + " to " + value);
                 } catch (IOException e) {
                      Log.e(TAG, "Failed to write to " + path, e);
                 }
             }
         });
    }

    private boolean isFileWritable(String path) {
         File file = new File(path);
         if (!file.exists()) {
              Log.e(TAG, "File does not exist: " + path);
              return false;
         }
         if (!file.canWrite()) {
              Log.e(TAG, "File is not writable: " + path);
              return false;
         }
         return true;
    }

    @VisibleForTesting
    public static final VibrationAttributes UDFPS_VIBRATION_ATTRIBUTES =
            new VibrationAttributes.Builder()
@@ -742,6 +794,19 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mSessionTracker = sessionTracker;
        mDeviceEntryUdfpsTouchOverlayViewModel = deviceEntryUdfpsTouchOverlayViewModel;
        mDefaultUdfpsTouchOverlayViewModel = defaultUdfpsTouchOverlayViewModel;
        mHandler = new Handler(Looper.getMainLooper());

        mIsUdfpsNodeFeatureEnabled = mContext.getResources().getBoolean(
            com.android.systemui.res.R.bool.config_enableUdfpsSysfsNodes
        );
        Log.d(TAG, "UDFPS sysfs node feature enabled: " + mIsUdfpsNodeFeatureEnabled);

        mUdfpsSysfsNodePaths = Arrays.asList(
            mContext.getResources().getStringArray(
                com.android.systemui.res.R.array.config_udfpsSysfsNodePaths
            )
        );
        Log.d(TAG, "Initialized UDFPS node paths: " + mUdfpsSysfsNodePaths);

        mDumpManager.registerDumpable(TAG, this);

@@ -857,6 +922,13 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        if (!isOptical()) {
            return;
        }

        // Check if the fingerprint is still pressed before proceeding
        if (mIsUdfpsNodeFeatureEnabled && mOnFingerDown) {
            Log.v(TAG, "Fingerprint is still pressed; skipping unconfigureDisplay.");
            return;
        }

        if (DeviceEntryUdfpsRefactor.isEnabled()) {
            if (mUdfpsDisplayMode != null) {
                mUdfpsDisplayMode.disable(null); // beverlt
@@ -991,6 +1063,9 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mFingerprintManager.onUdfpsUiEvent(FingerprintManager.UDFPS_UI_READY, requestId,
                mSensorProps.sensorId);
        mLatencyTracker.onActionEnd(LatencyTracker.ACTION_UDFPS_ILLUMINATE);
        mHandler.postDelayed(() -> {
            updateUdfpsNodes("1");
        }, 50);
    }

    private void onFingerDown(
@@ -1110,6 +1185,9 @@ public class UdfpsController implements DozeReceiver, Dumpable {
            }
        }
        mOnFingerDown = false;

	updateUdfpsNodes("0");

        unconfigureDisplay(view);
        cancelAodSendFingerUpAction();
    }