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(
|
class ChatMessageContentData(
|
||||||
private val chatMessage: ChatMessage,
|
private val chatMessage: ChatMessage,
|
||||||
private val contentIndex: Int,
|
private val contentIndex: Int,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
var listener: OnContentClickedListener? = null
|
var listener: OnContentClickedListener? = null
|
||||||
|
|
||||||
|
@ -144,13 +143,7 @@ class ChatMessageContentData(
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
scope.cancel()
|
scope.cancel()
|
||||||
|
|
||||||
val path = filePath.value.orEmpty()
|
deletePlainFilePath()
|
||||||
if (path.isNotEmpty() && isFileEncrypted) {
|
|
||||||
Log.i("[Content] Deleting file used for preview: $path")
|
|
||||||
FileUtils.deleteFile(path)
|
|
||||||
filePath.value = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
chatMessage.removeListener(chatMessageListener)
|
chatMessage.removeListener(chatMessageListener)
|
||||||
|
|
||||||
if (this::voiceRecordingPlayer.isInitialized) {
|
if (this::voiceRecordingPlayer.isInitialized) {
|
||||||
|
@ -180,9 +173,22 @@ class ChatMessageContentData(
|
||||||
listener?.onContentClicked(getContent())
|
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() {
|
private fun updateContent() {
|
||||||
|
Log.i("[Content] Updating content")
|
||||||
|
deletePlainFilePath()
|
||||||
|
|
||||||
val content = getContent()
|
val content = getContent()
|
||||||
isFileEncrypted = content.isFileEncrypted
|
isFileEncrypted = content.isFileEncrypted
|
||||||
|
Log.i("[Content] Is content encrypted ? $isFileEncrypted")
|
||||||
|
|
||||||
filePath.value = ""
|
filePath.value = ""
|
||||||
fileName.value = if (content.name.isNullOrEmpty() && !content.filePath.isNullOrEmpty()) {
|
fileName.value = if (content.name.isNullOrEmpty() && !content.filePath.isNullOrEmpty()) {
|
||||||
|
@ -198,7 +204,7 @@ class ChatMessageContentData(
|
||||||
downloadLabel.value = spannable
|
downloadLabel.value = spannable
|
||||||
|
|
||||||
if (content.isFile || (content.isFileTransfer && chatMessage.isOutgoing)) {
|
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 ?: ""
|
val path = if (isFileEncrypted) content.plainFilePath else content.filePath ?: ""
|
||||||
downloadable.value = content.filePath.orEmpty().isEmpty()
|
downloadable.value = content.filePath.orEmpty().isEmpty()
|
||||||
|
|
||||||
|
@ -320,8 +326,7 @@ class ChatMessageContentData(
|
||||||
}
|
}
|
||||||
voiceRecordingPlayer.addListener(playerListener)
|
voiceRecordingPlayer.addListener(playerListener)
|
||||||
|
|
||||||
val content = getContent()
|
val path = filePath.value
|
||||||
val path = if (content.isFileEncrypted) content.plainFilePath else content.filePath ?: ""
|
|
||||||
voiceRecordingPlayer.open(path.orEmpty())
|
voiceRecordingPlayer.open(path.orEmpty())
|
||||||
voiceRecordDuration.value = voiceRecordingPlayer.duration
|
voiceRecordDuration.value = voiceRecordingPlayer.duration
|
||||||
formattedDuration.value = SimpleDateFormat("mm:ss", Locale.getDefault()).format(voiceRecordingPlayer.duration) // is already in milliseconds
|
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()
|
dialog.dismiss()
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
Log.w("[Chat Room] Content is encrypted, requesting plain file path")
|
||||||
val plainFilePath = content.plainFilePath
|
val plainFilePath = content.plainFilePath
|
||||||
Log.i("[Cht Room] Making a copy of [$plainFilePath] to the cache directory before exporting it")
|
Log.i("[Cht Room] Making a copy of [$plainFilePath] to the cache directory before exporting it")
|
||||||
val cacheCopyPath = FileUtils.copyFileToCache(plainFilePath)
|
val cacheCopyPath = FileUtils.copyFileToCache(plainFilePath)
|
||||||
if (cacheCopyPath != null) {
|
if (cacheCopyPath != null) {
|
||||||
Log.i("[Cht Room] Cache copy has been made: $cacheCopyPath")
|
Log.i("[Cht Room] Cache copy has been made: $cacheCopyPath")
|
||||||
|
FileUtils.deleteFile(plainFilePath)
|
||||||
if (!FileUtils.openFileInThirdPartyApp(requireActivity(), cacheCopyPath)) {
|
if (!FileUtils.openFileInThirdPartyApp(requireActivity(), cacheCopyPath)) {
|
||||||
showDialogToSuggestOpeningFileAsText()
|
showDialogToSuggestOpeningFileAsText()
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
attachments.value.orEmpty().forEach(ChatMessageAttachmentData::destroy)
|
attachments.value.orEmpty().forEach(ChatMessageAttachmentData::destroy)
|
||||||
|
pendingChatMessageToReplyTo.value?.destroy()
|
||||||
|
|
||||||
if (recorder.state != RecorderState.Closed) {
|
if (recorder.state != RecorderState.Closed) {
|
||||||
recorder.close()
|
recorder.close()
|
||||||
|
|
|
@ -29,7 +29,12 @@ open class FileViewerViewModel(val content: Content) : ViewModel() {
|
||||||
private val deleteAfterUse: Boolean = content.isFileEncrypted
|
private val deleteAfterUse: Boolean = content.isFileEncrypted
|
||||||
|
|
||||||
init {
|
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() {
|
override fun onCleared() {
|
||||||
|
|
|
@ -79,6 +79,7 @@ class Api21Compatibility {
|
||||||
|
|
||||||
val plainFilePath = content.plainFilePath.orEmpty()
|
val plainFilePath = content.plainFilePath.orEmpty()
|
||||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||||
|
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
Log.e("[Media Store] Content doesn't have a file path!")
|
Log.e("[Media Store] Content doesn't have a file path!")
|
||||||
|
@ -116,6 +117,7 @@ class Api21Compatibility {
|
||||||
|
|
||||||
val plainFilePath = content.plainFilePath.orEmpty()
|
val plainFilePath = content.plainFilePath.orEmpty()
|
||||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||||
|
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
Log.e("[Media Store] Content doesn't have a file path!")
|
Log.e("[Media Store] Content doesn't have a file path!")
|
||||||
|
@ -154,6 +156,7 @@ class Api21Compatibility {
|
||||||
|
|
||||||
val plainFilePath = content.plainFilePath.orEmpty()
|
val plainFilePath = content.plainFilePath.orEmpty()
|
||||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||||
|
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
Log.e("[Media Store] Content doesn't have a file path!")
|
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 {
|
suspend fun addImageToMediaStore(context: Context, content: Content): Boolean {
|
||||||
val plainFilePath = content.plainFilePath.orEmpty()
|
val plainFilePath = content.plainFilePath.orEmpty()
|
||||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||||
|
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
Log.e("[Media Store] Content doesn't have a file path!")
|
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 {
|
suspend fun addVideoToMediaStore(context: Context, content: Content): Boolean {
|
||||||
val plainFilePath = content.plainFilePath.orEmpty()
|
val plainFilePath = content.plainFilePath.orEmpty()
|
||||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||||
|
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
Log.e("[Media Store] Content doesn't have a file path!")
|
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 {
|
suspend fun addAudioToMediaStore(context: Context, content: Content): Boolean {
|
||||||
val plainFilePath = content.plainFilePath.orEmpty()
|
val plainFilePath = content.plainFilePath.orEmpty()
|
||||||
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
val isVfsEncrypted = plainFilePath.isNotEmpty()
|
||||||
|
Log.w("[Media Store] Content is encrypted, requesting plain file path")
|
||||||
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
val filePath = if (isVfsEncrypted) plainFilePath else content.filePath
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
Log.e("[Media Store] Content doesn't have a file path!")
|
Log.e("[Media Store] Content doesn't have a file path!")
|
||||||
|
|
Loading…
Reference in a new issue