forked from raidzero/RZrecovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_menu.c
executable file
·189 lines (161 loc) · 4.29 KB
/
options_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <stdlib.h>
#include <stdio.h>
#include "recovery_lib.h"
#include "roots.h"
#include "recovery_ui.h"
void disable_OTA() {
ui_print("\nDisabling OTA updates in ROM...");
ensure_root_path_mounted("SYSTEM:");
remove("/system/etc/security/otacerts.zip");
remove("/cache/signed-*.*");
ui_print("\nOTA-updates disabled.\n");
ensure_root_path_unmounted("SYSTEM:");
return;
}
void show_battstat() {
FILE* fs = fopen("/sys/class/power_supply/battery/status","r");
char* bstat = calloc(13,sizeof(char));
fgets(bstat, 13, fs);
FILE* fc = fopen("/sys/class/power_supply/battery/capacity","r");
char* bcap = calloc(4,sizeof(char));
fgets(bcap, 4, fc);
FILE* ft = fopen("/sys/class/power_supply/battery/temp","r");
char* btemp = calloc(3,sizeof(char));
fgets(btemp, 3, ft);
btemp = strcat(btemp," C");
int caplen = strlen(bcap);
if( bcap[caplen-1] == '\n' ) {
bcap[caplen-1] = 0;
}
bcap = strcat(bcap,"%%");
ui_print("\n");
ui_print("\nBattery Status: ");
ui_print(bstat);
ui_print("Charge Level: ");
ui_print(bcap);
ui_print("\nTemperature: ");
ui_print(btemp);
fclose(ft);
fclose(fc);
fclose(fs);
}
void keylight() {
char brightness[3];
int bi;
FILE* flr = fopen("/sys/class/leds/keyboard-backlight/brightness","r");
fgets(brightness, 3, flr);
bi = atoi(brightness);
FILE* flw = fopen("/sys/class/leds/keyboard-backlight/brightness","w");
if (bi == 0) {
fputs("255",flw);
fputs("\n",flw);
} else {
fputs("0",flw);
fputs("\n",flw);
}
fclose(flr);
fclose(flw);
}
void flashlight() {
char brightness[3];
int bi;
FILE* flr = fopen("/sys/class/leds/spotlight/brightness","r");
fgets(brightness, 3, flr);
bi = atoi(brightness);
FILE* flw = fopen("/sys/class/leds/spotlight/brightness","w");
if (bi == 0) {
fputs("255",flw);
fputs("\n",flw);
} else {
fputs("0",flw);
fputs("\n",flw);
}
fclose(flr);
fclose(flw);
}
void fix_permissions() {
char* argv[] = { "/sbin/fix_permissions",
NULL };
char* envp[] = { NULL };
int status = runve("/sbin/fix_permissions",argv,envp,1);
return;
}
void root_menu(int confirm) {
if (confirm) {
static char** title_headers = NULL;
if (title_headers == NULL) {
char* headers[] = { "ROOT installed ROM?",
" ",
"Rooting without the superuser app installed",
"does nothing. Please install the superuser app",
"from the market! (by ChainsDD)",
" ",
NULL };
title_headers = prepend_title(headers);
}
char* items[] = { " No",
" OK, give me root!",
NULL };
int chosen_item = get_menu_selection(title_headers, items, 1, 0);
if (chosen_item != 1) {
return;
}
}
char* argv[] = { "/sbin/actroot",
NULL };
char* envp[] = { NULL };
ensure_root_path_mounted("SYSTEM:");
remove("/system/recovery-from-boot.p");
int status = runve("/sbin/actroot",argv,envp,1);
ensure_root_path_unmounted("SYSTEM:");
return;
}
void show_options_menu()
{
static char* headers[] = { "Extras",
"or press DEL or POWER to return",
"",
NULL };
char* items[] = { "Custom Colors",
"Disable OTA Update Downloads in ROM",
"Show Battery Status",
"Toggle Flashlight",
"Activate Root Access in ROM",
"Recovery Overclocking",
"Toggle keyboard light",
NULL };
#define COLORS 0
#define OTA 1
#define BATT 2
#define FLASHLIGHT 3
#define ROOT_MENU 4
#define OVERCLOCK 5
#define KEYLIGHT 6
int chosen_item = -1;
while(chosen_item!=ITEM_BACK) {
chosen_item = get_menu_selection(headers,items,1,chosen_item<0?0:chosen_item);
switch (chosen_item) {
case COLORS:
show_colors_menu();
return;
case OTA:
disable_OTA();
break;
case BATT:
show_battstat();
break;
case FLASHLIGHT:
flashlight();
break;
case ROOT_MENU:
root_menu(ui_text_visible());
break;
case OVERCLOCK:
show_overclock_menu();
break;
case KEYLIGHT:
keylight();
break;
}
}
}