diff --git a/common/src/androidMain/AndroidManifest.xml b/common/src/androidMain/AndroidManifest.xml index 76a20ff3..0606131b 100644 --- a/common/src/androidMain/AndroidManifest.xml +++ b/common/src/androidMain/AndroidManifest.xml @@ -1,6 +1,10 @@ + + diff --git a/common/src/androidMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingCredentialProvider.kt b/common/src/androidMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingCredentialProvider.kt index 03c6c704..cb404929 100644 --- a/common/src/androidMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingCredentialProvider.kt +++ b/common/src/androidMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingCredentialProvider.kt @@ -1,26 +1,32 @@ package com.artemchep.keyguard.feature.home.settings.component +import android.content.pm.PackageManager import android.os.Build import androidx.annotation.RequiresApi import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Key import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp import androidx.credentials.CredentialManager import com.artemchep.keyguard.common.io.ioEffect import com.artemchep.keyguard.common.io.launchIn import com.artemchep.keyguard.common.usecase.WindowCoroutineScope -import com.artemchep.keyguard.res.Res import com.artemchep.keyguard.res.* import com.artemchep.keyguard.ui.FlatItem +import com.artemchep.keyguard.ui.FlatSimpleNote +import com.artemchep.keyguard.ui.SimpleNote import com.artemchep.keyguard.ui.icons.ChevronIcon import com.artemchep.keyguard.ui.icons.icon -import org.jetbrains.compose.resources.stringResource +import com.artemchep.keyguard.ui.theme.Dimens import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.flowOf +import org.jetbrains.compose.resources.stringResource import org.kodein.di.DirectDI import org.kodein.di.instance @@ -58,12 +64,22 @@ fun settingCredentialProviderProvider( .create(context) .createSettingsPendingIntent() } + val hasFeature = remember(context) { + val pm = context.packageManager + pm.hasSystemFeature(PackageManager.FEATURE_CREDENTIALS) + } SettingCredentialProvider( - onClick = { - ioEffect(Dispatchers.Main.immediate) { - pi.send() - }.launchIn(windowCoroutineScope) + onClick = if (hasFeature) { + // lambda + { + ioEffect(Dispatchers.Main.immediate) { + pi.send() + }.launchIn(windowCoroutineScope) + } + } else { + null }, + hasFeature = hasFeature, ) } flowOf(item) @@ -72,6 +88,7 @@ fun settingCredentialProviderProvider( @Composable private fun SettingCredentialProvider( onClick: (() -> Unit)?, + hasFeature: Boolean, ) { FlatItem( leading = icon(Icons.Outlined.Key), @@ -90,4 +107,16 @@ private fun SettingCredentialProvider( }, onClick = onClick, ) + if (!hasFeature) { + FlatSimpleNote( + modifier = Modifier + .padding( + top = 8.dp, + bottom = 8.dp, + start = Dimens.horizontalPadding * 1 + 24.dp, + ), + type = SimpleNote.Type.INFO, + text = stringResource(Res.string.pref_item_credential_provider_no_feature_note), + ) + } } \ No newline at end of file diff --git a/common/src/commonMain/composeResources/values/strings.xml b/common/src/commonMain/composeResources/values/strings.xml index 5eda7a41..23e9a87b 100644 --- a/common/src/commonMain/composeResources/values/strings.xml +++ b/common/src/commonMain/composeResources/values/strings.xml @@ -1007,6 +1007,7 @@ Crash Credential provider Passkeys, passwords and data services + The device doesn't support retrieval of user credentials via integration with credential providers. Contact the manufacturer for more information. Privacy policy Contact us Experimental