Fix for so load (#7692)
This commit is contained in:
@@ -128,4 +128,6 @@ dependencies {
|
||||
|
||||
implementation "com.google.accompanist:accompanist-pager:$accompanist_pager_version"
|
||||
implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist_pager_version"
|
||||
|
||||
implementation playCore.implementation
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.navi.pay.db
|
||||
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteException
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteOpenHelper
|
||||
import com.google.android.play.core.splitinstall.SplitInstallHelper
|
||||
import net.sqlcipher.database.SQLiteDatabase
|
||||
import net.sqlcipher.database.SQLiteDatabaseHook
|
||||
import net.sqlcipher.database.SQLiteOpenHelper
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* A factory to create [SupportSQLiteOpenHelper] instances that uses SQLCipher to encrypt the database.
|
||||
* It is created to load the SQLCipher native libraries before opening the database using SplitInstallHelper
|
||||
* Keep this updated with new SupportSQLiteOpenHelper in-case of Cipher Lin Update
|
||||
* @param passphrase The passphrase to use to encrypt the database.
|
||||
* @param hook The hook to use to configure the database.
|
||||
* @param clearPassphrase Whether to clear the passphrase after opening the database.
|
||||
*/
|
||||
class SqlCipherOpenerFactory @JvmOverloads constructor(
|
||||
private val passphrase: ByteArray,
|
||||
private val hook: SQLiteDatabaseHook? = null,
|
||||
private val clearPassphrase: Boolean = true
|
||||
) : SupportSQLiteOpenHelper.Factory {
|
||||
override fun create(configuration: SupportSQLiteOpenHelper.Configuration): SupportSQLiteOpenHelper {
|
||||
return SqlCipherOpenerHelper(configuration, passphrase, hook, clearPassphrase)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SqlCipherOpenerHelper internal constructor(
|
||||
configuration: SupportSQLiteOpenHelper.Configuration,
|
||||
passphrase: ByteArray?,
|
||||
hook: SQLiteDatabaseHook?,
|
||||
clearPassphrase: Boolean
|
||||
) : SupportSQLiteOpenHelper {
|
||||
private val standardHelper: SQLiteOpenHelper
|
||||
private val passphrase: ByteArray?
|
||||
private val clearPassphrase: Boolean
|
||||
|
||||
init {
|
||||
loadLibs(configuration.context, configuration.context.filesDir)
|
||||
this.passphrase = passphrase
|
||||
this.clearPassphrase = clearPassphrase
|
||||
standardHelper = object : SQLiteOpenHelper(
|
||||
configuration.context,
|
||||
configuration.name,
|
||||
null as SQLiteDatabase.CursorFactory?,
|
||||
configuration.callback.version,
|
||||
hook
|
||||
) {
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
configuration.callback.onCreate(db)
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
configuration.callback.onUpgrade(db, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
configuration.callback.onDowngrade(db, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
override fun onOpen(db: SQLiteDatabase) {
|
||||
configuration.callback.onOpen(db)
|
||||
}
|
||||
|
||||
override fun onConfigure(db: SQLiteDatabase) {
|
||||
configuration.callback.onConfigure(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val databaseName: String
|
||||
get() = standardHelper.databaseName
|
||||
override val readableDatabase: SupportSQLiteDatabase
|
||||
get() = writableDatabase
|
||||
|
||||
override fun setWriteAheadLoggingEnabled(enabled: Boolean) {
|
||||
standardHelper.setWriteAheadLoggingEnabled(enabled)
|
||||
}
|
||||
|
||||
override val writableDatabase: SupportSQLiteDatabase
|
||||
get() {
|
||||
val result: SQLiteDatabase
|
||||
try {
|
||||
result = standardHelper.getWritableDatabase(passphrase)
|
||||
} catch (var8: SQLiteException) {
|
||||
if (passphrase != null) {
|
||||
var isCleared = true
|
||||
val var4 = passphrase
|
||||
val var5 = var4.size
|
||||
var var6 = 0
|
||||
while (var6 < var5) {
|
||||
val b = var4[var6]
|
||||
isCleared = isCleared && b.toInt() == 0
|
||||
++var6
|
||||
}
|
||||
if (isCleared) {
|
||||
throw IllegalStateException(
|
||||
"The passphrase appears to be cleared. This happens by default the first time you use the factory to open a database, so we can remove the cleartext passphrase from memory. If you close the database yourself, please use a fresh SupportFactory to reopen it. If something else (e.g., Room) closed the database, and you cannot control that, use SupportFactory boolean constructor option to opt out of the automatic password clearing step. See the project README for more information.",
|
||||
var8
|
||||
)
|
||||
}
|
||||
}
|
||||
throw var8
|
||||
}
|
||||
if (clearPassphrase && passphrase != null) {
|
||||
for (i in passphrase.indices) {
|
||||
passphrase[i] = 0
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
standardHelper.close()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the SQLCipher native libraries using SplitInstallHelper
|
||||
* @param context The context to use to load the libraries.
|
||||
* @param workingDir The working directory to use to load the libraries.
|
||||
*/
|
||||
@Synchronized
|
||||
fun loadLibs(context: Context, workingDir: File?) {
|
||||
SQLiteDatabase.loadLibs(
|
||||
context, workingDir
|
||||
) { libNames ->
|
||||
val var3 = libNames.size
|
||||
for (var4 in 0 until var3) {
|
||||
val libName = libNames[var4]
|
||||
SplitInstallHelper.loadLibrary(context, libName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,10 @@ import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.google.gson.Gson
|
||||
import com.navi.base.sharedpref.PreferenceManager
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper
|
||||
import com.navi.common.model.ModuleName
|
||||
import com.navi.common.model.NetworkInfo
|
||||
import com.navi.common.utils.log
|
||||
import com.navi.pay.common.cache.ImageCache
|
||||
import com.navi.pay.common.cache.ImageCacheImpl
|
||||
import com.navi.pay.common.cache.NaviPayCache
|
||||
@@ -27,6 +29,7 @@ import com.navi.pay.common.utils.NaviPayCommonUtils
|
||||
import com.navi.pay.common.utils.naviPayGsonBuilder
|
||||
import com.navi.pay.db.NaviPayAppDatabase
|
||||
import com.navi.pay.db.NaviPayAppEncryptedDatabase
|
||||
import com.navi.pay.db.SqlCipherOpenerFactory
|
||||
import com.navi.pay.management.paytocontacts.PhoneContactManager
|
||||
import com.navi.pay.management.paytocontacts.PhoneContactManagerImpl
|
||||
import com.navi.pay.network.NaviPayHttpClient
|
||||
@@ -37,6 +40,7 @@ import com.navi.pay.onboarding.home.VpaQRCodeManager
|
||||
import com.navi.pay.onboarding.home.VpaQRCodeManagerImpl
|
||||
import com.navi.pay.permission.utils.PermissionStateProvider
|
||||
import com.navi.pay.permission.utils.PermissionStateProviderImpl
|
||||
import com.navi.pay.utils.ENABLE_DEFAULT_SUPPORT_FACTORY
|
||||
import com.navi.pay.utils.KEY_DB_ENCRYPTION
|
||||
import com.navi.pay.utils.NAVIPAY_NETWORK_INFO_TIMEOUT
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_NAME
|
||||
@@ -127,13 +131,22 @@ object NaviPayNetworkModule {
|
||||
value = passphrase.toString(Charsets.ISO_8859_1)
|
||||
)
|
||||
}
|
||||
|
||||
val sqlCipherOpenerFactory = try {
|
||||
if (FirebaseRemoteConfigHelper.getBoolean(ENABLE_DEFAULT_SUPPORT_FACTORY)) {
|
||||
SupportFactory(passphrase)
|
||||
} else {
|
||||
SqlCipherOpenerFactory(passphrase)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.log()
|
||||
SqlCipherOpenerFactory(passphrase)
|
||||
}
|
||||
return Room.databaseBuilder(
|
||||
context,
|
||||
NaviPayAppEncryptedDatabase::class.java,
|
||||
NAVI_PAY_ENCRYPTED_DATABASE_NAME
|
||||
)
|
||||
.openHelperFactory(SupportFactory(passphrase))
|
||||
.openHelperFactory(sqlCipherOpenerFactory)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
@@ -211,4 +211,7 @@ const val KEY_CHECK_BALANCE_ACTION = "checkBalanceAction"
|
||||
const val CUSTOMER_STATUS_AFTER_ONBOARDING = "customerStatusAfterOnboarding"
|
||||
const val VPA_QR_CODE_IMAGES = "vpa_qr_code_images"
|
||||
const val QR_CODE_IMAGE_EXTENSION = ".jpeg"
|
||||
const val NAVI_PAY_DEBUG_LOG = "NAVI_PAY_DEBUG_LOG"
|
||||
const val NAVI_PAY_DEBUG_LOG = "NAVI_PAY_DEBUG_LOG"
|
||||
|
||||
// Firebase Config Keys
|
||||
const val ENABLE_DEFAULT_SUPPORT_FACTORY = "ENABLE_DEFAULT_SUPPORT_FACTORY"
|
||||
Reference in New Issue
Block a user