[Scummvm-git-logs] scummvm branch-2-7-0-android -> 767f70d595d6a1bd28b56faf6d9eb4ed71a2be23

antoniou79 noreply at scummvm.org
Sun Mar 26 10:49:33 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b1eb46ed44 ANDROID: Write to a scummvm.log file
767f70d595 ANDROID: Clean up log code and use Backends::Log


Commit: b1eb46ed4433be8df05089869afc9ded5164dfe1
    https://github.com/scummvm/scummvm/commit/b1eb46ed4433be8df05089869afc9ded5164dfe1
Author: Antoniou Athanasios (a.antoniou79 at gmail.com)
Date: 2023-03-26T13:49:21+03:00

Commit Message:
ANDROID: Write to a scummvm.log file

Changed paths:
    backends/platform/android/android.cpp
    backends/platform/android/android.h
    backends/platform/android/jni-android.cpp
    backends/platform/android/jni-android.h
    backends/platform/android/org/scummvm/scummvm/ScummVM.java
    backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
    dists/android/res/values/strings.xml


diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 13a51736fdc..c16543d4489 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -40,6 +40,14 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#define FORBIDDEN_SYMBOL_EXCEPTION_fopen
+#define FORBIDDEN_SYMBOL_EXCEPTION_fclose
+#define FORBIDDEN_SYMBOL_EXCEPTION_fputs
+#define FORBIDDEN_SYMBOL_EXCEPTION_fwrite
+#define FORBIDDEN_SYMBOL_EXCEPTION_ftell
+#define FORBIDDEN_SYMBOL_EXCEPTION_fflush
+
 #include <EGL/egl.h>
 #include <sys/time.h>
 #include <sys/resource.h>
@@ -180,7 +188,10 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
 	_secondPointerId(-1),
 	_thirdPointerId(-1),
 	_trackball_scale(2),
-	_joystick_scale(10) {
+	_joystick_scale(10),
+	_defaultConfigFileName(""),
+	_defaultLogFileName("") {
+//	_scvmLogFilePtr(nullptr) {
 
 	LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s",
 			getSystemProperty("ro.product.manufacturer").c_str(),
@@ -232,6 +243,12 @@ OSystem_Android::~OSystem_Android() {
 
 	// Uninitialize surface now to avoid it to be done later when touch controls are destroyed
 	dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->deinitSurface();
+
+//	// close log file
+//	if (_scvmLogFilePtr != nullptr) {
+//		fflush(_scvmLogFilePtr);
+//		fclose(_scvmLogFilePtr);
+//	}
 }
 
 void *OSystem_Android::timerThreadFunc(void *arg) {
@@ -405,6 +422,19 @@ void OSystem_Android::initBackend() {
 
 	_main_thread = pthread_self();
 
+//	// Open log file
+//	if (!getDefaultLogFileName().empty()) {
+//		_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
+//		if (_scvmLogFilePtr != nullptr) {
+//			LOGD("Opened log file for writing upon initializing backend");
+//		} else {
+//			LOGE("Error when opening log file for writing upon initializing backend");
+//		}
+//	} else {
+//		LOGE("Error: log file path not known yet, upon initializing backend");
+//	}
+
+
 	// Warning: ConfMan.registerDefault() can be used for a Session of ScummVM
 	//          but:
 	//              1. The values will NOT persist to storage
@@ -531,7 +561,18 @@ void OSystem_Android::initBackend() {
 }
 
 Common::String OSystem_Android::getDefaultConfigFileName() {
-	return JNI::getScummVMConfigPath();
+	// if possible, skip JNI call which is more costly (performance wise)
+	if (_defaultConfigFileName.empty()) {
+		_defaultConfigFileName = JNI::getScummVMConfigPath();
+	}
+	return _defaultConfigFileName;
+}
+
+Common::String OSystem_Android::getDefaultLogFileName() {
+	if (_defaultLogFileName.empty()) {
+		_defaultLogFileName = JNI::getScummVMLogPath();
+	}
+	return _defaultLogFileName;
 }
 
 bool OSystem_Android::hasFeature(Feature f) {
@@ -728,6 +769,42 @@ void OSystem_Android::logMessage(LogMessageType::Type type, const char *message)
 		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, message);
 		break;
 	}
+
+	if (!getDefaultLogFileName().empty()) {
+		// open for append by default
+		FILE *_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
+
+		// TODO Do we need to worry about threading/synchronization here?
+		if (_scvmLogFilePtr != nullptr) {
+			long sz = ftell(_scvmLogFilePtr);
+			if (sz > MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
+				fclose(_scvmLogFilePtr);
+				__android_log_write(ANDROID_LOG_WARN, android_log_tag, "Default log file is bigger than 100KB. It will be overwritten!");
+				if (!getDefaultLogFileName().empty()) {
+					// Create the log file from scratch overwriting the previous one
+					_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "w");
+					if (_scvmLogFilePtr == nullptr) {
+						__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for rewrite!");
+						return;
+					}
+				} else {
+					__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known!");
+					return;
+				}
+			}
+
+			fputs(message, _scvmLogFilePtr);
+			fwrite("\n", 1, 1, _scvmLogFilePtr);
+			// close log file
+			fflush(_scvmLogFilePtr);
+			fclose(_scvmLogFilePtr);
+		} else {
+			__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for writing/appending.");
+			__android_log_write(ANDROID_LOG_ERROR, android_log_tag, getDefaultLogFileName().c_str());
+		}
+	}   else {
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Error: log file path not known yet, upon initializing backend");
+	}
 }
 
 Common::String OSystem_Android::getSystemLanguage() const {
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 119dc07c3d7..517681d51d6 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -18,6 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
+//#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
 
 #ifndef _ANDROID_H_
 #define _ANDROID_H_
@@ -54,6 +55,8 @@ extern const char *android_log_tag;
 #define LOGW(fmt, args...) _ANDROID_LOG(ANDROID_LOG_WARN, fmt, ##args)
 #define LOGE(fmt, args...) _ANDROID_LOG(ANDROID_LOG_ERROR, fmt, ##args)
 
+#define MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES (100*1024)
+
 #ifdef ANDROID_DEBUG_ENTER
 #define ENTER(fmt, args...) LOGD("%s(" fmt ")", __FUNCTION__, ##args)
 #else
@@ -167,6 +170,11 @@ private:
 
 	TouchControls _touchControls;
 
+	Common::String _defaultConfigFileName;
+	Common::String _defaultLogFileName;
+
+//	FILE *_scvmLogFilePtr;
+
 #if defined(USE_OPENGL) && defined(USE_GLAD)
 	// Cached dlopen object
 	mutable void *_gles2DL;
@@ -178,6 +186,7 @@ public:
 	Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override;
 
 	Common::String getDefaultConfigFileName() override;
+	Common::String getDefaultLogFileName() override;
 
 	void registerDefaultSettings(const Common::String &target) const override;
 	GUI::OptionsContainerWidget *buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
diff --git a/backends/platform/android/jni-android.cpp b/backends/platform/android/jni-android.cpp
index e94edde61e5..4d9567be215 100644
--- a/backends/platform/android/jni-android.cpp
+++ b/backends/platform/android/jni-android.cpp
@@ -95,6 +95,7 @@ jmethodID JNI::_MID_setTouchMode = 0;
 jmethodID JNI::_MID_getTouchMode = 0;
 jmethodID JNI::_MID_getScummVMBasePath;
 jmethodID JNI::_MID_getScummVMConfigPath;
+jmethodID JNI::_MID_getScummVMLogPath;
 jmethodID JNI::_MID_getSysArchives = 0;
 jmethodID JNI::_MID_getAllStorageLocations = 0;
 jmethodID JNI::_MID_initSurface = 0;
@@ -513,7 +514,7 @@ Common::String JNI::getScummVMBasePath() {
 	jstring pathObj = (jstring)env->CallObjectMethod(_jobj, _MID_getScummVMBasePath);
 
 	if (env->ExceptionCheck()) {
-		LOGE("Failed to get ScummVM base path");
+		LOGE("Failed to get ScummVM base folder path");
 
 		env->ExceptionDescribe();
 		env->ExceptionClear();
@@ -538,7 +539,7 @@ Common::String JNI::getScummVMConfigPath() {
 	jstring pathObj = (jstring)env->CallObjectMethod(_jobj, _MID_getScummVMConfigPath);
 
 	if (env->ExceptionCheck()) {
-		LOGE("Failed to get ScummVM base path");
+		LOGE("Failed to get ScummVM config file path");
 
 		env->ExceptionDescribe();
 		env->ExceptionClear();
@@ -557,6 +558,30 @@ Common::String JNI::getScummVMConfigPath() {
 	return path;
 }
 
+Common::String JNI::getScummVMLogPath() {
+	JNIEnv *env = JNI::getEnv();
+
+	jstring pathObj = (jstring)env->CallObjectMethod(_jobj, _MID_getScummVMLogPath);
+
+	if (env->ExceptionCheck()) {
+		LOGE("Failed to get ScummVM log file path");
+
+		env->ExceptionDescribe();
+		env->ExceptionClear();
+
+		return Common::String();
+	}
+
+	Common::String path;
+	const char *pathP = env->GetStringUTFChars(pathObj, 0);
+	if (pathP != 0) {
+		path = Common::String(pathP);
+		env->ReleaseStringUTFChars(pathObj, pathP);
+	}
+	env->DeleteLocalRef(pathObj);
+
+	return path;
+}
 
 // The following adds assets folder to search set.
 // However searching and retrieving from "assets" on Android this is slow
@@ -746,6 +771,7 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager,
 	FIND_METHOD(, getTouchMode, "()I");
 	FIND_METHOD(, getScummVMBasePath, "()Ljava/lang/String;");
 	FIND_METHOD(, getScummVMConfigPath, "()Ljava/lang/String;");
+	FIND_METHOD(, getScummVMLogPath, "()Ljava/lang/String;");
 	FIND_METHOD(, getSysArchives, "()[Ljava/lang/String;");
 	FIND_METHOD(, getAllStorageLocations, "()[Ljava/lang/String;");
 	FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;");
diff --git a/backends/platform/android/jni-android.h b/backends/platform/android/jni-android.h
index d0fbfb6ebe5..8073c838f03 100644
--- a/backends/platform/android/jni-android.h
+++ b/backends/platform/android/jni-android.h
@@ -90,6 +90,7 @@ public:
 	static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
 	static Common::String getScummVMBasePath();
 	static Common::String getScummVMConfigPath();
+	static Common::String getScummVMLogPath();
 	static jint getAndroidSDKVersionId();
 
 	static inline bool haveSurface();
@@ -149,6 +150,7 @@ private:
 	static jmethodID _MID_getTouchMode;
 	static jmethodID _MID_getScummVMBasePath;
 	static jmethodID _MID_getScummVMConfigPath;
+	static jmethodID _MID_getScummVMLogPath;
 	static jmethodID _MID_getSysArchives;
 	static jmethodID _MID_getAllStorageLocations;
 	static jmethodID _MID_initSurface;
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
index e6368b77ae2..d166fd7ba22 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
@@ -80,6 +80,7 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
 	abstract protected int getTouchMode();
 	abstract protected String getScummVMBasePath();
 	abstract protected String getScummVMConfigPath();
+	abstract protected String getScummVMLogPath();
 	abstract protected String[] getSysArchives();
 	abstract protected String[] getAllStorageLocations();
 	abstract protected String[] getAllStorageLocationsNoPermissionRequest();
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
index a8bd33e7aac..f3c9e5c84ac 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
@@ -77,6 +77,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
 
 	private Version _currentScummVMVersion;
 	private File _configScummvmFile;
+	private File _logScummvmFile;
 	private File _actualScummVMDataDir;
 	private File _possibleExternalScummVMDir;
 	boolean _externalPathAvailableForReadAccess;
@@ -793,6 +794,13 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
 			return _configScummvmFile.getPath();
 		}
 
+		@Override
+		protected String getScummVMLogPath() {
+			if (_logScummvmFile != null) {
+				return _logScummvmFile.getPath();
+			} else return "";
+		}
+
 		@Override
 		protected String[] getSysArchives() {
 			Log.d(ScummVM.LOG_TAG, "Adding to Search Archive: " + _actualScummVMDataDir.getPath());
@@ -866,6 +874,8 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
 
 		super.onCreate(savedInstanceState);
 
+		setLogFile();
+
 		safSyncObject = new Object();
 
 		hideSystemUI();
@@ -1156,6 +1166,34 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
 //		}
 	}
 
+	private void setLogFile() {
+		// NOTE: our LOG file scummvm.log is created directly inside the ScummVM internal app path
+		_logScummvmFile = new File(getFilesDir(), "scummvm.log");
+		try {
+			if (_logScummvmFile.exists() || !_logScummvmFile.createNewFile()) {
+				Log.d(ScummVM.LOG_TAG, "ScummVM Log file already exists!");
+				Log.d(ScummVM.LOG_TAG, "Existing ScummVM Log: " + _logScummvmFile.getPath());
+			} else {
+				Log.d(ScummVM.LOG_TAG, "An empty ScummVM log file was created!");
+				Log.d(ScummVM.LOG_TAG, "New ScummVM log: " + _logScummvmFile.getPath());
+			}
+		} catch(Exception e) {
+			e.printStackTrace();
+			new AlertDialog.Builder(this)
+				.setTitle(R.string.no_log_file_title)
+				.setIcon(android.R.drawable.ic_dialog_alert)
+				.setMessage(R.string.no_log_file)
+				.setNegativeButton(R.string.quit,
+					new DialogInterface.OnClickListener() {
+						public void onClick(DialogInterface dialog, int which) {
+							finish();
+						}
+					})
+				.show();
+			return;
+		}
+	}
+
 	// TODO setSystemUiVisibility is introduced in API 11 and deprecated in API 30 - When we move to API 30 we will have to replace this code
 	//	https://developer.android.com/training/system-ui/immersive.html#java
 	//
@@ -1897,7 +1935,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
 	}
 
 	// clear up any possibly deprecated assets (when upgrading to a new version)
-	// Don't remove the scummvm.ini file!
+	// Don't remove the scummvm.ini nor the scummvm.log file!
 	// Remove any files not in the filesItenary, even in a sideUpgrade
 	// Remove any files in the filesItenary only if not a sideUpgrade
 	private void internalAppFolderCleanup(String[] filesItenary, boolean sideUpgrade) {
@@ -1908,6 +1946,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
 				for (File extfile : extfiles) {
 					if (extfile.isFile()) {
 						if (extfile.getName().compareToIgnoreCase("scummvm.ini") != 0
+							&& extfile.getName().compareToIgnoreCase("scummvm.log") != 0
 							&& (!containsStringEntry(filesItenary, extfile.getName())
 							|| !sideUpgrade)
 						) {
diff --git a/dists/android/res/values/strings.xml b/dists/android/res/values/strings.xml
index b0e642f1aea..c4e951c0dee 100644
--- a/dists/android/res/values/strings.xml
+++ b/dists/android/res/values/strings.xml
@@ -19,8 +19,8 @@
 	<!-- <string name="no_external_files_dir_access">Unable to access external storage
 		to retrieve ScummVM config info! Please grant storage access permissions to
 		the ScummVM app, in order to function properly!</string> -->
-	<!-- <string name="no_log_file_title">Log File Error</string> -->
-	<!-- <string name="no_log_file">Unable to read ScummVM log file or create a new one!</string> -->
+	<string name="no_log_file_title">Log File Error</string>
+	<string name="no_log_file">Unable to read ScummVM log file or create a new one!</string>
 	<string name="no_config_file_title">Config File Error</string>
 	<string name="no_config_file">Unable to read ScummVM config file or create a new one!</string>
 	<string name="no_save_path_title">Save Path Error</string>


Commit: 767f70d595d6a1bd28b56faf6d9eb4ed71a2be23
    https://github.com/scummvm/scummvm/commit/767f70d595d6a1bd28b56faf6d9eb4ed71a2be23
Author: Antoniou Athanasios (a.antoniou79 at gmail.com)
Date: 2023-03-26T13:49:24+03:00

Commit Message:
ANDROID: Clean up log code and use Backends::Log

Changed paths:
    backends/graphics/android/android-graphics.cpp
    backends/graphics3d/android/android-graphics3d.cpp
    backends/graphics3d/android/texture.cpp
    backends/platform/android/android.cpp
    backends/platform/android/android.h
    backends/platform/android/events.cpp
    backends/platform/android/jni-android.cpp
    backends/platform/android/options.cpp


diff --git a/backends/graphics/android/android-graphics.cpp b/backends/graphics/android/android-graphics.cpp
index 06e85eba9b2..ebdf4f3b858 100644
--- a/backends/graphics/android/android-graphics.cpp
+++ b/backends/graphics/android/android-graphics.cpp
@@ -36,13 +36,12 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
-#include "graphics/blit.h"
-
-#include "backends/graphics/opengl/pipelines/pipeline.h"
-
-#include "backends/graphics/android/android-graphics.h"
 #include "backends/platform/android/android.h"
 #include "backends/platform/android/jni-android.h"
+#include "backends/graphics/android/android-graphics.h"
+#include "backends/graphics/opengl/pipelines/pipeline.h"
+
+#include "graphics/blit.h"
 
 static void loadBuiltinTexture(JNI::BitmapResources resource, OpenGL::Surface *surf) {
 	const Graphics::Surface *src = JNI::getBitmapResource(resource);
diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 89c2b26cd8e..73e496253d2 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -36,14 +36,15 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+
 #include "common/tokenizer.h"
 #include "graphics/blit.h"
 #include "graphics/opengl/shader.h"
 #include "graphics/opengl/context.h"
 
 #include "backends/graphics3d/android/android-graphics3d.h"
-#include "backends/platform/android/android.h"
-#include "backends/platform/android/jni-android.h"
 
 // These helper macros let us setup our context only when the game has different settings than us
 #define CONTEXT_SAVE_STATE(gl_param) GLboolean saved ## gl_param; GLCALL(saved ## gl_param = glIsEnabled(gl_param))
diff --git a/backends/graphics3d/android/texture.cpp b/backends/graphics3d/android/texture.cpp
index 36782d8e0b3..7ae71ac930e 100644
--- a/backends/graphics3d/android/texture.cpp
+++ b/backends/graphics3d/android/texture.cpp
@@ -36,6 +36,9 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+
 #include "base/main.h"
 #include "graphics/surface.h"
 #include "graphics/opengl/shader.h"
@@ -45,8 +48,6 @@
 #include "common/array.h"
 #include "common/util.h"
 
-#include "backends/platform/android/android.h"
-#include "backends/platform/android/jni-android.h"
 #include "backends/graphics3d/android/texture.h"
 
 // Supported GL extensions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index c16543d4489..ffb4725322c 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -43,10 +43,10 @@
 #define FORBIDDEN_SYMBOL_EXCEPTION_FILE
 #define FORBIDDEN_SYMBOL_EXCEPTION_fopen
 #define FORBIDDEN_SYMBOL_EXCEPTION_fclose
-#define FORBIDDEN_SYMBOL_EXCEPTION_fputs
-#define FORBIDDEN_SYMBOL_EXCEPTION_fwrite
+//#define FORBIDDEN_SYMBOL_EXCEPTION_fputs
+//#define FORBIDDEN_SYMBOL_EXCEPTION_fwrite
 #define FORBIDDEN_SYMBOL_EXCEPTION_ftell
-#define FORBIDDEN_SYMBOL_EXCEPTION_fflush
+//#define FORBIDDEN_SYMBOL_EXCEPTION_fflush
 
 #include <EGL/egl.h>
 #include <sys/time.h>
@@ -56,14 +56,14 @@
 #include <unistd.h>
 #include <dlfcn.h>
 
-#include "common/util.h"
-#include "common/textconsole.h"
-#include "common/rect.h"
-#include "common/queue.h"
-#include "common/mutex.h"
-#include "common/events.h"
-#include "common/config-manager.h"
-#include "graphics/cursorman.h"
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+#include "backends/fs/android/android-fs.h"
+#include "backends/fs/android/android-fs-factory.h"
+#include "backends/fs/posix/posix-iostream.h"
+
+#include "backends/graphics/android/android-graphics.h"
+#include "backends/graphics3d/android/android-graphics3d.h"
 
 #include "backends/audiocd/default/default-audiocd.h"
 #include "backends/events/default/default-events.h"
@@ -75,12 +75,14 @@
 #include "backends/keymapper/keymapper-defaults.h"
 #include "backends/keymapper/standard-actions.h"
 
-#include "backends/graphics/android/android-graphics.h"
-#include "backends/graphics3d/android/android-graphics3d.h"
-#include "backends/platform/android/jni-android.h"
-#include "backends/platform/android/android.h"
-#include "backends/fs/android/android-fs.h"
-#include "backends/fs/android/android-fs-factory.h"
+#include "common/util.h"
+#include "common/textconsole.h"
+#include "common/rect.h"
+#include "common/queue.h"
+#include "common/mutex.h"
+#include "common/events.h"
+#include "common/config-manager.h"
+#include "graphics/cursorman.h"
 
 const char *android_log_tag = "ScummVM";
 
@@ -190,23 +192,29 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
 	_trackball_scale(2),
 	_joystick_scale(10),
 	_defaultConfigFileName(""),
-	_defaultLogFileName("") {
-//	_scvmLogFilePtr(nullptr) {
-
-	LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s",
-			getSystemProperty("ro.product.manufacturer").c_str(),
-			getSystemProperty("ro.product.model").c_str(),
-			getSystemProperty("ro.product.brand").c_str(),
-			getSystemProperty("ro.build.fingerprint").c_str(),
-			getSystemProperty("ro.build.display.id").c_str(),
-			getSystemProperty("ro.build.version.sdk").c_str(),
-			getSystemProperty("ro.product.cpu.abi").c_str());
+	_defaultLogFileName(""),
+	_systemPropertiesSummaryStr(""),
+	_systemSDKdetectedStr(""),
+	_logger(nullptr) {
+
+	_systemPropertiesSummaryStr = Common::String::format("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s\n",
+	                                                   getSystemProperty("ro.product.manufacturer").c_str(),
+	                                                   getSystemProperty("ro.product.model").c_str(),
+	                                                   getSystemProperty("ro.product.brand").c_str(),
+	                                                   getSystemProperty("ro.build.fingerprint").c_str(),
+	                                                   getSystemProperty("ro.build.display.id").c_str(),
+	                                                   getSystemProperty("ro.build.version.sdk").c_str(),
+	                                                   getSystemProperty("ro.product.cpu.abi").c_str()) ;
+
+	LOGI("%s", _systemPropertiesSummaryStr.c_str());
 	// JNI::getAndroidSDKVersionId() should be identical to the result from ("ro.build.version.sdk"),
 	// though getting it via JNI is maybe the most reliable option (?)
 	// Also __system_property_get which is used by getSystemProperty() is being deprecated in recent NDKs
 
 	int sdkVersion = JNI::getAndroidSDKVersionId();
-	LOGI("SDK Version: %d", sdkVersion);
+
+	_systemSDKdetectedStr = Common::String::format("SDK Version: %d\n", sdkVersion) ;
+	LOGI("%s", _systemSDKdetectedStr.c_str());
 
 	AndroidFilesystemFactory &fsFactory = AndroidFilesystemFactory::instance();
 	if (sdkVersion >= 24) {
@@ -244,11 +252,8 @@ OSystem_Android::~OSystem_Android() {
 	// Uninitialize surface now to avoid it to be done later when touch controls are destroyed
 	dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->deinitSurface();
 
-//	// close log file
-//	if (_scvmLogFilePtr != nullptr) {
-//		fflush(_scvmLogFilePtr);
-//		fclose(_scvmLogFilePtr);
-//	}
+	delete _logger;
+	_logger = nullptr;
 }
 
 void *OSystem_Android::timerThreadFunc(void *arg) {
@@ -422,18 +427,25 @@ void OSystem_Android::initBackend() {
 
 	_main_thread = pthread_self();
 
-//	// Open log file
-//	if (!getDefaultLogFileName().empty()) {
-//		_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
-//		if (_scvmLogFilePtr != nullptr) {
-//			LOGD("Opened log file for writing upon initializing backend");
-//		} else {
-//			LOGE("Error when opening log file for writing upon initializing backend");
-//		}
-//	} else {
-//		LOGE("Error: log file path not known yet, upon initializing backend");
-//	}
+	if (!_logger)
+		_logger = new Backends::Log::Log(this);
+
+	if (_logger) {
+		Common::WriteStream *logFile = createLogFileForAppending();
+		if (logFile) {
+			_logger->open(logFile);
 
+			if (!_systemPropertiesSummaryStr.empty())
+				_logger->print(_systemPropertiesSummaryStr.c_str());
+
+			if (!_systemSDKdetectedStr.empty())
+				_logger->print(_systemSDKdetectedStr.c_str());
+		} else {
+			LOGE("Error when opening log file for writing upon initializing backend");
+			//_logger->close();
+			_logger = nullptr;
+		}
+	}
 
 	// Warning: ConfMan.registerDefault() can be used for a Session of ScummVM
 	//          but:
@@ -575,6 +587,37 @@ Common::String OSystem_Android::getDefaultLogFileName() {
 	return _defaultLogFileName;
 }
 
+Common::WriteStream *OSystem_Android::createLogFileForAppending() {
+	if (getDefaultLogFileName().empty()) {
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known upon create attempt!");
+		return nullptr;
+	}
+
+	FILE *scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
+	if (scvmLogFilePtr != nullptr) {
+		long sz = ftell(scvmLogFilePtr);
+		if (sz > MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
+			fclose(scvmLogFilePtr);
+			__android_log_write(ANDROID_LOG_WARN, android_log_tag, "Default log file is bigger than 100KB. It will be overwritten!");
+			if (!getDefaultLogFileName().empty()) {
+				// Create the log file from scratch overwriting the previous one
+				scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "w");
+				if (scvmLogFilePtr == nullptr) {
+					__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for rewrite!");
+					return nullptr;
+				}
+			} else {
+				__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known upon rewrite attempt!");
+				return nullptr;
+			}
+		}
+	} else {
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for writing/appending.");
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, getDefaultLogFileName().c_str());
+	}
+	return new PosixIoStream(scvmLogFilePtr);
+}
+
 bool OSystem_Android::hasFeature(Feature f) {
 	if (f == kFeatureFullscreenMode)
 		return false;
@@ -770,41 +813,10 @@ void OSystem_Android::logMessage(LogMessageType::Type type, const char *message)
 		break;
 	}
 
-	if (!getDefaultLogFileName().empty()) {
-		// open for append by default
-		FILE *_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
-
-		// TODO Do we need to worry about threading/synchronization here?
-		if (_scvmLogFilePtr != nullptr) {
-			long sz = ftell(_scvmLogFilePtr);
-			if (sz > MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
-				fclose(_scvmLogFilePtr);
-				__android_log_write(ANDROID_LOG_WARN, android_log_tag, "Default log file is bigger than 100KB. It will be overwritten!");
-				if (!getDefaultLogFileName().empty()) {
-					// Create the log file from scratch overwriting the previous one
-					_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "w");
-					if (_scvmLogFilePtr == nullptr) {
-						__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for rewrite!");
-						return;
-					}
-				} else {
-					__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known!");
-					return;
-				}
-			}
+	// Then log into file (via the logger)
+	if (_logger)
+		_logger->print(message);
 
-			fputs(message, _scvmLogFilePtr);
-			fwrite("\n", 1, 1, _scvmLogFilePtr);
-			// close log file
-			fflush(_scvmLogFilePtr);
-			fclose(_scvmLogFilePtr);
-		} else {
-			__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for writing/appending.");
-			__android_log_write(ANDROID_LOG_ERROR, android_log_tag, getDefaultLogFileName().c_str());
-		}
-	}   else {
-		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Error: log file path not known yet, upon initializing backend");
-	}
 }
 
 Common::String OSystem_Android::getSystemLanguage() const {
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 517681d51d6..3e3ad59fb3c 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -18,13 +18,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
-//#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
 
 #ifndef _ANDROID_H_
 #define _ANDROID_H_
 
 #if defined(__ANDROID__)
 
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+
 #include "backends/platform/android/portdefs.h"
 #include "common/fs.h"
 #include "common/archive.h"
@@ -34,7 +35,8 @@
 #include "backends/modular-backend.h"
 #include "backends/plugins/posix/posix-provider.h"
 #include "backends/fs/posix/posix-fs-factory.h"
-
+#include "backends/fs/posix/posix-fs-factory.h"
+#include "backends/log/log.h"
 #include "backends/platform/android/touchcontrols.h"
 
 #include <pthread.h>
@@ -110,46 +112,15 @@ private:
 
 	bool _timer_thread_exit;
 	pthread_t _timer_thread;
-	static void *timerThreadFunc(void *arg);
 
 	bool _audio_thread_exit;
 	pthread_t _audio_thread;
-	static void *audioThreadFunc(void *arg);
 
 	bool _virtkeybd_on;
 
 	Audio::MixerImpl *_mixer;
 	timeval _startTime;
 
-	Common::String getSystemProperty(const char *name) const;
-
-public:
-	enum {
-		TOUCH_MODE_TOUCHPAD = 0,
-		TOUCH_MODE_MOUSE = 1,
-		TOUCH_MODE_GAMEPAD = 2,
-		TOUCH_MODE_MAX = 3
-	};
-
-	OSystem_Android(int audio_sample_rate, int audio_buffer_size);
-	virtual ~OSystem_Android();
-
-	void initBackend() override;
-
-	bool hasFeature(OSystem::Feature f) override;
-	void setFeatureState(OSystem::Feature f, bool enable) override;
-	bool getFeatureState(OSystem::Feature f) override;
-
-public:
-	void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
-	void pushEvent(const Common::Event &event);
-	void pushEvent(const Common::Event &event1, const Common::Event &event2);
-
-	TouchControls &getTouchControls() { return _touchControls; }
-	void applyTouchSettings(bool _3dMode, bool overlayShown);
-	void setupTouchMode(int oldValue, int newValue);
-
-private:
 	Common::Queue<Common::Event> _event_queue;
 	Common::Event _queuedEvent;
 	uint32 _queuedEventTime;
@@ -172,14 +143,47 @@ private:
 
 	Common::String _defaultConfigFileName;
 	Common::String _defaultLogFileName;
+	Common::String _systemPropertiesSummaryStr;
+	Common::String _systemSDKdetectedStr;
 
-//	FILE *_scvmLogFilePtr;
+	Backends::Log::Log *_logger;
 
 #if defined(USE_OPENGL) && defined(USE_GLAD)
 	// Cached dlopen object
 	mutable void *_gles2DL;
 #endif
+
+	static void *timerThreadFunc(void *arg);
+	static void *audioThreadFunc(void *arg);
+	Common::String getSystemProperty(const char *name) const;
+
+	Common::WriteStream *createLogFileForAppending();
+
 public:
+	enum {
+		TOUCH_MODE_TOUCHPAD = 0,
+		TOUCH_MODE_MOUSE = 1,
+		TOUCH_MODE_GAMEPAD = 2,
+		TOUCH_MODE_MAX = 3
+	};
+
+	OSystem_Android(int audio_sample_rate, int audio_buffer_size);
+	virtual ~OSystem_Android();
+
+	void initBackend() override;
+
+	bool hasFeature(OSystem::Feature f) override;
+	void setFeatureState(OSystem::Feature f, bool enable) override;
+	bool getFeatureState(OSystem::Feature f) override;
+
+	void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
+	void pushEvent(const Common::Event &event);
+	void pushEvent(const Common::Event &event1, const Common::Event &event2);
+
+	TouchControls &getTouchControls() { return _touchControls; }
+	void applyTouchSettings(bool _3dMode, bool overlayShown);
+	void setupTouchMode(int oldValue, int newValue);
+
 	bool pollEvent(Common::Event &event) override;
 	Common::HardwareInputSet *getHardwareInputSet() override;
 	Common::KeymapArray getGlobalKeymaps() override;
@@ -224,6 +228,7 @@ public:
 #ifdef ANDROID_DEBUG_GL_CALLS
 	bool isRunningInMainThread() { return pthread_self() == _main_thread; }
 #endif
+
 };
 
 #endif
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index beab7fae4e9..9d3a64ead7d 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -40,8 +40,8 @@
 
 #include <android/input.h>
 
-#include "backends/graphics/android/android-graphics.h"
 #include "backends/platform/android/android.h"
+#include "backends/graphics/android/android-graphics.h"
 #include "backends/platform/android/jni-android.h"
 
 // floating point. use sparingly
diff --git a/backends/platform/android/jni-android.cpp b/backends/platform/android/jni-android.cpp
index 4d9567be215..b60da9ccde9 100644
--- a/backends/platform/android/jni-android.cpp
+++ b/backends/platform/android/jni-android.cpp
@@ -41,6 +41,10 @@
 
 #include <android/bitmap.h>
 
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+#include "backends/platform/android/asset-archive.h"
+
 #include "base/main.h"
 #include "base/version.h"
 #include "common/config-manager.h"
@@ -49,10 +53,6 @@
 #include "engines/engine.h"
 #include "graphics/surface.h"
 
-#include "backends/platform/android/android.h"
-#include "backends/platform/android/asset-archive.h"
-#include "backends/platform/android/jni-android.h"
-
 __attribute__ ((visibility("default")))
 jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
 	return JNI::onLoad(vm);
diff --git a/backends/platform/android/options.cpp b/backends/platform/android/options.cpp
index 75a03f77d4b..2258a84c0b4 100644
--- a/backends/platform/android/options.cpp
+++ b/backends/platform/android/options.cpp
@@ -36,10 +36,10 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
-#include "backends/fs/android/android-fs-factory.h"
-#include "backends/fs/android/android-saf-fs.h"
 #include "backends/platform/android/android.h"
 #include "backends/platform/android/jni-android.h"
+#include "backends/fs/android/android-fs-factory.h"
+#include "backends/fs/android/android-saf-fs.h"
 
 #include "gui/gui-manager.h"
 #include "gui/ThemeEval.h"




More information about the Scummvm-git-logs mailing list