From 827a90fb309fd26f5b155c1ad612512011d58437 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Thu, 17 Sep 2015 18:10:58 -0700 Subject: Wrap some privileged Telecom operations with permission checks If the Dialer is not the default dialer and does not have the CALL_PHONE permission, don't call TelecomManager methods that will cause SecurityExceptions. Bug: 20266292 Change-Id: I229dd045269a262632c4a911e2321203443de684 --- src/com/android/dialer/util/TelecomUtil.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/com/android/dialer/util/TelecomUtil.java') diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java index 1cd270c9b..43b9a72a3 100644 --- a/src/com/android/dialer/util/TelecomUtil.java +++ b/src/com/android/dialer/util/TelecomUtil.java @@ -26,6 +26,9 @@ import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.Log; +import java.util.ArrayList; +import java.util.List; + public class TelecomUtil { private static final String TAG = "TelecomUtil"; private static boolean sWarningLogged = false; @@ -78,6 +81,20 @@ public class TelecomUtil { return false; } + public static List getCallCapablePhoneAccounts(Context context) { + if (hasReadPhoneStatePermission(context)) { + return getTelecomManager(context).getCallCapablePhoneAccounts(); + } + return new ArrayList<>(); + } + + public static boolean isInCall(Context context) { + if (hasReadPhoneStatePermission(context)) { + return getTelecomManager(context).isInCall(); + } + return false; + } + public static Uri getCallLogUri(Context context) { return hasReadWriteVoicemailPermissions(context) ? Calls.CONTENT_URI_WITH_VOICEMAIL : Calls.CONTENT_URI; @@ -94,6 +111,16 @@ public class TelecomUtil { || hasPermission(context, Manifest.permission.MODIFY_PHONE_STATE); } + public static boolean hasReadPhoneStatePermission(Context context) { + return isDefaultDialer(context) + || hasPermission(context, Manifest.permission.READ_PHONE_STATE); + } + + public static boolean hasCallPhonePermission(Context context) { + return isDefaultDialer(context) + || hasPermission(context, Manifest.permission.CALL_PHONE); + } + private static boolean hasPermission(Context context, String permission) { return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED; -- cgit v1.2.3