Well, it may be just as slow. I’ve seen systems where starting a shell is slow.
I don't know the "pidof" of "dumpsys" commands, as those are likely some Android-specific thing and not general Unix stuff, but that’s not really material here.
I know nothing about the Android kernel, but it may make soft real-time guarantees of some sort, or not run a normal context-switcher.
> Bob, you were 100% correct. The majority of time is taken up by android to startup the shell. In my case it takes ~1005 milliseconds to run an empty shell and just additional 4-7 milliseconds to execute the statements.
It probably doesn’t matter which is the first command run: it will always be slowest due to some latency involved in starting up a new process of this sort.
That will append a copy of the output produced by cmd into the named file while continuing to pass along what it found to the next pipeline phase as though nothing had gotten in the way.
@tchrist The purpose of all this is for Android to automatically allow the location permission whenever I am actually using Google Maps, and restrict it again when the application is no longer in the foreground.
(I need to know the PID of the foreground application in order to modify Xprivacy's database, so that Xprivacy will give and take the permission automatically.)
@tchrist Perhaps the reason he chose mCurrentApp because it contains the PID, whereas mFocusedApp does not. But I can convert the com.google.android.apps.maps thingy into the PID with some other command, so perhaps that would be more reliable.
OK, so basically, you can't get the PID of the focused window when there is no focused window. Seems reasonable enough. Now, when isn't there a focused window in android?
Yes, [it seems to be POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html) : "FS Input field separator regular expression; a <space> by default."
@Cerberus Ah. That does complicate things. OK, let's make it either/or then. Hang on.
@Cerberus can you show me an example of the output of dumpsys window windows for each case? I mean one where mCurrentFocus=null and one where mFocusedApp is?