Address several small lint warning throughout the app (#6233)

This commit is contained in:
David Perez
2025-12-05 11:47:52 -06:00
committed by GitHub
parent ca13e615ec
commit 127809b8df
20 changed files with 34 additions and 52 deletions

View File

@@ -28,7 +28,6 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.isActive
import java.time.Clock
import javax.inject.Singleton
import kotlin.coroutines.coroutineContext
private const val PASSWORDLESS_NOTIFICATION_TIMEOUT_MILLIS: Long = 15L * 60L * 1_000L
private const val PASSWORDLESS_NOTIFICATION_RETRY_INTERVAL_MILLIS: Long = 4L * 1_000L
@@ -163,7 +162,7 @@ class AuthRequestManagerImpl(
emit(result)
if (result is AuthRequestUpdatesResult.Error) return@flow
var isComplete = false
while (coroutineContext.isActive && !isComplete) {
while (currentCoroutineContext().isActive && !isComplete) {
delay(PASSWORDLESS_APPROVER_INTERVAL_MILLIS)
val updateResult = result as AuthRequestUpdatesResult.Update
authRequestsService

View File

@@ -1356,10 +1356,10 @@ class AuthRepositoryImpl(
)
.fold(
onSuccess = {
when (val json = it) {
when (it) {
VerifyEmailTokenResponseJson.Valid -> EmailTokenResult.Success
is VerifyEmailTokenResponseJson.Invalid -> {
EmailTokenResult.Error(message = json.message, error = null)
EmailTokenResult.Error(message = it.message, error = null)
}
VerifyEmailTokenResponseJson.TokenExpired -> EmailTokenResult.Expired

View File

@@ -1,7 +1,7 @@
package com.x8bit.bitwarden.data.auth.util
import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
import com.x8bit.bitwarden.data.platform.manager.model.CompleteRegistrationData
/**
@@ -14,7 +14,7 @@ fun Intent.getCompleteRegistrationDataIntentOrNull(): CompleteRegistrationData?
newValue = "/",
ignoreCase = true,
)
val uri = runCatching { Uri.parse(sanitizedUriString) }.getOrNull() ?: return null
val uri = runCatching { sanitizedUriString.toUri() }.getOrNull() ?: return null
uri.host ?: return null
if (uri.path != "/finish-signup") return null
val email = uri.getQueryParameter("email") ?: return null

View File

@@ -1,6 +1,7 @@
package com.x8bit.bitwarden.data.autofill.accessibility.util
import android.net.Uri
import androidx.core.net.toUri
import com.bitwarden.annotation.OmitFromCoverage
import java.net.URISyntaxException
@@ -10,7 +11,7 @@ import java.net.URISyntaxException
@OmitFromCoverage
fun String.toUriOrNull(): Uri? =
try {
Uri.parse(this)
} catch (e: URISyntaxException) {
this.toUri()
} catch (_: URISyntaxException) {
null
}

View File

@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.auth.feature.enterprisesignon
import android.net.Uri
import android.os.Parcelable
import androidx.core.net.toUri
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.bitwarden.data.repository.util.baseIdentityUrl
@@ -400,7 +401,7 @@ class EnterpriseSignOnViewModel @Inject constructor(
// Hide any dialog since we're about to launch a custom tab and could return without getting
// a result due to user intervention
sendAction(EnterpriseSignOnAction.Internal.OnGenerateUriForSsoResult(Uri.parse(uri)))
sendAction(EnterpriseSignOnAction.Internal.OnGenerateUriForSsoResult(uri.toUri()))
}
private fun showError(

View File

@@ -185,7 +185,7 @@ class TwoFactorLoginViewModel @Inject constructor(
// The url should not be empty unless the environment is somehow not supported.
authUrl
?.let {
sendEvent(event = TwoFactorLoginEvent.NavigateToDuo(uri = Uri.parse(it)))
sendEvent(event = TwoFactorLoginEvent.NavigateToDuo(uri = it.toUri()))
}
?: mutableStateFlow.update {
it.copy(

View File

@@ -257,7 +257,7 @@ private fun LoginUriView.toUriData() =
isLaunchable = !uri.isNullOrBlank(),
)
private fun Fido2Credential.getCreationDateText(clock: Clock): Text? =
private fun Fido2Credential.getCreationDateText(clock: Clock): Text =
BitwardenString.created_x.asText(
this.creationDate.toFormattedDateTimeStyle(
dateStyle = FormatStyle.MEDIUM,

View File

@@ -1,6 +1,6 @@
package com.x8bit.bitwarden.ui.vault.feature.vault.util
import android.net.Uri
import androidx.core.net.toUri
import com.bitwarden.collections.CollectionView
import com.bitwarden.ui.platform.components.icon.model.IconData
import com.bitwarden.ui.platform.resource.BitwardenDrawable
@@ -249,7 +249,7 @@ fun List<LoginUriView>?.toLoginIconData(
uri = "http://$uri"
}
val iconUri = Uri.parse(uri)
val iconUri = uri.toUri()
val hostname = iconUri.host
val url = "$baseIconUrl/$hostname/icon.png"

View File

@@ -168,9 +168,6 @@ class AutofillCallbackViewModelTest : BaseViewModelTest() {
fun `on IntentReceived should emit FinishActivity when cipherID is extracted, vault unlocked, and cipherView not found`() =
runTest {
// Setup
val cipherView: CipherView = mockk {
every { id } returns "NEW CIPHER ID"
}
val totpCopyData = AutofillCallbackData(
cipherId = CIPHER_ID,
)

View File

@@ -143,6 +143,6 @@ class ReviewPromptManagerTest {
}
private const val USER_ID = "user_id"
private val MOCK_USER_STATE = mockk<UserStateJson>() {
private val MOCK_USER_STATE = mockk<UserStateJson> {
every { activeUserId } returns USER_ID
}

View File

@@ -10,7 +10,7 @@ class FakeNetworkConnectionManager(
isNetworkConnected: Boolean,
networkConnection: NetworkConnection,
) : NetworkConnectionManager {
private val mutableIsNetworkConnectedStateFlow = MutableStateFlow<Boolean>(isNetworkConnected)
private val mutableIsNetworkConnectedStateFlow = MutableStateFlow(isNetworkConnected)
private val mutableNetworkConnectionStateFlow = MutableStateFlow(networkConnection)
var fakeIsNetworkConnected: Boolean

View File

@@ -5,7 +5,6 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import app.cash.turbine.test
import com.bitwarden.core.EnrollPinResponse
import com.bitwarden.core.InitOrgCryptoRequest
import com.bitwarden.core.InitUserCryptoMethod
import com.bitwarden.core.InitUserCryptoRequest
@@ -1635,7 +1634,6 @@ class VaultLockManagerTest {
}
}
@Suppress("MaxLineLength")
@Test
fun `unlockVault with initializeCrypto success should migrate pinProtectedUserKey`() =
runTest {
@@ -1644,12 +1642,6 @@ class VaultLockManagerTest {
val masterPassword = "mockValue"
val privateKey = "54321"
val organizationKeys = mapOf("orgId1" to "orgKey1")
val userKeyEncryptedPin = "encryptedPin"
val pinProtectedUserKeyEnvelope = "pinProtectedUserKeyEnvelope"
val enrollResponse = EnrollPinResponse(
pinProtectedUserKeyEnvelope = pinProtectedUserKeyEnvelope,
userKeyEncryptedPin = userKeyEncryptedPin,
)
coEvery {
vaultSdkSource.initializeCrypto(
userId = USER_ID,

View File

@@ -418,7 +418,7 @@ class InlinePresentationSpecExtensionsTest {
}
private fun createMockContentDescription(cipherType: String): String =
"${AUTOFILL_SUGGESTION}, $cipherType, ${AUTOFILL_CIPHER_NAME}, ${AUTOFILL_CIPHER_SUBTITLE}"
"$AUTOFILL_SUGGESTION, $cipherType, $AUTOFILL_CIPHER_NAME, $AUTOFILL_CIPHER_SUBTITLE"
private const val AUTOFILL_SUGGESTION = "Autofill suggestion"
private const val CARD = "Card"

View File

@@ -77,9 +77,6 @@ class VerifyPasswordScreenTest : BitwardenComposeTest() {
.onNodeWithText("active@bitwarden.com")
.assertIsDisplayed()
composeTestRule
.onNodeWithText("You vault is locked. Verify your master password to continue.")
composeTestRule
.onNodeWithText("Continue")
.assertIsNotEnabled()
@@ -99,6 +96,7 @@ class VerifyPasswordScreenTest : BitwardenComposeTest() {
composeTestRule
.onNodeWithText("Verify your account email address")
.assertIsDisplayed()
composeTestRule
.onNodeWithText("Enter the 6-digit code that was emailed to the address below")

View File

@@ -452,7 +452,7 @@ class CipherViewExtensionsTest {
@Suppress("MaxLineLength")
@Test
fun `toViewState should transform full CipherView into ViewState with iconData based on cipher type`() {
mapOf<CipherType, Int>(
mapOf(
CipherType.LOGIN to BitwardenDrawable.ic_globe,
CipherType.IDENTITY to BitwardenDrawable.ic_id_card,
CipherType.CARD to BitwardenDrawable.ic_payment_card,

View File

@@ -36,7 +36,7 @@ class ManualCodeEntryScreenTests : BitwardenComposeTest() {
private var onNavigateToScanQrCodeCalled = false
private val mutableEventFlow = bufferedMutableSharedFlow<ManualCodeEntryEvent>()
private val mutableStateFlow = MutableStateFlow<ManualCodeEntryState>(DEFAULT_STATE)
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val fakePermissionManager: FakePermissionManager = FakePermissionManager()
private val intentManager = mockk<IntentManager>(relaxed = true)

View File

@@ -1,6 +1,6 @@
package com.bitwarden.authenticator.data.authenticator.repository.util
import android.net.Uri
import androidx.core.net.toUri
import com.bitwarden.authenticator.data.authenticator.manager.TotpCodeManager
import com.bitwarden.authenticator.data.authenticator.repository.model.AuthenticatorItem
import com.bitwarden.authenticatorbridge.model.SharedAccountData
@@ -12,7 +12,7 @@ fun List<SharedAccountData.Account>.toAuthenticatorItems(): List<AuthenticatorIt
flatMap { sharedAccount ->
sharedAccount.totpUris.mapNotNull { totpUriString ->
runCatching {
val uri = Uri.parse(totpUriString)
val uri = totpUriString.toUri()
val issuer = uri.getQueryParameter(TotpCodeManager.ISSUER_PARAM)
val label = uri.pathSegments
.firstOrNull()

View File

@@ -1,6 +1,6 @@
package com.bitwarden.authenticator.data.platform.manager.imports.parsers
import android.net.Uri
import androidx.core.net.toUri
import com.bitwarden.authenticator.data.authenticator.datasource.disk.entity.AuthenticatorItemAlgorithm
import com.bitwarden.authenticator.data.authenticator.datasource.disk.entity.AuthenticatorItemEntity
import com.bitwarden.authenticator.data.authenticator.datasource.disk.entity.AuthenticatorItemType
@@ -53,22 +53,16 @@ class BitwardenExportParser(
it.toAuthenticatorItemEntity()
}
@Suppress("MaxLineLength", "CyclomaticComplexMethod", "LongMethod")
@Suppress("CyclomaticComplexMethod", "LongMethod")
private fun ExportJsonData.ExportItem.toAuthenticatorItemEntity(): AuthenticatorItemEntity {
val otpString = requireNotNull(login?.totp)
val otpUri = when {
otpString.startsWith(TotpCodeManager.TOTP_CODE_PREFIX) -> {
Uri.parse(otpString)
}
otpString.startsWith(TotpCodeManager.STEAM_CODE_PREFIX) -> {
Uri.parse(otpString)
}
otpString.startsWith(TotpCodeManager.TOTP_CODE_PREFIX) -> otpString.toUri()
otpString.startsWith(TotpCodeManager.STEAM_CODE_PREFIX) -> otpString.toUri()
else -> {
val uriString = "${TotpCodeManager.TOTP_CODE_PREFIX}/$name?${TotpCodeManager.SECRET_PARAM}=$otpString"
Uri.parse(uriString)
val prefix = TotpCodeManager.TOTP_CODE_PREFIX
"$prefix/$name?${TotpCodeManager.SECRET_PARAM}=$otpString".toUri()
}
}

View File

@@ -235,11 +235,11 @@ private fun ManualCodeEntryDialogs(
dialog: ManualCodeEntryState.DialogState?,
onDismissRequest: () -> Unit,
) {
when (val dialogString = dialog) {
when (dialog) {
is ManualCodeEntryState.DialogState.Error -> {
BitwardenBasicDialog(
title = dialogString.title?.invoke(),
message = dialogString.message(),
title = dialog.title?.invoke(),
message = dialog.message(),
onDismissRequest = onDismissRequest,
)
}

View File

@@ -40,7 +40,7 @@ class BiometricsManagerImpl(
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED,
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE,
BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED,
-> false
-> false
else -> false
}
@@ -71,13 +71,13 @@ class BiometricsManagerImpl(
BiometricPrompt.ERROR_NO_BIOMETRICS,
BiometricPrompt.ERROR_HW_NOT_PRESENT,
BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL,
-> onError()
-> onError()
BiometricPrompt.ERROR_NEGATIVE_BUTTON -> onCancel()
BiometricPrompt.ERROR_LOCKOUT,
BiometricPrompt.ERROR_LOCKOUT_PERMANENT,
-> onLockOut()
-> onLockOut()
}
}