- Added Debug config option to turn on/off logcat messages

This commit is contained in:
Juha Heinanen
2019-04-12 18:13:39 +03:00
parent eb81b77cea
commit 4afe9ca23c
22 changed files with 120 additions and 27 deletions
+12 -6
View File
@@ -7,16 +7,18 @@
#include <baresip.h> #include <baresip.h>
#define LOGD(...) \ #define LOGD(...) \
((void)__android_log_print(ANDROID_LOG_DEBUG, "Baresip", __VA_ARGS__)) if (log_level_get() < LEVEL_INFO) ((void)__android_log_print(ANDROID_LOG_DEBUG, "Baresip Lib", __VA_ARGS__))
#define LOGI(...) \ #define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, "Baresip", __VA_ARGS__)) if (log_level_get() < LEVEL_WARN) ((void)__android_log_print(ANDROID_LOG_DEBUG, "Baresip Lib", __VA_ARGS__))
#define LOGW(...) \ #define LOGW(...) \
((void)__android_log_print(ANDROID_LOG_WARN, "Baresip", __VA_ARGS__)) if (log_level_get() < LEVEL_ERROR) ((void)__android_log_print(ANDROID_LOG_DEBUG, "Baresip Lib", __VA_ARGS__))
#define LOGE(...) \ #define LOGE(...) \
((void)__android_log_print(ANDROID_LOG_ERROR, "Baresip", __VA_ARGS__)) if (log_level_get() <= LEVEL_ERROR) ((void)__android_log_print(ANDROID_LOG_DEBUG, "Baresip Lib", __VA_ARGS__))
typedef struct baresip_context { typedef struct baresip_context {
JavaVM *javaVM; JavaVM *javaVM;
@@ -1305,7 +1307,6 @@ Java_com_tutpro_baresip_Api_contact_1add(JNIEnv *env, jobject thiz, jstring java
} else { } else {
LOGD("added contact %s\n", native_contact); LOGD("added contact %s\n", native_contact);
} }
return;
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
@@ -1316,7 +1317,12 @@ Java_com_tutpro_baresip_Api_contacts_1remove(JNIEnv *env, jobject thiz) {
struct contact *c = le->data; struct contact *c = le->data;
contact_remove(baresip_contacts(), c); contact_remove(baresip_contacts(), c);
} }
return;
} }
JNIEXPORT void JNICALL
Java_com_tutpro_baresip_Api_log_1level_1set(JNIEnv *env, jobject thiz, jint level) {
const enum log_level native_level = (enum log_level)level;
LOGD("seting log level '%u'\n", native_level);
log_level_set(native_level);
}
@@ -2,7 +2,6 @@ package com.tutpro.baresip
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@@ -5,7 +5,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import android.widget.* import android.widget.*
@@ -30,5 +30,6 @@ object Api {
external fun cmd_exec(cmd: String): Int external fun cmd_exec(cmd: String): Int
external fun contact_add(contact: String) external fun contact_add(contact: String)
external fun contacts_remove() 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.os.PowerManager
import android.support.annotation.Keep import android.support.annotation.Keep
import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationCompat
import android.util.Log
import android.view.View import android.view.View
import android.widget.RemoteViews import android.widget.RemoteViews
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.os.Build import android.os.Build
import android.support.v4.app.NotificationCompat.VISIBILITY_PRIVATE import android.support.v4.app.NotificationCompat.VISIBILITY_PRIVATE
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
import android.net.Network
import android.net.NetworkRequest
import java.io.File import java.io.File
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.io.InputStream import java.io.InputStream
import java.util.* import java.util.*
import android.net.Network
import android.net.NetworkRequest
class BaresipService: Service() { class BaresipService: Service() {
@@ -149,10 +148,21 @@ class BaresipService: Service() {
contents = "${contents}opus_application voip\n" contents = "${contents}opus_application voip\n"
write = true 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) { if (write) {
Log.d(LOG_TAG, "Writing $contents") Log.d(LOG_TAG, "Writing $contents")
Utils.putFileContents(file, contents) Utils.putFileContents(file, contents)
} }
} }
} }
} }
@@ -1,7 +1,6 @@
package com.tutpro.baresip package com.tutpro.baresip
import android.text.TextWatcher import android.text.TextWatcher
import android.util.Log
import java.util.ArrayList import java.util.ArrayList
class Call(val callp: String, val ua: UserAgent, val peerURI: String, val dir: String, class Call(val callp: String, val ua: UserAgent, val peerURI: String, val dir: String,
@@ -1,6 +1,5 @@
package com.tutpro.baresip package com.tutpro.baresip
import android.util.Log
import java.io.* import java.io.*
import java.util.ArrayList import java.util.ArrayList
import java.util.GregorianCalendar import java.util.GregorianCalendar
@@ -6,7 +6,6 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.ListView import android.widget.ListView
@@ -6,7 +6,6 @@ import android.os.Bundle
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@@ -5,7 +5,6 @@ import android.content.*
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import android.widget.* import android.widget.*
@@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@@ -19,12 +18,15 @@ class ConfigActivity : AppCompatActivity() {
internal lateinit var dnsServers: EditText internal lateinit var dnsServers: EditText
internal lateinit var opusBitRate: EditText internal lateinit var opusBitRate: EditText
internal lateinit var iceLite: CheckBox internal lateinit var iceLite: CheckBox
internal lateinit var debug: CheckBox
private var oldAutoStart = "" private var oldAutoStart = ""
private var oldDnsServers = "" private var oldDnsServers = ""
private var oldOpusBitrate = "" private var oldOpusBitrate = ""
private var oldIceMode = "" private var oldIceMode = ""
private var oldLogLevel = ""
private var save = false private var save = false
private var restart = false
private var config = "" private var config = ""
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -62,6 +64,14 @@ class ConfigActivity : AppCompatActivity() {
oldIceMode = if (imCv.size == 0) "full" else imCv[0] oldIceMode = if (imCv.size == 0) "full" else imCv[0]
iceLite.isChecked = oldIceMode == "lite" 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 { override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -83,6 +93,7 @@ class ConfigActivity : AppCompatActivity() {
config = Utils.removeLinesStartingWithName(config, "auto_start") config = Utils.removeLinesStartingWithName(config, "auto_start")
config += "\nauto_start $autoStartString\n" config += "\nauto_start $autoStartString\n"
save = true save = true
restart = false
} }
val dnsServers = dnsServers.text.toString().trim() val dnsServers = dnsServers.text.toString().trim()
@@ -95,6 +106,7 @@ class ConfigActivity : AppCompatActivity() {
for (server in dnsServers.split(",")) for (server in dnsServers.split(","))
config += "\ndns_server ${server.trim()}\n" config += "\ndns_server ${server.trim()}\n"
save = true save = true
restart = true
} }
val opusBitRate = opusBitRate.text.toString().trim() val opusBitRate = opusBitRate.text.toString().trim()
@@ -106,6 +118,7 @@ class ConfigActivity : AppCompatActivity() {
config = Utils.removeLinesStartingWithName(config, "opus_bitrate") config = Utils.removeLinesStartingWithName(config, "opus_bitrate")
config += "\nopus_bitrate $opusBitRate\n" config += "\nopus_bitrate $opusBitRate\n"
save = true save = true
restart = true
} }
var iceModeString = "full" var iceModeString = "full"
@@ -114,6 +127,17 @@ class ConfigActivity : AppCompatActivity() {
config = Utils.removeLinesStartingWithName(config, "ice_mode") config = Utils.removeLinesStartingWithName(config, "ice_mode")
config += "\nice_mode $iceModeString\n" config += "\nice_mode $iceModeString\n"
save = true 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) { if (save) {
@@ -127,6 +151,8 @@ class ConfigActivity : AppCompatActivity() {
Utils.putFileContents(configFile, newConfig) Utils.putFileContents(configFile, newConfig)
// Api.reload_config() // Api.reload_config()
} }
intent.putExtra("restart", restart )
setResult(RESULT_OK, intent) setResult(RESULT_OK, intent)
finish() finish()
return true return true
@@ -155,6 +181,9 @@ class ConfigActivity : AppCompatActivity() {
findViewById(R.id.IceLiteTitle) as TextView-> { findViewById(R.id.IceLiteTitle) as TextView-> {
Utils.alertView(this, "ICE Lite Mode", getString(R.string.iceLite)) 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.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.* import android.widget.*
@@ -6,7 +6,6 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@@ -5,7 +5,6 @@ import android.content.*
import android.os.Bundle import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.ImageButton 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.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.content.pm.PackageManager import android.content.pm.PackageManager
@@ -930,7 +929,8 @@ class MainActivity : AppCompatActivity() {
} }
CONFIG_CODE -> { CONFIG_CODE -> {
if (resultCode == RESULT_OK) if ((resultCode == RESULT_OK) &&
(data!!.getBooleanExtra("restart", true)))
Utils.alertView(this, "Notice", Utils.alertView(this, "Notice",
"You need to restart baresip in order to activate saved config!") "You need to restart baresip in order to activate saved config!")
if (resultCode == RESULT_CANCELED) if (resultCode == RESULT_CANCELED)
@@ -4,7 +4,6 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log
import java.io.File import java.io.File
@@ -1,7 +1,5 @@
package com.tutpro.baresip package com.tutpro.baresip
import android.util.Log
class UserAgent (val uap: String) { class UserAgent (val uap: String) {
val account = Account(Api.ua_account(uap)) val account = Account(Api.ua_account(uap))
@@ -3,7 +3,6 @@ package com.tutpro.baresip
import android.app.ActivityManager import android.app.ActivityManager
import android.content.Context import android.content.Context
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.util.Log
import android.os.PowerManager import android.os.PowerManager
import android.app.KeyguardManager import android.app.KeyguardManager
import android.content.Intent import android.content.Intent
@@ -123,6 +123,31 @@
</CheckBox> </CheckBox>
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/DebugTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:textSize="18sp"
android:textColor="@android:color/black"
android:onClick="onClick"
android:text="Debug" >
</TextView>
<CheckBox
android:id="@+id/Debug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="end"
android:checked="false" >
</CheckBox>
</RelativeLayout>
</LinearLayout> </LinearLayout>
+1
View File
@@ -54,4 +54,5 @@
<string name="opusBitRate">Average maximum bit rate used by Opus audio stream. <string name="opusBitRate">Average maximum bit rate used by Opus audio stream.
Valid value are 6000-510000. Factory default is 28000.</string> Valid value are 6000-510000. Factory default is 28000.</string>
<string name="iceLite">If checked, ICE Lite Mode is used.</string> <string name="iceLite">If checked, ICE Lite Mode is used.</string>
<string name="debug">If checked, debug and info level log messages are available in logcat.</string>
</resources> </resources>