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

Commit 6d8b2930 authored by Joshua Mccloskey's avatar Joshua Mccloskey Committed by Android (Google) Code Review
Browse files

Merge "Moved FakeFingerprintManagerInteractor" into main

parents 4d71b801 1ec20257
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ android_library {
    ],

    srcs: ["src/**/*.java", "src/**/*.kt"],
    exclude_srcs: [
        "src/com/android/settings/biometrics/fingerprint2/shared/**/*.kt",
    ],
    use_resource_processor: true,
    resource_dirs: [
        "res",
@@ -113,6 +116,7 @@ android_library {
        "SystemUIUnfoldLib",
        "aconfig_settings_flags_lib",
        "android.content.pm.flags-aconfig-java",
        "FingerprintManagerInteractor",
    ],

    plugins: [
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.biometrics.fingerprint2.conversion

import android.hardware.fingerprint.FingerprintManager
import android.hardware.fingerprint.FingerprintSensorProperties
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
import com.android.settings.biometrics.fingerprint2.shared.model.EnrollReason
import com.android.settings.biometrics.fingerprint2.shared.model.FingerprintSensorPropertyViewModel
import com.android.settings.biometrics.fingerprint2.shared.model.SensorStrength
import com.android.settings.biometrics.fingerprint2.shared.model.SensorType

class Util {
  companion object {
    fun sensorPropsToViewModel(
      props: FingerprintSensorPropertiesInternal
    ): FingerprintSensorPropertyViewModel {
      val sensorStrength: SensorStrength =
        when (props.sensorStrength) {
          FingerprintSensorProperties.STRENGTH_CONVENIENCE -> SensorStrength.Convenient
          FingerprintSensorProperties.STRENGTH_WEAK -> SensorStrength.Weak
          FingerprintSensorProperties.STRENGTH_STRONG -> SensorStrength.Strong
          else -> SensorStrength.Unknown
        }
      val sensorType: SensorType =
        when (props.sensorType) {
          FingerprintSensorProperties.TYPE_UDFPS_OPTICAL -> SensorType.Optical
          FingerprintSensorProperties.TYPE_UDFPS_ULTRASONIC -> SensorType.Ultrasonic
          FingerprintSensorProperties.TYPE_REAR -> SensorType.RFPS
          FingerprintSensorProperties.TYPE_POWER_BUTTON -> SensorType.SFPS
          else -> SensorType.Unknown
        }
      return FingerprintSensorPropertyViewModel(
        props.sensorId,
        sensorStrength,
        props.maxEnrollmentsPerUser,
        sensorType
      )
    }
  }

}
fun EnrollReason.toOriginalReason(): Int {
  return when (this) {
    EnrollReason.EnrollEnrolling -> FingerprintManager.ENROLL_ENROLL
    EnrollReason.FindSensor -> FingerprintManager.ENROLL_FIND_SENSOR
  }
}
+10 −59
Original line number Diff line number Diff line
@@ -21,15 +21,16 @@ import android.content.Intent
import android.hardware.fingerprint.FingerprintManager
import android.hardware.fingerprint.FingerprintManager.GenerateChallengeCallback
import android.hardware.fingerprint.FingerprintManager.RemovalCallback
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
import android.os.CancellationSignal
import android.util.Log
import com.android.settings.biometrics.GatekeeperPasswordProvider
import com.android.settings.biometrics.fingerprint2.conversion.Util
import com.android.settings.biometrics.fingerprint2.conversion.toOriginalReason
import com.android.settings.biometrics.fingerprint2.shared.domain.interactor.FingerprintManagerInteractor
import com.android.settings.biometrics.fingerprint2.shared.model.EnrollReason
import com.android.settings.biometrics.fingerprint2.shared.model.FingerprintAuthAttemptViewModel
import com.android.settings.biometrics.fingerprint2.shared.model.FingerprintViewModel
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.EnrollReason
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerEnrollStateViewModel
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.toOriginalReason
import com.android.settings.biometrics.fingerprint2.shared.model.FingerEnrollStateViewModel
import com.android.settings.password.ChooseLockSettingsHelper
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
@@ -45,59 +46,6 @@ import kotlinx.coroutines.withContext

private const val TAG = "FingerprintManagerInteractor"

/** Encapsulates business logic related to managing fingerprints. */
interface FingerprintManagerInteractor {
  /** Returns the list of current fingerprints. */
  val enrolledFingerprints: Flow<List<FingerprintViewModel>>

  /** Returns the max enrollable fingerprints, note during SUW this might be 1 */
  val maxEnrollableFingerprints: Flow<Int>

  /** Returns true if a user can enroll a fingerprint false otherwise. */
  val canEnrollFingerprints: Flow<Boolean>

  /** Retrieves the sensor properties of a device */
  val sensorPropertiesInternal: Flow<FingerprintSensorPropertiesInternal?>

  /** Runs [FingerprintManager.authenticate] */
  suspend fun authenticate(): FingerprintAuthAttemptViewModel

  /**
   * Generates a challenge with the provided [gateKeeperPasswordHandle] and on success returns a
   * challenge and challenge token. This info can be used for secure operations such as
   * [FingerprintManager.enroll]
   *
   * @param gateKeeperPasswordHandle GateKeeper password handle generated by a Confirm
   * @return A [Pair] of the challenge and challenge token
   */
  suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray>

  /**
   * Runs [FingerprintManager.enroll] with the [hardwareAuthToken] and [EnrollReason] for this
   * enrollment. Returning the [FingerEnrollStateViewModel] that represents this fingerprint
   * enrollment state.
   */
  suspend fun enroll(
    hardwareAuthToken: ByteArray?,
    enrollReason: EnrollReason,
  ): Flow<FingerEnrollStateViewModel>

  /**
   * Removes the given fingerprint, returning true if it was successfully removed and false
   * otherwise
   */
  suspend fun removeFingerprint(fp: FingerprintViewModel): Boolean

  /** Renames the given fingerprint if one exists */
  suspend fun renameFingerprint(fp: FingerprintViewModel, newName: String)

  /** Indicates if the device has side fingerprint */
  suspend fun hasSideFps(): Boolean

  /** Indicates if the press to auth feature has been enabled */
  suspend fun pressToAuthEnabled(): Boolean
}

class FingerprintManagerInteractorImpl(
  applicationContext: Context,
  private val backgroundDispatcher: CoroutineDispatcher,
@@ -144,7 +92,10 @@ class FingerprintManagerInteractorImpl(

  override val sensorPropertiesInternal = flow {
    val sensorPropertiesInternal = fingerprintManager.sensorPropertiesInternal
    emit(if (sensorPropertiesInternal.isEmpty()) null else sensorPropertiesInternal.first())
    emit(
      if (sensorPropertiesInternal.isEmpty()) null
      else Util.sensorPropsToViewModel(sensorPropertiesInternal.first())
    )
  }

  override val maxEnrollableFingerprints = flow { emit(maxFingerprints) }
@@ -183,7 +134,7 @@ class FingerprintManagerInteractorImpl(
      cancellationSignal,
      applicationContext.userId,
      enrollmentCallback,
      enrollReason.toOriginalReason()
      enrollReason.toOriginalReason(),
    )
    awaitClose {
      // If the stream has not been ended, and the user has stopped collecting the flow
+13 −0
Original line number Diff line number Diff line
// This  library is mainly used for fakes which will be shared across are various types of tests
// unit/robo/screenshot etc.
//
// This library shouldn't have many dependencies.
android_library {
    name: "FingerprintManagerInteractor",
    srcs: [
      "**/*.kt"
    ],
    static_libs: [
      "kotlinx-coroutines-android",
    ],
}
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2023 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.settings.biometrics.fingerprint2.shared">
</manifest>
Loading