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

Unverified Commit 56d09f61 authored by Anay Wadhera's avatar Anay Wadhera Committed by LuK1337
Browse files

fixup! SystemUI: Add FingerprintInteractiveToAuthProvider implementation



Co-authored-by: default avatarMichael Bestas <mkbestas@lineageos.org>
Change-Id: Ie21f0acc8ae670dcb81486d8f75b640197d40c25
parent fabbde22
Loading
Loading
Loading
Loading
+0 −47
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 ArrowOS
 *
 * 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.systemui.biometrics;

import android.content.Context;
import android.provider.Settings;

import javax.inject.Inject;

public class FingerprintInteractiveToAuthProviderImpl implements
        FingerprintInteractiveToAuthProvider {

    private final Context mContext;
    private final int mDefaultValue;

    @Inject
    public FingerprintInteractiveToAuthProviderImpl(Context context) {
        mContext = context;
        mDefaultValue = context.getResources().getBoolean(
                org.lineageos.platform.internal.R.bool.config_fingerprintWakeAndUnlock) ? 1 : 0;
    }

    public boolean isEnabled(int userId) {
        int value = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.SFPS_PERFORMANT_AUTH_ENABLED, -1, userId);
        if (value == -1) {
            value = mDefaultValue;
            Settings.Secure.putIntForUser(mContext.getContentResolver(),
                    Settings.Secure.SFPS_PERFORMANT_AUTH_ENABLED, value, userId);
        }
        return value == 0;
    }
}
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 ArrowOS
 *
 * 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.systemui.biometrics

import android.content.Context
import android.database.ContentObserver
import android.hardware.biometrics.common.AuthenticateReason
import android.provider.Settings
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.user.domain.interactor.SelectedUserInteractor
import com.android.systemui.util.settings.SecureSettings
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
import org.lineageos.platform.internal.R.bool.config_fingerprintWakeAndUnlock

class FingerprintInteractiveToAuthProviderImpl @Inject constructor(
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val context: Context,
    private val secureSettings: SecureSettings,
    private val selectedUserInteractor: SelectedUserInteractor,
) : FingerprintInteractiveToAuthProvider {
    private val defaultValue = if (context.resources.getBoolean(config_fingerprintWakeAndUnlock)) {
        1
    } else {
        0
    }

    override val enabledForCurrentUser =
        selectedUserInteractor.selectedUser.flatMapLatest { currentUserId ->
            conflatedCallbackFlow {
                val callback = object : ContentObserver(null) {
                    override fun onChange(selfChange: Boolean) {
                        trySend(isEnabled(currentUserId))
                    }
                }
                secureSettings.registerContentObserver(
                    Settings.Secure.SFPS_PERFORMANT_AUTH_ENABLED, true, callback
                )
                trySend(isEnabled(currentUserId))
                awaitClose { secureSettings.unregisterContentObserver(callback) }
            }
        }
        .flowOn(backgroundDispatcher)

    override fun getVendorExtension(userId: Int): AuthenticateReason.Vendor? = null

    private fun isEnabled(userId: Int): Boolean {
        var value = Settings.Secure.getIntForUser(
            context.contentResolver,
            Settings.Secure.SFPS_PERFORMANT_AUTH_ENABLED,
            -1,
            userId,
        )
        if (value == -1) {
            value = defaultValue
            Settings.Secure.putIntForUser(
                context.contentResolver,
                Settings.Secure.SFPS_PERFORMANT_AUTH_ENABLED,
                value,
                userId,
            )
        }
        return value == 0
    }
}
+18 −4
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.content.res.Resources
import com.android.internal.R
import com.android.systemui.CoreStartable
import com.android.systemui.biometrics.EllipseOverlapDetectorParams
import com.android.systemui.biometrics.FingerprintInteractiveToAuthProvider
import com.android.systemui.biometrics.FingerprintInteractiveToAuthProviderImpl
import com.android.systemui.biometrics.UdfpsUtils
import com.android.systemui.biometrics.data.repository.BiometricStatusRepository
import com.android.systemui.biometrics.data.repository.BiometricStatusRepositoryImpl
@@ -40,9 +42,10 @@ import com.android.systemui.biometrics.udfps.EllipseOverlapDetector
import com.android.systemui.biometrics.udfps.OverlapDetector
import com.android.systemui.biometrics.ui.binder.SideFpsOverlayViewBinder
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.biometrics.FingerprintInteractiveToAuthProvider
import com.android.systemui.biometrics.FingerprintInteractiveToAuthProviderImpl
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.user.domain.interactor.SelectedUserInteractor
import com.android.systemui.util.concurrency.ThreadFactory
import com.android.systemui.util.settings.SecureSettings
import dagger.Binds
import dagger.Module
import dagger.Provides
@@ -50,6 +53,7 @@ import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap
import java.util.concurrent.Executor
import javax.inject.Qualifier
import kotlinx.coroutines.CoroutineDispatcher

/** Dagger module for all things biometric. */
@Module
@@ -120,8 +124,18 @@ interface BiometricsModule {
        }

        @Provides
        fun providesFingerprintInteractiveToAuth(ctx: Context): FingerprintInteractiveToAuthProvider =
            FingerprintInteractiveToAuthProviderImpl(ctx);
        fun providesFingerprintInteractiveToAuth(
            @Background backgroundDispatcher: CoroutineDispatcher,
            context: Context,
            secureSettings: SecureSettings,
            selectedUserInteractor: SelectedUserInteractor,
        ): FingerprintInteractiveToAuthProvider =
            FingerprintInteractiveToAuthProviderImpl(
                backgroundDispatcher,
                context,
                secureSettings,
                selectedUserInteractor,
            )
    }
}