Skip to content

Commit

Permalink
Merge "Kill App on Long-Press Back Key (framework)" into ics
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperb1iss authored and Gerrit Code Review committed Dec 29, 2011
2 parents 5b5e1cc + a6c200b commit 5e81d78
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
@@ -4069,6 +4069,12 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
*/
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.
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

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.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.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 void run() {
}
};

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 long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
}
}

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 long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
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

0 comments on commit 5e81d78

Please sign in to comment.