bug 595171 - crashreporter glue for Android. r=blassey a=blocking-fennec
authorTed Mielczarek <ted.mielczarek@gmail.com>
Wed, 13 Oct 2010 14:27:44 -0400
changeset 56279 1f000e6c5237dffab00563f64ea75456af6cbb5a
parent 56278 ca8226c47fea226ec94cb5755a537c505bebc0d0
child 56280 13dc6bfc5e7a578984cdbecdbe2e8253326a3525
push idunknown
push userunknown
push dateunknown
reviewersblassey, blocking-fennec
bugs595171
milestone2.0b8pre
bug 595171 - crashreporter glue for Android. r=blassey a=blocking-fennec
Makefile.in
configure.in
toolkit/crashreporter/Makefile.in
toolkit/crashreporter/client/Makefile.in
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/Makefile.in
+++ b/Makefile.in
@@ -167,17 +167,17 @@ SYM_STORE_SOURCE_DIRS := $(topsrcdir)
 
 include $(topsrcdir)/toolkit/mozapps/installer/package-name.mk
 
 ifdef MOZ_SYMBOLS_EXTRA_BUILDID
 EXTRA_BUILDID := -$(MOZ_SYMBOLS_EXTRA_BUILDID)
 endif
 
 SYMBOL_INDEX_NAME = \
-  $(MOZ_APP_NAME)-$(MOZ_APP_VERSION)-$(OS_ARCH)-$(BUILDID)$(EXTRA_BUILDID)-symbols.txt
+  $(MOZ_APP_NAME)-$(MOZ_APP_VERSION)-$(OS_TARGET)-$(BUILDID)$(EXTRA_BUILDID)-symbols.txt
 
 buildsymbols:
 ifdef MOZ_CRASHREPORTER
 	echo building symbol store
 	$(RM) -rf $(DIST)/crashreporter-symbols
 	$(RM) -f "$(DIST)/$(SYMBOL_ARCHIVE_BASENAME).zip"
 	$(NSINSTALL) -D $(DIST)/crashreporter-symbols
 	$(PYTHON) $(topsrcdir)/toolkit/crashreporter/tools/symbolstore.py \
--- a/configure.in
+++ b/configure.in
@@ -6274,17 +6274,17 @@ esac
 MOZ_ARG_DISABLE_BOOL(crashreporter,
 [  --disable-crashreporter Disable breakpad crash reporting],
     MOZ_CRASHREPORTER=,
     MOZ_CRASHREPORTER=1)
 
 if test -n "$MOZ_CRASHREPORTER"; then
    AC_DEFINE(MOZ_CRASHREPORTER)
 
-  if (test "$OS_ARCH" = "Linux" -o "$OS_ARCH" = "SunOS") && \
+  if (test "$OS_TARGET" = "Linux" -o "$OS_ARCH" = "SunOS") && \
     test -z "$SKIP_LIBRARY_CHECKS"; then
     PKG_CHECK_MODULES(MOZ_GTHREAD, gthread-2.0)
     AC_SUBST(MOZ_GTHREAD_CFLAGS)
     AC_SUBST(MOZ_GTHREAD_LIBS)
 
     AC_CHECK_HEADERS([curl/curl.h], [], [AC_MSG_ERROR([Couldn't find curl/curl.h which is required for the crash reporter.  Use --disable-crashreporter to disable the crash reporter.])])
   fi
 fi
--- a/toolkit/crashreporter/Makefile.in
+++ b/toolkit/crashreporter/Makefile.in
@@ -63,18 +63,23 @@ DIRS += \
   google-breakpad/src/client \
   google-breakpad/src/client/mac/crash_generation \
   google-breakpad/src/client/mac/handler \
   google-breakpad/src/tools/mac/dump_syms \
   $(NULL)
 endif
 
 ifeq ($(OS_ARCH),Linux)
-# there's no define for this normally
-DEFINES += -DXP_LINUX
+# There's no define for XP_LINUX normally.
+# MOZ_APP_NAME is needed on Android, where we
+# need to launch by package name.
+DEFINES += \
+  -DXP_LINUX \
+  -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\" \
+  $(NULL)
 DIRS += \
   google-breakpad/src/common \
   google-breakpad/src/common/linux \
   google-breakpad/src/client \
   google-breakpad/src/client/linux/crash_generation \
   google-breakpad/src/client/linux/handler \
   google-breakpad/src/client/linux/minidump_writer \
   google-breakpad/src/tools/linux/dump_syms \
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -46,18 +46,20 @@ relativesrcdir = toolkit/crashreporter/c
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = crashreporter
 
 # Don't use the STL wrappers in the crashreporter clients; they don't
 # link with -lmozalloc, and it really doesn't matter here anyway.
 STL_FLAGS =
 
+ifneq ($(OS_TARGET),Android)
 PROGRAM = crashreporter$(BIN_SUFFIX)
 DIST_PROGRAM = crashreporter$(BIN_SUFFIX)
+endif
 
 LOCAL_INCLUDES = -I$(srcdir)/../google-breakpad/src
 
 CPPSRCS = crashreporter.cpp
 
 ifeq ($(OS_ARCH),WINNT)
 CPPSRCS += crashreporter_win.cpp
 LIBS += \
@@ -78,17 +80,17 @@ OS_LIBS += -framework Cocoa
 LIBS += \
   $(DEPTH)/toolkit/crashreporter/google-breakpad/src/client/mac/handler/$(LIB_PREFIX)exception_handler_s.$(LIB_SUFFIX) \
   $(DEPTH)/toolkit/crashreporter/google-breakpad/src/common/mac/$(LIB_PREFIX)breakpad_mac_common_s.$(LIB_SUFFIX) \
   $(NULL)
 
 LOCAL_INCLUDES += -I$(srcdir) -I$(srcdir)/../google-breakpad/src/common/mac/
 endif
 
-ifeq ($(OS_ARCH),Linux)
+ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 CPPSRCS += crashreporter_gtk_common.cpp crashreporter_unix_common.cpp
 
 ifdef MOZ_PLATFORM_MAEMO
 CPPSRCS += crashreporter_maemo_gtk.cpp
 
 # Maemo's libcurl doesn't ship with a set of CA certificates,
 # so we have to ship our own.
 libs:: $(DIST)/bin/crashreporter.crt
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -455,21 +455,32 @@ bool MinidumpCallback(const XP_CHAR* dum
     return false;
 
 #else // !XP_MACOSX
   pid_t pid = sys_fork();
 
   if (pid == -1)
     return false;
   else if (pid == 0) {
+#if !defined(__ANDROID__)
     // need to clobber this, as libcurl might load NSS,
     // and we want it to load the system NSS.
     unsetenv("LD_LIBRARY_PATH");
     (void) execl(crashReporterPath,
                  crashReporterPath, minidumpPath, (char*)0);
+#else
+    // Invoke the reportCrash activity using am
+    (void) execlp("/system/bin/am",
+                 "/system/bin/am",
+                 "start",
+                 "-a", "org.mozilla.gecko.reportCrash",
+                 "-n", crashReporterPath,
+                 "--es", "minidumpPath", minidumpPath,
+                 (char*)0);
+#endif
     _exit(1);
   }
 #endif // XP_MACOSX
 #endif // XP_UNIX
 
  return returnValue;
 }
 
@@ -552,21 +563,28 @@ nsresult SetExceptionHandler(nsILocalFil
 
   exePath->AppendNative(NS_LITERAL_CSTRING(CRASH_REPORTER_FILENAME));
 
 #ifdef XP_WIN32
   nsString crashReporterPath_temp;
   exePath->GetPath(crashReporterPath_temp);
 
   crashReporterPath = ToNewUnicode(crashReporterPath_temp);
-#else
+#elif !defined(__ANDROID__)
   nsCString crashReporterPath_temp;
   exePath->GetNativePath(crashReporterPath_temp);
 
   crashReporterPath = ToNewCString(crashReporterPath_temp);
+#else
+  // On Android, we launch using the application package name
+  // instead of a filename, so use MOZ_APP_NAME to do that here.
+  //TODO: don't hardcode org.mozilla here, so other vendors can
+  // ship XUL apps with different package names on Android?
+  nsCString package("org.mozilla." MOZ_APP_NAME "/.CrashReporter");
+  crashReporterPath = ToNewCString(package);
 #endif
 
   // get temp path to use for minidump path
 #if defined(XP_WIN32)
   nsString tempPath;
 
   // first figure out buffer size
   int pathLen = GetTempPath(0, NULL);
@@ -585,16 +603,23 @@ nsresult SetExceptionHandler(nsILocalFil
 
   char path[PATH_MAX];
   OSStatus status = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX);
   if (status != noErr)
     return NS_ERROR_FAILURE;
 
   tempPath = path;
 
+#elif defined(__ANDROID__)
+  // GeckoAppShell sets this in the environment
+  const char *tempenv = PR_GetEnv("TMPDIR");
+  if (!tempenv)
+    return NS_ERROR_FAILURE;
+  nsCString tempPath(tempenv);
+
 #elif defined(XP_UNIX)
   // we assume it's always /tmp on unix systems
   nsCString tempPath = NS_LITERAL_CSTRING("/tmp/");
 #else
 #error "Implement this for your platform"
 #endif
 
 #ifdef XP_MACOSX