require the PERMISSION_READ_PHONE_STATE before getting the SIM card to use

This commit is contained in:
tibbi
2020-05-02 21:07:55 +02:00
parent ce281797b4
commit 3b0ca0ccf0

View File

@ -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)
} }