TP-69580 | Fallback to correct shared preference, DB crash fix, Provider changed to Lazy to DI injection (#11200)
This commit is contained in:
@@ -72,9 +72,9 @@ import com.naviapp.utils.Constants
|
||||
import com.naviapp.utils.DEV
|
||||
import com.naviapp.utils.QA
|
||||
import com.naviapp.utils.isDifferentPackage
|
||||
import dagger.Lazy
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -94,11 +94,11 @@ open class NaviApplication :
|
||||
private var isDifferentPackage: Boolean = false
|
||||
|
||||
// This will initialize NaviPayManager lazily i.e. when NaviPayManager::init() will be called
|
||||
@Inject lateinit var naviPayManager: Provider<NaviPayManager>
|
||||
@Inject lateinit var naviPayManager: Lazy<NaviPayManager>
|
||||
|
||||
@Inject lateinit var naviCacheRepository: Provider<NaviCacheRepository>
|
||||
@Inject lateinit var naviCacheRepository: Lazy<NaviCacheRepository>
|
||||
|
||||
@Inject lateinit var notificationManager: Provider<NotificationManager>
|
||||
@Inject lateinit var notificationManager: Lazy<NotificationManager>
|
||||
|
||||
private var rnJob = Job()
|
||||
private val applicationScope = CoroutineScope(Dispatchers.IO + rnJob)
|
||||
|
||||
@@ -14,11 +14,10 @@ import com.navi.common.upi.UpiDataType
|
||||
import com.navi.common.upi.UpiSdkAnalytics
|
||||
import com.navi.common.upi.UpiSdkHelper
|
||||
import com.navi.pay.common.setup.NaviPayManager
|
||||
import javax.inject.Provider
|
||||
import dagger.Lazy
|
||||
import org.json.JSONObject
|
||||
|
||||
class UpiSdkHelperImpl(private val naviPayManagerProvider: Provider<NaviPayManager>) :
|
||||
UpiSdkHelper {
|
||||
class UpiSdkHelperImpl(private val naviPayManagerProvider: Lazy<NaviPayManager>) : UpiSdkHelper {
|
||||
|
||||
private val upiSdkAnalytics = UpiSdkAnalytics()
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ object PreferenceManager {
|
||||
return if (shouldUseEncryptedSharedPref()) {
|
||||
secureSharedPreferencesForApp?.getString(key, null)
|
||||
} else {
|
||||
getStringPreference(key)
|
||||
getStringPreferenceApp(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ object PreferenceManager {
|
||||
val editor = secureSharedPreferencesForApp?.edit()
|
||||
editor?.putString(key, value)
|
||||
editor?.apply()
|
||||
} else setStringPreference(key, value)
|
||||
} else setStringPreferenceApp(key, value)
|
||||
}
|
||||
|
||||
fun saveObjectSecurely(key: String, value: Any?) {
|
||||
@@ -371,6 +371,8 @@ object PreferenceManager {
|
||||
}
|
||||
|
||||
private fun shouldUseEncryptedSharedPref(): Boolean {
|
||||
// Encrypted sharedPreference for session & app are initialised together
|
||||
// Hence a null check on one is enough
|
||||
return secureSharedPreferencesForSession != null
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ import com.navi.common.utils.CommonNaviAnalytics
|
||||
import com.navi.common.utils.getNoInternetData
|
||||
import com.navi.common.viewmodel.BaseVM
|
||||
import com.navi.naviwidgets.models.response.Action
|
||||
import dagger.Lazy
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -49,9 +49,9 @@ abstract class NaviBbpsBaseVM(val naviBbpsVmData: NaviBbpsVmData) : BaseVM() {
|
||||
|
||||
private val analyticsErrorEventTracker = CommonNaviAnalytics.naviAnalytics.Errors()
|
||||
|
||||
@Inject lateinit var errorEventHandler: Provider<ErrorEventHandler>
|
||||
@Inject lateinit var errorEventHandler: Lazy<ErrorEventHandler>
|
||||
|
||||
@Inject lateinit var resourceProvider: Provider<ResourceProvider>
|
||||
@Inject lateinit var resourceProvider: Lazy<ResourceProvider>
|
||||
|
||||
/**
|
||||
* Prepare error configuration using application specific logic and trigger event
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.navi.pay.common.repository.SharedPreferenceRepository
|
||||
import com.navi.pay.common.setup.model.NaviPayCustomerStatus
|
||||
import com.navi.pay.common.setup.model.NaviPaySetupFailureReason
|
||||
import com.navi.pay.common.setup.model.NaviPaySetupStatus
|
||||
import com.navi.pay.common.sync.repository.SyncRepository
|
||||
import com.navi.pay.common.usecase.LinkedAccountsUseCase
|
||||
import com.navi.pay.common.usecase.LitmusExperimentsUseCase
|
||||
import com.navi.pay.common.utils.DeviceInfoProvider
|
||||
@@ -42,9 +43,9 @@ import com.navi.pay.utils.KEY_UPI_LITE_ACTIVE_ACCOUNT_INFO
|
||||
import com.navi.pay.utils.LITMUS_EXPERIMENT_NAVIPAY_ONECLICK
|
||||
import com.navi.pay.utils.RUPEE_SYMBOL
|
||||
import com.navi.pay.utils.getFormattedAmountWithDecimal
|
||||
import dagger.Lazy
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Deferred
|
||||
@@ -61,16 +62,17 @@ class NaviPayManager
|
||||
@Inject
|
||||
constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val naviPaySetupUseCase: Provider<NaviPaySetupUseCase>,
|
||||
private val naviPayCustomerStatusHandler: Provider<NaviPayCustomerStatusHandler>,
|
||||
private val naviCacheRepository: Provider<NaviCacheRepository>,
|
||||
private val naviPayAppDatabase: Provider<NaviPayAppDatabase>,
|
||||
private val naviPayAppEncryptedDatabase: Provider<NaviPayAppEncryptedDatabase>,
|
||||
private val deviceInfoProvider: Provider<DeviceInfoProvider>,
|
||||
private val linkedAccountsUseCase: Provider<LinkedAccountsUseCase>,
|
||||
private val sharedPreferenceRepository: SharedPreferenceRepository,
|
||||
private val naviPayWidgetManager: Provider<NaviPayWidgetManager>,
|
||||
private val litmusExperimentsUseCase: Provider<LitmusExperimentsUseCase>
|
||||
private val naviPaySetupUseCase: Lazy<NaviPaySetupUseCase>,
|
||||
private val naviPayCustomerStatusHandler: Lazy<NaviPayCustomerStatusHandler>,
|
||||
private val naviCacheRepository: Lazy<NaviCacheRepository>,
|
||||
private val naviPayAppDatabase: Lazy<NaviPayAppDatabase>,
|
||||
private val naviPayAppEncryptedDatabase: Lazy<NaviPayAppEncryptedDatabase>,
|
||||
private val deviceInfoProvider: Lazy<DeviceInfoProvider>,
|
||||
private val linkedAccountsUseCase: Lazy<LinkedAccountsUseCase>,
|
||||
private val sharedPreferenceRepository: Lazy<SharedPreferenceRepository>,
|
||||
private val naviPayWidgetManager: Lazy<NaviPayWidgetManager>,
|
||||
private val litmusExperimentsUseCase: Lazy<LitmusExperimentsUseCase>,
|
||||
private val syncRepository: Lazy<SyncRepository>
|
||||
) {
|
||||
companion object {
|
||||
lateinit var baseUrl: String
|
||||
@@ -232,14 +234,22 @@ constructor(
|
||||
}
|
||||
|
||||
/** Removing upi customer status and fingerprint for soft logged out */
|
||||
fun triggerNaviPaySoftLogout() {
|
||||
private fun triggerNaviPaySoftLogout() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
naviPaySetupUseCase
|
||||
.get()
|
||||
.clearNaviPayData(
|
||||
encryptedDataKeys = listOf(KEY_DEVICE_FINGERPRINT),
|
||||
nonEncryptedDataKeys = listOf(KEY_CUSTOMER_STATUS)
|
||||
)
|
||||
val naviPaySoftLogoutTasks = mutableListOf<Deferred<Unit>>()
|
||||
|
||||
naviPaySoftLogoutTasks.add(
|
||||
async {
|
||||
naviPaySetupUseCase
|
||||
.get()
|
||||
.clearNaviPayData(
|
||||
encryptedDataKeys = listOf(KEY_DEVICE_FINGERPRINT),
|
||||
nonEncryptedDataKeys = listOf(KEY_CUSTOMER_STATUS)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
naviPaySoftLogoutTasks.add(async { syncRepository.get().deleteAll() })
|
||||
}
|
||||
naviPayWidgetManager.get().removeScanAndPayLauncherWidget()
|
||||
}
|
||||
@@ -291,11 +301,13 @@ constructor(
|
||||
|
||||
fun getUpiLiteBalance(): String {
|
||||
val liteAccountInfoString =
|
||||
sharedPreferenceRepository.getStringValueOnSameThread(
|
||||
key = KEY_UPI_LITE_ACTIVE_ACCOUNT_INFO,
|
||||
defValue = EMPTY,
|
||||
encrypt = true
|
||||
)
|
||||
sharedPreferenceRepository
|
||||
.get()
|
||||
.getStringValueOnSameThread(
|
||||
key = KEY_UPI_LITE_ACTIVE_ACCOUNT_INFO,
|
||||
defValue = EMPTY,
|
||||
encrypt = true
|
||||
)
|
||||
if (liteAccountInfoString.isEmpty()) return EMPTY
|
||||
val liteAccountInfo =
|
||||
Gson().fromJson(liteAccountInfoString, UpiLiteActiveAccountInfo::class.java)
|
||||
|
||||
@@ -21,4 +21,6 @@ interface SyncDao {
|
||||
|
||||
@Query("SELECT * FROM $NAVI_PAY_DATABASE_SYNC_TABLE_NAME WHERE syncKey = :key")
|
||||
suspend fun get(key: String): SyncEntity?
|
||||
|
||||
@Query("DELETE FROM $NAVI_PAY_DATABASE_SYNC_TABLE_NAME") suspend fun deleteAll()
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ class SyncRepository @Inject constructor(private val syncDao: SyncDao) {
|
||||
suspend fun get(key: String) = syncDao.get(key)
|
||||
|
||||
suspend fun insert(syncEntity: SyncEntity) = syncDao.insert(syncEntity = syncEntity)
|
||||
|
||||
suspend fun deleteAll() = syncDao.deleteAll()
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ import com.navi.pay.utils.DOT_IFSC_DOT_NPCI
|
||||
import com.navi.pay.utils.INTENT_ACTION_SMS_DELIVERED
|
||||
import com.navi.pay.utils.INTENT_ACTION_SMS_SENT
|
||||
import com.navi.pay.utils.KEY_CUSTOMER_STATUS
|
||||
import com.navi.pay.utils.KEY_DB_ENCRYPTION
|
||||
import com.navi.pay.utils.KEY_DEVICE_FINGERPRINT
|
||||
import com.navi.pay.utils.LITMUS_EXPERIMENT_NAVIPAY_ONECLICK
|
||||
import com.navi.pay.utils.NAVI_PAY_ENCRYPT_SHARED_PREF_DATA_KEYS
|
||||
@@ -576,7 +575,6 @@ fun getExcludeSecureSharedPrefKeys(): List<String> {
|
||||
|
||||
fun getExcludeSharedPrefKeys(): List<String> {
|
||||
val excludeSharedPrefKeys = NAVI_PAY_NON_ENCRYPT_SHARED_PREF_DATA_KEYS.toMutableList()
|
||||
excludeSharedPrefKeys.add(KEY_DB_ENCRYPTION)
|
||||
excludeSharedPrefKeys.remove(KEY_CUSTOMER_STATUS)
|
||||
return excludeSharedPrefKeys
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2022 by Navi Technologies Limited
|
||||
* * Copyright © 2022-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
@@ -142,6 +142,8 @@ object NaviPayNetworkModule {
|
||||
PreferenceManager.getSecureStringApp(KEY_DB_ENCRYPTION)
|
||||
?.toByteArray(Charsets.ISO_8859_1)
|
||||
if (passphrase == null) {
|
||||
// DB deletion is for devices in which crash related to passphrase lost is happening
|
||||
context.deleteDatabase(NAVI_PAY_ENCRYPTED_DATABASE_NAME)
|
||||
passphrase = NaviPayCommonUtils.generatePassphrase()
|
||||
PreferenceManager.saveStringSecurelyApp(
|
||||
key = KEY_DB_ENCRYPTION,
|
||||
|
||||
@@ -39,9 +39,9 @@ import com.navi.pay.onboarding.faq.repository.NaviPayFaqRepository
|
||||
import com.navi.pay.onboarding.home.model.network.DeRegisterRequest
|
||||
import com.navi.pay.utils.ConfigKey
|
||||
import com.navi.pay.utils.NAVI_PAY_API_STATUS_SUCCESS
|
||||
import dagger.Lazy
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -58,7 +58,7 @@ constructor(
|
||||
private val naviPayFaqRepository: NaviPayFaqRepository,
|
||||
private val naviPayConfigUseCase: NaviPayConfigUseCase,
|
||||
private val deviceInfoProvider: DeviceInfoProvider,
|
||||
private val naviPayManager: Provider<NaviPayManager>,
|
||||
private val naviPayManager: Lazy<NaviPayManager>,
|
||||
private val naviPayNetworkConnectivity: NaviPayNetworkConnectivity,
|
||||
private val naviPayCustomerStatusHandler: NaviPayCustomerStatusHandler,
|
||||
) : NaviPayBaseVM(NaviPayVmData(screenName = NaviPayAnalytics.NAVI_PAY_FAQ)) {
|
||||
|
||||
Reference in New Issue
Block a user