Skip to content

Commit

Permalink
Reboot options
Browse files Browse the repository at this point in the history
Change-Id: I5e01fe261f079a424c68fccb98230cad13e9614d
  • Loading branch information
imnuts committed Nov 15, 2012
1 parent 9a7debe commit 6bea62d
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 18 deletions.
1 change: 1 addition & 0 deletions core/java/android/view/WindowManagerPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public FakeWindow addFakeWindow(Looper looper,
public void switchKeyboardLayout(int deviceId, int direction);

public void shutdown(boolean confirm);
public void reboot(boolean confirm);
public void rebootSafeMode(boolean confirm);
}

Expand Down
Binary file added core/res/res/drawable-hdpi/ic_lock_reboot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/res/res/drawable-mdpi/ic_lock_reboot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/res/res/drawable-xhdpi/ic_lock_reboot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions core/res/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,21 @@
<item>TUV</item><!-- 8 -->
<item>WXYZ</item><!-- 9 -->
</string-array>

<!-- Defines the shutdown options shown in the reboot dialog. -->
<string-array name="reboot_options" translatable="false">
<item>@string/global_action_reboot</item>
<item>@string/global_action_reboot_recovery</item>
<item>@string/global_action_reboot_bootloader</item>
<item>@string/global_action_reboot_download</item>
</string-array>

<!-- Do not translate. Defines the shutdown actions passed to the kernel.
The first item should be empty for regular reboot. -->
<string-array name="reboot_actions" translatable="false">
<item></item>
<item>recovery</item>
<item>bootloader</item>
<item>download</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions core/res/res/values/public.xml
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@
<public type="drawable" name="ic_dialog_info" id="0x0108009b" />
<public type="drawable" name="ic_menu_sort_alphabetically" id="0x0108009c" />
<public type="drawable" name="ic_menu_sort_by_size" id="0x0108009d" />
<public type="drawable" name="ic_lock_reboot" id="0x0108009e" />

<public type="layout" name="activity_list_item" id="0x01090000" />
<public type="layout" name="expandable_list_content" id="0x01090001" />
Expand Down
27 changes: 27 additions & 0 deletions core/res/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@
power off dialog instead of the global actions menu. -->
<string name="shutdown_confirm_question">Do you want to shut down?</string>

<!-- Reboot Progress Dialog. This is shown if the user chooses to reboot the phone. -->
<string name="reboot_progress">Rebooting\u2026</string>

<!-- Reboot Confirmation Dialog. When the user chooses to reboot the phone, there will
be a confirmation dialog. This is the message. -->
<string name="reboot_confirm" product="tablet">Your tablet will reboot.</string>
<!-- Reboot Confirmation Dialog. When the user chooses to reboot the phone, there will
be a confirmation dialog. This is the message. -->
<string name="reboot_confirm" product="default">Your phone will reboot.</string>

<!-- Title of dialog to confirm rebooting into safe mode. [CHAR LIMIT=50] -->
<string name="reboot_safemode_title">Reboot to safe mode</string>

Expand Down Expand Up @@ -345,7 +355,24 @@

<!-- label for item that turns off power in phone options dialog -->
<string name="global_action_power_off">Power off</string>

<!-- label for item that reboots the phone in phone options dialog -->
<string name="global_action_reboot">Reboot</string>

<!-- label for item that reboots the phone to recovery in phone options dialog -->
<string name="global_action_reboot_recovery">Recovery</string>

<!-- label for item that reboots the phone to download in phone options dialog -->
<string name="global_action_reboot_download">Download</string>

<!-- label for item that reboots the phone to bootloader in phone options dialog -->
<string name="global_action_reboot_bootloader">Bootloader</string>

<!-- Button to reboot the phone, within the Phone Options dialog -->
<string name="reboot_system" product="tablet">Reboot tablet</string>
<string name="reboot_system" product="default">Reboot phone</string>
<!-- Reboot Progress Dialog. This is shown if the user chooses to reboot the phone. -->

<!-- label for item that generates a bug report in the phone options dialog -->
<string name="global_action_bug_report">Bug report</string>

Expand Down
9 changes: 9 additions & 0 deletions core/res/res/values/symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1813,4 +1813,13 @@
<!-- From PinyinIME(!!!) -->
<java-symbol type="string" name="inputMethod" />

<!-- Reboot Options -->
<java-symbol type="array" name="reboot_options" />
<java-symbol type="array" name="reboot_actions" />
<java-symbol type="string" name="reboot_progress" />
<java-symbol type="string" name="reboot_system" />
<java-symbol type="string" name="global_action_reboot" />
<java-symbol type="string" name="global_action_reboot_bootloader" />
<java-symbol type="string" name="global_action_reboot_download" />
<java-symbol type="string" name="global_action_reboot_recovery" />
</resources>
20 changes: 20 additions & 0 deletions policy/src/com/android/internal/policy/impl/GlobalActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,26 @@ public void onPress() {
mWindowManagerFuncs.shutdown(true);
}

public boolean showDuringKeyguard() {
return true;
}

public boolean showBeforeProvisioning() {
return true;
}
});

// next: reboot
mItems.add(
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_reboot,
R.string.global_action_reboot) {

public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
mWindowManagerFuncs.reboot(true);
}

public boolean onLongPress() {
mWindowManagerFuncs.rebootSafeMode(true);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ public void run() {
if (shutdown) {
ShutdownThread.shutdown(mContext, confirm);
} else {
ShutdownThread.reboot(mContext, reason, confirm);
ShutdownThread.reboot(mContext, confirm);
}
}
}
Expand Down
80 changes: 63 additions & 17 deletions services/java/com/android/server/power/ShutdownThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.android.internal.telephony.ITelephony;

import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;

public final class ShutdownThread extends Thread {
Expand Down Expand Up @@ -126,21 +127,62 @@ static void shutdownInner(final Context context, boolean confirm) {

if (confirm) {
final CloseDialogReceiver closer = new CloseDialogReceiver(context);
if (mReboot && !mRebootSafeMode){
sConfirmDialog = new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(com.android.internal.R.string.reboot_system)
.setSingleChoiceItems(com.android.internal.R.array.reboot_options, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which < 0)
return;

String actions[] = context.getResources().getStringArray(com.android.internal.R.array.reboot_actions);

if (actions != null && which < actions.length)
mRebootReason = actions[which];
}
})
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mReboot = true;
beginShutdownSequence(context);
}
})
.setNegativeButton(com.android.internal.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mReboot = false;
sConfirmDialog.cancel();
}
})
.create();
sConfirmDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
public boolean onKey (DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
mReboot = false;
sConfirmDialog.cancel();
}
return true;
}
});
} else {
sConfirmDialog = new AlertDialog.Builder(context)
.setTitle(mRebootSafeMode
? com.android.internal.R.string.reboot_safemode_title
: com.android.internal.R.string.power_off)
.setMessage(resourceId)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
beginShutdownSequence(context);
}
})
.setNegativeButton(com.android.internal.R.string.no, null)
.create();
}

if (sConfirmDialog != null) {
sConfirmDialog.dismiss();
}
sConfirmDialog = new AlertDialog.Builder(context)
.setTitle(mRebootSafeMode
? com.android.internal.R.string.reboot_safemode_title
: com.android.internal.R.string.power_off)
.setMessage(resourceId)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
beginShutdownSequence(context);
}
})
.setNegativeButton(com.android.internal.R.string.no, null)
.create();

closer.dialog = sConfirmDialog;
sConfirmDialog.setOnDismissListener(closer);
sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
Expand Down Expand Up @@ -180,10 +222,10 @@ public void onDismiss(DialogInterface unused) {
* @param reason code to pass to the kernel (e.g. "recovery"), or null.
* @param confirm true if user confirmation is needed before shutting down.
*/
public static void reboot(final Context context, String reason, boolean confirm) {
public static void reboot(final Context context, boolean confirm) {
mReboot = true;
mRebootSafeMode = false;
mRebootReason = reason;
mRebootReason = null;
shutdownInner(context, confirm);
}

Expand Down Expand Up @@ -213,9 +255,13 @@ private static void beginShutdownSequence(Context context) {
// throw up an indeterminate system dialog to indicate radio is
// shutting down.
ProgressDialog pd = new ProgressDialog(context);
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);
if (mReboot) {
pd.setTitle(context.getText(com.android.internal.R.string.reboot_system));
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.setIndeterminate(true);
pd.setCancelable(false);
pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);

Expand Down
6 changes: 6 additions & 0 deletions services/java/com/android/server/wm/WindowManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5417,6 +5417,12 @@ public void shutdown(boolean confirm) {
ShutdownThread.shutdown(mContext, confirm);
}

// Called by window manager policy. Not exposed externally.
@Override
public void reboot(boolean confirm) {
ShutdownThread.reboot(mContext, confirm);
}

// Called by window manager policy. Not exposed externally.
@Override
public void rebootSafeMode(boolean confirm) {
Expand Down

0 comments on commit 6bea62d

Please sign in to comment.