import com.android.ddmuilib.DdmUiPreferences;
import com.android.ddmuilib.console.DdmConsole;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import java.io.BufferedReader;
super(parentShell);
}
- public void onStartFailure(final Client client, final String message) {
- mParentShell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- displayError(
- "Unable to create Method Profiling file for application '%1$s'\n\n%2$s" +
- "Check logcat for more information.",
- client.getClientData().getClientDescription(),
- message != null ? message + "\n\n" : "");
- }
- });
+ @Override
+ protected String getDialogTitle() {
+ return "Method Profiling Error";
}
- public void onEndFailure(final Client client, final String message) {
- mParentShell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- displayError(
- "Unable to finish Method Profiling for application '%1$s'\n\n%2$s" +
- "Check logcat for more information.",
- client.getClientData().getClientDescription(),
- message != null ? message + "\n\n" : "");
- }
- });
+ public void onStartFailure(final Client client, final String message) {
+ displayErrorInUiThread(
+ "Unable to create Method Profiling file for application '%1$s'\n\n%2$s" +
+ "Check logcat for more information.",
+ client.getClientData().getClientDescription(),
+ message != null ? message + "\n\n" : "");
}
- public void onEndLocalFailure(final Client client, final String message) {
- mParentShell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- displayError(
- "Unable to write trace file locally for application '%1$s'\n\n%2$s",
- client.getClientData().getClientDescription(),
- message);
- }
- });
+ public void onEndFailure(final Client client, final String message) {
+ displayErrorInUiThread(
+ "Unable to finish Method Profiling for application '%1$s'\n\n%2$s" +
+ "Check logcat for more information.",
+ client.getClientData().getClientDescription(),
+ message != null ? message + "\n\n" : "");
}
public void onSuccess(final String remoteFilePath, final Client client) {
mParentShell.getDisplay().asyncExec(new Runnable() {
public void run() {
if (remoteFilePath == null) {
- displayError(
+ displayErrorFromUiThread(
"Unable to download trace file: unknown file name.\n" +
"This can happen if you disconnected the device while recording the trace.");
return;
if (sync != null) {
pullAndOpen(sync, remoteFilePath);
} else {
- displayError("Unable to download trace file from device '%1$s'.",
+ displayErrorFromUiThread("Unable to download trace file from device '%1$s'.",
device.getSerialNumber());
}
} catch (Exception e) {
- displayError("Unable to download trace file from device '%1$s'.",
+ displayErrorFromUiThread("Unable to download trace file from device '%1$s'.",
device.getSerialNumber());
}
}
});
}
- public void onSuccess(File localFile, final Client client) {
- openInTraceview(localFile.getAbsolutePath());
+ public void onSuccess(byte[] data, final Client client) {
+ try {
+ File tempFile = saveTempFile(data);
+ openInTraceview(tempFile.getAbsolutePath());
+ } catch (IOException e) {
+ String errorMsg = e.getMessage();
+ displayErrorInUiThread(
+ "Failed to save trace data into temp file%1$s",
+ errorMsg != null ? ":\n" + errorMsg : ".");
+ }
}
+ /**
+ * pulls and open a file. This is run from the UI thread.
+ */
private void pullAndOpen(SyncService sync, String remoteFilePath)
throws InvocationTargetException, InterruptedException, IOException {
// get a temp file
// open the temp file in traceview
openInTraceview(tempPath);
} else {
- displayError("Unable to download trace file:\n\n%1$s",
+ displayErrorFromUiThread("Unable to download trace file:\n\n%1$s",
result.getMessage());
}
} else {
// this really shouldn't happen.
- displayError("Unable to download trace file.");
+ displayErrorFromUiThread("Unable to download trace file.");
}
}
Log.e("traceview", e);
}
}
-
- private void displayError(String format, Object... args) {
- MessageDialog.openError(mParentShell, "Method Profiling Error",
- String.format(format, args));
- }
}