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:04 +0000
commit839ffc3675664de26bd34337b41ef232f3076cc6 (patch)
tree495e1a6d3e97cb0c2295b361a1f485bf1b5fc3c9
parente1913eb1fb84fc782bd3bb5d49ff75ed3b89ca06 (diff)
downloadandroid_packages_apps_CMFileManager-839ffc3675664de26bd34337b41ef232f3076cc6.tar.gz
android_packages_apps_CMFileManager-839ffc3675664de26bd34337b41ef232f3076cc6.tar.bz2
android_packages_apps_CMFileManager-839ffc3675664de26bd34337b41ef232f3076cc6.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)
-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