<?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>Mihai Mobile &#187; Uncategorized</title>
	<atom:link href="http://blog.javia.org/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.javia.org</link>
	<description>Android apps</description>
	<lastBuildDate>Fri, 25 Nov 2011 01:50:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Fast clamp</title>
		<link>http://blog.javia.org/fast-clamp/</link>
		<comments>http://blog.javia.org/fast-clamp/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 01:38:54 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=187</guid>
		<description><![CDATA[Sometimes one needs to bound a value between two limits, min and max. This operation is called clamp. Let&#8217;s consider the clamp of an integer to the interval [0, 255]. int clamp(int x) { return x 255 ? 255 : x; } JPEG decoding requires three such clamp operations per decoded pixel, so we&#8217;d like [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes one needs to bound a value between two limits, min and max. This operation is called <em>clamp</em>. </p>
<p>Let&#8217;s consider the clamp of an integer to the interval [0, 255].</p>
<pre>
int clamp(int x) {
    return x<0 ? 0 : x > 255 ? 255 : x;
}
</pre>
<p>JPEG decoding requires three such clamp operations per decoded pixel, so we&#8217;d like to find a fast way to do it. (I&#8217;m mainly concerned with the ARM architecture as often found on Android).</p>
<p>A faster way to do it is:</p>
<pre>
int clamp(int x) {
    return !(x &#038; 0xffffff00) ? x : ((~x >> 31) &#038; 0xff);
}
</pre>
<p>The <em>~x>>31</em> works because it&#8217;s an ASR, <em>Arithmetic Shift Right</em>, which feeds from the left copies of the sign bit, not zero bits.</p>
<p>An even faster way to do it, as discussed <a href="http://www.coranac.com/documents/bittrick/">here</a>, is:</p>
<pre>
int clamp(int x) {
    unsigned y;
    return !(y=x>>8) ? x : (0xff ^ (y>>24));
}
</pre>
<p>Of course, you wouldn&#8217;t like to pay the price of a function call for such a tiny operation, so let&#8217;s make the clamp() inlinable by declaring it <em>static inline</em>.</p>
<pre>
static inline int clamp(int x) {
    unsigned y;
    return !(y=x>>8) ? x : (0xff ^ (y>>24));
}
</pre>
<p>That&#8217;s about as fast as it gets while staying at the C level. Perhaps we can make it even faster by using some cool ARM instruction?</p>
<p>The USAT (<em>Unsigned SATurate</em>) <a href="http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf">ARM instruction</a> does exactly what we want, and here&#8217;s how to put it cleanly in code:</p>
<pre>
static inline int clamp(int x) {
    int ret;
    asm("USAT %0, #8, %1": "=r" (ret): "r" (x));
    return ret;
}
</pre>
<p>This way, we cut the clamp() down to a single processor instruction! (yet losing the portability of the pure-C code).</p>
<p>Anything faster? it turns out, the USAT can do at the same time (in the same instruction) an optional shift left/right (ASR or LSL). So if it happens that you anyway needed a fixed shift before the clamp(), you can integrate the two in a shiftAndClamp(), and this way you achieve both the shift and the clamp with a single instruction. We could say that the clamp() alone now takes less than one instruction <img src='http://blog.javia.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/fast-clamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The first Galaxy Nexus challenge too hard for anybody</title>
		<link>http://blog.javia.org/the-first-galaxy-nexus-challenge-too-hard-for-anybody/</link>
		<comments>http://blog.javia.org/the-first-galaxy-nexus-challenge-too-hard-for-anybody/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 05:31:00 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=184</guid>
		<description><![CDATA[Google posted the first Galaxy Nexus challenge, which proved too difficult for anybody to solve. After 3 hours of waiting for a solution, Google gave in and posted a spoiler hint Dots are like flag messages, which makes the challenge pretty much trivial. It looks like the initial task was too hard (nobody was solving [...]]]></description>
			<content:encoded><![CDATA[<p>Google posted the first <a href="http://www.google.com/nexus/challenge3/01sdfpogiue.html">Galaxy Nexus challenge</a>, which proved too difficult for anybody to solve. After 3 hours of waiting for a solution, Google gave in and posted a spoiler hint <em>Dots are like flag messages</em>, which makes the challenge pretty much trivial.</p>
<p>It looks like the initial task was too hard (nobody was solving it), and after the give-away hint it become too easy. Let&#8217;s look forward to the next challenges.</p>
<p>PS: in task #1, each android represents a word, making up &#8220;what did j cook call hawaii&#8221;, and the answer is &#8220;the sandwich islands&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/the-first-galaxy-nexus-challenge-too-hard-for-anybody/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thanks to Eric Sink for his new book</title>
		<link>http://blog.javia.org/thanks-to-eric-sink-for-his-new-book/</link>
		<comments>http://blog.javia.org/thanks-to-eric-sink-for-his-new-book/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 10:54:15 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=180</guid>
		<description><![CDATA[I just received by international mail the printed edition of Version Control by Example by Eric Sink, offered as a gift. Thanks!]]></description>
			<content:encoded><![CDATA[<p>I just received by international mail the printed edition of <a href="http://www.ericsink.com/vcbe/">Version Control by Example</a> by <a href="http://www.ericsink.com/">Eric Sink</a>, offered as a gift. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/thanks-to-eric-sink-for-his-new-book/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fast RGB pixel average on ARM</title>
		<link>http://blog.javia.org/fast-rgb-pixel-average-on-arm/</link>
		<comments>http://blog.javia.org/fast-rgb-pixel-average-on-arm/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 18:20:32 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=177</guid>
		<description><![CDATA[Here I present a small trick, how to compute extremely fast the average of two RGBA_8888 values on an ARM processor, and how to implement it easily in C++/gcc (e.g. using the Android NDK). We have two 4-byte values representing two pixels, in format RGBA_8888. Let&#8217;s ignore the Alpha channel, assuming both have alpha=0xff (opaque). [...]]]></description>
			<content:encoded><![CDATA[<p>Here I present a small trick, how to compute extremely  fast the average of two RGBA_8888 values on an ARM processor, and how to implement it easily in C++/gcc (e.g. using the Android NDK).</p>
<p>We have two 4-byte values representing two pixels, in format RGBA_8888. Let&#8217;s ignore the Alpha channel, assuming both have alpha=0xff (opaque). We want to produce a new 4-byte value with the per-channel average of the two pixels.</p>
<p>Below we see the byte structure of the two pixels and of the desired average:<br />
pixel1: r1|g1|b1|a1<br />
pixel2: r2|g2|b2|a2<br />
average: (r1+r2)/2 | (g1+g2)/2 | (b1+b2)/2 | (a1+a2)/2</p>
<p>To implement this operation in C, we&#8217;d need to extract the individual bytes (R,G,B,A) of each pixel, average them (four additions and four shifts) and finally recompose the bytes to form the result (e.g. with shifts and ORs).</p>
<p>It turns out there is a much faster way to do it, which takes exactly.. one CPU instruction!</p>
<p>The magic instruction is <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CHDHCAIH.html">UHADD8</a>, which adds the corresponding bytes of two registers, in pairs, halves the result and recomposes the bytes &#8212; exactly the operation we needed for our RGBA average.</p>
<p>But how to access this ARM instruction from C++? It turns out, again, that there is a clean and simple way to do it:</p>
<pre>
extern inline unsigned averageBytes(unsigned a, unsigned b) {
    unsigned ret;
    asm("uhadd8 %0, %1, %2": "=r" (ret): "r" (a), "r" (b));
    return ret;
}
</pre>
<p>GCC is smart enough that invoking this inline function compiles down to just one CPU instruction (the UHADD8) without any other overhead.</p>
<p>So, problem solved: we have this neat C++ function for averaging two RGBA values, with a total cost of just one CPU instruction!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/fast-rgb-pixel-average-on-arm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ARM: PLD preload magic</title>
		<link>http://blog.javia.org/android-arm-preload-magic/</link>
		<comments>http://blog.javia.org/android-arm-preload-magic/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 00:02:54 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=167</guid>
		<description><![CDATA[I just discovered the incredible performance boost that can be achieved by using the PLD (&#8220;Preload Data&#8221;) ARM assembler instruction. What I needed to do is convert image pixel data from RGB to RGBA format &#8212; from 3bytes/pixel to 4bytes/pixel; fullscreen in real time during animation. But the general situation is anytime you need to [...]]]></description>
			<content:encoded><![CDATA[<p>I just discovered the incredible performance boost that can be achieved by using the <em>PLD</em> (&#8220;Preload Data&#8221;) ARM assembler instruction.</p>
<p>What I needed to do is convert image pixel data from RGB to RGBA format &#8212; from 3bytes/pixel to 4bytes/pixel; fullscreen in real time during animation. But the general situation is anytime you need to process a large amount of RAM data really fast.</p>
<pre>
while (n--) {
    *dest++ = *src++;
}
</pre>
<p>This loop is plain, it just copies data from a memory source to a destination. It is used here just a as a placeholder for some processing of src data. (of course, if you only need to copy the data you should use <em>memcpy</em> instead)</p>
<p>Let&#8217;s time this loop over 1MB of data, on a <a href="http://en.wikipedia.org/wiki/Samsung_Galaxy_Tab_10.1">Samsung Galaxy Tab 10.1</a> with a Tegra 2 processor &#8212; it takes about 25ms. What slows the loop down is waiting for data that is not in the processor cache to be fetched from the main memory, which is slow. We can fix this by directing the CPU to prefetch data ahead of the read. We modify the loop adding the PLD magic line:</p>
<pre>
while (n--) {
    asm ("PLD [%0, #128]"::"r" (src));
    *dest++ = *src++;
}
</pre>
<p>That asm line starts preloading data from memory to the CPU cache, 128 bytes ahead of the current <em>src</em> location, without blocking the CPU.</p>
<p>We measure again, and the same loop over 1MB of data now takes only 8ms instead of 25ms &#8212; it is three times faster! Amazing for that 1-liner, I say. By the way, this is now very close to the performance of memcpy, which is itself implemented in highly-optimized ARM assembly.</p>
<p>You may observe that our loop may be optimized a little bit further by doing partial unrolling &#8212; processing more than a single element at each iteration.</p>
<p>With partial loop unrolling:</p>
<pre>
n /= 4; //assume it's multiple of 4
while (n--) {
    asm ("PLD [%0, #128]"::"r" (src));
    *dest++ = *src++;
    *dest++ = *src++;
    *dest++ = *src++;
    *dest++ = *src++;
}
</pre>
<p>The conclusion is that if you find yourself optimizing to death some piece of C/C++ code on Android that reads a lot of memory, you should try using the PLD and profile again to see if it helps.. Enjoy!<br />
<code><br />
asm ("PLD [%0, #128]"::"r" (src));<br />
</code></p>
<p>PS:<br />
If you&#8217;re curious about the RGB_888 to RGBA_8888 conversion speed, it is possible to do a fullscreen conversion (1280&#215;752 px) on the Tab in about 7ms, which is quite impressive IMO. This is faster than the corresponding memcpy() RGBA to RGBA which takes about 8ms, and thus makes the case for the introduction of the RGB_888 (3bytes/pixel) Bitmap format in the Android Java API (as it saves RAM and memory bandwidth when the Alpha channel isn&#8217;t needed).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/android-arm-preload-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Floating point exact representation of integers</title>
		<link>http://blog.javia.org/floating-point-exact-representation-of-integers/</link>
		<comments>http://blog.javia.org/floating-point-exact-representation-of-integers/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 18:06:21 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=160</guid>
		<description><![CDATA[There are two main floating point formats: single-precision (float in Java) which stores a value in 4bytes, and double-precision (double) using 8bytes. The question is what range of integers can be represented exactly by these floating point formats? In other words, what is the maximum value for which such a statement holds: long v; (long)(float) [...]]]></description>
			<content:encoded><![CDATA[<p>There are two main floating point formats: single-precision (<em>float</em> in Java) which stores a value in 4bytes, and double-precision (<em>double</em>) using 8bytes.</p>
<p>The question is what range of integers can be represented exactly by these floating point formats?<br />
In other words, what is the maximum value for which such a statement holds:<br />
<code><br />
long v;<br />
(long)(float) v == v;<br />
(long)(double) v == v;<br />
</code></p>
<p><em>float</em> represents integers exactly up to 2^24 (<strong>16,777,216</strong>), while <em>double</em> represents them exactly up to 2^53 (<strong>9,007,199,254,740,992</strong>). These numbers are consistent with the mantissa size being 23bits for single precision and 52bits for double precision.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/floating-point-exact-representation-of-integers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apple is bad</title>
		<link>http://blog.javia.org/apple-is-bad/</link>
		<comments>http://blog.javia.org/apple-is-bad/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 19:50:18 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=156</guid>
		<description><![CDATA[I&#8217;ll never buy an Apple product again. I find the patent situation in the US profoundly sick. Microsoft is making money on the back of Android with patent fees. Apple and Microsoft team up together to buy the Nortel patents for 4.5billion, to be used against competitor Android. Apple suing HTC and Motorola over Android. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll never buy an Apple product again.</p>
<p>I find the patent situation in the US profoundly sick. Microsoft is making money on the back of Android with patent fees.<br />
Apple and Microsoft team up together to buy the Nortel patents for 4.5billion, to be used against competitor Android. Apple suing HTC and Motorola over Android. Oracle suing Google over Java patents used in Android.</p>
<p>Really, the software patents as they are used now in the US are a cancer. They are not good in any way, and most of all they do not promote innovation &#8212; quite the opposite, they clearly are used to stifle innovation when it happens.</p>
<p>The real fix is to abolish the software patents in the US. I deeply hope this <em>will</em> happen, but I don&#8217;t quite hold my breath for it.</p>
<p>In the meantime, the least I can do is vote with my money, as a humble consumer. I&#8217;ll never buy an Apple product again!</p>
<p>PS: Of course, there is quite some time since last I used any Microsoft product. But with Apple it&#8217;s new.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/apple-is-bad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RenderFX: color vs. power</title>
		<link>http://blog.javia.org/renderfx-color-vs-power/</link>
		<comments>http://blog.javia.org/renderfx-color-vs-power/#comments</comments>
		<pubDate>Tue, 24 May 2011 22:05:49 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=145</guid>
		<description><![CDATA[Android render effects is a way to globally change the colors used when rendering, for example by using only the Red channel (disabling Green and Blue). It was first presented on Jeff Sharkey&#8217;s blog, and it is now implemented and available in CyanogenMod. Instead of using the three color channels (RGB) you may chose to [...]]]></description>
			<content:encoded><![CDATA[<p>Android render effects is a way to globally change the colors used when rendering, for example by using only the Red channel (disabling Green and Blue). It was first presented on <a href="http://jsharkey.org/blog/2010/07/01/android-surfaceflinger-tricks-for-fun-and-profit/">Jeff Sharkey&#8217;s blog</a>, and it is now implemented and available in <a href="http://cyanogenmod.com/">CyanogenMod</a>.</p>
<p>Instead of using the three color channels (RGB) you may chose to use only one, let&#8217;s say Red. White becomes Red, while the disabled channels (Green, Blue) become black. The colors are very weird, but the screen remains sort-of readable in general. Why would anybody want to do something so horrible to a display?</p>
<p>The first reason is to save power. A phone&#8217;s display uses a significant portion of the battery. For OLED displays, making pixels (or subpixels) black saves power. Turning color channels off saves power. For example using only the Red channel instead of all three RGB cuts the display power to less than 50%.</p>
<h2>Automatic Brightness</h2>
<p>Android phones have a <em>Display Brightness</em> setting, which is usually set to &#8220;Automatic Brightness&#8221;. This reduces the brightness of the display in dark indoors (when the screen is easy to read), while increasing the brightness in sunny outdoors, when the screen is barely readable.</p>
<p>On OLED displays, which have deep blacks, increased brightness usually looks better. So why there exists this <em>adaptive brightness</em> at all, instead of keeping the display simply set to maximum brightness all the time?<br />
Mainly for two reasons:</p>
<ul>
<li>lower brightness saves battery power
<li>lower brightness increases the display lifetime (for OLED).
</ul>
<p>Yes, that&#8217;s right: the &#8220;brightness&#8221; setting is not there to improve the visual quality &#8212; it is there to increase the battery life. Try setting your phone to &#8220;maximum brightness&#8221; for one day, it&#8217;ll look great but will empty the battery much faster.</p>
<h2>OLED</h2>
<p>Traditional LCD displays need a backlight, a source of white light that is filtered through the liquid cristal layer to produce the colors. The power usage of an LCD display is independent of the colors displayed (e.g. redardless whether the screen is white, red or blue, the power usage of the display is the same).</p>
<p>OLED displays do not have a backlight. In OLED the pixels themselves emit light, and each individual subpixel uses power in doing so. OLED power usage depends on the colors displayed. A white screen (which has all subpixels Red, Green, Blue lighten up at maximum intensity) uses the most power, while a black screen uses almost no power at all.</p>
<p>In addition, OLEDs have a general difficulty with Blue. The Blue subpixels use much more power (compared to the Red or Green channels). In addition to the increased power usage (or because of it) the Blue subpixels have a much shorter lifetime. If the OLED display is kept on, bright white, for a long time, the Blue subpixels will wear off visibly and irreversibly.</p>
<p>So a way to increase the battery lifetime of the phone is to disable the Blue channel. Of course, this is a pretty high price to pay for power as the colors don&#8217;t look normal anymore. A more extreme is to disable two channels, e.g. Blue and Green, resulting in more battery life and a Red-only display.</p>
<p>But hacking is fun, and Jeff Sharkey first implemented a <a href="http://jsharkey.org/blog/2010/07/01/android-surfaceflinger-tricks-for-fun-and-profit/">proof-of-concept of the color-reduction</a>. It is implemented as an OpenGL transform in SurfaceFlinger. This means that the pixel colors undergo a final modification (e.g. zeroing-out the Blue and Green channels) just before they&#8217;re sent to the display panel. The problem is that this solution uses CPU or GPU resources (due to the additional OpenGL processing), and this means more power usage. So while some power is gained by reducing OLED colors, some power is lost because of the additional GPU usage.</p>
<p>Now the question presents itself: is it possible to implement this color warping, a.k.a. RenderFX, without the burden of the additional OpenGL transform? Well.. yes, there is a cool trick that does it, but it only works for OLED displays. But anyway we&#8217;re only interested in RenderFX on OLEDs (because only there it saves power).</p>
<h2>Colored backlight</h2>
<p>The trick concerns the backlight color. Traditional LCDs have a real backlight, a source of white light, whose intensity can be changed (more or less bright) but the color stays white. </p>
<p>On the other hand OLEDs do not have a real backlight. The brightness setting for OLED is not implemented by changing the backlight intensity, but simply by remapping the intensity of the pixels in the display controller. You can think of an OLED backlight, but that&#8217;s an imaginary concept simulated by the display controller.</p>
<p>It turns out, the OLED panel can control the intensity of the backlight color channels (RGB) independently. This can be represented as if having a backlight which can be set to any color and intensity, not only grayscale. And this is the solution: by setting the backlight to various non-white colors it is possible to implement RenderFX without the OpenGL overhead.</p>
<p>For example, to disable the Blue channel, it is enough to set the backlight to Yellow (Red+Green). To disable both Blue and Green we set the backlight to Red. And so on, many intermediate variations are possible.</p>
<p>I tested this in practice on Nexus One with CyanogenMod by modifying the kernel file<br />
arch/arm/mach-msm/board-mahimahi-panel.c<br />
which implements the &#8220;backlight intensity setting&#8221; for the OLED panel, to allow for non-white backlight colors &#8212; and it works nicely!</p>
<p>For a general and clean solution, a bit more work is needed throughout the framework in order to expose in the API the concept of &#8220;LCD backlight color&#8221; instead of &#8220;LCD backlight intensity&#8221; as it is now. This is a generalization, as an RGB color can easily be mapped to a grayscale intensity, but not the other way around (i.e. RGB is a superset of grayscale).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/renderfx-color-vs-power/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cyanogen Rules</title>
		<link>http://blog.javia.org/cyanogen-rules/</link>
		<comments>http://blog.javia.org/cyanogen-rules/#comments</comments>
		<pubDate>Tue, 24 May 2011 00:41:06 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=140</guid>
		<description><![CDATA[I use a Nexus One phone. I have been using it for more than one year. I&#8217;ve written apps for it. Yet until yesterday I didn&#8217;t know it has an FM receiver. Yes, the Nexus One has a perfectly good functional FM receiver. The hardware (FM radio) is there in the phone. It&#8217;s just that [...]]]></description>
			<content:encoded><![CDATA[<p>I use a Nexus One phone. I have been using it for more than one year. I&#8217;ve written apps for it.</p>
<p>Yet until yesterday I didn&#8217;t know it has an FM receiver. Yes, the Nexus One has a perfectly good functional FM receiver.</p>
<p>The hardware (FM radio) is there in the phone. It&#8217;s just that the software is not enabling the radio. It&#8217;s such a pity: you pay for the &#8220;hard&#8221; part, the electronics, but the &#8220;soft&#8221; part is not making any use of it.</p>
<p>But yesterday, when I installed CyanogenMod for the first time, suddenly the FM receiver was there, and I was shocked: FM radio? working? my phone <em>has</em> an FM receiver?!</p>
<p><a href="http://cyanogenmod.com/">CyanogenMod</a> is a fork of the Android project. It is so much better than the &#8220;stock Android&#8221; that comes with your phone.</p>
<p>And CyanogenMod is open. Really <em>OPEN</em>. You can take the source code, compile/hack it and install it on the phone, and you get a working phone. This is unlike the AOSP (android open source project), where you can get the source code, compile it, but it won&#8217;t work on any device.</p>
<p>And CyanogenMod is accepting contributions from external developers. And is open to source-code change, and to improvement. CyanogenMod is putting into life the <strong>open</strong> that Google is only talking about.</p>
<p>So, if you have an Android phone, put CyanogenMod on it and be enthrilled! If you are a developer, and you want to propose a change/improvement to Android source code, send it to CyanogenMod for inclusion. </p>
<p>On the other hand.. thinking about sending a change to Google AOSP? think twice.. Most likely your change is not good enough, and anyway nobody cares &#8212; the Google android developers are too busy to bother.</p>
<p>Kudos to CyanogenMod for showing us all what an <em>open</em> Android really can be.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/cyanogen-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to work around Android&#8217;s 24 MB memory limit</title>
		<link>http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/</link>
		<comments>http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 16:20:02 +0000</pubDate>
		<dc:creator>Mihai Preda</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.javia.org/?p=137</guid>
		<description><![CDATA[The Android framework enforces a per-process 24 MB memory limit. On some older devices, such as the G1, the limit is even lower at 16 MB. What&#8217;s more, the memory used by Bitmaps is included in the limit. For an application manipulating images it is pretty easy to reach this limit and get the process [...]]]></description>
			<content:encoded><![CDATA[<p>The Android framework enforces a per-process 24 MB memory limit. On some older devices, such as the G1, the limit is even lower at 16 MB.</p>
<p>What&#8217;s more, the memory used by Bitmaps is included in the limit. For an application manipulating images it is pretty easy to reach this limit and get the process killed with an OOM exception:</p>
<pre>
E/dalvikvm-heap(12517): 1048576-byte external allocation too large for this process.
E/GraphicsJNI(12517): VM won't let us allocate 1048576 bytes
D/AndroidRuntime(12517): Shutting down VM
W/dalvikvm(12517): threadid=1: thread exiting with uncaught exception (group=0x4001d7f0)
E/AndroidRuntime(12517): FATAL EXCEPTION: main
E/AndroidRuntime(12517): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
</pre>
<p>This limit is ridiculously low. For a device, like the Nexus One, with 512MB of physical RAM, setting the per-process memory limit for the foreground activity to only 5% of the RAM is a silly mistake. But anyway, that&#8217;s how things are and we have to live with it &#8212; i.e. find how to work around it.</p>
<p>There are two ways to allocate <em>much</em> more memory than the limit:</p>
<p>One way is to allocate memory from native code. Using the NDK (native development kit) and JNI, it&#8217;s possible to allocate memory from the C level (e.g. malloc/free or new/delete), and such allocations are not counted towards the 24 MB limit. It&#8217;s true, allocating memory from native code is not as convenient as from Java, but it can be used to store some large amounts of data in RAM (even image data).</p>
<p>Another way, which works well for images, is to use OpenGL textures &#8212; the texture memory is not counted towards the limit.</p>
<p>To see how much memory your app has really allocated you can use android.os.Debug.getNativeHeapAllocatedSize().</p>
<p>Using either of the two techniques presented above, on a Nexus One, I could easily allocate 300MB for a single foreground process &#8212; more than 10 times the default 24 MB limit.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

