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

Commit 27b25e1a authored by Adam Stone's avatar Adam Stone
Browse files

Add getMetrics impl to ClearKey impl

Adds an implementation of getMetrics to the ClearKey implementation.

BUG: 69635855

Test: VtsHalDrmV1_1TargetTest
Change-Id: I3e01037081e8855e1dc9ff332c27edb8c79040df
parent a97e318d
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -45,10 +45,12 @@ namespace V1_1 {
namespace clearkey {

DrmPlugin::DrmPlugin(SessionLibrary* sessionLibrary)
        : mSessionLibrary(sessionLibrary) {
        : mSessionLibrary(sessionLibrary),
          mOpenSessionOkCount(0),
          mCloseSessionOkCount(0),
          mCloseSessionNotOpenedCount(0) {
    mPlayPolicy.clear();
    initProperties();

}

void DrmPlugin::initProperties() {
@@ -77,6 +79,7 @@ Return<void> DrmPlugin::openSession(openSession_cb _hidl_cb) {

    setSecurityLevel(sessionId, SecurityLevel::SW_SECURE_CRYPTO);
    _hidl_cb(Status::OK, toHidlVec(sessionId));
    mOpenSessionOkCount++;
    return Void();
}

@@ -87,9 +90,11 @@ Return<Status> DrmPlugin::closeSession(const hidl_vec<uint8_t>& sessionId) {

    sp<Session> session = mSessionLibrary->findSession(toVector(sessionId));
    if (session.get()) {
        mCloseSessionOkCount++;
        mSessionLibrary->destroySession(session);
        return Status::OK;
    }
    mCloseSessionNotOpenedCount++;
    return Status::ERROR_DRM_SESSION_NOT_OPENED;
}

@@ -364,6 +369,50 @@ Return<Status> DrmPlugin::setSecurityLevel(const hidl_vec<uint8_t>& sessionId,
    return Status::OK;
}

Return<void> DrmPlugin::getMetrics(getMetrics_cb _hidl_cb) {
    // Set the open session count metric.
    DrmMetricGroup::Attribute openSessionOkAttribute = {
      "status", DrmMetricGroup::ValueType::INT64_TYPE, (int64_t) Status::OK, 0.0, ""
    };
    DrmMetricGroup::Value openSessionMetricValue = {
      "count", DrmMetricGroup::ValueType::INT64_TYPE, mOpenSessionOkCount, 0.0, ""
    };
    DrmMetricGroup::Metric openSessionMetric = {
      "open_session", { openSessionOkAttribute }, { openSessionMetricValue }
    };

    // Set the close session count metric.
    DrmMetricGroup::Attribute closeSessionOkAttribute = {
      "status", DrmMetricGroup::ValueType::INT64_TYPE, (int64_t) Status::OK, 0.0, ""
    };
    DrmMetricGroup::Value closeSessionMetricValue = {
      "count", DrmMetricGroup::ValueType::INT64_TYPE, mCloseSessionOkCount, 0.0, ""
    };
    DrmMetricGroup::Metric closeSessionMetric = {
      "close_session", { closeSessionOkAttribute }, { closeSessionMetricValue }
    };

    // Set the close session, not opened metric.
    DrmMetricGroup::Attribute closeSessionNotOpenedAttribute = {
      "status", DrmMetricGroup::ValueType::INT64_TYPE,
      (int64_t) Status::ERROR_DRM_SESSION_NOT_OPENED, 0.0, ""
    };
    DrmMetricGroup::Value closeSessionNotOpenedMetricValue = {
      "count", DrmMetricGroup::ValueType::INT64_TYPE, mCloseSessionNotOpenedCount, 0.0, ""
    };
    DrmMetricGroup::Metric closeSessionNotOpenedMetric = {
      "close_session", { closeSessionNotOpenedAttribute }, { closeSessionNotOpenedMetricValue }
    };

    DrmMetricGroup metrics = { { openSessionMetric, closeSessionMetric,
                                closeSessionNotOpenedMetric } };

    _hidl_cb(Status::OK, hidl_vec<DrmMetricGroup>({metrics}));
    return Void();
}



}  // namespace clearkey
}  // namespace V1_1
}  // namespace drm
+7 −5
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ using ::android::hardware::drm::V1_0::KeyValue;
using ::android::hardware::drm::V1_0::SecureStop;
using ::android::hardware::drm::V1_0::SecureStopId;
using ::android::hardware::drm::V1_0::Status;
using ::android::hardware::drm::V1_1::DrmMetricGroup;

using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
@@ -45,6 +46,7 @@ using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;


struct DrmPlugin : public IDrmPlugin {
    explicit DrmPlugin(SessionLibrary* sessionLibrary);

@@ -163,6 +165,8 @@ struct DrmPlugin : public IDrmPlugin {
    Return<Status> setSecurityLevel(const hidl_vec<uint8_t>& sessionId,
            SecurityLevel level) override;

    Return<void> getMetrics(getMetrics_cb _hidl_cb) override;

    Return<void> getPropertyString(
        const hidl_string& name,
        getPropertyString_cb _hidl_cb) override;
@@ -302,11 +306,6 @@ struct DrmPlugin : public IDrmPlugin {
        return Void();
    }

    Return<void> getMetrics(getMetrics_cb _hidl_cb) {
        _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, hidl_vec<DrmMetricGroup>());
        return Void();
    }

    Return<void> getSecureStopIds(getSecureStopIds_cb _hidl_cb) {
        _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, hidl_vec<SecureStopId>());
        return Void();
@@ -340,6 +339,9 @@ private:
    std::map<std::vector<uint8_t>, SecurityLevel> mSecurityLevel;
    sp<IDrmPluginListener> mListener;
    SessionLibrary *mSessionLibrary;
    int64_t mOpenSessionOkCount;
    int64_t mCloseSessionOkCount;
    int64_t mCloseSessionNotOpenedCount;

    CLEARKEY_DISALLOW_COPY_AND_ASSIGN_AND_NEW(DrmPlugin);
};