I think doing this from the kernel is actually more difficult.
Ultimately, it might be simpler and faster to use the framework to
lookup the foreground process.
Implemented well, it should not be much of a drain on the battery.
Also it might be better to look for the foreground app only when the
screen is on (depending on your usecase)
However there is the problem that you might be responding to the
change in the foreground app a bit late, depending on your check
period.
Compared to the alternative of modifying the framework or the kernel
it seems to be minimally invasive, and probably good enough?
As for using the kernel, as far as I know there is not easy way of
getting context switch information without enabling some debug flags
for the kernel, which would probably be a bad idea because of
performance and code size increase.
On Nov 16, 12:22 am, Bateman <7thharmo...@gmail.com> wrote:
Doing a periodic check using a background service might be a drain on
the battery and also will introduce a latency in detecting the
foreground app.
I in fact prefer hacking the kernel. I have looked at sched.c and
sched.h, however I have not yet found any flag that denotes an app as
foreground or background.
Any information will be helpful.
Thanks.