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

Commit 84daaf8b authored by Maksymilian Osowski's avatar Maksymilian Osowski Committed by Android (Google) Code Review
Browse files

Merge "Fixed and slightly improved crash detection mechanism."

parents 1770b872 bcf114c2
Loading
Loading
Loading
Loading
+28 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.Message;
import android.os.Messenger;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.PowerManager.WakeLock;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.util.Log;
@@ -44,6 +45,7 @@ import android.webkit.GeolocationPermissions;
import android.webkit.WebStorage.QuotaUpdater;
import android.webkit.WebStorage.QuotaUpdater;


import java.io.File;
import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
import java.net.MalformedURLException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URL;
import java.util.HashMap;
import java.util.HashMap;
@@ -256,6 +258,32 @@ public class LayoutTestsExecutor extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(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);
        requestWindowFeature(Window.FEATURE_PROGRESS);


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


    private static final String LOG_TAG = "ManagerService";
    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;
    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_PROCESS_ACTUAL_RESULTS = 0;
    static final int MSG_ALL_TESTS_FINISHED = 1;
    static final int MSG_ALL_TESTS_FINISHED = 1;
    static final int MSG_FIRST_TEST = 2;
    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
     * This handler is purely for IPC. It is used to create mMessenger
@@ -92,6 +93,11 @@ public class ManagerService extends Service {
                    onActualResultsObtained(msg.getData());
                    onActualResultsObtained(msg.getData());
                    break;
                    break;


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

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


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


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


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


    /**
    /**