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

Commit 69f8f744 authored by Xin Li's avatar Xin Li
Browse files

DO NOT MERGE - Merge RQ3A.210605.005

Bug: 190855093
Merged-In: Id0a543a695fec5523410b41a289f2a71cd850b70
Change-Id: Iddab4cc5480ea83283e56514d9bc00319419a714
parents 11854c2d b8cf151c
Loading
Loading
Loading
Loading
+14 −3
Original line number Original line Diff line number Diff line
@@ -31,6 +31,14 @@ namespace impl {
GeneratorHub::GeneratorHub(const OnHalEvent& onHalEvent)
GeneratorHub::GeneratorHub(const OnHalEvent& onHalEvent)
    : mOnHalEvent(onHalEvent), mThread(&GeneratorHub::run, this) {}
    : mOnHalEvent(onHalEvent), mThread(&GeneratorHub::run, this) {}


GeneratorHub::~GeneratorHub() {
    mShuttingDownFlag.store(true);
    mCond.notify_all();
    if (mThread.joinable()) {
        mThread.join();
    }
}

void GeneratorHub::registerGenerator(int32_t cookie, FakeValueGeneratorPtr generator) {
void GeneratorHub::registerGenerator(int32_t cookie, FakeValueGeneratorPtr generator) {
    {
    {
        std::lock_guard<std::mutex> g(mLock);
        std::lock_guard<std::mutex> g(mLock);
@@ -58,15 +66,18 @@ void GeneratorHub::unregisterGenerator(int32_t cookie) {
}
}


void GeneratorHub::run() {
void GeneratorHub::run() {
    while (true) {
    while (!mShuttingDownFlag.load()) {
        std::unique_lock<std::mutex> g(mLock);
        std::unique_lock<std::mutex> g(mLock);
        // Pop events whose generator does not exist (may be already unregistered)
        // Pop events whose generator does not exist (may be already unregistered)
        while (!mEventQueue.empty()
        while (!mEventQueue.empty()
               && mGenerators.find(mEventQueue.top().cookie) == mGenerators.end()) {
               && mGenerators.find(mEventQueue.top().cookie) == mGenerators.end()) {
             mEventQueue.pop();
             mEventQueue.pop();
        }
        }
        // Wait until event queue is not empty
        // Wait until event queue is not empty or shutting down flag is set
        mCond.wait(g, [this] { return !mEventQueue.empty(); });
        mCond.wait(g, [this] { return !mEventQueue.empty() || mShuttingDownFlag.load(); });
        if (mShuttingDownFlag.load()) {
            break;
        }


        const VhalEvent& curEvent = mEventQueue.top();
        const VhalEvent& curEvent = mEventQueue.top();


+2 −1
Original line number Original line Diff line number Diff line
@@ -58,7 +58,7 @@ private:


public:
public:
    GeneratorHub(const OnHalEvent& onHalEvent);
    GeneratorHub(const OnHalEvent& onHalEvent);
    ~GeneratorHub() = default;
    ~GeneratorHub();


    /**
    /**
     * Register a new generator. The generator will be discarded if it could not produce next event.
     * Register a new generator. The generator will be discarded if it could not produce next event.
@@ -84,6 +84,7 @@ private:
    mutable std::mutex mLock;
    mutable std::mutex mLock;
    std::condition_variable mCond;
    std::condition_variable mCond;
    std::thread mThread;
    std::thread mThread;
    std::atomic<bool> mShuttingDownFlag{false};
};
};


}  // namespace impl
}  // namespace impl
+0 −1
Original line number Original line Diff line number Diff line
@@ -549,7 +549,6 @@ void CameraModule::removeCamera(int cameraId) {
                }
                }
            }
            }
        }
        }
        free_camera_metadata(metadata);
    }
    }


    mCameraInfoMap.removeItem(cameraId);
    mCameraInfoMap.removeItem(cameraId);
+2 −1
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ cc_library_static {
        "-Werror",
        "-Werror",
        "-Wextra",
        "-Wextra",
        "-Wall",
        "-Wall",
        "-Wthread-safety",
    ],
    ],
    shared_libs: [
    shared_libs: [
        "liblog",
        "liblog",
@@ -42,7 +43,7 @@ cc_library_static {
    export_header_lib_headers: [
    export_header_lib_headers: [
        "libutils_headers",
        "libutils_headers",
    ],
    ],
    export_include_dirs : ["include"]
    export_include_dirs: ["include"],
}
}


soong_config_module_type {
soong_config_module_type {
+13 −4
Original line number Original line Diff line number Diff line
@@ -53,6 +53,8 @@ namespace implementation {
            uint32_t bufferId) {
            uint32_t bufferId) {
        sp<IMemory> hidlMemory = mapMemory(base);
        sp<IMemory> hidlMemory = mapMemory(base);


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

        // allow mapMemory to return nullptr
        // allow mapMemory to return nullptr
        mSharedBufferMap[bufferId] = hidlMemory;
        mSharedBufferMap[bufferId] = hidlMemory;
        return Void();
        return Void();
@@ -65,7 +67,7 @@ namespace implementation {
            const SharedBuffer& source, uint64_t offset,
            const SharedBuffer& source, uint64_t offset,
            const DestinationBuffer& destination,
            const DestinationBuffer& destination,
            decrypt_cb _hidl_cb) {
            decrypt_cb _hidl_cb) {

        std::unique_lock<std::mutex> shared_buffer_lock(mSharedBufferLock);
        if (mSharedBufferMap.find(source.bufferId) == mSharedBufferMap.end()) {
        if (mSharedBufferMap.find(source.bufferId) == mSharedBufferMap.end()) {
            _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "source decrypt buffer base not set");
            _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "source decrypt buffer base not set");
            return Void();
            return Void();
@@ -79,7 +81,7 @@ namespace implementation {
            }
            }
        }
        }


        android::CryptoPlugin::Mode legacyMode;
        android::CryptoPlugin::Mode legacyMode = android::CryptoPlugin::kMode_Unencrypted;
        switch(mode) {
        switch(mode) {
        case Mode::UNENCRYPTED:
        case Mode::UNENCRYPTED:
            legacyMode = android::CryptoPlugin::kMode_Unencrypted;
            legacyMode = android::CryptoPlugin::kMode_Unencrypted;
@@ -146,7 +148,10 @@ namespace implementation {
                return Void();
                return Void();
            }
            }


            if (destBuffer.offset + destBuffer.size > destBase->getSize()) {
            size_t totalSize = 0;
            if (__builtin_add_overflow(destBuffer.offset, destBuffer.size, &totalSize) ||
                totalSize > destBase->getSize()) {
                android_errorWriteLog(0x534e4554, "176496353");
                _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
                _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
                return Void();
                return Void();
            }
            }
@@ -170,6 +175,10 @@ namespace implementation {
            _hidl_cb(Status::BAD_VALUE, 0, "invalid destination type");
            _hidl_cb(Status::BAD_VALUE, 0, "invalid destination type");
            return Void();
            return Void();
        }
        }

        // release mSharedBufferLock
        shared_buffer_lock.unlock();

        ssize_t result = mLegacyPlugin->decrypt(secure, keyId.data(), iv.data(),
        ssize_t result = mLegacyPlugin->decrypt(secure, keyId.data(), iv.data(),
                legacyMode, legacyPattern, srcPtr, legacySubSamples.get(),
                legacyMode, legacyPattern, srcPtr, legacySubSamples.get(),
                subSamples.size(), destPtr, &detailMessage);
                subSamples.size(), destPtr, &detailMessage);
Loading