com.android.sdklib.internal.repository.updater
Class UpdaterData

java.lang.Object
  extended by com.android.sdklib.internal.repository.updater.UpdaterData
All Implemented Interfaces:
IUpdaterData

public class UpdaterData
extends java.lang.Object
implements IUpdaterData

Data shared by the SDK Manager updaters.


Field Summary
static int NO_TOOLS_MSG
           
static int TOOLS_MSG_UPDATED_FROM_ADT
           
static int TOOLS_MSG_UPDATED_FROM_SDKMAN
           
 
Constructor Summary
UpdaterData(java.lang.String osSdkRoot, com.android.utils.ILogger sdkLog)
          Creates a new updater data.
 
Method Summary
 void addListeners(ISdkChangeListener listener)
          Adds a listener (ISdkChangeListener) that is notified when the SDK is reloaded.
protected  void askForAdbRestart(ITaskMonitor monitor)
          Attempts to restart ADB.
 void broadcastOnSdkLoaded()
          Safely invoke all the registered ISdkChangeListener.onSdkLoaded().
 boolean checkIfInitFailed()
          Check if any error occurred during initialization.
protected  ArchiveInstaller createArchiveInstaler()
          Internal helper to return a new ArchiveInstaller.
protected  void displayInitError(java.lang.String error)
           
 AvdManager getAvdManager()
           
 DownloadCache getDownloadCache()
           
 Package[] getInstalledPackages(ITaskMonitor monitor)
          Returns the list of installed packages, parsing them if this has not yet been done.
 LocalSdkParser getLocalSdkParser()
           
 java.lang.String getOsSdkRoot()
           
 PackageLoader getPackageLoader()
           
 com.android.utils.ILogger getSdkLog()
           
 SdkManager getSdkManager()
           
 SettingsController getSettingsController()
           
 SdkSources getSources()
           
 ITaskFactory getTaskFactory()
           
protected  void initSdk()
          Initializes the SdkManager and the AvdManager.
protected  SettingsController initSettingsController()
          Initializes the SettingsController Extracted so that we can override this in unit tests.
protected  java.util.List<Archive> installArchives(java.util.List<ArchiveInfo> archives, int flags)
          Install the list of given Archives.
 void listRemotePackages_NoGUI(boolean includeAll, boolean extendedOutput)
          Lists remote packages available for install using updateOrInstallAll_NoGUI(java.util.Collection, boolean, boolean, java.lang.String).
protected  void notifyToolsNeedsToBeRestarted(int flags)
           
 void refreshSources(boolean forceFetching)
          Refresh all sources.
 void reloadAvds()
          Reloads the AVDs.
 void reloadSdk()
          Reloads the SDK content (targets).
 void removeListener(ISdkChangeListener listener)
          Removes a listener (ISdkChangeListener) that is notified when the SDK is reloaded.
protected  void runOnUiThread(java.lang.Runnable r)
          Runs a runnable on the UI thread.
protected  void setSdkManager(SdkManager sdkManager)
           
 void setTaskFactory(ITaskFactory taskFactory)
           
 void setupDefaultSources()
          Sets up the default sources:
- the default google SDK repository,
- the user sources from prefs
- the extra repo URLs from the environment,
- and finally the extra user repo URLs from the environment.
 java.util.List<Archive> updateOrInstallAll_NoGUI(java.util.Collection<java.lang.String> pkgFilter, boolean includeAll, boolean dryMode, java.lang.String acceptLicense)
          Tries to update all the *existing* local packages.
 java.util.List<Archive> updateOrInstallAll_WithGUI(java.util.Collection<Archive> selectedArchives, boolean includeObsoletes, int flags)
          Tries to update all the *existing* local packages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_TOOLS_MSG

public static final int NO_TOOLS_MSG
See Also:
Constant Field Values

TOOLS_MSG_UPDATED_FROM_ADT

public static final int TOOLS_MSG_UPDATED_FROM_ADT
See Also:
Constant Field Values

TOOLS_MSG_UPDATED_FROM_SDKMAN

public static final int TOOLS_MSG_UPDATED_FROM_SDKMAN
See Also:
Constant Field Values
Constructor Detail

UpdaterData

public UpdaterData(java.lang.String osSdkRoot,
                   com.android.utils.ILogger sdkLog)
Creates a new updater data.

Parameters:
sdkLog - Logger. Cannot be null.
osSdkRoot - The OS path to the SDK root.
Method Detail

getOsSdkRoot

public java.lang.String getOsSdkRoot()

getDownloadCache

public DownloadCache getDownloadCache()
Specified by:
getDownloadCache in interface IUpdaterData

setTaskFactory

public void setTaskFactory(ITaskFactory taskFactory)

getTaskFactory

public ITaskFactory getTaskFactory()
Specified by:
getTaskFactory in interface IUpdaterData

getSources

public SdkSources getSources()

getLocalSdkParser

public LocalSdkParser getLocalSdkParser()

getSdkLog

public com.android.utils.ILogger getSdkLog()
Specified by:
getSdkLog in interface IUpdaterData

getSdkManager

public SdkManager getSdkManager()
Specified by:
getSdkManager in interface IUpdaterData

getAvdManager

public AvdManager getAvdManager()
Specified by:
getAvdManager in interface IUpdaterData

getSettingsController

public SettingsController getSettingsController()
Specified by:
getSettingsController in interface IUpdaterData

addListeners

public void addListeners(ISdkChangeListener listener)
Adds a listener (ISdkChangeListener) that is notified when the SDK is reloaded.


removeListener

public void removeListener(ISdkChangeListener listener)
Removes a listener (ISdkChangeListener) that is notified when the SDK is reloaded.


getPackageLoader

public PackageLoader getPackageLoader()

checkIfInitFailed

public boolean checkIfInitFailed()
Check if any error occurred during initialization. If it did, display an error message.

Returns:
True if an error occurred, false if we should continue.

displayInitError

protected void displayInitError(java.lang.String error)

runOnUiThread

protected void runOnUiThread(@NonNull
                             java.lang.Runnable r)
Runs a runnable on the UI thread. The base implementation just runs the runnable right away.

Parameters:
r - Non-null runnable.

initSdk

protected void initSdk()
Initializes the SdkManager and the AvdManager. Extracted so that we can override this in unit tests.


initSettingsController

protected SettingsController initSettingsController()
Initializes the SettingsController Extracted so that we can override this in unit tests.


setSdkManager

protected void setSdkManager(SdkManager sdkManager)

reloadSdk

public void reloadSdk()
Reloads the SDK content (targets).

This also reloads the AVDs in case their status changed.

This does not notify the listeners (ISdkChangeListener).


reloadAvds

public void reloadAvds()
Reloads the AVDs.

This does not notify the listeners.


setupDefaultSources

public void setupDefaultSources()
Sets up the default sources:
- the default google SDK repository,
- the user sources from prefs
- the extra repo URLs from the environment,
- and finally the extra user repo URLs from the environment.


getInstalledPackages

public Package[] getInstalledPackages(ITaskMonitor monitor)
Returns the list of installed packages, parsing them if this has not yet been done.

The package list is cached in the LocalSdkParser and will be reset when reloadSdk() is invoked.


installArchives

protected java.util.List<Archive> installArchives(java.util.List<ArchiveInfo> archives,
                                                  int flags)
Install the list of given Archives. This is invoked by the user selecting some packages in the remote page and then clicking "install selected".

Parameters:
archives - The archives to install. Incompatible ones will be skipped.
flags - Optional flags for the installer, such as NO_TOOLS_MSG.
Returns:
A list of archives that have been installed. Can be empty but not null.

askForAdbRestart

protected void askForAdbRestart(ITaskMonitor monitor)
Attempts to restart ADB.

If the "ask before restart" setting is set (the default), prompt the user whether now is a good time to restart ADB.


notifyToolsNeedsToBeRestarted

protected void notifyToolsNeedsToBeRestarted(int flags)

listRemotePackages_NoGUI

public void listRemotePackages_NoGUI(boolean includeAll,
                                     boolean extendedOutput)
Lists remote packages available for install using updateOrInstallAll_NoGUI(java.util.Collection, boolean, boolean, java.lang.String).

Parameters:
includeAll - True to list and install all packages, including obsolete ones.
extendedOutput - True to display more details on each package.

updateOrInstallAll_WithGUI

public java.util.List<Archive> updateOrInstallAll_WithGUI(java.util.Collection<Archive> selectedArchives,
                                                          boolean includeObsoletes,
                                                          int flags)
Tries to update all the *existing* local packages. This version *requires* to be run with a GUI.

There are two modes of operation:

Parameters:
selectedArchives - The list of remote archives to consider for the update. This can be null, in which case a list of remote archive is fetched from all available sources.
includeObsoletes - True if obsolete packages should be used when resolving what to update.
flags - Optional flags for the installer, such as NO_TOOLS_MSG.
Returns:
A list of archives that have been installed. Can be null if nothing was done.

updateOrInstallAll_NoGUI

public java.util.List<Archive> updateOrInstallAll_NoGUI(java.util.Collection<java.lang.String> pkgFilter,
                                                        boolean includeAll,
                                                        boolean dryMode,
                                                        java.lang.String acceptLicense)
Tries to update all the *existing* local packages. This version is intended to run without a GUI and only outputs to the current ILogger.

Parameters:
pkgFilter - A list of SdkRepoConstants.NODES or Package.installId() or package indexes to limit the packages we can update or install. A null or empty list means to update everything possible.
includeAll - True to list and install all packages, including obsolete ones.
dryMode - True to check what would be updated/installed but do not actually download or install anything.
acceptLicense - SDK licenses to automatically accept.
Returns:
A list of archives that have been installed. Can be null if nothing was done.

refreshSources

public void refreshSources(boolean forceFetching)
Refresh all sources. This is invoked either internally (reusing an existing monitor) or as a UI callback on the remote page "Refresh" button (in which case the monitor is null and a new task should be created.)

Parameters:
forceFetching - When true, load sources that haven't been loaded yet. When false, only refresh sources that have been loaded yet.

broadcastOnSdkLoaded

public void broadcastOnSdkLoaded()
Safely invoke all the registered ISdkChangeListener.onSdkLoaded(). This can be called from any thread.


createArchiveInstaler

protected ArchiveInstaller createArchiveInstaler()
Internal helper to return a new ArchiveInstaller. This allows us to override the installer for unit-testing.