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

java.lang.Object
  extended by com.android.sdklib.internal.repository.updater.PackageLoader

public class PackageLoader
extends java.lang.Object

Loads packages fetched from the remote SDK Repository and keeps track of their state compared with the current local SDK installation.


Nested Class Summary
static interface PackageLoader.IAutoInstallTask
          Interface describing the task of installing a specific package.
static interface PackageLoader.ISourceLoadedCallback
          Interface for the callback called by loadPackages(boolean, ISourceLoadedCallback).
 
Constructor Summary
PackageLoader(UpdaterData updaterData)
          Creates a new PackageManager associated with the given UpdaterData and using the UpdaterData's default DownloadCache.
PackageLoader(UpdaterData updaterData, DownloadCache cache)
          Creates a new PackageManager associated with the given UpdaterData but using the specified DownloadCache instead of the one from UpdaterData.
 
Method Summary
 UpdaterData getUpdaterData()
           
 void loadPackages(boolean overrideExisting, PackageLoader.ISourceLoadedCallback sourceLoadedCallback)
          Loads all packages from the remote repository.
 void loadPackagesWithInstallTask(int installFlags, PackageLoader.IAutoInstallTask installTask)
          Load packages, source by source using loadPackages(boolean, ISourceLoadedCallback), and executes the given PackageLoader.IAutoInstallTask on the current package list.
 void loadRemoteAddonsList(ITaskMonitor monitor)
          Loads the remote add-ons list.
protected  void runOnUiThread(java.lang.Runnable r)
          Runs a runnable on the UI thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageLoader

public PackageLoader(UpdaterData updaterData)
Creates a new PackageManager associated with the given UpdaterData and using the UpdaterData's default DownloadCache.

Parameters:
updaterData - The UpdaterData. Must not be null.

PackageLoader

public PackageLoader(UpdaterData updaterData,
                     DownloadCache cache)
Creates a new PackageManager associated with the given UpdaterData but using the specified DownloadCache instead of the one from UpdaterData.

Parameters:
updaterData - The UpdaterData. Must not be null.
cache - The DownloadCache to use instead of the one from UpdaterData.
Method Detail

getUpdaterData

public UpdaterData getUpdaterData()

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.

loadPackages

public void loadPackages(boolean overrideExisting,
                         PackageLoader.ISourceLoadedCallback sourceLoadedCallback)
Loads all packages from the remote repository. This runs in an ITask. The call is blocking.

The callback is called with each set of PkgItem found in each source. The caller is responsible to accumulate the packages given to the callback after each source is finished loaded. In return the callback tells the loader whether to continue loading sources.

Normally this method doesn't access the remote source if it's already been loaded in the in-memory source (e.g. don't fetch twice).

Parameters:
overrideExisting - Set this to true when the caller wants to check for updates and discard any existing source already loaded in memory. It should be false for normal use.
sourceLoadedCallback - The callback to invoke for each loaded source.

loadPackagesWithInstallTask

public void loadPackagesWithInstallTask(int installFlags,
                                        PackageLoader.IAutoInstallTask installTask)
Load packages, source by source using loadPackages(boolean, ISourceLoadedCallback), and executes the given PackageLoader.IAutoInstallTask on the current package list. That is for each package known, the install task is queried to find if the package is the one to be installed or updated.

- If an already installed package is accepted by the task, it is returned.
- If a new package (remotely available but not installed locally) is accepted, the user will be prompted for permission to install it.
- If an existing package has updates, the install task will be accept if it accepts one of the updating packages, and if yes the the user will be prompted for permission to install it.

Only one package can be accepted, after which the task is completed. There is no direct return value, PackageLoader.IAutoInstallTask.setResult(boolean, java.util.Map) is called on the result of the accepted package. When the task is completed, PackageLoader.IAutoInstallTask.taskCompleted() is called.

The call is blocking. Although the name says "Task", this is not an ITask running in its own thread but merely a synchronous call.

Parameters:
installFlags - Flags for installation such as UpdaterData.TOOLS_MSG_UPDATED_FROM_ADT.
installTask - The task to perform.

loadRemoteAddonsList

public void loadRemoteAddonsList(ITaskMonitor monitor)
Loads the remote add-ons list.