summaryrefslogtreecommitdiff
path: root/android/src/org/rockbox/RockboxService.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/src/org/rockbox/RockboxService.java')
-rw-r--r--android/src/org/rockbox/RockboxService.java49
1 files changed, 42 insertions, 7 deletions
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index be02342768..c403736c72 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -46,11 +46,22 @@ import android.content.IntentFilter;
46import android.os.IBinder; 46import android.os.IBinder;
47import android.util.Log; 47import android.util.Log;
48 48
49/* This class is used as the main glue between java and c.
50 * All access should be done through RockboxService.get_instance() for safety.
51 */
52
49public class RockboxService extends Service 53public class RockboxService extends Service
50{ 54{
51 /* this Service is really a singleton class */ 55 /* this Service is really a singleton class - well almost.
52 public static RockboxFramebuffer fb = null; 56 * To do it properly this line should be instance = new RockboxService()
53 private static RockboxService instance; 57 * but apparently that doesnt work with the way android Services are created.
58 */
59 private static RockboxService instance = null;
60
61 /* locals needed for the c code and rockbox state */
62 private RockboxFramebuffer fb = null;
63 private boolean mRockboxRunning = false;
64
54 private Notification notification; 65 private Notification notification;
55 private static final Class<?>[] mStartForegroundSignature = 66 private static final Class<?>[] mStartForegroundSignature =
56 new Class[] { int.class, Notification.class }; 67 new Class[] { int.class, Notification.class };
@@ -70,6 +81,7 @@ public class RockboxService extends Service
70 @Override 81 @Override
71 public void onCreate() 82 public void onCreate()
72 { 83 {
84 instance = this;
73 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 85 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
74 try 86 try
75 { 87 {
@@ -83,9 +95,24 @@ public class RockboxService extends Service
83 /* Running on an older platform: fall back to old API */ 95 /* Running on an older platform: fall back to old API */
84 mStartForeground = mStopForeground = null; 96 mStartForeground = mStopForeground = null;
85 } 97 }
86 instance = this;
87 startservice(); 98 startservice();
88 } 99 }
100
101 public static RockboxService get_instance()
102 {
103 return instance;
104 }
105
106 public RockboxFramebuffer get_fb()
107 {
108 return fb;
109 }
110 /* framebuffer is initialised by the native code(!) so this is needed */
111 public void set_fb(RockboxFramebuffer newfb)
112 {
113 fb = newfb;
114 mRockboxRunning = true;
115 }
89 116
90 private void do_start(Intent intent) 117 private void do_start(Intent intent)
91 { 118 {
@@ -190,8 +217,16 @@ public class RockboxService extends Service
190 rb.setDaemon(false); 217 rb.setDaemon(false);
191 rb.start(); 218 rb.start();
192 } 219 }
193
194 private native void main(); 220 private native void main();
221
222 /* returns true once rockbox is up and running.
223 * This is considered done once the framebuffer is initialised
224 */
225 public boolean isRockboxRunning()
226 {
227 return mRockboxRunning;
228 }
229
195 @Override 230 @Override
196 public IBinder onBind(Intent intent) 231 public IBinder onBind(Intent intent)
197 { 232 {
@@ -262,7 +297,7 @@ public class RockboxService extends Service
262 getText(R.string.notification), text, contentIntent); 297 getText(R.string.notification), text, contentIntent);
263 } 298 }
264 299
265 public static void startForeground() 300 public void startForeground()
266 { 301 {
267 if (instance != null) 302 if (instance != null)
268 { 303 {
@@ -282,7 +317,7 @@ public class RockboxService extends Service
282 } 317 }
283 } 318 }
284 319
285 public static void stopForeground() 320 public void stopForeground()
286 { 321 {
287 if (instance.notification != null) 322 if (instance.notification != null)
288 { 323 {