From cded3beaf28a703e1ef8f71bbc6836e6806c3736 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Fri, 9 Jun 2017 14:16:05 +0000 Subject: Revert "Update AOSP Dialer source from internal google3 repository at cl/158012278. am: 91ce7d2a47" This reverts commit c67d658e7daa453fe9ad9fd1a37f81eaf2048c44. Reason for revert: This CL broke the sailfish-userdebug_javac-all target on master. Change-Id: I9b54333a654c00154ca84f4ece84bea4f07cc19b --- java/com/android/dialer/telecom/TelecomUtil.java | 80 +++++++++++------------- 1 file changed, 37 insertions(+), 43 deletions(-) (limited to 'java/com/android/dialer/telecom') diff --git a/java/com/android/dialer/telecom/TelecomUtil.java b/java/com/android/dialer/telecom/TelecomUtil.java index 82b43835f..87ddda58b 100644 --- a/java/com/android/dialer/telecom/TelecomUtil.java +++ b/java/com/android/dialer/telecom/TelecomUtil.java @@ -38,17 +38,12 @@ import java.util.List; * perform the required check and return the fallback default if the permission is missing, * otherwise return the value from TelecomManager. */ -public abstract class TelecomUtil { +public class TelecomUtil { private static final String TAG = "TelecomUtil"; private static boolean sWarningLogged = false; - - private static TelecomUtilImpl instance = new TelecomUtilImpl(); - - @VisibleForTesting(otherwise = VisibleForTesting.NONE) - public static void setInstanceForTesting(TelecomUtilImpl instanceForTesting) { - instance = instanceForTesting; - } + private static Boolean isDefaultDialerForTesting; + private static Boolean hasPermissionForTesting; public static void showInCallScreen(Context context, boolean showDialpad) { if (hasReadPhoneStatePermission(context)) { @@ -130,7 +125,10 @@ public abstract class TelecomUtil { } public static boolean isInCall(Context context) { - return instance.isInCall(context); + if (hasReadPhoneStatePermission(context)) { + return getTelecomManager(context).isInCall(); + } + return false; } public static boolean isVoicemailNumber( @@ -191,47 +189,43 @@ public abstract class TelecomUtil { } private static boolean hasPermission(Context context, String permission) { - return instance.hasPermission(context, permission); + if (hasPermissionForTesting != null) { + return hasPermissionForTesting; + } + return ContextCompat.checkSelfPermission(context, permission) + == PackageManager.PERMISSION_GRANTED; + } + + public static boolean isDefaultDialer(Context context) { + if (isDefaultDialerForTesting != null) { + return isDefaultDialerForTesting; + } + final boolean result = + TextUtils.equals( + context.getPackageName(), getTelecomManager(context).getDefaultDialerPackage()); + if (result) { + sWarningLogged = false; + } else { + if (!sWarningLogged) { + // Log only once to prevent spam. + LogUtil.w(TAG, "Dialer is not currently set to be default dialer"); + sWarningLogged = true; + } + } + return result; } private static TelecomManager getTelecomManager(Context context) { return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); } - public static boolean isDefaultDialer(Context context) { - return instance.isDefaultDialer(context); + @VisibleForTesting(otherwise = VisibleForTesting.NONE) + public static void setIsDefaultDialerForTesting(Boolean defaultDialer) { + isDefaultDialerForTesting = defaultDialer; } - /** Contains an implementation for {@link TelecomUtil} methods */ - @VisibleForTesting() - public static class TelecomUtilImpl { - - public boolean isInCall(Context context) { - if (hasReadPhoneStatePermission(context)) { - return getTelecomManager(context).isInCall(); - } - return false; - } - - public boolean hasPermission(Context context, String permission) { - return ContextCompat.checkSelfPermission(context, permission) - == PackageManager.PERMISSION_GRANTED; - } - - public boolean isDefaultDialer(Context context) { - final boolean result = - TextUtils.equals( - context.getPackageName(), getTelecomManager(context).getDefaultDialerPackage()); - if (result) { - sWarningLogged = false; - } else { - if (!sWarningLogged) { - // Log only once to prevent spam. - LogUtil.w(TAG, "Dialer is not currently set to be default dialer"); - sWarningLogged = true; - } - } - return result; - } + @VisibleForTesting(otherwise = VisibleForTesting.NONE) + public static void setHasPermissionForTesting(Boolean hasPermission) { + hasPermissionForTesting = hasPermission; } } -- cgit v1.2.3