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

Commit 4add2548 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Call getSensorProps only after filtering" into main

parents a3f69da9 ed9bd910
Loading
Loading
Loading
Loading
+41 −33
Original line number Diff line number Diff line
@@ -22,11 +22,12 @@ import android.annotation.Nullable;
import android.content.Context;
import android.hardware.biometrics.face.IFace;
import android.hardware.biometrics.face.SensorProps;
import android.os.Binder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;

import androidx.annotation.NonNull;
@@ -36,7 +37,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
 * Provides the sensor props for face sensor, if available.
@@ -74,22 +74,10 @@ public class FaceSensorConfigurations implements Parcelable {
    /**
     * Process AIDL instances to extract sensor props and add it to the sensor map.
     * @param aidlInstances available face AIDL instances
     * @param getIFace function that provides the daemon for the specific instance
     */
    public void addAidlConfigs(@NonNull String[] aidlInstances,
            @NonNull Function<String, IFace> getIFace) {
    public void addAidlConfigs(@NonNull String[] aidlInstances) {
        for (String aidlInstance : aidlInstances) {
            final String fqName = IFace.DESCRIPTOR + "/" + aidlInstance;
            IFace face = getIFace.apply(fqName);
            try {
                if (face != null) {
                    mSensorPropsMap.put(aidlInstance, face.getSensorProps());
                } else {
                    Slog.e(TAG, "Unable to get declared service: " + fqName);
                }
            } catch (RemoteException e) {
                Log.d(TAG, "Unable to get sensor properties!");
            }
            mSensorPropsMap.put(aidlInstance, null);
        }
    }

@@ -131,38 +119,31 @@ public class FaceSensorConfigurations implements Parcelable {
    }

    /**
     * Return sensor props for the given instance. If instance is not available,
     * then null is returned.
     * Checks if {@param instance} exists.
     */
    @Nullable
    public Pair<String, SensorProps[]> getSensorPairForInstance(String instance) {
        if (mSensorPropsMap.containsKey(instance)) {
            return new Pair<>(instance, mSensorPropsMap.get(instance));
        }

        return null;
    public boolean doesInstanceExist(String instance) {
        return mSensorPropsMap.containsKey(instance);
    }

    /**
     * Return the first pair of instance and sensor props, which does not correspond to the given
     * If instance is not available, then null is returned.
     * Return the first HAL instance, which does not correspond to the given {@param instance}.
     * If another instance is not available, then null is returned.
     */
    @Nullable
    public Pair<String, SensorProps[]> getSensorPairNotForInstance(String instance) {
    public String getSensorNameNotForInstance(String instance) {
        Optional<String> notAVirtualInstance = mSensorPropsMap.keySet().stream().filter(
                (instanceName) -> !instanceName.equals(instance)).findFirst();
        return notAVirtualInstance.map(this::getSensorPairForInstance).orElseGet(
                this::getSensorPair);
        return notAVirtualInstance.orElse(null);
    }

    /**
     * Returns the first pair of instance and sensor props that has been added to the map.
     * Returns the first instance that has been added to the map.
     */
    @Nullable
    public Pair<String, SensorProps[]> getSensorPair() {
    public String getSensorInstance() {
        Optional<String> optionalInstance = mSensorPropsMap.keySet().stream().findFirst();
        return optionalInstance.map(this::getSensorPairForInstance).orElse(null);

        return optionalInstance.orElse(null);
    }

    public boolean getResetLockoutRequiresChallenge() {
@@ -179,4 +160,31 @@ public class FaceSensorConfigurations implements Parcelable {
        dest.writeByte((byte) (mResetLockoutRequiresChallenge ? 1 : 0));
        dest.writeMap(mSensorPropsMap);
    }

    /**
     * Returns face sensor props for the HAL {@param instance}.
     */
    @Nullable
    public SensorProps[] getSensorPropForInstance(String instance) {
        SensorProps[] props = mSensorPropsMap.get(instance);

        //Props should not be null for HIDL configs
        if (props != null) {
            return props;
        }

        final String fqName = IFace.DESCRIPTOR + "/" + instance;
        IFace face = IFace.Stub.asInterface(Binder.allowBlocking(
                ServiceManager.waitForDeclaredService(fqName)));
        try {
            if (face != null) {
                props = face.getSensorProps();
            } else {
                Slog.e(TAG, "Unable to get declared service: " + fqName);
            }
        } catch (RemoteException e) {
            Log.d(TAG, "Unable to get sensor properties!");
        }
        return props;
    }
}
+41 −34
Original line number Diff line number Diff line
@@ -23,18 +23,18 @@ import android.annotation.Nullable;
import android.content.Context;
import android.hardware.biometrics.fingerprint.IFingerprint;
import android.hardware.biometrics.fingerprint.SensorProps;
import android.os.Binder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.util.Pair;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
 * Provides the sensor props for fingerprint sensor, if available.
@@ -68,23 +68,10 @@ public class FingerprintSensorConfigurations implements Parcelable {
    /**
     * Process AIDL instances to extract sensor props and add it to the sensor map.
     * @param aidlInstances available face AIDL instances
     * @param getIFingerprint function that provides the daemon for the specific instance
     */
    public void addAidlSensors(@NonNull String[] aidlInstances,
            @NonNull Function<String, IFingerprint> getIFingerprint) {
    public void addAidlSensors(@NonNull String[] aidlInstances) {
        for (String aidlInstance : aidlInstances) {
            try {
                final String fqName = IFingerprint.DESCRIPTOR + "/" + aidlInstance;
                final IFingerprint fp = getIFingerprint.apply(fqName);
                if (fp != null) {
                    SensorProps[] props = fp.getSensorProps();
                    mSensorPropsMap.put(aidlInstance, props);
                } else {
                    Log.d(TAG, "IFingerprint null for instance " + aidlInstance);
                }
            } catch (RemoteException e) {
                Log.d(TAG, "Unable to get sensor properties!");
            }
            mSensorPropsMap.put(aidlInstance, null);
        }
    }

@@ -133,38 +120,31 @@ public class FingerprintSensorConfigurations implements Parcelable {
    }

    /**
     * Return sensor props for the given instance. If instance is not available,
     * then null is returned.
     * Checks if {@param instance} exists.
     */
    @Nullable
    public Pair<String, SensorProps[]> getSensorPairForInstance(String instance) {
        if (mSensorPropsMap.containsKey(instance)) {
            return new Pair<>(instance, mSensorPropsMap.get(instance));
        }

        return null;
    public boolean doesInstanceExist(String instance) {
        return mSensorPropsMap.containsKey(instance);
    }

    /**
     * Return the first pair of instance and sensor props, which does not correspond to the given
     * If instance is not available, then null is returned.
     * Return the first HAL instance, which does not correspond to the given {@param instance}.
     * If another instance is not available, then null is returned.
     */
    @Nullable
    public Pair<String, SensorProps[]> getSensorPairNotForInstance(String instance) {
    public String getSensorNameNotForInstance(String instance) {
        Optional<String> notAVirtualInstance = mSensorPropsMap.keySet().stream().filter(
                (instanceName) -> !instanceName.equals(instance)).findFirst();
        return notAVirtualInstance.map(this::getSensorPairForInstance).orElseGet(
                this::getSensorPair);
        return notAVirtualInstance.orElse(null);
    }

    /**
     * Returns the first pair of instance and sensor props that has been added to the map.
     * Returns the first instance that has been added to the map.
     */
    @Nullable
    public Pair<String, SensorProps[]> getSensorPair() {
    public String getSensorInstance() {
        Optional<String> optionalInstance = mSensorPropsMap.keySet().stream().findFirst();
        return optionalInstance.map(this::getSensorPairForInstance).orElse(null);

        return optionalInstance.orElse(null);
    }

    public boolean getResetLockoutRequiresHardwareAuthToken() {
@@ -181,4 +161,31 @@ public class FingerprintSensorConfigurations implements Parcelable {
        dest.writeByte((byte) (mResetLockoutRequiresHardwareAuthToken ? 1 : 0));
        dest.writeMap(mSensorPropsMap);
    }

    /**
     * Returns fingerprint sensor props for the HAL {@param instance}.
     */
    @Nullable
    public SensorProps[] getSensorPropForInstance(String instance) {
        SensorProps[] props = mSensorPropsMap.get(instance);

        //Props should not be null for HIDL configs
        if (props != null) {
            return props;
        }

        try {
            final String fqName = IFingerprint.DESCRIPTOR + "/" + instance;
            final IFingerprint fp = IFingerprint.Stub.asInterface(Binder.allowBlocking(
                    ServiceManager.waitForDeclaredService(fqName)));
            if (fp != null) {
                props = fp.getSensorProps();
            } else {
                Log.d(TAG, "IFingerprint null for instance " + instance);
            }
        } catch (RemoteException e) {
            Log.d(TAG, "Unable to get sensor properties!");
        }
        return props;
    }
}
+1 −12
Original line number Diff line number Diff line
@@ -18,13 +18,10 @@ package android.hardware.face;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.hardware.biometrics.face.IFace;
import android.hardware.biometrics.face.SensorProps;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;

@@ -37,8 +34,6 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.util.function.Function;

@Presubmit
@SmallTest
public class FaceSensorConfigurationsTest {
@@ -48,10 +43,6 @@ public class FaceSensorConfigurationsTest {
    private Context mContext;
    @Mock
    private Resources mResources;
    @Mock
    private IFace mFace;
    @Mock
    private Function<String, IFace> mGetIFace;

    private final String[] mAidlInstances = new String[]{"default", "virtual"};
    private String[] mHidlConfigStrings = new String[]{"0:2:15", "0:8:15"};
@@ -59,15 +50,13 @@ public class FaceSensorConfigurationsTest {

    @Before
    public void setUp() throws RemoteException {
        when(mGetIFace.apply(anyString())).thenReturn(mFace);
        when(mFace.getSensorProps()).thenReturn(new SensorProps[]{});
        when(mContext.getResources()).thenReturn(mResources);
    }

    @Test
    public void testAidlInstanceSensorProps() {
        mFaceSensorConfigurations = new FaceSensorConfigurations(false);
        mFaceSensorConfigurations.addAidlConfigs(mAidlInstances, mGetIFace);
        mFaceSensorConfigurations.addAidlConfigs(mAidlInstances);

        assertThat(mFaceSensorConfigurations.hasSensorConfigurations()).isTrue();
        assertThat(!mFaceSensorConfigurations.isSingleSensorConfigurationPresent()).isTrue();
+1 −12
Original line number Diff line number Diff line
@@ -18,13 +18,10 @@ package android.hardware.fingerprint;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.hardware.biometrics.fingerprint.IFingerprint;
import android.hardware.biometrics.fingerprint.SensorProps;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;

@@ -37,8 +34,6 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.util.function.Function;

@Presubmit
@SmallTest
public class FingerprintSensorConfigurationsTest {
@@ -48,10 +43,6 @@ public class FingerprintSensorConfigurationsTest {
    private Context mContext;
    @Mock
    private Resources mResources;
    @Mock
    private IFingerprint mFingerprint;
    @Mock
    private Function<String, IFingerprint> mGetIFingerprint;

    private final String[] mAidlInstances = new String[]{"default", "virtual"};
    private String[] mHidlConfigStrings = new String[]{"0:2:15", "0:8:15"};
@@ -59,8 +50,6 @@ public class FingerprintSensorConfigurationsTest {

    @Before
    public void setUp() throws RemoteException {
        when(mGetIFingerprint.apply(anyString())).thenReturn(mFingerprint);
        when(mFingerprint.getSensorProps()).thenReturn(new SensorProps[]{});
        when(mContext.getResources()).thenReturn(mResources);
    }

@@ -68,7 +57,7 @@ public class FingerprintSensorConfigurationsTest {
    public void testAidlInstanceSensorProps() {
        mFingerprintSensorConfigurations = new FingerprintSensorConfigurations(
                true /* resetLockoutRequiresHardwareAuthToken */);
        mFingerprintSensorConfigurations.addAidlSensors(mAidlInstances, mGetIFingerprint);
        mFingerprintSensorConfigurations.addAidlSensors(mAidlInstances);

        assertThat(mFingerprintSensorConfigurations.hasSensorConfigurations()).isTrue();
        assertThat(!mFingerprintSensorConfigurations.isSingleSensorConfigurationPresent())
+2 −6
Original line number Diff line number Diff line
@@ -869,9 +869,7 @@ public class AuthService extends SystemService {
            }

            if (faceAidlInstances != null && faceAidlInstances.length > 0) {
                mFaceSensorConfigurations.addAidlConfigs(faceAidlInstances,
                        name -> IFace.Stub.asInterface(Binder.allowBlocking(
                                ServiceManager.waitForDeclaredService(name))));
                mFaceSensorConfigurations.addAidlConfigs(faceAidlInstances);
            }

            if (faceService != null) {
@@ -909,9 +907,7 @@ public class AuthService extends SystemService {
            }

            if (fingerprintAidlInstances != null && fingerprintAidlInstances.length > 0) {
                mFingerprintSensorConfigurations.addAidlSensors(fingerprintAidlInstances,
                        name -> IFingerprint.Stub.asInterface(Binder.allowBlocking(
                                ServiceManager.waitForDeclaredService(name))));
                mFingerprintSensorConfigurations.addAidlSensors(fingerprintAidlInstances);
            }

            if (fingerprintService != null) {
Loading