Preload2: Add isSingleThreaded
Expose whether a UI is single-threaded to avoid spawning threads
in actions.
Bug: 31961946
Test: manual
Change-Id: I37c8daa6a00784e833bad53b8e83ab4417955df7
diff --git a/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java b/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java
index fbf83d2..5787d85 100644
--- a/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java
+++ b/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java
@@ -16,6 +16,7 @@
package com.android.preload.actions;
+import com.android.preload.Main;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
@@ -28,7 +29,11 @@
@Override
public void actionPerformed(ActionEvent e) {
- new Thread(this).start();
+ if (Main.getUI().isSingleThreaded()) {
+ run();
+ } else {
+ new Thread(this).start();
+ }
}
}
diff --git a/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java b/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java
index 385e857..29464fc 100644
--- a/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java
+++ b/tools/preload2/src/com/android/preload/actions/RunMonkeyAction.java
@@ -58,7 +58,12 @@
if (packages.isEmpty()) {
packages = DEFAULT_MONKEY_PACKAGES;
}
- new Thread(new RunMonkeyRunnable(packages)).start();
+ Runnable r = new RunMonkeyRunnable(packages);
+ if (Main.getUI().isSingleThreaded()) {
+ r.run();
+ } else {
+ new Thread(r).start();
+ }
}
private class RunMonkeyRunnable implements Runnable {
diff --git a/tools/preload2/src/com/android/preload/ui/IUI.java b/tools/preload2/src/com/android/preload/ui/IUI.java
index 3c151d9..9371463 100644
--- a/tools/preload2/src/com/android/preload/ui/IUI.java
+++ b/tools/preload2/src/com/android/preload/ui/IUI.java
@@ -18,6 +18,8 @@
void ready();
+ boolean isSingleThreaded();
+
Client getSelectedClient();
int getSelectedDataTableRow();
diff --git a/tools/preload2/src/com/android/preload/ui/SwingUI.java b/tools/preload2/src/com/android/preload/ui/SwingUI.java
index 1245f2c..cab3744 100644
--- a/tools/preload2/src/com/android/preload/ui/SwingUI.java
+++ b/tools/preload2/src/com/android/preload/ui/SwingUI.java
@@ -54,6 +54,11 @@
}
@Override
+ public boolean isSingleThreaded() {
+ return false;
+ }
+
+ @Override
public void prepare(ListModel<Client> clientListModel, TableModel dataTableModel,
List<Action> actions) {
getContentPane().add(new JScrollPane(clientList = new JList<Client>(clientListModel)),