com.android.repository.util
Class InstallerUtil

java.lang.Object
  extended by com.android.repository.util.InstallerUtil

public class InstallerUtil
extends java.lang.Object

Utility methods for PackageInstaller implementations.


Constructor Summary
InstallerUtil()
           
 
Method Summary
static boolean checkValidPath(java.io.File path, RepoManager manager, ProgressIndicator progress)
          Checks to see whether path is a valid install path.
static java.util.List<RemotePackage> computeRequiredPackages(java.util.Collection<RemotePackage> requests, RepositoryPackages packages, ProgressIndicator logger)
          Compute the complete list of packages that need to be installed to meet the dependencies of the given list (including the requested packages themselves, if they are not already installed).
static java.net.URL resolveCompleteArchiveUrl(RemotePackage p, ProgressIndicator progress)
          Returns a URL corresponding to Archive.getComplete() of the given RemotePackage.
static void unzip(java.io.File in, java.io.File out, FileOp fop, long expectedSize, ProgressIndicator progress)
          Unzips the given zipped input stream into the given directory.
static void writePackageXml(RemotePackage p, java.io.File packageRoot, RepoManager manager, FileOp fop, ProgressIndicator progress)
          Writes out the XML for a LocalPackageImpl corresponding to the given RemotePackage to a package.xml file in packageRoot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstallerUtil

public InstallerUtil()
Method Detail

unzip

public static void unzip(@NonNull
                         java.io.File in,
                         @NonNull
                         java.io.File out,
                         @NonNull
                         FileOp fop,
                         long expectedSize,
                         @NonNull
                         ProgressIndicator progress)
                  throws java.io.IOException
Unzips the given zipped input stream into the given directory.

Parameters:
in - The (zipped) input stream.
out - The directory into which to expand the files. Must exist.
fop - The FileOp to use for file operations.
expectedSize - Compressed size of the stream.
progress - Currently only used for logging.
Throws:
java.io.IOException - If we're unable to read or write.

writePackageXml

public static void writePackageXml(@NonNull
                                   RemotePackage p,
                                   @NonNull
                                   java.io.File packageRoot,
                                   @NonNull
                                   RepoManager manager,
                                   @NonNull
                                   FileOp fop,
                                   @NonNull
                                   ProgressIndicator progress)
                            throws java.io.IOException
Writes out the XML for a LocalPackageImpl corresponding to the given RemotePackage to a package.xml file in packageRoot.

Parameters:
p - The package to convert to a local package and write out.
packageRoot - The location to write to. Must exist and be a directory.
manager - A RepoManager instance.
fop - The FileOp to use for file operations.
progress - Currently only used for logging.
Throws:
java.io.IOException - If we fail to write the output file.

resolveCompleteArchiveUrl

@Nullable
public static java.net.URL resolveCompleteArchiveUrl(@NonNull
                                                              RemotePackage p,
                                                              @NonNull
                                                              ProgressIndicator progress)
Returns a URL corresponding to Archive.getComplete() of the given RemotePackage. If the url in the package is a relative url, resolves it by using the prefix of the url in the RepositorySource of the package.

Returns:
The resolved URL, or null if the given archive location is not parsable in its original or resolved form.

computeRequiredPackages

@Nullable
public static java.util.List<RemotePackage> computeRequiredPackages(@NonNull
                                                                             java.util.Collection<RemotePackage> requests,
                                                                             @NonNull
                                                                             RepositoryPackages packages,
                                                                             @NonNull
                                                                             ProgressIndicator logger)
Compute the complete list of packages that need to be installed to meet the dependencies of the given list (including the requested packages themselves, if they are not already installed). Returns null if we were unable to compute a complete list of dependencies due to not being able to find required packages of the specified version. Packages are returned in install order (that is, if we request A which depends on B, the result will be [B, A]). If a dependency cycle is encountered the order of the returned results at or below the cycle is undefined. For example if we have A -> [B, C], B -> D, and D -> B then the returned list will be either [B, D, C, A] or [D, B, C, A]. Note that we assume installed packages already have their dependencies met.


checkValidPath

public static boolean checkValidPath(@NonNull
                                     java.io.File path,
                                     @NonNull
                                     RepoManager manager,
                                     @NonNull
                                     ProgressIndicator progress)
Checks to see whether path is a valid install path. Specifically, checks whether there are any existing packages installed in parents or children of path. Returns true if the path is valid. Otherwise returns false and logs a warning.