From ebb5d060ae588b21c428f85b5ffffc50d388f9aa Mon Sep 17 00:00:00 2001 From: Katharine Chui Date: Fri, 29 Dec 2023 17:45:05 +0800 Subject: [PATCH] ANDROID: ag x86: disable wake alarms On x86 platforms, especially laptops, it might make sense to never wake device up just to fetch notifications, or perform other tasks that android would wake device up for Andorid does not seem to currently use the posix timer_create entry point, but changing that too for completness, disabling alarms from userspace --- fs/timerfd.c | 9 +++++++++ kernel/time/posix-timers.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/fs/timerfd.c b/fs/timerfd.c index de8e736bbf7bb..492fb46fa40e4 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -415,6 +415,15 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC); BUILD_BUG_ON(TFD_NONBLOCK != O_NONBLOCK); + // disabling alarms for android on x86 platforms + // doing it in a way that won't cause errors in frameworks/base/apex/jobscheduler/service/jni/com_android_server_alarm_AlarmManagerService.cpp + if(clockid == CLOCK_REALTIME_ALARM){ + clockid = CLOCK_REALTIME; + } + if(clockid == CLOCK_BOOTTIME_ALARM){ + clockid = CLOCK_BOOTTIME; + } + if ((flags & ~TFD_CREATE_FLAGS) || (clockid != CLOCK_MONOTONIC && clockid != CLOCK_REALTIME && diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index ed3c4a9543982..d682a1423449c 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -498,6 +498,12 @@ static int common_timer_create(struct k_itimer *new_timer) static int do_timer_create(clockid_t which_clock, struct sigevent *event, timer_t __user *created_timer_id) { + if(which_clock == CLOCK_REALTIME_ALARM){ + which_clock = CLOCK_REALTIME; + } + if(which_clock == CLOCK_BOOTTIME_ALARM){ + which_clock = CLOCK_BOOTTIME; + } const struct k_clock *kc = clockid_to_kclock(which_clock); struct k_itimer *new_timer; int error, new_timer_id;