summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-02-19 16:42:44 +0000
committerThomas Martitz <kugel@rockbox.org>2011-02-19 16:42:44 +0000
commitd6ce7fe3d4b5fbc2a49207112fe4e88627aa9af4 (patch)
treeb981a55d5de0bc09e685042de759ca6d00dfd58f /android
parent171b4ff807e098f76a70736426e2dca917d808c3 (diff)
Android: Fix some race conditions and crashes on startup.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29341 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'android')
-rw-r--r--android/src/org/rockbox/Helper/RunForegroundManager.java2
-rw-r--r--android/src/org/rockbox/RockboxService.java56
2 files changed, 40 insertions, 18 deletions
diff --git a/android/src/org/rockbox/Helper/RunForegroundManager.java b/android/src/org/rockbox/Helper/RunForegroundManager.java
index 99ac66b686..e8b9620280 100644
--- a/android/src/org/rockbox/Helper/RunForegroundManager.java
+++ b/android/src/org/rockbox/Helper/RunForegroundManager.java
@@ -25,7 +25,7 @@ public class RunForegroundManager
private IRunForeground api;
private Service mCurrentService;
- public RunForegroundManager(Service service) throws Exception
+ public RunForegroundManager(Service service)
{
mCurrentService = service;
mNM = (NotificationManager)
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 912142c7a1..43d122a8cc 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -69,18 +69,21 @@ public class RockboxService extends Service
@SuppressWarnings("unused")
private int battery_level;
private ResultReceiver resultReceiver;
+ final private Object lock = new Object();
public static final int RESULT_INVOKING_MAIN = 0;
public static final int RESULT_LIB_LOAD_PROGRESS = 1;
public static final int RESULT_FB_INITIALIZED = 2;
public static final int RESULT_SERVICE_RUNNING = 3;
public static final int RESULT_ERROR_OCCURED = 4;
+ public static final int RESULT_LIB_LOADED = 5;
@Override
public void onCreate()
{
instance = this;
mMediaButtonReceiver = new MediaButtonReceiver(this);
+ fg_runner = new RunForegroundManager(this);
}
public static RockboxService get_instance()
@@ -108,9 +111,38 @@ public class RockboxService extends Service
if (intent != null && intent.hasExtra("callback"))
resultReceiver = (ResultReceiver) intent.getParcelableExtra("callback");
+
+ /* Display a notification about us starting.
+ * We put an icon in the status bar. */
+ if (fg_runner == null)
+ { /* needs to be initialized before main() runs */
+ try {
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
if (!rockbox_running)
- startservice();
-
+ {
+ synchronized(lock)
+ {
+ startservice();
+ while(true) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ continue;
+ }
+ break;
+ }
+ fb = new RockboxFramebuffer(this);
+ if (resultReceiver != null)
+ resultReceiver.send(RESULT_FB_INITIALIZED, null);
+ }
+ }
+ if (resultReceiver != null)
+ resultReceiver.send(RESULT_LIB_LOADED, null);
+
if (intent != null && intent.getAction() != null)
{
Log.d("RockboxService", intent.getAction());
@@ -136,16 +168,6 @@ public class RockboxService extends Service
}
}
- /* Display a notification about us starting.
- * We put an icon in the status bar. */
- if (fg_runner == null)
- {
- try {
- fg_runner = new RunForegroundManager(this);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
/* (Re-)attach the media button receiver, in case it has been lost */
mMediaButtonReceiver.register();
@@ -176,9 +198,6 @@ public class RockboxService extends Service
private void startservice()
{
final int BUFFER = 8*1024;
- fb = new RockboxFramebuffer(this);
- if (resultReceiver != null)
- resultReceiver.send(RESULT_FB_INITIALIZED, null);
Thread rb = new Thread(new Runnable()
{
public void run()
@@ -249,8 +268,11 @@ public class RockboxService extends Service
}
}
}
-
- System.loadLibrary("rockbox");
+
+ synchronized (lock) {
+ System.loadLibrary("rockbox");
+ lock.notify();
+ }
rockbox_running = true;
if (resultReceiver != null)