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 bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) = 0; 38 39 virtual status_t createPlugin(const uint8_t uuid[16], 40 const String8 &appPackageName) = 0; 41 42 virtual status_t destroyPlugin() = 0; 43 44 virtual status_t openSession(DrmPlugin::SecurityLevel securityLevel, 45 Vector<uint8_t> &sessionId) = 0; 46 47 virtual status_t closeSession(Vector<uint8_t> const &sessionId) = 0; 48 49 virtual status_t 50 getKeyRequest(Vector<uint8_t> const &sessionId, 51 Vector<uint8_t> const &initData, 52 String8 const &mimeType, DrmPlugin::KeyType keyType, 53 KeyedVector<String8, String8> const &optionalParameters, 54 Vector<uint8_t> &request, String8 &defaultUrl, 55 DrmPlugin::KeyRequestType *keyRequestType) = 0; 56 57 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId, 58 Vector<uint8_t> const &response, 59 Vector<uint8_t> &keySetId) = 0; 60 61 virtual status_t removeKeys(Vector<uint8_t> const &keySetId) = 0; 62 63 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId, 64 Vector<uint8_t> const &keySetId) = 0; 65 66 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId, 67 KeyedVector<String8, String8> &infoMap) const = 0; 68 69 virtual status_t getProvisionRequest(String8 const &certType, 70 String8 const &certAuthority, 71 Vector<uint8_t> &request, 72 String8 &defaulUrl) = 0; 73 74 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response, 75 Vector<uint8_t> &certificate, 76 Vector<uint8_t> &wrappedKey) = 0; 77 78 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) = 0; 79 virtual status_t getSecureStopIds(List<Vector<uint8_t> > &secureStopIds) = 0; 80 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) = 0; 81 82 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) = 0; 83 virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) = 0; 84 virtual status_t removeAllSecureStops() = 0; 85 86 virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connectedLevel, 87 DrmPlugin::HdcpLevel *maxLevel) 88 const = 0; 89 virtual status_t getNumberOfSessions(uint32_t *currentSessions, 90 uint32_t *maxSessions) const = 0; 91 virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId, 92 DrmPlugin::SecurityLevel *level) const = 0; 93 94 virtual status_t getPropertyString(String8 const &name, String8 &value) const = 0; 95 virtual status_t getPropertyByteArray(String8 const &name, 96 Vector<uint8_t> &value) const = 0; 97 virtual status_t setPropertyString(String8 const &name, 98 String8 const &value ) const = 0; 99 virtual status_t setPropertyByteArray(String8 const &name, 100 Vector<uint8_t> const &value) const = 0; 101 102 virtual status_t getMetrics(os::PersistableBundle *metrics) = 0; 103 104 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, 105 String8 const &algorithm) = 0; 106 107 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, 108 String8 const &algorithm) = 0; 109 110 virtual status_t encrypt(Vector<uint8_t> const &sessionId, 111 Vector<uint8_t> const &keyId, 112 Vector<uint8_t> const &input, 113 Vector<uint8_t> const &iv, 114 Vector<uint8_t> &output) = 0; 115 116 virtual status_t decrypt(Vector<uint8_t> const &sessionId, 117 Vector<uint8_t> const &keyId, 118 Vector<uint8_t> const &input, 119 Vector<uint8_t> const &iv, 120 Vector<uint8_t> &output) = 0; 121 122 virtual status_t sign(Vector<uint8_t> const &sessionId, 123 Vector<uint8_t> const &keyId, 124 Vector<uint8_t> const &message, 125 Vector<uint8_t> &signature) = 0; 126 127 virtual status_t verify(Vector<uint8_t> const &sessionId, 128 Vector<uint8_t> const &keyId, 129 Vector<uint8_t> const &message, 130 Vector<uint8_t> const &signature, 131 bool &match) = 0; 132 133 virtual status_t signRSA(Vector<uint8_t> const &sessionId, 134 String8 const &algorithm, 135 Vector<uint8_t> const &message, 136 Vector<uint8_t> const &wrappedKey, 137 Vector<uint8_t> &signature) = 0; 138 139 virtual status_t setListener(const sp<IDrmClient>& listener) = 0; 140 141 private: 142 DISALLOW_EVIL_CONSTRUCTORS(IDrm); 143 }; 144 145 struct BnDrm : public BnInterface<IDrm> { 146 virtual status_t onTransact( 147 uint32_t code, const Parcel &data, Parcel *reply, 148 uint32_t flags = 0); 149 private: 150 void readVector(const Parcel &data, Vector<uint8_t> &vector) const; 151 void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const; 152 }; 153 154 } // namespace android 155 156 #endif // ANDROID_IDRM_H_ 157