Skip to content

Commit

Permalink
Update firebase to latest version
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Feb 10, 2023
1 parent a80e4dd commit e46a43f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ updates:
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 99
ignore:
- dependency-name: "com.google.firebase:firebase-bom"
2 changes: 1 addition & 1 deletion mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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&regId=%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) {
Expand Down

0 comments on commit e46a43f

Please sign in to comment.