From 5cb8998363a16e667faee4eaa7e5040bce7e702b Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 28 Nov 2016 13:15:10 -0800 Subject: Preload2: Abstract out UI Create IUI interface and move UI to SwingUI. Bug: 31961946 Test: manual Change-Id: If56347fdde8b441c0c01337a3f5eac002ea5b4f3 --- tools/preload2/src/com/android/preload/Main.java | 17 +- .../preload/actions/ComputeThresholdAction.java | 7 +- tools/preload2/src/com/android/preload/ui/IUI.java | 43 ++++ .../src/com/android/preload/ui/SwingUI.java | 286 +++++++++++++++++++++ tools/preload2/src/com/android/preload/ui/UI.java | 267 ------------------- 5 files changed, 341 insertions(+), 279 deletions(-) create mode 100644 tools/preload2/src/com/android/preload/ui/IUI.java create mode 100644 tools/preload2/src/com/android/preload/ui/SwingUI.java delete mode 100644 tools/preload2/src/com/android/preload/ui/UI.java diff --git a/tools/preload2/src/com/android/preload/Main.java b/tools/preload2/src/com/android/preload/Main.java index ca5b0e005a1d..cc54a8d9c715 100644 --- a/tools/preload2/src/com/android/preload/Main.java +++ b/tools/preload2/src/com/android/preload/Main.java @@ -32,7 +32,8 @@ import com.android.preload.actions.ShowDataAction; import com.android.preload.classdataretrieval.ClassDataRetriever; import com.android.preload.classdataretrieval.hprof.Hprof; import com.android.preload.classdataretrieval.jdwp.JDWPClassDataRetriever; -import com.android.preload.ui.UI; +import com.android.preload.ui.IUI; +import com.android.preload.ui.SwingUI; import java.util.ArrayList; import java.util.Collection; @@ -66,7 +67,7 @@ public class Main { private DumpTableModel dataTableModel; private DefaultListModel clientListModel; - private UI ui; + private IUI ui; // Actions that need to be updated once a device is selected. private Collection deviceSpecificActions; @@ -89,13 +90,15 @@ public class Main { * @param args */ public static void main(String[] args) { - Main m = new Main(); + Main m = new Main(new SwingUI()); top = m; m.startUp(); } - public Main() { + public Main(IUI ui) { + this.ui = ui; + clientListModel = new DefaultListModel(); dataTableModel = new DumpTableModel(); @@ -124,11 +127,10 @@ public class Main { } } - ui = new UI(clientListModel, dataTableModel, actions); - ui.setVisible(true); + ui.prepare(clientListModel, dataTableModel, actions); } - public static UI getUI() { + public static IUI getUI() { return top.ui; } @@ -176,6 +178,7 @@ public class Main { new ReloadListAction(clientUtils, getDevice(), clientListModel).run(); getUI().hideWaitDialog(); + getUI().ready(); } private void initDevice() { diff --git a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java index b524716fc2cb..5d052ccc7072 100644 --- a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java +++ b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java @@ -32,7 +32,6 @@ import java.util.TreeSet; import java.util.regex.Pattern; import javax.swing.AbstractAction; -import javax.swing.JFileChooser; /** * Compute an intersection of classes from the given data. A class is in the intersection if it @@ -92,10 +91,8 @@ public class ComputeThresholdAction extends AbstractAction implements Runnable { boolean ret = Main.getUI().showConfirmDialog("Computed a set with " + result.size() + " classes, would you like to save to disk?", "Save?"); if (ret) { - JFileChooser jfc = new JFileChooser(); - int ret2 = jfc.showSaveDialog(Main.getUI()); - if (ret2 == JFileChooser.APPROVE_OPTION) { - File f = jfc.getSelectedFile(); + File f = Main.getUI().showSaveDialog(); + if (f != null) { saveSet(result, f); } } diff --git a/tools/preload2/src/com/android/preload/ui/IUI.java b/tools/preload2/src/com/android/preload/ui/IUI.java new file mode 100644 index 000000000000..3c151d90ab0a --- /dev/null +++ b/tools/preload2/src/com/android/preload/ui/IUI.java @@ -0,0 +1,43 @@ +package com.android.preload.ui; + +import com.android.ddmlib.Client; +import java.io.File; +import java.util.List; +import javax.swing.Action; +import javax.swing.ListModel; +import javax.swing.table.TableModel; + +/** + * UI abstraction for the tool. This allows a graphical mode, command line mode, + * or silent mode. + */ +public interface IUI { + + void prepare(ListModel clientListModel, TableModel dataTableModel, + List actions); + + void ready(); + + Client getSelectedClient(); + + int getSelectedDataTableRow(); + + void showWaitDialog(); + + void updateWaitDialog(String s); + + void hideWaitDialog(); + + void showMessageDialog(String s); + + boolean showConfirmDialog(String title, String message); + + String showInputDialog(String message); + + T showChoiceDialog(String title, String message, T[] choices); + + File showSaveDialog(); + + File[] showOpenDialog(boolean multi); + +} diff --git a/tools/preload2/src/com/android/preload/ui/SwingUI.java b/tools/preload2/src/com/android/preload/ui/SwingUI.java new file mode 100644 index 000000000000..1245f2c23d7e --- /dev/null +++ b/tools/preload2/src/com/android/preload/ui/SwingUI.java @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.preload.ui; + +import com.android.ddmlib.Client; +import com.android.ddmlib.ClientData; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.io.File; +import java.util.List; + +import javax.swing.Action; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListModel; +import javax.swing.SwingUtilities; +import javax.swing.table.TableModel; + +public class SwingUI extends JFrame implements IUI { + + private JList clientList; + private JTable dataTable; + + // Shared file chooser, means the directory is retained. + private JFileChooser jfc; + + public SwingUI() { + super("Preloaded-classes computation"); + } + + @Override + public void prepare(ListModel clientListModel, TableModel dataTableModel, + List actions) { + getContentPane().add(new JScrollPane(clientList = new JList(clientListModel)), + BorderLayout.WEST); + clientList.setCellRenderer(new ClientListCellRenderer()); + // clientList.addListSelectionListener(listener); + + dataTable = new JTable(dataTableModel); + getContentPane().add(new JScrollPane(dataTable), BorderLayout.CENTER); + + JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL); + for (Action a : actions) { + if (a == null) { + toolbar.addSeparator(); + } else { + toolbar.add(a); + } + } + getContentPane().add(toolbar, BorderLayout.PAGE_START); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 800, 600); + + setVisible(true); + } + + @Override + public void ready() { + } + + @Override + public Client getSelectedClient() { + return clientList.getSelectedValue(); + } + + @Override + public int getSelectedDataTableRow() { + return dataTable.getSelectedRow(); + } + + private JDialog currentWaitDialog = null; + + @Override + public void showWaitDialog() { + if (currentWaitDialog == null) { + currentWaitDialog = new JDialog(this, "Please wait...", true); + currentWaitDialog.getContentPane().add(new JLabel("Please be patient."), + BorderLayout.CENTER); + JProgressBar progress = new JProgressBar(JProgressBar.HORIZONTAL); + progress.setIndeterminate(true); + currentWaitDialog.getContentPane().add(progress, BorderLayout.SOUTH); + currentWaitDialog.setSize(200, 100); + currentWaitDialog.setLocationRelativeTo(null); + showWaitDialogLater(); + } + } + + private void showWaitDialogLater() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(true); // This is blocking. + } + } + }); + } + + @Override + public void updateWaitDialog(String s) { + if (currentWaitDialog != null) { + ((JLabel) currentWaitDialog.getContentPane().getComponent(0)).setText(s); + Dimension prefSize = currentWaitDialog.getPreferredSize(); + Dimension curSize = currentWaitDialog.getSize(); + if (prefSize.width > curSize.width || prefSize.height > curSize.height) { + currentWaitDialog.setSize(Math.max(prefSize.width, curSize.width), + Math.max(prefSize.height, curSize.height)); + currentWaitDialog.invalidate(); + } + } + } + + @Override + public void hideWaitDialog() { + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + currentWaitDialog = null; + } + } + + @Override + public void showMessageDialog(String s) { + // Hide the wait dialog... + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + } + + try { + JOptionPane.showMessageDialog(this, s); + } finally { + // And reshow it afterwards... + if (currentWaitDialog != null) { + showWaitDialogLater(); + } + } + } + + @Override + public boolean showConfirmDialog(String title, String message) { + // Hide the wait dialog... + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + } + + try { + return JOptionPane.showConfirmDialog(this, title, message, JOptionPane.YES_NO_OPTION) + == JOptionPane.YES_OPTION; + } finally { + // And reshow it afterwards... + if (currentWaitDialog != null) { + showWaitDialogLater(); + } + } + } + + @Override + public String showInputDialog(String message) { + // Hide the wait dialog... + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + } + + try { + return JOptionPane.showInputDialog(message); + } finally { + // And reshow it afterwards... + if (currentWaitDialog != null) { + showWaitDialogLater(); + } + } + } + + @Override + @SuppressWarnings("unchecked") + public T showChoiceDialog(String title, String message, T[] choices) { + // Hide the wait dialog... + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + } + + try{ + return (T)JOptionPane.showInputDialog(this, + title, + message, + JOptionPane.QUESTION_MESSAGE, + null, + choices, + choices[0]); + } finally { + // And reshow it afterwards... + if (currentWaitDialog != null) { + showWaitDialogLater(); + } + } + } + + @Override + public File showSaveDialog() { + // Hide the wait dialog... + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + } + + try{ + if (jfc == null) { + jfc = new JFileChooser(); + } + + int ret = jfc.showSaveDialog(this); + if (ret == JFileChooser.APPROVE_OPTION) { + return jfc.getSelectedFile(); + } else { + return null; + } + } finally { + // And reshow it afterwards... + if (currentWaitDialog != null) { + showWaitDialogLater(); + } + } + } + + @Override + public File[] showOpenDialog(boolean multi) { + // Hide the wait dialog... + if (currentWaitDialog != null) { + currentWaitDialog.setVisible(false); + } + + try{ + if (jfc == null) { + jfc = new JFileChooser(); + } + + jfc.setMultiSelectionEnabled(multi); + int ret = jfc.showOpenDialog(this); + if (ret == JFileChooser.APPROVE_OPTION) { + return jfc.getSelectedFiles(); + } else { + return null; + } + } finally { + // And reshow it afterwards... + if (currentWaitDialog != null) { + showWaitDialogLater(); + } + } + } + + private class ClientListCellRenderer extends DefaultListCellRenderer { + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + ClientData cd = ((Client) value).getClientData(); + String s = cd.getClientDescription() + " (pid " + cd.getPid() + ")"; + return super.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus); + } + } +} diff --git a/tools/preload2/src/com/android/preload/ui/UI.java b/tools/preload2/src/com/android/preload/ui/UI.java deleted file mode 100644 index 47174ddd0e07..000000000000 --- a/tools/preload2/src/com/android/preload/ui/UI.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.preload.ui; - -import com.android.ddmlib.Client; -import com.android.ddmlib.ClientData; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.io.File; -import java.util.List; - -import javax.swing.Action; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JProgressBar; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JToolBar; -import javax.swing.ListModel; -import javax.swing.SwingUtilities; -import javax.swing.table.TableModel; - -public class UI extends JFrame { - - private JList clientList; - private JTable dataTable; - - // Shared file chooser, means the directory is retained. - private JFileChooser jfc; - - public UI(ListModel clientListModel, - TableModel dataTableModel, - List actions) { - super("Preloaded-classes computation"); - - getContentPane().add(new JScrollPane(clientList = new JList(clientListModel)), - BorderLayout.WEST); - clientList.setCellRenderer(new ClientListCellRenderer()); - // clientList.addListSelectionListener(listener); - - dataTable = new JTable(dataTableModel); - getContentPane().add(new JScrollPane(dataTable), BorderLayout.CENTER); - - JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL); - for (Action a : actions) { - if (a == null) { - toolbar.addSeparator(); - } else { - toolbar.add(a); - } - } - getContentPane().add(toolbar, BorderLayout.PAGE_START); - - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(100, 100, 800, 600); - } - - public Client getSelectedClient() { - return clientList.getSelectedValue(); - } - - public int getSelectedDataTableRow() { - return dataTable.getSelectedRow(); - } - - private JDialog currentWaitDialog = null; - - public void showWaitDialog() { - if (currentWaitDialog == null) { - currentWaitDialog = new JDialog(this, "Please wait...", true); - currentWaitDialog.getContentPane().add(new JLabel("Please be patient."), - BorderLayout.CENTER); - JProgressBar progress = new JProgressBar(JProgressBar.HORIZONTAL); - progress.setIndeterminate(true); - currentWaitDialog.getContentPane().add(progress, BorderLayout.SOUTH); - currentWaitDialog.setSize(200, 100); - currentWaitDialog.setLocationRelativeTo(null); - showWaitDialogLater(); - } - } - - private void showWaitDialogLater() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(true); // This is blocking. - } - } - }); - } - - public void updateWaitDialog(String s) { - if (currentWaitDialog != null) { - ((JLabel) currentWaitDialog.getContentPane().getComponent(0)).setText(s); - Dimension prefSize = currentWaitDialog.getPreferredSize(); - Dimension curSize = currentWaitDialog.getSize(); - if (prefSize.width > curSize.width || prefSize.height > curSize.height) { - currentWaitDialog.setSize(Math.max(prefSize.width, curSize.width), - Math.max(prefSize.height, curSize.height)); - currentWaitDialog.invalidate(); - } - } - } - - public void hideWaitDialog() { - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - currentWaitDialog = null; - } - } - - public void showMessageDialog(String s) { - // Hide the wait dialog... - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - } - - try { - JOptionPane.showMessageDialog(this, s); - } finally { - // And reshow it afterwards... - if (currentWaitDialog != null) { - showWaitDialogLater(); - } - } - } - - public boolean showConfirmDialog(String title, String message) { - // Hide the wait dialog... - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - } - - try { - return JOptionPane.showConfirmDialog(this, title, message, JOptionPane.YES_NO_OPTION) - == JOptionPane.YES_OPTION; - } finally { - // And reshow it afterwards... - if (currentWaitDialog != null) { - showWaitDialogLater(); - } - } - } - - public String showInputDialog(String message) { - // Hide the wait dialog... - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - } - - try { - return JOptionPane.showInputDialog(message); - } finally { - // And reshow it afterwards... - if (currentWaitDialog != null) { - showWaitDialogLater(); - } - } - } - - @SuppressWarnings("unchecked") - public T showChoiceDialog(String title, String message, T[] choices) { - // Hide the wait dialog... - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - } - - try{ - return (T)JOptionPane.showInputDialog(this, - title, - message, - JOptionPane.QUESTION_MESSAGE, - null, - choices, - choices[0]); - } finally { - // And reshow it afterwards... - if (currentWaitDialog != null) { - showWaitDialogLater(); - } - } - } - - public File showSaveDialog() { - // Hide the wait dialog... - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - } - - try{ - if (jfc == null) { - jfc = new JFileChooser(); - } - - int ret = jfc.showSaveDialog(this); - if (ret == JFileChooser.APPROVE_OPTION) { - return jfc.getSelectedFile(); - } else { - return null; - } - } finally { - // And reshow it afterwards... - if (currentWaitDialog != null) { - showWaitDialogLater(); - } - } - } - - public File[] showOpenDialog(boolean multi) { - // Hide the wait dialog... - if (currentWaitDialog != null) { - currentWaitDialog.setVisible(false); - } - - try{ - if (jfc == null) { - jfc = new JFileChooser(); - } - - jfc.setMultiSelectionEnabled(multi); - int ret = jfc.showOpenDialog(this); - if (ret == JFileChooser.APPROVE_OPTION) { - return jfc.getSelectedFiles(); - } else { - return null; - } - } finally { - // And reshow it afterwards... - if (currentWaitDialog != null) { - showWaitDialogLater(); - } - } - } - - private class ClientListCellRenderer extends DefaultListCellRenderer { - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, - boolean isSelected, boolean cellHasFocus) { - ClientData cd = ((Client) value).getClientData(); - String s = cd.getClientDescription() + " (pid " + cd.getPid() + ")"; - return super.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus); - } - } -} -- cgit v1.2.3-59-g8ed1b From 1c809a3d3240978ab393b48ec5501090ec5a0e57 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 28 Nov 2016 15:04:25 -0800 Subject: Preload2: Fix action inheritance Use AbstractThreadedAction as a base. Bug: 31961946 Test: manual Change-Id: I5a05b65d753be775c8b8382bb1a81e869c388f8d --- .../src/com/android/preload/actions/ComputeThresholdAction.java | 4 ++-- tools/preload2/src/com/android/preload/actions/ExportAction.java | 7 ++----- tools/preload2/src/com/android/preload/actions/ImportAction.java | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java index 5d052ccc7072..3a7f7f74d755 100644 --- a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java +++ b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java @@ -38,7 +38,7 @@ import javax.swing.AbstractAction; * appears in at least the number of threshold given packages. An optional blacklist can be * used to filter classes from the intersection. */ -public class ComputeThresholdAction extends AbstractAction implements Runnable { +public class ComputeThresholdAction extends AbstractThreadedAction { protected int threshold; private Pattern blacklist; private DumpTableModel dataTableModel; @@ -71,7 +71,7 @@ public class ComputeThresholdAction extends AbstractAction implements Runnable { return; } - new Thread(this).start(); + super.actionPerformed(e); } @Override diff --git a/tools/preload2/src/com/android/preload/actions/ExportAction.java b/tools/preload2/src/com/android/preload/actions/ExportAction.java index cb8b3df75b18..848a56826788 100644 --- a/tools/preload2/src/com/android/preload/actions/ExportAction.java +++ b/tools/preload2/src/com/android/preload/actions/ExportAction.java @@ -19,14 +19,11 @@ package com.android.preload.actions; import com.android.preload.DumpDataIO; import com.android.preload.DumpTableModel; import com.android.preload.Main; - import java.awt.event.ActionEvent; import java.io.File; import java.io.PrintWriter; -import javax.swing.AbstractAction; - -public class ExportAction extends AbstractAction implements Runnable { +public class ExportAction extends AbstractThreadedAction { private File lastSaveFile; private DumpTableModel dataTableModel; @@ -39,7 +36,7 @@ public class ExportAction extends AbstractAction implements Runnable { public void actionPerformed(ActionEvent e) { lastSaveFile = Main.getUI().showSaveDialog(); if (lastSaveFile != null) { - new Thread(this).start(); + super.actionPerformed(e); } } diff --git a/tools/preload2/src/com/android/preload/actions/ImportAction.java b/tools/preload2/src/com/android/preload/actions/ImportAction.java index 5c1976580f94..bfeeb836fd45 100644 --- a/tools/preload2/src/com/android/preload/actions/ImportAction.java +++ b/tools/preload2/src/com/android/preload/actions/ImportAction.java @@ -27,7 +27,7 @@ import java.util.Collection; import javax.swing.AbstractAction; -public class ImportAction extends AbstractAction implements Runnable { +public class ImportAction extends AbstractThreadedAction { private File[] lastOpenFiles; private DumpTableModel dataTableModel; @@ -40,7 +40,7 @@ public class ImportAction extends AbstractAction implements Runnable { public void actionPerformed(ActionEvent e) { lastOpenFiles = Main.getUI().showOpenDialog(true); if (lastOpenFiles != null) { - new Thread(this).start(); + super.actionPerformed(e); } } -- cgit v1.2.3-59-g8ed1b From 3bf65c916ce65c06b0920ec4b8f68d3ef6c5e721 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 28 Nov 2016 15:06:35 -0800 Subject: Preload2: Add isSingleThreaded Expose whether a UI is single-threaded to avoid spawning threads in actions. Bug: 31961946 Test: manual Change-Id: I37c8daa6a00784e833bad53b8e83ab4417955df7 --- .../src/com/android/preload/actions/AbstractThreadedAction.java | 7 ++++++- .../preload2/src/com/android/preload/actions/RunMonkeyAction.java | 7 ++++++- tools/preload2/src/com/android/preload/ui/IUI.java | 2 ++ tools/preload2/src/com/android/preload/ui/SwingUI.java | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java b/tools/preload2/src/com/android/preload/actions/AbstractThreadedAction.java index fbf83d2e2339..5787d8507230 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 @@ public abstract class AbstractThreadedAction extends AbstractAction implements R @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 385e8577b1c8..29464fc7abdf 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 @@ public class RunMonkeyAction extends AbstractAction implements DeviceSpecific { 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 3c151d90ab0a..9371463e9a79 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 @@ public interface IUI { 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 1245f2c23d7e..cab3744ad74c 100644 --- a/tools/preload2/src/com/android/preload/ui/SwingUI.java +++ b/tools/preload2/src/com/android/preload/ui/SwingUI.java @@ -53,6 +53,11 @@ public class SwingUI extends JFrame implements IUI { super("Preloaded-classes computation"); } + @Override + public boolean isSingleThreaded() { + return false; + } + @Override public void prepare(ListModel clientListModel, TableModel dataTableModel, List actions) { -- cgit v1.2.3-59-g8ed1b