1 /*
2  * Copyright (C) 2007-2008 Esmertec AG.
3  * Copyright (C) 2007-2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.google.android.mms;
19 
20 import android.compat.annotation.UnsupportedAppUsage;
21 
22 import java.util.ArrayList;
23 
24 public class ContentType {
25     public static final String MMS_MESSAGE       = "application/vnd.wap.mms-message";
26     // The phony content type for generic PDUs (e.g. ReadOrig.ind,
27     // Notification.ind, Delivery.ind).
28     public static final String MMS_GENERIC       = "application/vnd.wap.mms-generic";
29     public static final String MULTIPART_MIXED   = "application/vnd.wap.multipart.mixed";
30     public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
31     public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
32 
33     public static final String TEXT_PLAIN        = "text/plain";
34     public static final String TEXT_HTML         = "text/html";
35     public static final String TEXT_VCALENDAR    = "text/x-vCalendar";
36     public static final String TEXT_VCARD        = "text/x-vCard";
37 
38     public static final String IMAGE_UNSPECIFIED = "image/*";
39     public static final String IMAGE_JPEG        = "image/jpeg";
40     public static final String IMAGE_JPG         = "image/jpg";
41     public static final String IMAGE_GIF         = "image/gif";
42     public static final String IMAGE_WBMP        = "image/vnd.wap.wbmp";
43     public static final String IMAGE_PNG         = "image/png";
44     public static final String IMAGE_X_MS_BMP    = "image/x-ms-bmp";
45 
46     public static final String AUDIO_UNSPECIFIED = "audio/*";
47     public static final String AUDIO_AAC         = "audio/aac";
48     public static final String AUDIO_AMR         = "audio/amr";
49     public static final String AUDIO_IMELODY     = "audio/imelody";
50     public static final String AUDIO_MID         = "audio/mid";
51     public static final String AUDIO_MIDI        = "audio/midi";
52     public static final String AUDIO_MP3         = "audio/mp3";
53     public static final String AUDIO_MPEG3       = "audio/mpeg3";
54     public static final String AUDIO_MPEG        = "audio/mpeg";
55     public static final String AUDIO_MPG         = "audio/mpg";
56     public static final String AUDIO_MP4         = "audio/mp4";
57     public static final String AUDIO_X_MID       = "audio/x-mid";
58     public static final String AUDIO_X_MIDI      = "audio/x-midi";
59     public static final String AUDIO_X_MP3       = "audio/x-mp3";
60     public static final String AUDIO_X_MPEG3     = "audio/x-mpeg3";
61     public static final String AUDIO_X_MPEG      = "audio/x-mpeg";
62     public static final String AUDIO_X_MPG       = "audio/x-mpg";
63     public static final String AUDIO_3GPP        = "audio/3gpp";
64     public static final String AUDIO_X_WAV       = "audio/x-wav";
65     public static final String AUDIO_OGG         = "application/ogg";
66     public static final String AUDIO_OGG2        = "audio/ogg";
67 
68     public static final String VIDEO_UNSPECIFIED = "video/*";
69     public static final String VIDEO_3GPP        = "video/3gpp";
70     public static final String VIDEO_3G2         = "video/3gpp2";
71     public static final String VIDEO_H263        = "video/h263";
72     public static final String VIDEO_MP4         = "video/mp4";
73 
74     public static final String APP_SMIL          = "application/smil";
75     public static final String APP_WAP_XHTML     = "application/vnd.wap.xhtml+xml";
76     public static final String APP_XHTML         = "application/xhtml+xml";
77 
78     public static final String APP_DRM_CONTENT   = "application/vnd.oma.drm.content";
79     public static final String APP_DRM_MESSAGE   = "application/vnd.oma.drm.message";
80 
81     private static final ArrayList<String> sSupportedContentTypes = new ArrayList<String>();
82     private static final ArrayList<String> sSupportedImageTypes = new ArrayList<String>();
83     private static final ArrayList<String> sSupportedAudioTypes = new ArrayList<String>();
84     private static final ArrayList<String> sSupportedVideoTypes = new ArrayList<String>();
85 
86     static {
87         sSupportedContentTypes.add(TEXT_PLAIN);
88         sSupportedContentTypes.add(TEXT_HTML);
89         sSupportedContentTypes.add(TEXT_VCALENDAR);
90         sSupportedContentTypes.add(TEXT_VCARD);
91 
92         sSupportedContentTypes.add(IMAGE_JPEG);
93         sSupportedContentTypes.add(IMAGE_GIF);
94         sSupportedContentTypes.add(IMAGE_WBMP);
95         sSupportedContentTypes.add(IMAGE_PNG);
96         sSupportedContentTypes.add(IMAGE_JPG);
97         sSupportedContentTypes.add(IMAGE_X_MS_BMP);
98         //supportedContentTypes.add(IMAGE_SVG); not yet supported.
99 
100         sSupportedContentTypes.add(AUDIO_AAC);
101         sSupportedContentTypes.add(AUDIO_AMR);
102         sSupportedContentTypes.add(AUDIO_IMELODY);
103         sSupportedContentTypes.add(AUDIO_MID);
104         sSupportedContentTypes.add(AUDIO_MIDI);
105         sSupportedContentTypes.add(AUDIO_MP3);
106         sSupportedContentTypes.add(AUDIO_MP4);
107         sSupportedContentTypes.add(AUDIO_MPEG3);
108         sSupportedContentTypes.add(AUDIO_MPEG);
109         sSupportedContentTypes.add(AUDIO_MPG);
110         sSupportedContentTypes.add(AUDIO_X_MID);
111         sSupportedContentTypes.add(AUDIO_X_MIDI);
112         sSupportedContentTypes.add(AUDIO_X_MP3);
113         sSupportedContentTypes.add(AUDIO_X_MPEG3);
114         sSupportedContentTypes.add(AUDIO_X_MPEG);
115         sSupportedContentTypes.add(AUDIO_X_MPG);
116         sSupportedContentTypes.add(AUDIO_X_WAV);
117         sSupportedContentTypes.add(AUDIO_3GPP);
118         sSupportedContentTypes.add(AUDIO_OGG);
119         sSupportedContentTypes.add(AUDIO_OGG2);
120 
121         sSupportedContentTypes.add(VIDEO_3GPP);
122         sSupportedContentTypes.add(VIDEO_3G2);
123         sSupportedContentTypes.add(VIDEO_H263);
124         sSupportedContentTypes.add(VIDEO_MP4);
125 
126         sSupportedContentTypes.add(APP_SMIL);
127         sSupportedContentTypes.add(APP_WAP_XHTML);
128         sSupportedContentTypes.add(APP_XHTML);
129 
130         sSupportedContentTypes.add(APP_DRM_CONTENT);
131         sSupportedContentTypes.add(APP_DRM_MESSAGE);
132 
133         // add supported image types
134         sSupportedImageTypes.add(IMAGE_JPEG);
135         sSupportedImageTypes.add(IMAGE_GIF);
136         sSupportedImageTypes.add(IMAGE_WBMP);
137         sSupportedImageTypes.add(IMAGE_PNG);
138         sSupportedImageTypes.add(IMAGE_JPG);
139         sSupportedImageTypes.add(IMAGE_X_MS_BMP);
140 
141         // add supported audio types
142         sSupportedAudioTypes.add(AUDIO_AAC);
143         sSupportedAudioTypes.add(AUDIO_AMR);
144         sSupportedAudioTypes.add(AUDIO_IMELODY);
145         sSupportedAudioTypes.add(AUDIO_MID);
146         sSupportedAudioTypes.add(AUDIO_MIDI);
147         sSupportedAudioTypes.add(AUDIO_MP3);
148         sSupportedAudioTypes.add(AUDIO_MPEG3);
149         sSupportedAudioTypes.add(AUDIO_MPEG);
150         sSupportedAudioTypes.add(AUDIO_MPG);
151         sSupportedAudioTypes.add(AUDIO_MP4);
152         sSupportedAudioTypes.add(AUDIO_X_MID);
153         sSupportedAudioTypes.add(AUDIO_X_MIDI);
154         sSupportedAudioTypes.add(AUDIO_X_MP3);
155         sSupportedAudioTypes.add(AUDIO_X_MPEG3);
156         sSupportedAudioTypes.add(AUDIO_X_MPEG);
157         sSupportedAudioTypes.add(AUDIO_X_MPG);
158         sSupportedAudioTypes.add(AUDIO_X_WAV);
159         sSupportedAudioTypes.add(AUDIO_3GPP);
160         sSupportedAudioTypes.add(AUDIO_OGG);
161         sSupportedAudioTypes.add(AUDIO_OGG2);
162 
163         // add supported video types
164         sSupportedVideoTypes.add(VIDEO_3GPP);
165         sSupportedVideoTypes.add(VIDEO_3G2);
166         sSupportedVideoTypes.add(VIDEO_H263);
167         sSupportedVideoTypes.add(VIDEO_MP4);
168     }
169 
170     // This class should never be instantiated.
ContentType()171     private ContentType() {
172     }
173 
174     @UnsupportedAppUsage
isSupportedType(String contentType)175     public static boolean isSupportedType(String contentType) {
176         return (null != contentType) && sSupportedContentTypes.contains(contentType);
177     }
178 
179     @UnsupportedAppUsage
isSupportedImageType(String contentType)180     public static boolean isSupportedImageType(String contentType) {
181         return isImageType(contentType) && isSupportedType(contentType);
182     }
183 
184     @UnsupportedAppUsage
isSupportedAudioType(String contentType)185     public static boolean isSupportedAudioType(String contentType) {
186         return isAudioType(contentType) && isSupportedType(contentType);
187     }
188 
189     @UnsupportedAppUsage
isSupportedVideoType(String contentType)190     public static boolean isSupportedVideoType(String contentType) {
191         return isVideoType(contentType) && isSupportedType(contentType);
192     }
193 
194     @UnsupportedAppUsage
isTextType(String contentType)195     public static boolean isTextType(String contentType) {
196         return (null != contentType) && contentType.startsWith("text/");
197     }
198 
199     @UnsupportedAppUsage
isImageType(String contentType)200     public static boolean isImageType(String contentType) {
201         return (null != contentType) && contentType.startsWith("image/");
202     }
203 
204     @UnsupportedAppUsage
isAudioType(String contentType)205     public static boolean isAudioType(String contentType) {
206         return (null != contentType) && contentType.startsWith("audio/");
207     }
208 
209     @UnsupportedAppUsage
isVideoType(String contentType)210     public static boolean isVideoType(String contentType) {
211         return (null != contentType) && contentType.startsWith("video/");
212     }
213 
214     @UnsupportedAppUsage
isDrmType(String contentType)215     public static boolean isDrmType(String contentType) {
216         return (null != contentType)
217                 && (contentType.equals(APP_DRM_CONTENT)
218                         || contentType.equals(APP_DRM_MESSAGE));
219     }
220 
isUnspecified(String contentType)221     public static boolean isUnspecified(String contentType) {
222         return (null != contentType) && contentType.endsWith("*");
223     }
224 
225     @UnsupportedAppUsage
226     @SuppressWarnings("unchecked")
getImageTypes()227     public static ArrayList<String> getImageTypes() {
228         return (ArrayList<String>) sSupportedImageTypes.clone();
229     }
230 
231     @UnsupportedAppUsage
232     @SuppressWarnings("unchecked")
getAudioTypes()233     public static ArrayList<String> getAudioTypes() {
234         return (ArrayList<String>) sSupportedAudioTypes.clone();
235     }
236 
237     @UnsupportedAppUsage
238     @SuppressWarnings("unchecked")
getVideoTypes()239     public static ArrayList<String> getVideoTypes() {
240         return (ArrayList<String>) sSupportedVideoTypes.clone();
241     }
242 
243     @SuppressWarnings("unchecked")
getSupportedTypes()244     public static ArrayList<String> getSupportedTypes() {
245         return (ArrayList<String>) sSupportedContentTypes.clone();
246     }
247 }
248