diff options
author | Nancy Chen <nancychen@google.com> | 2015-11-25 14:40:23 -0800 |
---|---|---|
committer | Nancy Chen <nancychen@google.com> | 2015-11-25 14:40:23 -0800 |
commit | 15d1f41fb48ef119ec02b3d50bede25281ae8f50 (patch) | |
tree | 27334db56d58ea82150e865aff448e50f0f1b678 | |
parent | 76545e667b10a1b02e5b6bc5f42c0673aca2a5bc (diff) |
Guard against crashes in <M devices for getDefaultDialerPackage call.
Since TelecomManager was hidden in L, calls to getDefaultDialerPackage
will crash. Furthermore, default dialer was not even a concept in
Android <M so return false for the isDefaultDialer check.
Bug: 25776171
Change-Id: I05c9f55b69bdbe1e07cf44886dbff29d99f36bbb
-rw-r--r-- | src/com/android/dialer/compat/DialerCompatUtils.java | 11 | ||||
-rw-r--r-- | src/com/android/dialer/util/TelecomUtil.java | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/com/android/dialer/compat/DialerCompatUtils.java b/src/com/android/dialer/compat/DialerCompatUtils.java index 678ffb09d..cda51c691 100644 --- a/src/com/android/dialer/compat/DialerCompatUtils.java +++ b/src/com/android/dialer/compat/DialerCompatUtils.java @@ -30,4 +30,15 @@ public final class DialerCompatUtils { return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M; } + + /** + * Determines if this version is compatible with a default dialer. Can also force the version to + * be lower through SdkVersionOverride. + * + * @return {@code true} if default dialer is a feature on this device, {@code false} otherwise. + */ + public static boolean isDefaultDialerCompatible() { + return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP) + >= Build.VERSION_CODES.M; + } }
\ No newline at end of file diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java index 123057787..a0c833462 100644 --- a/src/com/android/dialer/util/TelecomUtil.java +++ b/src/com/android/dialer/util/TelecomUtil.java @@ -28,6 +28,8 @@ import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.Log; +import com.android.dialer.compat.DialerCompatUtils; + import java.util.ArrayList; import java.util.List; @@ -187,6 +189,10 @@ public class TelecomUtil { } public static boolean isDefaultDialer(Context context) { + if (!DialerCompatUtils.isDefaultDialerCompatible()) { + return false; + } + final boolean result = TextUtils.equals(context.getPackageName(), getTelecomManager(context).getDefaultDialerPackage()); if (result) { |