summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/telecom/TelecomUtil.java
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-06-05 13:35:02 -0700
committerEric Erfanian <erfanian@google.com>2017-06-07 20:44:54 +0000
commit91ce7d2a476bd04fe525049a37a2f8b2824e9724 (patch)
treeb9bbc285430ffb5363a70eb27e382c38f5a85b7a /java/com/android/dialer/telecom/TelecomUtil.java
parent75233ff03785f24789b32039ac2c208805b7e506 (diff)
Update AOSP Dialer source from internal google3 repository at
cl/158012278. Test: make, treehugger This CL updates the AOSP Dialer source with all the changes that have gone into the private google3 repository. This includes all the changes from cl/152373142 (4/06/2017) to cl/158012278 (6/05/2017). This goal of these drops is to keep the AOSP source in sync with the internal google3 repository. Currently these sync are done by hand with very minor modifications to the internal source code. See the Android.mk file for list of modifications. Our current goal is to do frequent drops (daily if possible) and eventually switched to an automated process. Change-Id: I4d3f14b5140e2e51bead9497bc118a205b3ebe76
Diffstat (limited to 'java/com/android/dialer/telecom/TelecomUtil.java')
-rw-r--r--java/com/android/dialer/telecom/TelecomUtil.java80
1 files changed, 43 insertions, 37 deletions
diff --git a/java/com/android/dialer/telecom/TelecomUtil.java b/java/com/android/dialer/telecom/TelecomUtil.java
index 87ddda58b..82b43835f 100644
--- a/java/com/android/dialer/telecom/TelecomUtil.java
+++ b/java/com/android/dialer/telecom/TelecomUtil.java
@@ -38,12 +38,17 @@ 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 class TelecomUtil {
+public abstract class TelecomUtil {
private static final String TAG = "TelecomUtil";
private static boolean sWarningLogged = false;
- private static Boolean isDefaultDialerForTesting;
- private static Boolean hasPermissionForTesting;
+
+ private static TelecomUtilImpl instance = new TelecomUtilImpl();
+
+ @VisibleForTesting(otherwise = VisibleForTesting.NONE)
+ public static void setInstanceForTesting(TelecomUtilImpl instanceForTesting) {
+ instance = instanceForTesting;
+ }
public static void showInCallScreen(Context context, boolean showDialpad) {
if (hasReadPhoneStatePermission(context)) {
@@ -125,10 +130,7 @@ public class TelecomUtil {
}
public static boolean isInCall(Context context) {
- if (hasReadPhoneStatePermission(context)) {
- return getTelecomManager(context).isInCall();
- }
- return false;
+ return instance.isInCall(context);
}
public static boolean isVoicemailNumber(
@@ -189,43 +191,47 @@ public class TelecomUtil {
}
private static boolean hasPermission(Context context, String 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;
+ return instance.hasPermission(context, permission);
}
private static TelecomManager getTelecomManager(Context context) {
return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
}
- @VisibleForTesting(otherwise = VisibleForTesting.NONE)
- public static void setIsDefaultDialerForTesting(Boolean defaultDialer) {
- isDefaultDialerForTesting = defaultDialer;
+ public static boolean isDefaultDialer(Context context) {
+ return instance.isDefaultDialer(context);
}
- @VisibleForTesting(otherwise = VisibleForTesting.NONE)
- public static void setHasPermissionForTesting(Boolean hasPermission) {
- hasPermissionForTesting = hasPermission;
+ /** 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;
+ }
}
}