summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/RockboxActivity.java2
-rw-r--r--android/src/org/rockbox/RockboxFramebuffer.java5
-rw-r--r--android/src/org/rockbox/RockboxPCM.java5
-rw-r--r--android/src/org/rockbox/RockboxService.java91
-rw-r--r--android/src/org/rockbox/RockboxTimer.java5
5 files changed, 52 insertions, 56 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index 3be9e3ed47..8d3beb99a0 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -86,8 +86,6 @@ public class RockboxActivity extends Activity {
86 ViewGroup g = (ViewGroup)RockboxService.fb.getParent(); 86 ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
87 g.removeView(RockboxService.fb); 87 g.removeView(RockboxService.fb);
88 setContentView(RockboxService.fb); 88 setContentView(RockboxService.fb);
89 } catch (Exception e) {
90 LOG(e.toString());
91 } 89 }
92 RockboxService.fb.resume(); 90 RockboxService.fb.resume();
93 } 91 }
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index ca11de090c..32fbfef111 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -25,7 +25,6 @@ import java.nio.ByteBuffer;
25import android.content.Context; 25import android.content.Context;
26import android.graphics.Bitmap; 26import android.graphics.Bitmap;
27import android.graphics.Canvas; 27import android.graphics.Canvas;
28import android.os.Handler;
29import android.util.Log; 28import android.util.Log;
30import android.view.MotionEvent; 29import android.view.MotionEvent;
31import android.view.View; 30import android.view.View;
@@ -68,14 +67,14 @@ public class RockboxFramebuffer extends View
68 postInvalidate(x, y, x+w, y+h); 67 postInvalidate(x, y, x+w, y+h);
69 } 68 }
70 69
70 @SuppressWarnings("unused")
71 private void LOG(CharSequence text) 71 private void LOG(CharSequence text)
72 { 72 {
73 Log.d("RockboxBootloader", (String) text); 73 Log.d("Rockbox", (String) text);
74 } 74 }
75 75
76 public boolean onTouchEvent(MotionEvent me) 76 public boolean onTouchEvent(MotionEvent me)
77 { 77 {
78 LOG("onTouchEvent");
79 switch (me.getAction()) 78 switch (me.getAction())
80 { 79 {
81 case MotionEvent.ACTION_CANCEL: 80 case MotionEvent.ACTION_CANCEL:
diff --git a/android/src/org/rockbox/RockboxPCM.java b/android/src/org/rockbox/RockboxPCM.java
index eef56f501d..003ca7c74c 100644
--- a/android/src/org/rockbox/RockboxPCM.java
+++ b/android/src/org/rockbox/RockboxPCM.java
@@ -138,7 +138,7 @@ public class RockboxPCM extends AudioTrack
138 } 138 }
139 @Override 139 @Override
140 public void onMarkerReached(AudioTrack track) { 140 public void onMarkerReached(AudioTrack track) {
141 // push new data to the hardware 141 /* push new data to the hardware */
142 RockboxPCM pcm = (RockboxPCM)track; 142 RockboxPCM pcm = (RockboxPCM)track;
143 int result = -1; 143 int result = -1;
144 pcm.pcmSamplesToByteArray(buf); 144 pcm.pcmSamplesToByteArray(buf);
@@ -169,8 +169,7 @@ public class RockboxPCM extends AudioTrack
169 169
170 @Override 170 @Override
171 public void onPeriodicNotification(AudioTrack track) { 171 public void onPeriodicNotification(AudioTrack track) {
172 // TODO Auto-generated method stub 172 // TODO Auto-generated method stub
173
174 } 173 }
175 } 174 }
176} 175}
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index a73f614782..8ef6b5a302 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -3,7 +3,9 @@ package org.rockbox;
3import java.io.BufferedInputStream; 3import java.io.BufferedInputStream;
4import java.io.BufferedOutputStream; 4import java.io.BufferedOutputStream;
5import java.io.File; 5import java.io.File;
6import java.io.FileNotFoundException;
6import java.io.FileOutputStream; 7import java.io.FileOutputStream;
8import java.io.IOException;
7import java.lang.reflect.InvocationTargetException; 9import java.lang.reflect.InvocationTargetException;
8import java.lang.reflect.Method; 10import java.lang.reflect.Method;
9import java.util.Enumeration; 11import java.util.Enumeration;
@@ -15,7 +17,6 @@ import android.app.NotificationManager;
15import android.app.PendingIntent; 17import android.app.PendingIntent;
16import android.app.Service; 18import android.app.Service;
17import android.content.Intent; 19import android.content.Intent;
18import android.os.Binder;
19import android.os.IBinder; 20import android.os.IBinder;
20import android.util.Log; 21import android.util.Log;
21 22
@@ -25,9 +26,9 @@ public class RockboxService extends Service
25 public static RockboxFramebuffer fb = null; 26 public static RockboxFramebuffer fb = null;
26 private static RockboxService instance; 27 private static RockboxService instance;
27 private Notification notification; 28 private Notification notification;
28 private static final Class[] mStartForegroundSignature = new Class[] { 29 private static final Class<?>[] mStartForegroundSignature = new Class[] {
29 int.class, Notification.class}; 30 int.class, Notification.class};
30 private static final Class[] mStopForegroundSignature = new Class[] { 31 private static final Class<?>[] mStopForegroundSignature = new Class[] {
31 boolean.class}; 32 boolean.class};
32 33
33 private NotificationManager mNM; 34 private NotificationManager mNM;
@@ -45,7 +46,7 @@ public class RockboxService extends Service
45 mStopForeground = getClass().getMethod("stopForeground", 46 mStopForeground = getClass().getMethod("stopForeground",
46 mStopForegroundSignature); 47 mStopForegroundSignature);
47 } catch (NoSuchMethodException e) { 48 } catch (NoSuchMethodException e) {
48 // Running on an older platform. 49 /* Running on an older platform: fall back to old API */
49 mStartForeground = mStopForeground = null; 50 mStartForeground = mStopForeground = null;
50 } 51 }
51 startservice(); 52 startservice();
@@ -63,6 +64,11 @@ public class RockboxService extends Service
63 { 64 {
64 Log.d("Rockbox", (String) text); 65 Log.d("Rockbox", (String) text);
65 } 66 }
67
68 private void LOG(CharSequence text, Throwable tr)
69 {
70 Log.d("Rockbox", (String) text, tr);
71 }
66 72
67 public void onStart(Intent intent, int startId) { 73 public void onStart(Intent intent, int startId) {
68 do_start(intent); 74 do_start(intent);
@@ -71,7 +77,7 @@ public class RockboxService extends Service
71 public int onStartCommand(Intent intent, int flags, int startId) 77 public int onStartCommand(Intent intent, int flags, int startId)
72 { 78 {
73 do_start(intent); 79 do_start(intent);
74 return 1; /* START_STICKY */ 80 return 1; /* old API compatibility: 1 == START_STICKY */
75 } 81 }
76 82
77 private void startservice() 83 private void startservice()
@@ -83,8 +89,8 @@ public class RockboxService extends Service
83 * because there's no other way to ship files and have access 89 * because there's no other way to ship files and have access
84 * to them from native code 90 * to them from native code
85 */ 91 */
86 try 92 try
87 { 93 {
88 BufferedOutputStream dest = null; 94 BufferedOutputStream dest = null;
89 BufferedInputStream is = null; 95 BufferedInputStream is = null;
90 ZipEntry entry; 96 ZipEntry entry;
@@ -127,8 +133,12 @@ public class RockboxService extends Service
127 is.close(); 133 is.close();
128 } 134 }
129 } 135 }
130 } catch(Exception e) { 136 } catch(FileNotFoundException e) {
131 e.printStackTrace(); 137 LOG("FileNotFoundException when unzipping", e);
138 e.printStackTrace();
139 } catch(IOException e) {
140 LOG("IOException when unzipping", e);
141 e.printStackTrace();
132 } 142 }
133 143
134 System.loadLibrary("rockbox"); 144 System.loadLibrary("rockbox");
@@ -149,36 +159,25 @@ public class RockboxService extends Service
149 public IBinder onBind(Intent intent) { 159 public IBinder onBind(Intent intent) {
150 // TODO Auto-generated method stub 160 // TODO Auto-generated method stub
151 return null; 161 return null;
152 } /** 162 }
153 * Class for clients to access. Because we know this service always
154 * runs in the same process as its clients, we don't need to deal with
155 * IPC.
156 */
157 public class LocalBinder extends Binder {
158 RockboxService getService() {
159 return RockboxService.this;
160 }
161 }
162 163
163 /* heavily based on the example found on 164 /* all below is heavily based on the examples found on
164 * http://developer.android.com/reference/android/app/Service.html 165 * http://developer.android.com/reference/android/app/Service.html
165 */ 166 */
166 167
167 private void create_notification() 168 private void create_notification()
168 { 169 {
169 // In this sample, we'll use the same text for the ticker and the expanded notification 170 /* For now we'll use the same text for the ticker and the expanded notification */
170 CharSequence text = getText(R.string.notification); 171 CharSequence text = getText(R.string.notification);
171 172 /* Set the icon, scrolling text and timestamp */
172 // Set the icon, scrolling text and timestamp
173 notification = new Notification(R.drawable.icon, text, 173 notification = new Notification(R.drawable.icon, text,
174 System.currentTimeMillis()); 174 System.currentTimeMillis());
175 175
176 // The PendingIntent to launch our activity if the user selects this notification 176 /* The PendingIntent to launch our activity if the user selects this notification */
177 Intent intent = new Intent(this, RockboxActivity.class); 177 Intent intent = new Intent(this, RockboxActivity.class);
178 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); 178 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
179
180 179
181 // Set the info for the views that show in the notification panel. 180 /* Set the info for the views that show in the notification panel. */
182 notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent); 181 notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent);
183 } 182 }
184 183
@@ -186,10 +185,11 @@ public class RockboxService extends Service
186 { 185 {
187 if (instance != null) 186 if (instance != null)
188 { 187 {
189 // Send the notification. 188 /*
190 // We use a layout id because it is a unique number. We use it later to cancel. 189 * Send the notification.
190 * We use a layout id because it is a unique number. We use it later to cancel.
191 */
191 instance.mNM.notify(R.string.notification, instance.notification); 192 instance.mNM.notify(R.string.notification, instance.notification);
192
193 /* 193 /*
194 * this call makes the service run as foreground, which 194 * this call makes the service run as foreground, which
195 * provides enough cpu time to do music decoding in the 195 * provides enough cpu time to do music decoding in the
@@ -212,24 +212,24 @@ public class RockboxService extends Service
212 * This is a wrapper around the new startForeground method, using the older 212 * This is a wrapper around the new startForeground method, using the older
213 * APIs if it is not available. 213 * APIs if it is not available.
214 */ 214 */
215 void startForegroundCompat(int id, Notification notification) { 215 void startForegroundCompat(int id, Notification notification)
216 // If we have the new startForeground API, then use it. 216 {
217 if (mStartForeground != null) { 217 if (mStartForeground != null) {
218 mStartForegroundArgs[0] = Integer.valueOf(id); 218 mStartForegroundArgs[0] = Integer.valueOf(id);
219 mStartForegroundArgs[1] = notification; 219 mStartForegroundArgs[1] = notification;
220 try { 220 try {
221 mStartForeground.invoke(this, mStartForegroundArgs); 221 mStartForeground.invoke(this, mStartForegroundArgs);
222 } catch (InvocationTargetException e) { 222 } catch (InvocationTargetException e) {
223 // Should not happen. 223 /* Should not happen. */
224 Log.w("ApiDemos", "Unable to invoke startForeground", e); 224 LOG("Unable to invoke startForeground", e);
225 } catch (IllegalAccessException e) { 225 } catch (IllegalAccessException e) {
226 // Should not happen. 226 /* Should not happen. */
227 Log.w("ApiDemos", "Unable to invoke startForeground", e); 227 LOG("Unable to invoke startForeground", e);
228 } 228 }
229 return; 229 return;
230 } 230 }
231 231
232 // Fall back on the old API. 232 /* Fall back on the old API.*/
233 setForeground(true); 233 setForeground(true);
234 mNM.notify(id, notification); 234 mNM.notify(id, notification);
235 } 235 }
@@ -238,31 +238,32 @@ public class RockboxService extends Service
238 * This is a wrapper around the new stopForeground method, using the older 238 * This is a wrapper around the new stopForeground method, using the older
239 * APIs if it is not available. 239 * APIs if it is not available.
240 */ 240 */
241 void stopForegroundCompat(int id) { 241 void stopForegroundCompat(int id)
242 // If we have the new stopForeground API, then use it. 242 {
243 if (mStopForeground != null) { 243 if (mStopForeground != null) {
244 mStopForegroundArgs[0] = Boolean.TRUE; 244 mStopForegroundArgs[0] = Boolean.TRUE;
245 try { 245 try {
246 mStopForeground.invoke(this, mStopForegroundArgs); 246 mStopForeground.invoke(this, mStopForegroundArgs);
247 } catch (InvocationTargetException e) { 247 } catch (InvocationTargetException e) {
248 // Should not happen. 248 /* Should not happen. */
249 Log.w("ApiDemos", "Unable to invoke stopForeground", e); 249 LOG("Unable to invoke stopForeground", e);
250 } catch (IllegalAccessException e) { 250 } catch (IllegalAccessException e) {
251 // Should not happen. 251 /* Should not happen. */
252 Log.w("ApiDemos", "Unable to invoke stopForeground", e); 252 LOG("Unable to invoke stopForeground", e);
253 } 253 }
254 return; 254 return;
255 } 255 }
256 256
257 // Fall back on the old API. Note to cancel BEFORE changing the 257 /* Fall back on the old API. Note to cancel BEFORE changing the
258 // foreground state, since we could be killed at that point. 258 * foreground state, since we could be killed at that point. */
259 mNM.cancel(id); 259 mNM.cancel(id);
260 setForeground(false); 260 setForeground(false);
261 } 261 }
262 262
263 @Override 263 @Override
264 public void onDestroy() { 264 public void onDestroy() {
265 // Make sure our notification is gone. 265 super.onDestroy();
266 /* Make sure our notification is gone. */
266 stopForegroundCompat(R.string.notification); 267 stopForegroundCompat(R.string.notification);
267 } 268 }
268} 269}
diff --git a/android/src/org/rockbox/RockboxTimer.java b/android/src/org/rockbox/RockboxTimer.java
index 68a0e866fb..a38e6c12d6 100644
--- a/android/src/org/rockbox/RockboxTimer.java
+++ b/android/src/org/rockbox/RockboxTimer.java
@@ -75,6 +75,7 @@ public class RockboxTimer extends Timer
75 interval = period_inverval_in_ms; 75 interval = period_inverval_in_ms;
76 } 76 }
77 77
78 @SuppressWarnings("unused")
78 private void LOG(CharSequence text) 79 private void LOG(CharSequence text)
79 { 80 {
80 Log.d("Rockbox", (String) text); 81 Log.d("Rockbox", (String) text);
@@ -88,9 +89,7 @@ public class RockboxTimer extends Timer
88 try { 89 try {
89 this.wait(); 90 this.wait();
90 } catch (InterruptedException e) { 91 } catch (InterruptedException e) {
91 /* wakeup and return */ 92 /* Not an error: wakeup and return */
92 } catch (Exception e) {
93 LOG(e.toString());
94 } 93 }
95 } 94 }
96 } 95 }