diff options
author | Raphael Moll <ralf@android.com> | 2011-02-17 16:17:06 -0800 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2011-02-17 16:27:32 -0800 |
commit | ab3ac497d03c1b0e74694d8631046e4e4a5e2d7d (patch) | |
tree | aa61e88702d9da190e16c0749d5049503b568ac7 /sdkmanager | |
parent | 5f3a13dc5b51dbd3eb88daf6f9bd57059aa046dd (diff) | |
download | sdk-ab3ac497d03c1b0e74694d8631046e4e4a5e2d7d.zip sdk-ab3ac497d03c1b0e74694d8631046e4e4a5e2d7d.tar.gz sdk-ab3ac497d03c1b0e74694d8631046e4e4a5e2d7d.tar.bz2 |
Adjust AVD create dialog to match sdcard size limits.
Change mksdcard to a minimum of 9 MiB, which is what
we enforce in the UI (I believe the 8 MiB min was obsoleted
by the 9 MiB one.)
Also warn the user about the min/max sdcard size properly
directly in the creation dialog, instead of relying on
mksdcard to fail later.
Change-Id: I30bc425ed6b75d8a00965e9e2e25890bd9bd8b39
Diffstat (limited to 'sdkmanager')
3 files changed, 52 insertions, 44 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java index eba8e07..9bca42b 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java @@ -138,7 +138,16 @@ public final class AvdManager { /** * Pattern for matching SD Card sizes, e.g. "4K" or "16M". */ - public final static Pattern SDCARD_SIZE_PATTERN = Pattern.compile("(\\d+)([MK])"); //$NON-NLS-1$ + public final static Pattern SDCARD_SIZE_PATTERN = Pattern.compile("(\\d+)([KMG])"); //$NON-NLS-1$ + + /** + * Minimal size of an SDCard image file in bytes. Currently 9 MiB. + */ + public static final long SDCARD_MIN_BYTE_SIZE = 9<<20; + /** + * Maximal size of an SDCard image file in bytes. Currently 1023 GiB. + */ + public static final long SDCARD_MAX_BYTE_SIZE = 1023L<<30; /** Regex used to validate characters that compose an AVD name. */ public final static Pattern RE_AVD_NAME = Pattern.compile("[a-zA-Z0-9._-]+"); //$NON-NLS-1$ @@ -640,26 +649,18 @@ public final class AvdManager { try { long sdcardSize = Long.parseLong(m.group(1)); - // prevent overflow: no more than 999GB - // 10 digit for MiB, 13 for KiB - int digitCount = m.group(1).length(); - String sdcardSizeModifier = m.group(2); - if ("K".equals(sdcardSizeModifier)) { - sdcardSize *= 1024L; - } else { // must be "M" per the pattern - sdcardSize *= 1024L * 1024L; - digitCount += 3; // convert the number of digit into "KiB" - } - - if (digitCount >= 13) { - log.error(null, "SD Card size is too big!"); - needCleanup = true; - return null; + if ("K".equals(sdcardSizeModifier)) { //$NON-NLS-1$ + sdcardSize <<= 10; + } else if ("M".equals(sdcardSizeModifier)) { //$NON-NLS-1$ + sdcardSize <<= 20; + } else if ("G".equals(sdcardSizeModifier)) { //$NON-NLS-1$ + sdcardSize <<= 30; } - if (sdcardSize < 9 * 1024 * 1024) { - log.error(null, "SD Card size must be at least 9MB"); + if (sdcardSize < SDCARD_MIN_BYTE_SIZE || + sdcardSize > SDCARD_MAX_BYTE_SIZE) { + log.error(null, "SD Card size must be in the range 9 MiB..1023 GiB."); needCleanup = true; return null; } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java index 4411034..7197ecd 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java @@ -322,6 +322,7 @@ final class AvdCreationDialog extends GridDialog { mSdCardSizeCombo = new Combo(sdCardGroup, SWT.DROP_DOWN | SWT.READ_ONLY); mSdCardSizeCombo.add("KiB"); mSdCardSizeCombo.add("MiB"); + mSdCardSizeCombo.add("GiB"); mSdCardSizeCombo.select(1); mSdCardSizeCombo.addSelectionListener(validateListener); @@ -918,30 +919,25 @@ final class AvdCreationDialog extends GridDialog { } else { String valueString = mSdCardSize.getText(); if (valueString.length() > 0) { - // prevent overflow: no more than 999GB - // 10 digit for MiB, 13 for KiB - if (valueString.length() >= 10 + - (mSdCardSizeCombo.getSelectionIndex() == 0 ? 3 : 0)) { - error = "SD Card size is too big!"; - } else { - try { - long value = Long.parseLong(valueString); - - switch (mSdCardSizeCombo.getSelectionIndex()) { - case 0: - value *= 1024L; - break; - case 1: - value *= 1024L * 1024L; - break; - } - - if (value < 9 * 1024 * 1024) { - error = "SD Card size must be at least 9 MiB"; - } - } catch (NumberFormatException e) { - // will never happen thanks to the VerifyListener. + long value = 0; + try { + value = Long.parseLong(valueString); + + int sizeIndex = mSdCardSizeCombo.getSelectionIndex(); + if (sizeIndex >= 0) { + // index 0 shifts by 10 (1024=K), index 1 by 20, etc. + value <<= 10*(1 + sizeIndex); } + + if (value < AvdManager.SDCARD_MIN_BYTE_SIZE || + value > AvdManager.SDCARD_MAX_BYTE_SIZE) { + value = 0; + } + } catch (Exception e) { + // ignore, we'll test value below. + } + if (value <= 0) { + error = "SD Card size is invalid. Range is 9 MiB..1023 GiB."; } } } @@ -1112,10 +1108,13 @@ final class AvdCreationDialog extends GridDialog { // add the unit switch (mSdCardSizeCombo.getSelectionIndex()) { case 0: - sdName += "K"; + sdName += "K"; //$NON-NLS-1$ break; case 1: - sdName += "M"; + sdName += "M"; //$NON-NLS-1$ + break; + case 2: + sdName += "G"; //$NON-NLS-1$ break; default: // shouldn't be here diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/MessageBoxLog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/MessageBoxLog.java index d5c1818..89edb2f 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/MessageBoxLog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/MessageBoxLog.java @@ -95,7 +95,15 @@ public final class MessageBoxLog implements ISdkLog { if (logMessages.size() > 0) { final StringBuilder sb = new StringBuilder(mMessage + "\n\n"); for (String msg : logMessages) { - sb.append(msg); + if (msg.length() > 0) { + if (msg.charAt(0) != '\n') { + int n = sb.length(); + if (n > 0 && sb.charAt(n-1) != '\n') { + sb.append('\n'); + } + } + sb.append(msg); + } } // display the message |