capacitor-community / contacts

Contacts Plugin for Capacitor
https://capacitor-community.github.io/contacts/
119 stars 52 forks source link

Check for the array length when formatting birthdays on Android #87

Closed leechy closed 1 year ago

leechy commented 1 year ago

On some Samsung phones, I got strings that are not matching the pattern and the application crashes. This way I'm avoiding the error.

tafelnl commented 1 year ago

Do you have information about the Android version and phone type? Also do you know what the birthdayString did look like instead?

Also probably shouldn't allow the application to crash upon receiving an unexpected birthdayString. So I'll probably have to add a try-catch here.

leechy commented 1 year ago

These are pretty old contacts transferred multiple times from device to device, but anyway it's crashing on Samsung Galaxy Tab S6 on Android 12 and Samsung Galaxy S21 on Android 13 (API33).

It's crashing no matter if birthdays are requested or not. Loggins is returning these values:

2022-12-27 14:32:30.899 18363-18363/com.leechylabs.papers V/Capacitor: callback: 72261204, pluginId: Contacts, methodName: getContacts, methodData: {"projection":{"name":true,"birthday":false,"organization":true,"phones":true,"emails":true,"urls":true,"postalAddresses":true,"image":true}}
2022-12-27 14:32:31.024 18363-18473/com.leechylabs.papers D/unexpected birthday: Thu Nov 04 00:00:00 GMT+01:00 1982
2022-12-27 14:32:31.041 18363-18473/com.leechylabs.papers D/unexpected birthday: Sun Jul 16 00:00:00 GMT+01:00 1950

Try-catch may be a good idea, but I'm not a Java expert and for me was easier just to make sure that it's not breaking when trying to access the second item in the array.

tafelnl commented 1 year ago

Hm, weird. That's not a format I've seen before. Looks like a datetime object that got parsed to a human readable string somewhere along the way. Could you please take a look at your native contacts app, to see if that recognizes the birthdays correctly?

tafelnl commented 1 year ago

Also, could you please provide me with a crash log. That makes it a bit easier for me to know at which line exactly the crash happens.

tafelnl commented 1 year ago

I tested a bunch of things, and this seems to be the way to go. Thanks for the PR.

It should've been pointed to v3, but I couldn't edit your branch, so I've added it manually: 47d6bf808fdafb177808843831f67602b0e9e2de