summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-03 22:56:24 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-03 22:56:24 +0000
commit9dd0158ffb98ddbd5bef0e45a9b561294ce50264 (patch)
tree7df364f01c95c6f9b9b0a831aa802670eb4a0933
parent83c60a1012f2db6c21c5779f7e11b2f3e479df85 (diff)
downloadrockbox-9dd0158ffb98ddbd5bef0e45a9b561294ce50264.tar.gz
rockbox-9dd0158ffb98ddbd5bef0e45a9b561294ce50264.zip
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
-rw-r--r--android/AndroidManifest.xml3
-rw-r--r--android/default.properties2
-rw-r--r--android/gen/org/rockbox/R.java2
-rw-r--r--android/res/values/strings.xml1
-rw-r--r--android/src/org/rockbox/RockboxActivity.java159
-rw-r--r--android/src/org/rockbox/RockboxTimer.java17
-rw-r--r--firmware/target/hosted/android/kernel-android.c2
-rw-r--r--firmware/target/hosted/android/lcd-android.c12
-rw-r--r--firmware/target/hosted/android/pcm-android.c2
-rw-r--r--firmware/target/hosted/android/system-android.c10
10 files changed, 74 insertions, 136 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index a22c393379..30acaf09f7 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -10,7 +10,8 @@
10 <action android:name="android.intent.action.MAIN" /> 10 <action android:name="android.intent.action.MAIN" />
11 <category android:name="android.intent.category.LAUNCHER" /> 11 <category android:name="android.intent.category.LAUNCHER" />
12 </intent-filter> 12 </intent-filter>
13 </activity> 13 </activity>
14 <service android:name=".RockboxService"/>
14 15
15 </application> 16 </application>
16<uses-sdk android:minSdkVersion="4" /> 17<uses-sdk android:minSdkVersion="4" />
diff --git a/android/default.properties b/android/default.properties
index 9d79b12c71..9d135cb85f 100644
--- a/android/default.properties
+++ b/android/default.properties
@@ -8,4 +8,4 @@
8# project structure. 8# project structure.
9 9
10# Project target. 10# Project target.
11target=android-4 11target=android-7
diff --git a/android/gen/org/rockbox/R.java b/android/gen/org/rockbox/R.java
index 38c177ef36..50f3456e5f 100644
--- a/android/gen/org/rockbox/R.java
+++ b/android/gen/org/rockbox/R.java
@@ -12,11 +12,13 @@ public final class R {
12 } 12 }
13 public static final class drawable { 13 public static final class drawable {
14 public static final int icon=0x7f020000; 14 public static final int icon=0x7f020000;
15 public static final int rb=0x7f020001;
15 } 16 }
16 public static final class layout { 17 public static final class layout {
17 public static final int main=0x7f030000; 18 public static final int main=0x7f030000;
18 } 19 }
19 public static final class string { 20 public static final class string {
20 public static final int app_name=0x7f040000; 21 public static final int app_name=0x7f040000;
22 public static final int notification=0x7f040001;
21 } 23 }
22} 24}
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index 6c3c8464fd..9320b2624d 100644
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -2,4 +2,5 @@
2<resources> 2<resources>
3 3
4 <string name="app_name">Rockbox</string> 4 <string name="app_name">Rockbox</string>
5<string name="notification">Rockbox</string>
5</resources> 6</resources>
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index 791cad90ff..eadfd5a40a 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -21,128 +21,81 @@
21 21
22package org.rockbox; 22package org.rockbox;
23 23
24import java.io.BufferedInputStream;
25import java.io.BufferedOutputStream;
26import java.io.File;
27import java.io.FileOutputStream;
28import java.util.Enumeration;
29import java.util.zip.ZipEntry;
30import java.util.zip.ZipFile;
31
32import android.app.Activity; 24import android.app.Activity;
33import android.graphics.Rect; 25import android.content.Intent;
34import android.os.Bundle; 26import android.os.Bundle;
35import android.util.Log; 27import android.util.Log;
28import android.view.ViewGroup;
36import android.view.Window; 29import android.view.Window;
37import android.view.WindowManager; 30import android.view.WindowManager;
38 31
39public class RockboxActivity extends Activity { 32public class RockboxActivity extends Activity {
40 /** Called when the activity is first created. */ 33 /** Called when the activity is first created. */
41 public RockboxFramebuffer fb;
42 private Thread rb;
43 static final int BUFFER = 2048;
44 /** Called when the activity is first created. */
45 @Override 34 @Override
46 public void onCreate(Bundle savedInstanceState) { 35 public void onCreate(Bundle savedInstanceState)
36 {
47 super.onCreate(savedInstanceState); 37 super.onCreate(savedInstanceState);
48 LOG("start rb");
49 requestWindowFeature(Window.FEATURE_NO_TITLE); 38 requestWindowFeature(Window.FEATURE_NO_TITLE);
50 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN 39 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
51 ,WindowManager.LayoutParams.FLAG_FULLSCREEN); 40 ,WindowManager.LayoutParams.FLAG_FULLSCREEN);
52 fb = new RockboxFramebuffer(this); 41 final Intent intent = new Intent(this,
53 if (true) { 42 RockboxService.class);
54 try 43 startService(intent);
44 /* Now it gets a bit tricky:
45 * The service is started in the same thread as we are now,
46 * but the service also initializes the framebuffer
47 * Unforunately, this happens *after* any of the default
48 * startup methods of an activity, so we need to poll for it
49 *
50 * In order to get the fb, we need to let the Service start up
51 * run, we can wait in a separate thread for fb to get ready
52 * This thread waits for the fb to become ready */
53 new Thread(new Runnable()
55 { 54 {
56 BufferedOutputStream dest = null; 55 public void run() {
57 BufferedInputStream is = null; 56 while (RockboxService.fb == null)
58 ZipEntry entry; 57 {
59 File file = new File("/data/data/org.rockbox/lib/libmisc.so"); 58 try {
60 /* use arbitary file to determine whether extracting is needed */ 59 Thread.sleep(250);
61 File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec"); 60 } catch (InterruptedException e) {
62 if (!file2.exists() || (file.lastModified() > file2.lastModified())) 61 } catch (Exception e) {
63 { 62 LOG(e.toString());
64 ZipFile zipfile = new ZipFile(file); 63 }
65 Enumeration<? extends ZipEntry> e = zipfile.entries(); 64 /* drawing needs to happen in ui thread */
66 File folder; 65 runOnUiThread(new Runnable()
67 while(e.hasMoreElements()) { 66 { @Override
68 entry = (ZipEntry) e.nextElement(); 67 public void run() {
69 LOG("Extracting: " +entry); 68 setContentView(RockboxService.fb);
70 if (entry.isDirectory()) 69 RockboxService.fb.invalidate();
71 { 70 }
72 folder = new File(entry.getName()); 71 });
73 LOG("mkdir "+ entry); 72 }
74 try { 73
75 folder.mkdirs(); 74 }
76 } catch (SecurityException ex){ 75 }).start();
77 LOG(ex.getMessage());
78 }
79 continue;
80 }
81 is = new BufferedInputStream(zipfile.getInputStream(entry));
82 int count;
83 byte data[] = new byte[BUFFER];
84 folder = new File(new File(entry.getName()).getParent());
85 LOG("" + folder.getAbsolutePath());
86 if (!folder.exists())
87 folder.mkdirs();
88 FileOutputStream fos = new FileOutputStream(entry.getName());
89 dest = new BufferedOutputStream(fos, BUFFER);
90 while ((count = is.read(data, 0, BUFFER)) != -1) {
91 dest.write(data, 0, count);
92 }
93 dest.flush();
94 dest.close();
95 is.close();
96 }
97 }
98 } catch(Exception e) {
99 e.printStackTrace();
100 }}
101 Rect r = new Rect();
102 fb.getDrawingRect(r);
103 LOG(r.left + " " + r.top + " " + r.right + " " + r.bottom);
104 rb = new Thread(new Runnable()
105 {
106 public void run()
107 {
108 main();
109 }
110 },"Rockbox thread");
111 System.loadLibrary("rockbox");
112 rb.setDaemon(false);
113 setContentView(fb);
114 }
115
116 private void LOG(CharSequence text)
117 {
118 Log.d("RockboxBootloader", (String) text);
119 }
120
121 public synchronized void onStart()
122 {
123 super.onStart();
124 if (!rb.isAlive())
125 rb.start();
126 }
127
128 public void onPause()
129 {
130 super.onPause();
131 } 76 }
132 77
133 public void onResume() 78 public void onResume()
134 { 79 {
135 super.onResume(); 80 super.onResume();
136 switch (rb.getState()) { 81 if (RockboxService.fb != null)
137 case BLOCKED: LOG("BLOCKED"); break; 82 {
138 case RUNNABLE: LOG("RUNNABLE"); break; 83 try {
139 case NEW: LOG("NEW"); break; 84 setContentView(RockboxService.fb);
140 case TERMINATED: LOG("TERMINATED"); break; 85 } catch (IllegalStateException e) {
141 case TIMED_WAITING: LOG("TIMED_WAITING"); break; 86 /* we are already using the View,
142 case WAITING: LOG("WAITING"); break; 87 * need to remove it and re-attach it */
88 ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
89 g.removeView(RockboxService.fb);
90 setContentView(RockboxService.fb);
91 } catch (Exception e) {
92 LOG(e.toString());
93 }
143 } 94 }
144 } 95 }
145 96
146 97 private void LOG(CharSequence text)
147 private native void main(); 98 {
99 Log.d("Rockbox", (String) text);
100 }
148} \ No newline at end of file 101} \ No newline at end of file
diff --git a/android/src/org/rockbox/RockboxTimer.java b/android/src/org/rockbox/RockboxTimer.java
index c7239b4ee6..6491e4ffe9 100644
--- a/android/src/org/rockbox/RockboxTimer.java
+++ b/android/src/org/rockbox/RockboxTimer.java
@@ -47,21 +47,6 @@ public class RockboxTimer extends Timer
47 } 47 }
48 } 48 }
49 49
50 public void pause()
51 {
52 cancel();
53 }
54 public void resume()
55 {
56 try {
57 schedule(task, 0, interval);
58 } catch (IllegalStateException e) {
59 /* not an error */
60 } catch (Exception e) {
61 LOG(e.toString());
62 }
63 }
64
65 public RockboxTimer(long period_inverval_in_ms) 50 public RockboxTimer(long period_inverval_in_ms)
66 { 51 {
67 super("tick timer", false); 52 super("tick timer", false);
@@ -72,7 +57,7 @@ public class RockboxTimer extends Timer
72 57
73 private void LOG(CharSequence text) 58 private void LOG(CharSequence text)
74 { 59 {
75 Log.d("RockboxBootloader", (String) text); 60 Log.d("Rockbox", (String) text);
76 } 61 }
77 62
78 63
diff --git a/firmware/target/hosted/android/kernel-android.c b/firmware/target/hosted/android/kernel-android.c
index 9594516460..1a9b97b419 100644
--- a/firmware/target/hosted/android/kernel-android.c
+++ b/firmware/target/hosted/android/kernel-android.c
@@ -25,8 +25,6 @@
25#include "system.h" 25#include "system.h"
26 26
27extern JNIEnv *env_ptr; 27extern JNIEnv *env_ptr;
28extern jclass RockboxActivity_class;
29extern jobject RockboxActivity_instance;
30 28
31static jclass RockboxTimer_class; 29static jclass RockboxTimer_class;
32static jobject RockboxTimer_instance; 30static jobject RockboxTimer_instance;
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index ef4004ef2a..efe68cdd71 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -26,8 +26,8 @@
26#include "lcd.h" 26#include "lcd.h"
27 27
28extern JNIEnv *env_ptr; 28extern JNIEnv *env_ptr;
29extern jclass RockboxActivity_class; 29extern jclass RockboxService_class;
30extern jobject RockboxActivity_instance; 30extern jobject RockboxService_instance;
31 31
32static jobject Framebuffer_instance; 32static jobject Framebuffer_instance;
33static jmethodID java_lcd_update; 33static jmethodID java_lcd_update;
@@ -35,13 +35,13 @@ static jmethodID java_lcd_update;
35void lcd_init_device(void) 35void lcd_init_device(void)
36{ 36{
37 /* get the RockboxFramebuffer instance allocated by the activity */ 37 /* get the RockboxFramebuffer instance allocated by the activity */
38 jfieldID id = (*env_ptr)->GetFieldID(env_ptr, 38 jfieldID id = (*env_ptr)->GetStaticFieldID(env_ptr,
39 RockboxActivity_class, 39 RockboxService_class,
40 "fb", 40 "fb",
41 "Lorg/rockbox/RockboxFramebuffer;"); 41 "Lorg/rockbox/RockboxFramebuffer;");
42 42
43 Framebuffer_instance = (*env_ptr)->GetObjectField(env_ptr, 43 Framebuffer_instance = (*env_ptr)->GetStaticObjectField(env_ptr,
44 RockboxActivity_instance, 44 RockboxService_class,
45 id); 45 id);
46 46
47 jclass Framebuffer_class = (*env_ptr)->GetObjectClass(env_ptr, 47 jclass Framebuffer_class = (*env_ptr)->GetObjectClass(env_ptr,
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
index 91978f422b..8c5d2597c4 100644
--- a/firmware/target/hosted/android/pcm-android.c
+++ b/firmware/target/hosted/android/pcm-android.c
@@ -25,8 +25,6 @@
25#include "pcm.h" 25#include "pcm.h"
26 26
27extern JNIEnv *env_ptr; 27extern JNIEnv *env_ptr;
28extern jclass RockboxActivity_class;
29extern jobject RockboxActivity_instance;
30 28
31/* infos about our pcm chunks */ 29/* infos about our pcm chunks */
32static size_t pcm_data_size; 30static size_t pcm_data_size;
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index 16c6973474..1fb69b3465 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -32,8 +32,8 @@ void system_init(void) { }
32 32
33/* global fields for use with various JNI calls */ 33/* global fields for use with various JNI calls */
34JNIEnv *env_ptr; 34JNIEnv *env_ptr;
35jobject RockboxActivity_instance; 35jobject RockboxService_instance;
36jclass RockboxActivity_class; 36jclass RockboxService_class;
37 37
38uintptr_t *stackbegin; 38uintptr_t *stackbegin;
39uintptr_t *stackend; 39uintptr_t *stackend;
@@ -41,7 +41,7 @@ uintptr_t *stackend;
41extern int main(void); 41extern int main(void);
42/* this is the entry point of the android app initially called by jni */ 42/* this is the entry point of the android app initially called by jni */
43JNIEXPORT void JNICALL 43JNIEXPORT void JNICALL
44Java_org_rockbox_RockboxActivity_main(JNIEnv *env, jobject this) 44Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
45{ 45{
46 /* hack!!! we can't have a valid stack pointer otherwise. 46 /* hack!!! we can't have a valid stack pointer otherwise.
47 * but we don't really need it anyway, thread.c only needs it 47 * 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)
53 volatile uintptr_t stack = 0; 53 volatile uintptr_t stack = 0;
54 stackbegin = stackend = (uintptr_t*) &stack; 54 stackbegin = stackend = (uintptr_t*) &stack;
55 env_ptr = env; 55 env_ptr = env;
56 RockboxActivity_instance = this; 56 RockboxService_instance = this;
57 RockboxActivity_class = (*env)->GetObjectClass(env, this); 57 RockboxService_class = (*env)->GetObjectClass(env, this);
58 main(); 58 main();
59} 59}