mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Android: Fix some race conditions and crashes on startup.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29341 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
171b4ff807
commit
d6ce7fe3d4
3 changed files with 45 additions and 18 deletions
|
@ -25,7 +25,7 @@ public class RunForegroundManager
|
||||||
private IRunForeground api;
|
private IRunForeground api;
|
||||||
private Service mCurrentService;
|
private Service mCurrentService;
|
||||||
|
|
||||||
public RunForegroundManager(Service service) throws Exception
|
public RunForegroundManager(Service service)
|
||||||
{
|
{
|
||||||
mCurrentService = service;
|
mCurrentService = service;
|
||||||
mNM = (NotificationManager)
|
mNM = (NotificationManager)
|
||||||
|
|
|
@ -69,18 +69,21 @@ public class RockboxService extends Service
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private int battery_level;
|
private int battery_level;
|
||||||
private ResultReceiver resultReceiver;
|
private ResultReceiver resultReceiver;
|
||||||
|
final private Object lock = new Object();
|
||||||
|
|
||||||
public static final int RESULT_INVOKING_MAIN = 0;
|
public static final int RESULT_INVOKING_MAIN = 0;
|
||||||
public static final int RESULT_LIB_LOAD_PROGRESS = 1;
|
public static final int RESULT_LIB_LOAD_PROGRESS = 1;
|
||||||
public static final int RESULT_FB_INITIALIZED = 2;
|
public static final int RESULT_FB_INITIALIZED = 2;
|
||||||
public static final int RESULT_SERVICE_RUNNING = 3;
|
public static final int RESULT_SERVICE_RUNNING = 3;
|
||||||
public static final int RESULT_ERROR_OCCURED = 4;
|
public static final int RESULT_ERROR_OCCURED = 4;
|
||||||
|
public static final int RESULT_LIB_LOADED = 5;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
mMediaButtonReceiver = new MediaButtonReceiver(this);
|
mMediaButtonReceiver = new MediaButtonReceiver(this);
|
||||||
|
fg_runner = new RunForegroundManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RockboxService get_instance()
|
public static RockboxService get_instance()
|
||||||
|
@ -108,9 +111,38 @@ public class RockboxService extends Service
|
||||||
|
|
||||||
if (intent != null && intent.hasExtra("callback"))
|
if (intent != null && intent.hasExtra("callback"))
|
||||||
resultReceiver = (ResultReceiver) intent.getParcelableExtra("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)
|
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)
|
if (intent != null && intent.getAction() != null)
|
||||||
{
|
{
|
||||||
Log.d("RockboxService", intent.getAction());
|
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 */
|
/* (Re-)attach the media button receiver, in case it has been lost */
|
||||||
mMediaButtonReceiver.register();
|
mMediaButtonReceiver.register();
|
||||||
|
|
||||||
|
@ -176,9 +198,6 @@ public class RockboxService extends Service
|
||||||
private void startservice()
|
private void startservice()
|
||||||
{
|
{
|
||||||
final int BUFFER = 8*1024;
|
final int BUFFER = 8*1024;
|
||||||
fb = new RockboxFramebuffer(this);
|
|
||||||
if (resultReceiver != null)
|
|
||||||
resultReceiver.send(RESULT_FB_INITIALIZED, null);
|
|
||||||
Thread rb = new Thread(new Runnable()
|
Thread rb = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
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;
|
rockbox_running = true;
|
||||||
if (resultReceiver != null)
|
if (resultReceiver != null)
|
||||||
|
|
|
@ -83,6 +83,11 @@ void notification_init(void)
|
||||||
"fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;");
|
"fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;");
|
||||||
NotificationManager_instance = e->GetObjectField(env_ptr,
|
NotificationManager_instance = e->GetObjectField(env_ptr,
|
||||||
RockboxService_instance, nNM);
|
RockboxService_instance, nNM);
|
||||||
|
if (NotificationManager_instance == NULL)
|
||||||
|
{
|
||||||
|
DEBUGF("Failed to get RunForegroundManager instance. Performance will be bad");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance);
|
jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance);
|
||||||
updateNotification = e->GetMethodID(env_ptr, class, "updateNotification",
|
updateNotification = e->GetMethodID(env_ptr, class, "updateNotification",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue