summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-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;
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 */