• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.drm;
18 
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 
22 /**
23  * An entity class that wraps the capability of each DRM plug-in (agent),
24  * such as the MIME type and file suffix the DRM plug-in can handle.
25  *<p>
26  * Plug-in developers can expose the capability of their plug-in by passing an instance of this
27  * class to an application.
28  *
29  * @deprecated Please use {@link android.media.MediaDrm}
30  */
31 @Deprecated
32 public class DrmSupportInfo {
33     private final ArrayList<String> mFileSuffixList = new ArrayList<String>();
34     private final ArrayList<String> mMimeTypeList = new ArrayList<String>();
35     private String mDescription = "";
36 
37     /**
38      * Adds the specified MIME type to the list of MIME types this DRM plug-in supports.
39      *
40      * @param mimeType MIME type that can be handles by this DRM plug-in.
41      * Must not be null or an empty string.
42      */
addMimeType(String mimeType)43     public void addMimeType(String mimeType) {
44         if (mimeType == null) {
45             throw new IllegalArgumentException("mimeType is null");
46         }
47         if (mimeType == "") {
48             throw new IllegalArgumentException("mimeType is an empty string");
49         }
50 
51         mMimeTypeList.add(mimeType);
52     }
53 
54     /**
55      * Adds the specified file suffix to the list of file suffixes this DRM plug-in supports.
56      *
57      * @param fileSuffix File suffix that can be handled by this DRM plug-in.
58      * it could be null but not an empty string. When it is null, it indicates
59      * that some DRM content comes with no file suffix.
60      */
addFileSuffix(String fileSuffix)61     public void addFileSuffix(String fileSuffix) {
62         if (fileSuffix == "") {
63             throw new IllegalArgumentException("fileSuffix is an empty string");
64         }
65 
66         mFileSuffixList.add(fileSuffix);
67     }
68 
69     /**
70      * Retrieves an iterator object that you can use to iterate over the MIME types that
71      * this DRM plug-in supports.
72      *
73      * @return The iterator object
74      */
getMimeTypeIterator()75     public Iterator<String> getMimeTypeIterator() {
76         return mMimeTypeList.iterator();
77     }
78 
79     /**
80      * Retrieves an iterator object that you can use to iterate over the file suffixes that
81      * this DRM plug-in supports.
82      *
83      * @return The iterator object.
84      */
getFileSuffixIterator()85     public Iterator<String> getFileSuffixIterator() {
86         return mFileSuffixList.iterator();
87     }
88 
89     /**
90      * Sets a description for the DRM plug-in (agent).
91      *
92      * @param description Unique description of plug-in. Must not be null
93      * or an empty string.
94      */
setDescription(String description)95     public void setDescription(String description) {
96         if (description == null) {
97             throw new IllegalArgumentException("description is null");
98         }
99         if (description == "") {
100             throw new IllegalArgumentException("description is an empty string");
101         }
102 
103         mDescription = description;
104     }
105 
106     /**
107      * Retrieves the DRM plug-in (agent) description.
108      *
109      * @return The plug-in description.
110      * @deprecated The method name is mis-spelled, and it is replaced by
111      * {@link #getDescription()}.
112      */
getDescriprition()113     public String getDescriprition() {
114         return mDescription;
115     }
116 
117     /**
118      * Retrieves the DRM plug-in (agent) description. Even if null or an empty
119      * string is not allowed in {@link #setDescription(String)}, if
120      * {@link #setDescription(String)} is not called, description returned
121      * from this method is an empty string.
122      *
123      * @return The plug-in description.
124      */
getDescription()125     public String getDescription() {
126         return mDescription;
127     }
128 
129     /**
130      * Overridden hash code implementation.
131      *
132      * @return The hash code value.
133      */
hashCode()134     public int hashCode() {
135         return mFileSuffixList.hashCode() + mMimeTypeList.hashCode() + mDescription.hashCode();
136     }
137 
138     /**
139      * Overridden <code>equals</code> implementation. Two DrmSupportInfo objects
140      * are considered being equal if they support exactly the same set of mime
141      * types, file suffixes, and has exactly the same description.
142      *
143      * @param object The object to be compared.
144      * @return True if equal; false if not equal.
145      */
equals(Object object)146     public boolean equals(Object object) {
147         if (object instanceof DrmSupportInfo) {
148             DrmSupportInfo info = (DrmSupportInfo) object;
149             return mFileSuffixList.equals(info.mFileSuffixList) &&
150                    mMimeTypeList.equals(info.mMimeTypeList) &&
151                    mDescription.equals(info.mDescription);
152         }
153         return false;
154     }
155 
156     /**
157      * Determines whether a given MIME type is supported.
158      *
159      * @param mimeType MIME type.
160      * @return True if Mime type is supported; false if MIME type is not supported.
161      * Null or empty string is not a supported mimeType.
162      */
isSupportedMimeType(String mimeType)163     /* package */ boolean isSupportedMimeType(String mimeType) {
164         if (null != mimeType && !mimeType.equals("")) {
165             for (int i = 0; i < mMimeTypeList.size(); i++) {
166                 String completeMimeType = mMimeTypeList.get(i);
167 
168                 // The reason that equals() is not used is that sometimes,
169                 // content distributor might just append something to
170                 // the basic MIME type. startsWith() is used to avoid
171                 // frequent update of DRM agent.
172                 if (completeMimeType.startsWith(mimeType)) {
173                     return true;
174                 }
175             }
176         }
177         return false;
178     }
179 
180     /**
181      * Determines whether a given file suffix is supported.
182      *
183      * @param fileSuffix File suffix.
184      * @return True if file suffix is supported; false if file suffix is not supported.
185      */
isSupportedFileSuffix(String fileSuffix)186     /* package */ boolean isSupportedFileSuffix(String fileSuffix) {
187         return mFileSuffixList.contains(fileSuffix);
188     }
189 }
190 
191