summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/RockboxService.java120
1 files changed, 60 insertions, 60 deletions
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index d078fe83b6..3aeffa21ff 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -52,14 +52,14 @@ import android.view.KeyEvent;
52 * All access should be done through RockboxService.get_instance() for safety. 52 * All access should be done through RockboxService.get_instance() for safety.
53 */ 53 */
54 54
55public class RockboxService extends Service 55public class RockboxService extends Service
56{ 56{
57 /* this Service is really a singleton class - well almost. 57 /* this Service is really a singleton class - well almost.
58 * To do it properly this line should be instance = new RockboxService() 58 * To do it properly this line should be instance = new RockboxService()
59 * but apparently that doesnt work with the way android Services are created. 59 * but apparently that doesnt work with the way android Services are created.
60 */ 60 */
61 private static RockboxService instance = null; 61 private static RockboxService instance = null;
62 62
63 /* locals needed for the c code and rockbox state */ 63 /* locals needed for the c code and rockbox state */
64 private static volatile boolean rockbox_running; 64 private static volatile boolean rockbox_running;
65 private Activity current_activity = null; 65 private Activity current_activity = null;
@@ -84,25 +84,25 @@ public class RockboxService extends Service
84 mMediaButtonReceiver = new MediaButtonReceiver(this); 84 mMediaButtonReceiver = new MediaButtonReceiver(this);
85 fg_runner = new RunForegroundManager(this); 85 fg_runner = new RunForegroundManager(this);
86 } 86 }
87 87
88 public static RockboxService get_instance() 88 public static RockboxService get_instance()
89 { 89 {
90 /* don't call the construtor here, the instances are managed by 90 /* don't call the construtor here, the instances are managed by
91 * android, so we can't just create a new one */ 91 * android, so we can't just create a new one */
92 return instance; 92 return instance;
93 } 93 }
94 94
95 public boolean isRockboxRunning() 95 public boolean isRockboxRunning()
96 { 96 {
97 return rockbox_running; 97 return rockbox_running;
98 } 98 }
99 public Activity get_activity() 99 public Activity get_activity()
100 { 100 {
101 return current_activity; 101 return current_activity;
102 } 102 }
103 public void set_activity(Activity a) 103 public void set_activity(Activity a)
104 { 104 {
105 current_activity = a; 105 current_activity = a;
106 } 106 }
107 107
108 private void do_start(Intent intent) 108 private void do_start(Intent intent)
@@ -125,7 +125,7 @@ public class RockboxService extends Service
125 resultReceiver.send(RESULT_LIB_LOADED, null); 125 resultReceiver.send(RESULT_LIB_LOADED, null);
126 126
127 if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) 127 if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON))
128 { 128 {
129 /* give it a bit of time so we can register button presses 129 /* give it a bit of time so we can register button presses
130 * sleeping longer doesn't work here, apparently Android 130 * sleeping longer doesn't work here, apparently Android
131 * surpresses long sleeps during intent handling */ 131 * surpresses long sleeps during intent handling */
@@ -142,7 +142,7 @@ public class RockboxService extends Service
142 mMediaButtonReceiver.register(); 142 mMediaButtonReceiver.register();
143 if (resultReceiver != null) 143 if (resultReceiver != null)
144 resultReceiver.send(RESULT_SERVICE_RUNNING, null); 144 resultReceiver.send(RESULT_SERVICE_RUNNING, null);
145 145
146 rockbox_running = true; 146 rockbox_running = true;
147 } 147 }
148 148
@@ -150,7 +150,7 @@ public class RockboxService extends Service
150 { 150 {
151 Log.d("Rockbox", (String) text); 151 Log.d("Rockbox", (String) text);
152 } 152 }
153 153
154 private void LOG(CharSequence text, Throwable tr) 154 private void LOG(CharSequence text, Throwable tr)
155 { 155 {
156 Log.d("Rockbox", (String) text, tr); 156 Log.d("Rockbox", (String) text, tr);
@@ -168,7 +168,7 @@ public class RockboxService extends Service
168 168
169 private void startservice() 169 private void startservice()
170 { 170 {
171 final Object lock = new Object(); 171 final Object lock = new Object();
172 Thread rb = new Thread(new Runnable() 172 Thread rb = new Thread(new Runnable()
173 { 173 {
174 public void run() 174 public void run()
@@ -183,35 +183,35 @@ public class RockboxService extends Service
183 lock.notify(); 183 lock.notify();
184 } 184 }
185 185
186 /* the following block unzips libmisc.so, which contains the files 186 /* the following block unzips libmisc.so, which contains the files
187 * we ship, such as themes. It's needed to put it into a .so file 187 * we ship, such as themes. It's needed to put it into a .so file
188 * because there's no other way to ship files and have access 188 * because there's no other way to ship files and have access
189 * to them from native code 189 * to them from native code
190 */ 190 */
191 File libMisc = new File("/data/data/org.rockbox/lib/libmisc.so"); 191 File libMisc = new File("/data/data/org.rockbox/lib/libmisc.so");
192 /* use arbitrary file to determine whether extracting is needed */ 192 /* use arbitrary file to determine whether extracting is needed */
193 File arbitraryFile = new File(rockboxDir, "viewers.config"); 193 File arbitraryFile = new File(rockboxDir, "viewers.config");
194 if (!arbitraryFile.exists() || (libMisc.lastModified() > arbitraryFile.lastModified())) 194 if (!arbitraryFile.exists() || (libMisc.lastModified() > arbitraryFile.lastModified()))
195 { 195 {
196 try 196 try
197 { 197 {
198 Bundle progressData = new Bundle(); 198 Bundle progressData = new Bundle();
199 byte data[] = new byte[BUFFER]; 199 byte data[] = new byte[BUFFER];
200 ZipFile zipfile = new ZipFile(libMisc); 200 ZipFile zipfile = new ZipFile(libMisc);
201 Enumeration<? extends ZipEntry> e = zipfile.entries(); 201 Enumeration<? extends ZipEntry> e = zipfile.entries();
202 progressData.putInt("max", zipfile.size()); 202 progressData.putInt("max", zipfile.size());
203 203
204 while(e.hasMoreElements()) 204 while(e.hasMoreElements())
205 { 205 {
206 ZipEntry entry = (ZipEntry) e.nextElement(); 206 ZipEntry entry = (ZipEntry) e.nextElement();
207 File file; 207 File file;
208 /* strip off /.rockbox when extracting */ 208 /* strip off /.rockbox when extracting */
209 String fileName = entry.getName(); 209 String fileName = entry.getName();
210 int slashIndex = fileName.indexOf('/', 1); 210 int slashIndex = fileName.indexOf('/', 1);
211 file = new File(rockboxDirPath + fileName.substring(slashIndex)); 211 file = new File(rockboxDirPath + fileName.substring(slashIndex));
212 212
213 if (!entry.isDirectory()) 213 if (!entry.isDirectory())
214 { 214 {
215 /* Create the parent folders if necessary */ 215 /* Create the parent folders if necessary */
216 File folder = new File(file.getParent()); 216 File folder = new File(file.getParent());
217 if (!folder.exists()) 217 if (!folder.exists())
@@ -229,22 +229,22 @@ public class RockboxService extends Service
229 dest.flush(); 229 dest.flush();
230 dest.close(); 230 dest.close();
231 is.close(); 231 is.close();
232 } 232 }
233 233
234 if (resultReceiver != null) { 234 if (resultReceiver != null) {
235 progressData.putInt("value", progressData.getInt("value", 0) + 1); 235 progressData.putInt("value", progressData.getInt("value", 0) + 1);
236 resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData); 236 resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData);
237 } 237 }
238 } 238 }
239 } catch(Exception e) { 239 } catch(Exception e) {
240 LOG("Exception when unzipping", e); 240 LOG("Exception when unzipping", e);
241 e.printStackTrace(); 241 e.printStackTrace();
242 if (resultReceiver != null) { 242 if (resultReceiver != null) {
243 Bundle bundle = new Bundle(); 243 Bundle bundle = new Bundle();
244 bundle.putString("error", getString(R.string.error_extraction)); 244 bundle.putString("error", getString(R.string.error_extraction));
245 resultReceiver.send(RESULT_ERROR_OCCURED, bundle); 245 resultReceiver.send(RESULT_ERROR_OCCURED, bundle);
246 } 246 }
247 } 247 }
248 } 248 }
249 249
250 /* Generate default config if none exists yet */ 250 /* Generate default config if none exists yet */
@@ -267,8 +267,8 @@ public class RockboxService extends Service
267 } 267 }
268 268
269 /* Start native code */ 269 /* Start native code */
270 if (resultReceiver != null) 270 if (resultReceiver != null)
271 resultReceiver.send(RESULT_INVOKING_MAIN, null); 271 resultReceiver.send(RESULT_INVOKING_MAIN, null);
272 272
273 main(); 273 main();
274 274
@@ -281,10 +281,10 @@ public class RockboxService extends Service
281 }, "Rockbox thread"); 281 }, "Rockbox thread");
282 rb.setDaemon(false); 282 rb.setDaemon(false);
283 /* wait at least until the library is loaded */ 283 /* wait at least until the library is loaded */
284 synchronized (lock) 284 synchronized (lock)
285 { 285 {
286 rb.start(); 286 rb.start();
287 while(true) 287 while(true)
288 { 288 {
289 try { 289 try {
290 lock.wait(); 290 lock.wait();
@@ -292,34 +292,34 @@ public class RockboxService extends Service
292 continue; 292 continue;
293 } 293 }
294 break; 294 break;
295 } 295 }
296 } 296 }
297 } 297 }
298 298
299 private native void main(); 299 private native void main();
300 300
301 @Override 301 @Override
302 public IBinder onBind(Intent intent) 302 public IBinder onBind(Intent intent)
303 { 303 {
304 // TODO Auto-generated method stub 304 // TODO Auto-generated method stub
305 return null; 305 return null;
306 } 306 }
307 307
308 308
309 private void initBatteryMonitor() 309 private void initBatteryMonitor()
310 { 310 {
311 itf = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); 311 itf = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
312 batt_monitor = new BroadcastReceiver() 312 batt_monitor = new BroadcastReceiver()
313 { 313 {
314 @Override 314 @Override
315 public void onReceive(Context context, Intent intent) 315 public void onReceive(Context context, Intent intent)
316 { 316 {
317 /* we get literally spammed with battery statuses 317 /* we get literally spammed with battery statuses
318 * if we don't delay the re-attaching 318 * if we don't delay the re-attaching
319 */ 319 */
320 TimerTask tk = new TimerTask() 320 TimerTask tk = new TimerTask()
321 { 321 {
322 public void run() 322 public void run()
323 { 323 {
324 registerReceiver(batt_monitor, itf); 324 registerReceiver(batt_monitor, itf);
325 } 325 }
@@ -332,25 +332,25 @@ public class RockboxService extends Service
332 battery_level = (rawlevel * 100) / scale; 332 battery_level = (rawlevel * 100) / scale;
333 else 333 else
334 battery_level = -1; 334 battery_level = -1;
335 /* query every 30s should be sufficient */ 335 /* query every 30s should be sufficient */
336 t.schedule(tk, 30000); 336 t.schedule(tk, 30000);
337 } 337 }
338 }; 338 };
339 registerReceiver(batt_monitor, itf); 339 registerReceiver(batt_monitor, itf);
340 } 340 }
341 341
342 void startForeground() 342 void startForeground()
343 { 343 {
344 fg_runner.startForeground(); 344 fg_runner.startForeground();
345 } 345 }
346 346
347 void stopForeground() 347 void stopForeground()
348 { 348 {
349 fg_runner.stopForeground(); 349 fg_runner.stopForeground();
350 } 350 }
351 351
352 @Override 352 @Override
353 public void onDestroy() 353 public void onDestroy()
354 { 354 {
355 super.onDestroy(); 355 super.onDestroy();
356 mMediaButtonReceiver.unregister(); 356 mMediaButtonReceiver.unregister();