feat(native): native grpc unaryCall hook

This commit is contained in:
rhunk
2023-08-27 21:09:48 +02:00
parent 84a4f87fb1
commit bf5031d0d0
5 changed files with 172 additions and 17 deletions

View File

@ -1,11 +1,29 @@
package me.rhunk.snapenhance.nativelib
import android.util.Log
class NativeLib {
var nativeUnaryCallCallback: (NativeRequestData) -> Unit = {}
fun initOnce(classloader: ClassLoader) {
System.loadLibrary("nativelib")
init(classloader)
}
@Suppress("unused")
private fun onNativeUnaryCall(uri: String, buffer: ByteArray): NativeRequestData? {
Log.d("SnapEnhance", "onNativeUnaryCall: uri=$uri, bufferSize=${buffer.size}, buffer=${buffer.contentToString()}")
val nativeRequestData = NativeRequestData(uri, buffer)
runCatching {
nativeUnaryCallCallback(nativeRequestData)
}.onFailure {
Log.e("SnapEnhance", "nativeUnaryCallCallback failed", it)
}
if (!nativeRequestData.buffer.contentEquals(buffer) || nativeRequestData.canceled) return nativeRequestData
return null
}
external fun init(classLoader: ClassLoader)
external fun loadConfig(config: NativeConfig)
}

View File

@ -0,0 +1,7 @@
package me.rhunk.snapenhance.nativelib
data class NativeRequestData(
val uri: String,
var buffer: ByteArray,
var canceled: Boolean = false,
)