OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.DownloadManager; | 8 import android.app.DownloadManager; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
13 import android.net.Uri; | 13 import android.net.Uri; |
14 import android.os.AsyncTask; | 14 import android.os.AsyncTask; |
15 import android.os.Environment; | 15 import android.os.Environment; |
16 import android.os.ParcelFileDescriptor; | 16 import android.os.ParcelFileDescriptor; |
17 import android.provider.Browser; | 17 import android.provider.Browser; |
18 import android.support.v7.app.AlertDialog; | 18 import android.support.v7.app.AlertDialog; |
19 import android.text.TextUtils; | 19 import android.text.TextUtils; |
20 import android.util.Log; | 20 import android.util.Log; |
21 import android.util.LongSparseArray; | 21 import android.util.LongSparseArray; |
22 import android.view.LayoutInflater; | 22 import android.view.LayoutInflater; |
23 import android.view.View; | 23 import android.view.View; |
24 import android.webkit.URLUtil; | 24 import android.webkit.URLUtil; |
25 import android.widget.TextView; | 25 import android.widget.TextView; |
26 | 26 |
| 27 import org.xmlpull.v1.XmlPullParser; |
| 28 import org.xmlpull.v1.XmlPullParserException; |
| 29 import org.xmlpull.v1.XmlPullParserFactory; |
| 30 |
27 import org.chromium.base.ApplicationStatus; | 31 import org.chromium.base.ApplicationStatus; |
28 import org.chromium.base.VisibleForTesting; | 32 import org.chromium.base.VisibleForTesting; |
29 import org.chromium.chrome.R; | 33 import org.chromium.chrome.R; |
30 import org.chromium.chrome.browser.ChromeApplication; | 34 import org.chromium.chrome.browser.ChromeApplication; |
31 import org.xmlpull.v1.XmlPullParser; | |
32 import org.xmlpull.v1.XmlPullParserException; | |
33 import org.xmlpull.v1.XmlPullParserFactory; | |
34 | 35 |
35 import java.io.DataOutputStream; | 36 import java.io.DataOutputStream; |
36 import java.io.File; | 37 import java.io.File; |
37 import java.io.FileInputStream; | 38 import java.io.FileInputStream; |
38 import java.io.FileNotFoundException; | 39 import java.io.FileNotFoundException; |
39 import java.io.IOException; | 40 import java.io.IOException; |
40 import java.io.InputStream; | 41 import java.io.InputStream; |
41 import java.net.HttpURLConnection; | 42 import java.net.HttpURLConnection; |
42 import java.net.MalformedURLException; | 43 import java.net.MalformedURLException; |
43 import java.net.URL; | 44 import java.net.URL; |
44 import java.util.ArrayList; | 45 import java.util.ArrayList; |
45 import java.util.Arrays; | 46 import java.util.Arrays; |
46 import java.util.HashMap; | 47 import java.util.HashMap; |
47 import java.util.List; | 48 import java.util.List; |
48 import java.util.Map; | 49 import java.util.Map; |
49 | 50 |
50 /** | 51 /** |
51 * This class handles OMA downloads according to the steps described in | 52 * This class handles OMA downloads according to the steps described in |
52 * http://xml.coverpages.org/OMA-Download-OTA-V10-20020620.pdf: | 53 * http://xml.coverpages.org/OMA-Download-OTA-V10-20020620.pdf: |
53 * 1. Receives a download descriptor xml file. | 54 * 1. Receives a download descriptor xml file. |
54 * 2. Parses all the contents. | 55 * 2. Parses all the contents. |
55 * 3. Checks device capability to see if it is able to handle the content. | 56 * 3. Checks device capability to see if it is able to handle the content. |
56 * 4. Find the objectURI value from the download descriptor and prompt user with | 57 * 4. Find the objectURI value from the download descriptor and prompt user with |
57 * a dialog to proceed with the download. | 58 * a dialog to proceed with the download. |
58 * 5. On positive confirmation, sends a request to the download manager. | 59 * 5. On positive confirmation, sends a request to the download manager. |
59 * 6. Once the download is completed, sends a message to the server if installNo
tifyURI | 60 * 6. Once the download is completed, sends a message to the server if installNo
tifyURI |
60 * is present in the download descriptor. | 61 * is present in the download descriptor. |
61 * 7. Prompts user with a dialog to open the NextURL specified in the download d
escriptor. | 62 * 7. Prompts user with a dialog to open the NextURL specified in the download d
escriptor. |
62 * If steps 2 - 6 fails, a warning dialog will be prompted to the user to let hi
m | 63 * If steps 2 - 6 fails, a warning dialog will be prompted to the user to let th
em |
63 * know the error. Steps 6-7 will be executed afterwards. | 64 * know the error. Steps 6-7 will be executed afterwards. |
64 * If installNotifyURI is present in the download descriptor, the downloaded con
tent will | 65 * If installNotifyURI is present in the download descriptor, the downloaded con
tent will |
65 * be saved to the app directory first. If step 6 completes successfully, the co
ntent will | 66 * be saved to the app directory first. If step 6 completes successfully, the co
ntent will |
66 * be moved to the public external storage. Otherwise, it will be removed from t
he device. | 67 * be moved to the public external storage. Otherwise, it will be removed from t
he device. |
67 */ | 68 */ |
68 public class OMADownloadHandler { | 69 public class OMADownloadHandler { |
69 private static final String TAG = "OMADownloadHandler"; | 70 private static final String TAG = "OMADownloadHandler"; |
70 | 71 |
71 // MIME types for OMA downloads. | 72 // MIME types for OMA downloads. |
72 public static final String OMA_DOWNLOAD_DESCRIPTOR_MIME = "application/vnd.o
ma.dd+xml"; | 73 public static final String OMA_DOWNLOAD_DESCRIPTOR_MIME = "application/vnd.o
ma.dd+xml"; |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 } | 732 } |
732 } | 733 } |
733 showNextUrlDialog(mOMAInfo); | 734 showNextUrlDialog(mOMAInfo); |
734 } else if (mDownloadId != DownloadItem.INVALID_DOWNLOAD_ID) { | 735 } else if (mDownloadId != DownloadItem.INVALID_DOWNLOAD_ID) { |
735 // Remove the downloaded content. | 736 // Remove the downloaded content. |
736 manager.remove(mDownloadId); | 737 manager.remove(mDownloadId); |
737 } | 738 } |
738 } | 739 } |
739 } | 740 } |
740 } | 741 } |
OLD | NEW |