Class LocalSdk
- java.lang.Object
-
- com.android.sdklib.repository.legacy.local.LocalSdk
-
@Deprecated public class LocalSdk extends java.lang.ObjectDeprecated.in favor ofAndroidSdkHandler/RepoManager.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(com.android.sdklib.repository.legacy.descriptors.IPkgDesc)which depend on the query attribute.
Apps/libraries that use it are encouraged to keep an existing instance around (using a singleton or similar mechanism).Type Query parameter Getter Tools Unique instance getPkgInfo(PkgType.PKG_TOOLS)⇒LocalPkgInfoPlatform-Tools Unique instance getPkgInfo(PkgType.PKG_PLATFORM_TOOLS)⇒LocalPkgInfoDocs Unique instance getPkgInfo(PkgType.PKG_DOCS)⇒LocalPkgInfoBuild-Tools RevisiongetLatestBuildTool()⇒BuildToolInfo,
orgetBuildTool(Revision)⇒BuildToolInfo,
orgetPkgInfo(PkgType.PKG_BUILD_TOOLS, Revision)⇒LocalPkgInfo,
orgetPkgsInfos(PkgType.PKG_BUILD_TOOLS)⇒LocalPkgInfo[]Extras String vendor/path getExtra(String)⇒LocalExtraPkgInfo,
orgetPkgInfo(PkgType.PKG_EXTRAS, String)⇒LocalPkgInfo,
orgetPkgsInfos(PkgType.PKG_EXTRAS)⇒LocalPkgInfo[]Sources AndroidVersiongetPkgInfo(PkgType.PKG_SOURCES, AndroidVersion)⇒LocalPkgInfo,
orgetPkgsInfos(PkgType.PKG_SOURCES)⇒LocalPkgInfo[]Samples AndroidVersiongetPkgInfo(PkgType.PKG_SAMPLES, AndroidVersion)⇒LocalPkgInfo,
orgetPkgsInfos(PkgType.PKG_SAMPLES)⇒LocalPkgInfo[]Platforms AndroidVersiongetPkgInfo(PkgType.PKG_PLATFORMS, AndroidVersion)⇒LocalPkgInfo,
orgetPkgInfo(PkgType.PKG_ADDONS, String)⇒LocalPkgInfo,
orgetPkgsInfos(PkgType.PKG_PLATFORMS)⇒LocalPkgInfo[],
orgetTargetFromHashString(String)⇒IAndroidTargetAdd-ons AndroidVersionx String vendor/pathgetPkgInfo(PkgType.PKG_ADDONS, String)⇒LocalPkgInfo,
orgetPkgsInfos(PkgType.PKG_ADDONS)⇒LocalPkgInfo[],
orgetTargetFromHashString(String)⇒IAndroidTargetSystem images AndroidVersionxStringABIgetPkgsInfos(PkgType.PKG_SYS_IMAGES)⇒LocalPkgInfo[]Threading: All accessor methods are synchronized on the same internal lock so it's safe to call them from any thread, even concurrently.
A method likegetPkgsInfosreturns a copy of its data array, which objects are not altered after creation, so its value is not influenced by the internal state after it returns.Implementation Background:
- The sdk manager has a set of "Package" classes that cover both local and remote SDK operations.
- Goal was to split it in 2 cleanly separated parts:
LocalSdkparses sdk on disk, and a separate class wraps the downloaded manifest (this is now handled within Studio only) - The local SDK should be a singleton accessible somewhere, so there will be one in ADT
(via the Sdk instance), one in Studio, and one in the command line tool.
Right now there's a bit of mess with some classes creating a temp LocalSdkParser, some others using an SdkManager instance, and that needs to be sorted out. - As a transition, the SdkManager instance wraps a LocalSdk and uses this. Eventually the SdkManager.java class will go away (its name is totally misleading, for starters.)
- The current LocalSdkParser stays as-is for compatibility purposes and the goal is also to totally remove it when the SdkManager class goes away.
-
-
Constructor Summary
Constructors Constructor Description LocalSdk()Deprecated.Creates an initial LocalSdk instance with an unknown location.LocalSdk(com.android.repository.io.FileOp fileOp)Deprecated.Creates an initial LocalSdk instance with an unknown location.LocalSdk(java.io.File sdkRoot)Deprecated.Creates an initial LocalSdk instance for a known SDK location.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.StringandroidCmdName()Deprecated.Returns the appropriate name for the 'android' command, which is 'android.bat' for Windows and 'android' for all other platforms.voidclearLocalPkg(java.util.EnumSet<PkgType> filters)Deprecated.Clear the tracked visited folders and the cachedLocalPkgInfofor the given filter types.BuildToolInfogetBuildTool(com.android.repository.Revision revision)Deprecated.Returns theBuildToolInfofor the given revision.LocalExtraPkgInfogetExtra(java.lang.String vendor, java.lang.String path)Deprecated.Retrieves information on an extra package identified by itsStringvendor/path.com.android.repository.io.FileOpgetFileOp()Deprecated.BuildToolInfogetLatestBuildTool()Deprecated.Returns the highest build-tool revision known, or null if there are are no build-tools.java.io.FilegetLocation()Deprecated.Location of the SDK.java.lang.StringgetPath()Deprecated.LocalPkgInfogetPkgInfo(IPkgDesc descriptor)Deprecated.Retrieves information on a package identified by anIPkgDesc.LocalPkgInfogetPkgInfo(PkgType filter)Deprecated.For unique local packages.LocalPkgInfogetPkgInfo(PkgType filter, com.android.repository.Revision revision)Deprecated.Retrieves information on a package identified by itsRevision.LocalPkgInfogetPkgInfo(PkgType filter, com.android.sdklib.AndroidVersion version)Deprecated.Retrieves information on a package identified by anAndroidVersion.LocalPkgInfogetPkgInfo(PkgType filter, java.lang.String path)Deprecated.Retrieves information on a package identified by itsStringpath.LocalPkgInfogetPkgInfo(PkgType filter, java.lang.String vendor, java.lang.String path)Deprecated.Retrieves information on a package identified by both vendor and path strings.LocalPkgInfo[]getPkgsInfos(PkgType filter)Deprecated.Retrieve all the info about the requested package type.LocalPkgInfo[]getPkgsInfos(java.util.EnumSet<PkgType> filters)Deprecated.Retrieve all the info about the requested package types.voidsetLocation(java.io.File sdkRoot)Deprecated.Sets or changes the SDK root location.
-
-
-
Constructor Detail
-
LocalSdk
public LocalSdk()
Deprecated.Creates an initial LocalSdk instance with an unknown location.
-
LocalSdk
public LocalSdk(@NonNull java.io.File sdkRoot)Deprecated.Creates an initial LocalSdk instance for a known SDK location.- Parameters:
sdkRoot- The location of the SDK root folder.
-
LocalSdk
public LocalSdk(@NonNull com.android.repository.io.FileOp fileOp)Deprecated.Creates an initial LocalSdk instance with an unknown location. This is designed for unit tests to override theFileOpbeing used.- Parameters:
fileOp- The alternateFileOpto use for all file-based interactions.
-
-
Method Detail
-
getFileOp
@NonNull public com.android.repository.io.FileOp getFileOp()
Deprecated.
-
setLocation
public void setLocation(@NonNull java.io.File sdkRoot)Deprecated.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()
Deprecated.Location of the SDK. Maybe null. Can be changed.- Returns:
- The location of the SDK. Null if not initialized yet.
-
getPath
@Deprecated @Nullable public java.lang.String getPath()
Deprecated.Location of the SDK. Maybe null. Can be changed. The getLocation() API replaces this function.- Returns:
- The location of the SDK. Null if not initialized yet.
-
clearLocalPkg
public void clearLocalPkg(@NonNull java.util.EnumSet<PkgType> filters)Deprecated.Clear the tracked visited folders and the cachedLocalPkgInfofor the given filter types.- Parameters:
filters- A set of PkgType constants orPkgType.PKG_ALLto clear everything.
-
getPkgInfo
@Nullable public LocalPkgInfo getPkgInfo(@NonNull IPkgDesc descriptor)
Deprecated.Retrieves information on a package identified by anIPkgDesc.- Parameters:
descriptor-IPkgDescdescribing a package.- Returns:
- The first package found with the same descriptor or null.
-
getPkgInfo
@Nullable public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull com.android.sdklib.AndroidVersion version)
Deprecated.Retrieves information on a package identified by anAndroidVersion. Note: don't use this forPkgType.PKG_SYS_IMAGEsince there can be more than one ABI and this method only returns a single package per filter type.- Parameters:
filter-PkgType.PKG_PLATFORM,PkgType.PKG_SAMPLEorPkgType.PKG_SOURCE.version- TheAndroidVersionspecific for this package type.- Returns:
- An existing package information or null if not found.
-
getPkgInfo
@Nullable public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull com.android.repository.Revision revision)
Deprecated.Retrieves information on a package identified by itsRevision.Note that
PkgType.PKG_TOOLSandPkgType.PKG_PLATFORM_TOOLSare unique in a local SDK so you'll want to usegetPkgInfo(PkgType)to retrieve them instead.- Parameters:
filter-PkgType.PKG_BUILD_TOOLS.revision- TheRevisionuniquely identifying this package.- Returns:
- An existing package information or null if not found.
-
getPkgInfo
@Nullable public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull java.lang.String path)
Deprecated.Retrieves information on a package identified by itsStringpath.For add-ons and platforms, the path is the target hash string (see
AndroidTargetHashfor helpers methods to generate this string.)- Parameters:
filter-PkgType.PKG_ADDON,PkgType.PKG_PLATFORM.path- The vendor/path uniquely identifying this package.- Returns:
- An existing package information or null if not found.
-
getPkgInfo
@Nullable public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull java.lang.String vendor, @NonNull java.lang.String path)
Deprecated.Retrieves information on a package identified by both vendor and path strings.For add-ons the path is target hash string (see
AndroidTargetHashfor helpers methods to generate this string.)- Parameters:
filter-PkgType.PKG_EXTRA,PkgType.PKG_ADDON.vendor- The vendor id of the extra package.path- The path uniquely identifying this package for its vendor.- Returns:
- An existing package information or null if not found.
-
getExtra
@Nullable public LocalExtraPkgInfo getExtra(@NonNull java.lang.String vendor, @NonNull java.lang.String path)
Deprecated.Retrieves information on an extra package identified by itsStringvendor/path.- Parameters:
vendor- The vendor id of the extra package.path- The path uniquely identifying this package for its vendor.- Returns:
- An existing extra package information or null if not found.
-
getPkgInfo
@Nullable public LocalPkgInfo getPkgInfo(@NonNull PkgType filter)
Deprecated.For unique local packages. Returns the cached LocalPkgInfo for the requested type. Loads it from disk if not cached.- Parameters:
filter-PkgType.PKG_TOOLSorPkgType.PKG_PLATFORM_TOOLSorPkgType.PKG_DOC.- Returns:
- null if the package is not installed.
-
getPkgsInfos
@NonNull public LocalPkgInfo[] getPkgsInfos(@NonNull PkgType filter)
Deprecated.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. The resulting array is sorted according to the PkgInfo's sort order.Note: you can use this with
PkgType.PKG_TOOLS,PkgType.PKG_PLATFORM_TOOLSandPkgType.PKG_DOCbut since there can only be one package of these types, it is more efficient to usegetPkgInfo(PkgType)to query them.- Parameters:
filter- One ofPkgTypeconstants.- Returns:
- A list (possibly empty) of matching installed packages. Never returns null.
-
getPkgsInfos
@NonNull public LocalPkgInfo[] getPkgsInfos(@NonNull java.util.EnumSet<PkgType> filters)
Deprecated.Retrieve all the info about the requested package types. This is used for the package types that have one or more instances, each with different versions. The resulting array is sorted according to the PkgInfo's sort order.To force the LocalSdk parser to load everything, simply call this method with the
PkgType.PKG_ALLargument to load all the known package types.Note: you can use this with
PkgType.PKG_TOOLS,PkgType.PKG_PLATFORM_TOOLSandPkgType.PKG_DOCbut since there can only be one package of these types, it is more efficient to usegetPkgInfo(PkgType)to query them.- Parameters:
filters- One or more ofPkgType.PKG_ADDON,PkgType.PKG_PLATFORM,PkgType.PKG_BUILD_TOOLS,PkgType.PKG_EXTRA,PkgType.PKG_SOURCE,PkgType.PKG_SYS_IMAGE- Returns:
- A list (possibly empty) of matching installed packages. Never returns null.
-
getBuildTool
@Nullable public BuildToolInfo getBuildTool(@Nullable com.android.repository.Revision revision)
Deprecated.Returns theBuildToolInfofor the given revision.- Parameters:
revision- The requested revision.- Returns:
- A
BuildToolInfo. Can be null ifrevisionis null or is not part of the known set returned bygetPkgsInfos(PkgType.PKG_BUILD_TOOLS).
-
getLatestBuildTool
@Nullable public BuildToolInfo getLatestBuildTool()
Deprecated.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.
-
androidCmdName
public static java.lang.String androidCmdName()
Deprecated.Returns the appropriate name for the 'android' command, which is 'android.bat' for Windows and 'android' for all other platforms.
-
-