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