Skip to content

Commit 9dcff76

Browse files
committed
Default to not include MMS part sub_ids in import
Some MMS part metadata apparently contain a sub_id field (despite the absence of any mention of this in the API documentation at https://developer.android.com/reference/android/provider/Telephony.Mms.Part), and attempting to import these sub_ids can cause the app to crash with a FileNotFoundException: No entry for content. This is probably related to #128. In any event, this commit fixes the problem by extending the solution to that issue (c56fa0e) to MMS part metadata sub_ids. Addresses: #142 Related: #128
1 parent 7170506 commit 9dcff76

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Note that upon import or wipe, message apps present on the system may not immedi
6464

6565
SMS Import / Export tries to preserve as much data and metadata as possible upon import. Android includes a `sub_id` ([Subscription ID](https://developer.android.com/training/articles/user-data-ids#accounts)) field in both [SMS](https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns) and [MMS](https://developer.android.com/reference/android/provider/Telephony.BaseMmsColumns#SUBSCRIPTION_ID) message metadata. Earlier versions of the app included these `sub_id`s when importing, but this can cause messages to disappear on Android 14 ([issue #128](https://github.com/tmo1/sms-ie/issues/128), [Reddit](https://old.reddit.com/r/android_beta/comments/15mzaij/sms_backup_and_restore_issues/)), so the current default is to set all `sub_id`s to `-1` upon import ([negative values indicate that "the sub id cannot be determined"](https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns#SUBSCRIPTION_ID)). The old behavior is still available via a settings toggle.
6666

67+
Additionally, some MMS part metadata apparently contain a `sub_id` field as well (despite the absence of any mention of this in [the API documentation](https://developer.android.com/reference/android/provider/Telephony.Mms.Part)), and [attempting to import these `sub_id`s can cause the app to crash](https://github.com/tmo1/sms-ie/issues/142). These `sub_id`s are currently handled the same way as the ones in the SMS and MMS metadata.
68+
6769
### Deduplication
6870

6971
SMS Import / Export can attempt to deduplicate messages upon import. If this feature is enabled in the app's settings, the app will check all new messages against the existing message database (including those messages already inserted earlier in the import process) and ignore those it considers to be duplicates of ones already present. This feature is currently considered experimental.

app/src/main/java/com/github/tmo1/sms_ie/ImportExportMessages.kt

+13-8
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ suspend fun importMessages(
412412
if (key in smsColumns) messageMetadata.put(
413413
key, messageJSON.getString(key)
414414
)
415-
}
416-
/* If we don't yet have a 'thread_id' (i.e., the message has a new
415+
}/* If we don't yet have a 'thread_id' (i.e., the message has a new
417416
'thread_id' that we haven't yet encountered and so isn't yet in
418417
'threadIdMap'), then we need to get a new 'thread_id' and record the mapping
419418
between the old and new ones in 'threadIdMap'
@@ -526,8 +525,7 @@ suspend fun importMessages(
526525
addresses.add(address)
527526
}
528527
}
529-
}
530-
/* If we don't yet have a thread_id (i.e., the message has a new
528+
}/* If we don't yet have a thread_id (i.e., the message has a new
531529
thread_id that we haven't yet encountered and so isn't yet in
532530
threadIdMap), then we need to get a new thread_id and record the mapping
533531
between the old and new ones in threadIdMap
@@ -562,8 +560,7 @@ suspend fun importMessages(
562560
addresses.forEach { address ->
563561
address.put(
564562
Telephony.Mms.Addr.MSG_ID, messageId
565-
)
566-
/*Log.v(
563+
)/*Log.v(
567564
LOG_TAG,
568565
"Trying to insert MMS address - metadata:" + address.toString()
569566
)*/
@@ -572,8 +569,7 @@ suspend fun importMessages(
572569
addressUri, address
573570
)
574571
if (insertAddressUri == null) Log.e(
575-
LOG_TAG,
576-
"MMS address insert failed!"
572+
LOG_TAG, "MMS address insert failed!"
577573
)
578574
else Log.d(LOG_TAG, "MMS address insert succeeded")
579575
}
@@ -589,6 +585,15 @@ suspend fun importMessages(
589585
partKey, messagePart.getString(partKey)
590586
)
591587
}
588+
// Some MMS part metadata contain sub_ids, and attempting to import them can cause a FileNotFoundException: No entry for content
589+
// when subsequently trying to write the part's binary data.
590+
// See: https://github.com/tmo1/sms-ie/issues/142
591+
if (!prefs.getBoolean(
592+
"import_sub_ids", false
593+
) && part.containsKey("sub_id")
594+
) {
595+
part.put("sub_id", "-1")
596+
}
592597
val insertPartUri =
593598
appContext.contentResolver.insert(
594599
partUri, part

0 commit comments

Comments
 (0)