Mobile account improvements

This commit is contained in:
Juha Heinanen
2026-05-11 12:16:33 +03:00
parent c74d780619
commit dfd33ad791
3 changed files with 82 additions and 58 deletions
@@ -44,7 +44,6 @@ class Account(val accp: Long, virtualAor: String? = null) {
var customParams = "" var customParams = ""
init { init {
if (accp != 0L) { if (accp != 0L) {
if (authPass == "") if (authPass == "")
authPass = NO_AUTH_PASS authPass = NO_AUTH_PASS
@@ -70,10 +69,12 @@ class Account(val accp: Long, virtualAor: String? = null) {
break break
} }
} }
}
val extra = Api.account_extra(accp) val extra = Api.account_extra(accp)
if (Utils.paramExists(extra, "nickname")) if (Utils.paramExists(extra, "nickname"))
nickName = Utils.paramValue(extra, "nickname") nickName = Utils.paramValue(extra, "nickname")
isMobile = Utils.paramExists(extra, "is_mobile")
if (Utils.paramExists(extra, "regint")) if (Utils.paramExists(extra, "regint"))
configuredRegInt = Utils.paramValue(extra, "regint").toInt() configuredRegInt = Utils.paramValue(extra, "regint").toInt()
callHistory = Utils.paramValue(extra, "call_history") == "" callHistory = Utils.paramValue(extra, "call_history") == ""
@@ -85,20 +86,23 @@ class Account(val accp: Long, virtualAor: String? = null) {
numericKeypad = Utils.paramExists(extra, "numeric_keypad") numericKeypad = Utils.paramExists(extra, "numeric_keypad")
customParams = extra.substringAfter("last=empty").substringAfter(";") customParams = extra.substringAfter("last=empty").substringAfter(";")
} }
}
fun print() : String { fun print() : String {
if (isMobile) return "" var res = if (isMobile) {
"<${aor};transport=udp>"
var res = if (displayName != "") } else {
if (displayName != "")
"\"${displayName}\" " "\"${displayName}\" "
else 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)) if ((authPass != "") && !BaresipService.aorPasswords.containsKey(aor))
res += ";auth_pass=\"${authPass}\"" res += ";auth_pass=\"${authPass}\""
@@ -160,13 +164,19 @@ class Account(val accp: Long, virtualAor: String? = null) {
if (autoRedirect) if (autoRedirect)
res += ";sip_autoredirect=yes" 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 = "" var extra = ""
if (nickName != "") if (nickName != "")
extra += ";nickname=${nickName}" extra += ";nickname=${nickName}"
if (isMobile)
extra += ";is_mobile=yes"
if (!callHistory) if (!callHistory)
extra += ";call_history=no" extra += ";call_history=no"
@@ -233,7 +233,7 @@ private fun AccountContent(
horizontalArrangement = Arrangement.Start horizontalArrangement = Arrangement.Start
) { ) {
val aorText = if (ua.account.isMobile) { val aorText = if (ua.account.isMobile) {
if (ua.account.aor == "tel:mobile") if (ua.account.aor == "sip:mobile@pstn")
stringResource(R.string.not_available) stringResource(R.string.not_available)
else else
ua.account.aor ua.account.aor
@@ -1258,6 +1258,7 @@ private fun AccountContent(
) { ) {
AoR() AoR()
Nickname() Nickname()
if (!ua.account.isMobile) {
DisplayName() DisplayName()
AuthUser() AuthUser()
AuthPass() AuthPass()
@@ -1269,7 +1270,9 @@ private fun AccountContent(
RegInt() RegInt()
CheckOrigin() CheckOrigin()
} }
}
BlockUnknown() BlockUnknown()
if (!ua.account.isMobile) {
AudioCodecs(navController, aor) AudioCodecs(navController, aor)
MediaEnc() MediaEnc()
MediaNat() MediaNat()
@@ -1281,13 +1284,17 @@ private fun AccountContent(
RtcpMux() RtcpMux()
Rel100() Rel100()
Dtmf() Dtmf()
Answer()
Redirect() Redirect()
}
Answer()
Voicemail() Voicemail()
if (!ua.account.isMobile) {
CountryCode() CountryCode()
TelProvider() TelProvider()
}
NumericKeypad() NumericKeypad()
DefaultAccount() DefaultAccount()
if (!ua.account.isMobile)
CustomParams() CustomParams()
} }
} }
@@ -491,10 +491,9 @@ class BaresipService: Service() {
activeNetwork = cm.activeNetwork activeNetwork = cm.activeNetwork
Log.i(TAG, "Active network: $activeNetwork") Log.i(TAG, "Active network: $activeNetwork")
if (telecom) { if (telecom)
registerPhoneAccount() registerPhoneAccount()
addMobileUserAgent() else
} else
if (btAdapter != null) { if (btAdapter != null) {
Log.i(TAG, "Registering bluetooth receiver") Log.i(TAG, "Registering bluetooth receiver")
val filter = IntentFilter() val filter = IntentFilter()
@@ -726,7 +725,9 @@ class BaresipService: Service() {
if (ev[0] == "create") { if (ev[0] == "create") {
val ua = UserAgent(uap) 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 R.drawable.circle_white
else else
circleYellow.getValue(colorblind) circleYellow.getValue(colorblind)
@@ -1850,28 +1851,34 @@ class BaresipService: Service() {
private fun addMobileUserAgent() { private fun addMobileUserAgent() {
if (!telecom || Utils.pstnAccountHandle(this) == null) return 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 } val existingMobileUa = uas.value.find { it.account.isMobile }
if (existingMobileUa != null) { if (existingMobileUa != null) {
// Replace previous tel:mobile with real number // Replace previous sip:mobile@pstn with real number if available
if (existingMobileUa.account.aor == "tel:mobile" && mobileAor != "tel:mobile") { if (existingMobileUa.account.aor == "sip:mobile@pstn" && mobileAor != "sip:mobile@pstn") {
val updatedUas = uas.value.toMutableList() val updatedUas = uas.value.toMutableList()
updatedUas.remove(existingMobileUa) updatedUas.remove(existingMobileUa)
uas.value = updatedUas.toList() uas.value = updatedUas.toList()
} else { } else
return return
} }
}
val account = Account(0L, mobileAor) val account = Account(0L, mobileAor)
account.isMobile = true account.isMobile = true
account.nickName = "Mobile" account.nickName = "Mobile"
account.regint = 0
account.telProvider = ""
val mobileUa = UserAgent(0L, account) val mobileUa = UserAgent(0L, account)
val updatedUas = uas.value.toMutableList() val updatedUas = uas.value.toMutableList()
updatedUas.add(mobileUa) updatedUas.add(mobileUa)
uas.value = updatedUas.toList() uas.value = updatedUas.toList()
uasStatus.value = UserAgent.statusMap() uasStatus.value = UserAgent.statusMap()
Account.saveAccounts()
} }
private fun toast(message: String, length: Int = Toast.LENGTH_SHORT) { private fun toast(message: String, length: Int = Toast.LENGTH_SHORT) {