Loading core/java/android/provider/Settings.java +6 −0 Original line number Diff line number Diff line Loading @@ -6122,6 +6122,12 @@ public final class Settings { */ 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 * @hide Loading core/res/res/values/cm_strings.xml 0 → 100644 +23 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2012-2014 The CyanogenMod Project Copyright (c) 2013, The Linux Foundation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Long-press back kill application --> <string name="app_killed_message">Application killed</string> </resources> core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -2564,4 +2564,8 @@ <string-array translatable="false" name="config_defaultPinnerServiceFiles"> </string-array> <!-- 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> core/res/res/values/symbols.xml +6 −0 Original line number Diff line number Diff line Loading @@ -2625,4 +2625,10 @@ <!-- Gesture Sensor --> <java-symbol type="bool" name="config_enableGestureService" /> <!-- 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> services/core/java/com/android/server/policy/PhoneWindowManager.java +62 −0 Original line number Diff line number Diff line Loading @@ -42,7 +42,9 @@ import android.app.ActivityManager; import android.app.ActivityManager.StackId; import android.app.ActivityManagerInternal; import android.app.ActivityManagerInternal.SleepToken; import android.app.ActivityManager.RunningAppProcessInfo; import android.app.ActivityManagerNative; import android.app.IActivityManager; import android.app.AppOpsManager; import android.app.IUiModeManager; import android.app.ProgressDialog; Loading Loading @@ -141,6 +143,8 @@ import android.view.accessibility.AccessibilityManager; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.widget.Toast; import com.android.internal.R; import com.android.internal.logging.MetricsLogger; import com.android.internal.os.DeviceKeyHandler; Loading Loading @@ -499,6 +503,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mHasSoftInput = false; boolean mTranslucentDecorEnabled = true; boolean mUseTvRouting; int mBackKillTimeout; int mDeviceHardwareKeys; Loading Loading @@ -1445,6 +1450,50 @@ public class PhoneWindowManager implements WindowManagerPolicy { 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() { sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); if (mGlobalActions == null) { Loading Loading @@ -1749,6 +1798,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { mDeviceHardwareKeys = mContext.getResources().getInteger( com.android.internal.R.integer.config_deviceHardwareKeys); mBackKillTimeout = mContext.getResources().getInteger( com.android.internal.R.integer.config_backKillTimeout); updateKeyAssignments(); Loading Loading @@ -3198,6 +3249,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { mPendingCapsLockToggle = false; } 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 Loading Loading @@ -3558,6 +3613,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); } 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 Loading Loading
core/java/android/provider/Settings.java +6 −0 Original line number Diff line number Diff line Loading @@ -6122,6 +6122,12 @@ public final class Settings { */ 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 * @hide Loading
core/res/res/values/cm_strings.xml 0 → 100644 +23 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2012-2014 The CyanogenMod Project Copyright (c) 2013, The Linux Foundation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Long-press back kill application --> <string name="app_killed_message">Application killed</string> </resources>
core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -2564,4 +2564,8 @@ <string-array translatable="false" name="config_defaultPinnerServiceFiles"> </string-array> <!-- 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>
core/res/res/values/symbols.xml +6 −0 Original line number Diff line number Diff line Loading @@ -2625,4 +2625,10 @@ <!-- Gesture Sensor --> <java-symbol type="bool" name="config_enableGestureService" /> <!-- 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>
services/core/java/com/android/server/policy/PhoneWindowManager.java +62 −0 Original line number Diff line number Diff line Loading @@ -42,7 +42,9 @@ import android.app.ActivityManager; import android.app.ActivityManager.StackId; import android.app.ActivityManagerInternal; import android.app.ActivityManagerInternal.SleepToken; import android.app.ActivityManager.RunningAppProcessInfo; import android.app.ActivityManagerNative; import android.app.IActivityManager; import android.app.AppOpsManager; import android.app.IUiModeManager; import android.app.ProgressDialog; Loading Loading @@ -141,6 +143,8 @@ import android.view.accessibility.AccessibilityManager; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.widget.Toast; import com.android.internal.R; import com.android.internal.logging.MetricsLogger; import com.android.internal.os.DeviceKeyHandler; Loading Loading @@ -499,6 +503,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mHasSoftInput = false; boolean mTranslucentDecorEnabled = true; boolean mUseTvRouting; int mBackKillTimeout; int mDeviceHardwareKeys; Loading Loading @@ -1445,6 +1450,50 @@ public class PhoneWindowManager implements WindowManagerPolicy { 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() { sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); if (mGlobalActions == null) { Loading Loading @@ -1749,6 +1798,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { mDeviceHardwareKeys = mContext.getResources().getInteger( com.android.internal.R.integer.config_deviceHardwareKeys); mBackKillTimeout = mContext.getResources().getInteger( com.android.internal.R.integer.config_backKillTimeout); updateKeyAssignments(); Loading Loading @@ -3198,6 +3249,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { mPendingCapsLockToggle = false; } 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 Loading Loading @@ -3558,6 +3613,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); } 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 Loading