Browser: real download path can't match the displayed path

When download type is image/audio/video,will put them in corresponding
subfolder Pictures/Music/Movies not only in Download subfolder.So the
path can't match the displayed path.

Move the code change into Browser app.So that when user try to
download some file whose type is image/audio/video,download settings
will show the corresponding subfolder to let user download in.

CRs-Fixed: 539491

Change-Id: Ia5b77501d402bc02b7578a70bac7b6554278a671
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 7d0223c..e16cb17 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -454,7 +454,7 @@
     <string name="download_file_exist_msg">文件已经存在,请重新输入文件名!</string>
     <string name="download_file_exist">文件已经存在</string>
     <string name ="time_min">分钟</string>
-    <string name="download_path_phone_stroage_label">/内置存储器</string>
+    <string name="download_path_phone_storage_label">/内置存储器</string>
     <string name="download_path_sd_card_label">/SD卡</string>
     <string name="download_path_unavailable_dlg_title">浏览器的下载路径不可达</string>
     <string name="download_path_unavailable_dlg_msg">请重新设置浏览器的下载路径</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index dab4f51..e4c2fd3 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1069,7 +1069,7 @@
     <string name="download_file_exist_msg">This File is Already Exist,Please Input a New File\'s Name!</string>
     <string name="download_file_exist">File Exist</string>
     <string name ="time_min">min</string>
-    <string name="download_path_phone_stroage_label">/Phone Stroage</string>
+    <string name="download_path_phone_storage_label">/Phone Storage</string>
     <string name="download_path_sd_card_label">/SD card</string>
     <string name="download_path_unavailable_dlg_title">Download Directory is Unavailable</string>
     <string name="download_path_unavailable_dlg_msg">Please modify the Download Directory of Browser</string>
diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java
index 15167a0..1ce33da 100644
--- a/src/com/android/browser/DownloadHandler.java
+++ b/src/com/android/browser/DownloadHandler.java
@@ -566,7 +566,7 @@
             downloadPath = downloadPath.replace(sdCardDir, sdCardLabel);
         } else if ((phoneStorageDir != null) && downloadPath.startsWith(phoneStorageDir)) {
             String phoneStorageLabel = activity.getResources().getString(
-                    R.string.download_path_phone_stroage_label);
+                    R.string.download_path_phone_storage_label);
             downloadPath = downloadPath.replace(phoneStorageDir, phoneStorageLabel);
         }
         return downloadPath;
diff --git a/src/com/android/browser/DownloadSettings.java b/src/com/android/browser/DownloadSettings.java
index aecb543..698fa88 100644
--- a/src/com/android/browser/DownloadSettings.java
+++ b/src/com/android/browser/DownloadSettings.java
@@ -36,6 +36,7 @@
 import java.lang.Thread;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.Environment;
 import android.text.format.*;
 import android.util.Log;
 import android.view.View;
@@ -115,7 +116,8 @@
                 BrowserUtils.FILENAME_MAX_LENGTH);
 
         downloadFilenameET.setText(filenameBase);
-        downloadPath = BrowserSettings.getInstance().getDownloadPath();
+        downloadPath = chooseFolderFromMimeType(BrowserSettings.getInstance().getDownloadPath(),
+                mimetype);
         downloadPathForUser = DownloadHandler.getDownloadPathForUser(DownloadSettings.this,
                 downloadPath);
         setDownloadPathForUserText(downloadPathForUser);
@@ -238,6 +240,22 @@
         }
     }
 
+    // Add for carrier feature - download to related folders by mimetype.
+    private static String chooseFolderFromMimeType(String path, String mimeType) {
+        String destinationFolder = null;
+        if (!path.contains(Environment.DIRECTORY_DOWNLOADS) || null == mimeType)
+            return path;
+        if (mimeType.startsWith("audio"))
+            destinationFolder = Environment.DIRECTORY_MUSIC;
+        else if (mimeType.startsWith("video"))
+            destinationFolder = Environment.DIRECTORY_MOVIES;
+        else if (mimeType.startsWith("image"))
+            destinationFolder = Environment.DIRECTORY_PICTURES;
+        if (null != destinationFolder)
+            path = path.replace(Environment.DIRECTORY_DOWNLOADS, destinationFolder);
+        return path;
+    }
+
     /**
      * show download path for user
      *