1dc549d60f98d809f626c99de614960409a847054Takeshi Aimi/*
2dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * Copyright (C) 2010 The Android Open Source Project
3dc549d60f98d809f626c99de614960409a847054Takeshi Aimi *
4dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * Licensed under the Apache License, Version 2.0 (the "License");
5dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * you may not use this file except in compliance with the License.
6dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * You may obtain a copy of the License at
7dc549d60f98d809f626c99de614960409a847054Takeshi Aimi *
8dc549d60f98d809f626c99de614960409a847054Takeshi Aimi *      http://www.apache.org/licenses/LICENSE-2.0
9dc549d60f98d809f626c99de614960409a847054Takeshi Aimi *
10dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * Unless required by applicable law or agreed to in writing, software
11dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * distributed under the License is distributed on an "AS IS" BASIS,
12dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * See the License for the specific language governing permissions and
14dc549d60f98d809f626c99de614960409a847054Takeshi Aimi * limitations under the License.
15dc549d60f98d809f626c99de614960409a847054Takeshi Aimi */
16dc549d60f98d809f626c99de614960409a847054Takeshi Aimi
17dc549d60f98d809f626c99de614960409a847054Takeshi Aimipackage android.drm;
18dc549d60f98d809f626c99de614960409a847054Takeshi Aimi
19f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wangimport java.util.HashMap;
20f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang
21dc549d60f98d809f626c99de614960409a847054Takeshi Aimi/**
220e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber * An entity class that is passed to the
230e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber * {@link DrmManagerClient.OnErrorListener#onError onError()} callback.
24dc549d60f98d809f626c99de614960409a847054Takeshi Aimi *
25dc549d60f98d809f626c99de614960409a847054Takeshi Aimi */
26dc549d60f98d809f626c99de614960409a847054Takeshi Aimipublic class DrmErrorEvent extends DrmEvent {
27e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong
28e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // Please add newly defined type constants to the end of the list,
29e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // and modify checkTypeValidity() accordingly.
30e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong
31dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
320e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Something went wrong installing the rights.
33dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
34dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    public static final int TYPE_RIGHTS_NOT_INSTALLED = 2001;
35dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
360e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * The server rejected the renewal of rights.
37dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
38dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    public static final int TYPE_RIGHTS_RENEWAL_NOT_ALLOWED = 2002;
39dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
400e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Response from the server cannot be handled by the DRM plug-in (agent).
41dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
42dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    public static final int TYPE_NOT_SUPPORTED = 2003;
43dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
440e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Memory allocation failed during renewal. Can in the future perhaps be used to trigger
450e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * garbage collector.
46dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
47dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    public static final int TYPE_OUT_OF_MEMORY = 2004;
48dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
490e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * An Internet connection is not available and no attempt can be made to renew rights.
50dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
51dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    public static final int TYPE_NO_INTERNET_CONNECTION = 2005;
52dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
530e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Failed to process {@link DrmInfo}. This error event is sent when a
540e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * {@link DrmManagerClient#processDrmInfo processDrmInfo()} call fails.
55dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
56c7b3ccc564448cb4b918728421f9402bc18278c5Takeshi Aimi    public static final int TYPE_PROCESS_DRM_INFO_FAILED = 2006;
57dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
580e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Failed to remove all the rights objects associated with all DRM schemes.
59dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
60c7b3ccc564448cb4b918728421f9402bc18278c5Takeshi Aimi    public static final int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2007;
6127b277779c89251f2aafcc7a56db95d264900c9dGloria Wang    /**
620e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Failed to acquire {@link DrmInfo}. This error event is sent when an
630e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * {@link DrmManagerClient#acquireDrmInfo acquireDrmInfo()} call fails.
6427b277779c89251f2aafcc7a56db95d264900c9dGloria Wang     */
6527b277779c89251f2aafcc7a56db95d264900c9dGloria Wang    public static final int TYPE_ACQUIRE_DRM_INFO_FAILED = 2008;
66dc549d60f98d809f626c99de614960409a847054Takeshi Aimi
67e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // Add more type constants here...
68e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong
69e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // FIXME:
70e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // We may want to add a user-defined type constant, such as
71e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // TYPE_VENDOR_SPECIFIC_FAILED, to take care vendor specific use
72e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    // cases.
73e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong
74e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong
75dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    /**
760e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Creates a <code>DrmErrorEvent</code> object with the specified parameters.
77dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     *
780e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * @param uniqueId Unique session identifier.
79e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong     * @param type Type of the event. Must be any of the event types defined above.
80e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong     * @param message Message description. It can be null.
81dc549d60f98d809f626c99de614960409a847054Takeshi Aimi     */
82dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    public DrmErrorEvent(int uniqueId, int type, String message) {
83dc549d60f98d809f626c99de614960409a847054Takeshi Aimi        super(uniqueId, type, message);
84e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong        checkTypeValidity(type);
85dc549d60f98d809f626c99de614960409a847054Takeshi Aimi    }
86f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang
87f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang    /**
880e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * Creates a <code>DrmErrorEvent</code> object with the specified parameters.
89f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang     *
900e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * @param uniqueId Unique session identifier.
91e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong     * @param type Type of the event. Must be any of the event types defined above.
920e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber     * @param message Message description.
93f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang     * @param attributes Attributes for extensible information. Could be any
94e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong     * information provided by the plug-in. It can be null.
95f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang     */
96f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang    public DrmErrorEvent(int uniqueId, int type, String message,
97f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang                            HashMap<String, Object> attributes) {
98f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang        super(uniqueId, type, message, attributes);
99e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong        checkTypeValidity(type);
100e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    }
101e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong
102e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong    private void checkTypeValidity(int type) {
103e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong        if (type < TYPE_RIGHTS_NOT_INSTALLED ||
104e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong            type > TYPE_ACQUIRE_DRM_INFO_FAILED) {
105e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong            final String msg = "Unsupported type: " + type;
106e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong            throw new IllegalArgumentException(msg);
107e82f055e3eb1b0b3daf87bc14258fa65568b4f8aJames Dong        }
108f8bf3c46f524b1252bf466a351daaef61afdcecbGloria Wang    }
109dc549d60f98d809f626c99de614960409a847054Takeshi Aimi}
110