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 17 package android.drm; 18 19 import java.util.HashMap; 20 21 /** 22 * A base class that is used to send asynchronous event information from the DRM framework. 23 * 24 */ 25 public class DrmEvent { 26 27 // Please do not add type constants in this class. More event type constants 28 // should go to DrmInfoEvent or DrmErrorEvent classes. 29 30 /** 31 * All of the rights information associated with all DRM schemes have been successfully removed. 32 */ 33 public static final int TYPE_ALL_RIGHTS_REMOVED = 1001; 34 /** 35 * The given DRM information has been successfully processed. 36 */ 37 public static final int TYPE_DRM_INFO_PROCESSED = 1002; 38 /** 39 * The key that is used in the <code>attributes</code> HashMap to pass the return status. 40 */ 41 public static final String DRM_INFO_STATUS_OBJECT = "drm_info_status_object"; 42 /** 43 * The key that is used in the <code>attributes</code> HashMap to pass the 44 * {@link DrmInfo} object. 45 */ 46 public static final String DRM_INFO_OBJECT = "drm_info_object"; 47 48 private final int mUniqueId; 49 private final int mType; 50 private String mMessage = ""; 51 52 private HashMap<String, Object> mAttributes = new HashMap<String, Object>(); 53 54 /** 55 * Creates a <code>DrmEvent</code> object with the specified parameters. 56 * 57 * @param uniqueId Unique session identifier. 58 * @param type Type of information. 59 * @param message Message description. 60 * @param attributes Attributes for extensible information. 61 */ DrmEvent(int uniqueId, int type, String message, HashMap<String, Object> attributes)62 protected DrmEvent(int uniqueId, int type, String message, 63 HashMap<String, Object> attributes) { 64 mUniqueId = uniqueId; 65 mType = type; 66 67 if (null != message) { 68 mMessage = message; 69 } 70 71 if (null != attributes) { 72 mAttributes = attributes; 73 } 74 } 75 76 /** 77 * Creates a <code>DrmEvent</code> object with the specified parameters. 78 * 79 * @param uniqueId Unique session identifier. 80 * @param type Type of information. 81 * @param message Message description. 82 */ DrmEvent(int uniqueId, int type, String message)83 protected DrmEvent(int uniqueId, int type, String message) { 84 mUniqueId = uniqueId; 85 mType = type; 86 87 if (null != message) { 88 mMessage = message; 89 } 90 } 91 92 /** 93 * Retrieves the unique session identifier associated with this object. 94 * 95 * @return The unique session identifier. 96 */ getUniqueId()97 public int getUniqueId() { 98 return mUniqueId; 99 } 100 101 /** 102 * Retrieves the type of information that is associated with this object. 103 * 104 * @return The type of information. 105 */ getType()106 public int getType() { 107 return mType; 108 } 109 110 /** 111 * Retrieves the message description associated with this object. 112 * 113 * @return The message description. 114 */ getMessage()115 public String getMessage() { 116 return mMessage; 117 } 118 119 /** 120 * Retrieves the attribute associated with the specified key. 121 * 122 * @return One of the attributes or null if no mapping for 123 * the key is found. 124 */ getAttribute(String key)125 public Object getAttribute(String key) { 126 return mAttributes.get(key); 127 } 128 } 129