import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
private final static String PREFS_THREAD_REFRESH_INTERVAL = "threadStatusInterval"; //$NON-NLS-1$
private final static String PREFS_LOG_LEVEL = "ddmsLogLevel"; //$NON-NLS-1$
private final static String PREFS_TIMEOUT = "timeOut"; //$NON-NLS-1$
+ private final static String PREFS_USE_ADBHOST = "useAdbHost"; //$NON-NLS-1$
+ private final static String PREFS_ADBHOST_VALUE = "adbHostValue"; //$NON-NLS-1$
/**
DdmPreferences.setInitialThreadUpdate(mPrefStore.getBoolean(PREFS_DEFAULT_THREAD_UPDATE));
DdmPreferences.setInitialHeapUpdate(mPrefStore.getBoolean(PREFS_DEFAULT_HEAP_UPDATE));
DdmPreferences.setTimeOut(mPrefStore.getInt(PREFS_TIMEOUT));
+ DdmPreferences.setUseAdbHost(mPrefStore.getBoolean(PREFS_USE_ADBHOST));
+ DdmPreferences.setAdbHostValue(mPrefStore.getString(PREFS_ADBHOST_VALUE));
// some static values
String out = System.getenv("ANDROID_PRODUCT_OUT"); //$NON-NLS-1$
mPrefStore.setDefault(PREFS_SELECTED_DEBUG_PORT,
DdmPreferences.DEFAULT_SELECTED_DEBUG_PORT);
+ mPrefStore.setDefault(PREFS_USE_ADBHOST, DdmPreferences.DEFAULT_USE_ADBHOST);
+ mPrefStore.setDefault(PREFS_ADBHOST_VALUE, DdmPreferences.DEFAULT_ADBHOST_VALUE);
+
mPrefStore.setDefault(PREFS_DEFAULT_THREAD_UPDATE, true);
mPrefStore.setDefault(PREFS_DEFAULT_HEAP_UPDATE, false);
mPrefStore.setDefault(PREFS_THREAD_REFRESH_INTERVAL,
(String) event.getNewValue());
} else if (changed.equals(PREFS_TIMEOUT)) {
DdmPreferences.setTimeOut(mPrefStore.getInt(PREFS_TIMEOUT));
+ } else if (changed.equals(PREFS_USE_ADBHOST)) {
+ DdmPreferences.setUseAdbHost(mPrefStore.getBoolean(PREFS_USE_ADBHOST));
+ } else if (changed.equals(PREFS_ADBHOST_VALUE)) {
+ DdmPreferences.setAdbHostValue(mPrefStore.getString(PREFS_ADBHOST_VALUE));
} else {
Log.v("ddms", "Preference change: " + event.getProperty()
+ ": '" + event.getOldValue()
*/
private static class DebuggerPrefs extends FieldEditorPreferencePage {
+ private BooleanFieldEditor mUseAdbHost;
+ private StringFieldEditor mAdbHostValue;
+
/**
* Basic constructor.
*/
ife = new PortFieldEditor(PREFS_SELECTED_DEBUG_PORT,
"Port of Selected VM:", getFieldEditorParent());
addField(ife);
+
+ mUseAdbHost = new BooleanFieldEditor(PREFS_USE_ADBHOST,
+ "Use ADBHOST", getFieldEditorParent());
+ addField(mUseAdbHost);
+
+ mAdbHostValue = new StringFieldEditor(PREFS_ADBHOST_VALUE,
+ "ADBHOST value:", getFieldEditorParent());
+ mAdbHostValue.setEnabled(getPreferenceStore()
+ .getBoolean(PREFS_USE_ADBHOST), getFieldEditorParent());
+ addField(mAdbHostValue);
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ // TODO Auto-generated method stub
+ if (event.getSource().equals(mUseAdbHost)) {
+ mAdbHostValue.setEnabled(mUseAdbHost.getBooleanValue(), getFieldEditorParent());
+ }
}
}
}
});
+ final MenuItem actionResetAdb = new MenuItem(actionMenu, SWT.NONE);
+ actionResetAdb.setText("&Reset adb");
+ actionResetAdb.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
+ if (bridge != null) {
+ bridge.restart();
+ }
+ }
+ });
+
// configure Action items based on current state
actionMenu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
actionHaltItem.setEnabled(mTBHalt.getEnabled() && mCurrentClient != null);
actionCauseGcItem.setEnabled(mTBCauseGc.getEnabled() && mCurrentClient != null);
+ actionResetAdb.setEnabled(true);
}
});
import java.net.UnknownHostException;
import java.security.InvalidParameterException;
import java.util.ArrayList;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Log.d(DDMS,
String.format("Launching '%1$s %2$s' to ensure ADB is running.", //$NON-NLS-1$
mAdbOsLocation, command[1]));
- proc = Runtime.getRuntime().exec(command);
+ ProcessBuilder processBuilder = new ProcessBuilder(command);
+ if (DdmPreferences.getUseAdbHost()) {
+ String adbHostValue = DdmPreferences.getAdbHostValue();
+ if (adbHostValue != null && adbHostValue.length() > 0) {
+ //TODO : check that the String is a valid IP address
+ Map<String, String> env = processBuilder.environment();
+ env.put("ADBHOST", adbHostValue);
+ }
+ }
+ proc = processBuilder.start();
ArrayList<String> errorOutput = new ArrayList<String>();
ArrayList<String> stdOutput = new ArrayList<String>();
public final static LogLevel DEFAULT_LOG_LEVEL = LogLevel.ERROR;
/** Default timeout values for adb connection (milliseconds) */
public static final int DEFAULT_TIMEOUT = 5000; // standard delay, in ms
+ /** Default values for the use of the ADBHOST environment variable. */
+ public final static boolean DEFAULT_USE_ADBHOST = false;
+ public final static String DEFAULT_ADBHOST_VALUE = "127.0.0.1";
private static boolean sThreadUpdate = DEFAULT_INITIAL_THREAD_UPDATE;
private static boolean sInitialHeapUpdate = DEFAULT_INITIAL_HEAP_UPDATE;
private static LogLevel sLogLevel = DEFAULT_LOG_LEVEL;
private static int sTimeOut = DEFAULT_TIMEOUT;
+ private static boolean sUseAdbHost = DEFAULT_USE_ADBHOST;
+ private static String sAdbHostValue = DEFAULT_ADBHOST_VALUE;
+
/**
* Returns the initial {@link Client} flag for thread updates.
* @see #setInitialThreadUpdate(boolean)
}
/**
+ * Returns a boolean indicating that the user uses or not the variable ADBHOST.
+ */
+ public static boolean getUseAdbHost() {
+ return sUseAdbHost;
+ }
+
+ /**
+ * Sets the value of the boolean indicating that the user uses or not the variable ADBHOST.
+ * @param useAdbHost true if the user uses ADBHOST
+ */
+ public static void setUseAdbHost(boolean useAdbHost) {
+ sUseAdbHost = useAdbHost;
+ }
+
+ /**
+ * Returns the value of the ADBHOST variable set by the user.
+ */
+ public static String getAdbHostValue() {
+ return sAdbHostValue;
+ }
+
+ /**
+ * Sets the value of the ADBHOST variable.
+ * @param adbHostValue
+ */
+ public static void setAdbHostValue(String adbHostValue) {
+ sAdbHostValue = adbHostValue;
+ }
+
+ /**
* Non accessible constructor.
*/
private DdmPreferences() {
} else if (PreferenceInitializer.ATTR_TIME_OUT.equals(property)) {
DdmPreferences.setTimeOut(
eclipseStore.getInt(PreferenceInitializer.ATTR_TIME_OUT));
+ } else if (PreferenceInitializer.ATTR_USE_ADBHOST.equals(property)) {
+ DdmPreferences.setUseAdbHost(
+ eclipseStore.getBoolean(PreferenceInitializer.ATTR_USE_ADBHOST));
+ } else if (PreferenceInitializer.ATTR_ADBHOST_VALUE.equals(property)) {
+ DdmPreferences.setAdbHostValue(
+ eclipseStore.getString(PreferenceInitializer.ATTR_ADBHOST_VALUE));
}
}
});
public final static String ATTR_LOGCAT_GOTO_PROBLEM =
DdmsPlugin.PLUGIN_ID + ".logcatGoToProblem"; //$NON-NLS-1$
+ public final static String ATTR_USE_ADBHOST =
+ DdmsPlugin.PLUGIN_ID + ".useAdbHost"; //$NON-NLS-1$
+
+ public final static String ATTR_ADBHOST_VALUE =
+ DdmsPlugin.PLUGIN_ID + ".adbHostValue"; //$NON-NLS-1$
+
/*
* (non-Javadoc)
*
store.setDefault(ATTR_TIME_OUT, DdmPreferences.DEFAULT_TIMEOUT);
store.setDefault(ATTR_LOGCAT_GOTO_PROBLEM, LogCatView.CHOICE_ERROR_LINE);
+ store.setDefault(ATTR_USE_ADBHOST, DdmPreferences.DEFAULT_USE_ADBHOST);
+ store.setDefault(ATTR_ADBHOST_VALUE, DdmPreferences.DEFAULT_ADBHOST_VALUE);
}
/**
DdmPreferences.setInitialHeapUpdate(store.getBoolean(ATTR_DEFAULT_HEAP_UPDATE));
DdmUiPreferences.setThreadRefreshInterval(store.getInt(ATTR_THREAD_INTERVAL));
DdmPreferences.setTimeOut(store.getInt(ATTR_TIME_OUT));
+ DdmPreferences.setUseAdbHost(store.getBoolean(ATTR_USE_ADBHOST));
+ DdmPreferences.setAdbHostValue(store.getString(ATTR_ADBHOST_VALUE));
}
}
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class PreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
+ private BooleanFieldEditor mUseAdbHost;
+ private StringFieldEditor mAdbHostValue;
+
public PreferencePage() {
super(GRID);
setPreferenceStore(DdmsPlugin.getDefault().getPreferenceStore());
},
getFieldEditorParent(), true);
addField(rgfe);
+
+ mUseAdbHost = new BooleanFieldEditor(PreferenceInitializer.ATTR_USE_ADBHOST,
+ "Use ADBHOST", getFieldEditorParent());
+ addField(mUseAdbHost);
+
+ mAdbHostValue = new StringFieldEditor(PreferenceInitializer.ATTR_ADBHOST_VALUE,
+ "ADBHOST value:", getFieldEditorParent());
+ mAdbHostValue.setEnabled(getPreferenceStore()
+ .getBoolean(PreferenceInitializer.ATTR_USE_ADBHOST), getFieldEditorParent());
+ addField(mAdbHostValue);
}
public void init(IWorkbench workbench) {
}
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ // TODO Auto-generated method stub
+ if (event.getSource().equals(mUseAdbHost)) {
+ mAdbHostValue.setEnabled(mUseAdbHost.getBooleanValue(), getFieldEditorParent());
+ }
+ }
}