From 5049b0109fa90c0074d5428a77ca990041cf39e8 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Fri, 5 May 2023 12:50:35 -0400 Subject: [PATCH 1/2] Check whether signout has been processed Update name for settings tracking of sign out Update name for settings tracking of sign out Update comment --- .../com/shiftyjelly/pocketcasts/preferences/Settings.kt | 8 ++++++++ .../shiftyjelly/pocketcasts/preferences/SettingsImpl.kt | 8 ++++++++ .../pocketcasts/repositories/sync/SyncManagerImpl.kt | 3 +++ .../pocketcasts/repositories/user/UserManager.kt | 4 +++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt index ef8482609ec..2645a94d255 100644 --- a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt +++ b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt @@ -613,4 +613,12 @@ interface Settings { fun setLastSelectedSubscriptionFrequency(frequency: SubscriptionFrequency) fun getLastSelectedSubscriptionFrequency(): SubscriptionFrequency? + + // This boolean should be update to false when a user signs in and should be set to + // true once a user signs out and that sign out has been fully handled + // by the app. This field helps make sure the app fully handles signing a user + // out even if they sign out from outside the app (i.e., from the Android OS's + // account management settings). + fun setFullySignedOut(boolean: Boolean) + fun getFullySignedOut(): Boolean } diff --git a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt index 6b88458bea7..dfbb88c41d1 100644 --- a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt +++ b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt @@ -64,6 +64,7 @@ class SettingsImpl @Inject constructor( private const val CUSTOM_MEDIA_ACTIONS_VISIBLE_KEY = "CustomMediaActionsVisibleKey" private const val LAST_SELECTED_SUBSCRIPTION_TIER_KEY = "LastSelectedSubscriptionTierKey" private const val LAST_SELECTED_SUBSCRIPTION_FREQUENCY_KEY = "LastSelectedSubscriptionFrequencyKey" + private const val PROCESSED_SIGNOUT_KEY = "ProcessedSignout" } private var languageCode: String? = null @@ -1402,4 +1403,11 @@ class SettingsImpl @Inject constructor( getString(LAST_SELECTED_SUBSCRIPTION_FREQUENCY_KEY)?.let { SubscriptionFrequency.valueOf(it) } + + override fun setFullySignedOut(boolean: Boolean) { + setBoolean(PROCESSED_SIGNOUT_KEY, boolean) + } + + override fun getFullySignedOut(): Boolean = + getBoolean(PROCESSED_SIGNOUT_KEY, true) } diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt index 346e9250344..a0eb9907375 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/sync/SyncManagerImpl.kt @@ -188,6 +188,9 @@ class SyncManagerImpl @Inject constructor( val loginResult = try { val response = loginFunction() val result = handleTokenResponse(loginIdentity = loginIdentity, response = response) + + settings.setFullySignedOut(false) + LoginResult.Success(result) } catch (ex: Exception) { Timber.e(ex, "Failed to sign in with Pocket Casts") diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt index 629aa9a122a..0864afcb7a1 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt @@ -91,6 +91,7 @@ class UserManagerImpl @Inject constructor( @OptIn(DelicateCoroutinesApi::class) override fun signOut(playbackManager: PlaybackManager, wasInitiatedByUser: Boolean) { + val hasProcessedSignOut = settings.getFullySignedOut() val wasSignedIn = syncManager.isLoggedIn() LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out") @@ -104,7 +105,7 @@ class UserManagerImpl @Inject constructor( settings.setMarketingOptIn(false) settings.setMarketingOptInNeedsSync(false) settings.setEndOfYearModalHasBeenShown(false) - if (wasSignedIn) { + if (wasSignedIn || !hasProcessedSignOut) { analyticsTracker.track( AnalyticsEvent.USER_SIGNED_OUT, mapOf(KEY_USER_INITIATED to wasInitiatedByUser) @@ -114,5 +115,6 @@ class UserManagerImpl @Inject constructor( analyticsTracker.clearAllData() analyticsTracker.refreshMetadata() } + settings.setFullySignedOut(true) } } From 10f87b78e0fd92492986116d4dd0cd7810ac0dc6 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Fri, 5 May 2023 14:05:54 -0400 Subject: [PATCH 2/2] Avoid sign out work if already fully signed out --- .../repositories/user/UserManager.kt | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt index 0864afcb7a1..b44ce792d70 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/user/UserManager.kt @@ -91,29 +91,26 @@ class UserManagerImpl @Inject constructor( @OptIn(DelicateCoroutinesApi::class) override fun signOut(playbackManager: PlaybackManager, wasInitiatedByUser: Boolean) { - val hasProcessedSignOut = settings.getFullySignedOut() - val wasSignedIn = syncManager.isLoggedIn() - - LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out") - subscriptionManager.clearCachedStatus() - syncManager.signOut { - settings.clearPlusPreferences() - GlobalScope.launch { - userEpisodeManager.removeCloudStatusFromFiles(playbackManager) - } + if (wasInitiatedByUser || !settings.getFullySignedOut()) { + LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out") + subscriptionManager.clearCachedStatus() + syncManager.signOut { + settings.clearPlusPreferences() + GlobalScope.launch { + userEpisodeManager.removeCloudStatusFromFiles(playbackManager) + } - settings.setMarketingOptIn(false) - settings.setMarketingOptInNeedsSync(false) - settings.setEndOfYearModalHasBeenShown(false) - if (wasSignedIn || !hasProcessedSignOut) { + settings.setMarketingOptIn(false) + settings.setMarketingOptInNeedsSync(false) + settings.setEndOfYearModalHasBeenShown(false) analyticsTracker.track( AnalyticsEvent.USER_SIGNED_OUT, mapOf(KEY_USER_INITIATED to wasInitiatedByUser) ) + analyticsTracker.flush() + analyticsTracker.clearAllData() + analyticsTracker.refreshMetadata() } - analyticsTracker.flush() - analyticsTracker.clearAllData() - analyticsTracker.refreshMetadata() } settings.setFullySignedOut(true) }