Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2017 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.media;
     18 
     19 import android.hardware.cas.V1_0.Status;
     20 
     21 /**
     22  * Base class for MediaCas exceptions
     23  */
     24 public class MediaCasException extends Exception {
     25     private MediaCasException(String detailMessage) {
     26         super(detailMessage);
     27     }
     28 
     29     static void throwExceptionIfNeeded(int error) throws MediaCasException {
     30         if (error == Status.OK) {
     31             return;
     32         }
     33 
     34         if (error == Status.ERROR_CAS_NOT_PROVISIONED) {
     35             throw new NotProvisionedException(null);
     36         } else if (error == Status.ERROR_CAS_RESOURCE_BUSY) {
     37             throw new ResourceBusyException(null);
     38         } else if (error == Status.ERROR_CAS_DEVICE_REVOKED) {
     39             throw new DeniedByServerException(null);
     40         } else {
     41             MediaCasStateException.throwExceptionIfNeeded(error);
     42         }
     43     }
     44 
     45     /**
     46      * Exception thrown when an attempt is made to construct a MediaCas object
     47      * using a CA_system_id that is not supported by the device
     48      */
     49     public static final class UnsupportedCasException extends MediaCasException {
     50         /** @hide */
     51         public UnsupportedCasException(String detailMessage) {
     52             super(detailMessage);
     53         }
     54     }
     55 
     56     /**
     57      * Exception thrown when an operation on a MediaCas object is attempted
     58      * before it's provisioned successfully.
     59      */
     60     public static final class NotProvisionedException extends MediaCasException {
     61         /** @hide */
     62         public NotProvisionedException(String detailMessage) {
     63             super(detailMessage);
     64         }
     65     }
     66 
     67     /**
     68      * Exception thrown when the provisioning server or key server denies a
     69      * license for a device.
     70      */
     71     public static final class DeniedByServerException extends MediaCasException {
     72         /** @hide */
     73         public DeniedByServerException(String detailMessage) {
     74             super(detailMessage);
     75         }
     76     }
     77 
     78     /**
     79      * Exception thrown when an operation on a MediaCas object is attempted
     80      * and hardware resources are not available, due to being in use.
     81      */
     82     public static final class ResourceBusyException extends MediaCasException {
     83         /** @hide */
     84         public ResourceBusyException(String detailMessage) {
     85             super(detailMessage);
     86         }
     87     }
     88 }
     89