1 /* 2 * Copyright (C) 2016 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 #ifndef ANDROID_HARDWARE_DRM_V1_0__DRMPLUGIN_H 18 #define ANDROID_HARDWARE_DRM_V1_0__DRMPLUGIN_H 19 20 #include <android/hardware/drm/1.0/IDrmPlugin.h> 21 #include <android/hardware/drm/1.0/IDrmPluginListener.h> 22 #include <hidl/Status.h> 23 #include <media/drm/DrmAPI.h> 24 25 namespace android { 26 namespace hardware { 27 namespace drm { 28 namespace V1_0 { 29 namespace implementation { 30 31 using ::android::hardware::drm::V1_0::EventType; 32 using ::android::hardware::drm::V1_0::IDrmPlugin; 33 using ::android::hardware::drm::V1_0::IDrmPluginListener; 34 using ::android::hardware::drm::V1_0::KeyRequestType; 35 using ::android::hardware::drm::V1_0::KeyStatus; 36 using ::android::hardware::drm::V1_0::KeyType; 37 using ::android::hardware::drm::V1_0::KeyValue; 38 using ::android::hardware::drm::V1_0::SecureStop; 39 using ::android::hardware::hidl_array; 40 using ::android::hardware::hidl_string; 41 using ::android::hardware::hidl_vec; 42 using ::android::hardware::Return; 43 using ::android::hardware::Void; 44 using ::android::sp; 45 46 struct DrmPlugin : public IDrmPlugin, android::DrmPluginListener { 47 DrmPluginDrmPlugin48 DrmPlugin(android::DrmPlugin *plugin) : mLegacyPlugin(plugin) {} ~DrmPluginDrmPlugin49 ~DrmPlugin() {delete mLegacyPlugin;} 50 51 // Methods from ::android::hardware::drm::V1_0::IDrmPlugin follow. 52 53 Return<void> openSession(openSession_cb _hidl_cb) override; 54 55 Return<Status> closeSession(const hidl_vec<uint8_t>& sessionId) override; 56 57 Return<void> getKeyRequest(const hidl_vec<uint8_t>& scope, 58 const hidl_vec<uint8_t>& initData, const hidl_string& mimeType, 59 KeyType keyType, const hidl_vec<KeyValue>& optionalParameters, 60 getKeyRequest_cb _hidl_cb) override; 61 62 Return<void> provideKeyResponse(const hidl_vec<uint8_t>& scope, 63 const hidl_vec<uint8_t>& response, provideKeyResponse_cb _hidl_cb) 64 override; 65 66 Return<Status> removeKeys(const hidl_vec<uint8_t>& sessionId) override; 67 68 Return<Status> restoreKeys(const hidl_vec<uint8_t>& sessionId, 69 const hidl_vec<uint8_t>& keySetId) override; 70 71 Return<void> queryKeyStatus(const hidl_vec<uint8_t>& sessionId, 72 queryKeyStatus_cb _hidl_cb) override; 73 74 Return<void> getProvisionRequest(const hidl_string& certificateType, 75 const hidl_string& certificateAuthority, 76 getProvisionRequest_cb _hidl_cb) override; 77 78 Return<void> provideProvisionResponse(const hidl_vec<uint8_t>& response, 79 provideProvisionResponse_cb _hidl_cb) override; 80 81 Return<void> getSecureStops(getSecureStops_cb _hidl_cb) override; 82 83 Return<void> getSecureStop(const hidl_vec<uint8_t>& secureStopId, 84 getSecureStop_cb _hidl_cb) override; 85 86 Return<Status> releaseAllSecureStops() override; 87 88 Return<Status> releaseSecureStop(const hidl_vec<uint8_t>& secureStopId) 89 override; 90 91 Return<void> getPropertyString(const hidl_string& propertyName, 92 getPropertyString_cb _hidl_cb) override; 93 94 Return<void> getPropertyByteArray(const hidl_string& propertyName, 95 getPropertyByteArray_cb _hidl_cb) override; 96 97 Return<Status> setPropertyString(const hidl_string& propertyName, 98 const hidl_string& value) override; 99 100 Return<Status> setPropertyByteArray(const hidl_string& propertyName, 101 const hidl_vec<uint8_t>& value) override; 102 103 Return<Status> setCipherAlgorithm(const hidl_vec<uint8_t>& sessionId, 104 const hidl_string& algorithm) override; 105 106 Return<Status> setMacAlgorithm(const hidl_vec<uint8_t>& sessionId, 107 const hidl_string& algorithm) override; 108 109 Return<void> encrypt(const hidl_vec<uint8_t>& sessionId, 110 const hidl_vec<uint8_t>& keyId, const hidl_vec<uint8_t>& input, 111 const hidl_vec<uint8_t>& iv, encrypt_cb _hidl_cb) override; 112 113 Return<void> decrypt(const hidl_vec<uint8_t>& sessionId, 114 const hidl_vec<uint8_t>& keyId, const hidl_vec<uint8_t>& input, 115 const hidl_vec<uint8_t>& iv, decrypt_cb _hidl_cb) override; 116 117 Return<void> sign(const hidl_vec<uint8_t>& sessionId, 118 const hidl_vec<uint8_t>& keyId, const hidl_vec<uint8_t>& message, 119 sign_cb _hidl_cb) override; 120 121 Return<void> verify(const hidl_vec<uint8_t>& sessionId, 122 const hidl_vec<uint8_t>& keyId, const hidl_vec<uint8_t>& message, 123 const hidl_vec<uint8_t>& signature, verify_cb _hidl_cb) override; 124 125 Return<void> signRSA(const hidl_vec<uint8_t>& sessionId, 126 const hidl_string& algorithm, const hidl_vec<uint8_t>& message, 127 const hidl_vec<uint8_t>& wrappedkey, signRSA_cb _hidl_cb) override; 128 129 Return<void> setListener(const sp<IDrmPluginListener>& listener) override; 130 131 Return<void> sendEvent(EventType eventType, 132 const hidl_vec<uint8_t>& sessionId, const hidl_vec<uint8_t>& data) 133 override; 134 135 Return<void> sendExpirationUpdate(const hidl_vec<uint8_t>& sessionId, 136 int64_t expiryTimeInMS) override; 137 138 Return<void> sendKeysChange(const hidl_vec<uint8_t>& sessionId, 139 const hidl_vec<KeyStatus>& keyStatusList, bool hasNewUsableKey) 140 override; 141 142 // Methods from android::DrmPluginListener follow 143 144 virtual void sendEvent(android::DrmPlugin::EventType eventType, int extra, 145 Vector<uint8_t> const *sessionId, Vector<uint8_t> const *data); 146 147 virtual void sendExpirationUpdate(Vector<uint8_t> const *sessionId, 148 int64_t expiryTimeInMS); 149 150 virtual void sendKeysChange(Vector<uint8_t> const *sessionId, 151 Vector<android::DrmPlugin::KeyStatus> const *keyStatusList, 152 bool hasNewUsableKey); 153 154 private: 155 android::DrmPlugin *mLegacyPlugin; 156 sp<IDrmPluginListener> mListener; 157 158 DrmPlugin() = delete; 159 DrmPlugin(const DrmPlugin &) = delete; 160 void operator=(const DrmPlugin &) = delete; 161 }; 162 163 } // namespace implementation 164 } // namespace V1_0 165 } // namespace drm 166 } // namespace hardware 167 } // namespace android 168 169 #endif // ANDROID_HARDWARE_DRM_V1_0__DRMPLUGIN_H 170