crash_dump: don't notify ActivityManager if it crashed.

Bug: http://b/38427757
Test: killall -ABRT system_server, plus added logging
Merged-In: Ic15e0b0870b1ec08a2f165ad0e5356afed02eece
Change-Id: Ic15e0b0870b1ec08a2f165ad0e5356afed02eece
(cherry picked from commit b0e51e388b8c952e28280f0e7035dc18fb9aa4e5)
diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp
index 1027f69..355cb22 100644
--- a/debuggerd/crash_dump.cpp
+++ b/debuggerd/crash_dump.cpp
@@ -41,6 +41,7 @@
 #include <android-base/unique_fd.h>
 #include <cutils/sockets.h>
 #include <log/log.h>
+#include <private/android_filesystem_config.h>
 #include <procinfo/process.h>
 #include <selinux/selinux.h>
 
@@ -100,8 +101,9 @@
   return true;
 }
 
-static bool activity_manager_notify(int pid, int signal, const std::string& amfd_data) {
-  android::base::unique_fd amfd(socket_local_client("/data/system/ndebugsocket", ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM));
+static bool activity_manager_notify(pid_t pid, int signal, const std::string& amfd_data) {
+  android::base::unique_fd amfd(socket_local_client(
+      "/data/system/ndebugsocket", ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM));
   if (amfd.get() == -1) {
     PLOG(ERROR) << "unable to connect to activity manager";
     return false;
@@ -408,7 +410,10 @@
   }
 
   if (fatal_signal) {
-    activity_manager_notify(target, signo, amfd_data);
+    // Don't try to notify ActivityManager if it just crashed, or we might hang until timeout.
+    if (target_info.name != "system_server" || target_info.uid != AID_SYSTEM) {
+      activity_manager_notify(target, signo, amfd_data);
+    }
   }
 
   // Close stdout before we notify tombstoned of completion.