Moved updateAdb into SdkManager and updated with new adb_usb.ini format.

New format is: 1 number per line. First number is vendor ID count, followed
by  the vendor IDs themselves. Comment lines starting with # accepted.
This commit is contained in:
Xavier Ducrohet
2009-05-21 17:46:12 -07:00
parent 1a0b3ffd5e
commit 0064943f50
2 changed files with 56 additions and 32 deletions

View File

@@ -32,10 +32,8 @@ import com.android.sdklib.internal.project.ProjectCreator.OutputLevel;
import com.android.sdkuilib.repository.UpdaterWindow;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -53,9 +51,6 @@ class Main {
private final static String[] BOOLEAN_YES_REPLIES = new String[] { "yes", "y" };
private final static String[] BOOLEAN_NO_REPLIES = new String[] { "no", "n" };
/** Preference file containing the usb ids for adb */
private final static String ADB_INI = "adb_usb.ini";
/** Path to the SDK folder. This is the parent of {@link #TOOLSDIR}. */
private String mOsSdkFolder;
/** Logger object. Use this to print normal output, warnings or errors. */
@@ -758,26 +753,8 @@ class Main {
* Updates adb with the USB devices declared in the SDK add-ons.
*/
private void updateAdb() {
FileWriter writer = null;
try {
// get the android prefs location to know where to write the file.
File adbIni = new File(AndroidLocation.getFolder(), ADB_INI);
writer = new FileWriter(adbIni);
// first, put all the vendor id in an HashSet to remove duplicate.
HashSet<Integer> set = new HashSet<Integer>();
IAndroidTarget[] targets = mSdkManager.getTargets();
for (IAndroidTarget target : targets) {
if (target.getUsbVendorId() != IAndroidTarget.NO_USB_ID) {
set.add(target.getUsbVendorId());
}
}
// now write the Id in a text file, one per line.
for (Integer i : set) {
writer.write(i.toString());
writer.write("\n");
}
mSdkManager.updateAdb();
mSdkLog.printf(
"adb has been updated. You must restart adb with the following commands\n" +
@@ -787,14 +764,6 @@ class Main {
errorAndExit(e.getMessage());
} catch (IOException e) {
errorAndExit(e.getMessage());
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// ignore
}
}
}
}