Home | History | Annotate | Download | only in downloads
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.providers.downloads;
     18 
     19 import android.os.Build;
     20 import android.os.Environment;
     21 import android.text.TextUtils;
     22 import android.util.Log;
     23 
     24 /**
     25  * Contains the internal constants that are used in the download manager.
     26  * As a general rule, modifying these constants should be done with care.
     27  */
     28 public class Constants {
     29 
     30     /** Tag used for debugging/logging */
     31     public static final String TAG = "DownloadManager";
     32 
     33     /** The column that used to be used for the HTTP method of the request */
     34     public static final String RETRY_AFTER_X_REDIRECT_COUNT = "method";
     35 
     36     /** The column that used to be used for the magic OTA update filename */
     37     public static final String OTA_UPDATE = "otaupdate";
     38 
     39     /** The column that used to be used to reject system filetypes */
     40     public static final String NO_SYSTEM_FILES = "no_system";
     41 
     42     /** The column that is used for the downloads's ETag */
     43     public static final String ETAG = "etag";
     44 
     45     /** The column that is used for the initiating app's UID */
     46     public static final String UID = "uid";
     47 
     48     /** The column that is used to remember whether the media scanner was invoked */
     49     public static final String MEDIA_SCANNED = "scanned";
     50 
     51     /** The intent that gets sent when the service must wake up for a retry */
     52     public static final String ACTION_RETRY = "android.intent.action.DOWNLOAD_WAKEUP";
     53 
     54     /** the intent that gets sent when clicking a successful download */
     55     public static final String ACTION_OPEN = "android.intent.action.DOWNLOAD_OPEN";
     56 
     57     /** the intent that gets sent when clicking an incomplete/failed download  */
     58     public static final String ACTION_LIST = "android.intent.action.DOWNLOAD_LIST";
     59 
     60     /** the intent that gets sent when deleting the notification of a completed download */
     61     public static final String ACTION_HIDE = "android.intent.action.DOWNLOAD_HIDE";
     62 
     63     /** The default base name for downloaded files if we can't get one at the HTTP level */
     64     public static final String DEFAULT_DL_FILENAME = "downloadfile";
     65 
     66     /** The default extension for html files if we can't get one at the HTTP level */
     67     public static final String DEFAULT_DL_HTML_EXTENSION = ".html";
     68 
     69     /** The default extension for text files if we can't get one at the HTTP level */
     70     public static final String DEFAULT_DL_TEXT_EXTENSION = ".txt";
     71 
     72     /** The default extension for binary files if we can't get one at the HTTP level */
     73     public static final String DEFAULT_DL_BINARY_EXTENSION = ".bin";
     74 
     75     public static final String PROVIDER_PACKAGE_NAME = "com.android.providers.downloads";
     76 
     77     /**
     78      * When a number has to be appended to the filename, this string is used to separate the
     79      * base filename from the sequence number
     80      */
     81     public static final String FILENAME_SEQUENCE_SEPARATOR = "-";
     82 
     83     /** Where we store downloaded files on the external storage */
     84     public static final String DEFAULT_DL_SUBDIR = "/" + Environment.DIRECTORY_DOWNLOADS;
     85 
     86     /** A magic filename that is allowed to exist within the system cache */
     87     public static final String RECOVERY_DIRECTORY = "recovery";
     88 
     89     /** The default user agent used for downloads */
     90     public static final String DEFAULT_USER_AGENT;
     91 
     92     static {
     93         final StringBuilder builder = new StringBuilder();
     94 
     95         final boolean validRelease = !TextUtils.isEmpty(Build.VERSION.RELEASE);
     96         final boolean validId = !TextUtils.isEmpty(Build.ID);
     97         final boolean includeModel = "REL".equals(Build.VERSION.CODENAME)
     98                 && !TextUtils.isEmpty(Build.MODEL);
     99 
    100         builder.append("AndroidDownloadManager");
    101         if (validRelease) {
    102             builder.append("/").append(Build.VERSION.RELEASE);
    103         }
    104         builder.append(" (Linux; U; Android");
    105         if (validRelease) {
    106             builder.append(" ").append(Build.VERSION.RELEASE);
    107         }
    108         if (includeModel || validId) {
    109             builder.append(";");
    110             if (includeModel) {
    111                 builder.append(" ").append(Build.MODEL);
    112             }
    113             if (validId) {
    114                 builder.append(" Build/").append(Build.ID);
    115             }
    116         }
    117         builder.append(")");
    118 
    119         DEFAULT_USER_AGENT = builder.toString();
    120     }
    121 
    122     /** The MIME type of APKs */
    123     public static final String MIMETYPE_APK = "application/vnd.android.package";
    124 
    125     /** The buffer size used to stream the data */
    126     public static final int BUFFER_SIZE = 4096;
    127 
    128     /** The minimum amount of progress that has to be done before the progress bar gets updated */
    129     public static final int MIN_PROGRESS_STEP = 4096;
    130 
    131     /** The minimum amount of time that has to elapse before the progress bar gets updated, in ms */
    132     public static final long MIN_PROGRESS_TIME = 1500;
    133 
    134     /** The maximum number of rows in the database (FIFO) */
    135     public static final int MAX_DOWNLOADS = 1000;
    136 
    137     /**
    138      * The number of times that the download manager will retry its network
    139      * operations when no progress is happening before it gives up.
    140      */
    141     public static final int MAX_RETRIES = 5;
    142 
    143     /**
    144      * The minimum amount of time that the download manager accepts for
    145      * a Retry-After response header with a parameter in delta-seconds.
    146      */
    147     public static final int MIN_RETRY_AFTER = 30; // 30s
    148 
    149     /**
    150      * The maximum amount of time that the download manager accepts for
    151      * a Retry-After response header with a parameter in delta-seconds.
    152      */
    153     public static final int MAX_RETRY_AFTER = 24 * 60 * 60; // 24h
    154 
    155     /**
    156      * The maximum number of redirects.
    157      */
    158     public static final int MAX_REDIRECTS = 5; // can't be more than 7.
    159 
    160     /**
    161      * The time between a failure and the first retry after an IOException.
    162      * Each subsequent retry grows exponentially, doubling each time.
    163      * The time is in seconds.
    164      */
    165     public static final int RETRY_FIRST_DELAY = 30;
    166 
    167     /** Enable separate connectivity logging */
    168     static final boolean LOGX = false;
    169 
    170     /** Enable verbose logging - use with "setprop log.tag.DownloadManager VERBOSE" */
    171     private static final boolean LOCAL_LOGV = false;
    172     public static final boolean LOGV = LOCAL_LOGV && Log.isLoggable(TAG, Log.VERBOSE);
    173 
    174     /** Enable super-verbose logging */
    175     private static final boolean LOCAL_LOGVV = false;
    176     public static final boolean LOGVV = LOCAL_LOGVV && LOGV;
    177 }
    178