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 19/** 20 * An entity class that wraps the result of communication between a device 21 * and an online DRM server. Specifically, when the 22 * {@link DrmManagerClient#processDrmInfo DrmManagerClient.processDrmInfo()} 23 * method is called, an instance of <code>DrmInfoStatus</code> is returned. 24 *<p> 25 * This class contains the {@link ProcessedData} object, which can be used 26 * to instantiate a {@link DrmRights} object during license acquisition. 27 * 28 */ 29public class DrmInfoStatus { 30 // The following status code constants must be in sync with DrmInfoStatus.cpp 31 // Please update isValidStatusCode() if more status codes are added. 32 /** 33 * Indicate successful communication. 34 */ 35 public static final int STATUS_OK = 1; 36 37 /** 38 * Indicate failed communication. 39 */ 40 public static final int STATUS_ERROR = 2; 41 42 /** 43 * The status of the communication. Must be one of the defined status 44 * constants above. 45 */ 46 public final int statusCode; 47 /** 48 * The type of DRM information processed. Must be one of the valid type 49 * constants defined in {@link DrmInfoRequest}. 50 */ 51 public final int infoType; 52 /** 53 * The MIME type of the content. Must not be null or an empty string. 54 */ 55 public final String mimeType; 56 /** 57 * The processed data. It is optional and thus could be null. When it 58 * is null, it indicates that a particular call to 59 * {@link DrmManagerClient#processDrmInfo DrmManagerClient.processDrmInfo()} 60 * does not return any additional useful information except for the status code. 61 */ 62 public final ProcessedData data; 63 64 /** 65 * Creates a <code>DrmInfoStatus</code> object with the specified parameters. 66 * 67 * @param statusCode The status of the communication. Must be one of the defined 68 * status constants above. 69 * @param infoType The type of the DRM information processed. Must be a valid 70 * type for {@link DrmInfoRequest}. 71 * @param data The processed data. 72 * @param mimeType The MIME type. 73 */ 74 public DrmInfoStatus(int statusCode, int infoType, ProcessedData data, String mimeType) { 75 if (!DrmInfoRequest.isValidType(infoType)) { 76 throw new IllegalArgumentException("infoType: " + infoType); 77 } 78 79 if (!isValidStatusCode(statusCode)) { 80 throw new IllegalArgumentException("Unsupported status code: " + statusCode); 81 } 82 83 if (mimeType == null || mimeType == "") { 84 throw new IllegalArgumentException("mimeType is null or an empty string"); 85 } 86 87 this.statusCode = statusCode; 88 this.infoType = infoType; 89 this.data = data; 90 this.mimeType = mimeType; 91 } 92 93 private boolean isValidStatusCode(int statusCode) { 94 return statusCode == STATUS_OK || statusCode == STATUS_ERROR; 95 } 96} 97 98