Bring idle poweroff to RaaA and the sim

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29543 a1c6a512-1295-4272-9138-f99709370657
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 1194432..808c858 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -164,7 +164,7 @@
 
 void set_sleep_timer(int seconds);
 int get_sleep_timer(void);
-void handle_sleep_timer(void);
+void handle_auto_poweroff(void);
 void set_car_adapter_mode(bool setting);
 void reset_poweroff_timer(void);
 void cancel_shutdown(void);
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index b1a08bf..d9014dc 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -81,9 +81,9 @@
 
 static int shutdown_timeout = 0;
 
-static void handle_auto_poweroff(void);
+void handle_auto_poweroff(void);
 static int poweroff_timeout = 0;
-static long last_event_tick;
+static long last_event_tick = 0;
 
 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
 /*
@@ -134,11 +134,6 @@
         *level = voltage_to_battery_level(millivolts);
 }
 
-void reset_poweroff_timer(void)
-{
-    last_event_tick = current_tick;
-}
-
 #if BATTERY_TYPES_COUNT > 1
 void set_battery_type(int type)
 {
@@ -204,11 +199,6 @@
 #endif
 }
 
-void set_poweroff_timeout(int timeout)
-{
-    poweroff_timeout = timeout;
-}
-
 /* look into the percent_to_volt_* table and get a realistic battery level */
 static int voltage_to_percent(int voltage, const short* table)
 {
@@ -712,6 +702,16 @@
 }
 #endif /* PLATFORM_NATIVE */
 
+void set_poweroff_timeout(int timeout)
+{
+    poweroff_timeout = timeout;
+}
+
+void reset_poweroff_timer(void)
+{
+    last_event_tick = current_tick;
+}
+
 void sys_poweroff(void)
 {
 #ifndef BOOTLOADER
@@ -790,7 +790,7 @@
         return 0;
 }
 
-void handle_sleep_timer(void)
+static void handle_sleep_timer(void)
 {
     if (!sleeptimer_active)
       return;
@@ -817,7 +817,6 @@
     }
 }
 
-
 /*
  * We shut off in the following cases:
  * 1) The unit is idle, not playing music
@@ -830,7 +829,7 @@
  * 3) We are recording, or recording with pause
  * 4) The radio is playing
  */
-static void handle_auto_poweroff(void)
+void handle_auto_poweroff(void)
 {
     long timeout = poweroff_timeout*60*HZ;
     int audio_stat = audio_status();
@@ -846,7 +845,7 @@
     }
 #endif
 
-#ifndef APPLICATION
+#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
     if (!shutdown_timeout && query_force_shutdown()) {
         backlight_on();
         sys_poweroff();
@@ -863,7 +862,7 @@
           !sleeptimer_active))) {
 
         if (TIME_AFTER(tick, last_event_tick + timeout)
-#ifndef APPLICATION
+#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
             && TIME_AFTER(tick, storage_last_disk_activity() + timeout)
 #endif
         ) {
diff --git a/firmware/target/hosted/android/powermgmt-android.c b/firmware/target/hosted/android/powermgmt-android.c
index e5e8344..d23fece 100644
--- a/firmware/target/hosted/android/powermgmt-android.c
+++ b/firmware/target/hosted/android/powermgmt-android.c
@@ -58,10 +58,6 @@
     return 0;
 }
 
-/* could be useful to stop the service after some time of inactivity */
-void reset_poweroff_timer(void) {}
-void set_poweroff_timeout(int timeout) { (void)timeout; };
-
 /* should always be safe on android targets, the host shuts us down before */
 bool battery_level_safe(void)
 {
diff --git a/firmware/target/hosted/maemo/maemo-thread.c b/firmware/target/hosted/maemo/maemo-thread.c
index 8300c8f..a32a563 100644
--- a/firmware/target/hosted/maemo/maemo-thread.c
+++ b/firmware/target/hosted/maemo/maemo-thread.c
@@ -200,13 +200,3 @@
 {
     return battery_level() >= 5;
 }
-
-/** Rockbox stubs */
-void set_poweroff_timeout(int timeout)
-{
-    (void)timeout;
-}
-
-void reset_poweroff_timer(void)
-{
-}
diff --git a/firmware/target/hosted/powermgmt.c b/firmware/target/hosted/powermgmt.c
index d4103a0..bf05e5f 100644
--- a/firmware/target/hosted/powermgmt.c
+++ b/firmware/target/hosted/powermgmt.c
@@ -44,7 +44,7 @@
         /* Sleep two seconds */
         sleep(HZ*2);
 
-        handle_sleep_timer();
+        handle_auto_poweroff();
     }
 } /* power_thread */
 
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c
index 14054dc..e747d7d 100644
--- a/uisimulator/common/powermgmt-sim.c
+++ b/uisimulator/common/powermgmt-sim.c
@@ -118,11 +118,6 @@
     return battery_level() >= 10;
 }
 
-void set_poweroff_timeout(int timeout)
-{
-    (void)timeout;
-}
-
 void set_battery_capacity(int capacity)
 {
   (void)capacity;
@@ -148,7 +143,3 @@
     (void)enable;
 }
 #endif
-
-void reset_poweroff_timer(void)
-{
-}