NTP-60797 | Move activity foreground counter to common module (#16460)
This commit is contained in:
@@ -63,8 +63,6 @@ open class NaviApplication : BaseApplication(), ImageLoaderFactory, Configuratio
|
||||
isDifferentPackage(this@NaviApplication)
|
||||
}
|
||||
|
||||
private var appForegroundCounter: Int = 0
|
||||
|
||||
override fun onCreate() {
|
||||
TraceManager.init(Config(traceCallback = TraceCallbackImpl()))
|
||||
TraceManager.startTrace(TC.TRACE_APP_STARTUP)
|
||||
@@ -85,12 +83,6 @@ open class NaviApplication : BaseApplication(), ImageLoaderFactory, Configuratio
|
||||
|
||||
fun isDifferentPackage() = isDifferentPackageValue
|
||||
|
||||
fun incrementAppInForeground() = appForegroundCounter++
|
||||
|
||||
fun decrementAppInForeground() = appForegroundCounter--
|
||||
|
||||
fun getAppInForegroundCounter() = appForegroundCounter
|
||||
|
||||
override fun newImageLoader(): ImageLoader = imageLoaderProvider.createImageLoader()
|
||||
|
||||
override val workManagerConfiguration: Configuration
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.navi.analytics.utils.AlfredFacade
|
||||
import com.navi.analytics.utils.NaviTrackEvent
|
||||
import com.navi.base.utils.orFalse
|
||||
import com.navi.base.utils.orZero
|
||||
import com.navi.common.CommonLibManager
|
||||
import com.navi.common.checkmate.core.CheckMateManager
|
||||
import com.navi.common.checkmate.utils.getVerticalFromStackTrace
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper
|
||||
@@ -114,7 +115,7 @@ class AnrErrorHandlerInitializer @Inject constructor() : ComponentInitializer {
|
||||
SCREEN_NAME to (NaviTrackEvent.currentScreenName ?: className),
|
||||
METHOD_NAME to stackTraceElement.methodName,
|
||||
LINE_NUMBER to stackTraceElement.lineNumber.toString(),
|
||||
APP_IN_FOREGROUND to (application.getAppInForegroundCounter() >= 1).toString(),
|
||||
APP_IN_FOREGROUND to CommonLibManager.isAppInForeground().toString(),
|
||||
ANR_MESSAGE to error.message.orEmpty(),
|
||||
TRACE_SIZE to
|
||||
(error.stackTrace.size + error.cause?.stackTrace?.size.orZero()).toString(),
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.navi.analytics.utils.NaviTrackEvent
|
||||
import com.navi.base.utils.AppLaunchUtils
|
||||
import com.navi.base.utils.coroutine.CoroutineManager
|
||||
import com.navi.chat.base.ChatBaseActivity
|
||||
import com.navi.common.CommonLibManager
|
||||
import com.navi.common.NaviActivityLifecycleCallbacks
|
||||
import com.navi.common.checkmate.core.CheckMateManager
|
||||
import com.navi.common.checkmate.model.SessionDetails
|
||||
@@ -64,14 +65,14 @@ constructor(
|
||||
}
|
||||
|
||||
override fun onActivityStarted(activity: Activity) {
|
||||
if (application.getAppInForegroundCounter() == 0) {
|
||||
if (CommonLibManager.isAppInForeground().not()) {
|
||||
BiometricPromptUtils.appInForegroundTimeStamp = System.currentTimeMillis()
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
startSessionDetails = getCurrentSessionMetrics(application)
|
||||
}
|
||||
}
|
||||
|
||||
application.incrementAppInForeground()
|
||||
CommonLibManager.incrementAppInForeground()
|
||||
when (activity) {
|
||||
is BaseActivity -> {
|
||||
NaviTrackEvent.setForegroundScreenAndVertical(
|
||||
@@ -108,7 +109,7 @@ constructor(
|
||||
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
|
||||
if (application.getAppInForegroundCounter() > 0) {
|
||||
if (CommonLibManager.isAppInForeground()) {
|
||||
alfredInitializer.alfredOnActivityResumed(application, activity)
|
||||
if (isQaRelease()) {
|
||||
NetWatchUtil.addUniversalButtonToActivity(
|
||||
@@ -145,9 +146,9 @@ constructor(
|
||||
}
|
||||
|
||||
override fun onActivityStopped(activity: Activity) {
|
||||
application.decrementAppInForeground()
|
||||
CommonLibManager.decrementAppInForeground()
|
||||
|
||||
if (application.getAppInForegroundCounter() == 0) {
|
||||
if (CommonLibManager.isAppInForeground().not()) {
|
||||
startSessionDetails?.let { initSessionDetails ->
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val endSessionDetails = getCurrentSessionMetrics(application)
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.navi.alfred.model.EventType
|
||||
import com.navi.analytics.utils.AlfredFacade
|
||||
import com.navi.analytics.utils.NaviTrackEvent
|
||||
import com.navi.base.utils.orZero
|
||||
import com.navi.common.CommonLibManager
|
||||
import com.navi.common.checkmate.core.CheckMateManager
|
||||
import com.navi.common.checkmate.utils.getVerticalFromStackTrace
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper
|
||||
@@ -79,7 +80,7 @@ class CrashHandlerInitializer @Inject constructor() : ComponentInitializer {
|
||||
?: exception.stackTrace.firstOrNull()?.className.orEmpty()),
|
||||
METHOD_NAME to exception.stackTrace.firstOrNull()?.methodName.orEmpty(),
|
||||
LINE_NUMBER to exception.stackTrace.firstOrNull()?.lineNumber.toString(),
|
||||
APP_IN_FOREGROUND to (application.getAppInForegroundCounter() >= 1).toString(),
|
||||
APP_IN_FOREGROUND to CommonLibManager.isAppInForeground().toString(),
|
||||
TRACE_SIZE to
|
||||
(exception.stackTrace.size + exception.cause?.stackTrace?.size.orZero()).toString(),
|
||||
VERTICAL to getVerticalFromStackTrace(exception),
|
||||
|
||||
@@ -33,6 +33,8 @@ object CommonLibManager {
|
||||
commonHttpClient.reactHeaderInterceptor
|
||||
}
|
||||
|
||||
private var appForegroundCounter: Int = 0
|
||||
|
||||
fun getPulseUrl(): String? {
|
||||
return pulseUrl
|
||||
}
|
||||
@@ -97,4 +99,12 @@ object CommonLibManager {
|
||||
fun getHeaderInterceptorForReact(): Interceptor {
|
||||
return reactHeaderInterceptor
|
||||
}
|
||||
|
||||
fun incrementAppInForeground() = appForegroundCounter++
|
||||
|
||||
fun decrementAppInForeground() = appForegroundCounter--
|
||||
|
||||
fun isAppInForeground(): Boolean {
|
||||
return appForegroundCounter > 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user