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

Commit baf8d092 authored by David Brown's avatar David Brown
Browse files

Accessibility: optionally allow Power key to end the current call.

This is part 2 of the fix for bug 2364220 "Accessibility improvements for
ending calls".

This change updates the POWER key logic in interceptKeyTq() to check the
value of Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, which allows the
user to specify that the Power button should hang up while in-call,
instead of just turning off the screen.

Bug: 2364220

Change-Id: If6d8e3155f7d60142ab6fd61f0a9db7f0b0d95ab
parent 5f3063e3
Loading
Loading
Loading
Loading
+38 −16
Original line number Diff line number Diff line
@@ -260,11 +260,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    int mLockScreenTimeout;
    boolean mLockScreenTimerActive;

    static final int ENDCALL_HOME = 0x1;
    static final int ENDCALL_SLEEPS = 0x2;
    static final int DEFAULT_ENDCALL_BEHAVIOR = ENDCALL_SLEEPS;
    // Behavior of ENDCALL Button.  (See Settings.System.END_BUTTON_BEHAVIOR.)
    int mEndcallBehavior;

    // Behavior of POWER button while in-call and screen on.
    // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
    int mIncallPowerBehavior;

    int mLandscapeRotation = -1;
    int mPortraitRotation = -1;

@@ -283,6 +285,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.END_BUTTON_BEHAVIOR), false, this);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
@@ -548,7 +552,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        View removeView = null;
        synchronized (mLock) {
            mEndcallBehavior = Settings.System.getInt(resolver,
                    Settings.System.END_BUTTON_BEHAVIOR, DEFAULT_ENDCALL_BEHAVIOR);
                    Settings.System.END_BUTTON_BEHAVIOR,
                    Settings.System.END_BUTTON_BEHAVIOR_DEFAULT);
            mIncallPowerBehavior = Settings.Secure.getInt(resolver,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
            mFancyRotationAnimation = Settings.System.getInt(resolver,
                    "fancy_rotation_anim", 0) != 0 ? 0x80 : 0;
            int accelerometerDefault = Settings.System.getInt(resolver,
@@ -1797,6 +1805,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    || code == KeyEvent.KEYCODE_POWER) {
                if (down) {
                    boolean handled = false;
                    boolean hungUp = false;
                    // key repeats are generated by the window manager, and we don't see them
                    // here, so unless the driver is doing something it shouldn't be, we know
                    // this is the real press event.
@@ -1804,11 +1813,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    if (phoneServ != null) {
                        try {
                            if (code == KeyEvent.KEYCODE_ENDCALL) {
                                handled = phoneServ.endCall();
                            } else if (code == KeyEvent.KEYCODE_POWER && phoneServ.isRinging()) {
                                // Pressing power during incoming call should silence the ringer
                                handled = hungUp = phoneServ.endCall();
                            } else if (code == KeyEvent.KEYCODE_POWER) {
                                if (phoneServ.isRinging()) {
                                    // Pressing Power while there's a ringing incoming
                                    // call should silence the ringer.
                                    phoneServ.silenceRinger();
                                    handled = true;
                                } else if (phoneServ.isOffhook() &&
                                           ((mIncallPowerBehavior
                                             & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP)
                                            != 0)) {
                                    // Otherwise, if "Power button ends call" is enabled,
                                    // the Power button will hang up any current active call.
                                    handled = hungUp = phoneServ.endCall();
                                }
                            }
                        } catch (RemoteException ex) {
                            Log.w(TAG, "ITelephony threw RemoteException" + ex);
@@ -1816,8 +1835,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    } else {
                        Log.w(TAG, "!!! Unable to find ITelephony interface !!!");
                    }
                    // power button should turn off screen in addition to hanging up the phone
                    if ((handled && code != KeyEvent.KEYCODE_POWER) || !screenIsOn) {

                    if (!screenIsOn
                            || (handled && code != KeyEvent.KEYCODE_POWER)
                            || (handled && hungUp && code == KeyEvent.KEYCODE_POWER)) {
                        mShouldTurnOffOnKeyUp = false;
                    } else {
                        // only try to turn off the screen if we didn't already hang up
@@ -1832,8 +1853,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        mShouldTurnOffOnKeyUp = false;
                        boolean gohome, sleeps;
                        if (code == KeyEvent.KEYCODE_ENDCALL) {
                            gohome = (mEndcallBehavior & ENDCALL_HOME) != 0;
                            sleeps = (mEndcallBehavior & ENDCALL_SLEEPS) != 0;
                            gohome = (mEndcallBehavior
                                      & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0;
                            sleeps = (mEndcallBehavior
                                      & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0;
                        } else {
                            gohome = false;
                            sleeps = true;
@@ -2374,4 +2397,3 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return mScreenOn;
    }
}