Index: android/src/org/rockbox/RockboxActivity.java =================================================================== --- android/src/org/rockbox/RockboxActivity.java (revision 27760) +++ android/src/org/rockbox/RockboxActivity.java (working copy) @@ -30,14 +30,10 @@ import android.view.WindowManager; public class RockboxActivity extends Activity { - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN - ,WindowManager.LayoutParams.FLAG_FULLSCREEN); + RockboxUpdater updater = null; + + public void startService() + { final Intent intent = new Intent(this, RockboxService.class); startService(intent); @@ -70,12 +66,26 @@ }); } }).start(); + } + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + if (RockboxService.fb == null) + { + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN + ,WindowManager.LayoutParams.FLAG_FULLSCREEN); + updater = new RockboxUpdater(this); + + updater.CheckForUpdate(); + } } public void onResume() { super.onResume(); - if (RockboxService.fb != null) { try { @@ -97,22 +107,31 @@ @Override protected void onPause() { super.onPause(); - RockboxService.fb.suspend(); + if (RockboxService.fb != null) + { + RockboxService.fb.suspend(); + } } @Override protected void onStop() { super.onStop(); - RockboxService.fb.suspend(); + if (RockboxService.fb != null) + { + RockboxService.fb.suspend(); + } } @Override protected void onDestroy() { super.onDestroy(); - RockboxService.fb.suspend(); + if (RockboxService.fb != null) + { + RockboxService.fb.suspend(); + } } - private void LOG(CharSequence text) + void LOG(CharSequence text) { Log.d("Rockbox", (String) text); } Index: android/src/org/rockbox/RockboxService.java =================================================================== --- android/src/org/rockbox/RockboxService.java (revision 27760) +++ android/src/org/rockbox/RockboxService.java (working copy) @@ -1,17 +1,7 @@ package org.rockbox; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -49,6 +39,7 @@ /* Running on an older platform: fall back to old API */ mStartForeground = mStopForeground = null; } + startservice(); instance = this; } @@ -83,66 +74,14 @@ private void startservice() { fb = new RockboxFramebuffer(this); - final int BUFFER = 2048; - /* the following block unzips libmisc.so, which contains the files - * we ship, such as themes. It's needed to put it into a .so file - * because there's no other way to ship files and have access - * to them from native code - */ - try - { - BufferedOutputStream dest = null; - BufferedInputStream is = null; - ZipEntry entry; - File file = new File("/data/data/org.rockbox/lib/libmisc.so"); - /* use arbitary file to determine whether extracting is needed */ - File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec"); - if (!file2.exists() || (file.lastModified() > file2.lastModified())) - { - ZipFile zipfile = new ZipFile(file); - Enumeration e = zipfile.entries(); - File folder; - while(e.hasMoreElements()) { - entry = (ZipEntry) e.nextElement(); - LOG("Extracting: " +entry); - if (entry.isDirectory()) - { - folder = new File(entry.getName()); - LOG("mkdir "+ entry); - try { - folder.mkdirs(); - } catch (SecurityException ex){ - LOG(ex.getMessage()); - } - continue; - } - is = new BufferedInputStream(zipfile.getInputStream(entry)); - int count; - byte data[] = new byte[BUFFER]; - folder = new File(new File(entry.getName()).getParent()); - LOG("" + folder.getAbsolutePath()); - if (!folder.exists()) - folder.mkdirs(); - FileOutputStream fos = new FileOutputStream(entry.getName()); - dest = new BufferedOutputStream(fos, BUFFER); - while ((count = is.read(data, 0, BUFFER)) != -1) { - dest.write(data, 0, count); - } - dest.flush(); - dest.close(); - is.close(); - } - } - } catch(FileNotFoundException e) { - LOG("FileNotFoundException when unzipping", e); - e.printStackTrace(); - } catch(IOException e) { - LOG("IOException when unzipping", e); - e.printStackTrace(); + try { + System.load("/data/data/org.rockbox/rockbox/librockbox.so"); } - - System.loadLibrary("rockbox"); - + catch (UnsatisfiedLinkError e) { + fb = null; + return; + } + Thread rb = new Thread(new Runnable() { public void run() @@ -153,7 +92,7 @@ rb.setDaemon(false); rb.start(); } - + private native void main(); @Override public IBinder onBind(Intent intent) { Index: android/src/org/rockbox/RockboxUpdater.java =================================================================== --- android/src/org/rockbox/RockboxUpdater.java (revision 0) +++ android/src/org/rockbox/RockboxUpdater.java (revision 0) @@ -0,0 +1,110 @@ +package org.rockbox; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import android.app.AlertDialog; +import android.content.DialogInterface; + +public class RockboxUpdater { + private final String zipfile = "/sdcard/rockbox/rockbox.zip"; + public String librockbox = null; + private RockboxActivity myActivity = null; + public RockboxUpdater(RockboxActivity activity) { + myActivity = activity; + librockbox = activity.getFilesDir().toString() + "/librockbox.so"; + } + + public void CheckForUpdate() { + File file = new File(zipfile); + File file2 = new File(librockbox); + String message = null; + if (!file.exists() && !file2.exists()) { + message = "Do you want to download the ROCKbox application data?"; + } + else if (file.exists() && (file.lastModified() > file2.lastModified())) { + message = "ROCKbox update found, install it?"; + } + if (message != null) { + AlertDialog alert = new AlertDialog.Builder(myActivity).create(); + alert.setTitle("ROCKbox Installer"); + alert.setMessage(message); + alert.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + if (!new File(zipfile).exists()){ + /* Do the download here */ + myActivity.finish(); + } + doUpdate(); + myActivity.startService(); + } + }); + alert.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + if (!new File(librockbox).exists()) { + myActivity.finish(); + } else { + myActivity.startService(); + } + } + }); + alert.show(); + } else { + myActivity.startService(); + } + } + + private void doUpdate() { + final int BUFFER = 1024*8; + BufferedOutputStream dest = null; + BufferedInputStream is = null; + ZipEntry entry; + myActivity.LOG("librockbox: "+ librockbox); + try { + File file = new File(zipfile); + ZipFile zipfile; + zipfile = new ZipFile(file); + Enumeration e = zipfile.entries(); + File folder; + while(e.hasMoreElements()) { + entry = (ZipEntry) e.nextElement(); + myActivity.LOG("Extracting: " +entry); + if (entry.isDirectory()) + { + folder = new File(entry.getName()); + myActivity.LOG("mkdir "+ entry); + try { + folder.mkdirs(); + } catch (SecurityException ex){ + myActivity.LOG(ex.getMessage()); + } + continue; + } + is = new BufferedInputStream(zipfile.getInputStream(entry), BUFFER); + int count; + byte data[] = new byte[BUFFER]; + folder = new File(new File(entry.getName()).getParent()); + myActivity.LOG("" + folder.getAbsolutePath()); + if (!folder.exists()) + folder.mkdirs(); + FileOutputStream fos = new FileOutputStream(entry.getName()); + dest = new BufferedOutputStream(fos, BUFFER); + while ((count = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, count); + } + dest.flush(); + dest.close(); + is.close(); + } + } + catch (Exception e) + { + } + } + +} Index: tools/configure =================================================================== --- tools/configure (revision 27760) +++ tools/configure (working copy) @@ -95,10 +95,10 @@ if [ -n "$PREFIX" ]; then echo "WARNING: PREFIX not supported on Android. You can however use --rbdir" fi - rbdir="/data/data/org.rockbox/app_rockbox/rockbox" - bindir="/data/data/org.rockbox/lib" + rbdir="/data/data/org.rockbox/rockbox" + bindir="/data/data/org.rockbox/" bindir_full=$bindir - libdir="/data/data/org.rockbox/app_rockbox" + libdir="/data/data/org.rockbox/" libdir_full=$libdir output="librockbox.so" bootoutput="librockbox.so" Index: tools/buildzip.pl =================================================================== --- tools/buildzip.pl (revision 27760) +++ tools/buildzip.pl (working copy) @@ -620,9 +620,17 @@ # Don't include image file in fonts-only package undef $target; } + + unless (".rockbox" eq $rbdir) { + mkpath($rbdir); + rmtree($rbdir); + move(".rockbox", $rbdir); + print "mv .rockbox $rbdir\n" if $verbose; + } if($target && ($target !~ /(mod|ajz|wma)\z/i)) { # On some targets, the image goes into .rockbox. copy("$target", "$rbdir/$target"); + print "copy $target $rbdir/$target\n" if $verbose; undef $target; } @@ -630,16 +638,10 @@ make_install(".rockbox", $install) or die "MKDIRFAILED\n"; } else { - unless (".rockbox" eq $rbdir) { - mkpath($rbdir); - rmtree($rbdir); - move(".rockbox", $rbdir); - print "mv .rockbox $rbdir\n" if $verbose; - } system("$ziptool $output $rbdir $target >/dev/null"); print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose; } - rmtree(".rockbox"); + #rmtree(".rockbox"); print "rm .rockbox\n" if $verbose; }; Index: uisimulator/common/io.c =================================================================== --- uisimulator/common/io.c (revision 27760) +++ uisimulator/common/io.c (working copy) @@ -554,7 +554,7 @@ * from (no exec permissions) */ snprintf(path, sizeof(path), - "/data/data/org.rockbox/app_rockbox/libtemp_codec_%d.so", + "/data/data/org.rockbox/rockbox/libtemp_codec_%d.so", codec_count); #else char name[MAX_PATH];