Added Custom Parameters account setting

This commit is contained in:
Juha Heinanen
2026-04-12 12:12:32 +03:00
parent 118d6026bb
commit 687799d419
6 changed files with 64 additions and 5 deletions

View File

@ -40,6 +40,7 @@ class Account(val accp: Long) {
var telProvider = Utils.aorDomain(aor)
var resumeUri = ""
var numericKeypad = false
var customParams = ""
init {
@ -80,6 +81,7 @@ class Account(val accp: Long) {
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 {
@ -166,7 +168,8 @@ class Account(val accp: Long) {
if (blockUnknown)
extra += ";block_unknown=yes"
extra += ";tel_provider=${URLEncoder.encode(telProvider, "UTF-8")}"
if (telProvider != "")
extra += ";tel_provider=${URLEncoder.encode(telProvider, "UTF-8")}"
if (countryCode != "")
extra += ";country_code=$countryCode"
@ -177,8 +180,15 @@ class Account(val accp: Long) {
if (numericKeypad)
extra += ";numeric_keypad=yes"
if (extra !="")
res += ";extra=\"" + extra.substringAfter(";") + "\""
extra += ";last=empty"
if (customParams != "")
extra += ";$customParams"
res += ";extra=\"" + extra.substringAfter(";") + "\""
if (customParams != "")
res += ";$customParams"
return res
}
@ -261,7 +271,7 @@ class Account(val accp: Long) {
BaresipService.filesPath + "/accounts",
accounts.toByteArray(Charsets.UTF_8)
)
// Log.d(TAG, "Saved accounts '${accounts}' to '${BaresipService.filesPath}/accounts'")
Log.d(TAG, "Saved accounts '${accounts}' to '${BaresipService.filesPath}/accounts'")
}
fun ofAor(aor: String): Account? {

View File

@ -1194,6 +1194,35 @@ private fun AccountContent(
}
}
@Composable
fun CustomParams() {
val customParamsTitle = stringResource(R.string.custom_parameters)
val customParamsHelp = stringResource(R.string.custom_parameters_help)
val customParams by viewModel.customParams.collectAsState()
Row(
Modifier.fillMaxWidth().padding(top = 8.dp, end = 10.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start
) {
OutlinedTextField(
value = customParams,
placeholder = { Text(customParamsTitle) },
onValueChange = { viewModel.customParams.value = it },
modifier = Modifier
.fillMaxWidth()
.clickable {
alertTitle.value = customParamsTitle
alertMessage.value = customParamsHelp
showAlert.value = true
},
singleLine = true,
textStyle = TextStyle(fontSize = 18.sp),
label = { Text(customParamsTitle) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
)
}
}
if (showAlert.value) {
AlertDialog(
showDialog = showAlert,
@ -1248,6 +1277,7 @@ private fun AccountContent(
TelProvider()
NumericKeypad()
DefaultAccount()
CustomParams()
}
}
@ -1615,6 +1645,12 @@ private fun checkOnClick(ctx: Context, viewModel: AccountViewModel, ua: UserAgen
Log.d(TAG, "New numericKeyboard is ${acc.numericKeypad}")
}
val newCustomParams = viewModel.customParams.value
if (newCustomParams != acc.customParams) {
acc.customParams = newCustomParams
Log.d(TAG, "New customParams is ${acc.customParams}")
}
if (viewModel.defaultAccount.value) ua.makeDefault()
Api.account_debug(acc.accp)

View File

@ -28,9 +28,11 @@ class AccountViewModel: ViewModel() {
val vmUri = MutableStateFlow("")
val countryCode = MutableStateFlow("")
val telProvider = MutableStateFlow("")
val defaultAccount = MutableStateFlow(false)
val numericKeypad = MutableStateFlow(false)
val defaultAccount = MutableStateFlow(false)
val customParams = MutableStateFlow("")
private var isLoaded = false
fun loadAccount(acc: Account) {
@ -63,5 +65,6 @@ class AccountViewModel: ViewModel() {
telProvider.value = acc.telProvider
numericKeypad.value = acc.numericKeypad
defaultAccount.value = UserAgent.findAorIndex(acc.aor)!! == 0
customParams.value = acc.customParams
}
}

View File

@ -328,6 +328,11 @@ object Utils {
return false
}
fun customParams(params: String): String {
return params.substringAfter("last=empty")
}
fun checkHostPortParams(hpp: String) : Boolean {
val restParams = hpp.split(";", limit = 2)
return if (restParams.size == 1)

View File

@ -240,6 +240,9 @@
<string name="default_account_help">Jos merkitty, niin tämä tili on
valittuna, kun baresip käynnistetään.
</string>
<string name="custom_parameters">Räätälöidyt parametrit</string>
<string name="custom_parameters_help">Puolipisteellä toisistaan eroteltu lista
räätälöityjä tilin parametrejä</string>
<!-- Accounts Activity -->
<string name="accounts">Tilit</string>
<string name="new_account">Uuden tilin SIP URI</string>

View File

@ -229,6 +229,8 @@
<string name="default_account">Default Account</string>
<string name="default_account_help">If checked, this account is selected when baresip is started.
</string>
<string name="custom_parameters">Custom Parameters</string>
<string name="custom_parameters_help">Semicolor separeted list of custom account parameters</string>
<!-- Accounts Activity -->
<string name="accounts">Accounts</string>
<string name="new_account">SIP URI of New Account</string>