From fbe395f071b1d699b0832d6c88eaeb7139e49eae Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 22 Nov 2023 11:00:52 -0500 Subject: [PATCH] Adds logs for lifetime events. --- .../service/playback/PlaybackService.kt | 12 ++++++++ .../vitorpamplona/amethyst/ui/MainActivity.kt | 29 +++++++++++++++++-- .../PushNotificationReceiverService.kt | 7 +++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/playback/PlaybackService.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/playback/PlaybackService.kt index f1e80b39f..2660b318a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/playback/PlaybackService.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/playback/PlaybackService.kt @@ -1,5 +1,7 @@ package com.vitorpamplona.amethyst.service.playback +import android.content.Intent +import android.util.Log import androidx.annotation.OptIn import androidx.media3.common.util.UnstableApi import androidx.media3.datasource.okhttp.OkHttpDataSource @@ -58,6 +60,8 @@ class PlaybackService : MediaSessionService() { override fun onCreate() { super.onCreate() + Log.d("Lifetime Event", "PlaybackService.onCreate") + // Stop all videos and recreates all managers when the proxy changes. HttpClient.proxyChangeListeners.add(this@PlaybackService::onProxyUpdated) } @@ -73,7 +77,15 @@ class PlaybackService : MediaSessionService() { toDestroyProgressive?.releaseAppPlayers() } + override fun onTaskRemoved(rootIntent: Intent?) { + super.onTaskRemoved(rootIntent) + + Log.d("Lifetime Event", "onTaskRemoved") + } + override fun onDestroy() { + Log.d("Lifetime Event", "PlaybackService.onDestroy") + HttpClient.proxyChangeListeners.remove(this@PlaybackService::onProxyUpdated) managerHls?.releaseAppPlayers() diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt index 11d4698f2..e8cfd0a60 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt @@ -65,6 +65,8 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + Log.d("Lifetime Event", "MainActivity.onCreate") + setContent { val sharedPreferencesViewModel: SharedPreferencesViewModel = viewModel() @@ -106,6 +108,8 @@ class MainActivity : AppCompatActivity() { override fun onResume() { super.onResume() + Log.d("Lifetime Event", "MainActivity.onResume") + // starts muted every time DefaultMutedSetting.value = true @@ -130,6 +134,8 @@ class MainActivity : AppCompatActivity() { } override fun onPause() { + Log.d("Lifetime Event", "MainActivity.onPause") + LanguageTranslatorService.clear() serviceManager.cleanObservers() @@ -152,11 +158,28 @@ class MainActivity : AppCompatActivity() { super.onPause() } + override fun onStart() { + super.onStart() + + Log.d("Lifetime Event", "MainActivity.onStart") + } + + override fun onStop() { + super.onStop() + + Log.d("Lifetime Event", "MainActivity.onStop") + } + override fun onDestroy() { + Log.d("Lifetime Event", "MainActivity.onDestroy") + + GlobalScope.launch(Dispatchers.IO) { + keepPlayingMutex?.stop() + keepPlayingMutex?.release() + keepPlayingMutex = null + } + super.onDestroy() - keepPlayingMutex?.stop() - keepPlayingMutex?.release() - keepPlayingMutex = null } /** diff --git a/app/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt b/app/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt index 1c7f47662..b35af836c 100644 --- a/app/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt +++ b/app/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationReceiverService.kt @@ -50,7 +50,14 @@ class PushNotificationReceiverService : FirebaseMessagingService() { } } + override fun onCreate() { + super.onCreate() + Log.d("Lifetime Event", "PushNotificationReceiverService.onCreate") + } + override fun onDestroy() { + Log.d("Lifetime Event", "PushNotificationReceiverService.onDestroy") + scope.cancel() super.onDestroy() }