<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>freedom blog reloaded &#187; Android</title>
	<atom:link href="http://blog.peijnik.at/topics/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.peijnik.at</link>
	<description>Stephan's Free Software blog</description>
	<lastBuildDate>Tue, 10 Nov 2009 18:04:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android&#8217;s roaming detection &amp; its implementation</title>
		<link>http://blog.peijnik.at/2009/11/08/androids-roaming-detection-its-implementation/</link>
		<comments>http://blog.peijnik.at/2009/11/08/androids-roaming-detection-its-implementation/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 19:04:32 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[gsoc]]></category>

		<guid isPermaLink="false">http://blog.peijnik.at/?p=173</guid>
		<description><![CDATA[I know I wrote about Android already today, but there is another thing that concerns me right now. I am owner of an Android-based phone (an HTC Dream) and recently switched my mobile network provider. The problem is that my new provider is a virtual provider and as such there is no real network of [...]]]></description>
			<content:encoded><![CDATA[<p>I know I wrote about Android already today, but there is another thing that concerns me right now. I am owner of an Android-based phone (an HTC Dream) and recently switched my mobile network provider. The problem is that my new provider is a <a href="http://en.wikipedia.org/wiki/Mobile_Virtual_Network_Operator">virtual provider</a> and as such there is no real network of that provider. Now Android has a feature to turn off broadband connections when in roaming mode, which itself is a great idea and can save you from paying quite a lot of money when the phone connects to 3G abroad, but this feature also turns off broadband connections when roaming locally. All this is being discussed in bug report <a href="http://code.google.com/p/android/issues/detail?id=3499">#3499</a>.</p>
<p>After noticing this problem I became curious on how Android detects that it is roaming and I found the GsmServiceStateTracker.isRoamingBetweenOperators method to be responsible for that magic, but soon noticed that the method is not only inefficient, but also doesn&#8217;t work as intended. This is hardly related to the bug mentioned above, but let&#8217;s have a look at the code in question:</p>
<pre name="code" class="java">/**
* Set roaming state when gsmRoaming is true and, if operator mcc is the
* same as sim mcc, ons is different from spn
* @param gsmRoaming TS 27.007 7.2 CREG registered roaming
* @param s ServiceState hold current ons
* @return true for roaming state set
*/
    private
    boolean isRoamingBetweenOperators(boolean gsmRoaming, ServiceState s) {
        String spn = SystemProperties.get(PROPERTY_ICC_OPERATOR_ALPHA, "empty");

        String onsl = s.getOperatorAlphaLong();
        String onss = s.getOperatorAlphaShort();

        boolean equalsOnsl = onsl != null &amp;&amp; spn.equals(onsl);
        boolean equalsOnss = onss != null &amp;&amp; spn.equals(onss);

        String simNumeric = SystemProperties.get(PROPERTY_ICC_OPERATOR_NUMERIC, "");
        String operatorNumeric = s.getOperatorNumeric();

        boolean equalsMcc = true;
        try {
            equalsMcc = simNumeric.substring(0, 3).
                    equals(operatorNumeric.substring(0, 3));
        } catch (Exception e){
        }

        return gsmRoaming &amp;&amp; !(equalsMcc &amp;&amp; (equalsOnsl || equalsOnss));
    }</pre>
<p>Okay, let me summarize what this piece of code does wrong, at least from my understanding:</p>
<ul>
<li>It takes both the network operator alphanumeric identifier and alphanumeric long identifier and compares both to the alphanumeric identifier coming from the SIM card, whilst&#8230;</li>
<li>&#8230; it could simply use the network and SIM card numeric identifiers and compare those, which should be a lot cheaper than comparing those strings</li>
<li>Then it takes the first three characters/digits of the numeric identifiers (which indicate the country) and compares those</li>
</ul>
<p>Now in my case my SIM card doesn&#8217;t seem to provide the phone with a alphanumeric identifier, so the first two comparisons always fail for obvious reasons and, looking at the inline-if in the last line of that method my phone will always indicate that I am in roaming mode, even when I am not.</p>
<p>The problem is not only the logic which seems to be wrong, but I rather see the inefficient comparisons used there to be a major problem in embedded systems like mobile phones. This is the first piece of Android code I have had a look at, but if all other code is as ugly and inefficient as these few lines Android really needs some major fixes. Related to this I have reported bug <a href="http://code.google.com/p/android/issues/detail?id=4590">#4590</a> and forked the <a href="http://github.com/speijnik/android_frameworks_base">git repository in question</a> over at github, to fix this method, should be a matter of 5 minutes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.peijnik.at/2009/11/08/androids-roaming-detection-its-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
