@@ -30,7 +30,6 @@ import com.google.firebase.inject.Provider
30
30
import com.google.firebase.internal.api.FirebaseNoSignedInUserException
31
31
import com.google.firebase.util.nextAlphanumericString
32
32
import java.lang.ref.WeakReference
33
- import java.util.concurrent.atomic.AtomicReference
34
33
import kotlin.coroutines.coroutineContext
35
34
import kotlin.random.Random
36
35
import kotlinx.coroutines.CancellationException
@@ -129,7 +128,7 @@ internal sealed class DataConnectCredentialsTokenManager<T : Any>(
129
128
* coroutines to run on the thread.
130
129
*/
131
130
private val state =
132
- AtomicReference <State <T >>(State .Idle (provider = null , forceTokenRefresh = false ))
131
+ MutableStateFlow <State <T >>(State .Idle (provider = null , forceTokenRefresh = false ))
133
132
134
133
/* *
135
134
* Adds the token listener to the given provider.
@@ -171,7 +170,7 @@ internal sealed class DataConnectCredentialsTokenManager<T : Any>(
171
170
// This function must ONLY be called from close().
172
171
private fun setClosedState () {
173
172
while (true ) {
174
- val oldState = state.get()
173
+ val oldState = state.value
175
174
val providerProvider: ProviderProvider <T > =
176
175
when (oldState) {
177
176
is State .Closed -> return
@@ -194,7 +193,7 @@ internal sealed class DataConnectCredentialsTokenManager<T : Any>(
194
193
suspend fun forceRefresh () {
195
194
logger.debug { " forceRefresh()" }
196
195
while (true ) {
197
- val oldState = state.get()
196
+ val oldState = state.value
198
197
val oldStateProviderProvider =
199
198
when (oldState) {
200
199
is State .Closed -> return
@@ -246,7 +245,7 @@ internal sealed class DataConnectCredentialsTokenManager<T : Any>(
246
245
logger.debug { " $invocationId getToken(requestId=$requestId )" }
247
246
while (true ) {
248
247
val attemptSequenceNumber = nextSequenceNumber()
249
- val oldState = state.get()
248
+ val oldState = state.value
250
249
251
250
val newState: State .Active <T > =
252
251
when (oldState) {
@@ -342,7 +341,7 @@ internal sealed class DataConnectCredentialsTokenManager<T : Any>(
342
341
addTokenListener(newProvider)
343
342
344
343
while (true ) {
345
- val oldState = state.get()
344
+ val oldState = state.value
346
345
val newState =
347
346
when (oldState) {
348
347
is State .Closed -> {
0 commit comments