kernel: count time of volumedown to enter safemode
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
#include "linux/version.h"
|
#include "linux/version.h"
|
||||||
#include "linux/workqueue.h"
|
#include "linux/workqueue.h"
|
||||||
#include "linux/input.h"
|
#include "linux/input.h"
|
||||||
#include "linux/time64.h"
|
|
||||||
|
|
||||||
#include "allowlist.h"
|
#include "allowlist.h"
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
@@ -192,13 +191,10 @@ int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const time64_t UNINITIALIZED = -1;
|
static unsigned int volumedown_pressed_count = 0;
|
||||||
static time64_t last_vol_down_pressed = UNINITIALIZED;
|
|
||||||
static time64_t last_vol_down_release = UNINITIALIZED;
|
|
||||||
|
|
||||||
static bool is_time_initialized(time64_t t)
|
static bool is_volumedown_enough(unsigned int count) {
|
||||||
{
|
return count >= 3;
|
||||||
return t != UNINITIALIZED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code,
|
int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code,
|
||||||
@@ -213,20 +209,12 @@ int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code,
|
|||||||
int val = *value;
|
int val = *value;
|
||||||
pr_info("KEY_VOLUMEDOWN val: %d\n", val);
|
pr_info("KEY_VOLUMEDOWN val: %d\n", val);
|
||||||
if (val) {
|
if (val) {
|
||||||
// key pressed
|
// key pressed, count it
|
||||||
last_vol_down_pressed = ktime_get_seconds();
|
volumedown_pressed_count += 1;
|
||||||
} else {
|
if (is_volumedown_enough(volumedown_pressed_count)) {
|
||||||
// key released
|
|
||||||
if (is_time_initialized(last_vol_down_pressed)) {
|
|
||||||
last_vol_down_release = ktime_get_seconds();
|
|
||||||
// when released, stop hook
|
|
||||||
stop_input_hook();
|
stop_input_hook();
|
||||||
} else {
|
|
||||||
pr_info("KEY_VOLUMEDOWN released, but not pressed yet\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pr_info("last_vol_down_pressed: %ld, last_vol_down_release: %ld\n",
|
|
||||||
last_vol_down_pressed, last_vol_down_release);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -243,27 +231,10 @@ bool ksu_is_safe_mode() {
|
|||||||
// stop hook first!
|
// stop hook first!
|
||||||
stop_input_hook();
|
stop_input_hook();
|
||||||
|
|
||||||
pr_info("ksu_is_safe_mode last_vol_down_pressed: %ld, last_vol_down_release: %ld\n",
|
pr_info("volumedown_pressed_count: %d\n", volumedown_pressed_count);
|
||||||
last_vol_down_pressed, last_vol_down_release);
|
if (is_volumedown_enough(volumedown_pressed_count)) {
|
||||||
if (!is_time_initialized(last_vol_down_pressed)) {
|
// pressed over 3 times
|
||||||
// not pressed yet
|
pr_info("KEY_VOLUMEDOWN pressed max times, safe mode detected!\n");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// vol down pressed
|
|
||||||
time64_t vol_down_time;
|
|
||||||
if (!is_time_initialized(last_vol_down_release)) {
|
|
||||||
// not released yet, use current time
|
|
||||||
vol_down_time = ktime_get_seconds();
|
|
||||||
} else {
|
|
||||||
vol_down_time = last_vol_down_release;
|
|
||||||
}
|
|
||||||
|
|
||||||
pr_info("ksu_is_safe_mode vol_down_time: %ld, last_vol_down_pressed: %ld\n",
|
|
||||||
vol_down_time, last_vol_down_pressed);
|
|
||||||
if (vol_down_time - last_vol_down_pressed >= 2) {
|
|
||||||
// pressed over 2 seconds
|
|
||||||
pr_info("KEY_VOLUMEDOWN pressed over 2 seconds, safe mode detected!\n");
|
|
||||||
safe_mode = true;
|
safe_mode = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user