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,35 +69,40 @@ class Account(val accp: Long, virtualAor: String? = null) {
break 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 { fun print() : String {
if (isMobile) return "" var res = if (isMobile) {
"<${aor};transport=udp>"
} else {
if (displayName != "")
"\"${displayName}\" "
else
""
}
var res = if (displayName != "") if (!isMobile) {
"\"${displayName}\" " res = "$res<$luri>"
else
""
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,37 +1258,44 @@ private fun AccountContent(
) { ) {
AoR() AoR()
Nickname() Nickname()
DisplayName() if (!ua.account.isMobile) {
AuthUser() DisplayName()
AuthPass() AuthUser()
if (showPasswordDialog.value) AuthPass()
AskPassword(ctx, navController, ua) if (showPasswordDialog.value)
Outbound() AskPassword(ctx, navController, ua)
Register() Outbound()
if (viewModel.register.collectAsState().value) { Register()
RegInt() if (viewModel.register.collectAsState().value) {
CheckOrigin() RegInt()
CheckOrigin()
}
} }
BlockUnknown() BlockUnknown()
AudioCodecs(navController, aor) if (!ua.account.isMobile) {
MediaEnc() AudioCodecs(navController, aor)
MediaNat() MediaEnc()
if (showStun) { MediaNat()
StunServer() if (showStun) {
StunUser() StunServer()
StunPass() StunUser()
StunPass()
}
RtcpMux()
Rel100()
Dtmf()
Redirect()
} }
RtcpMux()
Rel100()
Dtmf()
Answer() Answer()
Redirect()
Voicemail() Voicemail()
CountryCode() if (!ua.account.isMobile) {
TelProvider() CountryCode()
TelProvider()
}
NumericKeypad() NumericKeypad()
DefaultAccount() DefaultAccount()
CustomParams() if (!ua.account.isMobile)
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) {