forked from raidzero/RZrecovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extras_menu.c
175 lines (153 loc) · 3.27 KB
/
extras_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
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include "recovery.h"
#include "roots.h"
#include "recovery_ui.h"
#include "plugins_menu.h"
void show_battstat ()
{
FILE *fs = fopen ("/sys/class/power_supply/battery/status", "r");
char *bstat = calloc (14, sizeof (char));
fgets (bstat, 14, fs);
FILE *fc = fopen ("/sys/class/power_supply/battery/capacity", "r");
char *bcap = calloc (14, sizeof (char));
fgets (bcap, 4, fc);
int noTemp;
int caplen = strlen (bcap);
if (bcap[caplen - 1] == '\n')
{
bcap[caplen - 1] = 0;
}
bcap = strcat (bcap, "%");
ui_print ("\nBattery Status: ");
ui_print ("%s\n", bstat);
char *cmp;
if (!(cmp = strstr (bstat, "Unknown")))
{
ui_print ("Charge Level: ");
ui_print ("%s\n", bcap);
if (!access ("/sys/class/power_supply/battery/temp", F_OK)) {
ui_print ("Temperature: ");
FILE *ft = fopen ("/sys/class/power_supply/battery/temp", "r");
char *btemp = calloc (13, sizeof (char));
fgets (btemp, 3, ft);
btemp = strcat (btemp, " C");
ui_print ("%s\n", btemp);
fclose(ft);
}
}
fclose (fc);
fclose (fs);
}
void
flashlight ()
{
if (access ("/sys/class/leds/spotlight/brightness", F_OK))
{
ui_print_n ("\nFlashlight not found.\n");
return;
}
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);
}
int plugins_present(const char* sdpath)
{
DIR * dir;
struct dirent *de;
int present;
int total = 0;
ensure_path_mounted ("/sdcard");
if (access(sdpath, F_OK) != -1)
{
dir = opendir (sdpath);
printf("Dir opened.\n");
while ((de = readdir (dir)) != NULL)
{
if (strcmp(de->d_name + strlen (de->d_name) - 4, ".tar") == 0 || strcmp(de->d_name + strlen (de->d_name) - 4, ".tgz") == 0)
{
total++;
}
}
if (closedir(dir) > 0)
{
printf("Failed to close plugin directory.\n");
}
if (total > 0)
{
printf("Plugins found.\n");
return 1;
}
else
{
printf("No plugins found.\n");
return 0;
}
}
else
{
printf("Plugins directory not present.\n");
return 0;
}
}
void
show_extras_menu ()
{
static char *headers[] = { "Extras",
"",
NULL
};
char* items[6];
items[0] = "Custom Colors";
items[1] = "Show Battery Status";
items[2] = "Recovery Overclocking";
if (plugins_present("/sdcard/RZR/plugins"))
{
items[3] = "Plugins";
items[4] = NULL;
}
else items[3] = NULL;
#define COLORS 0
#define BATT 1
#define OVERCLOCK 2
#define PLUGINS 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 COLORS:
show_colors_menu ();
break;
case BATT:
show_battstat ();
break;
case OVERCLOCK:
show_overclock_menu ();
break;
case PLUGINS:
choose_plugin_menu("/sdcard/RZR/plugins/");
break;
}
}
}