If an application calls System.exit() terminate it immediately.

There is no graceful way to kill Android application processes.
They typically have many threads running doing various things
When System.exit() is called, those threads just keep going
while the cleanup actions run until the process finally.

Performing shutdown actions can easily cause more harm than good.
For example, closing the Binder driver's file descriptor may
cause other threads waiting on Binder to wake up and then crash
in nasty ways after receiving EBADF.

So when an Android application exits, skip the cleanup and just
call _exit() to end it all.

Bug: 6168809
Change-Id: I29790c064426a0bf7dae7cdf444eea3eef1d5275
diff --git a/include/android_runtime/AndroidRuntime.h b/include/android_runtime/AndroidRuntime.h
index fd33d59..0b3ce9a 100644
--- a/include/android_runtime/AndroidRuntime.h
+++ b/include/android_runtime/AndroidRuntime.h
@@ -66,6 +66,12 @@
 
     void start(const char *classname, const char* options);
 
+    void exit(int code);
+
+    void setExitWithoutCleanup(bool exitWithoutCleanup) {
+        mExitWithoutCleanup = exitWithoutCleanup;
+    }
+
     static AndroidRuntime* getRuntime();
 
     /**
@@ -86,14 +92,13 @@
      * fork. Override it to initialize threads, etc. Upon return, the
      * correct static main will be invoked.
      */
-    virtual void onZygoteInit() {};
-
+    virtual void onZygoteInit() { }
 
     /**
-     * Called when the Java application exits.  The default
-     * implementation calls exit(code).
+     * Called when the Java application exits to perform additional cleanup actions
+     * before the process is terminated.
      */
-    virtual void onExit(int code);
+    virtual void onExit(int code) { }
 
     /** create a new thread that is visible from Java */
     static android_thread_id_t createJavaThread(const char* name, void (*start)(void *),
@@ -114,6 +119,7 @@
     int startVm(JavaVM** pJavaVM, JNIEnv** pEnv);
 
     Vector<JavaVMOption> mOptions;
+    bool mExitWithoutCleanup;
 
     /* JNI JavaVM pointer */
     static JavaVM* mJavaVM;