summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/android.make5
-rw-r--r--android/src/org/rockbox/RockboxService.java81
-rw-r--r--android/src/org/rockbox/monitors/BatteryMonitor.java74
-rw-r--r--android/src/org/rockbox/monitors/HeadphoneMonitor.java60
-rw-r--r--android/src/org/rockbox/monitors/TelephonyMonitor.java (renamed from android/src/org/rockbox/RockboxTelephony.java)6
5 files changed, 140 insertions, 86 deletions
diff --git a/android/android.make b/android/android.make
index f319bb9507..e4fd3693de 100644
--- a/android/android.make
+++ b/android/android.make
@@ -39,9 +39,10 @@ MANIFEST_SRC := $(ANDROID_DIR)/AndroidManifest.xml
39R_JAVA := $(BUILDDIR)/gen/$(PACKAGE_PATH)/R.java 39R_JAVA := $(BUILDDIR)/gen/$(PACKAGE_PATH)/R.java
40R_OBJ := $(BUILDDIR)/bin/$(PACKAGE_PATH)/R.class 40R_OBJ := $(BUILDDIR)/bin/$(PACKAGE_PATH)/R.class
41 41
42JAVA_SRC := $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/Helper/*.java) 42JAVA_SRC := $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/*.java)
43JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/*.java) 43JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/Helper/*.java)
44JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/widgets/*.java) 44JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/widgets/*.java)
45JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/monitors/*.java)
45JAVA_OBJ := $(call java2class,$(subst $(ANDROID)/src/$(PACKAGE_PATH),$(ANDROID)/bin/$(PACKAGE_PATH),$(JAVA_SRC))) 46JAVA_OBJ := $(call java2class,$(subst $(ANDROID)/src/$(PACKAGE_PATH),$(ANDROID)/bin/$(PACKAGE_PATH),$(JAVA_SRC)))
46 47
47 48
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 49abb52dd5..20b8d0c806 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -27,20 +27,13 @@ import java.io.File;
27import java.io.FileOutputStream; 27import java.io.FileOutputStream;
28import java.io.OutputStreamWriter; 28import java.io.OutputStreamWriter;
29import java.util.Enumeration; 29import java.util.Enumeration;
30import java.util.Timer;
31import java.util.TimerTask;
32import java.util.zip.ZipEntry; 30import java.util.zip.ZipEntry;
33import java.util.zip.ZipFile; 31import java.util.zip.ZipFile;
34
35import org.rockbox.Helper.MediaButtonReceiver; 32import org.rockbox.Helper.MediaButtonReceiver;
36import org.rockbox.Helper.RunForegroundManager; 33import org.rockbox.Helper.RunForegroundManager;
37
38import android.app.Activity; 34import android.app.Activity;
39import android.app.Service; 35import android.app.Service;
40import android.content.BroadcastReceiver;
41import android.content.Context;
42import android.content.Intent; 36import android.content.Intent;
43import android.content.IntentFilter;
44import android.os.Bundle; 37import android.os.Bundle;
45import android.os.Environment; 38import android.os.Environment;
46import android.os.IBinder; 39import android.os.IBinder;
@@ -63,17 +56,9 @@ public class RockboxService extends Service
63 /* locals needed for the c code and rockbox state */ 56 /* locals needed for the c code and rockbox state */
64 private static volatile boolean rockbox_running; 57 private static volatile boolean rockbox_running;
65 private Activity current_activity = null; 58 private Activity current_activity = null;
66 private IntentFilter itf;
67 private IntentFilter ifh;
68 private BroadcastReceiver batt_monitor;
69 private BroadcastReceiver headphone_monitor;
70 private BroadcastReceiver noisy_monitor;
71 private RunForegroundManager fg_runner; 59 private RunForegroundManager fg_runner;
72 private MediaButtonReceiver mMediaButtonReceiver; 60 private MediaButtonReceiver mMediaButtonReceiver;
73 private int battery_level;
74 private int headphone_state;
75 private ResultReceiver resultReceiver; 61 private ResultReceiver resultReceiver;
76 private RockboxService rbservice;
77 62
78 public static final int RESULT_INVOKING_MAIN = 0; 63 public static final int RESULT_INVOKING_MAIN = 0;
79 public static final int RESULT_LIB_LOAD_PROGRESS = 1; 64 public static final int RESULT_LIB_LOAD_PROGRESS = 1;
@@ -314,72 +299,6 @@ public class RockboxService extends Service
314 return null; 299 return null;
315 } 300 }
316 301
317
318 private void initBatteryMonitor()
319 {
320 itf = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
321 batt_monitor = new BroadcastReceiver()
322 {
323 @Override
324 public void onReceive(Context context, Intent intent)
325 {
326 /* we get literally spammed with battery statuses
327 * if we don't delay the re-attaching
328 */
329 TimerTask tk = new TimerTask()
330 {
331 public void run()
332 {
333 registerReceiver(batt_monitor, itf);
334 }
335 };
336 Timer t = new Timer();
337 context.unregisterReceiver(this);
338 int rawlevel = intent.getIntExtra("level", -1);
339 int scale = intent.getIntExtra("scale", -1);
340 if (rawlevel >= 0 && scale > 0)
341 battery_level = (rawlevel * 100) / scale;
342 else
343 battery_level = -1;
344 /* query every 30s should be sufficient */
345 t.schedule(tk, 30000);
346 }
347 };
348 registerReceiver(batt_monitor, itf);
349 }
350
351
352 private void initHeadphoneMonitor()
353 {
354 ifh = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
355 headphone_monitor = new BroadcastReceiver()
356 {
357 @Override
358 public void onReceive(Context context, Intent intent)
359 {
360 int state = intent.getIntExtra("state", -1);
361 LOG("headphone state:" + state);
362 headphone_state = state;
363 }
364 };
365 registerReceiver(headphone_monitor, ifh);
366 noisy_monitor = new BroadcastReceiver()
367 {
368 @Override
369 public void onReceive(Context context, Intent intent)
370 {
371 LOG("audio becoming noisy");
372 headphone_state = 0;
373 }
374 };
375 rbservice = RockboxService.get_instance();
376 /* We're relying on internal API's here,
377 this can break in the future! */
378 rbservice.registerReceiver(noisy_monitor,
379 new IntentFilter("android.media.AUDIO_BECOMING_NOISY"));
380 }
381
382
383 void startForeground() 302 void startForeground()
384 { 303 {
385 fg_runner.startForeground(); 304 fg_runner.startForeground();
diff --git a/android/src/org/rockbox/monitors/BatteryMonitor.java b/android/src/org/rockbox/monitors/BatteryMonitor.java
new file mode 100644
index 0000000000..0896a58242
--- /dev/null
+++ b/android/src/org/rockbox/monitors/BatteryMonitor.java
@@ -0,0 +1,74 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22package org.rockbox.monitors;
23
24import java.util.Timer;
25import java.util.TimerTask;
26import android.content.BroadcastReceiver;
27import android.content.Context;
28import android.content.Intent;
29import android.content.IntentFilter;
30
31public class BatteryMonitor extends BroadcastReceiver
32{
33 private final IntentFilter mBattFilter;
34 private final Context mContext;
35 @SuppressWarnings("unused")
36 private int mBattLevel; /* read by native code */
37
38 /*
39 * We get literally spammed with battery status updates
40 * Therefore we actually unregister after each onReceive() and
41 * setup a timer to re-register in 30s */
42 public BatteryMonitor(Context c)
43 {
44 mBattFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
45 mContext = c;
46 Timer t = new Timer();
47 TimerTask task = new TimerTask()
48 {
49 public void run()
50 {
51 attach();
52 }
53 };
54 t.schedule(task, 5000, 30000);
55 attach();
56 }
57
58 @Override
59 public void onReceive(Context arg0, Intent intent)
60 {
61 int rawlevel = intent.getIntExtra("level", -1);
62 int scale = intent.getIntExtra("scale", -1);
63 if (rawlevel >= 0 && scale > 0)
64 mBattLevel = (rawlevel * 100) / scale;
65 else
66 mBattLevel = -1;
67 mContext.unregisterReceiver(this);
68 }
69
70 void attach()
71 {
72 mContext.registerReceiver(this, mBattFilter);
73 }
74}
diff --git a/android/src/org/rockbox/monitors/HeadphoneMonitor.java b/android/src/org/rockbox/monitors/HeadphoneMonitor.java
new file mode 100644
index 0000000000..99d2f7ab8a
--- /dev/null
+++ b/android/src/org/rockbox/monitors/HeadphoneMonitor.java
@@ -0,0 +1,60 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22package org.rockbox.monitors;
23
24import android.content.BroadcastReceiver;
25import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28
29public class HeadphoneMonitor extends BroadcastReceiver
30{
31 @SuppressWarnings("unused")
32 private int mHpState; /* read by native code */
33
34 public HeadphoneMonitor(Context c)
35 {
36 IntentFilter hpFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
37 /* caution: hidden API; might break */
38 IntentFilter noisyFilter = new IntentFilter("android.media.AUDIO_BECOMING_NOISY");
39
40 c.registerReceiver(this, hpFilter);
41 c.registerReceiver(new NoisyMonitor(), noisyFilter);
42 }
43
44 @Override
45 public void onReceive(Context arg0, Intent intent)
46 {
47 int state = intent.getIntExtra("state", -1);
48 mHpState = state;
49 }
50
51 /* audio becoming noise acts as headphones extracted */
52 private class NoisyMonitor extends BroadcastReceiver
53 {
54 @Override
55 public void onReceive(Context arg0, Intent arg1)
56 {
57 mHpState = 0;
58 }
59 }
60}
diff --git a/android/src/org/rockbox/RockboxTelephony.java b/android/src/org/rockbox/monitors/TelephonyMonitor.java
index faaf0c36b7..6881f243af 100644
--- a/android/src/org/rockbox/RockboxTelephony.java
+++ b/android/src/org/rockbox/monitors/TelephonyMonitor.java
@@ -19,16 +19,16 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22package org.rockbox; 22package org.rockbox.monitors;
23 23
24import android.content.Context; 24import android.content.Context;
25import android.os.Handler; 25import android.os.Handler;
26import android.telephony.PhoneStateListener; 26import android.telephony.PhoneStateListener;
27import android.telephony.TelephonyManager; 27import android.telephony.TelephonyManager;
28 28
29public class RockboxTelephony 29public class TelephonyMonitor
30{ 30{
31 public RockboxTelephony(Context c) 31 public TelephonyMonitor(Context c)
32 { 32 {
33 final Handler handler = new Handler(c.getMainLooper()); 33 final Handler handler = new Handler(c.getMainLooper());
34 final TelephonyManager tm = (TelephonyManager) 34 final TelephonyManager tm = (TelephonyManager)