sms-ie icon indicating copy to clipboard operation
sms-ie copied to clipboard

Do not crash if mms part data is not exist

Open keydon3 opened this issue 3 years ago • 4 comments

When i export messages with "Include (encoded) binary MMS data", i get fatal error:

07-30 22:41:37.675  7582  7582 D MediaScannerReceiver: action: android.intent.action.MEDIA_SCANNER_SCAN_FILE path: /storage/emulated/0/backup/messages.json
07-30 22:41:37.715  5454  5454 E AndroidRuntime: FATAL EXCEPTION: main
07-30 22:41:37.715  5454  5454 E AndroidRuntime: Process: com.github.tmo1.sms_ie, PID: 5454
07-30 22:41:37.715  5454  5454 E AndroidRuntime: java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:144)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:698)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1410)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1247)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at android.content.ContentResolver.openInputStream(ContentResolver.java:967)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at com.github.tmo1.sms_ie.ImportExportKt.mmsToJSON(ImportExport.kt:374)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at com.github.tmo1.sms_ie.ImportExportKt.access$mmsToJSON(ImportExport.kt:1)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at com.github.tmo1.sms_ie.ImportExportKt$mmsToJSON$1.invokeSuspend(Unknown Source:17)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
07-30 22:41:37.715  5454  5454 E AndroidRuntime:        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
07-30 22:41:37.719  1243  2063 W ActivityManager:   Force finishing activity com.github.tmo1.sms_ie/.MainActivity
07-30 22:41:37.723  1243  2063 E LightsService: Light requested not available on this device. 2
07-30 22:41:37.726  1243  2063 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:966 com.android.server.am.AppErrors.crashApplicationInner:393 com.android.server.am.AppErrors.crashApplication:321 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:14489 com.android.server.am.ActivityManagerService.handleApplicationCrash:14471 
07-30 22:41:37.728  1243  1262 I ActivityManager: Showing crash dialog for package com.github.tmo1.sms_ie u0

Tail in messages.json:

    "parts": [
      {
        "_id": "6",
        "mid": "5",
        "seq": "-1",
        "ct": "application/smil",
        "cid": "<smil>",
        "cl": "smil.xml",
        "text": "<smil>...</smil>"
      },
      {
        "_id": "7",
        "mid": "5",
        "seq": "0",
        "ct": "image/jpeg",
        "cid": "<image000000>",
        "cl": "image000000.jpg",
        "_data": "/data/user_de/0/com.android.providers.telephony/app_parts/PART_1617028091818_image000000.jpg"

Probably it's because the file doesn't exist:

/data/user_de/0/com.android.providers.telephony/app_parts # ls PART_1617028091818_image000000.jpg
ls: PART_1617028091818_image000000.jpg: No such file or directory

Without "Include (encoded) binary MMS data" all works fine.

keydon3 avatar Jul 30 '22 20:07 keydon3

Thank you for reporting this. I'm not sure why Android is providing us with the name of a non-existent file, but perhaps we need to add some sort of null check to work around this. Is this a normal Android system, or have you done low-level manipulation of the filesystem, perhaps deleting the JPG file in question?

tmo1 avatar Aug 05 '22 19:08 tmo1

Is this a normal Android system, or have you done low-level manipulation of the filesystem, perhaps deleting the JPG file in question?

I didn't do any low-level manipulations and didn't delete the JPG file. But I can't guarantee that some software didn't. I'm using a custom build of android (crDroid 4.7 on android 8.1.0), but I will assume that it works like a "normal" android.

keydon3 avatar Aug 27 '22 13:08 keydon3

Thank you. I should probably add a check for problems, even if I don't understand why they would occur :)

tmo1 avatar Aug 28 '22 03:08 tmo1

I've attached a patched version of the app that should catch and log any exceptions thrown when trying to access MMS binary message parts and then continue with the export. Please test it and report back here, if you can. catch-mms-part-access-exceptions.zip

tmo1 avatar Aug 30 '22 03:08 tmo1

catch-mms-part-access-exceptions.zip perfectly works without any errors

keydon3 avatar Sep 18 '22 18:09 keydon3

catch-mms-part-access-exceptions.zip perfectly works without any errors

Thank you! Closing.

[Edit:] It's this commit (below in the thread) that fixes the problem.

tmo1 avatar Sep 19 '22 22:09 tmo1