summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-09-01 23:36:15 +0000
committerThomas Martitz <kugel@rockbox.org>2010-09-01 23:36:15 +0000
commitf05cdc46f23bf28d31dfc4fc2ebe4d20e4d6f961 (patch)
tree26fb9244e04ffd4297cb918ae8c7de2b731dd28a
parentc00fbc4d06dee2f075e8bb1671350c3079c992bf (diff)
downloadrockbox-f05cdc46f23bf28d31dfc4fc2ebe4d20e4d6f961.tar.gz
rockbox-f05cdc46f23bf28d31dfc4fc2ebe4d20e4d6f961.zip
Android: don't compile powermgmt-sim.c
Instead implement a bit of battery monitoring. Currently it only fetches the battery level (in %) every 30s, but it could do more like battery status, charger connected, voltage... Theoretically, we could also exit/quit after some time of inactivity too (perhaps not a bad idea since Rockbox puts a slight but still non-zero CPU load even if doing nothing). Ironically, Rockbox is now the only way to get the exact battery level (at least I haven't found anything yet) on my phone :-) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27974 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--android/src/org/rockbox/RockboxService.java45
-rw-r--r--apps/settings.c3
-rw-r--r--apps/settings.h2
-rw-r--r--apps/settings_list.c2
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/target/hosted/android/system-android.c3
-rw-r--r--uisimulator/common/SOURCES2
7 files changed, 56 insertions, 2 deletions
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 8ef6b5a302..6dc69b3404 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -9,6 +9,8 @@ import java.io.IOException;
9import java.lang.reflect.InvocationTargetException; 9import java.lang.reflect.InvocationTargetException;
10import java.lang.reflect.Method; 10import java.lang.reflect.Method;
11import java.util.Enumeration; 11import java.util.Enumeration;
12import java.util.Timer;
13import java.util.TimerTask;
12import java.util.zip.ZipEntry; 14import java.util.zip.ZipEntry;
13import java.util.zip.ZipFile; 15import java.util.zip.ZipFile;
14 16
@@ -16,7 +18,10 @@ import android.app.Notification;
16import android.app.NotificationManager; 18import android.app.NotificationManager;
17import android.app.PendingIntent; 19import android.app.PendingIntent;
18import android.app.Service; 20import android.app.Service;
21import android.content.BroadcastReceiver;
22import android.content.Context;
19import android.content.Intent; 23import android.content.Intent;
24import android.content.IntentFilter;
20import android.os.IBinder; 25import android.os.IBinder;
21import android.util.Log; 26import android.util.Log;
22 27
@@ -36,6 +41,9 @@ public class RockboxService extends Service
36 private Method mStopForeground; 41 private Method mStopForeground;
37 private Object[] mStartForegroundArgs = new Object[2]; 42 private Object[] mStartForegroundArgs = new Object[2];
38 private Object[] mStopForegroundArgs = new Object[1]; 43 private Object[] mStopForegroundArgs = new Object[1];
44 private IntentFilter itf;
45 private BroadcastReceiver batt_monitor;
46 private int battery_level;
39 @Override 47 @Override
40 public void onCreate() 48 public void onCreate()
41 { 49 {
@@ -161,6 +169,43 @@ public class RockboxService extends Service
161 return null; 169 return null;
162 } 170 }
163 171
172
173 @SuppressWarnings("unused")
174 /*
175 * Sets up the battery monitor which receives the battery level
176 * about each 30 seconds
177 */
178 private void initBatteryMonitor()
179 {
180 itf = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
181 batt_monitor = new BroadcastReceiver()
182 {
183 @Override
184 public void onReceive(Context context, Intent intent)
185 {
186 /* we get literally spammed with battery statuses
187 * if we don't delay the re-attaching
188 */
189 TimerTask tk = new TimerTask() {
190 public void run() {
191 registerReceiver(batt_monitor, itf);
192 }
193 };
194 Timer t = new Timer();
195 context.unregisterReceiver(this);
196 int rawlevel = intent.getIntExtra("level", -1);
197 int scale = intent.getIntExtra("scale", -1);
198 if (rawlevel >= 0 && scale > 0)
199 battery_level = (rawlevel * 100) / scale;
200 else
201 battery_level = -1;
202 /* query every 30s should be sufficient */
203 t.schedule(tk, 30000);
204 }
205 };
206 registerReceiver(batt_monitor, itf);
207 }
208
164 /* all below is heavily based on the examples found on 209 /* all below is heavily based on the examples found on
165 * http://developer.android.com/reference/android/app/Service.html 210 * http://developer.android.com/reference/android/app/Service.html
166 */ 211 */
diff --git a/apps/settings.c b/apps/settings.c
index 3a851df0ff..e9f0dc9330 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -852,7 +852,10 @@ void settings_apply(bool read_disk)
852#endif 852#endif
853 set_poweroff_timeout(global_settings.poweroff); 853 set_poweroff_timeout(global_settings.poweroff);
854 854
855#if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
855 set_battery_capacity(global_settings.battery_capacity); 856 set_battery_capacity(global_settings.battery_capacity);
857#endif
858
856#if BATTERY_TYPES_COUNT > 1 859#if BATTERY_TYPES_COUNT > 1
857 set_battery_type(global_settings.battery_type); 860 set_battery_type(global_settings.battery_type);
858#endif 861#endif
diff --git a/apps/settings.h b/apps/settings.h
index 7deb2def41..3ba8fe9868 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -619,7 +619,9 @@ struct user_settings
619 619
620 /* power settings */ 620 /* power settings */
621 int poweroff; /* idle power off timer */ 621 int poweroff; /* idle power off timer */
622#if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
622 int battery_capacity; /* in mAh */ 623 int battery_capacity; /* in mAh */
624#endif
623 625
624#if BATTERY_TYPES_COUNT > 1 626#if BATTERY_TYPES_COUNT > 1
625 int battery_type; /* for units which can take multiple types (Ondio). */ 627 int battery_type; /* for units which can take multiple types (Ondio). */
diff --git a/apps/settings_list.c b/apps/settings_list.c
index cab326671a..5a9eeb90ce 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -763,7 +763,7 @@ const struct settings_list settings[] = {
763#endif 763#endif
764 "max files in dir", UNIT_INT, 50, 10000, 50, 764 "max files in dir", UNIT_INT, 50, 10000, 50,
765 NULL, NULL, NULL), 765 NULL, NULL, NULL),
766#if BATTERY_CAPACITY_INC > 0 766#if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
767 INT_SETTING(0, battery_capacity, LANG_BATTERY_CAPACITY, 767 INT_SETTING(0, battery_capacity, LANG_BATTERY_CAPACITY,
768 BATTERY_CAPACITY_DEFAULT, "battery capacity", UNIT_MAH, 768 BATTERY_CAPACITY_DEFAULT, "battery capacity", UNIT_MAH,
769 BATTERY_CAPACITY_MIN, BATTERY_CAPACITY_MAX, 769 BATTERY_CAPACITY_MIN, BATTERY_CAPACITY_MAX,
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 8b71674b36..ac1a3e1be4 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1709,6 +1709,7 @@ target/hosted/android/lc-android.c
1709target/hosted/android/button-android.c 1709target/hosted/android/button-android.c
1710target/hosted/android/kernel-android.c 1710target/hosted/android/kernel-android.c
1711target/hosted/android/pcm-android.c 1711target/hosted/android/pcm-android.c
1712target/hosted/android/powermgmt-android.c
1712target/hosted/android/system-android.c 1713target/hosted/android/system-android.c
1713#ifdef APPLICATION 1714#ifdef APPLICATION
1714target/hosted/android/app/button-application.c 1715target/hosted/android/app/button-application.c
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index 1fb69b3465..87b6584135 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -55,5 +55,8 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
55 env_ptr = env; 55 env_ptr = env;
56 RockboxService_instance = this; 56 RockboxService_instance = this;
57 RockboxService_class = (*env)->GetObjectClass(env, this); 57 RockboxService_class = (*env)->GetObjectClass(env, this);
58
59
60 powermgmt_init_target();
58 main(); 61 main();
59} 62}
diff --git a/uisimulator/common/SOURCES b/uisimulator/common/SOURCES
index db5b22fa42..5f068c5bdc 100644
--- a/uisimulator/common/SOURCES
+++ b/uisimulator/common/SOURCES
@@ -12,7 +12,7 @@ backlight-sim.c
12#if (CONFIG_PLATFORM & PLATFORM_SDL) 12#if (CONFIG_PLATFORM & PLATFORM_SDL)
13io.c 13io.c
14sim_tasks.c 14sim_tasks.c
15powermgmt-sim.c
15#endif 16#endif
16/* this is still needed for application since it has some stubs */ 17/* this is still needed for application since it has some stubs */
17powermgmt-sim.c
18stubs.c 18stubs.c