mirror of
https://github.com/bitwarden/android.git
synced 2026-10-22 02:53:19 -05:00
chore: Update PushManager to clarify Logout logic (#7423)
This commit is contained in:
1 parent
3c0e6449e0
commit
33d5a7baa6
1 file changed
+27
-28
@@ -48,7 +48,7 @@ private val PUSH_TOKEN_UPDATE_DELAY: Duration = 7.days
|
||||
* Primary implementation of [PushManager].
|
||||
*/
|
||||
@Suppress("LongParameterList")
|
||||
class PushManagerImpl @Inject constructor(
|
||||
internal class PushManagerImpl @Inject constructor(
|
||||
private val authDiskSource: AuthDiskSource,
|
||||
private val pushDiskSource: PushDiskSource,
|
||||
private val pushService: PushService,
|
||||
@@ -162,33 +162,7 @@ class PushManagerImpl @Inject constructor(
|
||||
}
|
||||
|
||||
NotificationType.LOG_OUT -> {
|
||||
json
|
||||
.decodeFromString<NotificationPayload.UserNotification>(
|
||||
string = notification.payload,
|
||||
)
|
||||
.takeUnless { it.userId == null }
|
||||
?.takeUnless {
|
||||
featureFlagManager.getFeatureFlag(FlagKey.NoLogoutOnKdfChange) &&
|
||||
it.logOutReason == PushNotificationLogOutReason.KDF_CHANGE
|
||||
}
|
||||
?.let {
|
||||
val userId = requireNotNull(it.userId)
|
||||
when (it.logOutReason) {
|
||||
PushNotificationLogOutReason.KEY_ROTATION -> {
|
||||
// We do not want to logout, we need to sync to help
|
||||
// facilitate the key rotation.
|
||||
mutableFullSyncSharedFlow.tryEmit(userId)
|
||||
}
|
||||
|
||||
PushNotificationLogOutReason.KDF_CHANGE,
|
||||
null,
|
||||
-> {
|
||||
mutableLogoutSharedFlow.tryEmit(
|
||||
NotificationLogoutData(userId = userId),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
handleLogoutPayload(payload = json.decodeFromString(string = notification.payload))
|
||||
}
|
||||
|
||||
NotificationType.SYNC_CIPHER_CREATE,
|
||||
@@ -353,6 +327,31 @@ class PushManagerImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleLogoutPayload(payload: NotificationPayload.UserNotification) {
|
||||
payload
|
||||
.takeUnless { it.userId == null }
|
||||
?.let {
|
||||
val userId = requireNotNull(it.userId)
|
||||
when (it.logOutReason) {
|
||||
PushNotificationLogOutReason.KEY_ROTATION -> {
|
||||
// We do not want to log out, we need to sync to help
|
||||
// facilitate the key rotation.
|
||||
mutableFullSyncSharedFlow.tryEmit(userId)
|
||||
}
|
||||
|
||||
PushNotificationLogOutReason.KDF_CHANGE -> {
|
||||
if (!featureFlagManager.getFeatureFlag(key = FlagKey.NoLogoutOnKdfChange)) {
|
||||
mutableLogoutSharedFlow.tryEmit(NotificationLogoutData(userId = userId))
|
||||
}
|
||||
}
|
||||
|
||||
null -> {
|
||||
mutableLogoutSharedFlow.tryEmit(NotificationLogoutData(userId = userId))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerPushTokenIfNecessary(token: String) {
|
||||
pushDiskSource.registeredPushToken = token
|
||||
|
||||
|
||||
Reference in new issue
Block a user