aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Garnes <matt@cyngn.com>2015-04-01 11:38:44 -0700
committerMatt Garnes <matt@cyngn.com>2015-04-01 18:46:27 +0000
commitad9e51955f2489a4e0d62cccc7f71aaf0d1bc1b7 (patch)
tree64857b6704917435e21f9ec9a6c44985b50c84ee
parentbfd2ad6ad5937aede7dcd1df31b88caa59cb78b9 (diff)
downloadandroid_packages_apps_CMFileManager-ad9e51955f2489a4e0d62cccc7f71aaf0d1bc1b7.tar.gz
android_packages_apps_CMFileManager-ad9e51955f2489a4e0d62cccc7f71aaf0d1bc1b7.tar.bz2
android_packages_apps_CMFileManager-ad9e51955f2489a4e0d62cccc7f71aaf0d1bc1b7.zip
Catch RuntimeException when opening 3gp files for inspection.
When reading metadata from .3gp files, FileManager can crash if the file is unreadable. MediaMetaDataRetriever.setDataSource() throws RuntimeException if this happens. Catch it. Fixes NIGHTLIES-958. Change-Id: I465f7c961793b468e0469a5844894f3ed56b374c (cherry picked from commit 4bd0d070f76d5180e6de1d20843bb9c16a782f4c) (cherry picked from commit 839ffc3675664de26bd34337b41ef232f3076cc6)
-rw-r--r--src/com/cyanogenmod/filemanager/util/AmbiguousExtensionHelper.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/com/cyanogenmod/filemanager/util/AmbiguousExtensionHelper.java b/src/com/cyanogenmod/filemanager/util/AmbiguousExtensionHelper.java
index 567ae5de..3aaeb691 100644
--- a/src/com/cyanogenmod/filemanager/util/AmbiguousExtensionHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/AmbiguousExtensionHelper.java
@@ -17,6 +17,8 @@
package com.cyanogenmod.filemanager.util;
import android.media.MediaMetadataRetriever;
+import android.util.Log;
+
import java.util.HashMap;
/**
@@ -50,6 +52,7 @@ public abstract class AmbiguousExtensionHelper {
* on the content of the file.
*/
public static class ThreeGPExtensionHelper extends AmbiguousExtensionHelper {
+ private static final String TAG = "ThreeGPExtensionHelper";
private static final String[] sSupportedExtensions = {"3gp", "3gpp", "3g2", "3gpp2"};
public static final String VIDEO_3GPP_MIME_TYPE = "video/3gpp";
public static final String AUDIO_3GPP_MIME_TYPE = "audio/3gpp";
@@ -59,15 +62,22 @@ public abstract class AmbiguousExtensionHelper {
@Override
public String getMimeType(String absolutePath, String extension) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
- retriever.setDataSource(absolutePath);
- boolean hasVideo =
- retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO) != null;
- if (is3GPP(extension)) {
- return hasVideo ? VIDEO_3GPP_MIME_TYPE : AUDIO_3GPP_MIME_TYPE;
- } else if (is3GPP2(extension)) {
- return hasVideo ? VIDEO_3GPP2_MIME_TYPE : AUDIO_3GPP2_MIME_TYPE;
+ try {
+ retriever.setDataSource(absolutePath);
+ boolean hasVideo =
+ retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO) !=
+ null;
+ if (is3GPP(extension)) {
+ return hasVideo ? VIDEO_3GPP_MIME_TYPE : AUDIO_3GPP_MIME_TYPE;
+ } else if (is3GPP2(extension)) {
+ return hasVideo ? VIDEO_3GPP2_MIME_TYPE : AUDIO_3GPP2_MIME_TYPE;
+ }
+ } catch (RuntimeException e) {
+ Log.e(TAG, "Unable to open 3GP file to determine mimetype");
}
- return null;
+ // Default to video 3gp if the file is unreadable as this was the default before
+ // ambiguous resolution support was added.
+ return VIDEO_3GPP_MIME_TYPE;
}
@Override