com.android.sdklib
Class SdkManager

java.lang.Object
  extended by com.android.sdklib.SdkManager

public class SdkManager
extends java.lang.Object

The SDK manager parses the SDK folder and gives access to the content.

See Also:
PlatformTarget, AddOnTarget

Nested Class Summary
static class SdkManager.LayoutlibVersion
           
 
Field Summary
static java.lang.String ADDON_API
           
static java.lang.String ADDON_DEFAULT_SKIN
           
static java.lang.String ADDON_DESCRIPTION
           
static java.lang.String ADDON_LIBRARIES
           
static java.lang.String ADDON_NAME
           
static java.lang.String ADDON_REVISION
           
static java.lang.String ADDON_REVISION_OLD
           
static java.lang.String ADDON_USB_VENDOR
           
static java.lang.String ADDON_VENDOR
           
static java.lang.String PROP_VERSION_CODENAME
           
static java.lang.String PROP_VERSION_RELEASE
           
static java.lang.String PROP_VERSION_SDK
           
 
Constructor Summary
protected SdkManager(java.lang.String osSdkPath)
          Create a new SdkManager instance.
 
Method Summary
static SdkManager createManager(java.lang.String osSdkPath, com.android.utils.ILogger log)
          Creates an SdkManager for a given sdk location.
 BuildToolInfo getBuildTool(FullRevision revision)
          Returns the BuildToolInfo for the given revision.
 java.util.Set<FullRevision> getBuildTools()
          Returns an unmodifiable set of known build-tools revisions.
 java.util.Map<java.io.File,java.lang.String> getExtraSamples()
          Returns a map of the root samples directories located in the SDK/extras packages.
 java.util.Map<java.lang.String,java.lang.Integer> getExtrasVersions()
          Returns a map of all the extras found in the local SDK with their major revision.
 BuildToolInfo getLatestBuildTool()
          Returns the highest build-tool revision known.
 java.lang.String getLocation()
          Returns the location of the SDK.
 SdkManager.LayoutlibVersion getMaxLayoutlibVersion()
          Deprecated. This does NOT solve the right problem and will be changed later.
 java.lang.String getPlatformToolsVersion()
          Returns the platform tools version if installed, null otherwise.
 IAndroidTarget getTargetFromHashString(java.lang.String hash)
          Returns a target from a hash that was generated by IAndroidTarget.hashString().
 IAndroidTarget[] getTargets()
          Returns the targets that are available in the SDK.
 boolean hasChanged()
          Checks whether any of the SDK platforms/add-ons/build-tools have changed on-disk since we last loaded the SDK.
 boolean hasChanged(com.android.utils.ILogger log)
          Checks whether any of the SDK platforms/add-ons/build-tools have changed on-disk since we last loaded the SDK.
static com.android.utils.Pair<java.util.Map<java.lang.String,java.lang.String>,java.lang.String> parseAddonProperties(java.io.File addonDir, IAndroidTarget[] targetList, com.android.utils.ILogger log)
          Parses the add-on properties and decodes any error that occurs when loading an addon.
 void reloadSdk(com.android.utils.ILogger log)
          Reloads the content of the SDK.
protected  void setTargets(IAndroidTarget[] targets)
          Sets the targets that are available in the SDK.
 void updateAdb()
          Updates adb with the USB devices declared in the SDK add-ons.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_VERSION_SDK

public static final java.lang.String PROP_VERSION_SDK
See Also:
Constant Field Values

PROP_VERSION_CODENAME

public static final java.lang.String PROP_VERSION_CODENAME
See Also:
Constant Field Values

PROP_VERSION_RELEASE

public static final java.lang.String PROP_VERSION_RELEASE
See Also:
Constant Field Values

ADDON_NAME

public static final java.lang.String ADDON_NAME
See Also:
Constant Field Values

ADDON_VENDOR

public static final java.lang.String ADDON_VENDOR
See Also:
Constant Field Values

ADDON_API

public static final java.lang.String ADDON_API
See Also:
Constant Field Values

ADDON_DESCRIPTION

public static final java.lang.String ADDON_DESCRIPTION
See Also:
Constant Field Values

ADDON_LIBRARIES

public static final java.lang.String ADDON_LIBRARIES
See Also:
Constant Field Values

ADDON_DEFAULT_SKIN

public static final java.lang.String ADDON_DEFAULT_SKIN
See Also:
Constant Field Values

ADDON_USB_VENDOR

public static final java.lang.String ADDON_USB_VENDOR
See Also:
Constant Field Values

ADDON_REVISION

public static final java.lang.String ADDON_REVISION
See Also:
Constant Field Values

ADDON_REVISION_OLD

public static final java.lang.String ADDON_REVISION_OLD
See Also:
Constant Field Values
Constructor Detail

SdkManager

protected SdkManager(@NonNull
                     java.lang.String osSdkPath)
Create a new SdkManager instance. External users should use createManager(String, ILogger).

Parameters:
osSdkPath - the location of the SDK.
Method Detail

createManager

@Nullable
public static SdkManager createManager(@NonNull
                                                java.lang.String osSdkPath,
                                                @NonNull
                                                com.android.utils.ILogger log)
Creates an SdkManager for a given sdk location.

Parameters:
osSdkPath - the location of the SDK.
log - the ILogger object receiving warning/error from the parsing.
Returns:
the created SdkManager or null if the location is not valid.

reloadSdk

public void reloadSdk(@NonNull
                      com.android.utils.ILogger log)
Reloads the content of the SDK.

Parameters:
log - the ILogger object receiving warning/error from the parsing.

hasChanged

public boolean hasChanged()
Checks whether any of the SDK platforms/add-ons/build-tools have changed on-disk since we last loaded the SDK. This does not reload the SDK nor does it change the underlying targets.

Returns:
True if at least one directory or source.prop has changed.

hasChanged

public boolean hasChanged(@Nullable
                          com.android.utils.ILogger log)
Checks whether any of the SDK platforms/add-ons/build-tools have changed on-disk since we last loaded the SDK. This does not reload the SDK nor does it change the underlying targets.

Parameters:
log - An optional logger used to print verbose info on what changed. Can be null.
Returns:
True if at least one directory or source.prop has changed.

getLocation

@NonNull
public java.lang.String getLocation()
Returns the location of the SDK.


getTargets

@NonNull
public IAndroidTarget[] getTargets()
Returns the targets that are available in the SDK.

The array can be empty but not null.


setTargets

protected void setTargets(@NonNull
                          IAndroidTarget[] targets)
Sets the targets that are available in the SDK.

The array can be empty but not null.


getBuildTools

@NonNull
public java.util.Set<FullRevision> getBuildTools()
Returns an unmodifiable set of known build-tools revisions. Can be empty but not null.


getLatestBuildTool

@Nullable
public BuildToolInfo getLatestBuildTool()
Returns the highest build-tool revision known. Can be null.

Returns:
The highest build-tool revision known, or 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 getBuildTools().

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.

updateAdb

public void updateAdb()
               throws com.android.prefs.AndroidLocation.AndroidLocationException,
                      java.io.IOException
Updates adb with the USB devices declared in the SDK add-ons.

Throws:
com.android.prefs.AndroidLocation.AndroidLocationException
java.io.IOException

getMaxLayoutlibVersion

@Deprecated
@Nullable
public SdkManager.LayoutlibVersion getMaxLayoutlibVersion()
Deprecated. This does NOT solve the right problem and will be changed later.

Returns the greatest SdkManager.LayoutlibVersion found amongst all platform targets currently loaded in the SDK.

We only started recording Layoutlib Versions recently in the platform meta data so it's possible to have an SDK with many platforms loaded but no layoutlib version defined.

Returns:
The greatest SdkManager.LayoutlibVersion or null if none is found.

getExtraSamples

@NonNull
public java.util.Map<java.io.File,java.lang.String> getExtraSamples()
Returns a map of the root samples directories located in the SDK/extras packages. No guarantee is made that the extras' samples directory actually contain any valid samples. The only guarantee is that the root samples directory actually exists. The map is { File: Samples root directory => String: Extra package display name. }

Returns:
A non-null possibly empty map of extra samples directories and their associated extra package display name.

getExtrasVersions

@NonNull
public java.util.Map<java.lang.String,java.lang.Integer> getExtrasVersions()
Returns a map of all the extras found in the local SDK with their major revision.

Map keys are in the form "vendor-id/path-id". These ids uniquely identify an extra package. The version is the incremental integer major revision of the package.

Returns:
A non-null possibly empty map of { string "vendor/path" => integer major revision }

getPlatformToolsVersion

@Nullable
public java.lang.String getPlatformToolsVersion()
Returns the platform tools version if installed, null otherwise.


parseAddonProperties

@NonNull
public static com.android.utils.Pair<java.util.Map<java.lang.String,java.lang.String>,java.lang.String> parseAddonProperties(@NonNull
                                                                                                                                     java.io.File addonDir,
                                                                                                                                     @NonNull
                                                                                                                                     IAndroidTarget[] targetList,
                                                                                                                                     @NonNull
                                                                                                                                     com.android.utils.ILogger log)
Parses the add-on properties and decodes any error that occurs when loading an addon.

Parameters:
addonDir - the location of the addon directory.
targetList - The list of Android target that were already loaded from the SDK.
log - the ILogger object receiving warning/error from the parsing.
Returns:
A pair with the property map and an error string. Both can be null but not at the same time. If a non-null error is present then the property map must be ignored. The error should be translatable as it might show up in the SdkManager UI.