Bug1276588 Handling Hyphenation-Dictionaries in DownloadAction r?sebastian draft
authorKrishna <k.krish@yahoo.com>
Sun, 04 Dec 2016 23:06:35 +0800
changeset 447361 34b0fb28e8c0a33b2a3102755d642450319b468e
parent 447335 6bdef7ba8b4108a996b9f61ef9f81c5ea6c93017
child 447362 387e818305c549076531b4298b2ff0ac7167adf1
push id38047
push userk.krish@yahoo.com
push dateSun, 04 Dec 2016 15:07:22 +0000
reviewerssebastian
bugs1276588
milestone53.0a1
Bug1276588 Handling Hyphenation-Dictionaries in DownloadAction r?sebastian MozReview-Commit-ID: GTuR0IarjGe
mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java
mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java
mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java
@@ -89,29 +89,31 @@ public abstract class BaseAction {
             super(cause);
         }
     }
 
     public abstract void perform(Context context, DownloadContentCatalog catalog);
 
     protected File getDestinationFile(Context context, DownloadContent content)
             throws UnrecoverableDownloadContentException, RecoverableDownloadContentException {
+        File destinationDirectory;
         if (content.isFont()) {
-            File destinationDirectory = new File(context.getApplicationInfo().dataDir, "fonts");
-
-            if (!destinationDirectory.exists() && !destinationDirectory.mkdirs()) {
-                throw new RecoverableDownloadContentException(RecoverableDownloadContentException.DISK_IO,
-                        "Destination directory does not exist and cannot be created");
-            }
-
-            return new File(destinationDirectory, content.getFilename());
+            destinationDirectory = new File(context.getApplicationInfo().dataDir, "fonts");
+        } else if (content.isHyphenationDictionary()) {
+            destinationDirectory = new File(context.getApplicationInfo().dataDir, "hyphenation");
+        } else {
+            throw new UnrecoverableDownloadContentException("Can't determine destination for kind: " + content.getKind());
         }
 
-        // Unrecoverable: We downloaded a file and we don't know what to do with it (Should not happen)
-        throw new UnrecoverableDownloadContentException("Can't determine destination for kind: " + content.getKind());
+        if (!destinationDirectory.exists() && !destinationDirectory.mkdirs()) {
+            throw new RecoverableDownloadContentException(RecoverableDownloadContentException.DISK_IO,
+                    "Destination directory does not exist and cannot be created");
+        }
+
+        return new File(destinationDirectory, content.getFilename());
     }
 
     protected boolean verify(File file, String expectedChecksum)
             throws RecoverableDownloadContentException, UnrecoverableDownloadContentException {
         InputStream inputStream = null;
 
         try {
             inputStream = new BufferedInputStream(new FileInputStream(file));
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
@@ -6,34 +6,30 @@
 package org.mozilla.gecko.dlc;
 
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.support.v4.net.ConnectivityManagerCompat;
 import android.util.Log;
 
-import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.dlc.catalog.DownloadContent;
 import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog;
-import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.IOUtils;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.zip.GZIPInputStream;
 
 /**
  * Download content that has been scheduled during "study" or "verify".
  */
 public class DownloadAction extends BaseAction {
     private static final String LOGTAG = "DLCDownloadAction";
 
@@ -248,18 +244,16 @@ public class DownloadAction extends Base
     }
 
     protected boolean isActiveNetworkMetered(Context context) {
         return ConnectivityManagerCompat.isActiveNetworkMetered(
                 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
     }
 
     protected String createDownloadURL(DownloadContent content) {
-        final String location = content.getLocation();
-
         return CDN_BASE_URL + content.getLocation();
     }
 
     protected File createTemporaryFile(Context context, DownloadContent content)
             throws RecoverableDownloadContentException {
         File cacheDirectory = new File(context.getCacheDir(), CACHE_DIRECTORY);
 
         if (!cacheDirectory.exists() && !cacheDirectory.mkdirs()) {
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java
@@ -24,17 +24,17 @@ public class StudyAction extends BaseAct
         Log.d(LOGTAG, "Studying catalog..");
 
         for (DownloadContent content : catalog.getContentToStudy()) {
             if (!isMatching(context, content)) {
                 // This content is not for this particular version of the application or system
                 continue;
             }
 
-            if (content.isAssetArchive() && content.isFont()) {
+            if (content.isKnownContent()) {
                 catalog.scheduleDownload(content);
 
                 Log.d(LOGTAG, "Scheduled download: " + content);
             }
         }
 
         if (catalog.hasScheduledDownloads()) {
             startDownloads(context);
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java
@@ -125,17 +125,17 @@ public class SyncAction extends BaseActi
         try {
             Uri.Builder builder = Uri.parse(CATALOG_ENDPOINT).buildUpon();
 
             if (lastModified > 0) {
                 builder.appendQueryParameter(KINTO_PARAMETER_SINCE, String.valueOf(lastModified));
             }
             // Only select the fields we are actually going to read.
             builder.appendQueryParameter(KINTO_PARAMETER_FIELDS,
-                    "attachment.location,attachment.original.filename,attachment.original.hash,attachment.hash,type,kind,attachment.original.size,match");
+                    "type,kind,attachment.location,attachment.hash,attachment.original.size,attachment.original.filename,attachment.original.hash,match");
 
             // We want to process items in the order they have been modified. This is to ensure that
             // our last_modified values are correct if we processing is interrupted and not all items
             // have been processed.
             builder.appendQueryParameter(KINTO_PARAMETER_SORT, "last_modified");
 
             connection = buildHttpURLConnection(builder.build().toString());