Skip to content
Snippets Groups Projects
Commit 645706bf authored by Sébastien Blin's avatar Sébastien Blin
Browse files

JamiPushReceiver.kt: avoid crash if non json received

`curl -d "Hi" ${topic}` is crashing Jami because data is not a JSON
object

Change-Id: I7e077d8adafcaa2b836254df66cac9a70346d553
parent 8f9c24df
No related branches found
No related tags found
No related merge requests found
...@@ -29,11 +29,15 @@ import java.net.URI ...@@ -29,11 +29,15 @@ import java.net.URI
class JamiPushReceiver : MessagingReceiver() { class JamiPushReceiver : MessagingReceiver() {
override fun onMessage(context: Context, message: ByteArray, instance: String) { override fun onMessage(context: Context, message: ByteArray, instance: String) {
Log.w("JamiPushReceiver", "onMessage ${String(message)} $instance") Log.w("JamiPushReceiver", "onMessage ${String(message)} $instance")
try {
val obj = JSONObject(String(message)) val obj = JSONObject(String(message))
val msg = HashMap<String, String>() val msg = HashMap<String, String>()
obj.keys().forEach { msg[it] = obj.getString(it) } obj.keys().forEach { msg[it] = obj.getString(it) }
val app = JamiApplication.instance as JamiApplicationUnifiedPush? val app = JamiApplication.instance as JamiApplicationUnifiedPush?
app?.onMessage(msg) app?.onMessage(msg)
} catch(e: Exception) {
Log.e("JamiPushReceiver", "onMessage", e)
}
} }
override fun onNewEndpoint(context: Context, endpoint: String, instance: String) { override fun onNewEndpoint(context: Context, endpoint: String, instance: String) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment