Skip to content

Commit

Permalink
detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Jan 14, 2025
1 parent 882ee4e commit ef73962
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@
package com.wire.kalium.logic.feature.debug

import com.wire.kalium.logic.di.UserStorage
import com.wire.kalium.persistence.db.DBProfile

class ChangeProfilingUseCase(
private val userStorage: UserStorage,
) {
/**
* Changes the profiling of the database (cipher_profile) if the profile is specified and the database is encrypted
* @param enabled true to enable profiling, false to disable
* Change profiling state.
*/
suspend operator fun invoke(status: DBProfile) {
userStorage.database.debugExtension.changeProfiling(status)
}

suspend operator fun invoke(enabled: Boolean) {
userStorage.database.debugExtension.changeProfiling(if (enabled) DBProfile.ON.Device else DBProfile.Off)
userStorage.database.debugExtension.changeProfiling(enabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
package com.wire.kalium.logic.feature.debug

import com.wire.kalium.logic.di.UserStorage
import com.wire.kalium.persistence.db.DBProfile
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

/**
* Use case to observe the state of the database logger.
*/
class ObserveDatabaseLoggerStateUseCase(
private val userStorage: UserStorage,
) {
suspend operator fun invoke(): Flow<Boolean> = userStorage.database.debugExtension.getProfilingState().map {
it is DBProfile.ON
}
suspend operator fun invoke(): Flow<Boolean> = userStorage.database.debugExtension.observeIsProfilingEnabled()
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ class DebugExtension(
private val metaDataDao: MetadataDAO,
) {

suspend fun getProfilingState(): Flow<DBProfile?> =
suspend fun observeIsProfilingEnabled(): Flow<Boolean> =
metaDataDao.valueByKeyFlow(KEY_CIPHER_PROFILE)
.map {
it?.let { DBProfile.fromString(it) }
.map { state ->
state?.let { DBProfile.fromString(it) }.let {
it is DBProfile.ON
}
}

/**
* Changes the profiling of the database (cipher_profile) if the profile is specified and the database is encrypted
* @param enabled true to enable profiling, false to disable
*/
suspend fun changeProfiling(state: DBProfile): Long? =
suspend fun changeProfiling(enabled: Boolean): Long? =
if (isEncrypted) {
val state = if (enabled) DBProfile.ON.Device else DBProfile.Off
sqlDriver.executeQuery(
identifier = null,
sql = """PRAGMA cipher_profile= '${state.logTarget}';""",
Expand Down

0 comments on commit ef73962

Please sign in to comment.