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