Do not create Mobile account if SIM is data-only
This commit is contained in:
@ -59,6 +59,7 @@ import android.telecom.PhoneAccountHandle
|
|||||||
import android.telecom.TelecomManager
|
import android.telecom.TelecomManager
|
||||||
import android.telephony.PhoneStateListener
|
import android.telephony.PhoneStateListener
|
||||||
import android.telephony.ServiceState
|
import android.telephony.ServiceState
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
import android.telephony.TelephonyCallback
|
import android.telephony.TelephonyCallback
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -879,8 +880,10 @@ class BaresipService: Service() {
|
|||||||
Log.d(TAG, "Removing Mobile account on API < 29")
|
Log.d(TAG, "Removing Mobile account on API < 29")
|
||||||
removeMobile = true
|
removeMobile = true
|
||||||
}
|
}
|
||||||
else if (Utils.pstnAccountHandle(this) == null || !isSimReady()) {
|
else if (Utils.pstnAccountHandle(this) == null || !isSimReady() ||
|
||||||
Log.d(TAG, "Removing Mobile account (SIM not ready or not default dialer)")
|
!telephonyManager.isVoiceCapable ||
|
||||||
|
SubscriptionManager.getDefaultVoiceSubscriptionId() == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
Log.d(TAG, "Removing Mobile account (SIM not ready, not default dialer, or not voice capable)")
|
||||||
removeMobile = true
|
removeMobile = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2325,13 +2328,15 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
val mobileAccountHandle = Utils.pstnAccountHandle(this)
|
val mobileAccountHandle = Utils.pstnAccountHandle(this)
|
||||||
val isSimReady = isSimReady()
|
val isSimReady = isSimReady()
|
||||||
|
val isVoiceCapable = telephonyManager.isVoiceCapable
|
||||||
|
val voiceSubId = SubscriptionManager.getDefaultVoiceSubscriptionId()
|
||||||
val existingMobileUa = uas.value.find { it.account.isMobile || Utils.uriMatch(it.account.aor, "sip:mobile@pstn") }
|
val existingMobileUa = uas.value.find { it.account.isMobile || Utils.uriMatch(it.account.aor, "sip:mobile@pstn") }
|
||||||
|
|
||||||
if (mobileAccountHandle == null || !isSimReady) {
|
if (mobileAccountHandle == null || !isSimReady || !isVoiceCapable ||
|
||||||
|
voiceSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
if (existingMobileUa != null) {
|
if (existingMobileUa != null) {
|
||||||
Log.d(TAG, "Removing existing Mobile account (SIM not ready or not default dialer)")
|
Log.d(TAG, "Removing existing Mobile account (SIM not ready, not default dialer, or not voice capable)")
|
||||||
if (existingMobileUa.uap != 0L)
|
if (existingMobileUa.uap != 0L) Api.ua_destroy(existingMobileUa.uap)
|
||||||
Api.ua_destroy(existingMobileUa.uap)
|
|
||||||
existingMobileUa.remove()
|
existingMobileUa.remove()
|
||||||
if (isNativeReady) Account.saveAccounts()
|
if (isNativeReady) Account.saveAccounts()
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
@ -2399,9 +2404,12 @@ class BaresipService: Service() {
|
|||||||
private fun updateMobileStatus(newStatus: Int? = null) {
|
private fun updateMobileStatus(newStatus: Int? = null) {
|
||||||
val mobileAccountHandle = Utils.pstnAccountHandle(this)
|
val mobileAccountHandle = Utils.pstnAccountHandle(this)
|
||||||
val isSimReady = isSimReady()
|
val isSimReady = isSimReady()
|
||||||
|
val isVoiceCapable = telephonyManager.isVoiceCapable
|
||||||
|
val voiceSubId = SubscriptionManager.getDefaultVoiceSubscriptionId()
|
||||||
val mobileUa = uas.value.find { it.account.isMobile }
|
val mobileUa = uas.value.find { it.account.isMobile }
|
||||||
|
|
||||||
if (mobileUa == null || mobileAccountHandle == null || !isSimReady) {
|
if (mobileUa == null || mobileAccountHandle == null || !isSimReady || !isVoiceCapable ||
|
||||||
|
voiceSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
addMobileUserAgent()
|
addMobileUserAgent()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2431,10 +2439,15 @@ class BaresipService: Service() {
|
|||||||
if (VERSION.SDK_INT >= 29) {
|
if (VERSION.SDK_INT >= 29) {
|
||||||
val isAirplaneModeOn = Utils.isAirplaneModeOn(this)
|
val isAirplaneModeOn = Utils.isAirplaneModeOn(this)
|
||||||
val isSimReady = isSimReady()
|
val isSimReady = isSimReady()
|
||||||
|
val isVoiceCapable = telephonyManager.isVoiceCapable
|
||||||
|
val voiceSubId = SubscriptionManager.getDefaultVoiceSubscriptionId()
|
||||||
val mobileAccountHandle = Utils.pstnAccountHandle(this)
|
val mobileAccountHandle = Utils.pstnAccountHandle(this)
|
||||||
val status = if (state == ServiceState.STATE_IN_SERVICE && isSimReady && mobileAccountHandle != null)
|
val status = if (state == ServiceState.STATE_IN_SERVICE && isSimReady &&
|
||||||
|
mobileAccountHandle != null && isVoiceCapable &&
|
||||||
|
voiceSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID)
|
||||||
circleGreen.getValue(colorblind)
|
circleGreen.getValue(colorblind)
|
||||||
else if (mobileAccountHandle == null || isAirplaneModeOn || !isSimReady)
|
else if (mobileAccountHandle == null || isAirplaneModeOn || !isSimReady ||
|
||||||
|
!isVoiceCapable || voiceSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
|
||||||
R.drawable.circle_white
|
R.drawable.circle_white
|
||||||
else
|
else
|
||||||
circleRed.getValue(colorblind)
|
circleRed.getValue(colorblind)
|
||||||
|
|||||||
Reference in New Issue
Block a user