Try to prevent VFS leaks as much as possible, added logs before each plainFilePath call
This commit is contained in:
parent
1522d3b17d
commit
0e17da27e8
6 changed files with 31 additions and 12 deletions
|
@ -44,7 +44,6 @@ import org.linphone.utils.ImageUtils
|
|||
class ChatMessageContentData(
|
||||
private val chatMessage: ChatMessage,
|
||||
private val contentIndex: Int,
|
||||
|
||||
) {
|
||||
var listener: OnContentClickedListener? = null
|
||||
|
||||
|
@ -144,13 +143,7 @@ class ChatMessageContentData(
|
|||
fun destroy() {
|
||||
scope.cancel()
|
||||
|
||||
val path = filePath.value.orEmpty()
|
||||
if (path.isNotEmpty() && isFileEncrypted) {
|
||||
Log.i("[Content] Deleting file used for preview: $path")
|
||||
FileUtils.deleteFile(path)
|
||||
filePath.value = ""
|
||||
}
|
||||
|
||||
deletePlainFilePath()
|
||||
chatMessage.removeListener(chatMessageListener)
|
||||
|
||||
if (this::voiceRecordingPlayer.isInitialized) {
|
||||
|
@ -180,9 +173,22 @@ class ChatMessageContentData(
|
|||
listener?.onContentClicked(getContent())
|
||||
}
|
||||
|
||||
private fun deletePlainFilePath() {
|
||||
val path = filePath.value.orEmpty()
|
||||
if (path.isNotEmpty() && isFileEncrypted) {
|
||||
Log.i("[Content] Deleting file used for preview: $path")
|
||||
FileUtils.deleteFile(path)
|
||||
filePath.value = ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateContent() {
|
||||
Log.i("[Content] Updating content")
|
||||
deletePlainFilePath()
|
||||
|
||||
val content = getContent()
|
||||
isFileEncrypted = content.isFileEncrypted
|
||||
Log.i("[Content] Is content encrypted ? $isFileEncrypted")
|
||||
|
||||
filePath.value = ""
|
||||
fileName.value = if (content.name.isNullOrEmpty() && !content.filePath.isNullOrEmpty()) {
|
||||
|
@ -198,7 +204,7 @@ class ChatMessageContentData(
|
|||
downloadLabel.value = spannable
|
||||
|
||||
if (content.isFile || (content.isFileTransfer && chatMessage.isOutgoing)) {
|
||||
Log.i("[Content] Is content encrypted ? $isFileEncrypted")
|
||||
Log.i("[Content] Content is encrypted, requesting plain file path")
|
||||
val path = if (isFileEncrypted) content.plainFilePath else content.filePath ?: ""
|
||||
downloadable.value = content.filePath.orEmpty().isEmpty()
|
||||
|
||||
|
@ -320,8 +326,7 @@ class ChatMessageContentData(
|
|||
}
|
||||
voiceRecordingPlayer.addListener(playerListener)
|
||||
|
||||
val content = getContent()
|
||||
val path = if (content.isFileEncrypted) content.plainFilePath else content.filePath ?: ""
|
||||
val path = filePath.value
|
||||
voiceRecordingPlayer.open(path.orEmpty())
|
||||
voiceRecordDuration.value = voiceRecordingPlayer.duration
|
||||
formattedDuration.value = SimpleDateFormat("mm:ss", Locale.getDefault()).format(voiceRecordingPlayer.duration) // is already in milliseconds
|
||||
|
|
|
@ -901,11 +901,13 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
{
|
||||
dialog.dismiss()
|
||||
lifecycleScope.launch {
|
||||
Log.w("[Chat Room] Content is encrypted, requesting plain file path")
|
||||
val plainFilePath = content.plainFilePath
|
||||
Log.i("[Cht Room] Making a copy of [$plainFilePath] to the cache directory before exporting it")
|
||||
val cacheCopyPath = FileUtils.copyFileToCache(plainFilePath)
|
||||
if (cacheCopyPath != null) {
|
||||
Log.i("[Cht Room] Cache copy has been made: $cacheCopyPath")
|
||||
FileUtils.deleteFile(plainFilePath)
|
||||
if (!FileUtils.openFileInThirdPartyApp(requireActivity(), cacheCopyPath)) {
|
||||
showDialogToSuggestOpeningFileAsText()
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
|||
|
||||
override fun onCleared() {
|
||||
attachments.value.orEmpty().forEach(ChatMessageAttachmentData::destroy)
|
||||
pendingChatMessageToReplyTo.value?.destroy()
|
||||
|
||||
if (recorder.state != RecorderState.Closed) {
|
||||
recorder.close()
|
||||
|
|
|
@ -29,7 +29,12 @@ open class FileViewerViewModel(val content: Content) : ViewModel() {
|
|||
private val deleteAfterUse: Boolean = content.isFileEncrypted
|
||||
|
||||
init {
|
||||
filePath = if (deleteAfterUse) content.plainFilePath else content.filePath.orEmpty()
|
||||
filePath = if (deleteAfterUse) {
|
||||
Log.i("[File Viewer] Content is encrypted, requesting plain file path")
|
||||
content.plainFilePath
|
||||
} else {
|
||||
content.filePath.orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
|
|
|
@ -79,6 +79,7 @@ class Api21Compatibility {
|
|||
|
||||
val plainFilePath = content.plainFilePath.orEmpty()
|
||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||
if (filePath == null) {
|
||||
Log.e("[Media Store] Content doesn't have a file path!")
|
||||
|
@ -116,6 +117,7 @@ class Api21Compatibility {
|
|||
|
||||
val plainFilePath = content.plainFilePath.orEmpty()
|
||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||
if (filePath == null) {
|
||||
Log.e("[Media Store] Content doesn't have a file path!")
|
||||
|
@ -154,6 +156,7 @@ class Api21Compatibility {
|
|||
|
||||
val plainFilePath = content.plainFilePath.orEmpty()
|
||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||
if (filePath == null) {
|
||||
Log.e("[Media Store] Content doesn't have a file path!")
|
||||
|
|
|
@ -101,6 +101,7 @@ class Api29Compatibility {
|
|||
suspend fun addImageToMediaStore(context: Context, content: Content): Boolean {
|
||||
val plainFilePath = content.plainFilePath.orEmpty()
|
||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||
if (filePath == null) {
|
||||
Log.e("[Media Store] Content doesn't have a file path!")
|
||||
|
@ -136,6 +137,7 @@ class Api29Compatibility {
|
|||
suspend fun addVideoToMediaStore(context: Context, content: Content): Boolean {
|
||||
val plainFilePath = content.plainFilePath.orEmpty()
|
||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||
if (filePath == null) {
|
||||
Log.e("[Media Store] Content doesn't have a file path!")
|
||||
|
@ -172,6 +174,7 @@ class Api29Compatibility {
|
|||
suspend fun addAudioToMediaStore(context: Context, content: Content): Boolean {
|
||||
val plainFilePath = content.plainFilePath.orEmpty()
|
||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||
if (filePath == null) {
|
||||
Log.e("[Media Store] Content doesn't have a file path!")
|
||||
|
|
Loading…
Reference in a new issue