DrmEvent.java revision f8bf3c46f524b1252bf466a351daaef61afdcecb
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.HashMap;
20
21/**
22 * This is the base class which would be used to notify the caller
23 * about any event occurred in DRM framework.
24 *
25 */
26public class DrmEvent {
27    /**
28     * Constant field signifies that all the rights information associated with
29     * all DRM schemes are removed successfully
30     */
31    public static final int TYPE_ALL_RIGHTS_REMOVED = 1001;
32    /**
33     * Constant field signifies that given information is processed successfully
34     */
35    public static final int TYPE_DRM_INFO_PROCESSED = 1002;
36
37    public static final String DRM_INFO_STATUS_OBJECT = "drm_info_status_object";
38    public static final String DRM_INFO_OBJECT = "drm_info_object";
39
40    private final int mUniqueId;
41    private final int mType;
42    private String mMessage = "";
43
44    private HashMap<String, Object> mAttributes = new HashMap<String, Object>();
45
46    /**
47     * constructor for DrmEvent class
48     *
49     * @param uniqueId Unique session identifier
50     * @param type Type of information
51     * @param message Message description
52     * @param attributes Attributes for extensible information
53     */
54    protected DrmEvent(int uniqueId, int type, String message,
55                            HashMap<String, Object> attributes) {
56        mUniqueId = uniqueId;
57        mType = type;
58
59        if (null != message) {
60            mMessage = message;
61        }
62
63        if (null != attributes) {
64            mAttributes = attributes;
65        }
66    }
67
68    /**
69     * constructor for DrmEvent class
70     *
71     * @param uniqueId Unique session identifier
72     * @param type Type of information
73     * @param message Message description
74     */
75    protected DrmEvent(int uniqueId, int type, String message) {
76        mUniqueId = uniqueId;
77        mType = type;
78
79        if (null != message) {
80            mMessage = message;
81        }
82    }
83
84    /**
85     * Returns the Unique Id associated with this object
86     *
87     * @return Unique Id
88     */
89    public int getUniqueId() {
90        return mUniqueId;
91    }
92
93    /**
94     * Returns the Type of information associated with this object
95     *
96     * @return Type of information
97     */
98    public int getType() {
99        return mType;
100    }
101
102    /**
103     * Returns the message description associated with this object
104     *
105     * @return message description
106     */
107    public String getMessage() {
108        return mMessage;
109    }
110
111    /**
112     * Returns the attribute corresponding to the specified key
113     *
114     * @return one of the attributes or null if no mapping for
115     * the key is found
116     */
117    public Object getAttribute(String key) {
118        return mAttributes.get(key);
119    }
120}
121
122