summaryrefslogtreecommitdiffstats
path: root/android/src
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 /android/src
parentc00fbc4d06dee2f075e8bb1671350c3079c992bf (diff)
downloadrockbox-f05cdc46f23bf28d31dfc4fc2ebe4d20e4d6f961.tar.gz
rockbox-f05cdc46f23bf28d31dfc4fc2ebe4d20e4d6f961.tar.bz2
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
Diffstat (limited to 'android/src')
-rw-r--r--android/src/org/rockbox/RockboxService.java45
1 files changed, 45 insertions, 0 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;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -16,7 +18,10 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
@@ -36,6 +41,9 @@ public class RockboxService extends Service
private Method mStopForeground;
private Object[] mStartForegroundArgs = new Object[2];
private Object[] mStopForegroundArgs = new Object[1];
+ private IntentFilter itf;
+ private BroadcastReceiver batt_monitor;
+ private int battery_level;
@Override
public void onCreate()
{
@@ -161,6 +169,43 @@ public class RockboxService extends Service
return null;
}
+
+ @SuppressWarnings("unused")
+ /*
+ * Sets up the battery monitor which receives the battery level
+ * about each 30 seconds
+ */
+ private void initBatteryMonitor()
+ {
+ itf = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+ batt_monitor = new BroadcastReceiver()
+ {
+ @Override
+ public void onReceive(Context context, Intent intent)
+ {
+ /* we get literally spammed with battery statuses
+ * if we don't delay the re-attaching
+ */
+ TimerTask tk = new TimerTask() {
+ public void run() {
+ registerReceiver(batt_monitor, itf);
+ }
+ };
+ Timer t = new Timer();
+ context.unregisterReceiver(this);
+ int rawlevel = intent.getIntExtra("level", -1);
+ int scale = intent.getIntExtra("scale", -1);
+ if (rawlevel >= 0 && scale > 0)
+ battery_level = (rawlevel * 100) / scale;
+ else
+ battery_level = -1;
+ /* query every 30s should be sufficient */
+ t.schedule(tk, 30000);
+ }
+ };
+ registerReceiver(batt_monitor, itf);
+ }
+
/* all below is heavily based on the examples found on
* http://developer.android.com/reference/android/app/Service.html
*/