Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure app has correct SignInType after upgrading #930

Merged
merged 5 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
7.38
-----

7.37.1
-----
* Bug Fixes:
* Fixed an issue that could cause users to be repeatedly logged out of the app.
([#930](https://github.com/Automattic/pocket-casts-android/pull/930)).

7.37
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ class SyncAccountManager @Inject constructor(
AccountConstants.SIGN_IN_TYPE_KEY to AccountConstants.SignInType.Tokens.value,
AccountConstants.LOGIN_IDENTITY to loginIdentity.value
)
accountManager.addAccountExplicitly(account, refreshToken.value, userData)
val accountAdded = accountManager.addAccountExplicitly(account, refreshToken.value, userData)
accountManager.setAuthToken(account, AccountConstants.TOKEN_TYPE, accessToken.value)

// When the account was already added, set the sign in type to Tokens because the account
// does not seem to get updated with this from the userData in the addAccountExplicitly call
if (!accountAdded) {
LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Account already added, setting sign in type to Tokens")
accountManager.setUserData(account, AccountConstants.SIGN_IN_TYPE_KEY, AccountConstants.SignInType.Tokens.value)
}
}

fun signOut() {
Expand All @@ -128,6 +135,7 @@ class SyncAccountManager @Inject constructor(
fun setRefreshToken(refreshToken: RefreshToken) {
val account = getAccount() ?: return
accountManager.setPassword(account, refreshToken.value)
accountManager.setUserData(account, AccountConstants.SIGN_IN_TYPE_KEY, AccountConstants.SignInType.Tokens.value)
}

fun setAccessToken(accessToken: AccessToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class SyncManagerImpl @Inject constructor(
private suspend fun fetchAccessToken(account: Account): AccessToken? {
val refreshToken = syncAccountManager.getRefreshToken(account) ?: return null
return try {
Timber.d("Refreshing the access token")
val signInType = syncAccountManager.getSignInType(account)
LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Fetching the access token, SignInType: $signInType")
val tokenResponse = downloadTokens(
email = account.name,
refreshToken = refreshToken,
syncServerManager = syncServerManager,
signInType = syncAccountManager.getSignInType(account),
signInType = signInType,
signInSource = SignInSource.AccountAuthenticator
)

Expand Down Expand Up @@ -419,9 +419,8 @@ class SyncManagerImpl @Inject constructor(
private suspend fun downloadTokens(
email: String,
refreshToken: RefreshToken,
syncServerManager: SyncServerManager,
Copy link
Contributor Author

@mchowning mchowning May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be passed because the class already has the SyncServerManager stored as a field.

signInSource: SignInSource,
signInType: AccountConstants.SignInType
signInType: AccountConstants.SignInType,
): LoginTokenResponse {
val properties = mapOf(TRACKS_KEY_SIGN_IN_SOURCE to signInSource.analyticsValue)
try {
Expand Down Expand Up @@ -498,7 +497,7 @@ class SyncManagerImpl @Inject constructor(

private suspend fun refreshTokenSuspend(): AccessToken {
syncAccountManager.invalidateAccessToken()
return syncAccountManager.getAccessToken() ?: throw Exception("Failed to get refresh token")
return syncAccountManager.getAccessToken() ?: throw Exception("Failed to get access token")
}

private fun isHttpUnauthorized(throwable: Throwable?): Boolean {
Expand Down