summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/Helper/RunForegroundManager.java2
-rw-r--r--android/src/org/rockbox/RockboxService.java56
-rw-r--r--apps/hosted/notification.c5
3 files changed, 45 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
25 private IRunForeground api; 25 private IRunForeground api;
26 private Service mCurrentService; 26 private Service mCurrentService;
27 27
28 public RunForegroundManager(Service service) throws Exception 28 public RunForegroundManager(Service service)
29 { 29 {
30 mCurrentService = service; 30 mCurrentService = service;
31 mNM = (NotificationManager) 31 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
69 @SuppressWarnings("unused") 69 @SuppressWarnings("unused")
70 private int battery_level; 70 private int battery_level;
71 private ResultReceiver resultReceiver; 71 private ResultReceiver resultReceiver;
72 final private Object lock = new Object();
72 73
73 public static final int RESULT_INVOKING_MAIN = 0; 74 public static final int RESULT_INVOKING_MAIN = 0;
74 public static final int RESULT_LIB_LOAD_PROGRESS = 1; 75 public static final int RESULT_LIB_LOAD_PROGRESS = 1;
75 public static final int RESULT_FB_INITIALIZED = 2; 76 public static final int RESULT_FB_INITIALIZED = 2;
76 public static final int RESULT_SERVICE_RUNNING = 3; 77 public static final int RESULT_SERVICE_RUNNING = 3;
77 public static final int RESULT_ERROR_OCCURED = 4; 78 public static final int RESULT_ERROR_OCCURED = 4;
79 public static final int RESULT_LIB_LOADED = 5;
78 80
79 @Override 81 @Override
80 public void onCreate() 82 public void onCreate()
81 { 83 {
82 instance = this; 84 instance = this;
83 mMediaButtonReceiver = new MediaButtonReceiver(this); 85 mMediaButtonReceiver = new MediaButtonReceiver(this);
86 fg_runner = new RunForegroundManager(this);
84 } 87 }
85 88
86 public static RockboxService get_instance() 89 public static RockboxService get_instance()
@@ -108,9 +111,38 @@ public class RockboxService extends Service
108 111
109 if (intent != null && intent.hasExtra("callback")) 112 if (intent != null && intent.hasExtra("callback"))
110 resultReceiver = (ResultReceiver) intent.getParcelableExtra("callback"); 113 resultReceiver = (ResultReceiver) intent.getParcelableExtra("callback");
114
115 /* Display a notification about us starting.
116 * We put an icon in the status bar. */
117 if (fg_runner == null)
118 { /* needs to be initialized before main() runs */
119 try {
120 } catch (Exception e) {
121 e.printStackTrace();
122 }
123 }
124
111 if (!rockbox_running) 125 if (!rockbox_running)
112 startservice(); 126 {
113 127 synchronized(lock)
128 {
129 startservice();
130 while(true) {
131 try {
132 lock.wait();
133 } catch (InterruptedException e) {
134 continue;
135 }
136 break;
137 }
138 fb = new RockboxFramebuffer(this);
139 if (resultReceiver != null)
140 resultReceiver.send(RESULT_FB_INITIALIZED, null);
141 }
142 }
143 if (resultReceiver != null)
144 resultReceiver.send(RESULT_LIB_LOADED, null);
145
114 if (intent != null && intent.getAction() != null) 146 if (intent != null && intent.getAction() != null)
115 { 147 {
116 Log.d("RockboxService", intent.getAction()); 148 Log.d("RockboxService", intent.getAction());
@@ -136,16 +168,6 @@ public class RockboxService extends Service
136 } 168 }
137 } 169 }
138 170
139 /* Display a notification about us starting.
140 * We put an icon in the status bar. */
141 if (fg_runner == null)
142 {
143 try {
144 fg_runner = new RunForegroundManager(this);
145 } catch (Exception e) {
146 e.printStackTrace();
147 }
148 }
149 /* (Re-)attach the media button receiver, in case it has been lost */ 171 /* (Re-)attach the media button receiver, in case it has been lost */
150 mMediaButtonReceiver.register(); 172 mMediaButtonReceiver.register();
151 173
@@ -176,9 +198,6 @@ public class RockboxService extends Service
176 private void startservice() 198 private void startservice()
177 { 199 {
178 final int BUFFER = 8*1024; 200 final int BUFFER = 8*1024;
179 fb = new RockboxFramebuffer(this);
180 if (resultReceiver != null)
181 resultReceiver.send(RESULT_FB_INITIALIZED, null);
182 Thread rb = new Thread(new Runnable() 201 Thread rb = new Thread(new Runnable()
183 { 202 {
184 public void run() 203 public void run()
@@ -249,8 +268,11 @@ public class RockboxService extends Service
249 } 268 }
250 } 269 }
251 } 270 }
252 271
253 System.loadLibrary("rockbox"); 272 synchronized (lock) {
273 System.loadLibrary("rockbox");
274 lock.notify();
275 }
254 276
255 rockbox_running = true; 277 rockbox_running = true;
256 if (resultReceiver != null) 278 if (resultReceiver != null)
diff --git a/apps/hosted/notification.c b/apps/hosted/notification.c
index fa8c286808..4dd1bece3d 100644
--- a/apps/hosted/notification.c
+++ b/apps/hosted/notification.c
@@ -83,6 +83,11 @@ void notification_init(void)
83 "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); 83 "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;");
84 NotificationManager_instance = e->GetObjectField(env_ptr, 84 NotificationManager_instance = e->GetObjectField(env_ptr,
85 RockboxService_instance, nNM); 85 RockboxService_instance, nNM);
86 if (NotificationManager_instance == NULL)
87 {
88 DEBUGF("Failed to get RunForegroundManager instance. Performance will be bad");
89 return;
90 }
86 91
87 jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance); 92 jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance);
88 updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", 93 updateNotification = e->GetMethodID(env_ptr, class, "updateNotification",