From c29dcc011d3c39094663afbf02918bf923a01efb Mon Sep 17 00:00:00 2001 From: megamegax Date: Thu, 10 Oct 2024 14:31:47 +0200 Subject: [PATCH] fix(shared-prefs): encrypt null values as nulls SUITEDEV-36673 45048607+eduzatoni@users.noreply.github.com --- .../core/storage/EmarsysEncryptedSharedPreferencesV3.kt | 5 +++-- core/src/main/java/com/emarsys/core/util/log/Logger.kt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/emarsys/core/storage/EmarsysEncryptedSharedPreferencesV3.kt b/core/src/main/java/com/emarsys/core/storage/EmarsysEncryptedSharedPreferencesV3.kt index f14a26a5..ca5aa76d 100644 --- a/core/src/main/java/com/emarsys/core/storage/EmarsysEncryptedSharedPreferencesV3.kt +++ b/core/src/main/java/com/emarsys/core/storage/EmarsysEncryptedSharedPreferencesV3.kt @@ -91,7 +91,7 @@ class EmarsysEncryptedSharedPreferencesV3( private val editor: SharedPreferences.Editor = realPreferences.edit() override fun putString(key: String, value: String?): SharedPreferences.Editor { - editor.putString(key, encryptString(value ?: "")) + editor.putString(key, encryptString(value)) return this } @@ -143,7 +143,8 @@ class EmarsysEncryptedSharedPreferencesV3( editor } - private fun encryptString(value: String): String { + private fun encryptString(value: String?): String? { + value ?: return null return sharedPreferenceCrypto.encrypt(value, secretKey) } } diff --git a/core/src/main/java/com/emarsys/core/util/log/Logger.kt b/core/src/main/java/com/emarsys/core/util/log/Logger.kt index 2ed71136..c784cae3 100644 --- a/core/src/main/java/com/emarsys/core/util/log/Logger.kt +++ b/core/src/main/java/com/emarsys/core/util/log/Logger.kt @@ -153,7 +153,7 @@ class Logger( private fun shouldLogBasedOnRemoteConfig(logLevel: LogLevel): Boolean { val savedLogLevel: LogLevel = - if (logLevelStorage.get() == null) ERROR else valueOf(logLevelStorage.get()!!) + if (logLevelStorage.get().isNullOrBlank()) ERROR else valueOf(logLevelStorage.get()!!) return logLevel.priority >= savedLogLevel.priority }