/drm/java/android/drm/DrmInfoRequest.java

http://github.com/CyanogenMod/android_frameworks_base · Java · 163 lines · 57 code · 17 blank · 89 comment · 7 complexity · 9523bd19636a2231320944dbc9126912 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.HashMap;
  18. import java.util.Iterator;
  19. /**
  20. * An entity class that is used to pass information to an online DRM server. An instance of this
  21. * class is passed to the {@link DrmManagerClient#acquireDrmInfo acquireDrmInfo()} method to get an
  22. * instance of a {@link DrmInfo}.
  23. *
  24. */
  25. public class DrmInfoRequest {
  26. // Changes in following constants should be in sync with DrmInfoRequest.h
  27. /**
  28. * Acquires DRM server registration information.
  29. */
  30. public static final int TYPE_REGISTRATION_INFO = 1;
  31. /**
  32. * Acquires information for unregistering the DRM server.
  33. */
  34. public static final int TYPE_UNREGISTRATION_INFO = 2;
  35. /**
  36. * Acquires rights information.
  37. */
  38. public static final int TYPE_RIGHTS_ACQUISITION_INFO = 3;
  39. /**
  40. * Acquires the progress of the rights acquisition.
  41. */
  42. public static final int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4;
  43. /**
  44. * Key that is used to pass the unique session ID for the account or the user.
  45. */
  46. public static final String ACCOUNT_ID = "account_id";
  47. /**
  48. * Key that is used to pass the unique session ID for the subscription.
  49. */
  50. public static final String SUBSCRIPTION_ID = "subscription_id";
  51. private final int mInfoType;
  52. private final String mMimeType;
  53. private final HashMap<String, Object> mRequestInformation = new HashMap<String, Object>();
  54. /**
  55. * Creates a <code>DrmInfoRequest</code> object with type and MIME type.
  56. *
  57. * @param infoType Type of information.
  58. * @param mimeType MIME type.
  59. */
  60. public DrmInfoRequest(int infoType, String mimeType) {
  61. mInfoType = infoType;
  62. mMimeType = mimeType;
  63. if (!isValid()) {
  64. final String msg = "infoType: " + infoType + "," +
  65. "mimeType: " + mimeType;
  66. throw new IllegalArgumentException(msg);
  67. }
  68. }
  69. /**
  70. * Retrieves the MIME type associated with this object.
  71. *
  72. * @return The MIME type.
  73. */
  74. public String getMimeType() {
  75. return mMimeType;
  76. }
  77. /**
  78. * Retrieves the information type associated with this object.
  79. *
  80. * @return The information type.
  81. */
  82. public int getInfoType() {
  83. return mInfoType;
  84. }
  85. /**
  86. * Adds optional information as key-value pairs to this object.
  87. *
  88. * @param key The key to add.
  89. * @param value The value to add.
  90. */
  91. public void put(String key, Object value) {
  92. mRequestInformation.put(key, value);
  93. }
  94. /**
  95. * Retrieves the value of a given key.
  96. *
  97. * @param key The key whose value is being retrieved.
  98. *
  99. * @return The value of the key that is being retrieved. Returns null if the key cannot be
  100. * found.
  101. */
  102. public Object get(String key) {
  103. return mRequestInformation.get(key);
  104. }
  105. /**
  106. * Retrieves an iterator object that you can use to iterate over the keys associated with
  107. * this <code>DrmInfoRequest</code> object.
  108. *
  109. * @return The iterator object.
  110. */
  111. public Iterator<String> keyIterator() {
  112. return mRequestInformation.keySet().iterator();
  113. }
  114. /**
  115. * Retrieves an iterator object that you can use to iterate over the values associated with
  116. * this <code>DrmInfoRequest</code> object.
  117. *
  118. * @return The iterator object.
  119. */
  120. public Iterator<Object> iterator() {
  121. return mRequestInformation.values().iterator();
  122. }
  123. /**
  124. * Returns whether this instance is valid or not
  125. *
  126. * @return
  127. * true if valid
  128. * false if invalid
  129. */
  130. boolean isValid() {
  131. return (null != mMimeType && !mMimeType.equals("")
  132. && null != mRequestInformation && isValidType(mInfoType));
  133. }
  134. /* package */ static boolean isValidType(int infoType) {
  135. boolean isValid = false;
  136. switch (infoType) {
  137. case TYPE_REGISTRATION_INFO:
  138. case TYPE_UNREGISTRATION_INFO:
  139. case TYPE_RIGHTS_ACQUISITION_INFO:
  140. case TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO:
  141. isValid = true;
  142. break;
  143. }
  144. return isValid;
  145. }
  146. }