NTP-74270 | Make initialization as singleton (#16667)
This commit is contained in:
@@ -23,6 +23,7 @@ class NetworkConfigurationInitializer @Inject constructor() : ComponentInitializ
|
||||
override fun initialize(application: NaviApplication) {
|
||||
CoroutineManager.scope.launchOnIO {
|
||||
SoLoader.init(application, false)
|
||||
EncryptionHashInterceptor.loadNaviLib(application.applicationContext)
|
||||
NetworkingModule.setCustomClientBuilder { builder ->
|
||||
builder.addInterceptor(CommonLibManager.getHeaderInterceptorForReact())
|
||||
builder.addInterceptor(EncryptionHashInterceptor(application.applicationContext))
|
||||
|
||||
@@ -27,8 +27,6 @@ import com.navi.base.utils.HEADER_SIGNATURE
|
||||
import com.navi.base.utils.SoUtils
|
||||
import com.navi.base.utils.X_SOURCE_SIGNATURE
|
||||
import com.navi.base.utils.isNotNullAndNotEmpty
|
||||
import java.util.concurrent.Executors
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Protocol
|
||||
@@ -37,7 +35,6 @@ import okhttp3.RequestBody
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import okio.Buffer
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Interceptor to add encryption hash to the request. Don't add this at last in the interceptor
|
||||
@@ -48,45 +45,44 @@ class EncryptionHashInterceptor(
|
||||
private val context: Context,
|
||||
private val enableSignatureKeyByDefault: Boolean? = null,
|
||||
) : Interceptor {
|
||||
private val coroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||
private var firebaseAnalytics: FirebaseAnalytics? = null
|
||||
|
||||
private val firebaseAnalyticsInstance: FirebaseAnalytics
|
||||
get() {
|
||||
companion object {
|
||||
|
||||
private val firebaseAnalyticsInstance: FirebaseAnalytics
|
||||
get() = Firebase.analytics
|
||||
|
||||
private var isNaviLibLoaded: Boolean = false
|
||||
|
||||
suspend fun loadNaviLib(context: Context) {
|
||||
try {
|
||||
if (firebaseAnalytics == null) {
|
||||
firebaseAnalytics = Firebase.analytics
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
return firebaseAnalytics!!
|
||||
}
|
||||
if (isNaviLibLoaded) return
|
||||
System.loadLibrary("navi-lib")
|
||||
isNaviLibLoaded = true
|
||||
} catch (_: UnsatisfiedLinkError) {
|
||||
// Dynamically loading Libs based on available .so file under the dir's for ARM64
|
||||
// and
|
||||
// ARM v7
|
||||
|
||||
init {
|
||||
firebaseAnalytics = Firebase.analytics
|
||||
try {
|
||||
System.loadLibrary("navi-lib")
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
// Dynamically loading Libs based on available .so file under the dir's for ARM64 and
|
||||
// ARM v7
|
||||
val params = Bundle()
|
||||
params.putString("os_arch", System.getProperty("os.arch"))
|
||||
params.putString("hardware", Build.HARDWARE)
|
||||
params.putString("build_cpu_abi", Build.CPU_ABI)
|
||||
params.putString("build_cpu_abi2", Build.CPU_ABI2)
|
||||
params.putString(
|
||||
"SO_file_path",
|
||||
context.applicationContext.applicationInfo.nativeLibraryDir,
|
||||
)
|
||||
firebaseAnalyticsInstance.logEvent("NaviLibSOLoadFailedTryingDynamicLoading", params)
|
||||
coroutineDispatcher.executor.execute {
|
||||
val params = Bundle()
|
||||
params.putString("os_arch", System.getProperty("os.arch"))
|
||||
params.putString("hardware", Build.HARDWARE)
|
||||
params.putString("build_cpu_abi", Build.CPU_ABI)
|
||||
params.putString("build_cpu_abi2", Build.CPU_ABI2)
|
||||
params.putString(
|
||||
"SO_file_path",
|
||||
context.applicationContext.applicationInfo.nativeLibraryDir,
|
||||
)
|
||||
firebaseAnalyticsInstance.logEvent(
|
||||
"NaviLibSOLoadFailedTryingDynamicLoading",
|
||||
params,
|
||||
)
|
||||
try {
|
||||
val soFile = SoUtils.getLibFileFromPath(context, "navi-lib")
|
||||
if (soFile?.exists() == true) {
|
||||
params.putString("NaviLibAbsoluteFilePath", soFile.absolutePath)
|
||||
firebaseAnalyticsInstance.logEvent("NaviLibSOFileExists", params)
|
||||
System.load(soFile.absolutePath)
|
||||
isNaviLibLoaded = true
|
||||
} else {
|
||||
firebaseAnalyticsInstance.logEvent("NaviLibSOFileNotFound", params)
|
||||
val archValue = SoUtils.getSupportedABIArch()
|
||||
@@ -105,6 +101,7 @@ class EncryptionHashInterceptor(
|
||||
params,
|
||||
)
|
||||
System.load(updatedSoFile.absolutePath)
|
||||
isNaviLibLoaded = true
|
||||
} else {
|
||||
firebaseAnalyticsInstance.logEvent(
|
||||
"NaviLibSOFileNotPresentWithUpdatedPath",
|
||||
|
||||
Reference in New Issue
Block a user