Bug 1343541 - restore signal actions changed by Android debugger. r?glandium draft
authorJohn Lin <jolin@mozilla.com>
Wed, 12 Apr 2017 17:34:17 +0800
changeset 564889 dd8f5041f0e3d583538a04c41099e61369153aba
parent 564706 3f9f6d6086b2d247831d1d03d530095bebd5a6b2
child 624858 ff7fe0540eb69605d0bf864d7edcc79bfe134262
push id54723
push userbmo:jolin@mozilla.com
push dateWed, 19 Apr 2017 05:35:37 +0000
reviewersglandium
bugs1343541
milestone55.0a1
Bug 1343541 - restore signal actions changed by Android debugger. r?glandium Android shows a dialog box when it detects app crashing. OOP decoder needs to hide that from user to resume playback gracefully. MozReview-Commit-ID: 3cE3GiHAuQk
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/MediaManager.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
mozglue/android/APKOpen.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/MediaManager.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/MediaManager.java
@@ -28,16 +28,17 @@ public final class MediaManager extends 
             return new RemoteMediaDrmBridgeStub(keySystem, stubId);
         }
     };
 
     @Override
     public synchronized void onCreate() {
         if (!sNativeLibLoaded) {
             GeckoLoader.doLoadLibrary(this, "mozglue");
+            GeckoLoader.suppressCrashDialog();
             sNativeLibLoaded = true;
         }
     }
 
     @Override
     public IBinder onBind(Intent intent) {
         return mBinder;
     }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
@@ -548,9 +548,10 @@ public final class GeckoLoader {
     private static native void putenv(String map);
 
     // These methods are implemented in mozglue/android/APKOpen.cpp
     public static native void nativeRun(String[] args, int crashFd, int ipcFd);
     private static native void loadGeckoLibsNative(String apkName);
     private static native void loadSQLiteLibsNative(String apkName);
     private static native void loadNSSLibsNative(String apkName);
     public static native boolean neonCompatible();
+    public static native void suppressCrashDialog();
 }
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * This custom library loading code is only meant to be called
- * during initialization. As a result, it takes no special 
+ * during initialization. As a result, it takes no special
  * precautions to be threadsafe. Any of the library loading functions
  * like mozload should not be available to other code.
  */
 
 #include <jni.h>
 #include <android/log.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -478,8 +478,49 @@ extern "C" APKOPEN_EXPORT jboolean MOZ_J
 Java_org_mozilla_gecko_mozglue_GeckoLoader_neonCompatible(JNIEnv *jenv, jclass jc)
 {
 #ifdef __ARM_EABI__
   return mozilla::supports_neon();
 #else
   return true;
 #endif // __ARM_EABI__
 }
+
+// Does current process name end with ':media'?
+static bool
+IsMediaProcess()
+{
+  pid_t pid = getpid();
+  char str[256];
+  snprintf(str, sizeof(str), "/proc/%d/cmdline", pid);
+  FILE* f = fopen(str, "r");
+  if (f) {
+    fgets(str, sizeof(str), f);
+    fclose(f);
+    const size_t strLen = strlen(str);
+    const char suffix[] = ":media";
+    const size_t suffixLen = sizeof(suffix) - 1;
+    if (strLen >= suffixLen &&
+        !strncmp(str + strLen - suffixLen, suffix, suffixLen)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+extern "C" APKOPEN_EXPORT void MOZ_JNICALL
+Java_org_mozilla_gecko_mozglue_GeckoLoader_suppressCrashDialog(JNIEnv *jenv, jclass jc)
+{
+  MOZ_RELEASE_ASSERT(IsMediaProcess(), "Suppress crash dialog only for media process");
+  // Restore all signal actions changed by Android debugger.
+  // See http://androidxref.com/7.1.1_r6/xref/bionic/linker/debugger.cpp#312
+  struct sigaction dfl = {};
+  dfl.sa_handler = SIG_DFL;
+  sigaction(SIGABRT, &dfl, nullptr);
+  sigaction(SIGBUS, &dfl, nullptr);
+  sigaction(SIGILL, &dfl, nullptr);
+  sigaction(SIGFPE, &dfl, nullptr);
+  sigaction(SIGSEGV, &dfl, nullptr);
+#if defined(SIGSTKFLT)
+  sigaction(SIGSTKFLT, &dfl, nullptr);
+#endif
+  sigaction(SIGTRAP, &dfl, nullptr);
+}
\ No newline at end of file