|
|
@ -17,21 +17,21 @@ import kotlin.coroutines.resumeWithException |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
|
|
|
|
|
|
|
|
interface FirebaseTokenGetter { |
|
|
|
interface FirebaseTokenGetter { |
|
|
|
suspend fun get(): String |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This class read the current Firebase token. |
|
|
|
* Read the current Firebase token from FirebaseMessaging. |
|
|
|
* If the token does not exist, it will be generated. |
|
|
|
* If the token does not exist, it will be generated. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
suspend fun get(): String |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ContributesBinding(AppScope::class) |
|
|
|
@ContributesBinding(AppScope::class) |
|
|
|
class DefaultFirebaseTokenGetter @Inject constructor( |
|
|
|
class DefaultFirebaseTokenGetter @Inject constructor( |
|
|
|
private val isPlayServiceAvailable: IsPlayServiceAvailable, |
|
|
|
private val isPlayServiceAvailable: IsPlayServiceAvailable, |
|
|
|
) : FirebaseTokenGetter { |
|
|
|
) : FirebaseTokenGetter { |
|
|
|
override suspend fun get(): String { |
|
|
|
override suspend fun get(): String { |
|
|
|
return suspendCoroutine { continuation -> |
|
|
|
|
|
|
|
// 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features' |
|
|
|
// 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features' |
|
|
|
if (isPlayServiceAvailable.isAvailable()) { |
|
|
|
isPlayServiceAvailable.checkAvailableOrThrow() |
|
|
|
|
|
|
|
return suspendCoroutine { continuation -> |
|
|
|
try { |
|
|
|
try { |
|
|
|
FirebaseMessaging.getInstance().token |
|
|
|
FirebaseMessaging.getInstance().token |
|
|
|
.addOnSuccessListener { token -> |
|
|
|
.addOnSuccessListener { token -> |
|
|
@ -45,11 +45,6 @@ class DefaultFirebaseTokenGetter @Inject constructor( |
|
|
|
Timber.e(e, "## retrievedFirebaseToken() : failed") |
|
|
|
Timber.e(e, "## retrievedFirebaseToken() : failed") |
|
|
|
continuation.resumeWithException(e) |
|
|
|
continuation.resumeWithException(e) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
val e = Exception("No valid Google Play Services found. Cannot use FCM.") |
|
|
|
|
|
|
|
Timber.e(e) |
|
|
|
|
|
|
|
continuation.resumeWithException(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|