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

Commit 077cddb8 authored by Diya Bera's avatar Diya Bera
Browse files

[DO NOT MERGE] Handling power press messages sent from the HAL

Test: Manually checked behavior when power is pressed for:
Biometric Prompt: an error is shown
Keyguard authentication: nothing happens
Fingerprint Enrollment: an acquired message is displayed
atest FingerprintAuthenticationClientTest FingerprintEnrollClientTest
Bug: 265202141

Change-Id: I842115fae9f25387c7d8d5b494336b3fe10c2cb0
parent c07d9725
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6038,6 +6038,12 @@
    <string-array translatable="false" name="config_fontManagerServiceCerts">
    </string-array>

    <!-- Whether the vendor power press code need to be mapped. -->
    <bool name="config_powerPressMapping">false</bool>

    <!-- Power press vendor code. -->
    <integer name="config_powerPressCode">-1</integer>

    <!-- Whether to show weather on the lock screen by default. -->
    <bool name="config_lockscreenWeatherEnabledByDefault">false</bool>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -2644,6 +2644,8 @@
  <java-symbol type="integer" name="config_sideFpsToastTimeout"/>
  <java-symbol type="integer" name="config_sidefpsSkipWaitForPowerAcquireMessage"/>
  <java-symbol type="integer" name="config_sidefpsSkipWaitForPowerVendorAcquireMessage"/>
  <java-symbol type="integer" name="config_powerPressCode"/>
  <java-symbol type="bool" name="config_powerPressMapping"/>

  <!-- Clickable toast used during sidefps enrollment -->
  <java-symbol type="layout" name="side_fps_toast" />
+10 −1
Original line number Diff line number Diff line
@@ -228,7 +228,16 @@ class FingerprintAuthenticationClient extends AuthenticationClient<AidlSession>

    @Override
    public void onError(int errorCode, int vendorCode) {
        if (getContext().getResources().getBoolean(R.bool.config_powerPressMapping)
                && errorCode == BiometricFingerprintConstants.FINGERPRINT_ERROR_VENDOR
                && vendorCode == getContext().getResources()
                .getInteger(R.integer.config_powerPressCode)) {
            // Translating vendor code to internal code
            super.onError(BiometricFingerprintConstants.BIOMETRIC_ERROR_POWER_PRESSED,
                    0 /* vendorCode */);
        } else {
            super.onError(errorCode, vendorCode);
        }

        if (errorCode == BiometricFingerprintConstants.FINGERPRINT_ERROR_BAD_CALIBRATION) {
            BiometricNotificationUtils.showBadCalibrationNotification(getContext());
+13 −5
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.RemoteException;
import android.util.Slog;
import android.view.accessibility.AccessibilityManager;

import com.android.internal.R;
import com.android.server.biometrics.HardwareAuthTokenUtils;
import com.android.server.biometrics.log.BiometricContext;
import com.android.server.biometrics.log.BiometricLogger;
@@ -143,8 +144,18 @@ class FingerprintEnrollClient extends EnrollClient<AidlSession> implements Udfps
            }
        });
        mCallback.onBiometricAction(BiometricStateListener.ACTION_SENSOR_TOUCH);

        if (getContext().getResources().getBoolean(R.bool.config_powerPressMapping)
                && acquiredInfo == BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_VENDOR
                && vendorCode == getContext().getResources()
                .getInteger(R.integer.config_powerPressCode)) {
            // Translating vendor code to internal code
            super.onAcquired(BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_POWER_PRESSED,
                    0 /* vendorCode */);
        } else {
            super.onAcquired(acquiredInfo, vendorCode);
        }
    }

    @Override
    public void onError(int errorCode, int vendorCode) {
@@ -270,8 +281,5 @@ class FingerprintEnrollClient extends EnrollClient<AidlSession> implements Udfps
    }

    @Override
    public void onPowerPressed() {
        onAcquired(BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_POWER_PRESSED,
                0 /* vendorCode */);
    }
    public void onPowerPressed() {}
}
+19 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.biometrics.sensors.fingerprint.aidl;

import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ERROR_VENDOR;

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

import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -35,6 +37,7 @@ import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.content.ComponentName;
import android.hardware.biometrics.BiometricFingerprintConstants;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.common.ICancellationSignal;
import android.hardware.biometrics.common.OperationContext;
@@ -54,6 +57,7 @@ import android.testing.TestableContext;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.internal.R;
import com.android.server.biometrics.log.BiometricContext;
import com.android.server.biometrics.log.BiometricLogger;
import com.android.server.biometrics.log.CallbackWithProbe;
@@ -335,6 +339,21 @@ public class FingerprintAuthenticationClientTest {
        showHideOverlay(c -> c.onLockoutPermanent());
    }

    @Test
    public void testPowerPressForwardsErrorMessage() throws RemoteException {
        final FingerprintAuthenticationClient client = createClient();
        final int testVendorPowerPressCode = 1;
        when(mContext.getOrCreateTestableResources().getResources()
                .getBoolean(R.bool.config_powerPressMapping)).thenReturn(true);
        when(mContext.getOrCreateTestableResources().getResources()
                .getInteger(R.integer.config_powerPressCode)).thenReturn(testVendorPowerPressCode);

        client.onError(FINGERPRINT_ERROR_VENDOR, testVendorPowerPressCode);

        verify(mClientMonitorCallbackConverter).onError(anyInt(), anyInt(),
                eq(BiometricFingerprintConstants.BIOMETRIC_ERROR_POWER_PRESSED), anyInt());
    }

    private void showHideOverlay(Consumer<FingerprintAuthenticationClient> block)
            throws RemoteException {
        final FingerprintAuthenticationClient client = createClient();
Loading