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

Commit a6c200be authored by nebkat's avatar nebkat
Browse files

Kill App on Long-Press Back Key (framework)

Change-Id: Ib78fff9e32d95a0a112ddd9274b79b3a3aa626b9
parent f8e2430b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4069,6 +4069,12 @@ public final class Settings {
         */
        public static final String ANR_SHOW_BACKGROUND = "anr_show_background";

        /**
         * Whether to allow killing of the foreground app by long-pressing the Back button
         * @hide
         */
        public static final String KILL_APP_LONGPRESS_BACK = "kill_app_longpress_back";

        /**
         * The {@link ComponentName} string of the service to be used as the voice recognition
         * service.
+36 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.policy.impl;

import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.IActivityManager;
import android.app.IUiModeManager;
import android.app.ProgressDialog;
@@ -48,6 +49,7 @@ import android.os.LocalPowerManager;
import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -142,6 +144,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * WindowManagerPolicy implementation for the Android phone UI.  This
@@ -660,6 +663,28 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    };

    Runnable mBackLongPress = new Runnable() {
        public void run() {
            try {
                IActivityManager mgr = ActivityManagerNative.getDefault();
                List<RunningAppProcessInfo> apps = mgr.getRunningAppProcesses();
                for (RunningAppProcessInfo appInfo : apps) {
                    int uid = appInfo.uid;
                    // Make sure it's a foreground user application (not system,
                    // root, phone, etc.)
                    if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID
                            && appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                        // Kill the entire pid
                        Process.killProcess(appInfo.pid);
                        break;
                    }
                }
            } catch (RemoteException remoteException) {
                // Do nothing; just let it go.
            }
        }
    };

    void showGlobalActionsDialog() {
        if (mGlobalActions == null) {
            mGlobalActions = new GlobalActions(mContext);
@@ -1520,6 +1545,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        }

        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
@@ -1628,6 +1657,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
            }
            return -1;
        } else if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (Settings.Secure.getInt(mContext.getContentResolver(),
                    Settings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 1) {
                if (down && repeatCount == 0) {
                    mHandler.postDelayed(mBackLongPress, 2000);
                }
            }
        }

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