| Index: testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReportingService.java
|
| diff --git a/testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReportingService.java b/testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReportingService.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..857dfc9af5ec03c5023af030b0233023f1ebafbe
|
| --- /dev/null
|
| +++ b/testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReportingService.java
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.test.outstrumentation.reporter;
|
| +
|
| +import android.app.Service;
|
| +import android.content.Intent;
|
| +import android.os.Handler;
|
| +import android.os.IBinder;
|
| +import android.os.Message;
|
| +import android.os.Messenger;
|
| +import android.os.RemoteException;
|
| +import android.util.Log;
|
| +
|
| +import java.util.HashSet;
|
| +import java.util.Set;
|
| +
|
| +/**
|
| + * A Service that allows instrumentation tests driven by
|
| + * {@link org.chromium.test.outstrumentation.master.Outstrumentation} to report results.
|
| + */
|
| +public class ReportingService extends Service {
|
| +
|
| + public static final String MSG_DATA_TEST_CLASS =
|
| + "org.chromium.test.reporter.MsgDataTestClass";
|
| + public static final String MSG_DATA_TEST_METHOD =
|
| + "org.chromium.test.reporter.MsgDataTestMethod";
|
| +
|
| + public static final int MSG_REGISTER_RECEIVER = 0;
|
| + public static final int MSG_UNREGISTER_RECEIVER = 1;
|
| + public static final int MSG_REPORT_TEST_STARTED = 2;
|
| + public static final int MSG_REPORT_TEST_PASSED = 3;
|
| + public static final int MSG_REPORT_TEST_FAILED = 4;
|
| +
|
| + private static final String TAG = "ReportingService";
|
| +
|
| + private final Set<Messenger> mReceivers = new HashSet<Messenger>();
|
| + private final Messenger mMessenger = new Messenger(new MessageHandler());
|
| +
|
| + private class MessageHandler extends Handler {
|
| + @Override
|
| + public void handleMessage(Message msg) {
|
| + switch (msg.what) {
|
| + case MSG_REGISTER_RECEIVER:
|
| + mReceivers.add(msg.replyTo);
|
| + break;
|
| + case MSG_UNREGISTER_RECEIVER:
|
| + mReceivers.remove(msg.replyTo);
|
| + break;
|
| + case MSG_REPORT_TEST_STARTED:
|
| + case MSG_REPORT_TEST_PASSED:
|
| + case MSG_REPORT_TEST_FAILED:
|
| + for (Messenger m : mReceivers) {
|
| + try {
|
| + m.send(msg);
|
| + } catch (RemoteException e) {
|
| + Log.e(TAG, "Error sending message to " + m.toString(), e);
|
| + }
|
| + }
|
| + break;
|
| + default:
|
| + super.handleMessage(msg);
|
| + break;
|
| + }
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public IBinder onBind(Intent intent) {
|
| + return mMessenger.getBinder();
|
| + }
|
| +
|
| +}
|
|
|