From 1d95d8f1be85d07f008d3904d3e305d00e75f2f7 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sun, 21 Mar 2021 14:58:19 +0200 Subject: [PATCH] More code laundry --- .../main/kotlin/com/tutpro/baresip/Account.kt | 2 +- .../com/tutpro/baresip/AccountActivity.kt | 4 +- app/src/main/kotlin/com/tutpro/baresip/Api.kt | 2 +- .../com/tutpro/baresip/AudioActivity.kt | 8 +- .../com/tutpro/baresip/BaresipService.kt | 156 +++++++++--------- .../main/kotlin/com/tutpro/baresip/CallRow.kt | 3 +- .../com/tutpro/baresip/CodecsActivity.kt | 2 +- .../com/tutpro/baresip/ConfigActivity.kt | 6 +- .../main/kotlin/com/tutpro/baresip/Contact.kt | 2 +- .../com/tutpro/baresip/ContactActivity.kt | 4 +- .../kotlin/com/tutpro/baresip/MainActivity.kt | 2 +- .../main/kotlin/com/tutpro/baresip/Utils.kt | 18 +- app/src/main/res/values/strings.xml | 1 + 13 files changed, 105 insertions(+), 105 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Account.kt b/app/src/main/kotlin/com/tutpro/baresip/Account.kt index b137d463..c6473da3 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Account.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Account.kt @@ -79,7 +79,7 @@ class Account(val accp: String) { if (outbound.size > 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" } diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt index a8098a71..7a4fd955 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt @@ -18,6 +18,8 @@ import java.net.URL import java.util.* import kotlin.collections.ArrayList +private const val TAG = "Baresip" + class AccountActivity : AppCompatActivity() { private lateinit var binding: ActivityAccountBinding @@ -53,7 +55,6 @@ class AccountActivity : AppCompatActivity() { private var save = false private var uaIndex= -1 - private val TAG = "Baresip" override fun onCreate(savedInstanceState: Bundle?) { @@ -622,7 +623,6 @@ class AccountActivity : AppCompatActivity() { AsyncTask() { private val activityReference: WeakReference = WeakReference(context) - private val TAG = "Baresip" override fun doInBackground(vararg url: String?): String? { val result = try { diff --git a/app/src/main/kotlin/com/tutpro/baresip/Api.kt b/app/src/main/kotlin/com/tutpro/baresip/Api.kt index 36da1793..c02cfd3a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Api.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Api.kt @@ -47,7 +47,7 @@ object Api { external fun account_extra(acc: String): 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 ua_account(ua: String): String diff --git a/app/src/main/kotlin/com/tutpro/baresip/AudioActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/AudioActivity.kt index f74b75f7..04445e08 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AudioActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AudioActivity.kt @@ -53,7 +53,7 @@ class AudioActivity : AppCompatActivity() { tvParams.addRule(RelativeLayout.CENTER_VERTICAL) tvParams.addRule(RelativeLayout.START_OF, id) 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.setTextColor(ContextCompat.getColor(this, R.color.colorItemText)) rl.addView(tv) @@ -240,14 +240,12 @@ class AudioActivity : AppCompatActivity() { } private fun checkOpusBitRate(opusBitRate: String): Boolean { - val number = opusBitRate.toIntOrNull() - if (number == null) return false + val number = opusBitRate.toIntOrNull() ?: return false return (number >= 6000) && (number <= 510000) } private fun checkOpusPacketLoss(opusPacketLoss: String): Boolean { - val number = opusPacketLoss.toIntOrNull() - if (number == null) return false + val number = opusPacketLoss.toIntOrNull() ?: return false return (number >= 0) && (number <= 100) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 2b050d8d..98492ace 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -33,9 +33,9 @@ import java.util.* import kotlin.concurrent.schedule 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 am: AudioManager @@ -60,7 +60,7 @@ class BaresipService: Service() { override fun onCreate() { - Log.d(LOG_TAG, "At onCreate") + Log.d(TAG, "At onCreate") intent = Intent("com.tutpro.baresip.EVENT") intent.setPackage("com.tutpro.baresip") @@ -91,27 +91,27 @@ class BaresipService: Service() { override fun onAvailable(network: Network) { super.onAvailable(network) - Log.i(LOG_TAG, "Network $network is available") + Log.i(TAG, "Network $network is available") updateNetwork() } override fun onLost(network: Network) { super.onLost(network) - Log.i(LOG_TAG, "Network $network is lost") + Log.i(TAG, "Network $network is lost") if (activeNetwork == "$network") updateNetwork() } override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) { super.onLinkPropertiesChanged(network, props) - Log.i(LOG_TAG, "Network $network link properties changed") + Log.i(TAG, "Network $network link properties changed") if (activeNetwork == "$network") updateNetwork() } override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) { 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) when (state) { BluetoothHeadset.STATE_CONNECTED -> { - Log.d(LOG_TAG, "Bluetooth headset is connected") + Log.d(TAG, "Bluetooth headset is connected") if (isAudioFocused()) { // Without delay, SCO_AUDIO_STATE_CONNECTING -> // SCO_AUDIO_STATE_DISCONNECTED Timer("Sco", false).schedule(1000) { - Log.d(LOG_TAG, "Starting Bluetooth SCO") + Log.d(TAG, "Starting Bluetooth SCO") am.startBluetoothSco() } } } BluetoothHeadset.STATE_DISCONNECTED -> { - Log.d(LOG_TAG, "Bluetooth headset is disconnected") + Log.d(TAG, "Bluetooth headset is disconnected") if (am.isBluetoothScoOn) { - Log.d(LOG_TAG, "Stopping Bluetooth SCO") + Log.d(TAG, "Stopping Bluetooth SCO") am.stopBluetoothSco() } } @@ -160,12 +160,12 @@ class BaresipService: Service() { BluetoothHeadset.STATE_AUDIO_DISCONNECTED) when (state) { 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 -> { - Log.d(LOG_TAG, "Bluetooth headset audio is disconnected") + Log.d(TAG, "Bluetooth headset audio is disconnected") if (am.isBluetoothScoOn) { - Log.d(LOG_TAG, "Stopping Bluetooth SCO") + Log.d(TAG, "Stopping Bluetooth SCO") am.stopBluetoothSco() } } @@ -177,17 +177,17 @@ class BaresipService: Service() { AudioManager.SCO_AUDIO_STATE_DISCONNECTED) when (state) { 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 -> { - Log.d(LOG_TAG, "Bluetooth headset SCO is connected") + Log.d(TAG, "Bluetooth headset SCO is connected") } AudioManager.SCO_AUDIO_STATE_DISCONNECTED -> { - Log.d(LOG_TAG, "Bluetooth headset SCO is disconnected") + Log.d(TAG, "Bluetooth headset SCO is disconnected") abandonAudioFocus() } 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) { action = "Start" - Log.d(LOG_TAG, "Received onStartCommand with null intent") + Log.d(TAG, "Received onStartCommand with null intent") } else { // Utils.dumpIntent(intent) action = intent.action!! - Log.d(LOG_TAG, "Received onStartCommand action $action") + Log.d(TAG, "Received onStartCommand action $action") } when (action) { @@ -230,20 +230,20 @@ class BaresipService: Service() { "error.wav", "notfound.wav", "ring.wav", "ringback.wav") var file = File(filesPath) if (!file.exists()) { - Log.d(LOG_TAG, "Creating baresip directory") + Log.d(TAG, "Creating baresip directory") try { File(filesPath).mkdirs() } catch (e: Error) { - Log.e(LOG_TAG, "Failed to create directory: $e") + Log.e(TAG, "Failed to create directory: $e") } } for (a in assets) { file = File("${filesPath}/$a") if (!file.exists()) { - Log.d(LOG_TAG, "Copying asset '$a'") + Log.d(TAG, "Copying asset '$a'") Utils.copyAssetToFile(applicationContext, a, "$filesPath/$a") } else { - Log.d(LOG_TAG, "Asset '$a' already copied") + Log.d(TAG, "Asset '$a' already copied") } if (a == "config") Config.initialize() @@ -260,7 +260,7 @@ class BaresipService: Service() { val ipV6Addr = Utils.findIpV6Address(linkAddresses) val dnsServers = Utils.findDnsServers(BaresipService.dnsServers) if ((ipV4Addr == "") && (ipV6Addr == "")) - Log.w(LOG_TAG, "Starting baresip without IP addresses") + Log.w(TAG, "Starting baresip without IP addresses") Thread({ baresipStart(filesPath, ipV4Addr, ipV6Addr, "", dnsServers, Api.AF_UNSPEC, logLevel) @@ -301,11 +301,11 @@ class BaresipService: Service() { val callp = intent!!.getStringExtra("callp")!! val call = Call.ofCallp(callp) if (call == null) { - Log.w(LOG_TAG, "onStartCommand did not find call $callp") + Log.w(TAG, "onStartCommand did not find call $callp") } else { val peerUri = call.peerUri 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") if (call.ua.account.callHistory) { CallHistory.add(CallHistory(aor, peerUri, "in", false)) @@ -318,7 +318,7 @@ class BaresipService: Service() { val uap = intent!!.getStringExtra("uap")!! val ua = UserAgent.ofUap(uap) if (ua == null) { - Log.w(LOG_TAG, "onStartCommand did not find ua $uap") + Log.w(TAG, "onStartCommand did not find ua $uap") } else { val newIntent = Intent(this, MainActivity::class.java) newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or @@ -335,7 +335,7 @@ class BaresipService: Service() { val callp = intent!!.getStringExtra("callp")!! val call = Call.ofCallp(callp) if (call == null) - Log.w(LOG_TAG, "onStartCommand did not find call $callp") + Log.w(TAG, "onStartCommand did not find call $callp") else call.notifySipfrag(603, "Decline") nm.cancel(TRANSFER_NOTIFICATION_ID) @@ -356,7 +356,7 @@ class BaresipService: Service() { val uap = intent!!.getStringExtra("uap")!! val ua = UserAgent.ofUap(uap) if (ua == null) - Log.w(LOG_TAG, "onStartCommand did not find UA $uap") + Log.w(TAG, "onStartCommand did not find UA $uap") else ChatsActivity.saveUaMessage(ua.account.aor, intent.getStringExtra("time")!!.toLong()) @@ -367,7 +367,7 @@ class BaresipService: Service() { val uap = intent!!.getStringExtra("uap")!! val ua = UserAgent.ofUap(uap) if (ua == null) - Log.w(LOG_TAG, "onStartCommand did not find UA $uap") + Log.w(TAG, "onStartCommand did not find UA $uap") else ChatsActivity.deleteUaMessage(ua.account.aor, intent.getStringExtra("time")!!.toLong()) @@ -399,7 +399,7 @@ class BaresipService: Service() { } override fun onDestroy() { - Log.d(LOG_TAG, "At Baresip Service onDestroy") + Log.d(TAG, "At Baresip Service onDestroy") super.onDestroy() this.unregisterReceiver(br) if (am.isBluetoothScoOn) am.stopBluetoothSco() @@ -413,15 +413,15 @@ class BaresipService: Service() { @Keep fun uaAdd(uap: String) { 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) if (ua.account.preferIPv6Media) Api.ua_set_media_af(ua.uap, Api.AF_INET6) 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) } 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) status.add(R.drawable.dot_white) else @@ -434,10 +434,10 @@ class BaresipService: Service() { if (!isServiceRunning) return val ua = UserAgent.ofUap(uap) if (ua == null) { - Log.w(LOG_TAG, "uaEvent did not find ua $uap") + Log.w(TAG, "uaEvent did not find ua $uap") 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 var newEvent: String? = null @@ -472,9 +472,9 @@ class BaresipService: Service() { val props = cm.getLinkProperties(activeNetwork) if (props != null) { val dnsServers = props.dnsServers - Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers") + Log.d(TAG, "Updating DNS Servers = $dnsServers") 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 { Api.net_dns_debug() if (!ua.registrationFailed) { @@ -484,7 +484,7 @@ class BaresipService: Service() { } } } 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) || !Utils.checkPermission(applicationContext, 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") if (ua.account.callHistory) { CallHistory.add(CallHistory(aor, peerUri, "in", false)) @@ -527,12 +527,12 @@ class BaresipService: Service() { return newEvent = "call rejected" } else { - Log.d(LOG_TAG, "Incoming call $uap/$callp/$peerUri") + Log.d(TAG, "Incoming call $uap/$callp/$peerUri") Call(callp, ua, peerUri, "in", "incoming", Utils.dtmfWatcher(callp)).add() if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) { 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) startRinging() } else { @@ -601,10 +601,10 @@ class BaresipService: Service() { nm.cancel(CALL_NOTIFICATION_ID) val call = Call.ofCallp(callp) 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 } - Log.d(LOG_TAG, "AoR $aor call $callp established") + Log.d(TAG, "AoR $aor call $callp established") call.status = "connected" call.onhold = false if (ua.account.callHistory) { @@ -638,7 +638,7 @@ class BaresipService: Service() { "call transfer" -> { val call = Call.ofCallp(callp) 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 } if (!Utils.isVisible()) { @@ -687,10 +687,10 @@ class BaresipService: Service() { nm.cancel(CALL_NOTIFICATION_ID) val call = Call.ofCallp(callp) 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 } - Log.d(LOG_TAG, "AoR $aor call $callp is closed") + Log.d(TAG, "AoR $aor call $callp is closed") stopRinging() call.remove() if (Call.calls().size == 0) { @@ -699,7 +699,7 @@ class BaresipService: Service() { am.mode = AudioManager.MODE_NORMAL am.isSpeakerphoneOn = false if (am.isBluetoothScoOn) { - Log.d(LOG_TAG, "Stopping Bluetooth SCO") + Log.d(TAG, "Stopping Bluetooth SCO") am.stopBluetoothSco() } else { abandonAudioFocus() @@ -738,11 +738,11 @@ class BaresipService: Service() { } } "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, "") val call = Call.ofCallp(callp) 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 { call.referTo = "" } @@ -765,15 +765,15 @@ class BaresipService: Service() { try { text = String(msg, StandardCharsets.UTF_8) } catch (e: Exception) { - Log.w(LOG_TAG, "UTF-8 decode failed") + Log.w(TAG, "UTF-8 decode failed") } val ua = UserAgent.ofUap(uap) if (ua == null) { - Log.w(LOG_TAG, "messageEvent did not find ua $uap") + Log.w(TAG, "messageEvent did not find ua $uap") return } 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(), R.drawable.arrow_down_green, 0, "", true).add() Message.save() @@ -835,7 +835,7 @@ class BaresipService: Service() { @Keep 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") intent.putExtra("response code", responseCode) intent.putExtra("response reason", responseReason) @@ -846,7 +846,7 @@ class BaresipService: Service() { @Keep fun getPassword(aor: String): String { if (!isServiceRunning) return "" - Log.d(LOG_TAG, "getPassword of $aor") + Log.d(TAG, "getPassword of $aor") if (MainActivity.aorPasswords[aor] != null) return MainActivity.aorPasswords[aor]!! else @@ -855,7 +855,7 @@ class BaresipService: Service() { @Keep fun started() { - Log.d(LOG_TAG, "Received 'started' from baresip") + Log.d(TAG, "Received 'started' from baresip") val intent = Intent("service event") intent.putExtra("event", "started") intent.putExtra("params", arrayListOf(callActionUri)) @@ -865,7 +865,7 @@ class BaresipService: Service() { @Keep 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 val intent = Intent("service event") intent.putExtra("event", "stopped") @@ -950,26 +950,26 @@ class BaresipService: Service() { } @TargetApi(26) 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 if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn) { - Log.d(LOG_TAG, "Starting Bluetooth Sco") + Log.d(TAG, "Starting Bluetooth Sco") am.startBluetoothSco() } } else { - Log.d(LOG_TAG, "Audio focus denied") + Log.d(TAG, "Audio focus denied") audioFocusRequest = null audioFocusUsage = -1 } } else { if (am.requestAudioFocus(null, usage, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) == 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 if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn) am.startBluetoothSco() } else { - Log.d(LOG_TAG, "Audio focus denied") + Log.d(TAG, "Audio focus denied") audioFocusUsage = -1 } } @@ -990,20 +990,20 @@ class BaresipService: Service() { if (audioFocusRequest != null) { if (am.abandonAudioFocusRequest(audioFocusRequest!!) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { - Log.d(LOG_TAG, "Audio focus abandoned") + Log.d(TAG, "Audio focus abandoned") audioFocusRequest = null audioFocusUsage = -1 } else { - Log.d(LOG_TAG, "Failed to abandon audio focus") + Log.d(TAG, "Failed to abandon audio focus") } } } else { if (audioFocusUsage != -1) { if (am.abandonAudioFocus(null) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { - Log.d(LOG_TAG, "Audio focus abandoned") + Log.d(TAG, "Audio focus abandoned") audioFocusUsage = -1 } 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, (callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(), 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)}") } } @@ -1055,7 +1055,7 @@ class BaresipService: Service() { for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC)) { if (origVolumes[streamType] != -1) { 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)}") origVolumes[streamType] = -1 } @@ -1065,17 +1065,17 @@ class BaresipService: Service() { private fun proximitySensing(enable: Boolean) { if (enable) { if (!proximityWakeLock.isHeld) { - Log.d(LOG_TAG, "Acquiring proximity wake lock") + Log.d(TAG, "Acquiring proximity wake lock") proximityWakeLock.acquire() } else { - Log.d(LOG_TAG, "Proximity wake lock already acquired") + Log.d(TAG, "Proximity wake lock already acquired") } } else { if (proximityWakeLock.isHeld) { proximityWakeLock.release() - Log.d(LOG_TAG, "Released proximity wake lock") + Log.d(TAG, "Released proximity wake lock") } 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 props = cm.getLinkProperties(n) ?: continue 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") activeNetwork = "$n" if (isConfigInitialized) { Utils.updateLinkProperties(props) } else { for (s in props.dnsServers) - Log.i(LOG_TAG, "DNS Server ${s.hostAddress}") + Log.i(TAG, "DNS Server ${s.hostAddress}") dnsServers = props.dnsServers linkAddresses = props.linkAddresses } @@ -1105,7 +1105,7 @@ class BaresipService: Service() { val caps = cm.getNetworkCapabilities(n) ?: continue val props = cm.getLinkProperties(n) ?: continue 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") activeNetwork = "$n" if (isServiceRunning) { @@ -1122,7 +1122,7 @@ class BaresipService: Service() { val caps = cm.getNetworkCapabilities(n) ?: continue val props = cm.getLinkProperties(n) ?: continue 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") activeNetwork = "$n" if (isServiceRunning) { @@ -1215,7 +1215,7 @@ class BaresipService: Service() { init { if (!libraryLoaded) { - Log.d(LOG_TAG, "Loading baresip library") + Log.d(TAG, "Loading baresip library") System.loadLibrary("baresip") libraryLoaded = true } diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt b/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt index 3013c049..a62a4a2c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallRow.kt @@ -1,6 +1,7 @@ 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() val indexes = ArrayList() diff --git a/app/src/main/kotlin/com/tutpro/baresip/CodecsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CodecsActivity.kt index b9d099db..4519e6d2 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CodecsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CodecsActivity.kt @@ -79,7 +79,7 @@ class CodecsActivity : AppCompatActivity() { codecSpinner.adapter = adapter codecSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { 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<*>) { } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt index f2d70610..7e1956c1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt @@ -13,6 +13,9 @@ import android.widget.AdapterView import androidx.appcompat.app.AppCompatDelegate 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() { private lateinit var binding: ActivityConfigBinding @@ -40,9 +43,6 @@ class ConfigActivity : AppCompatActivity() { private var restart = false private var menu: Menu? = null - private val READ_CERT_PERMISSION_CODE = 1 - private val READ_CA_PERMISSION_CODE = 2 - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt index 57e343e7..e7867863 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt @@ -29,7 +29,7 @@ class Contact(var name: String, var uri: String, var color: Int, val id: Long) { fun restore(): Boolean { val content = Utils.getFileContents(BaresipService.filesPath + "/contacts") - if (content == null) return false + ?: return false val contacts = String(content) Api.contacts_remove() BaresipService.contacts.clear() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactActivity.kt index a5d6c254..fd04520c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactActivity.kt @@ -28,6 +28,8 @@ import com.tutpro.baresip.databinding.ActivityContactBinding import java.io.ByteArrayOutputStream import java.io.File +private const val READ_REQUEST_CODE = 42 + class ContactActivity : AppCompatActivity() { private lateinit var binding: ActivityContactBinding @@ -48,8 +50,6 @@ class ContactActivity : AppCompatActivity() { private var id: Long = 0 private var oldAndroid = false - private val READ_REQUEST_CODE = 42 - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 892b9672..c6a13a2b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -975,7 +975,7 @@ class MainActivity : AppCompatActivity() { volumeControlStream = AudioManager.STREAM_MUSIC val param = ev[1].trim() if ((param != "") && (Call.uaCalls(ua, "").size == 0)) { - if (param.get(0).isDigit()) + if (param[0].isDigit()) Toast.makeText(applicationContext, "${getString(R.string.call_failed)}: $param", Toast.LENGTH_LONG).show() diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 263da454..ce8da069 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -171,8 +171,7 @@ object Utils { } private fun checkPort(port: String): Boolean { - val number = port.toIntOrNull() - if (number == null) return false + val number = port.toIntOrNull() ?: return false return (number > 0) && (number < 65536) } @@ -230,12 +229,13 @@ object Utils { fun checkSipUri(uri: String): Boolean { if (!uri.startsWith("sip:")) return false val userRest = uri.substring(4).split("@") - if (userRest.size == 1) { - return checkHostPortParams(userRest[0]) - } else if (userRest.size == 2) { - return checkUriUser(userRest[0]) && checkHostPortParams(userRest[1]) - } else - return false + return when (userRest.size) { + 1 -> + checkHostPortParams(userRest[0]) + 2 -> + checkUriUser(userRest[0]) && checkHostPortParams(userRest[1]) + else -> false + } } fun checkName(name: String): Boolean { @@ -308,7 +308,7 @@ object Utils { } if (updated) { BaresipService.linkAddresses = linkAddresses - Api.uag_reset_transp(true, true) + Api.uag_reset_transp(register = true, reinvite = true) Api.net_debug() } else { UserAgent.register() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b37828ee..0300240b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -350,6 +350,7 @@ Help Confirmation + \u2022 %1$s Backup Restore