Skip to content

Commit

Permalink
switch from grpc-netty to grpc-okhttp
Browse files Browse the repository at this point in the history
  • Loading branch information
nbransby committed Jan 4, 2024
1 parent d9fb9b9 commit 4b427e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
8 changes: 3 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ dependencies {
implementation("com.squareup.okhttp:okhttp:2.7.5")
implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("android.arch.lifecycle:common:1.1.1")
implementation("io.grpc:grpc-protobuf-lite:1.44.1")
implementation("io.grpc:grpc-stub:1.44.1")
implementation("io.grpc:grpc-protobuf-lite:1.52.1")
implementation("io.grpc:grpc-stub:1.52.1")
implementation("androidx.collection:collection:1.2.0")
implementation("androidx.lifecycle:lifecycle-common:2.4.0")
// gprc https://github.com/grpc/grpc-java/blob/master/SECURITY.md
implementation("io.grpc:grpc-netty:1.44.1")
implementation("io.netty:netty-tcnative-boringssl-static:2.0.51.Final")
implementation("io.grpc:grpc-okhttp:1.52.1")
}

tasks.named("publishToMavenLocal").configure {
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/android/net/Uri.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package android.net

import io.netty.handler.codec.http.QueryStringDecoder
import java.net.URI
import java.util.*

class Uri(private val uri: URI) {

Expand All @@ -10,12 +10,25 @@ class Uri(private val uri: URI) {
fun parse(uriString: String) = Uri(URI.create(uriString))
}

private val parameters by lazy {
QueryStringDecoder(uri).parameters()
}

val scheme get() = uri.scheme
val port get() = uri.port
val host get() = uri.host
fun getQueryParameter(name: String) = parameters[name]?.first()
}

fun getQueryParameterNames(): Set<String> {
val query: String = uri.query ?: return emptySet()
val names: MutableSet<String> = LinkedHashSet()
var start = 0
do {
val next = query.indexOf('&', start)
val end = if ((next == -1)) query.length else next
var separator = query.indexOf('=', start)
if (separator > end || separator == -1) {
separator = end
}
val name = query.substring(start, separator)
names.add(name)
// Move start to end of name.
start = end + 1
} while (start < query.length)
return Collections.unmodifiableSet(names)
}}
18 changes: 0 additions & 18 deletions src/main/java/com/google/firebase/FirebasePlatform.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.google.firebase

import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.remote.GrpcCallProvider
import com.google.firebase.firestore.util.Supplier
import io.grpc.ManagedChannelBuilder
import io.grpc.netty.NettyChannelBuilder

abstract class FirebasePlatform {

companion object {
Expand All @@ -16,18 +10,6 @@ abstract class FirebasePlatform {
firebasePlatform = platform
// prevent coroutines from thinking its on android
System.setProperty("kotlinx.coroutines.fast.service.loader", "false")

GrpcCallProvider::class.java
.getDeclaredField("overrideChannelBuilderSupplier")
.apply { trySetAccessible() }
.set(
null,
object : Supplier<ManagedChannelBuilder<*>> {
override fun get(): ManagedChannelBuilder<*> = FirebaseFirestore.getInstance(FirebaseApp.INSTANCES.values.first()).firestoreSettings.run {
NettyChannelBuilder.forTarget(host).also { it.takeUnless { isSslEnabled }?.usePlaintext() }
}
}
)
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java

This file was deleted.

0 comments on commit 4b427e1

Please sign in to comment.