Prevent crash if Security Exception is thrown in TelecomHelper.findExistingAccount (see on Oppo running Android 11 asking for READ_PHONE_STATE even if it shoudln't)
This commit is contained in:
parent
68fb96e3a1
commit
5bb5bd16ae
1 changed files with 19 additions and 14 deletions
|
@ -105,22 +105,27 @@ class TelecomHelper private constructor(context: Context) {
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun findExistingAccount(context: Context): PhoneAccount? {
|
fun findExistingAccount(context: Context): PhoneAccount? {
|
||||||
if (PermissionHelper.required(context).hasReadPhoneStateOrPhoneNumbersPermission()) {
|
if (PermissionHelper.required(context).hasReadPhoneStateOrPhoneNumbersPermission()) {
|
||||||
var account: PhoneAccount? = null
|
try {
|
||||||
val phoneAccountHandleList: List<PhoneAccountHandle> =
|
var account: PhoneAccount? = null
|
||||||
telecomManager.selfManagedPhoneAccounts
|
val phoneAccountHandleList: List<PhoneAccountHandle> =
|
||||||
val connectionService = ComponentName(context, TelecomConnectionService::class.java)
|
telecomManager.selfManagedPhoneAccounts
|
||||||
for (phoneAccountHandle in phoneAccountHandleList) {
|
val connectionService = ComponentName(context, TelecomConnectionService::class.java)
|
||||||
val phoneAccount: PhoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle)
|
for (phoneAccountHandle in phoneAccountHandleList) {
|
||||||
if (phoneAccountHandle.componentName == connectionService) {
|
val phoneAccount: PhoneAccount =
|
||||||
Log.i("[Telecom Helper] Found existing phone account: $phoneAccount")
|
telecomManager.getPhoneAccount(phoneAccountHandle)
|
||||||
account = phoneAccount
|
if (phoneAccountHandle.componentName == connectionService) {
|
||||||
break
|
Log.i("[Telecom Helper] Found existing phone account: $phoneAccount")
|
||||||
|
account = phoneAccount
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (account == null) {
|
||||||
|
Log.w("[Telecom Helper] Existing phone account not found")
|
||||||
|
}
|
||||||
|
return account
|
||||||
|
} catch (se: SecurityException) {
|
||||||
|
Log.w("[Telecom Helper] Can't check phone accounts: $se")
|
||||||
}
|
}
|
||||||
if (account == null) {
|
|
||||||
Log.w("[Telecom Helper] Existing phone account not found")
|
|
||||||
}
|
|
||||||
return account
|
|
||||||
} else {
|
} else {
|
||||||
Log.e("[Telecom Helper] Can't search for existing phone account, missing permission(s)")
|
Log.e("[Telecom Helper] Can't search for existing phone account, missing permission(s)")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue