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,12 +105,14 @@ class TelecomHelper private constructor(context: Context) {
|
|||
@SuppressLint("MissingPermission")
|
||||
fun findExistingAccount(context: Context): PhoneAccount? {
|
||||
if (PermissionHelper.required(context).hasReadPhoneStateOrPhoneNumbersPermission()) {
|
||||
try {
|
||||
var account: PhoneAccount? = null
|
||||
val phoneAccountHandleList: List<PhoneAccountHandle> =
|
||||
telecomManager.selfManagedPhoneAccounts
|
||||
val connectionService = ComponentName(context, TelecomConnectionService::class.java)
|
||||
for (phoneAccountHandle in phoneAccountHandleList) {
|
||||
val phoneAccount: PhoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle)
|
||||
val phoneAccount: PhoneAccount =
|
||||
telecomManager.getPhoneAccount(phoneAccountHandle)
|
||||
if (phoneAccountHandle.componentName == connectionService) {
|
||||
Log.i("[Telecom Helper] Found existing phone account: $phoneAccount")
|
||||
account = phoneAccount
|
||||
|
@ -121,6 +123,9 @@ class TelecomHelper private constructor(context: Context) {
|
|||
Log.w("[Telecom Helper] Existing phone account not found")
|
||||
}
|
||||
return account
|
||||
} catch (se: SecurityException) {
|
||||
Log.w("[Telecom Helper] Can't check phone accounts: $se")
|
||||
}
|
||||
} else {
|
||||
Log.e("[Telecom Helper] Can't search for existing phone account, missing permission(s)")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue