forked from len0rd/rockbox
Clean up usage of RockboxService. Add a proper way to check if rockbox is actually running (checking RockboxService.fb != null was very very bad)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28406 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
78b2711e58
commit
26f7ee13ce
4 changed files with 71 additions and 32 deletions
|
@ -32,6 +32,7 @@ import android.view.WindowManager;
|
||||||
public class RockboxActivity extends Activity
|
public class RockboxActivity extends Activity
|
||||||
{
|
{
|
||||||
private ProgressDialog loadingdialog;
|
private ProgressDialog loadingdialog;
|
||||||
|
private RockboxService rbservice;
|
||||||
/** 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)
|
||||||
|
@ -40,8 +41,7 @@ public class RockboxActivity extends Activity
|
||||||
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);
|
||||||
final Intent intent = new Intent(this,
|
final Intent intent = new Intent(this, RockboxService.class);
|
||||||
RockboxService.class);
|
|
||||||
/* prepare a please wait dialog in case we need
|
/* prepare a please wait dialog in case we need
|
||||||
* to wait for unzipping libmisc.so
|
* to wait for unzipping libmisc.so
|
||||||
*/
|
*/
|
||||||
|
@ -50,6 +50,7 @@ public class RockboxActivity extends Activity
|
||||||
loadingdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
loadingdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||||
loadingdialog.setCancelable(false);
|
loadingdialog.setCancelable(false);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
rbservice = RockboxService.get_instance();
|
||||||
/* Now it gets a bit tricky:
|
/* Now it gets a bit tricky:
|
||||||
* The service is started in the same thread as we are now,
|
* The service is started in the same thread as we are now,
|
||||||
* but the service also initializes the framebuffer
|
* but the service also initializes the framebuffer
|
||||||
|
@ -68,8 +69,8 @@ public class RockboxActivity extends Activity
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Thread.sleep(250);
|
Thread.sleep(250);
|
||||||
if (RockboxService.fb != null)
|
if (isRockboxRunning())
|
||||||
break;
|
break;
|
||||||
/* if it's still null show the please wait dialog
|
/* if it's still null show the please wait dialog
|
||||||
* but not before 0.5s are over */
|
* but not before 0.5s are over */
|
||||||
if (!loadingdialog.isShowing() && i > 0)
|
if (!loadingdialog.isShowing() && i > 0)
|
||||||
|
@ -92,32 +93,37 @@ public class RockboxActivity extends Activity
|
||||||
{
|
{
|
||||||
public void run() {
|
public void run() {
|
||||||
loadingdialog.dismiss();
|
loadingdialog.dismiss();
|
||||||
if (RockboxService.fb == null)
|
if (rbservice.get_fb() == null)
|
||||||
throw new IllegalStateException("FB NULL");
|
throw new IllegalStateException("FB NULL");
|
||||||
setContentView(RockboxService.fb);
|
setContentView(rbservice.get_fb());
|
||||||
RockboxService.fb.invalidate();
|
rbservice.get_fb().invalidate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
private boolean isRockboxRunning()
|
||||||
|
{
|
||||||
|
if (rbservice == null)
|
||||||
|
rbservice = RockboxService.get_instance();
|
||||||
|
return (rbservice!= null && rbservice.isRockboxRunning() == true);
|
||||||
|
}
|
||||||
|
|
||||||
public void onResume()
|
public void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
if (isRockboxRunning())
|
||||||
if (RockboxService.fb != null)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
setContentView(RockboxService.fb);
|
setContentView(rbservice.get_fb());
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
/* we are already using the View,
|
/* we are already using the View,
|
||||||
* need to remove it and re-attach it */
|
* need to remove it and re-attach it */
|
||||||
ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
|
ViewGroup g = (ViewGroup)rbservice.get_fb().getParent();
|
||||||
g.removeView(RockboxService.fb);
|
g.removeView(rbservice.get_fb());
|
||||||
setContentView(RockboxService.fb);
|
setContentView(rbservice.get_fb());
|
||||||
} finally {
|
} finally {
|
||||||
RockboxService.fb.resume();
|
rbservice.get_fb().resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,20 +135,20 @@ public class RockboxActivity extends Activity
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
super.onPause();
|
super.onPause();
|
||||||
RockboxService.fb.suspend();
|
rbservice.get_fb().suspend();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop()
|
protected void onStop()
|
||||||
{
|
{
|
||||||
super.onStop();
|
super.onStop();
|
||||||
RockboxService.fb.suspend();
|
rbservice.get_fb().suspend();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy()
|
protected void onDestroy()
|
||||||
{
|
{
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
RockboxService.fb.suspend();
|
rbservice.get_fb().suspend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class RockboxPCM extends AudioTrack
|
||||||
{
|
{
|
||||||
if (getPlayState() == AudioTrack.PLAYSTATE_STOPPED)
|
if (getPlayState() == AudioTrack.PLAYSTATE_STOPPED)
|
||||||
{
|
{
|
||||||
RockboxService.startForeground();
|
RockboxService.get_instance().startForeground();
|
||||||
if (getState() == AudioTrack.STATE_INITIALIZED)
|
if (getState() == AudioTrack.STATE_INITIALIZED)
|
||||||
{
|
{
|
||||||
if (h == null)
|
if (h == null)
|
||||||
|
@ -113,7 +113,7 @@ public class RockboxPCM extends AudioTrack
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
RockboxService.stopForeground();
|
RockboxService.get_instance().stopForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
@ -46,11 +46,22 @@ import android.content.IntentFilter;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
/* This class is used as the main glue between java and c.
|
||||||
|
* All access should be done through RockboxService.get_instance() for safety.
|
||||||
|
*/
|
||||||
|
|
||||||
public class RockboxService extends Service
|
public class RockboxService extends Service
|
||||||
{
|
{
|
||||||
/* this Service is really a singleton class */
|
/* this Service is really a singleton class - well almost.
|
||||||
public static RockboxFramebuffer fb = null;
|
* To do it properly this line should be instance = new RockboxService()
|
||||||
private static RockboxService instance;
|
* but apparently that doesnt work with the way android Services are created.
|
||||||
|
*/
|
||||||
|
private static RockboxService instance = null;
|
||||||
|
|
||||||
|
/* locals needed for the c code and rockbox state */
|
||||||
|
private RockboxFramebuffer fb = null;
|
||||||
|
private boolean mRockboxRunning = false;
|
||||||
|
|
||||||
private Notification notification;
|
private Notification notification;
|
||||||
private static final Class<?>[] mStartForegroundSignature =
|
private static final Class<?>[] mStartForegroundSignature =
|
||||||
new Class[] { int.class, Notification.class };
|
new Class[] { int.class, Notification.class };
|
||||||
|
@ -70,6 +81,7 @@ public class RockboxService extends Service
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
|
instance = this;
|
||||||
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -83,9 +95,24 @@ public class RockboxService extends Service
|
||||||
/* Running on an older platform: fall back to old API */
|
/* Running on an older platform: fall back to old API */
|
||||||
mStartForeground = mStopForeground = null;
|
mStartForeground = mStopForeground = null;
|
||||||
}
|
}
|
||||||
instance = this;
|
|
||||||
startservice();
|
startservice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RockboxService get_instance()
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RockboxFramebuffer get_fb()
|
||||||
|
{
|
||||||
|
return fb;
|
||||||
|
}
|
||||||
|
/* framebuffer is initialised by the native code(!) so this is needed */
|
||||||
|
public void set_fb(RockboxFramebuffer newfb)
|
||||||
|
{
|
||||||
|
fb = newfb;
|
||||||
|
mRockboxRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void do_start(Intent intent)
|
private void do_start(Intent intent)
|
||||||
{
|
{
|
||||||
|
@ -190,8 +217,16 @@ public class RockboxService extends Service
|
||||||
rb.setDaemon(false);
|
rb.setDaemon(false);
|
||||||
rb.start();
|
rb.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void main();
|
private native void main();
|
||||||
|
|
||||||
|
/* returns true once rockbox is up and running.
|
||||||
|
* This is considered done once the framebuffer is initialised
|
||||||
|
*/
|
||||||
|
public boolean isRockboxRunning()
|
||||||
|
{
|
||||||
|
return mRockboxRunning;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent)
|
public IBinder onBind(Intent intent)
|
||||||
{
|
{
|
||||||
|
@ -262,7 +297,7 @@ public class RockboxService extends Service
|
||||||
getText(R.string.notification), text, contentIntent);
|
getText(R.string.notification), text, contentIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startForeground()
|
public void startForeground()
|
||||||
{
|
{
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
{
|
{
|
||||||
|
@ -282,7 +317,7 @@ public class RockboxService extends Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stopForeground()
|
public void stopForeground()
|
||||||
{
|
{
|
||||||
if (instance.notification != null)
|
if (instance.notification != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,11 +78,9 @@ void lcd_init_device(void)
|
||||||
"java_lcd_update_rect",
|
"java_lcd_update_rect",
|
||||||
"(IIII)V");
|
"(IIII)V");
|
||||||
|
|
||||||
/* at last, give RockboxService the Framebuffer instance */
|
jmethodID fbsetter = e->GetMethodID(env_ptr,RockboxService_class,
|
||||||
jfieldID id = e->GetStaticFieldID(env_ptr, RockboxService_class,
|
"set_fb", "(Lorg/rockbox/RockboxFramebuffer;)V");
|
||||||
"fb", "Lorg/rockbox/RockboxFramebuffer;");
|
e->CallVoidMethod(env_ptr, RockboxService_instance, fbsetter, RockboxFramebuffer_instance);
|
||||||
e->SetStaticObjectField(env_ptr, RockboxService_class,
|
|
||||||
id, RockboxFramebuffer_instance);
|
|
||||||
display_on = true;
|
display_on = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue