aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Pfau <pfau@peakwork.de>2016-10-06 09:36:49 +0200
committerwsnipex <wsnipex@a1.net>2016-10-09 11:23:58 +0200
commit624f4032430e61821e63d7ed9f83624ea10f84b3 (patch)
tree778b39f3f4df70253230a549b09d77eb8b741b4a
parent88f02f22ff4eae428473e11d49d7728ad505978c (diff)
ADD: [droid] capture stderr/stdout to logcat / thanks to @koying
-rw-r--r--xbmc/platform/android/activity/android_main.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/xbmc/platform/android/activity/android_main.cpp b/xbmc/platform/android/activity/android_main.cpp
index 97451971b2..3b77b22f88 100644
--- a/xbmc/platform/android/activity/android_main.cpp
+++ b/xbmc/platform/android/activity/android_main.cpp
@@ -31,6 +31,48 @@
#include "platform/android/activity/JNIMainActivity.h"
+
+// redirect stdout / stderr to logcat
+// https://codelab.wordpress.com/2014/11/03/how-to-use-standard-output-streams-for-logging-in-android-apps/
+static int pfd[2];
+static pthread_t thr;
+static const char *tag = "myapp";
+
+static void *thread_logger(void*)
+{
+ ssize_t rdsz;
+ char buf[128];
+ while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0)
+ {
+ if(buf[rdsz - 1] == '\n')
+ --rdsz;
+ buf[rdsz] = 0; /* add null-terminator */
+ __android_log_write(ANDROID_LOG_DEBUG, tag, buf);
+ }
+ return 0;
+}
+
+int start_logger(const char *app_name)
+{
+ tag = app_name;
+
+ /* make stdout line-buffered and stderr unbuffered */
+ setvbuf(stdout, 0, _IOLBF, 0);
+ setvbuf(stderr, 0, _IONBF, 0);
+
+ /* create the pipe and redirect stdout and stderr */
+ pipe(pfd);
+ dup2(pfd[1], 1);
+ dup2(pfd[1], 2);
+
+ /* spawn the logging thread */
+ if(pthread_create(&thr, 0, thread_logger, 0) == -1)
+ return -1;
+ pthread_detach(thr);
+ return 0;
+}
+
+
// copied from new android_native_app_glue.c
static void process_input(struct android_app* app, struct android_poll_source* source) {
AInputEvent* event = NULL;
@@ -65,6 +107,8 @@ extern void android_main(struct android_app* state)
CXBMCApp xbmcApp(state->activity);
if (xbmcApp.isValid())
{
+ start_logger("Kodi");
+
IInputHandler inputHandler;
eventLoop.run(xbmcApp, inputHandler);
}