summaryrefslogtreecommitdiffstats
path: root/drm/java/android/drm/DrmSupportInfo.java
blob: 3694ff4304c430d29f6b3b5fc5e992c61a963984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.drm;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * An entity class that wraps the capability of each DRM plug-in (agent),
 * such as the MIME type and file suffix the DRM plug-in can handle.
 *<p>
 * Plug-in developers can expose the capability of their plug-in by passing an instance of this
 * class to an application.
 *
 */
public class DrmSupportInfo {
    private final ArrayList<String> mFileSuffixList = new ArrayList<String>();
    private final ArrayList<String> mMimeTypeList = new ArrayList<String>();
    private String mDescription = "";

    /**
     * Adds the specified MIME type to the list of MIME types this DRM plug-in supports.
     *
     * @param mimeType MIME type that can be handles by this DRM plug-in.
     * Must not be null or an empty string.
     */
    public void addMimeType(String mimeType) {
        if (mimeType == null) {
            throw new IllegalArgumentException("mimeType is null");
        }
        if (mimeType == "") {
            throw new IllegalArgumentException("mimeType is an empty string");
        }

        mMimeTypeList.add(mimeType);
    }

    /**
     * Adds the specified file suffix to the list of file suffixes this DRM plug-in supports.
     *
     * @param fileSuffix File suffix that can be handled by this DRM plug-in.
     * it could be null but not an empty string. When it is null, it indicates
     * that some DRM content comes with no file suffix.
     */
    public void addFileSuffix(String fileSuffix) {
        if (fileSuffix == "") {
            throw new IllegalArgumentException("fileSuffix is an empty string");
        }

        mFileSuffixList.add(fileSuffix);
    }

    /**
     * Retrieves an iterator object that you can use to iterate over the MIME types that 
     * this DRM plug-in supports.
     *
     * @return The iterator object
     */
    public Iterator<String> getMimeTypeIterator() {
        return mMimeTypeList.iterator();
    }

    /**
     * Retrieves an iterator object that you can use to iterate over the file suffixes that
     * this DRM plug-in supports.
     *
     * @return The iterator object.
     */
    public Iterator<String> getFileSuffixIterator() {
        return mFileSuffixList.iterator();
    }

    /**
     * Sets a description for the DRM plug-in (agent).
     *
     * @param description Unique description of plug-in. Must not be null
     * or an empty string.
     */
    public void setDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("description is null");
        }
        if (description == "") {
            throw new IllegalArgumentException("description is an empty string");
        }

        mDescription = description;
    }

    /**
     * Retrieves the DRM plug-in (agent) description.
     *
     * @return The plug-in description.
     * @deprecated The method name is mis-spelled, and it is replaced by
     * {@link #getDescription()}.
     */
    public String getDescriprition() {
        return mDescription;
    }

    /**
     * Retrieves the DRM plug-in (agent) description. Even if null or an empty
     * string is not allowed in {@link #setDescription(String)}, if
     * {@link #setDescription(String)} is not called, description returned
     * from this method is an empty string.
     *
     * @return The plug-in description.
     */
    public String getDescription() {
        return mDescription;
    }

    /**
     * Overridden hash code implementation.
     *
     * @return The hash code value.
     */
    public int hashCode() {
        return mFileSuffixList.hashCode() + mMimeTypeList.hashCode() + mDescription.hashCode();
    }

    /**
     * Overridden <code>equals</code> implementation. Two DrmSupportInfo objects
     * are considered being equal if they support exactly the same set of mime
     * types, file suffixes, and has exactly the same description.
     *
     * @param object The object to be compared.
     * @return True if equal; false if not equal.
     */
    public boolean equals(Object object) {
        if (object instanceof DrmSupportInfo) {
            DrmSupportInfo info = (DrmSupportInfo) object;
            return mFileSuffixList.equals(info.mFileSuffixList) &&
                   mMimeTypeList.equals(info.mMimeTypeList) &&
                   mDescription.equals(info.mDescription);
        }
        return false;
    }

    /**
     * Determines whether a given MIME type is supported.
     *
     * @param mimeType MIME type.
     * @return True if Mime type is supported; false if MIME type is not supported.
     * Null or empty string is not a supported mimeType.
     */
    /* package */ boolean isSupportedMimeType(String mimeType) {
        if (null != mimeType && !mimeType.equals("")) {
            for (int i = 0; i < mMimeTypeList.size(); i++) {
                String completeMimeType = mMimeTypeList.get(i);

                // The reason that equals() is not used is that sometimes,
                // content distributor might just append something to
                // the basic MIME type. startsWith() is used to avoid
                // frequent update of DRM agent.
                if (completeMimeType.startsWith(mimeType)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Determines whether a given file suffix is supported.
     *
     * @param fileSuffix File suffix.
     * @return True if file suffix is supported; false if file suffix is not supported.
     */
    /* package */ boolean isSupportedFileSuffix(String fileSuffix) {
        return mFileSuffixList.contains(fileSuffix);
    }
}