January 2010 2 posts

Windows Mobile is so broken the clock doesn't even work

Monday, January 11, 2010


This is part one of what will probably become a gigantic laundry list of my grievances against Windows Mobile.

Here is my shiny, not-quite-new-anymore HTC Touch Pro 2 (AT&T calls it the Tilt 2).

Windows Mobile 6.5 locked screen

Even on this simple screen, the locked screen where you can't do anything other than unlock it, there are many things wrong:

  1. Obviously the biggest problem is that the top right corner says 14:48 (the correct time) and the bottom, in big bold numbers, it says 00:00. Midnight is of absolutely no relevance to anything whatsoever, other than perhaps being an uninitialized/broken clock value. I have no meetings, alarms, or anything scheduled at midnight.
  2. The 00:00 (which displays the actual time 80% of the time, and midnight 20% of the time) is only available on this locked screen because the screen has more useful stuff when it's unlocked. The 14:48 in the top right is only displaying because I enabled a setting somewhere, which means when the phone is unlocked, by default you can't even see what time it is. (And when it's locked you often see a useless time.)
  3. How much battery charge do I have left? I have no idea. I also haven't figured out whether there exists a setting somewhere to enable displaying an icon for that.
  4. Why is there a big H icon (the type of data connection) and then a little H icon with signal bars next to it? Sometimes the big H turns into 3G or E — and the little symbol over the signal bars always changes with it. Why waste space with two icons when one clearly suffices? If this is not the case, why make it so confusing that I, as a Windows Mobile developer, can't even figure it out?

Tags: sucks, winmo | Posted at 20:57 | Comments (1)

Detecting user activity/inactivity in a Windows Mobile app

Saturday, January 9, 2010


There doesn't appear to be a simple API call on Windows Mobile or Windows CE to get the amount of time that the user has been idle. For example, maybe you want to pop up a dialog box or quit your app if the user hasn't done anything for more than 5 minutes. A quick search might turn up GetIdleTime(), but that function is for CPU idle time, not user idle time.

Most recent Windows Mobile devices use a Power Manager, which keeps track of this stuff. You can use the named activity timers "PowerManager/UserActivity_Active" and "PowerManager/UserActivity_Inactive" to detect when the user has become active and inactive. On the couple of devices I looked at, these events have timing resolutions of 100 ms, which is good enough for most purposes and won't cause your code to peg the CPU by constantly firing events. However, there does not appear to be any guarantee that these two activity timers actually exist and function correctly on every device.

Below is a code snippet that uses these events in managed code:

private const EVENT_ALL_ACCESS = 0x1F0003;
private const ActiveName = "PowerManager/UserActivity_Active";
private const InactiveName = "PowerManager/UserActivity_Inactive";

[DllImport("coredll.dll")]
private static extern IntPtr OpenEvent(int desiredAccess, bool inheritHandle, string name);
[DllImport("coredll.dll")]
private static extern int WaitForSingleObject(IntPtr handle, int milliseconds);

public static void Main(string[] args) {
  IntPtr activitySignal = OpenEvent(EVENT_ALL_ACCESS, false, ActiveName);
  IntPtr inactivitySignal = OpenEvent(EVENT_ALL_ACCESS, false, InactiveName);
  if(activitySignal == IntPtr.Zero || inactivitySignal == IntPtr.Zero) {
    // Can't open the events -- this device probably doesn't define them
    return;
  }
  while(true) {
    WaitForSingleObject(activitySignal, int.MaxValue);
    WriteLine("User is now active.");
    WaitForSingleObject(inactivitySignal, int.MaxValue);
    WriteLine("User is now inactive.");
  }
}

Given this code, it is then fairly trivial to figure out whether the user is currently active and if not, how long the user has been inactive. It's also easy to write a function that performs some action (like calling a callback) once the user has been idle for some amount of time.

Tags: idle, inactivity, wince, winmo | Posted at 13:09 | Comments (2)