Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6ef0373 authored by Xin Li's avatar Xin Li
Browse files

DO NOT MERGE - Merge ab/7272582

Bug: 190855093
Merged-In: I2094ab904a34104089f29a219596e61a7317e00b
Change-Id: I859709171f3fb3afef1e8cb94ede8e0a758fe717
parents 021f13b4 28343349
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ status_t DrmPlugin::queryKeyStatus(
    }

    infoMap.clear();
    android::Mutex::Autolock lock(mPlayPolicyLock);
    for (size_t i = 0; i < mPlayPolicy.size(); ++i) {
        infoMap.add(mPlayPolicy.keyAt(i), mPlayPolicy.valueAt(i));
    }
+1 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ private:
    void initProperties();
    void setPlayPolicy();

    android::Mutex mPlayPolicyLock;
    mutable android::Mutex mPlayPolicyLock;
    android::KeyedVector<String8, String8> mPlayPolicy;
    android::KeyedVector<String8, String8> mStringProperties;
    android::KeyedVector<String8, Vector<uint8_t>> mByteArrayProperties;
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ cc_defaults {

    relative_install_path: "hw",

    cflags: ["-Wall", "-Werror"],
    cflags: ["-Wall", "-Werror", "-Wthread-safety"],

    shared_libs: [
        "android.hardware.drm@1.0",
+10 −2
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ Return<void> CryptoPlugin::setSharedBufferBase(
    sp<IMemory> hidlMemory = mapMemory(base);
    ALOGE_IF(hidlMemory == nullptr, "mapMemory returns nullptr");

    std::lock_guard<std::mutex> shared_buffer_lock(mSharedBufferLock);

    // allow mapMemory to return nullptr
    mSharedBufferMap[bufferId] = hidlMemory;
    return Void();
@@ -94,6 +96,7 @@ Return<void> CryptoPlugin::decrypt_1_2(
        return Void();
    }

    std::unique_lock<std::mutex> shared_buffer_lock(mSharedBufferLock);
    if (mSharedBufferMap.find(source.bufferId) == mSharedBufferMap.end()) {
      _hidl_cb(Status_V1_2::ERROR_DRM_CANNOT_HANDLE, 0,
               "source decrypt buffer base not set");
@@ -142,12 +145,17 @@ Return<void> CryptoPlugin::decrypt_1_2(

    base = static_cast<uint8_t *>(static_cast<void *>(destBase->getPointer()));

    if (destBuffer.offset + destBuffer.size > destBase->getSize()) {
    totalSize = 0;
    if (__builtin_add_overflow(destBuffer.offset, destBuffer.size, &totalSize) ||
        totalSize > destBase->getSize()) {
        android_errorWriteLog(0x534e4554, "176444622");
        _hidl_cb(Status_V1_2::ERROR_DRM_FRAME_TOO_LARGE, 0, "invalid buffer size");
        return Void();
    }
    destPtr = static_cast<void*>(base + destination.nonsecureMemory.offset);

    // release mSharedBufferLock
    shared_buffer_lock.unlock();

    // Calculate the output buffer size and determine if any subsamples are
    // encrypted.
+12 −1
Original line number Diff line number Diff line
@@ -220,6 +220,7 @@ Status_V1_2 DrmPlugin::getKeyRequestCommon(const hidl_vec<uint8_t>& scope,
        if (requestString.find(kOfflineLicense) != std::string::npos) {
            std::string emptyResponse;
            std::string keySetIdString(keySetId.begin(), keySetId.end());
            Mutex::Autolock lock(mFileHandleLock);
            if (!mFileHandle.StoreLicense(keySetIdString,
                    DeviceFiles::kLicenseStateReleasing,
                    emptyResponse)) {
@@ -335,6 +336,7 @@ bool DrmPlugin::makeKeySetId(std::string* keySetId) {
        }
        *keySetId = kKeySetIdPrefix + ByteArrayToHexString(
                reinterpret_cast<const uint8_t*>(randomData.data()), randomData.size());
        Mutex::Autolock lock(mFileHandleLock);
        if (mFileHandle.LicenseExists(*keySetId)) {
            // collision, regenerate
            ALOGV("Retry generating KeySetId");
@@ -392,6 +394,7 @@ Return<void> DrmPlugin::provideKeyResponse(
    if (status == Status::OK) {
        if (isOfflineLicense) {
            if (isRelease) {
                Mutex::Autolock lock(mFileHandleLock);
                mFileHandle.DeleteLicense(keySetId);
                mSessionLibrary->destroySession(session);
            } else {
@@ -400,6 +403,7 @@ Return<void> DrmPlugin::provideKeyResponse(
                    return Void();
                }

                Mutex::Autolock lock(mFileHandleLock);
                bool ok = mFileHandle.StoreLicense(
                        keySetId,
                        DeviceFiles::kLicenseStateActive,
@@ -454,6 +458,7 @@ Return<Status> DrmPlugin::restoreKeys(
        DeviceFiles::LicenseState licenseState;
        std::string offlineLicense;
        Status status = Status::OK;
        Mutex::Autolock lock(mFileHandleLock);
        if (!mFileHandle.RetrieveLicense(std::string(keySetId.begin(), keySetId.end()),
                &licenseState, &offlineLicense)) {
            ALOGE("Failed to restore offline license");
@@ -576,7 +581,6 @@ Return<Status> DrmPlugin::setPropertyByteArray(
Return<void> DrmPlugin::queryKeyStatus(
        const hidl_vec<uint8_t>& sessionId,
        queryKeyStatus_cb _hidl_cb) {

    if (sessionId.size() == 0) {
        // Returns empty key status KeyValue pair
        _hidl_cb(Status::BAD_VALUE, hidl_vec<KeyValue>());
@@ -586,12 +590,14 @@ Return<void> DrmPlugin::queryKeyStatus(
    std::vector<KeyValue> infoMapVec;
    infoMapVec.clear();

    mPlayPolicyLock.lock();
    KeyValue keyValuePair;
    for (size_t i = 0; i < mPlayPolicy.size(); ++i) {
        keyValuePair.key = mPlayPolicy[i].key;
        keyValuePair.value = mPlayPolicy[i].value;
        infoMapVec.push_back(keyValuePair);
    }
    mPlayPolicyLock.unlock();
    _hidl_cb(Status::OK, toHidlVec(infoMapVec));
    return Void();
}
@@ -704,6 +710,8 @@ Return<void> DrmPlugin::getMetrics(getMetrics_cb _hidl_cb) {
}

Return<void> DrmPlugin::getOfflineLicenseKeySetIds(getOfflineLicenseKeySetIds_cb _hidl_cb) {
    Mutex::Autolock lock(mFileHandleLock);

    std::vector<std::string> licenseNames = mFileHandle.ListLicenses();
    std::vector<KeySetId> keySetIds;
    if (mMockError != Status_V1_2::OK) {
@@ -724,6 +732,7 @@ Return<Status> DrmPlugin::removeOfflineLicense(const KeySetId& keySetId) {
        return toStatus_1_0(mMockError);
    }
    std::string licenseName(keySetId.begin(), keySetId.end());
    Mutex::Autolock lock(mFileHandleLock);
    if (mFileHandle.DeleteLicense(licenseName)) {
        return Status::OK;
    }
@@ -732,6 +741,8 @@ Return<Status> DrmPlugin::removeOfflineLicense(const KeySetId& keySetId) {

Return<void> DrmPlugin::getOfflineLicenseState(const KeySetId& keySetId,
        getOfflineLicenseState_cb _hidl_cb) {
    Mutex::Autolock lock(mFileHandleLock);

    std::string licenseName(keySetId.begin(), keySetId.end());
    DeviceFiles::LicenseState state;
    std::string license;
Loading