Tuesday, April 28, 2009

BlackBerry connection tip

We developed a small client application for BlackBerry phones that connects to MiaMia servers. A lot of things can be said about BlackBerry adherence to standards, but I don't want to use cuss words here. The main problem is that these phones were initially devised to serve as "corporate walkie-talkies", and only recently their design was stretched to accommodate the needs of the general public. In a nutshell, this is a hardware equivalent of Lotus Notes - a combination of lack of respect for standards and a kungfu grip on the corporate customers.

As a result, once in a while developers encounter what can be described as a "chastity belt" - when it comes to communications with external world. Look for blackberry connection problems in Google or read this frustrated rant that sums it all. And if, as a BlackBerry user, you encountered problems with MSN Messenger, IRC, or anything else - same reason.

By default, when possible and a proxy-based connection (MDS, BES, BIS) exists, BlackBerry seems to re-route all requests there. It is not at all certain that your tiny app will be allowed to go further. Chances are, it will be stopped, and possibly hang. However, there are two possibilities that should work in most cases:


  • direct TCP/IP via GPRS network
  • wireless connection

To cut the long story short, the easiest way to provide maximum coverage is to create a tiny function that will be used like this:



 protected String getDeviceSpecificUrlParameters()
{
try {
if (net.rim.device.api.system.WLANInfo.getWLANState() == net.rim.device.api.system.WLANInfo.WLAN_STATE_CONNECTED)
{
return ";deviceside=true;interface=wifi;ConnectionSetup=delayed;retrynocontext=true";
}
} catch (Exception e) {} // doesn't matter, just go elsewhere
return ";deviceside=true";
}

then call it whenever you make a connection, e.g.
 ...
Connector.open(url + getDeviceSpecificUrlParameters());
...

If your application is designed to work across different platforms (like ours), you can re-implement that getDeviceSpecificUrlParameters() for whatever platform you need.


A word of warning: if it's a brand new phone, and the access to GPRS is not configured, you may need to explain your users how to set up their APN parameters. The carrier-specific parameters can be found here, here, and here.

Tuesday, April 14, 2009

Making peace with Vista

This is not directly related to the subject of the blog, but is worth sharing, since so many people are having problems with this.

My development machine runs Windows Vista. I'm not a fan of it (probably, like the majority), but I have to eat the same food my users do. Many people experience the same phenomenon, where Vista suddenly freezes without any provocation. It gets progressively worse with time. In my case, a few days ago it came to a point where the freezing occurred every half an hour. 

I tried different things: switching off visual styles, removing the useless Windows Defender, etc. The performance improved, of course, but the freeze attacks still remained.

Finally, I found this tip. (In Vista Home Basic, it is a bit different: you need to navigate to Control Panel -> System -> Performance -> Adjust indexing options.) It all makes sense: usually in databases functional indices are paramount, and when the system builds them, everything else is secondary. The most important analogy: if an index is corrupt, all kinds of bad things are likely to happen. Except that why would we need them in a desktop OS? It turns out that the reason is the ultra-annoying search, which is a part of the Start menu. I suppose the reason for this nuisance was to show that it's no worse OS X. Well, this is dumb. The old search was fine, and those who need better capabilities, generally use something else. In Vista, as a result, a background process is indexing nearly every file in the system. Why not make the indexing a scheduled task, and fall back to un-indexed search when necessary?

After I reduced the population of files to index to the contents of Start menu only, suddenly Vista became the most stable, high-performance system I have ever seen - I kid you not! On the other hand, if you do need and like that new bloated search, or need the thumbnails, simply go and rebuild the index. Also at this opportunity review what extensions you want to index.

Oh, and of course, I assume no responsibility if you do something silly to your machine, so don't just push everything without thinking.