Improved USSD and MMI code handling
This commit is contained in:
@ -1697,10 +1697,25 @@ class BaresipService: Service() {
|
|||||||
fun runCall(uap: Long, uri: String, conferenceCall: Boolean, onHoldCallp: Long) {
|
fun runCall(uap: Long, uri: String, conferenceCall: Boolean, onHoldCallp: Long) {
|
||||||
|
|
||||||
val ua = UserAgent.ofUap(uap)
|
val ua = UserAgent.ofUap(uap)
|
||||||
if (ua != null && ua.account.isMobile && Utils.isUssd(uri)) {
|
if (ua != null && ua.account.isMobile) {
|
||||||
sendUssd(Utils.uriUserPart(uri))
|
val user = Utils.uriUserPart(uri)
|
||||||
|
if (user.startsWith("*#*#") && user.endsWith("#*#*")) {
|
||||||
|
val code = user.substring(4, user.length - 4)
|
||||||
|
val intent = Intent("android.provider.Telephony.SECRET_CODE", "android_secret_code://$code".toUri())
|
||||||
|
sendBroadcast(intent)
|
||||||
|
postServiceEvent(ServiceEvent("ussd response", arrayListOf(uap, user, ""), System.nanoTime()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (user == "*#06#") {
|
||||||
|
val imei = getDeviceId(this)
|
||||||
|
postServiceEvent(ServiceEvent("imei", arrayListOf(uap, user, imei), System.nanoTime()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (Utils.isUssd(uri)) {
|
||||||
|
sendUssd(user)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val executeCall = {
|
val executeCall = {
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
@ -2338,6 +2353,16 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("HardwareIds", "MissingPermission")
|
||||||
|
private fun getDeviceId(context: Context): String {
|
||||||
|
val tm = context.getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
||||||
|
return try {
|
||||||
|
tm.imei ?: tm.meid ?: "N/A"
|
||||||
|
} catch (_: SecurityException) {
|
||||||
|
"N/A"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun toast(message: String, length: Int = Toast.LENGTH_SHORT) {
|
private fun toast(message: String, length: Int = Toast.LENGTH_SHORT) {
|
||||||
Handler(Looper.getMainLooper()).post {
|
Handler(Looper.getMainLooper()).post {
|
||||||
Toast.makeText(this, message, length).show()
|
Toast.makeText(this, message, length).show()
|
||||||
|
|||||||
@ -2339,6 +2339,15 @@ fun handleServiceEvent(ctx: Context, viewModel: ViewModel, event: String, params
|
|||||||
val aor = ua.account.aor
|
val aor = ua.account.aor
|
||||||
|
|
||||||
when (ev[0]) {
|
when (ev[0]) {
|
||||||
|
"imei" -> {
|
||||||
|
if (aor == viewModel.selectedAor.value) {
|
||||||
|
viewModel.dialerState.callButtonsEnabled.value = true
|
||||||
|
viewModel.dialerState.callUri.value = ""
|
||||||
|
}
|
||||||
|
handleDialog(ctx, ctx.getString(R.string.info), "IMEI: " + (params[2] as String))
|
||||||
|
handleNextEvent()
|
||||||
|
return
|
||||||
|
}
|
||||||
"ussd response" -> {
|
"ussd response" -> {
|
||||||
if (aor == viewModel.selectedAor.value) {
|
if (aor == viewModel.selectedAor.value) {
|
||||||
viewModel.dialerState.callButtonsEnabled.value = true
|
viewModel.dialerState.callButtonsEnabled.value = true
|
||||||
|
|||||||
@ -378,8 +378,9 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isUssd(uri: String): Boolean {
|
fun isUssd(uri: String): Boolean {
|
||||||
val user = uriUserPart(uri)
|
val u = uriUserPart(uri)
|
||||||
return user.startsWith("*") && user.endsWith("#")
|
// Must start with * or # and must end with #, but exclude "Secret Code" pattern (*#*#...#*#*)
|
||||||
|
return (u.startsWith("*") || u.startsWith("#")) && u.endsWith("#") && !u.startsWith("*#*#")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkUri(uri: String): Boolean {
|
fun checkUri(uri: String): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user