[Scummvm-git-logs] scummvm master -> fb673553ce6c7143491f4512f7bba5ba0f493f08
antoniou79
noreply at scummvm.org
Sat Mar 25 21:23:20 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
fb673553ce ANDROID: Write to a scummvm.log file
Commit: fb673553ce6c7143491f4512f7bba5ba0f493f08
https://github.com/scummvm/scummvm/commit/fb673553ce6c7143491f4512f7bba5ba0f493f08
Author: Antoniou Athanasios (a.antoniou79 at gmail.com)
Date: 2023-03-25T23:23:12+02: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>
More information about the Scummvm-git-logs
mailing list