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
           
 
Constructor Summary
protected SdkManager(java.lang.String osSdkPath)
          Create a new SdkManager instance.
 
Method Summary
static SdkManager createManager(LocalSdk localSdk)
          Creates an @{linkplain SdkManager} for an existing @{link LocalSdk}.
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()
          Deprecated. 
 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()
          Deprecated. Starting with add-on schema 6, extras can have full revisions instead of just major revisions. This API only returns the major revision. Callers should be modified to use the new {code LocalSdk.getPkgInfo(PkgType.PKG_EXTRAS)} API instead.
 BuildToolInfo getLatestBuildTool()
          Returns the highest build-tool revision known.
 LocalSdk getLocalSdk()
           
 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 (platforms & addons) 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.
 void reloadSdk(com.android.utils.ILogger log)
          Reloads the content of 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
 

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.

createManager

@NonNull
public static SdkManager createManager(@NonNull
                                               LocalSdk localSdk)
Creates an @{linkplain SdkManager} for an existing @{link LocalSdk}.

Parameters:
localSdk - the SDK to use with the SDK manager

getLocalSdk

@NonNull
public LocalSdk getLocalSdk()

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 (platforms & addons) that are available in the SDK. The target list is created on demand the first time then cached. It will not refreshed unless reloadSdk(ILogger) is called.

The array can be empty but not null.


getBuildTools

@Deprecated
@NonNull
public java.util.Set<FullRevision> getBuildTools()
Deprecated. 

Returns an unmodifiable set of known build-tools revisions. Can be empty but not null. Deprecated. I don't think anything uses this.


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

@Deprecated
@NonNull
public java.util.Map<java.lang.String,java.lang.Integer> getExtrasVersions()
Deprecated. Starting with add-on schema 6, extras can have full revisions instead of just major revisions. This API only returns the major revision. Callers should be modified to use the new {code LocalSdk.getPkgInfo(PkgType.PKG_EXTRAS)} API instead.

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.