summaryrefslogtreecommitdiff
path: root/tests/testables/src
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2018-05-16 10:15:33 -0400
committerJason Monk <jmonk@google.com>2018-05-16 10:15:33 -0400
commit1e352f4c34534864306a79f20a1af9d73b7cbd5f (patch)
tree357c2149f6531aae760d8dea75019f5bb6d78d6d /tests/testables/src
parente5c8e375e1fb3ce2f9f2531a5926d4136186824d (diff)
Fix testable looper threading
In the case where an annotation was not used and the TestableLooper was manually created, then the messages would be executed on the wrong thread. Also switch some handlers over to async, might save us a little time. Test: runtest --path frameworks/base/tests/testables Bug: 79550837 Change-Id: I70a36449ae08eb5799e2dad41a5d258bb51a3fd3
Diffstat (limited to 'tests/testables/src')
-rw-r--r--tests/testables/src/android/testing/TestableInstrumentation.java2
-rw-r--r--tests/testables/src/android/testing/TestableLooper.java14
2 files changed, 8 insertions, 8 deletions
diff --git a/tests/testables/src/android/testing/TestableInstrumentation.java b/tests/testables/src/android/testing/TestableInstrumentation.java
index 93fed859cf39..3207b486b329 100644
--- a/tests/testables/src/android/testing/TestableInstrumentation.java
+++ b/tests/testables/src/android/testing/TestableInstrumentation.java
@@ -77,7 +77,7 @@ public class TestableInstrumentation extends AndroidJUnitRunner {
private TestLooperManager mManager;
public MainLooperManager() {
- mMainHandler = new Handler(Looper.getMainLooper());
+ mMainHandler = Handler.createAsync(Looper.getMainLooper());
startManaging();
}
diff --git a/tests/testables/src/android/testing/TestableLooper.java b/tests/testables/src/android/testing/TestableLooper.java
index f1a70921a469..f8d223ab91b6 100644
--- a/tests/testables/src/android/testing/TestableLooper.java
+++ b/tests/testables/src/android/testing/TestableLooper.java
@@ -51,12 +51,12 @@ public class TestableLooper {
this(acquireLooperManager(l), l);
}
- private TestableLooper(TestLooperManager wrapper, Looper l) throws Exception {
+ private TestableLooper(TestLooperManager wrapper, Looper l) {
mQueueWrapper = wrapper;
setupQueue(l);
}
- private TestableLooper(Looper looper, boolean b) throws Exception {
+ private TestableLooper(Looper looper, boolean b) {
setupQueue(looper);
}
@@ -64,7 +64,7 @@ public class TestableLooper {
return mLooper;
}
- private void setupQueue(Looper l) throws Exception {
+ private void setupQueue(Looper l) {
mLooper = l;
mQueue = mLooper.getQueue();
mHandler = new Handler(mLooper);
@@ -75,7 +75,7 @@ public class TestableLooper {
* the looper will not be available for any subsequent tests. This is
* automatically handled for tests using {@link RunWithLooper}.
*/
- public void destroy() throws NoSuchFieldException, IllegalAccessException {
+ public void destroy() {
mQueueWrapper.release();
if (mLooper == Looper.getMainLooper()) {
TestableInstrumentation.releaseMain();
@@ -133,7 +133,7 @@ public class TestableLooper {
if (mMessageHandler != null) {
if (mMessageHandler.onMessageHandled(result)) {
- result.getTarget().dispatchMessage(result);
+ mQueueWrapper.execute(result);
mQueueWrapper.recycle(result);
} else {
mQueueWrapper.recycle(result);
@@ -141,7 +141,7 @@ public class TestableLooper {
return false;
}
} else {
- result.getTarget().dispatchMessage(result);
+ mQueueWrapper.execute(result);
mQueueWrapper.recycle(result);
}
} else {
@@ -238,7 +238,7 @@ public class TestableLooper {
super(base.getMethod());
mLooper = other.mLooper;
mTestableLooper = other;
- mHandler = new Handler(mLooper);
+ mHandler = Handler.createAsync(mLooper);
}
public static FrameworkMethod get(FrameworkMethod base, boolean setAsMain, Object test) {