diff options
Diffstat (limited to 'android/src/org')
-rw-r--r-- | android/src/org/rockbox/RockboxActivity.java | 43 | ||||
-rw-r--r-- | android/src/org/rockbox/RockboxService.java | 125 |
2 files changed, 81 insertions, 87 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java index 15576f4adb..ec22885c51 100644 --- a/android/src/org/rockbox/RockboxActivity.java +++ b/android/src/org/rockbox/RockboxActivity.java | |||
@@ -26,12 +26,14 @@ import android.app.Activity; | |||
26 | import android.app.ProgressDialog; | 26 | import android.app.ProgressDialog; |
27 | import android.content.Intent; | 27 | import android.content.Intent; |
28 | import android.os.Bundle; | 28 | import android.os.Bundle; |
29 | import android.os.Handler; | ||
29 | import android.os.ResultReceiver; | 30 | import android.os.ResultReceiver; |
30 | import android.util.Log; | 31 | import android.util.Log; |
31 | import android.view.View; | 32 | import android.view.View; |
32 | import android.view.ViewGroup; | 33 | import android.view.ViewGroup; |
33 | import android.view.Window; | 34 | import android.view.Window; |
34 | import android.view.WindowManager; | 35 | import android.view.WindowManager; |
36 | import android.widget.Toast; | ||
35 | 37 | ||
36 | public class RockboxActivity extends Activity | 38 | public class RockboxActivity extends Activity |
37 | { | 39 | { |
@@ -58,31 +60,28 @@ public class RockboxActivity extends Activity | |||
58 | loadingdialog.show(); | 60 | loadingdialog.show(); |
59 | 61 | ||
60 | Intent intent = new Intent(this, RockboxService.class); | 62 | Intent intent = new Intent(this, RockboxService.class); |
61 | intent.putExtra("callback", new ResultReceiver(null) { | 63 | intent.putExtra("callback", new ResultReceiver(new Handler(getMainLooper())) { |
62 | @Override | 64 | @Override |
63 | protected void onReceiveResult(final int resultCode, final Bundle resultData) | 65 | protected void onReceiveResult(final int resultCode, final Bundle resultData) |
64 | { | 66 | { |
65 | runOnUiThread(new Runnable() | 67 | switch (resultCode) { |
66 | { | 68 | case RockboxService.RESULT_LIB_LOADED: |
67 | public void run() { | 69 | rbservice = RockboxService.get_instance(); |
68 | switch (resultCode) { | 70 | loadingdialog.setIndeterminate(true); |
69 | case RockboxService.RESULT_LIB_LOADED: | 71 | break; |
70 | rbservice = RockboxService.get_instance(); | 72 | case RockboxService.RESULT_LIB_LOAD_PROGRESS: |
71 | loadingdialog.setIndeterminate(true); | 73 | loadingdialog.setIndeterminate(false); |
72 | break; | 74 | loadingdialog.setMax(resultData.getInt("max", 100)); |
73 | case RockboxService.RESULT_LIB_LOAD_PROGRESS: | 75 | loadingdialog.setProgress(resultData.getInt("value", 0)); |
74 | loadingdialog.setIndeterminate(false); | 76 | break; |
75 | loadingdialog.setMax(resultData.getInt("max", 100)); | 77 | case RockboxService.RESULT_FB_INITIALIZED: |
76 | loadingdialog.setProgress(resultData.getInt("value", 0)); | 78 | attachFramebuffer(); |
77 | break; | 79 | loadingdialog.dismiss(); |
78 | case RockboxService.RESULT_FB_INITIALIZED: | 80 | break; |
79 | attachFramebuffer(); | 81 | case RockboxService.RESULT_ERROR_OCCURED: |
80 | loadingdialog.dismiss(); | 82 | Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG); |
81 | break; | 83 | break; |
82 | } | 84 | } |
83 | |||
84 | } | ||
85 | }); | ||
86 | } | 85 | } |
87 | }); | 86 | }); |
88 | startService(intent); | 87 | startService(intent); |
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index 4d61dea7ff..e788251508 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java | |||
@@ -24,9 +24,7 @@ package org.rockbox; | |||
24 | import java.io.BufferedInputStream; | 24 | import java.io.BufferedInputStream; |
25 | import java.io.BufferedOutputStream; | 25 | import java.io.BufferedOutputStream; |
26 | import java.io.File; | 26 | import java.io.File; |
27 | import java.io.FileNotFoundException; | ||
28 | import java.io.FileOutputStream; | 27 | import java.io.FileOutputStream; |
29 | import java.io.IOException; | ||
30 | import java.util.Enumeration; | 28 | import java.util.Enumeration; |
31 | import java.util.Timer; | 29 | import java.util.Timer; |
32 | import java.util.TimerTask; | 30 | import java.util.TimerTask; |
@@ -73,6 +71,7 @@ public class RockboxService extends Service | |||
73 | public static final int RESULT_LIB_LOADED = 0; | 71 | public static final int RESULT_LIB_LOADED = 0; |
74 | public static final int RESULT_LIB_LOAD_PROGRESS = 1; | 72 | public static final int RESULT_LIB_LOAD_PROGRESS = 1; |
75 | public static final int RESULT_FB_INITIALIZED = 2; | 73 | public static final int RESULT_FB_INITIALIZED = 2; |
74 | public static final int RESULT_ERROR_OCCURED = 3; | ||
76 | 75 | ||
77 | @Override | 76 | @Override |
78 | public void onCreate() | 77 | public void onCreate() |
@@ -152,81 +151,77 @@ public class RockboxService extends Service | |||
152 | { | 151 | { |
153 | public void run() | 152 | public void run() |
154 | { | 153 | { |
155 | LOG("main"); | 154 | File rockboxDir = new File("/data/data/org.rockbox/app_rockbox/rockbox/"); |
156 | Bundle progressData = new Bundle(); | 155 | |
157 | /* the following block unzips libmisc.so, which contains the files | 156 | /* the following block unzips libmisc.so, which contains the files |
158 | * we ship, such as themes. It's needed to put it into a .so file | 157 | * we ship, such as themes. It's needed to put it into a .so file |
159 | * because there's no other way to ship files and have access | 158 | * because there's no other way to ship files and have access |
160 | * to them from native code | 159 | * to them from native code |
161 | */ | 160 | */ |
162 | try | 161 | File libMisc = new File("/data/data/org.rockbox/lib/libmisc.so"); |
163 | { | 162 | /* use arbitrary file to determine whether extracting is needed */ |
164 | BufferedOutputStream dest = null; | 163 | File arbitraryFile = new File(rockboxDir, "viewers.config"); |
165 | BufferedInputStream is = null; | 164 | if (!arbitraryFile.exists() || (libMisc.lastModified() > arbitraryFile.lastModified())) |
166 | ZipEntry entry; | 165 | { |
167 | File file = new File("/data/data/org.rockbox/" + | 166 | try |
168 | "lib/libmisc.so"); | 167 | { |
169 | /* use arbitrary file to determine whether extracting is needed */ | 168 | Bundle progressData = new Bundle(); |
170 | File file2 = new File("/data/data/org.rockbox/" + | 169 | byte data[] = new byte[BUFFER]; |
171 | "app_rockbox/rockbox/codecs/mpa.codec"); | 170 | ZipFile zipfile = new ZipFile(libMisc); |
172 | if (!file2.exists() || (file.lastModified() > file2.lastModified())) | 171 | Enumeration<? extends ZipEntry> e = zipfile.entries(); |
173 | { | 172 | progressData.putInt("max", zipfile.size()); |
174 | ZipFile zipfile = new ZipFile(file); | 173 | |
175 | Enumeration<? extends ZipEntry> e = zipfile.entries(); | 174 | while(e.hasMoreElements()) |
176 | File folder; | 175 | { |
177 | progressData.putInt("max", zipfile.size()); | 176 | ZipEntry entry = (ZipEntry) e.nextElement(); |
178 | while(e.hasMoreElements()) | 177 | File file = new File(entry.getName()); |
179 | { | 178 | |
180 | entry = (ZipEntry) e.nextElement(); | 179 | if (!entry.isDirectory()) |
181 | LOG("Extracting: " +entry); | 180 | { |
182 | if (entry.isDirectory()) | 181 | /* Create the parent folders if necessary */ |
183 | { | 182 | File folder = new File(file.getParent()); |
184 | folder = new File(entry.getName()); | 183 | if (!folder.exists()) |
185 | LOG("mkdir "+ entry); | 184 | folder.mkdirs(); |
186 | try { | 185 | |
187 | folder.mkdirs(); | 186 | /* Extract file */ |
188 | } catch (SecurityException ex) { | 187 | BufferedInputStream is = new BufferedInputStream(zipfile.getInputStream(entry), BUFFER); |
189 | LOG(ex.getMessage()); | 188 | FileOutputStream fos = new FileOutputStream(file); |
190 | } | 189 | BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); |
191 | continue; | 190 | |
192 | } | 191 | int count; |
193 | is = new BufferedInputStream(zipfile.getInputStream(entry), | 192 | while ((count = is.read(data, 0, BUFFER)) != -1) |
194 | BUFFER); | 193 | dest.write(data, 0, count); |
195 | int count; | 194 | |
196 | byte data[] = new byte[BUFFER]; | 195 | dest.flush(); |
197 | folder = new File(new File(entry.getName()).getParent()); | 196 | dest.close(); |
198 | LOG("" + folder.getAbsolutePath()); | 197 | is.close(); |
199 | if (!folder.exists()) | 198 | } |
200 | folder.mkdirs(); | 199 | |
201 | FileOutputStream fos = new FileOutputStream(entry.getName()); | 200 | if (resultReceiver != null) { |
202 | dest = new BufferedOutputStream(fos, BUFFER); | 201 | progressData.putInt("value", progressData.getInt("value", 0) + 1); |
203 | while ((count = is.read(data, 0, BUFFER)) != -1) | 202 | resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData); |
204 | dest.write(data, 0, count); | 203 | } |
205 | dest.flush(); | 204 | } |
206 | dest.close(); | 205 | } catch(Exception e) { |
207 | is.close(); | 206 | LOG("Exception when unzipping", e); |
208 | if (resultReceiver != null) { | 207 | e.printStackTrace(); |
209 | progressData.putInt("value", progressData.getInt("value", 0) + 1); | 208 | if (resultReceiver != null) { |
210 | resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData); | 209 | Bundle bundle = new Bundle(); |
211 | } | 210 | bundle.putString("error", "Error occured during extraction!"); |
212 | } | 211 | resultReceiver.send(RESULT_ERROR_OCCURED, bundle); |
213 | } | 212 | } |
214 | } catch(FileNotFoundException e) { | 213 | } |
215 | LOG("FileNotFoundException when unzipping", e); | 214 | } |
216 | e.printStackTrace(); | 215 | |
217 | } catch(IOException e) { | ||
218 | LOG("IOException when unzipping", e); | ||
219 | e.printStackTrace(); | ||
220 | } | ||
221 | |||
222 | System.loadLibrary("rockbox"); | 216 | System.loadLibrary("rockbox"); |
223 | rbLibLoaded = true; | 217 | rbLibLoaded = true; |
224 | if (resultReceiver != null) | 218 | if (resultReceiver != null) |
225 | resultReceiver.send(RESULT_LIB_LOADED, null); | 219 | resultReceiver.send(RESULT_LIB_LOADED, null); |
220 | |||
226 | main(); | 221 | main(); |
227 | throw new IllegalStateException("native main() returned!"); | 222 | throw new IllegalStateException("native main() returned!"); |
228 | } | 223 | } |
229 | },"Rockbox thread"); | 224 | }, "Rockbox thread"); |
230 | rb.setDaemon(false); | 225 | rb.setDaemon(false); |
231 | rb.start(); | 226 | rb.start(); |
232 | } | 227 | } |