BITAU-102 Return null BridgeService when API level is below 12 (#3887)

This commit is contained in:
Andrew Haisting 2024-09-10 15:10:05 -05:00 committed by GitHub
parent 8dce8cd576
commit 19596ea4c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package com.x8bit.bitwarden.data.platform.processor
import android.content.Intent
import android.os.Build
import com.bitwarden.bridge.IBridgeService
import com.bitwarden.bridge.IBridgeServiceCallback
import com.bitwarden.bridge.model.EncryptedAddTotpLoginItemData
@ -8,6 +9,7 @@ import com.bitwarden.bridge.model.SymmetricEncryptionKeyData
import com.bitwarden.bridge.model.SymmetricEncryptionKeyFingerprintData
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
/**
* Default implementation of [BridgeServiceProcessor].
@ -17,14 +19,17 @@ class BridgeServiceProcessorImpl(
) : BridgeServiceProcessor {
override val binder: IBridgeService.Stub?
// TODO: Check for Android API level as well: BITAU-102
get() {
return if (featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync)) {
defaultBinder
} else {
// If the feature flag is not enabled, return a null binder which will no-op all
// service calls.
return if (
!featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) ||
isBuildVersionBelow(Build.VERSION_CODES.S)
) {
// If the feature flag is not enabled, OR if version is below Android 12,
// return a null binder which will no-op all service calls
null
} else {
// Otherwise, return real binder implementation:
defaultBinder
}
}

View file

@ -1,11 +1,15 @@
package com.x8bit.bitwarden.data.platform.processor
import android.os.Build
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class BridgeServiceProcessorTest {
@ -16,15 +20,33 @@ class BridgeServiceProcessorTest {
featureFlagManager = featureFlagManager,
)
@BeforeEach
fun setup() {
mockkStatic(::isBuildVersionBelow)
}
@Test
fun `when AuthenticatorSync feature flag is off, should return null binder`() {
every { isBuildVersionBelow(Build.VERSION_CODES.S) } returns false
every { featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) } returns false
assertNull(bridgeServiceManager.binder)
}
@Test
fun `when AuthenticatorSync feature flag is on, should return non-null binder`() {
@Suppress("MaxLineLength")
fun `when AuthenticatorSync feature flag is on and running Android level greater than S, should return non-null binder`() {
every { isBuildVersionBelow(Build.VERSION_CODES.S) } returns false
every { featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) } returns true
assertNotNull(bridgeServiceManager.binder)
}
@Test
fun `when below Android level S, should never return a binder regardless of feature flag`() {
every { isBuildVersionBelow(Build.VERSION_CODES.S) } returns true
every { featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) } returns false
assertNull(bridgeServiceManager.binder)
every { featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) } returns true
assertNull(bridgeServiceManager.binder)
}
}