Skip to content

Commit 4df5ba4

Browse files
AchoArnoldCopilot
andauthored
Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c1dddc3 commit 4df5ba4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,27 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
270270
handleFailed(applicationContext, message.id, e.message ?: "Internal error while building or sending MMS.")
271271
return Result.failure()
272272
} finally {
273+
// Clean up any downloaded temporary files
273274
downloadedFiles.forEach { file ->
274275
if (file.exists()) {
275276
file.delete()
276277
}
277278
}
279+
280+
// Also clean up the MMS PDU file to avoid cache buildup in cases where
281+
// sendMultimediaMessage fails before the sent broadcast is delivered.
282+
try {
283+
val pduFile = java.io.File(applicationContext.cacheDir, "pdu_${message.id}.dat")
284+
if (pduFile.exists()) {
285+
val deleted = pduFile.delete()
286+
if (!deleted) {
287+
Timber.w("Failed to delete MMS PDU file for message ID [${message.id}] at [${pduFile.absolutePath}]")
288+
}
289+
}
290+
} catch (cleanupException: Exception) {
291+
// Best-effort cleanup; log but do not change the original result.
292+
Timber.w(cleanupException, "Error while cleaning up MMS PDU file for message ID [${message.id}]")
293+
}
278294
}
279295
}
280296

0 commit comments

Comments
 (0)