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 /**
     20  * An entity class that wraps converted data, conversion status, and the
     21  * offset for appending the header and body signature to the converted data.
     22  * An instance of this class may be created two ways by the drm framework:
     23  * a) a call to {@link DrmManagerClient#convertData DrmManagerClient.convertData()} and
     24  * b) a call to {@link DrmManagerClient#closeConvertSession DrmManagerClient.closeConvertSession()}.
     25  * An valid offset value is provided only from a success call to
     26  * {@link DrmManagerClient#closeConvertSession DrmManagerClient.closeConvertSession()}.
     27  *
     28  */
     29 public class DrmConvertedStatus {
     30     // The following status code constants must be in sync with
     31     // DrmConvertedStatus.cpp. Please also update isValidStatusCode()
     32     // when more status code constants are added.
     33     /**
     34      * Indicate the conversion status is successful.
     35      */
     36     public static final int STATUS_OK = 1;
     37     /**
     38      * Indicate a failed conversion status due to input data.
     39      */
     40     public static final int STATUS_INPUTDATA_ERROR = 2;
     41     /**
     42      * Indicate a general failed conversion status.
     43      */
     44     public static final int STATUS_ERROR = 3;
     45 
     46     /**
     47      * Status code for the conversion. Must be one of the defined status
     48      * constants above.
     49      */
     50     public final int statusCode;
     51     /**
     52      * Converted data. It is optional and thus can be null.
     53      */
     54     public final byte[] convertedData;
     55     /**
     56      * Offset value for the body and header signature.
     57      */
     58     public final int offset;
     59 
     60     /**
     61      * Creates a <code>DrmConvertedStatus</code> object with the specified parameters.
     62      *
     63      * @param statusCode Conversion status. Must be one of the status code constants
     64      * defined above.
     65      * @param convertedData Converted data. It can be null.
     66      * @param offset Offset value for appending the header and body signature.
     67      */
     68     public DrmConvertedStatus(int statusCode, byte[] convertedData, int offset) {
     69         if (!isValidStatusCode(statusCode)) {
     70             throw new IllegalArgumentException("Unsupported status code: " + statusCode);
     71         }
     72 
     73         this.statusCode = statusCode;
     74         this.convertedData = convertedData;
     75         this.offset = offset;
     76     }
     77 
     78     private boolean isValidStatusCode(int statusCode) {
     79         return statusCode == STATUS_OK ||
     80                statusCode == STATUS_INPUTDATA_ERROR ||
     81                statusCode == STATUS_ERROR;
     82     }
     83 }
     84 
     85