Add option to shutdown the device from trampoline_encmnt
This commit is contained in:
@@ -561,3 +561,8 @@ int ncard_try_cancel(void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ncard_is_visible(void)
|
||||
{
|
||||
return ncard.bg != NULL;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ typedef struct
|
||||
ncard_callback callback;
|
||||
} ncard_builder_btn;
|
||||
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
char *title;
|
||||
char *text;
|
||||
@@ -71,6 +71,7 @@ void ncard_set_from_black(ncard_builder *b, int from_black);
|
||||
void ncard_set_top_offset(int offset);
|
||||
void ncard_show(ncard_builder *b, int destroy_builder);
|
||||
void ncard_hide(void);
|
||||
int ncard_is_visible(void);
|
||||
int ncard_try_cancel(void);
|
||||
void ncard_hide_callback(void *data);
|
||||
void ncard_destroy_builder(ncard_builder *b);
|
||||
|
||||
26
lib/util.c
26
lib/util.c
@@ -24,6 +24,7 @@
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <cutils/android_reboot.h>
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
#include <selinux/label.h>
|
||||
@@ -733,3 +734,28 @@ int mount_image(const char *src, const char *dst, const char *fs, int flags, con
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void do_reboot(int type)
|
||||
{
|
||||
sync();
|
||||
emergency_remount_ro();
|
||||
|
||||
switch(type)
|
||||
{
|
||||
default:
|
||||
case REBOOT_SYSTEM:
|
||||
android_reboot(ANDROID_RB_RESTART, 0, 0);
|
||||
break;
|
||||
case REBOOT_RECOVERY:
|
||||
android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
|
||||
break;
|
||||
case REBOOT_BOOTLOADER:
|
||||
android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
|
||||
break;
|
||||
case REBOOT_SHUTDOWN:
|
||||
android_reboot(ANDROID_RB_POWEROFF, 0, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
#define REBOOT_SYSTEM 0
|
||||
#define REBOOT_RECOVERY 1
|
||||
#define REBOOT_BOOTLOADER 2
|
||||
#define REBOOT_SHUTDOWN 3
|
||||
|
||||
time_t gettime(void);
|
||||
unsigned int decode_uid(const char *s);
|
||||
int mkdir_recursive(const char *pathname, mode_t mode);
|
||||
@@ -49,6 +54,7 @@ inline int64_t timeval_us_diff(struct timeval now, struct timeval prev);
|
||||
void emergency_remount_ro(void);
|
||||
int create_loop_device(const char *dev_path, const char *img_path, int loop_num, int loop_chmod);
|
||||
int mount_image(const char *src, const char *dst, const char *fs, int flags, const void *data);
|
||||
void do_reboot(int type);
|
||||
|
||||
inline int imin(int a, int b);
|
||||
inline int imax(int a, int b);
|
||||
|
||||
25
main.c
25
main.c
@@ -36,18 +36,6 @@
|
||||
#define KEEP_REALDATA "/dev/.keep_realdata"
|
||||
#define REALDATA "/realdata"
|
||||
|
||||
static void do_reboot(int exit)
|
||||
{
|
||||
sync();
|
||||
umount(REALDATA);
|
||||
|
||||
if(exit & EXIT_REBOOT_RECOVERY) android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
|
||||
else if(exit & EXIT_REBOOT_BOOTLOADER) android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
|
||||
else if(exit & EXIT_SHUTDOWN) android_reboot(ANDROID_RB_POWEROFF, 0, 0);
|
||||
else android_reboot(ANDROID_RB_RESTART, 0, 0);
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
static void do_kexec(void)
|
||||
{
|
||||
@@ -102,11 +90,14 @@ int main(int argc, const char *argv[])
|
||||
|
||||
if(exit >= 0)
|
||||
{
|
||||
if(exit & EXIT_REBOOT_MASK)
|
||||
{
|
||||
do_reboot(exit);
|
||||
return 0;
|
||||
}
|
||||
if(exit & EXIT_REBOOT_RECOVERY)
|
||||
do_reboot(REBOOT_RECOVERY);
|
||||
else if(exit & EXIT_REBOOT_BOOTLOADER)
|
||||
do_reboot(REBOOT_BOOTLOADER);
|
||||
else if(exit & EXIT_SHUTDOWN)
|
||||
do_reboot(REBOOT_SHUTDOWN);
|
||||
else if(exit & EXIT_REBOOT)
|
||||
do_reboot(REBOOT_SYSTEM);
|
||||
|
||||
if(exit & EXIT_KEXEC)
|
||||
{
|
||||
|
||||
@@ -238,7 +238,7 @@ static inline void type_pattern_connect_dot(struct pwui_type_pattern_data *d, i
|
||||
{
|
||||
if(d->connected_dots_len >= PWUI_DOTS_CNT)
|
||||
{
|
||||
ERROR("d->connected_dots_len overflowed PWUI_DOTS_CNT!");
|
||||
ERROR("d->connected_dots_len overflowed PWUI_DOTS_CNT!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -379,6 +379,8 @@ static void init_ui(int pwtype)
|
||||
{
|
||||
fb_add_rect_lvl(100, 0, 0, fb_width, HEADER_HEIGHT, C_HIGHLIGHT_BG);
|
||||
|
||||
ncard_set_top_offset(HEADER_HEIGHT);
|
||||
|
||||
fb_text_proto *p = fb_text_create(0, 0, C_HIGHLIGHT_TEXT, SIZE_EXTRA, "Encrypted device");
|
||||
p->level = 110;
|
||||
fb_text *t = fb_text_finalize(p);
|
||||
@@ -436,11 +438,25 @@ static void destroy_ui(int pwtype)
|
||||
button_destroy(boot_primary_btn);
|
||||
}
|
||||
|
||||
static int pw_ui_shutdown_counter_touch_handler(touch_event *ev, void *data)
|
||||
{
|
||||
int *shutdown_counter = data;
|
||||
if(*shutdown_counter == 0)
|
||||
return -1;
|
||||
|
||||
ncard_hide();
|
||||
|
||||
*shutdown_counter = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pw_ui_run(int pwtype)
|
||||
{
|
||||
int shutdown_counter = 0;
|
||||
|
||||
if(fb_open(0) < 0)
|
||||
{
|
||||
ERROR("Failed to open framebuffer");
|
||||
ERROR("Failed to open framebuffer\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -453,6 +469,7 @@ int pw_ui_run(int pwtype)
|
||||
init_ui(pwtype);
|
||||
|
||||
start_input_thread();
|
||||
add_touch_handler(pw_ui_shutdown_counter_touch_handler, &shutdown_counter);
|
||||
|
||||
fb_freeze(0);
|
||||
|
||||
@@ -462,7 +479,8 @@ int pw_ui_run(int pwtype)
|
||||
a->on_finished_data = r;
|
||||
call_anim_add(a);
|
||||
|
||||
while(1) {
|
||||
while(1)
|
||||
{
|
||||
pthread_mutex_lock(&exit_code_mutex);
|
||||
const int c = exit_code;
|
||||
pthread_mutex_unlock(&exit_code_mutex);
|
||||
@@ -470,6 +488,25 @@ int pw_ui_run(int pwtype)
|
||||
if(c != ENCMNT_UIRES_ERROR)
|
||||
break;
|
||||
|
||||
if(get_last_key() == KEY_POWER && (!ncard_is_visible() || shutdown_counter))
|
||||
{
|
||||
++shutdown_counter;
|
||||
if(shutdown_counter == 1)
|
||||
{
|
||||
ncard_builder *b = ncard_create_builder();
|
||||
ncard_set_text(b, "Press power button again to shut down the device.");
|
||||
ncard_show(b, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncard_builder *b = ncard_create_builder();
|
||||
ncard_set_pos(b, NCARD_POS_CENTER);
|
||||
ncard_set_text(b, "Shutting down...");
|
||||
ncard_show(b, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
@@ -477,11 +514,16 @@ int pw_ui_run(int pwtype)
|
||||
fb_freeze(1);
|
||||
fb_force_draw();
|
||||
|
||||
rm_touch_handler(pw_ui_shutdown_counter_touch_handler, &shutdown_counter);
|
||||
|
||||
stop_input_thread();
|
||||
workers_stop();
|
||||
|
||||
destroy_ui(pwtype);
|
||||
|
||||
if(shutdown_counter == 2)
|
||||
do_reboot(REBOOT_SHUTDOWN);
|
||||
|
||||
fb_clear();
|
||||
fb_close();
|
||||
return exit_code;
|
||||
|
||||
Reference in New Issue
Block a user