TP-68421 | handle logout/db/clear task on Silent Notification (#11134)
This commit is contained in:
@@ -35,6 +35,7 @@ import com.navi.alfred.network.AlfredApiLogsManager
|
||||
import com.navi.alfred.utils.AlfredConstants
|
||||
import com.navi.alfred.utils.log
|
||||
import com.navi.analytics.utils.NaviTrackEvent
|
||||
import com.navi.base.cache.repository.NaviCacheRepository
|
||||
import com.navi.base.security.interceptor.EncryptionHashInterceptor
|
||||
import com.navi.base.sharedpref.PreferenceManager
|
||||
import com.navi.base.utils.AppLaunchUtils
|
||||
@@ -95,6 +96,8 @@ open class NaviApplication :
|
||||
// This will initialize NaviPayManager lazily i.e. when NaviPayManager::init() will be called
|
||||
@Inject lateinit var naviPayManager: Provider<NaviPayManager>
|
||||
|
||||
@Inject lateinit var naviCacheRepository: Provider<NaviCacheRepository>
|
||||
|
||||
@Inject lateinit var notificationManager: Provider<NotificationManager>
|
||||
|
||||
private var rnJob = Job()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.naviapp.pushnotification.firebase
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
@@ -44,9 +45,11 @@ import com.navi.common.utils.getSessionId
|
||||
import com.navi.common.utils.log
|
||||
import com.navi.pay.common.utils.NaviPayNotificationHandler
|
||||
import com.naviapp.R
|
||||
import com.naviapp.app.NaviApplication
|
||||
import com.naviapp.common.navigator.NaviDeepLinkNavigator.CHAT_ACTIVITY
|
||||
import com.naviapp.deeplinkmanagement.ui.DeeplinkManagementActivity
|
||||
import com.naviapp.pushnotification.NotificationHandler
|
||||
import com.naviapp.utils.COMMA
|
||||
import com.naviapp.utils.Constants
|
||||
import com.naviapp.utils.Constants.DELIVERED
|
||||
import com.naviapp.utils.Constants.FCM_DELIVERED
|
||||
@@ -54,6 +57,7 @@ import com.naviapp.utils.Constants.MESSAGE_ID
|
||||
import com.naviapp.utils.Constants.NOTIFICATION_PERMISSION_DENIED
|
||||
import com.naviapp.utils.Constants.TEMPLATE_NAME
|
||||
import com.naviapp.utils.FCM_TOKEN
|
||||
import com.naviapp.utils.deleteCacheAndOpenLoginPage
|
||||
import com.naviapp.utils.isNetworkAvailable
|
||||
import java.util.Random
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -168,11 +172,57 @@ class NaviFirebaseMessagingService : FirebaseMessagingService() {
|
||||
NotificationConstants.CANCEL_PUSH_NOTIFICATION -> {
|
||||
cancelPushNotification(context, data)
|
||||
}
|
||||
NotificationConstants.SILENT_PN -> {
|
||||
handleSilentNotificationAction(context, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleSilentNotificationAction(context: Context, data: Map<String, String>) {
|
||||
data[NotificationConstants.ACTION]?.let { action ->
|
||||
when (action) {
|
||||
NotificationConstants.CLEAR_TASK -> clearTask()
|
||||
NotificationConstants.LOGOUT -> deleteCacheAndOpenLoginPage()
|
||||
NotificationConstants.CLEAR_ALL_SHARED_DB -> {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
NaviApplication.instance.naviCacheRepository.get().clearAll()
|
||||
}
|
||||
}
|
||||
NotificationConstants.CLEAR_SHARED_DB_WITH_KEYS -> {
|
||||
clearSharedDbWithKeys(data[NotificationConstants.SHARED_DB_KEYS])
|
||||
}
|
||||
}
|
||||
NaviTrackEvent.trackEventOnClickStream(
|
||||
Constants.SILENT_PN_ACTION,
|
||||
mapOf(Constants.ACTION to action)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearSharedDbWithKeys(sharedDbKeys: String?) {
|
||||
sharedDbKeys?.let {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
it.split(COMMA).forEach { key ->
|
||||
NaviApplication.instance.naviCacheRepository.get().clear(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearTask() {
|
||||
try {
|
||||
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val appTasks = activityManager.appTasks
|
||||
for (task in appTasks) {
|
||||
task.finishAndRemoveTask()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.log()
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendNotification(
|
||||
messageBody: String,
|
||||
title: String,
|
||||
|
||||
@@ -486,6 +486,7 @@ object Constants {
|
||||
const val LENDING_PERMISSION_SCREEN = "LENDING_PERMISSION_SCREEN"
|
||||
const val ON_SYSTEM_BACK_PRESSED = "on_system_back_pressed"
|
||||
const val LENDING_PERMISSION_PAGE_LANDS = "lending_permission_page_lands"
|
||||
const val SILENT_PN_ACTION = "silent_pn_action"
|
||||
|
||||
const val SECTION_CONTENT_SIZE = 3
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2023 by Navi Technologies Limited
|
||||
* * Copyright © 2023-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
@@ -27,4 +27,6 @@ interface NaviCacheDao {
|
||||
|
||||
@Query("DELETE FROM ${NaviSharedDBConstant.TABLE_NAME} WHERE cache_key = :key")
|
||||
suspend fun clear(key: String)
|
||||
|
||||
@Query("DELETE FROM ${NaviSharedDBConstant.TABLE_NAME}") suspend fun clearAll()
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ interface NaviCacheRepository {
|
||||
|
||||
suspend fun clearOnLogout()
|
||||
|
||||
suspend fun clearAll()
|
||||
|
||||
suspend fun getDataOrFetchFromAltSource(
|
||||
key: String,
|
||||
version: Long? = null,
|
||||
@@ -95,6 +97,10 @@ class NaviCacheRepositoryImpl @Inject constructor(private val naviCacheDao: Navi
|
||||
naviCacheDao.clearOnLogout()
|
||||
}
|
||||
|
||||
override suspend fun clearAll() {
|
||||
naviCacheDao.clearAll()
|
||||
}
|
||||
|
||||
override suspend fun getDataOrFetchFromAltSource(
|
||||
key: String,
|
||||
version: Long?,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2020-2023 by Navi Technologies Limited
|
||||
* * Copyright © 2020-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
@@ -30,4 +30,11 @@ object NotificationConstants {
|
||||
const val SMALL_ICON = "small_icon"
|
||||
const val LARGE_ICON = "large_icon"
|
||||
const val NOTIFICATION_ERROR = "notification_error"
|
||||
const val SILENT_PN = "SILENT_PN"
|
||||
const val ACTION = "action"
|
||||
const val CLEAR_TASK = "clearTask"
|
||||
const val LOGOUT = "logout"
|
||||
const val CLEAR_ALL_SHARED_DB = "clearAllSharedDb"
|
||||
const val CLEAR_SHARED_DB_WITH_KEYS = "clearSharedDbWithKeys"
|
||||
const val SHARED_DB_KEYS = "sharedDbKeys"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user