Archis's Blog

October 30, 2008

The "My Pictures" folder on Windows Mobile

Filed under: Uncategorized — Tags: , , , — archisgore @ 4:22 am

Ever wanted to write a killer pictures app for WM? Ever wanted to do something cool like anotate pictures? Chances are, you’ll want to include a good old conventional folder-browser dialog to ensure your users can locate their folders manually.

SHGetSpecialFolder, while a great API in theory and documentation, is something you should treat with great skepticism – especially if you’re going to write to the folder returned by this function without confirming it with your users first.

SHGetSpecialFolder returns a hardcoded path to \My Documents\My Pictures. Don’t see anything wrong with that? Wait till you add a storage card to your phone (which you’re bound to do, unless you have one of the expensive models that come with a few gigs of inbuilt storage (and yet this will fail on that kind of storage too – HTC Diamond is a known example)). If your camera is storing pictures on a storage card, then it turns out, there is either no spec for where this path will be stored in a uniform manner, or the OEMs didn’t stick to it. Either way, there’s very little we can do about it. It’s out there, and that’s how it is, and you need to live with it.

There isn’t really a reliable way to get the folder to which your camera is saving pictures by default, and while a best-effort attempt at locating it can be done by some registry hacks and SHGetSpecialFolder, it would be a good precaution to confirm the path with your users first, and give them the option of locating the path if you get it wrong.

October 16, 2008

Richard Stallman’s Cloud Computing critique

Filed under: Uncategorized — Tags: , , , — archisgore @ 2:16 am

Say what you will, but you can’t deny that the FSF never fails to inspire passion in people. First the iPhone, and now Cloud Computing. What a rant! Seems that unless you can prepend a GNU behind it, you’re doomed to be the next target of the FSF. At least in the case of iPhone, it was just one product, but in Cloud Computing, an entire group of widely diverse technologies, architectures, design principles, and approaches are being blamed because a few idiot slasheads didn’t read gmail’s terms and conditions properly! What the hell?

Read Richard Stallman’s claim that Cloud Computing is a trap, to get a context, if you’re new to all this. There are many fallacies in his arguments, but let me present the few that my limited “non-hacker” intellectual ability permits me to understand.

First he claims that age-old technologies are being re-branded as cloud computing. If that’s true, then blame the age-old technologies. There are people who’re doing a lot of new cool things to connect the world, and there’s no need to throw mud at “Cloud Computing” itself (whatever it may be).

Secondly, he speaks of data-ownership. Again, he uses the example of Gmail and blames “Cloud Computing” for storing people’s data (he never mentions other mail-providers that _don’t_ store people’s data indefinately – apparently Google is the be-all-end-all in the Stallmanian universe.)

On this point, he fails to mention that Google had a full disclosure of their contract terms and conditions when people signed up for gmail. Besides, from what I’ve heard, gmail isn’t all that much popular amongst non-geek users too. Giving the geeks the benefit-of-the-doubt in terms of intelligence, I would say they were perfectly capable of understanding the contract that they signed when they agreed (read: wanted) to use Gmail. Nobody forced it on them.

I find this a fundamental failure to understand basic social dynamics. We store our money in a bank – we don’t “give it” to them. We ask them to store it. The bank signs a contract with us saying they don’t “own” my money, and I have my government establish laws to regulate the behaviour of the banks. I’ve made quite a few financial mistakes myself, losing thousands of rupees. Right from bad insurance investments, to bad mutual fund investments. In every situation, had I choosen to, I could have read the terms of the contract, or hired a competent attorney to do it for me.

It’s the same with Gmail. It’s the same with the iPhone. It doesn’t have to be what you consider as fair – to debate “fairness” go to a philosophy class. It wasn’t as if there wasn’t a big outcry raised over it – so nobody can claim Google did it silently. Everyone knew. Every willingly signed the contract.

It makes the people who hand over their data idiots. It doesn’t make the technology used to transmit the data bad. If someone was stupid enough to send floppies of his private files to Google with a certificate of transfer of ownership of those files to Google, it just makes the person a moron. It doesn’t make floppies bad. Heck, you may argue it makes Google bad, but it still doesn’t make floppies bad!

Whatever the technology the computing industry is rebranding – the technology cannot be blamed because people are incompetent enough to give away their rights to data when thousands of blogs on the web are talking about the terms and conditions. The best Stallman should be doing is to ask his followers to devote some of their valuable time reading contracts carefully, at the expense of getting only a level-4 insightful rating on Slashdot

On the point of whether “Cloud Computing” itself has any substance of not, only the market will tell. If it’s the same old crap re-packaged in new wrapping, the market won’t buy it. It may make the technology bad-as-in-crappy, but still doesn’t make the technology bad-as-in-evil!

October 12, 2008

VLC on Ubuntu can’t play files in folders with special chars?

Filed under: Uncategorized — Tags: , , , , , — archisgore @ 5:48 pm

Now this was way too stupid and annoying that I had to take the trouble and spread the word. I have some videos in a path where some folder names contain characters like +, (, and ). VLC threw some wierdo “could not open file” error (I didn’t care to read it much).

Copied the file to my root and double-clicked, and it just worked.

I’m sure most of you expect me to fix the bug myself – which I really wouldn’t mind if I didn’t have to go through the process of submitting a patch upstream.

October 10, 2008

On Terrorists and Freedom Fighters

Filed under: Uncategorized — Tags: , , , , , — archisgore @ 3:26 am

A friend of mine recently blogged about the latest bombings taking place in prominent Indian cities. He and I had a rather interesting exchange of comments which prompted me to write an entry of my own here.

I like to think of this as a memory-dump of all my thoughts on terrorists, freedom fighters, oppresive governments, fundamentalism, rights, duties, etc. – all that sort of stuff that sounds “noble” and “heroic” when told on stories.

Let me begin with one thought on Gandhianism (I admit I’m biased due to my own family being Gandhians and perhaps I never saw the proverbial “other side of the story.”) One of the things that any religion (well, all religions I know of so far) speaks of is purity of character. In particular, some of the great epics of Indian mythology (some may call it history) speak of this by far. There are no “gray areas”. There are no “acceptable deviances”. Even Yudhishthir, the eldest of the Pandavs, had to suffer Hell in order to atone for his one deception in his entire life. Sure, technically he spoke no false, but that didn’t let him off the hook.

What makes Gandhianism so appealing to me is the same principle reflected in his methods. You may claim Gandhi did absolutely nothing for the country. You may claim he was a worthless burden on earth. But no action of his can be labelled an act of Terrorism. Not by a long shot. A true religious movement cannot have “exceptions” or deviations. Perhaps we need to rethink whether Gandhi’s so-called secular movement was truly adhering to religion, or whether contemporary terrorists are more religious.

On this note, I will also venture to answer the question that most of you will start asking in the comments. What is meant by his advice that we turn the other cheek forward if the enemy slaps us on one cheek. The advice at first sight seems like that of surrender – of cowards. It is a matter of interpretation. To me, this is the same phrase that is glamourised in hollywood movies every single day – “The United States of America does not negotiate with terrorists.”

Turning the other cheek does not mean that you should not defend yourself. It rather means that the fear of getting slapped on the other cheek shall not deter you from what you believe in. It means that if a terrorist bombs one city, then the fear of bombing another city shall not make us negotiate with them or bow to their terms. In a religious context, it means that there can be no justification whatsoever for breaking religious rules. Just because a certain self-delcared religious cult claims they have the right to kill, doesn’t give you the “exception” to riot, kill, or terrorise and thereby ignore the rules of a religion you claim to follow. Turning the other cheek requires an act of immense bravery – it requires one to overcome anger, fear and other primal instincts and to adhere to religion.

So where does that leave terrorists? Are they just pure evil? Are they born this way? I refuse to believe that. Afterall, how many violent actions against the British Colonial regime do we glamourise in our own history textbooks in our schools? It is what we taught them. The right to oppose and overthrow an oppressive government is not only the right, but the duty of every citizen. However, now all citizens are shown a path by which they can do this – well, at least not the right path. Mathematically speaking, our school education boils down to this:
1. The British Government oppressed us. They do wrong.
2. Anyone opposing them do right.
3. Opposing them involved killings, terrorising, etc.

Some misguided, frustrated or desperate people get this message:
1. The Government is failing us every single day. Farmers dying. Inefficient management. An underground off-the-grid economy. A failing education system. Failure to provide even basic amenities.
2. We need to oppose them.
3. Lets do what people did less than 70 years ago.

It is on this note that I wish to comment. Many of you know my major fight with the University of Pune a couple of years ago – and I had raised this point to the Vice Chancellor at that time. When I take admission in the University, I get many threatening letters of my duties as a student – and the consequences of failing to follow rules. However, I am given no information on my rights in case the University fails to follow their side of the bargain. I have no rights as a citizen of the system. And while it shames me to say this – there was more than one time that I contemplated the use of violent means in order to exercise my rights – rights which I believed I deserved.

If any of you has ever had such sentiments ever in their lives, then we need to at least think of what outlets we can provide these terrorists as an alternative to taking lives of innocent people – which ends up making no difference to the oppressive government they are trying to oppose in the first place. The people they end up killing are potentially the very people who are frustrated and angry and the underdogs – the very people they are perhaps fighting for (if their claim is to be believed).

To be honest, I should like to learn how I can make a difference myself. I recently read about a person being charged with a criminal offense about posting to some orkut community. I may not know much about the case, but in my opinion, this is a blatant constitutional violation. Suppressing freedom of speech, censoring free expression, etc. are not what democray is built upon. I see corruption daily. I complain to the superiors and they take no action. You can complain to their superiors and they take no action. Less than 3% of Indians pay taxes. There are so many people who are making money on the black market. Ironically, these very people, due to their financial strength, end up getting all the previlidges of the government, whereas the taxpayers are insulted, humiliated and thrown out from most government offices. The educational system is the same – broken, filled with idiots, and stagnant with violations.

How does a common man exercise his right to oppose this oppression? How is the failure to crack down on money laundering different from the salt tax (basically a tax arbitrarily applied to some, and exempt to others)? How is the corruption in the educational system different from the era of the British?

Sure, let’s say 99% of terrorists are just plain evil – like the villians in childrens comics. They come out of nowhere and just spend their time and effort in blowing up bombs instead of using that time and energy in sleeping and eating. But if there are those possible 1% people who truly believe they are fighting for the rights and freedom of citizens, then can we help them? Can we educate them? Can we show them alternatives to oppose oppression?

If we don’t act now, we can capture one terrorist and more will come. As history has shown (as well as George Lucas), trying to suppress a rebellion only makes it stronger. The Indian Independence Movement, the American Independence movement, the war against Nazi Germany are examples we study in history every single day. Billions of people died in the 2nd World War, and the losses only increased the resolve of the Allied powers. They didn’t give up or surrender – even though that may have saved lives in the short term. I can’t even imagine the horrors if they had just “given up”.

Perhaps I’m a coward or I’m too lazy – but I didn’t act on my urges to react violently whenever I felt an injustice was being done to me. I can try and justify this cowardice off as “Gandhianism” or whatever but it doesn’t change the fact that I’m a coward. But not everyone will think that way – there will be those who will act. If they are shown a path of non-violence, perhaps we may save just those few 1% from turning into terrorists – that is of course, if we believe saving those few lives is important to us.

October 7, 2008

Avoid GetUniqueDeviceId on Windows Mobiles

Filed under: Uncategorized — Tags: , , , , — archisgore @ 12:47 pm

Again, a piece of information learnt the hard way. GetUniqueDeviceId, while the MSDN documentation guarantees a unique device ID in each device, doesn’t quite work the way it’s supposed to in actual practice. I don’t know exactly why that is, and there’s not much documentation, but the symptom is that multiple devices will keep throwing the same Device ID and thus its uniqueness is not guaranteed.

There are various workarounds you can use. In case your app just needs a different identifier for each device, the simplest and most elegant method is to generate a GUID and store it. Naturally, the side-effect of this is that if your app is ever uninstalled, the GUID is lost and the device gets a new identifier.

In such a case, where you need the device to be identified as the same device without storing any state locally, you may use a fixed seed and CryptProtectData it to generate the ID. CryptProtectData uses a provisioned private key on the device to encrypt a given string. This way, regardless of the state of your app, so long as you give it an identical string as input multiple times, you will get the exact same device identifier on the device, and yet a different identifier on different devices.

You can always go one step further to guarantee uniqueness and consistency even more. That would be to get the device’s IMEI number (if the device has a phone in it), and use CryptProtectData on that.

Using the webbrowser control in Windows Mobile

Filed under: Uncategorized — Tags: , , , , , , — archisgore @ 10:10 am

After eighteen months, I got a weekend free to write my own code, and hence continues my series on avoiding some major gottcha’s in WM coding.

One of the major frustrations you would hit is the webbrowser control. There are many scenarios when you want a formatted text based UX, or a flow-style UX where the WebBrowser control comes in pretty handy. However, here are a few things you should know before you start coding – lest you end up investing months of effort and finding out you won’t get the “exact” same effect as you hoped for.

All in all, it’s an amazing component that at times you will be very very thankful they included.

1. Most of the COM Interfaces that allow extensibility on the desktop aren’t supported on the phone (duh!). Most specifically the ones you’ll miss are the IDocHostUIHandler (preventing you from overloading the context menu), and IInternetSecurityManager (preventing you from implementing your own security zone/settings).

2. The DOM elements are specially made-for-mobile COM classes which are named IPIEHTML* instead of the IHTML*. Your Anchor would be IPIEHTMLAnchorElement (or somethign like that). There isn’t any documentation on these so don’t waste time hunting. Instead open up webvw.idl found in one of the sdk include paths and you’ll be able to figure out what does what.

3. DHTML is *NOT* supported. Many people repeatedly try to modify formatting/style of elements in a generated page. The precise and unambigious answer is “it cannot be done”. Don’t waste time trying. Having said that, the IPIEHTMLControlElement derivatives support some on-the-fly modification such as setting/modifing text in text boxes, or editing of lists, and disabling/enabling controls.

4. Some features not supported on desktop are actually supported on the mobile control. Some esoteric CSS pseudoclasses such as :focus which don’t work on desktop IE, work perfectly on pocket IE. You can make some really cool effects by changing formatting when a control is focussed – especially on smartphones where the dotted-line focus highlight can be too thin to notice and you might want to add a little more jazz to your links. In this case, there’s an undocumented CSS extension called x-focus-border which when set to none will get rid of the focus rectangle (found this in the comments section of the IE Mobile Blog).

5. If you’re using Document->Write to insert HTML into the control from your app, then note that the DocumentComplete event is not guaranteed to be fired. I found no documentation on this yet, but I’ve seen the symptom a few times. I admit that I may be doing something wrong here, but it’s something worth keeping in mind if you’re going to rely on that. Ensure you test this out with your pages first. To be more specific, when I didn’t put a background picture for the page, I didn’t get this event. When I did put a background picture, the event fires consistently as expected. The workaround, of course, is to put a dummy one-pixel white image as background.

That’s all I can think of for now. Will post more regularly on avoiding various gottchas that can end up saving a lot of time when developing for WM, if you know what to look out for.

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 122 other followers