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

Commit a9e0830c authored by Daniel Hillenbrand's avatar Daniel Hillenbrand Committed by Gerrit Code Review
Browse files

Merge "Kill App on Long-Press Back Key (framework)" into jellybean

parents 42dff0f3 139a04bd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1321,6 +1321,7 @@
  <java-symbol type="layout" name="screen_title" />
  <java-symbol type="layout" name="screen_title_icons" />
  <java-symbol type="string" name="abbrev_wday_month_day_no_year" />
  <java-symbol type="string" name="app_killed_message" />
  <java-symbol type="string" name="android_upgrading_title" />
  <java-symbol type="string" name="faceunlock_multiple_failures" />
  <java-symbol type="string" name="global_action_power_off" />
+3 −0
Original line number Diff line number Diff line
@@ -3592,6 +3592,9 @@
    <!-- STK setup Call -->
    <string name="SetupCallDefault">Accept call?</string>

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

    <!-- Title for a button to choose the currently selected activity
         as the default in the activity resolver. [CHAR LIMIT=25] -->
    <string name="activity_resolver_use_always">Always</string>
+48 −0
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@
package com.android.internal.policy.impl;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.IUiModeManager;
import android.app.ProgressDialog;
import android.app.SearchManager;
@@ -51,6 +53,7 @@ import android.os.Looper;
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;
@@ -144,12 +147,14 @@ import android.view.KeyCharacterMap.FallbackAction;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.util.List;

/**
 * WindowManagerPolicy implementation for the Android phone UI.  This
@@ -371,6 +376,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mOrientationSensorEnabled = false;
    int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    boolean mHasSoftInput = false;
    int mBackKillTimeout;
    
    int mPointerLocationMode = 0; // guarded by mLock

@@ -827,6 +833,32 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    };

    Runnable mBackLongPress = new Runnable() {
        public void run() {
            try {
                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) {
                        Toast.makeText(mContext, R.string.app_killed_message, Toast.LENGTH_SHORT).show();
                        if (appInfo.pkgList != null && (apps.size() > 0)) {
                            am.forceStopPackage(appInfo.pkgList[0]);
                        } else {
                            Process.killProcess(appInfo.pid);
                        }
                        break;
                    }
                }
            } catch (RemoteException remoteException) {
                // Do nothing; just let it go.
            }
        }
    };

    void showGlobalActionsDialog() {
        if (mGlobalActions == null) {
            mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
@@ -982,8 +1014,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                com.android.internal.R.integer.config_lidKeyboardAccessibility);
        mLidNavigationAccessibility = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_lidNavigationAccessibility);

        mLidControlsSleep = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_lidControlsSleep);

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

        // register for dock events
        IntentFilter filter = new IntentFilter();
        filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
@@ -1854,6 +1891,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
@@ -2010,6 +2051,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
            }
            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