From 2d903d966875bb2bc665cd33d3514fb6b2dcf7f5 Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Mon, 27 Jan 2014 18:29:00 -0800 Subject: ANDROID: Fix a race condition setSurface is done in a different thread than the one that starts the scummvm main. The main thread would then wait until the setSurface thread notifies. The setSurface thread would notify before it actually calls setSurface, meaning if the thread is preemted before calling setSurface, initSurface will assert, causing the app to crash. --- backends/platform/android/org/scummvm/scummvm/ScummVM.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'backends/platform/android/org') diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java index 3a25b54eeb..5047502e61 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java @@ -86,13 +86,15 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable { Log.d(LOG_TAG, String.format("surfaceChanged: %dx%d (%d)", width, height, format)); + // store values for the native code + // make sure to do it before notifying the lock + // as it leads to a race condition otherwise + setSurface(width, height); + synchronized(_sem_surface) { _surface_holder = holder; _sem_surface.notifyAll(); } - - // store values for the native code - setSurface(width, height); } // SurfaceHolder callback -- cgit v1.2.3 From 0def54a60d8a5c6e63bb5db238bbadf388dede97 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Fri, 21 Feb 2014 16:29:23 +0000 Subject: ANDROID: Fix runtime failure on earlier versions of Android. getAxisValue() is only present from Android 3.1 onwards and usage causes a runtime failure on earlier versions of Android. This bug was introduced by a50ede20 with addition of OUYA support. This solution is as recommended on the Android developer portal. --- .../android/org/scummvm/scummvm/ScummVMEvents.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'backends/platform/android/org') diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java index 702215341b..eef5d1911b 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java @@ -1,5 +1,6 @@ package org.scummvm.scummvm; +import android.os.Build; import android.os.Handler; import android.os.Message; import android.content.Context; @@ -69,13 +70,16 @@ public class ScummVMEvents implements } public boolean onGenericMotionEvent(final MotionEvent e) { - if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { - _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), - (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), - (int)(e.getAxisValue(MotionEvent.AXIS_Y)*100), - 0, 0); - return true; - } + // Make sure we're running on Android 3.1 or higher to use getAxisValue() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { + if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), + (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), + (int)(e.getAxisValue(MotionEvent.AXIS_Y)*100), + 0, 0); + return true; + } + } return false; } -- cgit v1.2.3 From d6a90f610f241b59e63b65088a2acfdd359b1d6d Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 22 Feb 2014 19:47:15 +0100 Subject: ANDROID: Slight formatting fix. --- backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'backends/platform/android/org') diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java index eef5d1911b..a96bc566eb 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java @@ -70,8 +70,8 @@ public class ScummVMEvents implements } public boolean onGenericMotionEvent(final MotionEvent e) { - // Make sure we're running on Android 3.1 or higher to use getAxisValue() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { + // Make sure we're running on Android 3.1 or higher to use getAxisValue() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), @@ -79,7 +79,7 @@ public class ScummVMEvents implements 0, 0); return true; } - } + } return false; } -- cgit v1.2.3 From cbf085287c74e0994fb18fb0830ccdb340b5b0ac Mon Sep 17 00:00:00 2001 From: D G Turner Date: Wed, 26 Feb 2014 15:26:12 +0000 Subject: ANDROID: Fix Android pre3.1 compatibility. This was broken by a50ede203b0424d800d2a1d4460121f9f1de8e7a. --- .../org/scummvm/scummvm/ScummVMActivity.java | 10 ++++++++- .../android/org/scummvm/scummvm/ScummVMEvents.java | 14 +----------- .../scummvm/scummvm/ScummVMEventsHoneycomb.java | 25 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 backends/platform/android/org/scummvm/scummvm/ScummVMEventsHoneycomb.java (limited to 'backends/platform/android/org') diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java index 5d041dafd2..5964d5bfde 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.media.AudioManager; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.util.DisplayMetrics; @@ -169,7 +170,14 @@ public class ScummVMActivity extends Activity { _mouseHelper.attach(main_surface); } - _events = new ScummVMEvents(this, _scummvm, _mouseHelper); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) + { + _events = new ScummVMEvents(this, _scummvm, _mouseHelper); + } + else + { + _events = new ScummVMEventsHoneycomb(this, _scummvm, _mouseHelper); + } main_surface.setOnKeyListener(_events); main_surface.setOnTouchListener(_events); diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java index a96bc566eb..32c65d3395 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java @@ -1,6 +1,5 @@ package org.scummvm.scummvm; -import android.os.Build; import android.os.Handler; import android.os.Message; import android.content.Context; @@ -69,18 +68,7 @@ public class ScummVMEvents implements return true; } - public boolean onGenericMotionEvent(final MotionEvent e) { - // Make sure we're running on Android 3.1 or higher to use getAxisValue() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { - if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { - _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), - (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), - (int)(e.getAxisValue(MotionEvent.AXIS_Y)*100), - 0, 0); - return true; - } - } - + public boolean onGenericMotionEvent(MotionEvent e) { return false; } diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsHoneycomb.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsHoneycomb.java new file mode 100644 index 0000000000..ab85429040 --- /dev/null +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsHoneycomb.java @@ -0,0 +1,25 @@ +package org.scummvm.scummvm; + +import android.content.Context; +import android.view.MotionEvent; +import android.view.InputDevice; + +public class ScummVMEventsHoneycomb extends ScummVMEvents { + + public ScummVMEventsHoneycomb(Context context, ScummVM scummvm, MouseHelper mouseHelper) { + super(context, scummvm, mouseHelper); + } + + @Override + public boolean onGenericMotionEvent(MotionEvent e) { + if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), + (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), + (int)(e.getAxisValue(MotionEvent.AXIS_Y)*100), + 0, 0); + return true; + } + + return false; + } +} -- cgit v1.2.3