Merge "Preload2: Add sequence UI" am: 56ddac7fd7
am: b9d8535a21
Change-Id: I721674c8381caa9c404c3708122f03d6c8d6d204
This commit is contained in:
@@ -34,4 +34,4 @@ PROG_NAME="$(follow_links)"
|
||||
PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
|
||||
ANDROID_ROOT=$PROG_DIR/..
|
||||
|
||||
java -cp $ANDROID_ROOT/framework/preload2.jar com.android.preload.Main
|
||||
java -cp $ANDROID_ROOT/framework/preload2.jar com.android.preload.Main $@
|
||||
|
||||
@@ -33,10 +33,13 @@ 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.IUI;
|
||||
import com.android.preload.ui.SequenceUI;
|
||||
import com.android.preload.ui.SwingUI;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -90,9 +93,14 @@ public class Main {
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Main m = new Main(new SwingUI());
|
||||
top = m;
|
||||
Main m;
|
||||
if (args.length > 0 && args[0].equals("--seq")) {
|
||||
m = createSequencedMain(args);
|
||||
} else {
|
||||
m = new Main(new SwingUI());
|
||||
}
|
||||
|
||||
top = m;
|
||||
m.startUp();
|
||||
}
|
||||
|
||||
@@ -130,6 +138,27 @@ public class Main {
|
||||
ui.prepare(clientListModel, dataTableModel, actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private static Main createSequencedMain(String[] args) {
|
||||
SequenceUI ui = new SequenceUI();
|
||||
Main main = new Main(ui);
|
||||
|
||||
Iterator<String> it = Arrays.asList(args).iterator();
|
||||
it.next(); // --seq
|
||||
|
||||
ui.choice("#" + it.next()); // Device.
|
||||
ui.confirmNo(); // Prepare: no.
|
||||
ui.action(ScanPackageAction.class); // Take hprof dump.
|
||||
ui.client("system_process"); // Select system server.
|
||||
ui.action(ExportAction.class); // Export data.
|
||||
ui.output(new File("/tmp/system_server.data")); // Write to file.
|
||||
|
||||
return main;
|
||||
}
|
||||
|
||||
public static IUI getUI() {
|
||||
return top.ui;
|
||||
}
|
||||
|
||||
222
tools/preload2/src/com/android/preload/ui/SequenceUI.java
Normal file
222
tools/preload2/src/com/android/preload/ui/SequenceUI.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package com.android.preload.ui;
|
||||
|
||||
import com.android.ddmlib.Client;
|
||||
import com.android.ddmlib.ClientData;
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
public class SequenceUI implements IUI {
|
||||
|
||||
private ListModel<Client> clientListModel;
|
||||
@SuppressWarnings("unused")
|
||||
private TableModel dataTableModel;
|
||||
private List<Action> actions;
|
||||
|
||||
private List<Object> sequence = new LinkedList<>();
|
||||
|
||||
public SequenceUI() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleThreaded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(ListModel<Client> clientListModel, TableModel dataTableModel,
|
||||
List<Action> actions) {
|
||||
this.clientListModel = clientListModel;
|
||||
this.dataTableModel = dataTableModel;
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
public SequenceUI action(Action a) {
|
||||
sequence.add(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI action(Class<? extends Action> actionClass) {
|
||||
for (Action a : actions) {
|
||||
if (actionClass.equals(a.getClass())) {
|
||||
sequence.add(a);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No action of class " + actionClass + " found.");
|
||||
}
|
||||
|
||||
public SequenceUI confirmYes() {
|
||||
sequence.add(Boolean.TRUE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI confirmNo() {
|
||||
sequence.add(Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI input(String input) {
|
||||
sequence.add(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI input(File... f) {
|
||||
sequence.add(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI output(File f) {
|
||||
sequence.add(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI tableRow(int i) {
|
||||
sequence.add(i);
|
||||
return this;
|
||||
}
|
||||
|
||||
private class ClientSelector {
|
||||
private String pkg;
|
||||
|
||||
public ClientSelector(String pkg) {
|
||||
this.pkg = pkg;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
for (int i = 0; i < clientListModel.getSize(); i++) {
|
||||
ClientData cd = clientListModel.getElementAt(i).getClientData();
|
||||
if (cd != null) {
|
||||
String s = cd.getClientDescription();
|
||||
if (pkg.equals(s)) {
|
||||
return clientListModel.getElementAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Didn't find client " + pkg);
|
||||
}
|
||||
}
|
||||
|
||||
public SequenceUI client(String pkg) {
|
||||
sequence.add(new ClientSelector(pkg));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SequenceUI choice(String pattern) {
|
||||
sequence.add(pattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ready() {
|
||||
// Run the actions.
|
||||
// No iterator or foreach loop as the sequence will be emptied while running.
|
||||
try {
|
||||
while (!sequence.isEmpty()) {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof Action) {
|
||||
((Action)next).actionPerformed(null);
|
||||
} else {
|
||||
throw new IllegalStateException("Didn't expect a non-action: " + next);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
// Now shut down.
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Client getSelectedClient() {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof ClientSelector) {
|
||||
return ((ClientSelector)next).getClient();
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSelectedDataTableRow() {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof Integer) {
|
||||
return ((Integer)next).intValue();
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showWaitDialog() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWaitDialog(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideWaitDialog() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessageDialog(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConfirmDialog(String title, String message) {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof Boolean) {
|
||||
return ((Boolean)next).booleanValue();
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String showInputDialog(String message) {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof String) {
|
||||
return (String)next;
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T showChoiceDialog(String title, String message, T[] choices) {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof String) {
|
||||
String s = (String)next;
|
||||
for (T t : choices) {
|
||||
if (t.toString().contains(s)) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File showSaveDialog() {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof File) {
|
||||
System.out.println(next);
|
||||
return (File)next;
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] showOpenDialog(boolean multi) {
|
||||
Object next = sequence.remove(0);
|
||||
if (next instanceof File[]) {
|
||||
return (File[])next;
|
||||
}
|
||||
throw new IllegalStateException("Unexpected: " + next);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user