Various native Android error messages

I’ve decided to keep a blog post containing various error messages encountered during Android debugging / playing …

These errors were encountered via deep trips in Android source both native and java source code, while trying to get zygote to execute a process as root (and hopefully this way, be able to somehow invoke the elusive forceStopPackage method which Google decided to ditch from Android 2.2; but is still there hidden behind proxies since it is very useful).


Connecting to /dev/socket/zygote (unix domain socket) from a native .C application and sending the following commands:

--setuid=0 --setgid=0 --enable-debugger --peer-wait --runtime-init android.app.ActivityThread

produces the log:

W/ActivityManager( 1559): No pending application record for pid 3544 (IApplicati
onThread android.app.ApplicationThreadProxy@405d6cc0); dropping process
I/Process ( 1559): Sending signal. PID: 3544 SIG: 9

It probably means that I did not provide an application record to be executed by the process zygote created. I need to research how to do that …


After building an ARM toolchain using build root, I was trying to compile some library using the config files from the Android toolchain. I had to xscale as family, but instead I selected generic-arm:

[9:20:29 PM] c1: error: unrecognized command line option "-mandroid"
cc1: error: unrecognized command line option "-mthumb-interwork"
cc1: error: unrecognized command line option "-mthumb"
cc1: error: unrecognized command line option "-mlong-calls"
conftest.c:1: error: bad value (armv5te) for -march= switch
conftest.c:1: error: bad value (xscale) for -mtune= switch
configure: failed program was:

#line 958 "configure"
#include "confdefs.h"

main(){return(0);}

Administer your Android phone from Internet (root needed)

Introduction

I’ve decided to make this tutorial since this issue was a long time frustration I had with the mobile phones.

I’d like to be able to administer my phone using any web browser when the phone is only connected to the GSM/3G network.

There are some tools that allow to administer the phone from a browser, but because mobile operators block access to the phone’s IP (when on GSM/3G), you can’t connect to the phone. You either have to pass through 3rd party proxies (if offered by tools developers) OR only use the phone over WiFi at home.

Some scenarios that I found frustrating:
1) I’m at the office, and I’d like to copy a file to the phone. But I don’t have the cable with me nor I can install Dropbox on PC tough.
2) Receiving an email with contact details. I don’t want to type it manually on the phone – I’d like to be able to edit the contacts list in a browser, even if the phone is only connected to 3G network.

Prerequisites

a) Home pc with a public IP address and OpenVPN server properly configured.
b) tun.ko / OpenVPN client installed on the phone – and properly connecting to the home pc OpenVPN server.
c) i-jetty + i-jetty console installed on the phone on default port 8080.

I put these as prerequisites since they require some time to get them running properly. I already had the OpenVPN server, and it took a while to find a working tun.ko that does not reset my phone.

Connection diagram

This diagram represents a standard setup and ports and IPs are shown as examples, they will be different in your setup:

a) Home PC is protected by a router which has external IP (allowing anybody to connect to it).
b) Router allows OpenVPN traffic to reach the home PC (and thus the phone can connect to the OpenVPN server).
c) Router will also forward each request on its 3080 port to the Home PC port 3080.

Right now, the only thing needed, is a small web server on HomePC port 3080 which will redirect all requests to the phone’s OpenVPN assigned IP (in my case, 10.7.7.22).

Configuration

1. OpenVPN server needs to allow inter client communications so please add this line to server.conf of OpenVPN:

client-to-client

2. As proxy server, I have used nginx. My home PC is running Ubuntu and thus I was able to easily apt-get install nginx.

To act as a proxy, you need to edit the file /etc/nginx/sites-enabled/default and add the following server configuration:

server {
        listen 3080;

        server_name <external_ip>;

        location / {
                proxy_pass        http://10.7.7.22:8080;
                proxy_set_header  X-Real-IP  $remote_addr;
        }
}

This instructs nginx to:
a) listen to port 3080.
b) reply with <external_ip> as address (so outside clients won’t see a LAN ip, but the external ip).
c) forward all requests to the phone’s OpenVPN IP, on port 8080, where i-jetty console listens for connections.

Thus, the only requirement is now that the phone has a working network connection which it can use to connect to the OpenVPN server at home.
When connection is established, you can connect to http://<external_ip>:3080 and then:
a) router will forward traffic to HomePC port 3080 (where nginx listens)
b) nginx forwards the traffic to the phone’s IP.
c) OpenVPN server will foward the traffic to the connected phone.
d) i-jetty console replies, and the packages travel now back to the browser.

This is an overview of the process, and specific details on how to configure everything is outside the scope of this tutorial. Google helps a lot with OpenVPN, and each phone subarea on XDA describes how to configure tun.ko.
There are also configurations to be done on router which depend on the router only – however, opening tunnels (even if not named like this) but meaning to allow connections from outside world to inside LAN is something that should be covered by the manual.

Conclusions

With a rooted phone and some configuration abilities, anybody can now connect to the phone, using any browser – no need for cables, etc.

Connection from the browser to the home pc is not encrypted. It can be if you generate a certificate and instruct nginx to answer via SSL and using that certificate, instead of standard HTTP. This is again covered in details on the internet.

There are other security aspects on opening your PC to the outside world, so … unless you know what you are doing – do not proceed.

But now I like Android even more [even if pthread / fork() implementation still leaves a lot of room to be improved]

Timidity

Your imagination should do the work and find the cues …

Timidity

Timidity

Post your feelings or your thoughts about it …

The circle represents the skin.

The galaxies represent the soul and the internal universe.

The heart feeds the body.

But the universe is within.

It is timid.

Without a heart, there can be no universe.

The heart is small.

Preparing to build Gingerbread / Android on Ubuntu.

This is a quick tip on how to setup Ubuntu to build Android from scrap.

Android / Gingerbread build process itself is pretty straightforward if you follow the standard documentation: http://source.android.com/source/building.html.

What will stop you is that Ubuntu has, in my opinion, two things that annoy every java developer:
a) openjdk / fastjar
b) pulseaudio! Neah, this just annoys everybody :) )

This crippled Java kills Gingerbread build process with errors like:

out/target/common/obj/APPS/Camera_intermediates/src/com/android/camera/R.ja va:10:
cannot access java.lang.Object
bad class file: java/lang/Object.class(java/lang:Object.class)
unable to access file: corrupted zip file
Please remove or make sure it appears in the correct subdirectory of the
classpath.
public final class R {
^

For all the details and the solution here’s how to fix: https://groups.google.com/group/pandaboard/browse_thread/thread/2ad9f0ae099e7db1?fwc=1&pli=1

Correcting the fastjar mess :

sudo update-alternatives --config jar

and selecting the proper Sun / Oracle JDK fastjar alternative.

It now builds correctly in just under one hour! (E8500 / 2Gb DDRAM 800Mhz / RAID-0).

# time make -j8
...
real 59m26.427s
user 69m54.414s
sys 9m24.187s

So, to get rid of OpenJDK/fastjar, issue the following commands:

apt-get remove icedtea-6-jre-cacao icedtea6-plugin openjdk-6-dbg openjdk-6-demo openjdk-6-doc openjdk-6-jre openjdk-6-jre-headless openjdk-6-jre-lib openjdk-6-source openjdk-6-jre-zero cacao-source default-jdk default-jdk-doc default-jre default-jre-headless

as well as:

apt-get remove fastjar

It will actually remove much more (as there are many dependencies not used), but this does not affect the build process of Gingerbread as long as you have Sun’s JDK installed.

Make sure you check the output and you don’t delete something you need.

Canon 7D AF Micro Adjustments – pixel peeping

Since my first post AF-MA ( found here ) I’ve refined the way I do tests for AF micro focus adjustments.

For a macro lens (in this case – Canon EF 100mm USM) the minute differences between small AF Micro Adjustments increments do not create visible differences in photos. I needed a more precise method to locate the sharpest AF MA value.

I’ve decided to use the focus charts found here http://regex.info/blog/photo-tech/focus-chart (the 25% version) but with a twist. Instead of having the sheet of paper on an inclined angle as opposed to the camera lens axis, I used a bottle and wrapped the focus chart around it as you can see below (in horizontal mode, the focus chart was too big to tell apart the variations between small AF MA changes)

Focus Chart wrapped around a bottle.

Focus Chart wrapped around a

Camera was set to use only the center cross type AF point, like in the screenshot below: (made with BreezeBrowser Pro 1.9.7):

Single AF point selection.

Single AF point selection.

Since the camera photographs the bottle from 70cm away, looking down a bit (I think is 15cm above the center of the focus chart), it is normal not to have all the digits (the bottom row and the top row) focused at the same time, as the focus plane slices the “bottle” instead of being parallel to it.

To compare, I first made a shot of the red area above using a different camera with better macro abilities (Canon SX20 IS on Super Macro mode). Then, I decided to go between -2 and 9 on the Canon 7D, and then pick up the setting that produced the best reproduction of the image.

Please check below, I believe that the best setting in my case is AF +2 (click on image to open live size):

AF from -2 to +9

AF from -2 to +9

My reference were the two small points to the right of the letter g (between ‘g’ and ‘p’). The best separation between them is on setting +2, in the other cases they look a bit more blurry.

Setup was like this:

a) Camera mounted on a tripod.
b) Shot in Tv mode, with speed of 1/200 and a 2 seconds timer (I don’t have a remote yet).
c) AF mode was “One Shot” and only the center sensor (cross type on Canon 7D) was selected.
d) No post processing, images below are crops from what the camera produced.

I want to thank Jeffrey for the focus charts, I am a pixel peeper and they proved to be extremely helpful! Having the focus chart wrapped around a bottle being photographed from above ads a new perspective to the test. You can see how the focus plane cuts through the ‘bottle’ (so not only the main AF focus point will be sharop, but also all the points within the image that will be found on thus focus plane).

20Km de Brussels, in 100 years …

Today there was the big race, 20 Km de Brussels.

Of course, I was there, but with my Canon 7D. I am drawn towards old photos, and the time that passes, so after some small leveling, a quick re-synthesizing of the big gate left column (covered by a light pole, now removed) and not to mention an old photo effect:

20Km de Brussels in 100 Years

20Km de Brussels in 100 Years - 2111

Original:

20km de Brussels - 2011

20km de Brussels - 2011

I felt nostalgic.

I just found out about a better way to simulate the old photo effect (Gimp):

Other effect.

Other effect.

What do you think ?

Gimp with Resynthesizer plugin

Resynthesizer plugin for Gimp works similar to Adobe Photoshop content aware fill. It is not as easy to install which is a bit of a shame since it is great.

This post details the installation steps I had to do so that I get it to work.

You need the following files, installed in the order below:

1) python-2.6.msi. Gimp only supports python 2.5 and 2.6. If you install later versions, you won’t be able to activate “GIMP Python extensions” in the “Customize” window when installing Gimp.

2) pygtk-all-in-one-2.24.0.win32-py2.6.msi. Make sure that you download the ALL IN ONE bundle ~32Mb as it includes the additional PyCairo, PyGObject and PyGTK modules. They are needed, and if you don’t install them then “Filters/Python-fu” won’t appear in Gimp menus and nor the python plug-ins that come on top of the Resynthesizer.

3) gimp-2.6.11-i686-setup-1.exe. On the installation page “Ready to Install”, click “Customize”. After you confirm the installation folder and clicking “Next”, the window “Select Components” appears. Confirm that “GIMP Python extensions” is selected as below, then finish the installation. Let Gimp start and confirm that you have the “Filters/Python-fu” entry available in the menus.

GIMP Python extensions window.

GIMP Python extensions

4) Resynthesizer_v1.0-i686.zip. I found the link on the Resynthesizer plugin description. The current author (bootchk) says that he does not have the time to create a Windows installer but a good guy samj seemed to have compiled a Windows version and offering it.

Installing Resynthersizer is a bit of .zip unpacking and copying the files. The zip contains the main resynthesizer plug-in (the executables) as well as some other Python plugins that do their job based on it. I found the most useful one to be the Heal selection one (which, at the end, you will find it in “Filters/Enhance/Heal Selection”.

5) Unpack the .zip archive, and copy the 10 files (basically the *.py and *.exe) into Gimp’s plugin folder. You find the Gimp plugin folder into “Edit/Preferences” screen and clicking on the “Folders/Plug-ins” item:

Plug-ins folder window

GIMP Plug-ins folder

I’ve chosen to copy them into “c:\Program Files\GIMP-2.0\lib\gimp\2.0\plug-ins”.

The list of files to be copied:

plugin-heal-selection.py
plugin-heal-transparency.py
plugin-map-style.py
plugin-render-texture.py
plugin-resynth-enlarge.py
plugin-resynth-fill-pattern.py
plugin-resynth-sharpen.py
plugin-uncrop.py
resynthesizer-gui.exe
resynthesizer.exe

I have the UAC disabled on Windows 7, but if you have UAC on, you need to copy the 10 files into your C:\Users\[username]\.gimp-2.6\plug-ins folder (in your home folder).

That’s it!

The magic happens after you select the area you want healed and then choose “Filters/Enhance/Heal selection…” tool:

Heal selection ...

Heal selection ...

The crane went away:

Photo healed

Photo healed

Happy editing :)

Observations:

It works also on Windows 7 64bit, but I kept everything 32bit just to be safe.

Canon 7D AF (autofocus) Micro Adjustments

I’m describing my method of  finding the specific “AF Micro Adjustments” value given camera + lens. You won’t need printer, tripods, LCD screens, other devices and auto-focus charts, you don’t need EOS Software installed or anything! Just MS Paint .

(I’ve wrote a new post on a more refined way to do focus testing. You can find it here.)

Introduction

When deciding between Canon 60D and Canon 7D, I found a post asking whether the “AF Micro Adjustments” is really needed. My answer ? YES!

Reality

Few days ago I just bought a Canon 7D (just for having the “AF Micro Adjustments” over the Canon 60D) but sadly discovered that more than 90% of the photos were blurry. Even my Canon SX20 IS did much better photos.

An example of a bad photo you can see here (as taken from the camera but saved at 90% to reduce upload size):

Out of focus image.
Out of focus image.

IS was ON, 1/30s, F5.6, ISO 125. By all means, this should have been a crisp image. The most disturbing fact was that the camera said the focus is in the center in the image, just to find out later that it was not the case. Focus was locked apparently but image was blurry.

Another example:

Jamón serrano - Front Focus
Jamón serrano – Front Focus

1/20s, f5.6, ISO 160. Camera said that focus is in the middle of the plate, just to find out that actually is few centimeters in front.

Lens I’ve tested with

I’ve returned from the shop after testing 5 more lenses (2 x EF-S 18-135, EF-S 60mm, EF 70-300mm L, EF-S 10-22mm) beside mine which is EF-S 18-135 mm; they all needed AF Micro Adjustments for the image to be crisp!

Steps

  1. No Live View – tests have to be done using camera’s AF sensors.
  2. In daylight, on ‘Av’ mode using F8 or higher, take some photos of something in the distance (let’s say 30m away) every time adjusting the AF Micro Adjustment value. Starting at -20 and increasing with 5 each time, do 9 photos (-20, -15, -10, -5, 0, 5, 10, 15, 20).
  3. You must photograph the same thing, for example some shop on the opposite side of the street. Precise framing is not important, but you must have some detail in the photo that you can later zoom in to help in deciding the best image quality.
  4. Out of 9 photos, one will be the sharpest. I’ve found that is easier to crop the detail and paste it in MsPaint to ease noticing subtle details. Please check below for an example.
  5. Let’s say that +10 is the sharpest image so far. It means that from +5 to +15 the focus increases in quality, peaks around +10, and then decreases towards +15.In your case the value will probably be different so just take 9 more photos, but now, center the interval around the value that produced the sharpest photo, by using increments of 1. In the given example center around +10: +5, +6, +7, +8, +9, +10, +11, +12, +13, +14, +15.
  6. Again, paste the detail into MsPaint and decide which one is the sharpest. That will be the final value for the given lens.

Example of a detailed letter ‘e’ taken from a batch of images I took:

AF Micro Adjustments Sample -20 to 20
AF Micro Adjustments Sample -20 to 20

These are the first samples from -20 to +20, in increments of 5. In this case, the sharpest seem to be the +5 and +10, so that’s where I would look (by adjusting again between +5 and +15, in increments of 1).

This is the old binary search algorithm :) used to identify which is the sharpest image.

Observations

Camera’s AF micro adjustment feature does not differentiate between same model lenses (Canon 7D, firmware 1.2.5). The manual says that camera will remember up to 20 lens – but in fact they have to be different models. I tried 3 EF-S 18-135 lenses and the camera showed the last AFMa value instead as going back to ’0′ as it did when changing lens with a different model.

The more out of focus an image is, the more color aberrations were noticeable in the corners of the photo.

Front focus / back focus is noticeable in macro shots (that’s why the other methods tend to insist on small charts) but it proportionally affects the shots taken at wide open. If in macro shots the focus can be few centimeters off, in wide views it can be some meters off (even to the point in which you don’t actually have anything focused).

Front focus / back focus does not affect manual mode nor Live View mode (but both methods are much slower at fixing the focus :) ).

Some people discuss that the focus of their Canon 7D is incorrect and that a full reset is needed by taking out both the batteries. I have to admit that I did also 2-3 full resets – even if I was skeptical about the method. The problem seemed optical and not electrical (in my case the camera was actually reporting focus but the results were not).

Conclusion

After trying out 6 lens, they all appeared to have a degree of variation.  The camera itself can be off too.
Having the AF Micro Adjustments at hand is a very very good way of bringing everything together instead of having to send all the materials to the producer to have them realigned. If IQ is important for you, better save more money and get a camera that has this feature.

MRTG Home Screen widget for Android – part 2.

As mentioned in part 1 , I’m working on an Android application to show some MRTG graphs from my website.

So far, I’ve managed to:

a) Integrate with AlarmManager and work with Services. When the widget starts, the onUpdate method is called which in turn takes care of registering with the AlarmManager for refresh rates quicker than 30 minutes and also set up the events of the widget.

Among the troubles encountered were:

1) AppWidgetProvider object does not remain the same throughout the widget lifetime on screen, but different instances of the provider class. So you cannot have private variables (they will appear NULL when onDelete is called for example). So you need to find different ways to remove the AlarmManager intent – by creating an intent with the same parameters, and asking the manager to delete the one that you just created. This seems a fudge but … that’s the way it works.

2) If you want widgets with different sizes (rows x cols), the only way is to create distinct classes (that might extend from a parent class, but you do need different classes). Then, in the AndroidManifest.xml, you have to describe all the widgets (as many as size combinations you want, each with its own layout). This means of course that you have to create a widget provider .xml file (appwidget-provider element) that will be referenced from the manifest file – because that’s where you specify the size of that specific widget. The providers can reference the same layout .xml file, but you need an widget provider .xml for each specific size.

3) By design, Android event notification consider destination to be a Class (so not an object, an instance of that Class) but a Class as the recipient of an event. Watch out that from the service you set the intents correctly to the correct class (if you have multiple widgets with different sizes – different classes).

4) You can start a PreferenceActivity from the Widget. I’ve managed to have each Widget show its own preference activity (you can see in the screenshots below that the title of each preferences screen contains the widget ID). I still have to find a way to share the properties between each widget on the screen.

Finaly, here are some screenshots!

Two widgets running at the same time.

Two widgets running at the same time.

Preferences for first Widget (id 116)

Preferences for first Widget (id 116)

Preferences for second Widget (id 117)

Preferences for second Widget (id 117)

MRTG Home Screen widget for Android

Since I like it a lot on my WM 6.1 Sony X1 phone, I decided to do the same for my X10 Mini Android 1.6 phone.

Here’s a teaser:

MRTG Home Screen widget

MRTG Home Screen widget

Using ADW Launcher, of course – to show it on 3×3 size – otherwise, the default on Sony’s home app would be 2×2 and the graphs would be too small.

Let me know if you like it.