Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8f8b9c8 authored by Brandon Maxwell's avatar Brandon Maxwell
Browse files

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
parent 1746cf5b
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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.");