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  * An entity class that is passed to the
23  * {@link DrmManagerClient.OnErrorListener#onError onError()} callback.
24  *
25  * @deprecated Please use {@link android.media.MediaDrm}
26  */
27 @Deprecated
28 public class DrmErrorEvent extends DrmEvent {
29 
30     // Please add newly defined type constants to the end of the list,
31     // and modify checkTypeValidity() accordingly.
32 
33     /**
34      * Something went wrong installing the rights.
35      */
36     public static final int TYPE_RIGHTS_NOT_INSTALLED = 2001;
37     /**
38      * The server rejected the renewal of rights.
39      */
40     public static final int TYPE_RIGHTS_RENEWAL_NOT_ALLOWED = 2002;
41     /**
42      * Response from the server cannot be handled by the DRM plug-in (agent).
43      */
44     public static final int TYPE_NOT_SUPPORTED = 2003;
45     /**
46      * Memory allocation failed during renewal. Can in the future perhaps be used to trigger
47      * garbage collector.
48      */
49     public static final int TYPE_OUT_OF_MEMORY = 2004;
50     /**
51      * An Internet connection is not available and no attempt can be made to renew rights.
52      */
53     public static final int TYPE_NO_INTERNET_CONNECTION = 2005;
54     /**
55      * Failed to process {@link DrmInfo}. This error event is sent when a
56      * {@link DrmManagerClient#processDrmInfo processDrmInfo()} call fails.
57      */
58     public static final int TYPE_PROCESS_DRM_INFO_FAILED = 2006;
59     /**
60      * Failed to remove all the rights objects associated with all DRM schemes.
61      */
62     public static final int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2007;
63     /**
64      * Failed to acquire {@link DrmInfo}. This error event is sent when an
65      * {@link DrmManagerClient#acquireDrmInfo acquireDrmInfo()} call fails.
66      */
67     public static final int TYPE_ACQUIRE_DRM_INFO_FAILED = 2008;
68 
69     // Add more type constants here...
70 
71     // FIXME:
72     // We may want to add a user-defined type constant, such as
73     // TYPE_VENDOR_SPECIFIC_FAILED, to take care vendor specific use
74     // cases.
75 
76 
77     /**
78      * Creates a <code>DrmErrorEvent</code> object with the specified parameters.
79      *
80      * @param uniqueId Unique session identifier.
81      * @param type Type of the event. Must be any of the event types defined above.
82      * @param message Message description. It can be null.
83      */
DrmErrorEvent(int uniqueId, int type, String message)84     public DrmErrorEvent(int uniqueId, int type, String message) {
85         super(uniqueId, type, message);
86         checkTypeValidity(type);
87     }
88 
89     /**
90      * Creates a <code>DrmErrorEvent</code> object with the specified parameters.
91      *
92      * @param uniqueId Unique session identifier.
93      * @param type Type of the event. Must be any of the event types defined above.
94      * @param message Message description.
95      * @param attributes Attributes for extensible information. Could be any
96      * information provided by the plug-in. It can be null.
97      */
DrmErrorEvent(int uniqueId, int type, String message, HashMap<String, Object> attributes)98     public DrmErrorEvent(int uniqueId, int type, String message,
99                             HashMap<String, Object> attributes) {
100         super(uniqueId, type, message, attributes);
101         checkTypeValidity(type);
102     }
103 
checkTypeValidity(int type)104     private void checkTypeValidity(int type) {
105         if (type < TYPE_RIGHTS_NOT_INSTALLED ||
106             type > TYPE_ACQUIRE_DRM_INFO_FAILED) {
107             final String msg = "Unsupported type: " + type;
108             throw new IllegalArgumentException(msg);
109         }
110     }
111 }
112