Class PackageManager

java.lang.Object
com.massifmaps.packagemanager.PackageManager

public class PackageManager extends Object
Base class for offline map package manager. Package manager supports downloading/removing packages.
It can be queried about available packages and status of the packages. It works asynchronously in
the background and can inform app when packages have been updated.
It works persistently. If a package download is started and app is closed, the download will resume
when the package manager is started next time.
  • Constructor Details

    • PackageManager

      public PackageManager(String packageListURL, String dataFolder, String serverEncKey, String localEncKey) throws IOException
      Constructs a new package manager, given URL for package list and data folder.
      The data folder must exist before creating a new package manager and it is assumed to be persistent.
      Note: the package manager must be explicitly started using start() method!
      Parameters:
      packageListURL - The URL that defines all packages.
      dataFolder - The folder where downloaded packages are kept. It must exist and must be writable.
      serverEncKey - Encryption key for server packages
      localEncKey - Encryption key for local packages
      Throws:
      Exception - If package manager fails to open or create package database.
      IOException
  • Method Details

    • equals

      public boolean equals(Object obj)
      Checks if this object is equal to the specified object.
      Overrides:
      equals in class Object
      Parameters:
      obj - The reference object.
      Returns:
      True when objects are equal, false otherwise.
    • hashCode

      public int hashCode()
      Returns the hash value of this object.
      Overrides:
      hashCode in class Object
      Returns:
      The hash value of this object.
    • getPackageManagerListener

      public PackageManagerListener getPackageManagerListener()
      Returns the current listener for package manager events.
      Returns:
      The current listener or null if none is set.
    • setPackageManagerListener

      public void setPackageManagerListener(PackageManagerListener listener)
      Sets the package manager listener.
      Parameters:
      listener - The new package manager listener to use.
    • start

      public boolean start()
      Starts the package manager. All previous tasks will be resumed after this.
      Returns:
      True if package manager was successfully started. False otherwise (can not create/access database).
    • stop

      public void stop(boolean wait)
      Stops the package manager. The stopping can be asynchronous or synchronous.
      Parameters:
      wait - If set to true, then synchronous stopping is performed and the operation may take a while.
    • getServerPackages

      public PackageInfoVector getServerPackages()
      Returns the list of available server packages.
      Note that the list must be retrieved from the server first, using startPackageListDownload.
      Returns:
      The list of available server packages.
    • getLocalPackages

      public PackageInfoVector getLocalPackages()
      Returns the list of available local downloaded packages.
      Returns:
      The list of available local downloaded packages.
    • getServerPackageListMetaInfo

      public PackageMetaInfo getServerPackageListMetaInfo()
      Returns the metainfo of server packages.
      Returns:
      The metainfo data about server packages, or null if no metainfo is available.
    • getServerPackageListAge

      public int getServerPackageListAge()
      Returns the age of server package list. This method can be used to measure the time of the download and check whether the list should be updated.
      Returns:
      The age of server package list in seconds.
    • getServerPackage

      public PackageInfo getServerPackage(String packageId)
      Returns the specified server package.
      Note that the list must be retrieved from the server first, using startPackageListDownload.
      Parameters:
      packageId - The id of the package.
      Returns:
      The specified server package or null if it is not in the server package list.
    • getLocalPackage

      public PackageInfo getLocalPackage(String packageId)
      Returns the specified local package.
      Parameters:
      packageId - The id of the package.
      Returns:
      The specified local package or null if it can not be found in the local package list. Note that if the package is being downloaded, null is returned.
    • getLocalPackageStatus

      public PackageStatus getLocalPackageStatus(String packageId, int version)
      Returns the status of the specified package.
      Parameters:
      packageId - The id of the package.
      version - The version of the package. Use -1 for the latest version.
      Returns:
      The status of the package or null if it is not yet downloaded. If the package is currently being downloaded, its status is returned.
    • suggestPackages

      public PackageInfoVector suggestPackages(MapPos mapPos, Projection projection)
      Suggests packages for given map position. Note that in order this to work, local package list must be available first.
      Parameters:
      mapPos - The map position.
      projection - The projection for the map position.
      Returns:
      The sorted list of suggested packages (from the best to the worst). The list may contain downloaded packages.
    • isAreaDownloaded

      public boolean isAreaDownloaded(MapBounds mapBounds, int zoom, Projection projection)
      Tests if the specified map area at specified zoom level is downloaded.
      Parameters:
      mapBounds - The area bounding box.
      zoom - The zoom level to check.
      projection - The projection for the bounding box.
      Returns:
      True if all required tiles are downloaded and available. False otherwise.
    • startPackageListDownload

      public boolean startPackageListDownload()
      Starts downloading package list asynchronously. When this task finishes, listener is called and server package list is updated.
      Returns:
      True if the package list will be downloaded and listener will be notified (if set). False if it can not be downloaded.
    • startPackageImport

      public boolean startPackageImport(String packageId, int version, String packageFileName)
      Starts importing the specified package asynchronously. When this task finishes, listener is called and local package list is updated.
      Note 1: In general, package manager may need temporary storage equal to the size of the package during import. It is the responsibility of the app to perform such checks.
      Note 2: the package may not be deleted after this call, as the import is asynchronous operation. It is safe to delete the original file once import is complete (this is notified via manager listener).
      Parameters:
      packageId - The id of the package to download.
      version - The version of the package.
      packageFileName - The fully qualified path of the package. The file name may also refer to URL or asset (using 'asset://' prefix).
      Returns:
      True is the package will be imported.
    • startPackageDownload

      public boolean startPackageDownload(String packageId)
      Starts downloading specified package asynchronously. When this task finishes, listener is called and local package list is updated.
      Note: In general, package manager may need temporary storage equal to the size of the package during download. It is the responsibility of the app to perform such checks.
      Parameters:
      packageId - The id of the package to download.
      Returns:
      True is the package is available and will be downloaded. False if the package was not found.
    • startPackageRemove

      public boolean startPackageRemove(String packageId)
      Starts the removal of specified package asynchronously. When this task finishes, listener is called and local package list is updated.
      Parameters:
      packageId - The id of the package to remove.
      Returns:
      True is the package was found and will be removed. False if the package was not found.
    • cancelPackageTasks

      public void cancelPackageTasks(String packageId)
      Cancels the current/pending tasks involving of the specified package.
      Parameters:
      packageId - The id of the package to cancel.
    • setPackagePriority

      public void setPackagePriority(String packageId, int priority)
      Sets the priority of the specific package.
      If the given priority is higher than priority of any other package, other operations will be paused and this package is processed immediately.
      If the given priority is set to negative value, package download will be paused until priority is reset to non-negative value.
      Parameters:
      packageId - The id of the download package.
      priority - The priority of the download package. If it is less than zero, package download is paused.