• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Esmertec AG.
3  * Copyright (C) 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 package com.android.mms.model;
18 
19 import java.util.ArrayList;
20 
21 import android.content.ContentResolver;
22 import android.util.Log;
23 
24 import com.google.android.mms.ContentType;
25 import com.android.mms.ContentRestrictionException;
26 import com.android.mms.ExceedMessageSizeException;
27 import com.android.mms.LogTag;
28 import com.android.mms.MmsConfig;
29 import com.android.mms.ResolutionException;
30 import com.android.mms.UnsupportContentTypeException;
31 
32 public class CarrierContentRestriction implements ContentRestriction {
33     private static final ArrayList<String> sSupportedImageTypes;
34     private static final ArrayList<String> sSupportedAudioTypes;
35     private static final ArrayList<String> sSupportedVideoTypes;
36     private static final boolean DEBUG = true;
37 
38     static {
39         sSupportedImageTypes = ContentType.getImageTypes();
40         sSupportedAudioTypes = ContentType.getAudioTypes();
41         sSupportedVideoTypes = ContentType.getVideoTypes();
42     }
43 
CarrierContentRestriction()44     public CarrierContentRestriction() {
45     }
46 
checkMessageSize(int messageSize, int increaseSize, ContentResolver resolver)47     public void checkMessageSize(int messageSize, int increaseSize, ContentResolver resolver)
48             throws ContentRestrictionException {
49         if (DEBUG) {
50             Log.d(LogTag.APP, "CarrierContentRestriction.checkMessageSize messageSize: " +
51                         messageSize + " increaseSize: " + increaseSize +
52                         " MmsConfig.getMaxMessageSize: " + MmsConfig.getMaxMessageSize());
53         }
54         if ( (messageSize < 0) || (increaseSize < 0) ) {
55             throw new ContentRestrictionException("Negative message size"
56                     + " or increase size");
57         }
58         int newSize = messageSize + increaseSize;
59 
60         if ( (newSize < 0) || (newSize > MmsConfig.getMaxMessageSize()) ) {
61             throw new ExceedMessageSizeException("Exceed message size limitation");
62         }
63     }
64 
checkResolution(int width, int height)65     public void checkResolution(int width, int height) throws ContentRestrictionException {
66         if ( (width > MmsConfig.getMaxImageWidth()) || (height > MmsConfig.getMaxImageHeight()) ) {
67             throw new ResolutionException("content resolution exceeds restriction.");
68         }
69     }
70 
checkImageContentType(String contentType)71     public void checkImageContentType(String contentType)
72             throws ContentRestrictionException {
73         if (null == contentType) {
74             throw new ContentRestrictionException("Null content type to be check");
75         }
76 
77         if (!sSupportedImageTypes.contains(contentType)) {
78             throw new UnsupportContentTypeException("Unsupported image content type : "
79                     + contentType);
80         }
81     }
82 
checkAudioContentType(String contentType)83     public void checkAudioContentType(String contentType)
84             throws ContentRestrictionException {
85         if (null == contentType) {
86             throw new ContentRestrictionException("Null content type to be check");
87         }
88 
89         if (!sSupportedAudioTypes.contains(contentType)) {
90             throw new UnsupportContentTypeException("Unsupported audio content type : "
91                     + contentType);
92         }
93     }
94 
checkVideoContentType(String contentType)95     public void checkVideoContentType(String contentType)
96             throws ContentRestrictionException {
97         if (null == contentType) {
98             throw new ContentRestrictionException("Null content type to be check");
99         }
100 
101         if (!sSupportedVideoTypes.contains(contentType)) {
102             throw new UnsupportContentTypeException("Unsupported video content type : "
103                     + contentType);
104         }
105     }
106 }
107