From fff6fcfc6887e113e25cfb7a8e07b8b73af0c62c Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 31 Aug 2017 15:30:58 -0700 Subject: Use TelecomManager#isInManagedCall starting from O. The TelecomManager#isInCall method returns true anytime the user is in a call. Starting in O, the APIs include support for self-managed ConnectionServices so that other apps like Duo can tell Telecom about its calls. So, if the user is in a Duo call, isInCall would return true. Dialer uses this to determine whether to show the "return to call in progress" when Dialer is launched. Instead, Dialer should use TelecomManager#isInManagedCall, which only returns true if the device is in a managed call which Dialer would know about. Bug: 36991070 Test: none PiperOrigin-RevId: 167200903 Change-Id: I12ac7b893dcbfa2fc842ca5ab356fbbc490a098b --- java/com/android/dialer/telecom/TelecomUtil.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 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 573bfe2d9..8ff4b3967 100644 --- a/java/com/android/dialer/telecom/TelecomUtil.java +++ b/java/com/android/dialer/telecom/TelecomUtil.java @@ -21,6 +21,8 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.provider.CallLog.Calls; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; @@ -140,7 +142,11 @@ public abstract class TelecomUtil { return new ArrayList<>(); } - public static boolean isInCall(Context context) { + /** + * Returns true if there is a dialer managed call in progress. Self managed calls starting from O + * are not included. + */ + public static boolean isInManagedCall(Context context) { return instance.isInCall(context); } @@ -234,7 +240,19 @@ public abstract class TelecomUtil { public boolean isInCall(Context context) { if (hasReadPhoneStatePermission(context)) { - return getTelecomManager(context).isInCall(); + // The TelecomManager#isInCall method returns true anytime the user is in a call. + // Starting in O, the APIs include support for self-managed ConnectionServices so that other + // apps like Duo can tell Telecom about its calls. So, if the user is in a Duo call, + // isInCall would return true. + // Dialer uses this to determine whether to show the "return to call in progress" when + // Dialer is launched. + // Instead, Dialer should use TelecomManager#isInManagedCall, which only returns true if the + // device is in a managed call which Dialer would know about. + if (VERSION.SDK_INT >= VERSION_CODES.O) { + return getTelecomManager(context).isInManagedCall(); + } else { + return getTelecomManager(context).isInCall(); + } } return false; } -- cgit v1.2.3