Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2013 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 #include <binder/IInterface.h>
     18 #include <binder/PersistableBundle.h>
     19 #include <media/stagefright/foundation/ABase.h>
     20 #include <media/drm/DrmAPI.h>
     21 #include <media/MediaAnalyticsItem.h>
     22 #include <mediadrm/IDrmClient.h>
     23 
     24 #ifndef ANDROID_IDRM_H_
     25 
     26 #define ANDROID_IDRM_H_
     27 
     28 namespace android {
     29 
     30 struct AString;
     31 
     32 struct IDrm : public IInterface {
     33     DECLARE_META_INTERFACE(Drm);
     34 
     35     virtual status_t initCheck() const = 0;
     36 
     37     virtual status_t isCryptoSchemeSupported(const uint8_t uuid[16],
     38                                              const String8 &mimeType,
     39                                              DrmPlugin::SecurityLevel securityLevel,
     40                                              bool *result) = 0;
     41 
     42     virtual status_t createPlugin(const uint8_t uuid[16],
     43                                   const String8 &appPackageName) = 0;
     44 
     45     virtual status_t destroyPlugin() = 0;
     46 
     47     virtual status_t openSession(DrmPlugin::SecurityLevel securityLevel,
     48             Vector<uint8_t> &sessionId) = 0;
     49 
     50     virtual status_t closeSession(Vector<uint8_t> const &sessionId) = 0;
     51 
     52     virtual status_t
     53         getKeyRequest(Vector<uint8_t> const &sessionId,
     54                       Vector<uint8_t> const &initData,
     55                       String8 const &mimeType, DrmPlugin::KeyType keyType,
     56                       KeyedVector<String8, String8> const &optionalParameters,
     57                       Vector<uint8_t> &request, String8 &defaultUrl,
     58                       DrmPlugin::KeyRequestType *keyRequestType) = 0;
     59 
     60     virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
     61                                         Vector<uint8_t> const &response,
     62                                         Vector<uint8_t> &keySetId) = 0;
     63 
     64     virtual status_t removeKeys(Vector<uint8_t> const &keySetId) = 0;
     65 
     66     virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
     67                                  Vector<uint8_t> const &keySetId) = 0;
     68 
     69     virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
     70                                     KeyedVector<String8, String8> &infoMap) const = 0;
     71 
     72     virtual status_t getProvisionRequest(String8 const &certType,
     73                                          String8 const &certAuthority,
     74                                          Vector<uint8_t> &request,
     75                                          String8 &defaulUrl) = 0;
     76 
     77     virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
     78                                               Vector<uint8_t> &certificate,
     79                                               Vector<uint8_t> &wrappedKey) = 0;
     80 
     81     virtual status_t getSecureStops(List<Vector<uint8_t>> &secureStops) = 0;
     82     virtual status_t getSecureStopIds(List<Vector<uint8_t>> &secureStopIds) = 0;
     83     virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) = 0;
     84 
     85     virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) = 0;
     86     virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) = 0;
     87     virtual status_t removeAllSecureStops() = 0;
     88 
     89     virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connectedLevel,
     90             DrmPlugin::HdcpLevel *maxLevel)
     91             const = 0;
     92     virtual status_t getNumberOfSessions(uint32_t *currentSessions,
     93             uint32_t *maxSessions) const = 0;
     94     virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId,
     95             DrmPlugin::SecurityLevel *level) const = 0;
     96 
     97     virtual status_t getOfflineLicenseKeySetIds(List<Vector<uint8_t>> &keySetIds) const = 0;
     98     virtual status_t removeOfflineLicense(Vector<uint8_t> const &keySetId) = 0;
     99     virtual status_t getOfflineLicenseState(Vector<uint8_t> const &keySetId,
    100             DrmPlugin::OfflineLicenseState *licenseState) const = 0;
    101 
    102     virtual status_t getPropertyString(String8 const &name, String8 &value) const = 0;
    103     virtual status_t getPropertyByteArray(String8 const &name,
    104                                           Vector<uint8_t> &value) const = 0;
    105     virtual status_t setPropertyString(String8 const &name,
    106                                        String8 const &value ) const = 0;
    107     virtual status_t setPropertyByteArray(String8 const &name,
    108                                           Vector<uint8_t> const &value) const = 0;
    109 
    110     virtual status_t getMetrics(os::PersistableBundle *metrics) = 0;
    111 
    112     virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
    113                                         String8 const &algorithm) = 0;
    114 
    115     virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
    116                                      String8 const &algorithm) = 0;
    117 
    118     virtual status_t encrypt(Vector<uint8_t> const &sessionId,
    119                              Vector<uint8_t> const &keyId,
    120                              Vector<uint8_t> const &input,
    121                              Vector<uint8_t> const &iv,
    122                              Vector<uint8_t> &output) = 0;
    123 
    124     virtual status_t decrypt(Vector<uint8_t> const &sessionId,
    125                              Vector<uint8_t> const &keyId,
    126                              Vector<uint8_t> const &input,
    127                              Vector<uint8_t> const &iv,
    128                              Vector<uint8_t> &output) = 0;
    129 
    130     virtual status_t sign(Vector<uint8_t> const &sessionId,
    131                           Vector<uint8_t> const &keyId,
    132                           Vector<uint8_t> const &message,
    133                           Vector<uint8_t> &signature) = 0;
    134 
    135     virtual status_t verify(Vector<uint8_t> const &sessionId,
    136                             Vector<uint8_t> const &keyId,
    137                             Vector<uint8_t> const &message,
    138                             Vector<uint8_t> const &signature,
    139                             bool &match) = 0;
    140 
    141     virtual status_t signRSA(Vector<uint8_t> const &sessionId,
    142                              String8 const &algorithm,
    143                              Vector<uint8_t> const &message,
    144                              Vector<uint8_t> const &wrappedKey,
    145                              Vector<uint8_t> &signature) = 0;
    146 
    147     virtual status_t setListener(const sp<IDrmClient>& listener) = 0;
    148 
    149 private:
    150     DISALLOW_EVIL_CONSTRUCTORS(IDrm);
    151 };
    152 
    153 struct BnDrm : public BnInterface<IDrm> {
    154     virtual status_t onTransact(
    155             uint32_t code, const Parcel &data, Parcel *reply,
    156             uint32_t flags = 0);
    157 private:
    158     void readVector(const Parcel &data, Vector<uint8_t> &vector) const;
    159     void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const;
    160 };
    161 
    162 }  // namespace android
    163 
    164 #endif // ANDROID_IDRM_H_
    165