Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bcf114c2 authored by Maksymilian Osowski's avatar Maksymilian Osowski
Browse files

Fixed and slightly improved crash detection mechanism.

Before, if a crash was detected, but the "Force quit" dialog remained on the screen, sending the intent to restart the executor would do nothing. It's fixed now with default
uncaught exception handler. Also, when we catch the uncaught exception, we can restart the executor straight away, without waiting for the time-out.

Change-Id: I2f0b4b5f2abd180ff518f1a40ad1294bed2f7f67
parent 9c12bd39
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.PowerManager.WakeLock;
import android.util.Log;
@@ -44,6 +45,7 @@ import android.webkit.GeolocationPermissions;
import android.webkit.WebStorage.QuotaUpdater;

import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
@@ -256,6 +258,32 @@ public class LayoutTestsExecutor extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /**
         * It detects the crash by catching all the uncaught exceptions. However, we
         * still have to kill the process, because after catching the exception the
         * activity remains in a strange state, where intents don't revive it.
         * However, we send the message to the service to speed up the rebooting
         * (we don't have to wait for time-out to kick in).
         */
        Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable e) {
                Log.w(LOG_TAG,
                        "onTestCrashed(): " + mCurrentTestRelativePath + " thread=" + thread, e);

                try {
                    Message serviceMsg =
                            Message.obtain(null, ManagerService.MSG_CURRENT_TEST_CRASHED);

                    mManagerServiceMessenger.send(serviceMsg);
                } catch (RemoteException e2) {
                    Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e2);
                }

                Process.killProcess(Process.myPid());
            }
        });

        requestWindowFeature(Window.FEATURE_PROGRESS);

        Intent intent = getIntent();
+10 −4
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ public class ManagerService extends Service {

    private static final String LOG_TAG = "ManagerService";

    private static final int MSG_TEST_CRASHED = 0;
    private static final int MSG_CRASH_TIMEOUT_EXPIRED = 0;

    private static final int CRASH_TIMEOUT_MS = 20 * 1000;

@@ -72,6 +72,7 @@ public class ManagerService extends Service {
    static final int MSG_PROCESS_ACTUAL_RESULTS = 0;
    static final int MSG_ALL_TESTS_FINISHED = 1;
    static final int MSG_FIRST_TEST = 2;
    static final int MSG_CURRENT_TEST_CRASHED = 3;

    /**
     * This handler is purely for IPC. It is used to create mMessenger
@@ -92,6 +93,11 @@ public class ManagerService extends Service {
                    onActualResultsObtained(msg.getData());
                    break;

                case MSG_CURRENT_TEST_CRASHED:
                    mCrashMessagesHandler.removeMessages(MSG_CRASH_TIMEOUT_EXPIRED);
                    onTestCrashed();
                    break;

                case MSG_ALL_TESTS_FINISHED:
                    mSummarizer.setTestsRelativePath(mAllTestsRelativePath);
                    mSummarizer.summarize();
@@ -110,7 +116,7 @@ public class ManagerService extends Service {
    private Handler mCrashMessagesHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MSG_TEST_CRASHED) {
            if (msg.what == MSG_CRASH_TIMEOUT_EXPIRED) {
                onTestCrashed();
            }
        }
@@ -145,7 +151,7 @@ public class ManagerService extends Service {
    }

    private void onActualResultsObtained(Bundle bundle) {
        mCrashMessagesHandler.removeMessages(MSG_TEST_CRASHED);
        mCrashMessagesHandler.removeMessages(MSG_CRASH_TIMEOUT_EXPIRED);
        ensureNextTestSetup(bundle.getString("nextTest"), bundle.getInt("testIndex") + 1);

        AbstractResult results =
@@ -163,7 +169,7 @@ public class ManagerService extends Service {

        mCurrentlyRunningTest = nextTest;
        mCurrentlyRunningTestIndex = index;
        mCrashMessagesHandler.sendEmptyMessageDelayed(MSG_TEST_CRASHED, CRASH_TIMEOUT_MS);
        mCrashMessagesHandler.sendEmptyMessageDelayed(MSG_CRASH_TIMEOUT_EXPIRED, CRASH_TIMEOUT_MS);
    }

    /**