BITAU-164 add no-op version of BridgeService (#3884)

This commit is contained in:
Andrew Haisting 2024-09-09 15:36:34 -05:00 committed by GitHub
parent bef05d5ed9
commit 19facaf8fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 157 additions and 0 deletions

View file

@ -135,6 +135,9 @@ dependencies {
add("standardImplementation", dependencyNotation)
}
// TODO: this should use a versioned aar instead of referencing the project BITAU-94
implementation(project(":bridge"))
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.autofill)

View file

@ -20,6 +20,8 @@ import com.x8bit.bitwarden.data.platform.manager.AssetManager
import com.x8bit.bitwarden.data.platform.manager.AssetManagerImpl
import com.x8bit.bitwarden.data.platform.manager.BiometricsEncryptionManager
import com.x8bit.bitwarden.data.platform.manager.BiometricsEncryptionManagerImpl
import com.x8bit.bitwarden.data.platform.processor.BridgeServiceProcessor
import com.x8bit.bitwarden.data.platform.processor.BridgeServiceProcessorImpl
import com.x8bit.bitwarden.data.platform.manager.CrashLogsManager
import com.x8bit.bitwarden.data.platform.manager.CrashLogsManagerImpl
import com.x8bit.bitwarden.data.platform.manager.DebugMenuFeatureFlagManagerImpl
@ -75,6 +77,14 @@ object PlatformManagerModule {
fun provideAppForegroundManager(): AppForegroundManager =
AppForegroundManagerImpl()
@Provides
@Singleton
fun provideBridgeServiceProcessor(
featureFlagManager: FeatureFlagManager,
): BridgeServiceProcessor = BridgeServiceProcessorImpl(
featureFlagManager = featureFlagManager,
)
@Provides
@Singleton
fun provideOrganizationEventManager(

View file

@ -0,0 +1,14 @@
package com.x8bit.bitwarden.data.platform.processor
import com.bitwarden.bridge.IBridgeService
/**
* Provides access to [IBridgeService] APIs in an injectable and testable manner.
*/
interface BridgeServiceProcessor {
/**
* Binder that implements [IBridgeService]. Null can be returned to represent a no-op binder.
*/
val binder: IBridgeService.Stub?
}

View file

@ -0,0 +1,73 @@
package com.x8bit.bitwarden.data.platform.processor
import android.content.Intent
import com.bitwarden.bridge.IBridgeService
import com.bitwarden.bridge.IBridgeServiceCallback
import com.bitwarden.bridge.model.EncryptedAddTotpLoginItemData
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
/**
* Default implementation of [BridgeServiceProcessor].
*/
class BridgeServiceProcessorImpl(
private val featureFlagManager: FeatureFlagManager,
) : 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.
null
}
}
/**
* Default implementation of the bridge service binder.
*/
private val defaultBinder = object : IBridgeService.Stub() {
override fun getVersionNumber(): String {
// TODO: BITAU-104
return ""
}
override fun checkSymmetricEncryptionKeyFingerprint(
data: SymmetricEncryptionKeyFingerprintData?,
): Boolean {
// TODO: BITAU-104
return false
}
override fun getSymmetricEncryptionKeyData(): SymmetricEncryptionKeyData? {
// TODO: BITAU-104
return null
}
override fun registerBridgeServiceCallback(callback: IBridgeServiceCallback?) {
// TODO: BITAU-104
}
override fun unregisterBridgeServiceCallback(callback: IBridgeServiceCallback?) {
// TODO: BITAU-104
}
override fun syncAccounts() {
// TODO: BITAU-104
}
override fun createAddTotpLoginItemIntent(): Intent {
// TODO: BITAU-104
return Intent()
}
override fun setPendingAddTotpLoginItemData(data: EncryptedAddTotpLoginItemData?) {
// TODO: BITAU-104
}
}
}

View file

@ -0,0 +1,27 @@
package com.x8bit.bitwarden.data.platform.service
import android.app.Service
import android.content.Intent
import com.x8bit.bitwarden.data.platform.processor.BridgeServiceProcessor
import com.bitwarden.bridge.IBridgeService
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
/**
* Service exposed via a custom permission
*/
@AndroidEntryPoint
class BridgeService : Service() {
@Inject
lateinit var bridgeServiceProcessor: BridgeServiceProcessor
/**
* When binding this service, logic to the [BridgeServiceProcessor], which implements
* [IBridgeService].
*
* Note that [BridgeServiceProcessor.binder] can return a null binder, which the OS will accept
* but never connect to, effectively making a null binder a noop binder.
*/
override fun onBind(intent: Intent) = bridgeServiceProcessor.binder
}

View file

@ -0,0 +1,30 @@
package com.x8bit.bitwarden.data.platform.processor
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test
class BridgeServiceProcessorTest {
private val featureFlagManager: FeatureFlagManager = mockk()
private val bridgeServiceManager = BridgeServiceProcessorImpl(
featureFlagManager = featureFlagManager,
)
@Test
fun `when AuthenticatorSync feature flag is off, should return null binder`() {
every { featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) } returns false
assertNull(bridgeServiceManager.binder)
}
@Test
fun `when AuthenticatorSync feature flag is on, should return non-null binder`() {
every { featureFlagManager.getFeatureFlag(FlagKey.AuthenticatorSync) } returns true
assertNotNull(bridgeServiceManager.binder)
}
}