Skip to content

Commit

Permalink
[feat]: option not to include device data in archives
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Nov 4, 2023
1 parent 8997f43 commit b28e1a0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class AppPreferences @Inject constructor(
var fallbackToDefaultTerminal
get() = get("pref_fallback_to_default_terminal", true)
set(value) { put("pref_fallback_to_default_terminal", value) }
var includeDeviceInfoInArchives
get() = get("pref_include_device_info_in_archives", true)
set(value) { put("pref_include_device_info_in_archives", value) }

var askedNotificationsPermission
get() = get("pref_asked_notifications_permission", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.f0x1d.logfox.extensions.io.output.putZipEntry
import com.f0x1d.logfox.model.Device
import com.f0x1d.logfox.repository.logging.CrashesRepository
import com.f0x1d.logfox.utils.DateTimeFormatter
import com.f0x1d.logfox.utils.preferences.AppPreferences
import com.f0x1d.logfox.viewmodel.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
Expand All @@ -24,6 +25,7 @@ class CrashDetailsViewModel @Inject constructor(
val dateTimeFormatter: DateTimeFormatter,
private val database: AppDatabase,
private val crashesRepository: CrashesRepository,
private val appPreferences: AppPreferences,
private val device: Device,
application: Application
): BaseViewModel(application) {
Expand All @@ -41,9 +43,17 @@ class CrashDetailsViewModel @Inject constructor(
crash.value?.also { appCrash ->
ctx.contentResolver.openOutputStream(uri)?.use {
it.exportToZip {
putZipEntry("device.txt", device.toString().encodeToByteArray())
if (appPreferences.includeDeviceInfoInArchives) putZipEntry(
"device.txt",
device.toString().encodeToByteArray()
)

putZipEntry("crash.log", appCrash.log.encodeToByteArray())
putZipEntry("dump.log", (appCrash.logDump ?: "").encodeToByteArray())

if (!appCrash.logDump.isNullOrEmpty()) putZipEntry(
"dump.log",
appCrash.logDump.encodeToByteArray()
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.f0x1d.logfox.extensions.io.output.putZipEntry
import com.f0x1d.logfox.model.Device
import com.f0x1d.logfox.repository.logging.RecordingsRepository
import com.f0x1d.logfox.utils.DateTimeFormatter
import com.f0x1d.logfox.utils.preferences.AppPreferences
import com.f0x1d.logfox.viewmodel.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
Expand All @@ -27,6 +28,7 @@ class RecordingViewModel @Inject constructor(
val dateTimeFormatter: DateTimeFormatter,
private val database: AppDatabase,
private val recordingsRepository: RecordingsRepository,
private val appPreferences: AppPreferences,
private val device: Device,
application: Application
): BaseViewModel(application) {
Expand Down Expand Up @@ -55,7 +57,11 @@ class RecordingViewModel @Inject constructor(
ctx.contentResolver.openOutputStream(uri)?.use {
recording.value?.apply {
it.exportToZip {
putZipEntry("device.txt", device.toString().encodeToByteArray())
if (appPreferences.includeDeviceInfoInArchives) putZipEntry(
"device.txt",
device.toString().encodeToByteArray()
)

putZipEntry("recorded.log", File(file))
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@
<string name="date_time">Дата, время</string>
<string name="date_format">Формат даты</string>
<string name="time_format">Формат времени</string>
<string name="archives">Архивы</string>
<string name="include_device_information_in_archives">Добавлять информацию об устройстве при экспорте записей и сбоев</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@
<string name="date_time">Date, time</string>
<string name="date_format">Date format</string>
<string name="time_format">Time format</string>
<string name="archives">Archives</string>
<string name="include_device_information_in_archives">Include device information with exported recordings and crashes</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/xml/settings_service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@
app:widgetLayout="@layout/preference_material_switch"
app:iconSpaceReserved="false" />
</PreferenceCategory>

<PreferenceCategory
android:title="@string/archives"
app:iconSpaceReserved="false"
app:allowDividerAbove="false">

<SwitchPreferenceCompat
android:title="@string/include_device_information_in_archives"
android:key="pref_include_device_info_in_archives"
android:defaultValue="true"
app:singleLineTitle="false"
app:widgetLayout="@layout/preference_material_switch"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit b28e1a0

Please sign in to comment.