diff --git a/dtool/src/prc/androidLogStream.cxx b/dtool/src/prc/androidLogStream.cxx index b5512f9f52..6427b9163a 100644 --- a/dtool/src/prc/androidLogStream.cxx +++ b/dtool/src/prc/androidLogStream.cxx @@ -92,6 +92,7 @@ overflow(int ch) { */ void AndroidLogStream::AndroidLogStreamBuf:: write_char(char c) { + nout.put(c); if (c == '\n') { // Write a line to the log file. __android_log_write(_priority, _tag.c_str(), _data.c_str()); diff --git a/dtool/src/prc/notify.cxx b/dtool/src/prc/notify.cxx index f97b7d78ac..f74f55e596 100644 --- a/dtool/src/prc/notify.cxx +++ b/dtool/src/prc/notify.cxx @@ -335,9 +335,8 @@ assert_failure(const char *expression, int line, #ifdef ANDROID __android_log_assert("assert", "Panda3D", "Assertion failed: %s", message.c_str()); -#else - nout << "Assertion failed: " << message << "\n"; #endif + nout << "Assertion failed: " << message << "\n"; // This is redefined here, shadowing the defining in config_prc.h, so we can // guarantee it has already been constructed. diff --git a/dtool/src/prc/notifyCategory.cxx b/dtool/src/prc/notifyCategory.cxx index a6e0a0181c..432dfca159 100644 --- a/dtool/src/prc/notifyCategory.cxx +++ b/dtool/src/prc/notifyCategory.cxx @@ -64,7 +64,11 @@ out(NotifySeverity severity, bool prefix) const { // logging system. We use a special type of stream that redirects it to // Android's log system. if (prefix) { - return AndroidLogStream::out(severity) << *this << ": "; + if (severity == NS_info) { + return AndroidLogStream::out(severity) << *this << ": "; + } else { + return AndroidLogStream::out(severity) << *this << "(" << severity << "): "; + } } else { return AndroidLogStream::out(severity); } diff --git a/panda/src/android/PandaActivity.java b/panda/src/android/PandaActivity.java index 91e6c38533..c9985986f6 100644 --- a/panda/src/android/PandaActivity.java +++ b/panda/src/android/PandaActivity.java @@ -61,6 +61,11 @@ public class PandaActivity extends NativeActivity { return path; } + public String getIntentOutputPath() { + Intent intent = getIntent(); + return intent.getStringExtra("org.panda3d.OUTPUT_PATH"); + } + public String getCacheDirString() { return getCacheDir().toString(); } diff --git a/panda/src/android/android_main.cxx b/panda/src/android/android_main.cxx index c19ba7d58b..05a98b768c 100644 --- a/panda/src/android/android_main.cxx +++ b/panda/src/android/android_main.cxx @@ -158,6 +158,28 @@ void android_main(struct android_app* app) { } } + // Were we given an optional location to write the stdout/stderr streams? + methodID = env->GetMethodID(activity_class, "getIntentOutputPath", "()Ljava/lang/String;"); + jstring joutput_path = (jstring) env->CallObjectMethod(activity->clazz, methodID); + if (joutput_path != nullptr) { + const char *output_path = env->GetStringUTFChars(joutput_path, nullptr); + + if (output_path != nullptr && output_path[0] != 0) { + int fd = open(output_path, O_CREAT | O_TRUNC | O_WRONLY); + if (fd != -1) { + android_cat.info() + << "Writing standard output to file " << output_path << "\n"; + + dup2(fd, 1); + dup2(fd, 2); + } else { + android_cat.error() + << "Failed to open output path " << output_path << "\n"; + } + env->ReleaseStringUTFChars(joutput_path, output_path); + } + } + // Create bogus argc and argv for calling the main function. const char *argv[] = {"pview", nullptr, nullptr}; int argc = 1; diff --git a/panda/src/express/virtualFileMountAndroidAsset.cxx b/panda/src/express/virtualFileMountAndroidAsset.cxx index 3c85aaebb7..d7ffb6254a 100644 --- a/panda/src/express/virtualFileMountAndroidAsset.cxx +++ b/panda/src/express/virtualFileMountAndroidAsset.cxx @@ -78,7 +78,7 @@ is_regular_file(const Filename &file) const { AAsset* asset; asset = AAssetManager_open(_asset_mgr, file.c_str(), AASSET_MODE_UNKNOWN); - express_cat.error() << "is_regular_file " << file << " - " << asset << "\n"; + //express_cat.error() << "is_regular_file " << file << " - " << asset << "\n"; if (asset == NULL) { return false;