More code laundry

This commit is contained in:
Juha Heinanen
2021-03-21 14:58:19 +02:00
parent 340a633ec2
commit 1d95d8f1be
13 changed files with 105 additions and 105 deletions
@@ -79,7 +79,7 @@ class Account(val accp: String) {
if (outbound.size > 0) { if (outbound.size > 0) {
res += ";outbound=\"${outbound[0]}\"" res += ";outbound=\"${outbound[0]}\""
if (outbound.size > 1) res = res + ";outbound2=\"${outbound[1]}\"" if (outbound.size > 1) res += ";outbound2=\"${outbound[1]}\""
res = "$res;sipnat=outbound" res = "$res;sipnat=outbound"
} }
@@ -18,6 +18,8 @@ import java.net.URL
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
private const val TAG = "Baresip"
class AccountActivity : AppCompatActivity() { class AccountActivity : AppCompatActivity() {
private lateinit var binding: ActivityAccountBinding private lateinit var binding: ActivityAccountBinding
@@ -53,7 +55,6 @@ class AccountActivity : AppCompatActivity() {
private var save = false private var save = false
private var uaIndex= -1 private var uaIndex= -1
private val TAG = "Baresip"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -622,7 +623,6 @@ class AccountActivity : AppCompatActivity() {
AsyncTask<String, String, String>() { AsyncTask<String, String, String>() {
private val activityReference: WeakReference<AccountActivity> = WeakReference(context) private val activityReference: WeakReference<AccountActivity> = WeakReference(context)
private val TAG = "Baresip"
override fun doInBackground(vararg url: String?): String? { override fun doInBackground(vararg url: String?): String? {
val result = try { val result = try {
@@ -47,7 +47,7 @@ object Api {
external fun account_extra(acc: String): String external fun account_extra(acc: String): String
external fun account_debug(acc: String) external fun account_debug(acc: String)
external fun uag_reset_transp(reg: Boolean, reinvite: Boolean) external fun uag_reset_transp(register: Boolean, reinvite: Boolean)
external fun uag_enable_sip_trace(enable: Boolean) external fun uag_enable_sip_trace(enable: Boolean)
external fun ua_account(ua: String): String external fun ua_account(ua: String): String
@@ -53,7 +53,7 @@ class AudioActivity : AppCompatActivity() {
tvParams.addRule(RelativeLayout.CENTER_VERTICAL) tvParams.addRule(RelativeLayout.CENTER_VERTICAL)
tvParams.addRule(RelativeLayout.START_OF, id) tvParams.addRule(RelativeLayout.START_OF, id)
tv.layoutParams = tvParams tv.layoutParams = tvParams
tv.text = "\u2022 $module" tv.text = String.format(getString(R.string.bullet_item), module)
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f) tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
tv.setTextColor(ContextCompat.getColor(this, R.color.colorItemText)) tv.setTextColor(ContextCompat.getColor(this, R.color.colorItemText))
rl.addView(tv) rl.addView(tv)
@@ -240,14 +240,12 @@ class AudioActivity : AppCompatActivity() {
} }
private fun checkOpusBitRate(opusBitRate: String): Boolean { private fun checkOpusBitRate(opusBitRate: String): Boolean {
val number = opusBitRate.toIntOrNull() val number = opusBitRate.toIntOrNull() ?: return false
if (number == null) return false
return (number >= 6000) && (number <= 510000) return (number >= 6000) && (number <= 510000)
} }
private fun checkOpusPacketLoss(opusPacketLoss: String): Boolean { private fun checkOpusPacketLoss(opusPacketLoss: String): Boolean {
val number = opusPacketLoss.toIntOrNull() val number = opusPacketLoss.toIntOrNull() ?: return false
if (number == null) return false
return (number >= 0) && (number <= 100) return (number >= 0) && (number <= 100)
} }
@@ -33,9 +33,9 @@ import java.util.*
import kotlin.concurrent.schedule import kotlin.concurrent.schedule
import kotlin.math.roundToInt import kotlin.math.roundToInt
class BaresipService: Service() { private const val TAG = "Baresip Service"
private val LOG_TAG = "Baresip Service" class BaresipService: Service() {
internal lateinit var intent: Intent internal lateinit var intent: Intent
internal lateinit var am: AudioManager internal lateinit var am: AudioManager
@@ -60,7 +60,7 @@ class BaresipService: Service() {
override fun onCreate() { override fun onCreate() {
Log.d(LOG_TAG, "At onCreate") Log.d(TAG, "At onCreate")
intent = Intent("com.tutpro.baresip.EVENT") intent = Intent("com.tutpro.baresip.EVENT")
intent.setPackage("com.tutpro.baresip") intent.setPackage("com.tutpro.baresip")
@@ -91,27 +91,27 @@ class BaresipService: Service() {
override fun onAvailable(network: Network) { override fun onAvailable(network: Network) {
super.onAvailable(network) super.onAvailable(network)
Log.i(LOG_TAG, "Network $network is available") Log.i(TAG, "Network $network is available")
updateNetwork() updateNetwork()
} }
override fun onLost(network: Network) { override fun onLost(network: Network) {
super.onLost(network) super.onLost(network)
Log.i(LOG_TAG, "Network $network is lost") Log.i(TAG, "Network $network is lost")
if (activeNetwork == "$network") if (activeNetwork == "$network")
updateNetwork() updateNetwork()
} }
override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) { override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) {
super.onLinkPropertiesChanged(network, props) super.onLinkPropertiesChanged(network, props)
Log.i(LOG_TAG, "Network $network link properties changed") Log.i(TAG, "Network $network link properties changed")
if (activeNetwork == "$network") if (activeNetwork == "$network")
updateNetwork() updateNetwork()
} }
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) { override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
super.onCapabilitiesChanged(network, caps) super.onCapabilitiesChanged(network, caps)
Log.i(LOG_TAG, "Network $network capabilities changed: $caps") Log.i(TAG, "Network $network capabilities changed: $caps")
} }
} }
) )
@@ -135,20 +135,20 @@ class BaresipService: Service() {
BluetoothHeadset.STATE_DISCONNECTED) BluetoothHeadset.STATE_DISCONNECTED)
when (state) { when (state) {
BluetoothHeadset.STATE_CONNECTED -> { BluetoothHeadset.STATE_CONNECTED -> {
Log.d(LOG_TAG, "Bluetooth headset is connected") Log.d(TAG, "Bluetooth headset is connected")
if (isAudioFocused()) { if (isAudioFocused()) {
// Without delay, SCO_AUDIO_STATE_CONNECTING -> // Without delay, SCO_AUDIO_STATE_CONNECTING ->
// SCO_AUDIO_STATE_DISCONNECTED // SCO_AUDIO_STATE_DISCONNECTED
Timer("Sco", false).schedule(1000) { Timer("Sco", false).schedule(1000) {
Log.d(LOG_TAG, "Starting Bluetooth SCO") Log.d(TAG, "Starting Bluetooth SCO")
am.startBluetoothSco() am.startBluetoothSco()
} }
} }
} }
BluetoothHeadset.STATE_DISCONNECTED -> { BluetoothHeadset.STATE_DISCONNECTED -> {
Log.d(LOG_TAG, "Bluetooth headset is disconnected") Log.d(TAG, "Bluetooth headset is disconnected")
if (am.isBluetoothScoOn) { if (am.isBluetoothScoOn) {
Log.d(LOG_TAG, "Stopping Bluetooth SCO") Log.d(TAG, "Stopping Bluetooth SCO")
am.stopBluetoothSco() am.stopBluetoothSco()
} }
} }
@@ -160,12 +160,12 @@ class BaresipService: Service() {
BluetoothHeadset.STATE_AUDIO_DISCONNECTED) BluetoothHeadset.STATE_AUDIO_DISCONNECTED)
when (state) { when (state) {
BluetoothHeadset.STATE_AUDIO_CONNECTED -> { BluetoothHeadset.STATE_AUDIO_CONNECTED -> {
Log.d(LOG_TAG, "Bluetooth headset audio is connected") Log.d(TAG, "Bluetooth headset audio is connected")
} }
BluetoothHeadset.STATE_AUDIO_DISCONNECTED -> { BluetoothHeadset.STATE_AUDIO_DISCONNECTED -> {
Log.d(LOG_TAG, "Bluetooth headset audio is disconnected") Log.d(TAG, "Bluetooth headset audio is disconnected")
if (am.isBluetoothScoOn) { if (am.isBluetoothScoOn) {
Log.d(LOG_TAG, "Stopping Bluetooth SCO") Log.d(TAG, "Stopping Bluetooth SCO")
am.stopBluetoothSco() am.stopBluetoothSco()
} }
} }
@@ -177,17 +177,17 @@ class BaresipService: Service() {
AudioManager.SCO_AUDIO_STATE_DISCONNECTED) AudioManager.SCO_AUDIO_STATE_DISCONNECTED)
when (state) { when (state) {
AudioManager.SCO_AUDIO_STATE_CONNECTING -> { AudioManager.SCO_AUDIO_STATE_CONNECTING -> {
Log.d(LOG_TAG, "Bluetooth headset SCO is connecting") Log.d(TAG, "Bluetooth headset SCO is connecting")
} }
AudioManager.SCO_AUDIO_STATE_CONNECTED -> { AudioManager.SCO_AUDIO_STATE_CONNECTED -> {
Log.d(LOG_TAG, "Bluetooth headset SCO is connected") Log.d(TAG, "Bluetooth headset SCO is connected")
} }
AudioManager.SCO_AUDIO_STATE_DISCONNECTED -> { AudioManager.SCO_AUDIO_STATE_DISCONNECTED -> {
Log.d(LOG_TAG, "Bluetooth headset SCO is disconnected") Log.d(TAG, "Bluetooth headset SCO is disconnected")
abandonAudioFocus() abandonAudioFocus()
} }
AudioManager.SCO_AUDIO_STATE_ERROR -> { AudioManager.SCO_AUDIO_STATE_ERROR -> {
Log.d(LOG_TAG, "Bluetooth headset SCO state ERROR") Log.d(TAG, "Bluetooth headset SCO state ERROR")
} }
} }
} }
@@ -213,11 +213,11 @@ class BaresipService: Service() {
if (intent == null) { if (intent == null) {
action = "Start" action = "Start"
Log.d(LOG_TAG, "Received onStartCommand with null intent") Log.d(TAG, "Received onStartCommand with null intent")
} else { } else {
// Utils.dumpIntent(intent) // Utils.dumpIntent(intent)
action = intent.action!! action = intent.action!!
Log.d(LOG_TAG, "Received onStartCommand action $action") Log.d(TAG, "Received onStartCommand action $action")
} }
when (action) { when (action) {
@@ -230,20 +230,20 @@ class BaresipService: Service() {
"error.wav", "notfound.wav", "ring.wav", "ringback.wav") "error.wav", "notfound.wav", "ring.wav", "ringback.wav")
var file = File(filesPath) var file = File(filesPath)
if (!file.exists()) { if (!file.exists()) {
Log.d(LOG_TAG, "Creating baresip directory") Log.d(TAG, "Creating baresip directory")
try { try {
File(filesPath).mkdirs() File(filesPath).mkdirs()
} catch (e: Error) { } catch (e: Error) {
Log.e(LOG_TAG, "Failed to create directory: $e") Log.e(TAG, "Failed to create directory: $e")
} }
} }
for (a in assets) { for (a in assets) {
file = File("${filesPath}/$a") file = File("${filesPath}/$a")
if (!file.exists()) { if (!file.exists()) {
Log.d(LOG_TAG, "Copying asset '$a'") Log.d(TAG, "Copying asset '$a'")
Utils.copyAssetToFile(applicationContext, a, "$filesPath/$a") Utils.copyAssetToFile(applicationContext, a, "$filesPath/$a")
} else { } else {
Log.d(LOG_TAG, "Asset '$a' already copied") Log.d(TAG, "Asset '$a' already copied")
} }
if (a == "config") if (a == "config")
Config.initialize() Config.initialize()
@@ -260,7 +260,7 @@ class BaresipService: Service() {
val ipV6Addr = Utils.findIpV6Address(linkAddresses) val ipV6Addr = Utils.findIpV6Address(linkAddresses)
val dnsServers = Utils.findDnsServers(BaresipService.dnsServers) val dnsServers = Utils.findDnsServers(BaresipService.dnsServers)
if ((ipV4Addr == "") && (ipV6Addr == "")) if ((ipV4Addr == "") && (ipV6Addr == ""))
Log.w(LOG_TAG, "Starting baresip without IP addresses") Log.w(TAG, "Starting baresip without IP addresses")
Thread({ Thread({
baresipStart(filesPath, ipV4Addr, ipV6Addr, "", baresipStart(filesPath, ipV4Addr, ipV6Addr, "",
dnsServers, Api.AF_UNSPEC, logLevel) dnsServers, Api.AF_UNSPEC, logLevel)
@@ -301,11 +301,11 @@ class BaresipService: Service() {
val callp = intent!!.getStringExtra("callp")!! val callp = intent!!.getStringExtra("callp")!!
val call = Call.ofCallp(callp) val call = Call.ofCallp(callp)
if (call == null) { if (call == null) {
Log.w(LOG_TAG, "onStartCommand did not find call $callp") Log.w(TAG, "onStartCommand did not find call $callp")
} else { } else {
val peerUri = call.peerUri val peerUri = call.peerUri
val aor = call.ua.account.aor val aor = call.ua.account.aor
Log.d(LOG_TAG, "Aor $aor rejected incoming call $callp from $peerUri") Log.d(TAG, "Aor $aor rejected incoming call $callp from $peerUri")
Api.ua_hangup(call.ua.uap, callp, 486, "Rejected") Api.ua_hangup(call.ua.uap, callp, 486, "Rejected")
if (call.ua.account.callHistory) { if (call.ua.account.callHistory) {
CallHistory.add(CallHistory(aor, peerUri, "in", false)) CallHistory.add(CallHistory(aor, peerUri, "in", false))
@@ -318,7 +318,7 @@ class BaresipService: Service() {
val uap = intent!!.getStringExtra("uap")!! val uap = intent!!.getStringExtra("uap")!!
val ua = UserAgent.ofUap(uap) val ua = UserAgent.ofUap(uap)
if (ua == null) { if (ua == null) {
Log.w(LOG_TAG, "onStartCommand did not find ua $uap") Log.w(TAG, "onStartCommand did not find ua $uap")
} else { } else {
val newIntent = Intent(this, MainActivity::class.java) val newIntent = Intent(this, MainActivity::class.java)
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
@@ -335,7 +335,7 @@ class BaresipService: Service() {
val callp = intent!!.getStringExtra("callp")!! val callp = intent!!.getStringExtra("callp")!!
val call = Call.ofCallp(callp) val call = Call.ofCallp(callp)
if (call == null) if (call == null)
Log.w(LOG_TAG, "onStartCommand did not find call $callp") Log.w(TAG, "onStartCommand did not find call $callp")
else else
call.notifySipfrag(603, "Decline") call.notifySipfrag(603, "Decline")
nm.cancel(TRANSFER_NOTIFICATION_ID) nm.cancel(TRANSFER_NOTIFICATION_ID)
@@ -356,7 +356,7 @@ class BaresipService: Service() {
val uap = intent!!.getStringExtra("uap")!! val uap = intent!!.getStringExtra("uap")!!
val ua = UserAgent.ofUap(uap) val ua = UserAgent.ofUap(uap)
if (ua == null) if (ua == null)
Log.w(LOG_TAG, "onStartCommand did not find UA $uap") Log.w(TAG, "onStartCommand did not find UA $uap")
else else
ChatsActivity.saveUaMessage(ua.account.aor, ChatsActivity.saveUaMessage(ua.account.aor,
intent.getStringExtra("time")!!.toLong()) intent.getStringExtra("time")!!.toLong())
@@ -367,7 +367,7 @@ class BaresipService: Service() {
val uap = intent!!.getStringExtra("uap")!! val uap = intent!!.getStringExtra("uap")!!
val ua = UserAgent.ofUap(uap) val ua = UserAgent.ofUap(uap)
if (ua == null) if (ua == null)
Log.w(LOG_TAG, "onStartCommand did not find UA $uap") Log.w(TAG, "onStartCommand did not find UA $uap")
else else
ChatsActivity.deleteUaMessage(ua.account.aor, ChatsActivity.deleteUaMessage(ua.account.aor,
intent.getStringExtra("time")!!.toLong()) intent.getStringExtra("time")!!.toLong())
@@ -399,7 +399,7 @@ class BaresipService: Service() {
} }
override fun onDestroy() { override fun onDestroy() {
Log.d(LOG_TAG, "At Baresip Service onDestroy") Log.d(TAG, "At Baresip Service onDestroy")
super.onDestroy() super.onDestroy()
this.unregisterReceiver(br) this.unregisterReceiver(br)
if (am.isBluetoothScoOn) am.stopBluetoothSco() if (am.isBluetoothScoOn) am.stopBluetoothSco()
@@ -413,15 +413,15 @@ class BaresipService: Service() {
@Keep @Keep
fun uaAdd(uap: String) { fun uaAdd(uap: String) {
val ua = UserAgent(uap) val ua = UserAgent(uap)
Log.d(LOG_TAG, "uaAdd ${ua.account.aor} at BaresipService") Log.d(TAG, "uaAdd ${ua.account.aor} at BaresipService")
uas.add(ua) uas.add(ua)
if (ua.account.preferIPv6Media) if (ua.account.preferIPv6Media)
Api.ua_set_media_af(ua.uap, Api.AF_INET6) Api.ua_set_media_af(ua.uap, Api.AF_INET6)
if (Api.ua_isregistered(uap)) { if (Api.ua_isregistered(uap)) {
Log.d(LOG_TAG, "Ua ${ua.account.aor} is registered") Log.d(TAG, "Ua ${ua.account.aor} is registered")
status.add(R.drawable.dot_green) status.add(R.drawable.dot_green)
} else { } else {
Log.d(LOG_TAG, "Ua ${ua.account.aor} is NOT registered") Log.d(TAG, "Ua ${ua.account.aor} is NOT registered")
if (ua.account.regint == 0) if (ua.account.regint == 0)
status.add(R.drawable.dot_white) status.add(R.drawable.dot_white)
else else
@@ -434,10 +434,10 @@ class BaresipService: Service() {
if (!isServiceRunning) return if (!isServiceRunning) return
val ua = UserAgent.ofUap(uap) val ua = UserAgent.ofUap(uap)
if (ua == null) { if (ua == null) {
Log.w(LOG_TAG, "uaEvent did not find ua $uap") Log.w(TAG, "uaEvent did not find ua $uap")
return return
} }
Log.d(LOG_TAG, "got uaEvent $event/${ua.account.aor}/$callp") Log.d(TAG, "got uaEvent $event/${ua.account.aor}/$callp")
val aor = ua.account.aor val aor = ua.account.aor
var newEvent: String? = null var newEvent: String? = null
@@ -472,9 +472,9 @@ class BaresipService: Service() {
val props = cm.getLinkProperties(activeNetwork) val props = cm.getLinkProperties(activeNetwork)
if (props != null) { if (props != null) {
val dnsServers = props.dnsServers val dnsServers = props.dnsServers
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers") Log.d(TAG, "Updating DNS Servers = $dnsServers")
if (Config.updateDnsServers(dnsServers) != 0) { if (Config.updateDnsServers(dnsServers) != 0) {
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'") Log.w(TAG, "Failed to update DNS servers '$dnsServers'")
} else { } else {
Api.net_dns_debug() Api.net_dns_debug()
if (!ua.registrationFailed) { if (!ua.registrationFailed) {
@@ -484,7 +484,7 @@ class BaresipService: Service() {
} }
} }
} else { } else {
Log.d(LOG_TAG, "No active network!") Log.d(TAG, "No active network!")
} }
} }
} }
@@ -516,7 +516,7 @@ class BaresipService: Service() {
(tm.callState != TelephonyManager.CALL_STATE_IDLE) || (tm.callState != TelephonyManager.CALL_STATE_IDLE) ||
!Utils.checkPermission(applicationContext, !Utils.checkPermission(applicationContext,
Manifest.permission.RECORD_AUDIO)) { Manifest.permission.RECORD_AUDIO)) {
Log.d(LOG_TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri") Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
Api.ua_hangup(uap, callp, 486, "Busy Here") Api.ua_hangup(uap, callp, 486, "Busy Here")
if (ua.account.callHistory) { if (ua.account.callHistory) {
CallHistory.add(CallHistory(aor, peerUri, "in", false)) CallHistory.add(CallHistory(aor, peerUri, "in", false))
@@ -527,12 +527,12 @@ class BaresipService: Service() {
return return
newEvent = "call rejected" newEvent = "call rejected"
} else { } else {
Log.d(LOG_TAG, "Incoming call $uap/$callp/$peerUri") Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
Call(callp, ua, peerUri, "in", "incoming", Call(callp, ua, peerUri, "in", "incoming",
Utils.dtmfWatcher(callp)).add() Utils.dtmfWatcher(callp)).add()
if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) { if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) {
if (VERSION.SDK_INT >= 23) { if (VERSION.SDK_INT >= 23) {
Log.d(LOG_TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}") Log.d(TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}")
if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL) if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL)
startRinging() startRinging()
} else { } else {
@@ -601,10 +601,10 @@ class BaresipService: Service() {
nm.cancel(CALL_NOTIFICATION_ID) nm.cancel(CALL_NOTIFICATION_ID)
val call = Call.ofCallp(callp) val call = Call.ofCallp(callp)
if (call == null) { if (call == null) {
Log.w(LOG_TAG, "Call $callp that is established is not found") Log.w(TAG, "Call $callp that is established is not found")
return return
} }
Log.d(LOG_TAG, "AoR $aor call $callp established") Log.d(TAG, "AoR $aor call $callp established")
call.status = "connected" call.status = "connected"
call.onhold = false call.onhold = false
if (ua.account.callHistory) { if (ua.account.callHistory) {
@@ -638,7 +638,7 @@ class BaresipService: Service() {
"call transfer" -> { "call transfer" -> {
val call = Call.ofCallp(callp) val call = Call.ofCallp(callp)
if (call == null) { if (call == null) {
Log.w(LOG_TAG, "Call $callp to be transferred is not found") Log.w(TAG, "Call $callp to be transferred is not found")
return return
} }
if (!Utils.isVisible()) { if (!Utils.isVisible()) {
@@ -687,10 +687,10 @@ class BaresipService: Service() {
nm.cancel(CALL_NOTIFICATION_ID) nm.cancel(CALL_NOTIFICATION_ID)
val call = Call.ofCallp(callp) val call = Call.ofCallp(callp)
if (call == null) { if (call == null) {
Log.d(LOG_TAG, "AoR $aor call $callp that is closed is not found") Log.d(TAG, "AoR $aor call $callp that is closed is not found")
return return
} }
Log.d(LOG_TAG, "AoR $aor call $callp is closed") Log.d(TAG, "AoR $aor call $callp is closed")
stopRinging() stopRinging()
call.remove() call.remove()
if (Call.calls().size == 0) { if (Call.calls().size == 0) {
@@ -699,7 +699,7 @@ class BaresipService: Service() {
am.mode = AudioManager.MODE_NORMAL am.mode = AudioManager.MODE_NORMAL
am.isSpeakerphoneOn = false am.isSpeakerphoneOn = false
if (am.isBluetoothScoOn) { if (am.isBluetoothScoOn) {
Log.d(LOG_TAG, "Stopping Bluetooth SCO") Log.d(TAG, "Stopping Bluetooth SCO")
am.stopBluetoothSco() am.stopBluetoothSco()
} else { } else {
abandonAudioFocus() abandonAudioFocus()
@@ -738,11 +738,11 @@ class BaresipService: Service() {
} }
} }
"refer failed" -> { "refer failed" -> {
Log.d(LOG_TAG, "AoR $aor hanging up call $callp with ${ev[1]}") Log.d(TAG, "AoR $aor hanging up call $callp with ${ev[1]}")
Api.ua_hangup(uap, callp, 0, "") Api.ua_hangup(uap, callp, 0, "")
val call = Call.ofCallp(callp) val call = Call.ofCallp(callp)
if (call == null) { if (call == null) {
Log.w(LOG_TAG, "Call $callp with failed refer is not found") Log.w(TAG, "Call $callp with failed refer is not found")
} else { } else {
call.referTo = "" call.referTo = ""
} }
@@ -765,15 +765,15 @@ class BaresipService: Service() {
try { try {
text = String(msg, StandardCharsets.UTF_8) text = String(msg, StandardCharsets.UTF_8)
} catch (e: Exception) { } catch (e: Exception) {
Log.w(LOG_TAG, "UTF-8 decode failed") Log.w(TAG, "UTF-8 decode failed")
} }
val ua = UserAgent.ofUap(uap) val ua = UserAgent.ofUap(uap)
if (ua == null) { if (ua == null) {
Log.w(LOG_TAG, "messageEvent did not find ua $uap") Log.w(TAG, "messageEvent did not find ua $uap")
return return
} }
val timeStamp = System.currentTimeMillis().toString() val timeStamp = System.currentTimeMillis().toString()
Log.d(LOG_TAG, "Message event for $uap from $peer at $timeStamp") Log.d(TAG, "Message event for $uap from $peer at $timeStamp")
Message(ua.account.aor, peer, text, timeStamp.toLong(), Message(ua.account.aor, peer, text, timeStamp.toLong(),
R.drawable.arrow_down_green, 0, "", true).add() R.drawable.arrow_down_green, 0, "", true).add()
Message.save() Message.save()
@@ -835,7 +835,7 @@ class BaresipService: Service() {
@Keep @Keep
fun messageResponse(responseCode: Int, responseReason: String, time: String) { fun messageResponse(responseCode: Int, responseReason: String, time: String) {
Log.d(LOG_TAG, "Message response '$responseCode $responseReason' at $time") Log.d(TAG, "Message response '$responseCode $responseReason' at $time")
val intent = Intent("message response") val intent = Intent("message response")
intent.putExtra("response code", responseCode) intent.putExtra("response code", responseCode)
intent.putExtra("response reason", responseReason) intent.putExtra("response reason", responseReason)
@@ -846,7 +846,7 @@ class BaresipService: Service() {
@Keep @Keep
fun getPassword(aor: String): String { fun getPassword(aor: String): String {
if (!isServiceRunning) return "" if (!isServiceRunning) return ""
Log.d(LOG_TAG, "getPassword of $aor") Log.d(TAG, "getPassword of $aor")
if (MainActivity.aorPasswords[aor] != null) if (MainActivity.aorPasswords[aor] != null)
return MainActivity.aorPasswords[aor]!! return MainActivity.aorPasswords[aor]!!
else else
@@ -855,7 +855,7 @@ class BaresipService: Service() {
@Keep @Keep
fun started() { fun started() {
Log.d(LOG_TAG, "Received 'started' from baresip") Log.d(TAG, "Received 'started' from baresip")
val intent = Intent("service event") val intent = Intent("service event")
intent.putExtra("event", "started") intent.putExtra("event", "started")
intent.putExtra("params", arrayListOf(callActionUri)) intent.putExtra("params", arrayListOf(callActionUri))
@@ -865,7 +865,7 @@ class BaresipService: Service() {
@Keep @Keep
fun stopped(error: String) { fun stopped(error: String) {
Log.d(LOG_TAG, "Received 'stopped' from baresip with param '$error'") Log.d(TAG, "Received 'stopped' from baresip with param '$error'")
isServiceRunning = false isServiceRunning = false
val intent = Intent("service event") val intent = Intent("service event")
intent.putExtra("event", "stopped") intent.putExtra("event", "stopped")
@@ -950,26 +950,26 @@ class BaresipService: Service() {
} }
@TargetApi(26) @TargetApi(26)
if (am.requestAudioFocus(audioFocusRequest!!) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (am.requestAudioFocus(audioFocusRequest!!) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d(LOG_TAG, "Audio focus granted for usage $usage") Log.d(TAG, "Audio focus granted for usage $usage")
audioFocusUsage = usage audioFocusUsage = usage
if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn) { if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn) {
Log.d(LOG_TAG, "Starting Bluetooth Sco") Log.d(TAG, "Starting Bluetooth Sco")
am.startBluetoothSco() am.startBluetoothSco()
} }
} else { } else {
Log.d(LOG_TAG, "Audio focus denied") Log.d(TAG, "Audio focus denied")
audioFocusRequest = null audioFocusRequest = null
audioFocusUsage = -1 audioFocusUsage = -1
} }
} else { } else {
if (am.requestAudioFocus(null, usage, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) == if (am.requestAudioFocus(null, usage, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) ==
AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d(LOG_TAG, "Audio focus granted for usage $usage") Log.d(TAG, "Audio focus granted for usage $usage")
audioFocusUsage = usage audioFocusUsage = usage
if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn) if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn)
am.startBluetoothSco() am.startBluetoothSco()
} else { } else {
Log.d(LOG_TAG, "Audio focus denied") Log.d(TAG, "Audio focus denied")
audioFocusUsage = -1 audioFocusUsage = -1
} }
} }
@@ -990,20 +990,20 @@ class BaresipService: Service() {
if (audioFocusRequest != null) { if (audioFocusRequest != null) {
if (am.abandonAudioFocusRequest(audioFocusRequest!!) == if (am.abandonAudioFocusRequest(audioFocusRequest!!) ==
AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d(LOG_TAG, "Audio focus abandoned") Log.d(TAG, "Audio focus abandoned")
audioFocusRequest = null audioFocusRequest = null
audioFocusUsage = -1 audioFocusUsage = -1
} else { } else {
Log.d(LOG_TAG, "Failed to abandon audio focus") Log.d(TAG, "Failed to abandon audio focus")
} }
} }
} else { } else {
if (audioFocusUsage != -1) { if (audioFocusUsage != -1) {
if (am.abandonAudioFocus(null) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (am.abandonAudioFocus(null) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d(LOG_TAG, "Audio focus abandoned") Log.d(TAG, "Audio focus abandoned")
audioFocusUsage = -1 audioFocusUsage = -1
} else { } else {
Log.d(LOG_TAG, "Failed to abandon audio focus") Log.d(TAG, "Failed to abandon audio focus")
} }
} }
} }
@@ -1045,7 +1045,7 @@ class BaresipService: Service() {
am.setStreamVolume(streamType, am.setStreamVolume(streamType,
(callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(), (callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(),
0) 0)
Log.d(LOG_TAG, "Orig/new call volume of stream type $streamType is " + Log.d(TAG, "Orig/new call volume of stream type $streamType is " +
"${origVolumes[streamType]}/${am.getStreamVolume(streamType)}") "${origVolumes[streamType]}/${am.getStreamVolume(streamType)}")
} }
} }
@@ -1055,7 +1055,7 @@ class BaresipService: Service() {
for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC)) { for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC)) {
if (origVolumes[streamType] != -1) { if (origVolumes[streamType] != -1) {
am.setStreamVolume(streamType, origVolumes[streamType], 0) am.setStreamVolume(streamType, origVolumes[streamType], 0)
Log.d(LOG_TAG, "Reset volume of stream type $streamType to " + Log.d(TAG, "Reset volume of stream type $streamType to " +
"${am.getStreamVolume(streamType)}") "${am.getStreamVolume(streamType)}")
origVolumes[streamType] = -1 origVolumes[streamType] = -1
} }
@@ -1065,17 +1065,17 @@ class BaresipService: Service() {
private fun proximitySensing(enable: Boolean) { private fun proximitySensing(enable: Boolean) {
if (enable) { if (enable) {
if (!proximityWakeLock.isHeld) { if (!proximityWakeLock.isHeld) {
Log.d(LOG_TAG, "Acquiring proximity wake lock") Log.d(TAG, "Acquiring proximity wake lock")
proximityWakeLock.acquire() proximityWakeLock.acquire()
} else { } else {
Log.d(LOG_TAG, "Proximity wake lock already acquired") Log.d(TAG, "Proximity wake lock already acquired")
} }
} else { } else {
if (proximityWakeLock.isHeld) { if (proximityWakeLock.isHeld) {
proximityWakeLock.release() proximityWakeLock.release()
Log.d(LOG_TAG, "Released proximity wake lock") Log.d(TAG, "Released proximity wake lock")
} else { } else {
Log.d(LOG_TAG, "Proximity wake lock is not held") Log.d(TAG, "Proximity wake lock is not held")
} }
} }
} }
@@ -1086,14 +1086,14 @@ class BaresipService: Service() {
val caps = cm.getNetworkCapabilities(n) ?: continue val caps = cm.getNetworkCapabilities(n) ?: continue
val props = cm.getLinkProperties(n) ?: continue val props = cm.getLinkProperties(n) ?: continue
if (isNetworkActive(n) && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) { if (isNetworkActive(n) && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
Log.i(LOG_TAG, "Active VPN network $n is available with caps: " + Log.i(TAG, "Active VPN network $n is available with caps: " +
"$caps, props: $props") "$caps, props: $props")
activeNetwork = "$n" activeNetwork = "$n"
if (isConfigInitialized) { if (isConfigInitialized) {
Utils.updateLinkProperties(props) Utils.updateLinkProperties(props)
} else { } else {
for (s in props.dnsServers) for (s in props.dnsServers)
Log.i(LOG_TAG, "DNS Server ${s.hostAddress}") Log.i(TAG, "DNS Server ${s.hostAddress}")
dnsServers = props.dnsServers dnsServers = props.dnsServers
linkAddresses = props.linkAddresses linkAddresses = props.linkAddresses
} }
@@ -1105,7 +1105,7 @@ class BaresipService: Service() {
val caps = cm.getNetworkCapabilities(n) ?: continue val caps = cm.getNetworkCapabilities(n) ?: continue
val props = cm.getLinkProperties(n) ?: continue val props = cm.getLinkProperties(n) ?: continue
if (isNetworkActive(n) && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { if (isNetworkActive(n) && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
Log.i(LOG_TAG, "Active Internet network $n is available with caps: " + Log.i(TAG, "Active Internet network $n is available with caps: " +
"$caps, props: $props") "$caps, props: $props")
activeNetwork = "$n" activeNetwork = "$n"
if (isServiceRunning) { if (isServiceRunning) {
@@ -1122,7 +1122,7 @@ class BaresipService: Service() {
val caps = cm.getNetworkCapabilities(n) ?: continue val caps = cm.getNetworkCapabilities(n) ?: continue
val props = cm.getLinkProperties(n) ?: continue val props = cm.getLinkProperties(n) ?: continue
if (isNetworkActive(n)) { if (isNetworkActive(n)) {
Log.i(LOG_TAG, "Active network $n is available with caps: " + Log.i(TAG, "Active network $n is available with caps: " +
"$caps, props: $props") "$caps, props: $props")
activeNetwork = "$n" activeNetwork = "$n"
if (isServiceRunning) { if (isServiceRunning) {
@@ -1215,7 +1215,7 @@ class BaresipService: Service() {
init { init {
if (!libraryLoaded) { if (!libraryLoaded) {
Log.d(LOG_TAG, "Loading baresip library") Log.d(TAG, "Loading baresip library")
System.loadLibrary("baresip") System.loadLibrary("baresip")
libraryLoaded = true libraryLoaded = true
} }
@@ -1,6 +1,7 @@
package com.tutpro.baresip package com.tutpro.baresip
class CallRow(val aor: String, val peerUri: String, val direction: Int, val time: String, val index: Int) { class CallRow(val aor: String, val peerUri: String, private val direction: Int, val time: String,
private val index: Int) {
val directions = ArrayList<Int>() val directions = ArrayList<Int>()
val indexes = ArrayList<Int>() val indexes = ArrayList<Int>()
@@ -79,7 +79,7 @@ class CodecsActivity : AppCompatActivity() {
codecSpinner.adapter = adapter codecSpinner.adapter = adapter
codecSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { codecSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
newCodecs.set(parent.id - 100, parent.selectedItem.toString()) newCodecs[parent.id - 100] = parent.selectedItem.toString()
} }
override fun onNothingSelected(parent: AdapterView<*>) { override fun onNothingSelected(parent: AdapterView<*>) {
} }
@@ -13,6 +13,9 @@ import android.widget.AdapterView
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import com.tutpro.baresip.databinding.ActivityConfigBinding import com.tutpro.baresip.databinding.ActivityConfigBinding
private const val READ_CERT_PERMISSION_CODE = 1
private const val READ_CA_PERMISSION_CODE = 2
class ConfigActivity : AppCompatActivity() { class ConfigActivity : AppCompatActivity() {
private lateinit var binding: ActivityConfigBinding private lateinit var binding: ActivityConfigBinding
@@ -40,9 +43,6 @@ class ConfigActivity : AppCompatActivity() {
private var restart = false private var restart = false
private var menu: Menu? = null private var menu: Menu? = null
private val READ_CERT_PERMISSION_CODE = 1
private val READ_CA_PERMISSION_CODE = 2
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -29,7 +29,7 @@ class Contact(var name: String, var uri: String, var color: Int, val id: Long) {
fun restore(): Boolean { fun restore(): Boolean {
val content = Utils.getFileContents(BaresipService.filesPath + "/contacts") val content = Utils.getFileContents(BaresipService.filesPath + "/contacts")
if (content == null) return false ?: return false
val contacts = String(content) val contacts = String(content)
Api.contacts_remove() Api.contacts_remove()
BaresipService.contacts.clear() BaresipService.contacts.clear()
@@ -28,6 +28,8 @@ import com.tutpro.baresip.databinding.ActivityContactBinding
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.File import java.io.File
private const val READ_REQUEST_CODE = 42
class ContactActivity : AppCompatActivity() { class ContactActivity : AppCompatActivity() {
private lateinit var binding: ActivityContactBinding private lateinit var binding: ActivityContactBinding
@@ -48,8 +50,6 @@ class ContactActivity : AppCompatActivity() {
private var id: Long = 0 private var id: Long = 0
private var oldAndroid = false private var oldAndroid = false
private val READ_REQUEST_CODE = 42
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -975,7 +975,7 @@ class MainActivity : AppCompatActivity() {
volumeControlStream = AudioManager.STREAM_MUSIC volumeControlStream = AudioManager.STREAM_MUSIC
val param = ev[1].trim() val param = ev[1].trim()
if ((param != "") && (Call.uaCalls(ua, "").size == 0)) { if ((param != "") && (Call.uaCalls(ua, "").size == 0)) {
if (param.get(0).isDigit()) if (param[0].isDigit())
Toast.makeText(applicationContext, Toast.makeText(applicationContext,
"${getString(R.string.call_failed)}: $param", "${getString(R.string.call_failed)}: $param",
Toast.LENGTH_LONG).show() Toast.LENGTH_LONG).show()
@@ -171,8 +171,7 @@ object Utils {
} }
private fun checkPort(port: String): Boolean { private fun checkPort(port: String): Boolean {
val number = port.toIntOrNull() val number = port.toIntOrNull() ?: return false
if (number == null) return false
return (number > 0) && (number < 65536) return (number > 0) && (number < 65536)
} }
@@ -230,12 +229,13 @@ object Utils {
fun checkSipUri(uri: String): Boolean { fun checkSipUri(uri: String): Boolean {
if (!uri.startsWith("sip:")) return false if (!uri.startsWith("sip:")) return false
val userRest = uri.substring(4).split("@") val userRest = uri.substring(4).split("@")
if (userRest.size == 1) { return when (userRest.size) {
return checkHostPortParams(userRest[0]) 1 ->
} else if (userRest.size == 2) { checkHostPortParams(userRest[0])
return checkUriUser(userRest[0]) && checkHostPortParams(userRest[1]) 2 ->
} else checkUriUser(userRest[0]) && checkHostPortParams(userRest[1])
return false else -> false
}
} }
fun checkName(name: String): Boolean { fun checkName(name: String): Boolean {
@@ -308,7 +308,7 @@ object Utils {
} }
if (updated) { if (updated) {
BaresipService.linkAddresses = linkAddresses BaresipService.linkAddresses = linkAddresses
Api.uag_reset_transp(true, true) Api.uag_reset_transp(register = true, reinvite = true)
Api.net_debug() Api.net_debug()
} else { } else {
UserAgent.register() UserAgent.register()
+1
View File
@@ -350,6 +350,7 @@
<string name="help">Help</string> <string name="help">Help</string>
<string name="confirmation">Confirmation</string> <string name="confirmation">Confirmation</string>
<string name="dots" translatable="false"></string> <string name="dots" translatable="false"></string>
<string name="bullet_item" translatable="false">\u2022 %1$s</string>
<!-- Main Activity --> <!-- Main Activity -->
<string name="backup">Backup</string> <string name="backup">Backup</string>
<string name="restore">Restore</string> <string name="restore">Restore</string>