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 import android.os.Build;
22 
23 import java.util.ArrayList;
24 
25 public class ContentType {
26     public static final String MMS_MESSAGE       = "application/vnd.wap.mms-message";
27     // The phony content type for generic PDUs (e.g. ReadOrig.ind,
28     // Notification.ind, Delivery.ind).
29     public static final String MMS_GENERIC       = "application/vnd.wap.mms-generic";
30     public static final String MULTIPART_MIXED   = "application/vnd.wap.multipart.mixed";
31     public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
32     public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
33 
34     public static final String TEXT_PLAIN        = "text/plain";
35     public static final String TEXT_HTML         = "text/html";
36     public static final String TEXT_VCALENDAR    = "text/x-vCalendar";
37     public static final String TEXT_VCARD        = "text/x-vCard";
38 
39     public static final String IMAGE_UNSPECIFIED = "image/*";
40     public static final String IMAGE_JPEG        = "image/jpeg";
41     public static final String IMAGE_JPG         = "image/jpg";
42     public static final String IMAGE_GIF         = "image/gif";
43     public static final String IMAGE_WBMP        = "image/vnd.wap.wbmp";
44     public static final String IMAGE_PNG         = "image/png";
45     public static final String IMAGE_X_MS_BMP    = "image/x-ms-bmp";
46 
47     public static final String AUDIO_UNSPECIFIED = "audio/*";
48     public static final String AUDIO_AAC         = "audio/aac";
49     public static final String AUDIO_AMR         = "audio/amr";
50     public static final String AUDIO_IMELODY     = "audio/imelody";
51     public static final String AUDIO_MID         = "audio/mid";
52     public static final String AUDIO_MIDI        = "audio/midi";
53     public static final String AUDIO_MP3         = "audio/mp3";
54     public static final String AUDIO_MPEG3       = "audio/mpeg3";
55     public static final String AUDIO_MPEG        = "audio/mpeg";
56     public static final String AUDIO_MPG         = "audio/mpg";
57     public static final String AUDIO_MP4         = "audio/mp4";
58     public static final String AUDIO_X_MID       = "audio/x-mid";
59     public static final String AUDIO_X_MIDI      = "audio/x-midi";
60     public static final String AUDIO_X_MP3       = "audio/x-mp3";
61     public static final String AUDIO_X_MPEG3     = "audio/x-mpeg3";
62     public static final String AUDIO_X_MPEG      = "audio/x-mpeg";
63     public static final String AUDIO_X_MPG       = "audio/x-mpg";
64     public static final String AUDIO_3GPP        = "audio/3gpp";
65     public static final String AUDIO_X_WAV       = "audio/x-wav";
66     public static final String AUDIO_OGG         = "application/ogg";
67     public static final String AUDIO_OGG2        = "audio/ogg";
68 
69     public static final String VIDEO_UNSPECIFIED = "video/*";
70     public static final String VIDEO_3GPP        = "video/3gpp";
71     public static final String VIDEO_3G2         = "video/3gpp2";
72     public static final String VIDEO_H263        = "video/h263";
73     public static final String VIDEO_MP4         = "video/mp4";
74 
75     public static final String APP_SMIL          = "application/smil";
76     public static final String APP_WAP_XHTML     = "application/vnd.wap.xhtml+xml";
77     public static final String APP_XHTML         = "application/xhtml+xml";
78 
79     public static final String APP_DRM_CONTENT   = "application/vnd.oma.drm.content";
80     public static final String APP_DRM_MESSAGE   = "application/vnd.oma.drm.message";
81 
82     private static final ArrayList<String> sSupportedContentTypes = new ArrayList<String>();
83     private static final ArrayList<String> sSupportedImageTypes = new ArrayList<String>();
84     private static final ArrayList<String> sSupportedAudioTypes = new ArrayList<String>();
85     private static final ArrayList<String> sSupportedVideoTypes = new ArrayList<String>();
86 
87     static {
88         sSupportedContentTypes.add(TEXT_PLAIN);
89         sSupportedContentTypes.add(TEXT_HTML);
90         sSupportedContentTypes.add(TEXT_VCALENDAR);
91         sSupportedContentTypes.add(TEXT_VCARD);
92 
93         sSupportedContentTypes.add(IMAGE_JPEG);
94         sSupportedContentTypes.add(IMAGE_GIF);
95         sSupportedContentTypes.add(IMAGE_WBMP);
96         sSupportedContentTypes.add(IMAGE_PNG);
97         sSupportedContentTypes.add(IMAGE_JPG);
98         sSupportedContentTypes.add(IMAGE_X_MS_BMP);
99         //supportedContentTypes.add(IMAGE_SVG); not yet supported.
100 
101         sSupportedContentTypes.add(AUDIO_AAC);
102         sSupportedContentTypes.add(AUDIO_AMR);
103         sSupportedContentTypes.add(AUDIO_IMELODY);
104         sSupportedContentTypes.add(AUDIO_MID);
105         sSupportedContentTypes.add(AUDIO_MIDI);
106         sSupportedContentTypes.add(AUDIO_MP3);
107         sSupportedContentTypes.add(AUDIO_MP4);
108         sSupportedContentTypes.add(AUDIO_MPEG3);
109         sSupportedContentTypes.add(AUDIO_MPEG);
110         sSupportedContentTypes.add(AUDIO_MPG);
111         sSupportedContentTypes.add(AUDIO_X_MID);
112         sSupportedContentTypes.add(AUDIO_X_MIDI);
113         sSupportedContentTypes.add(AUDIO_X_MP3);
114         sSupportedContentTypes.add(AUDIO_X_MPEG3);
115         sSupportedContentTypes.add(AUDIO_X_MPEG);
116         sSupportedContentTypes.add(AUDIO_X_MPG);
117         sSupportedContentTypes.add(AUDIO_X_WAV);
118         sSupportedContentTypes.add(AUDIO_3GPP);
119         sSupportedContentTypes.add(AUDIO_OGG);
120         sSupportedContentTypes.add(AUDIO_OGG2);
121 
122         sSupportedContentTypes.add(VIDEO_3GPP);
123         sSupportedContentTypes.add(VIDEO_3G2);
124         sSupportedContentTypes.add(VIDEO_H263);
125         sSupportedContentTypes.add(VIDEO_MP4);
126 
127         sSupportedContentTypes.add(APP_SMIL);
128         sSupportedContentTypes.add(APP_WAP_XHTML);
129         sSupportedContentTypes.add(APP_XHTML);
130 
131         sSupportedContentTypes.add(APP_DRM_CONTENT);
132         sSupportedContentTypes.add(APP_DRM_MESSAGE);
133 
134         // add supported image types
135         sSupportedImageTypes.add(IMAGE_JPEG);
136         sSupportedImageTypes.add(IMAGE_GIF);
137         sSupportedImageTypes.add(IMAGE_WBMP);
138         sSupportedImageTypes.add(IMAGE_PNG);
139         sSupportedImageTypes.add(IMAGE_JPG);
140         sSupportedImageTypes.add(IMAGE_X_MS_BMP);
141 
142         // add supported audio types
143         sSupportedAudioTypes.add(AUDIO_AAC);
144         sSupportedAudioTypes.add(AUDIO_AMR);
145         sSupportedAudioTypes.add(AUDIO_IMELODY);
146         sSupportedAudioTypes.add(AUDIO_MID);
147         sSupportedAudioTypes.add(AUDIO_MIDI);
148         sSupportedAudioTypes.add(AUDIO_MP3);
149         sSupportedAudioTypes.add(AUDIO_MPEG3);
150         sSupportedAudioTypes.add(AUDIO_MPEG);
151         sSupportedAudioTypes.add(AUDIO_MPG);
152         sSupportedAudioTypes.add(AUDIO_MP4);
153         sSupportedAudioTypes.add(AUDIO_X_MID);
154         sSupportedAudioTypes.add(AUDIO_X_MIDI);
155         sSupportedAudioTypes.add(AUDIO_X_MP3);
156         sSupportedAudioTypes.add(AUDIO_X_MPEG3);
157         sSupportedAudioTypes.add(AUDIO_X_MPEG);
158         sSupportedAudioTypes.add(AUDIO_X_MPG);
159         sSupportedAudioTypes.add(AUDIO_X_WAV);
160         sSupportedAudioTypes.add(AUDIO_3GPP);
161         sSupportedAudioTypes.add(AUDIO_OGG);
162         sSupportedAudioTypes.add(AUDIO_OGG2);
163 
164         // add supported video types
165         sSupportedVideoTypes.add(VIDEO_3GPP);
166         sSupportedVideoTypes.add(VIDEO_3G2);
167         sSupportedVideoTypes.add(VIDEO_H263);
168         sSupportedVideoTypes.add(VIDEO_MP4);
169     }
170 
171     // This class should never be instantiated.
ContentType()172     private ContentType() {
173     }
174 
175     @UnsupportedAppUsage
isSupportedType(String contentType)176     public static boolean isSupportedType(String contentType) {
177         return (null != contentType) && sSupportedContentTypes.contains(contentType);
178     }
179 
180     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
isSupportedImageType(String contentType)181     public static boolean isSupportedImageType(String contentType) {
182         return isImageType(contentType) && isSupportedType(contentType);
183     }
184 
185     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
isSupportedAudioType(String contentType)186     public static boolean isSupportedAudioType(String contentType) {
187         return isAudioType(contentType) && isSupportedType(contentType);
188     }
189 
190     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
isSupportedVideoType(String contentType)191     public static boolean isSupportedVideoType(String contentType) {
192         return isVideoType(contentType) && isSupportedType(contentType);
193     }
194 
195     @UnsupportedAppUsage
isTextType(String contentType)196     public static boolean isTextType(String contentType) {
197         return (null != contentType) && contentType.startsWith("text/");
198     }
199 
200     @UnsupportedAppUsage
isImageType(String contentType)201     public static boolean isImageType(String contentType) {
202         return (null != contentType) && contentType.startsWith("image/");
203     }
204 
205     @UnsupportedAppUsage
isAudioType(String contentType)206     public static boolean isAudioType(String contentType) {
207         return (null != contentType) && contentType.startsWith("audio/");
208     }
209 
210     @UnsupportedAppUsage
isVideoType(String contentType)211     public static boolean isVideoType(String contentType) {
212         return (null != contentType) && contentType.startsWith("video/");
213     }
214 
215     @UnsupportedAppUsage
isDrmType(String contentType)216     public static boolean isDrmType(String contentType) {
217         return (null != contentType)
218                 && (contentType.equals(APP_DRM_CONTENT)
219                         || contentType.equals(APP_DRM_MESSAGE));
220     }
221 
isUnspecified(String contentType)222     public static boolean isUnspecified(String contentType) {
223         return (null != contentType) && contentType.endsWith("*");
224     }
225 
226     @UnsupportedAppUsage
227     @SuppressWarnings("unchecked")
getImageTypes()228     public static ArrayList<String> getImageTypes() {
229         return (ArrayList<String>) sSupportedImageTypes.clone();
230     }
231 
232     @UnsupportedAppUsage
233     @SuppressWarnings("unchecked")
getAudioTypes()234     public static ArrayList<String> getAudioTypes() {
235         return (ArrayList<String>) sSupportedAudioTypes.clone();
236     }
237 
238     @UnsupportedAppUsage
239     @SuppressWarnings("unchecked")
getVideoTypes()240     public static ArrayList<String> getVideoTypes() {
241         return (ArrayList<String>) sSupportedVideoTypes.clone();
242     }
243 
244     @SuppressWarnings("unchecked")
getSupportedTypes()245     public static ArrayList<String> getSupportedTypes() {
246         return (ArrayList<String>) sSupportedContentTypes.clone();
247     }
248 }
249