/drm/java/android/drm/DrmSupportInfo.java

http://github.com/CyanogenMod/android_frameworks_base · Java · 188 lines · 70 code · 19 blank · 99 comment · 16 complexity · d49c34ac8bd9314c62432c533b4bea62 MD5 · raw file

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