diff options
Diffstat (limited to 'drm')
| -rw-r--r-- | drm/libmediadrm/DrmHal.cpp | 88 | ||||
| -rw-r--r-- | drm/libmediadrm/IDrm.cpp | 14 | ||||
| -rw-r--r-- | drm/libmediadrm/PluginMetricsReporting.cpp | 12 | ||||
| -rw-r--r-- | drm/mediadrm/plugins/clearkey/hidl/Android.bp | 19 | ||||
| -rw-r--r-- | drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc | 14 | ||||
| -rw-r--r-- | drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc | 6 | ||||
| -rw-r--r-- | drm/mediadrm/plugins/clearkey/hidl/service.cpp | 10 | ||||
| -rw-r--r-- | drm/mediadrm/plugins/clearkey/hidl/serviceLazy.cpp | 50 |
8 files changed, 148 insertions, 65 deletions
diff --git a/drm/libmediadrm/DrmHal.cpp b/drm/libmediadrm/DrmHal.cpp index 480c7cda0a..5888af0e58 100644 --- a/drm/libmediadrm/DrmHal.cpp +++ b/drm/libmediadrm/DrmHal.cpp @@ -168,7 +168,7 @@ static DrmPlugin::OfflineLicenseState toOfflineLicenseState( case OfflineLicenseState::USABLE: return DrmPlugin::kOfflineLicenseStateUsable; case OfflineLicenseState::INACTIVE: - return DrmPlugin::kOfflineLicenseStateInactive; + return DrmPlugin::kOfflineLicenseStateReleased; default: return DrmPlugin::kOfflineLicenseStateUnknown; } @@ -586,51 +586,57 @@ Return<void> DrmHal::sendSessionLostState( return Void(); } -bool DrmHal::matchMimeTypeAndSecurityLevel(sp<IDrmFactory> &factory, - const uint8_t uuid[16], - const String8 &mimeType, - DrmPlugin::SecurityLevel level) { - if (mimeType == "") { - return true; - } else if (!factory->isContentTypeSupported(mimeType.string())) { - return false; - } +status_t DrmHal::matchMimeTypeAndSecurityLevel(const sp<IDrmFactory> &factory, + const uint8_t uuid[16], + const String8 &mimeType, + DrmPlugin::SecurityLevel level, + bool *isSupported) { + *isSupported = false; + // handle default value cases if (level == DrmPlugin::kSecurityLevelUnknown) { - return true; - } else { - sp<drm::V1_2::IDrmFactory> factoryV1_2 = drm::V1_2::IDrmFactory::castFrom(factory); - if (factoryV1_2 == NULL) { - return true; - } else if (factoryV1_2->isCryptoSchemeSupported_1_2(uuid, - mimeType.string(), toHidlSecurityLevel(level))) { - return true; + if (mimeType == "") { + // isCryptoSchemeSupported(uuid) + *isSupported = true; + } else { + // isCryptoSchemeSupported(uuid, mimeType) + *isSupported = factory->isContentTypeSupported(mimeType.string()); } + return OK; + } else if (mimeType == "") { + return BAD_VALUE; + } + + sp<drm::V1_2::IDrmFactory> factoryV1_2 = drm::V1_2::IDrmFactory::castFrom(factory); + if (factoryV1_2 == NULL) { + return ERROR_UNSUPPORTED; + } else { + *isSupported = factoryV1_2->isCryptoSchemeSupported_1_2(uuid, + mimeType.string(), toHidlSecurityLevel(level)); + return OK; } - return false; } -bool DrmHal::isCryptoSchemeSupported(const uint8_t uuid[16], - const String8 &mimeType, - DrmPlugin::SecurityLevel level) { +status_t DrmHal::isCryptoSchemeSupported(const uint8_t uuid[16], + const String8 &mimeType, + DrmPlugin::SecurityLevel level, + bool *isSupported) { Mutex::Autolock autoLock(mLock); - - for (size_t i = 0; i < mFactories.size(); i++) { - sp<IDrmFactory> factory = mFactories[i]; - if (factory->isCryptoSchemeSupported(uuid)) { - if (matchMimeTypeAndSecurityLevel(factory, uuid, mimeType, level)) { - return true; - } + *isSupported = false; + for (ssize_t i = mFactories.size() - 1; i >= 0; i--) { + if (mFactories[i]->isCryptoSchemeSupported(uuid)) { + return matchMimeTypeAndSecurityLevel(mFactories[i], + uuid, mimeType, level, isSupported); } } - return false; + return OK; } status_t DrmHal::createPlugin(const uint8_t uuid[16], const String8& appPackageName) { Mutex::Autolock autoLock(mLock); - for (size_t i = mFactories.size() - 1; i >= 0; i--) { + for (ssize_t i = mFactories.size() - 1; i >= 0; i--) { if (mFactories[i]->isCryptoSchemeSupported(uuid)) { auto plugin = makeDrmPlugin(mFactories[i], uuid, appPackageName); if (plugin != NULL) { @@ -1213,7 +1219,7 @@ status_t DrmHal::getOfflineLicenseKeySetIds(List<Vector<uint8_t>> &keySetIds) co } if (mPluginV1_2 == NULL) { - return ERROR_DRM_CANNOT_HANDLE; + return ERROR_UNSUPPORTED; } status_t err = UNKNOWN_ERROR; @@ -1238,7 +1244,7 @@ status_t DrmHal::removeOfflineLicense(Vector<uint8_t> const &keySetId) { } if (mPluginV1_2 == NULL) { - return ERROR_DRM_CANNOT_HANDLE; + return ERROR_UNSUPPORTED; } Return<Status> status = mPluginV1_2->removeOfflineLicense(toHidlVec(keySetId)); @@ -1254,7 +1260,7 @@ status_t DrmHal::getOfflineLicenseState(Vector<uint8_t> const &keySetId, } if (mPluginV1_2 == NULL) { - return ERROR_DRM_CANNOT_HANDLE; + return ERROR_UNSUPPORTED; } *licenseState = DrmPlugin::kOfflineLicenseStateUnknown; @@ -1550,22 +1556,22 @@ void DrmHal::writeByteArray(Parcel &obj, hidl_vec<uint8_t> const &vec) void DrmHal::reportFrameworkMetrics() const { - MediaAnalyticsItem item("mediadrm"); - item.generateSessionID(); - item.setPkgName(mMetrics.GetAppPackageName().c_str()); + std::unique_ptr<MediaAnalyticsItem> item(MediaAnalyticsItem::create("mediadrm")); + item->generateSessionID(); + item->setPkgName(mMetrics.GetAppPackageName().c_str()); String8 vendor; String8 description; status_t result = getPropertyStringInternal(String8("vendor"), vendor); if (result != OK) { ALOGE("Failed to get vendor from drm plugin: %d", result); } else { - item.setCString("vendor", vendor.c_str()); + item->setCString("vendor", vendor.c_str()); } result = getPropertyStringInternal(String8("description"), description); if (result != OK) { ALOGE("Failed to get description from drm plugin: %d", result); } else { - item.setCString("description", description.c_str()); + item->setCString("description", description.c_str()); } std::string serializedMetrics; @@ -1576,9 +1582,9 @@ void DrmHal::reportFrameworkMetrics() const std::string b64EncodedMetrics = toBase64StringNoPad(serializedMetrics.data(), serializedMetrics.size()); if (!b64EncodedMetrics.empty()) { - item.setCString("serialized_metrics", b64EncodedMetrics.c_str()); + item->setCString("serialized_metrics", b64EncodedMetrics.c_str()); } - if (!item.selfrecord()) { + if (!item->selfrecord()) { ALOGE("Failed to self record framework metrics"); } } diff --git a/drm/libmediadrm/IDrm.cpp b/drm/libmediadrm/IDrm.cpp index 0f343151c8..51274d16c1 100644 --- a/drm/libmediadrm/IDrm.cpp +++ b/drm/libmediadrm/IDrm.cpp @@ -83,8 +83,8 @@ struct BpDrm : public BpInterface<IDrm> { return reply.readInt32(); } - virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType, - DrmPlugin::SecurityLevel level) { + virtual status_t isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType, + DrmPlugin::SecurityLevel level, bool *isSupported) { Parcel data, reply; data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); data.write(uuid, 16); @@ -94,10 +94,11 @@ struct BpDrm : public BpInterface<IDrm> { status_t status = remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply); if (status != OK) { ALOGE("isCryptoSchemeSupported: binder call failed: %d", status); - return false; + return status; } + *isSupported = static_cast<bool>(reply.readInt32()); - return reply.readInt32() != 0; + return reply.readInt32(); } virtual status_t createPlugin(const uint8_t uuid[16], @@ -773,7 +774,10 @@ status_t BnDrm::onTransact( String8 mimeType = data.readString8(); DrmPlugin::SecurityLevel level = static_cast<DrmPlugin::SecurityLevel>(data.readInt32()); - reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType, level)); + bool isSupported = false; + status_t result = isCryptoSchemeSupported(uuid, mimeType, level, &isSupported); + reply->writeInt32(isSupported); + reply->writeInt32(result); return OK; } diff --git a/drm/libmediadrm/PluginMetricsReporting.cpp b/drm/libmediadrm/PluginMetricsReporting.cpp index 5cb48bf678..8cd6f969cc 100644 --- a/drm/libmediadrm/PluginMetricsReporting.cpp +++ b/drm/libmediadrm/PluginMetricsReporting.cpp @@ -34,17 +34,17 @@ constexpr char kSerializedMetricsField[] = "serialized_metrics"; status_t reportVendorMetrics(const std::string& metrics, const String8& name, const String8& appPackageName) { - MediaAnalyticsItem analyticsItem(name.c_str()); - analyticsItem.generateSessionID(); + std::unique_ptr<MediaAnalyticsItem> analyticsItem(MediaAnalyticsItem::create(name.c_str())); + analyticsItem->generateSessionID(); std::string app_package_name(appPackageName.c_str(), appPackageName.size()); - analyticsItem.setPkgName(app_package_name); + analyticsItem->setPkgName(app_package_name); if (metrics.size() > 0) { - analyticsItem.setCString(kSerializedMetricsField, metrics.c_str()); + analyticsItem->setCString(kSerializedMetricsField, metrics.c_str()); } - if (!analyticsItem.selfrecord()) { - ALOGE("selfrecord() returned false. sessioId %" PRId64, analyticsItem.getSessionID()); + if (!analyticsItem->selfrecord()) { + ALOGE("selfrecord() returned false. sessioId %" PRId64, analyticsItem->getSessionID()); } return OK; diff --git a/drm/mediadrm/plugins/clearkey/hidl/Android.bp b/drm/mediadrm/plugins/clearkey/hidl/Android.bp index b44a6c7099..e91e918b1d 100644 --- a/drm/mediadrm/plugins/clearkey/hidl/Android.bp +++ b/drm/mediadrm/plugins/clearkey/hidl/Android.bp @@ -14,8 +14,8 @@ // limitations under the License. // -cc_binary { - name: "android.hardware.drm@1.2-service.clearkey", +cc_defaults { + name: "clearkey_service_defaults", vendor: true, srcs: [ @@ -33,13 +33,11 @@ cc_binary { "MemoryFileSystem.cpp", "Session.cpp", "SessionLibrary.cpp", - "service.cpp", ], relative_install_path: "hw", cflags: ["-Wall", "-Werror"], - init_rc: ["android.hardware.drm@1.2-service.clearkey.rc"], shared_libs: [ "android.hardware.drm@1.0", @@ -80,3 +78,16 @@ cc_library_static { }, srcs: ["protos/DeviceFiles.proto"], } +cc_binary { + name: "android.hardware.drm@1.2-service.clearkey", + defaults: ["clearkey_service_defaults"], + srcs: ["service.cpp"], + init_rc: ["android.hardware.drm@1.2-service.clearkey.rc"], +} +cc_binary { + name: "android.hardware.drm@1.2-service-lazy.clearkey", + overrides: ["android.hardware.drm@1.2-service.clearkey"], + defaults: ["clearkey_service_defaults"], + srcs: ["serviceLazy.cpp"], + init_rc: ["android.hardware.drm@1.2-service-lazy.clearkey.rc"], +} diff --git a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc new file mode 100644 index 0000000000..9afd3d7979 --- /dev/null +++ b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc @@ -0,0 +1,14 @@ +service vendor.drm-clearkey-hal-1-2 /vendor/bin/hw/android.hardware.drm@1.2-service-lazy.clearkey + interface android.hardware.drm@1.0::ICryptoFactory clearkey + interface android.hardware.drm@1.0::IDrmFactory clearkey + interface android.hardware.drm@1.1::ICryptoFactory clearkey + interface android.hardware.drm@1.1::IDrmFactory clearkey + interface android.hardware.drm@1.2::ICryptoFactory clearkey + interface android.hardware.drm@1.2::IDrmFactory clearkey + disabled + oneshot + class hal + user media + group media mediadrm + ioprio rt 4 + writepid /dev/cpuset/foreground/tasks diff --git a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc index ac184f7105..5ba669dc50 100644 --- a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc +++ b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc @@ -1,4 +1,10 @@ service vendor.drm-clearkey-hal-1-2 /vendor/bin/hw/android.hardware.drm@1.2-service.clearkey + interface android.hardware.drm@1.0::ICryptoFactory clearkey + interface android.hardware.drm@1.0::IDrmFactory clearkey + interface android.hardware.drm@1.1::ICryptoFactory clearkey + interface android.hardware.drm@1.1::IDrmFactory clearkey + interface android.hardware.drm@1.2::ICryptoFactory clearkey + interface android.hardware.drm@1.2::IDrmFactory clearkey class hal user media group media mediadrm diff --git a/drm/mediadrm/plugins/clearkey/hidl/service.cpp b/drm/mediadrm/plugins/clearkey/hidl/service.cpp index 4ca31f35c1..b39ea018e4 100644 --- a/drm/mediadrm/plugins/clearkey/hidl/service.cpp +++ b/drm/mediadrm/plugins/clearkey/hidl/service.cpp @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "android.hardware.drm@1.2-service.clearkey" - #include <CryptoFactory.h> #include <DrmFactory.h> #include <android-base/logging.h> #include <binder/ProcessState.h> +#include <hidl/HidlLazyUtils.h> #include <hidl/HidlTransportSupport.h> using ::android::hardware::configureRpcThreadpool; @@ -31,14 +30,7 @@ using android::hardware::drm::V1_2::IDrmFactory; using android::hardware::drm::V1_2::clearkey::CryptoFactory; using android::hardware::drm::V1_2::clearkey::DrmFactory; - int main(int /* argc */, char** /* argv */) { - ALOGD("android.hardware.drm@1.2-service.clearkey starting..."); - - // The DRM HAL may communicate to other vendor components via - // /dev/vndbinder - android::ProcessState::initWithDriver("/dev/vndbinder"); - sp<IDrmFactory> drmFactory = new DrmFactory; sp<ICryptoFactory> cryptoFactory = new CryptoFactory; diff --git a/drm/mediadrm/plugins/clearkey/hidl/serviceLazy.cpp b/drm/mediadrm/plugins/clearkey/hidl/serviceLazy.cpp new file mode 100644 index 0000000000..99fd883b16 --- /dev/null +++ b/drm/mediadrm/plugins/clearkey/hidl/serviceLazy.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <CryptoFactory.h> +#include <DrmFactory.h> + +#include <android-base/logging.h> +#include <binder/ProcessState.h> +#include <hidl/HidlLazyUtils.h> +#include <hidl/HidlTransportSupport.h> + +using ::android::hardware::configureRpcThreadpool; +using ::android::hardware::joinRpcThreadpool; +using ::android::sp; + +using android::hardware::drm::V1_2::ICryptoFactory; +using android::hardware::drm::V1_2::IDrmFactory; +using android::hardware::drm::V1_2::clearkey::CryptoFactory; +using android::hardware::drm::V1_2::clearkey::DrmFactory; +using android::hardware::LazyServiceRegistrar; + +int main(int /* argc */, char** /* argv */) { + sp<IDrmFactory> drmFactory = new DrmFactory; + sp<ICryptoFactory> cryptoFactory = new CryptoFactory; + + configureRpcThreadpool(8, true /* callerWillJoin */); + + // Setup hwbinder service + LazyServiceRegistrar serviceRegistrar; + + // Setup hwbinder service + CHECK_EQ(serviceRegistrar.registerService(drmFactory, "clearkey"), android::NO_ERROR) + << "Failed to register Clearkey Factory HAL"; + CHECK_EQ(serviceRegistrar.registerService(cryptoFactory, "clearkey"), android::NO_ERROR) + << "Failed to register Clearkey Crypto HAL"; + + joinRpcThreadpool(); +} |
