This repository has been archived on 2017-04-03. You can view files and clone it, but cannot push or open issues/pull-requests.
blog_post_tests/20130404080410.blog

10 lines
3.2 KiB
Plaintext

No, GPSD is not the battery-killer on your Android!
<p>Today, while doing research to answer some bug mail, I learned that all versions of Android since 4.0 (Ice Cream Sandwich) have used gpsd to read the take from the onboard GPS. Sadly, gpsd is getting blamed in some quarters for excessive battery drain. But it&#8217;s not gpsd&#8217;s fault! Here is what&#8217;s actually going on.</p>
<p><span id="more-4886"></span></p>
<p>Activating the onboard GPS in your phone eats power. Normally, Android economizes by computing a rough location from signal-tower strengths, information it gathers anyway in normal operation. To get a more precise fix, an app (such as Google Maps) can request &#8220;Detailed Location&#8221;. This is what is happening when the GPS icon appears on your status bar.</p>
<p>Requesting &#8220;Detailed Location&#8221; wakes up gpsd, causing it to power up the on-board GPS and begin interpreting the NMEA data stream it ships. Somewhere in Android&#8217;s Java code (I don&#8217;t know the details), the reports from gpsd are captured and made available to the Java API that apps can see. Normally this mode is a little expensive, mainly because of the power cost of running the GPS hardware; this is why Android doesn&#8217;t keep the GPS powered up all the time. Normally the gpsd demon itself is very economical; we&#8217;ve measured its processor utilization on low-power ARM chips and it&#8217;s below the noise floor of the process monitor. As it should be; the data rate from a GPS isn&#8217;t very high, there&#8217;s simply no <em>reason</em> for gpsd to spend a lot of cycles. </p>
<p>Nevertheless, instances of excessive battery drain have been reported with the system monitor fingering gpsd as the culprit, especially on the Samsung Galaxy SIII. In some cases this happens when the onboard GPS is powered off. In every case I&#8217;ve found through Googling for &#8220;Android gpsd&#8221;, the actual bad guy is an app that is both requesting Detailed Location and running in background; if you deinstall the app, the battery drain goes away. (On the Galaxy SIII, the &#8216;app&#8217; may actually be the &#8220;Remote Location Service&#8221; in the vendor firmware; you can&#8217;t remove it, but you can disable it through Settings.)</p>
<p>I suspect that there&#8217;s something else going on here. The fact that gpsd is reported to be processor-hogging when the GPS is powered off suggests that it&#8217;s spinning on its main select(2) call. We&#8217;ve occasionally seen behavior like this before, and it has always been down to some bug or misconfiguration in the Linux kernel&#8217;s serial I/O layer (gpsd exercises that layer in some unusual ways). This is consistent with the relative rareness of the bug; likely it&#8217;s only happening on a couple of specific phone models. If <em>every</em> background app using the GPS caused this problem, I&#8217;d have had a mob of pitchfork-wielding peasants at my castle door long since&#8230;</p>
<p>TL;DR: It&#8217;s not gpsd&#8217;s fault &#8211; find the buggy app and remove it.</p>
<p>All this having been said, why, yes I do think it&#8217;s seriously cool that gpsd is running in all newer Android phones. My code is ubiquitous and inescapable, bwahahahaha! But you knew that already.</p>