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

Commit 6f63ced9 authored by Danesh Mondegarian's avatar Danesh Mondegarian Committed by Steve Kondik
Browse files

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

Change-Id: Ia88d8a2753e203afb8d6117a643c33127f991c4a
parent 277dd1c1
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -5953,6 +5953,12 @@ public final class Settings {
         */
         */
        public static final String SCREENSAVER_DEFAULT_COMPONENT = "screensaver_default_component";
        public static final String SCREENSAVER_DEFAULT_COMPONENT = "screensaver_default_component";


        /**
         * 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 default NFC payment component
         * The default NFC payment component
         * @hide
         * @hide
+3 −0
Original line number Original line Diff line number Diff line
@@ -83,4 +83,7 @@
    <!-- Reboot Progress Dialog. This is shown if the user chooses to reboot the phone. -->
    <!-- Reboot Progress Dialog. This is shown if the user chooses to reboot the phone. -->
    <string name="reboot_progress">Rebooting\u2026</string>
    <string name="reboot_progress">Rebooting\u2026</string>


    <!-- Long-press back kill application -->
    <string name="app_killed_message">Application killed</string>

</resources>
</resources>
+5 −0
Original line number Original line Diff line number Diff line
@@ -2403,4 +2403,9 @@
    <bool name="config_proximityCheckOnWake">false</bool>
    <bool name="config_proximityCheckOnWake">false</bool>
    <integer name="config_proximityCheckTimeout">250</integer>
    <integer name="config_proximityCheckTimeout">250</integer>
    <bool name="config_proximityCheckOnWakeEnabledByDefault">false</bool>
    <bool name="config_proximityCheckOnWakeEnabledByDefault">false</bool>

    <!-- Timeout in MS for how long you have to long-press the back key to
         kill the foreground app. -->
    <integer name="config_backKillTimeout">2000</integer>

</resources>
</resources>
+7 −0
Original line number Original line Diff line number Diff line
@@ -2410,4 +2410,11 @@
  <java-symbol type="dimen" name="edge_gesture_trigger_distance" />
  <java-symbol type="dimen" name="edge_gesture_trigger_distance" />
  <java-symbol type="dimen" name="edge_gesture_perpendicular_distance" />
  <java-symbol type="dimen" name="edge_gesture_perpendicular_distance" />
  <java-symbol type="dimen" name="edge_gesture_trigger_thickness" />
  <java-symbol type="dimen" name="edge_gesture_trigger_thickness" />

  <!-- Developer settings - Kill app back press -->
  <java-symbol type="string" name="app_killed_message" />

  <!-- Config.xml entries -->
  <java-symbol type="integer" name="config_backKillTimeout" />

</resources>
</resources>
+62 −0
Original line number Original line Diff line number Diff line
@@ -19,7 +19,9 @@ package com.android.server.policy;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerInternal.SleepToken;
import android.app.ActivityManagerInternal.SleepToken;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManagerNative;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.IUiModeManager;
import android.app.IUiModeManager;
import android.app.ProgressDialog;
import android.app.ProgressDialog;
@@ -116,6 +118,8 @@ import android.view.accessibility.AccessibilityManager;
import android.view.animation.Animation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.os.DeviceKeyHandler;
import com.android.internal.os.DeviceKeyHandler;
import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IKeyguardService;
@@ -455,6 +459,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mHasSoftInput = false;
    boolean mHasSoftInput = false;
    boolean mTranslucentDecorEnabled = true;
    boolean mTranslucentDecorEnabled = true;
    boolean mUseTvRouting;
    boolean mUseTvRouting;
    int mBackKillTimeout;


    int mDeviceHardwareKeys;
    int mDeviceHardwareKeys;


@@ -1359,6 +1364,50 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
        mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
    }
    }


    Runnable mBackLongPress = new Runnable() {
        public void run() {
            try {
                final Intent intent = new Intent(Intent.ACTION_MAIN);
                String defaultHomePackage = "com.android.launcher";
                intent.addCategory(Intent.CATEGORY_HOME);
                final ResolveInfo res = mContext.getPackageManager().resolveActivity(intent, 0);
                if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
                    defaultHomePackage = res.activityInfo.packageName;
                }
                boolean targetKilled = false;
                IActivityManager am = ActivityManagerNative.getDefault();
                List<RunningAppProcessInfo> apps = am.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) {
                        if (appInfo.pkgList != null && (appInfo.pkgList.length > 0)) {
                            for (String pkg : appInfo.pkgList) {
                                if (!pkg.equals("com.android.systemui") && !pkg.equals(defaultHomePackage)) {
                                    am.forceStopPackage(pkg, UserHandle.USER_CURRENT);
                                    targetKilled = true;
                                    break;
                                }
                            }
                        } else {
                            Process.killProcess(appInfo.pid);
                            targetKilled = true;
                        }
                    }
                    if (targetKilled) {
                        performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
                        Toast.makeText(mContext, R.string.app_killed_message, Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            } catch (RemoteException remoteException) {
                // Do nothing; just let it go.
            }
        }
    };

    void showGlobalActionsInternal() {
    void showGlobalActionsInternal() {
        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
        if (mGlobalActions == null) {
        if (mGlobalActions == null) {
@@ -1638,6 +1687,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {


        mDeviceHardwareKeys = mContext.getResources().getInteger(
        mDeviceHardwareKeys = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_deviceHardwareKeys);
                com.android.internal.R.integer.config_deviceHardwareKeys);
        mBackKillTimeout = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_backKillTimeout);


        updateKeyAssignments();
        updateKeyAssignments();


@@ -2996,6 +3047,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mPendingMetaAction = false;
            mPendingMetaAction = 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
@@ -3300,6 +3355,13 @@ 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 (Settings.Secure.getInt(mContext.getContentResolver(),
                    Settings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 1) {
                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