DrmSupportInfo.java revision c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7
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 * 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 */
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     * Adds the specified MIME type to the list of MIME types this DRM plug-in supports.
37     *
38     * @param mimeType MIME type that can be handles by this DRM plug-in.
39     */
40    public void addMimeType(String mimeType) {
41        mMimeTypeList.add(mimeType);
42    }
43
44    /**
45     * Adds the specified file suffix to the list of file suffixes this DRM plug-in supports.
46     *
47     * @param fileSuffix File suffix that can be handled by this DRM plug-in.
48     */
49    public void addFileSuffix(String fileSuffix) {
50        mFileSuffixList.add(fileSuffix);
51    }
52
53    /**
54     * Retrieves an iterator object that you can use to iterate over the MIME types that
55     * this DRM plug-in supports.
56     *
57     * @return The iterator object
58     */
59    public Iterator<String> getMimeTypeIterator() {
60        return mMimeTypeList.iterator();
61    }
62
63    /**
64     * Retrieves an iterator object that you can use to iterate over the file suffixes that
65     * this DRM plug-in supports.
66     *
67     * @return The iterator object.
68     */
69    public Iterator<String> getFileSuffixIterator() {
70        return mFileSuffixList.iterator();
71    }
72
73    /**
74     * Sets a description for the DRM plug-in (agent).
75     *
76     * @param description Unique description of plug-in.
77     */
78    public void setDescription(String description) {
79        if (null != description) {
80            mDescription = description;
81        }
82    }
83
84    /**
85     * Retrieves the DRM plug-in (agent) description.
86     *
87     * @return The plug-in description.
88     * @deprecated The method name is mis-spelled, and it is replaced by
89     * {@link #getDescription()}.
90     */
91    public String getDescriprition() {
92        return mDescription;
93    }
94
95    /**
96     * Retrieves the DRM plug-in (agent) description.
97     *
98     * @return The plug-in description.
99     */
100    public String getDescription() {
101        return mDescription;
102    }
103
104    /**
105     * Overridden hash code implementation.
106     *
107     * @return The hash code value.
108     */
109    public int hashCode() {
110        return mFileSuffixList.hashCode() + mMimeTypeList.hashCode() + mDescription.hashCode();
111    }
112
113    /**
114     * Overridden <code>equals</code> implementation.
115     *
116     * @param object The object to be compared.
117     * @return True if equal; false if not equal.
118     */
119    public boolean equals(Object object) {
120        boolean result = false;
121
122        if (object instanceof DrmSupportInfo) {
123            result = mFileSuffixList.equals(((DrmSupportInfo) object).mFileSuffixList) &&
124                    mMimeTypeList.equals(((DrmSupportInfo) object).mMimeTypeList) &&
125                    mDescription.equals(((DrmSupportInfo) object).mDescription);
126        }
127        return result;
128    }
129
130    /**
131     * Determines whether a given MIME type is supported.
132     *
133     * @param mimeType MIME type.
134     * @return True if Mime type is supported; false if MIME type is not supported.
135     */
136    /* package */ boolean isSupportedMimeType(String mimeType) {
137        if (null != mimeType && !mimeType.equals("")) {
138            for (int i = 0; i < mMimeTypeList.size(); i++) {
139                String completeMimeType = mMimeTypeList.get(i);
140                if (completeMimeType.startsWith(mimeType)) {
141                    return true;
142                }
143            }
144        }
145        return false;
146    }
147
148    /**
149     * Determines whether a given file suffix is supported.
150     *
151     * @param fileSuffix File suffix.
152     * @return True if file suffix is supported; false if file suffix is not supported.
153     */
154    /* package */ boolean isSupportedFileSuffix(String fileSuffix) {
155        return mFileSuffixList.contains(fileSuffix);
156    }
157}
158
159