1 /* 2 * Copyright (C) 2021 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 DRM_HAL_AIDL_H_ 18 #define DRM_HAL_AIDL_H_ 19 20 #include <memory> 21 #include <aidl/android/hardware/drm/BnDrmPluginListener.h> 22 #include <aidl/android/hardware/drm/IDrmFactory.h> 23 #include <aidl/android/hardware/drm/IDrmPlugin.h> 24 #include <aidl/android/media/BnResourceManagerClient.h> 25 #include <mediadrm/DrmMetrics.h> 26 #include <mediadrm/DrmSessionManager.h> 27 #include <mediadrm/DrmHalListener.h> 28 #include <mediadrm/DrmStatus.h> 29 #include <mediadrm/IDrm.h> 30 31 using IDrmPluginAidl = ::aidl::android::hardware::drm::IDrmPlugin; 32 using IDrmFactoryAidl = ::aidl::android::hardware::drm::IDrmFactory; 33 using EventTypeAidl = ::aidl::android::hardware::drm::EventType; 34 using KeyStatusAidl = ::aidl::android::hardware::drm::KeyStatus; 35 using ::aidl::android::hardware::drm::Uuid; 36 37 namespace android { 38 struct DrmHalAidl : public IDrm{ 39 struct DrmSessionClient; 40 DrmHalAidl(); 41 virtual ~DrmHalAidl(); 42 virtual DrmStatus initCheck() const; 43 virtual DrmStatus isCryptoSchemeSupported(const uint8_t uuid[16], const String8& mimeType, 44 DrmPlugin::SecurityLevel securityLevel, bool* result); 45 virtual DrmStatus createPlugin(const uint8_t uuid[16], const String8& appPackageName); 46 virtual DrmStatus destroyPlugin(); 47 virtual DrmStatus openSession(DrmPlugin::SecurityLevel securityLevel, 48 Vector<uint8_t>& sessionId); 49 virtual DrmStatus closeSession(Vector<uint8_t> const& sessionId); 50 virtual DrmStatus getKeyRequest(Vector<uint8_t> const& sessionId, 51 Vector<uint8_t> const& initData, String8 const& mimeType, 52 DrmPlugin::KeyType keyType, 53 KeyedVector<String8, String8> const& optionalParameters, 54 Vector<uint8_t>& request, String8& defaultUrl, 55 DrmPlugin::KeyRequestType* keyRequestType); 56 virtual DrmStatus provideKeyResponse(Vector<uint8_t> const& sessionId, 57 Vector<uint8_t> const& response, 58 Vector<uint8_t>& keySetId); 59 virtual DrmStatus removeKeys(Vector<uint8_t> const& keySetId); 60 virtual DrmStatus restoreKeys(Vector<uint8_t> const& sessionId, 61 Vector<uint8_t> const& keySetId); 62 virtual DrmStatus queryKeyStatus(Vector<uint8_t> const& sessionId, 63 KeyedVector<String8, String8>& infoMap) const; 64 virtual DrmStatus getProvisionRequest(String8 const& certType, String8 const& certAuthority, 65 Vector<uint8_t>& request, String8& defaultUrl); 66 virtual DrmStatus provideProvisionResponse(Vector<uint8_t> const& response, 67 Vector<uint8_t>& certificate, 68 Vector<uint8_t>& wrappedKey); 69 virtual DrmStatus getSecureStops(List<Vector<uint8_t>>& secureStops); 70 virtual DrmStatus getSecureStopIds(List<Vector<uint8_t>>& secureStopIds); 71 virtual DrmStatus getSecureStop(Vector<uint8_t> const& ssid, Vector<uint8_t>& secureStop); 72 virtual DrmStatus releaseSecureStops(Vector<uint8_t> const& ssRelease); 73 virtual DrmStatus removeSecureStop(Vector<uint8_t> const& ssid); 74 virtual DrmStatus removeAllSecureStops(); 75 virtual DrmStatus getHdcpLevels(DrmPlugin::HdcpLevel* connectedLevel, 76 DrmPlugin::HdcpLevel* maxLevel) const; 77 virtual DrmStatus getNumberOfSessions(uint32_t* currentSessions, uint32_t* maxSessions) const; 78 virtual DrmStatus getSecurityLevel(Vector<uint8_t> const& sessionId, 79 DrmPlugin::SecurityLevel* level) const; 80 virtual DrmStatus getOfflineLicenseKeySetIds(List<Vector<uint8_t>>& keySetIds) const; 81 virtual DrmStatus removeOfflineLicense(Vector<uint8_t> const& keySetId); 82 virtual DrmStatus getOfflineLicenseState(Vector<uint8_t> const& keySetId, 83 DrmPlugin::OfflineLicenseState* licenseState) const; 84 virtual DrmStatus getPropertyString(String8 const& name, String8& value) const; 85 virtual DrmStatus getPropertyByteArray(String8 const& name, Vector<uint8_t>& value) const; 86 virtual DrmStatus setPropertyString(String8 const& name, String8 const& value) const; 87 virtual DrmStatus setPropertyByteArray(String8 const& name, Vector<uint8_t> const& value) const; 88 virtual DrmStatus getMetrics(const sp<IDrmMetricsConsumer>& consumer); 89 virtual DrmStatus setCipherAlgorithm(Vector<uint8_t> const& sessionId, 90 String8 const& algorithm); 91 virtual DrmStatus setMacAlgorithm(Vector<uint8_t> const& sessionId, String8 const& algorithm); 92 virtual DrmStatus encrypt(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, 93 Vector<uint8_t> const& input, Vector<uint8_t> const& iv, 94 Vector<uint8_t>& output); 95 virtual DrmStatus decrypt(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, 96 Vector<uint8_t> const& input, Vector<uint8_t> const& iv, 97 Vector<uint8_t>& output); 98 virtual DrmStatus sign(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, 99 Vector<uint8_t> const& message, Vector<uint8_t>& signature); 100 virtual DrmStatus verify(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, 101 Vector<uint8_t> const& message, Vector<uint8_t> const& signature, 102 bool& match); 103 virtual DrmStatus signRSA(Vector<uint8_t> const& sessionId, String8 const& algorithm, 104 Vector<uint8_t> const& message, Vector<uint8_t> const& wrappedKey, 105 Vector<uint8_t>& signature); 106 virtual DrmStatus setListener(const sp<IDrmClient>& listener); 107 virtual DrmStatus requiresSecureDecoder(const char* mime, bool* required) const; 108 virtual DrmStatus requiresSecureDecoder(const char* mime, 109 DrmPlugin::SecurityLevel securityLevel, 110 bool* required) const; 111 virtual DrmStatus setPlaybackId(Vector<uint8_t> const& sessionId, const char* playbackId); 112 virtual DrmStatus getLogMessages(Vector<drm::V1_4::LogMessage>& logs) const; 113 virtual DrmStatus getSupportedSchemes(std::vector<uint8_t>& schemes) const; 114 115 ::ndk::ScopedAStatus onEvent(EventTypeAidl in_eventType, 116 const std::vector<uint8_t>& in_sessionId, 117 const std::vector<uint8_t>& in_data); 118 ::ndk::ScopedAStatus onExpirationUpdate(const std::vector<uint8_t>& in_sessionId, 119 int64_t in_expiryTimeInMS); 120 ::ndk::ScopedAStatus onKeysChange(const std::vector<uint8_t>& in_sessionId, 121 const std::vector<KeyStatusAidl>& in_keyStatusList, 122 bool in_hasNewUsableKey); 123 ::ndk::ScopedAStatus onSessionLostState(const std::vector<uint8_t>& in_sessionId); 124 private: 125 static Mutex mLock; 126 std::shared_ptr<MediaDrmMetrics> mMetrics; 127 std::shared_ptr<DrmHalListener> mListener; 128 const std::vector<std::shared_ptr<IDrmFactoryAidl>> mFactories; 129 std::shared_ptr<IDrmPluginAidl> mPlugin; 130 status_t mInitCheck; 131 std::vector<std::shared_ptr<DrmSessionClient>> mOpenSessions; 132 void cleanup(); 133 void closeOpenSessions(); 134 std::string reportPluginMetrics() const; 135 std::string reportFrameworkMetrics(const std::string& pluginMetrics) const; 136 DrmStatus getPropertyStringInternal(String8 const& name, String8& value) const; 137 DrmStatus getPropertyByteArrayInternal(String8 const& name, Vector<uint8_t>& value) const; 138 DISALLOW_EVIL_CONSTRUCTORS(DrmHalAidl); 139 }; 140 141 } // namespace android 142 143 #endif // DRM_HAL_AIDL_H_