diff options
author | Xavier Ducrohet <xav@android.com> | 2009-05-21 17:46:12 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2009-05-21 18:11:36 -0700 |
commit | 55294ff87b58bb42ed65d762f873deb2956be1a2 (patch) | |
tree | 7dc62388fab087ac6eb86f343d5e8635b4ac48ac /sdkmanager | |
parent | 15ad13f6d499949256e3163f92bdbe4ce718055f (diff) | |
download | sdk-55294ff87b58bb42ed65d762f873deb2956be1a2.zip sdk-55294ff87b58bb42ed65d762f873deb2956be1a2.tar.gz sdk-55294ff87b58bb42ed65d762f873deb2956be1a2.tar.bz2 |
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.
Diffstat (limited to 'sdkmanager')
-rw-r--r-- | sdkmanager/app/src/com/android/sdkmanager/Main.java | 33 | ||||
-rw-r--r-- | sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java | 55 |
2 files changed, 56 insertions, 32 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java index 8c9ad26..94f3062 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/Main.java +++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java @@ -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 - } - } } } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java index 5827aa1..65fe5f0 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java @@ -16,15 +16,20 @@ package com.android.sdklib; +import com.android.prefs.AndroidLocation; +import com.android.prefs.AndroidLocation.AndroidLocationException; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,6 +73,16 @@ public final class SdkManager { 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 */ private final String mSdkLocation; private IAndroidTarget[] mTargets; @@ -132,6 +147,46 @@ public final class SdkManager { 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) { mSdkLocation = sdkLocation; |