android: change assets mount dir, point binary path to .apk

The binary path we get from /proc/self/exe isn't very useful; the path to the .apk is barely more useful but it still doesn't make a whole lot of sense.  It might make more sense to set it to the path of the native .so that is being loaded by NativeActivity.
This commit is contained in:
rdb 2018-01-29 19:38:46 +01:00
parent e301e5fe5e
commit 7c1dd4050b
3 changed files with 32 additions and 20 deletions

View File

@ -540,7 +540,6 @@ read_environment_variables() {
*/
void ExecutionEnvironment::
read_args() {
#ifndef ANDROID
// First, we need to fill in _dtool_name. This contains the full path to
// the p3dtool library.
@ -578,7 +577,7 @@ read_args() {
}
#endif
#if defined(IS_FREEBSD) || defined(IS_LINUX)
#if defined(IS_FREEBSD) || (defined(IS_LINUX) && !defined(__ANDROID__))
// FreeBSD and Linux have a function to get the origin of a loaded library.
char origin[PATH_MAX + 1];
@ -833,8 +832,6 @@ read_args() {
}
#endif // _WIN32
#endif // ANDROID
if (_dtool_name.empty()) {
_dtool_name = _binary_name;
}

View File

@ -2353,7 +2353,7 @@ def WriteConfigSettings():
dtool_config["HAVE_CGGL"] = '1'
dtool_config["HAVE_CGDX9"] = '1'
if (GetTarget() != "linux"):
if GetTarget() not in ("linux", "android"):
dtool_config["HAVE_PROC_SELF_EXE"] = 'UNDEF'
dtool_config["HAVE_PROC_SELF_MAPS"] = 'UNDEF'
dtool_config["HAVE_PROC_SELF_CMDLINE"] = 'UNDEF'

View File

@ -52,43 +52,58 @@ void android_main(struct android_app* app) {
// Fetch the path to the data directory.
jfieldID datadir_field = env->GetFieldID(appinfo_class, "dataDir", "Ljava/lang/String;");
jstring datadir = (jstring) env->GetObjectField(appinfo, datadir_field);
const char *data_path = env->GetStringUTFChars(datadir, NULL);
const char *data_path = env->GetStringUTFChars(datadir, nullptr);
Filename::_internal_data_dir = data_path;
android_cat.info() << "Path to data: " << data_path << "\n";
if (data_path != nullptr) {
Filename::_internal_data_dir = data_path;
android_cat.info() << "Path to data: " << data_path << "\n";
env->ReleaseStringUTFChars(datadir, data_path);
env->ReleaseStringUTFChars(datadir, data_path);
}
// Fetch the path to the library directory.
jfieldID libdir_field = env->GetFieldID(appinfo_class, "nativeLibraryDir", "Ljava/lang/String;");
jstring libdir = (jstring) env->GetObjectField(appinfo, libdir_field);
const char *lib_path = env->GetStringUTFChars(libdir, NULL);
if (ExecutionEnvironment::get_dtool_name().empty()) {
jfieldID libdir_field = env->GetFieldID(appinfo_class, "nativeLibraryDir", "Ljava/lang/String;");
jstring libdir = (jstring) env->GetObjectField(appinfo, libdir_field);
const char *lib_path = env->GetStringUTFChars(libdir, nullptr);
string dtool_name = string(lib_path) + "/libp3dtool.so";
ExecutionEnvironment::set_dtool_name(dtool_name);
android_cat.info() << "Path to dtool: " << dtool_name << "\n";
if (lib_path != nullptr) {
string dtool_name = string(lib_path) + "/libp3dtool.so";
ExecutionEnvironment::set_dtool_name(dtool_name);
android_cat.info() << "Path to dtool: " << dtool_name << "\n";
env->ReleaseStringUTFChars(libdir, lib_path);
env->ReleaseStringUTFChars(libdir, lib_path);
}
}
// Get the path to the APK.
jmethodID methodID = env->GetMethodID(activity_class, "getPackageCodePath", "()Ljava/lang/String;");
jstring code_path = (jstring) env->CallObjectMethod(activity->clazz, methodID);
const char* apk_path;
apk_path = env->GetStringUTFChars(code_path, NULL);
apk_path = env->GetStringUTFChars(code_path, nullptr);
// We're going to set this as binary name, which is better than the
// default (which refers to the zygote). Or should we set it to the
// native library? How do we get the path to that?
android_cat.info() << "Path to APK: " << apk_path << "\n";
ExecutionEnvironment::set_binary_name(apk_path);
// Mount the assets directory.
Filename apk_fn(apk_path);
PT(VirtualFileMountAndroidAsset) asset_mount;
asset_mount = new VirtualFileMountAndroidAsset(app->activity->assetManager, apk_path);
asset_mount = new VirtualFileMountAndroidAsset(app->activity->assetManager, apk_fn);
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->mount(asset_mount, "/android_asset", 0);
Filename asset_dir(apk_fn.get_dirname(), "assets");
vfs->mount(asset_mount, asset_dir, 0);
// Release the apk_path.
env->ReleaseStringUTFChars(code_path, apk_path);
// Now add the asset directory to the model-path.
get_model_path().append_directory("/android_asset");
//TODO: prevent it from adding the directory multiple times.
get_model_path().append_directory(asset_dir);
// Create bogus argc and argv, then call our main function.
char *argv[] = {NULL};