android, desktop: adapted code for self destruct for ios logic (#3643)

* android, desktop: adapted code for self destruct for ios logic

* init db in case of periodic && self destruct enabled
This commit is contained in:
Stanislav Dmitrenko
2024-01-09 16:59:21 +07:00
committed by GitHub
parent 61c507e7da
commit a853ba3a15
10 changed files with 39 additions and 23 deletions
@@ -3,11 +3,12 @@ package chat.simplex.app
import android.content.Context
import android.util.Log
import androidx.work.*
import chat.simplex.app.*
import chat.simplex.app.SimplexService.Companion.showPassphraseNotification
import chat.simplex.common.model.ChatController
import chat.simplex.common.views.helpers.DBMigrationResult
import chat.simplex.app.BuildConfig
import chat.simplex.common.platform.chatModel
import chat.simplex.common.platform.initChatControllerAndRunMigrations
import chat.simplex.common.views.helpers.DatabaseUtils
import kotlinx.coroutines.*
import java.util.Date
import java.util.concurrent.TimeUnit
@@ -57,6 +58,10 @@ class MessagesFetcherWork(
val durationSeconds = inputData.getInt(INPUT_DATA_DURATION, 60)
var shouldReschedule = true
try {
// In case of self-destruct is enabled the initialization process will not start in SimplexApp, Let's start it here
if (DatabaseUtils.ksSelfDestructPassword.get() != null && chatModel.chatDbStatus.value == null) {
initChatControllerAndRunMigrations()
}
withTimeout(durationSeconds * 1000L) {
val chatController = ChatController
SimplexService.waitDbMigrationEnds(chatController)
@@ -26,6 +26,7 @@ import kotlinx.coroutines.sync.withLock
import java.io.*
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.system.exitProcess
const val TAG = "SIMPLEX"
@@ -46,8 +47,8 @@ class SimplexApp: Application(), LifecycleEventObserver {
try {
Looper.loop()
} catch (e: Throwable) {
if (e.message != null && e.message!!.startsWith("Unable to start activity")) {
android.os.Process.killProcess(android.os.Process.myPid())
if (e is UnsatisfiedLinkError || e.message?.startsWith("Unable to start activity") == true) {
Process.killProcess(Process.myPid())
break
} else {
// Send it to our exception handled because it will not get the exception otherwise
@@ -63,7 +64,9 @@ class SimplexApp: Application(), LifecycleEventObserver {
tmpDir.deleteRecursively()
tmpDir.mkdir()
initChatControllerAndRunMigrations(false)
if (DatabaseUtils.ksSelfDestructPassword.get() == null) {
initChatControllerAndRunMigrations()
}
ProcessLifecycleOwner.get().lifecycle.addObserver(this@SimplexApp)
}
@@ -72,6 +72,10 @@ class SimplexService: Service() {
stopSelf()
} else {
isServiceStarted = true
// In case of self-destruct is enabled the initialization process will not start in SimplexApp, Let's start it here
if (DatabaseUtils.ksSelfDestructPassword.get() != null && chatModel.chatDbStatus.value == null) {
initChatControllerAndRunMigrations()
}
}
}