mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Prevent using requireContext() from Core's thead in Fragment
This commit is contained in:
parent
d8d424d446
commit
317bbb470b
4 changed files with 16 additions and 8 deletions
|
|
@ -19,9 +19,11 @@
|
|||
*/
|
||||
package org.linphone.ui.assistant.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.telephony.TelephonyManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -137,8 +139,10 @@ class LandingFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
val telephonyManager = requireContext().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
val countryIso = telephonyManager.networkCountryIso
|
||||
coreContext.postOnCoreThread {
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(requireContext())
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(countryIso)
|
||||
if (dialPlan != null) {
|
||||
viewModel.internationalPrefix.postValue(dialPlan.countryCallingCode)
|
||||
viewModel.internationalPrefixIsoCountryCode.postValue(dialPlan.isoCountryCode)
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@
|
|||
*/
|
||||
package org.linphone.ui.assistant.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.telephony.TelephonyManager
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.LayoutInflater
|
||||
|
|
@ -168,6 +170,8 @@ class RegisterFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
val telephonyManager = requireContext().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
val countryIso = telephonyManager.networkCountryIso
|
||||
coreContext.postOnCoreThread {
|
||||
val adapter = object : ArrayAdapter<String>(
|
||||
requireContext(),
|
||||
|
|
@ -183,7 +187,7 @@ class RegisterFragment : GenericFragment() {
|
|||
}
|
||||
adapter.setDropDownViewResource(R.layout.assistant_country_picker_dropdown_cell)
|
||||
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(requireContext())
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(countryIso)
|
||||
var default = 0
|
||||
if (dialPlan != null) {
|
||||
viewModel.selectedDialPlan.postValue(dialPlan)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@
|
|||
*/
|
||||
package org.linphone.ui.assistant.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.telephony.TelephonyManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -141,8 +143,10 @@ class ThirdPartySipAccountLoginFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
val telephonyManager = requireContext().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
val countryIso = telephonyManager.networkCountryIso
|
||||
coreContext.postOnCoreThread {
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(requireContext())
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(countryIso)
|
||||
if (dialPlan != null) {
|
||||
viewModel.internationalPrefix.postValue(dialPlan.countryCallingCode)
|
||||
viewModel.internationalPrefixIsoCountryCode.postValue(dialPlan.isoCountryCode)
|
||||
|
|
|
|||
|
|
@ -19,10 +19,8 @@
|
|||
*/
|
||||
package org.linphone.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.TelephonyManager
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import org.linphone.core.DialPlan
|
||||
|
|
@ -34,9 +32,7 @@ class PhoneNumberUtils {
|
|||
private const val TAG = "[Phone Number Utils]"
|
||||
|
||||
@WorkerThread
|
||||
fun getDeviceDialPlan(context: Context): DialPlan? {
|
||||
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
val countryIso = telephonyManager.networkCountryIso
|
||||
fun getDeviceDialPlan(countryIso: String): DialPlan? {
|
||||
for (dp in Factory.instance().dialPlans) {
|
||||
if (dp.isoCountryCode.equals(countryIso, true)) {
|
||||
val prefix = dp.countryCallingCode
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue