CarrierContentRestriction.java revision 8eed706474910ccb978acda03e85d3261037da6e
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 */ 17package com.android.mms.model; 18 19import java.util.ArrayList; 20 21import com.google.android.mms.ContentType; 22import com.android.mms.ContentRestrictionException; 23import com.android.mms.ExceedMessageSizeException; 24import com.android.mms.ResolutionException; 25import com.android.mms.UnsupportContentTypeException; 26 27public class CarrierContentRestriction implements ContentRestriction { 28 public static final int IMAGE_WIDTH_LIMIT = 1600; 29 public static final int IMAGE_HEIGHT_LIMIT = 1200; 30 public static final int MESSAGE_SIZE_LIMIT = 300 * 1024; 31 32 private static final ArrayList<String> sSupportedImageTypes; 33 private static final ArrayList<String> sSupportedAudioTypes; 34 private static final ArrayList<String> sSupportedVideoTypes; 35 36 static { 37 sSupportedImageTypes = ContentType.getImageTypes(); 38 sSupportedAudioTypes = ContentType.getAudioTypes(); 39 sSupportedVideoTypes = ContentType.getVideoTypes(); 40 } 41 42 public CarrierContentRestriction() { 43 } 44 45 public void checkMessageSize(int messageSize, int increaseSize) 46 throws ContentRestrictionException { 47 if ( (messageSize < 0) || (increaseSize < 0) ) { 48 throw new ContentRestrictionException("Negative message size" 49 + " or increase size"); 50 } 51 52 int newSize = messageSize + increaseSize; 53 if ( (newSize < 0) || (newSize > MESSAGE_SIZE_LIMIT) ) { 54 throw new ExceedMessageSizeException("Exceed message size limitation"); 55 } 56 } 57 58 public void checkResolution(int width, int height) throws ContentRestrictionException { 59 if ( (width > IMAGE_WIDTH_LIMIT) || (height > IMAGE_HEIGHT_LIMIT) ) { 60 throw new ResolutionException("content resolution exceeds restriction."); 61 } 62 } 63 64 public void checkImageContentType(String contentType) 65 throws ContentRestrictionException { 66 if (null == contentType) { 67 throw new ContentRestrictionException("Null content type to be check"); 68 } 69 70 if (!sSupportedImageTypes.contains(contentType)) { 71 throw new UnsupportContentTypeException("Unsupported image content type : " 72 + contentType); 73 } 74 } 75 76 public void checkAudioContentType(String contentType) 77 throws ContentRestrictionException { 78 if (null == contentType) { 79 throw new ContentRestrictionException("Null content type to be check"); 80 } 81 82 if (!sSupportedAudioTypes.contains(contentType)) { 83 throw new UnsupportContentTypeException("Unsupported audio content type : " 84 + contentType); 85 } 86 } 87 88 public void checkVideoContentType(String contentType) 89 throws ContentRestrictionException { 90 if (null == contentType) { 91 throw new ContentRestrictionException("Null content type to be check"); 92 } 93 94 if (!sSupportedVideoTypes.contains(contentType)) { 95 throw new UnsupportContentTypeException("Unsupported video content type : " 96 + contentType); 97 } 98 } 99} 100