Fix clearing logs on Android and checking if logs need to be deleted

This commit is contained in:
albexk 2024-04-20 17:51:33 +03:00
parent 89703ba58f
commit f14a2add0f
3 changed files with 16 additions and 12 deletions

View file

@ -453,7 +453,7 @@ class AmneziaActivity : QtActivity() {
@Suppress("unused") @Suppress("unused")
fun setSaveLogs(enabled: Boolean) { fun setSaveLogs(enabled: Boolean) {
Log.d(TAG, "Set save logs: $enabled") Log.v(TAG, "Set save logs: $enabled")
mainScope.launch { mainScope.launch {
Log.saveLogs = enabled Log.saveLogs = enabled
vpnServiceMessenger.send { vpnServiceMessenger.send {
@ -473,8 +473,10 @@ class AmneziaActivity : QtActivity() {
@Suppress("unused") @Suppress("unused")
fun clearLogs() { fun clearLogs() {
Log.v(TAG, "Clear logs") Log.v(TAG, "Clear logs")
mainScope.launch {
Log.clearLogs() Log.clearLogs()
} }
}
@Suppress("unused") @Suppress("unused")
fun setScreenshotsEnabled(enabled: Boolean) { fun setScreenshotsEnabled(enabled: Boolean) {

View file

@ -109,11 +109,13 @@ object Log {
"${deviceInfo()}\n${readLogs()}\nLOGCAT:\n${getLogcat()}" "${deviceInfo()}\n${readLogs()}\nLOGCAT:\n${getLogcat()}"
fun clearLogs() { fun clearLogs() {
if (logDir.exists()) {
withLock { withLock {
logFile.delete() logFile.delete()
rotateLogFile.delete() rotateLogFile.delete()
} }
} }
}
private fun log(tag: String, msg: String, priority: Priority) { private fun log(tag: String, msg: String, priority: Priority) {
if (saveLogs && priority != V) saveLogMsg(formatLogMsg(tag, msg, priority)) if (saveLogs && priority != V) saveLogMsg(formatLogMsg(tag, msg, priority))

View file

@ -77,8 +77,6 @@ void SettingsController::toggleLogging(bool enable)
AmneziaVPN::toggleLogging(enable); AmneziaVPN::toggleLogging(enable);
#endif #endif
if (enable == true) { if (enable == true) {
checkIfNeedDisableLogs();
qInfo().noquote() << QString("Logging has enabled on %1 version %2 %3").arg(APPLICATION_NAME, APP_VERSION, GIT_COMMIT_HASH); qInfo().noquote() << QString("Logging has enabled on %1 version %2 %3").arg(APPLICATION_NAME, APP_VERSION, GIT_COMMIT_HASH);
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName(), QSysInfo::currentCpuArchitecture()); qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName(), QSysInfo::currentCpuArchitecture());
} }
@ -216,6 +214,7 @@ bool SettingsController::isCameraPresent()
void SettingsController::checkIfNeedDisableLogs() void SettingsController::checkIfNeedDisableLogs()
{ {
if (m_settings->isSaveLogs()) {
m_loggingDisableDate = m_settings->getLogEnableDate().addDays(14); m_loggingDisableDate = m_settings->getLogEnableDate().addDays(14);
if (m_loggingDisableDate <= QDateTime::currentDateTime()) { if (m_loggingDisableDate <= QDateTime::currentDateTime()) {
toggleLogging(false); toggleLogging(false);
@ -223,3 +222,4 @@ void SettingsController::checkIfNeedDisableLogs()
emit loggingDisableByWatcher(); emit loggingDisableByWatcher();
} }
} }
}