summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/power/ShutdownThread.java
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2014-11-14 09:44:49 -0800
committerSteve Kondik <steve@cyngn.com>2015-10-25 21:49:31 -0700
commit8451a456fcfa23889c79c0ffe8406dde07c95c54 (patch)
tree754a51378c7ca92bd9d8bd531a0a4d7af27d50d9 /services/core/java/com/android/server/power/ShutdownThread.java
parentcdd6996ead6a1803f64df0e06300c507d868fcca (diff)
downloadframeworks_base-8451a456fcfa23889c79c0ffe8406dde07c95c54.zip
frameworks_base-8451a456fcfa23889c79c0ffe8406dde07c95c54.tar.gz
frameworks_base-8451a456fcfa23889c79c0ffe8406dde07c95c54.tar.bz2
Power menu customizations [1/2]
power reboot screenshot profile switcher airplane mode user switcher bug reports sound modes [mikeioannina]: Modify for CyanogenMod framework: Add advanced reboot options (2 of 2) This commit is an squash of the commits below and re-adds the reboot logic to CM. I took the liberty to rewrite some of the ShutdownThread code because it had some lingering issues present since I originally wrote this for CM7 (!!). Namely, the reboot reason was being changed when the items are pressed instead of when the user presses the positive button. This made some people add workarounds like handling back button presses and whatnot, these are gone now. commit 588464bea40b92b04c4aeee35c47f7becceeed56 Author: Roman Birg <roman@cyngn.com> Date: Thu Jul 10 14:20:42 2014 -0700 advanced reboot: add soft reboot option Adds a "Soft reboot" option which restarts zygote, as requested in JIRA CYAN-3998 Signed-off-by: Roman Birg <roman@cyngn.com> Conflicts: core/res/res/values/cm_arrays.xml core/res/res/values/cm_strings.xml services/java/com/android/server/power/ShutdownThread.java commit 3e7b92551bbf818ace41cd9b9532473ed7d18f2f Author: Veeti Paananen <veeti.paananen@rojekti.fi> Date: Tue Jul 23 16:34:35 2013 +0300 Show advanced reboot if using an insecure lock screen Enables the advanced reboot menu when locked if the selected lock method is insecure (= slide unlock). Conflicts: services/java/com/android/server/power/ShutdownThread.java commit cf42ed3993d5d05c9b2591883fefb6338fbcdd40 Author: DvTonder <david.vantonder@gmail.com> Date: Thu Feb 21 18:20:01 2013 -0500 Framework: Show the Advanced reboot menu only for the primary user Conflicts: services/java/com/android/server/power/ShutdownThread.java commit 08aa6fd643e0359114b86f50053921dd2d86fc50 Author: Ricardo Cerqueira <cyanogenmod@cerqueira.org> Date: Mon Nov 4 03:37:40 2013 +0000 Framework: Add Advanced reboot (2 of 2) This commit responds to a setting in Development settings for including options in the power menu for rebooting into recovery or bootloader. It is defauled to off. When enabled, the Advanced reboot options will only be available once the device is unlocked. Enhance power menu reboot option * Use our old reboot icon * Set correct dialog title & message when rebooting * Move strings to cm_strings * Add back reboot_download string used by samsung devices * Remove Chinese translations, will be handled through crowdin policy: Remove references of Profiles in android.policy. We can't reference the CMSDK within a jar that is exported in the BOOTCLASSPATH, otherwise we end up overriding the 3rd party applications classloaded jar and causing various issues during runtime. Change-Id: Ia0b7950d17bb7450347b57d8a423c44df982b195
Diffstat (limited to 'services/core/java/com/android/server/power/ShutdownThread.java')
-rw-r--r--services/core/java/com/android/server/power/ShutdownThread.java102
1 files changed, 90 insertions, 12 deletions
diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java
index d5ad30c..596828e 100644
--- a/services/core/java/com/android/server/power/ShutdownThread.java
+++ b/services/core/java/com/android/server/power/ShutdownThread.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2013 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@ import android.app.ActivityManagerNative;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.IActivityManager;
+import android.app.KeyguardManager;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.IBluetoothManager;
@@ -44,8 +46,10 @@ import android.os.Vibrator;
import android.os.SystemVibrator;
import android.os.storage.IMountService;
import android.os.storage.IMountShutdownObserver;
+import android.provider.Settings;
import android.system.ErrnoException;
import android.system.Os;
+import android.widget.ListView;
import com.android.internal.telephony.ITelephony;
import com.android.server.pm.PackageManagerService;
@@ -76,6 +80,8 @@ public final class ShutdownThread extends Thread {
private static final int RADIO_STOP_PERCENT = 18;
private static final int MOUNT_SERVICE_STOP_PERCENT = 20;
+ private static final String SOFT_REBOOT = "soft_reboot";
+
// length of vibration before shutting down
private static final int SHUTDOWN_VIBRATE_MS = 500;
@@ -134,6 +140,16 @@ public final class ShutdownThread extends Thread {
shutdownInner(context, confirm);
}
+ private static boolean isAdvancedRebootPossible(final Context context) {
+ KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
+ boolean keyguardLocked = km.inKeyguardRestrictedInputMode() && km.isKeyguardSecure();
+ boolean advancedRebootEnabled = Settings.Secure.getInt(context.getContentResolver(),
+ Settings.Secure.ADVANCED_REBOOT, 0) == 1;
+ boolean isPrimaryUser = UserHandle.getCallingUserId() == UserHandle.USER_OWNER;
+
+ return advancedRebootEnabled && !keyguardLocked && isPrimaryUser;
+ }
+
static void shutdownInner(final Context context, boolean confirm) {
// ensure that only one thread is trying to power down.
// any additional calls are just returned
@@ -145,10 +161,19 @@ public final class ShutdownThread extends Thread {
}
boolean showRebootOption = false;
- String[] defaultActions = context.getResources().getStringArray(
- com.android.internal.R.array.config_globalActionsList);
- for (int i = 0; i < defaultActions.length; i++) {
- if (defaultActions[i].equals("reboot")) {
+
+ String[] actionsArray;
+ String actions = Settings.Global.getStringForUser(context.getContentResolver(),
+ Settings.Global.POWER_MENU_ACTIONS, UserHandle.USER_CURRENT);
+ if (actions == null) {
+ actionsArray = context.getResources().getStringArray(
+ com.android.internal.R.array.config_globalActionsList);
+ } else {
+ actionsArray = actions.split("\\|");
+ }
+
+ for (int i = 0; i < actionsArray.length; i++) {
+ if (actionsArray[i].equals("reboot")) {
showRebootOption = true;
break;
}
@@ -168,23 +193,56 @@ public final class ShutdownThread extends Thread {
if (confirm) {
final CloseDialogReceiver closer = new CloseDialogReceiver(context);
+ final boolean advancedReboot = isAdvancedRebootPossible(context);
+
if (sConfirmDialog != null) {
sConfirmDialog.dismiss();
+ sConfirmDialog = null;
}
- sConfirmDialog = new AlertDialog.Builder(context)
+ AlertDialog.Builder confirmDialogBuilder = new AlertDialog.Builder(context)
.setTitle(mRebootSafeMode
? com.android.internal.R.string.reboot_safemode_title
: showRebootOption
? com.android.internal.R.string.reboot_title
- : com.android.internal.R.string.power_off)
- .setMessage(resourceId)
- .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
+ : com.android.internal.R.string.power_off);
+
+ if (!advancedReboot) {
+ confirmDialogBuilder.setMessage(resourceId);
+ } else {
+ confirmDialogBuilder
+ .setSingleChoiceItems(com.android.internal.R.array.shutdown_reboot_options,
+ 0, null);
+ }
+
+ confirmDialogBuilder.setPositiveButton(com.android.internal.R.string.yes,
+ new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int which) {
+ if (advancedReboot) {
+ boolean softReboot = false;
+ ListView reasonsList = ((AlertDialog)dialog).getListView();
+ int selected = reasonsList.getCheckedItemPosition();
+ if (selected != ListView.INVALID_POSITION) {
+ String actions[] = context.getResources().getStringArray(
+ com.android.internal.R.array.shutdown_reboot_actions);
+ if (selected >= 0 && selected < actions.length) {
+ mRebootReason = actions[selected];
+ if (actions[selected].equals(SOFT_REBOOT)) {
+ doSoftReboot();
+ return;
+ }
+ }
+ }
+
+ mReboot = true;
+ }
beginShutdownSequence(context);
- }
- })
- .setNegativeButton(com.android.internal.R.string.no, null)
- .create();
+ }
+ });
+
+ confirmDialogBuilder.setNegativeButton(com.android.internal.R.string.no, null);
+ sConfirmDialog = confirmDialogBuilder.create();
+
closer.dialog = sConfirmDialog;
sConfirmDialog.setOnDismissListener(closer);
sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
@@ -194,6 +252,18 @@ public final class ShutdownThread extends Thread {
}
}
+ private static void doSoftReboot() {
+ try {
+ final IActivityManager am =
+ ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
+ if (am != null) {
+ am.restart();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "failure trying to perform soft reboot", e);
+ }
+ }
+
private static class CloseDialogReceiver extends BroadcastReceiver
implements DialogInterface.OnDismissListener {
private Context mContext;
@@ -295,6 +365,14 @@ public final class ShutdownThread extends Thread {
pd.setIndeterminate(true);
}
} else {
+ if (mReboot) {
+ pd.setTitle(context.getText(com.android.internal.R.string.reboot_title));
+ pd.setMessage(context.getText(com.android.internal.R.string.reboot_progress));
+ } else {
+ pd.setTitle(context.getText(com.android.internal.R.string.power_off));
+ pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
+ }
+
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
pd.setIndeterminate(true);