DrmSupportInfo.java revision d074e30ce44b9e33da43b67a4515b8986ca72b26
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.drm; 18 19import java.util.ArrayList; 20import java.util.Iterator; 21 22/** 23 * This is an entity class which wraps the capability of each plug-in, 24 * such as mimetype's and file suffixes it could handle. 25 * 26 * Plug-in developer could return the capability of the plugin by passing 27 * {@link DrmSupportInfo} instance. 28 * 29 */ 30public class DrmSupportInfo { 31 private final ArrayList<String> mFileSuffixList = new ArrayList<String>(); 32 private final ArrayList<String> mMimeTypeList = new ArrayList<String>(); 33 private String mDescription = ""; 34 35 /** 36 * Add the mime-type to the support info such that respective plug-in is 37 * capable of handling the given mime-type. 38 * 39 * @param mimeType MIME type 40 */ 41 public void addMimeType(String mimeType) { 42 mMimeTypeList.add(mimeType); 43 } 44 45 /** 46 * Add the file suffix to the support info such that respective plug-in is 47 * capable of handling the given file suffix. 48 * 49 * @param fileSuffix File suffix which can be handled 50 */ 51 public void addFileSuffix(String fileSuffix) { 52 mFileSuffixList.add(fileSuffix); 53 } 54 55 /** 56 * Returns the iterator to walk to through mime types of this object 57 * 58 * @return Iterator object 59 */ 60 public Iterator<String> getMimeTypeIterator() { 61 return mMimeTypeList.iterator(); 62 } 63 64 /** 65 * Returns the iterator to walk to through file suffixes of this object 66 * 67 * @return Iterator object 68 */ 69 public Iterator<String> getFileSuffixIterator() { 70 return mFileSuffixList.iterator(); 71 } 72 73 /** 74 * Set the unique description about the plugin 75 * 76 * @param description Unique description 77 */ 78 public void setDescription(String description) { 79 if (null != description) { 80 mDescription = description; 81 } 82 } 83 84 /** 85 * Returns the unique description associated with the plugin 86 * 87 * @return Unique description 88 */ 89 public String getDescriprition() { 90 return mDescription; 91 } 92 93 /** 94 * Overridden hash code implementation 95 * 96 * @return Hash code value 97 */ 98 public int hashCode() { 99 return mFileSuffixList.hashCode() + mMimeTypeList.hashCode() + mDescription.hashCode(); 100 } 101 102 /** 103 * Overridden equals implementation 104 * 105 * @param object The object to be compared 106 * @return 107 * true if equal 108 * false if not equal 109 */ 110 public boolean equals(Object object) { 111 boolean result = false; 112 113 if (object instanceof DrmSupportInfo) { 114 result = mFileSuffixList.equals(((DrmSupportInfo) object).mFileSuffixList) && 115 mMimeTypeList.equals(((DrmSupportInfo) object).mMimeTypeList) && 116 mDescription.equals(((DrmSupportInfo) object).mDescription); 117 } 118 return result; 119 } 120 121 /** 122 * Returns whether given mime-type is supported or not 123 * 124 * @param mimeType MIME type 125 * @return 126 * true if mime type is supported 127 * false if mime type is not supported 128 */ 129 /* package */ boolean isSupportedMimeType(String mimeType) { 130 if (null != mimeType && !mimeType.equals("")) { 131 for (int i = 0; i < mMimeTypeList.size(); i++) { 132 String completeMimeType = mMimeTypeList.get(i); 133 if (completeMimeType.startsWith(mimeType)) { 134 return true; 135 } 136 } 137 } 138 return false; 139 } 140 141 /** 142 * Returns whether given file suffix is supported or not 143 * 144 * @param fileSuffix File suffix 145 * @return 146 * true - if file suffix is supported 147 * false - if file suffix is not supported 148 */ 149 /* package */ boolean isSupportedFileSuffix(String fileSuffix) { 150 return mFileSuffixList.contains(fileSuffix); 151 } 152} 153 154