diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 3d73377b..1b69d2fd 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -174,6 +174,9 @@ class BaresipService: Service() { } } + if (File(filesDir, "history").exists()) + File(filesDir, "history").renameTo(File(filesDir, "calls")) + Contact.restore() CallHistory.restore() Message.restore() @@ -887,7 +890,7 @@ class BaresipService: Service() { private fun cleanService() { uas.clear() status.clear() - history.clear() + callHistory.clear() messages.clear() if (this::nm.isInitialized) nm.cancelAll() @@ -937,7 +940,7 @@ class BaresipService: Service() { var uas = ArrayList() var status = ArrayList() var calls = ArrayList() - var history = ArrayList() + var callHistory = ArrayList() var messages = ArrayList() var contacts = ArrayList() var chatTexts: MutableMap = mutableMapOf() diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt index bd84c13d..16946270 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt @@ -13,45 +13,41 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String, const val CALL_HISTORY_SIZE = 100 - fun history(): ArrayList { - return BaresipService.history - } - fun add(history: CallHistory) { - BaresipService.history.add(history) + BaresipService.callHistory.add(history) if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) { var i = 0 - for (h in BaresipService.history) + for (h in BaresipService.callHistory) if (h.aor == history.aor) break else i++ - BaresipService.history.removeAt(i) + BaresipService.callHistory.removeAt(i) } } fun clear(aor: String) { - val it = BaresipService.history.iterator() + val it = BaresipService.callHistory.iterator() while (it.hasNext()) if (it.next().aor == aor) it.remove() } fun aorHistorySize(aor: String): Int { - return BaresipService.history.filter { it.aor == aor }.count() + return BaresipService.callHistory.filter { it.aor == aor }.count() } fun aorLatestHistory(aor: String): CallHistory? { - for (h in BaresipService.history.reversed()) + for (h in BaresipService.callHistory.reversed()) if (h.aor == aor) return h return null } fun save() { - Log.d("Baresip", "Saving call history of size ${BaresipService.history.size}") - val file = File(BaresipService.filesPath, "history") + Log.d("Baresip", "Saving history of ${BaresipService.callHistory.size} calls") + val file = File(BaresipService.filesPath, "calls") try { val fos = FileOutputStream(file) val oos = ObjectOutputStream(fos) - oos.writeObject(BaresipService.history) + oos.writeObject(BaresipService.callHistory) oos.close() fos.close() } catch (e: IOException) { @@ -61,22 +57,22 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String, } fun restore() { - val file = File(BaresipService.filesPath, "history") + val file = File(BaresipService.filesPath, "calls") if (file.exists()) try { val fis = FileInputStream(file) val ois = ObjectInputStream(fis) - BaresipService.history = ois.readObject() as ArrayList + BaresipService.callHistory = ois.readObject() as ArrayList ois.close() fis.close() - Log.d("Baresip", "Restored call history of size ${BaresipService.history.size}") + Log.d("Baresip", "Restored history of ${BaresipService.callHistory.size} calls") } catch (e: Exception) { Log.e("Baresip", "InputStream exception: - " + e.toString()) } } fun print() { - for (h in BaresipService.history) + for (h in BaresipService.callHistory) Log.d("Baresip", "[${h.aor}, ${h.peerURI}, ${h.direction}, ${h.connected}]") } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt index a113847c..7b296ab5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -197,8 +197,8 @@ class CallsActivity : AppCompatActivity() { private fun aorGenerateHistory(aor: String) { uaHistory.clear() - for (i in CallHistory.history().indices.reversed()) { - val h = CallHistory.history()[i] + for (i in BaresipService.callHistory.indices.reversed()) { + val h = BaresipService.callHistory[i] if (h.aor == aor) { var direction: Int if (h.direction == "in") @@ -231,7 +231,7 @@ class CallsActivity : AppCompatActivity() { private fun removeUaHistoryAt(i: Int) { for (index in uaHistory[i].indexes) - CallHistory.history().removeAt(index) + BaresipService.callHistory.removeAt(index) uaHistory.removeAt(i) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 103f8663..7ed71247 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -959,7 +959,7 @@ class MainActivity : AppCompatActivity() { } private fun backup(password: String) { - val files = arrayOf("accounts", "config", "contacts", "history", "messages", "uuid", + val files = arrayOf("accounts", "calls", "config", "contacts", "messages", "uuid", "zrtp_cache.dat", "zrtp_zid", "cert.pem", "ca_cert", "ca_certs.crt") val backupFilePath = BaresipService.downloadsPath + "/baresip.bs" val zipFilePath = BaresipService.filesPath + "/baresip.zip" diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index f8208bcb..c0a7754a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -414,7 +414,7 @@ object Utils { } fun unZip(zipFilePath: String): Boolean { - val allFiles = listOf("accounts", "config", "contacts", "history", "messages", "uuid", + val allFiles = listOf("accounts", "calls", "config", "contacts", "messages", "uuid", "zrtp_cache.dat", "zrtp_zid", "cert.pem", "ca_cert", "ca_certs.crt") val zipFiles = mutableListOf() try {