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.OnInfoListener#onInfo onInfo()} callback. 24 * 25 */ 26 public class DrmInfoEvent extends DrmEvent { 27 28 // Please add newly defined type constants to the end of the list, 29 // and modify checkTypeValidity() accordingly. 30 31 /** 32 * The registration has already been done by another account ID. 33 */ 34 public static final int TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT = 1; 35 /** 36 * The rights need to be removed completely. 37 */ 38 public static final int TYPE_REMOVE_RIGHTS = 2; 39 /** 40 * The rights have been successfully downloaded and installed. 41 */ 42 public static final int TYPE_RIGHTS_INSTALLED = 3; 43 /** 44 * The rights object is being delivered to the device. You must wait before 45 * calling {@link DrmManagerClient#acquireRights acquireRights()} again. 46 */ 47 public static final int TYPE_WAIT_FOR_RIGHTS = 4; 48 /** 49 * The registration has already been done for the given account. 50 */ 51 public static final int TYPE_ACCOUNT_ALREADY_REGISTERED = 5; 52 /** 53 * The rights have been removed. 54 */ 55 public static final int TYPE_RIGHTS_REMOVED = 6; 56 57 // Add more type constants here... 58 59 // FIXME: 60 // We may want to add a user-defined type constant, such as 61 // TYPE_VENDOR_SPECIFIC, to take care vendor specific use 62 // cases. 63 64 /** 65 * Creates a <code>DrmInfoEvent</code> object with the specified parameters. 66 * 67 * @param uniqueId Unique session identifier. 68 * @param type Type of the event. Must be any of the event types defined above, 69 * or the constants defined in {@link DrmEvent}. 70 * @param message Message description. It can be null. 71 */ DrmInfoEvent(int uniqueId, int type, String message)72 public DrmInfoEvent(int uniqueId, int type, String message) { 73 super(uniqueId, type, message); 74 checkTypeValidity(type); 75 } 76 77 /** 78 * Creates a <code>DrmInfoEvent</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 * or the constants defined in {@link DrmEvent} 83 * @param message Message description. It can be null. 84 * @param attributes Attributes for extensible information. Could be any 85 * information provided by the plug-in. 86 */ DrmInfoEvent(int uniqueId, int type, String message, HashMap<String, Object> attributes)87 public DrmInfoEvent(int uniqueId, int type, String message, 88 HashMap<String, Object> attributes) { 89 super(uniqueId, type, message, attributes); 90 checkTypeValidity(type); 91 } 92 93 /* 94 * Check the validity of the given type. 95 * To overcome a design flaw, we need also accept the type constants 96 * defined in super class, DrmEvent. 97 */ checkTypeValidity(int type)98 private void checkTypeValidity(int type) { 99 if (type < TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT || 100 type > TYPE_RIGHTS_REMOVED) { 101 102 if (type != TYPE_ALL_RIGHTS_REMOVED && 103 type != TYPE_DRM_INFO_PROCESSED) { 104 final String msg = "Unsupported type: " + type; 105 throw new IllegalArgumentException(msg); 106 } 107 } 108 } 109 } 110 111