tmo1 / sms-ie

SMS Import / Export is a simple Android app that imports and exports SMS and MMS messages, call logs, and contacts from and to JSON / NDJSON files.
GNU General Public License v3.0
336 stars 39 forks source link

Exporting contacts crash #50

Closed thanasistrisp closed 2 years ago

thanasistrisp commented 2 years ago

The first time worked, but not as expected (only one contact exported). I have multiple Google accounts with different contacts at each. The second time I tried, the app crashed. Each time after I get this error:

FATAL EXCEPTION: main
Process: com.github.tmo1.sms_ie, PID: 15940
android.database.sqlite.SQLiteException: unknown error (code 0 SQLITE_OK[0]): Unable to convert BLOB to string
    at android.database.CursorWindow.nativeGetString(Native Method)
    at android.database.CursorWindow.getString(CursorWindow.java:480)
    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:53)
    at android.database.CursorWrapper.getString(CursorWrapper.java:141)
    at com.github.tmo1.sms_ie.ImportExportContactsKt.contactsToJSON(ImportExportContacts.kt:135)
    at com.github.tmo1.sms_ie.ImportExportContactsKt.access$contactsToJSON(ImportExportContacts.kt:1)
    at com.github.tmo1.sms_ie.ImportExportContactsKt$contactsToJSON$1.invokeSuspend(Unknown Source:13)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
tmo1 commented 2 years ago

Thanks for reporting this. I have no idea why you only got one contact the first time, or why the app behaved differently between the first and subsequent runs, but I'm pretty sure I can guess what the error you've posted means: the app's code assumes that all the contacts data are strings (which is true in my case), but you apparently have some binary data in your contacts, such as images. I'll post a fixed version for you to try when I get a chance.

tmo1 commented 2 years ago

I was able to reproduce the crash by adding a photo to a contact. The latest commit fixes the problem, at least in my testing. Would you please test the fixed version and report the results here?

thanasistrisp commented 2 years ago

Ok, it's working! However, I see the file is too big! 10 MB for about 300 contacts with the JSON file having 300,000 lines approximately. I see the "contacts_data": [ ... ] section to have multiple duplicate entries. When importing… it imports too many contacts… went more than a thousand, and I stopped it. It did not import anything, maybe because the process should be finished completely.

tmo1 commented 2 years ago

Ok, it's working!

Great - thanks for testing!

However, I see the file is too big! 10 MB for about 300 contacts with the JSON file having 300,000 lines approximately.

I would assume that the size is due to the binary data included. You can search the file for tags ending with __base64__ to see what binary data is included. When encountering such tags, the nearby mimetype tag-value pair will describe the data in question.

For reference, on my phone, with no Google accounts, all contacts stored locally, and no binary data, I recently exported 272 contacts into a file of 1.6M.

I see the "contacts_data": [ ... ] section to have multiple duplicate entries.

The duplication is addressed in the README (see the second paragraph of the linked section).

When importing… it imports too many contacts… went more than a thousand, and I stopped it.

This is also addressed in the README (see the final paragraph of the linked section). This is likely to occur if you have the same contacts within multiple Google accounts. Exactly how many contacts did the app export? (You can either check the final status report displayed by the app at the conclusion of the export, or run jq '. | length' contacts-xxxx-xx-xx.json against the output file.)

It did not import anything, maybe because the process should be finished completely.

Possibly.

thanasistrisp commented 2 years ago

The jq command returned 279 contacts as expected. Tried it in android emulator to import, 836 imported. And all the contacts are imported twice. Indeed, the first contact is correct (with image and all fields) and the second is completely empty, only the name-title is correct.

tmo1 commented 2 years ago

This is a new problem, so I'm closing this issue and opening a new one. Please continue the discussion there.