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

Unverified Commit 1242b2dc authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

HidlFingerprintSensorConfig: Add support for HIDL workaround props

HIDL fingerprint implementations have no way of providing this info.

Change-Id: Ifdb82013fe03a036743fc7a1f6faa93c082ab9f7
parent 6a9e1ac2
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package android.hardware.fingerprint;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.TypedArray;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.common.CommonProps;
@@ -25,16 +27,22 @@ import android.hardware.biometrics.common.SensorStrength;
import android.hardware.biometrics.fingerprint.FingerprintSensorType;
import android.hardware.biometrics.fingerprint.SensorLocation;
import android.hardware.biometrics.fingerprint.SensorProps;
import android.util.Slog;

import com.android.internal.R;
import com.android.internal.util.ArrayUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Parse HIDL fingerprint sensor config and map it to SensorProps.aidl to match AIDL.
 * See core/res/res/values/config.xml config_biometric_sensors
 * @hide
 */
public final class HidlFingerprintSensorConfig extends SensorProps {
    private static final String TAG = "HidlFingerprintSensorConfig";

    private int mSensorId;
    private int mModality;
    private int mStrength;
@@ -70,6 +78,10 @@ public final class HidlFingerprintSensorConfig extends SensorProps {
        halControlsIllumination = false;
        sensorLocations = new SensorLocation[1];

        // Non-empty workaroundLocations indicates that the sensor is SFPS.
        final List<SensorLocation> workaroundLocations =
                getWorkaroundSensorProps(context);

        final int[] udfpsProps = context.getResources().getIntArray(
                com.android.internal.R.array.config_udfps_sensor_props);
        final boolean isUdfps = !ArrayUtils.isEmpty(udfpsProps);
@@ -87,6 +99,9 @@ public final class HidlFingerprintSensorConfig extends SensorProps {

        if (isUdfps && udfpsProps.length == 3) {
            setSensorLocation(udfpsProps[0], udfpsProps[1], udfpsProps[2]);
        } else if (!workaroundLocations.isEmpty()) {
            sensorLocations = new SensorLocation[workaroundLocations.size()];
            workaroundLocations.toArray(sensorLocations);
        } else {
            setSensorLocation(540 /* sensorLocationX */, 1636 /* sensorLocationY */,
                    130 /* sensorRadius */);
@@ -103,6 +118,48 @@ public final class HidlFingerprintSensorConfig extends SensorProps {
        sensorLocations[0].sensorRadius = sensorRadius;
    }

    // TODO(b/174868353): workaround for gaps in HAL interface (remove and get directly from HAL)
    // reads values via an overlay instead of querying the HAL
    @NonNull
    public static List<SensorLocation> getWorkaroundSensorProps(@NonNull Context context) {
        final List<SensorLocation> sensorLocations = new ArrayList<>();

        final TypedArray sfpsProps = context.getResources().obtainTypedArray(
                com.android.internal.R.array.config_sfps_sensor_props);
        for (int i = 0; i < sfpsProps.length(); i++) {
            final int id = sfpsProps.getResourceId(i, -1);
            if (id > 0) {
                final SensorLocation location = parseSensorLocation(
                        context.getResources().obtainTypedArray(id));
                if (location != null) {
                    sensorLocations.add(location);
                }
            }
        }
        sfpsProps.recycle();

        return sensorLocations;
    }

    @Nullable
    private static SensorLocation parseSensorLocation(@Nullable TypedArray array) {
        if (array == null) {
            return null;
        }

        try {
            SensorLocation sensorLocation = new SensorLocation();
            sensorLocation.display = array.getString(0);
            sensorLocation.sensorLocationX = array.getInt(1, 0);
            sensorLocation.sensorLocationY = array.getInt(2, 0);
            sensorLocation.sensorRadius = array.getInt(3, 0);
            return sensorLocation;
        } catch (Exception e) {
            Slog.w(TAG, "malformed sensor location", e);
        }
        return null;
    }

    private byte authenticatorStrengthToPropertyStrength(
            @BiometricManager.Authenticators.Types int strength) {
        switch (strength) {