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     */
89    public String getDescriprition() {
90        return mDescription;
91    }
92
93    /**
94     * Overridden hash code implementation.
95     *
96     * @return The hash code value.
97     */
98    public int hashCode() {
99        return mFileSuffixList.hashCode() + mMimeTypeList.hashCode() + mDescription.hashCode();
100    }
101
102    /**
103     * Overridden <code>equals</code> implementation.
104     *
105     * @param object The object to be compared.
106     * @return True if equal; false if not equal.
107     */
108    public boolean equals(Object object) {
109        boolean result = false;
110
111        if (object instanceof DrmSupportInfo) {
112            result = mFileSuffixList.equals(((DrmSupportInfo) object).mFileSuffixList) &&
113                    mMimeTypeList.equals(((DrmSupportInfo) object).mMimeTypeList) &&
114                    mDescription.equals(((DrmSupportInfo) object).mDescription);
115        }
116        return result;
117    }
118
119    /**
120     * Determines whether a given MIME type is supported.
121     *
122     * @param mimeType MIME type.
123     * @return True if Mime type is supported; false if MIME type is not supported.
124     */
125    /* package */ boolean isSupportedMimeType(String mimeType) {
126        if (null != mimeType && !mimeType.equals("")) {
127            for (int i = 0; i < mMimeTypeList.size(); i++) {
128                String completeMimeType = mMimeTypeList.get(i);
129                if (completeMimeType.startsWith(mimeType)) {
130                    return true;
131                }
132            }
133        }
134        return false;
135    }
136
137    /**
138     * Determines whether a given file suffix is supported.
139     *
140     * @param fileSuffix File suffix.
141     * @return True if file suffix is supported; false if file suffix is not supported.
142     */
143    /* package */ boolean isSupportedFileSuffix(String fileSuffix) {
144        return mFileSuffixList.contains(fileSuffix);
145    }
146}
147
148