-
Notifications
You must be signed in to change notification settings - Fork 1
added way to build without ee features #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.cblreactnative | ||
|
||
import android.util.Log | ||
import com.couchbase.lite.Database | ||
import com.couchbase.lite.DatabaseConfiguration | ||
import com.couchbase.lite.ReplicatorConfiguration | ||
|
||
object CouchbaseReflectionHelper { | ||
|
||
fun setEncryptionKey(config: DatabaseConfiguration, encryptionKey: String) { | ||
try { | ||
val encryptionKeyClass = Class.forName("com.couchbase.lite.EncryptionKey") | ||
val encryptionKeyInstance = encryptionKeyClass.getConstructor(String::class.java).newInstance(encryptionKey) | ||
val setMethod = config.javaClass.getMethod("setEncryptionKey", encryptionKeyClass) | ||
setMethod.invoke(config, encryptionKeyInstance) | ||
} catch (e: Exception) { | ||
Log.w("CouchbaseLite", "Failed to set encryption key: ${e.message}") | ||
} | ||
} | ||
|
||
fun changeEncryptionKey(database: Database, encryptionKey: String?) { | ||
try { | ||
val encryptionKeyClass = Class.forName("com.couchbase.lite.EncryptionKey") | ||
val encryptionKeyInstance = if (encryptionKey != null) { | ||
encryptionKeyClass.getConstructor(String::class.java).newInstance(encryptionKey) | ||
} else null | ||
|
||
val changeMethod = database.javaClass.getMethod("changeEncryptionKey", encryptionKeyClass) | ||
changeMethod.invoke(database, encryptionKeyInstance) | ||
} catch (e: Exception) { | ||
Log.w("CouchbaseLite", "Failed to change encryption key: ${e.message}") | ||
} | ||
} | ||
|
||
fun setAcceptOnlySelfSignedServerCertificate(config: ReplicatorConfiguration, value: Boolean) { | ||
try { | ||
val method = config.javaClass.getMethod("setAcceptOnlySelfSignedServerCertificate", Boolean::class.javaPrimitiveType) | ||
method.invoke(config, value) | ||
} catch (e: Exception) { | ||
Log.w("CouchbaseLite", "Failed to set certificate option: ${e.message}") | ||
} | ||
} | ||
|
||
fun isAcceptOnlySelfSignedServerCertificate(config: ReplicatorConfiguration): Boolean { | ||
return try { | ||
val method = config.javaClass.getMethod("isAcceptOnlySelfSignedServerCertificate") | ||
method.invoke(config) as Boolean | ||
} catch (e: Exception) { | ||
Log.w("CouchbaseLite", "Failed to get certificate option: ${e.message}") | ||
false | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ import kotlin.random.Random | |||||||||||||||
|
||||||||||||||||
import org.json.JSONObject | ||||||||||||||||
import java.io.File | ||||||||||||||||
import com.cblreactnative.CouchbaseReflectionHelper | ||||||||||||||||
typealias CBLCollection = com.couchbase.lite.Collection | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
@@ -30,7 +31,7 @@ object DatabaseManager { | |||||||||||||||
if (jsonConfig.has("encryptionKey")) { | ||||||||||||||||
val encryptionKey = jsonConfig.getString("encryptionKey") | ||||||||||||||||
if (encryptionKey.isNotEmpty()) { | ||||||||||||||||
databaseConfig.setEncryptionKey(EncryptionKey(encryptionKey)) | ||||||||||||||||
CouchbaseReflectionHelper.setEncryptionKey(databaseConfig, encryptionKey) | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
@@ -40,11 +41,10 @@ object DatabaseManager { | |||||||||||||||
fun changeEncryptionKey(databaseName: String, encryptionKey: String?) { | ||||||||||||||||
val db = getDatabase(databaseName) ?: throw Exception("Error: Database not found.") | ||||||||||||||||
if (encryptionKey == null) { | ||||||||||||||||
db.changeEncryptionKey(null) | ||||||||||||||||
CouchbaseReflectionHelper.changeEncryptionKey(db, null) | ||||||||||||||||
return | ||||||||||||||||
} | ||||||||||||||||
val encryptionKeyValue = EncryptionKey(encryptionKey) | ||||||||||||||||
db.changeEncryptionKey(encryptionKeyValue) | ||||||||||||||||
CouchbaseReflectionHelper.changeEncryptionKey(db, encryptionKey) | ||||||||||||||||
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
fun closeDatabase(databaseName: String) { | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching a generic
Exception
is dangerous as it can swallow any exception, includingRuntimeException
s that indicate a bug in the code, not just the absence of EE features. This can hide bugs and lead to unpredictable application behavior.You should only catch specific reflection-related exceptions. Any other exception should be allowed to propagate. This ensures you are only handling the expected 'feature not available' scenario.