mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +03:00
BITAU-102 Return null BridgeService when API level is below 12 (#3887)
This commit is contained in:
parent
8dce8cd576
commit
19596ea4c3
2 changed files with 34 additions and 7 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue