Thanks for the information hemanth. 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. On Nov 18, 5:58 am, Hemanth(ヘマント) <[email protected]> wrote: > Ah, I type faster than I read.You explicitly stated that you are > looking for something in the kernel to do it! > > 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 <[email protected]> wrote: > > > > > > > > > Hi, > > I want to detect the currently executing foreground app. If the > > foreground app is say "email" then perform some tasks. > > I tried doing this from within the android frame work. However, the > > only way to do it is using Activity Manager and checking the running > > tasks periodically from a background service. However, running this > > background service periodically will not be good as it will consume > > battery and might hog the cpu if the check period is low. > > > Instead of doing it from the android framework, is there any way I can > > do this from within the kernel? > > I can check the list of tasks in the run-queue. I can also check what > > task is being context-switched in. > > However, even while an app is running it will be getting context- > > switched in and out. Hence I will have to differentiate the context- > > switch in for the first time and the context-switches occurring during > > the execution of the application. > > Can anyone give me some feedback on this. > > > Thanks. -- unsubscribe: [email protected] website: http://groups.google.com/group/android-kernel
