ANDROID: Simplify Android startup

Do not pass arguments to the process but customize the backend instead
This commit is contained in:
Le Philousophe 2023-02-28 20:49:01 +01:00 committed by Athanasios Antoniou
parent 85e3a22510
commit 8d83dac31e
6 changed files with 83 additions and 11 deletions

View file

@ -483,12 +483,14 @@ void OSystem_Android::initBackend() {
ConfMan.setInt("gui_scale", 125); // "Large" (see gui/options.cpp and guiBaseValues[])
}
_savefileManager = new AndroidSaveFileManager(ConfMan.get("path") + "/saves");
Common::String basePath = JNI::getScummVMBasePath();
_savefileManager = new AndroidSaveFileManager(basePath + "/saves");
// TODO remove the debug message eventually
LOGD("Setting DefaultSaveFileManager path to: %s", ConfMan.get("savepath").c_str());
ConfMan.registerDefault("iconspath", ConfMan.get("path") + "/icons");
ConfMan.registerDefault("iconspath", basePath + "/icons");
// TODO remove the debug message eventually
LOGD("Setting Default Icons and Shaders path to: %s", ConfMan.get("iconspath").c_str());
@ -524,6 +526,10 @@ void OSystem_Android::initBackend() {
BaseBackend::initBackend();
}
Common::String OSystem_Android::getDefaultConfigFileName() {
return JNI::getScummVMConfigPath();
}
bool OSystem_Android::hasFeature(Feature f) {
if (f == kFeatureFullscreenMode)
return false;

View file

@ -173,6 +173,8 @@ public:
Common::KeymapArray getGlobalKeymaps() override;
Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override;
Common::String getDefaultConfigFileName() 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;
void applyBackendSettings() override;

View file

@ -92,6 +92,8 @@ jmethodID JNI::_MID_showKeyboardControl = 0;
jmethodID JNI::_MID_getBitmapResource = 0;
jmethodID JNI::_MID_setTouchMode = 0;
jmethodID JNI::_MID_getTouchMode = 0;
jmethodID JNI::_MID_getScummVMBasePath;
jmethodID JNI::_MID_getScummVMConfigPath;
jmethodID JNI::_MID_getSysArchives = 0;
jmethodID JNI::_MID_getAllStorageLocations = 0;
jmethodID JNI::_MID_initSurface = 0;
@ -503,9 +505,60 @@ int JNI::getTouchMode() {
return mode;
}
Common::String JNI::getScummVMBasePath() {
JNIEnv *env = JNI::getEnv();
jstring pathObj = (jstring)env->CallObjectMethod(_jobj, _MID_getScummVMBasePath);
if (env->ExceptionCheck()) {
LOGE("Failed to get ScummVM base 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;
}
Common::String JNI::getScummVMConfigPath() {
JNIEnv *env = JNI::getEnv();
jstring pathObj = (jstring)env->CallObjectMethod(_jobj, _MID_getScummVMConfigPath);
if (env->ExceptionCheck()) {
LOGE("Failed to get ScummVM base 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
// so we also make sure to add the "path" directory, with a higher priority
// so we also make sure to add the base directory, with a higher priority
// This is done via a call to ScummVMActivity's (java) getSysArchives
void JNI::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
JNIEnv *env = JNI::getEnv();
@ -672,6 +725,8 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager,
FIND_METHOD(, getBitmapResource, "(I)Landroid/graphics/Bitmap;");
FIND_METHOD(, setTouchMode, "(I)V");
FIND_METHOD(, getTouchMode, "()I");
FIND_METHOD(, getScummVMBasePath, "()Ljava/lang/String;");
FIND_METHOD(, getScummVMConfigPath, "()Ljava/lang/String;");
FIND_METHOD(, getSysArchives, "()[Ljava/lang/String;");
FIND_METHOD(, getAllStorageLocations, "()[Ljava/lang/String;");
FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;");

View file

@ -88,6 +88,8 @@ public:
static void setTouchMode(int touchMode);
static int getTouchMode();
static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
static Common::String getScummVMBasePath();
static Common::String getScummVMConfigPath();
static jint getAndroidSDKVersionId();
static inline bool haveSurface();
@ -137,6 +139,8 @@ private:
static jmethodID _MID_getBitmapResource;
static jmethodID _MID_setTouchMode;
static jmethodID _MID_getTouchMode;
static jmethodID _MID_getScummVMBasePath;
static jmethodID _MID_getScummVMConfigPath;
static jmethodID _MID_getSysArchives;
static jmethodID _MID_getAllStorageLocations;
static jmethodID _MID_initSurface;

View file

@ -77,6 +77,8 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
abstract protected Bitmap getBitmapResource(int resource);
abstract protected void setTouchMode(int touchMode);
abstract protected int getTouchMode();
abstract protected String getScummVMBasePath();
abstract protected String getScummVMConfigPath();
abstract protected String[] getSysArchives();
abstract protected String[] getAllStorageLocations();
abstract protected String[] getAllStorageLocationsNoPermissionRequest();

View file

@ -778,6 +778,16 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
return _events.getTouchMode();
}
@Override
protected String getScummVMBasePath() {
return _actualScummVMDataDir.getPath();
}
@Override
protected String getScummVMConfigPath() {
return _configScummvmFile.getPath();
}
@Override
protected String[] getSysArchives() {
Log.d(ScummVM.LOG_TAG, "Adding to Search Archive: " + _actualScummVMDataDir.getPath());
@ -944,15 +954,8 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
// We should have a valid path to a configuration file here
// Start ScummVM
// Log.d(ScummVM.LOG_TAG, "CONFIG: " + _configScummvmFile.getPath());
// Log.d(ScummVM.LOG_TAG, "PATH: " + _actualScummVMDataDir.getPath());
// TODO log file setting via "--logfile=" + _usingLogFile.getPath() causes crash
// probably because this option is specific to SDL_BACKEND (see: base/commandLine.cpp)
_scummvm.setArgs(new String[]{
"ScummVM",
"--config=" + _configScummvmFile.getPath(),
"--path=" + _actualScummVMDataDir.getPath()
"ScummVM"
});
Log.d(ScummVM.LOG_TAG, "Hover available: " + _hoverAvailable);