- Added Debug config option to turn on/off logcat messages
This commit is contained in:
@@ -2,7 +2,6 @@ package com.tutpro.baresip
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.*
|
||||
|
||||
|
||||
@@ -30,5 +30,6 @@ object Api {
|
||||
external fun cmd_exec(cmd: String): Int
|
||||
external fun contact_add(contact: String)
|
||||
external fun contacts_remove()
|
||||
external fun log_level_set(level: Int)
|
||||
|
||||
}
|
||||
|
||||
@@ -11,20 +11,19 @@ import android.os.IBinder
|
||||
import android.os.PowerManager
|
||||
import android.support.annotation.Keep
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
import android.os.Build
|
||||
import android.support.v4.app.NotificationCompat.VISIBILITY_PRIVATE
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.net.Network
|
||||
import android.net.NetworkRequest
|
||||
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
import android.net.Network
|
||||
import android.net.NetworkRequest
|
||||
|
||||
class BaresipService: Service() {
|
||||
|
||||
@@ -149,10 +148,21 @@ class BaresipService: Service() {
|
||||
contents = "${contents}opus_application voip\n"
|
||||
write = true
|
||||
}
|
||||
if (!contents.contains("log_level")) {
|
||||
contents = "${contents}log_level 2\n"
|
||||
Api.log_level_set(2)
|
||||
Log.logLevel = Log.LogLevel.WARN
|
||||
write = true
|
||||
} else {
|
||||
val ll = Utils.getNameValue(contents, "log_level")[0].toInt()
|
||||
Api.log_level_set(ll)
|
||||
Log.logLevelSet(ll)
|
||||
}
|
||||
if (write) {
|
||||
Log.d(LOG_TAG, "Writing $contents")
|
||||
Utils.putFileContents(file, contents)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import java.util.ArrayList
|
||||
|
||||
class Call(val callp: String, val ua: UserAgent, val peerURI: String, val dir: String,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.util.Log
|
||||
import java.io.*
|
||||
import java.util.ArrayList
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ListView
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.os.Bundle
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.*
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.*
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@@ -19,12 +18,15 @@ class ConfigActivity : AppCompatActivity() {
|
||||
internal lateinit var dnsServers: EditText
|
||||
internal lateinit var opusBitRate: EditText
|
||||
internal lateinit var iceLite: CheckBox
|
||||
internal lateinit var debug: CheckBox
|
||||
|
||||
private var oldAutoStart = ""
|
||||
private var oldDnsServers = ""
|
||||
private var oldOpusBitrate = ""
|
||||
private var oldIceMode = ""
|
||||
private var oldLogLevel = ""
|
||||
private var save = false
|
||||
private var restart = false
|
||||
private var config = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -62,6 +64,14 @@ class ConfigActivity : AppCompatActivity() {
|
||||
oldIceMode = if (imCv.size == 0) "full" else imCv[0]
|
||||
iceLite.isChecked = oldIceMode == "lite"
|
||||
|
||||
debug = findViewById(R.id.Debug) as CheckBox
|
||||
val dbCv = Utils.getNameValue(config, "log_level")
|
||||
if (dbCv.size == 0)
|
||||
oldLogLevel = "2"
|
||||
else
|
||||
oldLogLevel = dbCv[0]
|
||||
debug.isChecked = oldLogLevel == "0"
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@@ -83,6 +93,7 @@ class ConfigActivity : AppCompatActivity() {
|
||||
config = Utils.removeLinesStartingWithName(config, "auto_start")
|
||||
config += "\nauto_start $autoStartString\n"
|
||||
save = true
|
||||
restart = false
|
||||
}
|
||||
|
||||
val dnsServers = dnsServers.text.toString().trim()
|
||||
@@ -95,6 +106,7 @@ class ConfigActivity : AppCompatActivity() {
|
||||
for (server in dnsServers.split(","))
|
||||
config += "\ndns_server ${server.trim()}\n"
|
||||
save = true
|
||||
restart = true
|
||||
}
|
||||
|
||||
val opusBitRate = opusBitRate.text.toString().trim()
|
||||
@@ -106,6 +118,7 @@ class ConfigActivity : AppCompatActivity() {
|
||||
config = Utils.removeLinesStartingWithName(config, "opus_bitrate")
|
||||
config += "\nopus_bitrate $opusBitRate\n"
|
||||
save = true
|
||||
restart = true
|
||||
}
|
||||
|
||||
var iceModeString = "full"
|
||||
@@ -114,6 +127,17 @@ class ConfigActivity : AppCompatActivity() {
|
||||
config = Utils.removeLinesStartingWithName(config, "ice_mode")
|
||||
config += "\nice_mode $iceModeString\n"
|
||||
save = true
|
||||
restart = true
|
||||
}
|
||||
|
||||
var logLevelString = "2"
|
||||
if (debug.isChecked) logLevelString = "0"
|
||||
if (oldLogLevel != logLevelString) {
|
||||
config = Utils.removeLinesStartingWithName(config, "log_level")
|
||||
config += "\nlog_level $logLevelString\n"
|
||||
Api.log_level_set(logLevelString.toInt())
|
||||
Log.logLevelSet(logLevelString.toInt())
|
||||
save = true
|
||||
}
|
||||
|
||||
if (save) {
|
||||
@@ -127,6 +151,8 @@ class ConfigActivity : AppCompatActivity() {
|
||||
Utils.putFileContents(configFile, newConfig)
|
||||
// Api.reload_config()
|
||||
}
|
||||
|
||||
intent.putExtra("restart", restart )
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
return true
|
||||
@@ -155,6 +181,9 @@ class ConfigActivity : AppCompatActivity() {
|
||||
findViewById(R.id.IceLiteTitle) as TextView-> {
|
||||
Utils.alertView(this, "ICE Lite Mode", getString(R.string.iceLite))
|
||||
}
|
||||
findViewById(R.id.DebugTitle) as TextView-> {
|
||||
Utils.alertView(this, "Debug", getString(R.string.debug))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.*
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.*
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.ImageButton
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
object Log {
|
||||
|
||||
enum class LogLevel {
|
||||
DEBUG, INFO, WARN, ERROR, OFF
|
||||
}
|
||||
|
||||
var logLevel: LogLevel = LogLevel.INFO
|
||||
|
||||
fun logLevelSet(value: Int) {
|
||||
when (value) {
|
||||
0 -> logLevel = Log.LogLevel.DEBUG
|
||||
1 -> logLevel = Log.LogLevel.INFO
|
||||
2 -> logLevel = Log.LogLevel.WARN
|
||||
3 -> logLevel = Log.LogLevel.ERROR
|
||||
4 -> logLevel = Log.LogLevel.OFF
|
||||
}
|
||||
}
|
||||
|
||||
fun d(tag: String, msg: String) {
|
||||
if (logLevel < LogLevel.INFO) android.util.Log.d(tag, msg)
|
||||
}
|
||||
|
||||
fun i(tag: String, msg: String) {
|
||||
if (logLevel < LogLevel.WARN) android.util.Log.i(tag, msg)
|
||||
}
|
||||
|
||||
fun w(tag: String, msg: String) {
|
||||
if (logLevel < LogLevel.ERROR) android.util.Log.w(tag, msg)
|
||||
}
|
||||
|
||||
fun e(tag: String, msg: String) {
|
||||
if (logLevel < LogLevel.OFF) android.util.Log.w(tag, msg)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.content.pm.PackageManager
|
||||
@@ -930,7 +929,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
CONFIG_CODE -> {
|
||||
if (resultCode == RESULT_OK)
|
||||
if ((resultCode == RESULT_OK) &&
|
||||
(data!!.getBooleanExtra("restart", true)))
|
||||
Utils.alertView(this, "Notice",
|
||||
"You need to restart baresip in order to activate saved config!")
|
||||
if (resultCode == RESULT_CANCELED)
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
|
||||
import java.io.File
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.util.Log
|
||||
|
||||
class UserAgent (val uap: String) {
|
||||
|
||||
val account = Account(Api.ua_account(uap))
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.tutpro.baresip
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.os.PowerManager
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Intent
|
||||
|
||||
Reference in New Issue
Block a user