summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/Helper/MediaButtonReceiver.java2
-rw-r--r--android/src/org/rockbox/RockboxActivity.java4
-rw-r--r--android/src/org/rockbox/RockboxKeyboardInput.java4
-rw-r--r--android/src/org/rockbox/RockboxPCM.java8
-rw-r--r--android/src/org/rockbox/RockboxService.java116
-rw-r--r--android/src/org/rockbox/RockboxYesno.java4
6 files changed, 63 insertions, 75 deletions
diff --git a/android/src/org/rockbox/Helper/MediaButtonReceiver.java b/android/src/org/rockbox/Helper/MediaButtonReceiver.java
index e74ec5c8c2..a07e328c13 100644
--- a/android/src/org/rockbox/Helper/MediaButtonReceiver.java
+++ b/android/src/org/rockbox/Helper/MediaButtonReceiver.java
@@ -88,7 +88,7 @@ public class MediaButtonReceiver
88 KeyEvent key = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); 88 KeyEvent key = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
89 if (key.getAction() == KeyEvent.ACTION_UP) 89 if (key.getAction() == KeyEvent.ACTION_UP)
90 { /* pass the pressed key to Rockbox, starting it if needed */ 90 { /* pass the pressed key to Rockbox, starting it if needed */
91 RockboxService s = RockboxService.get_instance(); 91 RockboxService s = RockboxService.getInstance();
92 if (s == null || !s.isRockboxRunning()) 92 if (s == null || !s.isRockboxRunning())
93 startService(context, intent); 93 startService(context, intent);
94 else if (RockboxFramebuffer.buttonHandler(key.getKeyCode(), false)) 94 else if (RockboxFramebuffer.buttonHandler(key.getKeyCode(), false))
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index 372d866849..166d69ebe0 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -91,9 +91,9 @@ public class RockboxActivity extends Activity
91 91
92 private void setServiceActivity(boolean set) 92 private void setServiceActivity(boolean set)
93 { 93 {
94 RockboxService s = RockboxService.get_instance(); 94 RockboxService s = RockboxService.getInstance();
95 if (s != null) 95 if (s != null)
96 s.set_activity(set ? this : null); 96 s.setActivity(set ? this : null);
97 } 97 }
98 98
99 public void onResume() 99 public void onResume()
diff --git a/android/src/org/rockbox/RockboxKeyboardInput.java b/android/src/org/rockbox/RockboxKeyboardInput.java
index 107b72ddae..540ba12c22 100644
--- a/android/src/org/rockbox/RockboxKeyboardInput.java
+++ b/android/src/org/rockbox/RockboxKeyboardInput.java
@@ -35,7 +35,7 @@ public class RockboxKeyboardInput
35{ 35{
36 public void kbd_input(final String text, final String ok, final String cancel) 36 public void kbd_input(final String text, final String ok, final String cancel)
37 { 37 {
38 final Activity c = RockboxService.get_instance().get_activity(); 38 final Activity c = RockboxService.getInstance().getActivity();
39 39
40 c.runOnUiThread(new Runnable() { 40 c.runOnUiThread(new Runnable() {
41 public void run() 41 public void run()
@@ -74,6 +74,6 @@ public class RockboxKeyboardInput
74 74
75 public boolean is_usable() 75 public boolean is_usable()
76 { 76 {
77 return RockboxService.get_instance().get_activity() != null; 77 return RockboxService.getInstance().getActivity() != null;
78 } 78 }
79} 79}
diff --git a/android/src/org/rockbox/RockboxPCM.java b/android/src/org/rockbox/RockboxPCM.java
index f77bf3bb8f..e77a1b00d9 100644
--- a/android/src/org/rockbox/RockboxPCM.java
+++ b/android/src/org/rockbox/RockboxPCM.java
@@ -69,7 +69,7 @@ public class RockboxPCM extends AudioTrack
69 Arrays.fill(raw_data, (byte) 0); 69 Arrays.fill(raw_data, (byte) 0);
70 70
71 /* find cleaner way to get context? */ 71 /* find cleaner way to get context? */
72 rbservice = RockboxService.get_instance(); 72 rbservice = RockboxService.getInstance();
73 audiomanager = 73 audiomanager =
74 (AudioManager) rbservice.getSystemService(Context.AUDIO_SERVICE); 74 (AudioManager) rbservice.getSystemService(Context.AUDIO_SERVICE);
75 maxstreamvolume = audiomanager.getStreamMaxVolume(streamtype); 75 maxstreamvolume = audiomanager.getStreamMaxVolume(streamtype);
@@ -147,7 +147,7 @@ public class RockboxPCM extends AudioTrack
147 147
148 private void play_pause(boolean pause) 148 private void play_pause(boolean pause)
149 { 149 {
150 RockboxService service = RockboxService.get_instance(); 150 RockboxService service = RockboxService.getInstance();
151 if (pause) 151 if (pause)
152 { 152 {
153 Intent widgetUpdate = new Intent("org.rockbox.UpdateState"); 153 Intent widgetUpdate = new Intent("org.rockbox.UpdateState");
@@ -192,8 +192,8 @@ public class RockboxPCM extends AudioTrack
192 192
193 Intent widgetUpdate = new Intent("org.rockbox.UpdateState"); 193 Intent widgetUpdate = new Intent("org.rockbox.UpdateState");
194 widgetUpdate.putExtra("state", "stop"); 194 widgetUpdate.putExtra("state", "stop");
195 RockboxService.get_instance().sendBroadcast(widgetUpdate); 195 RockboxService.getInstance().sendBroadcast(widgetUpdate);
196 RockboxService.get_instance().stopForeground(); 196 RockboxService.getInstance().stopForeground();
197 } 197 }
198 198
199 public int setStereoVolume(float leftVolume, float rightVolume) 199 public int setStereoVolume(float leftVolume, float rightVolume)
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 4242726331..5c8f8cfd99 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -29,6 +29,7 @@ import java.io.OutputStreamWriter;
29import java.util.Enumeration; 29import java.util.Enumeration;
30import java.util.zip.ZipEntry; 30import java.util.zip.ZipEntry;
31import java.util.zip.ZipFile; 31import java.util.zip.ZipFile;
32import org.rockbox.Helper.Logger;
32import org.rockbox.Helper.MediaButtonReceiver; 33import org.rockbox.Helper.MediaButtonReceiver;
33import org.rockbox.Helper.RunForegroundManager; 34import org.rockbox.Helper.RunForegroundManager;
34import android.app.Activity; 35import android.app.Activity;
@@ -38,7 +39,6 @@ import android.os.Bundle;
38import android.os.Environment; 39import android.os.Environment;
39import android.os.IBinder; 40import android.os.IBinder;
40import android.os.ResultReceiver; 41import android.os.ResultReceiver;
41import android.util.Log;
42import android.view.KeyEvent; 42import android.view.KeyEvent;
43 43
44/* This class is used as the main glue between java and c. 44/* This class is used as the main glue between java and c.
@@ -47,19 +47,17 @@ import android.view.KeyEvent;
47 47
48public class RockboxService extends Service 48public class RockboxService extends Service
49{ 49{
50 /* this Service is really a singleton class - well almost. 50 /* this Service is really a singleton class - well almost. */
51 * To do it properly this line should be instance = new RockboxService()
52 * but apparently that doesnt work with the way android Services are created.
53 */
54 private static RockboxService instance = null; 51 private static RockboxService instance = null;
55 52
56 /* locals needed for the c code and rockbox state */ 53 /* locals needed for the c code and Rockbox state */
57 private static volatile boolean rockbox_running; 54 private static volatile boolean rockbox_running;
58 private Activity current_activity = null; 55 private Activity mCurrentActivity = null;
59 private RunForegroundManager fg_runner; 56 private RunForegroundManager mFgRunner;
60 private MediaButtonReceiver mMediaButtonReceiver; 57 private MediaButtonReceiver mMediaButtonReceiver;
61 private ResultReceiver resultReceiver; 58 private ResultReceiver mResultReceiver;
62 59
60 /* possible result values for intent handling */
63 public static final int RESULT_INVOKING_MAIN = 0; 61 public static final int RESULT_INVOKING_MAIN = 0;
64 public static final int RESULT_LIB_LOAD_PROGRESS = 1; 62 public static final int RESULT_LIB_LOAD_PROGRESS = 1;
65 public static final int RESULT_SERVICE_RUNNING = 3; 63 public static final int RESULT_SERVICE_RUNNING = 3;
@@ -72,12 +70,12 @@ public class RockboxService extends Service
72 { 70 {
73 instance = this; 71 instance = this;
74 mMediaButtonReceiver = new MediaButtonReceiver(this); 72 mMediaButtonReceiver = new MediaButtonReceiver(this);
75 fg_runner = new RunForegroundManager(this); 73 mFgRunner = new RunForegroundManager(this);
76 } 74 }
77 75
78 public static RockboxService get_instance() 76 public static RockboxService getInstance()
79 { 77 {
80 /* don't call the construtor here, the instances are managed by 78 /* don't call the constructor here, the instances are managed by
81 * android, so we can't just create a new one */ 79 * android, so we can't just create a new one */
82 return instance; 80 return instance;
83 } 81 }
@@ -86,33 +84,44 @@ public class RockboxService extends Service
86 { 84 {
87 return rockbox_running; 85 return rockbox_running;
88 } 86 }
89 public Activity get_activity() 87 public Activity getActivity()
90 { 88 {
91 return current_activity; 89 return mCurrentActivity;
92 } 90 }
93 public void set_activity(Activity a) 91
92 public void setActivity(Activity a)
93 {
94 mCurrentActivity = a;
95 }
96
97 private void putResult(int resultCode)
94 { 98 {
95 current_activity = a; 99 putResult(resultCode, null);
96 } 100 }
97 101
98 private void do_start(Intent intent) 102 private void putResult(int resultCode, Bundle resultData)
99 { 103 {
100 LOG("Start RockboxService (Intent: " + intent.getAction() + ")"); 104 if (mResultReceiver != null)
105 mResultReceiver.send(resultCode, resultData);
106 }
107
108 private void doStart(Intent intent)
109 {
110 Logger.d("Start RockboxService (Intent: " + intent.getAction() + ")");
101 111
102 if (intent.getAction().equals("org.rockbox.ResendTrackUpdateInfo")) 112 if (intent.getAction().equals("org.rockbox.ResendTrackUpdateInfo"))
103 { 113 {
104 if (rockbox_running) 114 if (rockbox_running)
105 fg_runner.resendUpdateNotification(); 115 mFgRunner.resendUpdateNotification();
106 return; 116 return;
107 } 117 }
108 118
109 if (intent.hasExtra("callback")) 119 if (intent.hasExtra("callback"))
110 resultReceiver = (ResultReceiver) intent.getParcelableExtra("callback"); 120 mResultReceiver = (ResultReceiver) intent.getParcelableExtra("callback");
111 121
112 if (!rockbox_running) 122 if (!rockbox_running)
113 startservice(); 123 startService();
114 if (resultReceiver != null) 124 putResult(RESULT_LIB_LOADED);
115 resultReceiver.send(RESULT_LIB_LOADED, null);
116 125
117 if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) 126 if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON))
118 { 127 {
@@ -123,24 +132,13 @@ public class RockboxService extends Service
123 132
124 /* (Re-)attach the media button receiver, in case it has been lost */ 133 /* (Re-)attach the media button receiver, in case it has been lost */
125 mMediaButtonReceiver.register(); 134 mMediaButtonReceiver.register();
126 if (resultReceiver != null) 135 putResult(RESULT_SERVICE_RUNNING);
127 resultReceiver.send(RESULT_SERVICE_RUNNING, null);
128 136
129 rockbox_running = true; 137 rockbox_running = true;
130 } 138 }
131 139
132 private void LOG(CharSequence text)
133 {
134 Log.d("Rockbox", (String) text);
135 }
136
137 private void LOG(CharSequence text, Throwable tr)
138 {
139 Log.d("Rockbox", (String) text, tr);
140 }
141
142 public void onStart(Intent intent, int startId) { 140 public void onStart(Intent intent, int startId) {
143 do_start(intent); 141 doStart(intent);
144 } 142 }
145 143
146 public int onStartCommand(Intent intent, int flags, int startId) 144 public int onStartCommand(Intent intent, int flags, int startId)
@@ -149,11 +147,11 @@ public class RockboxService extends Service
149 * after getting killed for memory pressure earlier */ 147 * after getting killed for memory pressure earlier */
150 if (intent == null) 148 if (intent == null)
151 intent = new Intent("org.rockbox.ServiceRestarted"); 149 intent = new Intent("org.rockbox.ServiceRestarted");
152 do_start(intent); 150 doStart(intent);
153 return START_STICKY; 151 return START_STICKY;
154 } 152 }
155 153
156 private void startservice() 154 private void startService()
157 { 155 {
158 final Object lock = new Object(); 156 final Object lock = new Object();
159 Thread rb = new Thread(new Runnable() 157 Thread rb = new Thread(new Runnable()
@@ -164,9 +162,6 @@ public class RockboxService extends Service
164 String rockboxDirPath = "/data/data/org.rockbox/app_rockbox/rockbox"; 162 String rockboxDirPath = "/data/data/org.rockbox/app_rockbox/rockbox";
165 String rockboxCreditsPath = "/data/data/org.rockbox/app_rockbox/rockbox/rocks/viewers"; 163 String rockboxCreditsPath = "/data/data/org.rockbox/app_rockbox/rockbox/rocks/viewers";
166 String rockboxSdDirPath = "/sdcard/rockbox"; 164 String rockboxSdDirPath = "/sdcard/rockbox";
167 File rockboxDir = new File(rockboxDirPath);
168 File rockboxSdDir = new File(rockboxSdDirPath);
169 File rockboxCreditsDir = new File(rockboxCreditsPath);
170 165
171 /* load library before unzipping which may take a while */ 166 /* load library before unzipping which may take a while */
172 synchronized (lock) { 167 synchronized (lock) {
@@ -186,10 +181,10 @@ public class RockboxService extends Service
186 boolean extractToSd = false; 181 boolean extractToSd = false;
187 if(rockboxInfoFile.exists()) { 182 if(rockboxInfoFile.exists()) {
188 extractToSd = true; 183 extractToSd = true;
189 LOG("extracting resources to SD card"); 184 Logger.d("extracting resources to SD card");
190 } 185 }
191 else { 186 else {
192 LOG("extracting resources to internal memory"); 187 Logger.d("extracting resources to internal memory");
193 } 188 }
194 if (!arbitraryFile.exists() || (libMisc.lastModified() > arbitraryFile.lastModified())) 189 if (!arbitraryFile.exists() || (libMisc.lastModified() > arbitraryFile.lastModified()))
195 { 190 {
@@ -240,20 +235,16 @@ public class RockboxService extends Service
240 is.close(); 235 is.close();
241 } 236 }
242 237
243 if (resultReceiver != null) { 238 progressData.putInt("value", progressData.getInt("value", 0) + 1);
244 progressData.putInt("value", progressData.getInt("value", 0) + 1); 239 putResult(RESULT_LIB_LOAD_PROGRESS, progressData);
245 resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData);
246 }
247 } 240 }
248 arbitraryFile.setLastModified(libMisc.lastModified()); 241 arbitraryFile.setLastModified(libMisc.lastModified());
249 } catch(Exception e) { 242 } catch(Exception e) {
250 LOG("Exception when unzipping", e); 243 Logger.d("Exception when unzipping", e);
244 Bundle bundle = new Bundle();
251 e.printStackTrace(); 245 e.printStackTrace();
252 if (resultReceiver != null) { 246 bundle.putString("error", getString(R.string.error_extraction));
253 Bundle bundle = new Bundle(); 247 putResult(RESULT_ERROR_OCCURED, bundle);
254 bundle.putString("error", getString(R.string.error_extraction));
255 resultReceiver.send(RESULT_ERROR_OCCURED, bundle);
256 }
257 } 248 }
258 } 249 }
259 250
@@ -272,21 +263,19 @@ public class RockboxService extends Service
272 strm.write("lang: /.rockbox/langs/" + getString(R.string.rockbox_language_file) + "\n"); 263 strm.write("lang: /.rockbox/langs/" + getString(R.string.rockbox_language_file) + "\n");
273 strm.close(); 264 strm.close();
274 } catch(Exception e) { 265 } catch(Exception e) {
275 LOG("Exception when writing default config", e); 266 Logger.d("Exception when writing default config", e);
276 } 267 }
277 } 268 }
278 269
279 /* Start native code */ 270 /* Start native code */
280 if (resultReceiver != null) 271 putResult(RESULT_INVOKING_MAIN);
281 resultReceiver.send(RESULT_INVOKING_MAIN, null);
282 272
283 main(); 273 main();
284 274
285 if (resultReceiver != null) 275 putResult(RESULT_ROCKBOX_EXIT);
286 resultReceiver.send(RESULT_ROCKBOX_EXIT, null);
287 276
288 LOG("Stop service: main() returned"); 277 Logger.d("Stop service: main() returned");
289 stopSelf(); /* serivce is of no use anymore */ 278 stopSelf(); /* service is of no use anymore */
290 } 279 }
291 }, "Rockbox thread"); 280 }, "Rockbox thread");
292 rb.setDaemon(false); 281 rb.setDaemon(false);
@@ -311,18 +300,17 @@ public class RockboxService extends Service
311 @Override 300 @Override
312 public IBinder onBind(Intent intent) 301 public IBinder onBind(Intent intent)
313 { 302 {
314 // TODO Auto-generated method stub
315 return null; 303 return null;
316 } 304 }
317 305
318 void startForeground() 306 void startForeground()
319 { 307 {
320 fg_runner.startForeground(); 308 mFgRunner.startForeground();
321 } 309 }
322 310
323 void stopForeground() 311 void stopForeground()
324 { 312 {
325 fg_runner.stopForeground(); 313 mFgRunner.stopForeground();
326 } 314 }
327 315
328 @Override 316 @Override
@@ -330,7 +318,7 @@ public class RockboxService extends Service
330 { 318 {
331 super.onDestroy(); 319 super.onDestroy();
332 /* Don't unregister so we can receive them (and startup the service) 320 /* Don't unregister so we can receive them (and startup the service)
333 * after idle poweroff. Hopefully it's ok if mMediaButtonReceiver is 321 * after idle power-off. Hopefully it's OK if mMediaButtonReceiver is
334 * garbage collected. 322 * garbage collected.
335 * mMediaButtonReceiver.unregister(); */ 323 * mMediaButtonReceiver.unregister(); */
336 mMediaButtonReceiver = null; 324 mMediaButtonReceiver = null;
diff --git a/android/src/org/rockbox/RockboxYesno.java b/android/src/org/rockbox/RockboxYesno.java
index f770f1c7e2..de8f88ab5f 100644
--- a/android/src/org/rockbox/RockboxYesno.java
+++ b/android/src/org/rockbox/RockboxYesno.java
@@ -29,7 +29,7 @@ public class RockboxYesno
29{ 29{
30 private void yesno_display(final String text, final String yes, final String no) 30 private void yesno_display(final String text, final String yes, final String no)
31 { 31 {
32 final Activity c = RockboxService.get_instance().get_activity(); 32 final Activity c = RockboxService.getInstance().getActivity();
33 33
34 c.runOnUiThread(new Runnable() { 34 c.runOnUiThread(new Runnable() {
35 public void run() 35 public void run()
@@ -60,7 +60,7 @@ public class RockboxYesno
60 60
61 private boolean is_usable() 61 private boolean is_usable()
62 { 62 {
63 return RockboxService.get_instance().get_activity() != null; 63 return RockboxService.getInstance().getActivity() != null;
64 } 64 }
65 65
66 private native void put_result(boolean result); 66 private native void put_result(boolean result);