summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2015-12-21 11:58:22 -0800
committerBrandon Maxwell <maxwelb@google.com>2015-12-21 15:41:58 -0800
commitf8f8b9c8166679709cbf5401d82921cecc07f8d0 (patch)
tree94ecf4c9b26c6a8ae91c5840f423173ea0d54034
parent1746cf5b5f90c092e86ebf199ce248af0b3a495b (diff)
Backporting calls to TelecomManager#silenceRinger
The method was a system API pre-M, but a public method in M. Added a compat method which checks if the method is callable. In the event that the method can't be called, the compat method is a noop - this matches the functionality from the L version of the phone. Bug=25776171 Change-Id: I4a9fc19bb2bf2749d697da2b8643601ebd1eb4a8
-rw-r--r--src/com/android/dialer/compat/telecom/TelecomManagerCompat.java14
-rw-r--r--src/com/android/dialer/util/TelecomUtil.java2
2 files changed, 15 insertions, 1 deletions
diff --git a/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java b/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java
index 05055a45e..845f378e3 100644
--- a/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java
+++ b/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java
@@ -82,4 +82,18 @@ public class TelecomManagerCompat {
}
return PhoneNumberUtils.isVoiceMailNumber(number);
}
+
+ /**
+ * Silences the ringer if a ringing call exists. Noop if {@link TelecomManager#silenceRinger()}
+ * is unavailable.
+ *
+ * @param telecomManager the {@link TelecomManager} to use to silence the ringer
+ * @throws NullPointerException if telecomManager is null
+ */
+ public static void silenceRinger(TelecomManager telecomManager) {
+ if (CompatUtils.isMarshmallowCompatible() || CompatUtils
+ .isMethodAvailable("android.telecom.TelecomManager", "silenceRinger")) {
+ telecomManager.silenceRinger();
+ }
+ }
}
diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java
index bc6b32d6e..01a379438 100644
--- a/src/com/android/dialer/util/TelecomUtil.java
+++ b/src/com/android/dialer/util/TelecomUtil.java
@@ -62,7 +62,7 @@ public class TelecomUtil {
public static void silenceRinger(Context context) {
if (hasModifyPhoneStatePermission(context)) {
try {
- getTelecomManager(context).silenceRinger();
+ TelecomManagerCompat.silenceRinger(getTelecomManager(context));
} catch (SecurityException e) {
// Just in case
Log.w(TAG, "TelecomManager.silenceRinger called without permission.");