mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
require the PERMISSION_READ_PHONE_STATE before getting the SIM card to use
This commit is contained in:
@ -122,19 +122,19 @@ fun SimpleActivity.callContact(contact: Contact) {
|
|||||||
// used at devices with multiple SIM cards
|
// used at devices with multiple SIM cards
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) {
|
fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) {
|
||||||
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
|
handlePermission(PERMISSION_READ_PHONE_STATE) {
|
||||||
when {
|
if (it) {
|
||||||
intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!)
|
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
|
||||||
config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> {
|
when {
|
||||||
val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber))
|
intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!)
|
||||||
val availableSIMs = getAvailableSIMCardLabels()
|
config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> {
|
||||||
val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle
|
val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber))
|
||||||
callback(firstornull)
|
val availableSIMs = getAvailableSIMCardLabels()
|
||||||
}
|
val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle
|
||||||
defaultHandle != null -> callback(defaultHandle)
|
callback(firstornull)
|
||||||
else -> {
|
}
|
||||||
handlePermission(PERMISSION_READ_PHONE_STATE) {
|
defaultHandle != null -> callback(defaultHandle)
|
||||||
if (it) {
|
else -> {
|
||||||
SelectSIMDialog(this, phoneNumber) { handle ->
|
SelectSIMDialog(this, phoneNumber) { handle ->
|
||||||
callback(handle)
|
callback(handle)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user