diff --git a/app/src/main/kotlin/com/tutpro/baresip/Account.kt b/app/src/main/kotlin/com/tutpro/baresip/Account.kt index 4ad306e4..84de4bb9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Account.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Account.kt @@ -44,7 +44,6 @@ class Account(val accp: Long, virtualAor: String? = null) { var customParams = "" init { - if (accp != 0L) { if (authPass == "") authPass = NO_AUTH_PASS @@ -70,35 +69,40 @@ class Account(val accp: Long, virtualAor: String? = null) { break } } - - val extra = Api.account_extra(accp) - if (Utils.paramExists(extra, "nickname")) - nickName = Utils.paramValue(extra, "nickname") - if (Utils.paramExists(extra, "regint")) - configuredRegInt = Utils.paramValue(extra, "regint").toInt() - callHistory = Utils.paramValue(extra, "call_history") == "" - blockUnknown = Utils.paramExists(extra, "block_unknown") - if (Utils.paramExists(extra, "country_code")) - countryCode = Utils.paramValue(extra, "country_code") - if (Utils.paramExists(extra, "tel_provider")) - telProvider = URLDecoder.decode(Utils.paramValue(extra, "tel_provider"), "UTF-8") - numericKeypad = Utils.paramExists(extra, "numeric_keypad") - customParams = extra.substringAfter("last=empty").substringAfter(";") } + + val extra = Api.account_extra(accp) + if (Utils.paramExists(extra, "nickname")) + nickName = Utils.paramValue(extra, "nickname") + isMobile = Utils.paramExists(extra, "is_mobile") + if (Utils.paramExists(extra, "regint")) + configuredRegInt = Utils.paramValue(extra, "regint").toInt() + callHistory = Utils.paramValue(extra, "call_history") == "" + blockUnknown = Utils.paramExists(extra, "block_unknown") + if (Utils.paramExists(extra, "country_code")) + countryCode = Utils.paramValue(extra, "country_code") + if (Utils.paramExists(extra, "tel_provider")) + telProvider = URLDecoder.decode(Utils.paramValue(extra, "tel_provider"), "UTF-8") + numericKeypad = Utils.paramExists(extra, "numeric_keypad") + customParams = extra.substringAfter("last=empty").substringAfter(";") } fun print() : String { - if (isMobile) return "" + var res = if (isMobile) { + "<${aor};transport=udp>" + } else { + if (displayName != "") + "\"${displayName}\" " + else + "" + } - var res = if (displayName != "") - "\"${displayName}\" " - else - "" + if (!isMobile) { + res = "$res<$luri>" - res = "$res<$luri>" - - if (authUser != "") res += ";auth_user=\"${authUser}\"" + if (authUser != "") res += ";auth_user=\"${authUser}\"" + } if ((authPass != "") && !BaresipService.aorPasswords.containsKey(aor)) res += ";auth_pass=\"${authPass}\"" @@ -160,13 +164,19 @@ class Account(val accp: Long, virtualAor: String? = null) { if (autoRedirect) res += ";sip_autoredirect=yes" - res += ";ptime=20;regint=${regint};regq=0.5;pubint=0;inreq_allowed=yes;call_transfer=yes" + res += ";ptime=20;regint=${regint};regq=0.5;pubint=0;inreq_allowed=yes" + + if (isMobile) + res += ";call_transfer=no" var extra = "" if (nickName != "") extra += ";nickname=${nickName}" + if (isMobile) + extra += ";is_mobile=yes" + if (!callHistory) extra += ";call_history=no" diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt index cf3971fe..86ad2a97 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt @@ -233,7 +233,7 @@ private fun AccountContent( horizontalArrangement = Arrangement.Start ) { val aorText = if (ua.account.isMobile) { - if (ua.account.aor == "tel:mobile") + if (ua.account.aor == "sip:mobile@pstn") stringResource(R.string.not_available) else ua.account.aor @@ -1258,37 +1258,44 @@ private fun AccountContent( ) { AoR() Nickname() - DisplayName() - AuthUser() - AuthPass() - if (showPasswordDialog.value) - AskPassword(ctx, navController, ua) - Outbound() - Register() - if (viewModel.register.collectAsState().value) { - RegInt() - CheckOrigin() + if (!ua.account.isMobile) { + DisplayName() + AuthUser() + AuthPass() + if (showPasswordDialog.value) + AskPassword(ctx, navController, ua) + Outbound() + Register() + if (viewModel.register.collectAsState().value) { + RegInt() + CheckOrigin() + } } BlockUnknown() - AudioCodecs(navController, aor) - MediaEnc() - MediaNat() - if (showStun) { - StunServer() - StunUser() - StunPass() + if (!ua.account.isMobile) { + AudioCodecs(navController, aor) + MediaEnc() + MediaNat() + if (showStun) { + StunServer() + StunUser() + StunPass() + } + RtcpMux() + Rel100() + Dtmf() + Redirect() } - RtcpMux() - Rel100() - Dtmf() Answer() - Redirect() Voicemail() - CountryCode() - TelProvider() + if (!ua.account.isMobile) { + CountryCode() + TelProvider() + } NumericKeypad() DefaultAccount() - CustomParams() + if (!ua.account.isMobile) + CustomParams() } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index cab10f92..299efba1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -491,10 +491,9 @@ class BaresipService: Service() { activeNetwork = cm.activeNetwork Log.i(TAG, "Active network: $activeNetwork") - if (telecom) { + if (telecom) registerPhoneAccount() - addMobileUserAgent() - } else + else if (btAdapter != null) { Log.i(TAG, "Registering bluetooth receiver") val filter = IntentFilter() @@ -726,7 +725,9 @@ class BaresipService: Service() { if (ev[0] == "create") { val ua = UserAgent(uap) - ua.status = if (ua.account.regint == 0) + ua.status = if (ua.account.isMobile) + R.drawable.circle_green + else if (ua.account.regint == 0) R.drawable.circle_white else circleYellow.getValue(colorblind) @@ -1850,28 +1851,34 @@ class BaresipService: Service() { private fun addMobileUserAgent() { if (!telecom || Utils.pstnAccountHandle(this) == null) return - val mobileAor = Utils.getLine1Number(this)?.let { "tel:$it" } ?: "tel:mobile" + + val userPart = Utils.getLine1Number(this) ?: "mobile" + val mobileAor = "sip:$userPart@pstn" + val existingMobileUa = uas.value.find { it.account.isMobile } if (existingMobileUa != null) { - // Replace previous tel:mobile with real number - if (existingMobileUa.account.aor == "tel:mobile" && mobileAor != "tel:mobile") { + // Replace previous sip:mobile@pstn with real number if available + if (existingMobileUa.account.aor == "sip:mobile@pstn" && mobileAor != "sip:mobile@pstn") { val updatedUas = uas.value.toMutableList() updatedUas.remove(existingMobileUa) uas.value = updatedUas.toList() - } else { + } else return - } } val account = Account(0L, mobileAor) account.isMobile = true account.nickName = "Mobile" + account.regint = 0 + account.telProvider = "" val mobileUa = UserAgent(0L, account) val updatedUas = uas.value.toMutableList() updatedUas.add(mobileUa) uas.value = updatedUas.toList() uasStatus.value = UserAgent.statusMap() + + Account.saveAccounts() } private fun toast(message: String, length: Int = Toast.LENGTH_SHORT) {