-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpower_menu.c
93 lines (85 loc) · 1.88 KB
/
power_menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <string.h>
#include <sys/reboot.h>
#include <unistd.h>
#include "recovery.h"
#include "recovery_ui.h"
#include "rz_funcs.h"
void
reboot_fn(char *action)
{
if (strcmp(action, "android") == 0
|| strcmp(action, "recovery") == 0
|| strcmp(action, "bootloader") == 0 || strcmp(action, "poweroff") == 0)
{
if (strcmp(action, "poweroff") != 0)
{
ui_print("\n-- Rebooting into %s --\n", action);
//write_files();
sync();
if (strcmp(action, "android") == 0)
action = NULL;
//if (access("/cache/recovery/command",F_OK) != -1) __system("rm /cache/recovery/command");
//if (access("/cache/update.zip",F_OK) != -1) __system("rm /cache/update.zip");
if (__reboot
(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_RESTART2, action))
{
reboot(RB_AUTOBOOT);
}
}
else
{
ui_print("\n-- Shutting down --\n");
//write_files();
sync();
if (__reboot
(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_POWER_OFF, NULL))
{
reboot(RB_AUTOBOOT);
}
}
}
}
void
show_power_menu()
{
static char *headers[] = {
"Power Options",
"",
NULL
};
static char *items[] = {
"Reboot android",
"Reboot recovery",
"Bootloader",
"Power off",
NULL
};
#define RB_ANDROID 0
#define RB_RECOVERY 1
#define RB_BOOTLOADER 2
#define RB_POWEROFF 3
int chosen_item = -1;
while (chosen_item != ITEM_BACK)
{
chosen_item =
get_menu_selection(headers, items, 0,
chosen_item < 0 ? 0 : chosen_item);
switch (chosen_item)
{
case RB_ANDROID:
reboot_fn("android");
break;
case RB_RECOVERY:
reboot_fn("recovery");
break;
case RB_BOOTLOADER:
reboot_fn("bootloader");
break;
case RB_POWEROFF:
reboot_fn("poweroff");
break;
}
}
}