diff options
author | nebkat <nebkat@gmail.com> | 2011-12-27 17:40:39 +0000 |
---|---|---|
committer | nebkat <nebkat@gmail.com> | 2011-12-27 19:40:07 +0000 |
commit | a6c200bee8cde400352b0c53ce42fb5dd308eb73 (patch) | |
tree | b36e228650d30a8a440e0782f876336cc9b13a2b /policy | |
parent | f8e2430be2d6b3e88afd7190f6712f3bc1df0cbf (diff) | |
download | frameworks_base-a6c200bee8cde400352b0c53ce42fb5dd308eb73.zip frameworks_base-a6c200bee8cde400352b0c53ce42fb5dd308eb73.tar.gz frameworks_base-a6c200bee8cde400352b0c53ce42fb5dd308eb73.tar.bz2 |
Kill App on Long-Press Back Key (framework)
Change-Id: Ib78fff9e32d95a0a112ddd9274b79b3a3aa626b9
Diffstat (limited to 'policy')
-rwxr-xr-x | policy/src/com/android/internal/policy/impl/PhoneWindowManager.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 0b223c1..9511a62 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -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 |