Skip to content

Commit 7a5319b

Browse files
author
neubauerm
committed
fix: PIN-6554 do not throw un-catchable exception if there are no log files, just return an empty zip.
1 parent 5508bfa commit 7a5319b

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

kotlinlog/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdk 21
1313
targetSdk 34
1414
versionCode 8
15-
versionName "2.2.16"
15+
versionName "2.2.17"
1616
buildConfigField 'int', 'VERSION_CODE', "$versionCode"
1717
buildConfigField 'String', 'VERSION_NAME', "\"$versionName\""
1818
consumerProguardFile('proguard-rules.pro')

kotlinlog/src/main/kotlin/quanti/com/kotlinlog/file/SendLogDialogFragment.kt

+16-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.app.AlertDialog
44
import android.app.Dialog
55
import android.content.DialogInterface
66
import android.content.Intent
7+
import android.os.Build
78
import android.os.Bundle
89
import android.widget.Toast
910
import androidx.fragment.app.DialogFragment
@@ -100,17 +101,6 @@ class SendLogDialogFragment : DialogFragment() {
100101
}
101102
}
102103

103-
private var zipFile: Deferred<File>? = null
104-
105-
override fun onCreate(savedInstanceState: Bundle?) {
106-
super.onCreate(savedInstanceState)
107-
zipFile = CoroutineScope(Dispatchers.IO).async {
108-
val extraFiles = requireArguments().getSerializable(EXTRA_FILES) as ArrayList<File>
109-
val maxFileAge = requireArguments().getInt(MAX_FILE_AGE)
110-
getZipOfLogs(requireActivity().applicationContext, maxFileAge, extraFiles)
111-
}
112-
}
113-
114104
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
115105
val hasFilePermission = requireActivity().applicationContext.hasFileWritePermission()
116106

@@ -146,7 +136,7 @@ class SendLogDialogFragment : DialogFragment() {
146136
val subject =
147137
getString(R.string.logs_email_subject) + " " + getFormattedFileNameDayNow()
148138
val bodyText = getString(R.string.logs_email_text)
149-
val zipFileUri = zipFile?.await()?.getUriForFile(appContext)
139+
val zipFileUri = getZipFileDeferred().await().getUriForFile(appContext)
150140

151141
val intent = Intent(Intent.ACTION_SEND).apply {
152142
type = "message/rfc822" // email
@@ -178,7 +168,7 @@ class SendLogDialogFragment : DialogFragment() {
178168
val appContext = this@SendLogDialogFragment.requireContext().applicationContext
179169

180170
val destinationDir = requireArguments().getString(SAVE_LOGS_DIR_NAME)
181-
val resultPath = zipFile?.await()?.copyLogsToSDCard(requireContext(), destinationDir ?: DEFAULT_SAVE_LOGS_DIR_NAME)
171+
val resultPath = getZipFileDeferred().await().copyLogsToSDCard(requireContext(), destinationDir ?: DEFAULT_SAVE_LOGS_DIR_NAME)
182172

183173
val text = if (resultPath == null) {
184174
"File copy failed"
@@ -192,4 +182,17 @@ class SendLogDialogFragment : DialogFragment() {
192182
Toast.LENGTH_LONG
193183
).show()
194184
}
185+
186+
private fun getZipFileDeferred(): Deferred<File> {
187+
return CoroutineScope(Dispatchers.IO).async {
188+
val extraFiles = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
189+
requireArguments().getSerializable(EXTRA_FILES, ArrayList::class.java)
190+
} else {
191+
@Suppress("DEPRECATION")
192+
requireArguments().getSerializable(EXTRA_FILES)
193+
} as ArrayList<File>
194+
val maxFileAge = requireArguments().getInt(MAX_FILE_AGE)
195+
getZipOfLogs(requireActivity().applicationContext, maxFileAge, extraFiles)
196+
}
197+
}
195198
}

kotlinlog/src/main/kotlin/quanti/com/kotlinlog/utils/FileUtils.kt

-4
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ fun getLogFiles(appCtx: Context, fileAge: Int = 4): List<File> {
194194
appCtx.logFilesDir.listFiles()?.deleteAllZips()
195195
appCtx.logFilesDir.listFiles()?.deleteAllOldFiles(fileAge)
196196

197-
if (appCtx.logFilesDir.listFiles().isNullOrEmpty()) {
198-
throw FileNotFoundException("No files were found")
199-
}
200-
201197
//create metadata info file
202198
MetadataFile(appCtx).apply {
203199
write()

0 commit comments

Comments
 (0)