Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Crash when mms contains unsupported content type
Browse files Browse the repository at this point in the history
Bug 5479474
Instead of crashing when an mms message contains an unsupported content
type, silently replace that part of the slideshow with empty text. I would
have added a string that says why that part isn't shown, but it's too late
for new strings.

Change-Id: I652c2e686d8a8518b358c3d4f56056ae5a389ce0
  • Loading branch information
Tom Taylor committed Oct 20, 2011
1 parent 70322de commit 6a82abf
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/com/android/mms/model/MediaModelFactory.java
Expand Up @@ -24,6 +24,7 @@
import com.android.mms.drm.DrmWrapper;
import com.google.android.mms.ContentType;
import com.google.android.mms.MmsException;
import com.google.android.mms.pdu.CharacterSets;
import com.google.android.mms.pdu.PduBody;
import com.google.android.mms.pdu.PduPart;

Expand Down Expand Up @@ -117,6 +118,16 @@ private static MediaModel getRegionMediaModel(Context context,
throw new IllegalArgumentException("Region not found or bad region ID.");
}

// When we encounter a content type we can't handle, such as "application/vnd.smaf", instead
// of throwing an exception and crashing, insert an empty TextModel in its place.
private static MediaModel createEmptyTextModel(Context context, DrmWrapper wrapper,
RegionModel regionModel) throws IOException {
return wrapper != null ?
new TextModel(context, ContentType.TEXT_PLAIN, null, CharacterSets.ANY_CHARSET,
wrapper, regionModel) :
new TextModel(context, ContentType.TEXT_PLAIN, null, regionModel);
}

private static MediaModel getGenericMediaModel(Context context,
String tag, String src, SMILMediaElement sme, PduPart part,
RegionModel regionModel) throws DrmException, IOException, MmsException {
Expand Down Expand Up @@ -158,8 +169,9 @@ private static MediaModel getGenericMediaModel(Context context,
media = new AudioModel(context, contentType, src,
wrapper);
} else {
throw new UnsupportContentTypeException(
"Unsupported Content-Type: " + drmContentType);
Log.d(TAG, "[MediaModelFactory] getGenericMediaModel Unsupported Content-Type: "
+ contentType);
media = createEmptyTextModel(context, wrapper, regionModel);
}
} else {
throw new IllegalArgumentException("Unsupported TAG: " + tag);
Expand Down Expand Up @@ -191,8 +203,9 @@ private static MediaModel getGenericMediaModel(Context context,
media = new AudioModel(context, contentType, src,
part.getDataUri());
} else {
throw new UnsupportContentTypeException(
"Unsupported Content-Type: " + contentType);
Log.d(TAG, "[MediaModelFactory] getGenericMediaModel Unsupported Content-Type: "
+ contentType);
media = createEmptyTextModel(context, null, regionModel);
}
} else {
throw new IllegalArgumentException("Unsupported TAG: " + tag);
Expand Down

0 comments on commit 6a82abf

Please sign in to comment.