diff options
author | Axesh R. Ajmera <aajmera@codeaurora.org> | 2014-04-01 16:03:42 -0700 |
---|---|---|
committer | WebTech Code Review <code-review@localhost> | 2014-04-01 21:06:12 -0700 |
commit | 7cfd7a7386a2fb315f5ec59af679e07ede49bc88 (patch) | |
tree | 1757e4856ef1d7bef8c6cf536c8eb83255e35495 /src/com/android/browser/DownloadSettings.java | |
parent | 5e631477197c54304a2a732f267bb09135015e44 (diff) | |
download | android_packages_apps_Gello-7cfd7a7386a2fb315f5ec59af679e07ede49bc88.tar.gz android_packages_apps_Gello-7cfd7a7386a2fb315f5ec59af679e07ede49bc88.tar.bz2 android_packages_apps_Gello-7cfd7a7386a2fb315f5ec59af679e07ede49bc88.zip |
Fix for download path when mimetype is not defined in response
- change mimetype of .apk files from octet-stream to vnd.package-archive
Change-Id: I000650f5355a5aeb363e67542898222f2582212e
Diffstat (limited to 'src/com/android/browser/DownloadSettings.java')
-rw-r--r-- | src/com/android/browser/DownloadSettings.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/com/android/browser/DownloadSettings.java b/src/com/android/browser/DownloadSettings.java index 2b8a8480..d9534e20 100644 --- a/src/com/android/browser/DownloadSettings.java +++ b/src/com/android/browser/DownloadSettings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * Copyright (c) 2013,2014, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -51,6 +51,8 @@ import android.view.Window; import android.widget.Toast; import android.text.TextUtils; +import com.android.browser.reflect.ReflectHelper; + public class DownloadSettings extends Activity { private EditText downloadFilenameET; @@ -78,6 +80,8 @@ public class DownloadSettings extends Activity { private boolean isDownloadStarted = false; private static final String ENV_EMULATED_STORAGE_TARGET = "EMULATED_STORAGE_TARGET"; + private static final String APK_TYPE="apk"; + private static final String OCTET_STREAM = "application/octet-stream"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -119,6 +123,23 @@ public class DownloadSettings extends Activity { BrowserUtils.FILENAME_MAX_LENGTH); downloadFilenameET.setText(filenameBase); + + String filenameExtension = DownloadHandler.getFilenameExtension(filename); + + if (mimetype == null || mimetype.isEmpty()) { + + String updatedFileName = filenameBase + "." + filenameExtension; + Object[] params = {updatedFileName}; + Class[] type = new Class[] {String.class}; + mimetype = (String) ReflectHelper.invokeStaticMethod("android.media.MediaFile", + "getMimeTypeForFile", type, params); + } + + //Add special check for .apk files with octet-stream mimetype + if (mimetype.equals(OCTET_STREAM) && filenameExtension.equals(APK_TYPE)) { + mimetype = "application/vnd.android.package-archive"; + } + downloadPath = chooseFolderFromMimeType(BrowserSettings.getInstance().getDownloadPath(), mimetype); downloadPathForUser = DownloadHandler.getDownloadPathForUser(DownloadSettings.this, @@ -126,7 +147,6 @@ public class DownloadSettings extends Activity { setDownloadPathForUserText(downloadPathForUser); setDownloadFileSizeText(); setDownloadFileTimeText(); - } private OnClickListener downloadPathListener = new OnClickListener() { @@ -197,7 +217,6 @@ public class DownloadSettings extends Activity { }; private OnClickListener downloadCancelListener = new OnClickListener() { - @Override public void onClick(View v) { finish(); |