forked from len0rd/rockbox
Android: clean up extracting a bit + add user-visible error-reporting
Also put ResultReceiver on the RockboxActivity UI thread. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28509 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4f747c1aaa
commit
fe2be33318
2 changed files with 81 additions and 87 deletions
|
@ -26,12 +26,14 @@ import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class RockboxActivity extends Activity
|
public class RockboxActivity extends Activity
|
||||||
{
|
{
|
||||||
|
@ -58,31 +60,28 @@ public class RockboxActivity extends Activity
|
||||||
loadingdialog.show();
|
loadingdialog.show();
|
||||||
|
|
||||||
Intent intent = new Intent(this, RockboxService.class);
|
Intent intent = new Intent(this, RockboxService.class);
|
||||||
intent.putExtra("callback", new ResultReceiver(null) {
|
intent.putExtra("callback", new ResultReceiver(new Handler(getMainLooper())) {
|
||||||
@Override
|
@Override
|
||||||
protected void onReceiveResult(final int resultCode, final Bundle resultData)
|
protected void onReceiveResult(final int resultCode, final Bundle resultData)
|
||||||
{
|
{
|
||||||
runOnUiThread(new Runnable()
|
switch (resultCode) {
|
||||||
{
|
case RockboxService.RESULT_LIB_LOADED:
|
||||||
public void run() {
|
rbservice = RockboxService.get_instance();
|
||||||
switch (resultCode) {
|
loadingdialog.setIndeterminate(true);
|
||||||
case RockboxService.RESULT_LIB_LOADED:
|
break;
|
||||||
rbservice = RockboxService.get_instance();
|
case RockboxService.RESULT_LIB_LOAD_PROGRESS:
|
||||||
loadingdialog.setIndeterminate(true);
|
loadingdialog.setIndeterminate(false);
|
||||||
break;
|
loadingdialog.setMax(resultData.getInt("max", 100));
|
||||||
case RockboxService.RESULT_LIB_LOAD_PROGRESS:
|
loadingdialog.setProgress(resultData.getInt("value", 0));
|
||||||
loadingdialog.setIndeterminate(false);
|
break;
|
||||||
loadingdialog.setMax(resultData.getInt("max", 100));
|
case RockboxService.RESULT_FB_INITIALIZED:
|
||||||
loadingdialog.setProgress(resultData.getInt("value", 0));
|
attachFramebuffer();
|
||||||
break;
|
loadingdialog.dismiss();
|
||||||
case RockboxService.RESULT_FB_INITIALIZED:
|
break;
|
||||||
attachFramebuffer();
|
case RockboxService.RESULT_ERROR_OCCURED:
|
||||||
loadingdialog.dismiss();
|
Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
|
|
@ -24,9 +24,7 @@ package org.rockbox;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
@ -73,6 +71,7 @@ public class RockboxService extends Service
|
||||||
public static final int RESULT_LIB_LOADED = 0;
|
public static final int RESULT_LIB_LOADED = 0;
|
||||||
public static final int RESULT_LIB_LOAD_PROGRESS = 1;
|
public static final int RESULT_LIB_LOAD_PROGRESS = 1;
|
||||||
public static final int RESULT_FB_INITIALIZED = 2;
|
public static final int RESULT_FB_INITIALIZED = 2;
|
||||||
|
public static final int RESULT_ERROR_OCCURED = 3;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
|
@ -152,81 +151,77 @@ public class RockboxService extends Service
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
LOG("main");
|
File rockboxDir = new File("/data/data/org.rockbox/app_rockbox/rockbox/");
|
||||||
Bundle progressData = new Bundle();
|
|
||||||
/* the following block unzips libmisc.so, which contains the files
|
/* 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
|
* 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
|
* because there's no other way to ship files and have access
|
||||||
* to them from native code
|
* to them from native code
|
||||||
*/
|
*/
|
||||||
try
|
File libMisc = new File("/data/data/org.rockbox/lib/libmisc.so");
|
||||||
{
|
/* use arbitrary file to determine whether extracting is needed */
|
||||||
BufferedOutputStream dest = null;
|
File arbitraryFile = new File(rockboxDir, "viewers.config");
|
||||||
BufferedInputStream is = null;
|
if (!arbitraryFile.exists() || (libMisc.lastModified() > arbitraryFile.lastModified()))
|
||||||
ZipEntry entry;
|
{
|
||||||
File file = new File("/data/data/org.rockbox/" +
|
try
|
||||||
"lib/libmisc.so");
|
{
|
||||||
/* use arbitrary file to determine whether extracting is needed */
|
Bundle progressData = new Bundle();
|
||||||
File file2 = new File("/data/data/org.rockbox/" +
|
byte data[] = new byte[BUFFER];
|
||||||
"app_rockbox/rockbox/codecs/mpa.codec");
|
ZipFile zipfile = new ZipFile(libMisc);
|
||||||
if (!file2.exists() || (file.lastModified() > file2.lastModified()))
|
Enumeration<? extends ZipEntry> e = zipfile.entries();
|
||||||
{
|
progressData.putInt("max", zipfile.size());
|
||||||
ZipFile zipfile = new ZipFile(file);
|
|
||||||
Enumeration<? extends ZipEntry> e = zipfile.entries();
|
while(e.hasMoreElements())
|
||||||
File folder;
|
{
|
||||||
progressData.putInt("max", zipfile.size());
|
ZipEntry entry = (ZipEntry) e.nextElement();
|
||||||
while(e.hasMoreElements())
|
File file = new File(entry.getName());
|
||||||
{
|
|
||||||
entry = (ZipEntry) e.nextElement();
|
if (!entry.isDirectory())
|
||||||
LOG("Extracting: " +entry);
|
{
|
||||||
if (entry.isDirectory())
|
/* Create the parent folders if necessary */
|
||||||
{
|
File folder = new File(file.getParent());
|
||||||
folder = new File(entry.getName());
|
if (!folder.exists())
|
||||||
LOG("mkdir "+ entry);
|
folder.mkdirs();
|
||||||
try {
|
|
||||||
folder.mkdirs();
|
/* Extract file */
|
||||||
} catch (SecurityException ex) {
|
BufferedInputStream is = new BufferedInputStream(zipfile.getInputStream(entry), BUFFER);
|
||||||
LOG(ex.getMessage());
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
}
|
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
|
||||||
continue;
|
|
||||||
}
|
int count;
|
||||||
is = new BufferedInputStream(zipfile.getInputStream(entry),
|
while ((count = is.read(data, 0, BUFFER)) != -1)
|
||||||
BUFFER);
|
dest.write(data, 0, count);
|
||||||
int count;
|
|
||||||
byte data[] = new byte[BUFFER];
|
dest.flush();
|
||||||
folder = new File(new File(entry.getName()).getParent());
|
dest.close();
|
||||||
LOG("" + folder.getAbsolutePath());
|
is.close();
|
||||||
if (!folder.exists())
|
}
|
||||||
folder.mkdirs();
|
|
||||||
FileOutputStream fos = new FileOutputStream(entry.getName());
|
if (resultReceiver != null) {
|
||||||
dest = new BufferedOutputStream(fos, BUFFER);
|
progressData.putInt("value", progressData.getInt("value", 0) + 1);
|
||||||
while ((count = is.read(data, 0, BUFFER)) != -1)
|
resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData);
|
||||||
dest.write(data, 0, count);
|
}
|
||||||
dest.flush();
|
}
|
||||||
dest.close();
|
} catch(Exception e) {
|
||||||
is.close();
|
LOG("Exception when unzipping", e);
|
||||||
if (resultReceiver != null) {
|
e.printStackTrace();
|
||||||
progressData.putInt("value", progressData.getInt("value", 0) + 1);
|
if (resultReceiver != null) {
|
||||||
resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData);
|
Bundle bundle = new Bundle();
|
||||||
}
|
bundle.putString("error", "Error occured during extraction!");
|
||||||
}
|
resultReceiver.send(RESULT_ERROR_OCCURED, bundle);
|
||||||
}
|
}
|
||||||
} catch(FileNotFoundException e) {
|
}
|
||||||
LOG("FileNotFoundException when unzipping", e);
|
}
|
||||||
e.printStackTrace();
|
|
||||||
} catch(IOException e) {
|
|
||||||
LOG("IOException when unzipping", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.loadLibrary("rockbox");
|
System.loadLibrary("rockbox");
|
||||||
rbLibLoaded = true;
|
rbLibLoaded = true;
|
||||||
if (resultReceiver != null)
|
if (resultReceiver != null)
|
||||||
resultReceiver.send(RESULT_LIB_LOADED, null);
|
resultReceiver.send(RESULT_LIB_LOADED, null);
|
||||||
|
|
||||||
main();
|
main();
|
||||||
throw new IllegalStateException("native main() returned!");
|
throw new IllegalStateException("native main() returned!");
|
||||||
}
|
}
|
||||||
},"Rockbox thread");
|
}, "Rockbox thread");
|
||||||
rb.setDaemon(false);
|
rb.setDaemon(false);
|
||||||
rb.start();
|
rb.start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue