diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 7ac9d00b..56531f70 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -2321,41 +2321,37 @@ class BaresipService: Service() { @SuppressLint("MissingPermission") private fun sendUssd(ussdCode: String) { val uap = uas.value.find { it.account.isMobile }?.uap ?: 0L - if (VERSION.SDK_INT >= 26) { - val tm = getSystemService(TELEPHONY_SERVICE) as TelephonyManager - try { - tm.sendUssdRequest(ussdCode, object : TelephonyManager.UssdResponseCallback() { - override fun onReceiveUssdResponse( - telephonyManager: TelephonyManager, - request: String, - response: CharSequence - ) { - super.onReceiveUssdResponse(telephonyManager, request, response) - Log.d(TAG, "USSD response for $request: $response") - postServiceEvent(ServiceEvent("ussd response", arrayListOf(uap, request, response.toString()), System.nanoTime())) - } + val tm = getSystemService(TELEPHONY_SERVICE) as TelephonyManager + try { + tm.sendUssdRequest(ussdCode, object : TelephonyManager.UssdResponseCallback() { + override fun onReceiveUssdResponse( + telephonyManager: TelephonyManager, + request: String, + response: CharSequence + ) { + super.onReceiveUssdResponse(telephonyManager, request, response) + Log.d(TAG, "USSD response for $request: $response") + postServiceEvent(ServiceEvent("ussd response", arrayListOf(uap, request, response.toString()), System.nanoTime())) + } - override fun onReceiveUssdResponseFailed( - telephonyManager: TelephonyManager, - request: String, - failureCode: Int - ) { - super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode) - Log.d(TAG, "USSD response for $request failed with code $failureCode") - val error = when (failureCode) { - TelephonyManager.USSD_RETURN_FAILURE -> getString(R.string.ussd_failed) - TelephonyManager.USSD_ERROR_SERVICE_UNAVAIL -> getString(R.string.ussd_service_unavailable) - else -> getString(R.string.ussd_unknown_error) - } - postServiceEvent(ServiceEvent("ussd fail", arrayListOf(uap, request, error), System.nanoTime())) + override fun onReceiveUssdResponseFailed( + telephonyManager: TelephonyManager, + request: String, + failureCode: Int + ) { + super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode) + Log.d(TAG, "USSD response for $request failed with code $failureCode") + val error = when (failureCode) { + TelephonyManager.USSD_RETURN_FAILURE -> getString(R.string.ussd_failed) + TelephonyManager.USSD_ERROR_SERVICE_UNAVAIL -> getString(R.string.ussd_service_unavailable) + else -> getString(R.string.ussd_unknown_error) } - }, Handler(Looper.getMainLooper())) - } catch (e: Exception) { - Log.e(TAG, "Exception sending USSD request: ${e.message}") - toast(getString(R.string.ussd_failed)) - } - } else { - toast(getString(R.string.ussd_not_supported)) + postServiceEvent(ServiceEvent("ussd fail", arrayListOf(uap, request, error), System.nanoTime())) + } + }, Handler(Looper.getMainLooper())) + } catch (e: Exception) { + Log.e(TAG, "Exception sending USSD request: ${e.message}") + toast(getString(R.string.ussd_failed)) } } @@ -3128,7 +3124,8 @@ class BaresipService: Service() { if (serviceEvents.size == 1) { Log.d(TAG, "Posted service event ${event.event} at ${event.timeStamp}") serviceEvent.postValue(Event(event.timeStamp)) - } else + } + else Log.d(TAG, "Added service event ${event.event}") } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt index 336be445..b3c2452a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt @@ -165,6 +165,7 @@ import kotlinx.coroutines.delay import java.io.File import java.text.SimpleDateFormat import java.util.Date +import java.util.GregorianCalendar import java.util.Locale import kotlin.time.Duration.Companion.milliseconds @@ -1533,7 +1534,8 @@ private fun CallRow( if (call.callOnHold.value) { Log.d(TAG, "User requested resume for ${call.callp}") call.resume() // This now automatically holds other calls - } else { + } + else { Log.d(TAG, "User requested hold for ${call.callp}") call.hold() } @@ -2249,11 +2251,13 @@ private fun showCall(ctx: Context, viewModel: ViewModel, ua: UserAgent?, showCal call.callUriLabel.value = ctx.getString(R.string.outgoing_call_to_dots) call.callUri.value = Utils.friendlyUri(ctx, call.referTo, ua.account) call.transferButtonEnabled.value = false - } else { + } + else { if (call.dir == "out") { call.callUriLabel.value = ctx.getString(R.string.outgoing_call_to_dots) call.callUri.value = Utils.friendlyUri(ctx, call.peerUri, ua.account) - } else { + } + else { call.callUriLabel.value = ctx.getString(R.string.incoming_call_from_dots) call.callUri.value = Utils.friendlyUri(ctx, call.peerUri, ua.account) } @@ -2339,15 +2343,29 @@ fun handleServiceEvent(ctx: Context, viewModel: ViewModel, event: String, params when (ev[0]) { "ussd response" -> { - if (aor == viewModel.selectedAor.value) + if (aor == viewModel.selectedAor.value) { viewModel.dialerState.callButtonsEnabled.value = true + viewModel.dialerState.callUri.value = "" + } + if (acc.callHistory) { + val history = CallHistoryNew(aor, "tel:" + (params[1] as String), "out") + history.startTime = GregorianCalendar() + history.add() + } handleDialog(ctx, ctx.getString(R.string.info), params[2] as String) handleNextEvent() return } "ussd fail" -> { - if (aor == viewModel.selectedAor.value) + if (aor == viewModel.selectedAor.value) { viewModel.dialerState.callButtonsEnabled.value = true + viewModel.dialerState.callUri.value = "" + } + if (acc.callHistory) { + val history = CallHistoryNew(aor, "tel:" + (params[1] as String), "out") + history.rejected = true + history.add() + } handleDialog(ctx, ctx.getString(R.string.error), params[2] as String) handleNextEvent() return diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index b7adc48d..83714353 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -198,7 +198,7 @@ object Utils { fun e164Uri(uri: String, countryCode: String): String { val scheme = uri.take(4) val userPart = uriUserPart(uri) - return if (userPart.isDigitsOnly()) { + return if (userPart.isNotEmpty() && userPart.isDigitsOnly()) { when { userPart.startsWith("00") -> uri.replace("$scheme$userPart", scheme + "+" + userPart.substring(2)) diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 8c3a0ec8..9486aa98 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -647,6 +647,9 @@ Puhelutiedot Et voi käyttää Androidin yhteystietoja ilman Yhteystiedot-lupaa. Audiofokus on evätty! + USSD-pyyntö epäonnistui + USSD-palvelu ei ole käytettävissä + Tuntematon USSD-virhe Tarvittavat luvat baresip tarvitsee Mikrofoni-luvan puheluita varten, Lähellä olevat laitteet -luvan Bluetooth-mikrofonin/kaiuttimen havaitsemista varten, Ilmoitukset-luvan ilmoitusten lähettämistä varten diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14f4083e..0a82b208 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -633,10 +633,9 @@ No network connection! No hardware Acoustic Echo Cancellation! Audio focus denied! - USSD failed + USSD request failed USSD service unavailable USSD unknown error - USSD not supported Permissions rationale baresip needs \"Microphone\" permission for voice calls, \"Nearby devices\" permission for Bluetooth microphone/speaker detection,