diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 34baf1ac0a..8ba84480e6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,5 +14,3 @@ updates: time: "04:00" timezone: Europe/Berlin open-pull-requests-limit: 99 - ignore: - - dependency-name: "com.google.firebase:firebase-bom" diff --git a/mobile/build.gradle b/mobile/build.gradle index 86c967b478..b0fc22c809 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -169,7 +169,7 @@ dependencies { implementation "com.mikepenz:aboutlibraries:$about_libraries_version" // Firebase - implementation platform("com.google.firebase:firebase-bom:25.11.0") + implementation platform("com.google.firebase:firebase-bom:31.1.1") fullImplementation "com.google.firebase:firebase-messaging-ktx" fullImplementation "com.google.firebase:firebase-crashlytics-ktx" diff --git a/mobile/src/full/java/org/openhab/habdroid/core/FcmRegistrationWorker.kt b/mobile/src/full/java/org/openhab/habdroid/core/FcmRegistrationWorker.kt index e97bccc28e..9ccd8ccafc 100644 --- a/mobile/src/full/java/org/openhab/habdroid/core/FcmRegistrationWorker.kt +++ b/mobile/src/full/java/org/openhab/habdroid/core/FcmRegistrationWorker.kt @@ -30,13 +30,13 @@ import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import androidx.work.WorkRequest import androidx.work.WorkerParameters -import com.google.firebase.iid.FirebaseInstanceId import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.RemoteMessage import java.io.IOException import java.net.URLEncoder import java.util.Locale import java.util.concurrent.TimeUnit +import kotlinx.coroutines.runBlocking import org.openhab.habdroid.R import org.openhab.habdroid.core.connection.CloudConnection import org.openhab.habdroid.core.connection.ConnectionFactory @@ -119,19 +119,25 @@ class FcmRegistrationWorker(private val context: Context, params: WorkerParamete // HttpException is thrown by our HTTP code, IOException can be thrown by FCM @Throws(HttpClient.HttpException::class, IOException::class) private suspend fun registerFcm(connection: CloudConnection) { - val token = FirebaseInstanceId.getInstance().getToken(connection.messagingSenderId, - FirebaseMessaging.INSTANCE_ID_SCOPE) - val deviceName = deviceName + if (Util.isFlavorBeta) " (${context.getString(R.string.beta)})" else "" - val deviceId = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID) + + FirebaseMessaging.getInstance().token.addOnSuccessListener { token: String -> + val deviceName = deviceName + if (Util.isFlavorBeta) " (${context.getString(R.string.beta)})" else "" + val deviceId = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID) + if (Util.isFlavorBeta) "-beta" else "" - val regUrl = String.format(Locale.US, + val registrationUrl = String.format( + Locale.US, "addAndroidRegistration?deviceId=%s&deviceModel=%s®Id=%s", - deviceId, URLEncoder.encode(deviceName, "UTF-8"), token) - - Log.d(TAG, "Register device at openHAB-cloud with URL: $regUrl") - connection.httpClient.get(regUrl).close() - Log.d(TAG, "FCM reg id success") + deviceId, + URLEncoder.encode(deviceName, "UTF-8"), + token + ) + + Log.d(TAG, "Register device at openHAB cloud with URL: $registrationUrl") + runBlocking { + connection.httpClient.get(registrationUrl).close() + } + Log.d(TAG, "FCM reg id success") + } } private fun sendHideNotificationRequest(notificationId: Int, senderId: String) {