{"id":207,"date":"2007-12-10T07:00:26","date_gmt":"2007-12-10T12:00:26","guid":{"rendered":"http:\/\/www.nynaeve.net\/?p=207"},"modified":"2019-12-13T17:43:57","modified_gmt":"2019-12-13T22:43:57","slug":"how-not-to-write-code-for-a-mobile-device","status":"publish","type":"post","link":"http:\/\/www.nynaeve.net\/?p=207","title":{"rendered":"How to not write code for a mobile device"},"content":{"rendered":"<p>Earlier this week, I got a shiny, brand-new <a title=\"XV6800\" href=\"http:\/\/reviews.cnet.com\/smartphones\/utstarcom-xv6800-verizon-wireless\/4507-6452_7-32774849.html?tag=specs\">XV6800<\/a> to replace my aging (and rather limited in terms of running user-created programs) BREW-ified phone.<\/p>\n<p>After setting up ActiveSync, IPsec, and all of the other usual required configuration settings, the next step was, of course, to install the baseline minimum set of applications on the device to get by.  Close to the top of this list is an SSH client (being able to project arbitrary console programs over SSH and <em>screen<\/em> to the device is, at the very least, a workable enough solution in the interm for programs that are not feasible to run directly on the device, such as my <a title=\"SILC\" href=\"http:\/\/silcnet.org\/\">SILC client<\/a>).  I&#8217;ve found <a title=\"PuTTY\"  href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/\">PuTTY<\/a> a fairly acceptable client for &#8220;big Windows&#8221;, and there just so happened to be a <a title=\"PocketPuTTY\" href=\"http:\/\/www.pocketputty.net\/\">Windows Mobile port<\/a> of it.  Great, or so I thought&#8230;<\/p>\n<p>While PocketPuTTY does <em>technically<\/em> work, I noticed a couple of deficiencies with it pretty quickly:<\/p>\n<ol>\n<li>The page up \/ page down keys are treated the same as the up arrow \/ down arrow keys when sent to the remote system.  This sucks, because I can&#8217;t access my scrollback buffer in SILC easily without page up \/ page down.  Other applications can tell the difference between the two keys (obviously, or there wouldn&#8217;t be much of a point to having the keys at all), so this one is clearly a PocketPuTTY bug.<\/li>\n<li>There is no way to restart a session once it is closed, or at least, not that I&#8217;ve found.  Normally, on &#8220;big Windows&#8221;, there&#8217;s a &#8220;Restart Session&#8221; menu option in the window menu of the PuTTy session, but (as far as I can tell) there&#8217;s no such equivalent to the window menu on PocketPuTTY.  There is a &#8220;Tools&#8221; menu, although it has some rather useless menu items (e.g. <em>About<\/em>) instead of some actually <em>useful<\/em> menu items, like &#8220;Restart Session&#8221;.<\/li>\n<li>Running PocketPuTTY seems to have a significantly negative effect on battery life.  This is really unfortunate for me, since the expected use is to leave an SSH session to a terminal running <em>screen<\/em> for a long period of time.  (<em>Note that this was resolved, partially, by locating a slightly more maintained copy of PocketPuTTY<\/em>.)<\/li>\n<li>SSH port forward support seems to be fairly broken, in that as soon as a socket is cleaned up, all receives in the process break until you restart it.  This is annoying, but workable if one can go without SSH port forwards.<\/li>\n<\/ol>\n<p>Most of these problems are actually not all that difficult to fix, and since the source code is available, I&#8217;m actually planning on trying my hand at doing just that, since I expect that this is an app that I&#8217;ll make fairly heavy use of.<\/p>\n<p>The latter problem is one I really want to call attention to among these deficiencies, however.  My intent here is not to bash the PocketPuTTY folks (and I&#8217;m certainly happy that they&#8217;ve at least gotten a (semi)-working port of PuTTY with source code out, so that other people can improve on it from there), but rather to point out some things that should really just not be done when you&#8217;re writing code that is intended to run on a mobile device (<em>especially<\/em> if the code is intended to run <em>exclusively<\/em> on a mobile device).<\/p>\n<p>On a portable device, one of the things that most users really expect is <em>long battery life<\/em>.  Though this particular point certainly holds true for laptops as well, it is arguably even more important that for converged mobile phone devices.  After all, most people consider their phone an &#8220;always on&#8221; contact mechanism, and unexpectedly running out of battery life is extremely annoying in this aspect.  Furthermore, if your mobile phone has the capability to run all sorts of useful programs on it, but doing so eats up your battery in a couple of hours, then there is really not that much point in having that capability at all, is there?<\/p>\n<p>Returning to PocketPuTTY, one of the main problems (at least with the version I initially used) was, again, that PocketPuTTY would reduce battery life significantly.  Looking around in the source code for possible causes, I noticed <a title=\"Old PocketPuTTY Network Reader Thread\" href=\"http:\/\/www.nynaeve.net\/Code\/pocketputty-old-netloop.c\">the following gem<\/a>,  which turned out to be the core of the network read loop for the program.<\/p>\n<p>Yes, there <em>really is<\/em> a <em>Sleep(1)<\/em> spin loop in there, in a software port that is <em>designed to run on battery powered devices<\/em>.  For starters, that blows any sort of processor power management completely out of the water.  Mobile devices have a lot of different components vying for power, and the easiest (and most effective) way to <em>save<\/em> on power (and thus battery life) is to <em>not turn those components on<\/em>.  Of course, it becomes difficult to do that for power hungry components like the 400MHz CPU in my XV6800 if there&#8217;s a program that has an always-ready-to-run thread&#8230;<\/p>\n<p>Fortunately, there happened to be a newer revision of PocketPuTTY floating about with the issue fixed (although getting ahold of the source code for that version proved to be slightly more difficult, as the original maintainer of the project seems to have disappeared).  I did eventually manage to get into contact with someone who had been maintaining their own set of improvements and grab a not-so-crusty-old source tree from them to do my own improvements, primarily for the purposes of fixing some of the annoyances I mentioned previously (thus beginning my initial forey into Windows CE development).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier this week, I got a shiny, brand-new XV6800 to replace my aging (and rather limited in terms of running user-created programs) BREW-ified phone. After setting up ActiveSync, IPsec, and all of the other usual required configuration settings, the next step was, of course, to install the baseline minimum set of applications on the device [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,4,5],"tags":[35,36],"_links":{"self":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/207"}],"collection":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=207"}],"version-history":[{"count":2,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":514,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions\/514"}],"wp:attachment":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}