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,6 +122,8 @@ 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) {
handlePermission(PERMISSION_READ_PHONE_STATE) {
if (it) {
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
when { when {
intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!)
@ -133,8 +135,6 @@ fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback
} }
defaultHandle != null -> callback(defaultHandle) defaultHandle != null -> callback(defaultHandle)
else -> { else -> {
handlePermission(PERMISSION_READ_PHONE_STATE) {
if (it) {
SelectSIMDialog(this, phoneNumber) { handle -> SelectSIMDialog(this, phoneNumber) { handle ->
callback(handle) callback(handle)
} }