aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdkuilib
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2012-05-17 21:46:57 -0700
committerRaphael Moll <ralf@android.com>2012-05-18 15:01:14 -0700
commitb681e01f17149c0ab1da96eabbc6d121e9e8b9d0 (patch)
tree01ac37dd9ddaeabceb1a348101031f32432d48a4 /sdkmanager/libs/sdkuilib
parent78a3b351ffb925f3fdcc8efad0eaaed7b8e58a11 (diff)
downloadsdk-b681e01f17149c0ab1da96eabbc6d121e9e8b9d0.zip
sdk-b681e01f17149c0ab1da96eabbc6d121e9e8b9d0.tar.gz
sdk-b681e01f17149c0ab1da96eabbc6d121e9e8b9d0.tar.bz2
SDK Manager: Settings to control download cache.
SDK Manager > Tools > Options now has a checkbox to deactivate the download cache. It also indicates the path to the cache directory, its size and a button to clear the cache immediately. This only affects the sdk manager files for the download cache, it doesn't clear other cached files such as the lint binaries. Also restructured the settings controller a tiny bit. There's more that could be restructured here but it's not a priority right now. Change-Id: I474e6155bdc041770f3f7664366d0d92bd96d9b0
Diffstat (limited to 'sdkmanager/libs/sdkuilib')
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java18
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java2
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java232
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsDialog.java193
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java39
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackageLoader.java5
-rw-r--r--sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java2
7 files changed, 320 insertions, 171 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java
index 7d730d6..a14337d 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java
@@ -16,6 +16,8 @@
package com.android.sdkuilib.internal.repository;
+import com.android.sdklib.internal.repository.DownloadCache;
+
import java.net.URL;
import java.util.Properties;
@@ -29,29 +31,41 @@ public interface ISettingsPage {
* Type: String.
*/
public static final String KEY_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
+
/**
* Java system setting picked up by {@link URL} for http proxy host.
* Type: String.
*/
public static final String KEY_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
+
/**
* Setting to force using http:// instead of https:// connections.
* Type: Boolean.
* Default: False.
*/
public static final String KEY_FORCE_HTTP = "sdkman.force.http"; //$NON-NLS-1$
+
/**
* Setting to display only packages that are new or updates.
* Type: Boolean.
* Default: True.
*/
public static final String KEY_SHOW_UPDATE_ONLY = "sdkman.show.update.only"; //$NON-NLS-1$
+
/**
* Setting to ask for permission before restarting ADB.
* Type: Boolean.
* Default: False.
*/
public static final String KEY_ASK_ADB_RESTART = "sdkman.ask.adb.restart"; //$NON-NLS-1$
+
+ /**
+ * Setting to use the {@link DownloadCache}, for small manifest XML files.
+ * Type: Boolean.
+ * Default: True.
+ */
+ public static final String KEY_USE_DOWNLOAD_CACHE = "sdkman.use.dl.cache"; //$NON-NLS-1$
+
/**
* Setting to set the density of the monitor.
* Type: Integer.
@@ -60,11 +74,11 @@ public interface ISettingsPage {
public static final String KEY_MONITOR_DENSITY = "sdkman.monitor.density"; //$NON-NLS-1$
/** Loads settings from the given {@link Properties} container and update the page UI. */
- public abstract void loadSettings(Properties in_settings);
+ public abstract void loadSettings(Properties inSettings);
/** Called by the application to retrieve settings from the UI and store them in
* the given {@link Properties} container. */
- public abstract void retrieveSettings(Properties out_settings);
+ public abstract void retrieveSettings(Properties outSettings);
/**
* Called by the application to give a callback that the page should invoke when
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java
index ba1cd2d..62a16d1 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java
@@ -1276,7 +1276,7 @@ class SdkUpdaterLogic {
return;
}
- final boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp();
+ final boolean forceHttp = mUpdaterData.getSettingsController().getSettings().getForceHttp();
mUpdaterData.getTaskFactory().start("Refresh Sources", new ITask() {
@Override
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java
index 2d8b57e..8ccb688 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java
@@ -20,13 +20,14 @@ import com.android.prefs.AndroidLocation;
import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdklib.ISdkLog;
-import org.eclipse.jface.dialogs.MessageDialog;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
import java.util.Properties;
/**
@@ -40,48 +41,113 @@ public class SettingsController {
private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$
- private final Properties mProperties = new Properties();
+ private final ISdkLog mSdkLog;
+ private final Settings mSettings = new Settings();
+
+ public interface OnChangedListener {
+ public void onSettingsChanged(SettingsController controller, Settings oldSettings);
+ }
+ private final List<OnChangedListener> mChangedListeners = new ArrayList<OnChangedListener>(1);
/** The currently associated {@link ISettingsPage}. Can be null. */
private ISettingsPage mSettingsPage;
- private final UpdaterData mUpdaterData;
- public SettingsController(UpdaterData updaterData) {
- mUpdaterData = updaterData;
+ public SettingsController(ISdkLog sdkLog) {
+ mSdkLog = sdkLog;
}
- //--- Access to settings ------------
+ public Settings getSettings() {
+ return mSettings;
+ }
- /**
- * Returns the value of the {@link ISettingsPage#KEY_FORCE_HTTP} setting.
- *
- * @see ISettingsPage#KEY_FORCE_HTTP
- */
- public boolean getForceHttp() {
- return Boolean.parseBoolean(mProperties.getProperty(ISettingsPage.KEY_FORCE_HTTP));
+ public void registerOnChangedListener(OnChangedListener listener) {
+ if (listener != null && !mChangedListeners.contains(listener)) {
+ mChangedListeners.add(listener);
+ }
}
- /**
- * Returns the value of the {@link ISettingsPage#KEY_ASK_ADB_RESTART} setting.
- *
- * @see ISettingsPage#KEY_ASK_ADB_RESTART
- */
- public boolean getAskBeforeAdbRestart() {
- return Boolean.parseBoolean(mProperties.getProperty(ISettingsPage.KEY_ASK_ADB_RESTART));
+ public void unregisterOnChangedListener(OnChangedListener listener) {
+ if (listener != null) {
+ mChangedListeners.remove(listener);
+ }
}
- /**
- * Returns the value of the {@link ISettingsPage#KEY_SHOW_UPDATE_ONLY} setting.
- *
- * @see ISettingsPage#KEY_SHOW_UPDATE_ONLY
- */
- public boolean getShowUpdateOnly() {
- String value = mProperties.getProperty(ISettingsPage.KEY_SHOW_UPDATE_ONLY);
- if (value == null) {
- return true;
+ //--- Access to settings ------------
+
+
+ public static class Settings {
+ private final Properties mProperties = new Properties();
+
+ /** Initialize an empty set of settings. */
+ public Settings() {
+ }
+
+ /** Duplicates a set of settings. */
+ public Settings(Settings settings) {
+ for (Entry<Object, Object> entry : settings.mProperties.entrySet()) {
+ mProperties.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
+ * Returns the value of the {@link ISettingsPage#KEY_FORCE_HTTP} setting.
+ *
+ * @see ISettingsPage#KEY_FORCE_HTTP
+ */
+ public boolean getForceHttp() {
+ return Boolean.parseBoolean(mProperties.getProperty(ISettingsPage.KEY_FORCE_HTTP));
+ }
+
+ /**
+ * Returns the value of the {@link ISettingsPage#KEY_ASK_ADB_RESTART} setting.
+ *
+ * @see ISettingsPage#KEY_ASK_ADB_RESTART
+ */
+ public boolean getAskBeforeAdbRestart() {
+ return Boolean.parseBoolean(mProperties.getProperty(ISettingsPage.KEY_ASK_ADB_RESTART));
+ }
+
+ /**
+ * Returns the value of the {@link ISettingsPage#KEY_USE_DOWNLOAD_CACHE} setting.
+ *
+ * @see ISettingsPage#KEY_USE_DOWNLOAD_CACHE
+ */
+ public boolean getUseDownloadCache() {
+ return Boolean.parseBoolean(
+ mProperties.getProperty(
+ ISettingsPage.KEY_USE_DOWNLOAD_CACHE,
+ Boolean.TRUE.toString()));
+ }
+
+ /**
+ * Returns the value of the {@link ISettingsPage#KEY_SHOW_UPDATE_ONLY} setting.
+ *
+ * @see ISettingsPage#KEY_SHOW_UPDATE_ONLY
+ */
+ public boolean getShowUpdateOnly() {
+ return Boolean.parseBoolean(
+ mProperties.getProperty(
+ ISettingsPage.KEY_SHOW_UPDATE_ONLY,
+ Boolean.TRUE.toString()));
+ }
+
+ /**
+ * Returns the value of the {@link ISettingsPage#KEY_MONITOR_DENSITY} setting
+ * @see ISettingsPage#KEY_MONITOR_DENSITY
+ */
+ public int getMonitorDensity() {
+ String value = mProperties.getProperty(ISettingsPage.KEY_MONITOR_DENSITY, null);
+ if (value == null) {
+ return -1;
+ }
+
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return -1;
+ }
}
- return Boolean.parseBoolean(value);
}
/**
@@ -95,37 +161,21 @@ public class SettingsController {
}
/**
- * Returns the value of the {@link ISettingsPage#KEY_MONITOR_DENSITY} setting
- * @see ISettingsPage#KEY_MONITOR_DENSITY
- */
- public int getMonitorDensity() {
- String value = mProperties.getProperty(ISettingsPage.KEY_MONITOR_DENSITY, null);
- if (value == null) {
- return -1;
- }
-
- try {
- return Integer.parseInt(value);
- } catch (NumberFormatException e) {
- return -1;
- }
- }
-
- /**
* Sets the value of the {@link ISettingsPage#KEY_MONITOR_DENSITY} setting.
*
* @param density the density of the monitor
* @see ISettingsPage#KEY_MONITOR_DENSITY
*/
public void setMonitorDensity(int density) {
- mProperties.setProperty(ISettingsPage.KEY_MONITOR_DENSITY, Integer.toString(density));
+ mSettings.mProperties.setProperty(
+ ISettingsPage.KEY_MONITOR_DENSITY, Integer.toString(density));
}
/**
* Internal helper to set a boolean setting.
*/
void setSetting(String key, boolean value) {
- mProperties.setProperty(key, Boolean.toString(value));
+ mSettings.mProperties.setProperty(key, Boolean.toString(value));
}
//--- Controller methods -------------
@@ -144,7 +194,7 @@ public class SettingsController {
mSettingsPage = settingsPage;
if (settingsPage != null) {
- settingsPage.loadSettings(mProperties);
+ settingsPage.loadSettings(mSettings.mProperties);
settingsPage.setOnSettingsChanged(new ISettingsPage.SettingsChangedCallback() {
@Override
@@ -168,17 +218,19 @@ public class SettingsController {
if (f.exists()) {
fis = new FileInputStream(f);
- mProperties.load(fis);
+ mSettings.mProperties.load(fis);
// Properly reformat some settings to enforce their default value when missing.
- setShowUpdateOnly(getShowUpdateOnly());
- setSetting(ISettingsPage.KEY_ASK_ADB_RESTART, getAskBeforeAdbRestart());
+ setShowUpdateOnly(mSettings.getShowUpdateOnly());
+ setSetting(ISettingsPage.KEY_ASK_ADB_RESTART, mSettings.getAskBeforeAdbRestart());
+ setSetting(ISettingsPage.KEY_USE_DOWNLOAD_CACHE, mSettings.getUseDownloadCache());
}
} catch (Exception e) {
- ISdkLog log = mUpdaterData.getSdkLog();
- if (log != null) {
- log.error(e, "Failed to load settings from .android folder. Path is '%1$s'.", path);
+ if (mSdkLog != null) {
+ mSdkLog.error(e,
+ "Failed to load settings from .android folder. Path is '%1$s'.",
+ path);
}
} finally {
if (fis != null) {
@@ -204,34 +256,27 @@ public class SettingsController {
fos = new FileOutputStream(f);
- mProperties.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$
+ mSettings.mProperties.store(fos, "## Settings for Android Tool"); //$NON-NLS-1$
} catch (Exception e) {
- ISdkLog log = mUpdaterData.getSdkLog();
-
- if (log != null) {
- log.error(e, "Failed to save settings at '%1$s'", path);
- }
+ if (mSdkLog != null) {
+ // This is important enough that we want to really nag the user about it
+ String reason = null;
+
+ if (e instanceof FileNotFoundException) {
+ reason = "File not found";
+ } else if (e instanceof AndroidLocationException) {
+ reason = ".android folder not found, please define ANDROID_SDK_HOME";
+ } else if (e.getMessage() != null) {
+ reason = String.format("%1$s: %2$s",
+ e.getClass().getSimpleName(),
+ e.getMessage());
+ } else {
+ reason = e.getClass().getName();
+ }
- // This is important enough that we want to really nag the user about it
- String reason = null;
-
- if (e instanceof FileNotFoundException) {
- reason = "File not found";
- } else if (e instanceof AndroidLocationException) {
- reason = ".android folder not found, please define ANDROID_SDK_HOME";
- } else if (e.getMessage() != null) {
- reason = String.format("%1$s: %2$s", e.getClass().getSimpleName(), e.getMessage());
- } else {
- reason = e.getClass().getName();
+ mSdkLog.error(e, "Failed to save settings file '%1$s': %2$s", path, reason);
}
-
- MessageDialog.openInformation(mUpdaterData.getWindowShell(),
- "SDK Manager Settings",
- String.format(
- "The Android SDK and AVD Manager failed to save its settings (%1$s) at %2$s",
- reason, path));
-
} finally {
if (fos != null) {
try {
@@ -243,28 +288,23 @@ public class SettingsController {
}
/**
- * When settings have changed: retrieve the new settings, apply them and save them.
- *
- * This updates Java system properties for the HTTP proxy.
+ * When settings have changed: retrieve the new settings, apply them, save them
+ * and notify on-settings-changed listeners.
*/
private void onSettingsChanged() {
if (mSettingsPage == null) {
return;
}
- String oldHttpsSetting = mProperties.getProperty(ISettingsPage.KEY_FORCE_HTTP,
- Boolean.FALSE.toString());
-
- mSettingsPage.retrieveSettings(mProperties);
+ Settings oldSettings = new Settings(mSettings);
+ mSettingsPage.retrieveSettings(mSettings.mProperties);
applySettings();
saveSettings();
- String newHttpsSetting = mProperties.getProperty(ISettingsPage.KEY_FORCE_HTTP,
- Boolean.FALSE.toString());
- if (!newHttpsSetting.equals(oldHttpsSetting)) {
- // In case the HTTP/HTTPS setting changes, force sources to be reloaded
- // (this only refreshes sources that the user has already tried to open.)
- mUpdaterData.refreshSources(false /*forceFetching*/);
+ for (OnChangedListener listener : mChangedListeners) {
+ try {
+ listener.onSettingsChanged(this, oldSettings);
+ } catch (Throwable ignore) {}
}
}
@@ -275,9 +315,9 @@ public class SettingsController {
Properties props = System.getProperties();
// Get the configured HTTP proxy settings
- String proxyHost = mProperties.getProperty(ISettingsPage.KEY_HTTP_PROXY_HOST,
+ String proxyHost = mSettings.mProperties.getProperty(ISettingsPage.KEY_HTTP_PROXY_HOST,
""); //$NON-NLS-1$
- String proxyPort = mProperties.getProperty(ISettingsPage.KEY_HTTP_PROXY_PORT,
+ String proxyPort = mSettings.mProperties.getProperty(ISettingsPage.KEY_HTTP_PROXY_PORT,
""); //$NON-NLS-1$
// Set both the HTTP and HTTPS proxy system properties.
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsDialog.java
index a90002c..af7cc6e 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsDialog.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsDialog.java
@@ -16,6 +16,9 @@
package com.android.sdkuilib.internal.repository;
+import com.android.sdklib.internal.repository.DownloadCache;
+import com.android.sdklib.internal.repository.DownloadCache.Strategy;
+import com.android.sdklib.util.FormatUtil;
import com.android.sdkuilib.ui.GridDataBuilder;
import com.android.sdkuilib.ui.GridLayoutBuilder;
@@ -35,19 +38,18 @@ import java.util.Properties;
public class SettingsDialog extends UpdaterBaseDialog implements ISettingsPage {
+
// data members
+ private final DownloadCache mDownloadCache = new DownloadCache(Strategy.SERVE_CACHE);
private final SettingsController mSettingsController;
private SettingsChangedCallback mSettingsChangedCallback;
// UI widgets
- private Group mProxySettingsGroup;
- private Group mMiscGroup;
- private Label mProxyServerLabel;
- private Label mProxyPortLabel;
- private Text mProxyServerText;
- private Text mProxyPortText;
- private Button mForceHttpCheck;
- private Button mAskAdbRestartCheck;
+ private Text mTextProxyServer;
+ private Text mTextProxyPort;
+ private Button mCheckUseCache;
+ private Button mCheckForceHttp;
+ private Button mCheckAskAdbRestart;
private SelectionAdapter mApplyOnSelected = new SelectionAdapter() {
@Override
@@ -62,6 +64,7 @@ public class SettingsDialog extends UpdaterBaseDialog implements ISettingsPage {
applyNewSettings(); //$hide$
}
};
+ private Text mTextCacheSize;
public SettingsDialog(Shell parentShell, UpdaterData updaterData) {
super(parentShell, updaterData, "Settings" /*title*/);
@@ -74,53 +77,102 @@ public class SettingsDialog extends UpdaterBaseDialog implements ISettingsPage {
super.createContents();
Shell shell = getShell();
- mProxySettingsGroup = new Group(shell, SWT.NONE);
- mProxySettingsGroup.setText("Proxy Settings");
- GridDataBuilder.create(mProxySettingsGroup).fill().grab().hSpan(2);
- GridLayoutBuilder.create(mProxySettingsGroup).columns(2);
-
- mProxyServerLabel = new Label(mProxySettingsGroup, SWT.NONE);
- GridDataBuilder.create(mProxyServerLabel).hRight().vCenter();
- mProxyServerLabel.setText("HTTP Proxy Server");
- String tooltip = "The DNS name or IP of the HTTP proxy server to use. " +
- "When empty, no HTTP proxy is used.";
- mProxyServerLabel.setToolTipText(tooltip);
-
- mProxyServerText = new Text(mProxySettingsGroup, SWT.BORDER);
- GridDataBuilder.create(mProxyServerText).hFill().hGrab().vCenter();
- mProxyServerText.addModifyListener(mApplyOnModified);
- mProxyServerText.setToolTipText(tooltip);
-
- mProxyPortLabel = new Label(mProxySettingsGroup, SWT.NONE);
- GridDataBuilder.create(mProxyPortLabel).hRight().vCenter();
- mProxyPortLabel.setText("HTTP Proxy Port");
- tooltip = "The port of the HTTP proxy server to use. " +
- "When empty, the default for HTTP or HTTPS is used.";
- mProxyPortLabel.setToolTipText(tooltip);
-
- mProxyPortText = new Text(mProxySettingsGroup, SWT.BORDER);
- GridDataBuilder.create(mProxyPortText).hFill().hGrab().vCenter();
- mProxyPortText.addModifyListener(mApplyOnModified);
- mProxyPortText.setToolTipText(tooltip);
-
- mMiscGroup = new Group(shell, SWT.NONE);
- mMiscGroup.setText("Misc");
- GridDataBuilder.create(mMiscGroup).fill().grab().hSpan(2);
- GridLayoutBuilder.create(mMiscGroup).columns(2);
-
- mForceHttpCheck = new Button(mMiscGroup, SWT.CHECK);
- GridDataBuilder.create(mForceHttpCheck).hFill().hGrab().vCenter().hSpan(2);
- mForceHttpCheck.setText("Force https://... sources to be fetched using http://...");
- mForceHttpCheck.setToolTipText("If you are not able to connect to the official Android repository " +
+ Group group = new Group(shell, SWT.NONE);
+ group.setText("Proxy Settings");
+ GridDataBuilder.create(group).fill().grab().hSpan(2);
+ GridLayoutBuilder.create(group).columns(2);
+
+ Label label = new Label(group, SWT.NONE);
+ GridDataBuilder.create(label).hRight().vCenter();
+ label.setText("HTTP Proxy Server");
+ String tooltip = "The hostname or IP of the HTTP & HTTPS proxy server to use (e.g. proxy.example.com). " +
+ "When empty, the default Java proxy setting is used.";
+ label.setToolTipText(tooltip);
+
+ mTextProxyServer = new Text(group, SWT.BORDER);
+ GridDataBuilder.create(mTextProxyServer).hFill().hGrab().vCenter();
+ mTextProxyServer.addModifyListener(mApplyOnModified);
+ mTextProxyServer.setToolTipText(tooltip);
+
+ label = new Label(group, SWT.NONE);
+ GridDataBuilder.create(label).hRight().vCenter();
+ label.setText("HTTP Proxy Port");
+ tooltip = "The port of the HTTP & HTTPS proxy server to use (e.g. 3128). " +
+ "When empty, the default Java proxy setting is used.";
+ label.setToolTipText(tooltip);
+
+ mTextProxyPort = new Text(group, SWT.BORDER);
+ GridDataBuilder.create(mTextProxyPort).hFill().hGrab().vCenter();
+ mTextProxyPort.addModifyListener(mApplyOnModified);
+ mTextProxyPort.setToolTipText(tooltip);
+
+ // ----
+ group = new Group(shell, SWT.NONE);
+ group.setText("Manifest Cache");
+ GridDataBuilder.create(group).fill().grab().hSpan(2);
+ GridLayoutBuilder.create(group).columns(3);
+
+ label = new Label(group, SWT.NONE);
+ GridDataBuilder.create(label).hRight().vCenter();
+ label.setText("Directory:");
+
+ Text text = new Text(group, SWT.NONE);
+ GridDataBuilder.create(text).hFill().hGrab().vCenter().hSpan(2);
+ text.setEnabled(false);
+ text.setText(mDownloadCache.getCacheRoot().getAbsolutePath());
+
+ label = new Label(group, SWT.NONE);
+ GridDataBuilder.create(label).hRight().vCenter();
+ label.setText("Current Size:");
+
+ mTextCacheSize = new Text(group, SWT.NONE);
+ GridDataBuilder.create(mTextCacheSize).hFill().hGrab().vCenter().hSpan(2);
+ mTextCacheSize.setEnabled(false);
+ updateDownloadCacheSize();
+
+ mCheckUseCache = new Button(group, SWT.CHECK);
+ GridDataBuilder.create(mCheckUseCache).vCenter().hSpan(1);
+ mCheckUseCache.setText("Use download cache");
+ mCheckUseCache.setToolTipText("When checked, small manifest files are cached locally. " +
+ "Large binary files are never cached locally.");
+ mCheckUseCache.addSelectionListener(mApplyOnSelected);
+
+ label = new Label(group, SWT.NONE);
+ GridDataBuilder.create(label).hFill().hGrab().hSpan(1);
+
+ Button button = new Button(group, SWT.PUSH);
+ GridDataBuilder.create(button).vCenter().hSpan(1);
+ button.setText("Clear Cache");
+ button.setToolTipText("Deletes all cached files.");
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ mDownloadCache.clearCache();
+ updateDownloadCacheSize();
+ }
+ });
+
+ // ----
+ group = new Group(shell, SWT.NONE);
+ group.setText("Misc");
+ GridDataBuilder.create(group).fill().grab().hSpan(2);
+ GridLayoutBuilder.create(group).columns(2);
+
+ mCheckForceHttp = new Button(group, SWT.CHECK);
+ GridDataBuilder.create(mCheckForceHttp).hFill().hGrab().vCenter().hSpan(2);
+ mCheckForceHttp.setText("Force https://... sources to be fetched using http://...");
+ mCheckForceHttp.setToolTipText(
+ "If you are not able to connect to the official Android repository " +
"using HTTPS, enable this setting to force accessing it via HTTP.");
- mForceHttpCheck.addSelectionListener(mApplyOnSelected);
+ mCheckForceHttp.addSelectionListener(mApplyOnSelected);
- mAskAdbRestartCheck = new Button(mMiscGroup, SWT.CHECK);
- GridDataBuilder.create(mAskAdbRestartCheck).hFill().hGrab().vCenter().hSpan(2);
- mAskAdbRestartCheck.setText("Ask before restarting ADB");
- mAskAdbRestartCheck.setToolTipText("When checked, the user will be asked for permission " +
+ mCheckAskAdbRestart = new Button(group, SWT.CHECK);
+ GridDataBuilder.create(mCheckAskAdbRestart).hFill().hGrab().vCenter().hSpan(2);
+ mCheckAskAdbRestart.setText("Ask before restarting ADB");
+ mCheckAskAdbRestart.setToolTipText(
+ "When checked, the user will be asked for permission " +
"to restart ADB after updating an addon-on package or a tool package.");
- mAskAdbRestartCheck.addSelectionListener(mApplyOnSelected);
+ mCheckAskAdbRestart.addSelectionListener(mApplyOnSelected);
Label filler = new Label(shell, SWT.NONE);
GridDataBuilder.create(filler).hFill().hGrab();
@@ -149,23 +201,29 @@ public class SettingsDialog extends UpdaterBaseDialog implements ISettingsPage {
/** Loads settings from the given {@link Properties} container and update the page UI. */
@Override
- public void loadSettings(Properties in_settings) {
- mProxyServerText.setText(in_settings.getProperty(KEY_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
- mProxyPortText.setText( in_settings.getProperty(KEY_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
- mForceHttpCheck.setSelection(Boolean.parseBoolean(in_settings.getProperty(KEY_FORCE_HTTP)));
- mAskAdbRestartCheck.setSelection(Boolean.parseBoolean(in_settings.getProperty(KEY_ASK_ADB_RESTART)));
+ public void loadSettings(Properties inSettings) {
+ mTextProxyServer.setText(inSettings.getProperty(KEY_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
+ mTextProxyPort.setText( inSettings.getProperty(KEY_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
+ mCheckForceHttp.setSelection(
+ Boolean.parseBoolean(inSettings.getProperty(KEY_FORCE_HTTP)));
+ mCheckAskAdbRestart.setSelection(
+ Boolean.parseBoolean(inSettings.getProperty(KEY_ASK_ADB_RESTART)));
+ mCheckUseCache.setSelection(
+ Boolean.parseBoolean(inSettings.getProperty(KEY_USE_DOWNLOAD_CACHE)));
}
/** Called by the application to retrieve settings from the UI and store them in
* the given {@link Properties} container. */
@Override
- public void retrieveSettings(Properties out_settings) {
- out_settings.setProperty(KEY_HTTP_PROXY_HOST, mProxyServerText.getText());
- out_settings.setProperty(KEY_HTTP_PROXY_PORT, mProxyPortText.getText());
- out_settings.setProperty(KEY_FORCE_HTTP,
- Boolean.toString(mForceHttpCheck.getSelection()));
- out_settings.setProperty(KEY_ASK_ADB_RESTART,
- Boolean.toString(mAskAdbRestartCheck.getSelection()));
+ public void retrieveSettings(Properties outSettings) {
+ outSettings.setProperty(KEY_HTTP_PROXY_HOST, mTextProxyServer.getText());
+ outSettings.setProperty(KEY_HTTP_PROXY_PORT, mTextProxyPort.getText());
+ outSettings.setProperty(KEY_FORCE_HTTP,
+ Boolean.toString(mCheckForceHttp.getSelection()));
+ outSettings.setProperty(KEY_ASK_ADB_RESTART,
+ Boolean.toString(mCheckAskAdbRestart.getSelection()));
+ outSettings.setProperty(KEY_USE_DOWNLOAD_CACHE,
+ Boolean.toString(mCheckUseCache.getSelection()));
}
/**
@@ -189,6 +247,13 @@ public class SettingsDialog extends UpdaterBaseDialog implements ISettingsPage {
}
}
+ private void updateDownloadCacheSize() {
+ long size = mDownloadCache.getCurrentSize();
+ String str = FormatUtil.byteSizeToString(size);
+ mTextCacheSize.setText(str);
+ }
+
+
// End of hiding from SWT Designer
//$hide<<$
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
index af40d78..e64075a 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
@@ -44,6 +44,7 @@ import com.android.sdklib.repository.SdkAddonConstants;
import com.android.sdklib.repository.SdkRepoConstants;
import com.android.sdklib.util.LineUtil;
import com.android.sdklib.util.SparseIntArray;
+import com.android.sdkuilib.internal.repository.SettingsController.OnChangedListener;
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
import com.android.sdkuilib.internal.repository.sdkman2.PackageLoader;
import com.android.sdkuilib.internal.repository.sdkman2.SdkUpdaterWindowImpl2;
@@ -113,9 +114,33 @@ public class UpdaterData implements IUpdaterData {
mOsSdkRoot = osSdkRoot;
mSdkLog = sdkLog;
- mSettingsController = new SettingsController(this);
+ mSettingsController = new SettingsController(sdkLog);
initSdk();
+
+ mSettingsController.registerOnChangedListener(new OnChangedListener() {
+ @Override
+ public void onSettingsChanged(
+ SettingsController controller,
+ SettingsController.Settings oldSettings) {
+
+ // Reset the download cache if it doesn't match the right strategy.
+ // The cache instance gets lazily recreated later in getDownloadCache().
+ if (mDownloadCache != null) {
+ if (controller.getSettings().getUseDownloadCache() &&
+ mDownloadCache.getStrategy() != DownloadCache.Strategy.FRESH_CACHE) {
+ mDownloadCache = null;
+ } else if (!controller.getSettings().getUseDownloadCache() &&
+ mDownloadCache.getStrategy() != DownloadCache.Strategy.DIRECT) {
+ mDownloadCache = null;
+ }
+ }
+
+ if (oldSettings.getForceHttp() != controller.getSettings().getForceHttp()) {
+ refreshSources(false /*forceFetching*/);
+ }
+ }
+ });
}
// ----- getters, setters ----
@@ -127,7 +152,10 @@ public class UpdaterData implements IUpdaterData {
@Override
public DownloadCache getDownloadCache() {
if (mDownloadCache == null) {
- mDownloadCache = new DownloadCache(DownloadCache.Strategy.FRESH_CACHE);
+ mDownloadCache = new DownloadCache(
+ mSettingsController.getSettings().getUseDownloadCache() ?
+ DownloadCache.Strategy.FRESH_CACHE :
+ DownloadCache.Strategy.DIRECT);
}
return mDownloadCache;
}
@@ -382,7 +410,7 @@ public class UpdaterData implements IUpdaterData {
// this will accumulate all the packages installed.
final List<Archive> newlyInstalledArchives = new ArrayList<Archive>();
- final boolean forceHttp = getSettingsController().getForceHttp();
+ final boolean forceHttp = getSettingsController().getSettings().getForceHttp();
// sort all archives based on their dependency level.
Collections.sort(archives, new InstallOrderComparator());
@@ -609,7 +637,8 @@ public class UpdaterData implements IUpdaterData {
private void askForAdbRestart(ITaskMonitor monitor) {
final boolean[] canRestart = new boolean[] { true };
- if (getWindowShell() != null && getSettingsController().getAskBeforeAdbRestart()) {
+ if (getWindowShell() != null &&
+ getSettingsController().getSettings().getAskBeforeAdbRestart()) {
// need to ask for permission first
final Shell shell = getWindowShell();
if (shell != null && !shell.isDisposed()) {
@@ -1001,7 +1030,7 @@ public class UpdaterData implements IUpdaterData {
public void refreshSources(final boolean forceFetching) {
assert mTaskFactory != null;
- final boolean forceHttp = getSettingsController().getForceHttp();
+ final boolean forceHttp = getSettingsController().getSettings().getForceHttp();
mTaskFactory.start("Refresh Sources", new ITask() {
@Override
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackageLoader.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackageLoader.java
index ecbefb7..4ad78b8 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackageLoader.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackageLoader.java
@@ -206,7 +206,8 @@ public class PackageLoader {
}
// get remote packages
- boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp();
+ boolean forceHttp =
+ mUpdaterData.getSettingsController().getSettings().getForceHttp();
loadRemoteAddonsList(monitor.createSubMonitor(1));
SdkSource[] sources = mUpdaterData.getSources().getAllSources();
@@ -432,7 +433,7 @@ public class PackageLoader {
}
}
- if (mUpdaterData.getSettingsController().getForceHttp()) {
+ if (mUpdaterData.getSettingsController().getSettings().getForceHttp()) {
url = url.replaceAll("https://", "http://"); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java
index edecb17..e2ac96b 100644
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java
@@ -417,7 +417,7 @@ final class AvdStartDialog extends GridDialog {
*/
private int getMonitorDpi() {
if (mSettingsController != null) {
- sMonitorDpi = mSettingsController.getMonitorDensity();
+ sMonitorDpi = mSettingsController.getSettings().getMonitorDensity();
}
if (sMonitorDpi == -1) { // first time? try to get a value