Run Rockbox as a service, which allows for music decoding&playback in the background,
the activity only attaches to the framebuffer for displaying it. An icon in the notification area is displayed (it could be prettier I guess). Note: Some HTC phones won't, includng mine, get enough CPU time to do background decoding fluently, see: http://code.google.com/p/android/issues/detail?id=9663 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27686 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
83c60a1012
commit
9dd0158ffb
10 changed files with 74 additions and 136 deletions
|
@ -10,7 +10,8 @@
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<service android:name=".RockboxService"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
<uses-sdk android:minSdkVersion="4" />
|
<uses-sdk android:minSdkVersion="4" />
|
||||||
|
|
|
@ -8,4 +8,4 @@
|
||||||
# project structure.
|
# project structure.
|
||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=android-4
|
target=android-7
|
||||||
|
|
|
@ -12,11 +12,13 @@ public final class R {
|
||||||
}
|
}
|
||||||
public static final class drawable {
|
public static final class drawable {
|
||||||
public static final int icon=0x7f020000;
|
public static final int icon=0x7f020000;
|
||||||
|
public static final int rb=0x7f020001;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int main=0x7f030000;
|
public static final int main=0x7f030000;
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int app_name=0x7f040000;
|
public static final int app_name=0x7f040000;
|
||||||
|
public static final int notification=0x7f040001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">Rockbox</string>
|
<string name="app_name">Rockbox</string>
|
||||||
|
<string name="notification">Rockbox</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -21,128 +21,81 @@
|
||||||
|
|
||||||
package org.rockbox;
|
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.Activity;
|
import android.app.Activity;
|
||||||
import android.graphics.Rect;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
public class RockboxActivity extends Activity {
|
public class RockboxActivity extends Activity {
|
||||||
/** Called when the activity is first created. */
|
|
||||||
public RockboxFramebuffer fb;
|
|
||||||
private Thread rb;
|
|
||||||
static final int BUFFER = 2048;
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
LOG("start rb");
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
,WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
,WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
fb = new RockboxFramebuffer(this);
|
final Intent intent = new Intent(this,
|
||||||
if (true) {
|
RockboxService.class);
|
||||||
try
|
startService(intent);
|
||||||
|
/* Now it gets a bit tricky:
|
||||||
|
* The service is started in the same thread as we are now,
|
||||||
|
* but the service also initializes the framebuffer
|
||||||
|
* Unforunately, this happens *after* any of the default
|
||||||
|
* startup methods of an activity, so we need to poll for it
|
||||||
|
*
|
||||||
|
* In order to get the fb, we need to let the Service start up
|
||||||
|
* run, we can wait in a separate thread for fb to get ready
|
||||||
|
* This thread waits for the fb to become ready */
|
||||||
|
new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
BufferedOutputStream dest = null;
|
public void run() {
|
||||||
BufferedInputStream is = null;
|
while (RockboxService.fb == null)
|
||||||
ZipEntry entry;
|
{
|
||||||
File file = new File("/data/data/org.rockbox/lib/libmisc.so");
|
try {
|
||||||
/* use arbitary file to determine whether extracting is needed */
|
Thread.sleep(250);
|
||||||
File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec");
|
} catch (InterruptedException e) {
|
||||||
if (!file2.exists() || (file.lastModified() > file2.lastModified()))
|
} catch (Exception e) {
|
||||||
{
|
LOG(e.toString());
|
||||||
ZipFile zipfile = new ZipFile(file);
|
}
|
||||||
Enumeration<? extends ZipEntry> e = zipfile.entries();
|
/* drawing needs to happen in ui thread */
|
||||||
File folder;
|
runOnUiThread(new Runnable()
|
||||||
while(e.hasMoreElements()) {
|
{ @Override
|
||||||
entry = (ZipEntry) e.nextElement();
|
public void run() {
|
||||||
LOG("Extracting: " +entry);
|
setContentView(RockboxService.fb);
|
||||||
if (entry.isDirectory())
|
RockboxService.fb.invalidate();
|
||||||
{
|
}
|
||||||
folder = new File(entry.getName());
|
});
|
||||||
LOG("mkdir "+ entry);
|
}
|
||||||
try {
|
|
||||||
folder.mkdirs();
|
}
|
||||||
} catch (SecurityException ex){
|
}).start();
|
||||||
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(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}}
|
|
||||||
Rect r = new Rect();
|
|
||||||
fb.getDrawingRect(r);
|
|
||||||
LOG(r.left + " " + r.top + " " + r.right + " " + r.bottom);
|
|
||||||
rb = new Thread(new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
main();
|
|
||||||
}
|
|
||||||
},"Rockbox thread");
|
|
||||||
System.loadLibrary("rockbox");
|
|
||||||
rb.setDaemon(false);
|
|
||||||
setContentView(fb);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LOG(CharSequence text)
|
|
||||||
{
|
|
||||||
Log.d("RockboxBootloader", (String) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void onStart()
|
|
||||||
{
|
|
||||||
super.onStart();
|
|
||||||
if (!rb.isAlive())
|
|
||||||
rb.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPause()
|
|
||||||
{
|
|
||||||
super.onPause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResume()
|
public void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
switch (rb.getState()) {
|
if (RockboxService.fb != null)
|
||||||
case BLOCKED: LOG("BLOCKED"); break;
|
{
|
||||||
case RUNNABLE: LOG("RUNNABLE"); break;
|
try {
|
||||||
case NEW: LOG("NEW"); break;
|
setContentView(RockboxService.fb);
|
||||||
case TERMINATED: LOG("TERMINATED"); break;
|
} catch (IllegalStateException e) {
|
||||||
case TIMED_WAITING: LOG("TIMED_WAITING"); break;
|
/* we are already using the View,
|
||||||
case WAITING: LOG("WAITING"); break;
|
* need to remove it and re-attach it */
|
||||||
|
ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
|
||||||
|
g.removeView(RockboxService.fb);
|
||||||
|
setContentView(RockboxService.fb);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG(e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LOG(CharSequence text)
|
||||||
private native void main();
|
{
|
||||||
|
Log.d("Rockbox", (String) text);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -47,21 +47,6 @@ public class RockboxTimer extends Timer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause()
|
|
||||||
{
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
public void resume()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
schedule(task, 0, interval);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
/* not an error */
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG(e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public RockboxTimer(long period_inverval_in_ms)
|
public RockboxTimer(long period_inverval_in_ms)
|
||||||
{
|
{
|
||||||
super("tick timer", false);
|
super("tick timer", false);
|
||||||
|
@ -72,7 +57,7 @@ public class RockboxTimer extends Timer
|
||||||
|
|
||||||
private void LOG(CharSequence text)
|
private void LOG(CharSequence text)
|
||||||
{
|
{
|
||||||
Log.d("RockboxBootloader", (String) text);
|
Log.d("Rockbox", (String) text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
extern JNIEnv *env_ptr;
|
extern JNIEnv *env_ptr;
|
||||||
extern jclass RockboxActivity_class;
|
|
||||||
extern jobject RockboxActivity_instance;
|
|
||||||
|
|
||||||
static jclass RockboxTimer_class;
|
static jclass RockboxTimer_class;
|
||||||
static jobject RockboxTimer_instance;
|
static jobject RockboxTimer_instance;
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
|
|
||||||
extern JNIEnv *env_ptr;
|
extern JNIEnv *env_ptr;
|
||||||
extern jclass RockboxActivity_class;
|
extern jclass RockboxService_class;
|
||||||
extern jobject RockboxActivity_instance;
|
extern jobject RockboxService_instance;
|
||||||
|
|
||||||
static jobject Framebuffer_instance;
|
static jobject Framebuffer_instance;
|
||||||
static jmethodID java_lcd_update;
|
static jmethodID java_lcd_update;
|
||||||
|
@ -35,13 +35,13 @@ static jmethodID java_lcd_update;
|
||||||
void lcd_init_device(void)
|
void lcd_init_device(void)
|
||||||
{
|
{
|
||||||
/* get the RockboxFramebuffer instance allocated by the activity */
|
/* get the RockboxFramebuffer instance allocated by the activity */
|
||||||
jfieldID id = (*env_ptr)->GetFieldID(env_ptr,
|
jfieldID id = (*env_ptr)->GetStaticFieldID(env_ptr,
|
||||||
RockboxActivity_class,
|
RockboxService_class,
|
||||||
"fb",
|
"fb",
|
||||||
"Lorg/rockbox/RockboxFramebuffer;");
|
"Lorg/rockbox/RockboxFramebuffer;");
|
||||||
|
|
||||||
Framebuffer_instance = (*env_ptr)->GetObjectField(env_ptr,
|
Framebuffer_instance = (*env_ptr)->GetStaticObjectField(env_ptr,
|
||||||
RockboxActivity_instance,
|
RockboxService_class,
|
||||||
id);
|
id);
|
||||||
|
|
||||||
jclass Framebuffer_class = (*env_ptr)->GetObjectClass(env_ptr,
|
jclass Framebuffer_class = (*env_ptr)->GetObjectClass(env_ptr,
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
#include "pcm.h"
|
#include "pcm.h"
|
||||||
|
|
||||||
extern JNIEnv *env_ptr;
|
extern JNIEnv *env_ptr;
|
||||||
extern jclass RockboxActivity_class;
|
|
||||||
extern jobject RockboxActivity_instance;
|
|
||||||
|
|
||||||
/* infos about our pcm chunks */
|
/* infos about our pcm chunks */
|
||||||
static size_t pcm_data_size;
|
static size_t pcm_data_size;
|
||||||
|
|
|
@ -32,8 +32,8 @@ void system_init(void) { }
|
||||||
|
|
||||||
/* global fields for use with various JNI calls */
|
/* global fields for use with various JNI calls */
|
||||||
JNIEnv *env_ptr;
|
JNIEnv *env_ptr;
|
||||||
jobject RockboxActivity_instance;
|
jobject RockboxService_instance;
|
||||||
jclass RockboxActivity_class;
|
jclass RockboxService_class;
|
||||||
|
|
||||||
uintptr_t *stackbegin;
|
uintptr_t *stackbegin;
|
||||||
uintptr_t *stackend;
|
uintptr_t *stackend;
|
||||||
|
@ -41,7 +41,7 @@ uintptr_t *stackend;
|
||||||
extern int main(void);
|
extern int main(void);
|
||||||
/* this is the entry point of the android app initially called by jni */
|
/* this is the entry point of the android app initially called by jni */
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_rockbox_RockboxActivity_main(JNIEnv *env, jobject this)
|
Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
|
||||||
{
|
{
|
||||||
/* hack!!! we can't have a valid stack pointer otherwise.
|
/* hack!!! we can't have a valid stack pointer otherwise.
|
||||||
* but we don't really need it anyway, thread.c only needs it
|
* but we don't really need it anyway, thread.c only needs it
|
||||||
|
@ -53,7 +53,7 @@ Java_org_rockbox_RockboxActivity_main(JNIEnv *env, jobject this)
|
||||||
volatile uintptr_t stack = 0;
|
volatile uintptr_t stack = 0;
|
||||||
stackbegin = stackend = (uintptr_t*) &stack;
|
stackbegin = stackend = (uintptr_t*) &stack;
|
||||||
env_ptr = env;
|
env_ptr = env;
|
||||||
RockboxActivity_instance = this;
|
RockboxService_instance = this;
|
||||||
RockboxActivity_class = (*env)->GetObjectClass(env, this);
|
RockboxService_class = (*env)->GetObjectClass(env, this);
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue