com.android.sdklib.local
Class LocalSdk

java.lang.Object
  extended by com.android.sdklib.local.LocalSdk

public class LocalSdk
extends java.lang.Object

This class keeps information on the current locally installed SDK. It tries to lazily load information as much as possible.

Packages are accessed by their type and a main query attribute, depending on the package type. There are different versions of getPkgInfo(int, com.android.sdklib.AndroidVersion) which depend on the query attribute.

Type Query parameter Getter
Tools Unique instance getPkgInfo(PKG_TOOLS) => LocalPkgInfo
Platform-Tools Unique instance getPkgInfo(PKG_PLATFORM_TOOLS) => LocalPkgInfo
Docs Unique instance getPkgInfo(PKG_DOCS) => LocalPkgInfo
Build-Tools FullRevision getLatestBuildTool() => BuildToolInfo,
or getBuildTool(FullRevision) => BuildToolInfo,
or getPkgInfo(PKG_BUILD_TOOLS, FullRevision) => LocalPkgInfo,
or getPkgsInfos(PKG_BUILD_TOOLS) => LocalPkgInfo[]
Extras String vendor/path getExtra(String) => LocalExtraPkgInfo,
or getPkgInfo(PKG_EXTRAS, String) => LocalPkgInfo,
or getPkgsInfos(PKG_EXTRAS) => LocalPkgInfo[]
Sources AndroidVersion getPkgInfo(PKG_SOURCES, AndroidVersion) => LocalPkgInfo,
or getPkgsInfos(PKG_SOURCES) => LocalPkgInfo[]
Samples AndroidVersion getPkgInfo(PKG_SAMPLES, AndroidVersion) => LocalPkgInfo,
or getPkgsInfos(PKG_SAMPLES) => LocalPkgInfo[]
Platforms AndroidVersion getPkgInfo(PKG_PLATFORMS, AndroidVersion) => LocalPkgInfo,
or getPkgInfo(PKG_ADDONS, String) => LocalPkgInfo,
or getPkgsInfos(PKG_PLATFORMS) => LocalPkgInfo[],
or getTargetFromHashString(String) => IAndroidTarget
Add-ons AndroidVersion x String vendor/path getPkgInfo(PKG_ADDONS, String) => LocalPkgInfo,
or getPkgsInfos(PKG_ADDONS) => LocalPkgInfo[],
or getTargetFromHashString(String) => IAndroidTarget
System images AndroidVersion x String ABI getPkgsInfos(PKG_SYS_IMAGES) => LocalPkgInfo[]
Apps/libraries that use it are encouraged to keep an existing instance around (using a singleton or similar mechanism).

Background:


Field Summary
static int PKG_ADDONS
          Filter the SDK/addons.
static int PKG_ALL
          Filter all SDK folders.
static int PKG_BUILD_TOOLS
          Filter the SDK/build-tools folder.
static int PKG_DOCS
          Filter the SDK/docs folder.
static int PKG_EXTRAS
          Filter the SDK/extras folder.
static int PKG_PLATFORM_TOOLS
          Filter the SDK/platform-tools folder.
static int PKG_PLATFORMS
          Filter the SDK/platforms.
static int PKG_SAMPLES
          Filter the SDK/samples folder.
static int PKG_SOURCES
          Filter the SDK/sources folder.
static int PKG_SYS_IMAGES
          Filter the SDK/sys-images.
static int PKG_TOOLS
          Filter the SDK/tools folder.
 
Constructor Summary
  LocalSdk()
          Creates an initial LocalSdk instance with an unknown location.
  LocalSdk(java.io.File sdkRoot)
          Creates an initial LocalSdk instance for a known SDK location.
protected LocalSdk(IFileOp fileOp)
          Creates an initial LocalSdk instance with an unknown location.
 
Method Summary
 void clearLocalPkg(int filters)
          Clear the tracked visited folders & the cached LocalPkgInfo for the given filter types.
 BuildToolInfo getBuildTool(FullRevision revision)
          Returns the BuildToolInfo for the given revision.
 LocalExtraPkgInfo getExtra(java.lang.String vendorPath)
          Retrieves information on an extra package identified by its String vendor/path.
 IFileOp getFileOp()
           
 BuildToolInfo getLatestBuildTool()
          Returns the highest build-tool revision known, or null if there are are no build-tools.
 java.io.File getLocation()
          Location of the SDK.
 LocalPkgInfo getPkgInfo(int filter)
          For unique local packages.
 LocalPkgInfo getPkgInfo(int filter, AndroidVersion version)
          Retrieves information on a package identified by an AndroidVersion.
 LocalPkgInfo getPkgInfo(int filter, FullRevision revision)
          Retrieves information on a package identified by its FullRevision.
 LocalPkgInfo getPkgInfo(int filter, java.lang.String vendorPath)
          Retrieves information on a package identified by its String vendor/path.
 LocalPkgInfo[] getPkgsInfos(int filters)
          Retrieve all the info about the requested package type.
 IAndroidTarget getTargetFromHashString(java.lang.String hash)
          Returns a target from a hash that was generated by IAndroidTarget.hashString().
 boolean hasChanged(int filters)
          Check the tracked visited folders to see if anything has changed for the requested filter types.
 void setLocation(java.io.File sdkRoot)
          Sets or changes the SDK root location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PKG_ALL

public static final int PKG_ALL
Filter all SDK folders.

See Also:
Constant Field Values

PKG_TOOLS

public static final int PKG_TOOLS
Filter the SDK/tools folder. Has FullRevision.

See Also:
Constant Field Values

PKG_PLATFORM_TOOLS

public static final int PKG_PLATFORM_TOOLS
Filter the SDK/platform-tools folder. Has FullRevision.

See Also:
Constant Field Values

PKG_BUILD_TOOLS

public static final int PKG_BUILD_TOOLS
Filter the SDK/build-tools folder. Has FullRevision.

See Also:
Constant Field Values

PKG_DOCS

public static final int PKG_DOCS
Filter the SDK/docs folder. Has MajorRevision.

See Also:
Constant Field Values

PKG_EXTRAS

public static final int PKG_EXTRAS
Filter the SDK/extras folder. Has Path. Has MajorRevision.

See Also:
Constant Field Values

PKG_PLATFORMS

public static final int PKG_PLATFORMS
Filter the SDK/platforms. Has AndroidVersion. Has MajorRevision.

See Also:
Constant Field Values

PKG_SYS_IMAGES

public static final int PKG_SYS_IMAGES
Filter the SDK/sys-images. Has AndroidVersion. Has MajorRevision.

See Also:
Constant Field Values

PKG_ADDONS

public static final int PKG_ADDONS
Filter the SDK/addons. Has AndroidVersion. Has MajorRevision.

See Also:
Constant Field Values

PKG_SAMPLES

public static final int PKG_SAMPLES
Filter the SDK/samples folder. Note: this will not detect samples located in the SDK/extras packages. Has AndroidVersion. Has MajorRevision.

See Also:
Constant Field Values

PKG_SOURCES

public static final int PKG_SOURCES
Filter the SDK/sources folder. Has AndroidVersion. Has MajorRevision.

See Also:
Constant Field Values
Constructor Detail

LocalSdk

public LocalSdk()
Creates an initial LocalSdk instance with an unknown location.


LocalSdk

public LocalSdk(@NonNull
                java.io.File sdkRoot)
Creates an initial LocalSdk instance for a known SDK location.

Parameters:
sdkRoot - The location of the SDK root folder.

LocalSdk

protected LocalSdk(@NonNull
                   IFileOp fileOp)
Creates an initial LocalSdk instance with an unknown location. This is designed for unit tests to override the FileOp being used.

Parameters:
fileOp - The alternate FileOp to use for all file-based interactions.
Method Detail

getFileOp

public IFileOp getFileOp()

setLocation

public void setLocation(@NonNull
                        java.io.File sdkRoot)
Sets or changes the SDK root location. This also clears any cached information.

Parameters:
sdkRoot - The location of the SDK root folder.

getLocation

@Nullable
public java.io.File getLocation()
Location of the SDK. Maybe null. Can be changed.

Returns:
The location of the SDK. Null if not initialized yet.

clearLocalPkg

public void clearLocalPkg(int filters)
Clear the tracked visited folders & the cached LocalPkgInfo for the given filter types.

Parameters:
filters - An OR of the PKG_ constants or PKG_ALL to clear everything.

hasChanged

public boolean hasChanged(int filters)
Check the tracked visited folders to see if anything has changed for the requested filter types. This does not refresh or reload any package information.

Parameters:
filters - An OR of the PKG_ constants or PKG_ALL to clear everything.

getPkgInfo

public LocalPkgInfo getPkgInfo(int filter,
                               AndroidVersion version)
Retrieves information on a package identified by an AndroidVersion. Note: don't use this for PKG_SYS_IMAGES since there can be more than one ABI and this method only returns a single package per filter type.

Parameters:
filter - PKG_PLATFORMS, PKG_SAMPLES or PKG_SOURCES.
version - The AndroidVersion specific for this package type.
Returns:
An existing package information or null if not found.

getPkgInfo

public LocalPkgInfo getPkgInfo(int filter,
                               FullRevision revision)
Retrieves information on a package identified by its FullRevision.

Note that PKG_TOOLS and PKG_PLATFORM_TOOLS are unique in a local SDK so you'll want to use getPkgInfo(int) to retrieve them instead.

Parameters:
filter - PKG_BUILD_TOOLS.
revision - The FullRevision uniquely identifying this package.
Returns:
An existing package information or null if not found.

getPkgInfo

public LocalPkgInfo getPkgInfo(int filter,
                               java.lang.String vendorPath)
Retrieves information on a package identified by its String vendor/path.

Parameters:
filter - PKG_EXTRAS, PKG_ADDONS, PKG_PLATFORMS.
vendorPath - The vendor/path uniquely identifying this package.
Returns:
An existing package information or null if not found.

getExtra

public LocalExtraPkgInfo getExtra(java.lang.String vendorPath)
Retrieves information on an extra package identified by its String vendor/path.

Parameters:
vendorPath - The vendor/path uniquely identifying this package.
Returns:
An existing extra package information or null if not found.

getPkgInfo

public LocalPkgInfo getPkgInfo(int filter)
For unique local packages. Returns the cached LocalPkgInfo for the requested type. Loads it from disk if not cached.

Parameters:
filter - PKG_TOOLS or PKG_PLATFORM_TOOLS or PKG_DOCS.
Returns:
null if the package is not installed.

getPkgsInfos

public LocalPkgInfo[] getPkgsInfos(int filters)
Retrieve all the info about the requested package type. This is used for the package types that have one or more instances, each with different versions.

To force the LocalSdk parser to load everything, simply call this method with the PKG_ALL argument to load all the known package types.

Note: you can use this with PKG_TOOLS, PKG_PLATFORM_TOOLS and PKG_DOCS but since there can only be one package of these types, it is more efficient to use getPkgInfo(int) to query them.

Parameters:
filters - One or more of PKG_ADDONS, PKG_PLATFORMS, PKG_BUILD_TOOLS, PKG_EXTRAS, PKG_SOURCES, PKG_SYS_IMAGES
Returns:
A list (possibly empty) of matching installed packages. Never returns null.

getBuildTool

@Nullable
public BuildToolInfo getBuildTool(@Nullable
                                           FullRevision revision)
Returns the BuildToolInfo for the given revision.

Parameters:
revision - The requested revision.
Returns:
A BuildToolInfo. Can be null if revision is null or is not part of the known set returned by getPkgsInfos(PKG_BUILD_TOOLS).

getLatestBuildTool

@Nullable
public BuildToolInfo getLatestBuildTool()
Returns the highest build-tool revision known, or null if there are are no build-tools.

If no specific build-tool package is installed but the platform-tools is lower than 17, then this creates and returns a "legacy" built-tool package using platform-tools. (We only split build-tools out of platform-tools starting with revision 17, before they were both the same thing.)

Returns:
The highest build-tool revision known, or null.

getTargetFromHashString

@Nullable
public IAndroidTarget getTargetFromHashString(@Nullable
                                                       java.lang.String hash)
Returns a target from a hash that was generated by IAndroidTarget.hashString().

Parameters:
hash - the IAndroidTarget hash string.
Returns:
The matching IAndroidTarget or null.