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:
@@ -32,10 +32,8 @@ import com.android.sdklib.internal.project.ProjectCreator.OutputLevel;
|
|||||||
import com.android.sdkuilib.repository.UpdaterWindow;
|
import com.android.sdkuilib.repository.UpdaterWindow;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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_YES_REPLIES = new String[] { "yes", "y" };
|
||||||
private final static String[] BOOLEAN_NO_REPLIES = new String[] { "no", "n" };
|
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}. */
|
/** Path to the SDK folder. This is the parent of {@link #TOOLSDIR}. */
|
||||||
private String mOsSdkFolder;
|
private String mOsSdkFolder;
|
||||||
/** Logger object. Use this to print normal output, warnings or errors. */
|
/** 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.
|
* Updates adb with the USB devices declared in the SDK add-ons.
|
||||||
*/
|
*/
|
||||||
private void updateAdb() {
|
private void updateAdb() {
|
||||||
FileWriter writer = null;
|
|
||||||
try {
|
try {
|
||||||
// get the android prefs location to know where to write the file.
|
mSdkManager.updateAdb();
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
mSdkLog.printf(
|
mSdkLog.printf(
|
||||||
"adb has been updated. You must restart adb with the following commands\n" +
|
"adb has been updated. You must restart adb with the following commands\n" +
|
||||||
@@ -787,14 +764,6 @@ class Main {
|
|||||||
errorAndExit(e.getMessage());
|
errorAndExit(e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
errorAndExit(e.getMessage());
|
errorAndExit(e.getMessage());
|
||||||
} finally {
|
|
||||||
if (writer != null) {
|
|
||||||
try {
|
|
||||||
writer.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,20 @@
|
|||||||
|
|
||||||
package com.android.sdklib;
|
package com.android.sdklib;
|
||||||
|
|
||||||
|
import com.android.prefs.AndroidLocation;
|
||||||
|
import com.android.prefs.AndroidLocation.AndroidLocationException;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -68,6 +73,16 @@ public final class SdkManager {
|
|||||||
SdkConstants.OS_SDK_TOOLS_LIB_FOLDER + SdkConstants.FN_DX_JAR,
|
SdkConstants.OS_SDK_TOOLS_LIB_FOLDER + SdkConstants.FN_DX_JAR,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Preference file containing the usb ids for adb */
|
||||||
|
private final static String ADB_INI_FILE = "adb_usb.ini";
|
||||||
|
//0--------90--------90--------90--------90--------90--------90--------90--------9
|
||||||
|
private final static String ADB_INI_COMMENT1 =
|
||||||
|
"# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT\n" +
|
||||||
|
"# USE 'android update adb' TO GENERATE\n" +
|
||||||
|
"# FIRST NUMBER IS VENDOR ID COUNT\n";
|
||||||
|
private final static String ADB_INI_COMMENT2 =
|
||||||
|
"# FOLLOWING NUMBERS ARE VENDOR ID IN DECIMAL\n";
|
||||||
|
|
||||||
/** the location of the SDK */
|
/** the location of the SDK */
|
||||||
private final String mSdkLocation;
|
private final String mSdkLocation;
|
||||||
private IAndroidTarget[] mTargets;
|
private IAndroidTarget[] mTargets;
|
||||||
@@ -132,6 +147,46 @@ public final class SdkManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates adb with the USB devices declared in the SDK add-ons.
|
||||||
|
* @throws AndroidLocationException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void updateAdb() throws AndroidLocationException, IOException {
|
||||||
|
FileWriter writer = null;
|
||||||
|
try {
|
||||||
|
// get the android prefs location to know where to write the file.
|
||||||
|
File adbIni = new File(AndroidLocation.getFolder(), ADB_INI_FILE);
|
||||||
|
writer = new FileWriter(adbIni);
|
||||||
|
|
||||||
|
// first, put all the vendor id in an HashSet to remove duplicate.
|
||||||
|
HashSet<Integer> set = new HashSet<Integer>();
|
||||||
|
IAndroidTarget[] targets = getTargets();
|
||||||
|
for (IAndroidTarget target : targets) {
|
||||||
|
if (target.getUsbVendorId() != IAndroidTarget.NO_USB_ID) {
|
||||||
|
set.add(target.getUsbVendorId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write the file header
|
||||||
|
writer.write(ADB_INI_COMMENT1);
|
||||||
|
|
||||||
|
// write the ID count
|
||||||
|
writer.write(Integer.toString(set.size()));
|
||||||
|
writer.write("\n");
|
||||||
|
|
||||||
|
// write header for 2nd section
|
||||||
|
writer.write(ADB_INI_COMMENT2);
|
||||||
|
|
||||||
|
// now write the Id in a text file, one per line.
|
||||||
|
for (Integer i : set) {
|
||||||
|
writer.write(i.toString());
|
||||||
|
writer.write("\n");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SdkManager(String sdkLocation) {
|
private SdkManager(String sdkLocation) {
|
||||||
mSdkLocation = sdkLocation;
|
mSdkLocation = sdkLocation;
|
||||||
|
|||||||
Reference in New Issue
Block a user