aboutsummaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2012-11-03 02:19:58 +0100
committerJorge Ruesga <jorge@ruesga.com>2012-11-03 02:19:58 +0100
commitdcbeb44a5eac6eaee94c15f9b084db8470c70826 (patch)
treeadcac924e993e1189cc922b28e46ff8c2632602c /src/com
parentc409789a27a2e0fa7572d4b8cd1acffd7b8975f0 (diff)
downloadandroid_packages_apps_CMFileManager-dcbeb44a5eac6eaee94c15f9b084db8470c70826.tar.gz
android_packages_apps_CMFileManager-dcbeb44a5eac6eaee94c15f9b084db8470c70826.tar.bz2
android_packages_apps_CMFileManager-dcbeb44a5eac6eaee94c15f9b084db8470c70826.zip
CMFileManager: Avoid crashes when drawable is not found
From reported issue https://github.com/jruesga/CMFileManager/issues/27 This change avoid to use invalid drawables from invalid mime/type resolution. Use default drawable and audit the invalid resolution. Change-Id: I2e27ac4038c87515dfa63d89e15fba0bc68a87ae
Diffstat (limited to 'src/com')
-rw-r--r--src/com/cyanogenmod/filemanager/util/MimeTypeHelper.java78
1 files changed, 73 insertions, 5 deletions
diff --git a/src/com/cyanogenmod/filemanager/util/MimeTypeHelper.java b/src/com/cyanogenmod/filemanager/util/MimeTypeHelper.java
index e983fea2..05c638aa 100644
--- a/src/com/cyanogenmod/filemanager/util/MimeTypeHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/MimeTypeHelper.java
@@ -119,6 +119,59 @@ public final class MimeTypeHelper {
public MimeTypeCategory mCategory;
public String mMimeType;
public String mDrawable;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((this.mCategory == null) ? 0 : this.mCategory.hashCode());
+ result = prime * result
+ + ((this.mDrawable == null) ? 0 : this.mDrawable.hashCode());
+ result = prime * result
+ + ((this.mMimeType == null) ? 0 : this.mMimeType.hashCode());
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MimeTypeInfo other = (MimeTypeInfo) obj;
+ if (this.mCategory != other.mCategory)
+ return false;
+ if (this.mDrawable == null) {
+ if (other.mDrawable != null)
+ return false;
+ } else if (!this.mDrawable.equals(other.mDrawable))
+ return false;
+ if (this.mMimeType == null) {
+ if (other.mMimeType != null)
+ return false;
+ } else if (!this.mMimeType.equals(other.mMimeType))
+ return false;
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "MimeTypeInfo [mCategory=" + this.mCategory + //$NON-NLS-1$
+ ", mMimeType="+ this.mMimeType + //$NON-NLS-1$
+ ", mDrawable=" + this.mDrawable + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
private static final String TAG = "MimeTypeHelper"; //$NON-NLS-1$
@@ -165,14 +218,29 @@ public final class MimeTypeHelper {
//Search the identifier in the cache
int drawableId = 0;
if (sCachedIndentifiers.containsKey(ext)) {
+ // Try from cached resources
drawableId = sCachedIndentifiers.get(ext).intValue();
- } else {
- drawableId = ResourcesHelper.getIdentifier(
- context.getResources(), "drawable", //$NON-NLS-1$
- mimeTypeInfo.mDrawable);
+ return drawableId;
+ }
+
+ // Create a new drawable
+ drawableId = ResourcesHelper.getIdentifier(
+ context.getResources(), "drawable", //$NON-NLS-1$
+ mimeTypeInfo.mDrawable);
+ if (drawableId != 0) {
sCachedIndentifiers.put(ext, Integer.valueOf(drawableId));
+ return drawableId;
}
- return drawableId;
+
+ // Something was wrong here. The resource should exist, but it's not present.
+ // Audit the wrong mime/type resource and return the best fso drawable (probably
+ // default)
+ Log.w(TAG, String.format(
+ "Something was wrong with the drawable of the fso:" + //$NON-NLS-1$
+ "%s, mime: %s", //$NON-NLS-1$
+ fso.toString(),
+ mimeTypeInfo.toString()
+ ));
}
}