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

Commit 83cea920 authored by Danesh Mondegarian's avatar Danesh Mondegarian Committed by Bruno Martins
Browse files

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

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

import com.android.internal.R;
import com.android.internal.accessibility.AccessibilityShortcutController;
@@ -668,6 +669,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    boolean mVolumeAnswerCall;

    boolean mKillAppLongpressBack;
    int mBackKillTimeout;

    int mPointerLocationMode = 0; // guarded by mLock

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

            updateSettings();
        }
@@ -1992,6 +1999,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    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
    public void showGlobalActions() {
        mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
@@ -2356,6 +2374,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {

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

        updateKeyAssignments();

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

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

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

        // First we always handle the home key here, so applications
        // can never break it, although if keyguard is on, we do let
        // it handle it, because that gives us the correct 5 second
@@ -4339,6 +4365,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
            }
            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