This won't work.  Suppose we are out of space on the sdcard, and are displaying hte "no space" overlay. Then the battery goes too low and we display the "battery too low" overlay.  Then the user plugs the phone is so we enter the charging state and this code gets run.  Now the "no space" overlay is gone too, and the user can take a picture that cannot be saved.

The problem is that this controller class is not well designed.  It allows an array of overlays and allows them to be added one by one, but there is no way to remove them other than by removing them all at once.  So once a new overlay has been added the old overlay will never be seen again. This means that there is no need for hte overlays[] array and the destroyOverlays() method.  They are both useless.

In order to get the battery overlay to work correctly, you'll have to fix the broken storage overlays first.  Sorry about that!

Here's what I propose.  Get rid of hte overlays[] array and the destroyOverlays() method.  And get rid of your previousOverlay property, too.  Instead, add this.storageOverlay and this.batteryOverlay as properties.  If the storage state changes to be anything other than 'available', create and display an overlay for that and remember it as this.storageOverlay.  If the storage state changes back to available, destroy this.storageOverlay.

Similarly, if the battery status goes to shutdown, create a and display an overlay for that case and remember it in this.batteryOverlay.  If the battery stat changes then destroy that overlay.

It is of course possible to have both a storage and a batter overlay displayed at the same time.  The user will see whichever is the more recent overlay.  That is fine.

Does that make sense?  If not, send me email or set needinfo on bugzilla and we can discuss it further.