From 19596ea4c3361d66d65f49d727f42395f670e59a Mon Sep 17 00:00:00 2001 From: Andrew Haisting <142518658+ahaisting-livefront@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:10:05 -0500 Subject: [PATCH] BITAU-102 Return null BridgeService when API level is below 12 (#3887) --- .../processor/BridgeServiceProcessorImpl.kt | 17 ++++++++----- .../processor/BridgeServiceProcessorTest.kt | 24 ++++++++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorImpl.kt index cb2641f33..415cd4ad6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorImpl.kt @@ -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 } } diff --git a/app/src/test/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorTest.kt index 07e22cca9..3c1d1e6e6 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/platform/processor/BridgeServiceProcessorTest.kt @@ -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) + } }