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

Commit 43a65667 authored by Danesh Mondegarian's avatar Danesh Mondegarian Committed by Michael Bestas
Browse files

Framework: Forward port Long press back to kill app (2/2)

Change-Id: If3ed27e8408cdf383653c7d18988112c13f8bcea
parent af482649
Loading
Loading
Loading
Loading
+32 −0
Original line number Original line Diff line number Diff line
@@ -233,6 +233,7 @@ import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.AnimationUtils;
import android.view.autofill.AutofillManagerInternal;
import android.view.autofill.AutofillManagerInternal;
import android.view.inputmethod.InputMethodManagerInternal;
import android.view.inputmethod.InputMethodManagerInternal;
import android.widget.Toast;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
@@ -620,6 +621,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {


    boolean mVolumeAnswerCall;
    boolean mVolumeAnswerCall;


    boolean mKillAppLongpressBack;
    int mBackKillTimeout;

    int mPointerLocationMode = 0; // guarded by mLock
    int mPointerLocationMode = 0; // guarded by mLock


    // The last window we were told about in focusChanged.
    // The last window we were told about in focusChanged.
@@ -1112,6 +1116,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.VOLUME_ANSWER_CALL), false, this,
                    LineageSettings.System.VOLUME_ANSWER_CALL), false, this,
                    UserHandle.USER_ALL);
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.Secure.getUriFor(
                    LineageSettings.Secure.KILL_APP_LONGPRESS_BACK), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
            updateSettings();
        }
        }


@@ -1837,6 +1844,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {


    private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
    private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();


    Runnable mBackLongPress = new Runnable() {
        public void run() {
            if (ActionUtils.killForegroundApp(mContext, mCurrentUserId)) {
                performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
                Toast.makeText(mContext,
                        org.lineageos.platform.internal.R.string.app_killed_message,
                        Toast.LENGTH_SHORT).show();
            }
        }
    };

    @Override
    @Override
    public void showGlobalActions() {
    public void showGlobalActions() {
        mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
        mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
@@ -2198,6 +2216,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {


        mDeviceHardwareKeys = mContext.getResources().getInteger(
        mDeviceHardwareKeys = mContext.getResources().getInteger(
                org.lineageos.platform.internal.R.integer.config_deviceHardwareKeys);
                org.lineageos.platform.internal.R.integer.config_deviceHardwareKeys);
        mBackKillTimeout = mContext.getResources().getInteger(
                org.lineageos.platform.internal.R.integer.config_backKillTimeout);


        updateKeyAssignments();
        updateKeyAssignments();


@@ -2622,6 +2642,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mVolumeAnswerCall = (LineageSettings.System.getIntForUser(resolver,
            mVolumeAnswerCall = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.VOLUME_ANSWER_CALL, 0, UserHandle.USER_CURRENT) == 1)
                    LineageSettings.System.VOLUME_ANSWER_CALL, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);
            mKillAppLongpressBack = LineageSettings.Secure.getInt(
                    resolver, LineageSettings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 1;


            // Configure wake gesture.
            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -3726,6 +3748,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mPendingCapsLockToggle = false;
            mPendingCapsLockToggle = false;
        }
        }


        if (keyCode == KeyEvent.KEYCODE_BACK && !down) {
            mHandler.removeCallbacks(mBackLongPress);
        }

        // First we always handle the home key here, so applications
        // First we always handle the home key here, so applications
        // can never break it, although if keyguard is on, we do let
        // can never break it, although if keyguard is on, we do let
        // it handle it, because that gives us the correct 5 second
        // it handle it, because that gives us the correct 5 second
@@ -4099,6 +4125,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
                launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
            }
            }
            return -1;
            return -1;
        } else if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mKillAppLongpressBack) {
                if (down && repeatCount == 0) {
                    mHandler.postDelayed(mBackLongPress, mBackKillTimeout);
                }
            }
        }
        }


        // Shortcuts are invoked through Search+key, so intercept those here
        // Shortcuts are invoked through Search+key, so intercept those here