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

Commit 8c5ef198 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin Committed by Gerrit Code Review
Browse files

Adds ability to answer call with hardware HOME button (preparation to winter time)

Change-Id: Ic11449acf87c6b4d932142b74158af7441658b3d

Patch set 1 : Upload the change
Patch set 2 : Only change the real Author
Patch set 3 : Bugfix:
              Add register for the ContentObserver (Settings.Secure.RING_HOME_BUTTON_BEHAVIOR) in PhoneWindowManager,
              and correcting the logging functions and deleting some unneeded comments
parent 3512a8b9
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -4824,6 +4824,36 @@ public final class Settings {
        public static final int INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT =
                INCALL_POWER_BUTTON_BEHAVIOR_SCREEN_OFF;

        /**
         * What happens when the user presses the Home button when the
         * phone is ringing.<br/>
         * <b>Values:</b><br/>
         * 1 - Nothing happens. (Default behavior)<br/>
         * 2 - The Home button answer the current call.<br/>
         *
         * @hide
         */
        public static final String RING_HOME_BUTTON_BEHAVIOR = "ring_home_button_behavior";

        /**
         * RING_HOME_BUTTON_BEHAVIOR value for "do nothing".
         * @hide
         */
        public static final int RING_HOME_BUTTON_BEHAVIOR_DO_NOTHING = 0x1;

        /**
         * RING_HOME_BUTTON_BEHAVIOR value for "answer".
         * @hide
         */
        public static final int RING_HOME_BUTTON_BEHAVIOR_ANSWER = 0x2;

        /**
         * RING_HOME_BUTTON_BEHAVIOR default value.
         * @hide
         */
        public static final int RING_HOME_BUTTON_BEHAVIOR_DEFAULT =
                RING_HOME_BUTTON_BEHAVIOR_DO_NOTHING;

        /**
         * The current night mode that has been selected by the user.  Owned
         * and controlled by UiModeManagerService.  Constants are as per
+23 −9
Original line number Diff line number Diff line
@@ -515,6 +515,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    Display mDisplay;

    // Behavior of HOME button during incomming call ring.
    // (See Settings.Secure.RING_HOME_BUTTON_BEHAVIOR.)
    int mRingHomeBehavior;

    int mLandscapeRotation = 0;  // default landscape rotation
    int mSeascapeRotation = 0;   // "other" landscape rotation, 180 degrees from mLandscapeRotation
    int mPortraitRotation = 0;   // default portrait rotation
@@ -596,6 +600,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.RING_HOME_BUTTON_BEHAVIOR), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
@@ -1313,6 +1320,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
                    UserHandle.USER_CURRENT);
            mRingHomeBehavior = Settings.Secure.getIntForUser(resolver,
                    Settings.Secure.RING_HOME_BUTTON_BEHAVIOR,
                    Settings.Secure.RING_HOME_BUTTON_BEHAVIOR_DEFAULT,
                    UserHandle.USER_CURRENT);
            mVolumeWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLUME_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1);
            mVolBtnMusicControls = (Settings.System.getIntForUser(resolver,
@@ -2168,24 +2179,26 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    }
                    mHomePressed = false;
                    if (!canceled) {
                        // If an incoming call is ringing, HOME is totally disabled.
                        // (The user is already on the InCallScreen at this point,
                        // and his ONLY options are to answer or reject the call.)
                        boolean incomingRinging = false;
                        try {
                            ITelephony telephonyService = getTelephonyService();
                            if (telephonyService != null) {
                                incomingRinging = telephonyService.isRinging();
                            }
                        } catch (RemoteException ex) {
                            Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
                        }

                            if (incomingRinging) {
                                if ((mRingHomeBehavior
                                        & Settings.Secure.RING_HOME_BUTTON_BEHAVIOR_ANSWER) != 0) {
                                    Log.i(TAG, "Answering with HOME button.");
                                    telephonyService.answerRingingCall();
                                } else {
                                    Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
                                }
                            } else {
                                launchHomeFromHotKey();
                            }
                        } catch (RemoteException ex) {
                            Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
                        }
                    } else {
                        Log.i(TAG, "Ignoring HOME; event canceled.");
                    }
@@ -5147,6 +5160,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
        pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
                pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
                pw.print(" mRingHomeBehavior="); pw.print(mRingHomeBehavior);
                pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
        pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
                pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);