Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error and crash when receive a push in foreground #143

Closed
jordanbisato opened this issue Aug 29, 2022 · 18 comments
Closed

Error and crash when receive a push in foreground #143

jordanbisato opened this issue Aug 29, 2022 · 18 comments

Comments

@jordanbisato
Copy link
Contributor

jordanbisato commented Aug 29, 2022

Hi,

When i receive a push in foreground on android using the 3.3.1 released version (and with 3.3.1 version from m1g4 too #137) i receive an error:

[DEBUG] FirebaseMsgService: Message Notification Body: TEST
[ERROR] V8Exception: Exception occurred at undefined:1050: Uncaught Error: Attempt to get length of null array
[DEBUG] AndroidRuntime: Shutting down VM

I put some logs into it to get the exactly location of error and it occours on CloudMessagingModule.java inside onMessageReceived in this line: fireEvent("didReceiveMessage", data);

It's possible give a look on it? Thanks!

Using an Xiaomi Mi 9T with Android 10 to test.
SDK 11.0.0.GA

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

can you say what is null? Since that part is in a try/catch it should end up in message exception if that line fails. The V8Exception is thrown by the SDK. Not sure at the moment where it tries to get the length of.

@jordanbisato
Copy link
Contributor Author

No, i can't discover what is null.
I only know it's between the fireEvent on https://github.com/hansemannn/titanium-firebase-cloud-messaging/blob/main/android/src/firebase/cloudmessaging/CloudMessagingModule.java#L239 and before the function of listener in my code.

fcm.addEventListener("didReceiveMessage", onMessage);
function onMessage(e) {
		// Fired for all kind of notifications (foreground, background & closed)
		Ti.API.debug("######### Got message: " + JSON.stringify(e));
		Alloy.Globals.fcm.lastData = e.data;
		Alloy.Globals.fcm.lastData.inBackground = e.inBackground;
	}

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

If you can reproduce it please add a Log.i("---", data.toString()); before to see if the data is filled. And Log.i("---", "Message: " + message); before 238. Perhaps its the message that can't be parsed into a KrollDict.
That lines hasn't been touched for 4 years (besides the linting in the last version)

@hansemannn
Copy link
Owner

Maybe it's related to the "data" changes we merged recently? It would be interesting to know if an earlier version works. But yeah, the debug logs will help!

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

could be but only if it is a data notification. But since Message Notification Body is called it should be a normal notifiaction and not go into that branch. But will check that

@jordanbisato
Copy link
Contributor Author

Huum, i noted something: i was sending a Data notification, but it enter in the if of the message notification.
In background it works well, but on foreground it crash.

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

what are you using to send the notification? And can you show the content?

@jordanbisato
Copy link
Contributor Author

I'm using the firebase console to send the push.
The content of push (in background):

Last data: {"google.original_priority":"high","gcm.n.analytics_data_google.c.a.c_l":"TESTE","google.sent_time":"1661886749988","telaPush":"/aporte/aporte","google.delivered_priority":"high","google.message_id":"0:1661886749998202%452c09d0452c09d0","collapse_key":"br.com.cvpb","gcm.n.analytics_data_google.c.a.ts":"1661886749","gcm.n.analytics_data_google.c.a.c_id":"7234120883046604539","inBackground":true,"google.ttl":"2419200","from":"869891314489","gcm.n.analytics_data_from":"869891314489","gcm.n.analytics_data_google.c.a.e":"1","gcm.n.analytics_data_google.c.a.udt":"0"}

@jordanbisato
Copy link
Contributor Author

jordanbisato commented Aug 30, 2022

And here the log of module on crash:

[DEBUG] �FirebaseMsgService: Message Notification Body: TESTE

[DEBUG] FirebaseCloudMessaging: (Firebase-Messaging-Intent-Handle) [61897,69177] onMessageReceived

[INFO] I/onMessageReceived data: : (Firebase-Messaging-Intent-Handle) [0,69177] {}

[INFO] I/--- : (Firebase-Messaging-Intent-Handle) [1,69178] Message: {messageType=null, data={"telaPush":"\/aporte\/aporte"}, messageId=0:1661886822393990%452c09d0452c09d0, from=869891314489, to=null, title=TESTE, body=TESTE, ttl=2419200, sendTime=1661886822368}

[INFO] I/onMessageReceived data after message: : (Firebase-Messaging-Intent-Handle) [0,69178] {"message":{"messageType":null,"data":{"telaPush":"\/aporte\/aporte"},"messageId":"0:1661886822393990%452c09d0452c09d0","from":"869891314489","to":null,"title":"TESTE","body":"TESTE","ttl":2419200,"sendTime":1661886822368}}

[ERROR] V8Exception: Exception occurred at undefined:1052: Uncaught Error: Attempt to get length of null array

[DEBUG] AndroidRuntime: Shutting down VM

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

so like this ?
Screenshot_20220830_212615
That works fine here.

I wonder if it is realted to: #137 (comment) since you have some other analytics data in your notification.

@jordanbisato
Copy link
Contributor Author

I put a log before this line: https://github.com/hansemannn/titanium-firebase-cloud-messaging/blob/main/android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java#L74

And send a push with data and one without data.

The result:

With data:

[DEBUG] �� �FirebaseMsgService: remoteMessage.getData(): {telaPush=/aporte/aporte}

[DEBUG] �� �FirebaseMsgService: remoteMessage.getNotification(): com.google.firebase.messaging.RemoteMessage$Notification@75a163e

[DEBUG] �� �FirebaseMsgService: Message Notification Body: TESTE

Without data:

[DEBUG] �� �FirebaseMsgService: remoteMessage.getData(): {}

[DEBUG] �� �FirebaseMsgService: remoteMessage.getNotification(): com.google.firebase.messaging.RemoteMessage$Notification@a9fa087

[DEBUG] �� �FirebaseMsgService: Message Notification Body: TESTE

Both entered in the if.

I think we need verify if data is truly, because remoteMessage.getNotification() isn't null in both cases.

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

The notification from Firebase is a mixed notification, so it has a notification block and a data part.

So this is my Firebase console push:

Message Notification Body: asdf

Message: {messageType=null, data={"asdf":"234"}, messageId=0:1661888246119579%ac3e80e4ac3e80e4, from=47582397024, to=null, title=asdf, body=asdf, ttl=2419200, sendTime=1661888190127}

KrollDict: {"message":{"messageType":null,"data":{"asdf":"234"},"messageId":"0:1661888246119579%ac3e80e4ac3e80e4","from":"47582397024","to":null,"title":"asdf","body":"asdf","ttl":2419200,"sendTime":1661888190127}}

and this is a data notification using PHP:

Data message: {telaPush=/aporte/aporte, id=1, type=noti/data: data part, badge=5, channelId=my_channel1}

Messge: {messageType=null, data={"badge":"5","id":"1","type":"noti\/data: data part","telaPush":"\/aporte\/aporte","channelId":"my_channel1"}, messageId=0:1661888210990602%ac3e80e4f9fd7ecd, from=47582397024, to=null, ttl=2419200, sendTime=1661888210973}

KrollDict: {"message":{"messageType":null,"data":{"badge":"5","id":"1","type":"noti\/data: data part","telaPush":"\/aporte\/aporte","channelId":"my_channel1"},"messageId":"0:1661888210990602%ac3e80e4f9fd7ecd","from":"47582397024","to":null,"ttl":2419200,"sendTime":1661888210973}}

Both cases don't crash for me and all of them have the data node.

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

I've found the issue 🤣
your log: Ti.API.debug("######### Got message: " + JSON.stringify(e));

remove that 😉

[ERROR] TiExceptionHandler: (main) [3,108462] /alloy/controllers/index.js:290
[ERROR] TiExceptionHandler: Ti.API.debug("######### Got message: "+JSON.stringify(e)),
[ERROR] TiExceptionHandler:                                             ^
[ERROR] TiExceptionHandler: Error: Attempt to get length of null array
[ERROR] TiExceptionHandler:     at JSON.stringify (<anonymous>)
[ERROR] TiExceptionHandler:     at CloudMessaging.onMessage (/alloy/controllers/index.js:290:45)
[ERROR] TiExceptionHandler:     at CloudMessaging.value (ti:/kroll.js:1604:27)
[ERROR] TiExceptionHandler:     at CloudMessaging.value (ti:/kroll.js:1656:25)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     ti.modules.titanium.android.notificationmanager.NotificationChannelProxy.getVibrationPattern(NotificationChannelProxy.java:225)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:63)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:985)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1219)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] TiExceptionHandler:     android.os.Looper.loopOnce(Looper.java:201)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:288)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:7898)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] V8Exception: Exception occurred at /alloy/controllers/index.js:290: Uncaught Error: Attempt to get length of null array

@jordanbisato
Copy link
Contributor Author

OMG.
THAT'S IT!!!
Hahahaha
Worked now! Thanks again @m1ga

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

But why didn't it show you that log but only the V8 part 🤔

@jordanbisato
Copy link
Contributor Author

And how i can get the data in a foreground notification?
Because JSON.stringify(e) crash, and if i log the e.data or e.inBackground, both are undefined.

@m1ga
Copy link
Collaborator

m1ga commented Aug 30, 2022

I use

if (OS_ANDROID) {
		console.log("Got message: " + JSON.stringify(e.message));
		alert("Got message: " + JSON.stringify(e.message.data));
	} else {
		var data = JSON.parse(e.data || '');
		console.log("Got message: " + JSON.stringify(data));
		alert("Got message: " + JSON.stringify(data));
	}

in my test app

@jordanbisato
Copy link
Contributor Author

It worked like a charm!
You're the man. Thank you.

@m1ga m1ga closed this as completed Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants