IT. Expert System.

Android Reference

DownloadManagerBaseTest


android.app

Class DownloadManagerBaseTest

    • Constructor Detail

      • DownloadManagerBaseTest

        public DownloadManagerBaseTest()
    • Method Detail

      • buildResponse

        protected MockResponse buildResponse(int status)
        Helper to build a response from the MockWebServer with no body.
        Parameters:
        status - The HTTP status code to return for this response
        Returns:
        Returns the mock web server response that was queued (which can be modified)
      • buildResponse

        protected MockResponse buildResponse(int status,
                                 byte[] body)
        Helper to build a response from the MockWebServer.
        Parameters:
        status - The HTTP status code to return for this response
        body - The body to return in this response
        Returns:
        Returns the mock web server response that was queued (which can be modified)
      • buildResponse

        protected MockResponse buildResponse(int status,
                                 File bodyFile)
                                      throws FileNotFoundException,
                                             IOException
        Helper to build a response from the MockWebServer.
        Parameters:
        status - The HTTP status code to return for this response
        bodyFile - The body to return in this response
        Returns:
        Returns the mock web server response that was queued (which can be modified)
        Throws:
        FileNotFoundException
        IOException
      • enqueueResponse

        protected void enqueueResponse(MockResponse resp)
      • verifyFileSize

        protected void verifyFileSize(ParcelFileDescriptor pfd,
                          long size)
        Helper to verify the size of a file.
        Parameters:
        pfd - The input file to compare the size of
        size - The expected size of the file
      • verifyFileContents

        protected void verifyFileContents(ParcelFileDescriptor actual,
                              byte[] expected)
                                   throws IOException
        Helper to verify the contents of a downloaded file versus a byte[].
        Parameters:
        actual - The file of whose contents to verify
        expected - The data we expect to find in the aforementioned file
        Throws:
        IOException - if there was a problem reading from the file
      • compareByteArrays

        protected void compareByteArrays(byte[] actual,
                             byte[] expected)
        Helper to compare 2 byte arrays.
        Parameters:
        actual - The array whose data we want to verify
        expected - The array of data we expect to see
      • verifyFileContents

        protected void verifyFileContents(ParcelFileDescriptor pfd,
                              File file)
                                   throws IOException
        Verifies the contents of a downloaded file versus the contents of a File.
        Parameters:
        pfd - The file whose data we want to verify
        file - The file containing the data we expect to see in the aforementioned file
        Throws:
        IOException - If there was a problem reading either of the two files
      • setServerMimeType

        protected void setServerMimeType(DownloadManagerBaseTest.DownloadFileType type)
        Sets the MIME type of file that will be served from the mock server
        Parameters:
        type - The MIME type to return from the server
      • getMimeMapping

        protected String getMimeMapping(DownloadManagerBaseTest.DownloadFileType type)
        Gets the MIME content string for a given type
        Parameters:
        type - The MIME type to return
        Returns:
        the String representation of that MIME content type
      • getServerUri

        protected Uri getServerUri(String filename)
                            throws Exception
        Gets the Uri that should be used to access the mock server
        Parameters:
        filename - The name of the file to try to retrieve from the mock server
        Returns:
        the Uri to use for access the file on the mock server
        Throws:
        Exception
      • logDBColumnData

        protected void logDBColumnData(Cursor cursor,
                           String column)
        Gets the Uri that should be used to access the mock server
        Parameters:
        filename - The name of the file to try to retrieve from the mock server
      • registerNewMultipleDownloadsReceiver

        protected DownloadManagerBaseTest.MultipleDownloadsCompletedReceiver registerNewMultipleDownloadsReceiver()
        Helper to create and register a new MultipleDownloadCompletedReciever This is used to track many simultaneous downloads by keeping count of all the downloads that have completed.
        Returns:
        A new receiver that records and can be queried on how many downloads have completed.
      • verifyAndCleanupSingleFileDownload

        protected void verifyAndCleanupSingleFileDownload(long requestId,
                                              byte[] fileData)
                                                   throws Exception
        Helper to verify a standard single-file download from the mock server, and clean up after verification Note that this also calls the Download manager's remove, which cleans up the file from cache.
        Parameters:
        requestId - The id of the download to remove
        fileData - The data to verify the file contains
        Throws:
        Exception
      • setWiFiStateOn

        protected void setWiFiStateOn(boolean enable)
                               throws Exception
        Enables or disables WiFi. Note: Needs the following permissions: android.permission.ACCESS_WIFI_STATE android.permission.CHANGE_WIFI_STATE
        Parameters:
        enable - true if it should be enabled, false if it should be disabled
        Throws:
        Exception
      • setAirplaneModeOn

        protected void setAirplaneModeOn(boolean enable)
                                  throws Exception
        Helper to enables or disables airplane mode. If successful, it also broadcasts an intent indicating that the mode has changed. Note: Needs the following permission: android.permission.WRITE_SETTINGS
        Parameters:
        enable - true if airplane mode should be ON, false if it should be OFF
        Throws:
        Exception
      • createFileOnSD

        protected File createFileOnSD(String filename,
                          long fileSize,
                          DownloadManagerBaseTest.DataType type,
                          String subdirectory)
                               throws IOException
        Helper to create a large file of random data on the SD card.
        Parameters:
        filename - (optional) The name of the file to create on the SD card; pass in null to use a default temp filename.
        type - The type of file to create
        subdirectory - If not null, the subdirectory under the SD card where the file should go
        Returns:
        The File that was created
        Throws:
        IOException - if there was an error while creating the file.
      • waitForDownloadOrTimeout_skipNotification

        protected void waitForDownloadOrTimeout_skipNotification(long id)
                                                          throws TimeoutException,
                                                                 InterruptedException
        Helper to wait for a particular download to finish, or else a timeout to occur Does not wait for a receiver notification of the download.
        Parameters:
        id - The download id to query on (wait for)
        Throws:
        TimeoutException
        InterruptedException
      • waitForDownloadOrTimeout

        protected void waitForDownloadOrTimeout(long id)
                                         throws TimeoutException,
                                                InterruptedException
        Helper to wait for a particular download to finish, or else a timeout to occur Also guarantees a notification has been posted for the download.
        Parameters:
        id - The download id to query on (wait for)
        Throws:
        TimeoutException
        InterruptedException
      • waitForDownloadOrTimeout

        protected void waitForDownloadOrTimeout(long id,
                                    long poll,
                                    long timeoutMillis)
                                         throws TimeoutException,
                                                InterruptedException
        Helper to wait for a particular download to finish, or else a timeout to occur Also guarantees a notification has been posted for the download.
        Parameters:
        id - The download id to query on (wait for)
        poll - The amount of time to wait
        timeoutMillis - The max time (in ms) to wait for the download(s) to complete
        Throws:
        TimeoutException
        InterruptedException
      • waitForDownloadsOrTimeout

        protected void waitForDownloadsOrTimeout(long poll,
                                     long timeoutMillis)
                                          throws TimeoutException,
                                                 InterruptedException
        Helper to wait for all downloads to finish, or else a specified timeout to occur Makes no guaranee that notifications have been posted for all downloads.
        Parameters:
        poll - The amount of time to wait
        timeoutMillis - The max time (in ms) to wait for the download(s) to complete
        Throws:
        TimeoutException
        InterruptedException
      • waitForDownloadOrTimeoutNoThrow

        protected boolean waitForDownloadOrTimeoutNoThrow(long id,
                                              long poll,
                                              long timeoutMillis)
        Helper to wait for all downloads to finish, or else a timeout to occur, but does not throw Also guarantees a notification has been posted for the download.
        Parameters:
        id - The id of the download to query against
        poll - The amount of time to wait
        timeoutMillis - The max time (in ms) to wait for the download(s) to complete
        Returns:
        true if download completed successfully (didn't timeout), false otherwise
      • timeoutWait

        protected int timeoutWait(int currentTotalWaitTime,
                      long poll,
                      long maxTimeoutMillis,
                      String timedOutMessage)
                           throws TimeoutException
        Helper function to synchronously wait, or timeout if the maximum threshold has been exceeded.
        Parameters:
        currentTotalWaitTime - The total time waited so far
        poll - The amount of time to wait
        maxTimeoutMillis - The total wait time threshold; if we've waited more than this long, we timeout and fail
        timedOutMessage - The message to display in the failure message if we timeout
        Returns:
        The new total amount of time we've waited so far
        Throws:
        TimeoutException - if timed out waiting for SD card to mount
      • doWaitForDownloadsOrTimeout

        protected void doWaitForDownloadsOrTimeout(DownloadManager.Query query,
                                       long poll,
                                       long timeoutMillis)
                                            throws TimeoutException
        Helper to wait for all downloads to finish, or else a timeout to occur
        Parameters:
        query - The query to pass to the download manager
        poll - The poll time to wait between checks
        timeoutMillis - The max amount of time (in ms) to wait for the download(s) to complete
        Throws:
        TimeoutException
      • waitForExternalStoreMount

        protected void waitForExternalStoreMount()
                                          throws Exception
        Synchronously waits for external store to be mounted (eg: SD Card).
        Throws:
        InterruptedException - if interrupted
        Exception - if timed out waiting for SD card to mount
      • waitForDownloadToStart

        protected void waitForDownloadToStart(long dlRequest)
                                       throws Exception
        Synchronously waits for a download to start.
        Parameters:
        dlRequest - the download request id used by Download Manager to track the download.
        Throws:
        Exception - if timed out while waiting for SD card to mount
      • waitForReceiverNotification

        protected void waitForReceiverNotification()
                                            throws Exception
        Convenience function to wait for just 1 notification of a download.
        Throws:
        Exception - if timed out while waiting
      • waitForReceiverNotifications

        protected void waitForReceiverNotifications(int targetNumber)
                                             throws TimeoutException
        Synchronously waits for our receiver to receive notification for a given number of downloads.
        Parameters:
        targetNumber - The number of notifications for unique downloads to wait for; pass in -1 to not wait for notification.
        Throws:
        Exception - if timed out while waiting
        TimeoutException
      • waitForFileToGrow

        protected void waitForFileToGrow(File file)
                                  throws Exception
        Synchronously waits for a file to increase in size (such as to monitor that a download is progressing).
        Parameters:
        file - The file whose size to track.
        Throws:
        Exception - if timed out while waiting for the file to grow in size.
      • removeAllCurrentDownloads

        protected void removeAllCurrentDownloads()
        Helper to remove all downloads that are registered with the DL Manager. Note: This gives us a clean slate b/c it includes downloads that are pending, running, paused, or have completed.
      • doStandardEnqueue

        protected long doStandardEnqueue(byte[] body)
                                  throws Exception
        Helper to perform a standard enqueue of data to the mock server. download is performed to the downloads cache dir (NOT systemcache dir)
        Parameters:
        body - The body to return in the response from the server
        Throws:
        Exception
      • enqueueDownloadRequest

        protected long enqueueDownloadRequest(byte[] body,
                                  int location)
                                       throws Exception
        Throws:
        Exception
      • doStandardEnqueue

        protected long doStandardEnqueue(File body)
                                  throws Exception
        Helper to perform a standard enqueue of data to the mock server.
        Parameters:
        body - The body to return in the response from the server, contained in the file
        Throws:
        Exception
      • enqueueDownloadRequest

        protected long enqueueDownloadRequest(File body,
                                  int location)
                                       throws Exception
        Throws:
        Exception
      • doCommonStandardEnqueue

        protected long doCommonStandardEnqueue()
                                        throws Exception
        Helper to do the additional steps (setting title and Uri of default filename) when doing a standard enqueue request to the server.
        Throws:
        Exception
      • verifyInt

        protected void verifyInt(Cursor cursor,
                     String columnName,
                     int expected)
        Helper to verify an int value in a Cursor
        Parameters:
        cursor - The cursor containing the query results
        columnName - The name of the column to query
        expected - The expected int value
      • verifyString

        protected void verifyString(Cursor cursor,
                        String columnName,
                        String expected)
        Helper to verify a String value in a Cursor
        Parameters:
        cursor - The cursor containing the query results
        columnName - The name of the column to query
        expected - The expected String value
      • getCursor

        protected Cursor getCursor(long id)
                            throws Exception
        Performs a query based on ID and returns a Cursor for the query.
        Parameters:
        id - The id of the download in DL Manager; pass -1 to query all downloads
        Returns:
        A cursor for the query results
        Throws:
        Exception
      • doBasicDownload

        protected long doBasicDownload(byte[] blobData,
                           int location)
                                throws Exception
        Helper that does the actual basic download verification.
        Throws:
        Exception


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 405 / . Delta: 0.04216 с