Add logs to debug next time notification request thrashes

Change-Id: I3613db1c5495549a0ea92ec96967b5c408c6aadb
This commit is contained in:
SpiritCroc 2024-09-24 20:02:32 +02:00
parent 2f5aff8fa5
commit a5fa01d5bf
5 changed files with 10 additions and 2 deletions

View File

@ -2,7 +2,7 @@
## From https://developer.android.com/develop/ui/views/notifications/notification-permission#test
PACKAGE_NAME=im.vector.app.debug
PACKAGE_NAME=de.spiritcroc.riotx.debug
# App is newly installed on a device that runs Android 13 or higher:

View File

@ -129,11 +129,13 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
get() = ViewModelProvider(this, viewModelFactory)
fun <T : VectorViewEvents> VectorViewModel<*, *, T>.observeViewEvents(
logTag: String? = null,
observer: (T) -> Unit,
) {
val tag = this@VectorBaseActivity::class.simpleName.toString()
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
logTag?.let { Timber.tag(it).i("observeViewEvents resumed - ${System.identityHashCode(this)}") }
viewEvents
.stream(tag)
.collect {

View File

@ -255,7 +255,8 @@ class HomeActivity :
}
}
homeActivityViewModel.observeViewEvents {
Timber.tag("SC_NP_DBG").i("Starting home event observation")
homeActivityViewModel.observeViewEvents("SC_NP_DBG") {
when (it) {
is HomeActivityViewEvents.AskPasswordToInitCrossSigning -> handleAskPasswordToInitCrossSigning(it)
is HomeActivityViewEvents.CurrentSessionNotVerified -> handleOnNewSession(it)
@ -291,6 +292,7 @@ class HomeActivity :
}
private fun handleShowNotificationDialog() {
Timber.tag("SC_NP_DBG").i("handleShowNotificationDialog")
notificationPermissionManager.eventuallyRequestPermission(this, postPermissionLauncher)
}

View File

@ -118,6 +118,7 @@ class HomeActivityViewModel @AssistedInject constructor(
private fun initialize() {
if (isInitialized) return
Timber.tag("SC_NP_DBG").i("Initialize homeActivity ${System.identityHashCode(this)}")
isInitialized = true
// Ensure Session is syncing
ensureSessionSyncingUseCase.execute()
@ -189,6 +190,7 @@ class HomeActivityViewModel @AssistedInject constructor(
if (!didAskUser) {
_viewEvents.post(HomeActivityViewEvents.ShowAnalyticsOptIn)
} else {
Timber.tag("SC_NP_DBG").i("didAskUser -> ask for notif permission")
_viewEvents.post(HomeActivityViewEvents.ShowNotificationDialog)
}
}
@ -210,6 +212,7 @@ class HomeActivityViewModel @AssistedInject constructor(
}
}
} else {
Timber.tag("SC_NP_DBG").i("no analytics -> ask for notif permission")
_viewEvents.post(HomeActivityViewEvents.ShowNotificationDialog)
}
}

View File

@ -50,6 +50,7 @@ class NotificationPermissionManager @Inject constructor(
) {
if (!sdkIntProvider.isAtLeast(Build.VERSION_CODES.TIRAMISU)) return
if (!vectorPreferences.areNotificationEnabledForDevice() && !ignorePreference) return
timber.log.Timber.tag("SC_NP_DBG").i("Checking notification permission")
checkPermissions(
listOf(Manifest.permission.POST_NOTIFICATIONS),
activity,