blob: ff34828e2f882c28be77830f34673a16f634d928 [file] [log] [blame]
Dees Troy3be70a82013-10-22 14:25:12 +00001/*
2 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
Dees_Troy38bd7602012-09-14 13:33:53 -040019#include <stdio.h>
20#include <stdlib.h>
Ethan Yonkeraf2897c2014-02-10 13:07:14 -060021#include <string>
Dees_Troy38bd7602012-09-14 13:33:53 -040022#include <unistd.h>
23#include <vector>
24#include <dirent.h>
25#include <time.h>
Dees_Troy43d8b002012-09-17 16:00:01 -040026#include <errno.h>
bigbiff bigbiff9c754052013-01-09 09:09:08 -050027#include <fcntl.h>
28#include <sys/mount.h>
Dees_Troya58bead2012-09-27 09:49:29 -040029#include <sys/reboot.h>
bigbiff bigbiff9c754052013-01-09 09:09:08 -050030#include <sys/sendfile.h>
31#include <sys/stat.h>
32#include <sys/vfs.h>
Dees_Troy83bd4832013-05-04 12:39:56 +000033#include <sys/types.h>
34#include <sys/wait.h>
bigbiff bigbiff9c754052013-01-09 09:09:08 -050035#include <iostream>
36#include <fstream>
Dees_Troy83bd4832013-05-04 12:39:56 +000037#include <sstream>
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -040038#include <cctype>
bigbiff74a6d0d2015-02-14 20:49:44 -050039#include <algorithm>
bigbiff bigbiff19874f12019-01-08 20:06:57 -050040#include <selinux/label.h>
Dees_Troy38bd7602012-09-14 13:33:53 -040041#include "twrp-functions.hpp"
Dees_Troy2673cec2013-04-02 20:22:16 +000042#include "twcommon.h"
Ethan Yonker472f5062016-02-25 13:47:30 -060043#include "gui/gui.hpp"
Ethan Yonkeraf2897c2014-02-10 13:07:14 -060044#ifndef BUILD_TWRPTAR_MAIN
Dees_Troyb46a6842012-09-25 11:06:46 -040045#include "data.hpp"
Ethan Yonkeraf2897c2014-02-10 13:07:14 -060046#include "partitions.hpp"
Dees_Troy3477d712012-09-27 15:44:01 -040047#include "variables.h"
Ethan Yonker8373cfe2017-09-08 06:50:54 -050048#include "bootloader_message_twrp/include/bootloader_message_twrp/bootloader_message.h"
Tom Hite5a926722014-09-15 01:31:03 +000049#include "cutils/properties.h"
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -050050#include "cutils/android_reboot.h"
51#include <sys/reboot.h>
Ethan Yonkeraf2897c2014-02-10 13:07:14 -060052#endif // ndef BUILD_TWRPTAR_MAIN
Dees_Troy83bd4832013-05-04 12:39:56 +000053#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
54 #include "openaes/inc/oaes_lib.h"
55#endif
Ethan Yonkerf1179622016-08-25 15:32:21 -050056#include "set_metadata.h"
Dees_Troy38bd7602012-09-14 13:33:53 -040057
Dees_Troyb05ddee2013-01-28 20:24:50 +000058extern "C" {
59 #include "libcrecovery/common.h"
60}
61
bigbiff bigbiff19874f12019-01-08 20:06:57 -050062struct selabel_handle *selinux_handle;
63
bigbiff bigbiff9c754052013-01-09 09:09:08 -050064/* Execute a command */
Vojtech Bocek05534202013-09-11 08:11:56 +020065int TWFunc::Exec_Cmd(const string& cmd, string &result) {
Dees_Troy29a06352013-08-24 12:06:47 +000066 FILE* exec;
67 char buffer[130];
68 int ret = 0;
69 exec = __popen(cmd.c_str(), "r");
70 if (!exec) return -1;
Matt Mowera8a89d12016-12-30 18:10:37 -060071 while (!feof(exec)) {
Dees_Troy29a06352013-08-24 12:06:47 +000072 if (fgets(buffer, 128, exec) != NULL) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -050073 result += buffer;
Dees_Troyb05ddee2013-01-28 20:24:50 +000074 }
bigbiff bigbiff9c754052013-01-09 09:09:08 -050075 }
Dees_Troy29a06352013-08-24 12:06:47 +000076 ret = __pclose(exec);
77 return ret;
bigbiff bigbiff9c754052013-01-09 09:09:08 -050078}
79
Vojtech Bocek05534202013-09-11 08:11:56 +020080int TWFunc::Exec_Cmd(const string& cmd) {
81 pid_t pid;
82 int status;
83 switch(pid = fork())
84 {
85 case -1:
bigbiff bigbiff731df792014-02-20 18:26:13 -050086 LOGERR("Exec_Cmd(): vfork failed: %d!\n", errno);
Vojtech Bocek05534202013-09-11 08:11:56 +020087 return -1;
88 case 0: // child
89 execl("/sbin/sh", "sh", "-c", cmd.c_str(), NULL);
90 _exit(127);
91 break;
92 default:
93 {
94 if (TWFunc::Wait_For_Child(pid, &status, cmd) != 0)
95 return -1;
96 else
97 return 0;
98 }
99 }
100}
101
Dees_Troy38bd7602012-09-14 13:33:53 -0400102// Returns "file.name" from a full /path/to/file.name
Ethan Yonker6e8c27a2016-12-22 17:55:57 -0600103string TWFunc::Get_Filename(const string& Path) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400104 size_t pos = Path.find_last_of("/");
105 if (pos != string::npos) {
106 string Filename;
107 Filename = Path.substr(pos + 1, Path.size() - pos - 1);
108 return Filename;
109 } else
110 return Path;
111}
112
113// Returns "/path/to/" from a full /path/to/file.name
Ethan Yonker6e8c27a2016-12-22 17:55:57 -0600114string TWFunc::Get_Path(const string& Path) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400115 size_t pos = Path.find_last_of("/");
116 if (pos != string::npos) {
117 string Pathonly;
118 Pathonly = Path.substr(0, pos + 1);
119 return Pathonly;
120 } else
121 return Path;
122}
123
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600124int TWFunc::Wait_For_Child(pid_t pid, int *status, string Child_Name) {
125 pid_t rc_pid;
126
127 rc_pid = waitpid(pid, status, 0);
128 if (rc_pid > 0) {
Vojtech Bocek0fdcbec2015-03-20 15:36:40 +0100129 if (WIFSIGNALED(*status)) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500130 gui_msg(Msg(msg::kError, "pid_signal={1} process ended with signal: {2}")(Child_Name)(WTERMSIG(*status))); // Seg fault or some other non-graceful termination
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600131 return -1;
Vojtech Bocek0fdcbec2015-03-20 15:36:40 +0100132 } else if (WEXITSTATUS(*status) == 0) {
133 LOGINFO("%s process ended with RC=%d\n", Child_Name.c_str(), WEXITSTATUS(*status)); // Success
134 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500135 gui_msg(Msg(msg::kError, "pid_error={1} process ended with ERROR: {2}")(Child_Name)(WEXITSTATUS(*status))); // Graceful exit, but there was an error
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600136 return -1;
137 }
138 } else { // no PID returned
139 if (errno == ECHILD)
that2252d242015-04-03 22:33:04 +0200140 LOGERR("%s no child process exist\n", Child_Name.c_str());
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600141 else {
that2252d242015-04-03 22:33:04 +0200142 LOGERR("%s Unexpected error %d\n", Child_Name.c_str(), errno);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600143 return -1;
144 }
145 }
146 return 0;
147}
148
Ethan Yonkerddb63e22017-01-19 14:01:57 -0600149int TWFunc::Wait_For_Child_Timeout(pid_t pid, int *status, const string& Child_Name, int timeout) {
150 pid_t retpid = waitpid(pid, status, WNOHANG);
151 for (; retpid == 0 && timeout; --timeout) {
152 sleep(1);
153 retpid = waitpid(pid, status, WNOHANG);
154 }
155 if (retpid == 0 && timeout == 0) {
156 LOGERR("%s took too long, killing process\n", Child_Name.c_str());
157 kill(pid, SIGKILL);
Ethan Yonkerddb63e22017-01-19 14:01:57 -0600158 for (timeout = 5; retpid == 0 && timeout; --timeout) {
159 sleep(1);
160 retpid = waitpid(pid, status, WNOHANG);
161 }
162 if (retpid)
163 LOGINFO("Child process killed successfully\n");
164 else
165 LOGINFO("Child process took too long to kill, may be a zombie process\n");
166 return -1;
167 } else if (retpid > 0) {
168 if (WIFSIGNALED(*status)) {
169 gui_msg(Msg(msg::kError, "pid_signal={1} process ended with signal: {2}")(Child_Name)(WTERMSIG(*status))); // Seg fault or some other non-graceful termination
170 return -1;
171 }
172 } else if (retpid < 0) { // no PID returned
173 if (errno == ECHILD)
174 LOGERR("%s no child process exist\n", Child_Name.c_str());
175 else {
176 LOGERR("%s Unexpected error %d\n", Child_Name.c_str(), errno);
177 return -1;
178 }
179 }
180 return 0;
181}
182
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600183bool TWFunc::Path_Exists(string Path) {
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600184 struct stat st;
185 if (stat(Path.c_str(), &st) != 0)
186 return false;
187 else
188 return true;
189}
190
bigbiffce8f83c2015-12-12 18:30:21 -0500191Archive_Type TWFunc::Get_File_Type(string fn) {
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600192 string::size_type i = 0;
193 int firstbyte = 0, secondbyte = 0;
194 char header[3];
195
196 ifstream f;
197 f.open(fn.c_str(), ios::in | ios::binary);
198 f.get(header, 3);
199 f.close();
200 firstbyte = header[i] & 0xff;
201 secondbyte = header[++i] & 0xff;
202
203 if (firstbyte == 0x1f && secondbyte == 0x8b)
bigbiffce8f83c2015-12-12 18:30:21 -0500204 return COMPRESSED;
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600205 else if (firstbyte == 0x4f && secondbyte == 0x41)
bigbiffce8f83c2015-12-12 18:30:21 -0500206 return ENCRYPTED;
207 return UNCOMPRESSED; // default
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600208}
209
210int TWFunc::Try_Decrypting_File(string fn, string password) {
211#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
212 OAES_CTX * ctx = NULL;
213 uint8_t _key_data[32] = "";
214 FILE *f;
215 uint8_t buffer[4096];
216 uint8_t *buffer_out = NULL;
217 uint8_t *ptr = NULL;
218 size_t read_len = 0, out_len = 0;
Matt Mower23d8aae2017-01-06 14:30:33 -0600219 int firstbyte = 0, secondbyte = 0;
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600220 size_t _j = 0;
221 size_t _key_data_len = 0;
222
223 // mostly kanged from OpenAES oaes.c
Matt Mowera8a89d12016-12-30 18:10:37 -0600224 for ( _j = 0; _j < 32; _j++ )
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600225 _key_data[_j] = _j + 1;
226 _key_data_len = password.size();
Matt Mowera8a89d12016-12-30 18:10:37 -0600227 if ( 16 >= _key_data_len )
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600228 _key_data_len = 16;
Matt Mowera8a89d12016-12-30 18:10:37 -0600229 else if ( 24 >= _key_data_len )
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600230 _key_data_len = 24;
231 else
Matt Mowera8a89d12016-12-30 18:10:37 -0600232 _key_data_len = 32;
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600233 memcpy(_key_data, password.c_str(), password.size());
234
235 ctx = oaes_alloc();
236 if (ctx == NULL) {
237 LOGERR("Failed to allocate OAES\n");
238 return -1;
239 }
240
241 oaes_key_import_data(ctx, _key_data, _key_data_len);
242
243 f = fopen(fn.c_str(), "rb");
244 if (f == NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500245 LOGERR("Failed to open '%s' to try decrypt: %s\n", fn.c_str(), strerror(errno));
Matt Mower13a8f0b2015-09-26 15:40:03 -0500246 oaes_free(&ctx);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600247 return -1;
248 }
249 read_len = fread(buffer, sizeof(uint8_t), 4096, f);
250 if (read_len <= 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500251 LOGERR("Read size during try decrypt failed: %s\n", strerror(errno));
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600252 fclose(f);
Matt Mower13a8f0b2015-09-26 15:40:03 -0500253 oaes_free(&ctx);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600254 return -1;
255 }
256 if (oaes_decrypt(ctx, buffer, read_len, NULL, &out_len) != OAES_RET_SUCCESS) {
257 LOGERR("Error: Failed to retrieve required buffer size for trying decryption.\n");
258 fclose(f);
Matt Mower13a8f0b2015-09-26 15:40:03 -0500259 oaes_free(&ctx);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600260 return -1;
261 }
262 buffer_out = (uint8_t *) calloc(out_len, sizeof(char));
263 if (buffer_out == NULL) {
264 LOGERR("Failed to allocate output buffer for try decrypt.\n");
265 fclose(f);
Matt Mower13a8f0b2015-09-26 15:40:03 -0500266 oaes_free(&ctx);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600267 return -1;
268 }
269 if (oaes_decrypt(ctx, buffer, read_len, buffer_out, &out_len) != OAES_RET_SUCCESS) {
270 LOGERR("Failed to decrypt file '%s'\n", fn.c_str());
271 fclose(f);
272 free(buffer_out);
Matt Mower13a8f0b2015-09-26 15:40:03 -0500273 oaes_free(&ctx);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600274 return 0;
275 }
276 fclose(f);
Matt Mower13a8f0b2015-09-26 15:40:03 -0500277 oaes_free(&ctx);
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600278 if (out_len < 2) {
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500279 LOGINFO("Successfully decrypted '%s' but read length too small.\n", fn.c_str());
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600280 free(buffer_out);
281 return 1; // Decrypted successfully
282 }
283 ptr = buffer_out;
284 firstbyte = *ptr & 0xff;
285 ptr++;
286 secondbyte = *ptr & 0xff;
287 if (firstbyte == 0x1f && secondbyte == 0x8b) {
288 LOGINFO("Successfully decrypted '%s' and file is compressed.\n", fn.c_str());
289 free(buffer_out);
290 return 3; // Compressed
291 }
292 if (out_len >= 262) {
293 ptr = buffer_out + 257;
294 if (strncmp((char*)ptr, "ustar", 5) == 0) {
295 LOGINFO("Successfully decrypted '%s' and file is tar format.\n", fn.c_str());
296 free(buffer_out);
297 return 2; // Tar
298 }
299 }
300 free(buffer_out);
301 LOGINFO("No errors decrypting '%s' but no known file format.\n", fn.c_str());
302 return 1; // Decrypted successfully
303#else
304 LOGERR("Encrypted backup support not included.\n");
305 return -1;
306#endif
307}
308
Ethan Yonker472f5062016-02-25 13:47:30 -0600309unsigned long TWFunc::Get_File_Size(const string& Path) {
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600310 struct stat st;
311
312 if (stat(Path.c_str(), &st) != 0)
313 return 0;
314 return st.st_size;
315}
316
Vojtech Bocek05f87d62014-03-11 22:08:23 +0100317std::string TWFunc::Remove_Trailing_Slashes(const std::string& path, bool leaveLast)
318{
319 std::string res;
320 size_t last_idx = 0, idx = 0;
321
Matt Mowera8a89d12016-12-30 18:10:37 -0600322 while (last_idx != std::string::npos)
Vojtech Bocek05f87d62014-03-11 22:08:23 +0100323 {
Matt Mowera8a89d12016-12-30 18:10:37 -0600324 if (last_idx != 0)
Vojtech Bocek05f87d62014-03-11 22:08:23 +0100325 res += '/';
326
327 idx = path.find_first_of('/', last_idx);
Matt Mowera8a89d12016-12-30 18:10:37 -0600328 if (idx == std::string::npos) {
Vojtech Bocek05f87d62014-03-11 22:08:23 +0100329 res += path.substr(last_idx, idx);
330 break;
331 }
332
333 res += path.substr(last_idx, idx-last_idx);
334 last_idx = path.find_first_not_of('/', idx);
335 }
336
Matt Mowera8a89d12016-12-30 18:10:37 -0600337 if (leaveLast)
Vojtech Bocek05f87d62014-03-11 22:08:23 +0100338 res += '/';
339 return res;
340}
341
Matt Mower2416a502016-04-12 19:54:46 -0500342void TWFunc::Strip_Quotes(char* &str) {
343 if (strlen(str) > 0 && str[0] == '\"')
344 str++;
345 if (strlen(str) > 0 && str[strlen(str)-1] == '\"')
346 str[strlen(str)-1] = 0;
347}
348
Ethan Yonker1b7a31b2014-07-03 15:09:22 -0500349vector<string> TWFunc::split_string(const string &in, char del, bool skip_empty) {
350 vector<string> res;
351
352 if (in.empty() || del == '\0')
353 return res;
354
355 string field;
356 istringstream f(in);
357 if (del == '\n') {
Matt Mowera8a89d12016-12-30 18:10:37 -0600358 while (getline(f, field)) {
Ethan Yonker1b7a31b2014-07-03 15:09:22 -0500359 if (field.empty() && skip_empty)
360 continue;
Matt Mowera8a89d12016-12-30 18:10:37 -0600361 res.push_back(field);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -0500362 }
363 } else {
Matt Mowera8a89d12016-12-30 18:10:37 -0600364 while (getline(f, field, del)) {
Ethan Yonker1b7a31b2014-07-03 15:09:22 -0500365 if (field.empty() && skip_empty)
366 continue;
367 res.push_back(field);
368 }
369 }
370 return res;
371}
372
Ethan Yonker472f5062016-02-25 13:47:30 -0600373timespec TWFunc::timespec_diff(timespec& start, timespec& end)
374{
375 timespec temp;
376 if ((end.tv_nsec-start.tv_nsec)<0) {
377 temp.tv_sec = end.tv_sec-start.tv_sec-1;
378 temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
379 } else {
380 temp.tv_sec = end.tv_sec-start.tv_sec;
381 temp.tv_nsec = end.tv_nsec-start.tv_nsec;
382 }
383 return temp;
384}
385
386int32_t TWFunc::timespec_diff_ms(timespec& start, timespec& end)
387{
388 return ((end.tv_sec * 1000) + end.tv_nsec/1000000) -
389 ((start.tv_sec * 1000) + start.tv_nsec/1000000);
390}
391
Ethan Yonkeraf2897c2014-02-10 13:07:14 -0600392#ifndef BUILD_TWRPTAR_MAIN
393
Dees_Troy38bd7602012-09-14 13:33:53 -0400394// Returns "/path" from a full /path/to/file.name
Ethan Yonker6e8c27a2016-12-22 17:55:57 -0600395string TWFunc::Get_Root_Path(const string& Path) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400396 string Local_Path = Path;
397
398 // Make sure that we have a leading slash
399 if (Local_Path.substr(0, 1) != "/")
400 Local_Path = "/" + Local_Path;
401
402 // Trim the path to get the root path only
403 size_t position = Local_Path.find("/", 2);
404 if (position != string::npos) {
405 Local_Path.resize(position);
406 }
407 return Local_Path;
408}
409
410void TWFunc::install_htc_dumlock(void) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400411 int need_libs = 0;
412
Captain Throwback9d6feb52018-07-27 10:05:24 -0400413 if (!PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true))
Dees_Troy38bd7602012-09-14 13:33:53 -0400414 return;
415
416 if (!PartitionManager.Mount_By_Path("/data", true))
417 return;
418
Ethan Yonker74db1572015-10-28 12:44:49 -0500419 gui_msg("install_dumlock=Installing HTC Dumlock to system...");
Dees Troy3454ade2015-01-20 19:21:04 +0000420 copy_file(TWHTCD_PATH "htcdumlocksys", "/system/bin/htcdumlock", 0755);
Dees_Troy8170a922012-09-18 15:40:25 -0400421 if (!Path_Exists("/system/bin/flash_image")) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500422 LOGINFO("Installing flash_image...\n");
Dees Troy3454ade2015-01-20 19:21:04 +0000423 copy_file(TWHTCD_PATH "flash_imagesys", "/system/bin/flash_image", 0755);
Dees_Troy38bd7602012-09-14 13:33:53 -0400424 need_libs = 1;
425 } else
Ethan Yonker74db1572015-10-28 12:44:49 -0500426 LOGINFO("flash_image is already installed, skipping...\n");
Dees_Troy8170a922012-09-18 15:40:25 -0400427 if (!Path_Exists("/system/bin/dump_image")) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500428 LOGINFO("Installing dump_image...\n");
Dees Troy3454ade2015-01-20 19:21:04 +0000429 copy_file(TWHTCD_PATH "dump_imagesys", "/system/bin/dump_image", 0755);
Dees_Troy38bd7602012-09-14 13:33:53 -0400430 need_libs = 1;
431 } else
Ethan Yonker74db1572015-10-28 12:44:49 -0500432 LOGINFO("dump_image is already installed, skipping...\n");
Dees_Troy38bd7602012-09-14 13:33:53 -0400433 if (need_libs) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500434 LOGINFO("Installing libs needed for flash_image and dump_image...\n");
Dees Troy3454ade2015-01-20 19:21:04 +0000435 copy_file(TWHTCD_PATH "libbmlutils.so", "/system/lib/libbmlutils.so", 0644);
436 copy_file(TWHTCD_PATH "libflashutils.so", "/system/lib/libflashutils.so", 0644);
437 copy_file(TWHTCD_PATH "libmmcutils.so", "/system/lib/libmmcutils.so", 0644);
438 copy_file(TWHTCD_PATH "libmtdutils.so", "/system/lib/libmtdutils.so", 0644);
Dees_Troy38bd7602012-09-14 13:33:53 -0400439 }
Ethan Yonker74db1572015-10-28 12:44:49 -0500440 LOGINFO("Installing HTC Dumlock app...\n");
Dees_Troy38bd7602012-09-14 13:33:53 -0400441 mkdir("/data/app", 0777);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500442 unlink("/data/app/com.teamwin.htcdumlock*");
Dees Troy3454ade2015-01-20 19:21:04 +0000443 copy_file(TWHTCD_PATH "HTCDumlock.apk", "/data/app/com.teamwin.htcdumlock.apk", 0777);
Dees_Troy38bd7602012-09-14 13:33:53 -0400444 sync();
Ethan Yonker74db1572015-10-28 12:44:49 -0500445 gui_msg("done=Done.");
Dees_Troy38bd7602012-09-14 13:33:53 -0400446}
447
448void TWFunc::htc_dumlock_restore_original_boot(void) {
449 if (!PartitionManager.Mount_By_Path("/sdcard", true))
450 return;
451
Ethan Yonker74db1572015-10-28 12:44:49 -0500452 gui_msg("dumlock_restore=Restoring original boot...");
Vojtech Bocek05534202013-09-11 08:11:56 +0200453 Exec_Cmd("htcdumlock restore");
Ethan Yonker74db1572015-10-28 12:44:49 -0500454 gui_msg("done=Done.");
Dees_Troy38bd7602012-09-14 13:33:53 -0400455}
456
457void TWFunc::htc_dumlock_reflash_recovery_to_boot(void) {
458 if (!PartitionManager.Mount_By_Path("/sdcard", true))
459 return;
Ethan Yonker74db1572015-10-28 12:44:49 -0500460 gui_msg("dumlock_reflash=Reflashing recovery to boot...");
Vojtech Bocek05534202013-09-11 08:11:56 +0200461 Exec_Cmd("htcdumlock recovery noreboot");
Ethan Yonker74db1572015-10-28 12:44:49 -0500462 gui_msg("done=Done.");
Dees_Troy38bd7602012-09-14 13:33:53 -0400463}
Dees_Troy43d8b002012-09-17 16:00:01 -0400464
465int TWFunc::Recursive_Mkdir(string Path) {
thatf1408b32016-01-03 11:09:15 +0100466 std::vector<std::string> parts = Split_String(Path, "/", true);
467 std::string cur_path;
468 for (size_t i = 0; i < parts.size(); ++i) {
469 cur_path += "/" + parts[i];
470 if (!TWFunc::Path_Exists(cur_path)) {
471 if (mkdir(cur_path.c_str(), 0777)) {
Matt Mower3c366972015-12-25 19:28:31 -0600472 gui_msg(Msg(msg::kError, "create_folder_strerr=Can not create '{1}' folder ({2}).")(cur_path)(strerror(errno)));
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600473 return false;
474 } else {
thatf1408b32016-01-03 11:09:15 +0100475 tw_set_default_metadata(cur_path.c_str());
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600476 }
Dees_Troy43d8b002012-09-17 16:00:01 -0400477 }
Dees_Troy43d8b002012-09-17 16:00:01 -0400478 }
Dees_Troy43d8b002012-09-17 16:00:01 -0400479 return true;
480}
481
Dees_Troyb46a6842012-09-25 11:06:46 -0400482void TWFunc::GUI_Operation_Text(string Read_Value, string Default_Text) {
483 string Display_Text;
484
485 DataManager::GetValue(Read_Value, Display_Text);
486 if (Display_Text.empty())
487 Display_Text = Default_Text;
488
489 DataManager::SetValue("tw_operation", Display_Text);
490 DataManager::SetValue("tw_partition", "");
491}
492
493void TWFunc::GUI_Operation_Text(string Read_Value, string Partition_Name, string Default_Text) {
494 string Display_Text;
495
496 DataManager::GetValue(Read_Value, Display_Text);
497 if (Display_Text.empty())
498 Display_Text = Default_Text;
499
500 DataManager::SetValue("tw_operation", Display_Text);
501 DataManager::SetValue("tw_partition", Partition_Name);
Dees_Troy7c2dec82012-09-26 09:49:14 -0400502}
503
Dees_Troy2673cec2013-04-02 20:22:16 +0000504void TWFunc::Copy_Log(string Source, string Destination) {
Dees Troy9d7fdf52013-09-19 20:49:25 +0000505 PartitionManager.Mount_By_Path(Destination, false);
Dees_Troy2673cec2013-04-02 20:22:16 +0000506 FILE *destination_log = fopen(Destination.c_str(), "a");
507 if (destination_log == NULL) {
508 LOGERR("TWFunc::Copy_Log -- Can't open destination log file: '%s'\n", Destination.c_str());
Dees_Troy6ef66352013-02-21 08:26:57 -0600509 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +0000510 FILE *source_log = fopen(Source.c_str(), "r");
511 if (source_log != NULL) {
512 fseek(source_log, Log_Offset, SEEK_SET);
513 char buffer[4096];
514 while (fgets(buffer, sizeof(buffer), source_log))
515 fputs(buffer, destination_log); // Buffered write of log file
516 Log_Offset = ftell(source_log);
517 fflush(source_log);
518 fclose(source_log);
Dees_Troy6ef66352013-02-21 08:26:57 -0600519 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000520 fflush(destination_log);
521 fclose(destination_log);
Dees_Troy6ef66352013-02-21 08:26:57 -0600522 }
Dees_Troya58bead2012-09-27 09:49:29 -0400523}
524
Dees_Troy2673cec2013-04-02 20:22:16 +0000525void TWFunc::Update_Log_File(void) {
bigbiff bigbiff19874f12019-01-08 20:06:57 -0500526 std::string recoveryDir = get_cache_dir() + "recovery/";
527
528 if (get_cache_dir() == NON_AB_CACHE_DIR) {
529 if (!PartitionManager.Mount_By_Path(NON_AB_CACHE_DIR, false)) {
530 LOGINFO("Failed to mount %s for TWFunc::Update_Log_File\n", NON_AB_CACHE_DIR);
Dees Troy9d7fdf52013-09-19 20:49:25 +0000531 }
Dees Troy9d7fdf52013-09-19 20:49:25 +0000532 }
Dees_Troya58bead2012-09-27 09:49:29 -0400533
bigbiff bigbiff19874f12019-01-08 20:06:57 -0500534 if (!TWFunc::Path_Exists(recoveryDir)) {
535 LOGINFO("Recreating %s folder.\n", recoveryDir.c_str());
536 if (mkdir(recoveryDir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) {
537 LOGINFO("Unable to create %s folder.\n", recoveryDir.c_str());
538 }
539 }
540
541 std::string logCopy = recoveryDir + "log";
542 std::string lastLogCopy = recoveryDir + "last_log";
543 copy_file(logCopy, lastLogCopy, 600);
544 Copy_Log(TMP_LOG_FILE, logCopy);
545 chown(logCopy.c_str(), 1000, 1000);
546 chmod(logCopy.c_str(), 0600);
547 chmod(lastLogCopy.c_str(), 0640);
548
Dees_Troy2673cec2013-04-02 20:22:16 +0000549 // Reset bootloader message
550 TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
551 if (Part != NULL) {
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500552 std::string err;
553 if (!clear_bootloader_message((void*)&err)) {
Ethan Yonkerb5236502016-11-19 22:24:59 -0600554 if (err == "no misc device set") {
555 LOGINFO("%s\n", err.c_str());
556 } else {
557 LOGERR("%s\n", err.c_str());
558 }
559 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000560 }
Dees_Troya58bead2012-09-27 09:49:29 -0400561
bigbiff bigbiff19874f12019-01-08 20:06:57 -0500562 if (get_cache_dir() == NON_AB_CACHE_DIR) {
563 if (PartitionManager.Mount_By_Path("/cache", false)) {
564 if (unlink("/cache/recovery/command") && errno != ENOENT) {
565 LOGINFO("Can't unlink %s\n", "/cache/recovery/command");
566 }
Dees Troy9d7fdf52013-09-19 20:49:25 +0000567 }
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500568 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000569 sync();
570}
571
572void TWFunc::Update_Intent_File(string Intent) {
573 if (PartitionManager.Mount_By_Path("/cache", false) && !Intent.empty()) {
Ethan Yonker6e8c27a2016-12-22 17:55:57 -0600574 TWFunc::write_to_file("/cache/recovery/intent", Intent);
Dees_Troy2673cec2013-04-02 20:22:16 +0000575 }
Dees_Troya58bead2012-09-27 09:49:29 -0400576}
577
578// reboot: Reboot the system. Return -1 on error, no return on success
579int TWFunc::tw_reboot(RebootCommand command)
580{
Ethan Yonkerfe916112016-03-14 14:54:37 -0500581 DataManager::Flush();
582 Update_Log_File();
Dees_Troya58bead2012-09-27 09:49:29 -0400583 // Always force a sync before we reboot
Dees_Troy6ef66352013-02-21 08:26:57 -0600584 sync();
Dees_Troya58bead2012-09-27 09:49:29 -0400585
Dees_Troy2673cec2013-04-02 20:22:16 +0000586 switch (command) {
587 case rb_current:
588 case rb_system:
Dees_Troy2673cec2013-04-02 20:22:16 +0000589 Update_Intent_File("s");
590 sync();
591 check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500592#ifdef ANDROID_RB_PROPERTY
593 return property_set(ANDROID_RB_PROPERTY, "reboot,");
594#elif defined(ANDROID_RB_RESTART)
595 return android_reboot(ANDROID_RB_RESTART, 0, 0);
596#else
Dees_Troy2673cec2013-04-02 20:22:16 +0000597 return reboot(RB_AUTOBOOT);
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500598#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000599 case rb_recovery:
600 check_and_run_script("/sbin/rebootrecovery.sh", "reboot recovery");
Ethan Yonker75bf0412014-11-21 13:54:27 -0600601#ifdef ANDROID_RB_PROPERTY
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500602 return property_set(ANDROID_RB_PROPERTY, "reboot,recovery");
Ethan Yonker75bf0412014-11-21 13:54:27 -0600603#else
604 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery");
605#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000606 case rb_bootloader:
607 check_and_run_script("/sbin/rebootbootloader.sh", "reboot bootloader");
Ethan Yonker75bf0412014-11-21 13:54:27 -0600608#ifdef ANDROID_RB_PROPERTY
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500609 return property_set(ANDROID_RB_PROPERTY, "reboot,bootloader");
Ethan Yonker75bf0412014-11-21 13:54:27 -0600610#else
611 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader");
612#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000613 case rb_poweroff:
614 check_and_run_script("/sbin/poweroff.sh", "power off");
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500615#ifdef ANDROID_RB_PROPERTY
616 return property_set(ANDROID_RB_PROPERTY, "shutdown,");
617#elif defined(ANDROID_RB_POWEROFF)
618 return android_reboot(ANDROID_RB_POWEROFF, 0, 0);
619#else
Dees_Troy2673cec2013-04-02 20:22:16 +0000620 return reboot(RB_POWER_OFF);
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500621#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000622 case rb_download:
623 check_and_run_script("/sbin/rebootdownload.sh", "reboot download");
Ethan Yonker75bf0412014-11-21 13:54:27 -0600624#ifdef ANDROID_RB_PROPERTY
Ethan Yonkerbc2bc6b2015-03-24 21:37:52 -0500625 return property_set(ANDROID_RB_PROPERTY, "reboot,download");
Ethan Yonker75bf0412014-11-21 13:54:27 -0600626#else
627 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "download");
628#endif
mauronofrioe9a49ef2018-10-03 13:38:16 +0200629 case rb_edl:
630 check_and_run_script("/sbin/rebootedl.sh", "reboot edl");
631#ifdef ANDROID_RB_PROPERTY
632 return property_set(ANDROID_RB_PROPERTY, "reboot,edl");
633#else
634 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "edl");
635#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000636 default:
637 return -1;
Dees_Troy6ef66352013-02-21 08:26:57 -0600638 }
639 return -1;
Dees_Troya58bead2012-09-27 09:49:29 -0400640}
641
642void TWFunc::check_and_run_script(const char* script_file, const char* display_name)
643{
644 // Check for and run startup script if script exists
645 struct stat st;
646 if (stat(script_file, &st) == 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500647 gui_msg(Msg("run_script=Running {1} script...")(display_name));
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500648 chmod(script_file, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
Vojtech Bocek05534202013-09-11 08:11:56 +0200649 TWFunc::Exec_Cmd(script_file);
Ethan Yonker74db1572015-10-28 12:44:49 -0500650 gui_msg("done=Done.");
Dees_Troya58bead2012-09-27 09:49:29 -0400651 }
Dees_Troy3477d712012-09-27 15:44:01 -0400652}
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500653
654int TWFunc::removeDir(const string path, bool skipParent) {
Dees_Troyce675462013-01-09 19:48:21 +0000655 DIR *d = opendir(path.c_str());
656 int r = 0;
657 string new_path;
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500658
Dees_Troyce675462013-01-09 19:48:21 +0000659 if (d == NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500660 gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(path)(strerror(errno)));
Dees_Troyce675462013-01-09 19:48:21 +0000661 return -1;
662 }
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500663
Dees_Troyce675462013-01-09 19:48:21 +0000664 if (d) {
665 struct dirent *p;
666 while (!r && (p = readdir(d))) {
Dees_Troyce675462013-01-09 19:48:21 +0000667 if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
668 continue;
669 new_path = path + "/";
670 new_path.append(p->d_name);
671 if (p->d_type == DT_DIR) {
672 r = removeDir(new_path, true);
673 if (!r) {
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500674 if (p->d_type == DT_DIR)
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500675 r = rmdir(new_path.c_str());
676 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000677 LOGINFO("Unable to removeDir '%s': %s\n", new_path.c_str(), strerror(errno));
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500678 }
bigbiff bigbiff98f1f902013-01-19 18:46:13 -0500679 } else if (p->d_type == DT_REG || p->d_type == DT_LNK || p->d_type == DT_FIFO || p->d_type == DT_SOCK) {
Dees_Troyce675462013-01-09 19:48:21 +0000680 r = unlink(new_path.c_str());
Dees_Troye34c1332013-02-06 19:13:00 +0000681 if (r != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000682 LOGINFO("Unable to unlink '%s: %s'\n", new_path.c_str(), strerror(errno));
Dees_Troye34c1332013-02-06 19:13:00 +0000683 }
Dees_Troyce675462013-01-09 19:48:21 +0000684 }
685 }
686 closedir(d);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500687
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500688 if (!r) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500689 if (skipParent)
690 return 0;
691 else
692 r = rmdir(path.c_str());
693 }
Dees_Troyce675462013-01-09 19:48:21 +0000694 }
695 return r;
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500696}
697
698int TWFunc::copy_file(string src, string dst, int mode) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000699 LOGINFO("Copying file %s to %s\n", src.c_str(), dst.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500700 ifstream srcfile(src.c_str(), ios::binary);
701 ofstream dstfile(dst.c_str(), ios::binary);
702 dstfile << srcfile.rdbuf();
703 srcfile.close();
704 dstfile.close();
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500705 if (chmod(dst.c_str(), mode) != 0)
706 return -1;
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500707 return 0;
708}
Dees_Troy3ee47bc2013-01-25 21:47:37 +0000709
710unsigned int TWFunc::Get_D_Type_From_Stat(string Path) {
711 struct stat st;
712
713 stat(Path.c_str(), &st);
714 if (st.st_mode & S_IFDIR)
715 return DT_DIR;
716 else if (st.st_mode & S_IFBLK)
717 return DT_BLK;
718 else if (st.st_mode & S_IFCHR)
719 return DT_CHR;
720 else if (st.st_mode & S_IFIFO)
721 return DT_FIFO;
722 else if (st.st_mode & S_IFLNK)
723 return DT_LNK;
724 else if (st.st_mode & S_IFREG)
725 return DT_REG;
726 else if (st.st_mode & S_IFSOCK)
727 return DT_SOCK;
728 return DT_UNKNOWN;
Dees_Troye34c1332013-02-06 19:13:00 +0000729}
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500730
731int TWFunc::read_file(string fn, string& results) {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200732 ifstream file;
733 file.open(fn.c_str(), ios::in);
734
735 if (file.is_open()) {
736 file >> results;
737 file.close();
738 return 0;
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -0500739 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740
741 LOGINFO("Cannot find file %s\n", fn.c_str());
742 return -1;
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -0500743}
744
745int TWFunc::read_file(string fn, vector<string>& results) {
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500746 ifstream file;
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -0500747 string line;
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500748 file.open(fn.c_str(), ios::in);
749 if (file.is_open()) {
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -0500750 while (getline(file, line))
751 results.push_back(line);
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500752 file.close();
753 return 0;
754 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000755 LOGINFO("Cannot find file %s\n", fn.c_str());
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500756 return -1;
757}
758
xNUTxe85f02d2014-07-18 01:30:58 +0200759int TWFunc::read_file(string fn, uint64_t& results) {
760 ifstream file;
761 file.open(fn.c_str(), ios::in);
762
763 if (file.is_open()) {
764 file >> results;
765 file.close();
766 return 0;
767 }
768
769 LOGINFO("Cannot find file %s\n", fn.c_str());
770 return -1;
771}
772
Ethan Yonker6e8c27a2016-12-22 17:55:57 -0600773int TWFunc::write_to_file(const string& fn, const string& line) {
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500774 FILE *file;
775 file = fopen(fn.c_str(), "w");
776 if (file != NULL) {
777 fwrite(line.c_str(), line.size(), 1, file);
778 fclose(file);
779 return 0;
780 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000781 LOGINFO("Cannot find file %s\n", fn.c_str());
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500782 return -1;
783}
784
Dees_Troy83bd4832013-05-04 12:39:56 +0000785bool TWFunc::Try_Decrypting_Backup(string Restore_Path, string Password) {
786 DIR* d;
787
788 string Filename;
789 Restore_Path += "/";
790 d = opendir(Restore_Path.c_str());
791 if (d == NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500792 gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Restore_Path)(strerror(errno)));
Dees_Troy83bd4832013-05-04 12:39:56 +0000793 return false;
794 }
795
796 struct dirent* de;
797 while ((de = readdir(d)) != NULL) {
798 Filename = Restore_Path;
799 Filename += de->d_name;
bigbiffce8f83c2015-12-12 18:30:21 -0500800 if (TWFunc::Get_File_Type(Filename) == ENCRYPTED) {
Dees_Troy83bd4832013-05-04 12:39:56 +0000801 if (TWFunc::Try_Decrypting_File(Filename, Password) < 2) {
802 DataManager::SetValue("tw_restore_password", ""); // Clear the bad password
803 DataManager::SetValue("tw_restore_display", ""); // Also clear the display mask
804 closedir(d);
805 return false;
806 }
807 }
808 }
809 closedir(d);
810 return true;
811}
812
Dees Troyb21cc642013-09-10 17:36:41 +0000813string TWFunc::Get_Current_Date() {
814 string Current_Date;
815 time_t seconds = time(0);
816 struct tm *t = localtime(&seconds);
817 char timestamp[255];
818 sprintf(timestamp,"%04d-%02d-%02d--%02d-%02d-%02d",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
819 Current_Date = timestamp;
820 return Current_Date;
821}
822
Ethan Yonkerb5557892014-02-07 21:43:20 -0600823string TWFunc::System_Property_Get(string Prop_Name) {
Captain Throwback9d6feb52018-07-27 10:05:24 -0400824 bool mount_state = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path());
Dees Troyb21cc642013-09-10 17:36:41 +0000825 std::vector<string> buildprop;
Ethan Yonkerb5557892014-02-07 21:43:20 -0600826 string propvalue;
Captain Throwback9d6feb52018-07-27 10:05:24 -0400827 if (!PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true))
Ethan Yonkerb5557892014-02-07 21:43:20 -0600828 return propvalue;
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -0600829 string prop_file = "/system/build.prop";
830 if (!TWFunc::Path_Exists(prop_file))
Captain Throwback9d6feb52018-07-27 10:05:24 -0400831 prop_file = PartitionManager.Get_Android_Root_Path() + "/system/build.prop"; // for devices with system as a root file system (e.g. Pixel)
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -0600832 if (TWFunc::read_file(prop_file, buildprop) != 0) {
Captain Throwback9d6feb52018-07-27 10:05:24 -0400833 LOGINFO("Unable to open build.prop for getting '%s'.\n", Prop_Name.c_str());
Vojtech Boceka2e70162013-09-17 17:05:10 +0200834 DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
Dees Troyb21cc642013-09-10 17:36:41 +0000835 if (!mount_state)
Captain Throwback9d6feb52018-07-27 10:05:24 -0400836 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
Ethan Yonkerb5557892014-02-07 21:43:20 -0600837 return propvalue;
Dees Troyb21cc642013-09-10 17:36:41 +0000838 }
839 int line_count = buildprop.size();
840 int index;
841 size_t start_pos = 0, end_pos;
Ethan Yonkerb5557892014-02-07 21:43:20 -0600842 string propname;
Dees Troyb21cc642013-09-10 17:36:41 +0000843 for (index = 0; index < line_count; index++) {
844 end_pos = buildprop.at(index).find("=", start_pos);
845 propname = buildprop.at(index).substr(start_pos, end_pos);
Ethan Yonkerb5557892014-02-07 21:43:20 -0600846 if (propname == Prop_Name) {
Dees Troyb21cc642013-09-10 17:36:41 +0000847 propvalue = buildprop.at(index).substr(end_pos + 1, buildprop.at(index).size());
Ethan Yonkerb5557892014-02-07 21:43:20 -0600848 if (!mount_state)
Captain Throwback9d6feb52018-07-27 10:05:24 -0400849 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
Ethan Yonkerb5557892014-02-07 21:43:20 -0600850 return propvalue;
Dees Troyb21cc642013-09-10 17:36:41 +0000851 }
852 }
Dees Troyb21cc642013-09-10 17:36:41 +0000853 if (!mount_state)
Captain Throwback9d6feb52018-07-27 10:05:24 -0400854 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
Ethan Yonkerb5557892014-02-07 21:43:20 -0600855 return propvalue;
856}
857
858void TWFunc::Auto_Generate_Backup_Name() {
859 string propvalue = System_Property_Get("ro.build.display.id");
860 if (propvalue.empty()) {
861 DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
862 return;
863 }
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -0400864 else {
865 //remove periods from build display so it doesn't confuse the extension code
866 propvalue.erase(remove(propvalue.begin(), propvalue.end(), '.'), propvalue.end());
867 }
Ethan Yonkerb5557892014-02-07 21:43:20 -0600868 string Backup_Name = Get_Current_Date();
bigbiff74a6d0d2015-02-14 20:49:44 -0500869 Backup_Name += "_" + propvalue;
Ethan Yonkerb5557892014-02-07 21:43:20 -0600870 if (Backup_Name.size() > MAX_BACKUP_NAME_LEN)
871 Backup_Name.resize(MAX_BACKUP_NAME_LEN);
872 // Trailing spaces cause problems on some file systems, so remove them
873 string space_check, space = " ";
874 space_check = Backup_Name.substr(Backup_Name.size() - 1, 1);
875 while (space_check == space) {
876 Backup_Name.resize(Backup_Name.size() - 1);
877 space_check = Backup_Name.substr(Backup_Name.size() - 1, 1);
878 }
bigbiff74a6d0d2015-02-14 20:49:44 -0500879 replace(Backup_Name.begin(), Backup_Name.end(), ' ', '_');
Ethan Yonkerb5557892014-02-07 21:43:20 -0600880 DataManager::SetValue(TW_BACKUP_NAME, Backup_Name);
Ethan Yonker92d48e02014-02-26 12:05:55 -0600881 if (PartitionManager.Check_Backup_Name(false) != 0) {
882 LOGINFO("Auto generated backup name '%s' contains invalid characters, using date instead.\n", Backup_Name.c_str());
883 DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
884 }
Vojtech Bocek05534202013-09-11 08:11:56 +0200885}
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100886
nkk7198fc3992017-12-16 16:26:42 +0200887void TWFunc::Fixup_Time_On_Boot(const string& time_paths /* = "" */)
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100888{
889#ifdef QCOM_RTC_FIX
nkk7198fc3992017-12-16 16:26:42 +0200890 static bool fixed = false;
891 if (fixed)
892 return;
xNUTxe85f02d2014-07-18 01:30:58 +0200893
894 LOGINFO("TWFunc::Fixup_Time: Pre-fix date and time: %s\n", TWFunc::Get_Current_Date().c_str());
895
896 struct timeval tv;
897 uint64_t offset = 0;
898 std::string sepoch = "/sys/class/rtc/rtc0/since_epoch";
899
900 if (TWFunc::read_file(sepoch, offset) == 0) {
901
902 LOGINFO("TWFunc::Fixup_Time: Setting time offset from file %s\n", sepoch.c_str());
903
904 tv.tv_sec = offset;
905 tv.tv_usec = 0;
906 settimeofday(&tv, NULL);
907
908 gettimeofday(&tv, NULL);
909
Phoenix59146b05f22018-02-03 06:41:08 +0000910 if (tv.tv_sec > 1517600000) { // Anything older then 2 Feb 2018 19:33:20 GMT will do nicely thank you ;)
xNUTxe85f02d2014-07-18 01:30:58 +0200911
912 LOGINFO("TWFunc::Fixup_Time: Date and time corrected: %s\n", TWFunc::Get_Current_Date().c_str());
nkk7198fc3992017-12-16 16:26:42 +0200913 fixed = true;
xNUTxe85f02d2014-07-18 01:30:58 +0200914 return;
915
916 }
917
918 } else {
919
920 LOGINFO("TWFunc::Fixup_Time: opening %s failed\n", sepoch.c_str());
921
922 }
923
Ethan Yonker9132d912015-02-02 10:32:49 -0600924 LOGINFO("TWFunc::Fixup_Time: will attempt to use the ats files now.\n");
xNUTxe85f02d2014-07-18 01:30:58 +0200925
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100926 // Devices with Qualcomm Snapdragon 800 do some shenanigans with RTC.
927 // They never set it, it just ticks forward from 1970-01-01 00:00,
928 // and then they have files /data/system/time/ats_* with 64bit offset
929 // in miliseconds which, when added to the RTC, gives the correct time.
930 // So, the time is: (offset_from_ats + value_from_RTC)
931 // There are multiple ats files, they are for different systems? Bases?
932 // Like, ats_1 is for modem and ats_2 is for TOD (time of day?).
933 // Look at file time_genoff.h in CodeAurora, qcom-opensource/time-services
934
nkk7198fc3992017-12-16 16:26:42 +0200935 std::vector<std::string> paths; // space separated list of paths
936 if (time_paths.empty()) {
Mauronofrio Matarrese2dab70d2019-03-05 02:22:26 +0100937 paths = Split_String("/data/system/time/ /data/time/ /data/vendor/time/", " ");
nkk7198fc3992017-12-16 16:26:42 +0200938 if (!PartitionManager.Mount_By_Path("/data", false))
939 return;
940 } else {
941 // When specific path(s) are used, Fixup_Time needs those
942 // partitions to already be mounted!
943 paths = Split_String(time_paths, " ");
944 }
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100945
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100946 FILE *f;
xNUTxe85f02d2014-07-18 01:30:58 +0200947 offset = 0;
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100948 struct dirent *dt;
949 std::string ats_path;
950
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100951 // Prefer ats_2, it seems to be the one we want according to logcat on hammerhead
952 // - it is the one for ATS_TOD (time of day?).
953 // However, I never saw a device where the offset differs between ats files.
nkk7198fc3992017-12-16 16:26:42 +0200954 for (size_t i = 0; i < paths.size(); ++i)
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100955 {
nkk7198fc3992017-12-16 16:26:42 +0200956 DIR *d = opendir(paths[i].c_str());
Matt Mowera8a89d12016-12-30 18:10:37 -0600957 if (!d)
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100958 continue;
959
Matt Mowera8a89d12016-12-30 18:10:37 -0600960 while ((dt = readdir(d)))
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100961 {
Matt Mowera8a89d12016-12-30 18:10:37 -0600962 if (dt->d_type != DT_REG || strncmp(dt->d_name, "ats_", 4) != 0)
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100963 continue;
964
Matt Mowera8a89d12016-12-30 18:10:37 -0600965 if (ats_path.empty() || strcmp(dt->d_name, "ats_2") == 0)
nkk7198fc3992017-12-16 16:26:42 +0200966 ats_path = paths[i] + dt->d_name;
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100967 }
968
969 closedir(d);
970 }
971
nkk7198fc3992017-12-16 16:26:42 +0200972 if (ats_path.empty()) {
xNUTxe85f02d2014-07-18 01:30:58 +0200973 LOGINFO("TWFunc::Fixup_Time: no ats files found, leaving untouched!\n");
nkk7198fc3992017-12-16 16:26:42 +0200974 } else if ((f = fopen(ats_path.c_str(), "r")) == NULL) {
Dees Troy3e254b92014-03-06 20:24:54 +0000975 LOGINFO("TWFunc::Fixup_Time: failed to open file %s\n", ats_path.c_str());
nkk7198fc3992017-12-16 16:26:42 +0200976 } else if (fread(&offset, sizeof(offset), 1, f) != 1) {
Dees Troy3e254b92014-03-06 20:24:54 +0000977 LOGINFO("TWFunc::Fixup_Time: failed load uint64 from file %s\n", ats_path.c_str());
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100978 fclose(f);
nkk7198fc3992017-12-16 16:26:42 +0200979 } else {
980 fclose(f);
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100981
nkk7198fc3992017-12-16 16:26:42 +0200982 LOGINFO("TWFunc::Fixup_Time: Setting time offset from file %s, offset %llu\n", ats_path.c_str(), (unsigned long long) offset);
983 DataManager::SetValue("tw_qcom_ats_offset", (unsigned long long) offset, 1);
984 fixed = true;
985 }
986
987 if (!fixed) {
988 // Failed to get offset from ats file, check twrp settings
989 unsigned long long value;
990 if (DataManager::GetValue("tw_qcom_ats_offset", value) < 0) {
991 return;
992 } else {
993 offset = (uint64_t) value;
994 LOGINFO("TWFunc::Fixup_Time: Setting time offset from twrp setting file, offset %llu\n", (unsigned long long) offset);
995 // Do not consider the settings file as a definitive answer, keep fixed=false so next run will try ats files again
996 }
997 }
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +0100998
999 gettimeofday(&tv, NULL);
1000
1001 tv.tv_sec += offset/1000;
Phoenix591e444d112018-02-03 07:23:54 +00001002#ifdef TW_CLOCK_OFFSET
1003// Some devices are even quirkier and have ats files that are offset from the actual time
1004 tv.tv_sec = tv.tv_sec + TW_CLOCK_OFFSET;
1005#endif
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +01001006 tv.tv_usec += (offset%1000)*1000;
1007
Matt Mowera8a89d12016-12-30 18:10:37 -06001008 while (tv.tv_usec >= 1000000)
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +01001009 {
1010 ++tv.tv_sec;
1011 tv.tv_usec -= 1000000;
1012 }
1013
1014 settimeofday(&tv, NULL);
xNUTxe85f02d2014-07-18 01:30:58 +02001015
1016 LOGINFO("TWFunc::Fixup_Time: Date and time corrected: %s\n", TWFunc::Get_Current_Date().c_str());
Vojtech Bocekd0e38bc2014-02-03 23:36:57 +01001017#endif
1018}
Ethan Yonkeraf2897c2014-02-10 13:07:14 -06001019
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001020std::vector<std::string> TWFunc::Split_String(const std::string& str, const std::string& delimiter, bool removeEmpty)
1021{
1022 std::vector<std::string> res;
1023 size_t idx = 0, idx_last = 0;
1024
Matt Mowera8a89d12016-12-30 18:10:37 -06001025 while (idx < str.size())
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001026 {
1027 idx = str.find_first_of(delimiter, idx_last);
Matt Mowera8a89d12016-12-30 18:10:37 -06001028 if (idx == std::string::npos)
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001029 idx = str.size();
1030
Matt Mowera8a89d12016-12-30 18:10:37 -06001031 if (idx-idx_last != 0 || !removeEmpty)
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001032 res.push_back(str.substr(idx_last, idx-idx_last));
1033
1034 idx_last = idx + delimiter.size();
1035 }
1036
1037 return res;
1038}
1039
Vojtech Bocek03fd6c52014-03-13 18:46:34 +01001040bool TWFunc::Create_Dir_Recursive(const std::string& path, mode_t mode, uid_t uid, gid_t gid)
1041{
1042 std::vector<std::string> parts = Split_String(path, "/");
1043 std::string cur_path;
1044 struct stat info;
Matt Mowera8a89d12016-12-30 18:10:37 -06001045 for (size_t i = 0; i < parts.size(); ++i)
Vojtech Bocek03fd6c52014-03-13 18:46:34 +01001046 {
1047 cur_path += "/" + parts[i];
Matt Mowera8a89d12016-12-30 18:10:37 -06001048 if (stat(cur_path.c_str(), &info) < 0 || !S_ISDIR(info.st_mode))
Vojtech Bocek03fd6c52014-03-13 18:46:34 +01001049 {
Matt Mowera8a89d12016-12-30 18:10:37 -06001050 if (mkdir(cur_path.c_str(), mode) < 0)
Vojtech Bocek03fd6c52014-03-13 18:46:34 +01001051 return false;
1052 chown(cur_path.c_str(), uid, gid);
1053 }
1054 }
1055 return true;
1056}
1057
xNUTxe85f02d2014-07-18 01:30:58 +02001058int TWFunc::Set_Brightness(std::string brightness_value)
1059{
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +09001060 int result = -1;
1061 std::string secondary_brightness_file;
xNUTxe85f02d2014-07-18 01:30:58 +02001062
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +09001063 if (DataManager::GetIntValue("tw_has_brightnesss_file")) {
xNUTxe85f02d2014-07-18 01:30:58 +02001064 LOGINFO("TWFunc::Set_Brightness: Setting brightness control to %s\n", brightness_value.c_str());
Ethan Yonker6e8c27a2016-12-22 17:55:57 -06001065 result = TWFunc::write_to_file(DataManager::GetStrValue("tw_brightness_file"), brightness_value);
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +09001066 DataManager::GetValue("tw_secondary_brightness_file", secondary_brightness_file);
1067 if (!secondary_brightness_file.empty()) {
1068 LOGINFO("TWFunc::Set_Brightness: Setting secondary brightness control to %s\n", brightness_value.c_str());
Ethan Yonker6e8c27a2016-12-22 17:55:57 -06001069 TWFunc::write_to_file(secondary_brightness_file, brightness_value);
xNUTxe85f02d2014-07-18 01:30:58 +02001070 }
xNUTxe85f02d2014-07-18 01:30:58 +02001071 }
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +09001072 return result;
xNUTxe85f02d2014-07-18 01:30:58 +02001073}
1074
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001075bool TWFunc::Toggle_MTP(bool enable) {
1076#ifdef TW_HAS_MTP
1077 static int was_enabled = false;
1078
1079 if (enable && was_enabled) {
1080 if (!PartitionManager.Enable_MTP())
1081 PartitionManager.Disable_MTP();
1082 } else {
1083 was_enabled = DataManager::GetIntValue("tw_mtp_enabled");
1084 PartitionManager.Disable_MTP();
1085 usleep(500);
1086 }
1087 return was_enabled;
1088#else
1089 return false;
1090#endif
1091}
1092
Tom Hite5a926722014-09-15 01:31:03 +00001093void TWFunc::SetPerformanceMode(bool mode) {
1094 if (mode) {
1095 property_set("recovery.perf.mode", "1");
1096 } else {
1097 property_set("recovery.perf.mode", "0");
1098 }
1099 // Some time for events to catch up to init handlers
1100 usleep(500000);
1101}
1102
Jenkins1710bf22014-10-02 20:22:21 -04001103std::string TWFunc::to_string(unsigned long value) {
1104 std::ostringstream os;
1105 os << value;
1106 return os.str();
1107}
1108
Ethan Yonker9132d912015-02-02 10:32:49 -06001109void TWFunc::Disable_Stock_Recovery_Replace(void) {
Captain Throwback9d6feb52018-07-27 10:05:24 -04001110 if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), false)) {
Ethan Yonker9132d912015-02-02 10:32:49 -06001111 // Disable flashing of stock recovery
1112 if (TWFunc::Path_Exists("/system/recovery-from-boot.p")) {
1113 rename("/system/recovery-from-boot.p", "/system/recovery-from-boot.bak");
Ethan Yonker74db1572015-10-28 12:44:49 -05001114 gui_msg("rename_stock=Renamed stock recovery file in /system to prevent the stock ROM from replacing TWRP.");
Ethan Yonker9132d912015-02-02 10:32:49 -06001115 sync();
1116 }
Captain Throwback9d6feb52018-07-27 10:05:24 -04001117 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
Ethan Yonker9132d912015-02-02 10:32:49 -06001118 }
1119}
1120
Ethan Yonker483e9f42016-01-11 22:21:18 -06001121unsigned long long TWFunc::IOCTL_Get_Block_Size(const char* block_device) {
1122 unsigned long block_device_size;
1123 int ret = 0;
1124
1125 int fd = open(block_device, O_RDONLY);
1126 if (fd < 0) {
1127 LOGINFO("Find_Partition_Size: Failed to open '%s', (%s)\n", block_device, strerror(errno));
1128 } else {
1129 ret = ioctl(fd, BLKGETSIZE, &block_device_size);
1130 close(fd);
1131 if (ret) {
1132 LOGINFO("Find_Partition_Size: ioctl error: (%s)\n", strerror(errno));
1133 } else {
1134 return (unsigned long long)(block_device_size) * 512LLU;
1135 }
1136 }
1137 return 0;
1138}
1139
bigbiff bigbiffbad332a2016-07-29 21:18:13 -04001140void TWFunc::copy_kernel_log(string curr_storage) {
1141 std::string dmesgDst = curr_storage + "/dmesg.log";
1142 std::string dmesgCmd = "/sbin/dmesg";
1143
1144 std::string result;
1145 Exec_Cmd(dmesgCmd, result);
Ethan Yonker6e8c27a2016-12-22 17:55:57 -06001146 write_to_file(dmesgDst, result);
bigbiff bigbiffbad332a2016-07-29 21:18:13 -04001147 gui_msg(Msg("copy_kernel_log=Copied kernel log to {1}")(dmesgDst));
1148 tw_set_default_metadata(dmesgDst.c_str());
1149}
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -04001150
1151bool TWFunc::isNumber(string strtocheck) {
1152 int num = 0;
1153 std::istringstream iss(strtocheck);
1154
1155 if (!(iss >> num).fail())
1156 return true;
1157 else
1158 return false;
1159}
1160
1161int TWFunc::stream_adb_backup(string &Restore_Name) {
1162 string cmd = "/sbin/bu --twrp stream " + Restore_Name;
1163 LOGINFO("stream_adb_backup: %s\n", cmd.c_str());
1164 int ret = TWFunc::Exec_Cmd(cmd);
1165 if (ret != 0)
1166 return -1;
1167 return ret;
1168}
bigbiff bigbiff19874f12019-01-08 20:06:57 -05001169
1170std::string TWFunc::get_cache_dir() {
1171 if (PartitionManager.Find_Partition_By_Path(NON_AB_CACHE_DIR) == NULL) {
1172 return AB_CACHE_DIR;
1173 }
1174 else {
1175 return NON_AB_CACHE_DIR;
1176 }
1177}
1178
1179void TWFunc::check_selinux_support() {
1180 if (TWFunc::Path_Exists("/prebuilt_file_contexts")) {
1181 if (TWFunc::Path_Exists("/file_contexts")) {
1182 printf("Renaming regular /file_contexts -> /file_contexts.bak\n");
1183 rename("/file_contexts", "/file_contexts.bak");
1184 }
1185 printf("Moving /prebuilt_file_contexts -> /file_contexts\n");
1186 rename("/prebuilt_file_contexts", "/file_contexts");
1187 }
1188 struct selinux_opt selinux_options[] = {
1189 { SELABEL_OPT_PATH, "/file_contexts" }
1190 };
1191 selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
1192 if (!selinux_handle)
1193 printf("No file contexts for SELinux\n");
1194 else
1195 printf("SELinux contexts loaded from /file_contexts\n");
1196 { // Check to ensure SELinux can be supported by the kernel
1197 char *contexts = NULL;
1198 std::string cacheDir = TWFunc::get_cache_dir();
1199 std::string se_context_check = cacheDir + "recovery/";
1200 int ret = 0;
1201
1202 if (cacheDir == NON_AB_CACHE_DIR) {
1203 PartitionManager.Mount_By_Path(NON_AB_CACHE_DIR, false);
1204 }
1205 if (TWFunc::Path_Exists(se_context_check)) {
1206 ret = lgetfilecon(se_context_check.c_str(), &contexts);
1207 if (ret > 0) {
1208 lsetfilecon(se_context_check.c_str(), "test");
1209 lgetfilecon(se_context_check.c_str(), &contexts);
1210 } else {
1211 LOGINFO("Could not check %s SELinux contexts, using /sbin/teamwin instead which may be inaccurate.\n", se_context_check.c_str());
1212 lgetfilecon("/sbin/teamwin", &contexts);
1213 }
1214 }
1215 if (ret < 0) {
1216 gui_warn("no_kernel_selinux=Kernel does not have support for reading SELinux contexts.");
1217 } else {
1218 free(contexts);
1219 gui_msg("full_selinux=Full SELinux support is present.");
1220 }
1221 }
1222}
Ethan Yonkeraf2897c2014-02-10 13:07:14 -06001223#endif // ndef BUILD_TWRPTAR_MAIN